View | Details | Raw Unified | Return to bug 24639
Collapse All | Expand All | Context: (Patch / File /
)

(-)gcc/doc/invoke.texi (+13 lines)
 Lines 2733-2738    Link Here 
2733
2733
2734
This warning is enabled by @option{-Wall}.
2734
This warning is enabled by @option{-Wall}.
2735
2735
2736
@item -Wuninitialized=1
2737
@opindex Wuninitialized=1
2738
This is a synonym for @option{-Wuninitialized}.
2739
2740
@item -Wuninitialized=2
2741
@opindex Wuninitialized=2
2742
Similar to @option{-Wuninitialized} except that it generates warnings for
2743
uninitialized variables before optimizing the program.  Use this option
2744
to generate uninitialized warnings when the uninitialized use occurs in
2745
unreachable or dead code.  This option will also generate spurious
2746
uninitialized warnings in cases where optimization analysis would normally
2747
prove the variable is always initialized.
2748
2736
@item -Wunknown-pragmas
2749
@item -Wunknown-pragmas
2737
@opindex Wunknown-pragmas
2750
@opindex Wunknown-pragmas
2738
@cindex warning for unknown pragmas
2751
@cindex warning for unknown pragmas
(-)gcc/testsuite/gcc.dg/pr18501.c (-2 / +2 lines)
 Lines 1-7    Link Here 
1
/* Expected uninitialized variable warning.  */
1
/* Expected uninitialized variable warning.  */
2
2
3
/* { dg-do compile } */
3
/* { dg-do compile } */
4
/* { dg-options "-O -Wuninitialized" } */
4
/* { dg-options "-O -Wuninitialized=2" } */
5
5
6
unsigned bmp_iter_set ();
6
unsigned bmp_iter_set ();
7
int something (void);
7
int something (void);
 Lines 9-15    Link Here 
9
void
9
void
10
bitmap_print_value_set (void)
10
bitmap_print_value_set (void)
11
{
11
{
12
  unsigned first;	/* { dg-warning "may be used" "conditional in loop" { xfail *-*-* } } */
12
  unsigned first;	/* { dg-warning "may be used" "conditional in loop" } */
13
  
13
  
14
  for (; bmp_iter_set (); )
14
  for (; bmp_iter_set (); )
15
    {
15
    {
(-)gcc/opts.c (-4 / +4 lines)
 Lines 663-671    Link Here 
663
      warn_inline = 0;
663
      warn_inline = 0;
664
664
665
      /* The c_decode_option function and decode_option hook set
665
      /* The c_decode_option function and decode_option hook set
666
	 this to `2' if -Wall is used, so we can avoid giving out
666
	 this to `-1' if -Wall is used, so we can avoid giving out
667
	 lots of errors for people who don't realize what -Wall does.  */
667
	 lots of errors for people who don't realize what -Wall does.  */
668
      if (warn_uninitialized == 1)
668
      if (warn_uninitialized == 1 || warn_uninitialized == 2)
669
	warning (OPT_Wuninitialized,
669
	warning (OPT_Wuninitialized,
670
		 "-Wuninitialized is not supported without -O");
670
		 "-Wuninitialized is not supported without -O");
671
    }
671
    }
 Lines 1090-1097    Link Here 
1090
     warning about not using it without also specifying -O.  */
1090
     warning about not using it without also specifying -O.  */
1091
  if (setting == 0)
1091
  if (setting == 0)
1092
    warn_uninitialized = 0;
1092
    warn_uninitialized = 0;
1093
  else if (warn_uninitialized != 1)
1093
  else if (warn_uninitialized != 1 && warn_uninitialized != 2)
1094
    warn_uninitialized = 2;
1094
    warn_uninitialized = -1;
1095
}
1095
}
1096
1096
1097
/* Initialize unused warning flags.  */
1097
/* Initialize unused warning flags.  */
(-)gcc/c-opts.c (-2 / +2 lines)
 Lines 394-401    Link Here 
394
      /* We save the value of warn_uninitialized, since if they put
394
      /* We save the value of warn_uninitialized, since if they put
395
	 -Wuninitialized on the command line, we need to generate a
395
	 -Wuninitialized on the command line, we need to generate a
396
	 warning about not using it without also specifying -O.  */
396
	 warning about not using it without also specifying -O.  */
397
      if (warn_uninitialized != 1)
397
      if (warn_uninitialized != 1 && warn_uninitialized != 2)
398
	warn_uninitialized = (value ? 2 : 0);
398
	warn_uninitialized = (value ? -1 : 0);
399
399
400
      if (!c_dialect_cxx ())
400
      if (!c_dialect_cxx ())
401
	/* We set this to 2 here, but 1 in -Wmain, so -ffreestanding
401
	/* We set this to 2 here, but 1 in -Wmain, so -ffreestanding
(-)gcc/common.opt (+4 lines)
 Lines 145-150    Link Here 
145
Common Var(warn_uninitialized)
145
Common Var(warn_uninitialized)
146
Warn about uninitialized automatic variables
146
Warn about uninitialized automatic variables
147
147
148
Wuninitialized=
149
Common Var(warn_uninitialized) Joined UInteger
150
Generate additional uninitialized automatic variable warnings
151
148
Wunreachable-code
152
Wunreachable-code
149
Common Var(warn_notreached)
153
Common Var(warn_notreached)
150
Warn about code that will never be executed
154
Warn about code that will never be executed
(-)gcc/tree-ssa.c (-6 / +56 lines)
 Lines 1186-1193    Link Here 
1186
    }
1186
    }
1187
}
1187
}
1188
1188
1189
/* Search through all the statements and warn if any use of an
1190
   uninitialized variable is found.  */
1191
1189
static void
1192
static void
1190
execute_early_warn_uninitialized (void)
1193
warn_uninitialized_stmts (void)
1191
{
1194
{
1192
  block_stmt_iterator bsi;
1195
  block_stmt_iterator bsi;
1193
  basic_block bb;
1196
  basic_block bb;
 Lines 1201-1220    Link Here 
1201
      }
1204
      }
1202
}
1205
}
1203
1206
1207
/* Search through all the PHIs any which may reference an 
1208
   uninitialized variable.  Warn if any such PHI is found.  */
1209
1204
static void
1210
static void
1205
execute_late_warn_uninitialized (void)
1211
warn_uninitialized_phis (void)
1206
{
1212
{
1207
  basic_block bb;
1213
  basic_block bb;
1208
  tree phi;
1214
  tree phi;
1209
1215
1216
  FOR_EACH_BB (bb)
1217
    for (phi = phi_nodes (bb); phi; phi = PHI_CHAIN (phi))
1218
      warn_uninitialized_phi (phi);
1219
}
1220
1221
/* This pass emits warnings for uninitialized variables before any
1222
   optimization occurs.
1223
1224
   We always identify and warn for variables which can be trivially
1225
   determined are uninitialized at one or more uses.
1226
1227
   We conditionally warn for "may be" uninitialized variables at this
1228
   time as well (dependent on user flags). 
1229
1230
   By emitting "may be" warnings before optimization we can get warnings
1231
   for uninitialized variables in which uses are optimized away or 
1232
   unreachable.  However, we get more false positive "may be" uninitialized
1233
   warnings and some "may be" uninitialized warnings which really should
1234
   be "is" uninitialized warnings.  */
1235
1236
static void
1237
execute_early_warn_uninitialized (void)
1238
{
1239
  warn_uninitialized_stmts ();
1240
1241
  /* If explicitly requested, look for "may be" uninitialized variables
1242
     before optimizations as well.  */
1243
  if (warn_uninitialized == 2)
1244
    warn_uninitialized_phis ();
1245
}
1246
1247
/* This pass emits warnings for uninitialized variables after 
1248
   optimization has been performed.
1249
1250
   By delaying warnings until after optimization we can turn more
1251
   "may be" uninitialized warnings into "is" uninitialized warnings.
1252
   We can also eliminate some false positive "may be" uninitialized
1253
   warnings. 
1254
1255
   This pass also emits warnings for any variables exposed by the
1256
   optimizers.  For example, if optimization removed the need to
1257
   take the address of a variable, then this pass will be the only
1258
   chance we have to get uninitialized warnings for such variables.  */
1259
static void
1260
execute_late_warn_uninitialized (void)
1261
{
1210
  /* Re-do the plain uninitialized variable check, as optimization may have
1262
  /* Re-do the plain uninitialized variable check, as optimization may have
1211
     straightened control flow.  Do this first so that we don't accidentally
1263
     straightened control flow.  Do this first so that we don't accidentally
1212
     get a "may be" warning when we'd have seen an "is" warning later.  */
1264
     get a "may be" warning when we'd have seen an "is" warning later.  */
1213
  execute_early_warn_uninitialized ();
1265
  warn_uninitialized_stmts ();
1214
1266
1215
  FOR_EACH_BB (bb)
1267
  warn_uninitialized_phis ();
1216
    for (phi = phi_nodes (bb); phi; phi = PHI_CHAIN (phi))
1217
      warn_uninitialized_phi (phi);
1218
}
1268
}
1219
1269
1220
static bool
1270
static bool

Return to bug 24639