Commit Graph

239 Commits

Author SHA1 Message Date
Ted Kremenek 5b4288440d Add temporary hack to -Wuninitialize to create a separate CFG (for C++ code) that doesn't include implicit dtors.
Implicit dtors confuse the ad hoc path-sensitivity of UninitializedValuesV2.cpp.  This isn't
the ideal solution, as it will directly impact compile time, but should significantly reduce
the noise of -Wuninitialized on some code bases.

This immediately "fixes" the false positive reported in PR 9063, although this
isn't the right fix in the long run.

llvm-svn: 124667
2011-02-01 17:43:21 +00:00
Ted Kremenek 1373e5496b Tweak -Wuninitialized fixit for '_Bool' types to be initialized to 0, and C++ 'bool' types to false.
llvm-svn: 124356
2011-01-27 05:18:52 +00:00
Ted Kremenek 064b0345f5 Teach -Wuninitialized to suggest "= false" for initializing bool variables.
llvm-svn: 124352
2011-01-27 02:57:57 +00:00
Ted Kremenek 5d068499a7 Teach -Wreturn-type that destructors can appear
after a 'return' in a CFGBlock.  This accidentally
was working before, but the false assumption that
'return' always appeared at the end of the block
was uncovered by a recent change.

llvm-svn: 124280
2011-01-26 04:49:52 +00:00
Ted Kremenek ebe6260137 Fix regression in -Wreturn-type caused by not
handling all CFGElement kinds.  While writing
the test case, it turned out that return-noreturn.cpp
wasn't actually testing anything since it has the wrong -W
flag.  That uncovered another regression with
the handling of destructors marked noreturn.  WIP.

llvm-svn: 124238
2011-01-25 22:50:47 +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 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 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
Anders Carlsson 48d7285fc6 Handle base and member destructors in CheckFallThrough.
llvm-svn: 123667
2011-01-17 19:06:31 +00:00
Anders Carlsson 128ddbf412 Fix a bug where the -Wmissing-noreturn would always treat constructors with base or member initializers as noreturn.
llvm-svn: 123603
2011-01-16 22:12:43 +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
Chandler Carruth b35635e942 Remove a kludge from analysis based warnings that used to detect
temporaries with no-return destructors. The CFG now properly supports
temporaries and implicit destructors which both makes this kludge no
longer work, and conveniently removes the need for it.

Turn on CFG handling of implicit destructors and initializers. Several
ad-hoc benchmarks don't indicate any measurable performance impact from
growing the CFG, and it fixes real correctness problems with warnings.

As a result of turning on these CFG elements, we started to tickle an
inf-loop in the unreachable code logic used for warnings. The fix is
trivial.

llvm-svn: 123056
2011-01-08 06:54:40 +00:00
Argyrios Kyrtzidis 1cb0de1d4c Fix diagnostic pragmas.
Diagnostic pragmas are broken because we don't keep track of the diagnostic state changes and we only check the current/latest state.
Problems manifest if a diagnostic is emitted for a source line that has different diagnostic state than the current state; this can affect
a lot of places, like C++ inline methods, template instantiations, the lexer, etc.

Fix the issue by having the Diagnostic object keep track of the source location of the pragmas so that it is able to know what is the diagnostic state at any given source location.

Fixes rdar://8365684.

llvm-svn: 121873
2010-12-15 18:44:22 +00:00
John McCall 5d41378146 Rename CXXExprWithTemporaries -> ExprWithCleanups; there's no theoretical
reason this is limited to C++, and it's certainly not limited to temporaries.

llvm-svn: 120996
2010-12-06 08:20:24 +00:00
Zhongxing Xu 2cd7a78c76 Introduce new CFGElement hierarchy to support C++ CFG, based on Marcin's patch
and discussions with Ted and Jordy.

llvm-svn: 114056
2010-09-16 01:25:47 +00:00
Ted Kremenek 50205744c3 Enhance -Wreturn-type to not warn when control-flow is most likely limited by a switch statement explicitly covering
all the cases for an enum value.

llvm-svn: 113450
2010-09-09 00:06:07 +00:00
John McCall 8302463dc6 Split out a header to hold APIs meant for the Sema implementation from Sema.h.
Clients of Sema don't need to know (for example) the list of diagnostics we
support.

llvm-svn: 112093
2010-08-25 22:03:47 +00:00
John McCall 28a0cf7825 Remove Sema.h's dependency on DeclCXX.h.
llvm-svn: 112032
2010-08-25 07:42:41 +00:00
John McCall 1d570a7e16 Remove AnalysisBasedWarnings.h's dependency on Type.h
llvm-svn: 112027
2010-08-25 05:56:39 +00:00
John McCall de6836a384 Struggle mightily against header inclusion in Sema.h.
llvm-svn: 111904
2010-08-24 07:21:54 +00:00
Douglas Gregor c3a6ade0bb Move Sema's headers into include/clang/Sema, renaming a few along the way.
llvm-svn: 110945
2010-08-12 20:07:10 +00:00
Dan Gohman 28ade550f4 Fix namespace polution.
llvm-svn: 109440
2010-07-26 21:25:24 +00:00
Zhongxing Xu eb2528104a Fix construction of AnalysisContext. Thanks Daniel.
llvm-svn: 108694
2010-07-19 13:16:50 +00:00
Chandler Carruth 3b43338870 Add a hack to silence warnings about failing to return from functions after
a temporary with a noreturn destructor has been created. Fixes PR6884 for now.

llvm-svn: 104000
2010-05-17 23:51:52 +00:00
John McCall 5c6ec8c797 Don't emit any fallthrough / missing-noreturn warnings if we can't
compute a CFG for a function.

llvm-svn: 103905
2010-05-16 09:34:11 +00:00
Ted Kremenek b802192a7e Don't perform AnalysisBasedWarnings in Sema or run the static analyzer when a
fatal error has occurred.

llvm-svn: 102778
2010-04-30 21:49:25 +00:00
John McCall 5af1aa6393 An edge from a call expression to the exit block is only an abnormal edge
if *none* of the successors of the call expression is the exit block.
This matters when a call of bool type is the condition of (say) a while
loop in a function with no statements after the loop.  This *can* happen
in C, but it's much more common in C++ because of overloaded operators.

Suppresses some substantial number of spurious -Wmissing-noreturn warnings.

llvm-svn: 102696
2010-04-30 07:10:06 +00:00
Douglas Gregor 24f27696db If a non-noreturn virtual member function is guaranteed not to return,
do *not* suggest that the function could be attribute 'noreturn';
overridden functions may end up returning.

llvm-svn: 101572
2010-04-16 23:28:44 +00:00
Ted Kremenek afed24b472 Remove micro-optimization for not issueing CFG-based warnings for 'static inline' functions
unless they are used.  I discussed this with Daniel Dunbar, and we agreed that this
provides an inconsistent warnings experience for the user and that there were
genuine cases where we wouldn't want to do this optimization.

llvm-svn: 100800
2010-04-08 18:51:44 +00:00
Ted Kremenek fc58c37b8c Removed unused object.
llvm-svn: 100750
2010-04-08 07:30:50 +00:00
Ted Kremenek 465dffa736 Use SmallVector instead of an std::queue.
llvm-svn: 100730
2010-04-08 00:05:00 +00:00
Rafael Espindola c50c27cca8 the big refactoring bits of PR3782.
This introduces FunctionType::ExtInfo to hold the calling convention and the
noreturn attribute. The next patch will extend it to include the regparm
attribute and fix the bug.

llvm-svn: 99920
2010-03-30 20:24:48 +00:00
Rafael Espindola 8756268ee5 Be a bit more consistent in using operator->
This patch moves some methods from QualType to Type and changes the users to
use -> instead of .

llvm-svn: 99805
2010-03-29 03:39:46 +00:00
Ted Kremenek a3ab0d7666 For forward-declared static inline functions, delay CFG-based warnings until we
encounter a definition.

llvm-svn: 99243
2010-03-23 01:37:12 +00:00
Ted Kremenek 0b40532b5e Only perform CFG-based warnings on 'static inline' functions that
are called (transitively) by regular functions/blocks within a
translation untion.

llvm-svn: 99233
2010-03-23 00:13:23 +00:00
Ted Kremenek b45ebee521 Don't bother running the analysis for CFG-based warnings if the
declaration is in a system header.

llvm-svn: 99087
2010-03-20 21:11:09 +00:00
Ted Kremenek 918fe8498d Refactor CFG-based warnings in Sema to be run by a worked object called AnalysisBasedWarnings.
This object controls when the warnings are executed, allowing the client code
in Sema to selectively disable warnings as needed.

Centralizing the logic for analysis-based warnings allows us to optimize
when and how they are run.

Along the way, remove the redundant logic for the 'check fall-through' warning
for blocks; now the same logic is used for both blocks and functions.

llvm-svn: 99085
2010-03-20 21:06:02 +00:00