[llvm] r373543 - [gicombiner] Fix a nullptr dereference when -combiners is given a name that isn't defined

Daniel Sanders via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 2 16:03:21 PDT 2019


Author: dsanders
Date: Wed Oct  2 16:03:21 2019
New Revision: 373543

URL: http://llvm.org/viewvc/llvm-project?rev=373543&view=rev
Log:
[gicombiner] Fix a nullptr dereference when -combiners is given a name that isn't defined

This is unlikely to be the root cause for the windows bot failures but
it would explain the stack trace seen.

Modified:
    llvm/trunk/utils/TableGen/GICombinerEmitter.cpp

Modified: llvm/trunk/utils/TableGen/GICombinerEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/GICombinerEmitter.cpp?rev=373543&r1=373542&r2=373543&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/GICombinerEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/GICombinerEmitter.cpp Wed Oct  2 16:03:21 2019
@@ -31,7 +31,8 @@ class GICombinerEmitter {
   StringRef Name;
   Record *Combiner;
 public:
-  explicit GICombinerEmitter(RecordKeeper &RK, StringRef Name);
+  explicit GICombinerEmitter(RecordKeeper &RK, StringRef Name,
+                             Record *Combiner);
   ~GICombinerEmitter() {}
 
   StringRef getClassName() const {
@@ -41,8 +42,9 @@ public:
 
 };
 
-GICombinerEmitter::GICombinerEmitter(RecordKeeper &RK, StringRef Name)
-    : Name(Name), Combiner(RK.getDef(Name)) {}
+GICombinerEmitter::GICombinerEmitter(RecordKeeper &RK, StringRef Name,
+                                     Record *Combiner)
+    : Name(Name), Combiner(Combiner) {}
 
 void GICombinerEmitter::run(raw_ostream &OS) {
   NamedRegionTimer T("Emit", "Time spent emitting the combiner",
@@ -87,8 +89,12 @@ void EmitGICombiner(RecordKeeper &RK, ra
 
   if (SelectedCombiners.empty())
     PrintFatalError("No combiners selected with -combiners");
-  for (const auto &Combiner : SelectedCombiners)
-    GICombinerEmitter(RK, Combiner).run(OS);
+  for (const auto &Combiner : SelectedCombiners) {
+    Record *CombinerDef = RK.getDef(Combiner);
+    if (!CombinerDef)
+      PrintFatalError("Could not find " + Combiner);
+    GICombinerEmitter(RK, Combiner, CombinerDef).run(OS);
+  }
 }
 
 } // namespace llvm




More information about the llvm-commits mailing list