On 10/4/18 11:23 AM, Jan Hubicka wrote: >> Hi. >> >> That's new warnings that warns about ifunc having a function body. >> It provides following warning: >> >> /home/marxin/Programming/gcc/gcc/testsuite/gcc.dg/pr87483.c: In function ‘g’: >> /home/marxin/Programming/gcc/gcc/testsuite/gcc.dg/pr87483.c:5:35: warning: >> ‘alias’ attribute ignored because function is defined [-Wattributes] >> 5 | __attribute__ ((alias ("f"))) int g () { return 1; } /* { dg-warning >> "attribute ignored because function is defined" } */ >> | ^ >> >> Hope I found proper place in cgraphunit.c for the warning. >> Patch survives bootstrap and tests on x86_64-linux-gnu. >> >> Ready for trunk? > > I think one can first define the function and later declare it again > with additional attribute. I think it is better to take care of this > in process_function_and_variable_attributes
I've done that. Patch survives regression tests. Is it ok now? Martin > > Honza >> Martin >> >> gcc/ChangeLog: >> >> 2018-10-03 Martin Liska <mli...@suse.cz> >> >> PR c/87483 >> * cgraphunit.c (cgraph_node::finalize_function): >> Print error for functions with alias attribute and >> body. >> >> gcc/testsuite/ChangeLog: >> >> 2018-10-03 Martin Liska <mli...@suse.cz> >> >> PR c/87483 >> * gcc.dg/pr87483.c: New test. >> --- >> gcc/cgraphunit.c | 6 ++++++ >> gcc/testsuite/gcc.dg/pr87483.c | 16 ++++++++++++++++ >> 2 files changed, 22 insertions(+) >> create mode 100644 gcc/testsuite/gcc.dg/pr87483.c >> >> > >> diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c >> index c0baaeaefa4..40d6d348214 100644 >> --- a/gcc/cgraphunit.c >> +++ b/gcc/cgraphunit.c >> @@ -488,6 +488,12 @@ cgraph_node::finalize_function (tree decl, bool >> no_collect) >> if (!TREE_ASM_WRITTEN (decl)) >> (*debug_hooks->deferred_inline_function) (decl); >> >> + if (lookup_attribute ("alias", DECL_ATTRIBUTES (decl)) >> + && node->definition) >> + warning_at (DECL_SOURCE_LOCATION (node->decl), OPT_Wattributes, >> + "%<alias%> attribute ignored" >> + " because function is defined"); >> + >> if (!no_collect) >> ggc_collect (); >> >> 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(); >> +} >> >
>From 09ebc54a2163d50c729a04223c1cb95dfc392fac Mon Sep 17 00:00:00 2001 From: marxin <mli...@suse.cz> Date: Wed, 3 Oct 2018 15:18:03 +0200 Subject: [PATCH] Error about alias attribute with body definition (PR c/87483). gcc/ChangeLog: 2018-10-03 Martin Liska <mli...@suse.cz> PR c/87483 * cgraphunit.c (process_function_and_variable_attributes): Warn about a function with alias attribute and a body. gcc/testsuite/ChangeLog: 2018-10-03 Martin Liska <mli...@suse.cz> PR c/87483 * gcc.dg/pr87483.c: New test. --- gcc/cgraphunit.c | 6 ++++++ gcc/testsuite/gcc.dg/pr87483.c | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/pr87483.c 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, + "%<alias%> attribute ignored" + " because function is defined"); if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (decl)) && !DECL_DECLARED_INLINE_P (decl) 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.19.0