[PATCH] D104052: [clang] Fix CallExpr dependence bit may not respecting all its arguments.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 10 12:01:43 PDT 2021


hokein created this revision.
hokein added a reviewer: sammccall.
hokein requested review of this revision.
Herald added a project: clang.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104052

Files:
  clang/include/clang/AST/Expr.h
  clang/lib/AST/Expr.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/test/SemaCXX/recovery-expr-type.cpp


Index: clang/test/SemaCXX/recovery-expr-type.cpp
===================================================================
--- clang/test/SemaCXX/recovery-expr-type.cpp
+++ 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 {{undeclare identifier}}
+void crash1() { fun(); }
+void crash2() { constexpr int s = fun(); }
 } // namespace test12
Index: clang/lib/Serialization/ASTReaderStmt.cpp
===================================================================
--- clang/lib/Serialization/ASTReaderStmt.cpp
+++ clang/lib/Serialization/ASTReaderStmt.cpp
@@ -1013,7 +1013,7 @@
   E->setRParenLoc(readSourceLocation());
   E->setCallee(Record.readSubExpr());
   for (unsigned I = 0; I != NumArgs; ++I)
-    E->setArg(I, Record.readSubExpr());
+    E->setArg(I, Record.readSubExpr(), false);
   E->setADLCallKind(static_cast<CallExpr::ADLCallKind>(Record.readInt()));
   if (HasFPFeatures)
     E->setStoredFPFeatures(
Index: clang/lib/AST/Expr.cpp
===================================================================
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -1394,9 +1394,9 @@
   for (unsigned I = 0; I != NumPreArgs; ++I)
     setPreArg(I, PreArgs[I]);
   for (unsigned I = 0; I != Args.size(); ++I)
-    setArg(I, Args[I]);
+    setArg(I, Args[I], false);
   for (unsigned I = Args.size(); I != NumArgs; ++I)
-    setArg(I, nullptr);
+    setArg(I, nullptr, false);
 
   setDependence(computeDependence(this, PreArgs));
 
Index: clang/include/clang/AST/Expr.h
===================================================================
--- clang/include/clang/AST/Expr.h
+++ clang/include/clang/AST/Expr.h
@@ -2987,9 +2987,14 @@
   }
 
   /// setArg - Set the specified argument.
-  void setArg(unsigned Arg, Expr *ArgExpr) {
+  void setArg(unsigned Arg, Expr *ArgExpr, bool RecomputeDependence = true) {
     assert(Arg < getNumArgs() && "Arg access out of range!");
     getArgs()[Arg] = ArgExpr;
+    if (RecomputeDependence)
+      setDependence(computeDependence(
+          this, llvm::makeArrayRef(reinterpret_cast<Expr **>(
+                                       getTrailingStmts() + PREARGS_START),
+                                   getNumPreArgs())));
   }
 
   /// Reduce the number of arguments in this call expression. This is used for


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104052.351230.patch
Type: text/x-patch
Size: 2479 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210610/db6f9f55/attachment.bin>


More information about the cfe-commits mailing list