Commit Graph

2733 Commits

Author SHA1 Message Date
Robert Reif e1e822275d
fix daca2 paraview crash from uninstantiated recursive template (#3237) 2021-04-29 11:09:51 +02:00
Daniel Marjamäki 8aa9e448f5 Parser; Set varid for structured binding variables 2021-04-26 18:04:27 +02:00
Daniel Marjamäki b798b99777 Parser; do not remove alignof and alignas in the same way 2021-04-26 11:44:08 +02:00
dummyunit b18e6f1e10
Fix varId assignment for uses of variables declared in the if condition (#3231)
Variables declared in the if condition (or in C++17 init-statement) are
visible not only in the if body but also in the else body. But logic in
Tokenizer::setVarIdPass1() handled such variables as if they were
declared in the if body.

As the result they were removed from variablesMap by the time the else
block was parsed and their uses in the else block were either given an
incorrect varId from variables in some outer scope or not given a varId
at all.

This then resulted in false positive unreadVariable errors for variables
declared in the if condition (or init-statement) and used only in the
else block.

Simplification from "else if ..." to "else { if ... }" was moved before
setVarId() to simplify detection for ends of blocks in if-else chains.
2021-04-26 07:38:03 +02:00
Daniel Marjamäki 28a7bb63ec Parser; simplify (break out) init expression from if/switch/range-for 2021-04-25 14:37:27 +02:00
Daniel Marjamäki c9dc92c266 Parser; C++20 for loop with initialization expression 2021-04-24 11:47:51 +02:00
Daniel Marjamäki 26c0945309 Handle c++20 spaceship operator 2021-04-22 19:15:22 +02:00
Oliver Stöneberg 5de58c4ddd
added clang-tidy to CI (#3218) 2021-04-18 21:51:47 +02:00
Daniel Marjamäki 56773b82c4 Simple handling of coroutines 2021-04-18 19:42:22 +02:00
Oliver Stöneberg 3bc71f982a
enabled "debug" findings in self-check / split "simplifyUsing" and "simplyTypedef" from more generic "debug" (#3210) 2021-04-17 18:07:47 +02:00
IOBYTE 5568ac95e7
fix simplifyUsing debug warning for: using value_type = const ValueFlow::Value; (#3211) 2021-04-17 14:20:16 +02:00
Daniel Marjamäki 11f828a669 Fixed #9415 (C++11: `alignas` not handled -> wrong code -> false negatives) 2021-04-15 20:26:53 +02:00
Oliver Stöneberg 6397e29f84
cleaned up includes based on include-what-you-use (#3141) 2021-04-03 21:30:50 +02:00
Ken-Patrick Lehrmann cddaa6d671
10221: Fix setVarId in template code (#3187)
The computation of the classname was not expecting templates. Simply
skipping the template part seems to fix the issue.
2021-03-29 12:16:02 +02:00
Lars Even Almaas 9786f1c34b
Suggested implementation for rule 8.2 (#3169) 2021-03-25 08:25:43 +01:00
Daniel Marjamäki 42437277dc Update Copyright year 2021-03-21 20:58:32 +01:00
Daniel Marjamäki 51564504a8 astyle formatting 2021-03-20 18:54:46 +01:00
Paul Fultz II b0ac92ce8f
Report an error if analysis becomes cyclic (#3173) 2021-03-20 14:02:07 +01:00
Tetrix 9b7f1f6280
simplifyCPPAttribute tokenizer strips alignas (#3171) 2021-03-20 10:38:47 +01:00
Rikard Falkeborn 103e52f394
Fix tokenizing of x[i](0) (Fixes #8875) (#3167)
Fix faulty removal of parenthesis when "]" is followed by parenthesis
with a number inside, for example when calling a function pointer in
an array or (perhaps more common) in c++, calling operator ( on an
element in an array.

Fixes #8875 where such wrong simplification lead to a FP with too many
bits shifted due to "<<" was interpreted like a shift operator rather
than a stream output.
2021-03-11 08:16:25 +01:00
IOBYTE bc8eb164a3
fix more daca simplifyUsing hangs (#3152) 2021-02-26 18:30:17 +01:00
PKEuS 141d2ac215 Refactorization: Improved internal implementation of severity and certainty levels
Backported from LCppC.
2021-02-24 22:00:06 +01:00
IOBYTE 9bb57a7b6f
fix #10183 (performance regression (hang) - ScopeInfo3::findInChildren()) (#3147) 2021-02-24 06:36:53 +01:00
IOBYTE fc1cfba5e0
fix simplifyUsing hang parsing class initializer list using {} (#3146)
Co-authored-by: Robert Reif <reif@FX6840>
2021-02-23 20:35:20 +01:00
IOBYTE a07f93f819
fix simplifyUsing crash and hang (#3145) 2021-02-23 09:48:15 +01:00
Robert Reif 3c6fae37e4 minor simplifyUsing optimizations
The using type aliases are a C++ 11 feature so only check for them in C++ 11 or later.

Don't try to simplify a type alias when it can't be parsed.
2021-02-19 22:48:31 +01:00
IOBYTE 8547ff8cc2
fix some hangs in daca from uninstantiated template classes derived f… (#3133)
* fix some hangs in daca from uninstantiated template classes derived from itself

* remove assertions

* fix another simplifyUsing hang

Co-authored-by: Robert Reif <reif@FX6840>
2021-02-17 18:12:49 +01:00
IOBYTE 7ab84bef0c
fix daca crash in intel-compute-runtime (#3132) 2021-02-15 08:12:29 +01:00
Daniel Marjamäki 70511464f5 Fixed Cppcheck self-check 2021-02-14 15:53:46 +01:00
Daniel Marjamäki f08dde1140 Fixed #10013 (Tokenizer: Code with 'not' is not handled) 2021-02-13 20:32:49 +01:00
IOBYTE 1eafed9e75
fix hang in simplifyUsing (#3128)
Co-authored-by: Robert Reif <reif@FX6840>
2021-02-12 16:21:51 +01:00
IOBYTE e57a674458
fix #10173 (syntax error from wrong simplifications for using type al… (#3126) 2021-02-12 09:47:16 +01:00
IOBYTE b6e93bb575
fix #10172 (debug: Executable scope 'x' with unknown function.) (#3121) 2021-02-11 08:08:45 +01:00
IOBYTE d3d2e16137
fix hang from f48e195c31 (fix #10136 TODO test (#3117)) (#3120)
Co-authored-by: Robert Reif <reif@FX6840>
2021-02-09 14:19:01 +01:00
IOBYTE f48e195c31
fix #10136 TODO test (#3117) 2021-02-07 21:46:35 +01:00
IOBYTE 1872725ca2
fix #10171 (debug: Executable scope 'x' with unknown function.) (#3116) 2021-02-07 09:04:57 +01:00
Daniel Marjamäki b7c4aeca16 astyle formatting 2021-02-06 12:27:51 +01:00
IOBYTE c70fcf8e2b
fix #10136 (debug: Executable scope 'x' with unknown function.) (#3113) 2021-02-05 15:50:32 +01:00
Oliver Stöneberg e8b8cfec78
some minor optimizations (#3057) 2021-01-28 22:18:17 +01:00
Simon Martin 9d10f4f572
Ticket #10028: Properly simplify auto variables' initialization. (#3079) 2021-01-23 17:56:58 +01:00
IOBYTE a4953575f1
fix #10127 (debug: Executable scope 'x' with unknown function.) (#3077) 2021-01-23 17:55:25 +01:00
orbitcowboy bb451ca289 Running astlye [ci skip] 2021-01-22 21:47:24 +01:00
IOBYTE d39956414f
fix #10122, #10124 and #10125 (debug: Executable scope 'x' with unknown function.) (#3073) 2021-01-21 19:47:51 +01:00
IOBYTE 664289792c
fix simplifyTypedef removing needed type qualification (#3058) 2021-01-18 10:08:55 +01:00
IOBYTE dd866f2898
fix using type alias with derived class (#3050) 2021-01-17 16:10:53 +01:00
Oliver Stöneberg 7aa85aa408
Use std::unordered_* containers for faster lookups (#3052) 2021-01-16 13:52:09 +01:00
Daniel Marjamäki a5babf25a7 Fixed #10080 (syntax error: operator) 2021-01-14 20:56:11 +01:00
Daniel Marjamäki 5f21d9d97b Fixed #8975 (Syntax error for valid C code) 2021-01-12 21:28:07 +01:00
Oliver Stöneberg ac7647fcd8
some self-check suppression cleanups (#3032) 2021-01-09 20:32:38 +01:00
IOBYTE cb02628c7c
fix #10075 (namespace alias changes variable name) (#3020) 2021-01-06 17:30:11 +01:00
IOBYTE 8897ad3408
fix #10068 (typedef not replaced when namespace is involved) (#3009) 2021-01-05 16:53:56 +01:00
Oliver Stöneberg d59abfd977
fixed clang-tidy warnings (#3006)
* clang_tidy.cmake: added clang-tidy-11 to list of executables to look for

* .clang-tidy: disabled warnings we are (currently) not interested in

* fixed clang-tidy warnings
2021-01-02 23:10:27 +01:00
Oliver Stöneberg fbf5858f76
fixed and enabled several clang-tidy warnings (#2816) 2021-01-02 19:10:25 +01:00
IOBYTE e7bdf5f71c
remove cleanupAfterSimplify from the template simplifier (#2998)
The template simplifier works well enough now so cleanupAfterSimplify is
no longer necessary.  In fact cleanupAfterSimplify was introducing a bug
which improperly simplified C++ style casts.

Bugs should be exposed and fixed properly rather than just hiding them.

Co-authored-by: Robert Reif <reif@FX6840>
2020-12-31 09:33:23 +01:00
IOBYTE 277da763aa
fix #10054 (debug: Executable scope 'x' with unknown function.) (#2994) 2020-12-30 08:09:34 +01:00
IOBYTE 765c1ace87
fix #10008 (false negative: knownEmptyContainer with alias in namespace and "using namespace") (#2979) 2020-12-26 13:45:17 +01:00
Daniel Marjamäki 37a5ec8cd5 Summaries: Moved to its own files 2020-12-20 19:53:58 +01:00
Daniel Marjamäki 1bf6a2f62b Summaries: Enhanced merge of noreturn info 2020-12-20 14:49:43 +01:00
Daniel Marjamäki 96caaedbd5 Generate basic function summaries 2020-12-19 19:02:42 +01:00
Daniel Marjamäki d340e8770c Fixed Tokenizer::setVarId when removing last scope name 2020-12-08 17:39:04 +01:00
Daniel Marjamäki 245284acde Tokenizer; Fixed varid for base class member variable 2020-12-08 17:25:50 +01:00
Daniel Marjamäki 7a4462dac5 Tokenizer: Refactoring, use isFunctionHead in setVarId. It should be more reliable. 2020-12-08 16:53:55 +01:00
IOBYTE 8161baf1e9
fix template debug output line numbers (#2938) 2020-12-08 10:35:13 +01:00
IOBYTE ab16603666
fix #9685 (Handle 'extern "C++"') (#2933) 2020-12-05 09:26:11 +01:00
Daniel Marjamäki 62810af7f3 Tokenizer: Avoid null pointer dereference in garbage code 2020-12-02 23:06:11 +01:00
Daniel Marjamäki cbb388d458 Tokenizer: Avoid wrong simplification of template right angle bracket 2020-12-02 20:21:32 +01:00
Daniel Marjamäki f250e06df7 Improved daca check for wrong detection of template right angle brackets 2020-11-30 20:00:38 +01:00
Daniel Marjamäki 9aa69661b5 More robust Token::findClosingBracket 2020-11-30 19:26:28 +01:00
Daniel Marjamäki 8a1c16a560 Tokenizer: add daca debug messages when right angle brackets in templates are not handled well 2020-11-29 16:07:56 +01:00
Daniel Marjamäki e2debac882 Fix testcases 2020-11-29 08:46:42 +01:00
Daniel Marjamäki fd75837494 Tokenizer: Remove extra 'template' keywords 2020-11-28 21:57:06 +01:00
Daniel Marjamäki 5b89b179ec Detect syntax error when script is checked 2020-11-28 14:41:05 +01:00
Daniel Marjamäki 2cd8ea83a7 Fixed #9860 (unused template not removed properly by default) 2020-11-22 16:43:36 +01:00
Daniel Marjamäki 22d6160624 Improve handling of decltype 2020-11-16 20:11:26 +01:00
Daniel Marjamäki 8b0699cd6a Revert "improved decltype() handling"
This reverts commit 6e8f77c519.
2020-11-15 21:32:05 +01:00
Daniel Marjamäki 6e8f77c519 improved decltype() handling 2020-11-15 20:58:17 +01:00
Daniel Marjamäki 54a93c4374 Fixed #9452 (FP syntaxError - _Pragma before struct with two constructors) 2020-11-15 15:03:47 +01:00
Daniel Marjamäki c95b0d2a51 Fixed #9977 (Template simplifier does not simplify in header) 2020-11-11 09:50:51 +01:00
uhziel aad29ddb9a
fix an error in Tokenizer::simplifyTypedef() (#2880) 2020-11-04 13:32:31 +01:00
Daniel Marjamäki 7804b28e70 AST: Tweaked debug output 2020-10-31 18:57:48 +01:00
Daniel Marjamäki 4eb829933e Tokenizer: Fixed unwanted unknownMacro warning for decltype 2020-10-27 09:08:13 +01:00
Daniel Marjamäki eb2c0bb6ee Fix TestExprEngine 2020-10-24 22:53:15 +02:00
Daniel Marjamäki 3876b601d5 Fixed #9476 (Tokenizer: report unknown macro) 2020-10-24 22:12:10 +02:00
Rikard Falkeborn d7a8e25d92
Fix #9647: Set correct enum value (#2856)
* Tokenize: Set varId for variables in enum

Set varIds in enum values. It was previously disabled in 5119ae84b8
to avoid issues with enums named the same as global variables. Take care
to only set varids to variables used to set the value of an enumerator,
not the enumerator itself. This is somewhat complicated by the fact that
at the time this happens, astOperand1(), astOperand2(), astParent() etc
are not set. The current implementation is not perfect, for example in
the code below, y will not have a varid set, but x and z will. This is
deemed sufficient for now.

            int x, y, z;
            enum E { a = f(x, y, z); };

* Fix #9647: Value of enums with variables as init values

C++ allows enum values to be set using constexprs, which cppcheck did
not handle before. To solve this, add a new pass to valueflow to update
enum values after global consts have been processed. In order to do so,
I moved all settings of enum values to valueflow. After setting the enum
values, we need another call to valueFlowNumber() to actually set users
of the enums.

There is still room for improvements, since each pass of
valueFlowGlobalConstVar() and valueFlowEnumValue() only sets variables
that are possible to set directly, and not if setting the value of a
variable allows us to set the value of another. For example

	constexpr int a = 5;
	constexpr int b = a + 5;
	enum E { X = a };
	constexpr E e = X;

Here both b and e will not have their values set, even though cppcheck
should be possible to figure out their values. That's for another PR
though.

This was tested by running test-my-pr.py with 500 packages. The only
difference was one error message in fairy-stockfish_11.1, where cppcheck
now printed the correct size of an array instead of 2147483648 which I
assume is some kind of default value. In that package, using a constexpr
when setting enum values is common, but as mentioned, there was no
change in the number of warnings.
2020-10-22 07:45:04 +02:00
Armin Müller 08cef9e815
Typos found by running "codespell" (#2846) 2020-10-15 19:24:13 +02:00
Daniel Marjamäki f956dee58a Tokenizer: Fixed simplification of parentheses in expression 'a=(b,c);' 2020-09-29 12:06:30 +02:00
Daniel Marjamäki ad9b2741cd varid: set varid for 'extern const char (*x[256]);'. This is a partial fix for #9922 2020-09-29 10:53:20 +02:00
Daniel Marjamäki 4c9db17742 Tokenizer: replace all or none of the alternative tokens in a translation unit 2020-09-28 19:01:31 +02:00
Daniel Marjamäki fa42d8c49c Fixed #9920 (Tokenizer: The keyword is not replaced, leads to false positive) 2020-09-28 16:35:50 +02:00
Oliver Stöneberg 7189b303ae
fixed some modernize-loop-convert clang-tidy warnings (#2815) 2020-09-21 19:30:47 +02:00
Daniel Marjamäki 3459f0da32 Fixed #9812 (False positive; syntax error 'using array_p = const array_t *;') 2020-09-14 21:59:58 +02:00
Daniel Marjamäki 687b44dbb7 Token: add flag for splitted variable declaration with initialization 2020-09-09 16:22:47 +02:00
Daniel Marjamäki e802d85315 Fixed #9445 (Syntax error on typeof word in C) 2020-09-08 17:12:54 +02:00
Daniel Marjamäki c0ef640304 Fixed #9881 ((Regression) Hang with operator() in function call) 2020-09-07 21:32:29 +02:00
Daniel Marjamäki cfd41fea83 Fixed #9879 (Tokenizer: Better handling of operator() '(*this)(...)') 2020-09-07 20:07:21 +02:00
Daniel Marjamäki 136ac2c643 Fixed #9266 (handle operator() better) 2020-09-06 21:02:06 +02:00
Daniel Marjamäki 9a943e7616 misra: rewrote rule 12.3 2020-09-06 11:33:37 +02:00
Daniel Marjamäki 7969bf7ae8 Token: Add 'isSplittedVarDecl attribute 2020-09-06 11:02:22 +02:00
Daniel Marjamäki 12d51ae5c4 Fixed #9809 (Tokenizer; Fix handling of variable declaration with @) 2020-09-02 13:04:33 +02:00
IOBYTE 8774e97f26
fix #9771 (Syntax error; operator != <> ()) (#2757) 2020-08-26 18:39:33 +02:00