bug 313956: expand installer .exe contents to make complete mar. r=ted.
[gecko.git] / xpcom / analysis / static-init.js
blob1816d0548541022edf0c93c12c2c2a196a9fd9ba
1 /**
2  * Detects static initializers i.e. functions called during static initialization.
3  */
5 require({ after_gcc_pass: "cfg" });
7 function process_tree(fn) {
8   for each (let attr in translate_attributes(DECL_ATTRIBUTES(fn)))
9     if (attr.name == "constructor")
10       warning(pretty_func(fn) + " marked with constructor attribute\n");
12   if (decl_name_string(fn) != "__static_initialization_and_destruction_0")
13     return;
15   let cfg = function_decl_cfg(fn);
16   for (let isn in cfg_isn_iterator(cfg)) {
17     if (isn.tree_code() != GIMPLE_CALL)
18       continue;
19     let decl = gimple_call_fndecl(isn);
20     let lhs = gimple_call_lhs(isn);
21     if (lhs) {
22       warning(pretty_var(lhs) + " defined by call to " + pretty_func(decl) +
23               " during static initialization", location_of(lhs));
24     } else {
25       let arg = constructorArg(isn);
26       if (arg)
27         warning(pretty_var(arg) + " defined by call to constructor " + pretty_func(decl) +
28                 " during static initialization", location_of(arg));
29       else
30         warning(pretty_func(decl) + " called during static initialization", location_of(decl));
31     }
32   }
35 function constructorArg(call) {
36   let decl = gimple_call_fndecl(call);
38   if (!DECL_CONSTRUCTOR_P(decl))
39     return null;
41   let arg = gimple_call_arg_iterator(call).next();
42   if (TYPE_MAIN_VARIANT(TREE_TYPE(TREE_TYPE(arg))) != DECL_CONTEXT(decl))
43     throw new Error("malformed constructor call?!");
45   return arg.tree_code() == ADDR_EXPR ? TREE_OPERAND(arg, 0) : arg;
48 function pretty_func(fn) {
49   return rfunc_string(rectify_function_decl(fn));
52 function pretty_var(v) {
53   return type_string(TREE_TYPE(v)) + " " + expr_display(v);