-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[clang] Call ActOnCaseExpr even if the 'case' is missing #166326
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
Conversation
|
@llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) ChangesThis otherwise happens in ParseCaseExpression. Full diff: https://github.com/llvm/llvm-project/pull/166326.diff 2 Files Affected:
diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp
index 92038985f9163..47da1a5b7cdb0 100644
--- a/clang/lib/Parse/ParseStmt.cpp
+++ b/clang/lib/Parse/ParseStmt.cpp
@@ -813,8 +813,7 @@ StmtResult Parser::ParseCaseStatement(ParsedStmtContext StmtCtx,
return StmtError();
}
} else {
- LHS = Expr;
- MissingCase = false;
+ LHS = Actions.ActOnCaseExpr(CaseLoc, Expr);
}
// GNU case range extension.
diff --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp b/clang/test/SemaCXX/constant-expression-cxx11.cpp
index 91c4ff1cb520d..7e28ac560ed23 100644
--- a/clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -2661,3 +2661,9 @@ namespace GH154567 {
constexpr S s{};
static_assert(s.val.i == 0, "");
}
+
+constexpr bool missingCase() {
+ switch (1) {
+ 1u: return false; // expected-error {{expected 'case' keyword before expression}}
+ }
+}
|
This otherwise happens in ParseCaseExpression. If we don't call this, we don't perform the usual arithmetic conversions, etc.
99b35ea to
933eb33
Compare
|
|
||
| constexpr bool missingCase() { | ||
| switch (1) { | ||
| 1u: return false; // expected-error {{expected 'case' keyword before expression}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit confused; we already emit this diagnostic today without your changes: https://godbolt.org/z/4379s9zGf
You mention this is about getting the usual conversions to happen, but those only need to happen for well-formed code, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not about the diagnostic, it's about clang crashing in constant evaluation because the type of the case stmt expression is wrong: #165555 (the second example further down).
I don't know if the conversions only need to happen for well-formed code or not. If not, we should instead mark the case stmt as having errors I guess, but just letting it through like that trips up a couple of places
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see now that my godbolt link does show the issue with an asserts build, that makes more sense now. Thank you!
AaronBallman
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/59/builds/26827 Here is the relevant piece of the build log for the reference |
This otherwise happens in ParseCaseExpression.
If we don't call this, we don't perform the usual arithmetic conversions, etc.