-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang] Use the materialized temporary's type while creating the APValue #73355
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
See llvm#72025 for the bug and its diagnosis.
@llvm/pr-subscribers-clang Author: Younan Zhang (zyn0217) ChangesSee #72025 for the bug and its diagnosis. Full diff: https://github.com/llvm/llvm-project/pull/73355.diff 3 Files Affected:
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 74358219ba9fb22..d434d016907f815 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -691,6 +691,9 @@ Bug Fixes to C++ Support
Fixes:
(`#68769 <https://github.com/llvm/llvm-project/issues/68769>`_)
+- Fixed a crash for C++98/03 while checking an ill-formed ``_Static_assert`` expression.
+ Fixes: (`#72025 <https://github.com/llvm/llvm-project/issues/72025>`_)
+
- Clang now defers the instantiation of explicit specifier until constraint checking
completes (except deduction guides). Fixes:
(`#59827 <https://github.com/llvm/llvm-project/issues/59827>`_)
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index e16fec6109e744e..6c6ad12119d13c3 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -8607,7 +8607,7 @@ bool LValueExprEvaluator::VisitMaterializeTemporaryExpr(
Result.set(E);
} else {
Value = &Info.CurrentCall->createTemporary(
- E, E->getType(),
+ E, Inner->getType(),
E->getStorageDuration() == SD_FullExpression ? ScopeKind::FullExpression
: ScopeKind::Block,
Result);
diff --git a/clang/test/SemaCXX/pr72025.cpp b/clang/test/SemaCXX/pr72025.cpp
new file mode 100644
index 000000000000000..9f0a4b0f43630c5
--- /dev/null
+++ b/clang/test/SemaCXX/pr72025.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -verify -std=c++03 -fsyntax-only %s
+struct V {
+ char c[2];
+ banana V() : c("i") {} // expected-error {{unknown type name}}
+ // expected-error@-1 {{constructor cannot have a return type}}
+};
+
+_Static_assert(V().c[0], ""); // expected-error {{is not an integral constant expression}}
+
|
You can test this locally with the following command:git-clang-format --diff d896b1f5a614daef1c3aa65cb3521ec82bc728d5 3ff1b189cf55d3705b2823dc39eaaf710fa26541 -- clang/test/SemaCXX/pr72025.cpp clang/lib/AST/ExprConstant.cpp View the diff from clang-format here.diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 6c6ad12119..0650c91a8f 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -3185,8 +3185,8 @@ static bool HandleLValueIndirectMember(EvalInfo &Info, const Expr *E,
}
/// Get the size of the given type in char units.
-static bool HandleSizeof(EvalInfo &Info, SourceLocation Loc,
- QualType Type, CharUnits &Size) {
+static bool HandleSizeof(EvalInfo &Info, SourceLocation Loc, QualType Type,
+ CharUnits &Size) {
// sizeof(void), __alignof__(void), sizeof(function) = 1 as a gcc
// extension.
if (Type->isVoidType() || Type->isFunctionType()) {
@@ -11516,8 +11516,8 @@ enum class GCCTypeClass {
/// EvaluateBuiltinClassifyType - Evaluate __builtin_classify_type the same way
/// as GCC.
-static GCCTypeClass
-EvaluateBuiltinClassifyType(QualType T, const LangOptions &LangOpts) {
+static GCCTypeClass EvaluateBuiltinClassifyType(QualType T,
+ const LangOptions &LangOpts) {
assert(!T->isDependentType() && "unexpected dependent type");
QualType CanTy = T.getCanonicalType();
|
Ping. And invited @cor3ntin to kindly take a look at this. |
The code-formatter failed on other unrelated lines, so I think I'd better not to touch them. |
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 -- thank you for the detailed analysis in the issue and fix!
See #72025 for the bug and its diagnosis.