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] A space is missing after a word token #92688

Closed
heiher opened this issue May 19, 2024 · 5 comments · Fixed by #92880
Closed

[clang-format] A space is missing after a word token #92688

heiher opened this issue May 19, 2024 · 5 comments · Fixed by #92880
Assignees

Comments

@heiher
Copy link
Member

heiher commented May 19, 2024

A space is missing after xor in the following case with the PR #90161.

Expected formatting:

void test(void) {
  static void (*xor)(uint8_t *, size_t, uint8_t);
  xor = resolve_xor_x86();
}

Actual formatting:

 void test(void) {
  static void (*xor)(uint8_t *, size_t, uint8_t);
  xor= resolve_xor_x86();
}
@heiher heiher added clang-format invalid-code-generation Tool (e.g. clang-format) produced invalid code that no longer compiles labels May 19, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented May 19, 2024

@llvm/issue-subscribers-clang-format

Author: hev (heiher)

A space is missing after `xor` in the following case with the PR https://github.com//pull/90161.

Expected formatting:

void test(void) {
  static void (*xor)(uint8_t *, size_t, uint8_t);
  xor = resolve_xor_x86();
}

Actual formatting:

 void test(void) {
  static void (*xor)(uint8_t *, size_t, uint8_t);
  xor= resolve_xor_x86();
}

@owenca owenca removed the invalid-code-generation Tool (e.g. clang-format) produced invalid code that no longer compiles label May 19, 2024
@owenca owenca self-assigned this May 20, 2024
@robincaloudis
Copy link
Contributor

As xor is a keyword, it cannot be used as a name. Must the correct formatting of the code in Clang be guaranteed, even if the code is not valid? If the function name gets changed from xor to valid_func_name, Clang formats the code correctly.

Actual and expected formatting:

void test(void) {
  static void (*valid_func_name)(uint8_t *, size_t, uint8_t);
  valid_func_name = resolve_xor_x86();
}

@robincaloudis
Copy link
Contributor

As xor is a keyword, it cannot be used as a name. Must the correct formatting of the code in Clang be guaranteed, even if the code is not valid? If the function name gets changed from xor to valid_func_name, Clang formats the code correctly.

Actual and expected formatting:

void test(void) {
  static void (*valid_func_name)(uint8_t *, size_t, uint8_t);
  valid_func_name = resolve_xor_x86();
}

I forgot that there is also the pure C world, where xor can be used as a valid function name.

@robincaloudis
Copy link
Contributor

robincaloudis commented May 20, 2024

Hi @owenca, stumbled across the problem myself and opened a draft as a starting point. I'm not sure how far you've gotten. Feel free to participate or discard if you have a better solution. I left some questions in the PR as some things are still not clear to me.

@owenca
Copy link
Contributor

owenca commented May 21, 2024

@robincaloudis see #92741 (comment).

owenca added a commit to owenca/llvm-project that referenced this issue May 21, 2024
PR llvm#90161 uncovered a bug that annotates C++ xor as UnaryOperator if
followed by a binary operator. This patch fixes that and all other C++
alternative operator keywords when followed by a binary operator in C.

Fixes llvm#92688.
owenca added a commit that referenced this issue May 22, 2024
)

PR #90161 uncovered a bug that annotates C++ xor as UnaryOperator if
followed by a binary operator. This patch fixes that and all other C++
alternative operator keywords when followed by a binary operator in C.

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