r285275 - Mark invalid RecordDecls as completed.

Erik Verbruggen via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 27 01:37:15 PDT 2016


Author: erikjv
Date: Thu Oct 27 03:37:14 2016
New Revision: 285275

URL: http://llvm.org/viewvc/llvm-project?rev=285275&view=rev
Log:
Mark invalid RecordDecls as completed.

Sema::ActOnTag creates TagDecls for records. However, if those record
declarations are invalid, and the parser is in C++ mode, it would
silently drop the TagDecl (and leave it as "beingDefined"). The problem
is that other code (e.g. the ASTWriter) will serialize all types, and
expects them to be complete. So, leaving them open would result in
failing asserts.

Fixes PR20320

Differential Revision: http://reviews.llvm.org/D21176

Added:
    cfe/trunk/test/Index/pr20320.cpp
    cfe/trunk/test/Index/pr20320.h
Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/SemaCXX/conversion-function.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=285275&r1=285274&r2=285275&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Oct 27 03:37:14 2016
@@ -13386,7 +13386,14 @@ CreateNewDecl:
   OwnedDecl = true;
   // In C++, don't return an invalid declaration. We can't recover well from
   // the cases where we make the type anonymous.
-  return (Invalid && getLangOpts().CPlusPlus) ? nullptr : New;
+  if (Invalid && getLangOpts().CPlusPlus) {
+    if (New->isBeingDefined())
+      if (auto RD = dyn_cast<RecordDecl>(New))
+        RD->completeDefinition();
+    return nullptr;
+  } else {
+    return New;
+  }
 }
 
 void Sema::ActOnTagStartDefinition(Scope *S, Decl *TagD) {

Added: cfe/trunk/test/Index/pr20320.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/pr20320.cpp?rev=285275&view=auto
==============================================================================
--- cfe/trunk/test/Index/pr20320.cpp (added)
+++ cfe/trunk/test/Index/pr20320.cpp Thu Oct 27 03:37:14 2016
@@ -0,0 +1,2 @@
+// RUN: env CINDEXTEST_EDITING=1 c-index-test -test-load-source-reparse 5 local -x c++ %s
+#include "pr20320.h"

Added: cfe/trunk/test/Index/pr20320.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/pr20320.h?rev=285275&view=auto
==============================================================================
--- cfe/trunk/test/Index/pr20320.h (added)
+++ cfe/trunk/test/Index/pr20320.h Thu Oct 27 03:37:14 2016
@@ -0,0 +1,14 @@
+#ifndef pr20320_h
+#define pr20320_h
+
+template<>
+struct S< ::Number::One>
+{
+};
+
+template<>
+struct S< ::Number::Two>
+{
+};
+
+#endif

Modified: cfe/trunk/test/SemaCXX/conversion-function.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/conversion-function.cpp?rev=285275&r1=285274&r2=285275&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/conversion-function.cpp (original)
+++ cfe/trunk/test/SemaCXX/conversion-function.cpp Thu Oct 27 03:37:14 2016
@@ -434,8 +434,12 @@ namespace PR18234 {
   struct A {
     operator enum E { e } (); // expected-error {{'PR18234::A::E' cannot be defined in a type specifier}}
     operator struct S { int n; } (); // expected-error {{'PR18234::A::S' cannot be defined in a type specifier}}
+    // expected-note at -1 {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'struct A' to 'const PR18234::A::S &' for 1st argument}}
+#if __cplusplus >= 201103L
+  // expected-note at -3 {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'struct A' to 'PR18234::A::S &&' for 1st argument}}
+#endif
   } a;
-  A::S s = a;
+  A::S s = a; // expected-error {{no viable conversion from 'struct A' to 'A::S'}}
   A::E e = a; // expected-note {{here}}
   bool k1 = e == A::e; // expected-error {{no member named 'e'}}
   bool k2 = e.n == 0;




More information about the cfe-commits mailing list