From: Alexander Basov Date: Mon, 3 Aug 2015 19:34:31 +0000 (+0000) Subject: re PR middle-end/64744 (ARM: gcc internal compiler error: in store_field, at expr... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=de0fb9055c0928960ecc8e3a5fe990728611c3ca;p=gcc.git re PR middle-end/64744 (ARM: gcc internal compiler error: in store_field, at expr.c:6659) PR middle-end/64744 PR middle-end/48470 PR middle-end/43404 * cfgexpand.c (expand_one_var): Add check if stack is going to be used in naked function. * expr.c (expand_expr_addr_expr_1): Remove excess checking whether expression should not reside in MEM. * function.c (use_register_for_decl): Do not use registers for non-register things (volatile, float, BLKMode) in naked functions. PR middle-end/64744 PR middle-end/48470 PR middle-end/43404 * gcc.target/arm/pr43404.c : New testcase. * gcc.target/arm/pr48470.c : New testcase. * gcc.target/arm/pr64744-1.c : New testcase. * gcc.target/arm/pr64744-2.c : New testcase. From-SVN: r226528 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index ca0da01fe0a..d9fb2c1495d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,15 @@ +2015-08-03 Alexander Basov + + PR middle-end/64744 + PR middle-end/48470 + PR middle-end/43404 + * cfgexpand.c (expand_one_var): Add check if stack is going to + be used in naked function. + * expr.c (expand_expr_addr_expr_1): Remove excess checking + whether expression should not reside in MEM. + * function.c (use_register_for_decl): Do not use registers for + non-register things (volatile, float, BLKMode) in naked functions. + 2015-08-03 John David Anglin PR target/67060 diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c index 8ff79abf691..7df9d06fab3 100644 --- a/gcc/cfgexpand.c +++ b/gcc/cfgexpand.c @@ -1335,7 +1335,16 @@ expand_one_var (tree var, bool toplevel, bool really_expand) else { if (really_expand) - expand_one_stack_var (origvar); + { + if (lookup_attribute ("naked", + DECL_ATTRIBUTES (current_function_decl))) + error ("cannot allocate stack for variable %q+D, naked function.", + var); + + expand_one_stack_var (origvar); + } + + return tree_to_uhwi (DECL_SIZE_UNIT (var)); } return 0; diff --git a/gcc/expr.c b/gcc/expr.c index 46084c2efec..31b4573009a 100644 --- a/gcc/expr.c +++ b/gcc/expr.c @@ -7603,15 +7603,7 @@ expand_expr_addr_expr_1 (tree exp, rtx target, machine_mode tmode, marked TREE_ADDRESSABLE, which will be either a front-end or a tree optimizer bug. */ - if (TREE_ADDRESSABLE (exp) - && ! MEM_P (result) - && ! targetm.calls.allocate_stack_slots_for_args ()) - { - error ("local frame unavailable (naked function?)"); - return result; - } - else - gcc_assert (MEM_P (result)); + gcc_assert (MEM_P (result)); result = XEXP (result, 0); /* ??? Is this needed anymore? */ diff --git a/gcc/function.c b/gcc/function.c index 536de195acf..20bf3b3a834 100644 --- a/gcc/function.c +++ b/gcc/function.c @@ -2105,9 +2105,6 @@ aggregate_value_p (const_tree exp, const_tree fntype) bool use_register_for_decl (const_tree decl) { - if (!targetm.calls.allocate_stack_slots_for_args ()) - return true; - /* Honor volatile. */ if (TREE_SIDE_EFFECTS (decl)) return false; @@ -2135,6 +2132,9 @@ use_register_for_decl (const_tree decl) if (flag_float_store && FLOAT_TYPE_P (TREE_TYPE (decl))) return false; + if (!targetm.calls.allocate_stack_slots_for_args ()) + return true; + /* If we're not interested in tracking debugging information for this decl, then we can certainly put it in a register. */ if (DECL_IGNORED_P (decl)) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 44d7eb95882..1fe025bc487 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,13 @@ +2015-08-03 Alexander Basov + + PR middle-end/64744 + PR middle-end/48470 + PR middle-end/43404 + * gcc.target/arm/pr43404.c : New testcase. + * gcc.target/arm/pr48470.c : New testcase. + * gcc.target/arm/pr64744-1.c : New testcase. + * gcc.target/arm/pr64744-2.c : New testcase. + 2015-08-03 H.J. Lu PR tree-optimization/67077 diff --git a/gcc/testsuite/gcc.target/arm/pr43404.c b/gcc/testsuite/gcc.target/arm/pr43404.c new file mode 100644 index 00000000000..4f2291df6a8 --- /dev/null +++ b/gcc/testsuite/gcc.target/arm/pr43404.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target naked_functions } */ +/* { dg-options "-O0" } */ + +__attribute__ ((naked)) +void __data_abort(void) +{ + long foo; /* { dg-error "cannot allocate stack for variable" } */ + long* bar = &foo; +} diff --git a/gcc/testsuite/gcc.target/arm/pr48470.c b/gcc/testsuite/gcc.target/arm/pr48470.c new file mode 100644 index 00000000000..20343e71bb9 --- /dev/null +++ b/gcc/testsuite/gcc.target/arm/pr48470.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target naked_functions } */ +/* { dg-options "-O0" } */ + +extern void g(int *x); + +void __attribute__((naked)) f(void) +{ + int x = 0; /* { dg-error "cannot allocate stack for variable" } */ + g(&x); +} diff --git a/gcc/testsuite/gcc.target/arm/pr64744-1.c b/gcc/testsuite/gcc.target/arm/pr64744-1.c new file mode 100644 index 00000000000..402930351b5 --- /dev/null +++ b/gcc/testsuite/gcc.target/arm/pr64744-1.c @@ -0,0 +1,40 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target naked_functions } */ +/* { dg-options "-O0" } */ + +__attribute__((naked)) +void foo1 () +{ + int aa = 0; + int ab = {0}; +} + +__attribute__((naked)) +void foo2() { + char aa [ ] = {}; /* { dg-error "cannot allocate stack for variable" } */ + char ab [1] = {}; + char ac [2] = {}; /* { dg-error "cannot allocate stack for variable" } */ + char ad [3] = {}; /* { dg-error "cannot allocate stack for variable" } */ +} + +__attribute__((naked)) +void foo3() { + char aa [1] = {0}; + char ab [2] = {0}; /* { dg-error "cannot allocate stack for variable" } */ + char ac [3] = {0}; /* { dg-error "cannot allocate stack for variable" } */ + char ad [4] = {0}; /* { dg-error "cannot allocate stack for variable" } */ +} + +__attribute__((naked)) +void foo4() { + char aa [2] = {0,0}; /* { dg-error "cannot allocate stack for variable" } */ +} +__attribute__((naked)) +void foo5() { + char aa [3] = {0,0,0}; /* { dg-error "cannot allocate stack for variable" } */ +} + +__attribute__((naked)) +void foo6() { + char aa [4] = {0,0,0,0}; /* { dg-error "cannot allocate stack for variable" } */ +} diff --git a/gcc/testsuite/gcc.target/arm/pr64744-2.c b/gcc/testsuite/gcc.target/arm/pr64744-2.c new file mode 100644 index 00000000000..d33ea7bd5fe --- /dev/null +++ b/gcc/testsuite/gcc.target/arm/pr64744-2.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target naked_functions } */ +/* { dg-options "-O0" } */ + +struct s { + char a; + int b; +}; + +__attribute__((naked)) +void foo () { + struct s x = {}; /* { dg-error "cannot allocate stack for variable" } */ +}