[cfe-commits] r139590 - in /cfe/trunk: include/clang/AST/CharUnits.h lib/CodeGen/CGObjC.cpp test/CodeGenObjC/property-aggregate.m
John McCall
rjmccall at apple.com
Tue Sep 13 00:33:35 PDT 2011
Author: rjmccall
Date: Tue Sep 13 02:33:34 2011
New Revision: 139590
URL: http://llvm.org/viewvc/llvm-project?rev=139590&view=rev
Log:
Don't use native atomics on ivars whose size is not a power of two,
even on architectures that support unaligned access (which is the
only way this is otherwise legal, given that ivars apparently do
not honor alignment attributes).
Added:
cfe/trunk/test/CodeGenObjC/property-aggregate.m
Modified:
cfe/trunk/include/clang/AST/CharUnits.h
cfe/trunk/lib/CodeGen/CGObjC.cpp
Modified: cfe/trunk/include/clang/AST/CharUnits.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/CharUnits.h?rev=139590&r1=139589&r2=139590&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/CharUnits.h (original)
+++ cfe/trunk/include/clang/AST/CharUnits.h Tue Sep 13 02:33:34 2011
@@ -125,6 +125,12 @@
/// isNegative - Test whether the quantity is less than zero.
bool isNegative() const { return Quantity < 0; }
+ /// isPowerOfTwo - Test whether the quantity is a power of two.
+ /// Zero is not a power of two.
+ bool isPowerOfTwo() const {
+ return (Quantity & -Quantity) == Quantity;
+ }
+
// Arithmetic operators.
CharUnits operator* (QuantityType N) const {
return CharUnits(Quantity * N);
Modified: cfe/trunk/lib/CodeGen/CGObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp?rev=139590&r1=139589&r2=139590&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjC.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjC.cpp Tue Sep 13 02:33:34 2011
@@ -527,6 +527,14 @@
// Otherwise, this is target-dependent and based on the size and
// alignment of the ivar.
+
+ // If the size of the ivar is not a power of two, give up. We don't
+ // want to get into the business of doing compare-and-swaps.
+ if (!IvarSize.isPowerOfTwo()) {
+ Kind = CopyStruct;
+ return;
+ }
+
llvm::Triple::ArchType arch =
CGM.getContext().getTargetInfo().getTriple().getArch();
Added: cfe/trunk/test/CodeGenObjC/property-aggregate.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/property-aggregate.m?rev=139590&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenObjC/property-aggregate.m (added)
+++ cfe/trunk/test/CodeGenObjC/property-aggregate.m Tue Sep 13 02:33:34 2011
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -fobjc-nonfragile-abi -emit-llvm %s -o - | FileCheck %s
+
+// This structure's size is not a power of two, so the property does
+// not get native atomics, even though x86-64 can do unaligned atomics
+// with a lock prefix.
+struct s3 { char c[3]; };
+
+// This structure's size is, so it does, because it can.
+struct s4 { char c[4]; };
+
+ at interface Test0
+ at property struct s3 s3;
+ at property struct s4 s4;
+ at end
+ at implementation Test0
+ at synthesize s3, s4;
+ at end
+
+// CHECK: define internal i24 @"\01-[Test0 s3]"(
+// CHECK: call void @objc_copyStruct
+
+// CHECK: define internal void @"\01-[Test0 setS3:]"(
+// CHECK: call void @objc_copyStruct
+
+// CHECK: define internal i32 @"\01-[Test0 s4]"(
+// CHECK: load atomic i32* {{%.*}} unordered, align 1
+
+// CHECK: define internal void @"\01-[Test0 setS4:]"(
+// CHECK: store atomic i32 {{%.*}}, i32* {{%.*}} unordered, align 1
More information about the cfe-commits
mailing list