[Lldb-commits] [PATCH] D135461: [LLDB] Fix crash when printing a struct with a static wchar_t member

Arthur Eubanks via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Oct 10 14:27:54 PDT 2022


aeubanks added inline comments.


================
Comment at: clang/lib/AST/StmtPrinter.cpp:1298
+  case BuiltinType::WChar_U:
+    break; // no suffix.
   }
----------------
DavidSpickett wrote:
> Is there any reason to have a suffix here?
> 
> I admit this function is puzzling to me anyway given that char has a prefix and this won't. Perhaps this is because char here is not "character" it's an integer of a certain size. Where wide char is more about, well, being an actual character.
> 
> And reading https://en.cppreference.com/w/cpp/language/character_literal the suffix would be "L" which we've already used.
> 
> As long as it prints in a way that's useful for the developer that's fine.
https://en.cppreference.com/w/cpp/language/character_literal is about char literal prefixes, which is not what this is

e.g.
```
$ lldb a.out
(lldb) im loo -t A
...
static const unsigned char uchar_max = 255Ui8;
```
this output isn't valid C++, I believe it's just more clarification for the user on the exact type of the integer literal. I could make this output something like "UW"/"SW"?

with and without this change, we already have
```
(lldb) print A::wchar_min
(const wchar_t) $0 = L'\U0000fffd'
```

this change makes the following not crash
```
$ lldb a.out
(lldb) im loo -t A
...
static const wchar_t wchar_max = 2147483647;
```
any suffix we choose here is appended to the `2147483647`


================
Comment at: lldb/test/API/lang/cpp/const_static_integral_member/main.cpp:38
       std::numeric_limits<unsigned long long>::max();
+  const static auto wchar_max = std::numeric_limits<wchar_t>::max();
 
----------------
DavidSpickett wrote:
> Is there a specific `signed wchar_t` and `unsigned wchar_t` like for char?
```
/tmp/a.cc:1:7: error: 'wchar_t' cannot be signed or unsigned [-Wsigned-unsigned-wchar]
const unsigned wchar_t a = 0;
```
https://en.cppreference.com/w/cpp/language/types
```
wchar_t - type for wide character representation (see wide strings). It has the same size, signedness, and alignment as one of the integer types, but is a distinct type.
```
so it sounds like under the hood the signedness is platform dependent, but there's only one wchar_t type


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135461/new/

https://reviews.llvm.org/D135461



More information about the lldb-commits mailing list