https://gcc.gnu.org/g:678c3f06fc165b883f63b0c44ce9f650b7c1504a
commit r15-6712-g678c3f06fc165b883f63b0c44ce9f650b7c1504a Author: Thomas Schwinge <tschwi...@baylibre.com> Date: Thu Dec 12 23:26:14 2024 +0100 nvptx: Add '__builtin_alloca(0)' test cases [PR65181] Documenting the status quo. This specific behavior relates to a 1994 change (Subversion r7229, Git commit 15fc002672d643fd9d93d220027b5cd2aefc632c). That one, however, isn't to blame here: we'd otherwise of course run into nvptx' 'sorry, unimplemented: target cannot support alloca'. PR target/65181 gcc/testsuite/ * gcc.target/nvptx/__builtin_alloca_0-1-O0.c: New. * gcc.target/nvptx/__builtin_alloca_0-1-O1.c: Likewise. Diff: --- .../gcc.target/nvptx/__builtin_alloca_0-1-O0.c | 37 ++++++++++++++++++++++ .../gcc.target/nvptx/__builtin_alloca_0-1-O1.c | 33 +++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/gcc/testsuite/gcc.target/nvptx/__builtin_alloca_0-1-O0.c b/gcc/testsuite/gcc.target/nvptx/__builtin_alloca_0-1-O0.c new file mode 100644 index 000000000000..8c00a66c7387 --- /dev/null +++ b/gcc/testsuite/gcc.target/nvptx/__builtin_alloca_0-1-O0.c @@ -0,0 +1,37 @@ +/* Document what we run into for '__builtin_alloca(0)'. */ + +/* { dg-do compile } + TODO We can't 'assemble' this -- it's invalid PTX code. */ +/* { dg-options {-O0 -mno-soft-stack} } */ +/* { dg-additional-options -save-temps } */ +/* { dg-final { check-function-bodies {** } {} } } */ + +void sink(void *); + +void f(void) +{ + sink(__builtin_alloca(0)); +} +/* +** f: +** .visible .func f +** { +** \.reg\.u64 (%r[0-9]+); +** \.reg\.u64 (%r[0-9]+); +** mov\.u64 \1, %stack; +** mov\.u64 \2, \1; +** { +** \.param\.u64 %out_arg1; +** st\.param\.u64 \[%out_arg1\], \2; +** call sink, \(%out_arg1\); +** } +** ret; +*/ + +/* '%stack' is 'VIRTUAL_STACK_DYNAMIC_REGNUM', 'virtual_stack_dynamic_rtx'. + For '__builtin_alloca (0)', we get to + 'gcc/explow.cc:allocate_dynamic_stack_space', where 'addr' gets set to + 'virtual_stack_dynamic_rtx', 'size == const0_rtx', therefore 'return addr;', + which gets us '%stack' -- undefined (TODO). + + { dg-final { scan-assembler-not {%stack} { xfail *-*-* } } } */ diff --git a/gcc/testsuite/gcc.target/nvptx/__builtin_alloca_0-1-O1.c b/gcc/testsuite/gcc.target/nvptx/__builtin_alloca_0-1-O1.c new file mode 100644 index 000000000000..2d61065d44d6 --- /dev/null +++ b/gcc/testsuite/gcc.target/nvptx/__builtin_alloca_0-1-O1.c @@ -0,0 +1,33 @@ +/* Document what we run into for '__builtin_alloca(0)'. */ + +/* { dg-do compile } + TODO We can't 'assemble' this -- it's invalid PTX code. */ +/* { dg-options {-O1 -mno-soft-stack} } */ +/* { dg-additional-options -save-temps } */ +/* { dg-final { check-function-bodies {** } {} } } */ + +void sink(void *); + +void f(void) +{ + sink(__builtin_alloca(0)); +} +/* +** f: +** .visible .func f +** { +** { +** \.param\.u64 %out_arg1; +** st\.param\.u64 \[%out_arg1\], %stack; +** call sink, \(%out_arg1\); +** } +** ret; +*/ + +/* '%stack' is 'VIRTUAL_STACK_DYNAMIC_REGNUM', 'virtual_stack_dynamic_rtx'. + For '__builtin_alloca (0)', we get to + 'gcc/explow.cc:allocate_dynamic_stack_space', where 'addr' gets set to + 'virtual_stack_dynamic_rtx', 'size == const0_rtx', therefore 'return addr;', + which gets us '%stack' -- undefined (TODO). + + { dg-final { scan-assembler-not {%stack} { xfail *-*-* } } } */