re PR middle-end/11498 (asm can't be used to give a variable its own name)

PR 11498
	* Makefile.in (c-opts.o): Add $(LANGHOOKS_DEF_H).
	(langhooks.o): Add $(GGC_H), gt-langhooks.h.
	(GTFILES): Add langhooks.c.
	(gt-langhooks.h): New.
	* c-common.h (c_static_assembler_name): Prototype.
	* c-lang.c (LANG_HOOKS_SET_DECL_ASSEMBLER_NAME): Define.
	* objc/objc-lang.c (LANG_HOOKS_SET_DECL_ASSEMBLER_NAME): Define.
	* c-opts.c: Include langhooks-def.h.
	(c_static_assembler_name): New.
	* langhooks.c: Include ggc.h.  Include gt-langhooks.h.
	(var_labelno): New.
	(lhd_set_decl_assembler_name): Give static objects with context
	unique names.
	* varasm.c (var_labelno): Delete.
	(make_decl_rtl): Don't change the assembler name once it's set.

From-SVN: r69527
This commit is contained in:
Geoffrey Keating 2003-07-17 21:52:51 +00:00 committed by Geoffrey Keating
parent 89e9faee22
commit 26e0dcb326
10 changed files with 91 additions and 44 deletions

View File

@ -1,5 +1,22 @@
2003-07-17 Geoffrey Keating <geoffk@apple.com>
PR 11498
* Makefile.in (c-opts.o): Add $(LANGHOOKS_DEF_H).
(langhooks.o): Add $(GGC_H), gt-langhooks.h.
(GTFILES): Add langhooks.c.
(gt-langhooks.h): New.
* c-common.h (c_static_assembler_name): Prototype.
* c-lang.c (LANG_HOOKS_SET_DECL_ASSEMBLER_NAME): Define.
* objc/objc-lang.c (LANG_HOOKS_SET_DECL_ASSEMBLER_NAME): Define.
* c-opts.c: Include langhooks-def.h.
(c_static_assembler_name): New.
* langhooks.c: Include ggc.h. Include gt-langhooks.h.
(var_labelno): New.
(lhd_set_decl_assembler_name): Give static objects with context
unique names.
* varasm.c (var_labelno): Delete.
(make_decl_rtl): Don't change the assembler name once it's set.
* c-opts.c (this_input_filename): New.
(finish_options): Take new parameter, name of file being compiled.
Update callers. Set this_input_filename.

View File

@ -1324,7 +1324,8 @@ c-pretty-print.o : c-pretty-print.c c-pretty-print.h pretty-print.h \
c-opts.o : c-opts.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \
c-pragma.h flags.h toplev.h langhooks.h tree-inline.h diagnostic.h \
intl.h debug.h $(C_COMMON_H) opts.h options.h $(PARAMS_H)
intl.h debug.h $(C_COMMON_H) opts.h options.h $(PARAMS_H) \
$(LANGHOOKS_DEF_H)
$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
$< $(OUTPUT_OPTION) @TARGET_SYSTEM_ROOT_DEFINE@
@ -1463,7 +1464,7 @@ convert.o: convert.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) flags
langhooks.o : langhooks.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) toplev.h \
tree-inline.h $(RTL_H) insn-config.h $(INTEGRATE_H) langhooks.h \
$(LANGHOOKS_DEF_H) flags.h
$(LANGHOOKS_DEF_H) flags.h $(GGC_H) gt-langhooks.h
tree.o : tree.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) flags.h function.h \
toplev.h $(GGC_H) $(HASHTAB_H) $(TARGET_H) output.h $(TM_P_H) langhooks.h \
real.h gt-tree.h
@ -2019,7 +2020,7 @@ GTFILES = $(srcdir)/input.h $(srcdir)/coretypes.h $(srcdir)/cpplib.h \
$(srcdir)/fold-const.c $(srcdir)/function.c \
$(srcdir)/gcse.c $(srcdir)/integrate.c $(srcdir)/lists.c $(srcdir)/optabs.c \
$(srcdir)/profile.c $(srcdir)/ra-build.c $(srcdir)/regclass.c \
$(srcdir)/reg-stack.c $(srcdir)/cfglayout.c \
$(srcdir)/reg-stack.c $(srcdir)/cfglayout.c $(srcdir)/langhooks.c \
$(srcdir)/sdbout.c $(srcdir)/stmt.c $(srcdir)/stor-layout.c \
$(srcdir)/stringpool.c $(srcdir)/tree.c $(srcdir)/varasm.c \
$(out_file) \
@ -2038,7 +2039,7 @@ gt-expr.h gt-sdbout.h gt-optabs.h gt-bitmap.h \
gt-dwarf2out.h gt-ra-build.h gt-reg-stack.h gt-dwarf2asm.h \
gt-dbxout.h gt-c-common.h gt-c-decl.h gt-c-parse.h \
gt-c-pragma.h gt-c-objc-common.h gtype-c.h gt-input.h gt-cfglayout.h \
gt-stringpool.h : s-gtype ; @true
gt-stringpool.h gt-langhooks.h : s-gtype ; @true
gtyp-gen.h: Makefile
echo "/* This file is machine generated. Do not edit. */" > tmp-gtyp.h

View File

@ -905,6 +905,7 @@ extern void check_function_format (int *, tree, tree);
extern void set_Wformat (int);
extern tree handle_format_attribute (tree *, tree, tree, int, bool *);
extern tree handle_format_arg_attribute (tree *, tree, tree, int, bool *);
extern void c_static_assembler_name (tree);
extern void c_common_insert_default_attributes (tree);
extern int c_common_handle_option (size_t code, const char *arg, int value);
extern void c_common_handle_filename (const char *filename);

View File

@ -71,6 +71,8 @@ enum c_language_kind c_language = clk_c;
#define LANG_HOOKS_UNSAFE_FOR_REEVAL c_common_unsafe_for_reeval
#undef LANG_HOOKS_STATICP
#define LANG_HOOKS_STATICP c_staticp
#undef LANG_HOOKS_SET_DECL_ASSEMBLER_NAME
#define LANG_HOOKS_SET_DECL_ASSEMBLER_NAME c_static_assembler_name
#undef LANG_HOOKS_NO_BODY_BLOCKS
#define LANG_HOOKS_NO_BODY_BLOCKS true
#undef LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL

View File

@ -37,6 +37,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
#include "debug.h" /* For debug_hooks. */
#include "opts.h"
#include "options.h"
#include "langhooks-def.h"
#ifndef DOLLARS_IN_IDENTIFIERS
# define DOLLARS_IN_IDENTIFIERS true
@ -1250,6 +1251,22 @@ c_common_finish (void)
fatal_error ("when writing output to %s: %m", out_fname);
}
/* A wrapper around lhd_set_decl_assembler_name that gives static
variables their C names if they are at the top level and only one
translation unit is being compiled, for backwards compatibility
with certain bizzare assembler hacks (like crtstuff.c). */
void
c_static_assembler_name (tree decl)
{
if (num_in_fnames == 1
&& TREE_STATIC (decl) && !TREE_PUBLIC (decl) && DECL_CONTEXT (decl)
&& TREE_CODE (DECL_CONTEXT (decl)) == TRANSLATION_UNIT_DECL)
SET_DECL_ASSEMBLER_NAME (decl, DECL_NAME (decl));
else
lhd_set_decl_assembler_name (decl);
}
/* Either of two environment variables can specify output of
dependencies. Their value is either "OUTPUT_FILE" or "OUTPUT_FILE
DEPS_TARGET", where OUTPUT_FILE is the file to write deps info to

View File

@ -32,6 +32,7 @@ Boston, MA 02111-1307, USA. */
#include "flags.h"
#include "langhooks.h"
#include "langhooks-def.h"
#include "ggc.h"
/* Do nothing; in many cases the default hook. */
@ -136,6 +137,11 @@ lhd_warn_unused_global_decl (tree decl)
return true;
}
/* Number for making the label on the next
static variable internal to a function. */
static GTY(()) int var_labelno;
/* Set the DECL_ASSEMBLER_NAME for DECL. */
void
lhd_set_decl_assembler_name (tree decl)
@ -149,12 +155,28 @@ lhd_set_decl_assembler_name (tree decl)
&& (TREE_STATIC (decl)
|| DECL_EXTERNAL (decl)
|| TREE_PUBLIC (decl))))
/* By default, assume the name to use in assembly code is the
same as that used in the source language. (That's correct
for C, and GCC used to set DECL_ASSEMBLER_NAME to the same
value as DECL_NAME in build_decl, so this choice provides
backwards compatibility with existing front-ends. */
SET_DECL_ASSEMBLER_NAME (decl, DECL_NAME (decl));
{
/* By default, assume the name to use in assembly code is the
same as that used in the source language. (That's correct
for C, and GCC used to set DECL_ASSEMBLER_NAME to the same
value as DECL_NAME in build_decl, so this choice provides
backwards compatibility with existing front-ends.
Can't use just the variable's own name for a variable whose
scope is less than the whole compilation. Concatenate a
distinguishing number. */
if (!TREE_PUBLIC (decl) && DECL_CONTEXT (decl))
{
const char *name = IDENTIFIER_POINTER (DECL_NAME (decl));
char *label;
ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
var_labelno++;
SET_DECL_ASSEMBLER_NAME (decl, get_identifier (label));
}
else
SET_DECL_ASSEMBLER_NAME (decl, DECL_NAME (decl));
}
else
/* Nobody should ever be asking for the DECL_ASSEMBLER_NAME of
these DECLs -- unless they're in language-dependent code, in
@ -456,3 +478,5 @@ write_global_declarations (void)
/* Clean up. */
free (vec);
}
#include "gt-langhooks.h"

View File

@ -69,6 +69,8 @@ enum c_language_kind c_language = clk_objc;
#define LANG_HOOKS_UNSAFE_FOR_REEVAL c_common_unsafe_for_reeval
#undef LANG_HOOKS_STATICP
#define LANG_HOOKS_STATICP c_staticp
#undef LANG_HOOKS_SET_DECL_ASSEMBLER_NAME
#define LANG_HOOKS_SET_DECL_ASSEMBLER_NAME c_static_assembler_name
#undef LANG_HOOKS_NO_BODY_BLOCKS
#define LANG_HOOKS_NO_BODY_BLOCKS true
#undef LANG_HOOKS_DUP_LANG_SPECIFIC_DECL

View File

@ -1,3 +1,8 @@
2003-07-17 Geoffrey Keating <geoffk@apple.com>
PR 11498
* gcc.c-torture/compile/mangle-1.c: New file.
2003-07-17 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/7809

View File

@ -0,0 +1,9 @@
int foo(void)
{
static int x asm ("x") = 3;
return x++;
}
int X2 asm ("x.0") = 4;
int X3 asm ("_x.0") = 5;

View File

@ -114,11 +114,6 @@ struct varasm_status GTY(())
static GTY(()) int const_labelno;
/* Number for making the label on the next
static variable internal to a function. */
static GTY(()) int var_labelno;
/* Carry information from ASM_DECLARE_OBJECT_NAME
to ASM_FINISH_DECLARE_OBJECT. */
@ -750,11 +745,7 @@ decode_reg_name (const char *asmspec)
void
make_decl_rtl (tree decl, const char *asmspec)
{
int top_level = (DECL_CONTEXT (decl) == NULL_TREE
|| (TREE_CODE (DECL_CONTEXT (decl))
== TRANSLATION_UNIT_DECL));
const char *name = 0;
const char *new_name = 0;
int reg_number;
rtx x;
@ -794,8 +785,6 @@ make_decl_rtl (tree decl, const char *asmspec)
return;
}
new_name = name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
reg_number = decode_reg_name (asmspec);
if (reg_number == -2)
{
@ -804,9 +793,11 @@ make_decl_rtl (tree decl, const char *asmspec)
char *starred = alloca (strlen (asmspec) + 2);
starred[0] = '*';
strcpy (starred + 1, asmspec);
new_name = starred;
SET_DECL_ASSEMBLER_NAME (decl, get_identifier (starred));
}
name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
{
/* First detect errors in declaring global registers. */
@ -878,28 +869,6 @@ make_decl_rtl (tree decl, const char *asmspec)
if (TREE_CODE (decl) == VAR_DECL && DECL_WEAK (decl))
DECL_COMMON (decl) = 0;
/* Can't use just the variable's own name for a variable
whose scope is less than the whole file, unless it's a member
of a local class (which will already be unambiguous).
Concatenate a distinguishing number. */
if (!top_level && !TREE_PUBLIC (decl)
&& ! (DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl)))
&& asmspec == 0
&& name == IDENTIFIER_POINTER (DECL_NAME (decl)))
{
char *label;
ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
var_labelno++;
new_name = label;
}
if (name != new_name)
{
SET_DECL_ASSEMBLER_NAME (decl, get_identifier (new_name));
name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
}
x = gen_rtx_SYMBOL_REF (Pmode, name);
SYMBOL_REF_WEAK (x) = DECL_WEAK (decl);
SYMBOL_REF_DECL (x) = decl;