* patch, libfortran] [patch, fortran] Fix PR 79956, part two, attempt 3
@ 2017-03-14 23:01 Thomas Koenig
2017-03-15 3:34 ` Jerry DeLisle
2017-03-17 16:48 ` Markus Trippelsdorf
0 siblings, 2 replies; 4+ messages in thread
From: Thomas Koenig @ 2017-03-14 23:01 UTC (permalink / raw)
To: fortran, gcc-patches, markus
[-- Attachment #1: Type: text/plain, Size: 1264 bytes --]
Hello world,
well, here is the third attempt at fixing the second part of the PR.
Glancing over the source, I think there are quite a few places where
we currently issue a runtime error which we could replace by an
assert, but that's something for 8.0.
Regression-tested on x86_64-pc-linux-gnu.
OK for trunk?
Thomas
(I won't be able to commit for a few days, so if somebody
wants to commit for me, feel free).
2017-03-12 Thomas Koenig <tkoenig@gcc.gnu.org>
PR libfortran/79956
* libgfortran.h (GFC_ASSERT): New macro.
* m4/reshape.m4 (reshape_'rtype_ccode`): Use GFC_ASSERT
to specify that sdim > 0 and rdim > 0.
* intrinsic/reshape_generic.c (reshape_internal): Likweise.
* generated/reshape_c10.c: Regenerated.
* generated/reshape_c16.c: Regenerated.
* generated/reshape_c4.c: Regenerated.
* generated/reshape_c8.c: Regenerated.
* generated/reshape_i16.c: Regenerated.
* generated/reshape_i4.c: Regenerated.
* generated/reshape_i8.c: Regenerated.
* generated/reshape_r10.c: Regenerated.
* generated/reshape_r16.c: Regenerated.
* generated/reshape_r4.c: Regenerated.
* generated/reshape_r8.c: Regenerated.
[-- Attachment #2: p6.diff --]
[-- Type: text/x-patch, Size: 7708 bytes --]
Index: generated/reshape_c10.c
===================================================================
--- generated/reshape_c10.c (Revision 245760)
+++ generated/reshape_c10.c (Arbeitskopie)
@@ -232,6 +232,11 @@ reshape_c10 (gfc_array_c10 * const restrict ret,
}
sdim = GFC_DESCRIPTOR_RANK (source);
+
+ /* sdim is always > 0; this lets the compiler optimize more and
+ avoids a warning. */
+ GFC_ASSERT(sdim>0);
+
ssize = 1;
sempty = 0;
for (n = 0; n < sdim; n++)
Index: generated/reshape_c16.c
===================================================================
--- generated/reshape_c16.c (Revision 245760)
+++ generated/reshape_c16.c (Arbeitskopie)
@@ -232,6 +232,11 @@ reshape_c16 (gfc_array_c16 * const restrict ret,
}
sdim = GFC_DESCRIPTOR_RANK (source);
+
+ /* sdim is always > 0; this lets the compiler optimize more and
+ avoids a warning. */
+ GFC_ASSERT(sdim>0);
+
ssize = 1;
sempty = 0;
for (n = 0; n < sdim; n++)
Index: generated/reshape_c4.c
===================================================================
--- generated/reshape_c4.c (Revision 245760)
+++ generated/reshape_c4.c (Arbeitskopie)
@@ -232,6 +232,11 @@ reshape_c4 (gfc_array_c4 * const restrict ret,
}
sdim = GFC_DESCRIPTOR_RANK (source);
+
+ /* sdim is always > 0; this lets the compiler optimize more and
+ avoids a warning. */
+ GFC_ASSERT(sdim>0);
+
ssize = 1;
sempty = 0;
for (n = 0; n < sdim; n++)
Index: generated/reshape_c8.c
===================================================================
--- generated/reshape_c8.c (Revision 245760)
+++ generated/reshape_c8.c (Arbeitskopie)
@@ -232,6 +232,11 @@ reshape_c8 (gfc_array_c8 * const restrict ret,
}
sdim = GFC_DESCRIPTOR_RANK (source);
+
+ /* sdim is always > 0; this lets the compiler optimize more and
+ avoids a warning. */
+ GFC_ASSERT(sdim>0);
+
ssize = 1;
sempty = 0;
for (n = 0; n < sdim; n++)
Index: generated/reshape_i16.c
===================================================================
--- generated/reshape_i16.c (Revision 245760)
+++ generated/reshape_i16.c (Arbeitskopie)
@@ -232,6 +232,11 @@ reshape_16 (gfc_array_i16 * const restrict ret,
}
sdim = GFC_DESCRIPTOR_RANK (source);
+
+ /* sdim is always > 0; this lets the compiler optimize more and
+ avoids a warning. */
+ GFC_ASSERT(sdim>0);
+
ssize = 1;
sempty = 0;
for (n = 0; n < sdim; n++)
Index: generated/reshape_i4.c
===================================================================
--- generated/reshape_i4.c (Revision 245760)
+++ generated/reshape_i4.c (Arbeitskopie)
@@ -232,6 +232,11 @@ reshape_4 (gfc_array_i4 * const restrict ret,
}
sdim = GFC_DESCRIPTOR_RANK (source);
+
+ /* sdim is always > 0; this lets the compiler optimize more and
+ avoids a warning. */
+ GFC_ASSERT(sdim>0);
+
ssize = 1;
sempty = 0;
for (n = 0; n < sdim; n++)
Index: generated/reshape_i8.c
===================================================================
--- generated/reshape_i8.c (Revision 245760)
+++ generated/reshape_i8.c (Arbeitskopie)
@@ -232,6 +232,11 @@ reshape_8 (gfc_array_i8 * const restrict ret,
}
sdim = GFC_DESCRIPTOR_RANK (source);
+
+ /* sdim is always > 0; this lets the compiler optimize more and
+ avoids a warning. */
+ GFC_ASSERT(sdim>0);
+
ssize = 1;
sempty = 0;
for (n = 0; n < sdim; n++)
Index: generated/reshape_r10.c
===================================================================
--- generated/reshape_r10.c (Revision 245760)
+++ generated/reshape_r10.c (Arbeitskopie)
@@ -232,6 +232,11 @@ reshape_r10 (gfc_array_r10 * const restrict ret,
}
sdim = GFC_DESCRIPTOR_RANK (source);
+
+ /* sdim is always > 0; this lets the compiler optimize more and
+ avoids a warning. */
+ GFC_ASSERT(sdim>0);
+
ssize = 1;
sempty = 0;
for (n = 0; n < sdim; n++)
Index: generated/reshape_r16.c
===================================================================
--- generated/reshape_r16.c (Revision 245760)
+++ generated/reshape_r16.c (Arbeitskopie)
@@ -232,6 +232,11 @@ reshape_r16 (gfc_array_r16 * const restrict ret,
}
sdim = GFC_DESCRIPTOR_RANK (source);
+
+ /* sdim is always > 0; this lets the compiler optimize more and
+ avoids a warning. */
+ GFC_ASSERT(sdim>0);
+
ssize = 1;
sempty = 0;
for (n = 0; n < sdim; n++)
Index: generated/reshape_r4.c
===================================================================
--- generated/reshape_r4.c (Revision 245760)
+++ generated/reshape_r4.c (Arbeitskopie)
@@ -232,6 +232,11 @@ reshape_r4 (gfc_array_r4 * const restrict ret,
}
sdim = GFC_DESCRIPTOR_RANK (source);
+
+ /* sdim is always > 0; this lets the compiler optimize more and
+ avoids a warning. */
+ GFC_ASSERT(sdim>0);
+
ssize = 1;
sempty = 0;
for (n = 0; n < sdim; n++)
Index: generated/reshape_r8.c
===================================================================
--- generated/reshape_r8.c (Revision 245760)
+++ generated/reshape_r8.c (Arbeitskopie)
@@ -232,6 +232,11 @@ reshape_r8 (gfc_array_r8 * const restrict ret,
}
sdim = GFC_DESCRIPTOR_RANK (source);
+
+ /* sdim is always > 0; this lets the compiler optimize more and
+ avoids a warning. */
+ GFC_ASSERT(sdim>0);
+
ssize = 1;
sempty = 0;
for (n = 0; n < sdim; n++)
Index: intrinsics/reshape_generic.c
===================================================================
--- intrinsics/reshape_generic.c (Revision 245760)
+++ intrinsics/reshape_generic.c (Arbeitskopie)
@@ -66,6 +66,10 @@ reshape_internal (parray *ret, parray *source, sha
index_type shape_data[GFC_MAX_DIMENSIONS];
rdim = GFC_DESCRIPTOR_EXTENT(shape,0);
+ /* rdim is always > 0; this lets the compiler optimize more and
+ avoids a warning. */
+ GFC_ASSERT (rdim > 0);
+
if (rdim != GFC_DESCRIPTOR_RANK(ret))
runtime_error("rank of return array incorrect in RESHAPE intrinsic");
@@ -158,6 +162,10 @@ reshape_internal (parray *ret, parray *source, sha
source_extent = 1;
sdim = GFC_DESCRIPTOR_RANK (source);
+ /* sdim is always > 0; this lets the compiler optimize more and
+ avoids a warning. */
+ GFC_ASSERT(sdim>0);
+
for (n = 0; n < sdim; n++)
{
index_type se;
@@ -219,6 +227,10 @@ reshape_internal (parray *ret, parray *source, sha
}
sdim = GFC_DESCRIPTOR_RANK (source);
+ /* sdim is always > 0; this lets the compiler optimize more and
+ avoids a warning. */
+ GFC_ASSERT(sdim>0);
+
ssize = 1;
sempty = 0;
for (n = 0; n < sdim; n++)
Index: libgfortran.h
===================================================================
--- libgfortran.h (Revision 245760)
+++ libgfortran.h (Arbeitskopie)
@@ -111,7 +111,12 @@ typedef off_t gfc_offset;
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
+/* This macro can be used to annotate conditions which we know to
+ be true, so that the compiler can optimize based on the condition. */
+#define GFC_ASSERT(EXPR) \
+ ((void)(__builtin_expect (!(EXPR), 0) ? __builtin_unreachable (), 0 : 0))
+
/* Make sure we have ptrdiff_t. */
#ifndef HAVE_PTRDIFF_T
typedef intptr_t ptrdiff_t;
Index: m4/reshape.m4
===================================================================
--- m4/reshape.m4 (Revision 245760)
+++ m4/reshape.m4 (Arbeitskopie)
@@ -236,6 +236,11 @@ reshape_'rtype_ccode` ('rtype` * const restrict re
}
sdim = GFC_DESCRIPTOR_RANK (source);
+
+ /* sdim is always > 0; this lets the compiler optimize more and
+ avoids a warning. */
+ GFC_ASSERT(sdim>0);
+
ssize = 1;
sempty = 0;
for (n = 0; n < sdim; n++)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: patch, libfortran] [patch, fortran] Fix PR 79956, part two, attempt 3
2017-03-14 23:01 patch, libfortran] [patch, fortran] Fix PR 79956, part two, attempt 3 Thomas Koenig
@ 2017-03-15 3:34 ` Jerry DeLisle
2017-03-17 16:48 ` Markus Trippelsdorf
1 sibling, 0 replies; 4+ messages in thread
From: Jerry DeLisle @ 2017-03-15 3:34 UTC (permalink / raw)
To: Thomas Koenig, fortran, gcc-patches, markus
On 03/14/2017 04:01 PM, Thomas Koenig wrote:
> Hello world,
>
> well, here is the third attempt at fixing the second part of the PR.
> Glancing over the source, I think there are quite a few places where
> we currently issue a runtime error which we could replace by an
> assert, but that's something for 8.0.
>
> Regression-tested on x86_64-pc-linux-gnu.
>
> OK for trunk?
Yes, OK.
Jerry
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: patch, libfortran] [patch, fortran] Fix PR 79956, part two, attempt 3
2017-03-14 23:01 patch, libfortran] [patch, fortran] Fix PR 79956, part two, attempt 3 Thomas Koenig
2017-03-15 3:34 ` Jerry DeLisle
@ 2017-03-17 16:48 ` Markus Trippelsdorf
2017-03-17 21:29 ` Thomas Koenig
1 sibling, 1 reply; 4+ messages in thread
From: Markus Trippelsdorf @ 2017-03-17 16:48 UTC (permalink / raw)
To: Thomas Koenig; +Cc: fortran, gcc-patches
On 2017.03.15 at 00:01 +0100, Thomas Koenig wrote:
> Hello world,
>
> well, here is the third attempt at fixing the second part of the PR.
> Glancing over the source, I think there are quite a few places where
> we currently issue a runtime error which we could replace by an
> assert, but that's something for 8.0.
>
> Regression-tested on x86_64-pc-linux-gnu.
> Index: generated/reshape_c10.c
> ===================================================================
> --- generated/reshape_c10.c (Revision 245760)
> +++ generated/reshape_c10.c (Arbeitskopie)
> @@ -232,6 +232,11 @@ reshape_c10 (gfc_array_c10 * const restrict ret,
> }
>
> sdim = GFC_DESCRIPTOR_RANK (source);
> +
> + /* sdim is always > 0; this lets the compiler optimize more and
> + avoids a warning. */
> + GFC_ASSERT(sdim>0);
> +
You have committed a different patch, which is obviously wrong:
diff --git a/libgfortran/generated/reshape_c10.c b/libgfortran/generated/reshape_c10.c
index 00c64aeb746f..af45e960ee7f 100644
--- a/libgfortran/generated/reshape_c10.c
+++ b/libgfortran/generated/reshape_c10.c
@@ -78,6 +78,10 @@ reshape_c10 (gfc_array_c10 * const restrict ret,
index_type shape_data[GFC_MAX_DIMENSIONS];
rdim = GFC_DESCRIPTOR_EXTENT(shape,0);
+ /* rdim is always > 0; this lets the compiler optimize more and
+ avoids a potential warning. */
+ GFC_ASSERT(sdim>0);
You should use rdim not sdim in the GFC_ASSERT.
--
Markus
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: patch, libfortran] [patch, fortran] Fix PR 79956, part two, attempt 3
2017-03-17 16:48 ` Markus Trippelsdorf
@ 2017-03-17 21:29 ` Thomas Koenig
0 siblings, 0 replies; 4+ messages in thread
From: Thomas Koenig @ 2017-03-17 21:29 UTC (permalink / raw)
To: Markus Trippelsdorf; +Cc: fortran, gcc-patches
Am 17.03.2017 um 17:48 schrieb Markus Trippelsdorf:
> You should use rdim not sdim in the GFC_ASSERT.
Fixed in rev 246248.
Sorry for the breakage.
Thomas
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-03-17 21:29 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-14 23:01 patch, libfortran] [patch, fortran] Fix PR 79956, part two, attempt 3 Thomas Koenig
2017-03-15 3:34 ` Jerry DeLisle
2017-03-17 16:48 ` Markus Trippelsdorf
2017-03-17 21:29 ` Thomas Koenig
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).