-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
Using clang as CPP makes unexpected indentation changes #78778
Comments
@llvm/issue-subscribers-clang-frontend Author: Tom Rini (trini)
For background, over in [U-Boot](https://docs.u-boot.org/) we use the same "Kconfig" language as the Linux kernel, and so have a config file for a build that is defined with `CONFIG_FOO=y` and `# CONFIG_BAR is not set`. What we're doing now is allowing for a config file to `#include` another valid config file fragment, and using `$(CC) -E` to handle the include directive.
When using GCC, this works as expected and nothing about the files is changed. However, with clang-16 I've put an example of what I'm doing at: https://gist.github.com/trini/a9fec05a1010611f287661e58b17cbd0 which shows the trivial case. Using the starfive_visionfive2_defconfig file as non-trivial testcase shows that even with |
Hi @trini. I was able to reproduce the reported issue. I spent a few minutes looking at this, but was unable to quickly identify where the leading space character is coming from. Any chance that you are able to investigate further? Alternatively, you might consider use of a |
Sorry @tahonermann but I have no idea where to start on the llvm side of the issue. I can work around the issue, yes, but I do worry about other cases where cpp is (ab)used and white space matters. |
Having just hit a much larger example of the problem, I'm just checking in to see if looking further in to this is on anyones radar, it sounds like it's unfortunately not clear where the problem might be and so possibly a difficult fix? Thanks. |
The leading whitespace is added by this block:
It looks like that hack may need to be improved. |
That hack goes back to at least 2006. Git history stops at 22eb972. |
Yeah, I'm not saying this is a recent regression in llvm, to be clear. A long-standing but just now problematic for someone situation is reasonable. |
For ease of reference, here is the hack Aaron linked to:
I played around a bit and discovered the following interesting things.
The following demonstrates how gcc's behavior changes with the hack in place. Note that
The first define directive is ignored and In contrast, Clang processes both define directives as directives and performs macro expansion.
My conclusions:
|
I locally removed the hack and ran the Clang testsuite. The following tests failed:
The The |
For background, over in U-Boot we use the same "Kconfig" language as the Linux kernel, and so have a config file for a build that is defined with
CONFIG_FOO=y
and# CONFIG_BAR is not set
. What we're doing now is allowing for a config file to#include
another valid config file fragment, and using$(CC) -E
to handle the include directive.When using GCC, this works as expected and nothing about the files is changed. However, with clang-16
# CONFIG_FOO is not set
becomes# CONFIG_FOO is not set
, which is invalid for the Kconfig language. I can pass in-traditional-cpp
as another flag and in some cases this will keep the expected behavior, but in others, it does not.I've put an example of what I'm doing at: https://gist.github.com/trini/a9fec05a1010611f287661e58b17cbd0 which shows the trivial case. Using the starfive_visionfive2_defconfig file as non-trivial testcase shows that even with
-traditional-cpp
we still get some whitespace changes.The text was updated successfully, but these errors were encountered: