Skip to content

Commit 990d14f

Browse files
committed
Fixed danmar#6328: Use isAttributeNoreturn() whereever we also check Library::isnoreturn().
1 parent 9e60f58 commit 990d14f

4 files changed

Lines changed: 6 additions & 5 deletions

File tree

lib/checkmemoryleak.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::list<co
572572
return 0;
573573
}
574574

575-
if (_settings->library.isnoreturn(tok->str()) && tok->strAt(-1) != "=")
575+
if ((_settings->library.isnoreturn(tok->str()) || (tok->function() && tok->function()->isAttributeNoreturn())) && tok->strAt(-1) != "=")
576576
return "exit";
577577

578578
if (varid > 0 && (getReallocationType(tok, varid) != No || getDeallocationType(tok, varid) != No))
@@ -1277,7 +1277,7 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
12771277
// just add a "::use"
12781278
// The "::use" means that a member function was probably called but it wasn't analysed further
12791279
else if (classmember) {
1280-
if (_settings->library.isnoreturn(tok->str()))
1280+
if (_settings->library.isnoreturn(tok->str()) || (tok->function() && tok->function()->isAttributeNoreturn()))
12811281
addtoken(&rettail, tok, "exit");
12821282

12831283
else if (!test_white_list_with_lib(tok->str(), _settings)) {

lib/checkother.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,7 @@ void CheckOther::checkUnreachableCode()
11521152
} else if (Token::Match(tok, "goto %any% ;")) {
11531153
secondBreak = tok->tokAt(3);
11541154
labelName = tok->next();
1155-
} else if (Token::Match(tok, "%var% (") && _settings->library.isnoreturn(tok->str()) && tok->strAt(-1) != ".") {
1155+
} else if (Token::Match(tok, "%var% (") && (_settings->library.isnoreturn(tok->str()) || (tok->function() && tok->function()->isAttributeNoreturn())) && tok->strAt(-1) != ".") {
11561156
if ((!tok->function() || (tok->function()->token != tok && tok->function()->tokenDef != tok)) && tok->linkAt(1)->strAt(1) != "{")
11571157
secondBreak = tok->linkAt(1)->tokAt(2);
11581158
}

lib/library.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "tokenlist.h"
2323
#include "mathlib.h"
2424
#include "token.h"
25+
#include "symboldatabase.h"
2526

2627
#include <string>
2728
#include <algorithm>
@@ -526,7 +527,7 @@ bool Library::isScopeNoReturn(const Token *end, std::string *unknownFunc) const
526527
if (funcname->str() == "exit")
527528
return true;
528529
if (!isnotnoreturn(funcname->str())) {
529-
if (unknownFunc && !isnoreturn(funcname->str()))
530+
if (unknownFunc && !(isnoreturn(funcname->str()) || (funcname->function() && funcname->function()->isAttributeNoreturn())))
530531
*unknownFunc = funcname->str();
531532
return true;
532533
}

lib/tokenize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4259,7 +4259,7 @@ void Tokenizer::simplifyFlowControl()
42594259

42604260
} else if (Token::Match(tok,"return|goto") ||
42614261
(Token::Match(tok->previous(), "[;{}] %var% (") &&
4262-
_settings->library.isnoreturn(tok->str())) ||
4262+
(_settings->library.isnoreturn(tok->str()) || (tok->function() && tok->function()->isAttributeNoreturn()))) ||
42634263
(tok->str() == "throw" && !isC())) {
42644264
//TODO: ensure that we exclude user-defined 'exit|abort|throw', except for 'noreturn'
42654265
//catch the first ';'

0 commit comments

Comments
 (0)