From: Fariborz Jahanian Date: Wed, 23 Apr 2014 17:44:58 +0000 (+0000) Subject: Objective-C [IRGen]. Fixes a crash in IRGen involving use of X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5828a1d8e9e9876a89ddd52b8f5160723cfbdfda;p=clang Objective-C [IRGen]. Fixes a crash in IRGen involving use of 'typeof' to extract type of an @encode expression used in an initializer. // rdar://16655340 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@207004 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp index bce0475cbc..4e615922fe 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -836,7 +836,10 @@ public: // as an inline array. std::string Str; CGM.getContext().getObjCEncodingForType(E->getEncodedType(), Str); - const ConstantArrayType *CAT = cast(E->getType()); + QualType T = E->getType(); + if (T->getTypeClass() == Type::TypeOfExpr) + T = cast(T)->getUnderlyingExpr()->getType(); + const ConstantArrayType *CAT = cast(T); // Resize the string to the right size, adding zeros at the end, or // truncating as needed. diff --git a/test/CodeGenObjC/encode-test-6.m b/test/CodeGenObjC/encode-test-6.m index 54a4eb03d5..4e9c422203 100644 --- a/test/CodeGenObjC/encode-test-6.m +++ b/test/CodeGenObjC/encode-test-6.m @@ -53,3 +53,14 @@ typedef struct } @end // CHECK: private global [39 x i8] c"{?=\22presentationInstance\22^{SCNCamera}}\00" + +// rdar://16655340 +int i; +typeof(@encode(typeof(i))) e = @encode(typeof(i)); +const char * Test() +{ + return e; +} +// CHECK: @e = global [2 x i8] c"i\00", align 1 +// CHECK: define i8* @Test() +// CHECK: ret i8* getelementptr inbounds ([2 x i8]* @e, i32 0, i32 0) diff --git a/test/SemaObjC/encode-typeof-test.m b/test/SemaObjC/encode-typeof-test.m new file mode 100644 index 0000000000..2cda973968 --- /dev/null +++ b/test/SemaObjC/encode-typeof-test.m @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s +// rdar://16655340 +@protocol X, Y, Z; +@class Foo; + +@protocol Proto +@end + +@interface Intf +{ +id IVAR_x; +id IVAR_xy; +id IVAR_xyz; +Foo *IVAR_Fooxyz; +Class IVAR_Classx; +} +@end + +@implementation Intf +@end + +int main() +{ + int i; + typeof(@encode(typeof(i))) e = @encode(typeof(Intf)); // expected-warning {{initializer-string for char array is too long}} +}