[PATCH] D91821: Fix PR42049 - Crash when parsing bad decltype use within template argument list after name assumed to be a function template

2020-12-06 Thread Faisal Vali via Phabricator via cfe-commits
faisalv updated this revision to Diff 309809.
faisalv edited the summary of this revision.
faisalv added a comment.

Per Richard's suggestion, instead of including the cached tokens into the 
decltype annotation, i revert the cache to match the end of where we think the 
(broken) decltype annotated token should end.

Thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91821/new/

https://reviews.llvm.org/D91821

Files:
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/test/Parser/PR42049.cpp


Index: clang/test/Parser/PR42049.cpp
===
--- /dev/null
+++ clang/test/Parser/PR42049.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// https://bugs.llvm.org/show_bug.cgi?id=42049
+
+void f() {
+  g(); // expected-error  {{use of undeclared identifier}} 
expected-error {{expected}}
+  g2 void f2() {
+  g(); // expected-error {{use of undeclared identifier}} 
expected-error {{expected}}
+  g2Index: clang/test/Parser/PR42049.cpp
===
--- /dev/null
+++ clang/test/Parser/PR42049.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// https://bugs.llvm.org/show_bug.cgi?id=42049
+
+void f() {
+  g(); // expected-error  {{use of undeclared identifier}} expected-error {{expected}}
+  g2 void f2() {
+  g(); // expected-error {{use of undeclared identifier}} expected-error {{expected}}
+  g2___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D91821: Fix PR42049 - Crash when parsing bad decltype use within template argument list after name assumed to be a function template

2020-11-20 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/lib/Parse/ParseDeclCXX.cpp:1055
+  // semi-colon.
+  EndLoc = PP.getLastCachedTokenLocation();
+}

It seems to me that either `EndLoc` was miscomputed and should already point to 
the last token that we skipped over, in which case we should fix 
`ParseDecltypeSpecifier` to return the correct source location, or `EndLoc` is 
correct and we should revert back to the corresponding token and only annotate 
that portion of the token stream as the decltype specifier. (Or maybe a third 
option: `EndLoc` is meaningless when the type specifier is erroneous, in which 
case this code is still wrong because it's using that value in the case where 
backtracking is not enabled.)

Rolling back the token stream to the token corresponding to `EndLoc` seems 
likely to give us the best error recovery here, assuming that `EndLoc` is 
currently set to the token that we think is the last one that's intended to be 
part of the decltype specifier.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91821/new/

https://reviews.llvm.org/D91821

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


[PATCH] D91821: Fix PR42049 - Crash when parsing bad decltype use within template argument list after name assumed to be a function template

2020-11-19 Thread Faisal Vali via Phabricator via cfe-commits
faisalv created this revision.
faisalv added a reviewer: rsmith.
faisalv added a project: clang.
Herald added a subscriber: cfe-commits.
faisalv requested review of this revision.

https://bugs.llvm.org/show_bug.cgi?id=42049

Currently clang, in the following code, when tentatively parsing the 
template-argument-list recognizes the error, and skips till the semi-colon.  
But when annotating the broken decltype specifier token (in an effort to 
backtrack gracefully and continue parsing), it appears we should include all 
the cached tokens  that were skipped until the sem-colon as an annotated subset 
of our annot_decltype token.  Not doing so results in a book-keeping assertion 
failure.

void f() {

  g();

}

This situation did not seem to arise prior to 
https://github.com/llvm/llvm-project/commit/b23c5e8c3df850177449268c5ca7dbf986157525
 - which implements assumption of names as function templates even if no 
function with that name is found.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D91821

Files:
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/test/Parser/PR42049.cpp


Index: clang/test/Parser/PR42049.cpp
===
--- /dev/null
+++ clang/test/Parser/PR42049.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// https://bugs.llvm.org/show_bug.cgi?id=42049
+
+void f() {
+  g(); // expected-error 2 {{expected}} expected-note {{to match}}
+  g2 void f2() {
+  g(); // expected-error 2 {{expected}} expected-note {{to match}}
+  g2Index: clang/test/Parser/PR42049.cpp
===
--- /dev/null
+++ clang/test/Parser/PR42049.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// https://bugs.llvm.org/show_bug.cgi?id=42049
+
+void f() {
+  g(); // expected-error 2 {{expected}} expected-note {{to match}}
+  g2 void f2() {
+  g(); // expected-error 2 {{expected}} expected-note {{to match}}
+  g2___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits