In order for parameter attribute uniquing to make
authorDuncan Sands <baldrick@free.fr>
Tue, 20 Nov 2007 14:09:29 +0000 (14:09 +0000)
committerDuncan Sands <baldrick@free.fr>
Tue, 20 Nov 2007 14:09:29 +0000 (14:09 +0000)
any sense it is important that ParamAttr::None gets
treated the same as not supplying an attribute at
all.  Rather than stripping ParamAttr::None out of
the list of attributes, assert if ParamAttr::None
is seen.  Fix up the bitcode reader which liked to
insert ParamAttr::None all over the place.  Patch
based on one by Török Edwin.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44250 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Bitcode/Reader/BitcodeReader.cpp
lib/VMCore/Function.cpp

index aa78e7c4dc0e8d57171247e872a679e70eaaa4d1..119a583358e4b00ef2451cacc49c1ed971832c48 100644 (file)
@@ -232,17 +232,15 @@ bool BitcodeReader::ParseParamAttrBlock() {
       if (Record.size() & 1)
         return Error("Invalid ENTRY record");
 
-      ParamAttrsWithIndex PAWI;
       for (unsigned i = 0, e = Record.size(); i != e; i += 2) {
-        PAWI.index = Record[i];
-        PAWI.attrs = Record[i+1];
-        Attrs.push_back(PAWI);
+        if (Record[i+1] != ParamAttr::None)
+          Attrs.push_back(ParamAttrsWithIndex::get(Record[i], Record[i+1]));
       }
-      ParamAttrs.push_back(ParamAttrsList::get(Attrs));
+      ParamAttrs.push_back(Attrs.empty() ? NULL : ParamAttrsList::get(Attrs));
       Attrs.clear();
       break;
     }
-    }    
+    }
   }
 }
 
index 3256d5b9f63378485a2fb73ebb3a45a27bb1597a..a011aaea3384c4eaac4db8000cc1de3e04007716 100644 (file)
@@ -129,8 +129,12 @@ ParamAttrsList *
 ParamAttrsList::get(const ParamAttrsVector &attrVec) {
   assert(!attrVec.empty() && "Illegal to create empty ParamAttrsList");
 #ifndef NDEBUG
-  for (unsigned i = 1, e = attrVec.size(); i < e; ++i)
-    assert(attrVec[i-1].index < attrVec[i].index && "Misordered ParamAttrsList!");
+  for (unsigned i = 0, e = attrVec.size(); i < e; ++i) {
+    assert(attrVec[i].attrs != ParamAttr::None
+           && "Pointless parameter attribute!");
+    assert((!i || attrVec[i-1].index < attrVec[i].index)
+           && "Misordered ParamAttrsList!");
+  }
 #endif
   ParamAttrsList key(attrVec);
   FoldingSetNodeID ID;