[PATCH] D84304: [AST][RecoveryExpr] Build dependent callexpr in C for error-recovery.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 22 03:57:05 PDT 2020


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

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84304

Files:
  clang/lib/Sema/SemaExpr.cpp
  clang/test/AST/ast-dump-recovery.c
  clang/test/Sema/error-dependence.c


Index: clang/test/Sema/error-dependence.c
===================================================================
--- clang/test/Sema/error-dependence.c
+++ clang/test/Sema/error-dependence.c
@@ -6,4 +6,8 @@
   // verify "assigning to 'int' from incompatible type '<dependent type>'" is
   // not emitted.
   s = call(); // expected-error {{too few arguments to function call}}
+
+  // verify disgnostic "called object type '<dependent type>' is not a function
+  // or function pointer" is not emitted.
+  (*__builtin_classify_type)(1); // expected-error {{builtin functions must be directly called}}
 }
Index: clang/test/AST/ast-dump-recovery.c
===================================================================
--- clang/test/AST/ast-dump-recovery.c
+++ clang/test/AST/ast-dump-recovery.c
@@ -55,3 +55,18 @@
   // CHECK-NEXT:   `-DeclRefExpr {{.*}} 'some_func'
   compoundOp += some_func();
 }
+
+void test3() {
+  // CHECK:      CallExpr {{.*}} '<dependent type>' contains-errors
+  // CHECK-NEXT:  |-ParenExpr {{.*}} contains-errors lvalue
+  // CHECK-NEXT:  | `-RecoveryExpr {{.*}} contains-errors
+  // CHECK-NEXT:  |   `-DeclRefExpr {{.*}} '__builtin_classify_type'
+  // CHECK-NEXT:  `-IntegerLiteral {{.*}} 'int' 1
+  (*__builtin_classify_type)(1);
+
+  extern void ext();
+  // FIXME: the broken AST will be preserved once we remove the early typo correction
+  // in Sema::CheckPlaceholderExpr.
+  // CHECK-NOT: DeclRefExpr {{.*}} 'ext' 'int (int)'
+  ext(undef_var);
+}
Index: clang/lib/Sema/SemaExpr.cpp
===================================================================
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -46,6 +46,7 @@
 #include "clang/Sema/SemaFixItUtils.h"
 #include "clang/Sema/SemaInternal.h"
 #include "clang/Sema/Template.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/ConvertUTF.h"
 #include "llvm/Support/SaveAndRestore.h"
 using namespace clang;
@@ -6433,6 +6434,17 @@
     checkDirectCallValidity(*this, Fn, FD, ArgExprs);
   }
 
+  if (getLangOpts().CDependence &&
+      (Fn->isTypeDependent() || Expr::hasAnyTypeDependentArguments(ArgExprs))) {
+    assert(!getLangOpts().CPlusPlus);
+    assert(Fn->containsErrors() ||
+           llvm::any_of(ArgExprs,
+                        [](clang::Expr *E) { return E->containsErrors(); }) &&
+               "should only occur in error-recovery path.");
+    return CallExpr::Create(Context, Fn, ArgExprs, Context.DependentTy,
+                            VK_RValue, RParenLoc);
+  }
+
   return BuildResolvedCallExpr(Fn, NDecl, LParenLoc, ArgExprs, RParenLoc,
                                ExecConfig, IsExecConfig);
 }
@@ -6572,7 +6584,7 @@
                                RParenLoc, NumParams, UsesADL);
   }
 
-  if (!getLangOpts().CPlusPlus) {
+  if (!getLangOpts().CPlusPlus && !getLangOpts().CDependence) {
     // Forget about the nulled arguments since typo correction
     // do not handle them well.
     TheCall->shrinkNumArgs(Args.size());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84304.279759.patch
Type: text/x-patch
Size: 2970 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200722/96fd98c3/attachment.bin>


More information about the cfe-commits mailing list