xpcom/analysis/static-init.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 /**
michael@0 6 * Detects static initializers i.e. functions called during static initialization.
michael@0 7 */
michael@0 8
michael@0 9 require({ after_gcc_pass: "cfg" });
michael@0 10
michael@0 11 function process_tree(fn) {
michael@0 12 for each (let attr in translate_attributes(DECL_ATTRIBUTES(fn)))
michael@0 13 if (attr.name == "constructor")
michael@0 14 warning(pretty_func(fn) + " marked with constructor attribute\n");
michael@0 15
michael@0 16 if (decl_name_string(fn) != "__static_initialization_and_destruction_0")
michael@0 17 return;
michael@0 18
michael@0 19 let cfg = function_decl_cfg(fn);
michael@0 20 for (let isn in cfg_isn_iterator(cfg)) {
michael@0 21 if (isn.tree_code() != GIMPLE_CALL)
michael@0 22 continue;
michael@0 23 let decl = gimple_call_fndecl(isn);
michael@0 24 let lhs = gimple_call_lhs(isn);
michael@0 25 if (lhs) {
michael@0 26 warning(pretty_var(lhs) + " defined by call to " + pretty_func(decl) +
michael@0 27 " during static initialization", location_of(lhs));
michael@0 28 } else {
michael@0 29 let arg = constructorArg(isn);
michael@0 30 if (arg)
michael@0 31 warning(pretty_var(arg) + " defined by call to constructor " + pretty_func(decl) +
michael@0 32 " during static initialization", location_of(arg));
michael@0 33 else
michael@0 34 warning(pretty_func(decl) + " called during static initialization", location_of(decl));
michael@0 35 }
michael@0 36 }
michael@0 37 }
michael@0 38
michael@0 39 function constructorArg(call) {
michael@0 40 let decl = gimple_call_fndecl(call);
michael@0 41
michael@0 42 if (!DECL_CONSTRUCTOR_P(decl))
michael@0 43 return null;
michael@0 44
michael@0 45 let arg = gimple_call_arg_iterator(call).next();
michael@0 46 if (TYPE_MAIN_VARIANT(TREE_TYPE(TREE_TYPE(arg))) != DECL_CONTEXT(decl))
michael@0 47 throw new Error("malformed constructor call?!");
michael@0 48
michael@0 49 return arg.tree_code() == ADDR_EXPR ? TREE_OPERAND(arg, 0) : arg;
michael@0 50 }
michael@0 51
michael@0 52 function pretty_func(fn) {
michael@0 53 return rfunc_string(rectify_function_decl(fn));
michael@0 54 }
michael@0 55
michael@0 56 function pretty_var(v) {
michael@0 57 return type_string(TREE_TYPE(v)) + " " + expr_display(v);
michael@0 58 }

mercurial