public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* extern "C" fixes for sunCC
@ 2012-12-11 21:40 Marc Glisse
  2013-01-02 13:45 ` Marc Glisse
  2013-01-03 15:44 ` Tom Tromey
  0 siblings, 2 replies; 6+ messages in thread
From: Marc Glisse @ 2012-12-11 21:40 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: TEXT/PLAIN, Size: 836 bytes --]

Hello,

this patch should help if we ever want to use sunCC to initiate a 
bootstrap, though I didn't test with sunCC. Note that using gmp_fprintf 
means we have to include stdio.h before gmp.h. I didn't investigate how, 
but this seems to already be the case :-) The reallocator cast is just a 
hack, but the point here is only to help sunCC, making gcc extern 
"C"-clean is a larger task...

Passes bootstrap+testsuite on x86_64-linux using the system's gcc 
(graphite is enabled, don't know if this particular code is exercised).

2012-12-12  Marc Glisse  <marc.glisse@inria.fr>

 	PR bootstrap/50167
 	PR bootstrap/50177
libcpp/
 	* line-map.c (get_combined_adhoc_loc): Cast to extern "C" type.
gcc/
 	* graphite-interchange.c (pdr_stride_in_loop): Use gmp_fprintf.
 	* graphite-poly.c (debug_gmp_value): Likewise.


-- 
Marc Glisse

[-- Attachment #2: Type: TEXT/PLAIN, Size: 3389 bytes --]

Index: gcc/graphite-poly.c
===================================================================
--- gcc/graphite-poly.c	(revision 194404)
+++ gcc/graphite-poly.c	(working copy)
@@ -48,26 +48,21 @@ along with GCC; see the file COPYING3.
 #include "graphite-poly.h"
 
 #define OPENSCOP_MAX_STRING 256
 
 
 /* Print to STDERR the GMP value VAL.  */
 
 DEBUG_FUNCTION void
 debug_gmp_value (mpz_t val)
 {
-  char *str = mpz_get_str (0, 10, val);
-  void (*gmp_free) (void *, size_t);
-
-  fprintf (stderr, "%s", str);
-  mp_get_memory_functions (NULL, NULL, &gmp_free);
-  (*gmp_free) (str, strlen (str) + 1);
+  gmp_fprintf (stderr, "%Zd", val);
 }
 
 /* Return the maximal loop depth in SCOP.  */
 
 int
 scop_max_loop_depth (scop_p scop)
 {
   int i;
   poly_bb_p pbb;
   int max_nb_loops = 0;
Index: gcc/graphite-interchange.c
===================================================================
--- gcc/graphite-interchange.c	(revision 194404)
+++ gcc/graphite-interchange.c	(working copy)
@@ -233,29 +233,22 @@ pdr_stride_in_loop (mpz_t stride, graphi
   aff = isl_aff_set_coefficient_si (aff, isl_dim_in, offset + offset - 1, 1);
   isl_int_init (islstride);
   isl_set_max (set, aff, &islstride);
   isl_int_get_gmp (islstride, stride);
   isl_int_clear (islstride);
   isl_aff_free (aff);
   isl_set_free (set);
 
   if (dump_file && (dump_flags & TDF_DETAILS))
     {
-      char *str;
-      void (*gmp_free) (void *, size_t);
-
-      fprintf (dump_file, "\nStride in BB_%d, DR_%d, depth %d:",
-	       pbb_index (pbb), PDR_ID (pdr), (int) depth);
-      str = mpz_get_str (0, 10, stride);
-      fprintf (dump_file, "  %s ", str);
-      mp_get_memory_functions (NULL, NULL, &gmp_free);
-      (*gmp_free) (str, strlen (str) + 1);
+      gmp_fprintf (dump_file, "\nStride in BB_%d, DR_%d, depth %d:  %Zd ",
+		   pbb_index (pbb), PDR_ID (pdr), (int) depth, stride);
     }
 }
 
 /* Sets STRIDES to the sum of all the strides of the data references
    accessed in LOOP at DEPTH.  */
 
 static void
 memory_strides_in_loop_1 (lst_p loop, graphite_dim_t depth, mpz_t strides)
 {
   int i, j;
Index: libcpp/line-map.c
===================================================================
--- libcpp/line-map.c	(revision 194404)
+++ libcpp/line-map.c	(working copy)
@@ -116,21 +116,22 @@ get_combined_adhoc_loc (struct line_maps
   slot = (struct location_adhoc_data **)
       htab_find_slot (set->location_adhoc_data_map.htab, &lb, INSERT);
   if (*slot == NULL)
     {
       if (set->location_adhoc_data_map.curr_loc >=
 	  set->location_adhoc_data_map.allocated)
 	{
 	  char *orig_data = (char *) set->location_adhoc_data_map.data;
 	  long long offset;
 	  line_map_realloc reallocator
-	      = set->reallocator ? set->reallocator : xrealloc;
+	      = set->reallocator ? set->reallocator
+				 : (line_map_realloc) xrealloc;
 
 	  if (set->location_adhoc_data_map.allocated == 0)
 	    set->location_adhoc_data_map.allocated = 128;
 	  else
 	    set->location_adhoc_data_map.allocated *= 2;
 	  set->location_adhoc_data_map.data = (struct location_adhoc_data *)
 	      reallocator (set->location_adhoc_data_map.data,
 			   set->location_adhoc_data_map.allocated
 			   * sizeof (struct location_adhoc_data));
 	  offset = (char *) (set->location_adhoc_data_map.data) - orig_data;

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: extern "C" fixes for sunCC
  2012-12-11 21:40 extern "C" fixes for sunCC Marc Glisse
@ 2013-01-02 13:45 ` Marc Glisse
  2013-01-02 14:09   ` Richard Biener
  2013-01-03 15:44 ` Tom Tromey
  1 sibling, 1 reply; 6+ messages in thread
From: Marc Glisse @ 2013-01-02 13:45 UTC (permalink / raw)
  To: gcc-patches

Ping
http://gcc.gnu.org/ml/gcc-patches/2012-12/msg00746.html
(I'll re-test since there have been changes around gmp.h inclusion)

On Tue, 11 Dec 2012, Marc Glisse wrote:

> Hello,
>
> this patch should help if we ever want to use sunCC to initiate a bootstrap, 
> though I didn't test with sunCC. Note that using gmp_fprintf means we have to 
> include stdio.h before gmp.h. I didn't investigate how, but this seems to 
> already be the case :-) The reallocator cast is just a hack, but the point 
> here is only to help sunCC, making gcc extern "C"-clean is a larger task...
>
> Passes bootstrap+testsuite on x86_64-linux using the system's gcc (graphite 
> is enabled, don't know if this particular code is exercised).
>
> 2012-12-12  Marc Glisse  <marc.glisse@inria.fr>
>
> 	PR bootstrap/50167
> 	PR bootstrap/50177
> libcpp/
> 	* line-map.c (get_combined_adhoc_loc): Cast to extern "C" type.
> gcc/
> 	* graphite-interchange.c (pdr_stride_in_loop): Use gmp_fprintf.
> 	* graphite-poly.c (debug_gmp_value): Likewise.

-- 
Marc Glisse

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: extern "C" fixes for sunCC
  2013-01-02 13:45 ` Marc Glisse
@ 2013-01-02 14:09   ` Richard Biener
  0 siblings, 0 replies; 6+ messages in thread
From: Richard Biener @ 2013-01-02 14:09 UTC (permalink / raw)
  To: Marc Glisse; +Cc: gcc-patches

On Wed, Jan 2, 2013 at 2:45 PM, Marc Glisse <marc.glisse@inria.fr> wrote:
> Ping
> http://gcc.gnu.org/ml/gcc-patches/2012-12/msg00746.html
> (I'll re-test since there have been changes around gmp.h inclusion)

The graphite changes are ok.

Thanks,
Richard.

>
> On Tue, 11 Dec 2012, Marc Glisse wrote:
>
>> Hello,
>>
>> this patch should help if we ever want to use sunCC to initiate a
>> bootstrap, though I didn't test with sunCC. Note that using gmp_fprintf
>> means we have to include stdio.h before gmp.h. I didn't investigate how, but
>> this seems to already be the case :-) The reallocator cast is just a hack,
>> but the point here is only to help sunCC, making gcc extern "C"-clean is a
>> larger task...
>>
>> Passes bootstrap+testsuite on x86_64-linux using the system's gcc
>> (graphite is enabled, don't know if this particular code is exercised).
>>
>> 2012-12-12  Marc Glisse  <marc.glisse@inria.fr>
>>
>>         PR bootstrap/50167
>>         PR bootstrap/50177
>> libcpp/
>>         * line-map.c (get_combined_adhoc_loc): Cast to extern "C" type.
>> gcc/
>>         * graphite-interchange.c (pdr_stride_in_loop): Use gmp_fprintf.
>>         * graphite-poly.c (debug_gmp_value): Likewise.
>
>
> --
> Marc Glisse

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: extern "C" fixes for sunCC
  2012-12-11 21:40 extern "C" fixes for sunCC Marc Glisse
  2013-01-02 13:45 ` Marc Glisse
@ 2013-01-03 15:44 ` Tom Tromey
  2013-01-03 16:12   ` Marc Glisse
  1 sibling, 1 reply; 6+ messages in thread
From: Tom Tromey @ 2013-01-03 15:44 UTC (permalink / raw)
  To: Marc Glisse; +Cc: gcc-patches

>>>>> "Marc" == Marc Glisse <marc.glisse@inria.fr> writes:

Marc> libcpp/
Marc> 	* line-map.c (get_combined_adhoc_loc): Cast to extern "C" type.

Yucky.

Marc>  	  line_map_realloc reallocator
Marc> -	      = set->reallocator ? set->reallocator : xrealloc;
Marc> +	      = set->reallocator ? set->reallocator
Marc> +				 : (line_map_realloc) xrealloc;

The indentation is wrong here, and it needs extra parens, per the GNU
coding standards.

I think it should have a comment as well.

Tom

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: extern "C" fixes for sunCC
  2013-01-03 15:44 ` Tom Tromey
@ 2013-01-03 16:12   ` Marc Glisse
  2013-01-03 17:28     ` Tom Tromey
  0 siblings, 1 reply; 6+ messages in thread
From: Marc Glisse @ 2013-01-03 16:12 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gcc-patches

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1110 bytes --]

On Thu, 3 Jan 2013, Tom Tromey wrote:

>>>>>> "Marc" == Marc Glisse <marc.glisse@inria.fr> writes:
>
> Marc> libcpp/
> Marc> 	* line-map.c (get_combined_adhoc_loc): Cast to extern "C" type.
>
> Yucky.

Yes, there is a discussion of what is necessary for a real fix (and an 
alternate hack) in the PR:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50177

Do you prefer an other approach?

> Marc>  	  line_map_realloc reallocator
> Marc> -	      = set->reallocator ? set->reallocator : xrealloc;
> Marc> +	      = set->reallocator ? set->reallocator
> Marc> +				 : (line_map_realloc) xrealloc;
>
> The indentation is wrong here, and it needs extra parens, per the GNU
> coding standards.
>
> I think it should have a comment as well.

Like this? (I'll test if approved, but I am not sure what was wrong with 
the indentation and parentheses so it may be wrong again)

Reformatting the patch, I noticed that I only fixed one of the 3 
occurences, so here are all 3.

 	* line-map.c (get_combined_adhoc_loc): Cast from extern "C" type.
 	(new_linemap): Likewise.
 	(linemap_enter_macro): Likewise.

-- 
Marc Glisse

[-- Attachment #2: Type: TEXT/PLAIN, Size: 3542 bytes --]

Index: line-map.c
===================================================================
--- line-map.c	(revision 194796)
+++ line-map.c	(working copy)
@@ -115,22 +115,24 @@ get_combined_adhoc_loc (struct line_maps
   lb.data = data;
   slot = (struct location_adhoc_data **)
       htab_find_slot (set->location_adhoc_data_map.htab, &lb, INSERT);
   if (*slot == NULL)
     {
       if (set->location_adhoc_data_map.curr_loc >=
 	  set->location_adhoc_data_map.allocated)
 	{
 	  char *orig_data = (char *) set->location_adhoc_data_map.data;
 	  long long offset;
-	  line_map_realloc reallocator
-	      = set->reallocator ? set->reallocator : xrealloc;
+	  /* Cast away extern "C" from the type of xrealloc.  */
+	  line_map_realloc reallocator = set->reallocator
+					 ? set->reallocator
+					 : ((line_map_realloc) xrealloc);
 
 	  if (set->location_adhoc_data_map.allocated == 0)
 	    set->location_adhoc_data_map.allocated = 128;
 	  else
 	    set->location_adhoc_data_map.allocated *= 2;
 	  set->location_adhoc_data_map.data = (struct location_adhoc_data *)
 	      reallocator (set->location_adhoc_data_map.data,
 			   set->location_adhoc_data_map.allocated
 			   * sizeof (struct location_adhoc_data));
 	  offset = (char *) (set->location_adhoc_data_map.data) - orig_data;
@@ -210,22 +212,24 @@ new_linemap (struct line_maps *set,
   /* Depending on this variable, a macro map would be allocated in a
      different memory location than an ordinary map.  */
   bool macro_map_p = (reason == LC_ENTER_MACRO);
   struct line_map *result;
 
   if (LINEMAPS_USED (set, macro_map_p) == LINEMAPS_ALLOCATED (set, macro_map_p))
     {
       /* We ran out of allocated line maps. Let's allocate more.  */
       unsigned alloc_size;
 
-      line_map_realloc reallocator
-	= set->reallocator ? set->reallocator : xrealloc;
+      /* Cast away extern "C" from the type of xrealloc.  */
+      line_map_realloc reallocator = set->reallocator
+				     ? set->reallocator
+				     : ((line_map_realloc) xrealloc);
       line_map_round_alloc_size_func round_alloc_size =
 	set->round_alloc_size;
 
       /* We are going to execute some dance to try to reduce the
 	 overhead of the memory allocator, in case we are using the
 	 ggc-page.c one.
 	 
 	 The actual size of memory we are going to get back from the
 	 allocator is the smallest power of 2 that is greater than the
 	 size we requested.  So let's consider that size then.  */
@@ -423,22 +427,24 @@ linemap_tracks_macro_expansion_locs_p (s
    locations, this function returns NULL.  In that case, callers of
    this function cannot encode {line,column} pairs into locations of
    macro tokens anymore.  */
 
 const struct line_map *
 linemap_enter_macro (struct line_maps *set, struct cpp_hashnode *macro_node,
 		     source_location expansion, unsigned int num_tokens)
 {
   struct line_map *map;
   source_location start_location;
-  line_map_realloc reallocator
-    = set->reallocator ? set->reallocator : xrealloc;
+  /* Cast away extern "C" from the type of xrealloc.  */
+  line_map_realloc reallocator = set->reallocator
+				 ? set->reallocator
+				 : ((line_map_realloc) xrealloc);
 
   start_location = LINEMAPS_MACRO_LOWEST_LOCATION (set) - num_tokens;
 
   if (start_location <= set->highest_line
       || start_location > LINEMAPS_MACRO_LOWEST_LOCATION (set))
     /* We ran out of macro map space.   */
     return NULL;
 
   map = new_linemap (set, LC_ENTER_MACRO);
 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: extern "C" fixes for sunCC
  2013-01-03 16:12   ` Marc Glisse
@ 2013-01-03 17:28     ` Tom Tromey
  0 siblings, 0 replies; 6+ messages in thread
From: Tom Tromey @ 2013-01-03 17:28 UTC (permalink / raw)
  To: Marc Glisse; +Cc: gcc-patches

>>>>> "Marc" == Marc Glisse <marc.glisse@inria.fr> writes:

Marc> Do you prefer an other approach?

No, this is fine, just yucky.

Marc> Like this? (I'll test if approved, but I am not sure what was wrong
Marc> with the indentation and parentheses so it may be wrong again)

From the node 'Formatting' in the GCS:

       Insert extra parentheses so that Emacs will indent the code properly.
    For example, the following indentation looks nice if you do it by hand,

         v = rup->ru_utime.tv_sec*1000 + rup->ru_utime.tv_usec/1000
             + rup->ru_stime.tv_sec*1000 + rup->ru_stime.tv_usec/1000;

    but Emacs would alter it.  Adding a set of parentheses produces
    something that looks equally nice, and which Emacs will preserve:

         v = (rup->ru_utime.tv_sec*1000 + rup->ru_utime.tv_usec/1000
              + rup->ru_stime.tv_sec*1000 + rup->ru_stime.tv_usec/1000);


The comments seem fine.
It is ok with the formatting fixed.

Tom

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-01-03 17:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-11 21:40 extern "C" fixes for sunCC Marc Glisse
2013-01-02 13:45 ` Marc Glisse
2013-01-02 14:09   ` Richard Biener
2013-01-03 15:44 ` Tom Tromey
2013-01-03 16:12   ` Marc Glisse
2013-01-03 17:28     ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).