[llvm] f7dce88 - [IR] Fix MSVC warning (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 17 09:27:49 PDT 2020


Author: Nikita Popov
Date: 2020-07-17T18:27:39+02:00
New Revision: f7dce88915ad1629df2d19cd41e45a5e64f2664c

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

LOG: [IR] Fix MSVC warning (NFC)

As requested by Andrew Kaylor, rewrite this code in a way that does
not warn on old MSVC versions.

Avoid the buggy constexpr warning by just not using constexpr and
removing the static_assert that depends on it.

Added: 
    

Modified: 
    llvm/lib/IR/Attributes.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp
index d57597a55dc8..8bf4e82357c6 100644
--- a/llvm/lib/IR/Attributes.cpp
+++ b/llvm/lib/IR/Attributes.cpp
@@ -969,7 +969,7 @@ std::string AttributeSetNode::getAsString(bool InAttrGrp) const {
 
 /// Map from AttributeList index to the internal array index. Adding one happens
 /// to work, because -1 wraps around to 0.
-static constexpr unsigned attrIdxToArrayIdx(unsigned Index) {
+static unsigned attrIdxToArrayIdx(unsigned Index) {
   return Index + 1;
 }
 
@@ -982,9 +982,7 @@ AttributeListImpl::AttributeListImpl(ArrayRef<AttributeSet> Sets)
 
   // Initialize AvailableFunctionAttrs and AvailableSomewhereAttrs
   // summary bitsets.
-  static_assert(attrIdxToArrayIdx(AttributeList::FunctionIndex) == 0U,
-                "function should be stored in slot 0");
-  for (const auto &I : Sets[0])
+  for (const auto &I : Sets[attrIdxToArrayIdx(AttributeList::FunctionIndex)])
     if (!I.isStringAttribute())
       AvailableFunctionAttrs.addAttribute(I.getKindAsEnum());
 


        


More information about the llvm-commits mailing list