jump into statement expression in unevaluated context
The C program
int main(void) {
goto L;
sizeof (int){({ L:; 1; })};
return 0;
}
makes Clang crash
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
[...]
clang-12: error: unable to execute command: Segmentation fault (core dumped)
clang-12: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 12.0.0 (https://github.com/llvm/llvm-project.git d28af7c654d8db0b68c175db5ce212d74fb5e9bc)
Target: x86_64-unknown-linux-gnu
Thread model: posix
Still happens in trunk: https://godbolt.org/z/qnxq9a3WP
@llvm/issue-subscribers-clang-frontend
Still problem in main: https://godbolt.org/z/MP3v77vPP
I feel like we should diagnose this like this case:
void f() {
label:
{}
}
void g() {
goto label;
}
but looking at how err_undeclared_label_use is handled for this case it is not obvious.
@shafik agreed, we are probably not supposed to jump contexts!
gcc produces "error: jump into statement expression". We probably want something similar. (I think we need to continue support jumping out of statement expressions, i.e. a goto inside a statement expression with a label outside it.)
https://reviews.llvm.org/D154696
Note that this is technically a breaking change. I wonder if anyone cares about jumping into expression statements though (it's not supported by GCC)
I had to revert.
The issue is that VerifyIndirectOrAsmJumps does not consider that labels may be local labels at all, I'm not exactly sure how to improve that.
The fact it works currently seems kind of brittle, what prevent incorrect jumps to be ill-formed is that we looked if a label is defined in the same scope as the __local__ label introduction, but for the purpose of checking jumps __local__ labels are not considered at all, it also fail in other cases, for example using try blocks or any kind of blocks https://compiler-explorer.com/z/Mrxonn9dc
@jyu2-git any idea?
I had to revert.
The issue is that
VerifyIndirectOrAsmJumpsdoes not consider that labels may be local labels at all, I'm not exactly sure how to improve that. The fact it works currently seems kind of brittle, what prevent incorrect jumps to be ill-formed is that we looked if a label is defined in the same scope as the__local__label introduction, but for the purpose of checking jumps__local__labels are not considered at all, it also fail in other cases, for example using try blocks or any kind of blocks https://compiler-explorer.com/z/Mrxonn9dc@jyu2-git any idea?
Sorry I don't really remember this. It looks like the problem related to ScopeChecking with HasBranchProtectedScope.
The problem seems to be the targets is not asm_goto's label. The error message is wrong. I think the check only needed if the asm_goto's label == taregetLabel. I will fix this.