[PATCH] D37382: Fixed a crash in code completion.

2017-09-08 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL312788: Fixed a crash in code completion. (authored by 
ibiryukov).

Repository:
  rL LLVM

https://reviews.llvm.org/D37382

Files:
  cfe/trunk/lib/Parse/ParseDecl.cpp
  cfe/trunk/test/CodeCompletion/crash-func-init.cpp


Index: cfe/trunk/test/CodeCompletion/crash-func-init.cpp
===
--- cfe/trunk/test/CodeCompletion/crash-func-init.cpp
+++ cfe/trunk/test/CodeCompletion/crash-func-init.cpp
@@ -0,0 +1,4 @@
+int (*foo(int a))(flo
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:1:21 %s -o - \
+// RUN:| FileCheck %s
+// CHECK: COMPLETION: float
Index: cfe/trunk/lib/Parse/ParseDecl.cpp
===
--- cfe/trunk/lib/Parse/ParseDecl.cpp
+++ cfe/trunk/lib/Parse/ParseDecl.cpp
@@ -2264,11 +2264,23 @@
   Actions.ActOnCXXEnterDeclInitializer(getCurScope(), ThisDecl);
 }
 
-if (ParseExpressionList(Exprs, CommaLocs, [&] {
-  Actions.CodeCompleteConstructor(getCurScope(),
- 
cast(ThisDecl)->getType()->getCanonicalTypeInternal(),
-  ThisDecl->getLocation(), Exprs);
-   })) {
+llvm::function_ref ExprListCompleter;
+auto ThisVarDecl = dyn_cast_or_null(ThisDecl);
+auto ConstructorCompleter = [&, ThisVarDecl] {
+  Actions.CodeCompleteConstructor(
+  getCurScope(), ThisVarDecl->getType()->getCanonicalTypeInternal(),
+  ThisDecl->getLocation(), Exprs);
+};
+if (ThisVarDecl) {
+  // ParseExpressionList can sometimes succeed even when ThisDecl is not
+  // VarDecl. This is an error and it is reported in a call to
+  // Actions.ActOnInitializerError(). However, we call
+  // CodeCompleteConstructor only on VarDecls, falling back to default
+  // completer in other cases.
+  ExprListCompleter = ConstructorCompleter;
+}
+
+if (ParseExpressionList(Exprs, CommaLocs, ExprListCompleter)) {
   Actions.ActOnInitializerError(ThisDecl);
   SkipUntil(tok::r_paren, StopAtSemi);
 


Index: cfe/trunk/test/CodeCompletion/crash-func-init.cpp
===
--- cfe/trunk/test/CodeCompletion/crash-func-init.cpp
+++ cfe/trunk/test/CodeCompletion/crash-func-init.cpp
@@ -0,0 +1,4 @@
+int (*foo(int a))(flo
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:1:21 %s -o - \
+// RUN:| FileCheck %s
+// CHECK: COMPLETION: float
Index: cfe/trunk/lib/Parse/ParseDecl.cpp
===
--- cfe/trunk/lib/Parse/ParseDecl.cpp
+++ cfe/trunk/lib/Parse/ParseDecl.cpp
@@ -2264,11 +2264,23 @@
   Actions.ActOnCXXEnterDeclInitializer(getCurScope(), ThisDecl);
 }
 
-if (ParseExpressionList(Exprs, CommaLocs, [&] {
-  Actions.CodeCompleteConstructor(getCurScope(),
- cast(ThisDecl)->getType()->getCanonicalTypeInternal(),
-  ThisDecl->getLocation(), Exprs);
-   })) {
+llvm::function_ref ExprListCompleter;
+auto ThisVarDecl = dyn_cast_or_null(ThisDecl);
+auto ConstructorCompleter = [&, ThisVarDecl] {
+  Actions.CodeCompleteConstructor(
+  getCurScope(), ThisVarDecl->getType()->getCanonicalTypeInternal(),
+  ThisDecl->getLocation(), Exprs);
+};
+if (ThisVarDecl) {
+  // ParseExpressionList can sometimes succeed even when ThisDecl is not
+  // VarDecl. This is an error and it is reported in a call to
+  // Actions.ActOnInitializerError(). However, we call
+  // CodeCompleteConstructor only on VarDecls, falling back to default
+  // completer in other cases.
+  ExprListCompleter = ConstructorCompleter;
+}
+
+if (ParseExpressionList(Exprs, CommaLocs, ExprListCompleter)) {
   Actions.ActOnInitializerError(ThisDecl);
   SkipUntil(tok::r_paren, StopAtSemi);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D37382: Fixed a crash in code completion.

2017-09-08 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 114349.
ilya-biryukov added a comment.

- Fix to account for change in the interface of ParseExpressionList.


https://reviews.llvm.org/D37382

Files:
  lib/Parse/ParseDecl.cpp
  test/CodeCompletion/crash-func-init.cpp


Index: test/CodeCompletion/crash-func-init.cpp
===
--- /dev/null
+++ test/CodeCompletion/crash-func-init.cpp
@@ -0,0 +1,4 @@
+int (*foo(int a))(flo
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:1:21 %s -o - \
+// RUN:| FileCheck %s
+// CHECK: COMPLETION: float
Index: lib/Parse/ParseDecl.cpp
===
--- lib/Parse/ParseDecl.cpp
+++ lib/Parse/ParseDecl.cpp
@@ -2264,11 +2264,23 @@
   Actions.ActOnCXXEnterDeclInitializer(getCurScope(), ThisDecl);
 }
 
-if (ParseExpressionList(Exprs, CommaLocs, [&] {
-  Actions.CodeCompleteConstructor(getCurScope(),
- 
cast(ThisDecl)->getType()->getCanonicalTypeInternal(),
-  ThisDecl->getLocation(), Exprs);
-   })) {
+llvm::function_ref ExprListCompleter;
+auto ThisVarDecl = dyn_cast_or_null(ThisDecl);
+auto ConstructorCompleter = [&, ThisVarDecl] {
+  Actions.CodeCompleteConstructor(
+  getCurScope(), ThisVarDecl->getType()->getCanonicalTypeInternal(),
+  ThisDecl->getLocation(), Exprs);
+};
+if (ThisVarDecl) {
+  // ParseExpressionList can sometimes succeed even when ThisDecl is not
+  // VarDecl. This is an error and it is reported in a call to
+  // Actions.ActOnInitializerError(). However, we call
+  // CodeCompleteConstructor only on VarDecls, falling back to default
+  // completer in other cases.
+  ExprListCompleter = ConstructorCompleter;
+}
+
+if (ParseExpressionList(Exprs, CommaLocs, ExprListCompleter)) {
   Actions.ActOnInitializerError(ThisDecl);
   SkipUntil(tok::r_paren, StopAtSemi);
 


Index: test/CodeCompletion/crash-func-init.cpp
===
--- /dev/null
+++ test/CodeCompletion/crash-func-init.cpp
@@ -0,0 +1,4 @@
+int (*foo(int a))(flo
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:1:21 %s -o - \
+// RUN:| FileCheck %s
+// CHECK: COMPLETION: float
Index: lib/Parse/ParseDecl.cpp
===
--- lib/Parse/ParseDecl.cpp
+++ lib/Parse/ParseDecl.cpp
@@ -2264,11 +2264,23 @@
   Actions.ActOnCXXEnterDeclInitializer(getCurScope(), ThisDecl);
 }
 
-if (ParseExpressionList(Exprs, CommaLocs, [&] {
-  Actions.CodeCompleteConstructor(getCurScope(),
- cast(ThisDecl)->getType()->getCanonicalTypeInternal(),
-  ThisDecl->getLocation(), Exprs);
-   })) {
+llvm::function_ref ExprListCompleter;
+auto ThisVarDecl = dyn_cast_or_null(ThisDecl);
+auto ConstructorCompleter = [&, ThisVarDecl] {
+  Actions.CodeCompleteConstructor(
+  getCurScope(), ThisVarDecl->getType()->getCanonicalTypeInternal(),
+  ThisDecl->getLocation(), Exprs);
+};
+if (ThisVarDecl) {
+  // ParseExpressionList can sometimes succeed even when ThisDecl is not
+  // VarDecl. This is an error and it is reported in a call to
+  // Actions.ActOnInitializerError(). However, we call
+  // CodeCompleteConstructor only on VarDecls, falling back to default
+  // completer in other cases.
+  ExprListCompleter = ConstructorCompleter;
+}
+
+if (ParseExpressionList(Exprs, CommaLocs, ExprListCompleter)) {
   Actions.ActOnInitializerError(ThisDecl);
   SkipUntil(tok::r_paren, StopAtSemi);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D37382: Fixed a crash in code completion.

2017-09-08 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer accepted this revision.
bkramer added a comment.
This revision is now accepted and ready to land.

lg


https://reviews.llvm.org/D37382



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


[PATCH] D37382: Fixed a crash in code completion.

2017-09-01 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov created this revision.

The crash occured when FunctionDecl was parsed with an initializer.


https://reviews.llvm.org/D37382

Files:
  lib/Parse/ParseDecl.cpp
  test/CodeCompletion/crash-func-init.cpp


Index: test/CodeCompletion/crash-func-init.cpp
===
--- /dev/null
+++ test/CodeCompletion/crash-func-init.cpp
@@ -0,0 +1,4 @@
+int (*foo(int a))(flo
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:1:21 %s -o - \
+// RUN:| FileCheck %s
+// CHECK: COMPLETION: float
Index: lib/Parse/ParseDecl.cpp
===
--- lib/Parse/ParseDecl.cpp
+++ lib/Parse/ParseDecl.cpp
@@ -2264,11 +2264,21 @@
   Actions.ActOnCXXEnterDeclInitializer(getCurScope(), ThisDecl);
 }
 
-if (ParseExpressionList(Exprs, CommaLocs, [&] {
-  Actions.CodeCompleteConstructor(getCurScope(),
- 
cast(ThisDecl)->getType()->getCanonicalTypeInternal(),
-  ThisDecl->getLocation(), Exprs);
-   })) {
+std::function ExprListCompleter = nullptr;
+if (auto ThisVarDecl = dyn_cast_or_null(ThisDecl)) {
+  // ParseExpressionList can sometimes succeed even when ThisDecl is not
+  // VarDecl. This is an error and it is reported in a call to
+  // Actions.ActOnInitializerError(). However, we call
+  // CodeCompleteConstructor only on VarDecls, falling back to default
+  // completer in other cases.
+  ExprListCompleter = [&, ThisVarDecl] {
+Actions.CodeCompleteConstructor(
+getCurScope(), ThisVarDecl->getType()->getCanonicalTypeInternal(),
+ThisDecl->getLocation(), Exprs);
+  };
+}
+
+if (ParseExpressionList(Exprs, CommaLocs, ExprListCompleter)) {
   Actions.ActOnInitializerError(ThisDecl);
   SkipUntil(tok::r_paren, StopAtSemi);
 


Index: test/CodeCompletion/crash-func-init.cpp
===
--- /dev/null
+++ test/CodeCompletion/crash-func-init.cpp
@@ -0,0 +1,4 @@
+int (*foo(int a))(flo
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:1:21 %s -o - \
+// RUN:| FileCheck %s
+// CHECK: COMPLETION: float
Index: lib/Parse/ParseDecl.cpp
===
--- lib/Parse/ParseDecl.cpp
+++ lib/Parse/ParseDecl.cpp
@@ -2264,11 +2264,21 @@
   Actions.ActOnCXXEnterDeclInitializer(getCurScope(), ThisDecl);
 }
 
-if (ParseExpressionList(Exprs, CommaLocs, [&] {
-  Actions.CodeCompleteConstructor(getCurScope(),
- cast(ThisDecl)->getType()->getCanonicalTypeInternal(),
-  ThisDecl->getLocation(), Exprs);
-   })) {
+std::function ExprListCompleter = nullptr;
+if (auto ThisVarDecl = dyn_cast_or_null(ThisDecl)) {
+  // ParseExpressionList can sometimes succeed even when ThisDecl is not
+  // VarDecl. This is an error and it is reported in a call to
+  // Actions.ActOnInitializerError(). However, we call
+  // CodeCompleteConstructor only on VarDecls, falling back to default
+  // completer in other cases.
+  ExprListCompleter = [&, ThisVarDecl] {
+Actions.CodeCompleteConstructor(
+getCurScope(), ThisVarDecl->getType()->getCanonicalTypeInternal(),
+ThisDecl->getLocation(), Exprs);
+  };
+}
+
+if (ParseExpressionList(Exprs, CommaLocs, ExprListCompleter)) {
   Actions.ActOnInitializerError(ThisDecl);
   SkipUntil(tok::r_paren, StopAtSemi);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits