Skip several analyzer socket tests on hppa*-*-hpux*
[official-gcc.git] / gcc / testsuite / c-c++-common / analyzer / abort.c
blob9497ae30b469a4ad0b8132ecb6671b7203551ede
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "analyzer-decls.h"
5 extern void foo ();
6 extern void bar ();
8 void test_1 (int i)
10 if (i == 42)
11 abort ();
13 __analyzer_eval (i != 42); /* { dg-warning "TRUE" } */
16 void test_2 (int i)
18 if (i)
19 foo ();
20 else
21 bar ();
23 foo ();
25 if (i)
26 foo ();
27 else
28 abort ();
30 __analyzer_eval (i != 0); /* { dg-warning "TRUE" } */
33 /**************************************************************************/
35 void calls_abort (const char *msg)
37 fprintf (stderr, "%s", msg);
38 abort ();
41 void test_3 (void *ptr)
43 if (!ptr)
44 calls_abort ("ptr was NULL");
46 __analyzer_eval (ptr != 0); /* { dg-warning "TRUE" } */
49 /**************************************************************************/
51 extern void marked_noreturn (const char *msg)
52 __attribute__ ((__noreturn__));
54 void test_4 (void *ptr)
56 if (!ptr)
57 marked_noreturn ("ptr was NULL");
59 __analyzer_eval (ptr != 0); /* { dg-warning "TRUE" } */
62 /**************************************************************************/
64 /* Verify that we discover conditions from assertions if the assert macro
65 isn't disabled, and that it has its failure-handler labelled with
66 __attribute__ ((__noreturn__)).
67 This attribute isn't present for all implementations of <assert.h>, so
68 we have to test the idea using our own assert macro. */
70 extern void my_assert_fail (const char *expr, const char *file, int line)
71 __attribute__ ((__noreturn__));
73 #define MY_ASSERT(EXPR) \
74 do { if (!(EXPR)) my_assert_fail (#EXPR, __FILE__, __LINE__); } while (0)
76 void test_5 (int i)
78 MY_ASSERT (i < 10);
79 __analyzer_eval (i < 10); /* { dg-warning "TRUE" } */