Closed Bug 509214 Opened 15 years ago Closed 11 years ago

dehydra does not fill in the .assign property for global initializers

Categories

(Developer Infrastructure :: Source Code Analysis, defect)

x86
Linux
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED WONTFIX

People

(Reporter: dnovillo, Unassigned)

References

Details

Attachments

(2 files)

User-Agent:       Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.10) Gecko/2009042708 Fedora/3.0.10-1.fc10 Firefox/3.0.10
Build Identifier: 

Given

int MyFunction(void);
int X = MyFunction();

I need dehydra to expose DECL_INITIAL for X for my analysis to determine that MyFunction is being referenced/called.

I was expecting the X.assign property to have MyFunction in it, but it doesn't:

({shortName:"X", name:"X", type:#1={min:{value:"-2147483648", type:#1#}, max:{value:"2147483647", type:#1#}, isSigned:true, precision:32, name:"int"}, isStatic:true, loc:{_source_location:220, file:"test.cc", line:2, column:5}})

In browsing the dehydra source code, I see that 'assign' is never even assigned.  Where should I start fixing this?

Reproducible: Always
> 
> In browsing the dehydra source code, I see that 'assign' is never even
> assigned.  Where should I start fixing this?
> 

A patch would be welcome. You are right, I missed .assign on globals, should be a simple fix in dehydra_visitVarDecl.
Blocks: 437502
(In reply to comment #1)

> A patch would be welcome. You are right, I missed .assign on globals, should be
> a simple fix in dehydra_visitVarDecl.

Thanks.  dehydra_visitVarDecl looks a bit late, however.  I need the walk_tree (&DECL_INITIAL) since the expression on the RHS may be quite complex, so I was thinking that I need to do something along the same lines as dehydra_visitFunctionDecl.

From what I've seen from dehydra_visitFunctionDecl, it looks like expressions are traversed beforehand and dehydra_visit... simply gets it from statementHierarchyArray.
(In reply to comment #2)
> (In reply to comment #1)
> 
> > A patch would be welcome. You are right, I missed .assign on globals, should be
> > a simple fix in dehydra_visitVarDecl.
> 
> Thanks.  dehydra_visitVarDecl looks a bit late, however.  I need the walk_tree
> (&DECL_INITIAL) since the expression on the RHS may be quite complex, so I was
> thinking that I need to do something along the same lines as
> dehydra_visitFunctionDecl.
> 
> From what I've seen from dehydra_visitFunctionDecl, it looks like expressions
> are traversed beforehand and dehydra_visit... simply gets it from
> statementHierarchyArray.

That might require a new plugin api callback from c++ fe.
When a global symbol is initialized with an expression, the code for the expression goes to the global ctors/dtors artificial function created by the compiler.  This patch traverses artificial functions so those user expressions can also be seen by dehydra scripts.
both of these need testcases
Blocks: 511407
I tried to reproduce this, but I can't get anything to to show  in .assign with your patch applied.
In the test case I submitted originally, you will see the .assign property filled in on 'X' when processing the function body for __static_initialization_and_destruction_0.  This actually needs the patch to traverse bodies of artificial functions.

The initializer for 'X' here is not a regular DECL_INITIAL.  It's an assignment in the static initializer function.  To see symbols in DECL_INITIAL you need constant initializers like 'int *P = &X;'

function process_function(fn, body)
{
  print("Function body found: " + fn.name + " location: " + fn.loc);
  print("Statements:");
  for each (var stmt in body) {
    for each (var sym in stmt.statements) {
      if (sym.assign)
        print(stmt.loc + ": " + sym.name + " - assign: " + sym.assign);
    }
  }
}

will produce

Function body found: __static_initialization_and_destruction_0(int, int) location: test.cc:2:21
Statements:
test.cc:2:5: X - assign: {shortName:"MyFunction", name:"MyFunction()", isExtern:true, isFunction:true, parameters:[], type:{type:#1={min:{value:"-2147483648", type:#1#}, max:{value:"2147483647", type:#1#}, isSigned:true, precision:32, name:"int"}, parameters:[]}, loc:{_source_location:92, file:"test.cc", line:1, column:5}, isFcall:true, arguments:[]}

on the snippet:

int MyFunction(void);
int X = MyFunction();
k, you did see that this is the patch that caused you grief in bug 521308? I doubt most users want to the vptr initialization.

By the way if you or your users have better ideas on how to represent function bodies, I'm all ears.
Dehydra and treehydra are no longer maintained by Mozilla.
Status: UNCONFIRMED → RESOLVED
Closed: 11 years ago
Resolution: --- → WONTFIX
Product: Core → Firefox Build System
Product: Firefox Build System → Developer Infrastructure
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: