ahatanak created this revision.
ahatanak added a reviewer: rjmccall.
ahatanak added a subscriber: cfe-commits.

This patch fixes an assert that fires when there is a property that has 
attribute nonatomic and type _Atomic(_Bool). The assert fires when an i1 value 
is bitcast to i8 (which is the type ConvertType(propType) returns).

I have a couple of questions as I wasn't sure this was the right way to fix the 
assert.

1. Is it legal to have attribute nonatomic on a property that has an atomic 
type? Should clang error out?
2. Should the return type of the getter method be i1 or i8? I chose not to 
change the return type (which was i8), but I think there are cases where 
changing it to i1 might make more sense. For example, the following code 
currently doesn't compile because foo1 and the getter for "p" (which is the 
property of A in the test case) have different return types.

```
_Bool foo1() {
  A *a = [A new];
  return i.p;
}
```

rdar://problem/26322972

http://reviews.llvm.org/D20407

Files:
  lib/CodeGen/CGObjC.cpp
  test/CodeGenObjC/property-atomic-bool.m

Index: test/CodeGenObjC/property-atomic-bool.m
===================================================================
--- /dev/null
+++ test/CodeGenObjC/property-atomic-bool.m
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10 -emit-llvm -x objective-c %s 
-o - | FileCheck %s
+
+// CHECK: define internal i8 @"\01-[A p]"(
+// CHECK:   %[[ATOMIC_LOAD:.*]] = load atomic i8, i8* %{{.*}} seq_cst
+// CHECK:   %[[TOBOOL:.*]] = trunc i8 %[[ATOMIC_LOAD]] to i1
+// CHECK:   %[[RETVAL:.*]] = zext i1 %[[TOBOOL]] to i8
+// CHECK:   ret i8 %[[RETVAL]]
+
+@interface A
+@property(nonatomic) _Atomic(_Bool) p;
+@end
+@implementation A
+@end
Index: lib/CodeGen/CGObjC.cpp
===================================================================
--- lib/CodeGen/CGObjC.cpp
+++ lib/CodeGen/CGObjC.cpp
@@ -1010,7 +1010,7 @@
           AutoreleaseResult = false;
         }
 
-        value = Builder.CreateBitCast(value, ConvertType(propType));
+        value = Builder.CreateZExtOrBitCast(value, ConvertType(propType));
         value = Builder.CreateBitCast(
             value, ConvertType(GetterMethodDecl->getReturnType()));
       }


Index: test/CodeGenObjC/property-atomic-bool.m
===================================================================
--- /dev/null
+++ test/CodeGenObjC/property-atomic-bool.m
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10 -emit-llvm -x objective-c %s -o - | FileCheck %s
+
+// CHECK: define internal i8 @"\01-[A p]"(
+// CHECK:   %[[ATOMIC_LOAD:.*]] = load atomic i8, i8* %{{.*}} seq_cst
+// CHECK:   %[[TOBOOL:.*]] = trunc i8 %[[ATOMIC_LOAD]] to i1
+// CHECK:   %[[RETVAL:.*]] = zext i1 %[[TOBOOL]] to i8
+// CHECK:   ret i8 %[[RETVAL]]
+
+@interface A
+@property(nonatomic) _Atomic(_Bool) p;
+@end
+@implementation A
+@end
Index: lib/CodeGen/CGObjC.cpp
===================================================================
--- lib/CodeGen/CGObjC.cpp
+++ lib/CodeGen/CGObjC.cpp
@@ -1010,7 +1010,7 @@
           AutoreleaseResult = false;
         }
 
-        value = Builder.CreateBitCast(value, ConvertType(propType));
+        value = Builder.CreateZExtOrBitCast(value, ConvertType(propType));
         value = Builder.CreateBitCast(
             value, ConvertType(GetterMethodDecl->getReturnType()));
       }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to