From 12e0bdc6595dea6133084b6014845e5436930457 Mon Sep 17 00:00:00 2001 From: Willem Date: Thu, 9 Oct 2014 06:47:30 -0700 Subject: Added tests to _testingUtils.c (currently failing due to a bug in printing 64bit numbers) Fixing this bug will expose a failing test case for Concrete/ConstantExpr.ll --- test/Concrete/_testingUtils.c | 44 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/test/Concrete/_testingUtils.c b/test/Concrete/_testingUtils.c index 693a5a09..aa85d010 100644 --- a/test/Concrete/_testingUtils.c +++ b/test/Concrete/_testingUtils.c @@ -1,6 +1,6 @@ -// This isn't a real test, just common code for the other ones. -// -// RUN: true +// RUN: %llvmgcc -D_TESTINGUTILS_TEST %s -o %t +// RUN: %t | FileCheck %s +// XFAIL: int printf(const char *fmt, ...); @@ -39,3 +39,41 @@ void print_int(unsigned long long val) { printf(char_format_string, '\n'); } + + +#ifdef _TESTINGUTILS_TEST +int main(int argc, char *argv[]) +{ + print_i64(0xf000000000000064); + // CHECK: 17293822569102704740 + print_i64(0x7000000000000064); + // CHECK: 8070450532247928932 + + print_i32(0xf0000032); + // CHECK: 4026531890 + print_i32(0x70000032); + // CHECK: 1879048242 + + print_i16(0xf016); + // CHECK: 61462 + print_i16(0x7016); + // CHECK: 28694 + + + print_i8(0xf8); + // CHECK: 248 + print_i8(0x78); + // CHECK: 120 + + printf("print_i1(0)\n"); + print_i1(0); + // CHECK: i1(0) + // CHECK_NEXT: 0 + + printf("print_i1(1)\n"); + print_i1(1); + // CHECK: i1(1) + // CHECK_NEXT: 1 + +} +#endif -- cgit 1.4.1 From f0e50a8374a398e52b224dff2aa88384f90424ff Mon Sep 17 00:00:00 2001 From: Willem Date: Thu, 9 Oct 2014 07:50:26 -0700 Subject: Fixed test/Concrete/ConstantExpr.ll The difference between a 64bit pointer truncated to 32 bits and the original 64bit pointer would never be 0 if any of the high 32bits in the pointer were test. If lli and klee had a different value for the top 32bits of the address this test would be marked as failing. Due to the 64bit printing buf in _testingUtils this was not exposed before. The fix clears the top 32bits of the difference. --- test/Concrete/ConstantExpr.ll | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Concrete/ConstantExpr.ll b/test/Concrete/ConstantExpr.ll index 3a151a0f..351223e7 100644 --- a/test/Concrete/ConstantExpr.ll +++ b/test/Concrete/ConstantExpr.ll @@ -24,8 +24,8 @@ define void @"test_int_to_ptr"() { define void @"test_constant_ops"() { %t1 = add i8 trunc(i64 add(i64 ptrtoint(i32* @gInt to i64), i64 -10) to i8), 10 - %t2 = sub i64 sext(i32 ptrtoint(i32* @gInt to i32) to i64), ptrtoint(i32* @gInt to i64) - %t3 = sub i64 zext(i32 ptrtoint(i32* @gInt to i32) to i64), ptrtoint(i32* @gInt to i64) + %t2 = and i64 sub(i64 sext(i32 ptrtoint(i32* @gInt to i32) to i64), i64 ptrtoint(i32* @gInt to i64)), 4294967295 + %t3 = and i64 sub(i64 zext(i32 ptrtoint(i32* @gInt to i32) to i64), i64 ptrtoint(i32* @gInt to i64)), 4294967295 %t4 = icmp eq i8 trunc(i64 ptrtoint(i32* @gInt to i64) to i8), %t1 %t5 = zext i1 %t4 to i8 -- cgit 1.4.1 From f017599be7cd7e71cea3aa0a1bccb4a2c6f38783 Mon Sep 17 00:00:00 2001 From: Willem Date: Thu, 9 Oct 2014 06:59:57 -0700 Subject: Fix the bug in printing 64bit numbers, set the test to expect passing. Changed _testingUtils to use stdint.h --- test/Concrete/_testingUtils.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/test/Concrete/_testingUtils.c b/test/Concrete/_testingUtils.c index aa85d010..dbab921d 100644 --- a/test/Concrete/_testingUtils.c +++ b/test/Concrete/_testingUtils.c @@ -1,6 +1,7 @@ // RUN: %llvmgcc -D_TESTINGUTILS_TEST %s -o %t // RUN: %t | FileCheck %s -// XFAIL: + +#include int printf(const char *fmt, ...); @@ -9,19 +10,19 @@ void print_int(unsigned long long val); #define TYPED_PRINT(_name_type, _arg_type) \ void print_ ## _name_type(_arg_type val) { print_int(val); } -TYPED_PRINT(i1, unsigned char) -TYPED_PRINT(i8, unsigned char) -TYPED_PRINT(i16, unsigned short) -TYPED_PRINT(i32, unsigned int) -TYPED_PRINT(i64, unsigned long long) +TYPED_PRINT(i1, uint8_t) +TYPED_PRINT(i8, uint8_t) +TYPED_PRINT(i16, uint16_t) +TYPED_PRINT(i32, uint32_t) +TYPED_PRINT(i64, uint64_t) // This is a workaround to hide the "%c" only format string from the compiler -- // llvm-gcc can optimize this into putchar even at -O0, and the LLVM JIT doesn't // recognize putchar() as a valid external function. char *char_format_string = "%c"; -void print_int(unsigned long long val) { - int cur = 1; +void print_int(uint64_t val) { + uint64_t cur = 1; // effectively do a log (can't call log because it returns floats) // do the nasty divide to prevent overflow -- cgit 1.4.1 From a6ce7bb9a8c01c62411f8484f13002f66e990293 Mon Sep 17 00:00:00 2001 From: Willem Date: Thu, 16 Oct 2014 10:00:35 -0700 Subject: Fixed declaration of print_int that Travis complained about --- test/Concrete/_testingUtils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Concrete/_testingUtils.c b/test/Concrete/_testingUtils.c index dbab921d..ef99f908 100644 --- a/test/Concrete/_testingUtils.c +++ b/test/Concrete/_testingUtils.c @@ -5,7 +5,7 @@ int printf(const char *fmt, ...); -void print_int(unsigned long long val); +void print_int(uint64_t val); #define TYPED_PRINT(_name_type, _arg_type) \ void print_ ## _name_type(_arg_type val) { print_int(val); } -- cgit 1.4.1