[llvm-commits] CVS: llvm-test/SingleSource/UnitTests/SignlessTypes/cast-bug.c cast.cpp
Reid Spencer
reid at x10sys.com
Sat Nov 25 00:50:43 PST 2006
Changes in directory llvm-test/SingleSource/UnitTests/SignlessTypes:
cast-bug.c added (r1.1)
cast.cpp added (r1.1)
---
Log message:
Add some tests for casting.
---
Diffs of the changes: (+165 -0)
cast-bug.c | 15 ++++++
cast.cpp | 150 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 165 insertions(+)
Index: llvm-test/SingleSource/UnitTests/SignlessTypes/cast-bug.c
diff -c /dev/null llvm-test/SingleSource/UnitTests/SignlessTypes/cast-bug.c:1.1
*** /dev/null Sat Nov 25 02:50:39 2006
--- llvm-test/SingleSource/UnitTests/SignlessTypes/cast-bug.c Sat Nov 25 02:50:29 2006
***************
*** 0 ****
--- 1,15 ----
+ int
+ main ( int argc, char** argv)
+ {
+ int i;
+ int result;
+ result = 1;
+ for (i = 2; i <= argc+2; i++)
+ {
+ if ((i & 1) == 0)
+ {
+ result = result + 17;
+ }
+ }
+ return (result);
+ }
Index: llvm-test/SingleSource/UnitTests/SignlessTypes/cast.cpp
diff -c /dev/null llvm-test/SingleSource/UnitTests/SignlessTypes/cast.cpp:1.1
*** /dev/null Sat Nov 25 02:50:43 2006
--- llvm-test/SingleSource/UnitTests/SignlessTypes/cast.cpp Sat Nov 25 02:50:29 2006
***************
*** 0 ****
--- 1,150 ----
+ /*
+ * This file is used to test combinations of eliminable cast
+ * operations to ensure that the logic in InstCombine is correct.
+ */
+
+ #include <stdio.h>
+ #include <stdlib.h>
+
+ int main(int argc, char**argv) {
+ int testVal = 42;
+ int i;
+ if (argc > 1)
+ testVal = atoi(argv[1]);
+
+ // First check for elimination of A -> B -> C type casts.
+
+ // Make sure the loop goes through 256 values to catch at
+ // least some single byte signed issues.
+ for (i = -128+testVal; i < 128+testVal; ++i) {
+
+ #define TRIPLECAST(num, first, second, third) \
+ { \
+ first X = (first) num; \
+ second Y = (second) X; \
+ third Z = (third) Y; \
+ printf("Test %d(%s) -> %s -> %s = %d\n", \
+ num, #first, #second, #third,(int)Z); \
+ }
+
+ // Test same size with sign rotation
+ TRIPLECAST(i, unsigned char, unsigned char, unsigned char);
+ TRIPLECAST(i, unsigned char, unsigned char, signed char);
+ TRIPLECAST(i, unsigned char, signed char, unsigned char);
+ TRIPLECAST(i, unsigned char, signed char, signed char);
+ TRIPLECAST(i, signed char, unsigned char, unsigned char);
+ TRIPLECAST(i, signed char, unsigned char, signed char);
+ TRIPLECAST(i, signed char, signed char, unsigned char);
+ TRIPLECAST(i, signed char, signed char, signed char);
+ TRIPLECAST(i, unsigned short, unsigned short, unsigned short);
+ TRIPLECAST(i, unsigned short, unsigned short, signed short);
+ TRIPLECAST(i, unsigned short, signed short, unsigned short);
+ TRIPLECAST(i, unsigned short, signed short, signed short);
+ TRIPLECAST(i, signed short, unsigned short, unsigned short);
+ TRIPLECAST(i, signed short, unsigned short, signed short);
+ TRIPLECAST(i, signed short, signed short, unsigned short);
+ TRIPLECAST(i, signed short, signed short, signed short);
+ TRIPLECAST(i, unsigned int, unsigned int, unsigned int);
+ TRIPLECAST(i, unsigned int, unsigned int, signed int);
+ TRIPLECAST(i, unsigned int, signed int, unsigned int);
+ TRIPLECAST(i, unsigned int, signed int, signed int);
+ TRIPLECAST(i, signed int, unsigned int, unsigned int);
+ TRIPLECAST(i, signed int, unsigned int, signed int);
+ TRIPLECAST(i, signed int, signed int, unsigned int);
+ TRIPLECAST(i, signed int, signed int, signed int);
+ TRIPLECAST(i, unsigned long, unsigned long, unsigned long);
+ TRIPLECAST(i, unsigned long, unsigned long, signed long);
+ TRIPLECAST(i, unsigned long, signed long, unsigned long);
+ TRIPLECAST(i, unsigned long, signed long, signed long);
+ TRIPLECAST(i, signed long, unsigned long, unsigned long);
+ TRIPLECAST(i, signed long, unsigned long, signed long);
+ TRIPLECAST(i, signed long, signed long, unsigned long);
+ TRIPLECAST(i, signed long, signed long, signed long);
+
+ // Same size through larger size
+ TRIPLECAST(i, unsigned char, unsigned short, unsigned char);
+ TRIPLECAST(i, unsigned char, unsigned short, signed char);
+ TRIPLECAST(i, unsigned char, signed short, unsigned char);
+ TRIPLECAST(i, unsigned char, signed short, signed char);
+ TRIPLECAST(i, signed char, unsigned short, unsigned char);
+ TRIPLECAST(i, signed char, unsigned short, signed char);
+ TRIPLECAST(i, signed char, signed short, unsigned char);
+ TRIPLECAST(i, signed char, signed short, signed char);
+ TRIPLECAST(i, unsigned short, unsigned int, unsigned short);
+ TRIPLECAST(i, unsigned short, unsigned int, signed short);
+ TRIPLECAST(i, unsigned short, signed int, unsigned short);
+ TRIPLECAST(i, unsigned short, signed int, signed short);
+ TRIPLECAST(i, signed short, unsigned int, unsigned short);
+ TRIPLECAST(i, signed short, unsigned int, signed short);
+ TRIPLECAST(i, signed short, signed int, unsigned short);
+ TRIPLECAST(i, signed short, signed int, signed short);
+ TRIPLECAST(i, unsigned int, unsigned long, unsigned int);
+ TRIPLECAST(i, unsigned int, unsigned long, signed int);
+ TRIPLECAST(i, unsigned int, signed long, unsigned int);
+ TRIPLECAST(i, unsigned int, signed long, signed int);
+ TRIPLECAST(i, signed int, unsigned long, unsigned int);
+ TRIPLECAST(i, signed int, unsigned long, signed int);
+ TRIPLECAST(i, signed int, signed long, unsigned int);
+ TRIPLECAST(i, signed int, signed long, signed int);
+
+ // Larger size through smaller size
+ TRIPLECAST(i, unsigned short, unsigned char, unsigned short);
+ TRIPLECAST(i, unsigned short, unsigned char, signed short);
+ TRIPLECAST(i, unsigned short, signed char, unsigned short);
+ TRIPLECAST(i, unsigned short, signed char, signed short);
+ TRIPLECAST(i, signed short, unsigned char, unsigned short);
+ TRIPLECAST(i, signed short, unsigned char, signed short);
+ TRIPLECAST(i, signed short, signed char, unsigned short);
+ TRIPLECAST(i, signed short, signed char, signed short);
+ TRIPLECAST(i, unsigned int, unsigned short, unsigned int);
+ TRIPLECAST(i, unsigned int, unsigned short, signed int);
+ TRIPLECAST(i, unsigned int, signed short, unsigned int);
+ TRIPLECAST(i, unsigned int, signed short, signed int);
+ TRIPLECAST(i, signed int, unsigned short, unsigned int);
+ TRIPLECAST(i, signed int, unsigned short, signed int);
+ TRIPLECAST(i, signed int, signed short, unsigned int);
+ TRIPLECAST(i, signed int, signed short, signed int);
+ TRIPLECAST(i, unsigned long, unsigned int, unsigned long);
+ TRIPLECAST(i, unsigned long, unsigned int, signed long);
+ TRIPLECAST(i, unsigned long, signed int, unsigned long);
+ TRIPLECAST(i, unsigned long, signed int, signed long);
+ TRIPLECAST(i, signed long, unsigned int, unsigned long);
+ TRIPLECAST(i, signed long, unsigned int, signed long);
+ TRIPLECAST(i, signed long, signed int, unsigned long);
+ TRIPLECAST(i, signed long, signed int, signed long);
+ }
+
+ // Check cast to bool
+ #define CASTTOBOOL(num, type) \
+ { \
+ type Y = (type) num; \
+ bool X = (bool) num; \
+ printf("%d(%s) -> bool = %d\n", num, #type, (int)X); \
+ }
+ CASTTOBOOL(testVal, float);
+ CASTTOBOOL(testVal, long);
+ CASTTOBOOL(testVal, unsigned int);
+ CASTTOBOOL(testVal, signed char);
+ CASTTOBOOL(testVal, bool);
+
+ // Check useless getelementptr
+ {
+ static int sillyArray[8] = { 2, 3, 5, 7, 11, 13, 17, 19 };
+ int* i_ptr = &sillyArray[ 0 ];
+ long* l_ptr = (long*) i_ptr;
+ printf("%ld\n", *l_ptr);
+ }
+
+ // Cast of malloc result to another type
+ {
+ int* int_ptr = (int*) malloc(sizeof(long));
+ *int_ptr = 42;
+ long* long_ptr = (long*) int_ptr;
+ printf("%ld\n", *long_ptr);
+ }
+
+ // Propagation of single-use casts into other instructions
+ {
+ }
+ return 0;
+ }
More information about the llvm-commits
mailing list