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

Yueh-Shun Li via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 19 16:04:56 PST 2023


================
@@ -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)) {
----------------
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<uint64_t>::max() || V.getInt() < std::numeric_limits<int64_t>::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


More information about the cfe-commits mailing list