Fix issue 8865: FP with dangling lifetime

This fixes:

```cpp
void f(uint32_t event, unsigned long op, const xen_ulong_t *args)
{
    struct __packed {
        uint32_t op;
        uint32_t args[6];
    } d;
    uint32_t *a = d.args;
}
```
This commit is contained in:
Paul Fultz II 2018-12-01 19:07:46 +01:00 committed by Daniel Marjamäki
parent 2c803a1ead
commit 229c45e7f8
2 changed files with 10 additions and 1 deletions

View File

@ -643,7 +643,8 @@ void CheckAutoVariables::checkVarLifetimeScope(const Token * start, const Token
} else if (isDeadScope(val.tokvalue, tok->scope())) { } else if (isDeadScope(val.tokvalue, tok->scope())) {
errorInvalidLifetime(tok, &val); errorInvalidLifetime(tok, &val);
break; break;
} else if (tok->variable() && !tok->variable()->isLocal() && !tok->variable()->isArgument() && } else if (tok->variable() && tok->variable()->declarationId() == tok->varId() &&
!tok->variable()->isLocal() && !tok->variable()->isArgument() &&
isInScope(val.tokvalue, tok->scope())) { isInScope(val.tokvalue, tok->scope())) {
errorDanglngLifetime(tok, &val); errorDanglngLifetime(tok, &val);
break; break;

View File

@ -1510,6 +1510,14 @@ private:
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
check("void f() {\n"
" struct b {\n"
" uint32_t f[6];\n"
" } d;\n"
" uint32_t *a = d.f;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// Make sure we dont hang // Make sure we dont hang
check("struct A;\n" check("struct A;\n"
"void f() {\n" "void f() {\n"