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
* [Bug c/110703] Incorrect "-Wfloat-conversion" diagnostic with _Generic
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 ` pinskia at gcc dot gnu.org
2023-08-04 6:05 ` muecker at gwdg dot de
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-17 19:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110703
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
Last reconfirmed| |2023-07-17
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
It is basically the same as PR 68193 really.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/110703] Incorrect "-Wfloat-conversion" diagnostic with _Generic
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
3 siblings, 0 replies; 5+ messages in thread
From: muecker at gwdg dot de @ 2023-08-04 6:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110703
Martin Uecker <muecker at gwdg dot de> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |muecker at gwdg dot de
--- Comment #2 from Martin Uecker <muecker at gwdg dot de> ---
PATCH
https://gcc.gnu.org/pipermail/gcc-patches/2023-August/626319.html
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/110703] Incorrect "-Wfloat-conversion" diagnostic with _Generic
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
3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-08-05 8:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110703
--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Martin Uecker <uecker@gcc.gnu.org>:
https://gcc.gnu.org/g:54be338589ea93ad4ff53d22adde476a0582537b
commit r14-3004-g54be338589ea93ad4ff53d22adde476a0582537b
Author: Martin Uecker <uecker@tugraz.at>
Date: Fri Aug 4 07:48:21 2023 +0200
c: _Generic should not warn in non-active branches
[PR68193,PR97100,PR110703]
To avoid false diagnostics, use c_inhibit_evaluation_warnings when
a generic association is known to not match during parsing. We may
still generate false positives if the default branch comes earler than
a specific association that matches.
PR c/68193
PR c/97100
PR c/110703
gcc/c/:
* c-parser.cc (c_parser_generic_selection): Inhibit evaluation
warnings branches that are known not be taken during parsing.
gcc/testsuite/ChangeLog:
* gcc.dg/pr68193.c: New test.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/110703] Incorrect "-Wfloat-conversion" diagnostic with _Generic
2023-07-17 14:50 [Bug c/110703] New: Incorrect "-Wfloat-conversion" diagnostic with _Generic jepler at unpythonic dot net
` (2 preceding siblings ...)
2023-08-05 8:40 ` cvs-commit at gcc dot gnu.org
@ 2023-11-03 20:09 ` uecker at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: uecker at gcc dot gnu.org @ 2023-11-03 20:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110703
uecker at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
CC| |uecker at gcc dot gnu.org
Known to fail| |4.9.0
Target Milestone|--- |14.0
Resolution|--- |FIXED
--- Comment #4 from uecker at gcc dot gnu.org ---
fixed on trunk.
^ 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).