This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
2004-07-07 Jan Beulich <jbeulich@novell.com> PR c/7054 * tree.h (initial_max_fld_align): Declare * stor-layout.c (initial_max_fld_align): Define and initialize. (maximum_field_alignment): Initialize to the same value. * common.opt: Add -fpack-struct= variant of switch. * opts.c: Handle -fpack-struct= variant of switch. * c-pragma.c: Change #pragma pack() handling so that is becomes compatible to other compilers: accept individual 'push' argument, make final pop restore (command line) default, correct interaction of push/pop and sole specification of a new alignment (so that the sequence #pragma pack(push) - #pragma pack(<n>) becomes identical to #pragma pack(push, <n>). * testsuite/gcc.dg/pack-test-2.c: Adjust to permit and check #pragma pack(push). --- /home/jbeulich/src/gcc/mainline/2004-07-05.10.09/gcc/c-pragma.c 2004-07-02 15:13:15.000000000 +0200 +++ 2004-07-05.10.09/gcc/c-pragma.c 2004-07-06 08:44:38.943513912 +0200 @@ -42,7 +42,6 @@ typedef struct align_stack GTY(()) { int alignment; - unsigned int num_pushes; tree id; struct align_stack * prev; } align_stack; @@ -59,8 +58,9 @@ happens, we restore the value to this, not to a value of 0 for maximum_field_alignment. Value is in bits. */ static int default_alignment; -#define SET_GLOBAL_ALIGNMENT(ALIGN) \ - (default_alignment = maximum_field_alignment = (ALIGN)) +#define SET_GLOBAL_ALIGNMENT(ALIGN) (maximum_field_alignment = *(alignment_stack == NULL \ + ? &default_alignment \ + : &alignment_stack->alignment) = (ALIGN)) static void push_alignment (int, tree); static void pop_alignment (tree); @@ -69,31 +69,23 @@ static void push_alignment (int alignment, tree id) { - if (alignment_stack == NULL - || alignment_stack->alignment != alignment - || id != NULL_TREE) - { - align_stack * entry; - - entry = ggc_alloc (sizeof (* entry)); - - entry->alignment = alignment; - entry->num_pushes = 1; - entry->id = id; - entry->prev = alignment_stack; - - /* The current value of maximum_field_alignment is not necessarily - 0 since there may be a #pragma pack(<n>) in effect; remember it - so that we can restore it after the final #pragma pop(). */ - if (alignment_stack == NULL) - default_alignment = maximum_field_alignment; - - alignment_stack = entry; + align_stack * entry; - maximum_field_alignment = alignment; - } - else - alignment_stack->num_pushes ++; + entry = ggc_alloc (sizeof (* entry)); + + entry->alignment = alignment; + entry->id = id; + entry->prev = alignment_stack; + + /* The current value of maximum_field_alignment is not necessarily + 0 since there may be a #pragma pack(<n>) in effect; remember it + so that we can restore it after the final #pragma pop(). */ + if (alignment_stack == NULL) + default_alignment = maximum_field_alignment; + + alignment_stack = entry; + + maximum_field_alignment = alignment; } /* Undo a push of an alignment onto the stack. */ @@ -103,12 +95,7 @@ align_stack * entry; if (alignment_stack == NULL) - { - warning ("\ -#pragma pack (pop) encountered without matching #pragma pack (push, <n>)" - ); - return; - } + GCC_BAD("#pragma pack (pop) encountered without matching #pragma pack (push)"); /* If we got an identifier, strip away everything above the target entry so that the next step will restore the state just below it. */ @@ -117,27 +104,20 @@ for (entry = alignment_stack; entry; entry = entry->prev) if (entry->id == id) { - entry->num_pushes = 1; alignment_stack = entry; break; } if (entry == NULL) warning ("\ -#pragma pack(pop, %s) encountered without matching #pragma pack(push, %s, <n>)" +#pragma pack(pop, %s) encountered without matching #pragma pack(push, %s)" , IDENTIFIER_POINTER (id), IDENTIFIER_POINTER (id)); } - if (-- alignment_stack->num_pushes == 0) - { - entry = alignment_stack->prev; + entry = alignment_stack->prev; - if (entry == NULL) - maximum_field_alignment = default_alignment; - else - maximum_field_alignment = entry->alignment; + maximum_field_alignment = entry ? entry->alignment : default_alignment; - alignment_stack = entry; - } + alignment_stack = entry; } #else /* not HANDLE_PRAGMA_PACK_PUSH_POP */ #define SET_GLOBAL_ALIGNMENT(ALIGN) (maximum_field_alignment = (ALIGN)) @@ -150,7 +130,9 @@ /* #pragma pack () #pragma pack (N) + #pragma pack (push) #pragma pack (push, N) + #pragma pack (push, ID) #pragma pack (push, ID, N) #pragma pack (pop) #pragma pack (pop, ID) */ @@ -169,7 +151,7 @@ if (token == CPP_CLOSE_PAREN) { action = set; - align = 0; + align = initial_max_fld_align; } else if (token == CPP_NUMBER) { @@ -180,8 +162,8 @@ } else if (token == CPP_NAME) { -#define GCC_BAD_ACTION do { if (action == push) \ - GCC_BAD ("malformed '#pragma pack(push[, id], <n>)' - ignored"); \ +#define GCC_BAD_ACTION do { if (action != pop) \ + GCC_BAD ("malformed '#pragma pack(push[, id][, <n>])' - ignored"); \ else \ GCC_BAD ("malformed '#pragma pack(pop[, id])' - ignored"); \ } while (0) @@ -194,31 +176,21 @@ else GCC_BAD2 ("unknown action '%s' for '#pragma pack' - ignored", op); - token = c_lex (&x); - if (token != CPP_COMMA && action == push) - GCC_BAD_ACTION; - - if (token == CPP_COMMA) + while ((token = c_lex (&x)) == CPP_COMMA) { token = c_lex (&x); - if (token == CPP_NAME) + if (token == CPP_NAME && id == 0) { id = x; - if (action == push && c_lex (&x) != CPP_COMMA) - GCC_BAD_ACTION; - token = c_lex (&x); } - - if (action == push) + else if (token == CPP_NUMBER && action == push && align == -1) { - if (token == CPP_NUMBER) - { - align = TREE_INT_CST_LOW (x); - token = c_lex (&x); - } - else - GCC_BAD_ACTION; + align = TREE_INT_CST_LOW (x); + if (align == -1) + action = set; } + else + GCC_BAD_ACTION; } if (token != CPP_CLOSE_PAREN) @@ -231,6 +203,9 @@ if (c_lex (&x) != CPP_EOF) warning ("junk at end of '#pragma pack'"); + if (flag_pack_struct) + GCC_BAD ("#pragma pack has no effect with -fpack-struct - ignored"); + if (action != pop) switch (align) { @@ -242,6 +217,12 @@ case 16: align *= BITS_PER_UNIT; break; + case -1: + if (action == push) + { + align = maximum_field_alignment; + break; + } default: GCC_BAD2 ("alignment must be a small power of two, not %d", align); } --- /home/jbeulich/src/gcc/mainline/2004-07-05.10.09/gcc/common.opt 2004-07-02 15:13:19.000000000 +0200 +++ 2004-07-05.10.09/gcc/common.opt 2004-07-06 08:44:38.935515128 +0200 @@ -527,6 +527,10 @@ Common Report Var(flag_pack_struct) Pack structure members together without holes +fpack-struct= +Common RejectNegative Joined UInteger +-fpack-struct=<number> Set initial maximum structure member alignment + fpcc-struct-return Common Report Var(flag_pcc_struct_return,1) VarExists Return small aggregates in memory, not registers --- /home/jbeulich/src/gcc/mainline/2004-07-05.10.09/gcc/opts.c 2004-07-02 15:13:53.000000000 +0200 +++ 2004-07-05.10.09/gcc/opts.c 2004-07-06 08:44:38.969509960 +0200 @@ -790,6 +790,13 @@ pp_set_line_maximum_length (global_dc->printer, value); break; + case OPT_fpack_struct_: + if (value <= 0 || (value & (value - 1)) || value > 16) + error("structure alignment must be a small power of two, not %d", value); + else + maximum_field_alignment = initial_max_fld_align = value * BITS_PER_UNIT; + break; + case OPT_fpeel_loops: flag_peel_loops_set = true; break; --- /home/jbeulich/src/gcc/mainline/2004-07-05.10.09/gcc/stor-layout.c 2004-07-05 09:18:04.000000000 +0200 +++ 2004-07-05.10.09/gcc/stor-layout.c 2004-07-06 08:44:38.986507376 +0200 @@ -48,7 +48,12 @@ /* If nonzero, this is an upper limit on alignment of structure fields. The value is measured in bits. */ -unsigned int maximum_field_alignment; +#ifndef DEFAULT_PACK_STRUCT +#define DEFAULT_PACK_STRUCT 0 +#endif +unsigned int maximum_field_alignment = DEFAULT_PACK_STRUCT * BITS_PER_UNIT; +/* ... and the original value of it, specified via -fpack-struct=<value>. */ +unsigned int initial_max_fld_align = DEFAULT_PACK_STRUCT * BITS_PER_UNIT; /* If nonzero, the alignment of a bitstring or (power-)set value, in bits. May be overridden by front-ends. */ --- /home/jbeulich/src/gcc/mainline/2004-07-05.10.09/gcc/testsuite/g++.dg/abi/vbase10.C 2004-01-08 04:32:11.000000000 +0100 +++ 2004-07-05.10.09/gcc/testsuite/g++.dg/abi/vbase10.C 2004-05-27 10:57:09.000000000 +0200 @@ -1,5 +1,5 @@ // { dg-do compile } -// { dg-options "-Wabi -fabi-version=1" } +// { dg-options "-Wabi -fabi-version=1 -fpack-struct=8" } // On ARM processors, the alignment of B will be 4 even though it // contains only a single "char". That would avoids the situation // that the warning below is designed to catch. We therefore --- /home/jbeulich/src/gcc/mainline/2004-07-05.10.09/gcc/testsuite/gcc.dg/Wpadded.c 2003-06-10 01:04:50.000000000 +0200 +++ 2004-07-05.10.09/gcc/testsuite/gcc.dg/Wpadded.c 2004-05-26 15:38:24.000000000 +0200 @@ -1,7 +1,7 @@ /* Source: EMC. */ /* { dg-do compile } */ -/* { dg-options "-Wpadded" } */ +/* { dg-options "-Wpadded -fpack-struct=8" } */ struct foo { char bar; --- /home/jbeulich/src/gcc/mainline/2004-07-05.10.09/gcc/testsuite/gcc.dg/c99-flex-array-4.c 2002-08-17 16:48:28.000000000 +0200 +++ 2004-07-05.10.09/gcc/testsuite/gcc.dg/c99-flex-array-4.c 2004-05-26 17:19:15.000000000 +0200 @@ -5,7 +5,7 @@ from Tony Finch <dot@dotat.at>, adapted to a testcase by Joseph Myers <jsm28@cam.ac.uk>. See also WG14 reflector messages 9571-3. */ /* { dg-do compile } */ -/* { dg-options "-std=iso9899:1999 -pedantic-errors" } */ +/* { dg-options "-std=iso9899:1999 -fpack-struct=8 -pedantic-errors" } */ #include <stddef.h> --- /home/jbeulich/src/gcc/mainline/2004-07-05.10.09/gcc/testsuite/gcc.dg/pack-test-2.c 2000-12-13 21:16:33.000000000 +0100 +++ 2004-07-05.10.09/gcc/testsuite/gcc.dg/pack-test-2.c 2004-05-18 16:17:53.000000000 +0200 @@ -3,9 +3,11 @@ /* { dg-do compile { target *-*-linux* *-*-cygwin* powerpc*-*-eabi* } } */ -#pragma pack(push) /* { dg-error "malformed" } */ #pragma pack(pop) /* { dg-error "without matching" } */ +#pragma pack(push) +#pragma pack(pop) /* reset */ + #pragma pack(push, foo, 1) #pragma pack(pop, foo, 1) /* { dg-error "malformed" } (/ #pragma pack(pop) /* reset */ --- /home/jbeulich/src/gcc/mainline/2004-07-05.10.09/gcc/tree.h 2004-07-05 09:18:05.000000000 +0200 +++ 2004-07-05.10.09/gcc/tree.h 2004-07-06 08:44:39.045498408 +0200 @@ -3026,8 +3026,10 @@ + (BITS_PER_UNIT > 8) + (BITS_PER_UNIT > 16) + (BITS_PER_UNIT > 32) \ + (BITS_PER_UNIT > 64) + (BITS_PER_UNIT > 128) + (BITS_PER_UNIT > 256)) -/* If nonzero, an upper limit on alignment of structure fields, in bits. */ +/* If nonzero, an upper limit on alignment of structure fields, in bits, */ extern unsigned int maximum_field_alignment; +/* and the original value of it, specified via -fpack-struct=<value>. */ +extern unsigned int initial_max_fld_align; /* If nonzero, the alignment of a bitstring or (power-)set value, in bits. */ extern unsigned int set_alignment;
Attachment:
gcc-mainline-pragma-pack.patch
Description: Binary data
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |