]> granicus.if.org Git - clang/commitdiff
Patch to issue error when target of MacOS and iOS
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 28 May 2013 17:37:39 +0000 (17:37 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 28 May 2013 17:37:39 +0000 (17:37 +0000)
does not support large load/store of atomic objects.
// rdar://13973577

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182781 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/ASTContext.h
include/clang/Basic/DiagnosticSemaKinds.td
lib/AST/ASTContext.cpp
lib/Sema/SemaChecking.cpp
test/CodeGen/atomic-ops.c
test/Sema/atomic-requires-library-error.c [new file with mode: 0644]

index 94dad6bbc3ab4add83f823b8c0b4de12100ee281..b69a4f4525d843f9b630884cb1b945af1d9b18bd 100644 (file)
@@ -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;
index f64df9c6b4682205c17657490c4d832d53d57a74..130f729a6008480960df977c06fb0d69eb9a1c36 100644 (file)
@@ -5322,6 +5322,10 @@ def err_atomic_op_needs_atomic_int_or_ptr : Error<
 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">;
 
index f5e4b42d2769ee5e9dea2c06b81beb727fbcf42a..946d3df86c2be00884cf3b49896ab9a41174b4d3 100644 (file)
@@ -8030,3 +8030,17 @@ unsigned ASTContext::getParameterIndex(const ParmVarDecl *D) const {
          "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);
+}
index cdc546c476197d32592c52bc65048e8782a5f421..da24667804b5d361217b613646b6ef538eca8710 100644 (file)
@@ -908,10 +908,18 @@ ExprResult Sema::SemaAtomicOpsOverloaded(ExprResult TheCallResult,
     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);
 }
 
 
index d79f4052234424f5d1eebe9ad6f415640cd2421e..830f21a569aa5fec464c24bdc2ded97cc9360aec 100644 (file)
@@ -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
 }
diff --git a/test/Sema/atomic-requires-library-error.c b/test/Sema/atomic-requires-library-error.c
new file mode 100644 (file)
index 0000000..b0aa278
--- /dev/null
@@ -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);
+}