[clang] Avoid printing overly large integer. (PR #75902)
Nhat Nguyen via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 21 10:34:14 PST 2023
https://github.com/changkhothuychung updated https://github.com/llvm/llvm-project/pull/75902
>From 0eb58740f33f2eef29c28e43e78118f9f0eea4b4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= <“nhat7203 at gmail.com”>
Date: Tue, 19 Dec 2023 00:03:28 -0800
Subject: [PATCH 1/3] return false if the value is too large
---
clang/lib/Sema/SemaDeclCXX.cpp | 3 +++
1 file changed, 3 insertions(+)
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index a3f68d4ffc0f6e..18631ec7dac152 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -17132,6 +17132,9 @@ static bool ConvertAPValueToString(const APValue &V, QualType T,
case BuiltinType::WChar_U: {
unsigned TyWidth = Context.getIntWidth(T);
assert(8 <= TyWidth && TyWidth <= 32 && "Unexpected integer width");
+ if (V.getInt() >= (1 << 64)) {
+ return false;
+ }
uint32_t CodeUnit = static_cast<uint32_t>(V.getInt().getZExtValue());
WriteCharTypePrefix(BTy->getKind(), OS);
OS << '\'';
>From 5e6326fb1cf4f1591fe927c94b1d16d1a7be0e66 Mon Sep 17 00:00:00 2001
From: Nhat Nguyen <nhat7203 at gmail.com>
Date: Thu, 21 Dec 2023 13:26:13 -0500
Subject: [PATCH 2/3] Update clang/lib/Sema/SemaDeclCXX.cpp
Co-authored-by: Yueh-Shun Li <shamrocklee at posteo.net>
---
clang/lib/Sema/SemaDeclCXX.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 18631ec7dac152..196e32a4a349f2 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -17132,7 +17132,7 @@ static bool ConvertAPValueToString(const APValue &V, QualType T,
case BuiltinType::WChar_U: {
unsigned TyWidth = Context.getIntWidth(T);
assert(8 <= TyWidth && TyWidth <= 32 && "Unexpected integer width");
- if (V.getInt() >= (1 << 64)) {
+ if (V.getInt() > std::numeric_limits<uint64_t>::max() || V.getInt() < std::numeric_limits<int64_t>::min()) {
return false;
}
uint32_t CodeUnit = static_cast<uint32_t>(V.getInt().getZExtValue());
>From b2794aba6969d694b55ab3a91ac1616f8469cd46 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= <“nhat7203 at gmail.com”>
Date: Thu, 21 Dec 2023 10:34:00 -0800
Subject: [PATCH 3/3] clang format
---
clang/lib/Sema/SemaDeclCXX.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 196e32a4a349f2..323890b38daeec 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -17132,7 +17132,8 @@ static bool ConvertAPValueToString(const APValue &V, QualType T,
case BuiltinType::WChar_U: {
unsigned TyWidth = Context.getIntWidth(T);
assert(8 <= TyWidth && TyWidth <= 32 && "Unexpected integer width");
- if (V.getInt() > std::numeric_limits<uint64_t>::max() || V.getInt() < std::numeric_limits<int64_t>::min()) {
+ if (V.getInt() > std::numeric_limits<uint64_t>::max() ||
+ V.getInt() < std::numeric_limits<int64_t>::min()) {
return false;
}
uint32_t CodeUnit = static_cast<uint32_t>(V.getInt().getZExtValue());
More information about the cfe-commits
mailing list