Skip to content

Commit

Permalink
Remove redundant leftmost decl from closure
Browse files Browse the repository at this point in the history
In the following case:
```
static float stbi__h2l_gamma_i=1.0f/2.2f, stbi__h2l_scale_i=1.0f;
```
we need to remove `stbi__h2l_gamma_i` from the closure else it will
output
```
static float stbi__h2l_gamma_i=1.0f/2.2f;
static float stbi__h2l_gamma_i=1.0f/2.2f, stbi__h2l_scale_i=1.0f;
```
which is a redeclaration fo the first variable.

Signed-off-by: Giuliano Belinassi <[email protected]>
  • Loading branch information
giulianobelinassi committed Jul 20, 2024
1 parent b4c013b commit 57e013e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 3 additions & 2 deletions libcextract/FunctionDepsFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,10 @@ void FunctionDependencyFinder::Remove_Redundant_Decls(void)

// FIXME: use interval tree
ASTUnit::top_level_iterator it;
TypedefDecl *prev = nullptr;
Decl *prev = nullptr;
for (it = AST->top_level_begin(); it != AST->top_level_end(); ++it) {
if (TypedefDecl *decl = dyn_cast<TypedefDecl>(*it)) {
Decl *decl = *it;
if (isa<TypedefDecl>(decl) || isa<VarDecl>(decl)) {
if (!closure.Is_Decl_Marked(decl))
continue;

Expand Down
13 changes: 13 additions & 0 deletions testsuite/small/globalvars-4.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* { dg-options "-DCE_EXTRACT_FUNCTIONS=f -DCE_NO_EXTERNALIZATION" }*/

extern double pow (double __x, double __y) __attribute__ ((__nothrow__ ));
extern double __pow (double __x, double __y) __attribute__ ((__nothrow__ ));

static float stbi__h2l_gamma_i=1.0f/2.2f, stbi__h2l_scale_i=1.0f;

void f() {
float z = (float) pow(stbi__h2l_scale_i, stbi__h2l_gamma_i) * 255 + 0.5f;
}

/* { dg-final { scan-tree-dump "static float stbi__h2l_gamma_i=1.0f/2.2f, stbi__h2l_scale_i=1.0f;" } } */
/* { dg-final { scan-tree-dump-not "static float stbi__h2l_gamma_i=1.0f/2.2f;" } } */

0 comments on commit 57e013e

Please sign in to comment.