int main (void) { if (__builtin_strcmp (str1, latin2_1) != 0 || __builtin_strcmp (str2, latin2_2) != 0 || __builtin_strcmp (str3, utf8_1) != 0 || __builtin_strcmp (str4, utf8_2) != 0 || __builtin_strncmp (str5, latin2_1, sizeof (latin2_1) - 1) != 0 || __builtin_strcmp (str5 + sizeof (latin2_1) - 1, latin2_2) != 0 || __builtin_strncmp (str6, utf8_1, sizeof (utf8_1) - 1) != 0 || __builtin_strcmp (str6 + sizeof (utf8_1) - 1, utf8_2) != 0 || __builtin_strncmp (str7, utf8_1, sizeof (utf8_1) - 1) != 0 || __builtin_strcmp (str7 + sizeof (utf8_1) - 1, utf8_2) != 0 || __builtin_strncmp (str8, utf8_1, sizeof (utf8_1) - 1) != 0 || __builtin_strcmp (str8 + sizeof (utf8_1) - 1, utf8_2) != 0) __builtin_abort (); if (sizeof ("a" u8"b"[0]) != 1 || sizeof (u8"a" "b"[0]) != 1 || sizeof (u8"a" u8"b"[0]) != 1 || sizeof ("a" "\u010d") != 3 || sizeof ("a" u8"\u010d") != 4 || sizeof (u8"a" "\u010d") != 4 || sizeof (u8"a" "\u010d") != 4) __builtin_abort (); return 0; }
__attribute__ ((noinline)) int f1 (S * s) { int result = 0; result += __builtin_strncmp (s->s, "ab", 2); result += __builtin_strncmp (s->s, "abc", 3); return result; }
__attribute__ ((noinline)) int f2 (char *p) { int result = 0; result += __builtin_strncmp (p, "ab", 2); result += __builtin_strncmp (p, "abc", 3); return result; }
int foo (const char *x) { const char *a; int b = 0; a = __builtin_strchr (s, '.'); if (a == 0) b = 1; else if ((a = __builtin_strchr (a + 1, '.')) == 0) b = 1; else if (__builtin_strncmp (s, x, a - s)) b = 1; else if (__builtin_strncmp (a + 1, x + (a - s + 1), 4) < 0) b = 1; if (b) return 4; return 0; }
int main() { long double d; char s[sizeof d]; __builtin_memcpy(&d, STR, sizeof d); __builtin_memcpy(&s, &d, sizeof s); if (__builtin_strncmp (s, STR, sizeof s) != 0) __builtin_abort (); return 0; }
foo (double x, double y ,double z ,double a, int size) { char *p = __builtin_alloca (size + 1); double i; bar (p, size); if (__builtin_strncmp (p, "good", size) != 0) { #ifdef DEBUG p[size] = '\0'; printf ("Failed: %s != good\n", p); #endif abort (); } check (&i, __alignof__(i)); }
foo (__m128 x, __m128 y ,__m128 z ,__m128 a, int size) { char *p = __builtin_alloca (size + 1); aligned i; bar (p, size); if (__builtin_strncmp (p, "good", size) != 0) { #ifdef DEBUG p[size] = '\0'; printf ("Failed: %s != good\n", p); #endif abort (); } if (check_int (&i, __alignof__(i)) != i) abort (); }
int main (void) { char *p = __builtin_alloca (6); bar (0); __builtin_strncpy (p, "good", 5); if (__builtin_strncmp (p, "good", 5) != 0) { #ifdef DEBUG p[5] = '\0'; printf ("Failed: %s != good\n", p); #endif abort (); } return 0; }
foo (int size) throw (B,A) { char *p = (char *) __builtin_alloca (size + 1); aligned i; bar (p, size); if (__builtin_strncmp (p, "good", size) != 0) { #ifdef DEBUG p[size] = '\0'; printf ("Failed: %s != good\n", p); #endif abort (); } if (check_int (&i, __alignof__(i)) != i) abort (); throw A(); }
foo () { int __attribute__ ((aligned(64))) a=4; char * s = (char *) __builtin_alloca (a + 1); copy (s, a); if (__builtin_strncmp (s, "good", a) != 0) { #ifdef DEBUG s[a] = '\0'; printf ("Failed: %s != good\n", s); #endif abort (); } if (check_int (&a, __alignof__(a)) != a) abort (); ALTER_REGS(); throw a; }
foo (int size) #if __cplusplus <= 201402L throw (B,A) // { dg-warning "deprecated" "" { target { c++11 && { ! c++1z } } } } #endif { char *p = (char *) __builtin_alloca (size + 1); aligned i; bar (p, size); if (__builtin_strncmp (p, "good", size) != 0) { #ifdef DEBUG p[size] = '\0'; printf ("Failed: %s != good\n", p); #endif abort (); } if (check_int (&i, __alignof__(i)) != i) abort (); throw A(); }
void test (va_list arg) #if __cplusplus <= 201402L throw (B,A) // { dg-warning "deprecated" "" { target { c++11 && { ! c++1z } } } } #endif { char *p; aligned i; int size; double x; size = va_arg (arg, int); if (size != 5) abort (); p = (char *) __builtin_alloca (size + 1); x = va_arg (arg, double); if (x != 5.0) abort (); bar (p, size); if (__builtin_strncmp (p, "good", size) != 0) { #ifdef DEBUG p[size] = '\0'; printf ("Failed: %s != good\n", p); #endif abort (); } if (check_int (&i, __alignof__(i)) != i) abort (); throw A(); }
/* Test that cmp/str is not used for small lengths. */ int test01 (const char *s1) { return __builtin_strncmp (s1, "abcde", 3); }
/* Test that no call is generated */ int test03 (const char *s1, int n) { return __builtin_strncmp (s1, "abcde", n); }
/* Test that the cmp/str loop is used. */ int test02 (const char *s1) { return __builtin_strncmp (s1, "abcdefghi", 8); }
static int callback (void *data, uintptr_t pc, const char *filename, int lineno, const char *function) { struct callers_data *arg = (struct callers_data *) data; Location *loc; /* Skip split stack functions. */ if (function != NULL) { const char *p; p = function; if (__builtin_strncmp (p, "___", 3) == 0) ++p; if (__builtin_strncmp (p, "__morestack_", 12) == 0) return 0; } else if (filename != NULL) { const char *p; p = strrchr (filename, '/'); if (p == NULL) p = filename; if (__builtin_strncmp (p, "/morestack.S", 12) == 0) return 0; } /* Skip thunks and recover functions. There is no equivalent to these functions in the gc toolchain, so returning them here means significantly different results for runtime.Caller(N). */ if (function != NULL) { const char *p; p = __builtin_strchr (function, '.'); if (p != NULL && __builtin_strncmp (p + 1, "$thunk", 6) == 0) return 0; p = __builtin_strrchr (function, '$'); if (p != NULL && __builtin_strcmp(p, "$recover") == 0) return 0; } if (arg->skip > 0) { --arg->skip; return 0; } loc = &arg->locbuf[arg->index]; loc->pc = pc; /* The libbacktrace library says that these strings might disappear, but with the current implementation they won't. We can't easily allocate memory here, so for now assume that we can save a pointer to the strings. */ loc->filename = runtime_gostringnocopy ((const byte *) filename); loc->function = runtime_gostringnocopy ((const byte *) function); loc->lineno = lineno; ++arg->index; return arg->index >= arg->max; }
int main () { const char *const s1 = "hello world"; const char *s2, *s3; int n = 6, x; if (strncmp (s1, "hello world", 12) != 0) abort(); if (strncmp ("hello world", s1, 12) != 0) abort(); if (strncmp ("hello", "hello", 6) != 0) abort(); if (strncmp ("hello", "hello", 2) != 0) abort(); if (strncmp ("hello", "hello", 100) != 0) abort(); if (strncmp (s1+10, "d", 100) != 0) abort(); if (strncmp (10+s1, "d", 100) != 0) abort(); if (strncmp ("d", s1+10, 1) != 0) abort(); if (strncmp ("d", 10+s1, 1) != 0) abort(); if (strncmp ("hello", "aaaaa", 100) <= 0) abort(); if (strncmp ("aaaaa", "hello", 100) >= 0) abort(); if (strncmp ("hello", "aaaaa", 1) <= 0) abort(); if (strncmp ("aaaaa", "hello", 1) >= 0) abort(); s2 = s1; s3 = s1+4; if (strncmp (++s2, ++s3, 0) != 0 || s2 != s1+1 || s3 != s1+5) abort(); s2 = s1; if (strncmp (++s2, "", 1) <= 0 || s2 != s1+1) abort(); if (strncmp ("", ++s2, 1) >= 0 || s2 != s1+2) abort(); if (strncmp (++s2, "", 100) <= 0 || s2 != s1+3) abort(); if (strncmp ("", ++s2, 100) >= 0 || s2 != s1+4) abort(); if (strncmp (++s2+6, "", 100) != 0 || s2 != s1+5) abort(); if (strncmp ("", ++s2+5, 100) != 0 || s2 != s1+6) abort(); if (strncmp ("ozz", ++s2, 1) != 0 || s2 != s1+7) abort(); if (strncmp (++s2, "rzz", 1) != 0 || s2 != s1+8) abort(); s2 = s1; s3 = s1+4; if (strncmp (++s2, ++s3+2, 1) >= 0 || s2 != s1+1 || s3 != s1+5) abort(); #if defined(__i386__) || defined (__pj__) || defined (__i370__) /* These tests work on platforms which support cmpstrsi. */ s2 = s1; if (strncmp (++s2, "ello", 3) != 0 || s2 != s1+1) abort(); s2 = s1; if (strncmp ("ello", ++s2, 3) != 0 || s2 != s1+1) abort(); s2 = s1; if (strncmp (++s2, "ello", 4) != 0 || s2 != s1+1) abort(); s2 = s1; if (strncmp ("ello", ++s2, 4) != 0 || s2 != s1+1) abort(); s2 = s1; if (strncmp (++s2, "ello", 5) <= 0 || s2 != s1+1) abort(); s2 = s1; if (strncmp ("ello", ++s2, 5) >= 0 || s2 != s1+1) abort(); s2 = s1; if (strncmp (++s2, "ello", 6) <= 0 || s2 != s1+1) abort(); s2 = s1; if (strncmp ("ello", ++s2, 6) >= 0 || s2 != s1+1) abort(); s2 = s1; if (strncmp (++s2, "zllo", 3) >= 0 || s2 != s1+1) abort(); s2 = s1; if (strncmp ("zllo", ++s2, 3) <= 0 || s2 != s1+1) abort(); s2 = s1; if (strncmp (++s2, "zllo", 4) >= 0 || s2 != s1+1) abort(); s2 = s1; if (strncmp ("zllo", ++s2, 4) <= 0 || s2 != s1+1) abort(); s2 = s1; if (strncmp (++s2, "zllo", 5) >= 0 || s2 != s1+1) abort(); s2 = s1; if (strncmp ("zllo", ++s2, 5) <= 0 || s2 != s1+1) abort(); s2 = s1; if (strncmp (++s2, "zllo", 6) >= 0 || s2 != s1+1) abort(); s2 = s1; if (strncmp ("zllo", ++s2, 6) <= 0 || s2 != s1+1) abort(); s2 = s1; if (strncmp (++s2, "allo", 3) <= 0 || s2 != s1+1) abort(); s2 = s1; if (strncmp ("allo", ++s2, 3) >= 0 || s2 != s1+1) abort(); s2 = s1; if (strncmp (++s2, "allo", 4) <= 0 || s2 != s1+1) abort(); s2 = s1; if (strncmp ("allo", ++s2, 4) >= 0 || s2 != s1+1) abort(); s2 = s1; if (strncmp (++s2, "allo", 5) <= 0 || s2 != s1+1) abort(); s2 = s1; if (strncmp ("allo", ++s2, 5) >= 0 || s2 != s1+1) abort(); s2 = s1; if (strncmp (++s2, "allo", 6) <= 0 || s2 != s1+1) abort(); s2 = s1; if (strncmp ("allo", ++s2, 6) >= 0 || s2 != s1+1) abort(); s2 = s1; n = 2; x = 1; if (strncmp (++s2, s1+(x&3), ++n) != 0 || s2 != s1+1 || n != 3) abort(); s2 = s1; n = 2; x = 1; if (strncmp (s1+(x&3), ++s2, ++n) != 0 || s2 != s1+1 || n != 3) abort(); s2 = s1; n = 3; x = 1; if (strncmp (++s2, s1+(x&3), ++n) != 0 || s2 != s1+1 || n != 4) abort(); s2 = s1; n = 3; x = 1; if (strncmp (s1+(x&3), ++s2, ++n) != 0 || s2 != s1+1 || n != 4) abort(); s2 = s1; n = 4; x = 1; if (strncmp (++s2, s1+(x&3), ++n) != 0 || s2 != s1+1 || n != 5) abort(); s2 = s1; n = 4; x = 1; if (strncmp (s1+(x&3), ++s2, ++n) != 0 || s2 != s1+1 || n != 5) abort(); s2 = s1; n = 5; x = 1; if (strncmp (++s2, s1+(x&3), ++n) != 0 || s2 != s1+1 || n != 6) abort(); s2 = s1; n = 5; x = 1; if (strncmp (s1+(x&3), ++s2, ++n) != 0 || s2 != s1+1 || n != 6) abort(); s2 = s1; n = 2; if (strncmp (++s2, "zllo", ++n) >= 0 || s2 != s1+1 || n != 3) abort(); s2 = s1; n = 2; x = 1; if (strncmp ("zllo", ++s2, ++n) <= 0 || s2 != s1+1 || n != 3) abort(); s2 = s1; n = 3; x = 1; if (strncmp (++s2, "zllo", ++n) >= 0 || s2 != s1+1 || n != 4) abort(); s2 = s1; n = 3; x = 1; if (strncmp ("zllo", ++s2, ++n) <= 0 || s2 != s1+1 || n != 4) abort(); s2 = s1; n = 4; x = 1; if (strncmp (++s2, "zllo", ++n) >= 0 || s2 != s1+1 || n != 5) abort(); s2 = s1; n = 4; x = 1; if (strncmp ("zllo", ++s2, ++n) <= 0 || s2 != s1+1 || n != 5) abort(); s2 = s1; n = 5; x = 1; if (strncmp (++s2, "zllo", ++n) >= 0 || s2 != s1+1 || n != 6) abort(); s2 = s1; n = 5; x = 1; if (strncmp ("zllo", ++s2, ++n) <= 0 || s2 != s1+1 || n != 6) abort(); s2 = s1; n = 2; if (strncmp (++s2, "allo", ++n) <= 0 || s2 != s1+1 || n != 3) abort(); s2 = s1; n = 2; x = 1; if (strncmp ("allo", ++s2, ++n) >= 0 || s2 != s1+1 || n != 3) abort(); s2 = s1; n = 3; x = 1; if (strncmp (++s2, "allo", ++n) <= 0 || s2 != s1+1 || n != 4) abort(); s2 = s1; n = 3; x = 1; if (strncmp ("allo", ++s2, ++n) >= 0 || s2 != s1+1 || n != 4) abort(); s2 = s1; n = 4; x = 1; if (strncmp (++s2, "allo", ++n) <= 0 || s2 != s1+1 || n != 5) abort(); s2 = s1; n = 4; x = 1; if (strncmp ("allo", ++s2, ++n) >= 0 || s2 != s1+1 || n != 5) abort(); s2 = s1; n = 5; x = 1; if (strncmp (++s2, "allo", ++n) <= 0 || s2 != s1+1 || n != 6) abort(); s2 = s1; n = 5; x = 1; if (strncmp ("allo", ++s2, ++n) >= 0 || s2 != s1+1 || n != 6) abort(); #endif /* Test at least one instance of the __builtin_ style. We do this to ensure that it works and that the prototype is correct. */ if (__builtin_strncmp ("hello", "a", 100) <= 0) abort(); return 0; }
void main_test (void) { const char *const s1 = "hello world"; const char *s2, *s3; int n = 6, x; if (strncmp (s1, "hello world", 12) != 0) abort(); if (strncmp ("hello world", s1, 12) != 0) abort(); if (strncmp ("hello", "hello", 6) != 0) abort(); if (strncmp ("hello", "hello", 2) != 0) abort(); if (strncmp ("hello", "hello", 100) != 0) abort(); if (strncmp (s1+10, "d", 100) != 0) abort(); if (strncmp (10+s1, "d", 100) != 0) abort(); if (strncmp ("d", s1+10, 1) != 0) abort(); if (strncmp ("d", 10+s1, 1) != 0) abort(); if (strncmp ("hello", "aaaaa", 100) <= 0) abort(); if (strncmp ("aaaaa", "hello", 100) >= 0) abort(); if (strncmp ("hello", "aaaaa", 1) <= 0) abort(); if (strncmp ("aaaaa", "hello", 1) >= 0) abort(); s2 = s1; s3 = s1+4; if (strncmp (++s2, ++s3, 0) != 0 || s2 != s1+1 || s3 != s1+5) abort(); s2 = s1; if (strncmp (++s2, "", 1) <= 0 || s2 != s1+1) abort(); if (strncmp ("", ++s2, 1) >= 0 || s2 != s1+2) abort(); if (strncmp (++s2, "", 100) <= 0 || s2 != s1+3) abort(); if (strncmp ("", ++s2, 100) >= 0 || s2 != s1+4) abort(); if (strncmp (++s2+6, "", 100) != 0 || s2 != s1+5) abort(); if (strncmp ("", ++s2+5, 100) != 0 || s2 != s1+6) abort(); if (strncmp ("ozz", ++s2, 1) != 0 || s2 != s1+7) abort(); if (strncmp (++s2, "rzz", 1) != 0 || s2 != s1+8) abort(); s2 = s1; s3 = s1+4; if (strncmp (++s2, ++s3+2, 1) >= 0 || s2 != s1+1 || s3 != s1+5) abort(); /* Test at least one instance of the __builtin_ style. We do this to ensure that it works and that the prototype is correct. */ if (__builtin_strncmp ("hello", "a", 100) <= 0) abort(); }
static int callback (void *data, uintptr_t pc, const char *filename, int lineno, const char *function) { struct callers_data *arg = (struct callers_data *) data; Location *loc; /* Skip split stack functions. */ if (function != NULL) { const char *p; p = function; if (__builtin_strncmp (p, "___", 3) == 0) ++p; if (__builtin_strncmp (p, "__morestack_", 12) == 0) return 0; } else if (filename != NULL) { const char *p; p = strrchr (filename, '/'); if (p == NULL) p = filename; if (__builtin_strncmp (p, "/morestack.S", 12) == 0) return 0; } /* Skip thunks and recover functions. There is no equivalent to these functions in the gc toolchain, so returning them here means significantly different results for runtime.Caller(N). */ if (function != NULL) { const char *p; p = __builtin_strchr (function, '.'); if (p != NULL && __builtin_strncmp (p + 1, "$thunk", 6) == 0) return 0; p = __builtin_strrchr (function, '$'); if (p != NULL && __builtin_strcmp(p, "$recover") == 0) return 0; } if (arg->skip > 0) { --arg->skip; return 0; } loc = &arg->locbuf[arg->index]; loc->pc = pc; /* The libbacktrace library says that these strings might disappear, but with the current implementation they won't. We can't easily allocate memory here, so for now assume that we can save a pointer to the strings. */ loc->filename = runtime_gostringnocopy ((const byte *) filename); loc->function = runtime_gostringnocopy ((const byte *) function); loc->lineno = lineno; ++arg->index; /* There is no point to tracing past certain runtime functions. Stopping the backtrace here can avoid problems on systems that don't provide proper unwind information for makecontext, such as Solaris (http://gcc.gnu.org/PR52583 comment #21). */ if (function != NULL) { if (__builtin_strcmp (function, "makecontext") == 0) return 1; if (filename != NULL) { const char *p; p = strrchr (filename, '/'); if (p == NULL) p = filename; if (__builtin_strcmp (p, "/proc.c") == 0) { if (__builtin_strcmp (function, "kickoff") == 0 || __builtin_strcmp (function, "runtime_mstart") == 0 || __builtin_strcmp (function, "runtime_main") == 0) return 1; } } } return arg->index >= arg->max; }
__attribute__ ((noinline)) int f7 (S *s) { return __builtin_strncmp ("abc", s->s, 3) != 0; }
__attribute__ ((noinline)) int f8 (void) { return __builtin_strncmp ("abc", s, 2) != 0; }
void __attribute__((noinline)) test (const char *p) { if (__builtin_strncmp (p, "abcdefghijklmnopq", 17) == 0) abort (); }