Skip to content
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

jump into statement expression in unevaluated context #63682

Closed
ChristopheSev opened this issue Jul 5, 2023 · 10 comments
Closed

jump into statement expression in unevaluated context #63682

ChristopheSev opened this issue Jul 5, 2023 · 10 comments
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party

Comments

@ChristopheSev
Copy link

ChristopheSev commented Jul 5, 2023

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
@tbaederr
Copy link
Contributor

tbaederr commented Jul 5, 2023

Still happens in trunk: https://godbolt.org/z/qnxq9a3WP

@tbaederr tbaederr added clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party and removed new issue labels Jul 5, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Jul 5, 2023

@llvm/issue-subscribers-clang-frontend

@EugeneZelenko
Copy link
Contributor

Still problem in main: https://godbolt.org/z/MP3v77vPP

@shafik
Copy link
Collaborator

shafik commented Jul 5, 2023

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.

@cor3ntin
Copy link
Contributor

cor3ntin commented Jul 6, 2023

@shafik agreed, we are probably not supposed to jump contexts!

@efriedma-quic
Copy link
Collaborator

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.)

@cor3ntin cor3ntin changed the title Bug report: Clang: jump into statement expression in unevaluated context jump into statement expression in unevaluated context Jul 7, 2023
@cor3ntin
Copy link
Contributor

cor3ntin commented Jul 7, 2023

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)

@cor3ntin cor3ntin reopened this Jul 12, 2023
@cor3ntin
Copy link
Contributor

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?

@jyu2-git
Copy link
Contributor

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?

Sorry I don't really remember this. It looks like the problem related to ScopeChecking with HasBranchProtectedScope.

@jyu2-git
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party
Projects
None yet
Development

No branches or pull requests

8 participants