hokein created this revision. hokein added a reviewer: kadircet. Herald added subscribers: usaxena95, arphaman, jkorous, MaskRay, ilya-biryukov. Herald added a project: clang.
We should not call getFieldOffset on invalid record decls. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D83189 Files: clang-tools-extra/clangd/Hover.cpp clang-tools-extra/clangd/unittests/HoverTests.cpp Index: clang-tools-extra/clangd/unittests/HoverTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/HoverTests.cpp +++ clang-tools-extra/clangd/unittests/HoverTests.cpp @@ -784,11 +784,24 @@ HI.NamespaceScope = ""; HI.Definition = "int xx"; HI.LocalScope = "Foo::"; - HI.Size = 4; HI.Type = "int"; HI.AccessSpecifier = "public"; }}, - }; + {R"cpp( + // error-ok + struct Foo { + Bar xx; + int [[y^y]]; + };)cpp", + [](HoverInfo &HI) { + HI.Name = "yy"; + HI.Kind = index::SymbolKind::Field; + HI.NamespaceScope = ""; + HI.Definition = "int yy"; + HI.LocalScope = "Foo::"; + HI.Type = "int"; + HI.AccessSpecifier = "public"; + }}}; for (const auto &Case : Cases) { SCOPED_TRACE(Case.Code); Index: clang-tools-extra/clangd/Hover.cpp =================================================================== --- clang-tools-extra/clangd/Hover.cpp +++ clang-tools-extra/clangd/Hover.cpp @@ -671,11 +671,11 @@ const auto *Record = FD->getParent(); if (Record) Record = Record->getDefinition(); - if (Record && !Record->isDependentType()) { - if (auto Size = Ctx.getTypeSizeInCharsIfKnown(FD->getType())) + if (Record && !Record->isInvalidDecl() && !Record->isDependentType()) { + if (auto Size = Ctx.getTypeSizeInCharsIfKnown(FD->getType())) { HI.Size = Size->getQuantity(); - if (!FD->isInvalidDecl()) HI.Offset = Ctx.getFieldOffset(FD) / 8; + } } return; }
Index: clang-tools-extra/clangd/unittests/HoverTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/HoverTests.cpp +++ clang-tools-extra/clangd/unittests/HoverTests.cpp @@ -784,11 +784,24 @@ HI.NamespaceScope = ""; HI.Definition = "int xx"; HI.LocalScope = "Foo::"; - HI.Size = 4; HI.Type = "int"; HI.AccessSpecifier = "public"; }}, - }; + {R"cpp( + // error-ok + struct Foo { + Bar xx; + int [[y^y]]; + };)cpp", + [](HoverInfo &HI) { + HI.Name = "yy"; + HI.Kind = index::SymbolKind::Field; + HI.NamespaceScope = ""; + HI.Definition = "int yy"; + HI.LocalScope = "Foo::"; + HI.Type = "int"; + HI.AccessSpecifier = "public"; + }}}; for (const auto &Case : Cases) { SCOPED_TRACE(Case.Code); Index: clang-tools-extra/clangd/Hover.cpp =================================================================== --- clang-tools-extra/clangd/Hover.cpp +++ clang-tools-extra/clangd/Hover.cpp @@ -671,11 +671,11 @@ const auto *Record = FD->getParent(); if (Record) Record = Record->getDefinition(); - if (Record && !Record->isDependentType()) { - if (auto Size = Ctx.getTypeSizeInCharsIfKnown(FD->getType())) + if (Record && !Record->isInvalidDecl() && !Record->isDependentType()) { + if (auto Size = Ctx.getTypeSizeInCharsIfKnown(FD->getType())) { HI.Size = Size->getQuantity(); - if (!FD->isInvalidDecl()) HI.Offset = Ctx.getFieldOffset(FD) / 8; + } } return; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits