[clang] [Parser][BoundsSafety] Print attribute as macro if it's system defined (PR #107619)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 20 09:21:40 PDT 2024


================
@@ -1105,16 +1120,16 @@ enum AttributeDeclKind {
 
 inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
                                              const ParsedAttr &At) {
-  DB.AddTaggedVal(reinterpret_cast<uint64_t>(At.getAttrName()),
+  const IdentifierInfo *AttrName =
+      At.printAsMacro() ? At.getMacroIdentifier() : At.getAttrName();
+  DB.AddTaggedVal(reinterpret_cast<uint64_t>(AttrName),
----------------
AaronBallman wrote:

I don't feel super comfortable deciding that system headers should drop detailed information in the diagnostic by virtue of being a system header. On the one hand, system headers often have a pile of implementation details and so I get it. On the other hand, the point to the diagnostic is to help the developer understand what they did wrong so they can fix it. I suspect any web search for `__counted_by` (macro name) will also return results for `__counted_by` (attribute name) and so the mapping won't cause problems in your use case. But `WINAPI` doesn't immediately help the user to know it means `__stdcall` and finding that through a web search isn't as straightforward, as an example.

https://github.com/llvm/llvm-project/pull/107619


More information about the cfe-commits mailing list