Skip to content

Linux: Wide character constants are interpreted as UTF16, which is wrong. #203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
PathogenDavid opened this issue Jul 6, 2021 · 2 comments
Labels
Area-Translation Issues concerning the translation from libclang into Biohazrd Bug Concept-Correctness Issues concerning the correctness of the translation from an ABI perspective Platform-Linux Issues specific to Linux

Comments

@PathogenDavid
Copy link
Member

This line assumes that wide character constants (IE: L"Hello, World") are UTF16, but this is not the case on Linux:

https://github.com/InfectedLibraries/Biohazrd/blob/e9145829b80dfc1d146177f66ef737930276f89f/Biohazrd/Expressions/ConstantValue.cs#L55

@PathogenDavid PathogenDavid added Concept-Correctness Issues concerning the correctness of the translation from an ABI perspective Bug Area-Translation Issues concerning the translation from libclang into Biohazrd Platform-Linux Issues specific to Linux labels Jul 6, 2021
PathogenDavid added a commit that referenced this issue Jul 9, 2021
@PathogenDavid
Copy link
Member Author

I'll probably end up just querying sizeof(wchar_t), but for posterity:

One interesting thing of note is that all builtins (apparently) end up being one of the five different sizes with signed/unsigned variants. Some of the sizes are completely fixed (for example, char is always 8 bits in Clang, short is always 16.) We can also use this to indirectly see which platforms are weird. (For instance, it looks like bool is 8 bits on everything except for PPC which uses 32-bits.)

@PathogenDavid
Copy link
Member Author

Since the translation unit is not available in the area where we decode constants, I actually ended up modifying pathogen_ComputeConstantValue in MochiLibraries/llvm-project@d9c68a3 to use the appropriate UTF kind for wchar_t constants. I also added a bit which is set when the string was a wchar_t constant just in case we ever care.

PathogenDavid added a commit that referenced this issue Aug 5, 2021
…s around string and char constants.

Also fixed a really dumb typo which was copy+pasted across multiple Unicode tests in DefaultArgumentValueTests.

Fixes #203
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Translation Issues concerning the translation from libclang into Biohazrd Bug Concept-Correctness Issues concerning the correctness of the translation from an ABI perspective Platform-Linux Issues specific to Linux
Projects
None yet
Development

No branches or pull requests

1 participant