[llvm] 6904c71 - [IR] Remove MSVC warning workaround (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 23 13:34:09 PDT 2020


Author: Nikita Popov
Date: 2020-06-23T22:33:57+02:00
New Revision: 6904c7129b26373eb33489b43538ab580829655e

URL: https://github.com/llvm/llvm-project/commit/6904c7129b26373eb33489b43538ab580829655e
DIFF: https://github.com/llvm/llvm-project/commit/6904c7129b26373eb33489b43538ab580829655e.diff

LOG: [IR] Remove MSVC warning workaround (NFC)

While LLVM does fold this to x+1, GCC does not. As this is hot
code, let's try to avoid that.

According to
https://developercommunity.visualstudio.com/content/problem/211134/unsigned-integer-overflows-in-constexpr-functionsa.html
this spurious warning in MSVC has been fixed in Visual Studio 2019
Version 16.4. Let's see if there are any build bots running old
MSVC versions with warnings treated as errors...

Added: 
    

Modified: 
    llvm/lib/IR/Attributes.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp
index d8798eb12ae7..8bdd67907106 100644
--- a/llvm/lib/IR/Attributes.cpp
+++ b/llvm/lib/IR/Attributes.cpp
@@ -965,11 +965,9 @@ std::string AttributeSetNode::getAsString(bool InAttrGrp) const {
 //===----------------------------------------------------------------------===//
 
 /// Map from AttributeList index to the internal array index. Adding one happens
-/// to work, but it relies on unsigned integer wrapping. MSVC warns about
-/// unsigned wrapping in constexpr functions, so write out the conditional. LLVM
-/// folds it to add anyway.
+/// to work, because -1 wraps around to 0.
 static constexpr unsigned attrIdxToArrayIdx(unsigned Index) {
-  return Index == AttributeList::FunctionIndex ? 0 : Index + 1;
+  return Index + 1;
 }
 
 AttributeListImpl::AttributeListImpl(ArrayRef<AttributeSet> Sets)


        


More information about the llvm-commits mailing list