forked from OSchip/llvm-project
[analyzer] Don't crash when a construction is followed by an uninitialized variable.
This could happen due to unfortunate CFG coincidences. PR19579 llvm-svn: 207486
This commit is contained in:
parent
cf37110920
commit
bcd889730d
|
|
@ -128,7 +128,7 @@ static const MemRegion *getRegionForConstructedObject(
|
||||||
if (Optional<CFGStmt> StmtElem = Next.getAs<CFGStmt>()) {
|
if (Optional<CFGStmt> StmtElem = Next.getAs<CFGStmt>()) {
|
||||||
if (const DeclStmt *DS = dyn_cast<DeclStmt>(StmtElem->getStmt())) {
|
if (const DeclStmt *DS = dyn_cast<DeclStmt>(StmtElem->getStmt())) {
|
||||||
if (const VarDecl *Var = dyn_cast<VarDecl>(DS->getSingleDecl())) {
|
if (const VarDecl *Var = dyn_cast<VarDecl>(DS->getSingleDecl())) {
|
||||||
if (Var->getInit()->IgnoreImplicit() == CE) {
|
if (Var->getInit() && Var->getInit()->IgnoreImplicit() == CE) {
|
||||||
SVal LValue = State->getLValue(Var, LCtx);
|
SVal LValue = State->getLValue(Var, LCtx);
|
||||||
QualType Ty = Var->getType();
|
QualType Ty = Var->getType();
|
||||||
LValue = makeZeroElementRegion(State, LValue, Ty);
|
LValue = makeZeroElementRegion(State, LValue, Ty);
|
||||||
|
|
|
||||||
|
|
@ -674,3 +674,30 @@ namespace InitializerList {
|
||||||
clang_analyzer_eval(list->usedInitializerList); // expected-warning{{UNKNOWN}}
|
clang_analyzer_eval(list->usedInitializerList); // expected-warning{{UNKNOWN}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace PR19579 {
|
||||||
|
class C {};
|
||||||
|
|
||||||
|
struct S {
|
||||||
|
C c;
|
||||||
|
int i;
|
||||||
|
};
|
||||||
|
|
||||||
|
void f() {
|
||||||
|
C();
|
||||||
|
int a;
|
||||||
|
}
|
||||||
|
|
||||||
|
void g() {
|
||||||
|
// This order triggers the initialization of the inner "a" after the
|
||||||
|
// constructor for "C" is run, which used to confuse the analyzer
|
||||||
|
// (is "C()" the initialization of "a"?).
|
||||||
|
struct S s = {
|
||||||
|
C(),
|
||||||
|
({
|
||||||
|
int a, b = 0;
|
||||||
|
0;
|
||||||
|
})
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue