From: jason Date: Fri, 6 Nov 2009 03:33:17 +0000 (+0000) Subject: PR c++/7046 X-Git-Tag: upstream/4.9.2~32731 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0a52fc4a6faa7c7baa63ddb59ae2fc042cb9a8f9;p=platform%2Fupstream%2Flinaro-gcc.git PR c++/7046 * class.c (finish_struct): Store maximum_field_alignment in TYPE_PRECISION. * pt.c (instantiate_class_template): Set maximum_field_alignment. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@153959 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 0dfc57f..98cca71 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,10 @@ 2009-11-05 Jason Merrill + PR c++/7046 + * class.c (finish_struct): Store maximum_field_alignment in + TYPE_PRECISION. + * pt.c (instantiate_class_template): Set maximum_field_alignment. + PR c++/34870 * name-lookup.c (arg_assoc_class): Call complete_type. * pt.c (instantiate_class_template): Call uses_template_parms diff --git a/gcc/cp/class.c b/gcc/cp/class.c index dc4c6b3..4020144 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -5516,6 +5516,9 @@ finish_struct (tree t, tree attributes) if (DECL_PURE_VIRTUAL_P (x)) VEC_safe_push (tree, gc, CLASSTYPE_PURE_VIRTUALS (t), x); complete_vars (t); + + /* Remember current #pragma pack value. */ + TYPE_PRECISION (t) = maximum_field_alignment; } else finish_struct_1 (t); diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index d4556cd..75180ea 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -7352,6 +7352,7 @@ instantiate_class_template (tree type) tree typedecl; tree pbinfo; tree base_list; + unsigned int saved_maximum_field_alignment; if (type == error_mark_node) return error_mark_node; @@ -7412,6 +7413,9 @@ instantiate_class_template (tree type) push_deferring_access_checks (dk_no_deferred); push_to_top_level (); + /* Use #pragma pack from the template context. */ + saved_maximum_field_alignment = maximum_field_alignment; + maximum_field_alignment = TYPE_PRECISION (pattern); SET_CLASSTYPE_INTERFACE_UNKNOWN (type); @@ -7827,6 +7831,7 @@ instantiate_class_template (tree type) perform_typedefs_access_check (pattern, args); perform_deferred_access_checks (); pop_nested_class (); + maximum_field_alignment = saved_maximum_field_alignment; pop_from_top_level (); pop_deferring_access_checks (); pop_tinst_level (); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index eedfe22..6d1786a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2009-11-05 Jason Merrill + PR c++/7046 + * g++.dg/abi/pragma-pack1.C: New. + PR c++/34870 * g++.dg/lookup/koenig7.C: New. diff --git a/gcc/testsuite/g++.dg/abi/pragma-pack1.C b/gcc/testsuite/g++.dg/abi/pragma-pack1.C new file mode 100644 index 0000000..d90fc20 --- /dev/null +++ b/gcc/testsuite/g++.dg/abi/pragma-pack1.C @@ -0,0 +1,37 @@ +// PR c++/7046 + +extern "C" int printf (const char *, ...); + +#pragma pack(4) + +template +struct T +{ + char x1; /* Usually 3 padding bytes are added after x1 member. */ + int x2; +}; + +template +int f() +{ + struct A { char i1; int i2; }; + return sizeof (A); +} + +#pragma pack(1) +template struct T; /* T is instantiated here */ +template int f(); + +#pragma pack(4) +template struct T; /* T is instantiated here */ +template int f(); + +int main() +{ + printf("sizeof T = %d\n", sizeof(T)); + printf("sizeof T = %d\n", sizeof(T)); + printf("f() = %d\n", f()); + printf("f() = %d\n", f()); + return (sizeof(T) != sizeof(T) + || f() != f()); +}