[PATCH] Expose AST Record layout attributes to libclang

Dmitri Gribenko gribozavr at gmail.com
Tue Feb 12 04:11:16 PST 2013


On Tue, Feb 12, 2013 at 4:44 AM, Loïc Jaquemet <loic.jaquemet at gmail.com> wrote:
>>      assert all(x.translation_unit is not None for x in fields)
>> +····
>> +    align = teststruct.type.get_record_alignment()
>>
>> Trailing whitespace.
>>
>> assert fields[2].get_record_field_offset() == 8*(2*ctypes.sizeof(ctypes.c_int))
>>
>> Sorry, but this (and other lines) is wrong (there might be padding).
>> The proposed functions are being added for precisely that reason -- we
>> can not compute member offsets *simply by adding sizes of members*.
>> This test should specify a triple, too, and check for hardcoded
>> values.
>
> So, should I drop this offset test case ?
> or is there a expected behaviour list for each triple somewhere ?

This testcase should stay there, but it needs a slight modification.
Just choose some triple and hardcode the expected results (instead of
expressions like '8*(2*ctypes.sizeof(ctypes.c_int))').

In order to do this in python tests, pass '-target' 'x86_64-linux-gnu'
in the args array you introduced to get_tu().

>>
>>> Yet I have no idea how to correctly implement the test of a record
>>> size, given it is dependent of the tester's arch.
>>> is there some lit.py magic for that ?
>>
>> You should to specify a '-triple' to c-index-test.  See above.
>>
>
> So I never managed to get -triple working.
> My understanding is that its use is reserved to cc1, which is not
> leveraged in this context.
> But -m64 or -m32 works .
>
> example :
> # ok
> c-index-test -test-print-typekind local record-layout.c -m32
>
> # not ok
> c-index-test -test-print-typekind local record-layout.c -triple
> "i386-pc-linux-gnu"
> warning: argument unused during compilation: '-triple
> i386-pc-linux-gnu' [-Wunused-command-line-argument]
>
>
> I'm sorry to ask (lack of knowledge on my part) but will this be
> enough or does the packing/sizes depends on the full triple ?
>
> // RUN: c-index-test -test-print-typekind %s -m64 | FileCheck
> -check-prefix=CHECK64 %s
> // RUN: c-index-test -test-print-typekind %s -m32 | FileCheck
> -check-prefix=CHECK32 %s
>
> Or is there something else on the clang command line I could use ?

Oh, I see -- sorry, I was suggesting that without actually trying.
c-index-test only accepts driver arguments and does not accept '-cc1'
at all.  So please try with driver arguments:

c-index-test -test-print-typekind -target x86_64-linux-gnu ...

Dmitri

-- 
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/




More information about the cfe-commits mailing list