[PATCH] D79337: Silence warnings when compiling x86 with latest MSVC

Alexandre Ganea via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 4 10:09:50 PDT 2020


aganea created this revision.
aganea added reviewers: bkramer, john.brawn, vsk.
Herald added subscribers: llvm-commits, cfe-commits, hiraditya.
Herald added projects: clang, LLVM.

When using Visual Studio 2019 16.5.4, and targetting 32-bit, before this patch we were seeing:

  [1378/3007] Building CXX object lib\ProfileData\CMakeFiles\LLVMProfileData.dir\InstrProfReader.cpp.obj
  F:\llvm-project\llvm\lib\ProfileData\InstrProfReader.cpp(426): warning C4018: '>': signed/unsigned mismatch
  F:\llvm-project\llvm\lib\ProfileData\InstrProfReader.cpp(415): note: while compiling class template member function 'llvm::Error llvm::RawInstrProfReader<uint32_t>::readRawCounts(llvm::InstrProfRecord &)'
  F:\llvm-project\llvm\lib\ProfileData\InstrProfReader.cpp(491): note: see reference to function template instantiation 'llvm::Error llvm::RawInstrProfReader<uint32_t>::readRawCounts(llvm::InstrProfRecord &)' being compiled
  F:\llvm-project\llvm\lib\ProfileData\InstrProfReader.cpp(78): note: see reference to class template instantiation 'llvm::RawInstrProfReader<uint32_t>' being compiled
  F:\llvm-project\llvm\lib\ProfileData\InstrProfReader.cpp(430): warning C4018: '>': signed/unsigned mismatch

And:

  [2060/3007] Building CXX object tools\clang\lib\Sema\CMakeFiles\obj.clangSema.dir\ParsedAttr.cpp.obj
  F:\llvm-project\clang\lib\Sema\ParsedAttr.cpp(114): warning C4018: '<': signed/unsigned mismatch

I can commit the two files independently if you prefer.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D79337

Files:
  clang/lib/Sema/ParsedAttr.cpp
  llvm/lib/ProfileData/InstrProfReader.cpp


Index: llvm/lib/ProfileData/InstrProfReader.cpp
===================================================================
--- llvm/lib/ProfileData/InstrProfReader.cpp
+++ llvm/lib/ProfileData/InstrProfReader.cpp
@@ -423,11 +423,11 @@
 
   // Check bounds. Note that the counter pointer embedded in the data record
   // may itself be corrupt.
-  if (NumCounters > MaxNumCounters)
+  if (MaxNumCounters < 0 || NumCounters > (uint32_t)MaxNumCounters)
     return error(instrprof_error::malformed);
   ptrdiff_t CounterOffset = getCounterOffset(CounterPtr);
   if (CounterOffset < 0 || CounterOffset > MaxNumCounters ||
-      (CounterOffset + NumCounters) > MaxNumCounters)
+      ((uint32_t)CounterOffset + NumCounters) > (uint32_t)MaxNumCounters)
     return error(instrprof_error::malformed);
 
   auto RawCounts = makeArrayRef(getCounter(CounterOffset), NumCounters);
Index: clang/lib/Sema/ParsedAttr.cpp
===================================================================
--- clang/lib/Sema/ParsedAttr.cpp
+++ clang/lib/Sema/ParsedAttr.cpp
@@ -111,7 +111,7 @@
 
 const ParsedAttrInfo &ParsedAttrInfo::get(const AttributeCommonInfo &A) {
   // If we have a ParsedAttrInfo for this ParsedAttr then return that.
-  if (A.getParsedKind() < llvm::array_lengthof(AttrInfoMap))
+  if ((size_t)A.getParsedKind() < llvm::array_lengthof(AttrInfoMap))
     return *AttrInfoMap[A.getParsedKind()];
 
   // If this is an ignored attribute then return an appropriate ParsedAttrInfo.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79337.261848.patch
Type: text/x-patch
Size: 1466 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200504/50d93d91/attachment.bin>


More information about the llvm-commits mailing list