| Issue |
83689
|
| Summary |
clang-format `BreakAfterAttributes: Always` should apply to `__attribute__` too
|
| Labels |
clang-format
|
| Assignees |
|
| Reporter |
jart
|
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.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs