[PATCH] D144006: [DebugMetadata][DwarfDebug] Support function-local types in lexical block scopes (5/7)

David Blaikie via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 20 17:49:05 PDT 2023


dblaikie added inline comments.


================
Comment at: llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp:712-714
+      assert(!getAbstractScopeDIEs().count(DS) &&
+             "Abstract DIE for this scope exists!");
+      getAbstractScopeDIEs()[DS] = ScopeDIE;
----------------
jmmartinez wrote:
> krisb wrote:
> > jmmartinez wrote:
> > > NIT: You could use `insert/try_emplace` instead of using `count` and `operator[]`. The assertion would become something like:
> > > ```
> > > auto Inserted = getAbstractScopeDIEs().try_emplace(DS, ScopeDIE);
> > > assert(Inserted.second && "Abstract DIE for this scope exists!");
> > > return ScopeDIE;
> > > ```
> > I'd slightly prefer to keep the original code as it looks a bit more readable to me (in your example, there should be another line to void out unused `Inserted` variable, otherwise it'd cause a warning). 
> > Additional `count()` call in the `assert()` doesn't seem too expensive to me, but if you still think `try_emplace()` is better, I'll change to it.
> Ok for me. If the use of count was outside the assert I would have argued against.
FWIW I'd lean towards avoiding the extra lookup in the +Asserts build (by using emplace or try_emplace, etc - yeah, with the extra void cast for the non-asserts-unused variable), but wouldn't insist on it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144006



More information about the cfe-commits mailing list