From: Fariborz Jahanian Date: Fri, 16 Jan 2009 19:58:32 +0000 (+0000) Subject: Don't ICE on user redeclaration of objc's built-in types. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c55a24095c3488fa6e99b537be64e57a2905477b;p=clang Don't ICE on user redeclaration of objc's built-in types. Issue diagnostics instead if types do not match. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62349 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index fe868d0768..8e7410c47c 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -2012,9 +2012,13 @@ void ASTContext::setObjCIdType(TypedefDecl *TD) // 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 @@ void ASTContext::setObjCSelType(TypedefDecl *TD) // 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; } diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 1d6b659e65..cfd33f6123 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -358,6 +358,7 @@ NamespaceDecl *Sema::GetStdNamespace() { /// 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 @@ TypedefDecl *Sema::MergeTypeDefDecl(TypedefDecl *New, Decl *OldD) { 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 @@ TypedefDecl *Sema::MergeTypeDefDecl(TypedefDecl *New, Decl *OldD) { 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 @@ TypedefDecl *Sema::MergeTypeDefDecl(TypedefDecl *New, Decl *OldD) { 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: diff --git a/test/SemaObjC/id-1.m b/test/SemaObjC/id-1.m new file mode 100644 index 0000000000..758f10112b --- /dev/null +++ b/test/SemaObjC/id-1.m @@ -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;