summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2018-07-30 07:19:54 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2018-07-30 07:19:54 +0000
commit5f2a3492802f69dfcb99dad75df4a50ade33493e (patch)
tree04a44a05c61cd3275f16af3332627420eb68e8d8
parent3327bcaeb1e019aac9d2e5028980e91852f28d15 (diff)
downloadbcm5719-llvm-5f2a3492802f69dfcb99dad75df4a50ade33493e.tar.gz
bcm5719-llvm-5f2a3492802f69dfcb99dad75df4a50ade33493e.zip
PR38355 Prevent infinite recursion when checking initializer lifetime if
an initializer is self-referential. llvm-svn: 338230
-rw-r--r--clang/lib/Sema/SemaInit.cpp3
-rw-r--r--clang/test/SemaCXX/warn-dangling-local.cpp6
2 files changed, 8 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 3ee5ec4a492..be0a74d8f85 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/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<DeclRefExpr>(L)) {
auto *VD = dyn_cast<VarDecl>(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/clang/test/SemaCXX/warn-dangling-local.cpp b/clang/test/SemaCXX/warn-dangling-local.cpp
index 19a722f84d1..5c1d5697294 100644
--- a/clang/test/SemaCXX/warn-dangling-local.cpp
+++ b/clang/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]};
+}
OpenPOWER on IntegriCloud