This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix ICF with error/warning attribute (PR ipa/84628, take 3)
Hi!
On Fri, Mar 02, 2018 at 10:54:36AM +0100, Jakub Jelinek wrote:
> On Fri, Mar 02, 2018 at 09:31:16AM +0100, Richard Biener wrote:
> > On Fri, 2 Mar 2018, Jakub Jelinek wrote:
> >
> > > On Fri, Mar 02, 2018 at 09:15:07AM +0100, Richard Biener wrote:
> > > > You probably need a virtual return thunk as otherwise we expand them
> > > > directly to asm?
> > >
> > > I was trying x86_64 -m32 -fpic regparm (3) method with thunks so that
> > > the asm isn't emitted. But the thunk was still using call to .LTHUNKN
> > > rather than the actual method FUNCTION_DECL. Perhaps on targets without
> > > proper alias support...
> > >
> > > > > Would you prefer just being silent in all thunks?
> > > >
> > > > Yes, I think all warnings from thunks are ultimately going to be bogus...
> > >
> > > Ok, I'll change the patch.
>
> Unfortunately it doesn't work, see patch below.
But this works, ok if it passes bootstrap/regtest?
2018-03-02 Jakub Jelinek <jakub@redhat.com>
Richard Biener <rguenther@suse.de>
PR ipa/84628
* expr.c (expand_expr_real_1) <case CALL_EXPR>: Don't emit diagnostics
for error or warning attributes if CALL_FROM_THUNK_P is set.
Formatting fixes.
* gcc.dg/pr84628.c: New test.
--- gcc/expr.c.jj 2018-02-09 19:11:29.094068531 +0100
+++ gcc/expr.c 2018-03-02 11:12:19.299665926 +0100
@@ -10963,18 +10963,30 @@ expand_expr_real_1 (tree exp, rtx target
tree fndecl = get_callee_fndecl (exp), attr;
if (fndecl
+ /* Don't diagnose the error attribute in thunks, those are
+ artificially created. */
+ && !CALL_FROM_THUNK_P (exp)
&& (attr = lookup_attribute ("error",
DECL_ATTRIBUTES (fndecl))) != NULL)
- error ("%Kcall to %qs declared with attribute error: %s",
- exp, identifier_to_locale (lang_hooks.decl_printable_name (fndecl, 1)),
- TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
+ {
+ const char *ident = lang_hooks.decl_printable_name (fndecl, 1);
+ error ("%Kcall to %qs declared with attribute error: %s", exp,
+ identifier_to_locale (ident),
+ TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
+ }
if (fndecl
+ /* Don't diagnose the warning attribute in thunks, those are
+ artificially created. */
+ && !CALL_FROM_THUNK_P (exp)
&& (attr = lookup_attribute ("warning",
DECL_ATTRIBUTES (fndecl))) != NULL)
- warning_at (tree_nonartificial_location (exp),
- 0, "%Kcall to %qs declared with attribute warning: %s",
- exp, identifier_to_locale (lang_hooks.decl_printable_name (fndecl, 1)),
- TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
+ {
+ const char *ident = lang_hooks.decl_printable_name (fndecl, 1);
+ warning_at (tree_nonartificial_location (exp), 0,
+ "%Kcall to %qs declared with attribute warning: %s",
+ exp, identifier_to_locale (ident),
+ TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
+ }
/* Check for a built-in function. */
if (fndecl && DECL_BUILT_IN (fndecl))
--- gcc/testsuite/gcc.dg/pr84628.c.jj 2018-03-02 10:24:08.975815667 +0100
+++ gcc/testsuite/gcc.dg/pr84628.c 2018-03-02 10:24:08.975815667 +0100
@@ -0,0 +1,8 @@
+/* PR ipa/84628 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+int f0 (void);
+__attribute__((error ("err"))) void f1 (void) { f0 (); f0 (); }
+__attribute__((error ("err"))) void f2 (void) { f0 (); f0 (); }
+/* { dg-bogus "declared with attribute error" "" { target *-*-* } 0 } */
Jakub