Skip to content

Commit af8514c

Browse files
authored
Fix logical or/and usage for MSVC compilation. (#3984)
The `or`/`and` alternate spellings are not supported on all compilers without additinoal flags (https://learn.microsoft.com/en-us/cpp/cpp/logical-or-operator-pipe-pipe?view=msvc-170#operator-keyword-for-). This code started producing errors in the downstream IREE project when building with MSVC on Windows: https://github.com/iree-org/iree/actions/runs/12985792116/job/36211327035#step:9:7446 ``` [6452/8792] Building CXX object compiler\plugins\input\Torch\torch-mlir\CMakeFiles\iree_compiler_plugins_input_Torch_torch-mlir_TorchDialectPasses.objects.dir\__\__\__\__\__\third_party\torch-mlir\lib\Dialect\Torch\Transforms\DecomposeComplexOps.cpp.obj FAILED: compiler/plugins/input/Torch/torch-mlir/CMakeFiles/iree_compiler_plugins_input_Torch_torch-mlir_TorchDialectPasses.objects.dir/__/__/__/__/__/third_party/torch-mlir/lib/Dialect/Torch/Transforms/DecomposeComplexOps.cpp.obj C:\ProgramData\chocolatey\bin\ccache "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.42.34433\bin\Hostx64\x64\cl.exe" /nologo /TP -IC:\home\runner\_work\iree\iree -IC:\mnt\azure\b\093843 -IC:\home\runner\_work\iree\iree\third_party\torch-mlir\include -IC:\home\runner\_work\iree\iree\compiler\plugins\input\Torch -IC:\mnt\azure\b\093843\compiler\plugins\input\Torch -IC:\home\runner\_work\iree\iree\third_party\llvm-project\llvm\include -IC:\mnt\azure\b\093843\llvm-project\include -IC:\home\runner\_work\iree\iree\third_party\llvm-project\mlir\include -IC:\mnt\azure\b\093843\llvm-project\tools\mlir\include -IC:\home\runner\_work\iree\iree\third_party\llvm-project\lld\include -IC:\mnt\azure\b\093843\llvm-project\tools\lld\include /DWIN32 /D_WINDOWS /EHsc /Z7 /O2 /Ob1 -std:c++17 -MD /wd4996 /Zc:preprocessor /DWIN32_LEAN_AND_MEAN /DNOMINMAX /D_USE_MATH_DEFINES /D_CRT_SECURE_NO_WARNINGS /D_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES /D_SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING /GR- /bigobj /W3 /wd4200 /wd4018 /wd4146 /wd4244 /wd4267 /wd4005 /wd4065 /wd4141 /wd4624 /wd4576 /wd5105 /showIncludes /Focompiler\plugins\input\Torch\torch-mlir\CMakeFiles\iree_compiler_plugins_input_Torch_torch-mlir_TorchDialectPasses.objects.dir\__\__\__\__\__\third_party\torch-mlir\lib\Dialect\Torch\Transforms\DecomposeComplexOps.cpp.obj /Fdcompiler\plugins\input\Torch\torch-mlir\CMakeFiles\iree_compiler_plugins_input_Torch_torch-mlir_TorchDialectPasses.objects.dir\ /FS -c C:\home\runner\_work\iree\iree\third_party\torch-mlir\lib\Dialect\Torch\Transforms\DecomposeComplexOps.cpp C:\home\runner\_work\iree\iree\third_party\torch-mlir\lib\Dialect\Torch\Transforms\DecomposeComplexOps.cpp(9783): error C2146: syntax error: missing ')' before identifier 'or' C:\home\runner\_work\iree\iree\third_party\torch-mlir\lib\Dialect\Torch\Transforms\DecomposeComplexOps.cpp(9783): error C2065: 'or': undeclared identifier C:\home\runner\_work\iree\iree\third_party\torch-mlir\lib\Dialect\Torch\Transforms\DecomposeComplexOps.cpp(9783): error C2146: syntax error: missing ';' before identifier 'selfRank' C:\home\runner\_work\iree\iree\third_party\torch-mlir\lib\Dialect\Torch\Transforms\DecomposeComplexOps.cpp(9783): error C2059: syntax error: ')' C:\home\runner\_work\iree\iree\third_party\torch-mlir\lib\Dialect\Torch\Transforms\DecomposeComplexOps.cpp(9784): error C2059: syntax error: 'return' C:\home\runner\_work\iree\iree\third_party\torch-mlir\lib\Dialect\Torch\Transforms\DecomposeComplexOps.cpp(9786): error C2059: syntax error: 'if' ```
1 parent 4f0b79c commit af8514c

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

lib/Conversion/TorchOnnxToTorch/DefaultDomainGtoP.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2346,7 +2346,7 @@ void mlir::torch::onnx_c::populateDefaultDomainGtoP(
23462346
ArrayRef<int64_t> inputShape = inputTensorType.getSizes();
23472347
unsigned inputRank = inputShape.size();
23482348
// only handle 2D, 3D and 5D pooling cases
2349-
if (inputRank > 5 or inputRank < 3) {
2349+
if (inputRank > 5 || inputRank < 3) {
23502350
return failure();
23512351
}
23522352
if (!resultType || !resultType.hasSizes()) {
@@ -2454,7 +2454,7 @@ void mlir::torch::onnx_c::populateDefaultDomainGtoP(
24542454
"Unimplemented: unranked tensor");
24552455
unsigned rank = *maybeRank;
24562456
// only 1D, 2D and 3D LpPool is supported.
2457-
if (rank > 5 or rank < 3) {
2457+
if (rank > 5 || rank < 3) {
24582458
return failure();
24592459
}
24602460

lib/Dialect/Torch/Transforms/DecomposeComplexOps.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9780,16 +9780,16 @@ class DecomposeAtenNllLossForwardOp
97809780
auto targetSizes = targetType.getSizes();
97819781
int64_t selfRank = selfSizes.size();
97829782
int64_t targetRank = targetSizes.size();
9783-
if (selfRank <= 0 or selfRank > 2) {
9783+
if (selfRank <= 0 || selfRank > 2) {
97849784
return rewriter.notifyMatchFailure(op, "input tensor should be 1D or 2D");
97859785
}
97869786
if (targetRank > 1) {
97879787
return rewriter.notifyMatchFailure(op,
97889788
"target tensor shoule be 0D or 1D!");
97899789
}
97909790

9791-
if (selfRank != 1 or targetRank != 0) {
9792-
if (!(selfSizes[0] == kUnknownSize and targetSizes[0] == kUnknownSize) and
9791+
if (selfRank != 1 || targetRank != 0) {
9792+
if (!(selfSizes[0] == kUnknownSize && targetSizes[0] == kUnknownSize) &&
97939793
selfSizes[0] != targetSizes[0]) {
97949794
return rewriter.notifyMatchFailure(
97959795
op,
@@ -9907,7 +9907,7 @@ class DecomposeAtenNllLossForwardOp
99079907
zeroTensor);
99089908

99099909
Value totalWeight;
9910-
if (reduction == 0 and selfRank > 1) {
9910+
if (reduction == 0 && selfRank > 1) {
99119911
auto zeroFloat =
99129912
rewriter.create<ConstantFloatOp>(loc, rewriter.getF64FloatAttr(0.0));
99139913
Value twSize = rewriter.create<PrimListConstructOp>(

0 commit comments

Comments
 (0)