forked from OSchip/llvm-project
Patch to issue error when target of MacOS and iOS
does not support large load/store of atomic objects. // rdar://13973577 llvm-svn: 182781
This commit is contained in:
parent
bac964e14f
commit
615de765ab
clang
include/clang
lib
test
|
@ -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;
|
||||
|
|
|
@ -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">;
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
Loading…
Reference in New Issue