diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h --- a/clang/include/clang/AST/Expr.h +++ b/clang/include/clang/AST/Expr.h @@ -2987,11 +2987,21 @@ } /// setArg - Set the specified argument. + /// ! the dependence bits might be stale after calling this setter, it is + /// *caller*'s responsibility to recompute them. void setArg(unsigned Arg, Expr *ArgExpr) { assert(Arg < getNumArgs() && "Arg access out of range!"); getArgs()[Arg] = ArgExpr; } + /// Compute and set dependence bits. + void computeDependence() { + setDependence(clang::computeDependence( + this, llvm::makeArrayRef( + reinterpret_cast(getTrailingStmts() + PREARGS_START), + getNumPreArgs()))); + } + /// Reduce the number of arguments in this call expression. This is used for /// example during error recovery to drop extra arguments. There is no way /// to perform the opposite because: 1.) We don't track how much storage diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -1398,7 +1398,7 @@ for (unsigned I = Args.size(); I != NumArgs; ++I) setArg(I, nullptr); - setDependence(computeDependence(this, PreArgs)); + this->computeDependence(); CallExprBits.HasFPFeatures = FPFeatures.requiresTrailingStorage(); if (hasStoredFPFeatures()) diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -5924,6 +5924,7 @@ for (unsigned i = 0; i < TotalNumArgs; ++i) Call->setArg(i, AllArgs[i]); + Call->computeDependence(); return false; } @@ -6836,6 +6837,7 @@ TheCall->setArg(i, Arg); } + TheCall->computeDependence(); } if (CXXMethodDecl *Method = dyn_cast_or_null(FDecl)) diff --git a/clang/test/SemaCXX/recovery-expr-type.cpp b/clang/test/SemaCXX/recovery-expr-type.cpp --- a/clang/test/SemaCXX/recovery-expr-type.cpp +++ b/clang/test/SemaCXX/recovery-expr-type.cpp @@ -139,6 +139,7 @@ namespace test12 { // Verify we do not crash. -void fun(int *foo = no_such_function()); // expected-error {{undeclared identifier}} -void baz() { fun(); } +int fun(int *foo = no_such_function()); // expected-error {{undeclared identifier}} +void crash1() { fun(); } +void crash2() { constexpr int s = fun(); } } // namespace test12