Fix for PR23310: llvm-dis crashes when trying to upgrade an intrinsic.
authorRafael Espindola <rafael.espindola@gmail.com>
Thu, 2 Jul 2015 16:22:40 +0000 (16:22 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Thu, 2 Jul 2015 16:22:40 +0000 (16:22 +0000)
When trying to upgrade @llvm.x86.sse2.psrl.dq while parsing a module,
BitcodeReader adds the function to its worklist twice, resulting in a
crash when accessing it the second time.

This patch replaces the worklist vector by a map.

Patch by Philip Pfaffe.

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

lib/Bitcode/Reader/BitcodeReader.cpp
test/Bitcode/Inputs/PR23310.bc [new file with mode: 0644]
test/Bitcode/PR23310.test [new file with mode: 0644]

index 29131d43ab030a67b30405229ad79cb502f5ffc7..d9ac3ad7c644086f9f2816983133bf8b24a7119e 100644 (file)
@@ -170,7 +170,7 @@ class BitcodeReader : public GVMaterializer {
 
   // When intrinsic functions are encountered which require upgrading they are
   // stored here with their replacement function.
 
   // When intrinsic functions are encountered which require upgrading they are
   // stored here with their replacement function.
-  typedef std::vector<std::pair<Function*, Function*> > UpgradedIntrinsicMap;
+  typedef DenseMap<Function*, Function*> UpgradedIntrinsicMap;
   UpgradedIntrinsicMap UpgradedIntrinsics;
 
   // Map the bitcode's custom MDKind ID to the Module's MDKind ID.
   UpgradedIntrinsicMap UpgradedIntrinsics;
 
   // Map the bitcode's custom MDKind ID to the Module's MDKind ID.
@@ -2710,7 +2710,7 @@ std::error_code BitcodeReader::globalCleanup() {
   for (Function &F : *TheModule) {
     Function *NewFn;
     if (UpgradeIntrinsicFunction(&F, NewFn))
   for (Function &F : *TheModule) {
     Function *NewFn;
     if (UpgradeIntrinsicFunction(&F, NewFn))
-      UpgradedIntrinsics.push_back(std::make_pair(&F, NewFn));
+      UpgradedIntrinsics[&F] = NewFn;
   }
 
   // Look for global variables which need to be renamed.
   }
 
   // Look for global variables which need to be renamed.
@@ -4540,7 +4540,7 @@ std::error_code BitcodeReader::materializeModule(Module *M) {
       I.first->eraseFromParent();
     }
   }
       I.first->eraseFromParent();
     }
   }
-  std::vector<std::pair<Function*, Function*> >().swap(UpgradedIntrinsics);
+  UpgradedIntrinsics.clear();
 
   for (unsigned I = 0, E = InstsWithTBAATag.size(); I < E; I++)
     UpgradeInstWithTBAATag(InstsWithTBAATag[I]);
 
   for (unsigned I = 0, E = InstsWithTBAATag.size(); I < E; I++)
     UpgradeInstWithTBAATag(InstsWithTBAATag[I]);
diff --git a/test/Bitcode/Inputs/PR23310.bc b/test/Bitcode/Inputs/PR23310.bc
new file mode 100644 (file)
index 0000000..cd1202f
Binary files /dev/null and b/test/Bitcode/Inputs/PR23310.bc differ
diff --git a/test/Bitcode/PR23310.test b/test/Bitcode/PR23310.test
new file mode 100644 (file)
index 0000000..6b79471
--- /dev/null
@@ -0,0 +1 @@
+RUN: llvm-dis -disable-output %p/Inputs/PR23310.bc