-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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 front-end segmentation fault #112516
Comments
The initializer of the constexpr variable is invalid and later using the variable as an array index causes the assertion failure: https://godbolt.org/z/fG84TTxqx void *freelist_thread(void *arg) {
constexpr int num_elem_allocated = 1/0;
void *allocated_elems[num_elem_allocated];
} IIRC we had a case similar to this before but I don't know what bug number that would be. @Fznamznon? |
@llvm/issue-subscribers-clang-frontend Author: Orian (zmochi)
Clang front-end crashes with a segmentation fault while processing C code.
The offending line is a C23 I tried to reduce the preprocessed files with Output of clang command causing the crash: The actual source files are: I tried to reproduce a minimal example with the following input which did not crash: #define min(a, b) ((a) < (b) ? (a) : (b))
struct min_st {
int a;
};
void foo(struct min_st *st) {
constexpr int bad_constexpr = min(10, st->a);
} |
Do you mean #109095 ? It is a bit different but I suppose the reason might be the same. |
Further minimized I get: // clang -cc1 -triple arm64-- -S -std=c23 freelist_tests-min.c
struct freelist {
int array_len;
};
void __assert_rtn() {
struct freelist *list = 0;
constexpr int num_elem_allocated = list->array_len;
void *allocated_elems[num_elem_allocated];
for (int i = 1;;
__builtin_expect(allocated_elems[i] != 0, 1) ? __assert_rtn() : 1)
;
} And the stack trace:
|
Looks like a clang-19 regression: https://godbolt.org/z/os59PbPPY |
I confirm that the simple solution I described by #109095 (comment) works for this case too, so it is basically the same problem. Should I put it to review since this is now considered as a regression? |
Yeah, it would be nice to try to get this into 19.x as well, if the fix is sufficiently straightforward |
Before using a constexpr variable that is not properly initialized check that it is valid. Fixes llvm#109095 Fixes llvm#112516
Before using a constexpr variable that is not properly initialized check that it is valid. Fixes llvm#109095 Fixes llvm#112516
Before using a constexpr variable that is not properly initialized check that it is valid. Fixes llvm#109095 Fixes llvm#112516
Before using a constexpr variable that is not properly initialized check that it is valid. Fixes llvm#109095 Fixes llvm#112516
Before using a constexpr variable that is not properly initialized check that it is valid. Fixes llvm#109095 Fixes llvm#112516
Before using a constexpr variable that is not properly initialized check that it is valid. Fixes llvm#109095 Fixes llvm#112516
Before using a constexpr variable that is not properly initialized check that it is valid. Fixes llvm#109095 Fixes llvm#112516
Before using a constexpr variable that is not properly initialized check that it is valid. Fixes llvm#109095 Fixes llvm#112516
Clang front-end crashes with a segmentation fault while processing C code.
The offending line is a C23
constexpr
very similar to the minimal example I attempted to write below.I tried to reduce the preprocessed files with
creduce
and creduce-clang-crash.py as suggested in how to submit a bug but the script did not emit the listed files (I did notice the repository is deprecated but worth a shot). This is the output of the script. It seems likecreduce
itself crashed but I'm not sure.Output of clang command causing the crash:
clang-crash-output.txt
Crash report:
clang-19-2024-10-16-130218.ips.txt
Preprocessed source:
freelist_tests-4bf7f5.c.txt
Run script:
freelist_tests-4bf7f5.sh.txt
The actual source files are:
freelist.c.txt
freelist_tests.c.txt
freelist.h.txt
I tried to reproduce a minimal example with the following input which did not crash:
The text was updated successfully, but these errors were encountered: