=?utf-8?q?“Nhat?= <nhat7...@gmail.com>, =?utf-8?q?“Nhat?= <nhat7...@gmail.com>, =?utf-8?q?“Nhat?= <nhat7...@gmail.com>, =?utf-8?q?“Nhat?= <nhat7...@gmail.com>, =?utf-8?q?“Nhat?= <nhat7...@gmail.com> Message-ID: In-Reply-To: <llvm.org/llvm/llvm-project/pull/75...@github.com>
https://github.com/changkhothuychung updated https://github.com/llvm/llvm-project/pull/75902 >From 4939edb1cb2b73f9c60c4cce0803fab4888beb6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CNhat?= <nhat7...@gmail.com> Date: Mon, 1 Jan 2024 20:59:26 -0500 Subject: [PATCH 1/6] 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 1932765f174e187a79144c4fd69657dc7bae480a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CNhat?= <nhat7...@gmail.com> Date: Mon, 1 Jan 2024 20:59:27 -0500 Subject: [PATCH 2/6] 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 69e21b2bf76b51914f835c74af9e2b3c685ffae0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CNhat?= <nhat7...@gmail.com> Date: Mon, 1 Jan 2024 20:59:28 -0500 Subject: [PATCH 3/6] 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 ac93beb74cbe6e0cb6383ece6b72b59b00aeca0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CNhat?= <nhat7...@gmail.com> Date: Mon, 1 Jan 2024 20:59:29 -0500 Subject: [PATCH 4/6] 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; } >From 35773add17d8b4e884daac0e3e7dc312f1947911 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CNhat?= <nhat7...@gmail.com> Date: Mon, 1 Jan 2024 21:09:21 -0500 Subject: [PATCH 5/6] move the condition right under toString --- clang/lib/Sema/SemaDeclCXX.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 80e6cd9ee07420..d3b68c9aa95645 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -17132,10 +17132,6 @@ 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()) { - return false; - } uint32_t CodeUnit = static_cast<uint32_t>(V.getInt().getZExtValue()); WriteCharTypePrefix(BTy->getKind(), OS); OS << '\''; @@ -17151,6 +17147,10 @@ static bool ConvertAPValueToString(const APValue &V, QualType T, } } V.getInt().toString(Str); + if (V.getInt() > std::numeric_limits<uint64_t>::max() || + V.getInt() < std::numeric_limits<int64_t>::min()) { + return false; + } } break; >From abbbe6a54d08a25d6b6707bdaf8795640a3cabdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CNhat?= <nhat7...@gmail.com> Date: Sat, 10 Feb 2024 13:31:22 -0500 Subject: [PATCH 6/6] print hexa --- clang/lib/Sema/SemaDeclCXX.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index d3b68c9aa95645..80c1888fde6843 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -17146,10 +17146,12 @@ static bool ConvertAPValueToString(const APValue &V, QualType T, break; } } - V.getInt().toString(Str); if (V.getInt() > std::numeric_limits<uint64_t>::max() || V.getInt() < std::numeric_limits<int64_t>::min()) { return false; + V.getInt().toString(Str, 16); + } else { + V.getInt().toString(Str); } } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits