regtest: remove compiler warnings with clang
[valgrind.git] / memcheck / tests / err_disable1.c
blobe43dde1f004432744dbf2408de1ae4773475a2ca
2 /* Test simple use of the disable/enable macros. */
4 #include <stdlib.h>
5 #include <stdio.h>
7 #include "../include/valgrind.h"
9 char* block = NULL;
11 __attribute__((noinline)) void usechar ( char c )
13 // Spook gcc into believing mysterious bad things are
14 // happening behind its back, and that 'c' is definitely
15 // used in some (unknown) way.
16 __asm__ __volatile__("" : : "r"(c) : "memory","cc");
19 __attribute__((noinline)) void err ( void )
21 usechar( block[5] );
24 int main ( void )
26 block = malloc(10);
27 free(block);
29 fprintf(stderr, "\n--------- SIMPLE TEST ---------\n\n");
30 fprintf(stderr, "\n--------- enabled (expect 1) ---------\n\n");
32 err();
34 fprintf(stderr, "\n--------- disabled (expect 0) ---------\n\n");
35 VALGRIND_DISABLE_ERROR_REPORTING;
37 err();
39 fprintf(stderr, "\n--------- re-enabled (expect 1) ---------\n\n");
40 VALGRIND_ENABLE_ERROR_REPORTING;
42 err();
46 fprintf(stderr, "\n--------- MULTI-LEVEL TEST (expect 2) ---------\n\n");
48 // 4 times
49 VALGRIND_DISABLE_ERROR_REPORTING;
50 VALGRIND_DISABLE_ERROR_REPORTING;
51 VALGRIND_DISABLE_ERROR_REPORTING;
52 VALGRIND_DISABLE_ERROR_REPORTING; // lev = 4
54 // now gradually undo them until an error appears
55 err(); // hidden
57 VALGRIND_ENABLE_ERROR_REPORTING; // lev = 3
58 err(); // hidden
60 VALGRIND_ENABLE_ERROR_REPORTING; // lev = 2
61 err(); // hidden
63 VALGRIND_ENABLE_ERROR_REPORTING; // lev = 1
64 err(); // hidden
66 VALGRIND_ENABLE_ERROR_REPORTING; // lev = 0
67 err(); // visible
69 VALGRIND_ENABLE_ERROR_REPORTING; // lev = 0 (won't go down further)
70 err(); // visible
72 fprintf(stderr, "\n--------- MULTI-LEVEL TEST end ---------\n\n");
74 return 0;