summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/AnalysisBasedWarnings.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Rename getResultType() on function and method declarations to getReturnType()Alp Toker2014-01-251-3/+3
| | | | | | | | | | | | | | | A return type is the declared or deduced part of the function type specified in the declaration. A result type is the (potentially adjusted) type of the value of an expression that calls the function. Rule of thumb: * Declarations have return types and parameters. * Expressions have result types and arguments. llvm-svn: 200082
* [analyzer] Add a CFG node for the allocator call in a C++ 'new' expression.Jordan Rose2014-01-131-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | In an expression like "new (a, b) Foo(x, y)", two things happen: - Memory is allocated by calling a function named 'operator new'. - The memory is initialized using the constructor for 'Foo'. Currently the analyzer only models the second event, though it has special cases for both the default and placement forms of operator new. This patch is the first step towards properly modeling both events: it changes the CFG so that the above expression now generates the following elements. 1. a 2. b 3. (CFGNewAllocator) 4. x 5. y 6. Foo::Foo The analyzer currently ignores the CFGNewAllocator element, but the next step is to treat that as a call like any other. The CFGNewAllocator element is not added to the CFG for analysis-based warnings, since none of them take advantage of it yet. llvm-svn: 199123
* Ignore qualified templated functions for -Winfinite-recursion. This treatsRichard Trieu2014-01-041-0/+12
| | | | | | functions like Foo<5>::run() the same way as run<5>() for this warning. llvm-svn: 198470
* Add -Winfinite-recursion to ClangRichard Trieu2013-12-211-0/+99
| | | | | | | | | | | | | | | | | | | | | | | | | | | This new warning detects when a function will recursively call itself on every code path though that function. This catches simple recursive cases such as: void foo() { foo(); } As well as more complex functions like: void bar() { if (test()) { bar(); return; } else { bar(); } return; } This warning uses the CFG. As with other CFG-based warnings, this is off by default. Due to false positives, this warning is also disabled for templated functions. llvm-svn: 197853
* Consumed analysis: Add param_typestate attribute, which specifies thatDeLesley Hutchins2013-10-171-0/+9
| | | | | | | function parameters must be in a particular state. Patch by chris.wailes@gmail.com. Reviewed by delesley@google.com. llvm-svn: 192934
* Consumed Analysis: Allow parameters that are passed by non-const referenceDeLesley Hutchins2013-10-171-0/+12
| | | | | | | to be treated as return values, and marked with the "returned_typestate" attribute. Patch by chris.wailes@gmail.com; reviewed by delesley@google.com. llvm-svn: 192932
* Move comment to its proper place.Ted Kremenek2013-10-141-2/+2
| | | | llvm-svn: 192613
* Consumed analysis: switch from tests_consumed/unconsumed to a generalDeLesley Hutchins2013-10-111-9/+0
| | | | | | tests_typestate attribute. Patch by chris.wailes@gmail.com. llvm-svn: 192513
* Consumed analysis: improve loop handling. The prior version of the analysisDeLesley Hutchins2013-10-091-0/+7
| | | | | | | | | | | | marked all variables as "unknown" at the start of a loop. The new version keeps the initial state of variables unchanged, but issues a warning if the state at the end of the loop is different from the state at the beginning. This patch will eventually be replaced with a more precise analysis. Initial patch by chris.wailes@gmail.com. Reviewed and edited by delesley@google.com. llvm-svn: 192314
* Consumed Analysis: Change callable_when so that it can take a list of statesDeLesley Hutchins2013-10-041-24/+8
| | | | | | | | that a function can be called in. This reduced the total number of annotations needed and makes writing more complicated behaviour less burdensome. Patch by chriswails@gmail.com. llvm-svn: 191983
* PR17290: Use 'false' macro in fix-it hint for initializing a variable of typeRichard Smith2013-09-201-7/+7
| | | | | | | | | _Bool in C, if the macro is defined. Also teach FixItUtils to look at whether the macro was defined at the source location for which it is creating a fixit, rather than looking at whether it's defined *now*. This is especially relevant for analysis-based warnings which are delayed until end of TU. llvm-svn: 191057
* PR16054: Slight strengthening for -Wsometimes-uninitialized: if we use aRichard Smith2013-09-121-10/+42
| | | | | | | | | | | variable uninitialized every time we reach its (reachable) declaration, or every time we call the surrounding function, promote the warning from -Wmaybe-uninitialized to -Wsometimes-uninitialized. This is still slightly weaker than desired: we should, in general, warn if a use is uninitialized the first time it is evaluated. llvm-svn: 190623
* Fix constructor-related typos.Benjamin Kramer2013-09-091-1/+1
| | | | | | Noticed by Roman Divacky. llvm-svn: 190311
* Consumed analysis: add return_typestate attribute.DeLesley Hutchins2013-09-031-31/+17
| | | | | | | | | | Patch by chris.wailes@gmail.com Functions can now declare what state the consumable type the are returning will be in. This is then used on the caller side and checked on the callee side. Constructors now use this attribute instead of the 'consumes' attribute. llvm-svn: 189843
* Update to consumed analysis.DeLesley Hutchins2013-08-221-4/+3
| | | | | | | | | | | Patch by chris.wailes@gmail.com. The following functionality was added: * The same functionality is now supported for both CXXOperatorCallExprs and CXXMemberCallExprs. * Factored out some code in StmtVisitor. * Removed variables from the state map when their destructors are encountered. * Started adding documentation for the consumed analysis attributes. llvm-svn: 189059
* AnalysisBasedWarnings.cpp:: Prune "\param VariableName", possibly copypasto, ↵NAKAMURA Takumi2013-08-131-6/+0
| | | | | | in comments. [-Wdocumentation] llvm-svn: 188248
* Remove Sema includes from Analysis code to fix layeringReid Kleckner2013-08-121-3/+5
| | | | | | | | | This moves a header-only class from Sema to Analysis and puts the option check in Sema. Patch by Chris Wailes! llvm-svn: 188230
* Patch by Chris Wailes <chris.wailes@gmail.com>.DeLesley Hutchins2013-08-121-6/+132
| | | | | | | | | | | | | | | | | | Reviewed by delesley, dblaikie. Add the annotations and code needed to support a basic 'consumed' analysis. Summary: This new analysis is based on academic literature on linear types. It tracks the state of a value, either as unconsumed, consumed, or unknown. Methods are then annotated as CallableWhenUnconsumed, and when an annotated method is called while the value is in the 'consumed' state a warning is issued. A value may be tested in the conditional statement of an if-statement; when this occurs we know the state of the value in the different branches, and this information is added to our analysis. The code is still highly experimental, and the names of annotations or the algorithm may be subject to change. llvm-svn: 188206
* Compress pairs. No functionality change.Benjamin Kramer2013-06-291-8/+7
| | | | llvm-svn: 185264
* Don't use unnamed local enums as template arguments.Joerg Sonnenberger2013-06-261-1/+1
| | | | | | Fixes -Werror bootstrap. llvm-svn: 185023
* Thread safety analysis: turn on checking within lock and unlock functions.DeLesley Hutchins2013-04-081-2/+6
| | | | | | These checks are enabled with the -Wthread-safety-beta flag. llvm-svn: 179046
* Fixed "fallthrough annotation does not directly precede switch label" warning inAlexander Kornienko2013-04-021-0/+4
| | | | | | case when [[clang::fallthrough]]; is used in a method of a local class. llvm-svn: 178543
* Fix typos: [Dd]iagnosic -> [Dd]iagnosticStefanus Du Toit2013-03-011-1/+1
| | | | | | These all appear in comments or (ironically) diagnostics output. llvm-svn: 176383
* Remove the CFGElement "Invalid" state.David Blaikie2013-02-231-4/+4
| | | | | | | | | | | | | Use Optional<CFG*> where invalid states were needed previously. In the one case where that's not possible (beginAutomaticObjDtorsInsert) just use a dummy CFGAutomaticObjDtor. Thanks for the help from Jordan Rose & discussion/feedback from Ted Kremenek and Doug Gregor. Post commit code review feedback on r175796 by Ted Kremenek. llvm-svn: 175938
* Replace CFGElement llvm::cast support to be well-defined.David Blaikie2013-02-211-6/+6
| | | | | | See r175462 for another example/more details. llvm-svn: 175796
* Fixed diagnostic nondeterministic order bug (pr14901).Enea Zaffanella2013-02-151-7/+10
| | | | llvm-svn: 175289
* -Wimplicit-fallthrough: fixed two cases where "fallthrough annotation in ↵Alexander Kornienko2013-02-071-3/+16
| | | | | | | | | | | | | | | | | | | | | | unreachable code" was issued incorrectly. Summary: -Wimplicit-fallthrough: fixed two cases where "fallthrough annotation in unreachable code" was issued incorrectly: 1. In actual unreachable code, but not immediately on a fall-through execution path "fallthrough annotation does not directly precede switch label" is better; 2. After default: in a switch with covered enum cases. Actually, these shouldn't be treated as unreachable code for our purpose. Reviewers: rsmith Reviewed By: rsmith CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D374 llvm-svn: 174575
* Fixed segmentation fault when a CFGBlock has NULL successor.Alexander Kornienko2013-02-011-1/+1
| | | | llvm-svn: 174182
* Don't warn on fall-through from unreachable code.Alexander Kornienko2013-01-301-3/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: A motivating example: class ClassWithDtor { public: ~ClassWithDtor() {} }; void fallthrough3(int n) { switch (n) { case 2: do { ClassWithDtor temp; return; } while (0); // This generates a chain of unreachable CFG blocks. case 3: break; } } Reviewers: rsmith, doug.gregor, alexfh Reviewed By: alexfh CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D330 llvm-svn: 173889
* Silence unintended fallthrough diagnostic on a case label preceded with a ↵Alexander Kornienko2013-01-251-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | normal label. Summary: It's unlikely that a fallthrough is unintended in the following code: switch (n) { ... label: case 1: ... goto label; ... } Reviewers: rsmith, doug.gregor Reviewed By: doug.gregor CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D329 llvm-svn: 173486
* Don't suggest to insert [[clang::fallthrough]] before empty cases. Fix for ↵Alexander Kornienko2013-01-251-5/+10
| | | | | | multiple case labels. llvm-svn: 173458
* Implement C++11 semantics for [[noreturn]] attribute. This required splittingRichard Smith2013-01-171-2/+1
| | | | | | | | it apart from [[gnu::noreturn]] / __attribute__((noreturn)), since their semantics are not equivalent (for instance, we treat [[gnu::noreturn]] as affecting the function type, whereas [[noreturn]] does not). llvm-svn: 172691
* Remove useless 'llvm::' qualifier from names like StringRef and others that areDmitri Gribenko2013-01-121-1/+1
| | | | | | brought into 'clang' namespace by clang/Basic/LLVM.h llvm-svn: 172323
* s/CPlusPlus0x/CPlusPlus11/gRichard Smith2013-01-021-2/+2
| | | | llvm-svn: 171367
* Fix analysis based warnings so that all warnings are emitted when compilingDeLesley Hutchins2012-12-071-1/+1
| | | | | | | | | with -Werror. Previously, compiling with -Werror would emit only the first warning in a compilation unit, because clang assumes that once an error occurs, further analysis is unlikely to return valid results. However, warnings that have been upgraded to errors should not be treated as "errors" in this sense. llvm-svn: 169649
* Thread safety analysis: Add a new "beta" warning flag: -Wthread-safety-beta.DeLesley Hutchins2012-12-051-0/+4
| | | | | | | | | | | | As the analysis improves, it will continue to add new warnings that are potentially disruptive to existing users. From now on, such warnings will first be introduced under the "beta" flag. Such warnings are not turned on by default; their purpose is to allow users to test their code against future planned changes, before those changes are actually made. After a suitable migration period, beta warnings will be folded into the standard -Wthread-safety. llvm-svn: 169338
* Sort all of Clang's files under 'lib', and fix up the broken headersChandler Carruth2012-12-041-17/+17
| | | | | | | | | | | | | uncovered. This required manually correcting all of the incorrect main-module headers I could find, and running the new llvm/utils/sort_includes.py script over the files. I also manually added quite a few missing headers that were uncovered by shuffling the order or moving headers up to be main-module-headers. llvm-svn: 169237
* Per discussion on cfe-dev, re-enable suppression of -Wimplicit-fallthrough ↵Ted Kremenek2012-11-121-0/+12
| | | | | | | | | | | | | | on C, but also include dialects of C++ earlier than C++11. There was enough consensus that we *can* get a good language solution to have an annotation outside of C++11, and without this annotation this warning doesn't quite mean's completeness criteria for this kind of warning. For now, restrict this warning to C++11 (where an annotation exists), and make this the behavior for the LLVM 3.2 release. Afterwards, we will hammer out a language solution that we are all happy with. llvm-svn: 167749
* Revert "Disable -Wimplicit-fallthrough when not using C++.", pending further ↵Ted Kremenek2012-11-101-13/+0
| | | | | | discussion on cfe-dev. llvm-svn: 167662
* Disable -Wimplicit-fallthrough when not using C++.Ted Kremenek2012-11-101-0/+13
| | | | | | | | | | | | | | | The rationale is that there is no good workflow to silence the warning for specific cases, other than using pragmas. This is because the attribute to decorate an explicit fall through is only available in C++11. By that argument, this should probably also be disabled unless one is using C++11, but apparently there is an explicit test case for this warning when using C++98. This will require further discussion on cfe-commits. Fixes: <rdar://problem/12584746> llvm-svn: 167655
* -Warc-repeated-use-of-weak: allow single reads in loops from local variables.Jordan Rose2012-10-291-5/+30
| | | | | | | | | | | | | | | | | | | | | Previously, the warning would erroneously fire on this: for (Test *a in someArray) use(a.weakProp); ...because it looks like the same property is being accessed over and over. However, clearly this is not the case. We now ignore loops like this for local variables, but continue to warn if the base object is a parameter, global variable, or instance variable, on the assumption that these are not repeatedly usually assigned to within loops. Additionally, do-while loops where the condition is 'false' are not really loops at all; usually they're just used for semicolon-swallowing macros or using "break" like "goto". <rdar://problem/12578785&12578849> llvm-svn: 166942
* -Warc-repeated-use-of-weak: Don't warn on a single read followed by writes.Jordan Rose2012-10-111-4/+36
| | | | | | | | | | This is a "safe" pattern, or at least one that cannot be helped by using a strong local variable. However, if the single read is within a loop, it should /always/ be treated as potentially dangerous. <rdar://problem/12437490> llvm-svn: 165719
* StringRef-ify Binary/UnaryOperator::getOpcodeStrDavid Blaikie2012-10-081-1/+1
| | | | llvm-svn: 165383
* Move the 'find macro by spelling' infrastructure to the Preprocessor class andDmitri Gribenko2012-09-291-58/+8
| | | | | | | use it to suggest appropriate macro for __attribute__((deprecated)) in -Wdocumentation-deprecated-sync. llvm-svn: 164892
* Fix buildbots by not using a template from another namespace.Jordan Rose2012-09-281-8/+7
| | | | | | | No need to specialize BeforeThanCompare for a comparator that's only going to be used once. llvm-svn: 164859
* Compatibility macro detection for the -Wimplicit-fallthrough diagnostic.Alexander Kornienko2012-09-281-1/+66
| | | | | | | | | | | | | | | | | | | Summary: When issuing a diagnostic message for the -Wimplicit-fallthrough diagnostics, always try to find the latest macro, defined at the point of fallthrough, which is immediately expanded to "[[clang::fallthrough]]", and use it's name instead of the actual sequence. Known issues: * uses PP.getSpelling() to compare macro definition with a string (anyone can suggest a convenient way to fill a token array, or maybe lex it in runtime?); * this can be generalized and used in other similar cases, any ideas where it should reside then? Reviewers: doug.gregor, rsmith Reviewed By: rsmith CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D50 llvm-svn: 164858
* -Warc-repeated-use-of-weak: check ivars and variables as well.Jordan Rose2012-09-281-5/+28
| | | | | | | | | | Like properties, loading from a weak ivar twice in the same function can give you inconsistent results if the object is deallocated between the two loads. It is safer to assign to a strong local variable and use that. Second half of <rdar://problem/12280249>. llvm-svn: 164855
* 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
OpenPOWER on IntegriCloud