[PATCH] D84304: [AST][RecoveryExpr] Part 2: Build dependent callexpr in C for error-recovery.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 7 03:21:34 PDT 2020
hokein updated this revision to Diff 296634.
hokein added a comment.
fix format.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D84304/new/
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,6 +6,10 @@
// 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}}
}
void test2(int* ptr, float f) {
Index: clang/test/AST/ast-dump-recovery.c
===================================================================
--- clang/test/AST/ast-dump-recovery.c
+++ clang/test/AST/ast-dump-recovery.c
@@ -82,3 +82,18 @@
// CHECK-NEXT: `-DeclRefExpr {{.*}} 'float' lvalue
(ptr > f ? ptr : f);
}
+
+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();
+ // CHECK: CallExpr {{.*}} 'void' contains-errors
+ // CHECK-NEXT: |-DeclRefExpr {{.*}} 'ext'
+ // CHECK-NEXT: `-RecoveryExpr {{.*}} '<dependent type>'
+ ext(undef_var);
+}
Index: clang/lib/Sema/SemaExpr.cpp
===================================================================
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -6439,6 +6439,21 @@
checkDirectCallValidity(*this, Fn, FD, ArgExprs);
}
+ if (Context.isDependenceAllowed() &&
+ (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.");
+ QualType ReturnType =
+ llvm::isa_and_nonnull<FunctionDecl>(NDecl)
+ ? dyn_cast<FunctionDecl>(NDecl)->getCallResultType()
+ : Context.DependentTy;
+ return CallExpr::Create(Context, Fn, ArgExprs, ReturnType,
+ Expr::getValueKindForType(ReturnType), RParenLoc,
+ CurFPFeatureOverrides());
+ }
return BuildResolvedCallExpr(Fn, NDecl, LParenLoc, ArgExprs, RParenLoc,
ExecConfig, IsExecConfig);
}
@@ -6579,7 +6594,7 @@
CurFPFeatureOverrides(), NumParams, UsesADL);
}
- if (!getLangOpts().CPlusPlus) {
+ if (!Context.isDependenceAllowed()) {
// Forget about the nulled arguments since typo correction
// do not handle them well.
TheCall->shrinkNumArgs(Args.size());
@@ -19116,7 +19131,7 @@
/// Check for operands with placeholder types and complain if found.
/// Returns ExprError() if there was an error and no recovery was possible.
ExprResult Sema::CheckPlaceholderExpr(Expr *E) {
- if (!getLangOpts().CPlusPlus) {
+ if (!Context.isDependenceAllowed()) {
// C cannot handle TypoExpr nodes on either side of a binop because it
// doesn't handle dependent types properly, so make sure any TypoExprs have
// been dealt with before checking the operands.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84304.296634.patch
Type: text/x-patch
Size: 3459 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201007/b4b00190/attachment.bin>
More information about the cfe-commits
mailing list