Don't call vg_assert inside sync_signalhandler_from_kernel
[valgrind.git] / memcheck / tests / varinfo5so.c
blob919bc7b3724207ff55bfbaa9db90af005b14d388
2 /* A concatenation of varinfo1 .. varinfo4 in a shared object. This
3 is to check for correct functionality in a non-zero-biased ELF
4 executable. */
6 /* Relevant compile flags are:
8 -Wall -g -I$prefix/include/valgrind
10 eg -Wall -g -I`pwd`/Inst/include/valgrind
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <assert.h>
16 #include "memcheck/memcheck.h"
18 /* Cause memcheck to complain about the address "a" and so to print
19 its best guess as to what "a" actually is. a must be
20 addressible. */
21 __attribute__((noinline))
22 void croak ( void* aV )
24 char* a = (char*)aV;
25 volatile char* undefp = malloc(1);
26 char saved = *a;
27 assert(undefp);
28 *a = *undefp;
29 (void) VALGRIND_CHECK_MEM_IS_DEFINED(a, 1);
30 *a = saved;
31 free((void*)undefp);
34 #include <stdio.h>
36 /* ------------ varinfo1 ------------ */
38 int global_u1;
40 int global_i1 = 17;
42 char global_u2[10];
44 char global_i2[10] = { 1,2,3,4,5,6,7,8,9,10 };
46 __attribute__((noinline))
47 static int varinfo1_main ( void )
49 int local;
50 char* onheap = malloc(3);
51 assert(onheap);
52 croak(onheap+1);
53 free(onheap);
55 croak( &global_u1 );
56 croak( &global_i1 );
57 croak( &global_u2[3] );
58 croak( &global_i2[7] );
59 croak( &local );
60 return 0;
63 /* ------------ varinfo2 ------------ */
64 __attribute__((noinline))
65 static void foo2 ( void )
67 int var;
68 var = 1;
69 { char var[10];
70 var[6] = 4;
71 croak( &var[7] );
72 { struct { double foo; float bar; } var;
73 croak ( 2 + (char*)&var.bar );
76 croak( 1 + (char*)&var );
78 __attribute__((noinline))
79 static int varinfo2_main ( void )
81 foo2();
82 return 0;
85 /* ------------ varinfo3 ------------ */
87 static char static_global_def[10] = {0,0,0,0,0, 0,0,0,0,0};
88 char nonstatic_global_def[10] = {0,0,0,0,0, 0,0,0,0,0};
89 static char static_global_undef[10];
90 char nonstatic_global_undef[10];
91 __attribute__((noinline))
92 static void bar3 ( char* p1, char* p2, char* p3, char* p4 )
94 croak(p1);
95 croak(p2);
96 croak(p3);
97 croak(p4);
99 __attribute__((noinline))
100 static void foo3 ( void )
102 static char static_local_def[10] = {0,0,0,0,0, 0,0,0,0,0};
103 char nonstatic_local_def[10] = {0,0,0,0,0, 0,0,0,0,0};
104 static char static_local_undef[10];
105 char nonstatic_local_undef[10];
106 croak ( 1 + (char*)&static_global_def );
107 croak ( 2 + (char*)&nonstatic_global_def );
108 croak ( 3 + (char*)&static_global_undef );
109 croak ( 4 + (char*)&nonstatic_global_undef );
110 bar3( 5 + (char*)&static_local_def,
111 6 + (char*)&nonstatic_local_def,
112 7 + (char*)&static_local_undef,
113 8 + (char*)&nonstatic_local_undef );
115 __attribute__((noinline))
116 static int varinfo3_main ( void )
118 foo3();
119 return 0;
122 /* ------------ varinfo4 ------------ */
124 #include <string.h>
126 typedef struct { short c1; char* c2[3]; } XX;
128 typedef
129 struct _str { int bing; int bong; XX xyzzy[77]; }
130 Str;
132 __attribute__((noinline))
133 static int blah4 ( int x, int y )
135 Str a[10];
136 memset(a, 0, sizeof(a));
137 croak(1 + (char*)(&a[3].xyzzy[x*y].c1));
138 croak( (char*)(&a[5].bong) );
139 croak( 1 + (char*)(&a[3].xyzzy[x*y].c2[2]) );
140 memset(a, 0, sizeof(a));
141 return a[3].xyzzy[x*y].c1;
143 __attribute__((noinline))
144 static int varinfo4_main ( void )
146 fprintf(stderr, "answer is %d\n", blah4(3,7) );
147 return 0;
149 static void inlinetest(void);
150 /* ------------ varinfo5 ------------ */
152 void varinfo5_main ( void )
154 varinfo1_main();
155 varinfo2_main();
156 varinfo3_main();
157 varinfo4_main();
158 inlinetest();
161 #define INLINE inline __attribute__((always_inline))
163 INLINE void fun_c(int argc) {
164 croak(&argc);
167 INLINE void fun_b(int argb) {
168 fun_c(argb);
171 INLINE void fun_a(int *arga) {
172 fun_b(*arga);
175 void inlinetest(void)
177 int i = 1;
178 fun_a(&i);