Fix #11838 FP uninitvar with label matching variable name (#5251)

This commit is contained in:
chrchr-github 2023-07-20 10:45:44 +02:00 committed by GitHub
parent d2546d5252
commit a6b0129725
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -4757,7 +4757,8 @@ void Tokenizer::setVarIdPass1()
continue; continue;
} }
if (!scopeStack.top().isEnum || !(Token::Match(tok->previous(), "{|,") && Token::Match(tok->next(), ",|=|}"))) { if ((!scopeStack.top().isEnum || !(Token::Match(tok->previous(), "{|,") && Token::Match(tok->next(), ",|=|}"))) &&
!Token::simpleMatch(tok->next(), ": ;")) {
const std::map<std::string, nonneg int>::const_iterator it = variableMap.map(globalNamespace).find(tok->str()); const std::map<std::string, nonneg int>::const_iterator it = variableMap.map(globalNamespace).find(tok->str());
if (it != variableMap.map(globalNamespace).end()) { if (it != variableMap.map(globalNamespace).end()) {
tok->varId(it->second); tok->varId(it->second);

View File

@ -2785,6 +2785,17 @@ private:
" break;\n" " break;\n"
" }\n" " }\n"
"}", "test.c")); "}", "test.c"));
ASSERT_EQUALS("1: int * f ( ) {\n" // #11838
"2: int * label@1 ; label@1 = 0 ;\n"
"3: label : ;\n"
"4: return label@1 ;\n"
"5: }\n",
tokenize("int* f() {\n"
" int* label = 0;\n"
"label:\n"
" return label;\n"
"}"));
} }
void varid_structinit() { // #6406 void varid_structinit() { // #6406