Strings
Philip Herron
redbrain@gcc.gnu.org
Fri Mar 25 04:34:00 GMT 2011
On 23 March 2011 21:36, Ian Lance Taylor <iant@google.com> wrote:
> Philip Herron <redbrain@gcc.gnu.org> writes:
>
>> In function ‘foo’:
>> gpy1: internal compiler error: output_operand: invalid expression as operand
>> Please submit a full bug report,
>> with preprocessed source if appropriate.
>> See <http://gcc.gnu.org/bugs.html> for instructions.
>>
>> I spent quite a while trying to trace it from when
>> cgraph_finalize_compilation_unit () and it comes down to:
>
> You will get farther if you set a breakpoint on fancy_abort and on
> internal_error and get a backtrace from that point.
>
>> Example of where this string code is being used is
>>
>> const char * c_ident = IDENTIFIER_POINTER(DECL_NAME(decl));
>>
>> tree str = build_string (strlen (c_ident), c_ident);
>
> You can use IDENTIFIER_LENGTH rather than strlen.
>
>> TREE_TYPE (str) = gpy_const_char_ptr;
>> tree ident = build_fold_addr_expr (str);
>>
>> return build_call_expr (gpy_rr_decl, 3,
>> build_fold_addr_expr (decl),
>> build_int_cst (integer_type_node, n),
>> ident);
>
> You may need to put the address in a variable rather than using it
> directly. I'm not sure offhand.
>
I just tried coping something similar to whats in c-decl.c
c_make_fname_decl which sets the __FUNCTION__ at the beginning of each
function and made this:
tree type = build_array_type (unsigned_char_type_node,
build_index_type (size_int (
IDENTIFIER_LENGTH (DECL_NAME(decl))
)));
type = build_qualified_type (type, TYPE_QUAL_CONST);
tree str = build_string (IDENTIFIER_LENGTH (DECL_NAME(decl)), c_ident);
TREE_TYPE (str) = type;
tree ident = build_fold_addr_expr (str);
tree address = build_decl (BUILTINS_LOCATION, VAR_DECL,
create_tmp_var_name("C"),
type);
VEC(tree,gc) * retval = VEC_alloc (tree,gc,0);
VEC_safe_push (tree, gc, retval,
build2 (MODIFY_EXPR, type,
address, ident));
VEC_safe_push (tree, gc, retval,
build_call_expr (gpy_rr_decl, 3,
build_fold_addr_expr (decl),
build_int_cst (integer_type_node, n),
address));
But i have a segv at:
Program received signal SIGSEGV, Segmentation fault.
useless_type_conversion_p (outer_type=0xb7ac1f60,
inner_type=0xafafafaf) at ../../gcc-dev/gcc/tree-ssa.c:1222
1222 if (POINTER_TYPE_P (inner_type)
(gdb) bt
#0 useless_type_conversion_p (outer_type=0xb7ac1f60,
inner_type=0xafafafaf) at ../../gcc-dev/gcc/tree-ssa.c:1222
#1 0x0828d4e3 in gimplify_modify_expr (expr_p=0xb7aad698,
pre_p=0xbfffef44, post_p=0xbfffede0, want_value=0 '\000') at
../../gcc-dev/gcc/gimplify.c:4487
#2 0x082782f1 in gimplify_expr (expr_p=0xb7aad698, pre_p=0xbfffef44,
post_p=0xbfffede0, gimple_test_f=0x8260b60 <is_gimple_stmt>,
fallback=0) at ../../gcc-dev/gcc/gimplify.c:6737
#3 0x0827ffca in gimplify_stmt (stmt_p=0xb7aad698, seq_p=0xbfffef44)
at ../../gcc-dev/gcc/gimplify.c:5350
#4 0x082771eb in gimplify_statement_list (expr_p=0xb7aae358,
pre_p=0xbfffef44, post_p=0xbfffeeb0, gimple_test_f=0x8260b60
<is_gimple_stmt>, fallback=0) at ../../gcc-dev/gcc/gimplify.c:1439
#5 gimplify_expr (expr_p=0xb7aae358, pre_p=0xbfffef44,
post_p=0xbfffeeb0, gimple_test_f=0x8260b60 <is_gimple_stmt>,
fallback=0) at ../../gcc-dev/gcc/gimplify.c:7094
#6 0x0827ffca in gimplify_stmt (stmt_p=0xb7aae358, seq_p=0xbfffef44)
at ../../gcc-dev/gcc/gimplify.c:5350
#7 0x082804a3 in gimplify_bind_expr (expr_p=0xb7ab3adc,
pre_p=0xbffff09c) at ../../gcc-dev/gcc/gimplify.c:1172
#8 0x082783fa in gimplify_expr (expr_p=0xb7ab3adc, pre_p=0xbffff09c,
post_p=0xbfffefe0, gimple_test_f=0x8260b60 <is_gimple_stmt>,
fallback=0) at ../../gcc-dev/gcc/gimplify.c:6879
#9 0x0827ffca in gimplify_stmt (stmt_p=0xb7ab3adc, seq_p=0xbffff09c)
at ../../gcc-dev/gcc/gimplify.c:5350
#10 0x0828e6cc in gimplify_body (body_p=0xb7ab3adc, fndecl=0xb7ab3a80,
do_parms=1 '\001') at ../../gcc-dev/gcc/gimplify.c:7710
#11 0x0828ebc2 in gimplify_function_tree (fndecl=0xb7ab3a80) at
../../gcc-dev/gcc/gimplify.c:7846
#12 0x080d124d in gpy_process_functor (functor=0x8bf59d0,
base_ident=0x0, context=<value optimised out>) at
../../gcc-dev/gcc/python/py-stmt.c:386
#13 0x080d0b80 in gpy_get_tree (sym=0x8bf59d0, context=0xb7aa75e8) at
../../gcc-dev/gcc/python/py-stmt.c:472
#14 0x080d21d2 in gpy_write_globals () at ../../gcc-dev/gcc/python/py-stmt.c:613
#15 0x083ac624 in compile_file (argc=14, argv=0xbffff364) at
../../gcc-dev/gcc/toplev.c:591
#16 do_compile (argc=14, argv=0xbffff364) at ../../gcc-dev/gcc/toplev.c:1900
#17 toplev_main (argc=14, argv=0xbffff364) at ../../gcc-dev/gcc/toplev.c:1963
#18 0x080c979b in main (argc=14, argv=0xbffff364) at ../../gcc-dev/gcc/main.c:36
(gdb) quit
Its having problems when i try to set the tmp_var this string. Not
quite sure what to try at the moment.
--Phil
More information about the Gcc-help
mailing list