<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/83689>83689</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang-format `BreakAfterAttributes: Always` should apply to `__attribute__` too
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-format
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
jart
</td>
</tr>
</table>
<pre>
clang-format behaves unpleasantly when functions use `__attribute__((__foo__))`. Let's assume I'm using:
```
BasedOnStyle: LLVM
ColumnLimit: 60
```
If I write a normal looking function, then clang-format does the right thing:
```c
static void Die(const char *thing, const char *reason) {
tinyprint(2, thing, ": ", reason, "\n", NULL);
exit(1);
}
```
But if I add an `__attribute__` then it changes to using a style more like Mozilla and BSD where the type is placed on its own line:
```c
__attribute__((__noreturn__)) static void
Die(const char *thing, const char *reason) {
tinyprint(2, thing, ": ", reason, "\n", NULL);
exit(1);
}
```
Here's what I expected to happen:
```c
__attribute__((__noreturn__))
static void Die(const char *thing, const char *reason) {
tinyprint(2, thing, ": ", reason, "\n", NULL);
exit(1);
}
```
There's no way to get the above style as far as I can tell. I've tried adding a `//` after the attribute to force a line break. But then I get:
```c
__attribute__((__noreturn__)) //
static void
Die(const char *thing, const char *reason) {
tinyprint(2, thing, ": ", reason, "\n", NULL);
exit(1);
}
```
The style clang-format chooses gets even funkier if I try to define macros for complicated `__attribute__` features, like target clones.
```c
__target_clones("arch=znver4,"
"arch=znver3,"
"arch=sapphirerapids,"
"arch=alderlake,"
"arch=rocketlake,"
"arch=cooperlake,"
"arch=tigerlake,"
"arch=cascadelake,"
"arch=skylake-avx512,"
"arch=skylake,"
"arch=znver1,"
"arch=tremont,"
"fma,"
"avx")
__attribute__((__optimize__(
"-O3,-ffast-math"))) static void Die(const char
*thing,
const char
*reason) {
tinyprint(2, thing, ": ", reason, "\n", NULL);
exit(1);
}
```
I would like it very much if `clang-format` could handle `__attribute__` with more grace. The only workaround I've found is to define them separately from the function declaration, e.g. `#define NOINLINE __attribute__((__noinline__))` but it'd be nice if I could attach them directly to functions.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcV02P4jgT_jXhUgIFB2g4cOhu3taLxPQcZnevqOJUiAfHjmwHmvn1q4pDfzK9PaM5zC6KiGxXPbie-gS9VztDtEymN8l0NcA2VNYtv6ILg9wWp6XUaHbD0roaA-RU4YE8tKbRhB5N0Cc4VmSgbI0MyhoPrSdIZul2iyE4lbeBtttEzBMx325La3mx4GeWjmBDIRFXHtD7tiZYJ-KqhtYrs0uy6yRdJen5e5b2T7e8QU_FZ_MlnDQl2TVsNn99iie3Vre12ahaBT44K7zSj9_rEtZwdCoQIBi2UIO2dq_M7tGeRNxCYANf8FBY8rwNTu2qAKF658Yyrn3AoCQcrCpgpSgRc2mNDyArdJCI64ghbuHltiP0fIsFJFc3EQkAIChzapwyIRFzEe_YqydCsOH8ErdwVo_701vT79__udmwE7IzJj0oxho_30yuVu-wd9MGUMwgFgWgeevzWRqZU501ZseU2ehdQPDsO6itI9BqT_DJflNaI6Ap4ObLiqPKUcdxODUEykOjUVIBlhE92KMBrQz9A-0Xw9BYR6F15hyL8Mw5Ue0_4aH_k6MuvY4VBlgDPTQkAxXshgqbhsyvIO9fEd4AP8HfH9WZQGPhiCfmbUehC0rM7YH6IEYPJTp-rUGigUBaj7pidiAITlHBORLDnn9C3PEzSwHLQC7CnXnm3yitk1ySOLwhd4T7EXC2ddm05iv8kqDv7_Hafb9tAvysD3svvSjgsrLWk2cuPdAhNrC9IhdLWnCdswsq2QU1Smc9uwWkrRutJHIWXSp4JWFoHXk2oCtrAR2HjNTWkB-977Qou42yndsEOlkl2eqbOZCbJOKWuYlsvDrMXhy--jzJemyaSjly2KjCfwcQdUFO454-hums3FN4I_8kIK1tfgQwqN0F8Wd46CUW9HFAvz-x8BAPD9Ox-A5qL_QxxI7z8XeQgqPacty_i1TW-Eb_8NAF_-JJ6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