From: Richard Smith Date: Mon, 30 Jul 2018 07:19:54 +0000 (+0000) Subject: PR38355 Prevent infinite recursion when checking initializer lifetime if X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=884df2d15b81bdc0bdb562af2ba90586848a48b7;p=clang PR38355 Prevent infinite recursion when checking initializer lifetime if an initializer is self-referential. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@338230 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index 3ee5ec4a49..be0a74d8f8 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -6570,7 +6570,8 @@ static void visitLocalsRetainedByInitializer(IndirectLocalPath &Path, [&](IndirectLocalPath &Path, Local L, ReferenceKind RK) -> bool { if (auto *DRE = dyn_cast(L)) { auto *VD = dyn_cast(DRE->getDecl()); - if (VD && VD->getType().isConstQualified() && VD->getInit()) { + if (VD && VD->getType().isConstQualified() && VD->getInit() && + !isVarOnPath(Path, VD)) { Path.push_back({IndirectLocalPathEntry::VarInit, DRE, VD}); visitLocalsRetainedByInitializer(Path, VD->getInit(), Visit, true); } diff --git a/test/SemaCXX/warn-dangling-local.cpp b/test/SemaCXX/warn-dangling-local.cpp index 19a722f84d..5c1d569729 100644 --- a/test/SemaCXX/warn-dangling-local.cpp +++ b/test/SemaCXX/warn-dangling-local.cpp @@ -18,3 +18,9 @@ void f() { // points to, which doesn't live long enough. int *const &s = (int *const &)T{1, 2, 3}; // expected-warning {{temporary bound to local reference 's' will be destroyed at the end of the full-expression}} } + +// PR38355 +void g() { + const int a[] = {a[0]}; + const int b[] = {a[0]}; +}