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]

[BUG REPORT + PATCH] -Wpadded on powerpc


If you take the simple program:

int main(void)
{
  return (0);
}

and compile it using a cross gcc compiler targeting powerpc-elf-eabi
with -Wpadded, you'll get the warning:

<built-in>:0: warning: padding struct to align `overflow_arg_area'

.

This bug is present in 3.2.3 and on the trunk; I would guess (but
didn't verify) that it's also present in 3.3.

Investigating, the problem is in config/rs6000/rs6000.c, function
rs6000_build_va_list.  It's building a structure (__va_list_tag) that
looks like:

    unsigned char gpr;
    unsigned char fpr;

    ==> 2 bytes of padding <==

    void *overflow_arg_area;
    void *reg_save_area;

Since backwards compatability is an issue and it's not very useful to
warn about padding in this structure that the compiler is generating
on the user's behalf (regardless of whether the user has a variable
argument function or not), I think that the only two real solutions
are to either (1) teach gcc to not complain about padding when it is
dealing with an internally created structure or to (2) add a member
that occupies the 2 bytes of padding.  Here's a patch for the latter
solution (against the trunk)

2003-05-21  David Taylor  <dtaylor@emc.com>

	* config/rs6000/rs6000.c (rs6000_build_va_list): Give the two
	bytes of padding in the __va_list_tag structure a name (reserved)
	so that -Wpadded won't warn on *EVERY* user file.

Index: gcc/config/rs6000/rs6000.c
===================================================================
RCS file: /cvs/uberbaum/gcc/config/rs6000/rs6000.c,v
retrieving revision 1.471
diff -c -r1.471 rs6000.c
*** gcc/config/rs6000/rs6000.c	5 May 2003 19:33:48 -0000	1.471
--- gcc/config/rs6000/rs6000.c	19 May 2003 18:51:15 -0000
***************
*** 3848,3854 ****
  tree
  rs6000_build_va_list ()
  {
!   tree f_gpr, f_fpr, f_ovf, f_sav, record, type_decl;
  
    /* For AIX, prefer 'char *' because that's what the system
       header files like.  */
--- 3848,3854 ----
  tree
  rs6000_build_va_list ()
  {
!   tree f_gpr, f_fpr, f_res, f_ovf, f_sav, record, type_decl;
  
    /* For AIX, prefer 'char *' because that's what the system
       header files like.  */
***************
*** 3862,3867 ****
--- 3862,3869 ----
  		      unsigned_char_type_node);
    f_fpr = build_decl (FIELD_DECL, get_identifier ("fpr"), 
  		      unsigned_char_type_node);
+   f_res = build_decl (FIELD_DECL, get_identifier ("reserved"),
+ 		      short_unsigned_type_node);
    f_ovf = build_decl (FIELD_DECL, get_identifier ("overflow_arg_area"),
  		      ptr_type_node);
    f_sav = build_decl (FIELD_DECL, get_identifier ("reg_save_area"),
***************
*** 3869,3874 ****
--- 3871,3877 ----
  
    DECL_FIELD_CONTEXT (f_gpr) = record;
    DECL_FIELD_CONTEXT (f_fpr) = record;
+   DECL_FIELD_CONTEXT (f_res) = record;
    DECL_FIELD_CONTEXT (f_ovf) = record;
    DECL_FIELD_CONTEXT (f_sav) = record;
  
***************
*** 3876,3882 ****
    TYPE_NAME (record) = type_decl;
    TYPE_FIELDS (record) = f_gpr;
    TREE_CHAIN (f_gpr) = f_fpr;
!   TREE_CHAIN (f_fpr) = f_ovf;
    TREE_CHAIN (f_ovf) = f_sav;
  
    layout_type (record);
--- 3879,3886 ----
    TYPE_NAME (record) = type_decl;
    TYPE_FIELDS (record) = f_gpr;
    TREE_CHAIN (f_gpr) = f_fpr;
!   TREE_CHAIN (f_fpr) = f_res;
!   TREE_CHAIN (f_res) = f_ovf;
    TREE_CHAIN (f_ovf) = f_sav;
  
    layout_type (record);


Built and tested both on powerpc-unknown-linux-gnu native and on
i686-pc-linux-gnu x powerpc-elf-eabi.

David
--
David Taylor
dtaylor@emc.com, taylor@candd.org


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]