https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/102302
We were not doing the final Neg here. >From 0b1a9b49382802a06fad9ac149e2f2a20539429e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com> Date: Wed, 7 Aug 2024 12:25:06 +0200 Subject: [PATCH] [clang][Interp] Fix BooleanToSignedIntegral casts for IntAP(S) We were not doing the final Neg here. --- clang/lib/AST/Interp/Compiler.cpp | 16 +++++++++++----- clang/test/AST/Interp/vectors.cpp | 11 +++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/clang/lib/AST/Interp/Compiler.cpp b/clang/lib/AST/Interp/Compiler.cpp index 02cbe38f5fb1fa..acda6f29fb0f88 100644 --- a/clang/lib/AST/Interp/Compiler.cpp +++ b/clang/lib/AST/Interp/Compiler.cpp @@ -480,19 +480,25 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) { } } + auto maybeNegate = [&]() -> bool { + if (CE->getCastKind() == CK_BooleanToSignedIntegral) + return this->emitNeg(*ToT, CE); + return true; + }; + if (ToT == PT_IntAP) - return this->emitCastAP(*FromT, Ctx.getBitWidth(CE->getType()), CE); + return this->emitCastAP(*FromT, Ctx.getBitWidth(CE->getType()), CE) && + maybeNegate(); if (ToT == PT_IntAPS) - return this->emitCastAPS(*FromT, Ctx.getBitWidth(CE->getType()), CE); + return this->emitCastAPS(*FromT, Ctx.getBitWidth(CE->getType()), CE) && + maybeNegate(); if (FromT == ToT) return true; if (!this->emitCast(*FromT, *ToT, CE)) return false; - if (CE->getCastKind() == CK_BooleanToSignedIntegral) - return this->emitNeg(*ToT, CE); - return true; + return maybeNegate(); } case CK_PointerToBoolean: diff --git a/clang/test/AST/Interp/vectors.cpp b/clang/test/AST/Interp/vectors.cpp index 6991a348b07a94..328f38bf21effa 100644 --- a/clang/test/AST/Interp/vectors.cpp +++ b/clang/test/AST/Interp/vectors.cpp @@ -91,3 +91,14 @@ namespace Temporaries { }; int &&s = S().w[1]; } + +#ifdef __SIZEOF_INT128__ +namespace bigint { + typedef __attribute__((__ext_vector_type__(4))) __int128 bigint4; + constexpr bigint4 A = (bigint4)true; + static_assert(A[0] == -1, ""); + static_assert(A[1] == -1, ""); + static_assert(A[2] == -1, ""); + static_assert(A[3] == -1, ""); +} +#endif _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits