Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang-format 18 idempotent regression with #define within an initializer #86550

Closed
JohnC32 opened this issue Mar 25, 2024 · 1 comment · Fixed by #87953
Closed

clang-format 18 idempotent regression with #define within an initializer #86550

JohnC32 opened this issue Mar 25, 2024 · 1 comment · Fixed by #87953

Comments

@JohnC32
Copy link

JohnC32 commented Mar 25, 2024

Running clang-format 18 twice produces different results when we have #define statements within an initializer. Running with clang-format 17.0.5 shows no difference on repeated invocations.

Given idempotent_define.cpp

int foo(MyType aFooSizeKind) {
    static const AType0123456789 table{
#define FOO_SIZE_KIND_2_OP_ROW(row) {GET_SYM_SIZE_KIND(row), GET_OP(row)}

        COMMA_LIST_OF(FOO_SIZE_KIND_2_OP_ROW, FOOBAR12_BINOP_SIZE_LIST),
        COMMA_LIST_OF(FOO_SIZE_KIND_2_OP_ROW, FOOBAR12_UNARY_SIZE_LIST)};

    return table.at(aFooSizeKind);
}

using _clang-format:

---
BasedOnStyle: Google
IndentWidth: 4
ColumnLimit: 100
...

clang-format 18.1.1 yields the following differences on successive runs. Notice that define flips between being on a single line and multiple lines.

/path/to/llvm-18.1.1/bin/clang-format -style=file idempotent_define.cpp >out.18.1.1.a.cpp 2>&1
/path/to/llvm-18.1.1/bin/clang-format -style=file out.18.1.1.a.cpp >out.18.1.1.b.cpp 2>&1
/path/to/llvm-18.1.1/bin/clang-format -style=file out.18.1.1.b.cpp >out.18.1.1.c.cpp 2>&1
diff -u out.18.1.1.a.cpp out.18.1.1.b.cpp
--- out.18.1.1.a.cpp	2024-03-25 14:02:26.681362489 -0400
+++ out.18.1.1.b.cpp	2024-03-25 14:02:26.697362606 -0400
@@ -1,7 +1,6 @@
 int foo(MyType aFooSizeKind) {
     static const AType0123456789 table{
-#define FOO_SIZE_KIND_2_OP_ROW(row) \
-    { GET_SYM_SIZE_KIND(row), GET_OP(row) }
+#define FOO_SIZE_KIND_2_OP_ROW(row) {GET_SYM_SIZE_KIND(row), GET_OP(row)}
 
         COMMA_LIST_OF(FOO_SIZE_KIND_2_OP_ROW, FOOBAR12_BINOP_SIZE_LIST),
         COMMA_LIST_OF(FOO_SIZE_KIND_2_OP_ROW, FOOBAR12_UNARY_SIZE_LIST)};

diff -u out.18.1.1.b.cpp out.18.1.1.c.cpp
--- out.18.1.1.b.cpp	2024-03-25 14:02:26.697362606 -0400
+++ out.18.1.1.c.cpp	2024-03-25 14:02:26.715362737 -0400
@@ -1,6 +1,7 @@
 int foo(MyType aFooSizeKind) {
     static const AType0123456789 table{
-#define FOO_SIZE_KIND_2_OP_ROW(row) {GET_SYM_SIZE_KIND(row), GET_OP(row)}
+#define FOO_SIZE_KIND_2_OP_ROW(row) \
+    { GET_SYM_SIZE_KIND(row), GET_OP(row) }
 
         COMMA_LIST_OF(FOO_SIZE_KIND_2_OP_ROW, FOOBAR12_BINOP_SIZE_LIST),
         COMMA_LIST_OF(FOO_SIZE_KIND_2_OP_ROW, FOOBAR12_UNARY_SIZE_LIST)};

diff -u out.18.1.1.a.cpp out.18.1.1.c.cpp
@owenca
Copy link
Contributor

owenca commented Mar 28, 2024

Bisected to 063e3fe. @rymiel

@owenca owenca self-assigned this Apr 6, 2024
owenca added a commit to owenca/llvm-project that referenced this issue Apr 8, 2024
Also fix unit tests and reformat polly.

Fixes llvm#86550.
@owenca owenca added this to the LLVM 18.X Release milestone Apr 8, 2024
owenca added a commit that referenced this issue Apr 10, 2024
Also fix unit tests and reformat polly.

Fixes #86550.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging a pull request may close this issue.

3 participants