[cfe-commits] r147730 - in /cfe/trunk: include/clang/Sema/Sema.h lib/CodeGen/CodeGenFunction.cpp lib/Parse/ParseDecl.cpp lib/Sema/SemaDecl.cpp test/CodeGen/vla.c
Abramo Bagnara
abramo.bagnara at gmail.com
Sun Jan 8 00:56:27 PST 2012
Il 08/01/2012 09:35, Eli Friedman ha scritto:
> On Sun, Jan 8, 2012 at 12:12 AM, Abramo Bagnara
> <abramo.bagnara at gmail.com> wrote:
>> $ cat p.cc
>> long f();
>> long g();
>>
>> void m() {
>> __decltype((int (*)[f()])g()) x;
>> }
>>
>> $ g++ -O2 -S p.cc -o -
>> .file "p.cc"
>> .text
>> .p2align 4,,15
>> .globl _Z1mv
>> .type _Z1mv, @function
>> _Z1mv:
>> .LFB0:
>> .cfi_startproc
>> rep
>> ret
>> .cfi_endproc
>> .LFE0:
>> .size _Z1mv, .-_Z1mv
>> .ident "GCC: (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1"
>> .section .note.GNU-stack,"", at progbits
>
> That's... interesting... what happens if you try to return sizeof(*x)?
It calls f() (but not g()), just like clang does. The difference between
the two compilers is that clang always generates the call to f while gcc
generates it only when needed.
However neither of them evaluates the decltype expression but only the
vla type size. This can be verified by the missing call to g.
$ cat p.cc
long f();
long g();
long m() {
__decltype((int (*)[f()])g()) x;
return sizeof(*x);
}
$ g++ -O2 -S p.cc -o -
.file "p.cc"
.text
.p2align 4,,15
.globl _Z1mv
.type _Z1mv, @function
_Z1mv:
.LFB0:
.cfi_startproc
subq $8, %rsp
.cfi_def_cfa_offset 16
call _Z1fv
addq $8, %rsp
.cfi_def_cfa_offset 8
salq $2, %rax
ret
.cfi_endproc
.LFE0:
.size _Z1mv, .-_Z1mv
.ident "GCC: (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1"
.section .note.GNU-stack,"", at progbits
More information about the cfe-commits
mailing list