summaryrefslogtreecommitdiff
path: root/libgfortran
diff options
context:
space:
mode:
authorJosé Rui Faustino de Sousa <jrfsousa@gmail.com>2019-11-11 10:18:14 +0000
committerTobias Burnus <burnus@gcc.gnu.org>2019-11-11 11:18:14 +0100
commit3f246567a44ba034c0b48f929c4d4586a4b914ed (patch)
tree1f4588827caf5b8df93c515cc20a1a7c61b3e8d9 /libgfortran
parenta5aeee56d897cb1120bf4d2a61c8f62c45fecb5b (diff)
PR fortran/92142 - CFI_setpointer corrupts descriptor
2019-11-11 José Rui Faustino de Sousa <jrfsousa@gmail.com> libgfortran/ PR fortran/92142 * runtime/ISO_Fortran_binding.c (CFI_setpointer): Don't override descriptor attribute; with -fcheck, check that it is a pointer. gcc/testsuite/ PR fortran/92142 * gcc/testsuite/gfortran.dg/ISO_Fortran_binding_16.c: New. * gcc/testsuite/gfortran.dg/ISO_Fortran_binding_16.f90: New. * gcc/testsuite/gfortran.dg/ISO_Fortran_binding_10.c: Correct upper bounds for case 0. From-SVN: r278048
Diffstat (limited to 'libgfortran')
-rw-r--r--libgfortran/ChangeLog7
-rw-r--r--libgfortran/runtime/ISO_Fortran_binding.c22
2 files changed, 22 insertions, 7 deletions
diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog
index 0684c35b9b3..075c9860c80 100644
--- a/libgfortran/ChangeLog
+++ b/libgfortran/ChangeLog
@@ -1,3 +1,10 @@
+2019-11-11 José Rui Faustino de Sousa <jrfsousa@gmail.com>
+
+ PR fortran/92142
+ * runtime/ISO_Fortran_binding.c (CFI_setpointer): Don't
+ override descriptor attribute; with -fcheck, check that
+ it is a pointer.
+
2019-11-06 Jerry DeLisle <jvdelisle@gcc.ngu.org>
PR fortran/90374
diff --git a/libgfortran/runtime/ISO_Fortran_binding.c b/libgfortran/runtime/ISO_Fortran_binding.c
index c71d8e89453..ae500571098 100644
--- a/libgfortran/runtime/ISO_Fortran_binding.c
+++ b/libgfortran/runtime/ISO_Fortran_binding.c
@@ -795,20 +795,29 @@ int CFI_select_part (CFI_cdesc_t *result, const CFI_cdesc_t *source,
int CFI_setpointer (CFI_cdesc_t *result, CFI_cdesc_t *source,
const CFI_index_t lower_bounds[])
{
- /* Result must not be NULL. */
- if (unlikely (compile_options.bounds_check) && result == NULL)
+ /* Result must not be NULL and must be a Fortran pointer. */
+ if (unlikely (compile_options.bounds_check))
{
- fprintf (stderr, "CFI_setpointer: Result is NULL.\n");
- return CFI_INVALID_DESCRIPTOR;
+ if (result == NULL)
+ {
+ fprintf (stderr, "CFI_setpointer: Result is NULL.\n");
+ return CFI_INVALID_DESCRIPTOR;
+ }
+
+ if (result->attribute != CFI_attribute_pointer)
+ {
+ fprintf (stderr, "CFI_setpointer: Result shall be the address of a "
+ "C descriptor for a Fortran pointer.\n");
+ return CFI_INVALID_ATTRIBUTE;
+ }
}
-
+
/* If source is NULL, the result is a C Descriptor that describes a
* disassociated pointer. */
if (source == NULL)
{
result->base_addr = NULL;
result->version = CFI_VERSION;
- result->attribute = CFI_attribute_pointer;
}
else
{
@@ -852,7 +861,6 @@ int CFI_setpointer (CFI_cdesc_t *result, CFI_cdesc_t *source,
/* Assign components to result. */
result->version = source->version;
- result->attribute = source->attribute;
/* Dimension information. */
for (int i = 0; i < source->rank; i++)