[patch, fortran] PR120049 - ICE when using IS_C_ASSOCIATED ()

Harald Anlauf anlauf@gmx.de
Sun May 18 21:10:07 GMT 2025


Hi Jerry,

I found 2 corner invalid cases which are silently accepted with
your patch when iso_c_binding is used indirectly:

   print *, c_associated(c_loc(val), C_NULL_FUNPTR)
   print *, c_associated(C_NULL_FUNPTR, c_loc(val))

These should get rejected, too.  Can you see how to catch these, too?

Thanks,
Harald

On 5/17/25 19:22, Jerry D wrote:
> Hello all,
> 
> The attached patch revises the logic of the checks in 
> gfc_check_c_associated to handle previous cases that ICE'ed as seen in 
> the PR. There are multiple gotchas in these cases, particularly with the 
> optional c_ptr_2 argument.
> 
> I factored the logic into two new helper functions. This helps to see 
> what is happening and allows the c_ptr_1 checks to be performed 
> separately in the event the c_ptr_2 checks succeed.
> 
> In  gfc_typename we did not handle the BT_VOID case which occurs in some 
> of the error conditions.  I thought to possibly let it fall through to 
> "UNKNOWN".  As it is with the patch I return "VOID".
> 
> I added a new test case.
> 
> I want to add Steve as Co-author as soon as I figure out how to do that 
> with the git machinery.
> 
> Regression tested on x86_64.  OK for trunk and eventual backport to 15?
> 
> Regards,
> 
> Jerry
> 
> Author: Jerry DeLisle <jvdelisle@gcc.gnu.org>
> Date:   Sat May 17 09:45:14 2025 -0700
> 
>      Fortran: Fix c_associated argument checks.
> 
>            PR fortran/120049
> 
>      gcc/fortran/ChangeLog:
> 
>            * check.cc (gfc_check_c_associated): Use new helper functions.
>              Only call check_c_ptr_1 if optional c_ptr_2 tests succeed.
>              (check_c_ptr_1):  Handle only c_ptr_1 checks.
>              (check_c_ptr_2): Expand checks for c_ptr_2 and handles cases
>              where there is no derived pointer in the gfc_expr and check
>              the inmod_sym_id only if it exists.
>              * misc.cc (gfc_typename): Handle the case for BT_VOID rather
>              than throw an internal error.
> 
>      gcc/testsuite/ChangeLog:
> 
>              * gfortran.dg/pr120049_2.f90: New test.
> 




More information about the Gcc-patches mailing list