diff mbox

PR debug/38757 gcc does not emit DW_LANG_C99

Message ID 1412763235-23197-1-git-send-email-mjw@redhat.com
State New
Headers show

Commit Message

Mark Wielaard Oct. 8, 2014, 10:13 a.m. UTC
Hi,

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.

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  <jakub@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  <jakub@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  <mjw@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

Comments

Marek Polacek Oct. 8, 2014, 10:17 a.m. UTC | #1
On Wed, Oct 08, 2014 at 12:13:55PM +0200, Mark Wielaard wrote:
> Hi,
> 
> 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.
> 
> This lang hook will be more useful when DWARFv5 gets out, which is
> supposed to define language identifiers for newer C and C++ versions.
 
It might have been discussed elsewhere, so sorry for not paying attention,
but what about DW_LANG_C11?

	Marek
Mark Wielaard Oct. 8, 2014, 10:29 a.m. UTC | #2
On Wed, 2014-10-08 at 12:17 +0200, Marek Polacek wrote:
> On Wed, Oct 08, 2014 at 12:13:55PM +0200, Mark Wielaard wrote:
> > This lang hook will be more useful when DWARFv5 gets out, which is
> > supposed to define language identifiers for newer C and C++ versions.
>  
> It might have been discussed elsewhere, so sorry for not paying attention,
> but what about DW_LANG_C11?

That is one of the new language versions to hopefully gets a definition
with DWARFv5. http://dwarfstd.org/ShowIssue.php?issue=140330.1

Cheers,

Mark
Jakub Jelinek Oct. 8, 2014, 10:35 a.m. UTC | #3
On Wed, Oct 08, 2014 at 12:29:38PM +0200, Mark Wielaard wrote:
> On Wed, 2014-10-08 at 12:17 +0200, Marek Polacek wrote:
> > On Wed, Oct 08, 2014 at 12:13:55PM +0200, Mark Wielaard wrote:
> > > This lang hook will be more useful when DWARFv5 gets out, which is
> > > supposed to define language identifiers for newer C and C++ versions.
> >  
> > It might have been discussed elsewhere, so sorry for not paying attention,
> > but what about DW_LANG_C11?
> 
> That is one of the new language versions to hopefully gets a definition
> with DWARFv5. http://dwarfstd.org/ShowIssue.php?issue=140330.1

Yeah, that is 0x1d it seems, but we don't have
DW_LANG_C_plus_plus_14
unfortunately.  IMHO still something that must be added to DWARF5.

	Jakub
Mark Wielaard Oct. 8, 2014, 11:04 a.m. UTC | #4
On Wed, 2014-10-08 at 12:35 +0200, Jakub Jelinek wrote:
> On Wed, Oct 08, 2014 at 12:29:38PM +0200, Mark Wielaard wrote:
> > On Wed, 2014-10-08 at 12:17 +0200, Marek Polacek wrote:
> > > On Wed, Oct 08, 2014 at 12:13:55PM +0200, Mark Wielaard wrote:
> > > > This lang hook will be more useful when DWARFv5 gets out, which is
> > > > supposed to define language identifiers for newer C and C++ versions.
> > >  
> > > It might have been discussed elsewhere, so sorry for not paying attention,
> > > but what about DW_LANG_C11?
> > 
> > That is one of the new language versions to hopefully gets a definition
> > with DWARFv5. http://dwarfstd.org/ShowIssue.php?issue=140330.1
> 
> Yeah, that is 0x1d it seems, but we don't have
> DW_LANG_C_plus_plus_14
> unfortunately.  IMHO still something that must be added to DWARF5.

Good point. There is a proposal to add DW_LANG_C_plus_plus_03 (0x17) and
DW_LANG_C_plus_plus_11 (0x18)
http://dwarfstd.org/ShowIssue.php?issue=120628.1
But no DW_LANG_C_plus_plus_14 yet. Probably because C++14 only got
approved last August. Although it has been too late to submit new
proposals for DWARFv5 since a couple of months now I did submit one
anyway. Hopefully we can still sneak it in before there is a first draft
of DWARFv5 out. http://article.gmane.org/gmane.comp.standards.dwarf/218

Cheers,

Mark
Mark Wielaard Oct. 13, 2014, 8:33 a.m. UTC | #5
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.

> 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  <jakub@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  <jakub@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  <mjw@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;
Mark Wielaard Nov. 12, 2014, 2:50 p.m. UTC | #6
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.

> > 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  <jakub@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  <jakub@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  <mjw@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 Jelinek Nov. 12, 2014, 2:54 p.m. UTC | #7
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?

> > > 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  <jakub@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  <jakub@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  <mjw@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
Richard Biener Nov. 12, 2014, 3:21 p.m. UTC | #8
On Wed, Nov 12, 2014 at 3:54 PM, Jakub Jelinek <jakub@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  <jakub@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  <jakub@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  <mjw@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
Jakub Jelinek Nov. 12, 2014, 3:33 p.m. UTC | #9
On Wed, Nov 12, 2014 at 04:21:09PM +0100, Richard Biener wrote:
> On Wed, Nov 12, 2014 at 3:54 PM, Jakub Jelinek <jakub@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?

That is an option too, Mark, do you want to work on such a patch?

	Jakub
Mark Wielaard Nov. 12, 2014, 3:46 p.m. UTC | #10
On Wed, 2014-11-12 at 16:33 +0100, Jakub Jelinek wrote:
> On Wed, Nov 12, 2014 at 04:21:09PM +0100, Richard Biener wrote:
> > On Wed, Nov 12, 2014 at 3:54 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> > > 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?
> 
> That is an option too, Mark, do you want to work on such a patch?

I don't mind changing the language hook to return the actual DW_LANG_*
constant directly, that seems like a nice cleanup.

But I don't think we can just replace TRANSLATION_UNIT_LANGUAGE and
lang_hooks.name. The name is (explicitly) const and isused to identify
the frontend used for a particular language in various places (for
example some backends seem to use it to write out some language/abi
information, or to detect when to use IEEE compliance mode, pch uses it
to match whether a header can be reused, the constant folder uses it to
make some decisions, etc.

So shall I change the patch so that the lang hook explicitly encodes the
DW_LANG_* constant/language standard variant in use, but keep
lang_hooks.name as is to not break any other users?

Thanks,

Mark
Jakub Jelinek Nov. 12, 2014, 4:31 p.m. UTC | #11
On Wed, Nov 12, 2014 at 04:46:39PM +0100, Mark Wielaard wrote:
> I don't mind changing the language hook to return the actual DW_LANG_*
> constant directly, that seems like a nice cleanup.
> 
> But I don't think we can just replace TRANSLATION_UNIT_LANGUAGE and
> lang_hooks.name. The name is (explicitly) const and isused to identify

It is const char *name; , so it isn't const, just what it points is const.
So you can change if (just after parsing the options set
  lang_hooks.name = "GNU C11";
or similar).

> the frontend used for a particular language in various places (for
> example some backends seem to use it to write out some language/abi
> information, or to detect when to use IEEE compliance mode, pch uses it
> to match whether a header can be reused, the constant folder uses it to
> make some decisions, etc.

If Richard prefers to use lang_hooks.name, I'd just change all the users
of lang_hooks.name or TRANSLATION_UNIT_LANGUAGE that need changing.
For PCH it is ok as is, parsing a header can depend on the language version,
for the cases that strcmp (lang_hooks.name, "GNU C++") I'd replace it
with strncmp (lang_hooks.name, "GNU C++", 7), you are not going to change
the ObjC/ObjC++ stuff, just in dwarf2out.c in addition to handling the new
names you also need to do something better for the LTO merging of
TRANSLATION_UNIT_LANGUAGE - say if merging "GNU C", "GNU C99" and "GNU C11",
pick up the newest out of those, if C++ is mixed into it, pick probably the
highest C++ version.
> 
> So shall I change the patch so that the lang hook explicitly encodes the
> DW_LANG_* constant/language standard variant in use, but keep
> lang_hooks.name as is to not break any other users?

	Jakub
Richard Biener Nov. 13, 2014, 11:08 a.m. UTC | #12
On Wed, Nov 12, 2014 at 5:31 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> On Wed, Nov 12, 2014 at 04:46:39PM +0100, Mark Wielaard wrote:
>> I don't mind changing the language hook to return the actual DW_LANG_*
>> constant directly, that seems like a nice cleanup.
>>
>> But I don't think we can just replace TRANSLATION_UNIT_LANGUAGE and
>> lang_hooks.name. The name is (explicitly) const and isused to identify
>
> It is const char *name; , so it isn't const, just what it points is const.
> So you can change if (just after parsing the options set
>   lang_hooks.name = "GNU C11";
> or similar).
>
>> the frontend used for a particular language in various places (for
>> example some backends seem to use it to write out some language/abi
>> information, or to detect when to use IEEE compliance mode, pch uses it
>> to match whether a header can be reused, the constant folder uses it to
>> make some decisions, etc.
>
> If Richard prefers to use lang_hooks.name, I'd just change all the users
> of lang_hooks.name or TRANSLATION_UNIT_LANGUAGE that need changing.
> For PCH it is ok as is, parsing a header can depend on the language version,
> for the cases that strcmp (lang_hooks.name, "GNU C++") I'd replace it
> with strncmp (lang_hooks.name, "GNU C++", 7), you are not going to change
> the ObjC/ObjC++ stuff, just in dwarf2out.c in addition to handling the new
> names you also need to do something better for the LTO merging of
> TRANSLATION_UNIT_LANGUAGE - say if merging "GNU C", "GNU C99" and "GNU C11",
> pick up the newest out of those, if C++ is mixed into it, pick probably the
> highest C++ version.

Right.

(that lang_hooks.name checks in fold-const.c really really really have to go!)

Btw, I have nothing against changing TRANSLATION_UNIT_LANGUAGE
to DW_LANG_* directly - we only use it for choosing the language
of the dwarf unit.  This would of course mean to change its initialization
from

  TRANSLATION_UNIT_LANGUAGE (tu) = lang_hooks.name;

to sth like

  TRANSLATION_UNIT_LANGUAGE (tu) = lang_hooks.dw_lang;

which means adding a langhook (thus more similar to your original
patch).

Richard.

>>
>> So shall I change the patch so that the lang hook explicitly encodes the
>> DW_LANG_* constant/language standard variant in use, but keep
>> lang_hooks.name as is to not break any other users?
>
>         Jakub
Jakub Jelinek Nov. 13, 2014, 11:17 a.m. UTC | #13
On Thu, Nov 13, 2014 at 12:08:01PM +0100, Richard Biener wrote:
> Btw, I have nothing against changing TRANSLATION_UNIT_LANGUAGE
> to DW_LANG_* directly - we only use it for choosing the language
> of the dwarf unit.  This would of course mean to change its initialization
> from
> 
>   TRANSLATION_UNIT_LANGUAGE (tu) = lang_hooks.name;
> 
> to sth like
> 
>   TRANSLATION_UNIT_LANGUAGE (tu) = lang_hooks.dw_lang;
> 
> which means adding a langhook (thus more similar to your original
> patch).

But that would mean having to include dwarf2 headers in every FE.

	Jakub
Richard Biener Nov. 13, 2014, 12:08 p.m. UTC | #14
On Thu, Nov 13, 2014 at 12:17 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> On Thu, Nov 13, 2014 at 12:08:01PM +0100, Richard Biener wrote:
>> Btw, I have nothing against changing TRANSLATION_UNIT_LANGUAGE
>> to DW_LANG_* directly - we only use it for choosing the language
>> of the dwarf unit.  This would of course mean to change its initialization
>> from
>>
>>   TRANSLATION_UNIT_LANGUAGE (tu) = lang_hooks.name;
>>
>> to sth like
>>
>>   TRANSLATION_UNIT_LANGUAGE (tu) = lang_hooks.dw_lang;
>>
>> which means adding a langhook (thus more similar to your original
>> patch).
>
> But that would mean having to include dwarf2 headers in every FE.

Don't see what would be bad about this, but well...

Richard.

>         Jakub
Jakub Jelinek Nov. 13, 2014, 1:07 p.m. UTC | #15
On Thu, Nov 13, 2014 at 01:08:44PM +0100, Richard Biener wrote:
> On Thu, Nov 13, 2014 at 12:17 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> > On Thu, Nov 13, 2014 at 12:08:01PM +0100, Richard Biener wrote:
> >> Btw, I have nothing against changing TRANSLATION_UNIT_LANGUAGE
> >> to DW_LANG_* directly - we only use it for choosing the language
> >> of the dwarf unit.  This would of course mean to change its initialization
> >> from
> >>
> >>   TRANSLATION_UNIT_LANGUAGE (tu) = lang_hooks.name;
> >>
> >> to sth like
> >>
> >>   TRANSLATION_UNIT_LANGUAGE (tu) = lang_hooks.dw_lang;
> >>
> >> which means adding a langhook (thus more similar to your original
> >> patch).
> >
> > But that would mean having to include dwarf2 headers in every FE.
> 
> Don't see what would be bad about this, but well...

I think strings are better than DWARF constants for middle-end thing,
say if DWARF doesn't make a difference between some language variants but
something different in the middle-end wants, or updating all the backends to
test when C++17 is released and DWARF assigns a language code for it
would be also weird.

If you want an integer instead of strings, it better should be some enum
with major and minor parts in it, so that one can easily test if it is
a C++ family, C family, C/C++ family, Fortran family etc.  Still, that would
make things hard for third party frontends, which wouldn't know what values
to use if they don't have a language code in DWARF.

	Jakub
Richard Biener Nov. 13, 2014, 1:19 p.m. UTC | #16
On Thu, Nov 13, 2014 at 2:07 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> On Thu, Nov 13, 2014 at 01:08:44PM +0100, Richard Biener wrote:
>> On Thu, Nov 13, 2014 at 12:17 PM, Jakub Jelinek <jakub@redhat.com> wrote:
>> > On Thu, Nov 13, 2014 at 12:08:01PM +0100, Richard Biener wrote:
>> >> Btw, I have nothing against changing TRANSLATION_UNIT_LANGUAGE
>> >> to DW_LANG_* directly - we only use it for choosing the language
>> >> of the dwarf unit.  This would of course mean to change its initialization
>> >> from
>> >>
>> >>   TRANSLATION_UNIT_LANGUAGE (tu) = lang_hooks.name;
>> >>
>> >> to sth like
>> >>
>> >>   TRANSLATION_UNIT_LANGUAGE (tu) = lang_hooks.dw_lang;
>> >>
>> >> which means adding a langhook (thus more similar to your original
>> >> patch).
>> >
>> > But that would mean having to include dwarf2 headers in every FE.
>>
>> Don't see what would be bad about this, but well...
>
> I think strings are better than DWARF constants for middle-end thing,
> say if DWARF doesn't make a difference between some language variants but
> something different in the middle-end wants, or updating all the backends to
> test when C++17 is released and DWARF assigns a language code for it
> would be also weird.
>
> If you want an integer instead of strings, it better should be some enum
> with major and minor parts in it, so that one can easily test if it is
> a C++ family, C family, C/C++ family, Fortran family etc.  Still, that would
> make things hard for third party frontends, which wouldn't know what values
> to use if they don't have a language code in DWARF.

I'm fine with the string solution as well.  Just properly transfer whatever
info you want through the translation unit decl and LTO stream it.

Richard.

>         Jakub
diff mbox

Patch

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;