re PR fortran/71935 (ICE is_c_interoperable(): gfc_simplify_expr failed)
authorSteven G. Kargl <kargl@gcc.gnu.org>
Fri, 22 Jul 2016 18:53:11 +0000 (18:53 +0000)
committerSteven G. Kargl <kargl@gcc.gnu.org>
Fri, 22 Jul 2016 18:53:11 +0000 (18:53 +0000)
2016-07-22  Steven G. Kargl  <kargl@gcc.gnu.org>

PR fortran/71935
* check.c (is_c_interoperable): Simplify right expression.

2016-07-22  Steven G. Kargl  <kargl@gcc.gnu.org>

PR fortran/71935
* gfortran.dg/c_sizeof_1.f90: Move invalid code to ...
* gfortran.dg/c_sizeof_6.f90: here.  Test for error.
* gfortran.dg/pr71935.f90: New test.

From-SVN: r238665

gcc/fortran/ChangeLog
gcc/fortran/check.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/c_sizeof_1.f90
gcc/testsuite/gfortran.dg/c_sizeof_6.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/pr71935.f90 [new file with mode: 0644]

index ff12b56ec2e350bc137c001cf6e3eb76d2a81d5c..b056e0e86e87a098ea2384ae6a1587d3f609ed07 100644 (file)
@@ -1,3 +1,8 @@
+2016-07-22  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       PR fortran/71935
+       * check.c (is_c_interoperable): Simplify right expression. 
+
 2016-07-22  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        PR fortran/71795
index d26e45ec406d6c595188569aa19748fa36eb9742..7fc608081cc79d7bb20bd83a79ff14fa7a8ad3e2 100644 (file)
@@ -4278,7 +4278,7 @@ is_c_interoperable (gfc_expr *expr, const char **msg, bool c_loc, bool c_f_ptr)
       }
 
     if (expr->ts.u.cl && expr->ts.u.cl->length
-       && !gfc_simplify_expr (expr, 0))
+       && !gfc_simplify_expr (expr->ts.u.cl->length, 0))
       gfc_internal_error ("is_c_interoperable(): gfc_simplify_expr failed");
 
     if (!c_loc && expr->ts.u.cl
index c38c41e492b7d2afe33b550935755823ff53fd3d..2c381514fb2b990130acd5b99f64995bfc0723c2 100644 (file)
@@ -1,3 +1,10 @@
+2016-07-22  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       PR fortran/71935
+       * gfortran.dg/c_sizeof_1.f90: Move invalid code to ...
+       * gfortran.dg/c_sizeof_6.f90: here.  Test for error.
+       * gfortran.dg/pr71935.f90: New test.
+
 2016-07-22 Martin Sebor  <msebor@redhat.com>
 
        PR c++/71675
index 4a8385b8d8fd5a7035192c9ecdb50ced7ac969e0..d601f1ec8ecd6b101162db99aeab61da677acef5 100644 (file)
@@ -22,9 +22,6 @@ if (i /= 4) call abort()
 i = c_sizeof(str2(1))
 if (i /= 1) call abort()
 
-i = c_sizeof(str2(1:3))
-if (i /= 3) call abort()
-
 write(*,*) c_sizeof(cptr), c_sizeof(iptr), c_sizeof(C_NULL_PTR)
 
 ! Using GNU's SIZEOF
diff --git a/gcc/testsuite/gfortran.dg/c_sizeof_6.f90 b/gcc/testsuite/gfortran.dg/c_sizeof_6.f90
new file mode 100644 (file)
index 0000000..0b57964
--- /dev/null
@@ -0,0 +1,16 @@
+! { dg-do compile }
+!
+program foo
+
+   use iso_c_binding, only: c_int, c_char, c_sizeof
+
+   integer(kind=c_int) :: i
+
+   character(kind=c_char,len=1),parameter :: str2(4) = ["a","b","c","d"]
+
+   i = c_sizeof(str2(1:3)) ! { dg-error "must be an interoperable data" }
+
+   if (i /= 3) call abort()
+
+end program foo
+
diff --git a/gcc/testsuite/gfortran.dg/pr71935.f90 b/gcc/testsuite/gfortran.dg/pr71935.f90
new file mode 100644 (file)
index 0000000..495759b
--- /dev/null
@@ -0,0 +1,7 @@
+! { dg-do compile }
+program p
+   use iso_c_binding
+   character(len=1, kind=c_char), parameter :: z(2) = 'z'
+   print *, sizeof(z(3))      ! { dg-warning "is out of bounds" }
+   print *, c_sizeof(z(3))    ! { dg-warning "is out of bounds" }
+end