From 1b2dafb41e63b904e18ef700ad103be513100a66 Mon Sep 17 00:00:00 2001 From: Ilya Biryukov Date: Mon, 30 Jul 2018 15:19:05 +0000 Subject: [PATCH] [CodeComplete] Fix the crash in code completion on access checking Started crashing in r337453. See the added test case for the crash repro. The fix reverts part of r337453 that causes the crash and does not actually break anything when reverted. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@338255 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaCodeComplete.cpp | 30 ++------------------- test/Index/complete-access-checks-crash.cpp | 13 +++++++++ 2 files changed, 15 insertions(+), 28 deletions(-) create mode 100644 test/Index/complete-access-checks-crash.cpp diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp index 4e571eba17..30af826ef6 100644 --- a/lib/Sema/SemaCodeComplete.cpp +++ b/lib/Sema/SemaCodeComplete.cpp @@ -1303,34 +1303,8 @@ namespace { void FoundDecl(NamedDecl *ND, NamedDecl *Hiding, DeclContext *Ctx, bool InBaseClass) override { bool Accessible = true; - if (Ctx) { - DeclContext *AccessingCtx = Ctx; - // If ND comes from a base class, set the naming class back to the - // derived class if the search starts from the derived class (i.e. - // InBaseClass is true). - // - // Example: - // class B { protected: int X; } - // class D : public B { void f(); } - // void D::f() { this->^; } - // The completion after "this->" will have `InBaseClass` set to true and - // `Ctx` set to "B", when looking up in `B`. We need to set the actual - // accessing context (i.e. naming class) to "D" so that access can be - // calculated correctly. - if (InBaseClass && isa(Ctx)) { - CXXRecordDecl *RC = nullptr; - // Get the enclosing record. - for (DeclContext *DC = CurContext; !DC->isFileContext(); - DC = DC->getParent()) { - if ((RC = dyn_cast(DC))) - break; - } - if (RC) - AccessingCtx = RC; - } - Accessible = Results.getSema().IsSimplyAccessible(ND, AccessingCtx); - } - + if (Ctx) + Accessible = Results.getSema().IsSimplyAccessible(ND, Ctx); ResultBuilder::Result Result(ND, Results.getBasePriority(ND), nullptr, false, Accessible, FixIts); Results.AddResult(Result, CurContext, Hiding, InBaseClass); diff --git a/test/Index/complete-access-checks-crash.cpp b/test/Index/complete-access-checks-crash.cpp new file mode 100644 index 0000000000..c7ac4d6563 --- /dev/null +++ b/test/Index/complete-access-checks-crash.cpp @@ -0,0 +1,13 @@ +struct Base { +protected: + bool bar(); +}; +struct Derived : Base { +}; + +struct X { + int foo() { + Derived(). // RUN: c-index-test -code-completion-at=%s:10:15 %s | FileCheck %s + // CHECK: bar{{.*}}(inaccessible) + } +}; -- 2.50.1