[cfe-commits] r41954 - in /cfe/trunk: Parse/ParseObjc.cpp Sema/SemaDecl.cpp test/Sema/ivar-sem-check-1.m
Fariborz Jahanian
fjahanian at apple.com
Fri Sep 14 09:28:05 PDT 2007
Author: fjahanian
Date: Fri Sep 14 11:27:55 2007
New Revision: 41954
URL: http://llvm.org/viewvc/llvm-project?rev=41954&view=rev
Log:
Semantic analysis for objective-c ivars.
Added:
cfe/trunk/test/Sema/ivar-sem-check-1.m
Modified:
cfe/trunk/Parse/ParseObjc.cpp
cfe/trunk/Sema/SemaDecl.cpp
Modified: cfe/trunk/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/ParseObjc.cpp?rev=41954&r1=41953&r2=41954&view=diff
==============================================================================
--- cfe/trunk/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/Parse/ParseObjc.cpp Fri Sep 14 11:27:55 2007
@@ -661,6 +661,8 @@
if (AllIvarDecls.size()) { // Check for {} - no ivars in braces
Actions.ObjcAddInstanceVariable(interfaceDecl,
&AllIvarDecls[0], AllIvarDecls.size(), &AllVisibilities[0]);
+ Actions.ParseRecordBody(LBraceLoc, interfaceDecl,
+ &AllIvarDecls[0], AllIvarDecls.size());
}
MatchRHSPunctuation(tok::r_brace, LBraceLoc);
return;
Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=41954&r1=41953&r2=41954&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Fri Sep 14 11:27:55 2007
@@ -1092,10 +1092,13 @@
return NewFD;
}
+// FIXME: Change ParseRecordBody name to something more generic as
+// it also used for ivar semantics check.
void Sema::ParseRecordBody(SourceLocation RecLoc, DeclTy *RecDecl,
DeclTy **Fields, unsigned NumFields) {
- RecordDecl *Record = cast<RecordDecl>(static_cast<Decl*>(RecDecl));
- if (Record->isDefinition()) {
+ RecordDecl *Record =
+ dyn_cast_or_null<RecordDecl>(static_cast<Decl*>(RecDecl));
+ if (Record && Record->isDefinition()) {
// Diagnose code like:
// struct S { struct S {} X; };
// We discover this when we complete the outer S. Reject and ignore the
@@ -1110,9 +1113,13 @@
unsigned NumNamedMembers = 0;
llvm::SmallVector<FieldDecl*, 32> RecFields;
llvm::SmallSet<const IdentifierInfo*, 32> FieldIDs;
-
for (unsigned i = 0; i != NumFields; ++i) {
- FieldDecl *FD = cast_or_null<FieldDecl>(static_cast<Decl*>(Fields[i]));
+
+ FieldDecl *FD;
+ if (Record)
+ FD = cast_or_null<FieldDecl>(static_cast<Decl*>(Fields[i]));
+ else
+ FD = cast_or_null<ObjcIvarDecl>(static_cast<Decl*>(Fields[i]));
if (!FD) continue; // Already issued a diagnostic.
// Get the type for the field.
@@ -1128,6 +1135,11 @@
// C99 6.7.2.1p2 - A field may not be an incomplete type except...
if (FDTy->isIncompleteType()) {
+ if (!Record) { // Incomplete ivar type is always an error.
+ Diag(FD->getLocation(), diag::err_field_incomplete, FD->getName());
+ delete FD;
+ continue;
+ }
if (i != NumFields-1 || // ... that the last member ...
Record->getKind() != Decl::Struct || // ... of a structure ...
!FDTy->isArrayType()) { //... may have incomplete array type.
@@ -1135,7 +1147,7 @@
delete FD;
continue;
}
- if (NumNamedMembers < 1) { //... must have more than named member ...
+ if (NumNamedMembers < 1) { //... must have more than named member ...
Diag(FD->getLocation(), diag::err_flexible_array_empty_struct,
FD->getName());
delete FD;
@@ -1143,7 +1155,8 @@
}
// Okay, we have a legal flexible array member at the end of the struct.
- Record->setHasFlexibleArrayMember(true);
+ if (Record)
+ Record->setHasFlexibleArrayMember(true);
}
@@ -1152,7 +1165,7 @@
if (const RecordType *FDTTy = FDTy->getAsRecordType()) {
if (FDTTy->getDecl()->hasFlexibleArrayMember()) {
// If this is a member of a union, then entire union becomes "flexible".
- if (Record->getKind() == Decl::Union) {
+ if (Record && Record->getKind() == Decl::Union) {
Record->setHasFlexibleArrayMember(true);
} else {
// If this is a struct/class and this is not the last element, reject
@@ -1169,7 +1182,8 @@
// as an extension.
Diag(FD->getLocation(), diag::ext_flexible_array_in_struct,
FD->getName());
- Record->setHasFlexibleArrayMember(true);
+ if (Record)
+ Record->setHasFlexibleArrayMember(true);
}
}
}
@@ -1201,7 +1215,8 @@
// Okay, we successfully defined 'Record'.
- Record->defineBody(&RecFields[0], RecFields.size());
+ if (Record)
+ Record->defineBody(&RecFields[0], RecFields.size());
}
void Sema::ObjcAddMethodsToClass(DeclTy *ClassDecl,
Added: cfe/trunk/test/Sema/ivar-sem-check-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/ivar-sem-check-1.m?rev=41954&view=auto
==============================================================================
--- cfe/trunk/test/Sema/ivar-sem-check-1.m (added)
+++ cfe/trunk/test/Sema/ivar-sem-check-1.m Fri Sep 14 11:27:55 2007
@@ -0,0 +1,15 @@
+struct S;
+typedef int FOO();
+
+ at interface INTF
+{
+ struct F {} JJ;
+ int arr[]; // expected-error {{field 'arr' has incomplete type}}
+ struct S IC; // expected-error {{field 'IC' has incomplete type}}
+ struct T { struct T {} X; }YYY; // expected-error {{nested redefinition of 'struct'}}
+ FOO BADFUNC; // expected-error {{field 'BADFUNC' declared as a function}}
+ int kaka;
+ int kaka; // expected-error {{duplicate member 'kaka'}}
+ char ch[]; // expected-error {{field 'ch' has incomplete type}}
+}
+ at end
More information about the cfe-commits
mailing list