[clang] ffab938 - [clang][Interp] Handle BooleanToSignedIntegral casts
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 13 05:38:47 PDT 2024
Author: Timm Bäder
Date: 2024-06-13T13:49:20+02:00
New Revision: ffab938f50fa999f2218976f7de78cf8e4f70d4e
URL: https://github.com/llvm/llvm-project/commit/ffab938f50fa999f2218976f7de78cf8e4f70d4e
DIFF: https://github.com/llvm/llvm-project/commit/ffab938f50fa999f2218976f7de78cf8e4f70d4e.diff
LOG: [clang][Interp] Handle BooleanToSignedIntegral casts
Added:
Modified:
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/AST/Interp/vectors.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index e0500983a31b5..60b1e089e74a6 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -343,6 +343,7 @@ bool ByteCodeExprGen<Emitter>::VisitCastExpr(const CastExpr *CE) {
}
case CK_IntegralToBoolean:
+ case CK_BooleanToSignedIntegral:
case CK_IntegralCast: {
if (DiscardResult)
return this->discard(SubExpr);
@@ -362,7 +363,12 @@ bool ByteCodeExprGen<Emitter>::VisitCastExpr(const CastExpr *CE) {
if (FromT == ToT)
return true;
- return this->emitCast(*FromT, *ToT, CE);
+ if (!this->emitCast(*FromT, *ToT, CE))
+ return false;
+
+ if (CE->getCastKind() == CK_BooleanToSignedIntegral)
+ return this->emitNeg(*ToT, CE);
+ return true;
}
case CK_PointerToBoolean:
diff --git a/clang/test/AST/Interp/vectors.cpp b/clang/test/AST/Interp/vectors.cpp
index 49dae14fcf646..1e0d473cbca5a 100644
--- a/clang/test/AST/Interp/vectors.cpp
+++ b/clang/test/AST/Interp/vectors.cpp
@@ -61,3 +61,12 @@ namespace {
typedef float __attribute__((vector_size(16))) VI42;
constexpr VI42 A2 = A; // expected-error {{must be initialized by a constant expression}}
}
+
+namespace BoolToSignedIntegralCast{
+ typedef __attribute__((__ext_vector_type__(4))) unsigned int int4;
+ constexpr int4 intsT = (int4)true;
+ static_assert(intsT[0] == -1, "");// ref-error {{not an integral constant expression}}
+ static_assert(intsT[1] == -1, "");// ref-error {{not an integral constant expression}}
+ static_assert(intsT[2] == -1, "");// ref-error {{not an integral constant expression}}
+ static_assert(intsT[3] == -1, "");// ref-error {{not an integral constant expression}}
+}
More information about the cfe-commits
mailing list