[llvm-commits] CVS: llvm-test/SingleSource/UnitTests/Integer/cppfield2.cpp cppfield2.reference_output cppfield.cpp cppfield.reference_output

Reid Spencer reid at x10sys.com
Mon Jan 29 16:49:00 PST 2007



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

cppfield2.cpp added (r1.1)
cppfield2.reference_output added (r1.1)
cppfield.cpp updated: 1.4 -> 1.5
cppfield.reference_output updated: 1.1 -> 1.2
---
Log message:

Update the cppfield tests to be correct. bit-accurate inteers are not the
same as bit fields when used in a struct.


---
Diffs of the changes:  (+106 -20)

 cppfield.cpp               |   49 +++++++++++++++++++++--------------
 cppfield.reference_output  |    8 +++++
 cppfield2.cpp              |   62 +++++++++++++++++++++++++++++++++++++++++++++
 cppfield2.reference_output |    7 +++++
 4 files changed, 106 insertions(+), 20 deletions(-)


Index: llvm-test/SingleSource/UnitTests/Integer/cppfield2.cpp
diff -c /dev/null llvm-test/SingleSource/UnitTests/Integer/cppfield2.cpp:1.1
*** /dev/null	Mon Jan 29 18:48:54 2007
--- llvm-test/SingleSource/UnitTests/Integer/cppfield2.cpp	Mon Jan 29 18:48:44 2007
***************
*** 0 ****
--- 1,62 ----
+ //===-- cppfield.cpp - Test C++ Fields With Bit Accurate Types ------------===//
+ //
+ // This file was developed by Guoling Han and is distributed under the 
+ // University of Illinois Open Source License. See LICENSE.TXT for details.
+ //
+ //===----------------------------------------------------------------------===//
+ // This is a test for conversion between different int types.
+ //
+ //===----------------------------------------------------------------------===//
+ 
+ 
+ #include <stdio.h>
+ 
+ typedef unsigned char __attribute__ ((bitwidth(7))) int7;
+ typedef unsigned int __attribute__ ((bitwidth(17))) int17;
+ typedef unsigned int __attribute__ ((bitwidth(32))) int32;
+ typedef unsigned int __attribute__ ((bitwidth(8))) int8;
+ 
+ class bitFieldStruct {
+   public:
+   int i;
+   unsigned char c:7;
+   int s:17;
+   char c2;
+ };
+ 
+ class bitAccurateStruct {
+   public:
+   int32 i;
+   int7 c : 7;
+   int17 s : 17;
+   int8 c2;
+ };
+ 
+ int main()
+ {
+   printf("sizeof(bitFieldStruct) == %d\n", sizeof(bitFieldStruct));
+   printf("sizeof(bitAccurateStruct) == %d\n", sizeof(bitAccurateStruct));
+ 
+   if (sizeof(bitAccurateStruct) != 2 * sizeof(int))
+     printf("bitAccurrateStruct should be %d but is %d \n", 
+             2 * sizeof(int), sizeof(bitAccurateStruct));
+ 
+   if (sizeof(bitFieldStruct) != 2 * sizeof(int))
+     printf("bitFieldStruct should be %d but is %d \n", 
+             2 * sizeof(int), sizeof(bitAccurateStruct));
+ 
+   bitFieldStruct x;
+   bitAccurateStruct y;
+ 
+   char* yip = (char*) &y.i;
+   char* yc2p = (char*) &y.c2;
+   printf("Offset bitAccurateStruct.i = %d\n", yip - yip);
+   printf("Offset bitAccurateStruct.c2 = %d\n", yc2p - yip);
+   
+   char* xip = (char*) &x.i;
+   char* xc2p = (char*) &x.c2;
+   printf("Offset bitFieldStruct.i = %d\n", xip - xip);
+   printf("Offset bitFieldStruct.c2 = %d\n", xc2p - xip);
+ 
+   return 0;
+ }


Index: llvm-test/SingleSource/UnitTests/Integer/cppfield2.reference_output
diff -c /dev/null llvm-test/SingleSource/UnitTests/Integer/cppfield2.reference_output:1.1
*** /dev/null	Mon Jan 29 18:49:00 2007
--- llvm-test/SingleSource/UnitTests/Integer/cppfield2.reference_output	Mon Jan 29 18:48:44 2007
***************
*** 0 ****
--- 1,7 ----
+ sizeof(bitFieldStruct) == 8
+ sizeof(bitAccurateStruct) == 8
+ Offset bitAccurateStruct.i = 0
+ Offset bitAccurateStruct.c2 = 7
+ Offset bitFieldStruct.i = 0
+ Offset bitFieldStruct.c2 = 7
+ exit 0


Index: llvm-test/SingleSource/UnitTests/Integer/cppfield.cpp
diff -u llvm-test/SingleSource/UnitTests/Integer/cppfield.cpp:1.4 llvm-test/SingleSource/UnitTests/Integer/cppfield.cpp:1.5
--- llvm-test/SingleSource/UnitTests/Integer/cppfield.cpp:1.4	Mon Jan 22 18:17:21 2007
+++ llvm-test/SingleSource/UnitTests/Integer/cppfield.cpp	Mon Jan 29 18:48:44 2007
@@ -11,12 +11,12 @@
 
 #include <stdio.h>
 
-typedef unsigned int __attribute__ ((bitwidth(7))) int7;
+typedef unsigned char __attribute__ ((bitwidth(7))) int7;
 typedef unsigned int __attribute__ ((bitwidth(17))) int17;
 typedef unsigned int __attribute__ ((bitwidth(32))) int32;
 typedef unsigned int __attribute__ ((bitwidth(8))) int8;
 
-class myStruct{
+class bitFieldStruct {
   public:
   int i;
   unsigned char c:7;
@@ -24,7 +24,7 @@
   char c2;
 };
 
-class myStruct2{
+class bitAccurateStruct {
   public:
   int32 i;
   int7 c;
@@ -34,24 +34,33 @@
 
 int main()
 {
-  myStruct x;
-  myStruct2 y;
+  printf("sizeof(bitFieldStruct) == %d\n", sizeof(bitFieldStruct));
+  printf("sizeof(bitAccurateStruct) == %d\n", sizeof(bitAccurateStruct));
 
-  char* ptrc, *ptrc1, *ptrc2, *ptrc3;
-  unsigned int offset, offset1;
-
-  ptrc = (char*)&(x.i);
-  ptrc1 = (char*)&(x.c2);
-
-  ptrc2 = (char*)&(y.i);
-  ptrc3 = (char*)&(y.c2);
-
-  offset = ptrc1 - ptrc;
-  offset1 = ptrc3 - ptrc2;
-
-    
-  if(offset != offset1 || sizeof(myStruct) != sizeof(myStruct2))
-    printf("error\n");
+  if (sizeof(bitAccurateStruct) != 4 * sizeof(int))
+    printf("bitAccurrateStruct should be %d but is %d \n", 
+            4 * sizeof(int), sizeof(bitAccurateStruct));
+
+  if (sizeof(bitFieldStruct) != 2 * sizeof(int))
+    printf("bitFieldStruct should be %d but is %d \n", 
+            2 * sizeof(int), sizeof(bitAccurateStruct));
+
+  bitFieldStruct x;
+  bitAccurateStruct y;
+
+  char* yip = (char*) &y.i;
+  char* ycp = (char*) &y.c;
+  char* ysp = (char*) &y.s;
+  char* yc2p = (char*) &y.c2;
+  printf("Offset bitAccurateStruct.i = %d\n", yip - yip);
+  printf("Offset bitAccurateStruct.c = %d\n", ycp - yip);
+  printf("Offset bitAccurateStruct.s = %d\n", ysp - yip);
+  printf("Offset bitAccurateStruct.c2 = %d\n", yc2p - yip);
+  
+  char* xip = (char*) &x.i;
+  char* xc2p = (char*) &x.c2;
+  printf("Offset bitFieldStruct.i = %d\n", xip - xip);
+  printf("Offset bitFieldStruct.c2 = %d\n", xc2p - xip);
 
   return 0;
 }


Index: llvm-test/SingleSource/UnitTests/Integer/cppfield.reference_output
diff -u llvm-test/SingleSource/UnitTests/Integer/cppfield.reference_output:1.1 llvm-test/SingleSource/UnitTests/Integer/cppfield.reference_output:1.2
--- llvm-test/SingleSource/UnitTests/Integer/cppfield.reference_output:1.1	Thu Jan 18 20:22:46 2007
+++ llvm-test/SingleSource/UnitTests/Integer/cppfield.reference_output	Mon Jan 29 18:48:44 2007
@@ -1 +1,9 @@
+sizeof(bitFieldStruct) == 8
+sizeof(bitAccurateStruct) == 16
+Offset bitAccurateStruct.i = 0
+Offset bitAccurateStruct.c = 4
+Offset bitAccurateStruct.s = 8
+Offset bitAccurateStruct.c2 = 12
+Offset bitFieldStruct.i = 0
+Offset bitFieldStruct.c2 = 7
 exit 0






More information about the llvm-commits mailing list