1 /* Mudflap: narrow-pointer bounds-checking by tree rewriting:
2 C++ front-end interface.
4 Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
5 Contributed by Frank Ch. Eigler <fche@redhat.com>
6 and Graydon Hoare <graydon@redhat.com>
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 2, or (at your option) any later
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING. If not, write to the Free
22 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
29 #include "coretypes.h"
32 #include "tree-inline.h"
35 #include "diagnostic.h"
38 #include "tree-mudflap.h"
45 /* Initialize the global tree nodes that correspond to mf-runtime.h
48 mflang_lookup_decl (const char* name
)
50 tree decl
= lookup_name (get_identifier (name
), 1);
51 if (decl
== NULL_TREE
)
52 internal_error ("mudflap: cannot find declaration of `%s' from mf-runtime.h",
59 /* Emit a synthetic CTOR function for the current file. Populate it from
60 the enqueued __mf_register calls. Register it with the constructors. */
63 mflang_flush_calls (tree enqueued_call_stmt_chain
)
65 tree fnname
, fndecl
, body
;
69 if (enqueued_call_stmt_chain
== NULL_TREE
)
72 /* Create a ctor function declaration. */
73 fnname
= get_identifier ("__static_initialization_and_destruction_mudflap");
74 type
= build_function_type (void_type_node
, void_list_node
);
75 fndecl
= build_lang_decl (FUNCTION_DECL
, fnname
, type
);
77 TREE_PUBLIC (fndecl
) = 0;
78 TREE_USED (fndecl
) = 1;
79 DECL_ARTIFICIAL (fndecl
) = 1;
82 /* Generate the body, one statement at a time. */
83 start_preparsed_function (fndecl
, /*attrs=*/NULL_TREE
, SF_PRE_PARSED
);
84 body
= begin_compound_stmt (BCS_FN_BODY
);
86 while (enqueued_call_stmt_chain
)
88 tree next
= TREE_CHAIN (enqueued_call_stmt_chain
);
89 finish_expr_stmt (enqueued_call_stmt_chain
);
90 enqueued_call_stmt_chain
= next
;
93 finish_compound_stmt (body
);
94 fndecl
= finish_function (0);
96 /* NB: We cannot call expand_or_defer_fn here, since that goes through
97 the callgraph queue. This queue will have already been processed by the
98 time this function is running. */
100 if (targetm
.have_ctors_dtors
)
101 (* targetm
.asm_out
.constructor
) (XEXP (DECL_RTL (fndecl
), 0),
102 DEFAULT_INIT_PRIORITY
);
104 /* By this time, it's too late to do this:
105 static_ctors = tree_cons (NULL_TREE, fndecl, static_ctors); */