Open MuAlphaOmegaEpsilon opened 6 days ago
@llvm/issue-subscribers-clang-codegen
Author: Tommaso Bonvicini (MuAlphaOmegaEpsilon)
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!
@awson does this PR fix this: https://github.com/llvm/llvm-project/pull/96464
@awson does this PR fix this: #96464
Unfortunately, no. Absolutely no difference — the same crash, the same diagnostics.
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
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: