[clang] Avoid printing overly large integer. (PR #75902)

2024-02-13 Thread Erich Keane via cfe-commits
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= ,Nhat Nguyen
 
Message-ID:
In-Reply-To: 


erichkeane wrote:

> > Looks like all the tests disappeared? Only thing I see is the code change. 
> > Also, no release note is currently present.
> 
> Hi I am still slowly working on it. I am not familiar with the release note. 
> Can you provide me some pointers so I can follow accordingly? Thanks a lot.

See the clang/docs/ directory, particularly 
https://github.com/llvm/llvm-project/blob/main/clang/docs/ReleaseNotes.rst .  
You can put an entry into whichever section makes the most sense (probably 
improvements to clang's diagnostics), just write a sentence or two explaining 
the improvement.

https://github.com/llvm/llvm-project/pull/75902
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Avoid printing overly large integer. (PR #75902)

2024-02-12 Thread Nhat Nguyen via cfe-commits
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= ,Nhat Nguyen
 
Message-ID:
In-Reply-To: 


changkhothuychung wrote:

> Looks like all the tests disappeared? Only thing I see is the code change. 
> Also, no release note is currently present.

Hi I am still slowly working on it. I am not familiar with the release note. 
Can you provide me some pointers so I can follow accordingly? Thanks a lot. 

https://github.com/llvm/llvm-project/pull/75902
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Avoid printing overly large integer. (PR #75902)

2024-02-12 Thread Erich Keane via cfe-commits
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= ,Nhat Nguyen
 
Message-ID:
In-Reply-To: 


erichkeane wrote:

Looks like all the tests disappeared?  Only thing I see is the code change.  
Also, no release note is currently present.

https://github.com/llvm/llvm-project/pull/75902
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Avoid printing overly large integer. (PR #75902)

2024-02-11 Thread Nhat Nguyen via cfe-commits
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= ,Nhat Nguyen
 
Message-ID:
In-Reply-To: 


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?= 
Date: Mon, 1 Jan 2024 20:59:26 -0500
Subject: [PATCH 1/7] 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 , 
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(V.getInt().getZExtValue());
   WriteCharTypePrefix(BTy->getKind(), OS);
   OS << '\'';

>From 1932765f174e187a79144c4fd69657dc7bae480a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= 
Date: Mon, 1 Jan 2024 20:59:27 -0500
Subject: [PATCH 2/7] Update clang/lib/Sema/SemaDeclCXX.cpp

Co-authored-by: Yueh-Shun Li 
---
 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 , 
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::max() || V.getInt() 
< std::numeric_limits::min()) {
 return false;
   }
   uint32_t CodeUnit = static_cast(V.getInt().getZExtValue());

>From 69e21b2bf76b51914f835c74af9e2b3c685ffae0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= 
Date: Mon, 1 Jan 2024 20:59:28 -0500
Subject: [PATCH 3/7] 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 , 
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::max() || V.getInt() 
< std::numeric_limits::min()) {
+  if (V.getInt() > std::numeric_limits::max() || 
+  V.getInt() < std::numeric_limits::min()) {
 return false;
   }
   uint32_t CodeUnit = static_cast(V.getInt().getZExtValue());

>From ac93beb74cbe6e0cb6383ece6b72b59b00aeca0d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= 
Date: Mon, 1 Jan 2024 20:59:29 -0500
Subject: [PATCH 4/7] 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 , 
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::max() || 
+  if (V.getInt() > std::numeric_limits::max() ||
   V.getInt() < std::numeric_limits::min()) {
 return false;
   }

>From 35773add17d8b4e884daac0e3e7dc312f1947911 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= 
Date: Mon, 1 Jan 2024 21:09:21 -0500
Subject: [PATCH 5/7] 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 , 
QualType T,
 case BuiltinType::WChar_U: {
   unsigned TyWidth = Context.getIntWidth(T);
   assert(8 <= TyWidth && TyWidth <= 32 && "Unexpected integer width");
- 

[clang] Avoid printing overly large integer. (PR #75902)

2024-02-10 Thread Yueh-Shun Li via cfe-commits
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= 
Message-ID:
In-Reply-To: 



@@ -17146,7 +17146,13 @@ static bool ConvertAPValueToString(const APValue , 
QualType T,
   break;
 }
   }
-  V.getInt().toString(Str);
+  if (V.getInt() > std::numeric_limits::max() ||
+  V.getInt() < std::numeric_limits::min()) {
+return false;

ShamrockLee wrote:

```suggestion

```

https://github.com/llvm/llvm-project/pull/75902
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Avoid printing overly large integer. (PR #75902)

2024-02-10 Thread Yueh-Shun Li via cfe-commits
=?utf-8?q?=E2=80=9CNhat?= ,
=?utf-8?q?=E2=80=9CNhat?= ,
=?utf-8?q?=E2=80=9CNhat?= ,
=?utf-8?q?=E2=80=9CNhat?= ,
=?utf-8?q?=E2=80=9CNhat?= 
Message-ID:
In-Reply-To: 


https://github.com/ShamrockLee requested changes to this pull request.


https://github.com/llvm/llvm-project/pull/75902
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Avoid printing overly large integer. (PR #75902)

2024-02-10 Thread Yueh-Shun Li via cfe-commits
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= 
Message-ID:
In-Reply-To: 


https://github.com/ShamrockLee edited 
https://github.com/llvm/llvm-project/pull/75902
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Avoid printing overly large integer. (PR #75902)

2024-02-10 Thread Nhat Nguyen via cfe-commits
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= 
Message-ID:
In-Reply-To: 


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?= 
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 , 
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(V.getInt().getZExtValue());
   WriteCharTypePrefix(BTy->getKind(), OS);
   OS << '\'';

>From 1932765f174e187a79144c4fd69657dc7bae480a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= 
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 
---
 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 , 
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::max() || V.getInt() 
< std::numeric_limits::min()) {
 return false;
   }
   uint32_t CodeUnit = static_cast(V.getInt().getZExtValue());

>From 69e21b2bf76b51914f835c74af9e2b3c685ffae0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= 
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 , 
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::max() || V.getInt() 
< std::numeric_limits::min()) {
+  if (V.getInt() > std::numeric_limits::max() || 
+  V.getInt() < std::numeric_limits::min()) {
 return false;
   }
   uint32_t CodeUnit = static_cast(V.getInt().getZExtValue());

>From ac93beb74cbe6e0cb6383ece6b72b59b00aeca0d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= 
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 , 
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::max() || 
+  if (V.getInt() > std::numeric_limits::max() ||
   V.getInt() < std::numeric_limits::min()) {
 return false;
   }

>From 35773add17d8b4e884daac0e3e7dc312f1947911 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= 
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 , 
QualType T,
 case BuiltinType::WChar_U: {
   unsigned TyWidth = Context.getIntWidth(T);
   assert(8 <= TyWidth && TyWidth <= 32 && "Unexpected integer width");
-  if 

[clang] Avoid printing overly large integer. (PR #75902)

2024-01-05 Thread Yueh-Shun Li via cfe-commits
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= 
Message-ID:
In-Reply-To: 


https://github.com/ShamrockLee edited 
https://github.com/llvm/llvm-project/pull/75902
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Avoid printing overly large integer. (PR #75902)

2024-01-05 Thread Yueh-Shun Li via cfe-commits
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= 
Message-ID:
In-Reply-To: 


https://github.com/ShamrockLee edited 
https://github.com/llvm/llvm-project/pull/75902
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Avoid printing overly large integer. (PR #75902)

2024-01-05 Thread Yueh-Shun Li via cfe-commits
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= 
Message-ID:
In-Reply-To: 



@@ -17132,6 +17132,10 @@ static bool ConvertAPValueToString(const APValue , 
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::max() ||

ShamrockLee wrote:

Besides, as @tbaederr and @shafik suggest, printing the hexadecimal 
representation of the integer is better than avoid printing it. This would be 
something like.

```c
  if (V.getInt() > std::numeric_limits::max() ||
  V.getInt() < std::numeric_limits::min()) {
// Code to print the hexadecimal expression
  } else {
V.getInt().toString(Str);
  }
```

https://github.com/llvm/llvm-project/pull/75902
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Avoid printing overly large integer. (PR #75902)

2024-01-05 Thread Yueh-Shun Li via cfe-commits
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= 
Message-ID:
In-Reply-To: 



@@ -17132,6 +17132,10 @@ static bool ConvertAPValueToString(const APValue , 
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::max() ||

ShamrockLee wrote:

> thanks for letting me know! I have moved the code overthere, however it looks 
> like there are some failed tests, is it because of my code which causes the 
> error?

It is because the conditional clause should be *above* the integer printing in 
question.

https://github.com/llvm/llvm-project/pull/75902
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Avoid printing overly large integer. (PR #75902)

2024-01-01 Thread Nhat Nguyen via cfe-commits
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= 
Message-ID:
In-Reply-To: 



@@ -17132,6 +17132,10 @@ static bool ConvertAPValueToString(const APValue , 
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::max() ||

changkhothuychung wrote:

@ShamrockLee 

thanks for letting me know! I have moved the code overthere, however it looks 
like there are some failed tests, is it because of my code which causes the 
error? 

https://github.com/llvm/llvm-project/pull/75902
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Avoid printing overly large integer. (PR #75902)

2024-01-01 Thread Nhat Nguyen via cfe-commits
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= 
Message-ID:
In-Reply-To: 


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?= 
Date: Mon, 1 Jan 2024 20:59:26 -0500
Subject: [PATCH 1/5] 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 , 
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(V.getInt().getZExtValue());
   WriteCharTypePrefix(BTy->getKind(), OS);
   OS << '\'';

>From 1932765f174e187a79144c4fd69657dc7bae480a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= 
Date: Mon, 1 Jan 2024 20:59:27 -0500
Subject: [PATCH 2/5] Update clang/lib/Sema/SemaDeclCXX.cpp

Co-authored-by: Yueh-Shun Li 
---
 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 , 
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::max() || V.getInt() 
< std::numeric_limits::min()) {
 return false;
   }
   uint32_t CodeUnit = static_cast(V.getInt().getZExtValue());

>From 69e21b2bf76b51914f835c74af9e2b3c685ffae0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= 
Date: Mon, 1 Jan 2024 20:59:28 -0500
Subject: [PATCH 3/5] 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 , 
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::max() || V.getInt() 
< std::numeric_limits::min()) {
+  if (V.getInt() > std::numeric_limits::max() || 
+  V.getInt() < std::numeric_limits::min()) {
 return false;
   }
   uint32_t CodeUnit = static_cast(V.getInt().getZExtValue());

>From ac93beb74cbe6e0cb6383ece6b72b59b00aeca0d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= 
Date: Mon, 1 Jan 2024 20:59:29 -0500
Subject: [PATCH 4/5] 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 , 
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::max() || 
+  if (V.getInt() > std::numeric_limits::max() ||
   V.getInt() < std::numeric_limits::min()) {
 return false;
   }

>From 35773add17d8b4e884daac0e3e7dc312f1947911 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= 
Date: Mon, 1 Jan 2024 21:09:21 -0500
Subject: [PATCH 5/5] 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 , 
QualType T,
 case BuiltinType::WChar_U: {
   unsigned TyWidth = Context.getIntWidth(T);
   assert(8 <= TyWidth && TyWidth <= 32 && "Unexpected integer width");
-  if (V.getInt() > 

[clang] Avoid printing overly large integer. (PR #75902)

2024-01-01 Thread Nhat Nguyen via cfe-commits
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= ,
=?utf-8?q?“Nhat?= 
Message-ID:
In-Reply-To: 


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?= 
Date: Mon, 1 Jan 2024 20:59:26 -0500
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 , 
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(V.getInt().getZExtValue());
   WriteCharTypePrefix(BTy->getKind(), OS);
   OS << '\'';

>From 1932765f174e187a79144c4fd69657dc7bae480a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= 
Date: Mon, 1 Jan 2024 20:59:27 -0500
Subject: [PATCH 2/4] Update clang/lib/Sema/SemaDeclCXX.cpp

Co-authored-by: Yueh-Shun Li 
---
 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 , 
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::max() || V.getInt() 
< std::numeric_limits::min()) {
 return false;
   }
   uint32_t CodeUnit = static_cast(V.getInt().getZExtValue());

>From 69e21b2bf76b51914f835c74af9e2b3c685ffae0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= 
Date: Mon, 1 Jan 2024 20:59:28 -0500
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 , 
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::max() || V.getInt() 
< std::numeric_limits::min()) {
+  if (V.getInt() > std::numeric_limits::max() || 
+  V.getInt() < std::numeric_limits::min()) {
 return false;
   }
   uint32_t CodeUnit = static_cast(V.getInt().getZExtValue());

>From ac93beb74cbe6e0cb6383ece6b72b59b00aeca0d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNhat?= 
Date: Mon, 1 Jan 2024 20:59:29 -0500
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 , 
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::max() || 
+  if (V.getInt() > std::numeric_limits::max() ||
   V.getInt() < std::numeric_limits::min()) {
 return false;
   }

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Avoid printing overly large integer. (PR #75902)

2023-12-28 Thread Yueh-Shun Li via cfe-commits


@@ -17132,6 +17132,10 @@ static bool ConvertAPValueToString(const APValue , 
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::max() ||

ShamrockLee wrote:

> do you have any idea where is actually the right place to fix the code?

IIUC, it should be around

```c++
  V.getInt().toString(Str);
```

as I mentioned earlier in 
https://github.com/llvm/llvm-project/pull/75902#discussion_r1432050810

https://github.com/llvm/llvm-project/pull/75902
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Avoid printing overly large integer. (PR #75902)

2023-12-27 Thread Nhat Nguyen via cfe-commits


@@ -17132,6 +17132,10 @@ static bool ConvertAPValueToString(const APValue , 
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::max() ||

changkhothuychung wrote:

Hi, do you have any idea where is actually the right place to fix the code? I 
am still looking for it, but if you have found it, it would be really 
appreciated!

https://github.com/llvm/llvm-project/pull/75902
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Avoid printing overly large integer. (PR #75902)

2023-12-26 Thread Nhat Nguyen via cfe-commits

changkhothuychung wrote:

Thanks everyone for the comments! I will address as soon as I can. 

https://github.com/llvm/llvm-project/pull/75902
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Avoid printing overly large integer. (PR #75902)

2023-12-23 Thread Craig Topper via cfe-commits


@@ -17132,6 +17132,10 @@ static bool ConvertAPValueToString(const APValue , 
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::max() ||

topperc wrote:

Also if `V.getInt()` was ever larger than 
`std::numeric_limits::max())`, the getZExtValue() call below would 
trigger an assertion.

https://github.com/llvm/llvm-project/pull/75902
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Avoid printing overly large integer. (PR #75902)

2023-12-23 Thread Craig Topper via cfe-commits


@@ -17132,6 +17132,10 @@ static bool ConvertAPValueToString(const APValue , 
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::max() ||

topperc wrote:

Is the right place to fix the original issue? The code right below this seems 
to be printing in hex, but the bug report shows a long decimal value. Also I'm 
not sure why _BitInt would got through any of the BuiltinTypes listed in this 
switch.

Is the later call to V.getInt().toString(Str); on line 17153 the right place?

https://github.com/llvm/llvm-project/pull/75902
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Avoid printing overly large integer. (PR #75902)

2023-12-23 Thread Yueh-Shun Li via cfe-commits

ShamrockLee wrote:

Some commits doesn't relate to the GitHub account correctly. This may result 
from incorrect `user.name` and `user.email` settings in your local Git 
repository.

![Screenshot_20231223-190834_GitHub_1.png](https://github.com/llvm/llvm-project/assets/44064051/41b65792-20da-4c1a-9ed6-8fa44545f482)

This error can be inspected by comparing the `From: ` field of the following 
patches:

Misconfigured: 
https://github.com/llvm/llvm-project/commit/0eb58740f33f2eef29c28e43e78118f9f0eea4b4.patch

Correct: 
https://github.com/llvm/llvm-project/commit/5e6326fb1cf4f1591fe927c94b1d16d1a7be0e66.patch

This can be fixed by

```sh
gt config user.name "Nhat Nguyen"
git config user.email "nhat7...@gmail.com"
git fetch 
git branch 71675-backup 71675
git switch -C 71675 /71675
git rebase --exec "git commit --amend --reset-author --no-edit" HEAD~4
### Double check before proceeding
git push -f 
```

https://github.com/llvm/llvm-project/pull/75902
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Avoid printing overly large integer. (PR #75902)

2023-12-21 Thread Nhat Nguyen via cfe-commits

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 , 
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(V.getInt().getZExtValue());
   WriteCharTypePrefix(BTy->getKind(), OS);
   OS << '\'';

>From 5e6326fb1cf4f1591fe927c94b1d16d1a7be0e66 Mon Sep 17 00:00:00 2001
From: Nhat Nguyen 
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 
---
 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 , 
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::max() || V.getInt() 
< std::numeric_limits::min()) {
 return false;
   }
   uint32_t CodeUnit = static_cast(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 , 
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::max() || V.getInt() 
< std::numeric_limits::min()) {
+  if (V.getInt() > std::numeric_limits::max() || 
+  V.getInt() < std::numeric_limits::min()) {
 return false;
   }
   uint32_t CodeUnit = static_cast(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 , 
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::max() || 
+  if (V.getInt() > std::numeric_limits::max() ||
   V.getInt() < std::numeric_limits::min()) {
 return false;
   }

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Avoid printing overly large integer. (PR #75902)

2023-12-21 Thread Nhat Nguyen via cfe-commits

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/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 , 
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(V.getInt().getZExtValue());
   WriteCharTypePrefix(BTy->getKind(), OS);
   OS << '\'';

>From 5e6326fb1cf4f1591fe927c94b1d16d1a7be0e66 Mon Sep 17 00:00:00 2001
From: Nhat Nguyen 
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 
---
 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 , 
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::max() || V.getInt() 
< std::numeric_limits::min()) {
 return false;
   }
   uint32_t CodeUnit = static_cast(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/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 , 
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::max() || V.getInt() 
< std::numeric_limits::min()) {
+  if (V.getInt() > std::numeric_limits::max() || 
+  V.getInt() < std::numeric_limits::min()) {
 return false;
   }
   uint32_t CodeUnit = static_cast(V.getInt().getZExtValue());

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Avoid printing overly large integer. (PR #75902)

2023-12-21 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 497b2ebb9edcfd5315586b796f47589e9820b4b9 
5e6326fb1cf4f1591fe927c94b1d16d1a7be0e66 -- clang/lib/Sema/SemaDeclCXX.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 196e32a4a3..80e6cd9ee0 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -17132,7 +17132,8 @@ static bool ConvertAPValueToString(const APValue , 
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::max() || V.getInt() 
< std::numeric_limits::min()) {
+  if (V.getInt() > std::numeric_limits::max() ||
+  V.getInt() < std::numeric_limits::min()) {
 return false;
   }
   uint32_t CodeUnit = static_cast(V.getInt().getZExtValue());

``




https://github.com/llvm/llvm-project/pull/75902
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Avoid printing overly large integer. (PR #75902)

2023-12-21 Thread Nhat Nguyen via cfe-commits

changkhothuychung wrote:

Thanks, I will look into adding tests! 

Regarding the floating point option, are we converting the value to float type 
and just print it to the output stream? @cor3ntin 

https://github.com/llvm/llvm-project/pull/75902
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Avoid printing overly large integer. (PR #75902)

2023-12-21 Thread Nhat Nguyen via cfe-commits

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/2] 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 , 
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(V.getInt().getZExtValue());
   WriteCharTypePrefix(BTy->getKind(), OS);
   OS << '\'';

>From 5e6326fb1cf4f1591fe927c94b1d16d1a7be0e66 Mon Sep 17 00:00:00 2001
From: Nhat Nguyen 
Date: Thu, 21 Dec 2023 13:26:13 -0500
Subject: [PATCH 2/2] Update clang/lib/Sema/SemaDeclCXX.cpp

Co-authored-by: Yueh-Shun Li 
---
 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 , 
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::max() || V.getInt() 
< std::numeric_limits::min()) {
 return false;
   }
   uint32_t CodeUnit = static_cast(V.getInt().getZExtValue());

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Avoid printing overly large integer. (PR #75902)

2023-12-21 Thread Yueh-Shun Li via cfe-commits

https://github.com/ShamrockLee edited 
https://github.com/llvm/llvm-project/pull/75902
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Avoid printing overly large integer. (PR #75902)

2023-12-20 Thread Shafik Yaghmour via cfe-commits

shafik wrote:

> I agree with @tbaederr, fixing the underlying issue - either by optimizing 
> divide (good luck!) or printing in hexadecimal, seems like a better solution. 
> At the minimum, we should have a fixme comment to explain the restriction
> 
> @tbaederr @erichkeane @shafik opinion?

I agree the hexadecimal option feel like the better solution. Should we also 
have a diagnostic when we hit this case?

Also as mentioned we need some test cases as well. 

https://github.com/llvm/llvm-project/pull/75902
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Avoid printing overly large integer. (PR #75902)

2023-12-20 Thread via cfe-commits

cor3ntin wrote:

I agree with @tbaederr, fixing the underlying issue - either by optimizing 
divide (good luck!) or printing in hexadecimal, seems like a better solution. 
At the minimum, we should have a fixme comment to explain the restriction

@tbaederr @erichkeane @shafik opinion?


https://github.com/llvm/llvm-project/pull/75902
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Avoid printing overly large integer. (PR #75902)

2023-12-19 Thread Yueh-Shun Li via cfe-commits


@@ -17132,6 +17132,9 @@ static bool ConvertAPValueToString(const APValue , 
QualType T,
 case BuiltinType::WChar_U: {
   unsigned TyWidth = Context.getIntWidth(T);
   assert(8 <= TyWidth && TyWidth <= 32 && "Unexpected integer width");
+  if (V.getInt() >= (1 << 64)) {

ShamrockLee wrote:

`V.getInt()` could also be negative. Sorry for my imprecise  comment in 
https://github.com/llvm/llvm-project/issues/71675#issuecomment-1862186784

Combining the above review suggestions, the following should do the trick:

```suggestion
  if (V.getInt() > std::numeric_limits::max() || V.getInt() < 
std::numeric_limits::min()) {
```

In addition, this changes doesn't seem to consider the situation where the 
value type is not char-like, and these char-like types wouldn't have such wide 
value. Maybe we should move this condition down right before the line

```c++
  V.getInt().toString(Str);
```

https://github.com/llvm/llvm-project/pull/75902
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Avoid printing overly large integer. (PR #75902)

2023-12-19 Thread Jon Roelofs via cfe-commits

jroelofs wrote:

This also needs a test case.

https://github.com/llvm/llvm-project/pull/75902
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Avoid printing overly large integer. (PR #75902)

2023-12-19 Thread Jon Roelofs via cfe-commits


@@ -17132,6 +17132,9 @@ static bool ConvertAPValueToString(const APValue , 
QualType T,
 case BuiltinType::WChar_U: {
   unsigned TyWidth = Context.getIntWidth(T);
   assert(8 <= TyWidth && TyWidth <= 32 && "Unexpected integer width");
+  if (V.getInt() >= (1 << 64)) {

jroelofs wrote:

> 1<<64 is results 0

Shifting beyond the width of the type is Undefined Behavior.

https://github.com/llvm/llvm-project/pull/75902
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Avoid printing overly large integer. (PR #75902)

2023-12-19 Thread Botond István Horváth via cfe-commits

https://github.com/HoBoIs edited https://github.com/llvm/llvm-project/pull/75902
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Avoid printing overly large integer. (PR #75902)

2023-12-19 Thread Botond István Horváth via cfe-commits


@@ -17132,6 +17132,9 @@ static bool ConvertAPValueToString(const APValue , 
QualType T,
 case BuiltinType::WChar_U: {
   unsigned TyWidth = Context.getIntWidth(T);
   assert(8 <= TyWidth && TyWidth <= 32 && "Unexpected integer width");
+  if (V.getInt() >= (1 << 64)) {

HoBoIs wrote:

In 1 << 64 you operates with ints(32 bit). (1 is an int) 1<<64 is results 0. I 
suggest to compare V.getInt() with std::numeric_limits\::max()} 
instead. (or uint64_t(-1)).

https://github.com/llvm/llvm-project/pull/75902
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Avoid printing overly large integer. (PR #75902)

2023-12-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Nhat Nguyen  (changkhothuychung)


Changes

Created a PR to fix issue #71675

---
Full diff: https://github.com/llvm/llvm-project/pull/75902.diff


1 Files Affected:

- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+3) 


``diff
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 , 
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(V.getInt().getZExtValue());
   WriteCharTypePrefix(BTy->getKind(), OS);
   OS << '\'';

``




https://github.com/llvm/llvm-project/pull/75902
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Avoid printing overly large integer. (PR #75902)

2023-12-19 Thread Nhat Nguyen via cfe-commits

https://github.com/changkhothuychung created 
https://github.com/llvm/llvm-project/pull/75902

Created a PR to fix issue #71675

>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] 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 , 
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(V.getInt().getZExtValue());
   WriteCharTypePrefix(BTy->getKind(), OS);
   OS << '\'';

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits