[llvm-bugs] [Bug 36526] New: Clang's debug info does not mark 'this' parameters 'const' but GCC and MSVC do

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Feb 26 13:27:54 PST 2018


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

            Bug ID: 36526
           Summary: Clang's debug info does not mark 'this' parameters
                    'const' but GCC and MSVC do
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangbugs at nondot.org
          Reporter: rnk at google.com
                CC: llvm-bugs at lists.llvm.org

$ cat t.cpp
struct Foo {
  void f();
};
void Foo::f() {}

$ gcc -c t.cpp -g -o t.o && llvm-dwarfdump t.o
...
0x00000097:   DW_TAG_pointer_type
                DW_AT_byte_size (0x08)
                DW_AT_type      (cu + 0x006f "Foo")

0x0000009d:   DW_TAG_const_type
                DW_AT_type      (cu + 0x0097 "Foo*")

0x000000a2:   DW_TAG_subprogram
                DW_AT_specification     (cu + 0x007b "_ZN3Foo1fEv")
                DW_AT_decl_line (4)
                DW_AT_object_pointer    (cu + 0x00c2)
                DW_AT_low_pc    (0x0000000000000000)
                DW_AT_high_pc   (0x000000000000000b)
                DW_AT_frame_base        (DW_OP_call_frame_cfa)
                DW_AT_object_pointer    (cu + 0x00c2)
                DW_AT_GNU_all_call_sites        (true)

0x000000c2:     DW_TAG_formal_parameter
                  DW_AT_name    ("this")
                  DW_AT_type    (cu + 0x009d "const Foo*")
                  DW_AT_artificial      (true)
                  DW_AT_location        (DW_OP_fbreg +0)

$ clang -c t.cpp -g -o t.o && llvm-dwarfdump t.o
...
0x00000045:   DW_TAG_pointer_type
                DW_AT_type      (cu + 0x002a "Foo")

0x0000004a:   DW_TAG_subprogram
                DW_AT_low_pc    (0x0000000000000000)
                DW_AT_high_pc   (0x0000000000000007)
                DW_AT_frame_base        (DW_OP_reg7 RSP)
                DW_AT_object_pointer    (cu + 0x0062)
                DW_AT_decl_line (4)
                DW_AT_specification     (cu + 0x0033 "?f at Foo@@QEAAXXZ")

0x00000062:     DW_TAG_formal_parameter
                  DW_AT_location        (DW_OP_fbreg +0)
                  DW_AT_name    ("this")
                  DW_AT_type    (cu + 0x006f "Foo*")
                  DW_AT_artificial      (true)

Also, llvm-dwarfdump applies 'const' in the wrong place. It should appear to
the right of the pointer, as in 'Foo *const this', to indicate that Foo can be
modified, but 'this' cannot be made to point to another object.

Here is MSVC's opinion (note the 'IsConst: 1' below):

$ cl -c t.cpp -Z7 && llvm-readobj -codeview t.obj
...
  Pointer (0x1001) {
    TypeLeafKind: LF_POINTER (0x1002)
    PointeeType: Foo (0x1000)
    PointerAttributes: 0x1040C
    PtrType: Near64 (0xC)
    PtrMode: Pointer (0x0)
    IsFlat: 0
    IsConst: 1
    IsVolatile: 0
    IsUnaligned: 0
    IsRestrict: 0
    SizeOf: 8
  }
  ArgList (0x1002) {
    TypeLeafKind: LF_ARGLIST (0x1201)
    NumArgs: 0
    Arguments [
    ]
  }
  MemberFunction (0x1003) {
    TypeLeafKind: LF_MFUNCTION (0x1009)
    ReturnType: void (0x3)
    ClassType: Foo (0x1000)
    ThisType: const Foo* (0x1001)
    CallingConvention: NearC (0x0)
    FunctionOptions [ (0x0)
    ]
    NumParameters: 0
    ArgListType: () (0x1002)
    ThisAdjustment: 0
  }

Given that both mainstream compilers disagree with us on this, we should
probably change our output.

-- 
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/20180226/97ec8d03/attachment.html>


More information about the llvm-bugs mailing list