Commit Graph

10736 Commits

Author SHA1 Message Date
Daniel Marjamäki d9a9743b8a Revert "Calculate token scopes in advance rather than as the tokenlist is iterated (#1882)"
This reverts commit 0d7836f3a0.
2019-06-30 09:12:18 +02:00
rebnridgway 0d7836f3a0 Calculate token scopes in advance rather than as the tokenlist is iterated (#1882)
* Added scopeinfo member to token class

Moved ScopeInfo2 declaration here as well because that's where it needs to be now.

* Added scopeinfo accessors and declaration to class

* Add new method for calculating scopes

This replaces the methods in the TemplateSimplifier which calculate the current scope as the token list is iterated.  The old method required checking if the scope had changed for every token multiple times (for multiple iterations), which was surprisingly costly.  Calculating scopes in advance like this decreases runtime on a worst-case file by around thirty percent.
ScopeInfo objects are disposed of when the TemplateSimplification is done as they are not used later.

* Add calculateScopes method to header

* Removed code that calculated current scope

This has been replaced by code that calculates the scopes up front and stores them with each token, which is much faster.

* Fixed compile errors from extra parentheses

* Added missing code to fix memory leak

* Added code to actually clean up ScopeInfo structs

* Tidy up a dodgy for loop

* Convert argument to const ref

* Calculate missing scopes

As the templatesimplificator expands templates and does multiple passes it needs to make sure all scopes are calculated.

* Remove copying the scope to the next token

This is now done properly when scopes are calculated.

* Remove call to calculateScopes

This is now done by the TemplateSimplifier.

* Recalculate scopes for every pass of simplifyTemplates

* Add code to calculate extra scopes as they are added

I thought that this might be useful for calculating scopes when Tokens are created, but as there are several ways of creating Tokens that don't guarantee that they are placed in a list it is easier to just calculate scopes when you know you have a list and when you know you're adding to a list.

* Fix several bugs and poorly designed code

Remove the global scopes collection, and clean them up instead by iterating through the tokenlist to find them.  This means scopes can be calculated by functions in the Token class as well as in the Tokenizer class without leaking the scope object.
Fix a couple of bugs in the calculateScopes method and make it more efficient.

* Remove unnecessary calls to calculateScopes

* Move brace to correct position

Calculating scopes during insertToken only needs to happen if we created a new Token.

* Handle 'using namespace' declarations separately

This fixes a bug caused by a statement matching 'struct B < 0 > ;'

* Fix argument name mismatch

* Actually use newScopeInfo when inserting Token

* Switch to using shared_ptr to hold scopeInfos

This means ScopeInfo2 objects get properly cleaned up when they are no longer needed.

* Change ScopeInfo member to be a shared_ptr

* Update code to use shared_ptr

* Add missing include for shared_ptr

* Remove unnecessary cleanup code

This has been replaced by shared_ptr for ScopeInfo2 objects
2019-06-29 14:34:22 +02:00
Rikard Falkeborn d1d622b74c Valueflow: support global static const variables (#1861) 2019-06-29 14:33:55 +02:00
Daniel Marjamäki faaabc74a7 Set version 1.88 2019-06-29 08:38:13 +02:00
Daniel Marjamäki 341406ab17 Fixed Cppcheck warning; ::AddonInfo::getFullPath can be static 2019-06-29 07:59:55 +02:00
Daniel Marjamäki 0a41f1ad6b Fix Cppcheck warning: Suppressions::dump can be const 2019-06-29 07:53:32 +02:00
Daniel Marjamäki 84cc09d17c Update Copyright 2019-06-29 07:49:14 +02:00
Daniel Marjamäki 9c3c2d785b Fixed Cppcheck warning 2019-06-29 07:46:25 +02:00
IOBYTE 8b347aed42 Fixed #8663 (Stack overflow with template disambiguator) (#1932) 2019-06-28 22:07:21 +02:00
IOBYTE 16788df055 template simplifier: various small fixes (#1916)
* fix adding instantiation of first argument to an instantiation

* add support for function pointer template variables

* fix more cases where templates ending in ">>" are changed to end in "> >"

* fix travis build

* standard types can't be a template parameter name

* remove redundant level == 0 checks

* fix lambda in template variable

* fix a test
2019-06-28 11:14:20 +02:00
Carlo Marcelo Arenas Belón ec4e43767e minor improvements (#1929)
* lib: isNonBoolStdType no longer needed

lib/checkbool.cpp:50:13: warning: unused function 'isNonBoolStdType'
      [-Wunused-function]
static bool isNonBoolStdType(const Variable* var)

* cmake: C++11 is required

also change instructions to a more common syntax
2019-06-28 06:57:05 +02:00
Ken-Patrick 927d139488 Fix FP #9165 (#1928)
Properly check the type of the expressions, instead of using the type
of the tokens
2019-06-27 07:48:44 +02:00
Daniel Marjamäki c97dc79815 --addon: Use json for addon output 2019-06-24 19:29:43 +02:00
Paul Fultz II 66e0f06494 Fixx issue 9163: FP returnDanglingLifetime - returning std::string::find (#1912)
* Fixx issue 9163: FP returnDanglingLifetime - returning std::string::find

* Use simpleMatch
2019-06-24 18:52:17 +02:00
IOBYTE 46b543ba27 template simplifier: stop running passes when nothing was simplified. (#1914) 2019-06-23 10:55:09 +02:00
Daniel Marjamäki 175070ca50 Revert "Fixed #8938 (FP identicalInnerCondition)"
This reverts commit 0edf0b5628.

This bailout seems to cause many false negatives
2019-06-22 21:57:19 +02:00
Daniel Marjamäki de9c999d79 Better handling of spaces in paths 2019-06-22 19:20:15 +02:00
Daniel Marjamäki 7ceb51a952 Try to improve 'clarifyStatement' warning message 2019-06-22 08:44:41 +02:00
Daniel Marjamäki beea7fa8d2 Token::index(): Created Token member that indicates the Token position in the token list. It can be used to quickly check if tok1 precedes tok2. 2019-06-21 22:16:23 +02:00
Daniel Marjamäki d636a83f8b Tokenizer: Assign Token 'progressValue' before returning so they are set properly when the checks are run 2019-06-21 08:43:19 +02:00
Daniel Marjamäki c98ceb6e14 Tweak bailout so it's only used in unused template classes 2019-06-20 14:00:44 +02:00
Daniel Marjamäki cf79830afd Revert "Remove bailout. It hides lots of warnings for real code to avoid FP in unused templates."
This reverts commit 2a4be5ae1c.

When I look at daca@home now there are still lots of false negatives. So this bailout did not cause as much false negatives as I thought.
2019-06-19 22:29:00 +02:00
Ken-Patrick 44d6066c6f FP on assignment through pointer (#1887)
* Fix FP when assigning through pointers

* Add test case for false positive

cppcheck would faulty warn:
"Condition '*b>0' is always true"
2019-06-17 21:25:15 +02:00
IOBYTE 246576fceb Fixed #9178 (Assertion `brackets1.empty() == false' failed on valid C++ code) (#1905)
This fixes a nasty intrinsics related bug causing instantiations that
shouldn't happen.
2019-06-17 21:18:27 +02:00
Daniel Marjamäki 59c7be307c Travis: Fix test/cli testing 2019-06-16 19:11:12 +02:00
Daniel Marjamäki 2a4be5ae1c Remove bailout. It hides lots of warnings for real code to avoid FP in unused templates. 2019-06-16 19:01:45 +02:00
Rikard Falkeborn d909ac8565 Bugfix buffer size for strdup like functions (#1893)
strdup() allocates the string length plus one for a terminating null
character. Add one to compensate for this.

Fixes false positive buffer out of bounds on code like this:

	void f() {
		const char *a = "abcd";
		char * b = strdup(a);
		printf("%c", b[4]); // prints the terminating null character
		free(b);
	}

Also, add a testcase for valueFlowDynamicBufferSize() and add tests for
strdup(), malloc() and calloc().
2019-06-16 16:02:27 +02:00
Daniel Marjamäki ba0a75881a Refactor AddonInfo::getAddonInfo 2019-06-16 15:46:20 +02:00
Ken-Patrick 66ebc187f6 Cleanup some const_cast of Token* (#1886)
* Add non const version of some methods of Token

The aim is to reduce the (ab)use of const_cast.

* Cleanup some more const_cast in valueflow

* Remove useless const_cast

* Remove some const_cast from templatesimplifier

* Remove some const_cast from valueflow
2019-06-16 10:09:38 +02:00
Daniel Marjamäki 61a259597b Fix Cppcheck warnings 2019-06-15 13:28:01 +02:00
Daniel Marjamäki 8359d85b12 Fix Cppcheck warning 2019-06-15 13:23:21 +02:00
Daniel Marjamäki 46cad95238 Fix Cppcheck warnings 2019-06-15 13:05:17 +02:00
Daniel Marjamäki d1f80a2a91 Fix Cppcheck warnings 2019-06-15 13:01:45 +02:00
Paul Fultz II b466415bb4 Fix syntax error in issue 9155 (#1885) 2019-06-15 09:48:22 +02:00
IOBYTE 75720528b0 template simplifier: add 2 new template parameter simplifications (#1884)
* template simplifier: add 2 new template parameter simplifications

int{} -> 0
decltype(int{}) -> int

This fixes reduced test cases like #9153.  I'm not sure they will help
real world code that much.

It was necessary to increase the pass count to 4 to get #9153 completly
simplified.

* relax decltype(type{}) simplification to any type
2019-06-15 09:46:32 +02:00
Daniel Marjamäki e37b92fb3b astyle formatting
[ci skip]
2019-06-14 12:07:22 +02:00
eivindt 44670005ea Record C/CPP/Posix Standard used for cppcheck in dump file / use this for misra checking (#1782)
* Add cmd parameter for choosing between C90 and C99

Misra specifies different requirements to the uniqueness of
macros/enums/variables depending on what C standard
that's being used.

* Add standards configuration to each dump file

Read standards config from misra addon to decide what rules to use.

* Posix as standard setting should be deprecated.  Don't include this in the xml

* Rewritten to use a switch
2019-06-14 12:06:57 +02:00
eivindt 5dd7dacfd7 Fix small error using correct name for addon script when specified in json file (#1881) 2019-06-13 14:11:21 +02:00
IOBYTE c0d8990e8b Fix up a few more cases where templates ending in ">>" should be changed to end in "> >". (#1883) 2019-06-13 13:37:55 +02:00
IOBYTE 2a4b28c267 Fixed #9155 (Syntax error on valid C++ code) (#1880)
Refactored simplifyTemplateAliases to iterate over template type aliases
rather than instantiations. This fixed template type aliases that were
not templates.

Don't instantiate templates in template type aliases. They will get
instantiated once the type alias is instantiated. This required
increasing the template simplifier pass count to 3 so one of the
existing tests continued to work.
2019-06-12 07:44:48 +02:00
Paul Fultz II b863c18e1d Fix crash in issue 9007 (#1878) 2019-06-10 08:24:09 +02:00
Paul Fultz II 169510bd3a Fix issue 9171: Endless recursion (#1877) 2019-06-10 08:22:48 +02:00
IOBYTE 5af8beecf6 template simplifier: specialized member class not recognized causing wrong instantiation (#1876)
Specialized member classes declared outsize the class were not
recognized. This caused the the member class to be instantiated rather
than the specialized class. We already had a test for this but it was
wrong so it went unnoticed.
2019-06-09 08:11:59 +02:00
Paul Fultz II 1f24aa778b Fix issue 9156: Analysis failed because square brackets arent linked correctly (#1871) 2019-06-09 08:10:57 +02:00
IOBYTE 7a87786cbc template simplifier: class or typename can't be a name (#1875)
* template simplifier: class or typename can't be a name

* struct can't be a name
2019-06-08 07:27:53 +02:00
IOBYTE 81e41f129a template simplifier: improve populating template specialization maps (#1873)
Declaration to specialization mapping is still not perfect.
2019-06-07 08:22:34 +02:00
IOBYTE f02e45bf3d fix syntax error for std::literals::complex_literals::operator""if (#1870) 2019-06-05 10:15:22 +02:00
IOBYTE 41cf865947 template simplifier: add links to expanded return type in function forward declaration (#1868)
This crash was seen in daca capnproto but I could only get creduce to
generate garbage code so the test is in checkgarbage.
2019-06-03 07:06:04 +02:00
Daniel Marjamäki 7ca35d181b uninitStructMember: Fixed FP shown in daca@home 2019-06-02 20:19:53 +02:00
Daniel Marjamäki 7a3302b3e3 CheckLeakAutoVar: Fixed FP seen in daca@home 2019-06-02 15:25:54 +02:00