On Wed, Nov 12, 2014 at 3:54 PM, Jakub Jelinek <ja...@redhat.com> wrote:
> On Wed, Nov 12, 2014 at 03:50:19PM +0100, Mark Wielaard wrote:
>> On Mon, 2014-10-13 at 10:33 +0200, Mark Wielaard wrote:
>> > On Wed, 2014-10-08 at 12:13 +0200, Mark Wielaard wrote:
>> > > This patch was written a long time ago by Jakub and has been in Fedora
>> > > gcc for some time. All I did was rebase it to current gcc trunk
>> > > and add a testcase. Back when it was originally proposed the issue was
>> > > that because DWARF was generated late adding new lang hooks for this
>> > > was problematic for LTO. Now that there is a move towards generating
>> > > DWARF early I am hoping this patch can finally make it to mainline gcc.
>> >
>> > Ping.
>>
>> Ping again.
>
> I think we want this (also extended for C11/C++11/C++14 afterwards), even
> when the early debug bits won't be ready for GCC 5; LTO will just continue
> claiming to be old C (or whatever it claims right now), but there is
> hope it will be improved for GCC 6.
>
> But, I can't approve my own patch...  Richard, can you live with this?

Why doesn't the patch simply make the FE return sth different
in lang_hooks.name?  Like "GNU C99" or "GNU ObjC"?  Or
even better change that to an unsigned int containing
DW_LANG_* directly and not a string?

I don't see why we would want another langhook whose value is
not reflected in TRANSLATION_UNIT_LANGUAGE.

Richard.

>> > > This lang hook will be more useful when DWARFv5 gets out, which is
>> > > supposed to define language identifiers for newer C and C++ versions.
>> > >
>> > > Previous discussions:
>> > > http://gcc.gnu.org/ml/gcc-patches/2009-03/msg00858.html
>> > > http://gcc.gnu.org/ml/gcc-patches/2010-04/msg00991.html
>> > >
>> > > gcc/ChangeLog
>> > >
>> > > 2009-03-18  Jakub Jelinek  <ja...@redhat.com>
>> > >
>> > >   PR debug/38757
>> > >   * langhooks.h (struct lang_hooks): Add source_language langhook.
>> > >   * langhooks-def.h (LANG_HOOKS_SOURCE_LANGUAGE): Define to NULL.
>> > >   (LANG_HOOKS_INITIALIZER): Add LANG_HOOKS_SOURCE_LANGUAGE.
>> > >   * dwarf2out.c (add_prototyped_attribute): Add DW_AT_prototype
>> > >   also for DW_LANG_{C,C99,ObjC}.
>> > >   (gen_compile_unit_die): Use lang_hooks.source_language () to
>> > >   determine if DW_LANG_C99 or DW_LANG_C89 should be returned.
>> > >
>> > > gcc/c/ChangeLog
>> > >
>> > > 2009-03-18  Jakub Jelinek  <ja...@redhat.com>
>> > >
>> > >   PR debug/38757
>> > >   * c-lang.c (c_source_language): New function.
>> > >   (LANG_HOOKS_SOURCE_LANGUAGE): Define.
>> > >
>> > > gcc/testsuite/ChangeLog
>> > >
>> > > 2014-10-08  Mark Wielaard  <m...@redhat.com>
>> > >
>> > >   PR debug/38757
>> > >   * gcc.dg/debug/dwarf2/lang-c89.c: New test.
>> > >   * gcc.dg/debug/dwarf2/lang-c99.c: Likewise.
>> > > ---
>> > >  gcc/ChangeLog                                | 11 +++++++++++
>> > >  gcc/c/ChangeLog                              |  6 ++++++
>> > >  gcc/c/c-lang.c                               |  8 ++++++++
>> > >  gcc/dwarf2out.c                              | 19 ++++++++++++++++---
>> > >  gcc/langhooks-def.h                          |  4 +++-
>> > >  gcc/langhooks.h                              |  4 ++++
>> > >  gcc/testsuite/ChangeLog                      |  6 ++++++
>> > >  gcc/testsuite/gcc.dg/debug/dwarf2/lang-c89.c |  6 ++++++
>> > >  gcc/testsuite/gcc.dg/debug/dwarf2/lang-c99.c |  6 ++++++
>> > >  9 files changed, 66 insertions(+), 4 deletions(-)
>> > >  create mode 100644 gcc/testsuite/gcc.dg/debug/dwarf2/lang-c89.c
>> > >  create mode 100644 gcc/testsuite/gcc.dg/debug/dwarf2/lang-c99.c
>> > >
>> > > diff --git a/gcc/c/c-lang.c b/gcc/c/c-lang.c
>> > > index 97c0443..dadeb1a 100644
>> > > --- a/gcc/c/c-lang.c
>> > > +++ b/gcc/c/c-lang.c
>> > > @@ -35,6 +35,12 @@ along with GCC; see the file COPYING3.  If not see
>> > >
>> > >  enum c_language_kind c_language = clk_c;
>> > >
>> > > +static int
>> > > +c_source_language (void)
>> > > +{
>> > > +  return flag_isoc99 ? 1999 : 1989;
>> > > +}
>> > > +
>> > >  /* Lang hooks common to C and ObjC are declared in c-objc-common.h;
>> > >     consequently, there should be very few hooks below.  */
>> > >
>> > > @@ -44,6 +50,8 @@ enum c_language_kind c_language = clk_c;
>> > >  #define LANG_HOOKS_INIT c_objc_common_init
>> > >  #undef LANG_HOOKS_INIT_TS
>> > >  #define LANG_HOOKS_INIT_TS c_common_init_ts
>> > > +#undef LANG_HOOKS_SOURCE_LANGUAGE
>> > > +#define LANG_HOOKS_SOURCE_LANGUAGE c_source_language
>> > >
>> > >  /* Each front end provides its own lang hook initializer.  */
>> > >  struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
>> > > diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
>> > > index 59c05ed..4932cd0 100644
>> > > --- a/gcc/dwarf2out.c
>> > > +++ b/gcc/dwarf2out.c
>> > > @@ -16708,9 +16708,18 @@ add_bit_size_attribute (dw_die_ref die, tree 
>> > > decl)
>> > >  static inline void
>> > >  add_prototyped_attribute (dw_die_ref die, tree func_type)
>> > >  {
>> > > -  if (get_AT_unsigned (comp_unit_die (), DW_AT_language) == DW_LANG_C89
>> > > -      && prototype_p (func_type))
>> > > -    add_AT_flag (die, DW_AT_prototyped, 1);
>> > > +  switch (get_AT_unsigned (comp_unit_die (), DW_AT_language))
>> > > +    {
>> > > +    case DW_LANG_C:
>> > > +    case DW_LANG_C89:
>> > > +    case DW_LANG_C99:
>> > > +    case DW_LANG_ObjC:
>> > > +      if (prototype_p (func_type))
>> > > + add_AT_flag (die, DW_AT_prototyped, 1);
>> > > +      break;
>> > > +    default:
>> > > +      break;
>> > > +    }
>> > >  }
>> > >
>> > >  /* Add an 'abstract_origin' attribute below a given DIE.  The DIE is 
>> > > found
>> > > @@ -19544,6 +19553,10 @@ gen_compile_unit_die (const char *filename)
>> > >   language = DW_LANG_ObjC;
>> > >        else if (strcmp (language_string, "GNU Objective-C++") == 0)
>> > >   language = DW_LANG_ObjC_plus_plus;
>> > > +      else if (strcmp (language_string, "GNU C") == 0
>> > > +        && lang_hooks.source_language
>> > > +        && lang_hooks.source_language () >= 1999)
>> > > + language = DW_LANG_C99;
>> > >        else if (dwarf_version >= 5 || !dwarf_strict)
>> > >   {
>> > >     if (strcmp (language_string, "GNU Go") == 0)
>> > > diff --git a/gcc/langhooks-def.h b/gcc/langhooks-def.h
>> > > index e5ae3e3..b6c8dd4 100644
>> > > --- a/gcc/langhooks-def.h
>> > > +++ b/gcc/langhooks-def.h
>> > > @@ -120,6 +120,7 @@ extern bool lhd_omp_mappable_type (tree);
>> > >  #define LANG_HOOKS_BLOCK_MAY_FALLTHRU    hook_bool_const_tree_true
>> > >  #define LANG_HOOKS_EH_USE_CXA_END_CLEANUP        false
>> > >  #define LANG_HOOKS_DEEP_UNSHARING        false
>> > > +#define LANG_HOOKS_SOURCE_LANGUAGE       NULL
>> > >
>> > >  /* Attribute hooks.  */
>> > >  #define LANG_HOOKS_ATTRIBUTE_TABLE               NULL
>> > > @@ -313,7 +314,8 @@ extern void lhd_end_section (void);
>> > >    LANG_HOOKS_EH_PROTECT_CLEANUP_ACTIONS, \
>> > >    LANG_HOOKS_BLOCK_MAY_FALLTHRU, \
>> > >    LANG_HOOKS_EH_USE_CXA_END_CLEANUP, \
>> > > -  LANG_HOOKS_DEEP_UNSHARING \
>> > > +  LANG_HOOKS_DEEP_UNSHARING, \
>> > > +  LANG_HOOKS_SOURCE_LANGUAGE \
>> > >  }
>> > >
>> > >  #endif /* GCC_LANG_HOOKS_DEF_H */
>> > > diff --git a/gcc/langhooks.h b/gcc/langhooks.h
>> > > index 32e76f9..0022516 100644
>> > > --- a/gcc/langhooks.h
>> > > +++ b/gcc/langhooks.h
>> > > @@ -485,6 +485,10 @@ struct lang_hooks
>> > >       gimplification.  */
>> > >    bool deep_unsharing;
>> > >
>> > > +  /* Return year of the source language standard version if the FE 
>> > > supports
>> > > +     multiple versions of the standard.  */
>> > > +  int (*source_language) (void);
>> > > +
>> > >    /* Whenever you add entries here, make sure you adjust langhooks-def.h
>> > >       and langhooks.c accordingly.  */
>> > >  };
>> > > diff --git a/gcc/testsuite/gcc.dg/debug/dwarf2/lang-c89.c 
>> > > b/gcc/testsuite/gcc.dg/debug/dwarf2/lang-c89.c
>> > > new file mode 100644
>> > > index 0000000..6292cf8
>> > > --- /dev/null
>> > > +++ b/gcc/testsuite/gcc.dg/debug/dwarf2/lang-c89.c
>> > > @@ -0,0 +1,6 @@
>> > > +/* { dg-do compile } */
>> > > +/* { dg-options "-O -std=c89 -g -dA" } */
>> > > +/* DW_LANG_C89 = 0x0001 */
>> > > +/* { dg-final { scan-assembler "0x1.*DW_AT_language" } } */
>> > > +
>> > > +int version;
>> > > diff --git a/gcc/testsuite/gcc.dg/debug/dwarf2/lang-c99.c 
>> > > b/gcc/testsuite/gcc.dg/debug/dwarf2/lang-c99.c
>> > > new file mode 100644
>> > > index 0000000..1d789fe
>> > > --- /dev/null
>> > > +++ b/gcc/testsuite/gcc.dg/debug/dwarf2/lang-c99.c
>> > > @@ -0,0 +1,6 @@
>> > > +// { dg-do compile }
>> > > +// { dg-options "-O -std=c99 -g -dA" }
>> > > +// DW_LANG_C99 = 0x000c
>> > > +// { dg-final { scan-assembler "0xc.*DW_AT_language" } } */
>> > > +
>> > > +int version;
>> >
>
>         Jakub

Reply via email to