+2020-01-27 David Malcolm <dmalcolm@redhat.com>
+
+ PR analyzer/93291
+ * gcc.dg/analyzer/pattern-test-2.c: Remove include of stdlib.h.
+ (test_2): Rewrite to explicitly perform a bitwise-or of two
+ boolean conditions.
+ (test_3): New function, to test bitwise-and.
+
2020-01-27 Richard Sandiford <richard.sandiford@arm.com>
PR testsuite/71727
/* { dg-additional-options "-fanalyzer-checker=pattern-test -O2" } */
// TODO: run this at every optimization level
-#include <stdlib.h>
-
extern void foo(void *);
extern void bar(void *);
void test_2 (void *p, void *q)
{
- if (p == NULL || q == NULL) /* { dg-line cond_2 } */
+ _Bool tmp1 = p == 0;
+ _Bool tmp2 = q == 0;
+ _Bool tmp = tmp1 | tmp2;
+
+ /* Verify that we can detect the implied conditions on p and q here. */
+ if (tmp) /* { dg-line cond_2 } */
return;
foo(p);
+ /* { dg-warning "pattern match on 'tmp1 == 0'" "tmp1 == 0" { target *-*-* } cond_2 } */
+ /* { dg-warning "pattern match on 'tmp2 == 0'" "tmp2 == 0" { target *-*-* } cond_2 } */
/* { dg-warning "pattern match on '<unknown> == 0'" "<unknown> == 0" { target *-*-* } cond_2 } */
/* { dg-warning "pattern match on '<unknown> != 0'" "<unknown> != 0" { target *-*-* } cond_2 } */
/* { dg-warning "pattern match on 'p != 0'" "p != 0" { target *-*-* } cond_2 } */
/* { dg-warning "pattern match on 'q != 0'" "q != 0" { target *-*-* } cond_2 } */
}
+
+void test_3 (void *p, void *q)
+{
+ _Bool tmp1 = p == 0;
+ _Bool tmp2 = q == 0;
+ _Bool tmp = tmp1 & tmp2;
+
+ /* Verify that we can detect the implied conditions on p and q here. */
+ if (tmp) /* { dg-line cond_3 } */
+ return;
+ foo(p);
+
+ /* { dg-warning "pattern match on 'tmp1 != 0'" "tmp1 != 0" { target *-*-* } cond_3 } */
+ /* { dg-warning "pattern match on 'tmp2 != 0'" "tmp2 != 0" { target *-*-* } cond_3 } */
+ /* { dg-warning "pattern match on '<unknown> == 0'" "<unknown> == 0" { target *-*-* } cond_3 } */
+ /* { dg-warning "pattern match on '<unknown> != 0'" "<unknown> != 0" { target *-*-* } cond_3 } */
+ /* { dg-warning "pattern match on 'p == 0'" "p == 0" { target *-*-* } cond_3 } */
+ /* { dg-warning "pattern match on 'q == 0'" "q == 0" { target *-*-* } cond_3 } */
+}