This is an archive of the discontinued LLVM Phabricator instance.

[LLDB] Fix crash when printing a struct with a static wchar_t member
ClosedPublic

Authored by aeubanks on Oct 7 2022, 10:12 AM.

Diff Detail

Event Timeline

aeubanks created this revision.Oct 7 2022, 10:12 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 7 2022, 10:12 AM
aeubanks requested review of this revision.Oct 7 2022, 10:12 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptOct 7 2022, 10:12 AM

You need to update the python file for the test as well.

What does the output look like, do we actually print the character itself or it's value? (just curious, which one we do is probably out of scope for this change)

clang/lib/AST/StmtPrinter.cpp
1298

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.

lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
39

Is there a specific signed wchar_t and unsigned wchar_t like for char?

aeubanks updated this revision to Diff 466622.Oct 10 2022, 2:27 PM

update python test, although those changes don't actually test the code path changed here, the code path here is tested via the existing self.expect("image lookup -t A")

clang/lib/AST/StmtPrinter.cpp
1298

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

lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
39
/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

DavidSpickett accepted this revision.Oct 11 2022, 1:26 AM

although those changes don't actually test the code path changed here

Yeah I'm just cargo culting on that one so it doesn't look strange that a few are missing.

If we're going to change the suffix that can be done elsewhere and reviewed by someone who understands them better than me :)

Not crashing is an improvement in itself, LGTM.

This revision is now accepted and ready to land.Oct 11 2022, 1:26 AM