public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/110703] New: Incorrect "-Wfloat-conversion" diagnostic with _Generic
@ 2023-07-17 14:50 jepler at unpythonic dot net
  2023-07-17 19:25 ` [Bug c/110703] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: jepler at unpythonic dot net @ 2023-07-17 14:50 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110703
           Summary: Incorrect "-Wfloat-conversion" diagnostic with
                    _Generic
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jepler at unpythonic dot net
  Target Milestone: ---

When compiled with `gcc -Wfloat-conversion -c boo.c` the following code results
in a `-Wfloat-conversion` diagnostic across a range of gcc versions including
gcc version 12.2.0 (Debian 12.2.0-14) and godbolt "trunk" as of today
(https://godbolt.org/z/3K7sTTv1x)

```
#include <math.h>

#define tgsin(x) \
    _Generic((x), \
            double: sin((x)), \
            float: sinf((x)) \
            )

int f(double d) {
    return tgsin(d) > 0;
}
```

The result is
```
$ gcc -Wfloat-conversion -c boo.c
boo.c: In function ‘f’:
boo.c:10:18: warning: conversion from ‘double’ to ‘float’ may change value
[-Wfloat-conversion]
   10 |     return tgsin(d) > 0;
      |                  ^
boo.c:6:25: note: in definition of macro ‘tgsin’
    6 |             float: sinf(x) \
      |                         ^
```

As far as I can tell, the diagnostic is spurious, because it applies to the
"float" case of _Generic, which is not the one that is actually chosen. That
is, inspecting the resulting object file `boo.o` there is a call to sin but not
to sinf.

This is prompted by https://github.com/v923z/micropython-ulab/pull/636 and
earlier
https://github.com/micropython/micropython/commit/f31f9a8b70db03cbcbcf39b493f959d0e284962a
-- it at first appeared to be related to -Os size optimization, but that's just
related to how glibc chooses to implement fpclassify, whether via _Generic or
not.

This may be related to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68193

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-11-03 20:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-17 14:50 [Bug c/110703] New: Incorrect "-Wfloat-conversion" diagnostic with _Generic jepler at unpythonic dot net
2023-07-17 19:25 ` [Bug c/110703] " pinskia at gcc dot gnu.org
2023-08-04  6:05 ` muecker at gwdg dot de
2023-08-05  8:40 ` cvs-commit at gcc dot gnu.org
2023-11-03 20:09 ` uecker at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).