[PATCH] D48928: [ms] Fix mangling of string literals used to initialize arrays larger or smaller than the literal

Nico Weber via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 5 14:31:56 PDT 2018


thakis accepted this revision.
thakis added a comment.
This revision is now accepted and ready to land.

Nice!



================
Comment at: lib/AST/MicrosoftMangle.cpp:3198
+                              ->getSize()
+                              .getZExtValue();
+
----------------
nit: Also do `unsigned StingByteLength = StringLength * SL->getCharByteWidth()` here and use it the 3 times you have that computation below


================
Comment at: lib/AST/MicrosoftMangle.cpp:3210
 
-  auto GetLittleEndianByte = [&SL](unsigned Index) {
+  auto GetLittleEndianByte = [&SL, StringLength](unsigned Index) {
     unsigned CharByteWidth = SL->getCharByteWidth();
----------------
You're capturing StringLength here, but then you don't use it in the lambda body.


================
Comment at: lib/AST/MicrosoftMangle.cpp:3219
 
-  auto GetBigEndianByte = [&SL](unsigned Index) {
+  auto GetBigEndianByte = [&SL, StringLength](unsigned Index) {
     unsigned CharByteWidth = SL->getCharByteWidth();
----------------
likewise


================
Comment at: test/CodeGen/mangle-ms-string-literals.c:7
+  struct {int x; char s[2]; } truncatedAscii = {x, "hello"};
+  // CHECK: "??_C at _01CONKJJHI@he@"
+  struct {int x; char s[16]; } paddedAscii = {x, "hello"};
----------------
Nice, we used to mismangle this. MSVC matches the string here: https://godbolt.org/g/dbm6jT (old clang: https://godbolt.org/g/Yy7iCK)


https://reviews.llvm.org/D48928





More information about the cfe-commits mailing list