Skip several analyzer socket tests on hppa*-*-hpux*
[official-gcc.git] / gcc / testsuite / c-c++-common / analyzer / pr101962.c
blob32cef1617c1be0126fcca7a45de2c755633802ed
1 #include "../../gcc.dg/analyzer/analyzer-decls.h"
4 /* Verify that the analyzer makes the simplifying assumption that we don't
5 hit NULL when incrementing pointers to non-NULL memory regions. */
7 static int * __attribute__((noinline))
8 maybe_inc_int_ptr (int *ptr)
10 if (!ptr)
11 return NULL;
12 return ++ptr;
15 int
16 test_1 (void)
18 int stack;
19 int *a = &stack;
20 a = maybe_inc_int_ptr (a);
21 a = maybe_inc_int_ptr (a);
22 __analyzer_eval (a == NULL); /* { dg-warning "FALSE" } */
23 __analyzer_eval (a != NULL); /* { dg-warning "TRUE" } */
24 return *a; /* { dg-line test_1 } */
26 /* { dg-warning "stack-based buffer over-read" "warning" { target *-*-* } test_1 } */
29 static const char * __attribute__((noinline))
30 maybe_inc_char_ptr (const char *ptr)
32 if (!ptr)
33 return NULL;
34 return ++ptr;
37 void
38 test_s (void)
40 const char *msg = "hello world";
41 const char *a = msg;
42 __analyzer_eval (*a == 'h'); /* { dg-warning "TRUE" } */
43 a = maybe_inc_char_ptr (a);
44 __analyzer_eval (*a == 'e'); /* { dg-warning "TRUE" } */
45 a = maybe_inc_char_ptr (a);
46 __analyzer_eval (*a == 'l'); /* { dg-warning "TRUE" } */
47 a = maybe_inc_char_ptr (a);
48 __analyzer_eval (*a == 'l'); /* { dg-warning "TRUE" } */
49 a = maybe_inc_char_ptr (a);
50 __analyzer_eval (*a == 'o'); /* { dg-warning "TRUE" } */