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?
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();
+}

Reply via email to