r338255 - [CodeComplete] Fix the crash in code completion on access checking
Eric Liu via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 28 02:43:09 PDT 2018
On Mon, Jul 30, 2018 at 5:19 PM Ilya Biryukov via cfe-commits <
cfe-commits at lists.llvm.org> wrote:
> Author: ibiryukov
> Date: Mon Jul 30 08:19:05 2018
> New Revision: 338255
>
> URL: http://llvm.org/viewvc/llvm-project?rev=338255&view=rev
> Log:
> [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.
>
It turns out that this was due to lit's partial string match ... so
"something" would match both "something" and "something (inaccessible)" XD
The protected member bug came up again after the revert, but it was the
right thing to do to fix the crash. I'll look into a proper fix.
>
> Added:
> cfe/trunk/test/Index/complete-access-checks-crash.cpp
> Modified:
> cfe/trunk/lib/Sema/SemaCodeComplete.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=338255&r1=338254&r2=338255&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Mon Jul 30 08:19:05 2018
> @@ -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<CXXRecordDecl>(Ctx)) {
> - CXXRecordDecl *RC = nullptr;
> - // Get the enclosing record.
> - for (DeclContext *DC = CurContext; !DC->isFileContext();
> - DC = DC->getParent()) {
> - if ((RC = dyn_cast<CXXRecordDecl>(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);
>
> Added: cfe/trunk/test/Index/complete-access-checks-crash.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-access-checks-crash.cpp?rev=338255&view=auto
>
> ==============================================================================
> --- cfe/trunk/test/Index/complete-access-checks-crash.cpp (added)
> +++ cfe/trunk/test/Index/complete-access-checks-crash.cpp Mon Jul 30
> 08:19:05 2018
> @@ -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)
> + }
> +};
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180928/818f3f2d/attachment.html>
More information about the cfe-commits
mailing list