This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
[tree-ssa] const declarations and temporaries in cc1plus
- From: Pop Sébastian <pop at gauvain dot u-strasbg dot fr>
- To: dnovillo at redhat dot com, gcc at gcc dot gnu dot org
- Date: Sun, 18 May 2003 22:57:10 +0200
- Subject: [tree-ssa] const declarations and temporaries in cc1plus
Hi,
I was investigating on the following test-case, but don't know
how to fix it. (Maybe by setting the appropriate flags on the decl?...)
----
int strcmp (const char *, const char *);
const char * const s = "foobar";
int foo (const char *c)
{
return strcmp(c, s);
}
----
This compiles without errors with cc1, but fails with cc1plus.
There is no error if you declare s as:
const char * s = "foobar";
char * const s = "foobar";
Here is the backtrace:
#0 make_decl_rtl (decl=0x401db3f0, asmspec=0x0) at ../../gcc/gcc/varasm.c:795
#1 0x40177210 in ?? ()
#2 0x081fe155 in expand_expr (exp=0x401db3f0, target=0x0, tmode=VOIDmode,
modifier=EXPAND_INITIALIZER) at ../../gcc/gcc/expr.c:6811
#3 0x08377f62 in output_constant (exp=0x401db3f0, size=4, align=32)
at ../../gcc/gcc/varasm.c:3836
#4 0x083570a6 in rest_of_decl_compilation (decl=0x401d8bd0, asmspec=0x0,
top_level=1, at_end=1) at ../../gcc/gcc/toplev.c:2370
#5 0x08356931 in wrapup_global_declarations (vec=0x40180410, len=1)
at ../../gcc/gcc/toplev.c:2093
#6 0x0805a72d in walk_namespaces_r (namespace=0x401db322,
f=0x805a890 <wrapup_globals_for_namespace>, data=0x0)
at ../../gcc/gcc/cp/decl.c:1765
#7 0x0805a799 in walk_namespaces (f=0x805a890 <wrapup_globals_for_namespace>,
data=0x0) at ../../gcc/gcc/cp/decl.c:1779
#8 0x080c27d6 in finish_file () at ../../gcc/gcc/cp/decl2.c:2807
#9 0x080e1a4d in yyparse () at ../../gcc/gcc/cp/parser.c:14666
#10 0x08149c61 in c_common_parse_file (set_yydebug=0)
at ../../gcc/gcc/c-opts.c:1634
#11 0x08356d37 in compile_file () at ../../gcc/gcc/toplev.c:2252
#12 0x0835c389 in do_compile () at ../../gcc/gcc/toplev.c:5648
#13 0x0835c3f9 in toplev_main (argc=2, argv=0x2) at ../../gcc/gcc/toplev.c:5679
#14 0x08155457 in main (argc=2, argv=0xbffff5f4) at ../../gcc/gcc/main.c:37
#15 0x400297f7 in __libc_start_main () from /lib/i686/libc.so.6
varasm.c:795
/* Check that we are not being given an automatic variable. */
/* A weak alias has TREE_PUBLIC set but not the other bits. */
if (TREE_CODE (decl) == PARM_DECL
|| TREE_CODE (decl) == RESULT_DECL
|| (TREE_CODE (decl) == VAR_DECL
&& !TREE_STATIC (decl)
&& !TREE_PUBLIC (decl)
&& !DECL_EXTERNAL (decl)
&& !DECL_REGISTER (decl)))
abort ();
however decl is a temporary:
(gdb) p debug_tree (decl)
<var_decl 0x401db3f0 T.1
type <pointer_type 0x401d8e00
type <array_type 0x401d8d90 type <integer_type 0x4018de70 char>
BLK
size <integer_cst 0x401d5690 constant 56>
unit size <integer_cst 0x401873b8 constant 7>
align 8 symtab 0 alias set -1 domain <integer_type 0x401d8c40>
pointer_to_this <pointer_type 0x401d8e00>>
unsigned SI
size <integer_cst 0x40179fdc constant 32>
unit size <integer_cst 0x40187054 constant 4>
align 32 symtab 0 alias set -1>
unsigned used SI file /home/seb/test/test/nsTest.cc line 7 size <integer_cst 0x40179fdc 32> unit size <integer_cst 0x40187054 4>
align 32 context <function_decl 0x401d8f50 foo> chain <var_decl 0x401db460 T.2>
/home/seb/test/test/nsTest.cc:7>
(gdb) p debug_generic_stmt (exp)
{
T.1 = "foobar";
T.2 = (const char *)T.1;
T.3 = __builtin_memcmp (c, T.2, 7);
return T.3;
}