Skip to content

Commit a96bcfb

Browse files
committed
[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
1 parent ba268d2 commit a96bcfb

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

clang/lib/Sema/SemaCast.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2707,6 +2707,17 @@ void CastOperation::CheckCStyleCast() {
27072707
return;
27082708
}
27092709

2710+
// If the type is dependent, we won't do any other semantic analysis now.
2711+
if (Self.getASTContext().isDependenceAllowed() &&
2712+
(DestType->isDependentType() || SrcExpr.get()->isTypeDependent() ||
2713+
SrcExpr.get()->isValueDependent())) {
2714+
assert((DestType->containsErrors() || SrcExpr.get()->containsErrors() ||
2715+
SrcExpr.get()->containsErrors()) &&
2716+
"should only occur in error-recovery path.");
2717+
assert(Kind == CK_Dependent);
2718+
return;
2719+
}
2720+
27102721
// Overloads are allowed with C extensions, so we need to support them.
27112722
if (SrcExpr.get()->getType() == Self.Context.OverloadTy) {
27122723
DeclAccessPair DAP;

clang/test/AST/ast-dump-recovery.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,9 @@ void test2() {
8181
// CHECK-NEXT: |-DeclRefExpr {{.*}} 'int *' lvalue
8282
// CHECK-NEXT: `-DeclRefExpr {{.*}} 'float' lvalue
8383
(ptr > f ? ptr : f);
84+
85+
// CHECK: CStyleCastExpr {{.*}} 'float' contains-errors <Dependent>
86+
// CHECK-NEXT: `-RecoveryExpr {{.*}} '<dependent type>'
87+
// CHECK-NEXT: `-DeclRefExpr {{.*}} 'some_func'
88+
(float)some_func();
8489
}

clang/test/Sema/error-dependence.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
// RUN: %clang_cc1 -fsyntax-only -verify -frecovery-ast -fno-recovery-ast-type %s
22

3-
int call(int); // expected-note2 {{'call' declared here}}
3+
int call(int); // expected-note3 {{'call' declared here}}
44

55
void test1(int s) {
66
// verify "assigning to 'int' from incompatible type '<dependent type>'" is
77
// not emitted.
88
s = call(); // expected-error {{too few arguments to function call}}
9+
10+
// verify diagnostic "operand of type '<dependent type>' where arithmetic or
11+
// pointer type is required" is not emitted.
12+
(float)call(); // expected-error {{too few arguments to function call}}
913
}
1014

1115
void test2(int* ptr, float f) {

0 commit comments

Comments
 (0)