when the bitcode reader is referencing a paramattr, make sure to bump its refcount.
[oota-llvm.git] / lib / Bitcode / Reader / BitcodeReader.cpp
index c1cfa975a7159a05475be2087aad55d9b67f2f6d..c86ee3048a9b65cd4df0a4ce4768e77bff6c1301 100644 (file)
@@ -31,6 +31,11 @@ void BitcodeReader::FreeState() {
   Buffer = 0;
   std::vector<PATypeHolder>().swap(TypeList);
   ValueList.clear();
+  
+  // Drop references to ParamAttrs.
+  for (unsigned i = 0, e = ParamAttrs.size(); i != e; ++i)
+    ParamAttrs[i]->dropRef();
+  
   std::vector<const ParamAttrsList*>().swap(ParamAttrs);
   std::vector<BasicBlock*>().swap(FunctionBBs);
   std::vector<Function*>().swap(FunctionsWithBodies);
@@ -237,7 +242,13 @@ bool BitcodeReader::ParseParamAttrBlock() {
         if (Record[i+1] != ParamAttr::None)
           Attrs.push_back(ParamAttrsWithIndex::get(Record[i], Record[i+1]));
       }
-      ParamAttrs.push_back(Attrs.empty() ? NULL : ParamAttrsList::get(Attrs));
+      if (Attrs.empty()) {
+        ParamAttrs.push_back(0);
+      } else {
+        ParamAttrs.push_back(ParamAttrsList::get(Attrs));
+        ParamAttrs.back()->addRef();
+      }
+
       Attrs.clear();
       break;
     }
@@ -1076,6 +1087,7 @@ bool BitcodeReader::ParseModule(const std::string &ModuleID) {
       break;
     }
     // ALIAS: [alias type, aliasee val#, linkage]
+    // ALIAS: [alias type, aliasee val#, linkage, visibility]
     case bitc::MODULE_CODE_ALIAS: {
       if (Record.size() < 3)
         return Error("Invalid MODULE_ALIAS record");
@@ -1085,6 +1097,9 @@ bool BitcodeReader::ParseModule(const std::string &ModuleID) {
       
       GlobalAlias *NewGA = new GlobalAlias(Ty, GetDecodedLinkage(Record[2]),
                                            "", 0, TheModule);
+      // Old bitcode files didn't have visibility field.
+      if (Record.size() > 3)
+        NewGA->setVisibility(GetDecodedVisibility(Record[3]));
       ValueList.push_back(NewGA);
       AliasInits.push_back(std::make_pair(NewGA, Record[1]));
       break;