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] Cannot recognize multiplication semantic of * #99271

Closed
chestnykh opened this issue Jul 17, 2024 · 3 comments · Fixed by #99433 or #107074
Closed

[clang-format] Cannot recognize multiplication semantic of * #99271

chestnykh opened this issue Jul 17, 2024 · 3 comments · Fixed by #99433 or #107074
Assignees

Comments

@chestnykh
Copy link
Contributor

chestnykh commented Jul 17, 2024

Consider the following sample

enum X {
        two = 2
};

#define FN(N) \
void fn(void *addr) \
{ \
        __builtin_memset(addr, 0, N * two); \
} \

FN(4)

And .clang-format containing just BasedOnStyle: LLVM

Then we get the output where clang-format made a 'pointer of type N' instead of multiplication:

#define FN(N)                                                                  \
  void fn(void *addr) { __builtin_memset(addr, 0, N *two); }
chestnykh added a commit to chestnykh/llvm-project that referenced this issue Jul 17, 2024
clang-format cannot recognize that this is multiplication,
not pointer declaration.
See llvm#99271
chestnykh added a commit to chestnykh/llvm-project that referenced this issue Jul 17, 2024
clang-format cannot recognize that this is multiplication,
not pointer declaration.
See llvm#99271
chestnykh added a commit to chestnykh/llvm-project that referenced this issue Jul 17, 2024
clang-format cannot recognize that this is multiplication,
not pointer declaration.
See llvm#99271
@chestnykh
Copy link
Contributor Author

Reduced repro:
#define X M(a * b) -> #define X M(a *b)

@owenca owenca self-assigned this Jul 18, 2024
owenca added a commit to owenca/llvm-project that referenced this issue Jul 18, 2024
sgundapa pushed a commit to sgundapa/upstream_effort that referenced this issue Jul 23, 2024
chestnykh added a commit to chestnykh/llvm-project that referenced this issue Jul 24, 2024
clang-format cannot recognize that this is multiplication,
not pointer declaration.
See llvm#99271
@owenca
Copy link
Contributor

owenca commented Jul 25, 2024

Reverted by 7e7a906.

@owenca owenca reopened this Jul 25, 2024
owenca added a commit to owenca/llvm-project that referenced this issue Sep 3, 2024
A macro definition needs its own scope stack in the annotator, so we add the
MacroBodyScopes stack and use ScopeStack to refer to it when in the macro
definition body.

Also, we need to have a scope type for a child block because its parent line
is parsed (and thus the scope type for the braces is popped off the scope
stack) before the lines in the child block are.

Fixes llvm#99271.
@owenca
Copy link
Contributor

owenca commented Sep 3, 2024

Reduced repro: #define X M(a * b) -> #define X M(a *b)

That's intended. Instead, a min repro is e.g.:

#define X     \
  {           \
    M(a * b); \
  }

owenca added a commit that referenced this issue Sep 4, 2024
A macro definition needs its own scope stack in the annotator, so we add
the MacroBodyScopes stack and use ScopeStack to refer to it when in the
macro definition body.

Also, we need to have a scope type for a child block because its parent
line is parsed (and thus the scope type for the braces is popped off the
scope stack) before the lines in the child block are.

Fixes #99271.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants