CodeGen: _Atomic(_Complex) shouldn't crash

We could be a little kinder if we did a compare-exchange loop instead of
an atomic-load/store pair.

llvm-svn: 229212
This commit is contained in:
David Majnemer 2015-02-14 01:48:17 +00:00
parent 7ddf832e0e
commit ce27e42d47
3 changed files with 16 additions and 2 deletions

View File

@ -820,10 +820,14 @@ LValue CodeGenFunction::EmitLValue(const Expr *E) {
return EmitObjCIsaExpr(cast<ObjCIsaExpr>(E));
case Expr::BinaryOperatorClass:
return EmitBinaryOperatorLValue(cast<BinaryOperator>(E));
case Expr::CompoundAssignOperatorClass:
if (!E->getType()->isAnyComplexType())
case Expr::CompoundAssignOperatorClass: {
QualType Ty = E->getType();
if (const AtomicType *AT = Ty->getAs<AtomicType>())
Ty = AT->getValueType();
if (!Ty->isAnyComplexType())
return EmitCompoundAssignmentLValue(cast<CompoundAssignOperator>(E));
return EmitComplexCompoundAssignmentLValue(cast<CompoundAssignOperator>(E));
}
case Expr::CallExprClass:
case Expr::CXXMemberCallExprClass:
case Expr::CXXOperatorCallExprClass:

View File

@ -820,6 +820,8 @@ EmitCompoundAssignLValue(const CompoundAssignOperator *E,
TestAndClearIgnoreReal();
TestAndClearIgnoreImag();
QualType LHSTy = E->getLHS()->getType();
if (const AtomicType *AT = LHSTy->getAs<AtomicType>())
LHSTy = AT->getValueType();
BinOpInfo OpInfo;

View File

@ -26,3 +26,11 @@ _Bool bar() {
// CHECK: ret i1 %[[tobool]]
return b;
}
extern _Atomic(_Complex int) x;
void baz(int y) {
// CHECK-LABEL: @baz
// CHECK: store atomic
x += y;
}