Skip to content

Commit 0b1a9b4

Browse files
committed
[clang][Interp] Fix BooleanToSignedIntegral casts for IntAP(S)
We were not doing the final Neg here.
1 parent 59e1366 commit 0b1a9b4

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

clang/lib/AST/Interp/Compiler.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -480,19 +480,25 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
480480
}
481481
}
482482

483+
auto maybeNegate = [&]() -> bool {
484+
if (CE->getCastKind() == CK_BooleanToSignedIntegral)
485+
return this->emitNeg(*ToT, CE);
486+
return true;
487+
};
488+
483489
if (ToT == PT_IntAP)
484-
return this->emitCastAP(*FromT, Ctx.getBitWidth(CE->getType()), CE);
490+
return this->emitCastAP(*FromT, Ctx.getBitWidth(CE->getType()), CE) &&
491+
maybeNegate();
485492
if (ToT == PT_IntAPS)
486-
return this->emitCastAPS(*FromT, Ctx.getBitWidth(CE->getType()), CE);
493+
return this->emitCastAPS(*FromT, Ctx.getBitWidth(CE->getType()), CE) &&
494+
maybeNegate();
487495

488496
if (FromT == ToT)
489497
return true;
490498
if (!this->emitCast(*FromT, *ToT, CE))
491499
return false;
492500

493-
if (CE->getCastKind() == CK_BooleanToSignedIntegral)
494-
return this->emitNeg(*ToT, CE);
495-
return true;
501+
return maybeNegate();
496502
}
497503

498504
case CK_PointerToBoolean:

clang/test/AST/Interp/vectors.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,14 @@ namespace Temporaries {
9191
};
9292
int &&s = S().w[1];
9393
}
94+
95+
#ifdef __SIZEOF_INT128__
96+
namespace bigint {
97+
typedef __attribute__((__ext_vector_type__(4))) __int128 bigint4;
98+
constexpr bigint4 A = (bigint4)true;
99+
static_assert(A[0] == -1, "");
100+
static_assert(A[1] == -1, "");
101+
static_assert(A[2] == -1, "");
102+
static_assert(A[3] == -1, "");
103+
}
104+
#endif

0 commit comments

Comments
 (0)