Debian Codegraph @

gcc/testsuite/gcc.dg/analyzer/deref-before-check-macro.c

raw
1 #define NULL ((void*)0)
2
3 #define MY_ASSERT(COND) \
4 do { \
5 if (!(COND)) { __builtin_abort(); } \
6 } while (0)
7
8 int test_1 (int *p)
9 {
10 int result = *p;
11 MY_ASSERT (p); /* { dg-warning "check of 'p' for NULL after already dereferencing it" "" { xfail *-*-* } } */
12 /* Due to lack of locations for gimple arguments we can't get
13 at the location of the condition separately from the
14 gimple_cond stmt, and thus can't distinguish if it's in the
15 macro definition or in the supplied params; we defer to
16 rejecting the diagnostic. */
17 return result;
18 }
19
20 int test_2 (int *p)
21 {
22 int result = *p;
23 MY_ASSERT (p != NULL); /* { dg-warning "check of 'p' for NULL after already dereferencing it" "" { xfail *-*-* } } */
24 return result;
25 }