[PATCH] D157470: [NFC]Add assert to avoid deref nullptr

Pierre van Houtryve via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 9 00:17:30 PDT 2023


Pierre-vh accepted this revision.
Pierre-vh added a comment.
This revision is now accepted and ready to land.

Thanks for the fix! It's good to commit as-is if you want a quick fix, but the version I propose is the best possible user experience.
Note it's all going away in D156315 <https://reviews.llvm.org/D156315> anyway.



================
Comment at: llvm/utils/TableGen/GlobalISelCombinerMatchTableEmitter.cpp:970-973
   const StringInit *Code = dyn_cast<StringInit>(Apply.getArg(0));
+  assert(Code && "Expected 1 StringInit argument in 'apply'");
   auto Pat = std::make_unique<CXXPattern>(*Code, makeAnonPatName("apply"),
                                           /*IsApply*/ true);
----------------
Ideally do this, otherwise just change the `dyn_cast` to a `cast` and it'll just assert if it's the wrong type.



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157470/new/

https://reviews.llvm.org/D157470



More information about the llvm-commits mailing list