possible bug with -fsecond-underscore ?

Bernhard Reutner-Fischer rep.dot.nop@gmail.com
Mon Sep 24 11:39:00 GMT 2018


On Mon, 24 Sep 2018 at 13:26, Bernhard Reutner-Fischer
<rep.dot.nop@gmail.com> wrote:
>
> Hi there.
>
> gfc_sym_mangled_function_id() and gfc_sym_mangled_common_id both have
> (identical, but that's for another patch to maybe factor it out) the
> following code for underscore handling which looks suspicious:
>
> ---8<---
> static tree
> gfc_sym_mangled_common_id (gfc_common_head *com)
> {
>   int has_underscore;
>   const char *name;
>
>   /* Get the name out of the common block pointer.  */
>   name = com->name;
>
>   /* If we're supposed to do a bind(c).  */
>   if (com->is_bind_c && com->binding_label)
>     return maybe_get_identifier (com->binding_label);
>
>   if (name == gfc_get_string (BLANK_COMMON_NAME))
>     return maybe_get_identifier (name);
>
>   if (flag_underscoring)
>     {
>       has_underscore = strchr (name, '_') != 0;
>       if (flag_second_underscore && has_underscore)
>         return gfc_get_identifier("%s__", name);
>       else
>         return gfc_get_identifier("%s_", name);
>     }
>   else
>     return maybe_get_identifier (name);
> }
> ---8<---
>
> the strchr looks somewhat suspicious, IMHO:
> Isn't what the code really wants to check the fact whether or not the
> name *already*ends* with an underscore?
>
> b@h:/tmp/o$ printf "common /C/ j,i\nend" | gfortran -x f95-cpp-input -
> -ffree-form -c -o huh.o -DC=foo && readelf -s huh.o | grep foo
>     14: 0000000000000010     8 OBJECT  GLOBAL DEFAULT  COM foo_
> b@h:/tmp/o$ printf "common /C/ j,i\nend" | gfortran -x f95-cpp-input -
> -ffree-form -c -o huh.o -DC=foo -fsecond-underscore && readelf -s
> huh.o | grep foo
>     14: 0000000000000010     8 OBJECT  GLOBAL DEFAULT  COM foo_
> b@h:/tmp/o$ printf "common /C/ j,i\nend" | gfortran -x f95-cpp-input -
> -ffree-form -c -o huh.o -DC=foo_bar && readelf -s huh.o | grep foo
>     14: 0000000000000010     8 OBJECT  GLOBAL DEFAULT  COM foo_bar_
> b@h:/tmp/o$ printf "common /C/ j,i\nend" | gfortran -x f95-cpp-input -
> -ffree-form -c -o huh.o -DC=foo_bar -fsecond-underscore && readelf -s
> huh.o | grep foo
>     14: 0000000000000010     8 OBJECT  GLOBAL DEFAULT  COM foo_bar__
>
> I had expected "common /foo/" with -fsecond-underscore to produce a
> "foo__" sym, no?
> What am i missing?

I should have read the documentation of -fsecond-underscore for
starters and maybe PR51820
"[doc] underscoring documentation incorrect" .

sorry for the noise.. :(



More information about the Fortran mailing list