OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /openrisc/trunk/gnu-src/gcc-4.2.2/libmudflap/testsuite/libmudflap.c
    from Rev 38 to Rev 154
    Reverse comparison

Rev 38 → Rev 154

/pass47-frag.c
0,0 → 1,10
#include <stdlib.h>
#include <ctype.h>
 
int main ()
{
char* buf = "hello";
return ! ((toupper (buf[0]) == 'H' && toupper ('z') == 'Z' &&
tolower (buf[4]) == 'o' && tolower ('X') == 'x' &&
isdigit (buf[3])) == 0 && isalnum ('4'));
}
/fail33-frag.c
0,0 → 1,25
#include <stdlib.h>
 
#define SIZE 16
 
char b[SIZE];
char a[SIZE];
 
int main ()
{
int i, j=0, k;
int a_before_b = (& a[0] < & b[0]);
/* Rather than iterating linearly, which would allow loop unrolling
and mapping to pointer manipulation, we traverse the "joined"
arrays in some random order. */
for (i=0; i<SIZE*2; i++)
{
k = rand() % (SIZE*2);
j += (a_before_b ? a[k] : b[k]);
}
return j;
}
/* { dg-output "mudflap violation 1.*" } */
/* { dg-output "Nearby object.*" } */
/* { dg-output "mudflap object.*\[ab\]" } */
/* { dg-do run { xfail *-*-* } } */
/fail17-frag.c
0,0 → 1,18
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
 
char * x;
int foo;
x = (char *) malloc (10);
strcpy (x, "123456789");
foo = strlen (x+10);
x [foo] = 1; /* we just just use foo to force execution of strlen */
return 0;
}
/* { dg-output "mudflap violation 1.*" } */
/* { dg-output "Nearby object 1.*" } */
/* { dg-output "mudflap object.*.malloc region.*" } */
/* { dg-do run { xfail *-*-* } } */
/fail27-frag.c
0,0 → 1,24
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
char volatile *
__attribute__((noinline))
foo (unsigned i)
{
char volatile buffer[10];
char volatile *k = i ? & buffer[i] : NULL; /* defeat addr-of-local-returned warning */
return k;
}
 
int main ()
{
char volatile *f = foo (5);
f[0] = 'b';
 
return 0;
}
/* { dg-output "mudflap violation 1.*" } */
/* { dg-output "Nearby object.*" } */
/* { dg-output "mudflap object.*buffer.*alloc.*dealloc" } */
/* { dg-do run { xfail *-*-* } } */
/fail37-frag.c
0,0 → 1,22
typedef struct
{
short f : 3;
} small;
 
struct
{
int i;
small s[4];
} x;
 
main ()
{
int i;
for (i = 0; i < 5; i++)
x.s[i].f = 0;
exit (0);
}
/* { dg-output "mudflap violation 1.*" } */
/* { dg-output "Nearby object.*" } */
/* { dg-output "mudflap object.* x.*" } */
/* { dg-do run { xfail *-*-* } } */
/pass2-frag.c
0,0 → 1,9
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
int foo [10][10];
foo[9][0] = 0;
return 0;
}
/pass6-frag.c
0,0 → 1,14
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
char *foo;
char *bar;
 
foo = (char *)malloc (10);
bar = (char *)malloc (10);
bar[2] = 'z'; /* touch memcpy source */
memcpy(foo, bar, 10);
return 0;
}
/fail1-frag.c
0,0 → 1,13
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
volatile int foo [10];
foo[10] = 0;
return 0;
}
/* { dg-output "mudflap violation 1.*" } */
/* { dg-output "Nearby object 1.*" } */
/* { dg-output "mudflap object.*.main. foo.*" } */
/* { dg-do run { xfail *-*-* } } */
/fail5-frag.c
0,0 → 1,14
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
char foo [15];
char bar [10];
memcpy(foo, bar, 11);
return 0;
}
/* { dg-output "mudflap violation 1.*" } */
/* { dg-output "Nearby object 1.*" } */
/* { dg-output "mudflap object.*.main. bar.*" } */
/* { dg-do run { xfail *-*-* } } */
/fail9-frag.c
0,0 → 1,21
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
char *foo;
char *bar;
foo = (char *)malloc (10);
bar = (char *)malloc (10);
 
free(foo);
 
bar[4] = 'a'; /* touch source buffer */
memcpy(foo, bar, 10);
return 0;
}
 
/* { dg-output "mudflap violation 1.*memcpy dest.*" } */
/* { dg-output "Nearby object.*" } */
/* { dg-output "mudflap object.*malloc region.*alloc time.*dealloc time.*" } */
/* { dg-do run { xfail *-*-* } } */
/pass12-frag.c
0,0 → 1,15
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
int i = 10;
int *x = (int *) malloc (i * sizeof (int));
 
while (--i)
{
++x;
*x = 0;
}
return 0;
}
/pass22-frag.c
0,0 → 1,23
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
struct foo {
unsigned base:8;
unsigned flag1:1;
unsigned flag2:3;
unsigned flag3:4;
char nothing[0];
};
 
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *) 0)->MEMBER)
 
struct foo* f = (struct foo *) malloc (offsetof (struct foo, nothing));
f->base = 1;
f->flag1 = 1;
free (f);
 
 
return 0;
}
/pass32-frag.c
0,0 → 1,18
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
struct foo { char z[10]; };
 
char * get_z (struct foo *this)
{
return & this->z[0] /* the `this' pointer is not dereferenced! */;
}
 
int main ()
{
struct foo k;
char *n = get_z (& k);
srand ((int)(__mf_uintptr_t) n); /* use the pointer value */
return 0;
}
/pass42-frag.c
0,0 → 1,17
#include <stdio.h>
 
void
foo ()
{
putc ('h', stdout);
putc ('i', stdout);
putc ('\n', stdout);
}
 
int
main (int argc, char *argv[])
{
foo ();
return 0;
}
/* { dg-output "hi" } */
/pass52-frag.c
0,0 → 1,36
#include <stdio.h>
 
 
void writestuff (FILE *f)
{
fprintf (f, "hello world\n");
fputc ('y', f);
putc ('e', f);
}
 
void readstuff (FILE *f)
{
int c, d;
char stuff[100], *s;
c = fgetc (f);
ungetc (c, f);
d = fgetc (f);
s = fgets (stuff, sizeof(stuff), f);
}
 
int main ()
{
FILE *f;
writestuff (stdout);
writestuff (stderr);
f = fopen ("/dev/null", "w");
writestuff (f);
fclose (f);
f = fopen ("/dev/zero", "r");
readstuff (f);
f = freopen ("/dev/null", "w", f);
writestuff (f);
fclose (f);
 
return 0;
}
/pass16-frag.c
0,0 → 1,22
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
struct base {
int basic;
};
 
struct derived {
struct base common;
char extra;
};
 
struct base *bp;
 
bp = (struct base *) malloc (sizeof (struct derived));
 
bp->basic = 10;
((struct derived *)bp)->extra = 'x';
return 0;
}
/fail12-frag.c
0,0 → 1,19
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
int i = 10;
int *x = (int *) malloc (i * sizeof (int));
 
while (i--)
{
++x;
*x = 0;
}
return 0;
}
/* { dg-output "mudflap violation 1.*" } */
/* { dg-output "Nearby object 1.*" } */
/* { dg-output "mudflap object.*malloc region.*" } */
/* { dg-do run { xfail *-*-* } } */
/pass26-frag.c
0,0 → 1,52
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
volatile int *p;
 
__mf_set_options ("-wipe-stack -no-check-initialization");
 
{
volatile int array [10];
p = & array[0];
 
array[0] = 2;
array[9] = 5;
 
/* Array[] should be wiped clean at this point. */
}
 
__mf_set_options ("-no-wipe-stack");
 
{
volatile int array2[10];
 
/* hope that this is allocated on top of old array[] */
if (p != & array2[0])
exit (0); /* Test is not applicable. */
 
array2[5] = 6;
 
/* Old values shouldn't still be around; the new one should. */
if (p[0] == 2 || p[9] == 5 || p[5] != 6)
abort() ;
 
/* array2[] should not be wiped at this point! */
}
 
{
volatile int array3[10];
 
/* hope that this is allocated on top of old array[] and array2[]*/
if (p != & array3[0])
exit (0); /* Test is not applicable. */
 
array3[1] = 2;
 
/* Check that old assignment is still around. */
if (p[5] != 6 || p[1] != 2)
abort() ;
}
return 0;
}
/pass36-frag.c
0,0 → 1,15
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
 
int main ()
{
char *k;
__mf_set_options ("-sigusr1-report -print-leaks");
k = (char *) malloc (100);
raise (SIGUSR1);
free (k);
return 0;
}
/* { dg-output "Leaked object.*name=.malloc region.*objects: 1" } */
/fail22-frag.c
0,0 → 1,17
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
struct boo { int a; };
int c;
struct boo *b = malloc (sizeof (struct boo));
__mf_set_options ("-check-initialization");
c = b->a;
(void) malloc (c); /* some dummy use of c */
return 0;
}
/* { dg-output "mudflap violation 1.*" } */
/* { dg-output "Nearby object 1.*" } */
/* { dg-output "mudflap object.*.malloc region.*1r/0w.*" } */
/* { dg-do run { xfail *-*-* } } */
/pass46-frag.c
0,0 → 1,18
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
int foo (int *u, int i)
{
return u[i]; /* this dereference should not be instrumented */
}
 
int main ()
{
int *k = malloc (6);
int l = foo (k, 8);
int boo [8];
int m = boo [l % 2 + 12]; /* should not be instrumented */
return m & strlen (""); /* a fancy way of saying "0" */
}
/* { dg-options "-fmudflap -fmudflapir -lmudflap -Wall" } */
/fail32-frag.c
0,0 → 1,16
void foo (int k)
{
volatile int *b = & k;
b++;
*b = 5;
}
 
int main ()
{
foo (5);
return 0;
}
/* { dg-output "mudflap violation 1.*" } */
/* { dg-output "Nearby object.*" } */
/* { dg-output "mudflap object.*k" } */
/* { dg-do run { xfail *-*-* } } */
/pass56-frag.c
0,0 → 1,14
#include <stdio.h>
#include <stdlib.h>
 
int main ()
{
volatile int *k = (int *) malloc (sizeof (int));
volatile int l;
if (k == NULL) abort ();
*k = 5;
free ((void *) k);
__mf_set_options ("-ignore-reads");
l = *k; /* Should not trip, even though memory region just freed. */
return 0;
}
/fail16-frag.c
0,0 → 1,26
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
struct base {
int basic;
};
 
struct derived {
struct base common;
char extra;
};
 
struct base *bp;
 
bp = (struct base *) malloc (sizeof (struct base));;
 
bp->basic = 10;
((struct derived *)bp)->extra = 'x';
return 0;
}
/* { dg-output "mudflap violation 1.*" } */
/* { dg-output "Nearby object 1.*" } */
/* { dg-output "mudflap object.*.malloc region.*" } */
/* { dg-do run { xfail *-*-* } } */
/hook-allocstuff.c
0,0 → 1,16
#include <stdio.h>
#include <stdlib.h>
 
int main ()
{
char *foo = (char *) malloc (10);
strcpy (foo, "hello");
foo = (char *) realloc (foo, 20);
printf ("%s", foo);
if (strcmp (foo, "hello"))
abort ();
free (foo);
printf (" world\n");
return 0;
}
/* { dg-output "hello world" } */
/fail26-frag.c
0,0 → 1,24
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
char *foo;
 
__mf_set_options ("-check-initialization");
foo = (char *)malloc (1);
 
/* These two operations each expand to a read-modify-write.
* Even though the end result is that every bit of foo[0] is
* eventually written to deterministically, the first read
* triggers an uninit error. Ideally, it shouldn't, so this
* should be treated more like a regular XFAIL. */
foo[0] &= 0xfe;
foo[0] |= 0x01;
 
return foo[0];
}
/* { dg-output "mudflap violation 1.*" } */
/* { dg-output "Nearby object.*" } */
/* { dg-output "mudflap object.*malloc region.*1r/0w.*" } */
/* { dg-do run { xfail *-*-* } } */
/fail36-frag.c
0,0 → 1,23
#include <stdlib.h>
 
struct k
{
int p;
struct {
int m : 31;
} q;
};
 
int
main ()
{
volatile struct k *l = malloc (sizeof (int)); /* make it only big enough for k.p */
/* Confirm that we instrument this nested construct
BIT_FIELD_REF(COMPONENT_REF(INDIRECT_REF)). */
l->q.m = 5;
return 0;
}
/* { dg-output "mudflap violation 1.*" } */
/* { dg-output "Nearby object.*" } */
/* { dg-output "mudflap object.*" } */
/* { dg-do run { xfail *-*-* } } */
/pass1-frag.c
0,0 → 1,9
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
int foo [10];
foo[9] = 0;
return 0;
}
/pass5-frag.c
0,0 → 1,11
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
char foo [10];
char bar [10];
bar[4] = 'k'; /* touch memcpy source */
memcpy(foo, bar, 10);
return 0;
}
/fail4-frag.c
0,0 → 1,13
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
char foo [10];
strcpy(foo, "1234567890");
return 0;
}
/* { dg-output "mudflap violation 1.*" } */
/* { dg-output "Nearby object 1.*" } */
/* { dg-output "mudflap object.*.main. foo.*" } */
/* { dg-do run { xfail *-*-* } } */
/pass9-frag.c
0,0 → 1,16
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
char *foo;
char *bar;
foo = (char *)malloc (10);
bar = (char *)malloc (10);
 
free(foo);
foo = (char *)malloc (10);
bar[3] = 'w'; /* touch memcpy source */
memcpy(foo, bar, 10);
return 0;
}
/cfrags.exp
0,0 → 1,21
global MUDFLAP_FLAGS
set MUDFLAP_FLAGS [list {} {-static} {-O2} {-O3}]
 
libmudflap-init c
 
dg-init
 
global srcdir
foreach flags $MUDFLAP_FLAGS {
foreach srcfile [lsort [glob -nocomplain \
${srcdir}/libmudflap.c/*frag.c \
${srcdir}/libmudflap.c/heap*.c \
${srcdir}/libmudflap.c/hook*.c \
${srcdir}/libmudflap.c/pass*.c]] {
set bsrc [file tail $srcfile]
setenv MUDFLAP_OPTIONS "-viol-segv"
dg-runtest $srcfile $flags "-fmudflap -lmudflap"
}
}
 
dg-finish
/fail8-frag.c
0,0 → 1,19
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
char *foo;
char *bar;
foo = (char *)malloc (10);
bar = (char *)malloc (10);
 
free(bar);
 
memcpy(foo, bar, 10);
return 0;
}
/* { dg-output "mudflap violation 1.*memcpy source.*" } */
/* { dg-output "Nearby object.*" } */
/* { dg-output "mudflap object.*malloc region.*alloc time.*dealloc time.*" } */
/* { dg-do run { xfail *-*-* } } */
/hook2-allocstuff.c
0,0 → 1,9
/* Generates recursive malloc call on i386-freebsd4.10 with -fmudflap. */
#include <stdlib.h>
 
int
main (void)
{
char *p = malloc (1<<24);
return 0;
}
/pass11-frag.c
0,0 → 1,15
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
int i = 10;
char *x = (char *) malloc (i * sizeof (char));
 
while (--i)
{
++x;
*x = 0;
}
return 0;
}
/externs-1.c
0,0 → 1,16
typedef struct { char *name; } dummy;
extern dummy d[];
 
int
main (void)
{
dummy *pd = d;
 
while (pd->name)
{
printf ("%s\n", pd->name);
pd++;
}
 
return 0;
}
/pass21-frag.c
0,0 → 1,15
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef __FreeBSD__
#include <alloca.h>
#endif
int main ()
{
char *boo, *foo;
boo = (char *) alloca (100);
boo[99] = 'a';
foo = (char *) __builtin_alloca (200);
foo[44] = 'b';
return 0;
}
/pass15-frag.c
0,0 → 1,23
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
struct base {
int basic;
};
 
struct derived {
struct base common;
char extra;
};
 
struct derived d;
struct base *bp;
 
bp = (struct base *)&d;
 
bp->basic = 10;
((struct derived *)bp)->extra = 'x';
return 0;
}
/pass51-frag.c
0,0 → 1,41
/* Test object-spanning accesses. This is most conveniently done with
mmap, thus the config.h specificity here. */
#include "../config.h"
 
#include <unistd.h>
#include <string.h>
#ifdef HAVE_SYS_MMAN_H
#include <sys/mman.h>
#endif
 
int main ()
{
#ifndef MAP_ANONYMOUS
#define MAP_ANONYMOUS MAP_ANON
#endif
#ifdef HAVE_MMAP
void *p;
unsigned pg = getpagesize ();
int rc;
 
p = mmap (NULL, 4 * pg, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
if (p == NULL)
return 1;
 
memset (p, 0, 4*pg);
rc = munmap (p, pg);
if (rc < 0) return 1;
memset (p+pg, 0, 3*pg);
rc = munmap (p+pg, pg);
if (rc < 0) return 1;
memset (p+2*pg, 0, 2*pg);
rc = munmap (p+2*pg, pg);
if (rc < 0) return 1;
memset (p+3*pg, 0, pg);
rc = munmap (p+3*pg, pg);
if (rc < 0) return 1;
#endif
 
return 0;
}
/fail11-frag.c
0,0 → 1,19
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
int i = 10;
char *x = (char *) malloc (i * sizeof (char));
 
while (i--)
{
++x;
*x = 0;
}
return 0;
}
/* { dg-output "mudflap violation 1.*" } */
/* { dg-output "Nearby object 1.*" } */
/* { dg-output "mudflap object.*malloc region.*" } */
/* { dg-do run { xfail *-*-* } } */
/pass25-frag.c
0,0 → 1,15
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
int *foo = malloc (10 * sizeof(int));
int *bar = & foo[3];
/* Watching occurs at the object granularity, which is in this case
the entire array. */
__mf_watch (& foo[1], sizeof(foo[1]));
__mf_unwatch (& foo[6], sizeof(foo[6]));
*bar = 10;
free (foo);
return 0;
}
/pass35-frag.c
0,0 → 1,14
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
extern char end []; /* Any old symbol we're sure will be defined. */
/* { dg-warning "cannot track unknown size extern" "cannot track unknown size extern" { target *-*-* } 0 } */
 
int main ()
{
/* dummy register */
__mf_register ((void *) end, 1, __MF_TYPE_GUESS, "end");
char z = end[0];
return z & 0;
}
/fail21-frag.c
0,0 → 1,18
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
int *bar = (int *) malloc (sizeof (int));
/* Make an access here to get &foo into the lookup cache. */
*bar = 5;
__mf_watch (bar, sizeof(int));
/* This access should trigger the watch violation. */
*bar = 10;
/* NOTREACHED */
return 0;
}
/* { dg-output "mudflap violation 1.*watch.*" } */
/* { dg-output "Nearby object 1.*" } */
/* { dg-output "mudflap object.*malloc region.*" } */
/* { dg-do run { xfail *-*-* } } */
/pass45-frag.c
0,0 → 1,31
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
extern void h (const char *p, const char *f);
int
main (void)
{
h (0, "foo");
return 0;
}
 
void
h (const char *p, const char *f)
{
size_t pl = p == NULL ? 0 : strlen (p);
size_t fl = strlen (f) + 1;
char a[pl + 1 + fl];
char *cp = a;
char b[pl + 5 + fl * 2];
char *cccp = b;
if (p != NULL)
{
cp = memcpy (cp, p, pl);
*cp++ = ':';
}
memcpy (cp, f, fl);
strcpy (b, a);
puts (a);
}
/* { dg-output "foo" } */
/fail31-frag.c
0,0 → 1,22
#include <stdio.h>
#include <stdlib.h>
 
extern int h (int i, int j);
 
int main ()
{
int z = h (4, 10);
return 0;
}
 
int h (int i, int j)
{
int k[i];
k[j] = i;
return j;
}
 
/* { dg-output "mudflap violation 1.*" } */
/* { dg-output "Nearby object.*" } */
/* { dg-output "mudflap object.*\(h\).*k" } */
/* { dg-do run { xfail *-*-* } } */
/pass19-frag.c
0,0 → 1,11
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
struct foo {int base; char variable[1]; }; /* a common idiom for variable-size structs */
 
struct foo * b = (struct foo *) malloc (sizeof (int)); /* enough for base */
b->base = 4;
return 0;
}
/pass29-frag.c
0,0 → 1,15
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
struct boo { int a; };
int c;
struct boo *b = malloc (sizeof (struct boo));
__mf_set_options ("-check-initialization");
b->a = 0;
/* That __mf_set_options call could be here instead. */
c = b->a;
(void) malloc (c); /* some dummy use of c */
return 0;
}
/fail15-frag.c
0,0 → 1,27
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
struct base {
int basic;
};
 
struct derived {
struct base common;
char extra;
};
 
volatile struct base b;
volatile struct base *bp;
 
bp = (struct base *)&b;
 
bp->basic = 10;
((struct derived volatile *)bp)->extra = 'x';
return 0;
}
/* { dg-output "mudflap violation 1.*" } */
/* { dg-output "Nearby object 1.*" } */
/* { dg-output "mudflap object.*.main. b.*" } */
/* { dg-do run { xfail *-*-* } } */
/fail25-frag.c
0,0 → 1,18
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
char *foo;
char *bar;
__mf_set_options ("-check-initialization");
foo = (char *)malloc (10);
bar = (char *)malloc (10);
/* bar[2] = 'z'; */ /* don't touch memcpy source */
memcpy(foo+1, bar+1, 9);
return 0;
}
/* { dg-output "mudflap violation 1.*check.read.*memcpy source.*" } */
/* { dg-output "Nearby object.*" } */
/* { dg-output "mudflap object.*malloc region.*alloc time.*" } */
/* { dg-do run { xfail *-*-* } } */
/fail35-frag.c
0,0 → 1,23
#include <stdlib.h>
 
struct k
{
int p;
struct {
int m;
} q;
};
 
int
main ()
{
volatile struct k *l = malloc (sizeof (int)); /* make it only big enough for k.p */
/* Confirm that we instrument this nested construct
COMPONENT_REF(COMPONENT_REF(INDIRECT_REF)). */
l->q.m = 5;
return 0;
}
/* { dg-output "mudflap violation 1.*" } */
/* { dg-output "Nearby object.*" } */
/* { dg-output "mudflap object.*" } */
/* { dg-do run { xfail *-*-* } } */
/pass49-frag.c
0,0 → 1,35
#include <stdlib.h>
#include <ctype.h>
#include <stdarg.h>
 
int foo (int a, ...)
{
va_list args;
char *a1;
int a2;
int k;
 
va_start (args, a);
for (k = 0; k < a; k++)
{
if ((k % 2) == 0)
{
char *b = va_arg (args, char *);
printf ("%s", b);
}
else
{
int b = va_arg (args, int);
printf ("%d", b);
}
}
va_end (args);
return a;
}
 
int main ()
{
foo (7, "hello ", 5, " ", 3, " world ", 9, "\n");
return 0;
}
/* { dg-output "hello 5 3 world 9" } */
/fail19-frag.c
0,0 → 1,18
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
struct foo {
int bar [10];
};
 
struct foo *k = (struct foo *) malloc (2 * sizeof(int));
k->bar[5] = 9;
free (k);
return 0;
}
/* { dg-output "mudflap violation 1.*" } */
/* { dg-output "Nearby object 1.*" } */
/* { dg-output "mudflap object.*.malloc region.*" } */
/* { dg-do run { xfail *-*-* } } */
/fail29-frag.c
0,0 → 1,17
#include <stdio.h>
#include <stdlib.h>
 
int foo (int u[10])
{
return u[8]; /* this dereference should be instrumented */
}
 
int main ()
{
int *k = malloc (6);
return foo (k);
}
/* { dg-output "mudflap violation 1.*" } */
/* { dg-output "Nearby object.*" } */
/* { dg-output "mudflap object.*malloc region.*alloc" } */
/* { dg-do run { xfail *-*-* } } */
/fail39-frag.c
0,0 → 1,20
#include <stdio.h>
#include <stdlib.h>
 
int main ()
{
volatile int *k = (int *) malloc (sizeof (int));
volatile int l;
if (k == NULL) abort ();
*k = 5;
free ((void *) k);
__mf_set_options ("-ignore-reads");
l = *k; /* Should not trip, even though memory region just freed. */
__mf_set_options ("-no-ignore-reads");
l = *k; /* Should trip now. */
return 0;
}
/* { dg-output "mudflap violation 1.*check/read.*" } */
/* { dg-output "Nearby object 1.*" } */
/* { dg-output "mudflap dead object.*malloc region.*" } */
/* { dg-do run { xfail *-*-* } } */
/pass-stratcliff.c
0,0 → 1,319
/* Test for string function add boundaries of usable memory.
Copyright (C) 1996,1997,1999,2000,2001,2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
 
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
 
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
 
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA. */
 
#define _GNU_SOURCE 1
#define __USE_GNU
 
/* Make sure we don't test the optimized inline functions if we want to
test the real implementation. */
#undef __USE_STRING_INLINES
 
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/param.h>
 
#ifndef MAX
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#endif
 
int
main (int argc, char *argv[])
{
int size = sysconf (_SC_PAGESIZE);
char *adr, *dest;
int result = 0;
 
adr = (char *) mmap (NULL, 3 * size, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANON, -1, 0);
dest = (char *) mmap (NULL, 3 * size, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANON, -1, 0);
if (adr == MAP_FAILED || dest == MAP_FAILED)
{
if (errno == ENOSYS)
puts ("No test, mmap not available.");
else
{
printf ("mmap failed: %m");
result = 1;
}
}
else
{
int inner, middle, outer;
 
mprotect(adr, size, PROT_NONE);
mprotect(adr + 2 * size, size, PROT_NONE);
adr += size;
 
mprotect(dest, size, PROT_NONE);
mprotect(dest + 2 * size, size, PROT_NONE);
dest += size;
 
memset (adr, 'T', size);
 
/* strlen test */
for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
{
for (inner = MAX (outer, size - 64); inner < size; ++inner)
{
adr[inner] = '\0';
 
if (strlen (&adr[outer]) != (size_t) (inner - outer))
{
printf ("strlen flunked for outer = %d, inner = %d\n",
outer, inner);
result = 1;
}
 
adr[inner] = 'T';
}
}
 
/* strchr test */
for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
{
for (middle = MAX (outer, size - 64); middle < size; ++middle)
{
for (inner = middle; inner < size; ++inner)
{
char *cp;
adr[middle] = 'V';
adr[inner] = '\0';
 
cp = strchr (&adr[outer], 'V');
 
if ((inner == middle && cp != NULL)
|| (inner != middle
&& (cp - &adr[outer]) != middle - outer))
{
printf ("strchr flunked for outer = %d, middle = %d, "
"inner = %d\n", outer, middle, inner);
result = 1;
}
 
adr[inner] = 'T';
adr[middle] = 'T';
}
}
}
 
/* Special test. */
adr[size - 1] = '\0';
if (strchr (&adr[size - 1], '\n') != NULL)
{
puts ("strchr flunked for test of empty string at end of page");
result = 1;
}
 
/* strrchr test */
for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
{
for (middle = MAX (outer, size - 64); middle < size; ++middle)
{
for (inner = middle; inner < size; ++inner)
{
char *cp;
adr[middle] = 'V';
adr[inner] = '\0';
 
cp = strrchr (&adr[outer], 'V');
 
if ((inner == middle && cp != NULL)
|| (inner != middle
&& (cp - &adr[outer]) != middle - outer))
{
printf ("strrchr flunked for outer = %d, middle = %d, "
"inner = %d\n", outer, middle, inner);
result = 1;
}
 
adr[inner] = 'T';
adr[middle] = 'T';
}
}
}
 
#ifndef __FreeBSD__
/* rawmemchr test */
for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
{
for (middle = MAX (outer, size - 64); middle < size; ++middle)
{
char *cp;
adr[middle] = 'V';
 
cp = (char *) rawmemchr (&adr[outer], 'V');
 
if (cp - &adr[outer] != middle - outer)
{
printf ("rawmemchr flunked for outer = %d, middle = %d\n",
outer, middle);
result = 1;
}
 
adr[middle] = 'T';
}
}
#endif
 
/* strcpy test */
for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
{
for (inner = MAX (outer, size - 64); inner < size; ++inner)
{
adr[inner] = '\0';
 
if (strcpy (dest, &adr[outer]) != dest
|| strlen (dest) != (size_t) (inner - outer))
{
printf ("strcpy flunked for outer = %d, inner = %d\n",
outer, inner);
result = 1;
}
 
adr[inner] = 'T';
}
}
 
/* strncpy tests */
adr[size-1] = 'T';
for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
{
size_t len;
 
for (len = 0; len < size - outer; ++len)
{
if (strncpy (dest, &adr[outer], len) != dest
|| memcmp (dest, &adr[outer], len) != 0)
{
printf ("outer strncpy flunked for outer = %d, len = %Zd\n",
outer, len);
result = 1;
}
}
}
adr[size-1] = '\0';
 
for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
{
for (inner = MAX (outer, size - 64); inner < size; ++inner)
{
size_t len;
 
adr[inner] = '\0';
 
for (len = 0; len < size - outer + 64; ++len)
{
if (strncpy (dest, &adr[outer], len) != dest
|| memcmp (dest, &adr[outer],
MIN (inner - outer, len)) != 0
|| (inner - outer < len
&& strlen (dest) != (inner - outer)))
{
printf ("strncpy flunked for outer = %d, inner = %d, len = %Zd\n",
outer, inner, len);
result = 1;
}
if (strncpy (dest + 1, &adr[outer], len) != dest + 1
|| memcmp (dest + 1, &adr[outer],
MIN (inner - outer, len)) != 0
|| (inner - outer < len
&& strlen (dest + 1) != (inner - outer)))
{
printf ("strncpy+1 flunked for outer = %d, inner = %d, len = %Zd\n",
outer, inner, len);
result = 1;
}
}
 
adr[inner] = 'T';
}
}
 
#ifndef __FreeBSD__
/* stpcpy test */
for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
{
for (inner = MAX (outer, size - 64); inner < size; ++inner)
{
adr[inner] = '\0';
 
if ((stpcpy (dest, &adr[outer]) - dest) != inner - outer)
{
printf ("stpcpy flunked for outer = %d, inner = %d\n",
outer, inner);
result = 1;
}
 
adr[inner] = 'T';
}
}
 
/* stpncpy test */
for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
{
for (middle = MAX (outer, size - 64); middle < size; ++middle)
{
adr[middle] = '\0';
 
for (inner = 0; inner < size - outer; ++ inner)
{
if ((stpncpy (dest, &adr[outer], inner) - dest)
!= MIN (inner, middle - outer))
{
printf ("stpncpy flunked for outer = %d, middle = %d, "
"inner = %d\n", outer, middle, inner);
result = 1;
}
}
 
adr[middle] = 'T';
}
}
#endif
 
/* memcpy test */
for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
for (inner = 0; inner < size - outer; ++inner)
if (memcpy (dest, &adr[outer], inner) != dest)
{
printf ("memcpy flunked for outer = %d, inner = %d\n",
outer, inner);
result = 1;
}
 
#ifndef __FreeBSD__
/* mempcpy test */
for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
for (inner = 0; inner < size - outer; ++inner)
if (mempcpy (dest, &adr[outer], inner) != dest + inner)
{
printf ("mempcpy flunked for outer = %d, inner = %d\n",
outer, inner);
result = 1;
}
#endif
}
 
return result;
}
/pass4-frag.c
0,0 → 1,9
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
char foo[10];
strcpy (foo, "123456789");
return 0;
}
/fail3-frag.c
0,0 → 1,13
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
volatile int foo [10][10][10];
foo[9][10][0] = 0;
return 0;
}
/* { dg-output "mudflap violation 1.*" } */
/* { dg-output "Nearby object 1.*" } */
/* { dg-output "mudflap object.*.main. foo.*" } */
/* { dg-do run { xfail *-*-* } } */
/pass8-frag.c
0,0 → 1,16
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
char *foo;
char *bar;
foo = (char *)malloc (10);
bar = (char *)malloc (10);
 
free(bar);
bar = (char *)malloc (10);
bar[6] = 'k'; /* touch memcpy source */
memcpy(foo, bar, 10);
return 0;
}
/fail7-frag.c
0,0 → 1,17
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
char *foo;
char *bar;
foo = (char *)malloc (12);
bar = (char *)malloc (10);
 
memcpy(foo+1, bar+1, 10);
return 0;
}
/* { dg-output "mudflap violation 1.*" } */
/* { dg-output "Nearby object 1.*" } */
/* { dg-output "mudflap object.*malloc region.*" } */
/* { dg-do run { xfail *-*-* } } */
/pass10-frag.c
0,0 → 1,12
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
int foo[10];
int sz = sizeof (int);
 
char *bar = (char *)foo;
bar [sz * 9] = 0;
return 0;
}
/pass20-frag.c
0,0 → 1,13
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
struct bar {int stuff; int array[10]; };
 
struct bar *foo = (struct bar *) malloc (sizeof (struct bar));
foo->array[5] = 4;
free (foo);
 
return 0;
}
/pass30-frag.c
0,0 → 1,12
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
char zoo [10];
 
int main ()
{
int i = strlen ("eight") + strlen ("one");
zoo[i] = 'a';
return 0;
}
/pass50-frag.c
0,0 → 1,29
#include <stdlib.h>
 
struct a
{
int a1[5];
union
{
int b1[5];
struct
{
int c1;
int c2;
} b2[4];
} a2[8];
};
 
int i1 = 5;
int i2 = 2;
int i3 = 6;
int i4 = 0;
 
int
main ()
{
volatile struct a *k = calloc (1, sizeof (struct a));
k->a2[i1].b1[i2] = k->a2[i3].b2[i4].c2;
free ((void *) k);
return 0;
}
/pass14-frag.c
0,0 → 1,20
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
struct a {
int x;
int y;
char z;
};
 
struct a k;
struct a *p;
 
p = &k;
 
p->z = 'q';
 
return 0;
}
/fail10-frag.c
0,0 → 1,16
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
volatile int foo[10];
int sz = sizeof (int);
 
volatile char *bar = (char *)foo;
bar [sz * 10] = 0;
return 0;
}
/* { dg-output "mudflap violation 1.*" } */
/* { dg-output "Nearby object 1.*" } */
/* { dg-output "mudflap object.*.main. foo.*" } */
/* { dg-do run { xfail *-*-* } } */
/pass24-frag.c
0,0 → 1,18
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
struct foo {
int zoo;
int bar [10];
float baz;
};
 
#define offsetof(S,F) ((size_t) & (((S *) 0)->F))
 
struct foo *k = (struct foo *) malloc (offsetof (struct foo, bar[4]));
k->bar[1] = 9;
free (k);
return 0;
}
/pass34-frag.c
0,0 → 1,18
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
void test (int *k)
{
if (*k > 5) { *k --; }
}
 
int z;
 
int main ()
{
/* z is initialized, but not via a pointer, so not instrumented */
z = rand ();
test (& z);
return 0;
}
/fail20-frag.c
0,0 → 1,13
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
volatile char *p = (char *) 0;
*p = 5;
return 0;
}
/* { dg-output "mudflap violation 1.*" } */
/* { dg-output "Nearby object 1.*" } */
/* { dg-output "mudflap object.*.NULL.*" } */
/* { dg-do run { xfail *-*-* } } */
/fail30-frag.c
0,0 → 1,18
#include <stdio.h>
#include <stdlib.h>
 
int foo (int u)
{
return u*u;
}
 
int main ()
{
int *k = malloc(5);
int j = foo (k[8]); /* this call argument should be instrumented */
return j;
}
/* { dg-output "mudflap violation 1.*" } */
/* { dg-output "Nearby object.*" } */
/* { dg-output "mudflap object.*malloc region.*alloc" } */
/* { dg-do run { xfail *-*-* } } */
/pass44-frag.c
0,0 → 1,14
#include <stdio.h>
 
void
foo ()
{
return; /* accept value-less return statement */
}
 
int
main (int argc, char *argv[])
{
foo ();
return 0;
}
/pass54-frag.c
0,0 → 1,33
struct k
{
struct {
int b;
int c;
} a;
};
 
static struct k l;
static struct k m;
 
void foo ()
{
/* This should not be instrumented. */
l.a.b = 5;
}
 
void bar ()
{
/* This should not be instrumented. */
m.a.b = 5;
}
 
int main ()
{
/* Force TREE_ADDRESSABLE on "l" only. */
volatile int *k = & l.a.c;
*k = 8;
__mf_set_options ("-mode-violate");
foo ();
bar ();
__mf_set_options ("-mode-check");
}
/pass18-frag.c
0,0 → 1,27
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
int t;
char foo[3] = { 'b', 'c', 'd' };
int bar[3] = {1, 2, 0};
t = 1;
 
/* These tests check expression evaluation rules, such as
ensuring that side-effect expression (++) get executed the
right number of times; that array lookup checks nest correctly. */
foo[t++] = 'a';
if (foo[0] != 'b' || foo[1] != 'a' || foo[2] != 'd' || t != 2) abort ();
if (bar[0] != 1 || bar[1] != 2 || bar[2] != 0) abort();
 
foo[bar[t--]] = 'e';
if (foo[0] != 'e' || foo[1] != 'a' || foo[2] != 'd' || t != 1) abort ();
if (bar[0] != 1 || bar[1] != 2 || bar[2] != 0) abort();
 
foo[bar[++t]--] = 'g';
if (foo[0] != 'g' || foo[1] != 'a' || foo[2] != 'd' || t != 2) abort ();
if (bar[0] != 1 || bar[1] != 2 || bar[2] != -1) abort();
 
return 0;
}
/fail40-frag.c
0,0 → 1,56
/* Test proper lookup-uncaching of large objects */
#include "../config.h"
 
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#ifdef HAVE_SYS_MMAN_H
#include <sys/mman.h>
#endif
 
int main ()
{
#ifndef MAP_ANONYMOUS
#define MAP_ANONYMOUS MAP_ANON
#endif
#ifdef HAVE_MMAP
volatile unsigned char *p;
unsigned num = getpagesize ();
unsigned i;
int rc;
 
/* Get a bit of usable address space. We really want an 2**N+1-sized object,
so the low/high addresses wrap when hashed into the lookup cache. So we
will manually unregister the entire mmap, then re-register a slice. */
p = mmap (NULL, num, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
if (p == NULL)
return 1;
/* Now unregister it, as if munmap was called. But don't actually munmap, so
we can write into the memory. */
__mf_unregister ((void *) p, num, __MF_TYPE_HEAP_I);
 
/* Now register it under a slightly inflated, 2**N+1 size. */
__mf_register ((void *) p, num+1, __MF_TYPE_HEAP_I, "fake mmap registration");
 
/* Traverse array to ensure that entire lookup cache is made to point at it. */
for (i=0; i<num; i++)
p[i] = 0;
 
/* Unregister it. This should clear the entire lookup cache, even though
hash(low) == hash (high) (and probably == 0) */
__mf_unregister ((void *) p, num+1, __MF_TYPE_HEAP_I);
 
/* Now touch the middle portion of the ex-array. If the lookup cache was
well and truly cleaned, then this access should trap. */
p[num/2] = 1;
 
return 0;
#else
return 1;
#endif
}
/* { dg-output "mudflap violation 1.*check/write.*" } */
/* { dg-output "Nearby object 1.*" } */
/* { dg-output "mudflap dead object.*fake mmap registration.*" } */
/* { dg-do run { xfail *-*-* } } */
/fail14-frag.c
0,0 → 1,29
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
struct a {
int x;
int y;
char z;
};
 
struct b {
int x;
int y;
};
 
volatile struct b k;
volatile struct a *p;
 
p = (struct a*) &k;
 
p->z = 'q';
 
return 0;
}
/* { dg-output "mudflap violation 1.*" } */
/* { dg-output "Nearby object 1.*" } */
/* { dg-output "mudflap object.*.main. k.*" } */
/* { dg-do run { xfail *-*-* } } */
/pass38-frag.c
0,0 → 1,9
/* Test an odd construct for compilability. */
static void *fwd;
void *bwd = &fwd;
static void *fwd = &bwd;
 
int main ()
{
return 0;
}
/fail34-frag.c
0,0 → 1,22
#include <stdlib.h>
 
struct s
{
int a1[4];
};
 
struct s a, b;
int idx = 7; /* should pass to the next object */
 
int
main ()
{
int i, j=0;
int a_before_b = (& a < & b);
j = (a_before_b ? a.a1[idx] : b.a1[idx]);
return j;
}
/* { dg-output "mudflap violation 1.*" } */
/* { dg-output "Nearby object.*" } */
/* { dg-output "mudflap object.*\[ab\]" } */
/* { dg-do run { xfail *-*-* } } */
/pass48-frag.c
0,0 → 1,11
void foo (int k)
{
volatile int *b = & k;
*b = 5;
}
 
int main ()
{
foo (5);
return 0;
}
/fail18-frag.c
0,0 → 1,16
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
/* One cannot redeclare __mf_lc_mask in proper C from instrumented
code, because of the way the instrumentation code emits its decls. */
extern unsigned foo __asm__ ("__mf_lc_mask");
unsigned * volatile bar = &foo;
*bar = 4;
return 0;
}
/* { dg-output "mudflap violation 1.*" } */
/* { dg-output "Nearby object 1.*" } */
/* { dg-output "mudflap object.*.__mf_lc_mask.*no-access.*" } */
/* { dg-do run { xfail *-*-* } } */
/externs.exp
0,0 → 1,43
global MUDFLAP_FLAGS
set MUDFLAP_FLAGS [list {} {-static} {-O2} {-O3}]
 
libmudflap-init c
dg-init
 
global srcdir subdir
 
foreach flags $MUDFLAP_FLAGS {
set l1 [libmudflap_target_compile "$srcdir/$subdir/externs-1.c" "externs-1.o" object {additional_flags=-fmudflap}]
set test "externs-1 compilation ${flags}"
if [string match "*mudflap cannot track unknown size extern *d*" $l1] { pass $test } { fail $test }
 
set l2 [libmudflap_target_compile "$srcdir/$subdir/externs-2.c" "externs-2.o" object {additional_flags=-fmudflap}]
set test "externs-2 compilation ${flags}"
if [string match "" $l2] { pass $test } { fail $test }
 
set l3 [libmudflap_target_compile "externs-1.o externs-2.o" "externs-12.exe" executable {additional_flags=-fmudflap additional_flags=-lmudflap}]
set test "externs-12 linkage ${flags}"
if [string match "" $l3] { pass $test } { fail $test }
 
set l4 [libmudflap_target_compile "externs-2.o externs-1.o" "externs-21.exe" executable {additional_flags=-fmudflap additional_flags=-lmudflap}]
set test "externs-21 linkage ${flags}"
if [string match "" $l3] { pass $test } { fail $test }
 
setenv MUDFLAP_OPTIONS "-viol-segv"
 
remote_spawn host "./externs-12.exe"
set l5 [remote_wait host 10]
set test "externs-12 execution ${flags}"
if {[lindex $l5 0] == 0} { pass $test } { fail $test }
 
remote_spawn host "./externs-21.exe"
set l6 [remote_wait host 10]
set test "externs-21 execution ${flags}"
if {[lindex $l6 0] == 0} { pass $test } { fail $test }
 
foreach f [glob -nocomplain "externs-*"] {
remote_file build delete $f
}
}
 
dg-finish
/fail28-frag.c
0,0 → 1,18
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
int foo (int *u, int i)
{
return u[i]; /* this dereference should be instrumented */
}
 
int main ()
{
int *k = malloc (6);
return foo (k, 8);
}
/* { dg-output "mudflap violation 1.*" } */
/* { dg-output "Nearby object.*" } */
/* { dg-output "mudflap object.*malloc region.*alloc" } */
/* { dg-do run { xfail *-*-* } } */
/fail38-frag.c
0,0 → 1,29
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
struct a {
int x;
int y;
int z : 10;
};
 
struct b {
int x;
int y;
};
 
volatile struct b k;
volatile struct a *p;
 
p = (struct a*) &k;
 
p->z = 'q';
 
return 0;
}
/* { dg-output "mudflap violation 1.*" } */
/* { dg-output "Nearby object 1.*" } */
/* { dg-output "mudflap object.*.main. k.*" } */
/* { dg-do run { xfail *-*-* } } */
/pass3-frag.c
0,0 → 1,9
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
int foo [10][10][10];
foo[9][9][0] = 0;
return 0;
}
/heap-scalestress.c
0,0 → 1,79
/* zz30
*
* demonstrate a splay-tree depth problem
*/
 
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
 
#ifndef SCALE
#define SCALE 100000
#endif
 
 
struct list
{
struct list *next;
};
 
 
int
main ()
{
struct list *head = NULL;
struct list *tail = NULL;
struct list *p;
long n;
int direction;
 
for (direction = 0; direction < 2; direction++)
{
fprintf (stdout, "allocating\n");
fflush (stdout);
 
for (n = 0; n < SCALE; ++n)
{
p = malloc (sizeof *p);
if (NULL == p)
{
fprintf (stdout, "malloc failed\n");
break;
}
if (direction == 0)
{ /* add at tail */
p->next = NULL;
if (NULL != tail)
tail->next = p;
else
head = p;
tail = p;
}
else
{ /* add at head */
p->next = head;
if (NULL == tail)
tail = p;
head = p;
}
}
 
fprintf (stdout, "freeing\n");
fflush (stdout);
 
while (NULL != head)
{
p = head;
head = head->next;
free (p);
}
 
}
 
fprintf (stdout, "done\n");
fflush (stdout);
 
return (0);
}
 
/* { dg-output "allocating.*freeing.*allocating.*freeing.*done" } */
/fail2-frag.c
0,0 → 1,13
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
volatile int foo [10][10];
foo[10][0] = 0;
return 0;
}
/* { dg-output "mudflap violation 1.*" } */
/* { dg-output "Nearby object 1.*" } */
/* { dg-output "mudflap object.*.main. foo.*" } */
/* { dg-do run { xfail *-*-* } } */
/pass7-frag.c
0,0 → 1,13
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
char *foo;
char *bar;
foo = (char *)malloc (10);
bar = (char *)malloc (10);
bar[2] = 'z'; /* touch memcpy source */
memcpy(foo+1, bar+1, 9);
return 0;
}
/fail6-frag.c
0,0 → 1,17
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
char *foo;
char *bar;
foo = (char *)malloc (10);
bar = (char *)malloc (15);
 
memcpy(foo, bar, 11);
return 0;
}
/* { dg-output "mudflap violation 1.*" } */
/* { dg-output "Nearby object 1.*" } */
/* { dg-output "mudflap object.*malloc region.*" } */
/* { dg-do run { xfail *-*-* } } */
/pass13-frag.c
0,0 → 1,17
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
struct a {
int x;
int y;
char z;
};
 
struct a k;
 
k.z = 'q';
 
return 0;
}
/externs-2.c
0,0 → 1,2
typedef struct { char *name; } dummy;
dummy d[] = { {"a"}, {0} };
/pass23-frag.c
0,0 → 1,29
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
struct foo {
int part1: 8;
int nothing : 1;
int part2 : 5;
int lots_more_nothing : 3;
int some_padding; /* for 64-bit hosts */
float some_more_nothing;
double yet_more_nothing;
};
 
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *) 0)->MEMBER)
 
struct foo* q = (struct foo *) malloc (offsetof (struct foo, some_more_nothing));
q->nothing = 1; /* touch q */
/* The RHS of the following expression is meant to trigger a
fold-const.c mapping the expression to a BIT_FIELD_REF. It glues
together the accesses to the two non-neighbouring bitfields into a
single bigger boolean test. */
q->lots_more_nothing = (q->part1 == 13 && q->part2 == 7);
free (q);
 
 
return 0;
}
/pass33-frag.c
0,0 → 1,17
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
void test (int *k)
{
if (*k > 5) { *k --; }
}
 
int main ()
{
int z;
/* z is initialized, but not via a pointer, so not instrumented */
z = rand ();
test (& z);
return 0;
}
/pass43-frag.c
0,0 → 1,11
void
foo ()
{
}
 
int
main (int argc, char *argv[])
{
foo ();
return 0;
}
/pass17-frag.c
0,0 → 1,9
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
 
strlen("123456789");
return 0;
}
/pass53-frag.c
0,0 → 1,41
int foo1 ()
{
union { int l; char c[sizeof (int)]; } k1;
char *m;
k1.l = 0;
/* This test variant triggers ADDR_EXPR of k explicitly in order to
ensure it's registered with the runtime. */
m = k1.c;
k1.c [sizeof (int)-1] = m[sizeof (int)-2];
}
 
int foo2 ()
{
union { int l; char c[sizeof (int)]; } k2;
k2.l = 0;
/* Since this access is known-in-range, k need not be registered
with the runtime, but then this access better not be instrumented
either. */
k2.c [sizeof (int)-1] ++;
return k2.l;
}
 
int foo3idx = sizeof (int)-1;
 
int foo3 ()
{
union { int l; char c[sizeof (int)]; } k3;
k3.l = 0;
/* NB this test uses foo3idx, an extern variable, to defeat mudflap
known-in-range-index optimizations. */
k3.c [foo3idx] ++;
return k3.l;
}
 
int main ()
{
foo1 ();
foo2 ();
foo3 ();
return 0;
}
/fail13-frag.c
0,0 → 1,26
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
struct a {
int x;
int y;
char z;
};
 
struct b {
int x;
int y;
};
 
struct b k;
 
(*((volatile struct a *) &k)).z = 'q';
 
return 0;
}
/* { dg-output "mudflap violation 1..check/write.*" } */
/* { dg-output "Nearby object 1.*" } */
/* { dg-output "mudflap object.*.main. k.*" } */
/* { dg-do run { xfail *-*-* } } */
/fail23-frag.c
0,0 → 1,16
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
char zoo [10];
 
int main ()
{
int i = strlen ("012345") + strlen ("6789") + strlen ("01"); /* 11 */
zoo[i] = 'a';
return 0;
}
/* { dg-output "mudflap violation 1.*" } */
/* { dg-output "Nearby object.*" } */
/* { dg-output "mudflap object.*zoo.*static.*" } */
/* { dg-do run { xfail *-*-* } } */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.