[llvm-commits] [llvm-gcc-4.2] r58589 - in /llvm-gcc-4.2/trunk/gcc: c.opt cp/decl2.c

Bill Wendling isanbard at gmail.com
Sun Nov 2 18:04:09 PST 2008


Author: void
Date: Sun Nov  2 20:04:09 2008
New Revision: 58589

URL: http://llvm.org/viewvc/llvm-project?rev=58589&view=rev
Log:
Implement Wglobal-constructors. Warn about missing prototypes for C++.

Modified:
    llvm-gcc-4.2/trunk/gcc/c.opt
    llvm-gcc-4.2/trunk/gcc/cp/decl2.c

Modified: llvm-gcc-4.2/trunk/gcc/c.opt
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/c.opt?rev=58589&r1=58588&r2=58589&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/c.opt (original)
+++ llvm-gcc-4.2/trunk/gcc/c.opt Sun Nov  2 20:04:09 2008
@@ -238,7 +238,7 @@
 
 ; APPLE LOCAL begin default to Wformat-security 5764921
 Wformat-security
-C ObjC C++ ObjC++ Var(warn_format_security) Init(0)
+C ObjC C++ ObjC++ Var(warn_format_security) Init(1)
 Warn about possible security problems with format functions
 ; APPLE LOCAL end default to Wformat-security 5764921
 
@@ -261,6 +261,15 @@
 Warn about multicharacter constants containing exactly four characters
 ; APPLE LOCAL end -Wfour-char-constants
 
+; APPLE LOCAL begin Wglobal-constructors 6324584
+Wglobal-constructors
+C ObjC C++ ObjC++ Var(warn_global_constructors)
+Warn when global (namespace scope) objects require runtime
+construction or destruction or when functions that use attribute
+constructor or destructor are used.  This is useful to help maintain
+fast program startup and end times.
+; APPLE LOCAL end Wglobal-constructors 6324584
+
 Winit-self
 C ObjC C++ ObjC++ Var(warn_init_self)
 Warn about variables which are initialized to themselves
@@ -320,9 +329,11 @@
 C ObjC C++ ObjC++
 Warn about user-specified include directories that do not exist
 
+; APPLE LOCAL begin warn missing prototype 6261539
 Wmissing-prototypes
-C ObjC Var(warn_missing_prototypes)
+C ObjC C++ Objc++ Var(warn_missing_prototypes)
 Warn about global functions without prototypes
+; APPLE LOCAL end warn missing prototype 6261539
 
 ; APPLE LOCAL begin -Wmost
 Wmost

Modified: llvm-gcc-4.2/trunk/gcc/cp/decl2.c
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/cp/decl2.c?rev=58589&r1=58588&r2=58589&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/cp/decl2.c (original)
+++ llvm-gcc-4.2/trunk/gcc/cp/decl2.c Sun Nov  2 20:04:09 2008
@@ -2781,6 +2781,20 @@
 }
 /* APPLE LOCAL end elide global inits 3814991 */
 
+/* APPLE LOCAL begin Wglobal-constructors 6324584 */
+static void
+warn_init (tree decl)
+{
+  warning (OPT_Wglobal_constructors, "%J%qD requires global construction", decl, decl);
+}
+
+static void
+warn_deinit (tree decl)
+{
+  warning (OPT_Wglobal_constructors, "%J%qD requires global destruction", decl, decl);
+}
+/* APPLE LOCAL end Wglobal-constructors 6324584 */
+
 /* Set up to handle the initialization or destruction of DECL.  If
    INITP is nonzero, we are initializing the variable.  Otherwise, we
    are destroying it.  */
@@ -2839,9 +2853,17 @@
       /* APPLE LOCAL begin elide global inits 5642351 */
       /* We can't avoid running the guard code.  */
       if (initp)
-	pi->initializations_p = 1;
+	{
+	  pi->initializations_p = 1;
+	  /* APPLE LOCAL Wglobal-constructors 6324584 */
+	  warn_init (decl);
+	}
       else
-	pi->destructions_p = 1;
+	{
+	  pi->destructions_p = 1;
+	  /* APPLE LOCAL Wglobal-constructors 6324584 */
+	  warn_deinit (decl);
+	}
       /* APPLE LOCAL end elide global inits 5642351 */
 
       /* When using __cxa_atexit, we just check the GUARD as we would
@@ -2894,6 +2916,8 @@
 	  if (!does_nothing_p (init))
 	    {
 	      pi->initializations_p = 1;
+	      /* APPLE LOCAL Wglobal-constructors 6324584 */
+	      if (!guard) warn_init (decl);
 	      finish_expr_stmt (init);
 	    }
 	}
@@ -2905,6 +2929,11 @@
 	/* APPLE LOCAL begin elide global inits 5642351 */
 	{
 	  pi->initializations_p = 1;
+	  /* APPLE LOCAL begin Wglobal-constructors 6324584 */
+	  if (!guard
+	      && !TYPE_HAS_TRIVIAL_DESTRUCTOR (TREE_TYPE (decl)))
+	    warn_deinit (decl);
+	  /* APPLE LOCAL end Wglobal-constructors 6324584 */
 	  finish_expr_stmt (register_dtor_fn (decl));
 	}
       /* APPLE LOCAL end global inits 5642351 */
@@ -2913,6 +2942,8 @@
     /* APPLE LOCAL begin elide global inits 5642351 */
     {
       pi->destructions_p = 1;
+      /* APPLE LOCAL Wglobal-constructors 6324584 */
+      if (!guard) warn_deinit (decl);
       finish_expr_stmt (build_cleanup (decl));
     }
   /* APPLE LOCAL end global inits 5642351 */
@@ -3124,6 +3155,10 @@
     {
       body = start_objects (function_key, priority);
       static_ctors = objc_generate_static_init_call (static_ctors);
+      /* APPLE LOCAL begin Wglobal-constructors 6324584 */
+      warning (OPT_Wglobal_constructors,
+	       "GNU Objective-C runtime requires global initialization");
+      /* APPLE LOCAL end Wglobal-constructors 6324584 */
     }
 
   /* Call the static storage duration function with appropriate
@@ -3159,6 +3194,13 @@
 	{
 	  fndecl = TREE_VALUE (fns);
 
+	  /* APPLE LOCAL begin Wglobal-constructors 6324584 */
+	  if (constructor_p)
+	    warn_init (fndecl);
+	  else
+	    warn_deinit (fndecl);
+	  /* APPLE LOCAL end Wglobal-constructors 6324584 */
+
 	  /* Calls to pure/const functions will expand to nothing.  */
 	  if (! (flags_from_decl_or_type (fndecl) & (ECF_CONST | ECF_PURE)))
 	    {





More information about the llvm-commits mailing list