[clang] [clang][Interp] Fix IntAP(s) to IntAP(s) casts (PR #69915)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 6 03:16:41 PST 2023
https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/69915
>From b82acd12f1217468d6fc53ab2b2f5856802b9b78 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Mon, 23 Oct 2023 12:46:25 +0200
Subject: [PATCH] [clang][Interp] Fix IntAP(s) to IntAP(s) casts
---
clang/lib/AST/Interp/ByteCodeExprGen.cpp | 7 ++-----
clang/test/AST/Interp/intap.cpp | 11 +++++++++++
2 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 485893d58f487ae..a2cf682b2532bde 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -200,16 +200,13 @@ bool ByteCodeExprGen<Emitter>::VisitCastExpr(const CastExpr *CE) {
if (!this->visit(SubExpr))
return false;
- if (FromT == ToT) {
- assert(ToT != PT_IntAP && ToT != PT_IntAPS);
- return true;
- }
-
if (ToT == PT_IntAP)
return this->emitCastAP(*FromT, Ctx.getBitWidth(CE->getType()), CE);
if (ToT == PT_IntAPS)
return this->emitCastAPS(*FromT, Ctx.getBitWidth(CE->getType()), CE);
+ if (FromT == ToT)
+ return true;
return this->emitCast(*FromT, *ToT, CE);
}
diff --git a/clang/test/AST/Interp/intap.cpp b/clang/test/AST/Interp/intap.cpp
index 02a860eb0986c15..c7df32b70d20a45 100644
--- a/clang/test/AST/Interp/intap.cpp
+++ b/clang/test/AST/Interp/intap.cpp
@@ -30,6 +30,17 @@ static_assert(UBitIntZero1 == 0, "");
constexpr unsigned _BitInt(2) BI1 = 3u;
static_assert(BI1 == 3, "");
+namespace APCast {
+ constexpr _BitInt(10) A = 1;
+ constexpr _BitInt(11) B = A;
+ static_assert(B == 1, "");
+ constexpr _BitInt(16) B2 = A;
+ static_assert(B2 == 1, "");
+ constexpr _BitInt(32) B3 = A;
+ static_assert(B3 == 1, "");
+ constexpr unsigned _BitInt(32) B4 = A;
+ static_assert(B4 == 1, "");
+}
#ifdef __SIZEOF_INT128__
namespace i128 {
More information about the cfe-commits
mailing list