[PATCH] D129152: [Clang][unittests] Silence trucation warning with MSVC
This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG0880b9d52620: [Clang][unittests] Silence trucation warning with MSVC 2022 (authored by aganea). Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D129152/new/ https://reviews.llvm.org/D129152 Files: clang/unittests/StaticAnalyzer/RangeSetTest.cpp Index: clang/unittests/StaticAnalyzer/RangeSetTest.cpp === --- clang/unittests/StaticAnalyzer/RangeSetTest.cpp +++ clang/unittests/StaticAnalyzer/RangeSetTest.cpp @@ -88,6 +88,12 @@ template static constexpr T X555TruncZeroOf = TruncZeroOf; // 0x'5600 +// Silence 'warning C4309: 'initializing': truncation of constant value' +// in RangeSetCastToPromotionConversionTest. +#if defined(_MSC_VER) && !defined(__clang__) +#pragma warning(push) +#pragma warning(disable : 4309) +#endif // Numbers for ranges with the same bits in the lowest byte. // 0x'AA2A static constexpr T FromA = ClearLowBytes + 42; @@ -95,6 +101,10 @@ // 0x'552A static constexpr T FromB = ClearLowBytes + 42; static constexpr T ToB = FromB + 2; // 0x'552C + +#if defined(_MSC_VER) && !defined(__clang__) +#pragma warning(pop) +#endif }; template Index: clang/unittests/StaticAnalyzer/RangeSetTest.cpp === --- clang/unittests/StaticAnalyzer/RangeSetTest.cpp +++ clang/unittests/StaticAnalyzer/RangeSetTest.cpp @@ -88,6 +88,12 @@ template static constexpr T X555TruncZeroOf = TruncZeroOf; // 0x'5600 +// Silence 'warning C4309: 'initializing': truncation of constant value' +// in RangeSetCastToPromotionConversionTest. +#if defined(_MSC_VER) && !defined(__clang__) +#pragma warning(push) +#pragma warning(disable : 4309) +#endif // Numbers for ranges with the same bits in the lowest byte. // 0x'AA2A static constexpr T FromA = ClearLowBytes + 42; @@ -95,6 +101,10 @@ // 0x'552A static constexpr T FromB = ClearLowBytes + 42; static constexpr T ToB = FromB + 2; // 0x'552C + +#if defined(_MSC_VER) && !defined(__clang__) +#pragma warning(pop) +#endif }; template ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D129152: [Clang][unittests] Silence trucation warning with MSVC
aganea added a comment. Thanks all for reviewing! Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D129152/new/ https://reviews.llvm.org/D129152 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D129152: [Clang][unittests] Silence trucation warning with MSVC
thieta accepted this revision. thieta added a comment. Thanks for switching to pragma! Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D129152/new/ https://reviews.llvm.org/D129152 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D129152: [Clang][unittests] Silence trucation warning with MSVC
ASDenysPetrov accepted this revision. ASDenysPetrov added a comment. This revision is now accepted and ready to land. @aganea Thank you for fixing this. `TestValues` structure impies to hold a set of values which can do some kind of convertions including truncations. This is what tests are about. That's true, it may happen that some test cases don't need some values. You can carry them out to some `TestValues2` structure and use them instead. That also would work. So it's up to you. I'm OK with both solutions. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D129152/new/ https://reviews.llvm.org/D129152 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D129152: [Clang][unittests] Silence trucation warning with MSVC
aganea updated this revision to Diff 442366. aganea added a comment. Use `#pragma` Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D129152/new/ https://reviews.llvm.org/D129152 Files: clang/unittests/StaticAnalyzer/RangeSetTest.cpp Index: clang/unittests/StaticAnalyzer/RangeSetTest.cpp === --- clang/unittests/StaticAnalyzer/RangeSetTest.cpp +++ clang/unittests/StaticAnalyzer/RangeSetTest.cpp @@ -88,6 +88,12 @@ template static constexpr T X555TruncZeroOf = TruncZeroOf; // 0x'5600 +// Silence 'warning C4309: 'initializing': truncation of constant value' +// in RangeSetCastToPromotionConversionTest. +#if defined(_MSC_VER) && !defined(__clang__) +#pragma warning(push) +#pragma warning(disable : 4309) +#endif // Numbers for ranges with the same bits in the lowest byte. // 0x'AA2A static constexpr T FromA = ClearLowBytes + 42; @@ -95,6 +101,10 @@ // 0x'552A static constexpr T FromB = ClearLowBytes + 42; static constexpr T ToB = FromB + 2; // 0x'552C + +#if defined(_MSC_VER) && !defined(__clang__) +#pragma warning(pop) +#endif }; template Index: clang/unittests/StaticAnalyzer/RangeSetTest.cpp === --- clang/unittests/StaticAnalyzer/RangeSetTest.cpp +++ clang/unittests/StaticAnalyzer/RangeSetTest.cpp @@ -88,6 +88,12 @@ template static constexpr T X555TruncZeroOf = TruncZeroOf; // 0x'5600 +// Silence 'warning C4309: 'initializing': truncation of constant value' +// in RangeSetCastToPromotionConversionTest. +#if defined(_MSC_VER) && !defined(__clang__) +#pragma warning(push) +#pragma warning(disable : 4309) +#endif // Numbers for ranges with the same bits in the lowest byte. // 0x'AA2A static constexpr T FromA = ClearLowBytes + 42; @@ -95,6 +101,10 @@ // 0x'552A static constexpr T FromB = ClearLowBytes + 42; static constexpr T ToB = FromB + 2; // 0x'552C + +#if defined(_MSC_VER) && !defined(__clang__) +#pragma warning(pop) +#endif }; template ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D129152: [Clang][unittests] Silence trucation warning with MSVC
thieta added a comment. Isn't it better to silence this warning with a pragma instead of disabling it for the whole file? Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D129152/new/ https://reviews.llvm.org/D129152 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D129152: [Clang][unittests] Silence trucation warning with MSVC
aganea created this revision. aganea added reviewers: ASDenysPetrov, thieta, hans. Herald added subscribers: steakhal, mgorny. Herald added a project: All. aganea requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits. I'm seeing the following with MSVC 2022: C:\git\llvm-project\clang\unittests\StaticAnalyzer\RangeSetTest.cpp(97): warning C4309: 'initializing': truncation of constant value C:\git\llvm-project\clang\unittests\StaticAnalyzer\RangeSetTest.cpp(948): note: see reference to class template instantiation '`anonymous-namespace'::TestValues' being compiled C:\git\llvm-project\clang\unittests\StaticAnalyzer\RangeSetTest.cpp(942): note: while compiling class template member function 'void `anonymous-namespace'::RangeSetCastToPromotionConversionTest_Test_Test::TestBody(void)' The issue here is that `RangeSetCastToPromotionConversionTest` tries to instantiate the template at L947, `using TV = TestValues;` which ends up trying to assign at L94, `static constexpr T ToA = FromA + 2;` which overflows with `T=char`. Ideally, we wouldn't need `FromA/ToA/FromB/ToB` for this test. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D129152 Files: clang/unittests/StaticAnalyzer/CMakeLists.txt Index: clang/unittests/StaticAnalyzer/CMakeLists.txt === --- clang/unittests/StaticAnalyzer/CMakeLists.txt +++ clang/unittests/StaticAnalyzer/CMakeLists.txt @@ -20,6 +20,11 @@ TestReturnValueUnderConstruction.cpp ) +if(MSVC) + # warning C4309: 'initializing': truncation of constant value + set_source_files_properties(RangeSetTest.cpp PROPERTIES COMPILE_FLAGS -wd4309) +endif() + clang_target_link_libraries(StaticAnalysisTests PRIVATE clangBasic Index: clang/unittests/StaticAnalyzer/CMakeLists.txt === --- clang/unittests/StaticAnalyzer/CMakeLists.txt +++ clang/unittests/StaticAnalyzer/CMakeLists.txt @@ -20,6 +20,11 @@ TestReturnValueUnderConstruction.cpp ) +if(MSVC) + # warning C4309: 'initializing': truncation of constant value + set_source_files_properties(RangeSetTest.cpp PROPERTIES COMPILE_FLAGS -wd4309) +endif() + clang_target_link_libraries(StaticAnalysisTests PRIVATE clangBasic ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits