-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[clang++ ][crash-on-valid] crash on C-style array creation #112189
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
Comments
@llvm/issue-subscribers-clang-codegen Author: Tommaso Bonvicini (MuAlphaOmegaEpsilon)
The following C++ code crashes clang in versions 17, 18 and 19.
I think it's a regression from version 16, where it was compiling and running fine.
The issue has to do with the added template argument and the fact that 2 different template instantiations are performed: commenting either `foo<0>()` or `foo<1>()` will compile fine.
template<unsigned int EXTRA_SPACE>
void foo() { char buffer[sizeof("foo") + EXTRA_SPACE] {"foo"}; }
int main()
{
foo<0>();
foo<1>();
} GCC and MSVC compile and run fine. This is the output from the example on godbolt.org:
|
If we change this to: https://godbolt.org/z/3ne4K13Wj foo<10>();
foo<1>(); The diagnostic is intriguing: <source>:2:56: error: initializer-string for char array is too long, array size is 5 but initializer has size 14 (including the null terminating character)
2 | void foo() { char buffer[sizeof("foo") + EXTRA_SPACE] {"foo"}; }
| ^~~~~
<source>:6:5: note: in instantiation of function template specialization 'foo<1U>' requested here
6 | foo<1>();
| ^
1 error generated.
Compiler returned: 1 |
@shafik yeah I know, I stumbled upon that first during my experiments, then I got the crash when trying to shrink those down for the bug report and decided to post the latter due to the added stack trace. If you change the EXTRA_SPACE you will see the diagnostic reported size change too! |
I've looked into this, seems the things are borked from the very inception (clang 3.8). Strangely, https://godbolt.org/z/hr6hvqz38 wants clang 6.0.0 to compile this (and barf on too long initializer), on my Windows desktop 3.8 is enough. |
The following C++ code crashes clang in versions 17, 18 and 19.
I think it's a regression from version 16, where it was compiling and running fine.
The issue has to do with the added template argument and the fact that 2 different template instantiations are performed: commenting either
foo<0>()
orfoo<1>()
will compile fine.GCC and MSVC compile and run fine.
This is the output from the example on godbolt.org:
The text was updated successfully, but these errors were encountered: