[LLVMdev] Wrong type qualifier for this pointer in case of ARM compiled binary

Tim Northover t.p.northover at gmail.com
Tue Oct 2 00:04:37 PDT 2012

Hi Karthik,

> Expected result when we run -
> print Simple::fun  in GDB is
> void fun(Simple* const this)
> as this should be a const pointer but in case of arm compiled binary we get
> void fun(Simple* this).

I believe the actual type is coming from CXXMethodDecl::getThisType,
which quotes the standard as saying:

  // C++ 9.3.2p1: The type of this in a member function of a class X is X*.
  // If the member function is declared const, the type of this is const X*,
  // if the member function is declared volatile, the type of this is
  // volatile X*, and if the member function is declared const volatile,
  // the type of this is const volatile X*.

I.e. no const where you're expecting it.

I've checked the standards, and we're not making it up either: both
C++11 and C++03 say the same.

> Seems to be problem with qualifier type but was wondering how is this
> target dependent?

I think it's the gdb programs that are printing different things for
the same DWARF debug information. Dumping the information from the x86
binary gives:

<1><6b>: Abbrev Number: 6 (DW_TAG_class_type)
    <6c>   DW_AT_name        : (indirect string, offset: 0x3e): Simple
    <70>   DW_AT_byte_size   : 1
    <71>   DW_AT_decl_file   : 1
    <72>   DW_AT_decl_line   : 1
<3><7f>: Abbrev Number: 8 (DW_TAG_formal_parameter)
    <80>   DW_AT_type        : <0x86>
    <84>   DW_AT_artificial  : 1
    <84>   DW_AT_object_pointer: 1
<1><86>: Abbrev Number: 9 (DW_TAG_pointer_type)
    <87>   DW_AT_type        : <0x6b>

The "this" parameter has type "Simple *" as expected, but also has the
attribute DW_AT_object_pointer. My guess is that the x86 gdb decides
to print it as "const" because of this, but the ARM one doesn't.

Hope this helps.


More information about the llvm-dev mailing list