This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: string constant of the constant pool entry..
- From: Richard Sandiford <rdsandiford at googlemail dot com>
- To: Umesh Kalappa <umesh dot kalappa0 at gmail dot com>
- Cc: "gcc\ at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Tue, 03 Mar 2015 21:59:01 +0000
- Subject: Re: string constant of the constant pool entry..
- Authentication-results: sourceware.org; auth=none
- References: <CAGfacvRWTTUE3EMkCEx-nZwysZc_XTarfY8afoPo-tSLQ6iLpQ at mail dot gmail dot com>
Umesh Kalappa <umesh.kalappa0@gmail.com> writes:
> Hi All,
>
> I'm trying to fetch the string constant from the constant pool entry
> for the symbol_ref rtx like
>
> c sample
>
> int i;
> int main()
> {
> printf("%d",i);
> }
>
> rtl is
>
> (gdb) p debug_rtx(val)
> (symbol_ref/f:SI ("*.LC0") [flags 0x2] <var_decl 0xb7c293f4 *.LC0>)
The SYMBOL_REF_DECL is a VAR_DECL whose DECL_INITIAL is the constant. So:
> corresponding asm
>
> .section .rodata,code
> .align 2
> .LC0:
> .ascii "%d\000"
>
>
> sample code to fetch the string "%d"
>
> tree sym = SYMBOL_REF_DECL(rtx);
>
> if (!(sym && (TREE_CODE(sym)==STRING_CST) && STRING_CST_CHECK(sym)))
> sym = 0;
...I think you want:
if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
{
tree str = DECL_INITIAL (SYMBOL_REF_DECL (symbol));
if (TREE_CODE (str) == STRING_CST)
...
}
(STRING_CST_CHECK is really local to the tree.h macros, it shouldn't
be used elsewhere.)
Thanks,
Richard