]> granicus.if.org Git - clang/commitdiff
Objective-C [IRGen]. Fixes a crash in IRGen involving use of
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 23 Apr 2014 17:44:58 +0000 (17:44 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 23 Apr 2014 17:44:58 +0000 (17:44 +0000)
'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

lib/CodeGen/CGExprConstant.cpp
test/CodeGenObjC/encode-test-6.m
test/SemaObjC/encode-typeof-test.m [new file with mode: 0644]

index bce0475cbc0973b9062e0248bc2e17b4b98df26f..4e615922fe2da836a8f3f76336684be458cdd4fb 100644 (file)
@@ -836,7 +836,10 @@ public:
     // as an inline array.
     std::string Str;
     CGM.getContext().getObjCEncodingForType(E->getEncodedType(), Str);
-    const ConstantArrayType *CAT = cast<ConstantArrayType>(E->getType());
+    QualType T = E->getType();
+    if (T->getTypeClass() == Type::TypeOfExpr)
+      T = cast<TypeOfExprType>(T)->getUnderlyingExpr()->getType();
+    const ConstantArrayType *CAT = cast<ConstantArrayType>(T);
 
     // Resize the string to the right size, adding zeros at the end, or
     // truncating as needed.
index 54a4eb03d5cb5a14cd8fdcf293e26cc16dd6c5e7..4e9c4222033f58a236bbf745f4ca87f4bf667ef8 100644 (file)
@@ -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 (file)
index 0000000..2cda973
--- /dev/null
@@ -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 <Proto>
+{
+id <X> IVAR_x;
+id <X, Y> IVAR_xy;
+id <X, Y, Z> IVAR_xyz;
+Foo <X, Y, Z> *IVAR_Fooxyz;
+Class <X> 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}}
+}