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?= <“nhat7...@gmail.com”> Date: Tue, 19 Dec 2023 00:03:28 -0800 Subject: [PATCH 1/4] 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 <nhat7...@gmail.com> Date: Thu, 21 Dec 2023 13:26:13 -0500 Subject: [PATCH 2/4] Update clang/lib/Sema/SemaDeclCXX.cpp Co-authored-by: Yueh-Shun Li <shamrock...@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?= <“nhat7...@gmail.com”> Date: Thu, 21 Dec 2023 10:34:00 -0800 Subject: [PATCH 3/4] 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()); >From d5208f02c9b130b85c15b32c945f871d0216885a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CNhat?= <“nhat7...@gmail.com”> Date: Thu, 21 Dec 2023 23:14:44 -0800 Subject: [PATCH 4/4] clang format --- 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 323890b38daeec..80e6cd9ee07420 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() > std::numeric_limits<uint64_t>::max() || + if (V.getInt() > std::numeric_limits<uint64_t>::max() || V.getInt() < std::numeric_limits<int64_t>::min()) { return false; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits