[PATCH] D50122: Complex Variable defined in InitCapture Crash fix

2018-08-08 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington added inline comments.



Comment at: lib/Sema/SemaTemplateInstantiate.cpp:2916-2918
+  if (const VarDecl *VD = dyn_cast(D))
+if (VD->isInitCapture())
+  return nullptr;

Why are we failing to find the instantiation of the VarDecl in this case? It 
seems to me like we should of picked it up in the `for` loop above. Is it not 
getting added to the LocalInstantiationScope? Or are we looking in the wrong 
LocalInstantiationScope?


Repository:
  rC Clang

https://reviews.llvm.org/D50122



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50122: Complex Variable defined in InitCapture Crash fix

2018-08-08 Thread Balaji Iyer via Phabricator via cfe-commits
bviyer added a comment.

Ping!


Repository:
  rC Clang

https://reviews.llvm.org/D50122



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50122: Complex Variable defined in InitCapture Crash fix

2018-08-02 Thread Balaji Iyer via Phabricator via cfe-commits
bviyer updated this revision to Diff 158870.
bviyer added a comment.

Simplified the case a bit more as requested by Erik. I also induced some errors 
in the test so that if someone symbolic-linked clang to /bin/true, the test 
will fail.


Repository:
  rC Clang

https://reviews.llvm.org/D50122

Files:
  lib/Sema/SemaTemplateInstantiate.cpp
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  test/SemaCXX/lambda-init-capture-vardefine.cpp


Index: test/SemaCXX/lambda-init-capture-vardefine.cpp
===
--- /dev/null
+++ test/SemaCXX/lambda-init-capture-vardefine.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -std=c++14  -fsyntax-only  -verify %s
+// RUN: %clang_cc1 -std=c++17  -fsyntax-only  -verify %s
+
+template  void func(k&&);
+
+template 
+void n(k o) {
+[f = o](auto) { // expected-note + {{instantiation of function template}}
+func([](auto)->int { return sizeof(f); }); // 
expected-error{{recursive template instantiation exceeded}} expected-note + 
{{instantiation of function template}}
+}(0);
+}
+
+template 
+void func(k &)
+{
+o(0);
+n(o); // expected-note + {{instantiation of function template}} 
expected-note + {{skipping}}
+}
+
+int main() {
+auto f = [](auto) {};
+func(f); // expected-note + {{instantiation of function template}}
+}
Index: lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4962,6 +4962,14 @@
   return cast(Inst);
 }
 
+// If the variable is in InitCapture and variable types are of type
+// mentioned in the above comment (the comment starting as "Normally
+// this function...") then its existance won't be known so we have to
+// make an exclusion for them.
+if (const VarDecl *VD = dyn_cast(D))
+  if (VD->isInitCapture())
+return nullptr;
+
 // If we didn't find the decl, then we must have a label decl that hasn't
 // been found yet.  Lazily instantiate it and return it now.
 assert(isa(D));
Index: lib/Sema/SemaTemplateInstantiate.cpp
===
--- lib/Sema/SemaTemplateInstantiate.cpp
+++ lib/Sema/SemaTemplateInstantiate.cpp
@@ -2913,6 +2913,9 @@
   // error recovery.
   if (isa(D))
 return nullptr;
+  if (const VarDecl *VD = dyn_cast(D))
+if (VD->isInitCapture())
+  return nullptr;
 
   // If we didn't find the decl, then we either have a sema bug, or we have a
   // forward reference to a label declaration.  Return null to indicate that


Index: test/SemaCXX/lambda-init-capture-vardefine.cpp
===
--- /dev/null
+++ test/SemaCXX/lambda-init-capture-vardefine.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -std=c++14  -fsyntax-only  -verify %s
+// RUN: %clang_cc1 -std=c++17  -fsyntax-only  -verify %s
+
+template  void func(k&&);
+
+template 
+void n(k o) {
+[f = o](auto) { // expected-note + {{instantiation of function template}}
+func([](auto)->int { return sizeof(f); }); // expected-error{{recursive template instantiation exceeded}} expected-note + {{instantiation of function template}}
+}(0);
+}
+
+template 
+void func(k &)
+{
+o(0);
+n(o); // expected-note + {{instantiation of function template}} expected-note + {{skipping}}
+}
+
+int main() {
+auto f = [](auto) {};
+func(f); // expected-note + {{instantiation of function template}}
+}
Index: lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4962,6 +4962,14 @@
   return cast(Inst);
 }
 
+// If the variable is in InitCapture and variable types are of type
+// mentioned in the above comment (the comment starting as "Normally
+// this function...") then its existance won't be known so we have to
+// make an exclusion for them.
+if (const VarDecl *VD = dyn_cast(D))
+  if (VD->isInitCapture())
+return nullptr;
+
 // If we didn't find the decl, then we must have a label decl that hasn't
 // been found yet.  Lazily instantiate it and return it now.
 assert(isa(D));
Index: lib/Sema/SemaTemplateInstantiate.cpp
===
--- lib/Sema/SemaTemplateInstantiate.cpp
+++ lib/Sema/SemaTemplateInstantiate.cpp
@@ -2913,6 +2913,9 @@
   // error recovery.
   if (isa(D))
 return nullptr;
+  if (const VarDecl *VD = dyn_cast(D))
+if (VD->isInitCapture())
+  return nullptr;
 
   // If we didn't find the decl, then we either have a sema bug, or we have a
   // forward reference to a label declaration.  Return null to indicate that
___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[PATCH] D50122: Complex Variable defined in InitCapture Crash fix

2018-08-01 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added inline comments.



Comment at: test/SemaCXX/lambda-init-capture-vardefine.cpp:3
+// RUN: %clang_cc1 -std=c++17  -fsyntax-only -verify %s
+// expected-no-diagnostics
+

These kinds of tests that don't check for any output are a bit dangerous, 
because they will also succeed if clang is symlinked to `/bin/true`.


Repository:
  rC Clang

https://reviews.llvm.org/D50122



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50122: Complex Variable defined in InitCapture Crash fix

2018-07-31 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington added a comment.

Hi Balaji,
Can you try to manually reduce the attached testcase? Its really difficult to 
understand exactly what is actually happening here, and why your fix is 
correct, without having a minimal reproducer. Ideally there would just be a few 
decls that succinctly demonstrate what the problem is.

Thanks!


Repository:
  rC Clang

https://reviews.llvm.org/D50122



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50122: Complex Variable defined in InitCapture Crash fix

2018-07-31 Thread Balaji Iyer via Phabricator via cfe-commits
bviyer created this revision.
bviyer added reviewers: erik.pilkington, ahatanak, arphaman, dexonsmith.
Herald added a subscriber: cfe-commits.

When a variable is defined in the init capture and it is of type struct that is 
dependent on additional structure, its definition is not found. An exception is 
created in the findInstantiatedDecl () function.


Repository:
  rC Clang

https://reviews.llvm.org/D50122

Files:
  lib/Sema/SemaTemplateInstantiate.cpp
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  test/SemaCXX/lambda-init-capture-vardefine.cpp


Index: test/SemaCXX/lambda-init-capture-vardefine.cpp
===
--- /dev/null
+++ test/SemaCXX/lambda-init-capture-vardefine.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -std=c++14  -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++17  -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+template  using a = void;
+template  struct c { static const int d = b; };
+template > struct e : c {};
+template  g h(int);
+template  decltype(h(0)) i;
+template  struct e())>>;
+template  auto func(k &&);
+template  struct l {
+  template  static auto n(k o) {
+return [f{o}](auto) { func([](auto...) -> decltype(f) {}); };
+  }
+};
+template  auto func(k &) { return l::d>::n(o); }
+int main(void) {
+  auto f = [](auto) {};
+  func(f)(1);
+}
Index: lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4962,6 +4962,14 @@
   return cast(Inst);
 }
 
+// If the variable is in InitCapture and variable types are of type
+// mentioned in the above comment (the comment starting as "Normally
+// this function...") then its existance won't be known so we have to
+// make an exclusion for them.
+if (const VarDecl *VD = dyn_cast(D))
+  if (VD->isInitCapture())
+return nullptr;
+
 // If we didn't find the decl, then we must have a label decl that hasn't
 // been found yet.  Lazily instantiate it and return it now.
 assert(isa(D));
Index: lib/Sema/SemaTemplateInstantiate.cpp
===
--- lib/Sema/SemaTemplateInstantiate.cpp
+++ lib/Sema/SemaTemplateInstantiate.cpp
@@ -2913,6 +2913,9 @@
   // error recovery.
   if (isa(D))
 return nullptr;
+  if (const VarDecl *VD = dyn_cast(D))
+if (VD->isInitCapture())
+  return nullptr;
 
   // If we didn't find the decl, then we either have a sema bug, or we have a
   // forward reference to a label declaration.  Return null to indicate that


Index: test/SemaCXX/lambda-init-capture-vardefine.cpp
===
--- /dev/null
+++ test/SemaCXX/lambda-init-capture-vardefine.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -std=c++14  -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++17  -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+template  using a = void;
+template  struct c { static const int d = b; };
+template > struct e : c {};
+template  g h(int);
+template  decltype(h(0)) i;
+template  struct e())>>;
+template  auto func(k &&);
+template  struct l {
+  template  static auto n(k o) {
+return [f{o}](auto) { func([](auto...) -> decltype(f) {}); };
+  }
+};
+template  auto func(k &) { return l::d>::n(o); }
+int main(void) {
+  auto f = [](auto) {};
+  func(f)(1);
+}
Index: lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4962,6 +4962,14 @@
   return cast(Inst);
 }
 
+// If the variable is in InitCapture and variable types are of type
+// mentioned in the above comment (the comment starting as "Normally
+// this function...") then its existance won't be known so we have to
+// make an exclusion for them.
+if (const VarDecl *VD = dyn_cast(D))
+  if (VD->isInitCapture())
+return nullptr;
+
 // If we didn't find the decl, then we must have a label decl that hasn't
 // been found yet.  Lazily instantiate it and return it now.
 assert(isa(D));
Index: lib/Sema/SemaTemplateInstantiate.cpp
===
--- lib/Sema/SemaTemplateInstantiate.cpp
+++ lib/Sema/SemaTemplateInstantiate.cpp
@@ -2913,6 +2913,9 @@
   // error recovery.
   if (isa(D))
 return nullptr;
+  if (const VarDecl *VD = dyn_cast(D))
+if (VD->isInitCapture())
+  return nullptr;
 
   // If we didn't find the decl, then we either have a sema bug, or we have a
   // forward reference to a label declaration.  Return null to indicate that
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits