1// Simple program that uses C99 restrict qualifier. 2// Once GCC is fixed to output DW_TAG_restrict_type in the debuginfo 3// valgrind --read-var-info=yes would get a serious error reading the 4// debuginfo. This tests makes sure that a fixed GCC and a fixed valgrind 5// work well together. 6// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59051 7// https://bugs.kde.org/show_bug.cgi?id=336619 8 9#include <assert.h> 10#include <stdlib.h> 11#include <stdio.h> 12#include <string.h> 13 14#include "memcheck/memcheck.h" 15 16/* Cause memcheck to complain about the address "a" and so to print 17 its best guess as to what "a" actually is. a must be addressible. */ 18void croak (void *aV ) 19{ 20 char* a = (char*)aV; 21 char* undefp = malloc(1); 22 char saved = *a; 23 assert(undefp); 24 *a = *undefp; 25 (void) VALGRIND_CHECK_MEM_IS_DEFINED(a, 1); 26 *a = saved; 27 free(undefp); 28} 29 30void 31bad_restrict_ptr (void * restrict bad_ptr) 32{ 33 croak ((void *) &bad_ptr); 34} 35 36char * 37cpy (char * restrict s1, const char * restrict s2, size_t n) 38{ 39 char *t1 = s1; 40 const char *t2 = s2; 41 while(n-- > 0) 42 *t1++ = *t2++; 43 return s1; 44} 45 46int 47main (int argc, char **argv) 48{ 49 const char *hello = "World"; 50 size_t l = strlen (hello) + 1; 51 char *earth = malloc (l); 52 fprintf (stderr, "Hello %s\n", cpy (earth, hello, l)); 53 free (earth); 54 55 void *bad = malloc (16); 56 bad_restrict_ptr (bad); 57 free (bad); 58 return 0; 59} 60