[PATCH] D89946: [clang] Suppress "follow-up" diagnostics on recovery call expressions.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 26 01:06:06 PDT 2020
hokein updated this revision to Diff 300590.
hokein marked an inline comment as done.
hokein added a comment.
address comment.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D89946/new/
https://reviews.llvm.org/D89946
Files:
clang/lib/Sema/SemaOverload.cpp
clang/test/AST/ast-dump-recovery.cpp
clang/test/SemaCXX/typo-correction-delayed.cpp
Index: clang/test/SemaCXX/typo-correction-delayed.cpp
===================================================================
--- clang/test/SemaCXX/typo-correction-delayed.cpp
+++ clang/test/SemaCXX/typo-correction-delayed.cpp
@@ -209,6 +209,15 @@
// expected-error-re at -1 {{use of undeclared identifier 'N'{{$}}}}
}
+namespace noSecondaryDiags {
+void abcc(); // expected-note {{'abcc' declared here}}
+
+void test() {
+ // Verify the secondary diagnostic ".. convertiable to 'bool'" is suppressed.
+ if (abc()) {} // expected-error {{use of undeclared identifier 'abc'; did you mean 'abcc'?}}
+}
+}
+
// PR 23285. This test must be at the end of the file to avoid additional,
// unwanted diagnostics.
// expected-error-re at +2 {{use of undeclared identifier 'uintmax_t'{{$}}}}
Index: clang/test/AST/ast-dump-recovery.cpp
===================================================================
--- clang/test/AST/ast-dump-recovery.cpp
+++ clang/test/AST/ast-dump-recovery.cpp
@@ -271,3 +271,12 @@
// CHECK-NEXT: `-IntegerLiteral {{.*}} 'int' 2
invalid() ? 1 : 2;
}
+
+void abcc();
+void TypoCorrection() {
+ // CHECK: RecoveryExpr {{.*}} '<dependent type>'
+ // CHECK-NEXT: `-CallExpr {{.*}} 'void'
+ // CHECK-NEXT: `-ImplicitCastExpr
+ // CHECK-NEXT: `-DeclRefExpr {{.*}} 'abcc'
+ abc();
+}
Index: clang/lib/Sema/SemaOverload.cpp
===================================================================
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -12725,8 +12725,6 @@
}
/// Attempts to recover from a call where no functions were found.
-///
-/// Returns true if new candidates were found.
static ExprResult
BuildRecoveryCallExpr(Sema &SemaRef, Scope *S, Expr *Fn,
UnresolvedLookupExpr *ULE,
@@ -12783,7 +12781,7 @@
return ExprError();
}
- // Build an implicit member call if appropriate. Just drop the
+ // Build an implicit member access expression if appropriate. Just drop the
// casts and such from the call, we don't really care.
ExprResult NewFn = ExprError();
if ((*R.begin())->isCXXClassMember())
@@ -12798,12 +12796,17 @@
if (NewFn.isInvalid())
return ExprError();
- // This shouldn't cause an infinite loop because we're giving it
- // an expression with viable lookup results, which should never
- // end up here.
- return SemaRef.BuildCallExpr(/*Scope*/ nullptr, NewFn.get(), LParenLoc,
- MultiExprArg(Args.data(), Args.size()),
- RParenLoc);
+ auto CallE =
+ SemaRef.BuildCallExpr(/*Scope*/ nullptr, NewFn.get(), LParenLoc,
+ MultiExprArg(Args.data(), Args.size()), RParenLoc);
+ if (CallE.isInvalid())
+ return ExprError();
+ // We now have recovered a callee. However, building a real call may lead to
+ // incorrect secondary diagnostics if our recovery wasn't correct.
+ // We keep the recovery behavior but suppress all following diagnostics by
+ // using RecoveryExpr.
+ return SemaRef.CreateRecoveryExpr(CallE.get()->getBeginLoc(),
+ CallE.get()->getEndLoc(), {CallE.get()});
}
/// Constructs and populates an OverloadedCandidateSet from
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89946.300590.patch
Type: text/x-patch
Size: 3215 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201026/866a31a3/attachment.bin>
More information about the cfe-commits
mailing list