From fc15d9ecb432173f2a17c58352d4b70c1ee049e4 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Mon, 19 Sep 2016 16:36:38 +0200 Subject: [PATCH] re PR ipa/77587 (C compiler produces incorrect stack alignment with __attribute__((weak))) PR target/77587 * cgraph.c (cgraph_node::rtl_info): Pass &avail to ultimate_alias_target call, return NULL if avail < AVAIL_AVAILABLE. Call ultimate_alias_target just once, not up to 4 times. * gcc.dg/pr77587.c: New test. * gcc.dg/pr77587a.c: New file. Co-Authored-By: Jan Hubicka From-SVN: r240232 --- gcc/ChangeLog | 8 ++++++++ gcc/cgraph.c | 17 ++++++++++------- gcc/testsuite/ChangeLog | 7 +++++++ gcc/testsuite/gcc.dg/pr77587.c | 14 ++++++++++++++ gcc/testsuite/gcc.dg/pr77587a.c | 23 +++++++++++++++++++++++ 5 files changed, 62 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr77587.c create mode 100644 gcc/testsuite/gcc.dg/pr77587a.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 2f3f91b4a03..3fb3b0f1e5b 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2016-09-19 Jakub Jelinek + Jan Hubicka + + PR target/77587 + * cgraph.c (cgraph_node::rtl_info): Pass &avail to + ultimate_alias_target call, return NULL if avail < AVAIL_AVAILABLE. + Call ultimate_alias_target just once, not up to 4 times. + 2016-09-19 Richard Biener * dwarf2out.c (early_dwarf_finished): New global. diff --git a/gcc/cgraph.c b/gcc/cgraph.c index 9bc5b6b7c51..0f9df95fd54 100644 --- a/gcc/cgraph.c +++ b/gcc/cgraph.c @@ -1955,14 +1955,17 @@ cgraph_node::rtl_info (tree decl) cgraph_node *node = get (decl); if (!node) return NULL; - node = node->ultimate_alias_target (); - if (node->decl != current_function_decl - && !TREE_ASM_WRITTEN (node->decl)) + enum availability avail; + node = node->ultimate_alias_target (&avail); + if (decl != current_function_decl + && (avail < AVAIL_AVAILABLE + || (node->decl != current_function_decl + && !TREE_ASM_WRITTEN (node->decl)))) return NULL; - /* Allocate if it doesnt exist. */ - if (node->ultimate_alias_target ()->rtl == NULL) - node->ultimate_alias_target ()->rtl = ggc_cleared_alloc (); - return node->ultimate_alias_target ()->rtl; + /* Allocate if it doesn't exist. */ + if (node->rtl == NULL) + node->rtl = ggc_cleared_alloc (); + return node->rtl; } /* Return a string describing the failure REASON. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 70d7c56535f..361ed14ca87 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2016-09-19 Jakub Jelinek + Jan Hubicka + + PR target/77587 + * gcc.dg/pr77587.c: New test. + * gcc.dg/pr77587a.c: New file. + 2016-09-19 Andre Vehreschild * gfortran.dg/coarray/alloc_comp_4.f90: New test. diff --git a/gcc/testsuite/gcc.dg/pr77587.c b/gcc/testsuite/gcc.dg/pr77587.c new file mode 100644 index 00000000000..1e42f142f7a --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr77587.c @@ -0,0 +1,14 @@ +/* PR target/77587 */ +/* { dg-do run } */ +/* { dg-require-weak-override "" } */ +/* { dg-additional-sources "pr77587a.c" } */ + +void +bar (long x, long y, long z) +{ + struct __attribute__((aligned (16))) S { long a, b, c, d; } s; + char *p = (char *) &s; + __asm ("" : "+r" (p)); + if (((__UINTPTR_TYPE__) p) & 15) + __builtin_abort (); +} diff --git a/gcc/testsuite/gcc.dg/pr77587a.c b/gcc/testsuite/gcc.dg/pr77587a.c new file mode 100644 index 00000000000..ed98e12b87e --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr77587a.c @@ -0,0 +1,23 @@ +/* PR target/77587 */ +/* { dg-do compile } */ +/* { dg-require-weak-override "" } */ + +void +foo (long x, long y, long z) +{ +} + +void bar (long x, long y, long z) __attribute__ ((weak, alias ("foo"))); + +void +baz (long x, long y, long z) +{ + bar (0, 0, 0); +} + +int +main () +{ + baz (0, 0, 0); + return 0; +} -- 2.30.2