[PATCH] D20407: [CodeGen][ObjC] zero-ext an i1 value to i8

Akira Hatanaka via cfe-commits cfe-commits at lists.llvm.org
Wed May 18 18:08:25 PDT 2016

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;




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]]
+ at interface A
+ at property(nonatomic) _Atomic(_Bool) p;
+ at end
+ at implementation A
+ at 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()));

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20407.57718.patch
Type: text/x-patch
Size: 1132 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160519/d6ff2e10/attachment.bin>

More information about the cfe-commits mailing list