Commit Graph

9537 Commits

Author SHA1 Message Date
Daniel Marjamäki a3f1d28fa5 astyle formatting
[ci skip]
2018-05-11 21:25:41 +02:00
rebnridgway cf6e72b150 Optimised simplifyKnownVariables (#1205)
* Optimised simplifyKnownVariables

Changed the check for references to constant variables so instead of iterating through all tokens looking for references (which is very slow for large files), usages of each known variable are recorded so each usage can be checked for whether or not it is a reference.  Just checking known usages is a lot quicker than checking through all tokens.

* Fixed test error caused by incorrect code

* Fixes to constant variable simplification optimisation

Indexing variables by varId is easier than by Token pointer, but means we also have to store a reference to the constant variable Token in another collection.
Switched to using unordered_map over map as it has slightly better find performance.

* Fixed incorrect simplification behaviour

This should remove constant variables correctly and efficiently.  Requires additional functions, Token::deleteThisInPlace() and TokenList::front(Token*).

* Added setter for TokenList::first

This allows code that adds and removes Tokens from the list to do so without copying nodes into other nodes, which sometimes create difficulties.

* Added deleteThisInPlace function

This allows a token to delete itself without invalidating pointers to the node after it.  If this token is the first or last in a list the calling code will have to remember to change the list's front or back.

* Added declaration for deleteThisInPlace()

* Removed premature MatchCompiler optimisation

* Added and removed some functions

Added declaration for deleteToken(Token*) which deletes a single token from the list
Removed public front(Token*) because it broke encapsulation

* Implemented deleteToken(Token*) function

* Removed 'delete this' from deleteThisInPlace

* Switched to using safer function

TokenList::deleteToken is better than calling straight into Token::deleteThisInPlace because it doesn't call delete this and doesn't break the TokenList's encapsulation.

* Replace constant variables in reverse order

This fixes the problem where you have two constant value assignment statements in a row.  Replacing and deleting them in reverse order means we avoid the problem of deleteThis() potentially invalidating the pointer to the start of the next assignment statement

* Removed unneeded and unsafe deleteThisInPlace

* Removed unneeded and unsafe deleteThisInPlace

* Removed unneeded deleteToken

* Removed unneeded deleteToken

* Removed extra whitespace
2018-05-11 21:14:04 +02:00
Daniel Marjamäki ce30a3ca71 astyle formatting
[ci skip]
2018-05-11 14:49:31 +02:00
Daniel Marjamäki 3044612fe9 Optimize usage of TemplateSimplifier::simplifyCalculations 2018-05-11 14:48:59 +02:00
Paul Fultz II c520735009 Improve checking of size condition against empty to avoid FPs (#1213)
* Improve checking of size condition against empty to avoid FPs

* Add const and todo for reverse conditions
2018-05-11 10:22:06 +02:00
Daniel Marjamäki 1e7c1841f7 Fixed #8515 (Wrong info message about unmatched suppression) 2018-05-11 09:01:24 +02:00
Daniel Marjamäki 7b6ddc50ae astyle formatting
[ci skip]
2018-05-10 17:57:16 +02:00
IOBYTE 184537884f Don't remove the volatile keyword so we can properly overload functions. (#1218)
* Don't remove the volatile keyword so we can properly overload functions.

I fixed all the checks that had tests that use volatile.  There will
probably be more changes needed due to lack of test coverage for
volatile in some checks.

* Fix unused private function warning.
2018-05-10 07:40:01 +02:00
IOBYTE 5452c4dc4a Fixed #8560 (Symboldatabase lacks entry for C++11 overloaded member function) (#1217) 2018-05-09 20:16:08 +02:00
Daniel Marjamäki 129bdb2752 SymbolDatabase::createSymbolDatabaseSetTypePointers: Optimize ~90% 2018-05-09 13:48:55 +02:00
Daniel Marjamäki ab6167e3e6 TokenList::validateAst: optimised ~25% 2018-05-09 12:36:58 +02:00
Daniel Marjamäki ecccce0608 Tokenizer::setVarId: Made it ~5% faster 2018-05-09 10:25:29 +02:00
Paul Fultz II 0197343e0c Fix false positive when using null arithmetic with class type (#1214) 2018-05-09 09:06:49 +02:00
Paul Fultz II f5dbfce8ff Fix false positive with oppositeExpression when using binary op (#1211)
* Fix false positive with oppositeExpression when using binary op

* Simplify conditional
2018-05-08 20:43:57 +02:00
Daniel Marjamäki c266688784 Fix syntax error 2018-05-08 10:21:03 +02:00
Daniel Marjamäki 315dc2ad8a only show information message when information messages are enabled 2018-05-08 09:47:14 +02:00
IOBYTE 8b0b659965 Add support for namespace aliases and C++17 nested namespaces. (#1210)
* Add support for namespace aliases and C++17 nested namespaces.

These are implemented as tokenizer simplifications so changes are not
needed to the tokenizer and symbol database.

* Fix codacy warning.
2018-05-08 06:35:51 +02:00
Daniel Marjamäki 8e8919e906 Fix comment 2018-05-07 22:06:23 +02:00
Daniel Marjamäki 0bff08ca44 Fixed #1378 (#error macro makes unrelated errors undetectable) 2018-05-06 22:02:23 +02:00
Daniel Marjamäki 3b8a3aa4ba Fixed crashes in daca 2018-05-06 09:52:04 +02:00
Daniel Marjamäki 8c2a5c9813 astyle formatting
[ci skip]
2018-05-06 09:50:53 +02:00
Paul Fultz II 0561877182 Fix false positive with negative array index in issue 8536 (#1202)
* Fix FP with negative array index in valueflow

* Remove values when valueflow fails

* Add valueflow test
2018-05-06 08:35:29 +02:00
IOBYTE 5d417bbfa1 SymbolDatabase: harden code for missing links (#1207)
* SymbolDatabase: harden code for missing links

Missing links for templates are common so check links before using them
to prevent crashes.

* SymbolDatabase: replace link check and single token match with match of two tokens
2018-05-06 08:23:07 +02:00
Daniel Marjamäki 858e055c0e ValueFlow: Wrote a few basic comments 2018-05-05 23:03:04 +02:00
Paul Fultz II 067d82f0ea Check for smart pointer release (#1206) 2018-05-05 18:06:49 +02:00
Daniel Marjamäki 4408628107 Fixed #8538 (SymbolDatabase: wrong parsing of noexcept) 2018-05-05 08:31:56 +02:00
Daniel Marjamäki 64b85b474c Fixed #8542 (False positive: noOperatorEq) 2018-05-05 07:46:58 +02:00
Daniel Marjamäki 7fb28b05f6 Check Class: Try to clarify the warnings for noCopyConstructor/noOperatorEq/noDestructor. 2018-05-04 15:39:23 +02:00
Daniel Marjamäki 99003c2084 CheckClass: Better handling of defaulted and deleted functions in the noCopyConstructor/noOperatorEq/noDestructor 2018-05-04 14:58:38 +02:00
Daniel Marjamäki f2bb7397b3 astyle formatting
[ci skip]
2018-05-04 14:57:45 +02:00
Paul Fultz II cac68c6b81 Fix FP when using - as a binary operator (#1201) 2018-05-04 07:58:30 +02:00
IOBYTE f94e9c5447 Fix #8540 (Syntax error involving forward-declared 'enum class') (#1203) 2018-05-04 07:56:20 +02:00
Daniel Marjamäki 59cc479855 Save bitfield bit counts 2018-05-02 20:55:11 +02:00
Daniel Marjamäki 920b553ebf astyle formatting
[ci skip]
2018-05-02 12:58:10 +02:00
Daniel Marjamäki 7dfbe7389b Clarify null pointer arithmetic message 2018-05-02 12:57:24 +02:00
Paul Fultz II f191a3e753 Improve checking of opposite expressions (#1199)
* Improve checking of opposite expressions

* Fix some formatting
2018-05-02 06:32:33 +02:00
Daniel Marjamäki b2343a2d4b Fixed #8518 (Clarify warning for a NULL pointer which is received by a function call parameter.) 2018-05-01 17:30:29 +02:00
Daniel Marjamäki 31148fdfed Fixed #8523 (Clarify warning: noConstructor) 2018-05-01 15:50:03 +02:00
Daniel Marjamäki 40b6f6b3dd CheckClass: Fix the noDestructor warning 2018-05-01 15:31:13 +02:00
Daniel Marjamäki 9710e819be CheckClass: Disable noDestructor for now, we need to handle new better 2018-05-01 09:26:03 +02:00
Daniel Marjamäki 42100fdf11 CheckClass: Better handling of non-copyable classes in the noCopyConstructor check 2018-05-01 08:33:23 +02:00
Sebastian f0646d3754 checkunusedfunctions.cpp: Fix files.txt parsing (#1197)
On Windows searching for the last colon finds the colon which is part of
the path of the source file (e.g. "C:/projects/a.cpp"). Thus the path is
saved incomplete. This fix searches for the second instead of the last
colon and uses the data after the second colon as the path of the source
file.
2018-05-01 08:09:11 +02:00
IOBYTE c3c1abd05e SymbolDatabase: improve checking of uninstantiated templates (#1196)
* SymbolDatabase: improve checking of uninstantiated templates

* Add bailout and debug warning for '>' token without a link in SymbolDatabase::findFunction()..

Don't crash on bad code simplification from tokenizer.
2018-05-01 07:32:19 +02:00
Daniel Marjamäki 73b41455dd CheckClass: If class has memory management it should have copy constructor, operator= and destructor 2018-04-30 23:13:33 +02:00
Daniel Marjamäki eb1571af81 Refactoring: use range for 2018-04-30 22:10:54 +02:00
Daniel Marjamäki fce7a0a128 dump: add Function::type 2018-04-30 16:52:51 +02:00
Daniel Marjamäki 7015fb097e SymbolDatabase::isFunction: better handling of return types 2018-04-29 15:35:31 +02:00
Daniel Marjamäki 45c4456c24 Tokenizer: Code cleanup 2018-04-29 15:05:13 +02:00
Daniel Marjamäki ff732e41ac SymbolDatabase: Remove unused Function constructor 2018-04-29 14:57:02 +02:00
Paul Fultz II e571e598b6 Fix false positive with inner conditions when using pointers (#1195) 2018-04-28 18:56:13 +02:00