Skip to content

Commit

Permalink
SymbolExternalizer: Drop initializer from expanded macros
Browse files Browse the repository at this point in the history
When the variable is created from a macro, like DECLARE_WORK, we need
expand the macro to then drop the initializer.

Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
  • Loading branch information
marcosps committed Aug 1, 2024
1 parent 1416118 commit e9f12bb
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions libcextract/SymbolExternalizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,19 @@ void SymbolExternalizer::Drop_Var_Initializer(VarDecl *decl)
SourceLocation init_loc = init->getSourceRange().getBegin();
SourceLocation head = init_loc.getLocWithOffset(-1);

StringRef text = PrettyPrint::Get_Source_Text(init->getSourceRange());
if (text.data() == nullptr) {
std::string o;
llvm::raw_string_ostream outstr(o);

decl->setInit(nullptr);
decl->print(outstr);
decl->setInit(init);

Replace_Text(decl->getSourceRange(), o, 1000);
return;
}

/* Search for the '=' initializer token. */
while (true) {
StringRef text = PrettyPrint::Get_Source_Text({head, init_loc});
Expand Down

0 comments on commit e9f12bb

Please sign in to comment.