Skip to content

Commit 2e580ae

Browse files
OSS-Fuzz Teamcopybara-github
authored andcommitted
Add cross-references to synthesized inherited members
Indexer-PiperOrigin-RevId: 794883704
1 parent 69e918e commit 2e580ae

File tree

9 files changed

+2080
-797
lines changed

9 files changed

+2080
-797
lines changed

infra/indexer/frontend/ast_visitor.cc

Lines changed: 657 additions & 225 deletions
Large diffs are not rendered by default.

infra/indexer/frontend/ast_visitor.h

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "indexer/index/in_memory_index.h"
2121
#include "indexer/index/types.h"
22+
#include "absl/container/flat_hash_map.h"
2223
#include "clang/AST/ASTConsumer.h"
2324
#include "clang/AST/Decl.h"
2425
#include "clang/AST/DeclTemplate.h"
@@ -28,6 +29,7 @@
2829
#include "clang/AST/Type.h"
2930
#include "clang/Basic/SourceLocation.h"
3031
#include "clang/Frontend/CompilerInstance.h"
32+
#include "clang/Sema/Sema.h"
3133

3234
namespace oss_fuzz {
3335
namespace indexer {
@@ -36,9 +38,12 @@ namespace indexer {
3638
// instead.
3739
class AstVisitor : public clang::RecursiveASTVisitor<AstVisitor> {
3840
public:
39-
AstVisitor(InMemoryIndex &index, clang::ASTContext &context,
40-
clang::CompilerInstance &compiler)
41-
: index_(index), context_(context), compiler_(compiler) {}
41+
AstVisitor(InMemoryIndex& index, clang::ASTContext& context,
42+
clang::CompilerInstance& compiler)
43+
: index_(index),
44+
context_(context),
45+
compiler_(compiler),
46+
sema_(compiler.getSema()) {}
4247

4348
bool shouldVisitImplicitCode() const { return true; }
4449
bool shouldVisitTemplateInstantiations() const { return true; }
@@ -69,11 +74,18 @@ class AstVisitor : public clang::RecursiveASTVisitor<AstVisitor> {
6974
LocationId GetLocationId(clang::SourceLocation start,
7075
clang::SourceLocation end);
7176
LocationId GetLocationId(const clang::Decl *decl);
77+
std::optional<Entity> GetEntityForDecl(
78+
const clang::Decl* decl, bool for_reference = false,
79+
LocationId location_id = kInvalidLocationId);
7280
EntityId GetEntityIdForDecl(const clang::Decl *decl,
73-
LocationId location_id = kInvalidLocationId,
7481
bool for_reference = false);
75-
std::optional<EntityId> GetEntityIdForCanonicalDecl(
76-
const clang::Decl *canonical_decl, const clang::Decl *original_decl);
82+
std::optional<SubstituteRelationship> GetTemplateSubstituteRelationship(
83+
const clang::Decl* template_decl, const clang::Decl* original_decl);
84+
void SynthesizeInheritedMemberEntities(
85+
const clang::CXXRecordDecl* class_decl);
86+
void AddSyntheticMemberReference(const clang::CXXRecordDecl* child_class,
87+
const clang::ValueDecl* inherited_member,
88+
const clang::SourceRange& range);
7789
void AddTypeReferencesFromLocation(LocationId location_id,
7890
const clang::Type *type,
7991
bool outermost_type = true);
@@ -84,9 +96,23 @@ class AstVisitor : public clang::RecursiveASTVisitor<AstVisitor> {
8496
void AddTypeReferencesForSourceRange(const clang::SourceRange &range,
8597
const clang::Type *type);
8698

99+
void AddVirtualMethodLinks(const clang::CXXMethodDecl* method_decl,
100+
EntityId child_id);
101+
void AddSynthesizedVirtualMethodLinks(
102+
const clang::CXXMethodDecl* prototype_method_decl,
103+
const clang::CXXRecordDecl* child_class_decl, EntityId child_id);
104+
87105
InMemoryIndex &index_;
88106
clang::ASTContext &context_;
89107
clang::CompilerInstance &compiler_;
108+
clang::Sema& sema_;
109+
110+
struct CachedEntityId {
111+
EntityId entity_id;
112+
bool for_reference_only;
113+
};
114+
115+
absl::flat_hash_map<const clang::Decl*, CachedEntityId> decl_to_entity_id_;
90116
};
91117
} // namespace indexer
92118
} // namespace oss_fuzz

0 commit comments

Comments
 (0)