This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: How to access points-to information for function pointers
- From: Richard Biener <richard dot guenther at gmail dot com>
- To: Swati Rathi <swatirathi at cse dot iitb dot ac dot in>
- Cc: GCC Development <gcc at gcc dot gnu dot org>
- Date: Tue, 29 Apr 2014 11:17:41 +0200
- Subject: Re: How to access points-to information for function pointers
- Authentication-results: sourceware.org; auth=none
- References: <535A8521 dot 1030300 at cse dot iitb dot ac dot in> <d67a70c3-3a71-44ac-b428-72e7fd87279f at email dot android dot com> <535B8B06 dot 3030007 at cse dot iitb dot ac dot in> <3afb1f89-4b04-4088-9ce5-7b34d298ea70 at email dot android dot com> <CAFiYyc3cE_RC3Rmjvhz=FCAvYhxfa4CDNxDih9JpXL+c6TVMUQ at mail dot gmail dot com> <535F45F8 dot 1030300 at cse dot iitb dot ac dot in>
On Tue, Apr 29, 2014 at 8:26 AM, Swati Rathi <swatirathi@cse.iitb.ac.in> wrote:
> On Monday 28 April 2014 02:46 PM, Richard Biener wrote:
>>
>> On Sat, Apr 26, 2014 at 4:07 PM, Richard Biener
>> <richard.guenther@gmail.com> wrote:
>>>
>>> On April 26, 2014 12:31:34 PM CEST, Swati Rathi
>>> <swatirathi@cse.iitb.ac.in> wrote:
>>>>
>>>> On Friday 25 April 2014 11:11 PM, Richard Biener wrote:
>>>>>
>>>>> On April 25, 2014 5:54:09 PM CEST, Swati Rathi
>>>>
>>>> <swatirathi@cse.iitb.ac.in> wrote:
>>>>>>
>>>>>> Hello,
>>>>>>
>>>>>> I am trying to print points-to information for SSA variables as
>>>>
>>>> below.
>>>>>>
>>>>>> for (i = 1; i < num_ssa_names; i++)
>>>>>> {
>>>>>> tree ptr = ssa_name (i);
>>>>>> struct ptr_info_def *pi;
>>>>>>
>>>>>> if (ptr == NULL_TREE
>>>>>> || SSA_NAME_IN_FREE_LIST (ptr))
>>>>>> continue;
>>>>>>
>>>>>> pi = SSA_NAME_PTR_INFO (ptr);
>>>>>> if (pi)
>>>>>> dump_points_to_info_for (file, ptr);
>>>>>> }
>>>>>>
>>>>>> -------------------------------------------------------------
>>>>>> My test program is given below :
>>>>>>
>>>>>> int main()
>>>>>> {
>>>>>> int *p, i, j;
>>>>>> void (*fp1)();
>>>>>>
>>>>>> if (i)
>>>>>> {
>>>>>> p = &i;
>>>>>> fp1 = fun1;
>>>>>> }
>>>>>> else
>>>>>> {
>>>>>> p = &j;
>>>>>> fp1 = fun2;
>>>>>> }
>>>>>>
>>>>>> fp1();
>>>>>>
>>>>>> printf ("\n%d %d\n", *p, i);
>>>>>> return 0;
>>>>>> }
>>>>>> -------------------------------------------------------------
>>>>>> I get the output as :-
>>>>>>
>>>>>> p_1, points-to vars: { i j }
>>>>>> fp1_2, points-to vars: { }
>>>>>> -------------------------------------------------------------
>>>>>>
>>>>>> Why is the pointees for function pointer not getting dumped?
>>>>>
>>>>> It's just not saved.
>>>>
>>>> Can we modify the code to preserve values for function pointer SSA
>>>> names?
>>>
>>> Sure.
>>
>> Index: gcc/tree-ssa-structalias.c
>> ===================================================================
>> --- gcc/tree-ssa-structalias.c (revision 209782)
>> +++ gcc/tree-ssa-structalias.c (working copy)
>> @@ -6032,7 +6032,8 @@ set_uids_in_ptset (bitmap into, bitmap f
>>
>> if (TREE_CODE (vi->decl) == VAR_DECL
>> || TREE_CODE (vi->decl) == PARM_DECL
>> - || TREE_CODE (vi->decl) == RESULT_DECL)
>> + || TREE_CODE (vi->decl) == RESULT_DECL
>> + || TREE_CODE (vi->decl) == FUNCTION_DECL)
>> {
>> /* If we are in IPA mode we will not recompute points-to
>> sets after inlining so make sure they stay valid. */
>
> Thanks a lot. :) This is of great help.
>
>
>> note that there isn't a convenient way to go back from a bit in the
>> points-to bitmap to the actual FUNCTION_DECL refered to.
>
> The bitmap is set by identifying the bit using DECL_PT_UID.
> For variables, referenced_var_lookup returns the associated variable.
Note that this table is gone from recent GCC.
> For FUNCTION_DECL's, all we need to do is store a mapping between uid and
> FUNCTION_DECL.
> Is this correct?
Correct.
Richard.
>
>>
>> Richard.
>>
>>>> What is the reason that it is not preserved for function pointers?
>>>
>>> Nobody uses this information.
>>>
>>>> Another alternative approach would be to replicate the code (of
>>>> pass_ipa_pta) and use the information before deleting it.
>>>>
>>>> Is there any other way to access this information?
>>>
>>> You can of course recompute it when needed.
>>>
>>> Richard.
>>>
>>>>>> How can I access this information?
>>>>>>
>>>>>>
>>>>>> Regards,
>>>>>> Swati
>>>
>>>
>