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]

don't warn about uninitialized anonymous bitfields


https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=229459

When compiling code such as:

// gcc -O2 -Wall -S uninit-anon-bitfield.c

struct foo {
  unsigned int a:16;
  unsigned int b:11;
  unsigned int :5;
};

extern struct foo bar;

void foo(int a, int b)
{
  struct foo tmp;

  tmp.a = a;
  tmp.b = b;

  bar = tmp;
}

GCC scalarizes tmp and then issues a warning about the use of the
uninitialized annoymous bitfield.

This patch silences the warning.  Bootstrapped and regtested on
x86_64-linux-gnu.   Ok to install?

:ADDPATCH tree-sra:

for  gcc/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	* c-decl.c (grokdeclarator): Disable warnings for anonymous
	bitfields.
	* tree-sra.c (instantiate_element): Propagate disabled warnings
	from the element itself to the created variable.

for  gcc/cp/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	* decl.c (grokdeclarator): Disable warnings for anonymous
	bitfields.

Index: gcc/c-decl.c
===================================================================
--- gcc/c-decl.c.orig	2007-02-27 01:59:21.000000000 -0300
+++ gcc/c-decl.c	2007-03-05 04:22:21.000000000 -0300
@@ -1,6 +1,6 @@
 /* Process declarations and variables for C compiler.
    Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-   2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+   2001, 2002, 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -4760,6 +4760,8 @@ grokdeclarator (const struct c_declarato
 	type = c_build_qualified_type (type, type_quals);
 	decl = build_decl (FIELD_DECL, declarator->u.id, type);
 	DECL_NONADDRESSABLE_P (decl) = bitfield;
+	if (bitfield && !declarator->u.id)
+	  TREE_NO_WARNING (decl) = 1;
 
 	if (size_varies)
 	  C_DECL_VARIABLE_SIZE (decl) = 1;
Index: gcc/cp/decl.c
===================================================================
--- gcc/cp/decl.c.orig	2007-03-03 03:53:47.000000000 -0300
+++ gcc/cp/decl.c	2007-03-05 04:24:34.000000000 -0300
@@ -1,6 +1,6 @@
 /* Process declarations and variables for C++ compiler.
    Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-   2001, 2002, 2003, 2004, 2005, 2006  Free Software Foundation, Inc.
+   2001, 2002, 2003, 2004, 2005, 2006, 2007  Free Software Foundation, Inc.
    Contributed by Michael Tiemann (tiemann@cygnus.com)
 
 This file is part of GCC.
@@ -8539,6 +8539,9 @@ grokdeclarator (const cp_declarator *dec
 	      {
 		decl = build_decl (FIELD_DECL, unqualified_id, type);
 		DECL_NONADDRESSABLE_P (decl) = bitfield;
+		if (bitfield && !unqualified_id)
+		  TREE_NO_WARNING (decl) = 1;
+
 		if (storage_class == sc_mutable)
 		  {
 		    DECL_MUTABLE_P (decl) = 1;
Index: gcc/tree-sra.c
===================================================================
--- gcc/tree-sra.c.orig	2007-03-03 03:53:50.000000000 -0300
+++ gcc/tree-sra.c	2007-03-05 04:17:47.000000000 -0300
@@ -1240,7 +1240,8 @@ instantiate_element (struct sra_elt *elt
       DECL_DEBUG_EXPR_IS_FROM (var) = 1;
       
       DECL_IGNORED_P (var) = 0;
-      TREE_NO_WARNING (var) = TREE_NO_WARNING (base);
+      TREE_NO_WARNING (var) = TREE_NO_WARNING (base)
+	|| (elt->element ? TREE_NO_WARNING (elt->element) : false);
     }
   else
     {
-- 
Alexandre Oliva         http://www.lsd.ic.unicamp.br/~oliva/
FSF Latin America Board Member         http://www.fsfla.org/
Red Hat Compiler Engineer   aoliva@{redhat.com, gcc.gnu.org}
Free Software Evangelist  oliva@{lsd.ic.unicamp.br, gnu.org}

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