[llvm] r241281 - Fix for PR23310: llvm-dis crashes when trying to upgrade an intrinsic.

Rafael Espindola rafael.espindola at gmail.com
Thu Jul 2 09:22:40 PDT 2015


Author: rafael
Date: Thu Jul  2 11:22:40 2015
New Revision: 241281

URL: http://llvm.org/viewvc/llvm-project?rev=241281&view=rev
Log:
Fix for PR23310: llvm-dis crashes when trying to upgrade an intrinsic.

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.

Added:
    llvm/trunk/test/Bitcode/Inputs/PR23310.bc
    llvm/trunk/test/Bitcode/PR23310.test
Modified:
    llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp

Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=241281&r1=241280&r2=241281&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Thu Jul  2 11:22:40 2015
@@ -170,7 +170,7 @@ class BitcodeReader : public GVMateriali
 
   // 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.
@@ -2710,7 +2710,7 @@ std::error_code BitcodeReader::globalCle
   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.
@@ -4540,7 +4540,7 @@ std::error_code BitcodeReader::materiali
       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]);

Added: llvm/trunk/test/Bitcode/Inputs/PR23310.bc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/Inputs/PR23310.bc?rev=241281&view=auto
==============================================================================
Binary files llvm/trunk/test/Bitcode/Inputs/PR23310.bc (added) and llvm/trunk/test/Bitcode/Inputs/PR23310.bc Thu Jul  2 11:22:40 2015 differ

Added: llvm/trunk/test/Bitcode/PR23310.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/PR23310.test?rev=241281&view=auto
==============================================================================
--- llvm/trunk/test/Bitcode/PR23310.test (added)
+++ llvm/trunk/test/Bitcode/PR23310.test Thu Jul  2 11:22:40 2015
@@ -0,0 +1 @@
+RUN: llvm-dis -disable-output %p/Inputs/PR23310.bc





More information about the llvm-commits mailing list