diff options
author | Nicola Pero <nicola.pero@meta-innovation.com> | 2011-06-05 11:10:31 +0000 |
---|---|---|
committer | Nicola Pero <nicola@gcc.gnu.org> | 2011-06-05 11:10:31 +0000 |
commit | b74b7579245cc7724490f6038908858963ac3104 (patch) | |
tree | 9e46a0736bc9ea59a5d3fe23daa93cbda170a39f | |
parent | 586e6d03db7c8353202fca41a9f47b9b99ecaefc (diff) | |
download | gcc-b74b7579245cc7724490f6038908858963ac3104.zip gcc-b74b7579245cc7724490f6038908858963ac3104.tar.gz gcc-b74b7579245cc7724490f6038908858963ac3104.tar.bz2 |
In gcc/testsuite/: 2011-06-05 Nicola Pero <nicola.pero@meta-innovation.com>
In gcc/testsuite/:
2011-06-05 Nicola Pero <nicola.pero@meta-innovation.com>
* objc.dg/gnu-api-2-objc.m: Fixed testcase. Use log2 of the
alignment, not the alignment, when calling class_addIvar(). Add
an 'isa' instance variable to the test root class.
* obj-c++.dg/gnu-api-2-objc.mm: Likewise.
From-SVN: r174656
-rw-r--r-- | gcc/testsuite/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/testsuite/obj-c++.dg/gnu-api-2-objc.mm | 24 | ||||
-rw-r--r-- | gcc/testsuite/objc.dg/gnu-api-2-objc.m | 24 |
3 files changed, 49 insertions, 6 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c4080ff..7194f87 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2011-06-05 Nicola Pero <nicola.pero@meta-innovation.com> + + * objc.dg/gnu-api-2-objc.m: Fixed testcase. Use log2 of the + alignment, not the alignment, when calling class_addIvar(). Add + an 'isa' instance variable to the test root class. + * obj-c++.dg/gnu-api-2-objc.mm: Likewise. + 2011-06-04 Jan Hubicka <jh@suse.cz> PR tree-optimization/48893 diff --git a/gcc/testsuite/obj-c++.dg/gnu-api-2-objc.mm b/gcc/testsuite/obj-c++.dg/gnu-api-2-objc.mm index 90da96a..ce70c5e 100644 --- a/gcc/testsuite/obj-c++.dg/gnu-api-2-objc.mm +++ b/gcc/testsuite/obj-c++.dg/gnu-api-2-objc.mm @@ -45,6 +45,23 @@ - (id) variable { return variable_ivar; } @end +/* Hack to calculate the log2 of a byte alignment. */ +unsigned char +log_2_of (unsigned int x) +{ + unsigned char result = 0; + + /* We count how many times we need to divide by 2 before we reach 1. + This algorithm is good enough for the small numbers (such as 8, + 16 or 64) that we have to deal with. */ + while (x > 1) + { + x = x / 2; + result++; + } + + return result; +} int main () { @@ -56,8 +73,9 @@ int main () Class new_class = objc_allocateClassPair (objc_getClass ("MyRootClass"), "MyNewSubClass", 0); /* A new root class would obviously need at least an 'isa' - instance variable. We don't add it so we never actually - instantiate an instance of the class, which wouldn't work. */ + instance variable. */ + class_addIvar (new_root_class, "isa", sizeof (Class), log_2_of (__alignof__ (Class)), + @encode (Class)); objc_registerClassPair (new_root_class); objc_registerClassPair (new_class); @@ -114,7 +132,7 @@ int main () /* Add a bit of everything to the class to exercise undoing all these changes. */ /* Instance variable. */ - class_addIvar (new_class, "my_variable", sizeof (float), __alignof__ (float), @encode (float)); + class_addIvar (new_class, "my_variable", sizeof (float), log_2_of (__alignof__ (float)), @encode (float)); /* Instance method. */ class_addMethod (new_class, @selector (setVariable:), method_getImplementation (method), diff --git a/gcc/testsuite/objc.dg/gnu-api-2-objc.m b/gcc/testsuite/objc.dg/gnu-api-2-objc.m index 59344ef..d1177d7 100644 --- a/gcc/testsuite/objc.dg/gnu-api-2-objc.m +++ b/gcc/testsuite/objc.dg/gnu-api-2-objc.m @@ -45,6 +45,23 @@ - (id) variable { return variable_ivar; } @end +/* Hack to calculate the log2 of a byte alignment. */ +unsigned char +log_2_of (unsigned int x) +{ + unsigned char result = 0; + + /* We count how many times we need to divide by 2 before we reach 1. + This algorithm is good enough for the small numbers (such as 8, + 16 or 64) that we have to deal with. */ + while (x > 1) + { + x = x / 2; + result++; + } + + return result; +} int main(int argc, void **args) { @@ -56,8 +73,9 @@ int main(int argc, void **args) Class new_class = objc_allocateClassPair (objc_getClass ("MyRootClass"), "MyNewSubClass", 0); /* A new root class would obviously need at least an 'isa' - instance variable. We don't add it so we never actually - instantiate an instance of the class, which wouldn't work. */ + instance variable. */ + class_addIvar (new_root_class, "isa", sizeof (Class), log_2_of (__alignof__ (Class)), + @encode (Class)); objc_registerClassPair (new_root_class); objc_registerClassPair (new_class); @@ -114,7 +132,7 @@ int main(int argc, void **args) /* Add a bit of everything to the class to exercise undoing all these changes. */ /* Instance variable. */ - class_addIvar (new_class, "my_variable", sizeof (float), __alignof__ (float), @encode (float)); + class_addIvar (new_class, "my_variable", sizeof (float), log_2_of (__alignof__ (float)), @encode (float)); /* Instance method. */ class_addMethod (new_class, @selector (setVariable:), method_getImplementation (method), |