summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/AnalysisBasedWarnings.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Avoid -Wshadow warnings about constructor parameters named after fieldsReid Kleckner2016-04-291-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | Usually these parameters are used solely to initialize the field in the initializer list, and there is no real shadowing confusion. There is a new warning under -Wshadow called -Wshadow-field-in-constructor-modified. It attempts to find modifications of such constructor parameters that probably intended to modify the field. It has some false negatives, though, so there is another warning group, -Wshadow-field-in-constructor, which always warns on this special case. For users who just want the old behavior and don't care about these fine grained groups, we have a new warning group called -Wshadow-all that activates everything. Fixes PR16088. Reviewers: rsmith Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D18271 llvm-svn: 267957
* P0188R1: add support for standard [[fallthrough]] attribute. This is almostRichard Smith2016-03-081-11/+32
| | | | | | | | | | | | | | exactly the same as clang's existing [[clang::fallthrough]] attribute, which has been updated to have the same semantics. The one significant difference is that [[fallthrough]] is ill-formed if it's not used immediately before a switch label (even when -Wimplicit-fallthrough is disabled). To support that, we now build a CFG of any function that uses a '[[fallthrough]];' statement to check. In passing, fix some bugs with our support for statement attributes -- in particular, diagnose their use on declarations, rather than asserting. llvm-svn: 262881
* [Sema] Replace pointer-to-map with a map. NFC.George Burgess IV2015-12-101-12/+6
| | | | llvm-svn: 255288
* Use Sema::getLocForEndOfToken instead of Preprocessor::getLocForEndOfToken. NFCCraig Topper2015-11-151-3/+1
| | | | llvm-svn: 253155
* Define weak and __weak to mean ARC-style weak references, even in MRC.John McCall2015-10-221-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, __weak was silently accepted and ignored in MRC mode. That makes this a potentially source-breaking change that we have to roll out cautiously. Accordingly, for the time being, actual support for __weak references in MRC is experimental, and the compiler will reject attempts to actually form such references. The intent is to eventually enable the feature by default in all non-GC modes. (It is, of course, incompatible with ObjC GC's interpretation of __weak.) If you like, you can enable this feature with -Xclang -fobjc-weak but like any -Xclang option, this option may be removed at any point, e.g. if/when it is eventually enabled by default. This patch also enables the use of the ARC __unsafe_unretained qualifier in MRC. Unlike __weak, this is being enabled immediately. Since variables are essentially __unsafe_unretained by default in MRC, the only practical uses are (1) communication and (2) changing the default behavior of by-value block capture. As an implementation matter, this means that the ObjC ownership qualifiers may appear in any ObjC language mode, and so this patch removes a number of checks for getLangOpts().ObjCAutoRefCount that were guarding the processing of these qualifiers. I don't expect this to be a significant drain on performance; it may even be faster to just check for these qualifiers directly on a type (since it's probably in a register anyway) than to do N dependent loads to grab the LangOptions. rdar://9674298 llvm-svn: 251041
* Fix Clang-tidy modernize-use-nullptr warnings in source directories; other ↵Hans Wennborg2015-10-061-14/+13
| | | | | | | | | | minor cleanups Patch by Eugene Zelenko! Differential Revision: http://reviews.llvm.org/D13406 llvm-svn: 249484
* Fix a few things with -Winfinite-recursion. NFCRichard Trieu2015-08-211-42/+48
| | | | | | | | | | | | | | Now that -Winfinite-recursion no longer uses recursive calls to before path analysis, several bits of the code can be improved. The main changes: 1) Early return when finding a path to the exit block without a recursive call 2) Moving the states vector into checkForRecursiveFunctionCall instead of passing it in by reference 3) Change checkForRecursiveFunctionCall to return a bool when the warning should be emitted. 4) Use the State vector instead of storing it in the Stack vector. llvm-svn: 245666
* Use llvm::reverse to make a bunch of loops use foreach. NFC.Pete Cooper2015-07-301-2/+1
| | | | | | | | | | | | | | | | In llvm commit r243581, a reverse range adapter was added which allows us to change code such as for (auto I = Fields.rbegin(), E = Fields.rend(); I != E; ++I) { in to for (const FieldDecl *I : llvm::reverse(Fields)) This commit changes a few of the places in clang which are eligible to use this new adapter. llvm-svn: 243663
* Sema: Avoid a stack overflow on large CFGsDuncan P. N. Exon Smith2015-07-231-16/+24
| | | | | | | | | Large CFGs cause `checkForFunctionCall()` to overflow its stack. Break the recursion by manually managing the call stack instead. Patch by Vedant Kumar! llvm-svn: 243039
* Sema: Split out helper from checkForFunctionCall(), NFCDuncan P. N. Exon Smith2015-07-231-37/+37
| | | | | | | | | | Split out `hasRecursiveCallInPath()` from `checkForFunctionCall()` to flatten nesting and clarify the code. This also simplifies a follow-up patch that refactors the other logic in `checkForFunctionCall()`. Patch by Vedant Kumar! llvm-svn: 243038
* Switch users of the 'for (StmtRange range = stmt->children(); range; ↵Benjamin Kramer2015-07-021-5/+4
| | | | | | | | | ++range)‘ pattern to range for loops. The pattern was born out of the lack of range-based for loops in C++98 and is somewhat obscure. No functionality change intended. llvm-svn: 241300
* Revert r240270 ("Fixed/added namespace ending comments using clang-tidy").Alexander Kornienko2015-06-221-10/+7
| | | | llvm-svn: 240353
* Fixed/added namespace ending comments using clang-tidy. NFCAlexander Kornienko2015-06-221-7/+10
| | | | | | | | | | | | The patch is generated using this command: $ tools/extra/clang-tidy/tool/run-clang-tidy.py -fix \ -checks=-*,llvm-namespace-comment -header-filter='llvm/.*|clang/.*' \ work/llvm/tools/clang To reduce churn, not touching namespaces spanning less than 10 lines. llvm-svn: 240270
* add ConstEvaluatedExprVisitorScott Douglass2015-06-101-8/+9
| | | | | | Differential Revision: http://reviews.llvm.org/D10210 llvm-svn: 239474
* Append CXXDefaultInitExpr's wrapped expression to the CFG when visiting a ↵Enrico Pertoso2015-06-031-0/+1
| | | | | | | | | | | | | | | | | | | constructor initializer Summary: This patch is part of http://llvm-reviews.chandlerc.com/D2181. In-class initializers are appended to the CFG when CFGBuilder::addInitializer is called. Reviewers: jordan_rose, rsmith Reviewed By: jordan_rose Subscribers: cfe-commits, klimek Differential Revision: http://reviews.llvm.org/D2370 llvm-svn: 238913
* Replace push_back(Constructor(foo)) with emplace_back(foo) for non-trivial typesBenjamin Kramer2015-05-291-31/+31
| | | | | | | | | | | | | | | | | | | | If the type isn't trivially moveable emplace can skip a potentially expensive move. It also saves a couple of characters. Call sites were found with the ASTMatcher + some semi-automated cleanup. memberCallExpr( argumentCountIs(1), callee(methodDecl(hasName("push_back"))), on(hasType(recordDecl(has(namedDecl(hasName("emplace_back")))))), hasArgument(0, bindTemporaryExpr( hasType(recordDecl(hasNonTrivialDestructor())), has(constructExpr()))), unless(isInTemplateInstantiation())) No functional change intended. llvm-svn: 238601
* Use 'override/final' instead of 'virtual' for overridden methodsAlexander Kornienko2015-04-111-14/+9
| | | | | | | | | | | | | | | | | | | | Summary: The patch is generated using clang-tidy misc-use-override check. This command was used: tools/clang/tools/extra/clang-tidy/tool/run-clang-tidy.py \ -checks='-*,misc-use-override' -header-filter='llvm|clang' -j=32 -fix Reviewers: dblaikie Reviewed By: dblaikie Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D8926 llvm-svn: 234678
* Move ThreadSafetyReporter into an anonymous namespace. NFC.Benjamin Kramer2015-03-191-4/+4
| | | | llvm-svn: 232723
* Move helper class into an anonymous namespace.Benjamin Kramer2015-02-161-1/+2
| | | | llvm-svn: 229404
* Thread Safety Analysis: add support for before/after annotations on mutexes.DeLesley Hutchins2015-02-031-2/+19
| | | | | | | | | | These checks detect potential deadlocks caused by inconsistent lock ordering. The checks are implemented under the -Wthread-safety-beta flag. This patch also replaces calls to getAttrs() with calls to attrs() throughout ThreadSafety.cpp, which fixes the earlier issue that cause assert failures. llvm-svn: 228051
* Revert "Thread Safety Analysis: add support for before/after annotations on ↵Reid Kleckner2015-02-031-19/+2
| | | | | | | | | mutexes." This reverts r227997, as well as r228009. It does not pass check-clang for me locally on Linux. llvm-svn: 228020
* Thread Safety Analysis: add support for before/after annotations on mutexes.DeLesley Hutchins2015-02-031-2/+19
| | | | | | | These checks detect potential deadlocks caused by inconsistent lock ordering. The checks are implemented under the -Wthread-safety-beta flag. llvm-svn: 227997
* Update for LLVM API change to make Small(Ptr)Set::insert return ↵David Blaikie2014-11-191-2/+2
| | | | | | pair<iterator, bool> as per the C++ standard's associative container concept. llvm-svn: 222335
* Report when a function-try-block does not return a value on all control ↵Aaron Ballman2014-10-241-36/+29
| | | | | | paths. Fixed PR14620. llvm-svn: 220557
* Adds 'override' to overriding methods. NFC.Fariborz Jahanian2014-10-011-1/+1
| | | | | | These were uncoveredby my yet undelivered patch. llvm-svn: 218774
* Thread Safety Analysis: add new warning flag, -Wthread-safety-reference, whichDeLesley Hutchins2014-09-181-1/+34
| | | | | | | | warns when a guarded variable is passed by reference as a function argument. This is released as a separate warning flag, because it could potentially break existing code that uses thread safety analysis. llvm-svn: 218087
* Const-correctness, return-after-else, and formatting updates. NFC.Aaron Ballman2014-08-151-12/+10
| | | | llvm-svn: 215706
* Thread safety analysis: add -Wthread-safety-verbose flag, which adds ↵DeLesley Hutchins2014-08-141-12/+60
| | | | | | additional notes that are helpful when compiling statistics on thread safety warnings. llvm-svn: 215677
* Thread Safety Analysis: add a -Wthread-safety-negative flag that warns wheneverDeLesley Hutchins2014-08-041-0/+9
| | | | | | | a mutex is acquired, but corresponding mutex is not provably not-held. This is based on the earlier negative requirements patch. llvm-svn: 214789
* Thread Safety Analysis: Replace the old and broken SExpr with the newDeLesley Hutchins2014-07-281-6/+6
| | | | | | | | til::SExpr. This is a large patch, with many small changes to pretty printing and expression lowering to make the new SExpr representation equivalent in functionality to the old. llvm-svn: 214089
* rewrap to 80 cols, no behavior changeNico Weber2014-07-081-2/+3
| | | | llvm-svn: 212574
* Fix "warning: fallthrough annotation does not directly precede switch label" ↵Alexander Kornienko2014-06-241-0/+3
| | | | | | | | | | | | | | | | in lambdas. Summary: This patch fixes http://llvm.org/PR17864 - "warning: fallthrough annotation does not directly precede switch label" in lambdas. Reviewers: rsmith Reviewed By: rsmith Subscribers: rnk, cfe-commits Differential Revision: http://reviews.llvm.org/D4258 llvm-svn: 211599
* Hide the concept of diagnostic levels from lex, parse and semaAlp Toker2014-06-151-31/+21
| | | | | | | | | | | | | | | | The compilation pipeline doesn't actually need to know about the high-level concept of diagnostic mappings, and hiding the final computed level presents several simplifications and other potential benefits. The only exceptions are opportunistic checks to see whether expensive code paths can be avoided for diagnostics that are guaranteed to be ignored at a certain SourceLocation. This commit formalizes that invariant by introducing and using DiagnosticsEngine::isIgnored() in place of individual level checks throughout lex, parse and sema. llvm-svn: 211005
* [C++11] Use 'nullptr'. Sema edition.Craig Topper2014-05-261-6/+6
| | | | llvm-svn: 209613
* Add a check for tautological bitwise comparisons to -Wtautological-compare.Jordan Rose2014-05-201-0/+9
| | | | | | | | | | | This catches issues like: if ((x & 8) == 4) { ... } if ((x | 4) != 3) { ... } Patch by Anders Rönnholm! llvm-svn: 209221
* Refactoring some for loops to use range-based for loops instead. No ↵Aaron Ballman2014-05-151-84/+46
| | | | | | functional changes intended. llvm-svn: 208915
* Fix a bunch of mislayered clang/Lex includes from SemaAlp Toker2014-05-031-3/+3
| | | | llvm-svn: 207896
* Fix a bad interaction between -Wtautological-overlap-compare and delayedRichard Trieu2014-04-151-4/+11
| | | | | | diagnostics which caused delayed diagnostics on dead paths to be emitted. llvm-svn: 206232
* Add a new subgroup to -Wtautological-compare, -Wtautological-overlap-compare,Richard Trieu2014-04-051-0/+39
| | | | | | | | | | | | | | which warns on compound conditionals that always evaluate to the same value. For instance, (x > 5 && x < 3) will always be false since no value for x can satisfy both conditions. This patch also changes the CFG to use these tautological values for better branch analysis. The test for -Wunreachable-code shows how this change catches additional dead code. Patch by Anders Rönnholm. llvm-svn: 205665
* Turn off -Wmissing-noreturn warning for blocks Fariborz Jahanian2014-04-031-6/+2
| | | | | | | as there is no way to attach this attribute to the block literal. // rdar://16274746 llvm-svn: 205580
* Updating the capability attribute diagnostics to be more capability-neutral. ↵Aaron Ballman2014-04-011-35/+46
| | | | | | Instead of using terminology such as "lock", "unlock" and "locked", the new terminology is "acquire", "release" and "held". Additionally, the capability attribute's name argument is now reported as part of the diagnostic, instead of hard coding as "mutex." llvm-svn: 205359
* Improve -Wunreachable-code to provide a means to indicate code is ↵Ted Kremenek2014-03-291-1/+14
| | | | | | | | | | | | | | | | | | intentionally marked dead via if((0)). Taking a hint from -Wparentheses, use an extra '()' as a sigil that a dead condition is intentionally dead. For example: if ((0)) { dead } When this sigil is found, do not emit a dead code warning. When the analysis sees: if (0) it suggests inserting '()' as a Fix-It. llvm-svn: 205069
* The release_capability, release_shared_capability and ↵Aaron Ballman2014-03-211-1/+9
| | | | | | release_generic_capability functions are now functionally distinct for capability analysis. The unlock_function attribute maps directly to release_generic_capability. llvm-svn: 204469
* [-Wunreachable-code] add a specialized diagnostic for unreachable increment ↵Ted Kremenek2014-03-211-1/+5
| | | | | | expressions of loops. llvm-svn: 204430
* [-Wunreachable-code] Simplify and broad -Wunreachable-code-return, including ↵Ted Kremenek2014-03-201-1/+1
| | | | | | | | | | | | | | | | | nontrivial returns. The exception is return statements that include control-flow, which are clearly doing something "interesting". 99% of the cases I examined for -Wunreachable-code that fired on return statements were not interesting enough to warrant being in -Wunreachable-code by default. Thus the move to include them in -Wunreachable-code-return. This simplifies a bunch of logic, including removing the ad hoc logic to look for std::string literals. llvm-svn: 204307
* Further refine -Wunreachable-code groups so that -Wno-unreachable-code-break ↵Ted Kremenek2014-03-151-10/+19
| | | | | | | | | | doesn't turn off all unreachable code warnings. Also relax unreachable 'break' and 'return' to not check for being preceded by a call to 'noreturn'. That turns out to not be so interesting in practice. llvm-svn: 204000
* Start breaking -Wunreachable-code up into different diagnostic groups.Ted Kremenek2014-03-151-2/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Recent work on -Wunreachable-code has focused on suppressing uninteresting unreachable code that center around "configuration values", but there are still some set of cases that are sometimes interesting or uninteresting depending on the codebase. For example, a dead "break" statement may not be interesting for a particular codebase, potentially because it is auto-generated or simply because code is written defensively. To address these workflow differences, -Wunreachable-code is now broken into several diagnostic groups: -Wunreachable-code: intended to be a reasonable "default" for most users. and then other groups that turn on more aggressive checking: -Wunreachable-code-break: warn about dead break statements -Wunreachable-code-trivial-return: warn about dead return statements that return "trivial" values (e.g., return 0). Other return statements that return non-trivial values are still reported under -Wunreachable-code (this is an area subject to more refinement). -Wunreachable-code-aggressive: supergroup that enables all these groups. The goal is to eventually make -Wunreachable-code good enough to either be in -Wall or on-by-default, thus finessing these warnings into different groups helps achieve maximum signal for more users. TODO: the tests need to be updated to reflect this extra control via diagnostic flags. llvm-svn: 203994
* [C++11] Add 'override' keyword to virtual methods that override their base ↵Craig Topper2014-03-121-22/+26
| | | | | | class. llvm-svn: 203640
* [-Wunreachable-code] Handle Objective-C bool literals in 'isConfigurationValue'.Ted Kremenek2014-03-091-1/+1
| | | | | | | This includes special casing 'YES' and 'NO', which are constants defined as macros. llvm-svn: 203380
* [C++11] Replace verbose functors with succinct lambdasBenjamin Kramer2014-03-011-33/+15
| | | | | | No functionality change. llvm-svn: 202590
OpenPOWER on IntegriCloud