Ejemplo n.º 1
0
static int
gf_ctime (char *s, size_t max, const time_t timev)
{
  struct tm ltm;
  int failed;
  char buf[CTIME_BUFSZ + 1];
  /* Some targets provide a localtime_r based on a draft of the POSIX
     standard where the return type is int rather than the
     standardized struct tm*.  */
  __builtin_choose_expr (__builtin_classify_type (localtime_r (&timev, &ltm)) 
			 == 5,
			 failed = localtime_r (&timev, &ltm) == NULL,
			 failed = localtime_r (&timev, &ltm) != 0);
  if (failed)
    goto blank;
  int n = snprintf (buf, sizeof (buf), 
		    "%3.3s %3.3s%3d %.2d:%.2d:%.2d %d",
		    "SunMonTueWedThuFriSat" + ltm.tm_wday * 3,
		    "JanFebMarAprMayJunJulAugSepOctNovDec" + ltm.tm_mon * 3,
		    ltm.tm_mday, ltm.tm_hour, ltm.tm_min, ltm.tm_sec, 
		    1900 + ltm.tm_year);
  if (n < 0)
    goto blank;
  if ((size_t) n <= max)
    {
      cf_strcpy (s, max, buf);
      return n;
    }
 blank:
  memset (s, ' ', max);
  return 0;
}
Ejemplo n.º 2
0
  return p;
}


/* Hopefully thread-safe wrapper for a strerror_r() style function.  */

char *
gf_strerror (int errnum, 
             char * buf __attribute__((unused)), 
	     size_t buflen __attribute__((unused)))
{
#ifdef HAVE_STRERROR_R
  /* POSIX returns an "int", GNU a "char*".  */
  return
    __builtin_choose_expr (__builtin_classify_type (strerror_r (0, buf, 0))
			   == 5,
			   /* GNU strerror_r()  */
			   strerror_r (errnum, buf, buflen),
			   /* POSIX strerror_r ()  */
			   (strerror_r (errnum, buf, buflen), buf));
#elif defined(HAVE_STRERROR_R_2ARGS)
  strerror_r (errnum, buf);
  return buf;
#else
  /* strerror () is not necessarily thread-safe, but should at least
     be available everywhere.  */
  return strerror (errnum);
#endif
}
Ejemplo n.º 3
0
// RUN: %clang_cc1 %s -verify -fsyntax-only

float a;

int b[__builtin_classify_type(a + 1i) == 9 ? 1 : -1];
int c[__builtin_classify_type(1i + a) == 9 ? 1 : -1];

double d;
__typeof__ (d + 1i) e;

int f[sizeof(e) == 2 * sizeof(double) ? 1 : -1];

int g;
int h[__builtin_classify_type(g + 1.0i) == 9 ? 1 : -1];
int i[__builtin_classify_type(1.0i + a) == 9 ? 1 : -1];
Ejemplo n.º 4
0
void test() {
  int a;
  int xs[10];
  ++a = 0; // ok
  a + ++a; // expected-warning {{unsequenced modification and access to 'a'}}
  a = ++a; // ok
  a + a++; // expected-warning {{unsequenced modification and access to 'a'}}
  a = a++; // expected-warning {{multiple unsequenced modifications to 'a'}}
  ++ ++a; // ok
  (a++, a++); // ok
  ++a + ++a; // expected-warning {{multiple unsequenced modifications to 'a'}}
  a++ + a++; // expected-warning {{multiple unsequenced modifications}}
  (a++, a) = 0; // ok, increment is sequenced before value computation of LHS
  a = xs[++a]; // ok
  a = xs[a++]; // expected-warning {{multiple unsequenced modifications}}
  (a ? xs[0] : xs[1]) = ++a; // expected-warning {{unsequenced modification and access}}
  a = (++a, ++a); // ok
  a = (a++, ++a); // ok
  a = (a++, a++); // expected-warning {{multiple unsequenced modifications}}
  f(a, a); // ok
  f(a = 0, a); // expected-warning {{unsequenced modification and access}}
  f(a, a += 0); // expected-warning {{unsequenced modification and access}}
  f(a = 0, a = 0); // expected-warning {{multiple unsequenced modifications}}

  // Compound assignment "A OP= B" is equivalent to "A = A OP B" except that A
  // is evaluated only once.
  (++a, a) = 1; // ok
  (++a, a) += 1; // ok
  a = ++a; // ok
  a += ++a; // expected-warning {{unsequenced modification and access}}

  A agg1 = { a++, a++ }; // ok
  A agg2 = { a++ + a, a++ }; // expected-warning {{unsequenced modification and access}}

  S str1(a++, a++); // expected-warning {{multiple unsequenced modifications}}
  S str2 = { a++, a++ }; // ok
  S str3 = { a++ + a, a++ }; // expected-warning {{unsequenced modification and access}}

  (xs[2] && (a = 0)) + a; // ok
  (0 && (a = 0)) + a; // ok
  (1 && (a = 0)) + a; // expected-warning {{unsequenced modification and access}}

  (xs[3] || (a = 0)) + a; // ok
  (0 || (a = 0)) + a; // expected-warning {{unsequenced modification and access}}
  (1 || (a = 0)) + a; // ok

  (xs[4] ? a : ++a) + a; // ok
  (0 ? a : ++a) + a; // expected-warning {{unsequenced modification and access}}
  (1 ? a : ++a) + a; // ok
  (xs[5] ? ++a : ++a) + a; // FIXME: warn here

  (++a, xs[6] ? ++a : 0) + a; // expected-warning {{unsequenced modification and access}}

  // Here, the read of the fourth 'a' might happen before or after the write to
  // the second 'a'.
  a += (a++, a) + a; // expected-warning {{unsequenced modification and access}}

  int *p = xs;
  a = *(a++, p); // ok
  a = a++ && a; // ok

  A *q = &agg1;
  (q = &agg2)->y = q->x; // expected-warning {{unsequenced modification and access to 'q'}}

  // This has undefined behavior if a == 0; otherwise, the side-effect of the
  // increment is sequenced before the value computation of 'f(a, a)', which is
  // sequenced before the value computation of the '&&', which is sequenced
  // before the assignment. We treat the sequencing in '&&' as being
  // unconditional.
  a = a++ && f(a, a);

  // This has undefined behavior if a != 0. FIXME: We should diagnose this.
  (a && a++) + a;

  (xs[7] && ++a) * (!xs[7] && ++a); // ok

  xs[0] = (a = 1, a); // ok
  (a -= 128) &= 128; // ok
  ++a += 1; // ok

  xs[8] ? ++a + a++ : 0; // expected-warning {{multiple unsequenced modifications}}
  xs[8] ? 0 : ++a + a++; // expected-warning {{multiple unsequenced modifications}}
  xs[8] ? ++a : a++; // ok

  xs[8] && (++a + a++); // expected-warning {{multiple unsequenced modifications}}
  xs[8] || (++a + a++); // expected-warning {{multiple unsequenced modifications}}

  (__builtin_classify_type(++a) ? 1 : 0) + ++a; // ok
  (__builtin_constant_p(++a) ? 1 : 0) + ++a; // ok
  (__builtin_object_size(&(++a, a), 0) ? 1 : 0) + ++a; // ok
  (__builtin_expect(++a, 0) ? 1 : 0) + ++a; // expected-warning {{multiple unsequenced modifications}}
}
Ejemplo n.º 5
0
void foo() {
  int i;
  char c;
  enum { red, green, blue} enum_obj;
  bool b;
  int *p;
  int &r = i;
  double d;
  extern void f();
  cl cl_obj;
  union { int a; float b; } u_obj;
  int arr[10];

  int a1[__builtin_classify_type(f()) == void_type_class ? 1 : -1];
  int a2[__builtin_classify_type(i) == integer_type_class ? 1 : -1];
  int a3[__builtin_classify_type(c) == integer_type_class ? 1 : -1];
  int a4[__builtin_classify_type(enum_obj) == enumeral_type_class ? 1 : -1];
  int a5[__builtin_classify_type(b) == boolean_type_class ? 1 : -1];
  int a6[__builtin_classify_type(p) == pointer_type_class ? 1 : -1];
  int a7[__builtin_classify_type(r) == integer_type_class ? 1 : -1];
  int a8[__builtin_classify_type(&cl::baz) == offset_type_class ? 1 : -1];
  int a9[__builtin_classify_type(d) == real_type_class ? 1 : -1];
  int a10[__builtin_classify_type(f) == function_type_class ? 1 : -1];
  int a11[__builtin_classify_type(&cl::bar) == method_type_class ? 1 : -1];
  int a12[__builtin_classify_type(cl_obj) == record_type_class ? 1 : -1];
  int a13[__builtin_classify_type(u_obj) == union_type_class ? 1 : -1];
  int a14[__builtin_classify_type(arr) == array_type_class ? 1 : -1];
  int a15[__builtin_classify_type("abc") == array_type_class ? 1 : -1];
}