r348590 - [CodeComplete] Fix assertion failure

Ilya Biryukov via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 7 05:17:52 PST 2018


Author: ibiryukov
Date: Fri Dec  7 05:17:52 2018
New Revision: 348590

URL: http://llvm.org/viewvc/llvm-project?rev=348590&view=rev
Log:
[CodeComplete] Fix assertion failure

Summary:
...that fires when running completion inside an argument of
UnresolvedMemberExpr (see the added test).

The assertion that fires is from Sema::TryObjectArgumentInitialization:

    assert(FromClassification.isLValue());

This happens because Sema::AddFunctionCandidates does not account for
object types which are pointers. It ends up classifying them incorrectly.
All usages of the function outside code completion are used to run
overload resolution for operators. In those cases the object type being
passed is always a non-pointer type, so it's not surprising the function
did not expect a pointer in the object argument.

However, code completion reuses the same function and calls it with the
object argument coming from UnresolvedMemberExpr, which can be a pointer
if the member expr is an arrow ('->') access.

Extending AddFunctionCandidates to allow pointer object types does not
seem too crazy since all the functions down the call chain can properly
handle pointer object types if we properly classify the object argument
as an l-value, i.e. the classification of the implicitly dereferenced
pointer.

Reviewers: kadircet

Reviewed By: kadircet

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D55331

Added:
    cfe/trunk/test/CodeCompletion/signatures-crash.cpp
Modified:
    cfe/trunk/lib/Sema/SemaOverload.cpp

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=348590&r1=348589&r2=348590&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Fri Dec  7 05:17:52 2018
@@ -6429,7 +6429,12 @@ void Sema::AddFunctionCandidates(const U
         if (Expr *E = Args[0]) {
           // Use the explicit base to restrict the lookup:
           ObjectType = E->getType();
-          ObjectClassification = E->Classify(Context);
+          // Pointers in the object arguments are implicitly dereferenced, so we
+          // always classify them as l-values.
+          if (!ObjectType.isNull() && ObjectType->isPointerType())
+            ObjectClassification = Expr::Classification::makeSimpleLValue();
+          else
+            ObjectClassification = E->Classify(Context);
         } // .. else there is an implicit base.
         FunctionArgs = Args.slice(1);
       }

Added: cfe/trunk/test/CodeCompletion/signatures-crash.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeCompletion/signatures-crash.cpp?rev=348590&view=auto
==============================================================================
--- cfe/trunk/test/CodeCompletion/signatures-crash.cpp (added)
+++ cfe/trunk/test/CodeCompletion/signatures-crash.cpp Fri Dec  7 05:17:52 2018
@@ -0,0 +1,15 @@
+struct map {
+  void find(int);
+  void find();
+};
+
+int main() {
+  map *m;
+  m->find(10);
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:8:11 %s -o - | FileCheck %s
+  // CHECK: OVERLOAD: [#void#]find(<#int#>)
+
+  // Also check when the lhs is an explicit pr-value.
+  (m+0)->find(10);
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:13:15 %s -o - | FileCheck %s
+}




More information about the cfe-commits mailing list