Skip to content

Commit 797994d

Browse files
committed
[clang][Interp] Strip _Atomic from _Complex types
... when doing binary operations on them.
1 parent 0b0798b commit 797994d

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -685,11 +685,17 @@ bool ByteCodeExprGen<Emitter>::VisitComplexBinOp(const BinaryOperator *E) {
685685
if (!this->emitSetLocal(PT_Ptr, ResultOffset, E))
686686
return false;
687687
}
688+
QualType LHSType = LHS->getType();
689+
if (const auto *AT = LHSType->getAs<AtomicType>())
690+
LHSType = AT->getValueType();
691+
QualType RHSType = RHS->getType();
692+
if (const auto *AT = RHSType->getAs<AtomicType>())
693+
RHSType = AT->getValueType();
688694

689695
// Evaluate LHS and save value to LHSOffset.
690696
bool LHSIsComplex;
691697
unsigned LHSOffset;
692-
if (LHS->getType()->isAnyComplexType()) {
698+
if (LHSType->isAnyComplexType()) {
693699
LHSIsComplex = true;
694700
LHSOffset = this->allocateLocalPrimitive(LHS, PT_Ptr, true, false);
695701
if (!this->visit(LHS))
@@ -698,7 +704,7 @@ bool ByteCodeExprGen<Emitter>::VisitComplexBinOp(const BinaryOperator *E) {
698704
return false;
699705
} else {
700706
LHSIsComplex = false;
701-
PrimType LHST = classifyPrim(LHS->getType());
707+
PrimType LHST = classifyPrim(LHSType);
702708
LHSOffset = this->allocateLocalPrimitive(LHS, LHST, true, false);
703709
if (!this->visit(LHS))
704710
return false;
@@ -709,7 +715,7 @@ bool ByteCodeExprGen<Emitter>::VisitComplexBinOp(const BinaryOperator *E) {
709715
// Same with RHS.
710716
bool RHSIsComplex;
711717
unsigned RHSOffset;
712-
if (RHS->getType()->isAnyComplexType()) {
718+
if (RHSType->isAnyComplexType()) {
713719
RHSIsComplex = true;
714720
RHSOffset = this->allocateLocalPrimitive(RHS, PT_Ptr, true, false);
715721
if (!this->visit(RHS))
@@ -718,7 +724,7 @@ bool ByteCodeExprGen<Emitter>::VisitComplexBinOp(const BinaryOperator *E) {
718724
return false;
719725
} else {
720726
RHSIsComplex = false;
721-
PrimType RHST = classifyPrim(RHS->getType());
727+
PrimType RHST = classifyPrim(RHSType);
722728
RHSOffset = this->allocateLocalPrimitive(RHS, RHST, true, false);
723729
if (!this->visit(RHS))
724730
return false;

clang/test/AST/Interp/complex.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,12 @@ const _Complex float FC = {0.0f, 0.0f};
1919
_Static_assert(!FC, "");
2020
const _Complex float FI = {0, 0};
2121
_Static_assert(!FI, "");
22+
23+
24+
/// Make sure we're stripping the _Atomic part from the
25+
/// complex type.
26+
void testComplexFloat(_Atomic(_Complex float) *fp) {
27+
_Atomic(_Complex float) x = 2.0f;
28+
_Complex float f = *fp;
29+
*fp = f;
30+
}

0 commit comments

Comments
 (0)