Szelethus added inline comments.

================
Comment at: clang/lib/StaticAnalyzer/Core/CheckerHelpers.cpp:114-117
+  const auto MacroIt = llvm::find_if(
+      PP.macros(), [&](const auto &K) { return K.first->getName() == Macro; });
+  if (MacroIt == PP.macro_end())
+    return llvm::None;
----------------
NoQ wrote:
> martong wrote:
> > Szelethus wrote:
> > > This seems a bit clunky even for the `Preprocessor` -- how about
> > > 
> > > ```lang=c++
> > > const auto *MacroII = PP.getIdentifierInfo(Macro);
> > > if (!MacroII)
> > >   return;
> > > const MacroInfo *MI = PP.getMacroInfo(MacroII);
> > > assert(MI);
> > > ```
> > Ok, but we cannot assert on `MI`, because there may be cases when the macro 
> > is not defined in a TU. In that case we should just return with None.
> What exactly happens when the macro is `#undef`-ined and redefined? We get 
> the last redefinition that's valid at the end of the translation unit, right? 
> Can we check whether there are multiple definitions and guard against that?
Ugh, now that you say it that is a valid concern. I had to deal with that back 
in the day: https://reviews.llvm.org/D52794?id=171962#inline-476352


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74473



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to