[llvm] r303693 - Silence MSVC warning about unsigned integer overflow, which has defined behavior

Reid Kleckner via llvm-commits llvm-commits at lists.llvm.org
Tue May 23 14:35:33 PDT 2017


Author: rnk
Date: Tue May 23 16:35:32 2017
New Revision: 303693

URL: http://llvm.org/viewvc/llvm-project?rev=303693&view=rev
Log:
Silence MSVC warning about unsigned integer overflow, which has defined behavior

Modified:
    llvm/trunk/lib/IR/Attributes.cpp

Modified: llvm/trunk/lib/IR/Attributes.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Attributes.cpp?rev=303693&r1=303692&r2=303693&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Attributes.cpp (original)
+++ llvm/trunk/lib/IR/Attributes.cpp Tue May 23 16:35:32 2017
@@ -793,7 +793,9 @@ std::string AttributeSetNode::getAsStrin
 ///   ReturnIndex:    0  -> 1
 ///   FirstArgIndex: 1.. -> 2..
 static constexpr unsigned attrIdxToArrayIdx(unsigned Index) {
-  return Index + 1;
+  // MSVC warns about '~0U + 1' wrapping around when this is called on
+  // FunctionIndex, so cast to int first.
+  return static_cast<int>(Index) + 1;
 }
 
 AttributeListImpl::AttributeListImpl(LLVMContext &C,




More information about the llvm-commits mailing list