[cfe-commits] r62349 - in /cfe/trunk: lib/AST/ASTContext.cpp lib/Sema/SemaDecl.cpp test/SemaObjC/id-1.m
Fariborz Jahanian
fjahanian at apple.com
Fri Jan 16 11:58:32 PST 2009
Author: fjahanian
Date: Fri Jan 16 13:58:32 2009
New Revision: 62349
URL: http://llvm.org/viewvc/llvm-project?rev=62349&view=rev
Log:
Don't ICE on user redeclaration of objc's built-in types.
Issue diagnostics instead if types do not match.
Added:
cfe/trunk/test/SemaObjC/id-1.m
Modified:
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=62349&r1=62348&r2=62349&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Fri Jan 16 13:58:32 2009
@@ -2012,9 +2012,13 @@
// typedef struct objc_object *id;
const PointerType *ptr = TD->getUnderlyingType()->getAsPointerType();
- assert(ptr && "'id' incorrectly typed");
+ // User error - caller will issue diagnostics.
+ if (!ptr)
+ return;
const RecordType *rec = ptr->getPointeeType()->getAsStructureType();
- assert(rec && "'id' incorrectly typed");
+ // User error - caller will issue diagnostics.
+ if (!rec)
+ return;
IdStructType = rec;
}
@@ -2024,9 +2028,11 @@
// typedef struct objc_selector *SEL;
const PointerType *ptr = TD->getUnderlyingType()->getAsPointerType();
- assert(ptr && "'SEL' incorrectly typed");
+ if (!ptr)
+ return;
const RecordType *rec = ptr->getPointeeType()->getAsStructureType();
- assert(rec && "'SEL' incorrectly typed");
+ if (!rec)
+ return;
SelStructType = rec;
}
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=62349&r1=62348&r2=62349&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Jan 16 13:58:32 2009
@@ -358,6 +358,7 @@
/// situation, merging decls or emitting diagnostics as appropriate.
///
TypedefDecl *Sema::MergeTypeDefDecl(TypedefDecl *New, Decl *OldD) {
+ bool objc_types = false;
// Allow multiple definitions for ObjC built-in typedefs.
// FIXME: Verify the underlying types are equivalent!
if (getLangOptions().ObjC1) {
@@ -368,21 +369,25 @@
if (!TypeID->isStr("id"))
break;
Context.setObjCIdType(New);
- return New;
+ objc_types = true;
+ break;
case 5:
if (!TypeID->isStr("Class"))
break;
Context.setObjCClassType(New);
+ objc_types = true;
return New;
case 3:
if (!TypeID->isStr("SEL"))
break;
Context.setObjCSelType(New);
+ objc_types = true;
return New;
case 8:
if (!TypeID->isStr("Protocol"))
break;
Context.setObjCProtoType(New->getUnderlyingType());
+ objc_types = true;
return New;
}
// Fall through - the typedef name was not a builtin type.
@@ -392,7 +397,8 @@
if (!Old) {
Diag(New->getLocation(), diag::err_redefinition_different_kind)
<< New->getDeclName();
- Diag(OldD->getLocation(), diag::note_previous_definition);
+ if (!objc_types)
+ Diag(OldD->getLocation(), diag::note_previous_definition);
return New;
}
@@ -403,10 +409,11 @@
Context.getCanonicalType(New->getUnderlyingType())) {
Diag(New->getLocation(), diag::err_redefinition_different_typedef)
<< New->getUnderlyingType() << Old->getUnderlyingType();
- Diag(Old->getLocation(), diag::note_previous_definition);
+ if (!objc_types)
+ Diag(Old->getLocation(), diag::note_previous_definition);
return New;
}
-
+ if (objc_types) return New;
if (getLangOptions().Microsoft) return New;
// C++ [dcl.typedef]p2:
Added: cfe/trunk/test/SemaObjC/id-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/id-1.m?rev=62349&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/id-1.m (added)
+++ cfe/trunk/test/SemaObjC/id-1.m Fri Jan 16 13:58:32 2009
@@ -0,0 +1,6 @@
+// RUN: clang -fsyntax-only -verify %s
+/* Test attempt to redefine 'id' in an incompatible fashion. */
+
+typedef int id; // expected-error {{typedef redefinition with different types}}
+
+id b;
More information about the cfe-commits
mailing list