Attachment 'new-wuninitialized.diff'

Download

   1 Index: gcc/flags.h
   2 ===================================================================
   3 --- gcc/flags.h	(revision 126606)
   4 +++ gcc/flags.h	(working copy)
   5 @@ -354,6 +354,15 @@
   6    WARN_STRICT_OVERFLOW_MAGNITUDE = 5
   7  };
   8 
   9 +/* Names for the different levels of -Wuninitialized. */
  10 +
  11 +enum warn_uninitialized_code
  12 +{
  13 +  WARN_UNINITIALIZED_PRECISE = 1,
  14 +
  15 +  WARN_UNINITIALIZED_VERBOSE = 2
  16 +};
  17 +
  18  /* Whether to emit an overflow warning whose code is C.  */
  19  #define issue_strict_overflow_warning(c) (warn_strict_overflow >= (int) (c))
  20 
  21 Index: gcc/opts.c
  22 ===================================================================
  23 --- gcc/opts.c	(revision 126606)
  24 +++ gcc/opts.c	(working copy)
  25 @@ -1379,2 +1372,2 @@
  26        set_Wunused (value);
  27        break;
  28 
  29 +    case OPT_Wuninitialized:
  30 +      warn_uninitialized = value ? WARN_UNINITIALIZED_PRECISE : 0;
  31 +      break;
  32 +
  33 +    case OPT_Wuninitialized_:
  34 +      if (!strcmp (arg, "precise"))
  35 +        warn_uninitialized = WARN_UNINITIALIZED_PRECISE;
  36 +      else if (!strcmp (arg, "verbose"))
  37 +        warn_uninitialized = WARN_UNINITIALIZED_VERBOSE;
  38 +      else
  39 +	return 0;
  40 +      break;
  41 +
  42      case OPT_aux_info:
  43      case OPT_aux_info_:
  44        aux_info_file_name = arg;
  45 Index: gcc/common.opt
  46 ===================================================================
  47 --- gcc/common.opt	(revision 126606)
  48 +++ gcc/common.opt	(working copy)
  49 @@ -186,2 +186,2 @@
  50  Common Var(warn_uninitialized) Warning
  51  Warn about uninitialized automatic variables
  52 
  53 +Wuninitialized=
  54 +Common Joined RejectNegative Warning
  55 +-Wuninitialized=[precise|verbose] Warn about uninitialized automatic variables
  56 +
  57  Wunreachable-code
  58  Common Var(warn_notreached) Warning
  59  Warn about code that will never be executed
  60 Index: gcc/tree-ssa.c
  61 ===================================================================
  62 --- gcc/tree-ssa.c	(revision 126606)
  63 +++ gcc/tree-ssa.c	(working copy)
  64 @@ -1205,7 +1205,7 @@
  65  /* Emit a warning for T, an SSA_NAME, being uninitialized.  The exact
  66     warning text is in MSGID and LOCUS may contain a location or be null.  */
  67  
  68 -static void
  69 +void
  70  warn_uninit (tree t, const char *gmsgid, void *data)
  71  {
  72    tree var = SSA_NAME_VAR (t);
  73 @@ -1302,8 +1311,11 @@
  74      }
  75  }
  76  
  77 -static unsigned int
  78 -execute_early_warn_uninitialized (void)
  79 +/* Search through all the statements and warn if any use of an
  80 +   uninitialized variable is found.  */
  81 +
  82 +static void
  83 +warn_uninitialized_stmts (void)
  84  {
  85    block_stmt_iterator bsi;
  86    basic_block bb;
  87 @@ -1315,23 +1327,72 @@
  88  	walk_tree (bsi_stmt_ptr (bsi), warn_uninitialized_var,
  89  		   context, NULL);
  90        }
  91 +}
  92 +
  93 +/* Search through all the PHIs any which may reference an 
  94 +   uninitialized variable.  Warn if any such PHI is found.  */
  95 +static void
  96 +warn_uninitialized_phis (void)
  97 +{
  98 +  basic_block bb;
  99 +  tree phi;
 100 +
 101 +  FOR_EACH_BB (bb)
 102 +    for (phi = phi_nodes (bb); phi; phi = PHI_CHAIN (phi))
 103 +      warn_uninitialized_phi (phi);
 104 +}
 105 +
 106 +/* This pass emits warnings for uninitialized variables before any
 107 +   optimization occurs.
 108 +
 109 +   We always identify and warn for variables which can be trivially
 110 +   determined are uninitialized at one or more uses.
 111 +
 112 +   We conditionally warn for "may be" uninitialized variables at this
 113 +   time as well (dependent on user flags). 
 114 +
 115 +   By emitting "may be" warnings before optimization we can get warnings
 116 +   for uninitialized variables in which uses are optimized away or 
 117 +   unreachable.  However, we get more false positive "may be" uninitialized
 118 +   warnings and some "may be" uninitialized warnings which really should
 119 +   be "is" uninitialized warnings.  */
 120 +
 121 +static unsigned int
 122 +execute_early_warn_uninitialized (void)
 123 +{
 124 +  warn_uninitialized_stmts ();
 125 +
 126 +  /* If explicitly requested, look for "may be" uninitialized variables
 127 +     before optimizations as well.  */
 128 +  if (warn_uninitialized == WARN_UNINITIALIZED_VERBOSE)
 129 +    warn_uninitialized_phis ();
 130 +
 131    return 0;
 132  }
 133  
 134 +/* This pass emits warnings for uninitialized variables after 
 135 +   optimization has been performed.
 136 +
 137 +   By delaying warnings until after optimization we can turn more
 138 +   "may be" uninitialized warnings into "is" uninitialized warnings.
 139 +   We can also eliminate some false positive "may be" uninitialized
 140 +   warnings. 
 141 +
 142 +   This pass also emits warnings for any variables exposed by the
 143 +   optimizers.  For example, if optimization removed the need to
 144 +   take the address of a variable, then this pass will be the only
 145 +   chance we have to get uninitialized warnings for such variables.  */
 146 +
 147  static unsigned int
 148  execute_late_warn_uninitialized (void)
 149  {
 150 -  basic_block bb;
 151 -  tree phi;
 152 -
 153    /* Re-do the plain uninitialized variable check, as optimization may have
 154       straightened control flow.  Do this first so that we don't accidentally
 155       get a "may be" warning when we'd have seen an "is" warning later.  */
 156 -  execute_early_warn_uninitialized ();
 157 +  warn_uninitialized_stmts ();
 158  
 159 -  FOR_EACH_BB (bb)
 160 -    for (phi = phi_nodes (bb); phi; phi = PHI_CHAIN (phi))
 161 -      warn_uninitialized_phi (phi);
 162 +  warn_uninitialized_phis ();
 163 +
 164    return 0;
 165  }
 166  

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.

You are not allowed to attach a file to this page.