diff --git a/libcextract/SymbolExternalizer.cpp b/libcextract/SymbolExternalizer.cpp index f7f4f70..23bcd6e 100644 --- a/libcextract/SymbolExternalizer.cpp +++ b/libcextract/SymbolExternalizer.cpp @@ -513,6 +513,33 @@ bool SymbolExternalizer::FunctionUpdater::Update_References_To_Symbol(Stmt *stmt expr->setDecl(NewSymbolDecl); replaced = true; } + } else if (DeclStmt::classof(stmt)) { + /* To handle symbol renames on situations like the sizeof below + * + * static char x[4]; + * + * void f(void) { + * char y[sizeof(x)]; + * } + */ + DeclStmt *dstmt = (DeclStmt *) stmt; + Decl *ddecl = dstmt->getSingleDecl(); + + auto vec_of_ranges = Get_Range_Of_Identifier_In_SrcRange(ddecl->getSourceRange(), + OldSymbolName.c_str()); + + if (vec_of_ranges.size() > 0) { + /* Prepare the text modification. */ + std::string new_name; + if (Wrap) { + new_name = NewSymbolDecl->getName().str(); + } else { + new_name = "(*" + NewSymbolDecl->getName().str() + ")"; + } + + /* Issue a text modification. */ + SE.Replace_Text(vec_of_ranges[0], new_name, 100); + } } /* Repeat the process to child statements. */ diff --git a/testsuite/ccp/ext5-obj-5.c b/testsuite/ccp/ext5-obj-5.c new file mode 100644 index 0000000..037ca95 --- /dev/null +++ b/testsuite/ccp/ext5-obj-5.c @@ -0,0 +1,10 @@ +/* { dg-options "-DCE_EXTRACT_FUNCTIONS=pu_f -DCE_EXPORT_SYMBOLS=ee_o" }*/ +static char ee_o[] = "123"; + +void pu_f(void) +{ + char s[sizeof(ee_o)]; + ee_o; +} + +/* { dg-final { scan-tree-dump "static char \(\*klpe_ee_o\)\[4\];" } } */