Skip to content

Commit f05e818

Browse files
authored
[clang][Interp] Fix BooleanToSignedIntegral casts for IntAP(S) (llvm#102302)
We were not doing the final Neg here.
1 parent 441f94f commit f05e818

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
@@ -90,3 +90,14 @@ namespace Temporaries {
9090
};
9191
int &&s = S().w[1];
9292
}
93+
94+
#ifdef __SIZEOF_INT128__
95+
namespace bigint {
96+
typedef __attribute__((__ext_vector_type__(4))) __int128 bigint4;
97+
constexpr bigint4 A = (bigint4)true;
98+
static_assert(A[0] == -1, "");
99+
static_assert(A[1] == -1, "");
100+
static_assert(A[2] == -1, "");
101+
static_assert(A[3] == -1, "");
102+
}
103+
#endif

0 commit comments

Comments
 (0)