This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/84294] attributes on a function template redeclaration silently discarded


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84294

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2018-02-28
            Summary|missing warning for ignored |attributes on a function
                   |attribute on a function     |template redeclaration
                   |template declaration        |silently discarded
     Ever confirmed|0                           |1
      Known to fail|                            |6.4.0, 7.3.0, 8.0

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
I'll confirm this bug because it was the indirect cause of a number of test
suite regressions recently (bug 84617).  The problem is also not just one of a
missing diagnostic but rather one of G++ failing to apply attributes specified
on a function template re-declaration that were not specified on the first
declaration of the template.  I.e., it's a missed optimization opportunity.

An enhanced test case:

$cat b.C && gcc -O2 -S -Wall -Wextra -fdump-tree-optimized=/dev/stdout b.C
int f ();

int __attribute__ ((const)) f ();

void ff ()
{
  int i0 = f ();
  int i1 = f ();

  if (i0 != i1)           // folded to false
    __builtin_abort ();
}

template <class>
int g ();

template <class>
int __attribute__ ((const)) g ();

void gg ()
{
  int i0 = g<int>();
  int i1 = g<int>();

  if (i0 != i1)           // not folded
    __builtin_abort ();
}

template <class>
int __attribute__ ((const)) h ();

template <class>
int h ();

void hh ()
{
  int i0 = h<int>();
  int i1 = h<int>();

  if (i0 != i1)           // folded to false
    __builtin_abort ();
}


;; Function ff (_Z2ffv, funcdef_no=0, decl_uid=2361, cgraph_uid=0,
symbol_order=0)

ff ()
{
  <bb 2> [local count: 1073741825]:
  return;

}



;; Function gg (_Z2ggv, funcdef_no=1, decl_uid=2371, cgraph_uid=1,
symbol_order=1)

gg ()
{
  int _3;
  int _5;

  <bb 2> [local count: 1073741825]:
  _3 = g<int> ();
  _5 = g<int> ();
  if (_3 != _5)
    goto <bb 3>; [0.00%]
  else
    goto <bb 4>; [99.96%]

  <bb 3> [count: 0]:
  __builtin_abort ();

  <bb 4> [local count: 1073312327]:
  return;

}



;; Function hh (_Z2hhv, funcdef_no=4, decl_uid=2382, cgraph_uid=2,
symbol_order=2)

hh ()
{
  <bb 2> [local count: 1073741825]:
  return;

}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]