[cfe-commits] r61068 - in /cfe/trunk: lib/AST/DeclObjC.cpp lib/Sema/SemaDecl.cpp test/SemaObjC/duplicate-ivar-check.m
Fariborz Jahanian
fjahanian at apple.com
Mon Dec 15 17:08:35 PST 2008
Author: fjahanian
Date: Mon Dec 15 19:08:35 2008
New Revision: 61068
URL: http://llvm.org/viewvc/llvm-project?rev=61068&view=rev
Log:
Diagnose that ivars in current and super class may not
be duplicates and a test case.
Added:
cfe/trunk/test/SemaObjC/duplicate-ivar-check.m
Modified:
cfe/trunk/lib/AST/DeclObjC.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
Modified: cfe/trunk/lib/AST/DeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=61068&r1=61067&r2=61068&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Mon Dec 15 19:08:35 2008
@@ -345,7 +345,8 @@
for (ObjCInterfaceDecl::ivar_iterator I = ivar_begin(),
E = ivar_end(); I != E; ++I) {
ObjCIvarDecl *IVDecl = (*I);
- Fields.push_back(cast<FieldDecl>(IVDecl));
+ if (!IVDecl->isInvalidDecl())
+ Fields.push_back(cast<FieldDecl>(IVDecl));
}
}
@@ -390,7 +391,8 @@
/// FIXME! Can do collection of ivars and adding to the record while
/// doing it.
for (unsigned int i = 0; i != RecFields.size(); i++) {
- FieldDecl *Field = FieldDecl::Create(Context, RD, SourceLocation(),
+ FieldDecl *Field = FieldDecl::Create(Context, RD,
+ RecFields[i]->getLocation(),
RecFields[i]->getIdentifier(),
RecFields[i]->getType(),
RecFields[i]->getBitWidth(), false, 0);
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=61068&r1=61067&r2=61068&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Dec 15 19:08:35 2008
@@ -3091,6 +3091,25 @@
if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(EnclosingDecl)) {
ID->addInstanceVariablesToClass(ClsFields, RecFields.size(), RBrac);
ID->addRecordToClass(Context);
+ // Must enforce the rule that ivars in the base classes may not be
+ // duplicates.
+ FieldIDs.clear();
+ RecordDecl *RD = ID->getRecordForDecl();
+ for (RecordDecl::field_iterator i = RD->field_begin(),
+ e = RD->field_end(); i != e; ++i) {
+ FieldDecl *FD = *i;
+ if (IdentifierInfo *II = FD->getIdentifier())
+ if (!FieldIDs.insert(II)) {
+ Diag(FD->getLocation(), diag::err_duplicate_member) << II;
+ FD->setInvalidDecl();
+ for (RecordDecl::field_iterator j = RD->field_begin(),
+ e1 = RD->field_end(); j != e1; ++j)
+ if (II == (*j)->getIdentifier()) {
+ Diag((*j)->getLocation(), diag::note_previous_definition);
+ break;
+ }
+ }
+ }
}
else if (ObjCImplementationDecl *IMPDecl =
dyn_cast<ObjCImplementationDecl>(EnclosingDecl)) {
Added: cfe/trunk/test/SemaObjC/duplicate-ivar-check.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/duplicate-ivar-check.m?rev=61068&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/duplicate-ivar-check.m (added)
+++ cfe/trunk/test/SemaObjC/duplicate-ivar-check.m Mon Dec 15 19:08:35 2008
@@ -0,0 +1,20 @@
+// RUN: clang -fsyntax-only -verify %s
+
+ at interface B1 {
+ at public
+ double fill_B; // expected-note {{previous definition is here}}
+}
+ at end
+
+ at interface B : B1 {
+ at public
+ int one; // expected-note {{previous definition is here}}
+ int one; // expected-error {{duplicate member 'one'}}
+}
+ at end
+
+ at interface A : B {
+ at public
+ int fill_B; // expected-error {{duplicate member 'fill_B'}}
+}
+ at end
More information about the cfe-commits
mailing list