This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[lto] fix builtins, take 3
- From: Nathan Froyd <froydnj at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: zadeck at naturalbridge dot com
- Date: Thu, 15 Nov 2007 13:08:25 -0800
- Subject: [lto] fix builtins, take 3
The patch below does a couple of things:
- Most obviously, it fixes cases where we would fail to recognize (some)
builtin functions. At the moment, we only recognize those functions
that the backend told us about and the common functions built by
tree.c:build_common_builtin_nodes. Eventually, we need to have the
LTO front-end know about all the builtins from all languages so we can
smash files together with abandon.
- lto_find_integral_type was being a bit too conservative in its search
for a usable integer type; this was causing a failure or two in the
testsuite.
- lto_read_variable_formal_parameter_constant_DIE was attempting to
reference DECL_ASSEMBLER_NAME of PARM_DECLs, which was a bad idea.
- We weren't setting TREE_CONTEXT for RESULT_DECLs that we constructed.
The first point merely turns several compilation failures into execution
failures.
Committed to the LTO branch.
-Nathan
gcc/
* tree.h (DECL_CONTEXT): Note that this applies to RESULT_DECLs too.
gcc/lto/
* lto.c: Include langhooks.h.
(lto_find_integral_type): Rework logic to handle the case where
got_byte_size is true, but the bitsize requested and that of the
base_type doesn't match.
(lto_read_variable_formal_parameter_constant_DIE): Only check for
asm_name if we are creating a VAR_DECL.
(lto_materialize_function): Set DECL_EXTERNAL if we can't find a
definition.
(lto_read_subroutine_type_subprogram_DIE): Check for a builtin
function reference and use the builtin's decl if so. Set the
DECL_CONTEXT of the RESULT_DECL for the function.
* lto-lang.c (registered_builtin_fndecls): New variable.
(lto_getdecls): Return it.
(lto_builtin_function): Chain the new decl onto
registered_builtin_fndecls.
Index: tree.h
===================================================================
--- tree.h (revision 130202)
+++ tree.h (working copy)
@@ -2515,9 +2515,9 @@ struct function;
/* For FIELD_DECLs, this is the RECORD_TYPE, UNION_TYPE, or
QUAL_UNION_TYPE node that the field is a member of. For VAR_DECL,
- PARM_DECL, FUNCTION_DECL, LABEL_DECL, and CONST_DECL nodes, this
- points to either the FUNCTION_DECL for the containing function,
- the RECORD_TYPE or UNION_TYPE for the containing type, or
+ PARM_DECL, FUNCTION_DECL, LABEL_DECL, RESULT_DECL, and CONST_DECL
+ nodes, this points to either the FUNCTION_DECL for the containing
+ function, the RECORD_TYPE or UNION_TYPE for the containing type, or
NULL_TREE or a TRANSLATION_UNIT_DECL if the given decl has "file
scope". */
#define DECL_CONTEXT(NODE) (DECL_MINIMAL_CHECK
(NODE)->decl_minimal.context)
Index: lto/lto.c
===================================================================
--- lto/lto.c (revision 130202)
+++ lto/lto.c (working copy)
@@ -33,6 +33,7 @@ Boston, MA 02110-1301, USA. */
#include "lto.h"
#include "lto-tree.h"
#include "tree-ssa-operands.h" /* For init_ssa_operands. */
+#include "langhooks.h"
/* References
@@ -1230,9 +1231,12 @@ lto_find_integral_type (tree base_type,
|| !TYPE_SIZE (base_type)
|| !host_integerp (TYPE_SIZE (base_type), 1))
lto_abi_mismatch_error ();
- else if (got_byte_size
- && nbits != tree_low_cst (TYPE_SIZE (base_type), 1))
- sorry ("size of base type (%d bits) doesn't match specified size (%d bits)",
+ else if (!got_byte_size)
+ return base_type;
+ else if (nbits <= tree_low_cst (TYPE_SIZE (base_type), 1))
+ base_type = lang_hooks.types.type_for_size (nbits, /*unsigned=*/true);
+ else
+ sorry ("size of base type (%d bits) smaller than specified size (%d bits)",
(int) tree_low_cst (TYPE_SIZE (base_type), 1),
nbits);
return base_type;
@@ -2043,8 +2047,6 @@ lto_read_variable_formal_parameter_const
name = DECL_NAME (referenced);
if (referenced && !type)
type = TREE_TYPE (referenced);
- if (referenced && !asm_name)
- asm_name = DECL_ASSEMBLER_NAME (referenced);
/* Build the tree node for this entity. */
decl = build_decl (code, name, type);
@@ -2055,6 +2057,8 @@ lto_read_variable_formal_parameter_const
etc. */
if (code == VAR_DECL)
{
+ if (referenced && !asm_name)
+ asm_name = DECL_ASSEMBLER_NAME (referenced);
SET_DECL_ASSEMBLER_NAME (decl, asm_name);
TREE_PUBLIC (decl) = external;
DECL_EXTERNAL (decl) = declaration;
@@ -2366,7 +2370,7 @@ lto_materialize_function (lto_info_fd *f
file->vtable->unmap_fn_body (file, name, body);
}
else
- DECL_EXTERNAL (decl) = 0;
+ DECL_EXTERNAL (decl) = 1;
/* Let the middle end know about the function. */
rest_of_decl_compilation (decl,
@@ -2556,6 +2560,30 @@ lto_read_subroutine_type_subprogram_DIE
if (!name)
lto_file_corrupt_error ((lto_fd *)fd);
+ if (external && declaration)
+ {
+ /* Check to see if this function is a builtin. */
+ tree builtins = lang_hooks.decls.getdecls ();
+
+ while (builtins)
+ {
+ tree candidate = builtins;
+
+ /* Check to see if this builtin matches this function's
+ DIE. Use the builtin decl if so. */
+ if (name == DECL_NAME (candidate)
+ || (DECL_ASSEMBLER_NAME (candidate)
+ && name == DECL_ASSEMBLER_NAME (candidate)))
+ {
+ result = candidate;
+
+ goto read_children;
+ }
+
+ builtins = TREE_CHAIN (candidate);
+ }
+ }
+
result = build_decl (FUNCTION_DECL, name, type);
TREE_PUBLIC (result) = external;
if (inlined == DW_INL_declared_inlined
@@ -2569,6 +2597,7 @@ lto_read_subroutine_type_subprogram_DIE
DECL_RESULT (result)
= build_decl (RESULT_DECL, NULL_TREE,
TYPE_MAIN_VARIANT (ret_type));
+ TREE_CONTEXT (DECL_RESULT (result)) = result;
#if 0
DECL_SOURCE_LOCATION (result) = { input_filename, line };
#endif
Index: lto/lto-lang.c
===================================================================
--- lto/lto-lang.c (revision 130202)
+++ lto/lto-lang.c (working copy)
@@ -59,6 +59,11 @@ static GTY(()) tree signed_and_unsigned_
static GTY(()) tree registered_builtin_types;
+/* A chain of builtin functions that we need to recognize. We will
+ assume that all other function names we see will be defined by the
+ user's program. */
+static GTY(()) tree registered_builtin_fndecls;
+
/* Language hooks. */
static bool
@@ -193,7 +198,7 @@ lto_pushdecl (tree t ATTRIBUTE_UNUSED)
static tree
lto_getdecls (void)
{
- gcc_unreachable ();
+ return registered_builtin_fndecls;
}
static void
@@ -208,7 +213,10 @@ lto_write_globals (void)
static tree
lto_builtin_function (tree decl)
{
- /* No special processing required. */
+ /* Record it. */
+ TREE_CHAIN (decl) = registered_builtin_fndecls;
+ registered_builtin_fndecls = decl;
+
return decl;
}