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

            Bug ID: 87890
           Summary: inconsistency in handling floating built-ins declared
                    without prototype
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

While testing a patch for pr83656 I noticed another surprising inconsistency in
how built-ins declared without a prototype are handled.  In the test case
below, the fabs() declaration is accepted without a warning and the call to
fabs(-1.0) is folded to a constant.  But the declaration of fabsf() triggers a
warning and the equivalent call fabsf(-1.0f) is not folded.

The reason for this inconsistency is that the self_promoting_args_p() function
returns false for type float, and so the fabsf() function declaration without a
prototype is considered to be incompatible with fabsf(float).  GCC issues a
warning for it and treats it as an ordinary function.

$ cat t.c && gcc -O2 -S -Wall -fdump-tree-optimized=/dev/stdout t.c
double fabs ();   // no warning

double f (void)
{
  return fabs (-1.0);   // folded to 1.0
}


float fabsf ();   // warning

float g (void)
{
  return fabsf (-1.0f);   // not folded
}

t.c:9:7: warning: conflicting types for built-in function ‘fabsf’
[-Wbuiltin-declaration-mismatch]
    9 | float fabsf ();
      |       ^~~~~

;; Function f (f, funcdef_no=0, decl_uid=1907, cgraph_uid=1, symbol_order=0)

f ()
{
  <bb 2> [local count: 1073741824]:
  return 1.0e+0;

}



;; Function g (g, funcdef_no=1, decl_uid=1911, cgraph_uid=2, symbol_order=1)

g ()
{
  float _3;

  <bb 2> [local count: 1073741824]:
  _3 = fabsf (-1.0e+0); [tail call]
  return _3;

}

Reply via email to