1 /* Test strncmp builtin expansion for compilation and proper execution. */
2 /* { dg-do run { target *-*-linux* *-*-gnu* } } */
3 /* { dg-options "-O2" } */
4 /* { dg-require-effective-target ptr32plus } */
13 int lib_memcmp(const void *a
, const void *b
, size_t n
) asm("memcmp");
14 int lib_strncmp(const char *a
, const char *b
, size_t n
) asm("strncmp");
16 static void test_driver_strncmp (void (test_strncmp
)(const char *, const char *, int),
17 void (test_memcmp
)(const void *, const void *, int),
20 long pgsz
= sysconf(_SC_PAGESIZE
);
23 #if _POSIX_C_SOURCE >= 200112L
24 if ( posix_memalign ((void **)&buf2
, pgsz
, 2*pgsz
) ) abort ();
26 if ( !(buf2
= valloc(2*pgsz
))) abort ();
31 r
= mprotect (buf2
+pgsz
,pgsz
,PROT_NONE
);
35 for(i
=10; i
>=0; i
--) {
38 e
= lib_strncmp(buf1
,p2
,sz
);
39 (*test_strncmp
)(buf1
,p2
,e
);
40 e
= lib_memcmp(buf1
,p2
,sz
);
41 (*test_memcmp
)(buf1
,p2
,e
);
46 #define RUN_TEST(SZ) test_driver_strncmp (test_strncmp_ ## SZ, test_memcmp_ ## SZ, SZ);
48 #define DEF_TEST(SZ) \
49 __attribute__((noinline)) \
50 void test_strncmp_ ## SZ (const char *str1, const char *str2, int expect) \
53 r = strncmp(str1,str2,SZ); \
54 if ( r < 0 && !(expect < 0) ) abort(); \
55 if ( r > 0 && !(expect > 0) ) abort(); \
56 if ( r == 0 && !(expect == 0) ) abort(); \
58 __attribute__((noinline)) \
59 void test_memcmp_ ## SZ (const void *p1, const void *p2, int expect) \
62 r = memcmp(p1,p2,SZ); \
63 if ( r < 0 && !(expect < 0) ) abort(); \
64 if ( r > 0 && !(expect > 0) ) abort(); \
65 if ( r == 0 && !(expect == 0) ) abort(); \
95 main(int argc
, char **argv
)