[clang] Sort attributes according to source position before printing (PR #162556)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 9 07:18:28 PDT 2025


erichkeane wrote:

> @erichkeane So, looking why the `asm` attribute is written after the visibility attribute, I see on
> 
> https://github.com/llvm/llvm-project/blob/92266681bfc89b71d1846b68da296186cd8bfbec/clang/lib/Sema/SemaDecl.cpp#L8128
> :
> 
> ```
>   ProcessDeclAttributes(S, NewVD, D);
> ```
> 
> which creates the VisibilityAttr. Then later on
> 
> https://github.com/llvm/llvm-project/blob/92266681bfc89b71d1846b68da296186cd8bfbec/clang/lib/Sema/SemaDecl.cpp#L8223
> 
> ```
> if (Expr *E = D.getAsmLabel()) {
>     <...>
>     NewVD->addAttr(AsmLabelAttr::Create(Context, Label, SE->getStrTokenLoc(0)));
> }
> ```
> 
> Which then creates the `asm` attribute. Hence the ASM attribute is created after visibility attributes at least. The question now is which attributes can be placed before an `asm` attribute which may resulted in this code layout.

Ah, whew, so it IS just a handful that are inserted incorrectly!  That is good to know.  The `AsmLabelAttr` being a 'special' thing there is a little frustrating... however, does its order ever matter?  I wouldn't expect so?  So it at least shouldn't cause any problems, right? 

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


More information about the cfe-commits mailing list