9ecc1a3
2009-03-18  Jakub Jelinek  <jakub@redhat.com>
9ecc1a3
9ecc1a3
	PR debug/38757
9ecc1a3
	* langhooks.h (struct lang_hooks): Add source_language langhook.
9ecc1a3
	* langhooks-def.h (LANG_HOOKS_SOURCE_LANGUAGE): Define to NULL.
9ecc1a3
	(LANG_HOOKS_INITIALIZER): Add LANG_HOOKS_SOURCE_LANGUAGE.
9ecc1a3
	* c-lang.c (c_source_language): New function.
9ecc1a3
	(LANG_HOOKS_SOURCE_LANGUAGE): Define.
9ecc1a3
	* dwarf2out.c (add_prototyped_attribute): Add DW_AT_prototype
9ecc1a3
	also for DW_LANG_{C,C99,ObjC}.
9ecc1a3
	(gen_compile_unit_die): Use lang_hooks.source_language () to
9ecc1a3
	determine if DW_LANG_C99 or DW_LANG_C89 should be returned.
9ecc1a3
759d907
--- gcc/langhooks.h.jj	2011-01-03 12:53:05.125745450 +0100
759d907
+++ gcc/langhooks.h	2011-01-04 17:59:43.166744926 +0100
759d907
@@ -467,6 +467,10 @@ struct lang_hooks
759d907
      gimplification.  */
759d907
   bool deep_unsharing;
9ecc1a3
 
9ecc1a3
+  /* Return year of the source language standard version if the FE supports
9ecc1a3
+     multiple versions of the standard.  */
9ecc1a3
+  int (*source_language) (void);
9ecc1a3
+
9ecc1a3
   /* Whenever you add entries here, make sure you adjust langhooks-def.h
9ecc1a3
      and langhooks.c accordingly.  */
9ecc1a3
 };
759d907
--- gcc/langhooks-def.h.jj	2011-01-03 12:53:05.000000000 +0100
759d907
+++ gcc/langhooks-def.h	2011-01-04 18:00:44.858851030 +0100
759d907
@@ -118,6 +118,7 @@ extern void lhd_omp_firstprivatize_type_
759d907
 #define LANG_HOOKS_EH_PROTECT_CLEANUP_ACTIONS	NULL
8717b1d
 #define LANG_HOOKS_EH_USE_CXA_END_CLEANUP	false
759d907
 #define LANG_HOOKS_DEEP_UNSHARING	false
9ecc1a3
+#define LANG_HOOKS_SOURCE_LANGUAGE	NULL
9ecc1a3
 
9ecc1a3
 /* Attribute hooks.  */
9ecc1a3
 #define LANG_HOOKS_ATTRIBUTE_TABLE		NULL
759d907
@@ -307,7 +308,8 @@ extern void lhd_end_section (void);
8717b1d
   LANG_HOOKS_EH_RUNTIME_TYPE, \
759d907
   LANG_HOOKS_EH_PROTECT_CLEANUP_ACTIONS, \
8717b1d
   LANG_HOOKS_EH_USE_CXA_END_CLEANUP, \
759d907
-  LANG_HOOKS_DEEP_UNSHARING \
759d907
+  LANG_HOOKS_DEEP_UNSHARING, \
759d907
+  LANG_HOOKS_SOURCE_LANGUAGE \
9ecc1a3
 }
9ecc1a3
 
9ecc1a3
 #endif /* GCC_LANG_HOOKS_DEF_H */
759d907
--- gcc/c-lang.c.jj	2011-01-03 12:53:05.376056936 +0100
759d907
+++ gcc/c-lang.c	2011-01-04 17:59:43.167743798 +0100
5c29a25
@@ -36,6 +36,12 @@ along with GCC; see the file COPYING3.
9ecc1a3
 
9ecc1a3
 enum c_language_kind c_language = clk_c;
9ecc1a3
 
9ecc1a3
+static int
9ecc1a3
+c_source_language (void)
9ecc1a3
+{
9ecc1a3
+  return flag_isoc99 ? 1999 : 1989;
9ecc1a3
+}
9ecc1a3
+
9ecc1a3
 /* Lang hooks common to C and ObjC are declared in c-objc-common.h;
9ecc1a3
    consequently, there should be very few hooks below.  */
9ecc1a3
 
5c29a25
@@ -45,6 +51,8 @@ enum c_language_kind c_language = clk_c;
9ecc1a3
 #define LANG_HOOKS_INIT c_objc_common_init
5c29a25
 #undef LANG_HOOKS_INIT_TS
5c29a25
 #define LANG_HOOKS_INIT_TS c_common_init_ts
9ecc1a3
+#undef LANG_HOOKS_SOURCE_LANGUAGE
9ecc1a3
+#define LANG_HOOKS_SOURCE_LANGUAGE c_source_language
9ecc1a3
 
9ecc1a3
 /* Each front end provides its own lang hook initializer.  */
8717b1d
 struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
759d907
--- gcc/dwarf2out.c.jj	2011-01-03 12:53:05.102056475 +0100
759d907
+++ gcc/dwarf2out.c	2011-01-04 18:03:14.534151763 +0100
a539bf4
@@ -15793,9 +15793,18 @@ add_bit_size_attribute (dw_die_ref die, 
9ecc1a3
 static inline void
9ecc1a3
 add_prototyped_attribute (dw_die_ref die, tree func_type)
9ecc1a3
 {
759d907
-  if (get_AT_unsigned (comp_unit_die (), DW_AT_language) == DW_LANG_C89
759d907
-      && prototype_p (func_type))
9ecc1a3
-    add_AT_flag (die, DW_AT_prototyped, 1);
759d907
+  switch (get_AT_unsigned (comp_unit_die (), DW_AT_language))
9ecc1a3
+    {
9ecc1a3
+    case DW_LANG_C:
9ecc1a3
+    case DW_LANG_C89:
9ecc1a3
+    case DW_LANG_C99:
9ecc1a3
+    case DW_LANG_ObjC:
5c29a25
+      if (prototype_p (func_type))
9ecc1a3
+	add_AT_flag (die, DW_AT_prototyped, 1);
9ecc1a3
+      break;
9ecc1a3
+    default:
9ecc1a3
+      break;
9ecc1a3
+    }
9ecc1a3
 }
9ecc1a3
 
9ecc1a3
 /* Add an 'abstract_origin' attribute below a given DIE.  The DIE is found
a539bf4
@@ -18438,6 +18447,10 @@ gen_compile_unit_die (const char *filena
a539bf4
 	  if (strcmp (language_string, "GNU Go") == 0)
a539bf4
 	    language = DW_LANG_Go;
a539bf4
 	}
e2781b7
+      else if (strcmp (language_string, "GNU C") == 0
e2781b7
+	       && lang_hooks.source_language
e2781b7
+	       && lang_hooks.source_language () >= 1999)
9ecc1a3
+	language = DW_LANG_C99;
e2781b7
     }
9ecc1a3
 
9ecc1a3
   add_AT_unsigned (die, DW_AT_language, language);