1 /* Test whether strncmp has not been "optimized" into memcmp 2 nor any code with memcmp semantics. */ 3 /* { dg-do run { target mmap } } */ 4 /* { dg-options "-O2" } */ 5 #include <stddef.h> 6 #include <stdio.h> 7 #include <sys/mman.h> 8 /* Darwin spells this differently */ 9 #ifndef MAP_ANONYMOUS 10 #define MAP_ANONYMOUS MAP_ANON 11 #endif 12 #ifndef MAP_ANON 13 #define MAP_ANON 0 14 #endif 15 #ifndef MAP_FAILED 16 #define MAP_FAILED ((void *)-1) 17 #endif 18 #include <stdlib.h> 19 20 struct Flags { 21 int filler[18]; 22 unsigned int a:14; 23 unsigned int b:14; 24 unsigned int c:1; 25 unsigned int d:1; 26 unsigned int e:1; 27 unsigned int f:1; 28 }; 29 static void __attribute__((noinline)) set (struct Flags *); set(struct Flags * fp)30static void set (struct Flags *fp) 31 { 32 fp->b = 5; 33 fp->d = 1; 34 } 35 36 static int __attribute__((noinline)) bar (int); bar(int x)37static int bar(int x) { return !(x==1); } main(void)38int main (void) 39 { 40 char *p = mmap (NULL, 131072, PROT_READ | PROT_WRITE, 41 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); 42 struct Flags *fp; 43 if (p == MAP_FAILED) 44 return 0; 45 if (munmap (p + 65536, 65536) < 0) 46 return 0; 47 fp = (struct Flags*)(p + 65536 - sizeof(struct Flags)); 48 set(fp); 49 if (fp->b > 0) 50 return (bar(fp->d)); 51 return 1; 52 } 53