]> granicus.if.org Git - clang/commitdiff
ir-gen for --/++ operators of objc object pointers
authorFariborz Jahanian <fjahanian@apple.com>
Thu, 16 Jul 2009 22:04:59 +0000 (22:04 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Thu, 16 Jul 2009 22:04:59 +0000 (22:04 +0000)
in 32bit abi.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@76109 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExprScalar.cpp
test/CodeGenObjC/object-incr-decr-1.m [new file with mode: 0644]

index 0316116631ad8ca48acd3c4a5525fe0a8eefd5da..8103506c2f478f9a146c079afc143ba9c7b2d138 100644 (file)
@@ -690,7 +690,25 @@ Value *ScalarExprEmitter::VisitPrePostIncDec(const UnaryOperator *E,
     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);
diff --git a/test/CodeGenObjC/object-incr-decr-1.m b/test/CodeGenObjC/object-incr-decr-1.m
new file mode 100644 (file)
index 0000000..96c2182
--- /dev/null
@@ -0,0 +1,19 @@
+// RUN: clang-cc -triple i386-apple-darwin9 -fnext-runtime -emit-llvm %s
+
+@interface Foo 
+{
+       double d1,d3,d4;
+}
+@end
+
+Foo* foo()
+{
+  Foo *f;
+  
+  // Both of these crash clang nicely
+  ++f;
+  --f;
+ f--;
+ f++;
+ return f;
+}