[cfe-commits] r55736 - in /cfe/trunk/test: CodeGen/builtins.c Sema/builtin-object-size.c
Daniel Dunbar
daniel at zuster.org
Wed Sep 3 14:17:21 PDT 2008
Author: ddunbar
Date: Wed Sep 3 16:17:21 2008
New Revision: 55736
URL: http://llvm.org/viewvc/llvm-project?rev=55736&view=rev
Log:
Add two test cases for builtins (mostly related to object size
builtins).
Added:
cfe/trunk/test/CodeGen/builtins.c
cfe/trunk/test/Sema/builtin-object-size.c
Added: cfe/trunk/test/CodeGen/builtins.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins.c?rev=55736&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/builtins.c (added)
+++ cfe/trunk/test/CodeGen/builtins.c Wed Sep 3 16:17:21 2008
@@ -0,0 +1,95 @@
+// RUN: clang -emit-llvm -o %t %s &&
+// RUN: not grep __builtin %t
+
+#include <stdio.h>
+#include <math.h>
+
+void p(char *str, int x) {
+ printf("%s: %d\n", str, x);
+}
+void q(char *str, double x) {
+ printf("%s: %f\n", str, x);
+}
+
+int main() {
+ int N = random();
+#define P(n,args) p(#n #args, __builtin_##n args)
+#define Q(n,args) q(#n #args, __builtin_##n args)
+#define V(n,args) p(#n #args, (__builtin_##n args, 0))
+ P(types_compatible_p, (int, float));
+ P(choose_expr, (0, 10, 20));
+ P(constant_p, (sizeof(10)));
+ P(expect, (N == 12, 0));
+ V(prefetch, (&N));
+ V(prefetch, (&N, 1));
+ V(prefetch, (&N, 1, 0));
+
+ // Numeric Constants
+
+ Q(huge_val, ());
+ Q(huge_valf, ());
+ Q(huge_vall, ());
+ Q(inf, ());
+ Q(inff, ());
+ Q(infl, ());
+
+ // FIXME:
+ // XXX note funny semantics for the (last) argument
+ // P(fpclassify, (FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, 1.0));
+ // P(isinf_sign, (1.0));
+
+ // FIXME:
+ // XXX I don't know what the string arg is for
+ Q(nan, ("0x12"));
+ Q(nanf, ("0x12"));
+ Q(nanl, ("0x12"));
+ Q(nans, ("0x12"));
+
+ // Bitwise & Numeric Functions
+
+ P(clz, (N));
+ P(clzl, (N));
+ P(clzll, (N));
+ P(ctz, (N));
+ P(ctzl, (N));
+ P(ctzll, (N));
+ P(ffs, (N));
+ P(ffsl, (N));
+ P(ffsll, (N));
+ P(parity, (N));
+ P(parityl, (N));
+ P(parityll, (N));
+ P(popcount, (N));
+ P(popcountl, (N));
+ P(popcountll, (N));
+ Q(powi, (1.2f, N));
+ Q(powif, (1.2f, N));
+ Q(powil, (1.2f, N));
+
+ // Object size checking
+ int a, b, n = random(); // Avoid optimizing out.
+ char s0[10], s1[] = "Hello";
+ V(__memset_chk, (s0, 0, sizeof s0, n));
+ V(__memcpy_chk, (s0, s1, sizeof s0, n));
+ V(__memmove_chk, (s0, s1, sizeof s0, n));
+ V(__mempcpy_chk, (s0, s1, sizeof s0, n));
+ V(__strncpy_chk, (s0, s1, sizeof s0, n));
+ V(__strcpy_chk, (s0, s1, n));
+ s0[0] = 0;
+ V(__strcat_chk, (s0, s1, n));
+ P(object_size, (s0, 0));
+ P(object_size, (s0, 1));
+ P(object_size, (s0, 2));
+ P(object_size, (s0, 3));
+
+ // Whatever
+
+ P(bswap32, (N));
+ P(bswap64, (N));
+ // FIXME
+ // V(clear_cache, (&N, &N+1));
+ V(trap, ());
+
+ return 0;
+}
+
Added: cfe/trunk/test/Sema/builtin-object-size.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/builtin-object-size.c?rev=55736&view=auto
==============================================================================
--- cfe/trunk/test/Sema/builtin-object-size.c (added)
+++ cfe/trunk/test/Sema/builtin-object-size.c Wed Sep 3 16:17:21 2008
@@ -0,0 +1,19 @@
+// RUN: clang -fsyntax-only -verify %s
+
+int a[10];
+
+int f0() {
+ return __builtin_object_size(&a); // expected-error {{too few arguments to function}}
+}
+int f1() {
+ return (__builtin_object_size(&a, 0) +
+ __builtin_object_size(&a, 1) +
+ __builtin_object_size(&a, 2) +
+ __builtin_object_size(&a, 3));
+}
+int f2() {
+ return __builtin_object_size(&a, -1); // expected-error {{argument should be a value from 0 to 3}}
+}
+int f3() {
+ return __builtin_object_size(&a, 4); // expected-error {{argument should be a value from 0 to 3}}
+}
More information about the cfe-commits
mailing list