summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/AnalysisBasedWarnings.cpp
Commit message (Collapse)AuthorAgeFilesLines
* -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
* 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
OpenPOWER on IntegriCloud