[PATCH] D159362: [clang][AST][DeclPrinter] Change "__attribute__" AST printing location for the sake of GCC compatibility.

Mateusz Stachyra via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 1 08:48:55 PDT 2023


mstachyraa created this revision.
Herald added a project: All.
mstachyraa requested review of this revision.
Herald added a subscriber: wangpc.
Herald added a project: clang.

When printing C representation of AST, clang puts the "__attribute__" elements after the name of printed function.
In order for the generated code to be GCC compatible, these attributes should be put at the beginning of function.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159362

Files:
  clang/lib/AST/DeclPrinter.cpp


Index: clang/lib/AST/DeclPrinter.cpp
===================================================================
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -612,6 +612,8 @@
          I < NumTemplateParams; ++I)
       printTemplateParameters(D->getTemplateParameterList(I));
   }
+  
+  prettyPrintAttributes(D);
 
   CXXConstructorDecl *CDecl = dyn_cast<CXXConstructorDecl>(D);
   CXXConversionDecl *ConversionDecl = dyn_cast<CXXConversionDecl>(D);
@@ -774,8 +776,6 @@
     Ty.print(Out, Policy, Proto);
   }
 
-  prettyPrintAttributes(D);
-
   if (D->isPure())
     Out << " = 0";
   else if (D->isDeletedAsWritten())


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D159362.555395.patch
Type: text/x-patch
Size: 640 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230901/c69cc8d4/attachment.bin>


More information about the cfe-commits mailing list