Revert "[AST] Build recovery expressions by default for C++."

This reverts commit 0788acbccb.
This reverts commit c2d7a1f79cedfc9fcb518596aa839da4de0adb69:  Revert "[clangd] Add test for FindTarget+RecoveryExpr (which already works). NFC"

It causes a crash on invalid code:

class X {
  decltype(unresolved()) foo;
};
constexpr int s = sizeof(X);
This commit is contained in:
Haojian Wu 2020-03-26 16:07:50 +01:00
parent 1e30396223
commit 62dea6e9be
18 changed files with 29 additions and 60 deletions

View File

@ -1195,9 +1195,7 @@ TEST(SignatureHelpTest, OpeningParen) {
int foo(int a, int b, int c);
int main() {
#define ID(X) X
// FIXME: figure out why ID(foo (foo(10), )) doesn't work when preserving
// the recovery expression.
ID(foo $p^( 10, ^ ))
ID(foo $p^( foo(10), ^ ))
})cpp"};
for (auto Test : Tests) {

View File

@ -132,16 +132,6 @@ TEST_F(TargetDeclTest, Exprs) {
EXPECT_DECLS("CXXOperatorCallExpr", "void operator()(int n)");
}
TEST_F(TargetDeclTest, Recovery) {
Code = R"cpp(
// error-ok: testing behavior on broken code
int f();
int f(int, int);
int x = [[f]](42);
)cpp";
EXPECT_DECLS("UnresolvedLookupExpr", "int f()", "int f(int, int)");
}
TEST_F(TargetDeclTest, UsingDecl) {
Code = R"cpp(
namespace foo {
@ -695,15 +685,6 @@ TEST_F(FindExplicitReferencesTest, All) {
)cpp",
"0: targets = {x}\n"
"1: targets = {X::a}\n"},
{R"cpp(
// error-ok: testing with broken code
int bar();
int foo() {
return $0^bar() + $1^bar(42);
}
)cpp",
"0: targets = {bar}\n"
"1: targets = {bar}\n"},
// Namespaces and aliases.
{R"cpp(
namespace ns {}

View File

@ -148,7 +148,7 @@ LANGOPT(RelaxedTemplateTemplateArgs, 1, 0, "C++17 relaxed matching of template t
LANGOPT(DoubleSquareBracketAttributes, 1, 0, "'[[]]' attributes extension for all language standard modes")
COMPATIBLE_LANGOPT(RecoveryAST, 1, CPlusPlus, "Preserve expressions in AST when encountering errors")
COMPATIBLE_LANGOPT(RecoveryAST, 1, 0, "Preserve expressions in AST when encountering errors")
BENIGN_LANGOPT(ThreadsafeStatics , 1, 1, "thread-safe static initializers")
LANGOPT(POSIXThreads , 1, 0, "POSIX thread support")

View File

@ -2909,7 +2909,7 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
if (Args.hasArg(OPT_fconcepts_ts))
Diags.Report(diag::warn_fe_concepts_ts_flag);
Opts.RecoveryAST =
Args.hasFlag(OPT_frecovery_ast, OPT_fno_recovery_ast, Opts.CPlusPlus);
Args.hasFlag(OPT_frecovery_ast, OPT_fno_recovery_ast, false);
Opts.HeinousExtensions = Args.hasArg(OPT_fheinous_gnu_extensions);
Opts.AccessControl = !Args.hasArg(OPT_fno_access_control);
Opts.ElideConstructors = !Args.hasArg(OPT_fno_elide_constructors);

View File

@ -18512,8 +18512,8 @@ bool Sema::IsDependentFunctionNameExpr(Expr *E) {
ExprResult Sema::CreateRecoveryExpr(SourceLocation Begin, SourceLocation End,
ArrayRef<Expr *> SubExprs) {
// RecoveryExpr is type-dependent to suppress bogus diagnostics and this trick
// does not work in C.
// FIXME: enable it for C++, RecoveryExpr is type-dependent to suppress
// bogus diagnostics and this trick does not work in C.
// FIXME: use containsErrors() to suppress unwanted diags in C.
if (!Context.getLangOpts().RecoveryAST)
return ExprError();

View File

@ -74,7 +74,7 @@ struct S8 {
#pragma omp target update from(*(this->S->i+this->S->s6[0].pp)) // le45-error {{expected expression containing only member accesses and/or array sections based on named variables}} le45-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
#pragma omp target update from(*(a+this->ptr)) // le45-error {{expected expression containing only member accesses and/or array sections based on named variables}} le45-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
#pragma omp target update from(*(*(this->ptr)+a+this->ptr)) // le45-error {{expected expression containing only member accesses and/or array sections based on named variables}} le45-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
#pragma omp target update from(*(this+this)) // expected-error {{invalid operands to binary expression ('S8 *' and 'S8 *')}}
#pragma omp target update from(*(this+this)) // expected-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}} expected-error {{invalid operands to binary expression ('S8 *' and 'S8 *')}}
}
};
@ -198,8 +198,8 @@ int main(int argc, char **argv) {
#pragma omp target update from(**(-(*offset)+BB+*m)) // le45-error {{expected expression containing only member accesses and/or array sections based on named variables}} le45-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
#pragma omp target update from(**(*(*(&offset))+BB-*m)) // le45-error {{expected expression containing only member accesses and/or array sections based on named variables}} le45-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
#pragma omp target update from(*(x+*(y+*(**BB+BBB)+s7.i))) // le45-error {{expected expression containing only member accesses and/or array sections based on named variables}} le45-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
#pragma omp target update from(*(m+(m))) // expected-error {{invalid operands to binary expression ('int *' and 'int *')}}
#pragma omp target update from(*(1+y+y)) // expected-error {{indirection requires pointer operand ('int' invalid)}}
#pragma omp target update from(*(m+(m))) // expected-error {{invalid operands to binary expression ('int *' and 'int *')}} expected-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
#pragma omp target update from(*(1+y+y)) // expected-error {{indirection requires pointer operand ('int' invalid)}} expected-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
#pragma omp target data map(to: s7.i)
{
#pragma omp target update from(s7.x)

View File

@ -77,7 +77,7 @@ struct S8 {
#pragma omp target update to(*(this->S->i+this->S->s6[0].pp)) // le45-error {{expected expression containing only member accesses and/or array sections based on named variables}} le45-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
#pragma omp target update to(*(a+this->ptr)) // le45-error {{expected expression containing only member accesses and/or array sections based on named variables}} le45-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
#pragma omp target update to(*(*(this->ptr)+a+this->ptr)) // le45-error {{expected expression containing only member accesses and/or array sections based on named variables}} le45-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
#pragma omp target update to(*(this+this)) // expected-error {{invalid operands to binary expression ('S8 *' and 'S8 *')}}
#pragma omp target update to(*(this+this)) // expected-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}} expected-error {{invalid operands to binary expression ('S8 *' and 'S8 *')}}
{}
}
};
@ -205,8 +205,8 @@ int main(int argc, char **argv) {
#pragma omp target update to(**(*offset+BB+*m)) // le45-error {{expected expression containing only member accesses and/or array sections based on named variables}} le45-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
#pragma omp target update to(**(*(*(&offset))+BB+*m)) // le45-error {{expected expression containing only member accesses and/or array sections based on named variables}} le45-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
#pragma omp target update to(*(x+*(y+*(**BB+BBB)+s7.i))) // le45-error {{expected expression containing only member accesses and/or array sections based on named variables}} le45-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
#pragma omp target update to(*(m+(m))) // expected-error {{invalid operands to binary expression ('int *' and 'int *')}}
#pragma omp target update to(*(1+y+y)) // expected-error {{indirection requires pointer operand ('int' invalid)}}
#pragma omp target update to(*(m+(m))) // expected-error {{invalid operands to binary expression ('int *' and 'int *')}} expected-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
#pragma omp target update to(*(1+y+y)) // expected-error {{indirection requires pointer operand ('int' invalid)}} expected-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
{}
return tmain<int, 3>(argc)+tmain<from, 4>(argc); // expected-note {{in instantiation of function template specialization 'tmain<int, 3>' requested here}} expected-note {{in instantiation of function template specialization 'tmain<int, 4>' requested here}}
}

View File

@ -11,8 +11,7 @@ class C {
[]; // expected-error {{expected body of lambda expression}}
[=,foo+] {}; // expected-error {{expected ',' or ']' in lambda capture list}}
[&this] {}; // expected-error {{cannot take the address of an rvalue of type 'C *'}} \
// expected-error {{expected identifier}}
[&this] {}; // expected-error {{cannot take the address of an rvalue of type 'C *'}}
[] {};
[=] (int i) {};
[&] (int) mutable -> void {};
@ -25,8 +24,7 @@ class C {
[foo{bar}] () {};
[foo = {bar}] () {}; // expected-error {{<initializer_list>}}
[foo(bar) baz] () {}; // expected-error {{called object type 'int' is not a function}} \
// expected-error {{expected ';'}}
[foo(bar) baz] () {}; // expected-error {{called object type 'int' is not a function}}
[foo(bar), baz] () {}; // ok
[foo = bar baz]; // expected-warning {{receiver type 'int'}} expected-warning {{instance method '-baz'}}

View File

@ -1,11 +1,10 @@
// RUN: %clang_cc1 -fsyntax-only -verify -x objective-c++ -std=c++11 %s
void foo() {
void foo() { // expected-note {{to match this '{'}}
int bar;
auto baz = [
bar( // expected-note 2{{to match this '('}}\
// expected-warning {{captures are a C++14 extension}}
bar( // expected-note {{to match this '('}} expected-note {{to match this '('}}
foo_undeclared() // expected-error{{use of undeclared identifier 'foo_undeclared'}}
/* ) */
] () { }; // expected-error 2{{expected ')'}}
}
] () { }; // expected-error{{expected ')'}}
} // expected-error{{expected ')'}} expected-error {{expected ',' or ']'}} expected-error{{expected ';' at end of declaration}} expected-error{{expected '}'}}

View File

@ -14,8 +14,8 @@ template<int (*Compare)(const char *s1, const char *s2)>
int equal(const char *s1, const char *s2) {
return Compare(s1, s2) == 0;
}
template int equal<&__builtin_strcmp>(const char*, const char*); // expected-error {{builtin functions must be directly called}}
// FIXME: Our error recovery here sucks
template int equal<&__builtin_strcmp>(const char*, const char*); // expected-error {{builtin functions must be directly called}} expected-error {{expected unqualified-id}} expected-error {{expected ')'}} expected-note {{to match this '('}}
// PR13195
void f2() {

View File

@ -1,4 +1,4 @@
// RUN: %clang_cc1 -fsyntax-only -triple x86_64-unknown-unknown -verify %s -std=c++11 -Wno-unused
// RUN: %clang_cc1 -fsyntax-only -triple x86_64-unknown-unknown -verify %s -std=c++11
struct R {
R(int);

View File

@ -250,7 +250,7 @@ namespace test3 {
B(const String& s, int e=0) // expected-error {{unknown type name}}
: A(e), m_String(s) , m_ErrorStr(__null) {} // expected-error {{no matching constructor}} expected-error {{does not name}}
B(const B& e)
: A(e), m_String(e.m_String), m_ErrorStr(__null) { // expected-error 2{{does not name}} \
: A(e), m_String(e.m_String), m_ErrorStr(__null) { // expected-error {{does not name}} \
// expected-error {{no member named 'm_String' in 'test3::B'}}
}
};

View File

@ -1,4 +1,4 @@
// RUN: %clang_cc1 -std=c++1z -verify -Wno-unused %s
// RUN: %clang_cc1 -std=c++1z -verify %s
struct Noncopyable {
Noncopyable();
@ -107,10 +107,8 @@ void test_expressions(bool b) {
sizeof(make_indestructible()); // expected-error {{deleted}}
sizeof(make_incomplete()); // expected-error {{incomplete}}
typeid(Indestructible{}); // expected-error {{deleted}}
typeid(make_indestructible()); // expected-error {{deleted}} \
// expected-error {{need to include <typeinfo>}}
typeid(make_incomplete()); // expected-error {{incomplete}} \
// expected-error {{need to include <typeinfo>}}
typeid(make_indestructible()); // expected-error {{deleted}}
typeid(make_incomplete()); // expected-error {{incomplete}}
// FIXME: The first two cases here are now also valid in C++17 onwards.
using I = decltype(Indestructible()); // expected-error {{deleted}}

View File

@ -3,8 +3,5 @@
int& a();
void f() {
decltype(a()) c; // expected-warning {{'decltype' is a keyword in C++11}} \
// expected-error {{use of undeclared identifier 'decltype'}} \
// expected-error {{expected ';' after expression}} \
// expected-error {{use of undeclared identifier 'c'}}
decltype(a()) c; // expected-warning {{'decltype' is a keyword in C++11}} expected-error {{use of undeclared identifier 'decltype'}}
}

View File

@ -22,8 +22,7 @@ void no_params(...) {
// default ctor.
void record_context(int a, ...) {
struct Foo {
// expected-error@+2 {{'va_start' cannot be used outside a function}}
// expected-error@+1 {{default argument references parameter 'a'}}
// expected-error@+1 {{'va_start' cannot be used outside a function}}
void meth(int a, int b = (__builtin_va_start(ap, a), 0)) {}
};
}

View File

@ -11,7 +11,7 @@ int bar(const __global unsigned int &i); // expected-note{{passing argument to p
int bar(const unsigned int &i);
void foo() {
bar(1); // expected-error{{binding reference of type 'const __global unsigned int' to value of type 'int' changes address space}}
bar(1) // expected-error{{binding reference of type 'const __global unsigned int' to value of type 'int' changes address space}}
}
// Test addr space conversion with nested pointers

View File

@ -100,7 +100,7 @@ namespace PR7985 {
integral_c<1> ic1 = array_lengthof(Description<int>::data);
(void)sizeof(array_lengthof(Description<float>::data));
(void)sizeof(array_lengthof( // expected-error{{no matching function for call to 'array_lengthof'}}
sizeof(array_lengthof( // expected-error{{no matching function for call to 'array_lengthof'}}
Description<int*>::data // expected-note{{in instantiation of static data member 'PR7985::Description<int *>::data' requested here}}
));

View File

@ -487,7 +487,6 @@ TEST(PreferredTypeTest, NoCrashOnInvalidTypes) {
auto x = decltype(&1)(^);
auto y = new decltype(&1)(^);
)cpp";
EXPECT_THAT(collectPreferredTypes(Code),
Each("decltype(<recovery-expr>(1))"));
EXPECT_THAT(collectPreferredTypes(Code), Each("NULL TYPE"));
}
} // namespace