From f22712bd8a2ed57d3cc7e6fa92730bd5852e27b3 Mon Sep 17 00:00:00 2001 From: Jan Hubicka Date: Thu, 19 Mar 2020 17:12:56 +0100 Subject: [PATCH] Fix inliner ICE on alias with flatten attribute [PR92372] gcc/ChangeLog: 2020-03-19 Jan Hubicka PR ipa/92372 * cgraphunit.c (process_function_and_variable_attributes): warn for flatten attribute on alias. * ipa-inline.c (ipa_inline): Do not ICE on flatten attribute on alias. gcc/testsuite/ChangeLog: 2020-03-19 Jan Hubicka PR ipa/92372 * gcc.c-torture/pr92372.c: New test. * gcc.dg/attr-flatten-1.c: New test. --- gcc/ChangeLog | 7 +++++++ gcc/cgraphunit.c | 8 ++++++++ gcc/ipa-inline.c | 3 +++ gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/gcc.c-torture/pr92372.c | 16 ++++++++++++++++ gcc/testsuite/gcc.dg/attr-flatten-1.c | 18 ++++++++++++++++++ 6 files changed, 58 insertions(+) create mode 100644 gcc/testsuite/gcc.c-torture/pr92372.c create mode 100644 gcc/testsuite/gcc.dg/attr-flatten-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 6b1b2956e7a..e1a778df202 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2020-03-19 Jan Hubicka + + PR ipa/92372 + * cgraphunit.c (process_function_and_variable_attributes): warn + for flatten attribute on alias. + * ipa-inline.c (ipa_inline): Do not ICE on flatten attribute on alias. + 2020-03-19 Martin Liska * lto-section-in.c: Add ext_symtab. diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c index fd586366bb9..d7ed405bf2c 100644 --- a/gcc/cgraphunit.c +++ b/gcc/cgraphunit.c @@ -851,6 +851,14 @@ process_function_and_variable_attributes (cgraph_node *first, node = symtab->next_function (node)) { tree decl = node->decl; + + if (node->alias + && lookup_attribute ("flatten", DECL_ATTRIBUTES (decl))) + { + warning_at (DECL_SOURCE_LOCATION (node->decl), OPT_Wattributes, + "%" + " attribute attribute is ignored on aliases"); + } if (DECL_PRESERVE_P (decl)) node->mark_force_output (); else if (lookup_attribute ("externally_visible", DECL_ATTRIBUTES (decl))) diff --git a/gcc/ipa-inline.c b/gcc/ipa-inline.c index 6b6ba9aa4b6..302ce16a646 100644 --- a/gcc/ipa-inline.c +++ b/gcc/ipa-inline.c @@ -2634,6 +2634,9 @@ ipa_inline (void) { node = order[i]; if (node->definition + /* Do not try to flatten aliases. These may happen for example when + creating local aliases. */ + && !node->alias && lookup_attribute ("flatten", DECL_ATTRIBUTES (node->decl)) != NULL) order[j--] = order[i]; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 58f2e7e7c47..cce16031845 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2020-03-19 Jan Hubicka + + PR ipa/92372 + * gcc.c-torture/pr92372.c: New test. + * gcc.dg/attr-flatten-1.c: New test. + 2020-03-19 Jakub Jelinek PR tree-optimization/94211 diff --git a/gcc/testsuite/gcc.c-torture/pr92372.c b/gcc/testsuite/gcc.c-torture/pr92372.c new file mode 100644 index 00000000000..72a13bb16f4 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/pr92372.c @@ -0,0 +1,16 @@ +int fn2(int); +int fn3(int); + +__attribute__((flatten)) +int fn1(int p1) +{ + int a = fn2(p1); + return fn3(a); +} +__attribute__((flatten)) +int fn4(int p1) +{ + int j = fn2(p1); + return fn3(j); +} + diff --git a/gcc/testsuite/gcc.dg/attr-flatten-1.c b/gcc/testsuite/gcc.dg/attr-flatten-1.c new file mode 100644 index 00000000000..ecb08fcd2ad --- /dev/null +++ b/gcc/testsuite/gcc.dg/attr-flatten-1.c @@ -0,0 +1,18 @@ +/* { dg-require-alias "" } */ +int fn2(int); +int fn3(int); + +__attribute__((flatten)) +int fn1(int p1) +{ + int a = fn2(p1); + return fn3(a); +} +__attribute__((flatten)) +__attribute__((alias("fn1"))) +int fn4(int p1); /* { dg-warning "ignored" } */ +int +test () +{ + return fn4(1); +} -- 2.30.2