[clang] 28ccd09 - [AST][RecoveryExpr] Populate the dependence bits from CompoundStmt result expr to StmtExpr.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 8 06:31:30 PDT 2020
Author: Haojian Wu
Date: 2020-06-08T15:31:08+02:00
New Revision: 28ccd09d700311f0d1ce3828a614aad231bdbb22
URL: https://github.com/llvm/llvm-project/commit/28ccd09d700311f0d1ce3828a614aad231bdbb22
DIFF: https://github.com/llvm/llvm-project/commit/28ccd09d700311f0d1ce3828a614aad231bdbb22.diff
LOG: [AST][RecoveryExpr] Populate the dependence bits from CompoundStmt result expr to StmtExpr.
Summary:
We lost errorBit for StmtExpr if a recoveryExpr is the result
expr of a CompoundStmt, which will lead to crashes.
```
// `-StmtExpr
// `-CompoundStmt
// `-RecoveryExp
({ invalid(); });
```
Reviewers: sammccall
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D81154
Added:
Modified:
clang/lib/AST/ComputeDependence.cpp
clang/test/SemaCXX/invalid-constructor-init.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ComputeDependence.cpp b/clang/lib/AST/ComputeDependence.cpp
index 3dcb9ba52356..53c43b194b38 100644
--- a/clang/lib/AST/ComputeDependence.cpp
+++ b/clang/lib/AST/ComputeDependence.cpp
@@ -128,15 +128,19 @@ ExprDependence clang::computeDependence(BinaryConditionalOperator *E) {
}
ExprDependence clang::computeDependence(StmtExpr *E, unsigned TemplateDepth) {
- // FIXME: why is unexpanded-pack not propagated?
- auto D = toExprDependence(E->getType()->getDependence()) &
- ~ExprDependence::UnexpandedPack;
+ auto D = toExprDependence(E->getType()->getDependence());
+ // Propagate dependence of the result.
+ if (const auto *CompoundExprResult =
+ dyn_cast_or_null<ValueStmt>(E->getSubStmt()->getStmtExprResult()))
+ if (const Expr *ResultExpr = CompoundExprResult->getExprStmt())
+ D |= ResultExpr->getDependence();
// Note: we treat a statement-expression in a dependent context as always
// being value- and instantiation-dependent. This matches the behavior of
// lambda-expressions and GCC.
if (TemplateDepth)
D |= ExprDependence::ValueInstantiation;
- return D;
+ // A param pack cannot be expanded over stmtexpr boundaries.
+ return D & ~ExprDependence::UnexpandedPack;
}
ExprDependence clang::computeDependence(ConvertVectorExpr *E) {
diff --git a/clang/test/SemaCXX/invalid-constructor-init.cpp b/clang/test/SemaCXX/invalid-constructor-init.cpp
index 8fda9cc525ba..df10afb1d726 100644
--- a/clang/test/SemaCXX/invalid-constructor-init.cpp
+++ b/clang/test/SemaCXX/invalid-constructor-init.cpp
@@ -14,6 +14,12 @@ struct X2 {
constexpr X2() {} // expected-error {{constexpr constructor never produces a constant expression}}
};
+struct X3 {
+ int Y;
+ constexpr X3() // expected-error {{constexpr constructor never produces}}
+ : Y(({foo();})) {} // expected-error {{use of undeclared identifier 'foo'}}
+};
+
struct CycleDelegate {
int Y;
CycleDelegate(int)
More information about the cfe-commits
mailing list