view gcc/testsuite/c-c++-common/Wtautological-compare-5.c @ 19:2b5abeee2509 default tip

update gcc11
author anatofuz
date Mon, 25 May 2020 07:50:57 +0900
parents 04ced10e8804
children
line wrap: on
line source

/* PR c/81783 */
/* { dg-do compile } */
/* { dg-options "-Wtautological-compare" } */

enum E { FOO = 128 };

int
f (int a)
{
  if ((a & 16) == 10) /* { dg-warning "bitwise comparison always evaluates to false" } */
    return 1;
  if ((16 & a) == 10) /* { dg-warning "bitwise comparison always evaluates to false" } */
    return 1;
  if (10 == (a & 16)) /* { dg-warning "bitwise comparison always evaluates to false" } */
    return 1;
  if (10 == (16 & a)) /* { dg-warning "bitwise comparison always evaluates to false" } */
    return 1;

  if ((a & 16) != 10) /* { dg-warning "bitwise comparison always evaluates to true" } */
    return 1;
  if ((16 & a) != 10) /* { dg-warning "bitwise comparison always evaluates to true" } */
    return 1;
  if (10 != (a & 16)) /* { dg-warning "bitwise comparison always evaluates to true" } */
    return 1;
  if (10 != (16 & a)) /* { dg-warning "bitwise comparison always evaluates to true" } */
    return 1;

  if ((a & 9) == 8)
    return 1;
  if ((9 & a) == 8)
    return 1;
  if (8 == (a & 9))
    return 1;
  if (8 == (9 & a))
    return 1;

  if ((a & 9) != 8)
    return 1;
  if ((9 & a) != 8)
    return 1;
  if (8 != (a & 9))
    return 1;
  if (8 != (9 & a))
    return 1;

  if ((a | 16) == 10) /* { dg-warning "bitwise comparison always evaluates to false" } */
    return 1;
  if ((16 | a) == 10) /* { dg-warning "bitwise comparison always evaluates to false" } */
    return 1;
  if (10 == (a | 16)) /* { dg-warning "bitwise comparison always evaluates to false" } */
    return 1;
  if (10 == (16 | a)) /* { dg-warning "bitwise comparison always evaluates to false" } */
    return 1;

  if ((a | 16) != 10) /* { dg-warning "bitwise comparison always evaluates to true" } */
    return 1;
  if ((16 | a) != 10) /* { dg-warning "bitwise comparison always evaluates to true" } */
    return 1;
  if (10 != (a | 16)) /* { dg-warning "bitwise comparison always evaluates to true" } */
    return 1;
  if (10 != (16 | a)) /* { dg-warning "bitwise comparison always evaluates to true" } */
    return 1;

  if ((a | 9) == 8) /* { dg-warning "bitwise comparison always evaluates to false" } */
    return 1;
  if ((9 | a) == 8) /* { dg-warning "bitwise comparison always evaluates to false" } */
    return 1;
  if (8 == (a | 9)) /* { dg-warning "bitwise comparison always evaluates to false" } */
    return 1;
  if (8 == (9 | a)) /* { dg-warning "bitwise comparison always evaluates to false" } */
    return 1;

  if ((a | 9) != 8) /* { dg-warning "bitwise comparison always evaluates to true" } */
    return 1;
  if ((9 | a) != 8) /* { dg-warning "bitwise comparison always evaluates to true" } */
    return 1;
  if (8 != (a | 9)) /* { dg-warning "bitwise comparison always evaluates to true" } */
    return 1;
  if (8 != (9 | a)) /* { dg-warning "bitwise comparison always evaluates to true" } */
    return 1;

  if ((a & 128) != 1) /* { dg-warning "bitwise comparison always evaluates to true" } */
    return 1;
  if ((128 & a) != 1) /* { dg-warning "bitwise comparison always evaluates to true" } */
    return 1;
  if ((a & FOO) != 1) /* { dg-warning "bitwise comparison always evaluates to true" } */
    return 1;
  if ((FOO & a) != 1) /* { dg-warning "bitwise comparison always evaluates to true" } */
    return 1;
  if ((a & 128) == 1) /* { dg-warning "bitwise comparison always evaluates to false" } */
    return 1;
  if ((128 & a) == 1) /* { dg-warning "bitwise comparison always evaluates to false" } */
    return 1;
  if ((a & FOO) == 1) /* { dg-warning "bitwise comparison always evaluates to false" } */
    return 1;
  if ((FOO & a) == 1) /* { dg-warning "bitwise comparison always evaluates to false" } */
    return 1;

#define N 0x10
  if ((a & N) == 10) /* { dg-bogus "bitwise comparison always evaluates to false" "" { xfail *-*-* } } */
    return 1;
  if ((a | N) == 10) /* { dg-bogus "bitwise comparison always evaluates to false" "" { xfail *-*-* } } */
    return 1;

  return 0;
}