From e9f12bb3173fce1d11e6030fd89e58659845597d Mon Sep 17 00:00:00 2001 From: Marcos Paulo de Souza Date: Thu, 1 Aug 2024 16:25:18 -0300 Subject: [PATCH] SymbolExternalizer: Drop initializer from expanded macros 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 --- libcextract/SymbolExternalizer.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libcextract/SymbolExternalizer.cpp b/libcextract/SymbolExternalizer.cpp index 40a480d..83c193e 100644 --- a/libcextract/SymbolExternalizer.cpp +++ b/libcextract/SymbolExternalizer.cpp @@ -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});