[llvm-bugs] [Bug 38567] New: Microsoft C++ Mangler Incompatibility with pointers to arrays.

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Aug 14 13:13:59 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=38567

            Bug ID: 38567
           Summary: Microsoft C++ Mangler Incompatibility with pointers to
                    arrays.
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: zturner at google.com
                CC: cdavis5x at gmail.com, david.majnemer at gmail.com,
                    llvm-bugs at lists.llvm.org, nicolasweber at gmx.de,
                    rnk at google.com

I discovered this while messing around with some test code.  Haven't hit this
in a real world scenario yet.

// foo.cpp
double const (*color4)[3] = nullptr;
extern double const (*const color5)[3];
int main(int argc, char **argv) {
  return (int)*color3[0] + (int)*color4[0] + (int)*color5[0];
}

D:\src\llvmbuild\cl\Release\x64>bin\clang-cl -m64 /Z7 /c /Od foo.cpp && dumpbin
/symbols foo.obj | grep color
012 00000000 SECT3  notype       External     | ?color4@@3PEAY02$$CBNEB (double
const (* const color4)[3])
013 00000000 UNDEF  notype       External     | ?color5@@3QEAY02$$CBNEB (double
const (* const color5)[3])

D:\src\llvmbuild\cl\Release\x64>cl /Z7 /c /Od foo.cpp && dumpbin /symbols
foo.obj | grep color
Microsoft (R) C/C++ Optimizing Compiler Version 19.14.26433 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

foo.cpp
00A 00000000 SECT4  notype       External     | ?color4@@3PEAY02$$CBNEA (double
const (* color4)[3])
016 00000000 UNDEF  notype       External     | ?color5@@3QEAY02$$CBNEA (double
const (* color5)[3])

The manglings of color4 and color5 don't match.

color4 (MSVC):  ?color4@@3PEAY02$$CBNEA
color4 (Clang): ?color4@@3PEAY02$$CBNEB

color5 (MSVC):  ?color5@@3QEAY02$$CBNEA
color5 (Clang): ?color5@@3QEAY02$$CBNEB

Despite the fact that in the original source code there are only two possible
locations for a cv qualifier, in the mangling there are 3.

In color 4, the first P means (non const pointer), and in color 5 the
corresponding Q means const pointer.
In color 4 and 5, the first B means "const double".
The last qualifier (which is where the mismatch occurs), is on the variable
itself, and is added to variables of pointer types and is supposed to describe
the CVR-ness of the pointee.  In this case, the "pointee" is the array.  

So for color4, MSVC is mangling this as "non-const pointer (P) to non-const
array (A) of const doubles (B)" while we are mangling this as "non-const
pointer (P) to const array (B2) of const doubles (B1)".
And for color5, MSVC is mangling this as "const pointer (Q) to non-const array
(A) of const doubles (B)", while we are mangling it as "const pointer (Q) to
const array (B2) of const doubles (B1)".

I think I have this explanation correct.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180814/57d8e6a7/attachment.html>


More information about the llvm-bugs mailing list