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

Giuliano Belinassi via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 9 07:05:13 PDT 2025


giulianobelinassi 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.

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


More information about the cfe-commits mailing list