Thread safety analysis no longer hands when analyzing a self-referencing initializer.

This fixes PR38640.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@340636 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Aaron Ballman 2018-08-24 18:48:35 +00:00
parent 3ad50fd19c
commit 8e7c1967e0
2 changed files with 11 additions and 0 deletions

View File

@ -1656,6 +1656,9 @@ void BuildLockset::checkAccess(const Expr *Exp, AccessKind AK,
const auto *VD = dyn_cast<VarDecl>(DRE->getDecl()->getCanonicalDecl());
if (VD && VD->isLocalVarDecl() && VD->getType()->isReferenceType()) {
if (const auto *E = VD->getInit()) {
// Guard against self-initialization. e.g., int &i = i;
if (E == Exp)
break;
Exp = E;
continue;
}

View File

@ -5503,3 +5503,11 @@ namespace ReturnScopedLockable {
return ptr->f();
}
}
namespace PR38640 {
void f() {
// Self-referencing assignment previously caused an infinite loop when thread
// safety analysis was enabled.
int &i = i; // expected-warning {{reference 'i' is not yet bound to a value when used within its own initialization}}
}
}