Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nested struct being discarded if parent struct is flagged as partial #78

Merged
merged 1 commit into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions libcextract/Closure.hh
Original file line number Diff line number Diff line change
Expand Up @@ -195,18 +195,14 @@ class DeclClosureVisitor : public RecursiveASTVisitor<DeclClosureVisitor>
return VISITOR_CONTINUE

/* Special Traversal functions which marks if a Decl was already analyzed.
This macro generates them. */
#define DEF_MARKING_TRAVERSE_DECL(DECL) \
bool Traverse##DECL(DECL *decl) \
{ \
DO_NOT_RUN_IF_ALREADY_ANALYZED(decl); \
Mark_As_Analyzed(decl); \
return RecursiveASTVisitor::Traverse##DECL(decl); \
}

/* Override of TraverseDecl that marks that the given Decl was analyzed. So
Override of TraverseDecl that marks that the given Decl was analyzed. So
far it seems we only need this function for now. */
DEF_MARKING_TRAVERSE_DECL(Decl);
bool TraverseDecl(Decl *decl)
{
DO_NOT_RUN_IF_ALREADY_ANALYZED(decl);
Mark_As_Analyzed(decl);
return RecursiveASTVisitor::TraverseDecl(decl);
}

/* -------- C Declarations ----------------- */

Expand Down Expand Up @@ -266,6 +262,20 @@ class DeclClosureVisitor : public RecursiveASTVisitor<DeclClosureVisitor>
typedef struct { int a; } A; */
return VisitTypedefNameDecl(typedecl);
} else {
/* In case this references a struct/union defined inside a struct (nested
struct), then we also need to analyze the parent struct. */
RecordDecl *parent = dyn_cast<RecordDecl>(decl->getLexicalDeclContext());
if (parent) {
/* If the parent struct is flagged as not needing a complete definition
then we need to set it to true, else the nested struct won't be
output as of only a partial definition of the parent struct is
output. */
parent->setCompleteDefinitionRequired(true);

/* Analyze parent struct. */
TRY_TO(TraverseDecl(parent));
}

Closure.Add_Decl_And_Prevs(Maybe_Partial_Decl(decl));
}

Expand Down Expand Up @@ -547,5 +557,4 @@ class DeclClosureVisitor : public RecursiveASTVisitor<DeclClosureVisitor>
std::unordered_set<Decl *> AnalyzedDecls;
#undef TRY_TO
#undef DO_NOT_RUN_IF_ALREADY_ANALYZED
#undef DEF_MARKING_TRAVERSE_DECL
};
19 changes: 19 additions & 0 deletions testsuite/small/record-nested-3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* { dg-options "-DCE_EXTRACT_FUNCTIONS=fts3PrefixParameter -DCE_NO_EXTERNALIZATION" }*/

struct Fts3Table {
struct Fts3Index {
int nPrefix;
} *aIndex;
};

int fts3PrefixParameter(
const char *zParam,
int *pnIndex,
struct Fts3Index **apIndex
){
int a = sizeof(struct Fts3Index);
return 0;
}

/* { dg-final { scan-tree-dump "struct Fts3Table *{" } } */
/* { dg-final { scan-tree-dump "} *\*aIndex;" } } */
Loading