Skip to content

Commit ffab938

Browse files
committed
[clang][Interp] Handle BooleanToSignedIntegral casts
1 parent 4f09ac7 commit ffab938

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ bool ByteCodeExprGen<Emitter>::VisitCastExpr(const CastExpr *CE) {
343343
}
344344

345345
case CK_IntegralToBoolean:
346+
case CK_BooleanToSignedIntegral:
346347
case CK_IntegralCast: {
347348
if (DiscardResult)
348349
return this->discard(SubExpr);
@@ -362,7 +363,12 @@ bool ByteCodeExprGen<Emitter>::VisitCastExpr(const CastExpr *CE) {
362363

363364
if (FromT == ToT)
364365
return true;
365-
return this->emitCast(*FromT, *ToT, CE);
366+
if (!this->emitCast(*FromT, *ToT, CE))
367+
return false;
368+
369+
if (CE->getCastKind() == CK_BooleanToSignedIntegral)
370+
return this->emitNeg(*ToT, CE);
371+
return true;
366372
}
367373

368374
case CK_PointerToBoolean:

clang/test/AST/Interp/vectors.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,12 @@ namespace {
6161
typedef float __attribute__((vector_size(16))) VI42;
6262
constexpr VI42 A2 = A; // expected-error {{must be initialized by a constant expression}}
6363
}
64+
65+
namespace BoolToSignedIntegralCast{
66+
typedef __attribute__((__ext_vector_type__(4))) unsigned int int4;
67+
constexpr int4 intsT = (int4)true;
68+
static_assert(intsT[0] == -1, "");// ref-error {{not an integral constant expression}}
69+
static_assert(intsT[1] == -1, "");// ref-error {{not an integral constant expression}}
70+
static_assert(intsT[2] == -1, "");// ref-error {{not an integral constant expression}}
71+
static_assert(intsT[3] == -1, "");// ref-error {{not an integral constant expression}}
72+
}

0 commit comments

Comments
 (0)