[clang] a96bcfb - [AST][RecoveryExpr] Support dependent cast-expr in C for error-recovery.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 8 01:03:50 PDT 2020


Author: Haojian Wu
Date: 2020-10-08T10:00:29+02:00
New Revision: a96bcfb196740b5be217f6166462ee1206530520

URL: https://github.com/llvm/llvm-project/commit/a96bcfb196740b5be217f6166462ee1206530520
DIFF: https://github.com/llvm/llvm-project/commit/a96bcfb196740b5be217f6166462ee1206530520.diff

LOG: [AST][RecoveryExpr] Support dependent cast-expr in C for error-recovery.

Suppress spurious "typecheck_cond_expect_scalar_operand" diagnostic.

See whole context: https://reviews.llvm.org/D85025

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D84387

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp
index d59f1880a7ff..0bd240585bd7 100644
--- a/clang/lib/Sema/SemaCast.cpp
+++ b/clang/lib/Sema/SemaCast.cpp
@@ -2707,6 +2707,17 @@ void CastOperation::CheckCStyleCast() {
     return;
   }
 
+  // If the type is dependent, we won't do any other semantic analysis now.
+  if (Self.getASTContext().isDependenceAllowed() &&
+      (DestType->isDependentType() || SrcExpr.get()->isTypeDependent() ||
+       SrcExpr.get()->isValueDependent())) {
+    assert((DestType->containsErrors() || SrcExpr.get()->containsErrors() ||
+            SrcExpr.get()->containsErrors()) &&
+           "should only occur in error-recovery path.");
+    assert(Kind == CK_Dependent);
+    return;
+  }
+
   // Overloads are allowed with C extensions, so we need to support them.
   if (SrcExpr.get()->getType() == Self.Context.OverloadTy) {
     DeclAccessPair DAP;

diff  --git a/clang/test/AST/ast-dump-recovery.c b/clang/test/AST/ast-dump-recovery.c
index 7b2bcf27ecce..d14aedebe490 100644
--- a/clang/test/AST/ast-dump-recovery.c
+++ b/clang/test/AST/ast-dump-recovery.c
@@ -81,4 +81,9 @@ void test2() {
   // CHECK-NEXT: |-DeclRefExpr {{.*}} 'int *' lvalue
   // CHECK-NEXT: `-DeclRefExpr {{.*}} 'float' lvalue
   (ptr > f ? ptr : f);
+
+  // CHECK:     CStyleCastExpr {{.*}} 'float' contains-errors <Dependent>
+  // CHECK-NEXT: `-RecoveryExpr {{.*}} '<dependent type>'
+  // CHECK-NEXT:   `-DeclRefExpr {{.*}} 'some_func'
+  (float)some_func();
 }

diff  --git a/clang/test/Sema/error-dependence.c b/clang/test/Sema/error-dependence.c
index b83a79f8c4c6..41733cdba3fe 100644
--- a/clang/test/Sema/error-dependence.c
+++ b/clang/test/Sema/error-dependence.c
@@ -1,11 +1,15 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -frecovery-ast -fno-recovery-ast-type %s
 
-int call(int); // expected-note2 {{'call' declared here}}
+int call(int); // expected-note3 {{'call' declared here}}
 
 void test1(int s) {
   // verify "assigning to 'int' from incompatible type '<dependent type>'" is
   // not emitted.
   s = call(); // expected-error {{too few arguments to function call}}
+
+  // verify diagnostic "operand of type '<dependent type>' where arithmetic or
+  // pointer type is required" is not emitted.
+  (float)call(); // expected-error {{too few arguments to function call}}
 }
 
 void test2(int* ptr, float f) {


        


More information about the cfe-commits mailing list