[PATCH] D149272: [clang] Call printName to get name of Decl

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 27 06:43:02 PDT 2023


aaron.ballman added inline comments.


================
Comment at: clang/lib/AST/DeclarationName.cpp:119-125
   if (const RecordType *ClassRec = ClassType->getAs<RecordType>()) {
-    OS << *ClassRec->getDecl();
+    ClassRec->getDecl()->printName(OS, Policy);
     return;
   }
   if (Policy.SuppressTemplateArgsInCXXConstructors) {
     if (auto *InjTy = ClassType->getAs<InjectedClassNameType>()) {
+      InjTy->getDecl()->printName(OS, Policy);
----------------
dankm wrote:
> aaron.ballman wrote:
> > This isn't the right way to go about this -- the diagnostic engine knows how to print a `NamedDecl` when given one, and that's what should be fixed. (We pass in a `NamedDecl` all over the place -- it's preferred to passing in a string.)
> > 
> > https://github.com/llvm/llvm-project/blob/b893368fd4fdf40b7778df8d0b17312def1a8156/clang/lib/AST/ASTDiagnostic.cpp#L460 is one place where that happens, and https://github.com/llvm/llvm-project/blob/b893368fd4fdf40b7778df8d0b17312def1a8156/clang/lib/Basic/Diagnostic.cpp#L1060 is another, so I'd start investigating from there.
> Maybe I could have been more clear in my description of the problem; it's not diagnostics. It's naming in the output. With -ffile-prefix-map in use and without this change I see this:
> 
> ```
> % strings lib/x86_64-dankm-freebsd13.2/libc++.so.1.0|grep barrier.cpp
> std::__1::__barrier_algorithm_base::__state_t::(unnamed struct at /home/dan/llvm/llvm-wip/libcxx/src/barrier.cpp:24:9)
> ```
> 
> when I expect (and get with this change):
> 
> ```
> % strings lib/x86_64-dankm-freebsd13.2/libc++.so.1.0|grep barrier.cpp
> std::__1::__barrier_algorithm_base::__state_t::(unnamed struct at /llvm-root/libcxx/src/barrier.cpp:24:9)
> ```
> 
> It looks like every other call in the DeclarationName::print function preserves the policy, these weren't. As far as I can tell, this is the only place this is used.
Ah, thank you for the explanation, now I see what's going on.


================
Comment at: clang/test/CodeGen/debug-prefix-map.cpp:1
+// RUN: %clang++ -g -fdebug-prefix-map=%p=./UNLIKELY_PATH/empty -S -c %s -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-REL
+
----------------
I'm taking a guess at correcting the RUN line here, but more tweaks may be needed. Basically, `%clang++` isn't a thing, so this test fails. Most of our tests should be testing `%clang_cc1` to test the frontend invocation, but some of the debug prefix map tests use `%clang` to test the driver functionality. I don't think there's a need to test the driver here, so I went with `%clang_cc1`. I'm not 100% certain whether `-debug-info-kind=` is necessary or not, but the other tests seem to be using that, which may be worth paying attention to.

Finally, there's no need to have a custom check prefix for `FileCheck`, the builtin `CHECK` prefix suffices.


================
Comment at: clang/test/CodeGen/debug-prefix-map.cpp:11
+
+// CHECK-REL: !DISubprogram(name: "(unnamed struct at ./UNLIKELY_PATH/empty{{/|\\\\}}{{.*}}",
----------------



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149272



More information about the cfe-commits mailing list