Skip to content

Commit

Permalink
Avoid issuing multiple declarations of same function
Browse files Browse the repository at this point in the history
When -DCE_OUTPUT_FUNCTION_PROTOTYPE_HEADER is passed to clang-extract,
the generated header file could have multiple declarations of the same
function.  This commit fixes this.

Signed-off-by: Giuliano Belinassi <gbelinassi@suse.de>
  • Loading branch information
giulianobelinassi committed Mar 28, 2024
1 parent 47af56d commit 03f03d3
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion libcextract/HeaderGenerate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,22 @@ static bool Contains(const std::vector<ExternalizerLogEntry> &v, const std::stri
bool HeaderGeneration::Run_Analysis(const std::vector<ExternalizerLogEntry> &set)
{
ASTUnit::top_level_iterator it;
std::unordered_set<std::string> nameset;

for (it = AST->top_level_begin(); it != AST->top_level_end(); ++it) {
Decl *decl = *it;

if (FunctionDecl *fdecl = dyn_cast<FunctionDecl>(decl)) {
if (Contains(set, fdecl->getNameAsString())) {
const std::string &fname = fdecl->getNameAsString();
/* If the function was already issued, then do not issue it again. */
if (Contains(set, fname) && nameset.find(fname) == nameset.end()) {
if (fdecl->doesThisDeclarationHaveABody() && fdecl->hasBody()) {
Stmt *body = fdecl->getBody();
fdecl->setRangeEnd(body->getBeginLoc().getLocWithOffset(-1));
fdecl->setBody(nullptr);
}
Closure.Add_Single_Decl(fdecl);
nameset.insert(fname);
}
}
}
Expand Down

0 comments on commit 03f03d3

Please sign in to comment.