brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.1 KiB · c30498e Raw
70 lines · c
1// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wbool-operation %s2// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wall %s3// RUN: %clang_cc1 -x c -fsyntax-only -Wbitwise-instead-of-logical -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s4// RUN: %clang_cc1 -x c -fsyntax-only -Wbool-operation -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s5// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wbool-operation %s6// RUN: %clang_cc1 -x c++ -fsyntax-only -verify -Wall %s7// RUN: %clang_cc1 -x c++ -fsyntax-only -Wbitwise-instead-of-logical -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s8// RUN: %clang_cc1 -x c++ -fsyntax-only -Wbool-operation -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s9 10#ifdef __cplusplus11typedef bool boolean;12#else13typedef _Bool boolean;14#endif15 16boolean foo(void);17boolean bar(void);18boolean baz(void) __attribute__((const));19void sink(boolean);20 21#define FOO foo()22#define MY_AND &23#define My_BITAND bitand24 25void test(boolean a, boolean b, int *p, volatile int *q, int i) {26  b = a & b;27  b = foo() & a;28  b = (p != 0) & (*p == 42);   // FIXME: also warn for a non-volatile pointer dereference29  b = foo() & (*q == 42);      // expected-warning {{use of bitwise '&' with boolean operands}}30                               // expected-note@-1 {{cast one or both operands to int to silence this warning}}31  b = foo() & (int)(*q == 42); // OK, no warning expected32  b = a & foo();33  b = (int)a & foo();     // OK, no warning expected34  b = foo() & bar();      // expected-warning {{use of bitwise '&' with boolean operands}}35                          // expected-note@-1 {{cast one or both operands to int to silence this warning}}36                          // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:13-[[@LINE-2]]:14}:"&&"37  b = foo() & (int)bar(); // OK, no warning expected38  b = foo() & !bar();     // expected-warning {{use of bitwise '&' with boolean operands}}39                          // expected-note@-1 {{cast one or both operands to int to silence this warning}}40                          // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:13-[[@LINE-2]]:14}:"&&"41  b = a & baz();42  b = bar() & FOO;        // expected-warning {{use of bitwise '&' with boolean operands}}43                          // expected-note@-1 {{cast one or both operands to int to silence this warning}}44                          // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:13-[[@LINE-2]]:14}:"&&"45  b = foo() & (int)FOO;   // OK, no warning expected46  b = b & foo();47  b = bar() & (i > 4);48  b = (i == 7) & foo();49  b = b MY_AND foo();     // OK, no warning expected50 51#ifdef __cplusplus52  b = foo() bitand bar(); // Ok, no warning expected53  b = foo() My_BITAND bar(); // Ok, no warning expected54                          55#endif56 57  if (foo() & bar())      // expected-warning {{use of bitwise '&' with boolean operands}}58                          // expected-note@-1 {{cast one or both operands to int to silence this warning}}59    ;60 61  sink(a & b);62  sink(a & foo());63  sink(foo() & bar());    // expected-warning {{use of bitwise '&' with boolean operands}}64                          // expected-note@-1 {{cast one or both operands to int to silence this warning}}65 66  int n = i + 10;67  b = (n & (n - 1));68 69}70