[cfe-commits] r99150 - in /cfe/trunk: lib/Sema/SemaDecl.cpp lib/Sema/SemaType.cpp test/Sema/nested-redef.c test/SemaCXX/PR6618.cpp test/SemaObjC/ivar-sem-check-1.m
Rafael Espindola
rafael.espindola at gmail.com
Sun Mar 21 15:56:43 PDT 2010
Author: rafael
Date: Sun Mar 21 17:56:43 2010
New Revision: 99150
URL: http://llvm.org/viewvc/llvm-project?rev=99150&view=rev
Log:
Fix PR6618.
If a struct has an invalid field, mark it as invalid. Also avoid producing
errors about incomplete types that are invalid.
Added:
cfe/trunk/test/SemaCXX/PR6618.cpp
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/Sema/nested-redef.c
cfe/trunk/test/SemaObjC/ivar-sem-check-1.m
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=99150&r1=99149&r2=99150&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sun Mar 21 17:56:43 2010
@@ -5261,6 +5261,10 @@
FieldDecl *NewFD
= CheckFieldDecl(II, T, TInfo, Record, Loc, Mutable, BitWidth, TSSL,
AS, PrevDecl, &D);
+
+ if (NewFD->isInvalidDecl())
+ Record->setInvalidDecl();
+
if (NewFD->isInvalidDecl() && PrevDecl) {
// Don't introduce NewFD into scope; there's already something
// with the same name in the same scope.
Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=99150&r1=99149&r2=99150&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Sun Mar 21 17:56:43 2010
@@ -1942,6 +1942,16 @@
if (diag == 0)
return true;
+ const TagType *Tag = 0;
+ if (const RecordType *Record = T->getAs<RecordType>())
+ Tag = Record;
+ else if (const EnumType *Enum = T->getAs<EnumType>())
+ Tag = Enum;
+
+ // Avoid diagnosing invalid decls as incomplete.
+ if (Tag && Tag->getDecl()->isInvalidDecl())
+ return true;
+
// We have an incomplete type. Produce a diagnostic.
Diag(Loc, PD) << T;
@@ -1950,13 +1960,7 @@
Diag(Note.first, Note.second);
// If the type was a forward declaration of a class/struct/union
- // type, produce
- const TagType *Tag = 0;
- if (const RecordType *Record = T->getAs<RecordType>())
- Tag = Record;
- else if (const EnumType *Enum = T->getAs<EnumType>())
- Tag = Enum;
-
+ // type, produce a note.
if (Tag && !Tag->getDecl()->isInvalidDecl())
Diag(Tag->getDecl()->getLocation(),
Tag->isBeingDefined() ? diag::note_type_being_defined
Modified: cfe/trunk/test/Sema/nested-redef.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/nested-redef.c?rev=99150&r1=99149&r2=99150&view=diff
==============================================================================
--- cfe/trunk/test/Sema/nested-redef.c (original)
+++ cfe/trunk/test/Sema/nested-redef.c Sun Mar 21 17:56:43 2010
@@ -1,7 +1,6 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
struct X { // expected-note{{previous definition is here}}
- struct X { } x; // expected-error{{nested redefinition of 'X'}} \
- // expected-error{{field has incomplete type}}
+ struct X { } x; // expected-error{{nested redefinition of 'X'}}
};
struct Y { };
Added: cfe/trunk/test/SemaCXX/PR6618.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/PR6618.cpp?rev=99150&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/PR6618.cpp (added)
+++ cfe/trunk/test/SemaCXX/PR6618.cpp Sun Mar 21 17:56:43 2010
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+class bar; // expected-note {{forward declaration of 'bar'}}
+struct zed {
+ bar g; // expected-error {{field has incomplete type}}
+};
+class baz {
+ zed h;
+};
+void f() {
+ enum {
+ e = sizeof(baz)
+ };
+}
Modified: cfe/trunk/test/SemaObjC/ivar-sem-check-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/ivar-sem-check-1.m?rev=99150&r1=99149&r2=99150&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/ivar-sem-check-1.m (original)
+++ cfe/trunk/test/SemaObjC/ivar-sem-check-1.m Sun Mar 21 17:56:43 2010
@@ -9,8 +9,7 @@
int arr[]; // expected-error {{field has incomplete type}}
struct S IC; // expected-error {{field has incomplete type}}
struct T { // expected-note {{previous definition is here}}
- struct T {} X; // expected-error {{nested redefinition of 'T'}} \
- // expected-error {{field has incomplete type}}
+ struct T {} X; // expected-error {{nested redefinition of 'T'}}
}YYY;
FOO BADFUNC; // expected-error {{field 'BADFUNC' declared as a function}}
int kaka; // expected-note {{previous declaration is here}}
More information about the cfe-commits
mailing list