From fb64fe5ff81f53cc82c98e1f7f5a7f98fd9532d4 Mon Sep 17 00:00:00 2001 From: Daniel Sanders Date: Wed, 2 Oct 2019 23:03:21 +0000 Subject: [PATCH] [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. llvm-svn: 373543 --- utils/TableGen/GICombinerEmitter.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/utils/TableGen/GICombinerEmitter.cpp b/utils/TableGen/GICombinerEmitter.cpp index 7a9c87b6b93..a85462b5aa8 100644 --- a/utils/TableGen/GICombinerEmitter.cpp +++ b/utils/TableGen/GICombinerEmitter.cpp @@ -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, raw_ostream &OS) { 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