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

Dan McGregor via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 26 13:35:43 PDT 2023


dankm 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);
----------------
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.


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