Commit Graph

39 Commits

Author SHA1 Message Date
David Blaikie e5f9a9e603 Show either a location or a fixit note, not both, for uninitialized variable warnings.
llvm-svn: 139463
2011-09-10 05:35:08 +00:00
Ted Kremenek aed4677a1c -Wuninitialized: fix insidious bug resulting from interplay of blocks and dead code. Fixes <rdar://problem/10060250>.
llvm-svn: 139027
2011-09-02 19:39:26 +00:00
Ted Kremenek ee9848e20d Fix regression in -Wuninitialized involving VLAs. It turns out that we were modeling sizeof(VLAs)
incorrectly in the CFG, and also the static analyzer.  This patch regresses the analyzer a bit, but
that needs to be followed up with a better solution.

Fixes <rdar://problem/10008112>.

llvm-svn: 138372
2011-08-23 20:30:50 +00:00
Chandler Carruth 4dd6c043ae Move duplicate uninitialized warning suppression into the
AnalysisBasedWarnings Sema layer and out of the Analysis library itself.
This returns the uninitialized values analysis to a more pure form,
allowing its original logic to correctly detect some categories of
definitely uninitialized values. Fixes PR10358 (again).

Thanks to Ted for reviewing and updating this patch after his rewrite of
several portions of this analysis.

llvm-svn: 135748
2011-07-22 05:27:52 +00:00
Ted Kremenek 65b3e0649c Fix false negative in -Wuninitialized involving a () wrapping an lvalue-to-rvalue conversion in a DeclStmt.
llvm-svn: 135525
2011-07-19 21:41:51 +00:00
Ted Kremenek 5d855bf7f2 Fix assertion failure in UninitializedValues.cpp where an lvalue to rvalue conversion is wrapped in a parenthesis.
llvm-svn: 135519
2011-07-19 20:33:49 +00:00
Chandler Carruth 7cf5a37605 Revert r135217, which wasn't the correct fix for PR10358. With this
patch, we actually move the state-machine for the value set backwards
one step. This can pretty easily lead to infinite loops where we
continually try to propagate a bit, succeed for one iteration, but then
back up because we find an uninitialized use.

A reduced test case from PR10379 is included.

llvm-svn: 135359
2011-07-16 22:27:02 +00:00
Ted Kremenek f0b28d7fe5 Fix false negative reported in PR 10358 by using 'Unknown' in -Wuninitialized to avoid cascading warnings. Patch by Kaelyn Uhrain.
llvm-svn: 135217
2011-07-14 23:43:06 +00:00
Ted Kremenek efdb7fe53b Fix crash in -Wuninitialized when using switch statments whose condition is a logical operation.
llvm-svn: 131158
2011-05-10 22:10:35 +00:00
Chandler Carruth 42983aef34 Switch 'is possibly uninitialized' to 'may be uninitialized' based on
Chris's feedback.

llvm-svn: 129127
2011-04-08 06:47:15 +00:00
Chandler Carruth 278f89732f Now that the analyzer is distinguishing between uninitialized uses that
definitely have a path leading to them, and possibly have a path leading
to them; reflect that distinction in the warning text emitted.

llvm-svn: 129126
2011-04-08 06:33:38 +00:00
Chandler Carruth 78c7e34485 Commit a bit of a hack to fully handle the situation where variables are
marked explicitly as uninitialized through direct self initialization:

  int x = x;

With r128894 we prevented warnings about this code, and this patch
teaches the analysis engine to continue analyzing subsequent uses of
'x'. This should wrap up PR9624.

There is still an open question of whether we should suppress the
maybe-uninitialized warnings resulting from variables initialized in
this fashion. The definitely-uninitialized uses should always be warned.

llvm-svn: 128932
2011-04-05 21:36:30 +00:00
Chandler Carruth b5d4831f83 Fix PR9624 by explicitly disabling uninitialized warnings for direct self-init:
int x = x;

GCC disables its warnings on this construct as a way of indicating that
the programmer intentionally wants the variable to be uninitialized.
Only the warning on the initializer is turned off in this iteration.

This makes the code a lot more ugly, but starts commenting the
surprising behavior here. This is a WIP, I want to refactor it
substantially for clarity, and to determine whether subsequent warnings
should be suppressed or not.

llvm-svn: 128894
2011-04-05 17:41:31 +00:00
Ted Kremenek 378819342e Fix PR 9626 (duplicated self-init warnings under -Wuninitialized) with numerous CFG and UninitializedValues analysis changes:
1) Change the CFG to include the DeclStmt for conditional variables, instead of using the condition itself as a faux DeclStmt.
2) Update ExprEngine (the static analyzer) to understand (1), so not to regress.
3) Update UninitializedValues.cpp to initialize all tracked variables to Uninitialized at the start of the function/method.
4) Only use the SelfReferenceChecker (SemaDecl.cpp) on global variables, leaving the dataflow analysis to handle other cases.

The combination of (1) and (3) allows the dataflow-based -Wuninitialized to find self-init problems when the initializer
contained control-flow.

llvm-svn: 128858
2011-04-04 23:29:12 +00:00
Ted Kremenek b8d8c4ec56 -Wuninitialized: use "self-init" warning when issue uninitialized values warnings from the dataflow analysis that include within the initializer of a variable.
llvm-svn: 128843
2011-04-04 20:56:00 +00:00
Ted Kremenek 35d800c39f -Wuninitialized: don't issue fixit for initializer if a variable declaration already has an initializer.
llvm-svn: 128838
2011-04-04 19:43:57 +00:00
Ted Kremenek 77361761fb -Wuninitialized should not warn about variables captured by blocks as byref.
Note this can potentially be enhanced to detect if the __block variable
is actually written by the block, or only when the block "escapes" or
is actually used, but that requires more analysis than it is probably worth
for this simple check.

llvm-svn: 128681
2011-03-31 22:32:41 +00:00
Ted Kremenek 61c74a1423 Rename -Wuninitialized-maybe to -Wconditional-uninitialized.
llvm-svn: 127793
2011-03-17 03:06:07 +00:00
Ted Kremenek ea6c20adaf Take 2: merge -Wuninitialized-experimental into -Wuninitialized. Only *must-be-uninitialized* warnings are reported, with *maybe-uninitialized* under a separate flag. I await any fallout/comments/feedback, although hopefully this will produce no noise for users.
llvm-svn: 127670
2011-03-15 05:22:33 +00:00
Ted Kremenek c8c4e5f371 Split warnings from -Wuninitialized-experimental into "must-be-initialized" and "may-be-initialized" warnings, each controlled by different flags.
llvm-svn: 127666
2011-03-15 04:57:38 +00:00
Ted Kremenek 792798549f Remove old UninitializedValues analysis.
llvm-svn: 127656
2011-03-15 03:17:01 +00:00
Ted Kremenek e6a12a97d4 Move uninitialized variable checking back under -Wuninitialized-experimental. It is clear from user feedback that this warning is not quite ready.
llvm-svn: 125007
2011-02-07 17:38:38 +00:00
Ted Kremenek 436cc8ffe7 Reenable -Wuninitialized warning for captured block variables.
llvm-svn: 124782
2011-02-03 06:51:50 +00:00
Ted Kremenek b3dbe28e31 Based on user feedback, swap -Wuninitialized diagnostics to have the warning refer to the bad use, and the note to the variable declaration.
llvm-svn: 124758
2011-02-02 23:35:53 +00:00
Ted Kremenek ba357296e7 Enhance -Wuninitialized to better reason about || and &&, tracking dual dataflow facts and properly merging them.
Fixes PR 9076.

llvm-svn: 124666
2011-02-01 17:43:18 +00:00
Ted Kremenek 1be4a59a11 Teach -Wuninitialized about indirect goto. Fixes PR 9071.
llvm-svn: 124394
2011-01-27 18:51:39 +00:00
Ted Kremenek 93a313869f Teach -Wuninitialized not to assert when analyzing
blocks that reference captured variables.

llvm-svn: 124348
2011-01-27 02:29:34 +00:00
Ted Kremenek e543be3531 Merge -Wuninitialized-experimental into -Wuninitialized.
llvm-svn: 124279
2011-01-26 04:49:48 +00:00
Ted Kremenek 33ddd9692d Tweak -Wuninitialized-experimental to not emit
a warning for uses of an uninitialized variable
when the use is a void cast, e.g. (void) x.

llvm-svn: 124278
2011-01-26 04:49:43 +00:00
Ted Kremenek bcf848f70a Teach -Wuninitialized-experimental to also warn
about uninitialized variables captured by blocks.

llvm-svn: 124213
2011-01-25 19:13:48 +00:00
Ted Kremenek 8f01420d9d Teach -Wuninitialized-experimental about sizeof().
llvm-svn: 124076
2011-01-23 17:53:04 +00:00
Ted Kremenek 33d4b5eb66 Provide -Wuninitialized-experimental fixits
for floats, and also check if 'nil' is declared
when suggesting it for initializing ObjC pointers.

llvm-svn: 124004
2011-01-21 22:49:49 +00:00
Ted Kremenek 2959fdd087 Add basic fixits for -Wuninitialized-experimental
to suggest initializations for pointer and
ObjC pointer types.

llvm-svn: 123995
2011-01-21 19:41:46 +00:00
Ted Kremenek 39fa056342 Enhance -Wuninitialized-experimental diagnostics
to issue the warning at an uninitialized variable's
declaration, but to issue notes at possible
uninitialized uses (which could be multiple).

llvm-svn: 123994
2011-01-21 19:41:41 +00:00
Ted Kremenek b82ddd6ada Add rudimentary path-sensitivity to UnintializedValuesV2
analysis for short-circuited operations.  For branch written like "if (x && y)",
we maintain two sets of dataflow values for the outgoing
branches.  This suppresses some common false positives
for -Wuninitialized-experimental.

This change introduces some assertion failures
when running on the LLVM codebase.  WIP.

llvm-svn: 123923
2011-01-20 17:37:17 +00:00
Ted Kremenek b63931eef6 Teach UninitializedValuesV2 to implicitly reason about C++
references by monitoring whether an access to
a variable is solely to compute it's lvalue or
to do an lvalue-to-rvalue conversion (i.e., a load).

llvm-svn: 123777
2011-01-18 21:18:58 +00:00
Ted Kremenek c8d55da05a Correctly enable test/Sema/unit-variables.c,
thus identifying a minor logical flaw in
UninitializedValuesV2.cpp.

llvm-svn: 123734
2011-01-18 05:00:42 +00:00
Ted Kremenek cab479f0ee Teach UninitializedValuesV2 about "int x = x" and
also properly handle confluence of loops.

llvm-svn: 123733
2011-01-18 04:53:25 +00:00
Ted Kremenek b749a6d62a Add initial prototype for implementation of
-Wuninitialized based on CFG dataflow analysis.  WIP.

llvm-svn: 123512
2011-01-15 02:58:47 +00:00