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)
Tue, Nov 19, 12:37 AM
Unknown Object (File)
Tue, Nov 5, 6:02 AM
Unknown Object (File)
Oct 13 2024, 2:04 AM
Unknown Object (File)
Oct 5 2024, 1:41 AM
Unknown Object (File)
Oct 4 2024, 10:59 PM
Unknown Object (File)
Oct 4 2024, 10:57 PM
Unknown Object (File)
Oct 2 2024, 6:18 PM
Unknown Object (File)
Oct 2 2024, 8:24 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