From 2b9fc83db5c892044f86a160a66f9709b8e44ff6 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Tue, 15 Dec 2009 21:34:52 +0000 Subject: [PATCH] Fixes a code gen bug related to accessing a now non-existing 'isa' field of a non-existing struct type all related to legacy type definition for 'id' which we have dropped in clang in favor of a built-in type. (fixes radar 7470820). llvm-svn: 91455 --- clang/lib/CodeGen/CGExpr.cpp | 1 + clang/lib/Sema/SemaExpr.cpp | 4 +++- clang/test/CodeGenObjC/id-isa-codegen.m | 9 +++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 8e1413386af4..c5a89e032b29 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -1389,6 +1389,7 @@ LValue CodeGenFunction::EmitCastLValue(const CastExpr *E) { case CastExpr::CK_NoOp: case CastExpr::CK_ConstructorConversion: case CastExpr::CK_UserDefinedConversion: + case CastExpr::CK_AnyPointerToObjCPointerCast: return EmitLValue(E->getSubExpr()); case CastExpr::CK_DerivedToBase: { diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index cda27cf68716..65c95b36aa07 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -3584,7 +3584,9 @@ static CastExpr::CastKind getScalarCastKind(ASTContext &Context, if (SrcTy->hasPointerRepresentation()) { if (DestTy->hasPointerRepresentation()) - return CastExpr::CK_BitCast; + return DestTy->isObjCObjectPointerType() ? + CastExpr::CK_AnyPointerToObjCPointerCast : + CastExpr::CK_BitCast; if (DestTy->isIntegerType()) return CastExpr::CK_PointerToIntegral; } diff --git a/clang/test/CodeGenObjC/id-isa-codegen.m b/clang/test/CodeGenObjC/id-isa-codegen.m index dc0bac3000e7..89e992209071 100644 --- a/clang/test/CodeGenObjC/id-isa-codegen.m +++ b/clang/test/CodeGenObjC/id-isa-codegen.m @@ -25,3 +25,12 @@ typedef struct objc_object { } @end + +// rdar 7470820 +static Class MyClass; + +Class Test(const void *inObject1) { + if(((id)inObject1)->isa == MyClass) + return ((id)inObject1)->isa; + return (id)0; +}