r207004 - Objective-C [IRGen]. Fixes a crash in IRGen involving use of

Fariborz Jahanian fjahanian at apple.com
Wed Apr 23 10:44:59 PDT 2014


Author: fjahanian
Date: Wed Apr 23 12:44:58 2014
New Revision: 207004

URL: http://llvm.org/viewvc/llvm-project?rev=207004&view=rev
Log:
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

Added:
    cfe/trunk/test/SemaObjC/encode-typeof-test.m
Modified:
    cfe/trunk/lib/CodeGen/CGExprConstant.cpp
    cfe/trunk/test/CodeGenObjC/encode-test-6.m

Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=207004&r1=207003&r2=207004&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Wed Apr 23 12:44:58 2014
@@ -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.

Modified: cfe/trunk/test/CodeGenObjC/encode-test-6.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/encode-test-6.m?rev=207004&r1=207003&r2=207004&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenObjC/encode-test-6.m (original)
+++ cfe/trunk/test/CodeGenObjC/encode-test-6.m Wed Apr 23 12:44:58 2014
@@ -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)

Added: cfe/trunk/test/SemaObjC/encode-typeof-test.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/encode-typeof-test.m?rev=207004&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/encode-typeof-test.m (added)
+++ cfe/trunk/test/SemaObjC/encode-typeof-test.m Wed Apr 23 12:44:58 2014
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1  -fsyntax-only -verify -Wno-objc-root-class %s
+// rdar://16655340
+ at protocol X, Y, Z;
+ at class Foo;
+
+ at protocol Proto
+ at end
+
+ at 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;
+}
+ at end
+
+ at implementation Intf 
+ at end
+
+int main()
+{
+    int i;
+    typeof(@encode(typeof(i))) e = @encode(typeof(Intf)); // expected-warning {{initializer-string for char array is too long}}
+}





More information about the cfe-commits mailing list