|
|
2985e0 |
From 40d6590b03a9f92c19b7097b1cae296276d6ce22 Mon Sep 17 00:00:00 2001
|
|
|
2985e0 |
From: Jim MacArthur <jim.macarthur@codethink.co.uk>
|
|
|
2985e0 |
Date: Mon, 28 Sep 2015 16:06:30 +0100
|
|
|
2985e0 |
Subject: [PATCH 02/23] Pad character-to-int conversions with spaces instead of
|
|
|
2985e0 |
zeros.
|
|
|
2985e0 |
|
|
|
2985e0 |
The pad character is 'undefined' or 'processor dependent' depending on which
|
|
|
2985e0 |
standard you read. This makes it 0x20 which matches the Oracle Fortran
|
|
|
2985e0 |
compiler. One of the tests tests this undefined behaviour, so I had to modify
|
|
|
2985e0 |
it.
|
|
|
2985e0 |
|
|
|
2985e0 |
0002-Pad-character-to-int-conversions-with-spaces-instead.patch
|
|
|
2985e0 |
|
|
|
2985e0 |
diff --git a/gcc/fortran/lang.opt b/gcc/fortran/lang.opt
|
|
|
2985e0 |
index 4808c27..93908f8 100644
|
|
|
2985e0 |
--- a/gcc/fortran/lang.opt
|
|
|
2985e0 |
+++ b/gcc/fortran/lang.opt
|
|
|
2985e0 |
@@ -428,6 +428,10 @@ fdec
|
|
|
2985e0 |
Fortran Var(flag_dec)
|
|
|
2985e0 |
Enable all DEC language extensions.
|
|
|
2985e0 |
|
|
|
2985e0 |
+fdec-pad-with-spaces
|
|
|
2985e0 |
+Fortran Var(flag_dec_pad_with_spaces)
|
|
|
2985e0 |
+For character to integer conversions, use spaces for the pad rather than NUL.
|
|
|
2985e0 |
+
|
|
|
2985e0 |
fdec-intrinsic-ints
|
|
|
2985e0 |
Fortran Var(flag_dec_intrinsic_ints)
|
|
|
2985e0 |
Enable kind-specific variants of integer intrinsic functions.
|
|
|
2985e0 |
diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c
|
|
|
2985e0 |
index d12ae5f..09da1d2 100644
|
|
|
2985e0 |
--- a/gcc/fortran/simplify.c
|
|
|
2985e0 |
+++ b/gcc/fortran/simplify.c
|
|
|
2985e0 |
@@ -6623,7 +6623,7 @@ gfc_simplify_transfer (gfc_expr *source, gfc_expr *mold, gfc_expr *size)
|
|
|
2985e0 |
/* Allocate the buffer to store the binary version of the source. */
|
|
|
2985e0 |
buffer_size = MAX (source_size, result_size);
|
|
|
2985e0 |
buffer = (unsigned char*)alloca (buffer_size);
|
|
|
2985e0 |
- memset (buffer, 0, buffer_size);
|
|
|
2985e0 |
+ memset (buffer, (flag_dec_pad_with_spaces ? 0x20 : 0x0), buffer_size);
|
|
|
2985e0 |
|
|
|
2985e0 |
/* Now write source to the buffer. */
|
|
|
2985e0 |
gfc_target_encode_expr (source, buffer, buffer_size);
|
|
|
2985e0 |
diff --git a/gcc/testsuite/gfortran.dg/c_ptr_tests_19.f90 b/gcc/testsuite/gfortran.dg/c_ptr_tests_19.f90
|
|
|
2985e0 |
new file mode 100644
|
|
|
2985e0 |
index 0000000..a50cd68
|
|
|
2985e0 |
--- /dev/null
|
|
|
2985e0 |
+++ b/gcc/testsuite/gfortran.dg/c_ptr_tests_19.f90
|
|
|
2985e0 |
@@ -0,0 +1,62 @@
|
|
|
2985e0 |
+! { dg-do compile }
|
|
|
2985e0 |
+! { dg-options "-fdump-tree-optimized -O -fdec-pad-with-spaces" }
|
|
|
2985e0 |
+!
|
|
|
2985e0 |
+! PR fortran/46974
|
|
|
2985e0 |
+
|
|
|
2985e0 |
+program test
|
|
|
2985e0 |
+ use ISO_C_BINDING
|
|
|
2985e0 |
+ implicit none
|
|
|
2985e0 |
+ type(c_ptr) :: m
|
|
|
2985e0 |
+ integer(c_intptr_t) :: a
|
|
|
2985e0 |
+ integer(transfer(transfer(4_c_intptr_t, c_null_ptr),1_c_intptr_t)) :: b
|
|
|
2985e0 |
+ a = transfer (transfer("ABCE", m), 1_c_intptr_t)
|
|
|
2985e0 |
+ print '(z8)', a
|
|
|
2985e0 |
+ if ( int(z'45434241') /= a &
|
|
|
2985e0 |
+ .and. int(z'41424345') /= a &
|
|
|
2985e0 |
+ .and. int(z'4142434520202020',kind=8) /= a &
|
|
|
2985e0 |
+ .and. int(z'2020202045434241',kind=8) /= a ) &
|
|
|
2985e0 |
+ call i_do_not_exist()
|
|
|
2985e0 |
+end program test
|
|
|
2985e0 |
+
|
|
|
2985e0 |
+! Examples contributed by Steve Kargl and James Van Buskirk
|
|
|
2985e0 |
+
|
|
|
2985e0 |
+subroutine bug1
|
|
|
2985e0 |
+ use ISO_C_BINDING
|
|
|
2985e0 |
+ implicit none
|
|
|
2985e0 |
+ type(c_ptr) :: m
|
|
|
2985e0 |
+ type mytype
|
|
|
2985e0 |
+ integer a, b, c
|
|
|
2985e0 |
+ end type mytype
|
|
|
2985e0 |
+ type(mytype) x
|
|
|
2985e0 |
+ print *, transfer(32512, x) ! Works.
|
|
|
2985e0 |
+ print *, transfer(32512, m) ! Caused ICE.
|
|
|
2985e0 |
+end subroutine bug1
|
|
|
2985e0 |
+
|
|
|
2985e0 |
+subroutine bug6
|
|
|
2985e0 |
+ use ISO_C_BINDING
|
|
|
2985e0 |
+ implicit none
|
|
|
2985e0 |
+ interface
|
|
|
2985e0 |
+ function fun()
|
|
|
2985e0 |
+ use ISO_C_BINDING
|
|
|
2985e0 |
+ implicit none
|
|
|
2985e0 |
+ type(C_FUNPTR) fun
|
|
|
2985e0 |
+ end function fun
|
|
|
2985e0 |
+ end interface
|
|
|
2985e0 |
+ type(C_PTR) array(2)
|
|
|
2985e0 |
+ type(C_FUNPTR) result
|
|
|
2985e0 |
+ integer(C_INTPTR_T), parameter :: const(*) = [32512,32520]
|
|
|
2985e0 |
+
|
|
|
2985e0 |
+ result = fun()
|
|
|
2985e0 |
+ array = transfer([integer(C_INTPTR_T)::32512,32520],array)
|
|
|
2985e0 |
+! write(*,*) transfer(result,const)
|
|
|
2985e0 |
+! write(*,*) transfer(array,const)
|
|
|
2985e0 |
+end subroutine bug6
|
|
|
2985e0 |
+
|
|
|
2985e0 |
+function fun()
|
|
|
2985e0 |
+ use ISO_C_BINDING
|
|
|
2985e0 |
+ implicit none
|
|
|
2985e0 |
+ type(C_FUNPTR) fun
|
|
|
2985e0 |
+ fun = transfer(32512_C_INTPTR_T,fun)
|
|
|
2985e0 |
+end function fun
|
|
|
2985e0 |
+
|
|
|
2985e0 |
+! { dg-final { scan-tree-dump-times "i_do_not_exist" 0 "optimized" } }
|