This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Silence warnings when building with MSVC
ClosedPublic

Authored by aganea on Jan 29 2022, 5:33 AM.

Details

Summary

This fixes the following warnings when building with MSVC 16.11.5:

[1035/1805] Building CXX object tools\mlir\lib\Parser\CMakeFiles\obj.MLIRParser.dir\TypeParser.cpp.obj
D:\git\llvm-project\mlir\lib\Parser\TypeParser.cpp(573): warning C4018: '>': signed/unsigned mismatch
[1187/1805] Building CXX object tools\mlir\lib\Conversion\...g\CMakeFiles\obj.MLIRTosaToLinalg.dir\TosaToLinalg.cpp.obj
D:\git\llvm-project\mlir\lib\Conversion\TosaToLinalg\TosaToLinalg.cpp(1627): warning C4334: '<<': result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)
[1239/1805] Building CXX object tools\mlir\lib\Dialect\GPU...MLIRGPUTransforms.dir\Transforms\AllReduceLowering.cpp.obj
D:\git\llvm-project\mlir\lib\Dialect\GPU\Transforms\AllReduceLowering.cpp(244) : warning C4715: '`anonymous namespace'::GpuAllReduceRewriter::getFactory': not all control paths return a value
[1251/1805] Building CXX object tools\mlir\lib\Dialect\GPU\CMakeFiles\obj.MLIRGPUOps.dir\IR\GPUDialect.cpp.obj
D:\git\llvm-project\release\tools\mlir\include\mlir/Dialect/GPU/GPUOpsAttributes.cpp.inc(107): warning C4927: illegal conversion; more than one user-defined conversion has been implicitly applied
D:\git\llvm-project\release\tools\mlir\include\mlir/Dialect/GPU/GPUOpsAttributes.cpp.inc(107): note: while calling the constructor 'mlir::FailureOr<mlir::gpu::AllReduceOperation>::FailureOr(mlir::LogicalResult)'
D:\git\llvm-project\mlir\include\mlir/Support/LogicalResult.h(81): note: see declaration of 'mlir::FailureOr<mlir::gpu::AllReduceOperation>::FailureOr'
D:\git\llvm-project\release\tools\mlir\include\mlir/Dialect/GPU/GPUOpsAttributes.cpp.inc(170): warning C4927: illegal conversion; more than one user-defined conversion has been implicitly applied
D:\git\llvm-project\release\tools\mlir\include\mlir/Dialect/GPU/GPUOpsAttributes.cpp.inc(170): note: while calling the constructor 'mlir::FailureOr<mlir::gpu::Dimension>::FailureOr(mlir::LogicalResult)'
D:\git\llvm-project\mlir\include\mlir/Support/LogicalResult.h(81): note: see declaration of 'mlir::FailureOr<mlir::gpu::Dimension>::FailureOr'
D:\git\llvm-project\release\tools\mlir\include\mlir/Dialect/GPU/GPUOpsAttributes.cpp.inc(233): warning C4927: illegal conversion; more than one user-defined conversion has been implicitly applied
D:\git\llvm-project\release\tools\mlir\include\mlir/Dialect/GPU/GPUOpsAttributes.cpp.inc(233): note: while calling the constructor 'mlir::FailureOr<mlir::gpu::ShuffleMode>::FailureOr(mlir::LogicalResult)'
D:\git\llvm-project\mlir\include\mlir/Support/LogicalResult.h(81): note: see declaration of 'mlir::FailureOr<mlir::gpu::ShuffleMode>::FailureOr'
D:\git\llvm-project\release\tools\mlir\include\mlir/Dialect/GPU/GPUOpsAttributes.cpp.inc(296): warning C4927: illegal conversion; more than one user-defined conversion has been implicitly applied
D:\git\llvm-project\release\tools\mlir\include\mlir/Dialect/GPU/GPUOpsAttributes.cpp.inc(296): note: while calling the constructor 'mlir::FailureOr<mlir::gpu::MMAElementwiseOp>::FailureOr(mlir::LogicalResult)'
D:\git\llvm-project\mlir\include\mlir/Support/LogicalResult.h(81): note: see declaration of 'mlir::FailureOr<mlir::gpu::MMAElementwiseOp>::FailureOr'
[1292/1805] Building CXX object tools\mlir\lib\Dialect\LLVMIR\CMakeFiles\obj.MLIRNVVMIR.dir\IR\NVVMDialect.cpp.obj
D:\git\llvm-project\release\tools\mlir\include\mlir/Dialect/LLVMIR/NVVMOpsAttributes.cpp.inc(110): warning C4927: illegal conversion; more than one user-defined conversion has been implicitly applied
D:\git\llvm-project\release\tools\mlir\include\mlir/Dialect/LLVMIR/NVVMOpsAttributes.cpp.inc(110): note: while calling the constructor 'mlir::FailureOr<mlir::NVVM::MMAFrag>::FailureOr(mlir::LogicalResult)'
D:\git\llvm-project\mlir\include\mlir/Support/LogicalResult.h(81): note: see declaration of 'mlir::FailureOr<mlir::NVVM::MMAFrag>::FailureOr'
D:\git\llvm-project\release\tools\mlir\include\mlir/Dialect/LLVMIR/NVVMOpsAttributes.cpp.inc(180): warning C4927: illegal conversion; more than one user-defined conversion has been implicitly applied
D:\git\llvm-project\release\tools\mlir\include\mlir/Dialect/LLVMIR/NVVMOpsAttributes.cpp.inc(180): note: while calling the constructor 'mlir::FailureOr<mlir::NVVM::MMALayout>::FailureOr(mlir::LogicalResult)'
D:\git\llvm-project\mlir\include\mlir/Support/LogicalResult.h(81): note: see declaration of 'mlir::FailureOr<mlir::NVVM::MMALayout>::FailureOr'
D:\git\llvm-project\release\tools\mlir\include\mlir/Dialect/LLVMIR/NVVMOpsAttributes.cpp.inc(250): warning C4927: illegal conversion; more than one user-defined conversion has been implicitly applied
D:\git\llvm-project\release\tools\mlir\include\mlir/Dialect/LLVMIR/NVVMOpsAttributes.cpp.inc(250): note: while calling the constructor 'mlir::FailureOr<mlir::NVVM::MMATypes>::FailureOr(mlir::LogicalResult)'
D:\git\llvm-project\mlir\include\mlir/Support/LogicalResult.h(81): note: see declaration of 'mlir::FailureOr<mlir::NVVM::MMATypes>::FailureOr'
D:\git\llvm-project\release\tools\mlir\include\mlir/Dialect/LLVMIR/NVVMOpsAttributes.cpp.inc(317): warning C4927: illegal conversion; more than one user-defined conversion has been implicitly applied
D:\git\llvm-project\release\tools\mlir\include\mlir/Dialect/LLVMIR/NVVMOpsAttributes.cpp.inc(317): note: while calling the constructor 'mlir::FailureOr<mlir::NVVM::ShflKind>::FailureOr(mlir::LogicalResult)'
D:\git\llvm-project\mlir\include\mlir/Support/LogicalResult.h(81): note: see declaration of 'mlir::FailureOr<mlir::NVVM::ShflKind>::FailureOr'
[1294/1805] Building CXX object tools\mlir\lib\Dialect\Math\Transforms\CMakeFiles\obj.MLIRMathTransforms.dir\PolynomialApproximation.cpp.obj
D:\git\llvm-project\mlir\lib\Dialect\Math\Transforms\PolynomialApproximation.cpp(317): warning C4305: 'argument': truncation from 'double' to 'float'
D:\git\llvm-project\mlir\lib\Dialect\Math\Transforms\PolynomialApproximation.cpp(318): warning C4305: 'argument': truncation from 'double' to 'float'
D:\git\llvm-project\mlir\lib\Dialect\Math\Transforms\PolynomialApproximation.cpp(319): warning C4305: 'argument': truncation from 'double' to 'float'
D:\git\llvm-project\mlir\lib\Dialect\Math\Transforms\PolynomialApproximation.cpp(320): warning C4305: 'argument': truncation from 'double' to 'float'
D:\git\llvm-project\mlir\lib\Dialect\Math\Transforms\PolynomialApproximation.cpp(393): warning C4305: 'argument': truncation from 'double' to 'float'
D:\git\llvm-project\mlir\lib\Dialect\Math\Transforms\PolynomialApproximation.cpp(1068): warning C4305: 'argument': truncation from 'long double' to 'float'
D:\git\llvm-project\mlir\lib\Dialect\Math\Transforms\PolynomialApproximation.cpp(1017): note: while compiling class template member function 'mlir::LogicalResult `anonymous-namespace'::SinAndCosApproximation<true,mlir::math::SinOp>::matchAndRewrite(OpTy,mlir::PatternRewriter &) const'
        with
        [
            OpTy=mlir::math::SinOp
        ]
D:\git\llvm-project\mlir\include\mlir/IR/PatternMatch.h(936): note: see reference to class template instantiation '`anonymous-namespace'::SinAndCosApproximation<true,mlir::math::SinOp>' being compiled
D:\git\llvm-project\mlir\lib\Dialect\Math\Transforms\PolynomialApproximation.cpp(1209): note: see reference to function template instantiation 'mlir::RewritePatternSet &mlir::RewritePatternSet::add<`anonymous-namespace'::AtanApproximation,`anonymous-namespace'::Atan2Approximation,`anonymous-namespace'::TanhApproximation,`anonymous-namespace'::LogApproximation,`anonymous-namespace'::Log2Approximation,`anonymous-namespace'::Log1pApproximation,mlir::math::ErfPolynomialApproximation,`anonymous-namespace'::ExpApproximation,`anonymous-namespace'::ExpM1Approximation,`anonymous-namespace'::SinAndCosApproximation<true,mlir::math::SinOp>,`anonymous-namespace'::SinAndCosApproximation<false,mlir::math::CosOp>,mlir::MLIRContext*,,void>(ConstructorArg &&)' being compiled
        with
        [
            ConstructorArg=mlir::MLIRContext *
        ]
D:\git\llvm-project\mlir\lib\Dialect\Math\Transforms\PolynomialApproximation.cpp(1069): warning C4305: 'argument': truncation from 'long double' to 'float'
[1306/1805] Building CXX object tools\mlir\lib\Dialect\OpenACC\CMakeFiles\obj.MLIROpenACC.dir\IR\OpenACC.cpp.obj
D:\git\llvm-project\release\tools\mlir\include\mlir/Dialect/OpenACC/OpenACCOpsAttributes.cpp.inc(87): warning C4927: illegal conversion; more than one user-defined conversion has been implicitly applied
D:\git\llvm-project\release\tools\mlir\include\mlir/Dialect/OpenACC/OpenACCOpsAttributes.cpp.inc(87): note: while calling the constructor 'mlir::FailureOr<mlir::acc::ClauseDefaultValue>::FailureOr(mlir::LogicalResult)'
D:\git\llvm-project\mlir\include\mlir/Support/LogicalResult.h(81): note: see declaration of 'mlir::FailureOr<mlir::acc::ClauseDefaultValue>::FailureOr'
D:\git\llvm-project\release\tools\mlir\include\mlir/Dialect/OpenACC/OpenACCOpsAttributes.cpp.inc(150): warning C4927: illegal conversion; more than one user-defined conversion has been implicitly applied
D:\git\llvm-project\release\tools\mlir\include\mlir/Dialect/OpenACC/OpenACCOpsAttributes.cpp.inc(150): note: while calling the constructor 'mlir::FailureOr<mlir::acc::ReductionOp>::FailureOr(mlir::LogicalResult)'
D:\git\llvm-project\mlir\include\mlir/Support/LogicalResult.h(81): note: see declaration of 'mlir::FailureOr<mlir::acc::ReductionOp>::FailureOr'
[1318/1805] Building CXX object tools\mlir\lib\Dialect\OpenMP\CMakeFiles\obj.MLIROpenMP.dir\IR\OpenMPDialect.cpp.obj
D:\git\llvm-project\release\tools\mlir\include\mlir/Dialect/OpenMP/OpenMPOpsAttributes.cpp.inc(137): warning C4927: illegal conversion; more than one user-defined conversion has been implicitly applied
D:\git\llvm-project\release\tools\mlir\include\mlir/Dialect/OpenMP/OpenMPOpsAttributes.cpp.inc(137): note: while calling the constructor 'mlir::FailureOr<mlir::omp::ClauseDefault>::FailureOr(mlir::LogicalResult)'
D:\git\llvm-project\mlir\include\mlir/Support/LogicalResult.h(81): note: see declaration of 'mlir::FailureOr<mlir::omp::ClauseDefault>::FailureOr'
D:\git\llvm-project\release\tools\mlir\include\mlir/Dialect/OpenMP/OpenMPOpsAttributes.cpp.inc(203): warning C4927: illegal conversion; more than one user-defined conversion has been implicitly applied
D:\git\llvm-project\release\tools\mlir\include\mlir/Dialect/OpenMP/OpenMPOpsAttributes.cpp.inc(203): note: while calling the constructor 'mlir::FailureOr<mlir::omp::ClauseDepend>::FailureOr(mlir::LogicalResult)'
D:\git\llvm-project\mlir\include\mlir/Support/LogicalResult.h(81): note: see declaration of 'mlir::FailureOr<mlir::omp::ClauseDepend>::FailureOr'
D:\git\llvm-project\release\tools\mlir\include\mlir/Dialect/OpenMP/OpenMPOpsAttributes.cpp.inc(270): warning C4927: illegal conversion; more than one user-defined conversion has been implicitly applied
D:\git\llvm-project\release\tools\mlir\include\mlir/Dialect/OpenMP/OpenMPOpsAttributes.cpp.inc(270): note: while calling the constructor 'mlir::FailureOr<mlir::omp::ClauseMemoryOrderKind>::FailureOr(mlir::LogicalResult)'
D:\git\llvm-project\mlir\include\mlir/Support/LogicalResult.h(81): note: see declaration of 'mlir::FailureOr<mlir::omp::ClauseMemoryOrderKind>::FailureOr'
D:\git\llvm-project\release\tools\mlir\include\mlir/Dialect/OpenMP/OpenMPOpsAttributes.cpp.inc(333): warning C4927: illegal conversion; more than one user-defined conversion has been implicitly applied
D:\git\llvm-project\release\tools\mlir\include\mlir/Dialect/OpenMP/OpenMPOpsAttributes.cpp.inc(333): note: while calling the constructor 'mlir::FailureOr<mlir::omp::ClauseOrderKind>::FailureOr(mlir::LogicalResult)'
D:\git\llvm-project\mlir\include\mlir/Support/LogicalResult.h(81): note: see declaration of 'mlir::FailureOr<mlir::omp::ClauseOrderKind>::FailureOr'
D:\git\llvm-project\release\tools\mlir\include\mlir/Dialect/OpenMP/OpenMPOpsAttributes.cpp.inc(396): warning C4927: illegal conversion; more than one user-defined conversion has been implicitly applied
D:\git\llvm-project\release\tools\mlir\include\mlir/Dialect/OpenMP/OpenMPOpsAttributes.cpp.inc(396): note: while calling the constructor 'mlir::FailureOr<mlir::omp::ClauseProcBindKind>::FailureOr(mlir::LogicalResult)'
D:\git\llvm-project\mlir\include\mlir/Support/LogicalResult.h(81): note: see declaration of 'mlir::FailureOr<mlir::omp::ClauseProcBindKind>::FailureOr'
D:\git\llvm-project\release\tools\mlir\include\mlir/Dialect/OpenMP/OpenMPOpsAttributes.cpp.inc(459): warning C4927: illegal conversion; more than one user-defined conversion has been implicitly applied
D:\git\llvm-project\release\tools\mlir\include\mlir/Dialect/OpenMP/OpenMPOpsAttributes.cpp.inc(459): note: while calling the constructor 'mlir::FailureOr<mlir::omp::ClauseScheduleKind>::FailureOr(mlir::LogicalResult)'
D:\git\llvm-project\mlir\include\mlir/Support/LogicalResult.h(81): note: see declaration of 'mlir::FailureOr<mlir::omp::ClauseScheduleKind>::FailureOr'
D:\git\llvm-project\release\tools\mlir\include\mlir/Dialect/OpenMP/OpenMPOpsAttributes.cpp.inc(522): warning C4927: illegal conversion; more than one user-defined conversion has been implicitly applied
D:\git\llvm-project\release\tools\mlir\include\mlir/Dialect/OpenMP/OpenMPOpsAttributes.cpp.inc(522): note: while calling the constructor 'mlir::FailureOr<mlir::omp::ScheduleModifier>::FailureOr(mlir::LogicalResult)'
D:\git\llvm-project\mlir\include\mlir/Support/LogicalResult.h(81): note: see declaration of 'mlir::FailureOr<mlir::omp::ScheduleModifier>::FailureOr'
[1762/1805] Building CXX object tools\mlir\test\lib\Dialect\Test\CMakeFiles\MLIRTestDialect.dir\TestAttributes.cpp.obj
D:\git\llvm-project\release\tools\mlir\test\lib\Dialect\Test\TestAttrDefs.cpp.inc(983): warning C4927: illegal conversion; more than one user-defined conversion has been implicitly applied
D:\git\llvm-project\release\tools\mlir\test\lib\Dialect\Test\TestAttrDefs.cpp.inc(983): note: while calling the constructor 'mlir::FailureOr<test::TestEnum>::FailureOr(mlir::LogicalResult)'
D:\git\llvm-project\mlir\include\mlir/Support/LogicalResult.h(81): note: see declaration of 'mlir::FailureOr<test::TestEnum>::FailureOr'

It also fixes a warning with clang-cl:

[3665/3748] Building CXX object tools\mlir\unittests\ExecutionEngine\CMakeFiles\MLIRExecutionEngineTests.dir\Invoke.cpp.obj
D:\git\llvm-project\mlir\unittests\ExecutionEngine\Invoke.cpp(43,22): warning: unused function 'lowerToLLVMDialect' [-Wunused-function]
static LogicalResult lowerToLLVMDialect(ModuleOp module) {
                     ^
1 warning generated.

Tested on Windows with MSVC 16.11.9 & clang-cl ToT. Tested on Linux with clang-13.

Diff Detail

Event Timeline

aganea created this revision.Jan 29 2022, 5:33 AM
aganea requested review of this revision.Jan 29 2022, 5:33 AM
aganea edited the summary of this revision. (Show Details)Jan 29 2022, 5:34 AM
aganea added inline comments.Jan 29 2022, 5:38 AM
mlir/include/mlir/IR/EnumAttr.td
31

Unfortunately the previous code was generating here warning C4927: illegal conversion; more than one user-defined conversion has been implicitly applied, see https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-1-c4927?view=msvc-170

This is because parser.emitError() returns a InFlightDiagnostic which has a cast operator to LogicalResult, then the whole expression constructs a FailureOr.

mehdi_amini accepted this revision.Jan 30 2022, 1:14 AM
mehdi_amini added inline comments.
mlir/unittests/ExecutionEngine/Invoke.cpp
54–55

Please move the comment with the guard

This revision is now accepted and ready to land.Jan 30 2022, 1:14 AM
aganea marked an inline comment as done.Jan 30 2022, 7:19 AM
aganea added inline comments.
mlir/unittests/ExecutionEngine/Invoke.cpp
54–55

Will do, thanks for reviewing!

This revision was automatically updated to reflect the committed changes.
aganea marked an inline comment as done.