From fb7125d771cb6fa103b40769dd305ba1c731ed25 Mon Sep 17 00:00:00 2001 From: marxin Date: Thu, 4 Oct 2018 14:44:53 +0000 Subject: [PATCH] Error about alias attribute with body definition (PR c/87483). 2018-10-04 Martin Liska PR c/87483 * cgraphunit.c (process_function_and_variable_attributes): Warn about a function with alias attribute and a body. 2018-10-04 Martin Liska PR c/87483 * gcc.dg/pr87483.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@264846 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 6 ++++++ gcc/cgraphunit.c | 6 ++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/pr87483.c | 16 ++++++++++++++++ 4 files changed, 33 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/pr87483.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index f7a15e34646..0340fa32e55 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,11 @@ 2018-10-04 Martin Liska + PR c/87483 + * cgraphunit.c (process_function_and_variable_attributes): + Warn about a function with alias attribute and a body. + +2018-10-04 Martin Liska + PR ipa/82625 * multiple_target.c (redirect_to_specific_clone): New function. (ipa_target_clone): Use it. diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c index c0baaeaefa4..146855fa804 100644 --- a/gcc/cgraphunit.c +++ b/gcc/cgraphunit.c @@ -784,6 +784,12 @@ process_function_and_variable_attributes (cgraph_node *first, DECL_ATTRIBUTES (decl) = remove_attribute ("weakref", DECL_ATTRIBUTES (decl)); } + else if (lookup_attribute ("alias", DECL_ATTRIBUTES (decl)) + && node->definition + && !node->alias) + warning_at (DECL_SOURCE_LOCATION (node->decl), OPT_Wattributes, + "% attribute ignored" + " because function is defined"); if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (decl)) && !DECL_DECLARED_INLINE_P (decl) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ee8a184c26a..7da77d1d4c4 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,10 @@ 2018-10-04 Martin Liska + PR c/87483 + * gcc.dg/pr87483.c: New test. + +2018-10-04 Martin Liska + PR ipa/82625 * g++.dg/ext/pr82625.C: New test. diff --git a/gcc/testsuite/gcc.dg/pr87483.c b/gcc/testsuite/gcc.dg/pr87483.c new file mode 100644 index 00000000000..d3af8dfee5d --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr87483.c @@ -0,0 +1,16 @@ +/* PR c/87483 */ +/* { dg-require-alias "" } */ + +int f (void) { return 0; } +__attribute__ ((alias ("f"))) int g () { return 1; } /* { dg-warning "attribute ignored because function is defined" } */ +__attribute__ ((alias ("f"))) int g2 (); + +int h (void) +{ + return g2 (); +} + +int main() +{ + return h(); +} -- 2.11.4.GIT