diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index 9951d8794b89..70373031bb26 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -1015,6 +1015,9 @@ Value *ScalarExprEmitter::EmitCompare(const BinaryOperator *E,unsigned UICmpOpc, LHS, RHS, "cmp"); } else { // Unsigned integers and pointers. + // Casting becomes necessary with -fobjc-gc as one or the other my turn + // into an 'id' type due to generation of read barriers. + RHS = Builder.CreateBitCast(RHS, LHS->getType()); Result = Builder.CreateICmp((llvm::ICmpInst::Predicate)UICmpOpc, LHS, RHS, "cmp"); } diff --git a/clang/test/CodeGenObjC/objc2-weak-compare.m b/clang/test/CodeGenObjC/objc2-weak-compare.m new file mode 100644 index 000000000000..5889b1ff8db4 --- /dev/null +++ b/clang/test/CodeGenObjC/objc2-weak-compare.m @@ -0,0 +1,24 @@ +// RUN: clang -fnext-runtime -fobjc-gc -emit-llvm -o %t %s + +@interface PBXTarget +{ + +PBXTarget * __weak _lastKnownTarget; +PBXTarget * __weak _KnownTarget; +PBXTarget * result; +} +- Meth; +@end + +@implementation PBXTarget +- Meth { + if (_lastKnownTarget != result) + foo(); + if (result != _lastKnownTarget) + foo(); + + if (_lastKnownTarget != _KnownTarget) + foo(); +} + +@end