r182781 - Patch to issue error when target of MacOS and iOS
Fariborz Jahanian
fjahanian at apple.com
Tue May 28 10:37:39 PDT 2013
Author: fjahanian
Date: Tue May 28 12:37:39 2013
New Revision: 182781
URL: http://llvm.org/viewvc/llvm-project?rev=182781&view=rev
Log:
Patch to issue error when target of MacOS and iOS
does not support large load/store of atomic objects.
// rdar://13973577
Added:
cfe/trunk/test/Sema/atomic-requires-library-error.c
Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/CodeGen/atomic-ops.c
Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=182781&r1=182780&r2=182781&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Tue May 28 12:37:39 2013
@@ -470,6 +470,8 @@ public:
const TargetInfo &getTargetInfo() const { return *Target; }
+ bool AtomicUsesUnsupportedLibcall(const AtomicExpr *E) const;
+
const LangOptions& getLangOpts() const { return LangOpts; }
DiagnosticsEngine &getDiagnostics() const;
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=182781&r1=182780&r2=182781&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue May 28 12:37:39 2013
@@ -5322,6 +5322,10 @@ def err_atomic_op_needs_atomic_int_or_pt
def err_atomic_op_bitwise_needs_atomic_int : Error<
"first argument to bitwise atomic operation must be a pointer to "
"%select{|atomic }0integer (%1 invalid)">;
+
+def err_atomic_load_store_uses_lib : Error<
+ "atomic %select{load|store}0 requires runtime support that is not "
+ "available for this target">;
def err_deleted_function_use : Error<"attempt to use a deleted function">;
Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=182781&r1=182780&r2=182781&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Tue May 28 12:37:39 2013
@@ -8030,3 +8030,17 @@ unsigned ASTContext::getParameterIndex(c
"ParmIndices lacks entry set by ParmVarDecl");
return I->second;
}
+
+bool ASTContext::AtomicUsesUnsupportedLibcall(const AtomicExpr *E) const {
+ const llvm::Triple &T = getTargetInfo().getTriple();
+ if (!T.isOSDarwin())
+ return false;
+
+ QualType AtomicTy = E->getPtr()->getType()->getPointeeType();
+ CharUnits sizeChars = getTypeSizeInChars(AtomicTy);
+ uint64_t Size = sizeChars.getQuantity();
+ CharUnits alignChars = getTypeAlignInChars(AtomicTy);
+ unsigned Align = alignChars.getQuantity();
+ unsigned MaxInlineWidthInBits = getTargetInfo().getMaxAtomicInlineWidth();
+ return (Size != Align || toBits(sizeChars) > MaxInlineWidthInBits);
+}
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=182781&r1=182780&r2=182781&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue May 28 12:37:39 2013
@@ -908,10 +908,18 @@ ExprResult Sema::SemaAtomicOpsOverloaded
SubExprs.push_back(TheCall->getArg(3)); // Weak
break;
}
+
+ AtomicExpr *AE = new (Context) AtomicExpr(TheCall->getCallee()->getLocStart(),
+ SubExprs, ResultType, Op,
+ TheCall->getRParenLoc());
+
+ if ((Op == AtomicExpr::AO__c11_atomic_load ||
+ (Op == AtomicExpr::AO__c11_atomic_store)) &&
+ Context.AtomicUsesUnsupportedLibcall(AE))
+ Diag(AE->getLocStart(), diag::err_atomic_load_store_uses_lib) <<
+ ((Op == AtomicExpr::AO__c11_atomic_load) ? 0 : 1);
- return Owned(new (Context) AtomicExpr(TheCall->getCallee()->getLocStart(),
- SubExprs, ResultType, Op,
- TheCall->getRParenLoc()));
+ return Owned(AE);
}
Modified: cfe/trunk/test/CodeGen/atomic-ops.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/atomic-ops.c?rev=182781&r1=182780&r2=182781&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/atomic-ops.c (original)
+++ cfe/trunk/test/CodeGen/atomic-ops.c Tue May 28 12:37:39 2013
@@ -246,9 +246,6 @@ _Atomic(struct foo) bigAtomic;
void structAtomicStore() {
// CHECK: @structAtomicStore
struct foo f = {0};
- __c11_atomic_store(&bigAtomic, f, 5);
- // CHECK: call void @__atomic_store(i32 512, i8* bitcast ({{.*}} @bigAtomic to i8*),
-
struct bar b = {0};
__atomic_store(&smallThing, &b, 5);
// CHECK: call void @__atomic_store(i32 3, i8* {{.*}} @smallThing
@@ -258,13 +255,11 @@ void structAtomicStore() {
}
void structAtomicLoad() {
// CHECK: @structAtomicLoad
- struct foo f = __c11_atomic_load(&bigAtomic, 5);
- // CHECK: call void @__atomic_load(i32 512, i8* bitcast ({{.*}} @bigAtomic to i8*),
-
struct bar b;
__atomic_load(&smallThing, &b, 5);
// CHECK: call void @__atomic_load(i32 3, i8* {{.*}} @smallThing
+ struct foo f = {0};
__atomic_load(&bigThing, &f, 5);
// CHECK: call void @__atomic_load(i32 512, i8* {{.*}} @bigThing
}
Added: cfe/trunk/test/Sema/atomic-requires-library-error.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/atomic-requires-library-error.c?rev=182781&view=auto
==============================================================================
--- cfe/trunk/test/Sema/atomic-requires-library-error.c (added)
+++ cfe/trunk/test/Sema/atomic-requires-library-error.c Tue May 28 12:37:39 2013
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 %s -triple=i686-apple-darwin9 -verify
+// rdar://13973577
+
+struct foo {
+ int big[128];
+};
+struct bar {
+ char c[3];
+};
+
+struct bar smallThing;
+struct foo bigThing;
+_Atomic(struct foo) bigAtomic;
+
+void structAtomicStore() {
+ struct foo f = {0};
+ __c11_atomic_store(&bigAtomic, f, 5); // expected-error {{atomic store requires runtime support that is not available for this target}}
+
+ struct bar b = {0};
+ __atomic_store(&smallThing, &b, 5);
+
+ __atomic_store(&bigThing, &f, 5);
+}
+
+void structAtomicLoad() {
+ struct foo f = __c11_atomic_load(&bigAtomic, 5); // expected-error {{atomic load requires runtime support that is not available for this target}}
+ struct bar b;
+ __atomic_load(&smallThing, &b, 5);
+
+ __atomic_load(&bigThing, &f, 5);
+}
More information about the cfe-commits
mailing list