Page MenuHomeFreeBSD

Remove unnecessary const and volatile qualifiers from __fp_type_select()
ClosedPublic

Authored by dim on Jul 14 2022, 11:22 AM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Apr 22, 11:00 AM
Unknown Object (File)
Sun, Apr 21, 11:07 AM
Unknown Object (File)
Sun, Apr 21, 1:25 AM
Unknown Object (File)
Mon, Apr 8, 2:17 AM
Unknown Object (File)
Sun, Apr 7, 5:39 PM
Unknown Object (File)
Mar 11 2024, 5:04 AM
Unknown Object (File)
Feb 18 2024, 6:44 AM
Unknown Object (File)
Jan 14 2024, 10:17 AM
Subscribers

Details

Summary

Since https://github.com/llvm/llvm-project/commit/ca75ac5f04f2, clang 15
has a new warning about _Generic selection expressions, such as used in
math.h:

lib/libc/gdtoa/_ldtoa.c:82:10: error: due to lvalue conversion of the controlling expression, association of type 'volatile float' will never be selected because it is qualified [-Werror,-Wunreachable-code-generic-assoc]
        switch (fpclassify(u.e)) {
                ^
lib/msun/src/math.h:109:2: note: expanded from macro 'fpclassify'
        __fp_type_select(x, __fpclassifyf, __fpclassifyd, __fpclassifyl)
        ^
lib/msun/src/math.h:85:14: note: expanded from macro '__fp_type_select'
    volatile float: f(x),                                               \
             ^

This is because the controlling expression always undergoes lvalue
conversion first, dropping any cv-qualifiers. The 'const', 'volatile',
and 'volatile const' associations will therefore never be used.

MFC after: 1 week

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

dim requested review of this revision.Jul 14 2022, 11:22 AM

This is because the controlling expression always undergoes lvalue
conversion first, dropping any cv-qualifiers

As I recall, this wasn't the case when _Generic was introduced and clang used to warn about missing cases. If buildworld works with the new version then I'm happy - this is what my initial version looked like, before I had to work around compiler bugs.

As I recall, this wasn't the case when _Generic was introduced and clang used to warn about missing cases.

Yes, it was quite a while ago now.

If buildworld works with the new version then I'm happy - this is what my initial version looked like, before I had to work around compiler bugs.

I tried building gdtoa against this header (where the original warning originated) with a few relatively recent versions of clang, and with the oldest gcc that I have here, which is gcc 8. None complained.

This revision is now accepted and ready to land.Jul 15 2022, 8:01 AM