[clang] 314e456 - [clang] Fix CallExpr dependence bit may not respect all its arguments.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 1 05:40:29 PDT 2021
Author: Haojian Wu
Date: 2021-07-01T14:40:03+02:00
New Revision: 314e456dfe85f8b5c53b85a7d815f7d463fe02ef
URL: https://github.com/llvm/llvm-project/commit/314e456dfe85f8b5c53b85a7d815f7d463fe02ef
DIFF: https://github.com/llvm/llvm-project/commit/314e456dfe85f8b5c53b85a7d815f7d463fe02ef.diff
LOG: [clang] Fix CallExpr dependence bit may not respect all its arguments.
Before this patch, the dependence of CallExpr was only computed in the
constructor, the dependence bits might not reflect truth -- some arguments might
be not set (nullptr) during this time, e.g. CXXDefaultArgExpr will be set via
the setArg method in the later parsing stage, so we need to recompute the
dependence bits.
Added:
Modified:
clang/include/clang/AST/Expr.h
clang/lib/AST/Expr.cpp
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaCXX/recovery-expr-type.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index ddef2564a43c..06164411cc2d 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -2987,11 +2987,22 @@ class CallExpr : public Expr {
}
/// setArg - Set the specified argument.
+ /// ! the dependence bits might be stale after calling this setter, it is
+ /// *caller*'s responsibility to recompute them by calling
+ /// computeDependence().
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<Expr **>(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
index 613abb7383da..03dc65eeb6b0 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -1398,7 +1398,7 @@ CallExpr::CallExpr(StmtClass SC, Expr *Fn, ArrayRef<Expr *> PreArgs,
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
index 3df74b5ea9db..a3a26d21422f 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -5928,6 +5928,7 @@ Sema::ConvertArgumentsForCall(CallExpr *Call, Expr *Fn,
for (unsigned i = 0; i < TotalNumArgs; ++i)
Call->setArg(i, AllArgs[i]);
+ Call->computeDependence();
return false;
}
@@ -6863,6 +6864,7 @@ ExprResult Sema::BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl,
TheCall->setArg(i, Arg);
}
+ TheCall->computeDependence();
}
if (CXXMethodDecl *Method = dyn_cast_or_null<CXXMethodDecl>(FDecl))
diff --git a/clang/test/SemaCXX/recovery-expr-type.cpp b/clang/test/SemaCXX/recovery-expr-type.cpp
index d3ac772db008..509cd1745976 100644
--- a/clang/test/SemaCXX/recovery-expr-type.cpp
+++ b/clang/test/SemaCXX/recovery-expr-type.cpp
@@ -139,6 +139,7 @@ void baz() {
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
More information about the cfe-commits
mailing list