[cfe-commits] r76109 - in /cfe/trunk: lib/CodeGen/CGExprScalar.cpp test/CodeGenObjC/object-incr-decr-1.m

Fariborz Jahanian fjahanian at apple.com
Thu Jul 16 15:04:59 PDT 2009


Author: fjahanian
Date: Thu Jul 16 17:04:59 2009
New Revision: 76109

URL: http://llvm.org/viewvc/llvm-project?rev=76109&view=rev
Log:
ir-gen for --/++ operators of objc object pointers
in 32bit abi.

Added:
    cfe/trunk/test/CodeGenObjC/object-incr-decr-1.m
Modified:
    cfe/trunk/lib/CodeGen/CGExprScalar.cpp

Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=76109&r1=76108&r2=76109&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Thu Jul 16 17:04:59 2009
@@ -690,7 +690,25 @@
     llvm::Constant *Inc =
       VMContext.getConstantInt(llvm::Type::Int32Ty, AmountVal);
     if (!isa<llvm::FunctionType>(PT->getElementType())) {
-      NextVal = Builder.CreateGEP(InVal, Inc, "ptrincdec");
+      QualType PTEE = ValTy->getPointeeType();
+      if (const ObjCInterfaceType *OIT = 
+          dyn_cast<ObjCInterfaceType>(PTEE)) {
+        // Handle interface types, which are not represented with a concrete type.
+        int size = CGF.getContext().getTypeSize(OIT) / 8;
+        if (!isInc)
+          size = -size;
+        Inc = VMContext.getConstantInt(Inc->getType(), size);
+        const llvm::Type *i8Ty = 
+          VMContext.getPointerTypeUnqual(llvm::Type::Int8Ty);
+        InVal = Builder.CreateBitCast(InVal, i8Ty);
+        NextVal = Builder.CreateGEP(InVal, Inc, "add.ptr");
+        llvm::Value *lhs = LV.getAddress();
+        lhs = Builder.CreateBitCast(lhs, VMContext.getPointerTypeUnqual(i8Ty));
+        LV = LValue::MakeAddr(lhs, ValTy.getCVRQualifiers(), 
+                              CGF.getContext().getObjCGCAttrKind(ValTy));
+      }
+      else
+        NextVal = Builder.CreateGEP(InVal, Inc, "ptrincdec");
     } else {
       const llvm::Type *i8Ty =
         VMContext.getPointerTypeUnqual(llvm::Type::Int8Ty);

Added: cfe/trunk/test/CodeGenObjC/object-incr-decr-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/object-incr-decr-1.m?rev=76109&view=auto

==============================================================================
--- cfe/trunk/test/CodeGenObjC/object-incr-decr-1.m (added)
+++ cfe/trunk/test/CodeGenObjC/object-incr-decr-1.m Thu Jul 16 17:04:59 2009
@@ -0,0 +1,19 @@
+// RUN: clang-cc -triple i386-apple-darwin9 -fnext-runtime -emit-llvm %s
+
+ at interface Foo 
+{
+	double d1,d3,d4;
+}
+ at end
+
+Foo* foo()
+{
+  Foo *f;
+  
+  // Both of these crash clang nicely
+  ++f;
+  --f;
+ f--;
+ f++;
+ return f;
+}





More information about the cfe-commits mailing list