|
From: <sv...@va...> - 2008-08-02 06:56:19
|
Author: sewardj
Date: 2008-08-02 07:56:27 +0100 (Sat, 02 Aug 2008)
New Revision: 8496
Log:
Make these tests 64-bit clean.
Modified:
branches/PTRCHECK/exp-ptrcheck/tests/arith.c
branches/PTRCHECK/exp-ptrcheck/tests/arith_include2.c
branches/PTRCHECK/exp-ptrcheck/tests/cmp.c
branches/PTRCHECK/exp-ptrcheck/tests/partial.c
branches/PTRCHECK/exp-ptrcheck/tests/pth_create.c
branches/PTRCHECK/exp-ptrcheck/tests/realloc.c
branches/PTRCHECK/exp-ptrcheck/tests/supp.c
branches/PTRCHECK/exp-ptrcheck/tests/tricky.c
Modified: branches/PTRCHECK/exp-ptrcheck/tests/arith.c
===================================================================
--- branches/PTRCHECK/exp-ptrcheck/tests/arith.c 2008-08-02 06:55:41 UTC (rev 8495)
+++ branches/PTRCHECK/exp-ptrcheck/tests/arith.c 2008-08-02 06:56:27 UTC (rev 8496)
@@ -1,57 +1,57 @@
#include <stdlib.h>
-typedef unsigned int Uint;
+typedef unsigned long Ulong;
int main(void)
{
- int* x = malloc(sizeof(int) * 10);
- int* y = malloc(sizeof(int) * 10);
- int* y2 = y + 3;
+ long* x = malloc(sizeof(long) * 10);
+ long* y = malloc(sizeof(long) * 10);
+ long* y2 = y + 3;
// ok -- same segment
- int w = y2 - y;
+ long w = y2 - y;
// ok -- different heap segments (result can only be used to index off
// 'x', but glibc's strcpy() does this...)
- int* z = (int*)((int)x - (int)y);
+ long* z = (long*)((long)x - (long)y);
- w = (int)y2 + (int)y; // bad (same segment)
+ w = (long)y2 + (long)y; // bad (same segment)
- w = (int)x & (int)y; // bad (different segments)
+ w = (long)x & (long)y; // bad (different segments)
- w = (int)y2 / (int)4; // bad, but indistinguishable from
- // acceptable '%' cases...
+ w = (long)y2 / (long)4; // bad, but indistinguishable from
+ // acceptable '%' cases...
- w = (int)y2 % (int)4; // ok
- w = (int)y2 % (int)y; // bad -- modulor(?) is a pointer
- w = (int)0xffffffff % (int)y; // bad -- modulend(?) is a non-pointer
+ w = (long)y2 % (long)4; // ok
+ w = (long)y2 % (long)y; // bad -- modulor(?) is a pointer
+ w = (long)0xffffffff % (long)y; // bad -- modulend(?) is a non-pointer
- w = (Uint)y2 % (Uint)4; // ok
- w = (Uint)y2 % (Uint)y; // bad -- modulor(?) is a pointer
- w = (Uint)0xffffffff % (Uint)y; // bad -- modulend(?) is a non-pointer
+ w = (Ulong)y2 % (Ulong)4; // ok
+ w = (Ulong)y2 % (Ulong)y; // bad -- modulor(?) is a pointer
+ w = (Ulong)0xffffffff % (Ulong)y; // bad -- modulend(?) is a non-pointer
- w = (int)y * (int)y2; // bad
+ w = (long)y * (long)y2; // bad
- w = (int)y >> (int)2; // ok
- w = (int)y << (int)2; // ok
+ w = (long)y >> (long)2; // ok
+ w = (long)y << (long)2; // ok
- w = (int)y & 0xffff; // ok
- w = (int)y | 0xffff; // ok
- w = (int)y ^ (int)y2; // ok
+ w = (long)y & 0xffff; // ok
+ w = (long)y | 0xffff; // ok
+ w = (long)y ^ (long)y2; // ok
- w = ~((int)y); // ok
+ w = ~((long)y); // ok
- w = -((int)y); // bad -- operand is a non-pointer
+ w = -((long)y); // bad -- operand is a non-polonger
- w = (int)x ^ (int)x; // xor(ptr,ptr) --> constant (0)
- z = x + w; // ok, because xor result was zero
+ w = (long)x ^ (long)x; // xor(ptr,ptr) --> constant (0)
+ z = x + w; // ok, because xor result was zero
- w = (int)x ^ ((int)x+1); // xor(ptr,ptr') --> constant (small)
- z = x + w; // ok, because xor result was constant
+ w = (long)x ^ ((long)x+1); // xor(ptr,ptr') --> constant (small)
+ z = x + w; // ok, because xor result was constant
- w = (int)x ^ (int)y; // xor(ptr,ptr') --> constant (small)
- z = x + w; // ok, because xor result was constant
+ w = (long)x ^ (long)y; // xor(ptr,ptr') --> constant (small)
+ z = x + w; // ok, because xor result was constant
- return (int)z;
+ return (long)z;
}
Modified: branches/PTRCHECK/exp-ptrcheck/tests/arith_include2.c
===================================================================
--- branches/PTRCHECK/exp-ptrcheck/tests/arith_include2.c 2008-08-02 06:55:41 UTC (rev 8495)
+++ branches/PTRCHECK/exp-ptrcheck/tests/arith_include2.c 2008-08-02 06:56:27 UTC (rev 8496)
@@ -8,30 +8,30 @@
if (__builtin_setjmp(TTT_jmpbuf) == 0) \
{ fprintf(stderr, "about to do %d [-1]\n", __LINE__); tn = tp[-1]; }
- #define b( a, c) tp = (int*)a; TTT
- #define ui(op, a, c) tp = (int*)op(int)a; TTT
- #define g(op, a,b,c) tp = (int*)((int)a op (int)b); TTT
+ #define b( a, c) tp = (long*)a; TTT
+ #define ui(op, a, c) tp = (long*)op(long)a; TTT
+ #define g(op, a,b,c) tp = (long*)((long)a op (long)b); TTT
#define UNU __attribute__((unused))
struct sigaction sigsegv;
// Scratch values
- int a, tn;
- int* tp;
+ long a, tn;
+ long* tp;
// Known pointers
- int* p = malloc(sizeof(int)*10); UNU int* p2 = malloc(sizeof(int)*10);
- UNU int* pp = p;
+ long* p = malloc(sizeof(long)*10); UNU long* p2 = malloc(sizeof(long)*10);
+ UNU long* pp = p;
// Unknown pointers
-// int up[10], UNU up2[10];
+// long up[10], UNU up2[10];
// Known nonptrs; make them zero and known
- int n = a ^ a, UNU n2 = n+1, UNU n7F = 0x7fffffff, UNU nFF = ~n;
+ long n = a ^ a, UNU n2 = n+1, UNU n7F = 0x7fffffffUL, UNU nFF = ~n;
// Unknown nonptrs; make them zero but unknown
- int un = 0x01100000, UNU un2 = un;
+ long un = 0x01100000UL, UNU un2 = un;
// Known nonptr, from pointerness range check
- UNU int nn = 0;
+ UNU long nn = 0;
// Intall SEGV handler
memset(&sigsegv, 0, sizeof(sigsegv));
Modified: branches/PTRCHECK/exp-ptrcheck/tests/cmp.c
===================================================================
--- branches/PTRCHECK/exp-ptrcheck/tests/cmp.c 2008-08-02 06:55:41 UTC (rev 8495)
+++ branches/PTRCHECK/exp-ptrcheck/tests/cmp.c 2008-08-02 06:56:27 UTC (rev 8496)
@@ -9,7 +9,7 @@
char* buf = malloc(sizeof(char) * 6);
// Known zero non-pointer
- char* nz = (char*)((int)buf^(int)buf); // known non-pointer
+ char* nz = (char*)((long)buf^(long)buf); // known non-pointer
// Unknown zero nonptr; make them zero but unknown
char* unz;
Modified: branches/PTRCHECK/exp-ptrcheck/tests/partial.c
===================================================================
--- branches/PTRCHECK/exp-ptrcheck/tests/partial.c 2008-08-02 06:55:41 UTC (rev 8495)
+++ branches/PTRCHECK/exp-ptrcheck/tests/partial.c 2008-08-02 06:56:27 UTC (rev 8496)
@@ -14,7 +14,7 @@
int* y6 = malloc(6);
int* y7 = malloc(7);
- #define ADDB(ptr, n) ((int*)(((unsigned int)(ptr)) + (n)))
+ #define ADDB(ptr, n) ((long*)(((unsigned long)(ptr)) + (n)))
// All these overrun by a single byte; the reads are happening at
// different alignments.
@@ -39,7 +39,7 @@
// These are all bad
f = * f3; // ok if --partial-loads-ok=yes
- d = * d7; // ok if --partial-loads-ok=yes
+ d = * d7;
lli = * lli7; // ok if --partial-loads-ok=yes
c = * c0;
s = * s1;
Modified: branches/PTRCHECK/exp-ptrcheck/tests/pth_create.c
===================================================================
--- branches/PTRCHECK/exp-ptrcheck/tests/pth_create.c 2008-08-02 06:55:41 UTC (rev 8495)
+++ branches/PTRCHECK/exp-ptrcheck/tests/pth_create.c 2008-08-02 06:56:27 UTC (rev 8496)
@@ -14,9 +14,9 @@
pthread_key_t* key = malloc(sizeof(pthread_key_t));
pthread_key_t* key2 = malloc(sizeof(pthread_key_t));
- pthread_key_create ( (pthread_key_t*)((int)key + 1), NULL );
+ pthread_key_create ( (pthread_key_t*)((long)key + 1), NULL );
free(key2);
- pthread_key_create ( key2 , NULL );
+ pthread_key_create ( key2 , NULL );
return 0;
}
Modified: branches/PTRCHECK/exp-ptrcheck/tests/realloc.c
===================================================================
--- branches/PTRCHECK/exp-ptrcheck/tests/realloc.c 2008-08-02 06:55:41 UTC (rev 8495)
+++ branches/PTRCHECK/exp-ptrcheck/tests/realloc.c 2008-08-02 06:56:27 UTC (rev 8496)
@@ -7,7 +7,7 @@
int* y;
int** x = malloc(sizeof(int) * 100);
int* x2 = malloc(sizeof(int) * 100);
-
+ void* sink;
x[0] = x2; // this is to check the pointerness is copied across ok
x[49] = x2; // this is to check the pointerness is copied across ok
@@ -40,7 +40,7 @@
i = *x[0]; // ok
i = *x[49]; // ok
- realloc((void*)0x99, 10); // fails
+ sink = realloc((void*)0x99, 10); // fails
return 0;
}
Modified: branches/PTRCHECK/exp-ptrcheck/tests/supp.c
===================================================================
--- branches/PTRCHECK/exp-ptrcheck/tests/supp.c 2008-08-02 06:55:41 UTC (rev 8495)
+++ branches/PTRCHECK/exp-ptrcheck/tests/supp.c 2008-08-02 06:56:27 UTC (rev 8496)
@@ -11,8 +11,8 @@
int i = 11;
char* buf = malloc(sizeof(char) * 6);
char c = buf[-1]; // LoadStoreErr
- char* x = buf + (int)buf; // ArithErr
- char* y = (char*)((int)buf * i); // AsmErr
+ char* x = buf + (long)buf; // ArithErr
+ char* y = (char*)((long)buf * i); // AsmErr
write(-1, buf+3, 5); // SysParamErr
return x-y+c;
Modified: branches/PTRCHECK/exp-ptrcheck/tests/tricky.c
===================================================================
--- branches/PTRCHECK/exp-ptrcheck/tests/tricky.c 2008-08-02 06:55:41 UTC (rev 8495)
+++ branches/PTRCHECK/exp-ptrcheck/tests/tricky.c 2008-08-02 06:56:27 UTC (rev 8496)
@@ -10,8 +10,8 @@
int* p = malloc(sizeof(int) * 100);
p[0] = 0; // ok
- int* n = (int*)((int)p+(int)u); // result is n, because near zero!
- int* x = (int*)((int)n - (int)u); // x == p
+ int* n = (int*)((long)p + (long)u); // result is n, because near zero!
+ int* x = (int*)((long)n - (long)u); // x == p
x[0] = 0; // ok, originally caused false pos.
return 0;
|