2 /* A concatenation of varinfo1 .. varinfo4 in a shared object. This
3 is to check for correct functionality in a non-zero-biased ELF
6 /* Relevant compile flags are:
8 -Wall -g -I$prefix/include/valgrind
10 eg -Wall -g -I`pwd`/Inst/include/valgrind
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
21 __attribute__((noinline
))
22 void croak ( void* aV
)
25 volatile char* undefp
= malloc(1);
29 (void) VALGRIND_CHECK_MEM_IS_DEFINED(a
, 1);
36 /* ------------ varinfo1 ------------ */
44 char global_i2
[10] = { 1,2,3,4,5,6,7,8,9,10 };
46 __attribute__((noinline
))
47 static int varinfo1_main ( void )
50 char* onheap
= malloc(3);
57 croak( &global_u2
[3] );
58 croak( &global_i2
[7] );
63 /* ------------ varinfo2 ------------ */
64 __attribute__((noinline
))
65 static void foo2 ( void )
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 )
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
)
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 )
122 /* ------------ varinfo4 ------------ */
126 typedef struct { short c1
; char* c2
[3]; } XX
;
129 struct _str
{ int bing
; int bong
; XX xyzzy
[77]; }
132 __attribute__((noinline
))
133 static int blah4 ( int x
, int y
)
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) );
149 static void inlinetest(void);
150 /* ------------ varinfo5 ------------ */
152 void varinfo5_main ( void )
161 #define INLINE inline __attribute__((always_inline))
163 INLINE
void fun_c(int argc
) {
167 INLINE
void fun_b(int argb
) {
171 INLINE
void fun_a(int *arga
) {
175 void inlinetest(void)