summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/AnalysisBasedWarnings.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Add a warning (off by default) for repeated use of the same weak property.Jordan Rose2012-09-281-0/+120
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The motivating example: if (self.weakProp) use(self.weakProp); As with any non-atomic test-then-use, it is possible a weak property to be non-nil at the 'if', but be deallocated by the time it is used. The correct way to write this example is as follows: id tmp = self.weakProp; if (tmp) use(tmp); The warning is controlled by -Warc-repeated-use-of-receiver, and uses the property name and base to determine if the same property on the same object is being accessed multiple times. In cases where the base is more complicated than just a single Decl (e.g. 'foo.bar.weakProp'), it picks a Decl for some degree of uniquing and reports the problem under a subflag, -Warc-maybe-repeated-use-of-receiver. This gives a way to tune the aggressiveness of the warning for a particular project. The warning is not on by default because it is not flow-sensitive and thus may have a higher-than-acceptable rate of false positives, though it is less noisy than -Wreceiver-is-weak. On the other hand, it will not warn about some cases that may be legitimate issues that -Wreceiver-is-weak will catch, and it does not attempt to reason about methods returning weak values. Even though this is not a real "analysis-based" check I've put the bug emission code in AnalysisBasedWarnings for two reasons: (1) to run on every kind of code body (function, method, block, or lambda), and (2) to suggest that it may be enhanced by flow-sensitive analysis in the future. The second (smaller) half of this work is to extend it to weak locals and weak ivars. This should use most of the same infrastructure. Part of <rdar://problem/12280249> llvm-svn: 164854
* Revert 'Fix a typo 'iff' => 'if''. iff is an abreviation of if and only if. ↵Sylvestre Ledru2012-09-271-4/+4
| | | | | | See: http://en.wikipedia.org/wiki/If_and_only_if Commit 164766 llvm-svn: 164769
* Fix a typo 'iff' => 'if'Sylvestre Ledru2012-09-271-4/+4
| | | | llvm-svn: 164766
* Thread-safety analysis: fix ICE when EXCLUSIVE_LOCKS_REQUIRED orDeLesley Hutchins2012-09-191-3/+3
| | | | | | | LOCKS_EXCLUDED is used on a method with a name that is is not a simple identifier. llvm-svn: 164242
* Thread-safety analysis: differentiate between two forms of analysis; a preciseDeLesley Hutchins2012-09-101-14/+34
| | | | | | | | | analysis that may give false positives because it is confused by aliasing, and a less precise analysis that has fewer false positives, but may have false negatives. The more precise warnings are enabled by -Wthread-safety-precise. An additional note clarify the warnings in the precise case. llvm-svn: 163537
* Continue including temporary destructors in the CFG used for warnings.Jordan Rose2012-09-051-1/+2
| | | | | | ...and hopefully unbreak buildbots. My apologies! llvm-svn: 163267
* [ms-inline asm] Remove old cruft now that MS-style asms their own code path.Chad Rosier2012-08-201-7/+0
| | | | llvm-svn: 162210
* Uninitialized variables: two little changes:Richard Smith2012-07-171-0/+1
| | | | | | | * Treat compound assignment as a use, at Jordy's request. * Always add compound assignments into the CFG, so we can correctly diagnose the use in 'return x += 1;' llvm-svn: 160334
* Thread safety analysis: fixed incorrect error message at the end of a ↵DeLesley Hutchins2012-07-021-0/+3
| | | | | | locks_required function. llvm-svn: 159607
* Stop referring to functions as methods in per-function fallthrough-checking.Alexis Hunt2012-06-151-7/+7
| | | | llvm-svn: 158545
* Etch out the code path for MS-style inline assembly.Chad Rosier2012-06-111-0/+6
| | | | llvm-svn: 158325
* Implementation of a "soft opt-in" option for -Wimplicit-fallthrough ↵Alexander Kornienko2012-06-021-5/+16
| | | | | | diagnostics: -Wimplicit-fallthrough-per-method llvm-svn: 157871
* In response to some discussions on IRC, tweak the wording of the newRichard Smith2012-05-261-44/+112
| | | | | | | | | | | | | | | -Wsometimes-uninitialized diagnostics to make it clearer that the cause of the issue may be a condition which must always evaluate to true or false, rather than an uninitialized variable. To emphasize this, add a new note with a fixit which removes the impossible condition or replaces it with a constant. Also, downgrade the diagnostic from -Wsometimes-uninitialized to -Wconditional-uninitialized when it applies to a range-based for loop, since the condition is not written explicitly in the code in that case. llvm-svn: 157511
* Don't offer '[[clang::fallthrough]];' fix-it when a fall-through occurs to aAlexander Kornienko2012-05-261-2/+5
| | | | | | switch label immediately followed by a 'break;'. llvm-svn: 157508
* Split a chunk of -Wconditional-uninitialized warnings out into a separate flag,Richard Smith2012-05-251-23/+122
| | | | | | | | | | | -Wsometimes-uninitialized. This detects cases where an explicitly-written branch inevitably leads to an uninitialized variable use (so either the branch is dead code or there is an uninitialized use bug). This chunk of warnings tentatively lives within -Wuninitialized, in order to give it more visibility to existing Clang users. llvm-svn: 157458
* Some cleanups around the uninitialized variables warning, and a FIXME. No ↵Richard Smith2012-05-241-0/+2
| | | | | | functional change. llvm-svn: 157440
* Pull some cases of initialization with self-reference warnings out ofRichard Trieu2012-05-091-33/+25
| | | | | | -Wconditional-uninitialized into -Wuninitialized. llvm-svn: 156512
* Silence unused-variable warning when assertions are disabled.Kaelyn Uhrain2012-05-031-0/+1
| | | | llvm-svn: 156091
* Add -Wimplicit-fallthrough warning flag, which warns on fallthrough betweenRichard Smith2012-05-031-1/+192
| | | | | | | | | | | | cases in switch statements. Also add a [[clang::fallthrough]] attribute, which can be used to suppress the warning in the case of intentional fallthrough. Patch by Alexander Kornienko! The handling of C++11 attribute namespaces in this patch is temporary, and will be replaced with a cleaner mechanism in a subsequent patch. llvm-svn: 156086
* Fix a note without a SourceLocation.Richard Trieu2012-05-031-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | #define TEST int y; int x = y; void foo() { TEST } -Wuninitialized gives this warning: invalid-loc.cc:4:3: warning: variable 'y' is uninitialized when used here [-Wuninitialized] TEST ^~~~ invalid-loc.cc:2:29: note: expanded from macro 'TEST' #define TEST int y; int x = y; ^ note: initialize the variable 'y' to silence this warning 1 warning generated. The second note lacks filename, line number, and code snippet. This change will remove the fixit and only point to variable declaration. invalid-loc.cc:4:3: warning: variable 'y' is uninitialized when used here [-Wuninitialized] TEST ^~~~ invalid-loc.cc:2:29: note: expanded from macro 'TEST' #define TEST int y; int x = y; ^ invalid-loc.cc:4:3: note: variable 'y' is declared here TEST ^ invalid-loc.cc:2:14: note: expanded from macro 'TEST' #define TEST int y; int x = y; ^ 1 warning generated. llvm-svn: 156045
* Add FixItHint for -Wnull-conversion to initialize with an appropriate literal.David Blaikie2012-04-301-2/+2
| | | | | | Reviewed by Doug Gregor. llvm-svn: 155839
* [analyzer] Remove references to idx::TranslationUnit. Index is dead, ↵Jordy Rose2012-04-281-1/+1
| | | | | | cross-TU inlining never panned out. llvm-svn: 155751
* ThreadSafetyReporter: Manage diagnostics in a std::list.Benjamin Kramer2012-03-261-7/+5
| | | | | | | | | std::list is expensive, but so is std::sorting a SmallVector of SmallVectors of heavyweight PartialDiagnostics. Saves ~30k in a i386-linux-Release+Asserts clang build. llvm-svn: 153437
* improve on diagnostic and provide a fixit hint whenFariborz Jahanian2012-03-081-7/+19
| | | | | | | an uninitialized block variable is being called inside the block literal. // rdar://10817031 llvm-svn: 152271
* When overload resolution picks an implicitly-deleted special memberDouglas Gregor2012-02-151-1/+0
| | | | | | | | | function, provide a specialized diagnostic that indicates the kind of special member function (default constructor, copy assignment operator, etc.) and that it was implicitly deleted. Add a hook where we can provide more detailed information later. llvm-svn: 150611
* Specialize noreturn diagnostics for lambda expressions.Douglas Gregor2012-02-151-8/+28
| | | | llvm-svn: 150586
* Revert my patches which removed Diagnostic.h includes by moving some ↵Benjamin Kramer2012-02-071-1/+0
| | | | | | | | | | | | | | | | | | operator overloads out of line. This seems to negatively affect compile time onsome ObjC tests (which use a lot of partial diagnostics I assume). I have to come up with a way to keep them inline without including Diagnostic.h everywhere. Now adding a new diagnostic requires a full rebuild of e.g. the static analyzer which doesn't even use those diagnostics. This reverts commit 6496bd10dc3a6d5e3266348f08b6e35f8184bc99. This reverts commit 7af19b817ba964ac560b50c1ed6183235f699789. This reverts commit fdd15602a42bbe26185978ef1e17019f6d969aa7. This reverts commit 00bd44d5677783527d7517c1ffe45e4d75a0f56f. This reverts commit ef9b60ffed980864a8db26ad30344be429e58ff5. llvm-svn: 150006
* Move various diagnostic operator<< overloads out of line and remove includes ↵Benjamin Kramer2012-02-041-0/+1
| | | | | | | | | of Diagnostic.h. Fix all the files that depended on transitive includes of Diagnostic.h. With this patch in place changing a diagnostic no longer requires a full rebuild of the StaticAnalyzer. llvm-svn: 149781
* Thread safety analysis:Richard Smith2012-02-031-31/+43
| | | | | | | | | | | | * When we detect that a CFG block has inconsistent lock sets, point the diagnostic at the location where we found the inconsistency, and point a note at somewhere the inconsistently-locked mutex was locked. * Fix the wording of the normal (non-loop, non-end-of-function) case of this diagnostic to not suggest that the mutex is going out of scope. * Fix the diagnostic emission code to keep a warning and its note together when sorting the diagnostics into source location order. llvm-svn: 149669
* Revert various template unreachability code I committed accidentally.David Blaikie2012-01-241-4/+5
| | | | | | r148774, r148775, r148776, r148777 llvm-svn: 148780
* Simple hack to do unreachable code analysis on template patterns.David Blaikie2012-01-241-5/+4
| | | | llvm-svn: 148774
* Make clang's AST model sizeof and typeof with potentially-evaluated operands ↵Eli Friedman2012-01-211-2/+6
| | | | | | correctly, similar to what we already do with typeid. llvm-svn: 148610
* Improve 0-argument -Wvexing-parse diagnostic by adding notes with fix-its:Richard Smith2012-01-121-33/+6
| | | | | | | | | | | | | | | | | | | | | | | - If the declarator is at the start of a line, and the previous line contained another declarator and ended with a comma, then that comma was probably a typo for a semicolon: int n = 0, m = 1, l = 2, // k = 5; myImportantFunctionCall(); // oops! - If removing the parentheses would correctly initialize the object, then produce a note suggesting that fix. - Otherwise, if there is a simple initializer we can suggest which performs value-initialization, then provide a note suggesting a correction to that initializer. Sema::Declarator now tracks the location of the comma prior to the declarator in the declaration, if there is one, to facilitate providing the note. The code to determine an appropriate initializer from the -Wuninitialized warning has been factored out to allow use in both that and -Wvexing-parse. llvm-svn: 148072
* Unweaken vtables as per ↵David Blaikie2011-12-201-0/+2
| | | | | | http://llvm.org/docs/CodingStandards.html#ll_virtual_anch llvm-svn: 146959
* This patch extends thread safety analysis with support for the ↵DeLesley Hutchins2011-12-081-2/+2
| | | | | | scoped_lockable attribute. llvm-svn: 146174
* Further tweak -Wurneachable-code and templates by allowing the warning to run onTed Kremenek2011-12-011-14/+6
| | | | | | | | | explicit template specializations (which represent actual functions somebody wrote). Along the way, refactor some other code which similarly cares about whether or not they are looking at a template instantiation. llvm-svn: 145547
* Don't run -Wunreachable-code on template instantiations. Different ↵Ted Kremenek2011-11-301-2/+8
| | | | | | instantiations may produce different unreachable code results, and it is very difficult for us to prove that ALL instantiations of a template have specific unreachable code. If we come up with a better solution, then we can revisit this, but this approach will at least greatly reduce the noise of this warning for code that makes use of templates. llvm-svn: 145520
* Rename AnalysisContext to AnalysisDeclContext. Not only is this name more ↵Ted Kremenek2011-10-241-4/+4
| | | | | | accurate, but it frees up the name AnalysisContext for other uses. llvm-svn: 142782
* [analyzer] Remove LocationContext creation methods from AnalysisManager, and ↵Ted Kremenek2011-10-231-1/+1
| | | | | | | | change clients to use AnalysisContext instead. WIP to remove/reduce ExprEngine's usage of AnalysisManager. llvm-svn: 142739
* Thread safety analysis refactoring: invalid lock expressions.DeLesley Hutchins2011-10-211-2/+9
| | | | llvm-svn: 142666
* Only warn at self-initialization if some later use is always uninitialized.Matt Beaumont-Gay2011-10-191-2/+13
| | | | llvm-svn: 142538
* Tweak -Wuninitialized's handling of 'int x = x' to report that as the root ↵Ted Kremenek2011-10-131-24/+46
| | | | | | cause of an uninitialized variable IFF there are other uses of that uninitialized variable. Fixes <rdar://problem/9259237>. llvm-svn: 141881
* Don't suggest 'noreturn' for function template instantiations, becauseDouglas Gregor2011-10-101-1/+17
| | | | | | | it might be wrong for other instantiations of the same function template. Fixes PR10801. llvm-svn: 141559
* Rename Diagnostic to DiagnosticsEngine as per issue 5397David Blaikie2011-09-251-12/+12
| | | | llvm-svn: 140478
* Thread safety: refactoring various out of scope warnings to use the same ↵Caitlin Sadowski2011-09-151-12/+15
| | | | | | inteface. This eliminates a lot of unnecessary duplicated code. llvm-svn: 139801
* Thread safety: reverting to use separate warning for requirement to hold any ↵Caitlin Sadowski2011-09-141-4/+9
| | | | | | lock llvm-svn: 139723
* Thread safety: Initializing var before exhaustive switch statement to deal ↵Caitlin Sadowski2011-09-131-1/+1
| | | | | | with extraneous warning produced by gcc but not clang llvm-svn: 139611
* Switch -Wreturn-type to completely rely on the CFG model of no-return.Chandler Carruth2011-09-131-47/+18
| | | | | | | This deletes a bunch of crufty code, and allows more logic sharing between the analyzer and the warnings. llvm-svn: 139594
* Show either a location or a fixit note, not both, for uninitialized variable ↵David Blaikie2011-09-101-52/+51
| | | | | | warnings. llvm-svn: 139463
* Fix a diagnostics crasher with -Wmissing-noreturn in Objective-CDouglas Gregor2011-09-101-1/+4
| | | | | | | methods, and improve the diagnostic slightly along the way. Fixes <rdar://problem/10098695>. llvm-svn: 139446
OpenPOWER on IntegriCloud