r292052 - [code-completion] Fix crash when trying to do postfix completion of instance member inside a static function.

Argyrios Kyrtzidis via cfe-commits cfe-commits at lists.llvm.org
Sat Jan 14 22:11:04 PST 2017


Author: akirtzidis
Date: Sun Jan 15 00:11:04 2017
New Revision: 292052

URL: http://llvm.org/viewvc/llvm-project?rev=292052&view=rev
Log:
[code-completion] Fix crash when trying to do postfix completion of instance member inside a static function.

Modified:
    cfe/trunk/lib/Parse/ParseExpr.cpp
    cfe/trunk/test/CodeCompletion/member-access.cpp

Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=292052&r1=292051&r2=292052&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Sun Jan 15 00:11:04 2017
@@ -1652,9 +1652,10 @@ Parser::ParsePostfixExpressionSuffix(Exp
 
       if (Tok.is(tok::code_completion)) {
         // Code completion for a member access expression.
-        Actions.CodeCompleteMemberReferenceExpr(
-            getCurScope(), LHS.get(), OpLoc, OpKind == tok::arrow,
-            ExprStatementTokLoc == LHS.get()->getLocStart());
+        if (Expr *Base = LHS.get())
+          Actions.CodeCompleteMemberReferenceExpr(
+              getCurScope(), Base, OpLoc, OpKind == tok::arrow,
+              ExprStatementTokLoc == Base->getLocStart());
 
         cutOffParsing();
         return ExprError();

Modified: cfe/trunk/test/CodeCompletion/member-access.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeCompletion/member-access.cpp?rev=292052&r1=292051&r2=292052&view=diff
==============================================================================
--- cfe/trunk/test/CodeCompletion/member-access.cpp (original)
+++ cfe/trunk/test/CodeCompletion/member-access.cpp Sun Jan 15 00:11:04 2017
@@ -27,6 +27,16 @@ public:
 
 void test(const Proxy &p) {
   p->
+}
+
+struct Test1 {
+  Base1 b;
+
+  static void sfunc() {
+    b. // expected-error {{invalid use of member 'b' in static member function}}
+  }
+};
+
   // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:29:6 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
   // CHECK-CC1: Base1 : Base1::
   // CHECK-CC1: member1 : [#int#][#Base1::#]member1
@@ -39,4 +49,6 @@ void test(const Proxy &p) {
   // CHECK-CC1: memfun1 (Hidden) : [#void#]Base2::memfun1(<#int#>)
   // CHECK-CC1: memfun2 : [#void#][#Base3::#]memfun2(<#int#>)
   // CHECK-CC1: memfun3 : [#int#]memfun3(<#int#>)
-  
+
+// Make sure this doesn't crash
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:36:7 %s -verify




More information about the cfe-commits mailing list