[llvm-commits] CVS: llvm-test/SingleSource/UnitTests/Integer/arith.c field.c offset.reference_output union-struct.c union2.c union2.reference_output

Guoling Han han at autoesl.com
Wed Jan 24 12:39:59 PST 2007



Changes in directory llvm-test/SingleSource/UnitTests/Integer:

arith.c updated: 1.6 -> 1.7
field.c updated: 1.5 -> 1.6
offset.reference_output updated: 1.1 -> 1.2
union-struct.c updated: 1.6 -> 1.7
union2.c updated: 1.5 -> 1.6
union2.reference_output updated: 1.1 -> 1.2
---
Log message:

We changed the outputs and reference outputs for these programs. This is mainly because the memory layout for bit-accurate types. For a n bit int type, it will occupy m bits where m is the nearest large number of power of 2. 



---
Diffs of the changes:  (+39 -19)

 arith.c                 |    2 +-
 field.c                 |   28 ++++++++++++++++++----------
 offset.reference_output |    2 +-
 union-struct.c          |    2 +-
 union2.c                |   21 +++++++++++++++------
 union2.reference_output |    3 +++
 6 files changed, 39 insertions(+), 19 deletions(-)


Index: llvm-test/SingleSource/UnitTests/Integer/arith.c
diff -u llvm-test/SingleSource/UnitTests/Integer/arith.c:1.6 llvm-test/SingleSource/UnitTests/Integer/arith.c:1.7
--- llvm-test/SingleSource/UnitTests/Integer/arith.c:1.6	Mon Jan 22 18:17:21 2007
+++ llvm-test/SingleSource/UnitTests/Integer/arith.c	Wed Jan 24 14:39:44 2007
@@ -43,7 +43,7 @@
   l = j / k;
   temp = l;
   printf( "temp = %hd\n", temp);
-  j *= (-176);
+  j *= (-176); // after truncation, the value should be -384
   l = j / k;
   temp = l;
   printf( "temp = %hd\n", temp);


Index: llvm-test/SingleSource/UnitTests/Integer/field.c
diff -u llvm-test/SingleSource/UnitTests/Integer/field.c:1.5 llvm-test/SingleSource/UnitTests/Integer/field.c:1.6
--- llvm-test/SingleSource/UnitTests/Integer/field.c:1.5	Mon Jan 22 18:17:21 2007
+++ llvm-test/SingleSource/UnitTests/Integer/field.c	Wed Jan 24 14:39:44 2007
@@ -9,6 +9,8 @@
 // data layout of the field should be the same as the corresponding
 // struct using bit accurate types.
 //
+// Note: we assume that sizeof(x-bit int) = round up x to the most
+// nearest 2^n. 
 //===----------------------------------------------------------------------===//
 
 
@@ -24,9 +26,9 @@
 typedef char __attribute__ ((bitwidth(7))) char7;
 typedef short __attribute__ ((bitwidth(17))) short17;
 
-typedef struct myStruct{int i; unsigned char c:7; int s:17; char c2;} myStruct;
+typedef struct myStruct{int i; char c:7; int s:17; char c2;} myStruct;
 
-typedef struct myStruct2{int32 i; int7 c;  int17 s; int8 c2;} myStruct2;
+typedef struct myStruct2{int32 i;  int17 s; int7 c; int8 c2;} myStruct2;
 
 int main()
 {
@@ -36,20 +38,26 @@
   void* ptr, *ptr1, *ptr2, *ptr3;
   unsigned int offset, offset1;
 
-  ptr = &(x.i);
-  ptr1 = &(x.c2);
+  // ptr = &(x.i);
+  // ptr1 = &(x.c2);
 
   ptr2 = &(y.i);
   ptr3 = &(y.c2);
 
-  offset = ptr1 - ptr;
+  //offset = ptr1 - ptr;
   offset1 = ptr3 - ptr2;
     
-  if(offset != offset1) 
-    printf("error: offset=%x, offset1=%x\n", offset, offset1);
-  if(sizeof(myStruct) != sizeof(myStruct2))
-    printf("error2: sizeof myStruct = %d, sizeof myStruct2 = %d\n",
-           sizeof(myStruct), sizeof(myStruct2));
+  if(offset1 != 2*sizeof(int) + sizeof(char))
+    printf("error:  offset1=%x\n", offset1);
+
+  x.c = -1;
+  y.c = -1;
+  if(x.c != y.c)
+    printf("error: x.c = %x, y.c = %x\n", x.c, y.c);
+  
+  //if(sizeof(myStruct) != sizeof(myStruct2))
+  //  printf("error2: sizeof myStruct = %d, sizeof myStruct2 = %d\n",
+  //         sizeof(myStruct), sizeof(myStruct2));
 
   return 0;
 }


Index: llvm-test/SingleSource/UnitTests/Integer/offset.reference_output
diff -u llvm-test/SingleSource/UnitTests/Integer/offset.reference_output:1.1 llvm-test/SingleSource/UnitTests/Integer/offset.reference_output:1.2
--- llvm-test/SingleSource/UnitTests/Integer/offset.reference_output:1.1	Thu Jan 18 20:22:46 2007
+++ llvm-test/SingleSource/UnitTests/Integer/offset.reference_output	Wed Jan 24 14:39:44 2007
@@ -1,2 +1,2 @@
-5
+8
 exit 0


Index: llvm-test/SingleSource/UnitTests/Integer/union-struct.c
diff -u llvm-test/SingleSource/UnitTests/Integer/union-struct.c:1.6 llvm-test/SingleSource/UnitTests/Integer/union-struct.c:1.7
--- llvm-test/SingleSource/UnitTests/Integer/union-struct.c:1.6	Mon Jan 22 18:17:21 2007
+++ llvm-test/SingleSource/UnitTests/Integer/union-struct.c	Wed Jan 24 14:39:44 2007
@@ -27,7 +27,7 @@
 
 int main()
 {
-  if( sizeof(struct Blend_Map_Entry) == 5 * sizeof(int) )
+  if( sizeof(struct Blend_Map_Entry) != 5 * sizeof(int) )
     printf("error: %d\n", sizeof(struct Blend_Map_Entry));
   return 0;
 }


Index: llvm-test/SingleSource/UnitTests/Integer/union2.c
diff -u llvm-test/SingleSource/UnitTests/Integer/union2.c:1.5 llvm-test/SingleSource/UnitTests/Integer/union2.c:1.6
--- llvm-test/SingleSource/UnitTests/Integer/union2.c:1.5	Mon Jan 22 18:17:21 2007
+++ llvm-test/SingleSource/UnitTests/Integer/union2.c	Wed Jan 24 14:39:44 2007
@@ -8,6 +8,10 @@
 // This is a test for union type. By assigning values to different
 // fields, we can check whether the assignment is correctly performed.
 //
+// Note: In the current implementation, a 9-bit data will also occupy
+// 2 bytes. So for this example, storing value to the 9-bit field will
+// change the two bytes of the memory.
+//
 //===----------------------------------------------------------------------===//
 
 
@@ -21,12 +25,17 @@
 myStruct test(myUnion u)
 {
   myStruct x;
-
-  u.i31 = 0;
-  u.i = 0xffff;
-  int9* ptr = &(u.i9);
-  *ptr= 0x00;
-
+  int9* ptr;
+  
+  u.i31 = -1;
+  u.i = 0x0;
+  ptr = &(u.i9);
+  *ptr= -1;
+
+  printf("u.i = %hd\n", u.i);
+  printf("u.i9 = %hd\n", u.i9);
+  printf("u.i31 = %d\n", u.i31);
+ 
   x.ptr = ptr;
   x.i = u.i;
 


Index: llvm-test/SingleSource/UnitTests/Integer/union2.reference_output
diff -u llvm-test/SingleSource/UnitTests/Integer/union2.reference_output:1.1 llvm-test/SingleSource/UnitTests/Integer/union2.reference_output:1.2
--- llvm-test/SingleSource/UnitTests/Integer/union2.reference_output:1.1	Thu Jan 18 20:22:46 2007
+++ llvm-test/SingleSource/UnitTests/Integer/union2.reference_output	Wed Jan 24 14:39:44 2007
@@ -1 +1,4 @@
+u.i = 511
+u.i9 = -1
+u.i31 = -65025
 exit 0






More information about the llvm-commits mailing list