public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/105435] New: Wtautological-constant-compare warning in trunk build
@ 2022-04-29 18:19 dcb314 at hotmail dot com
  2022-04-29 18:20 ` [Bug target/105435] " dcb314 at hotmail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: dcb314 at hotmail dot com @ 2022-04-29 18:19 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 105435
           Summary: Wtautological-constant-compare warning in trunk build
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dcb314 at hotmail dot com
  Target Milestone: ---

I just had a go at a clang-based build of gcc trunk
on arm, specifically Raspberry PI 3.

clang said:

trunk/gcc/config/arm/arm-c.cc:299:7: warning: converting the result of '?:'
with integer constants to a boolean always evaluates to 'true'
[-Wtautological-constant-compare]

Source code is

  if (TARGET_ARM_FP)

and

/* Set as a bit mask indicating the available widths of hardware floating
   point types.  Where bit 1 indicates 16-bit support, bit 2 indicates
   32-bit support, bit 3 indicates 64-bit support.  */
#define TARGET_ARM_FP                   \
  (!TARGET_SOFT_FLOAT ? (TARGET_VFP_SINGLE ? 4          \
                        : (TARGET_VFP_DOUBLE ? (TARGET_FP16 ? 14 : 12) : 0)) \
                      : 0)

Four ternary operators in one expression is a complex expression
and it looks like clang can find fault with it.

I hope there is a simpler way to write the code that hopefully
removes the clang warning.

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

* [Bug target/105435] Wtautological-constant-compare warning in trunk build
  2022-04-29 18:19 [Bug target/105435] New: Wtautological-constant-compare warning in trunk build dcb314 at hotmail dot com
@ 2022-04-29 18:20 ` dcb314 at hotmail dot com
  2022-04-30 19:05 ` dcb314 at hotmail dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: dcb314 at hotmail dot com @ 2022-04-29 18:20 UTC (permalink / raw)
  To: gcc-bugs

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

David Binderman <dcb314 at hotmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tobias.burnus at physik dot fu-ber
                   |                            |lin.de

--- Comment #1 from David Binderman <dcb314 at hotmail dot com> ---
Adding author of original code.

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

* [Bug target/105435] Wtautological-constant-compare warning in trunk build
  2022-04-29 18:19 [Bug target/105435] New: Wtautological-constant-compare warning in trunk build dcb314 at hotmail dot com
  2022-04-29 18:20 ` [Bug target/105435] " dcb314 at hotmail dot com
@ 2022-04-30 19:05 ` dcb314 at hotmail dot com
  2022-05-02  5:47 ` [Bug target/105435] clang warning about Wtautological-constant-compare for a target macro pinskia at gcc dot gnu.org
  2022-05-02  6:01 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: dcb314 at hotmail dot com @ 2022-04-30 19:05 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from David Binderman <dcb314 at hotmail dot com> ---
A reduction of the original code produces this:

void arm_cpu_builtins() {
  if (0 ? 0 ? 4 : 2 : 0)
    ;
}

The best parse of this I can think of is:

void arm_cpu_builtins() {
  if (0 ? (0 ? 4 : 2) : 0)
    ;
}

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

* [Bug target/105435] clang warning about Wtautological-constant-compare for a target macro
  2022-04-29 18:19 [Bug target/105435] New: Wtautological-constant-compare warning in trunk build dcb314 at hotmail dot com
  2022-04-29 18:20 ` [Bug target/105435] " dcb314 at hotmail dot com
  2022-04-30 19:05 ` dcb314 at hotmail dot com
@ 2022-05-02  5:47 ` pinskia at gcc dot gnu.org
  2022-05-02  6:01 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-05-02  5:47 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|diagnostic                  |
            Summary|Wtautological-constant-comp |clang warning about
                   |are warning in trunk build  |Wtautological-constant-comp
                   |                            |are for a target macro

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The easiest fix is to change:
  if (TARGET_ARM_FP)

To:
   if (TARGET_ARM_FP != 0)

But then again clang maybe should not warn when this is coming from a macro.

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

* [Bug target/105435] clang warning about Wtautological-constant-compare for a target macro
  2022-04-29 18:19 [Bug target/105435] New: Wtautological-constant-compare warning in trunk build dcb314 at hotmail dot com
                   ` (2 preceding siblings ...)
  2022-05-02  5:47 ` [Bug target/105435] clang warning about Wtautological-constant-compare for a target macro pinskia at gcc dot gnu.org
@ 2022-05-02  6:01 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-05-02  6:01 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The problem is clang tries to be smart and then recusively warn but that is
broken.

Take:
TARGET_VFP_DOUBLE ? (TARGET_FP16 ? 14 : 12) : 0

clang will even warn about that case.

That is:
#define TARGET_ARM_FP                   \
  (TARGET_VFP_DOUBLE ? (TARGET_FP16 ? 14 : 12) : 0)

#define TARGET_VFP_DOUBLE (1)
#define TARGET_FP16 (1)

int f(int t, int tt)
{
    if (TARGET_ARM_FP) return 1;
    return 2;
}

And yes just changing it to:
if (TARGET_ARM_FP != 0)

fixes the "warning" but the warning should really be fixed instead.

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

end of thread, other threads:[~2022-05-02  6:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-29 18:19 [Bug target/105435] New: Wtautological-constant-compare warning in trunk build dcb314 at hotmail dot com
2022-04-29 18:20 ` [Bug target/105435] " dcb314 at hotmail dot com
2022-04-30 19:05 ` dcb314 at hotmail dot com
2022-05-02  5:47 ` [Bug target/105435] clang warning about Wtautological-constant-compare for a target macro pinskia at gcc dot gnu.org
2022-05-02  6:01 ` pinskia 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).