Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions clang/lib/AST/ByteCode/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2827,10 +2827,10 @@ bool Compiler<Emitter>::VisitCompoundAssignOperator(
return false;
if (!this->emitLoad(*LT, E))
return false;
if (LT != LHSComputationT) {
if (!this->emitCast(*LT, *LHSComputationT, E))
return false;
}
if (LT != LHSComputationT &&
!this->emitIntegralCast(*LT, *LHSComputationT, E->getComputationLHSType(),
E))
return false;

// Get the RHS value on the stack.
if (!this->emitGetLocal(*RT, TempOffset, E))
Expand Down Expand Up @@ -2883,10 +2883,9 @@ bool Compiler<Emitter>::VisitCompoundAssignOperator(
}

// And now cast from LHSComputationT to ResultT.
if (ResultT != LHSComputationT) {
if (!this->emitCast(*LHSComputationT, *ResultT, E))
return false;
}
if (ResultT != LHSComputationT &&
!this->emitIntegralCast(*LHSComputationT, *ResultT, E->getType(), E))
return false;

// And store the result in LHS.
if (DiscardResult) {
Expand Down Expand Up @@ -7243,6 +7242,19 @@ bool Compiler<Emitter>::emitPrimCast(PrimType FromT, PrimType ToT,
return false;
}

template <class Emitter>
bool Compiler<Emitter>::emitIntegralCast(PrimType FromT, PrimType ToT,
QualType ToQT, const Expr *E) {
assert(FromT != ToT);

if (ToT == PT_IntAP)
return this->emitCastAP(FromT, Ctx.getBitWidth(ToQT), E);
if (ToT == PT_IntAPS)
return this->emitCastAPS(FromT, Ctx.getBitWidth(ToQT), E);

return this->emitCast(FromT, ToT, E);
}

/// Emits __real(SubExpr)
template <class Emitter>
bool Compiler<Emitter>::emitComplexReal(const Expr *SubExpr) {
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/AST/ByteCode/Compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,8 @@ class Compiler : public ConstStmtVisitor<Compiler<Emitter>, bool>,
}

bool emitPrimCast(PrimType FromT, PrimType ToT, QualType ToQT, const Expr *E);
bool emitIntegralCast(PrimType FromT, PrimType ToT, QualType ToQT,
const Expr *E);
PrimType classifyComplexElementType(QualType T) const {
assert(T->isAnyComplexType());

Expand Down
40 changes: 40 additions & 0 deletions clang/test/AST/ByteCode/intap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,46 @@ namespace UnderlyingInt128 {
static_assert(foo() == 0, ""); // both-error {{not an integral constant expression}} \
// both-note {{in call to}}
}

namespace CompoundAssignOperators {
constexpr unsigned __int128 foo() {
long b = 10;

b += (__int128)1;
b -= (__int128)1;
b *= (__int128)1;
b /= (__int128)1;

b += (unsigned __int128)1;
b -= (unsigned __int128)1;
b *= (unsigned __int128)1;
b /= (unsigned __int128)1;

__int128 i = 10;
i += (__int128)1;
i -= (__int128)1;
i *= (__int128)1;
i /= (__int128)1;
i += (unsigned __int128)1;
i -= (unsigned __int128)1;
i *= (unsigned __int128)1;
i /= (unsigned __int128)1;

unsigned __int128 i2 = 10;
i2 += (__int128)1;
i2 -= (__int128)1;
i2 *= (__int128)1;
i2 /= (__int128)1;
i2 += (unsigned __int128)1;
i2 -= (unsigned __int128)1;
i2 *= (unsigned __int128)1;
i2 /= (unsigned __int128)1;

return (int)b;
}
static_assert(foo() == 10);
}

#endif

#endif