[PATCH] D129152: [Clang][unittests] Silence trucation warning with MSVC

Alexandre Ganea via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 5 10:42:52 PDT 2022


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<F>' 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<T>::TestBody(void)'

The issue here is that `RangeSetCastToPromotionConversionTest` tries to instantiate the template at L947, `using TV = TestValues<F>;` 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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129152.442346.patch
Type: text/x-patch
Size: 529 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220705/8f3ab601/attachment.bin>


More information about the cfe-commits mailing list