Skip to content

Commit

Permalink
SymbolExternalizer: Rename externalized operand of sizeof
Browse files Browse the repository at this point in the history
Signed-off-by: Marcos Paulo de Souza <[email protected]>
  • Loading branch information
marcosps committed Jun 14, 2024
1 parent 0925bdb commit 46cbe4d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
27 changes: 27 additions & 0 deletions libcextract/SymbolExternalizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
10 changes: 10 additions & 0 deletions testsuite/ccp/ext5-obj-5.c
Original file line number Diff line number Diff line change
@@ -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\];" } } */

0 comments on commit 46cbe4d

Please sign in to comment.