aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/libgfortran
diff options
context:
space:
mode:
authorRong Xu <xur@google.com>2014-07-21 16:47:22 -0700
committerRong Xu <xur@google.com>2014-07-29 15:31:03 -0700
commit38a8aecfb882072900434499696b5c32a2274515 (patch)
tree2aac97f0ae24b03cd98c1a06e989c031c173f889 /gcc-4.9/libgfortran
parentc231900e5dcc14d8296bd9f62b45997a49d4d5e7 (diff)
downloadtoolchain_gcc-38a8aecfb882072900434499696b5c32a2274515.tar.gz
toolchain_gcc-38a8aecfb882072900434499696b5c32a2274515.tar.bz2
toolchain_gcc-38a8aecfb882072900434499696b5c32a2274515.zip
[4.9] Switch gcc-4.9 to use google/gcc-4_9 branch.
This source drop uses svn version r212828 of google/gcc-4.9 branch. We also cherry-picked r213062, r213063 and r213064 to fix windows build issues. All gcc-4.9 patches before July 3rd are ported to google/gcc-4.9. The following prior commits has not been merged to google branch yet. (They are included in this commit). e7af147f979e657fe2df00808e5b4319b0e088c6, baf87df3cb2683649ba7e9872362a7e721117c23, and c231900e5dcc14d8296bd9f62b45997a49d4d5e7. Change-Id: I4bea3ea470387ff751c2be4cb0d4a12059b9299b
Diffstat (limited to 'gcc-4.9/libgfortran')
-rw-r--r--gcc-4.9/libgfortran/ChangeLog42
-rwxr-xr-xgcc-4.9/libgfortran/configure21
-rw-r--r--gcc-4.9/libgfortran/intrinsics/ctime.c70
-rw-r--r--gcc-4.9/libgfortran/io/list_read.c47
-rw-r--r--gcc-4.9/libgfortran/io/unix.c18
5 files changed, 137 insertions, 61 deletions
diff --git a/gcc-4.9/libgfortran/ChangeLog b/gcc-4.9/libgfortran/ChangeLog
index a70f9bb4a..2d19304d5 100644
--- a/gcc-4.9/libgfortran/ChangeLog
+++ b/gcc-4.9/libgfortran/ChangeLog
@@ -1,3 +1,45 @@
+2014-07-06 Jerry DeLisle <jvdelisle@gcc.gnu.org>
+
+ Backport from trunk.
+ PR libgfortran/61640
+ * io/list_read.c (next_char_internal): Adjust the read length to
+ a single wide character. (eat_spaces): Add missing paren.
+ * io/unix.c (mem_read4): Use the correct mem_alloc function for
+ wide character internal reads.
+
+2014-06-27 Jerry DeLisle <jvdelisle@gcc.gnu.org>
+
+ Backport from trunk.
+ PR libgfortran/61499
+ * io/list_read.c (eat_spaces): Use a 'for' loop instead of
+ 'while' loop to skip the loop if there are no bytes left in the
+ string. Only seek if actual spaces can be skipped.
+
+2014-06-07 Jerry DeLisle <jvdelisle@gcc.gnu>
+
+ Backport from trunk.
+ PR libfortran/61173
+ * io/list_read.c (eat_spaces): If the next character pointed to
+ is a space, don't seek, must be at the end.
+
+2014-05-26 Janne Blomqvist <jb@gcc.gnu.org>
+
+ Backport from mainline
+ PR libfortran/61310
+ * intrinsics/ctime.c (strctime): Rename to gf_ctime, use snprintf
+ instead of strftime.
+ (fdate): Use gf_ctime.
+ (fdate_sub): Likewise.
+ (ctime): Likewise.
+ (ctime_sub): Likewise.
+
+2014-05-16 Janne Blomqvist <jb@gcc.gnu.org>
+
+ Backport from trunk:
+ PR libfortran/61187
+ * io/unix.c (raw_close): Check if s->fd is -1.
+ (fd_to_stream): Check return value of fstat(), handle error.
+
2014-05-10 Jerry DeLisle <jvdelisle@gcc.gnu>
Backport from Trunk.
diff --git a/gcc-4.9/libgfortran/configure b/gcc-4.9/libgfortran/configure
index 23f57c7af..8a1002c84 100755
--- a/gcc-4.9/libgfortran/configure
+++ b/gcc-4.9/libgfortran/configure
@@ -8917,7 +8917,22 @@ fi
# Check whether --with-pic was given.
if test "${with_pic+set}" = set; then :
- withval=$with_pic; pic_mode="$withval"
+ withval=$with_pic; p=${PACKAGE-default}
+ case "$withval" in
+ yes|no) pic_mode="$withval" ;;
+ *)
+ pic_mode=default
+ # Look at the argument we got. We use all the common list separators.
+ lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
+ for pkg in $withval; do
+ IFS="$lt_save_ifs"
+ if test "X$pkg" = "X$p"; then
+ pic_mode=yes
+ fi
+ done
+ IFS="$lt_save_ifs"
+ ;;
+ esac
else
pic_mode=default
fi
@@ -12343,7 +12358,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
-#line 12346 "configure"
+#line 12349 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
@@ -12449,7 +12464,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
-#line 12452 "configure"
+#line 12455 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
diff --git a/gcc-4.9/libgfortran/intrinsics/ctime.c b/gcc-4.9/libgfortran/intrinsics/ctime.c
index db41f02cd..9cda39b0e 100644
--- a/gcc-4.9/libgfortran/intrinsics/ctime.c
+++ b/gcc-4.9/libgfortran/intrinsics/ctime.c
@@ -31,31 +31,53 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#include <string.h>
-/* strftime-like function that fills a C string with %c format which
- is identical to ctime in the default locale. As ctime and ctime_r
- are poorly specified and their usage not recommended, the
- implementation instead uses strftime. */
-
-static size_t
-strctime (char *s, size_t max, const time_t *timep)
+/* Maximum space a ctime-like string might need. A "normal" ctime
+ string is 26 bytes, and in our case 24 bytes as we don't include
+ the trailing newline and null. However, the longest possible year
+ number is -2,147,481,748 (1900 - 2,147,483,648, since tm_year is a
+ 32-bit signed integer) so an extra 7 bytes are needed. */
+#define CTIME_BUFSZ 31
+
+
+/* Thread-safe ctime-like function that fills a Fortran
+ string. ctime_r is a portability headache and marked as obsolescent
+ in POSIX 2008, which recommends strftime in its place. However,
+ strftime(..., "%c",...) doesn't produce ctime-like output on
+ MinGW, so do it manually with snprintf. */
+
+static int
+gf_ctime (char *s, size_t max, const time_t timev)
{
struct tm ltm;
int failed;
+ char buf[CTIME_BUFSZ + 1];
/* Some targets provide a localtime_r based on a draft of the POSIX
standard where the return type is int rather than the
standardized struct tm*. */
- __builtin_choose_expr (__builtin_classify_type (localtime_r (timep, &ltm))
+ __builtin_choose_expr (__builtin_classify_type (localtime_r (&timev, &ltm))
== 5,
- failed = localtime_r (timep, &ltm) == NULL,
- failed = localtime_r (timep, &ltm) != 0);
+ failed = localtime_r (&timev, &ltm) == NULL,
+ failed = localtime_r (&timev, &ltm) != 0);
if (failed)
- return 0;
- return strftime (s, max, "%c", &ltm);
+ goto blank;
+ int n = snprintf (buf, sizeof (buf),
+ "%3.3s %3.3s%3d %.2d:%.2d:%.2d %d",
+ "SunMonTueWedThuFriSat" + ltm.tm_wday * 3,
+ "JanFebMarAprMayJunJulAugSepOctNovDec" + ltm.tm_mon * 3,
+ ltm.tm_mday, ltm.tm_hour, ltm.tm_min, ltm.tm_sec,
+ 1900 + ltm.tm_year);
+ if (n < 0)
+ goto blank;
+ if ((size_t) n <= max)
+ {
+ cf_strcpy (s, max, buf);
+ return n;
+ }
+ blank:
+ memset (s, ' ', max);
+ return 0;
}
-/* In the default locale, the date and time representation fits in 26
- bytes. However, other locales might need more space. */
-#define CSZ 100
extern void fdate (char **, gfc_charlen_type *);
export_proto(fdate);
@@ -64,8 +86,8 @@ void
fdate (char ** date, gfc_charlen_type * date_len)
{
time_t now = time(NULL);
- *date = xmalloc (CSZ);
- *date_len = strctime (*date, CSZ, &now);
+ *date = xmalloc (CTIME_BUFSZ);
+ *date_len = gf_ctime (*date, CTIME_BUFSZ, now);
}
@@ -76,10 +98,7 @@ void
fdate_sub (char * date, gfc_charlen_type date_len)
{
time_t now = time(NULL);
- char *s = xmalloc (date_len + 1);
- size_t n = strctime (s, date_len + 1, &now);
- fstrcpy (date, date_len, s, n);
- free (s);
+ gf_ctime (date, date_len, now);
}
@@ -91,8 +110,8 @@ void
PREFIX(ctime) (char ** date, gfc_charlen_type * date_len, GFC_INTEGER_8 t)
{
time_t now = t;
- *date = xmalloc (CSZ);
- *date_len = strctime (*date, CSZ, &now);
+ *date = xmalloc (CTIME_BUFSZ);
+ *date_len = gf_ctime (*date, CTIME_BUFSZ, now);
}
@@ -103,8 +122,5 @@ void
ctime_sub (GFC_INTEGER_8 * t, char * date, gfc_charlen_type date_len)
{
time_t now = *t;
- char *s = xmalloc (date_len + 1);
- size_t n = strctime (s, date_len + 1, &now);
- fstrcpy (date, date_len, s, n);
- free (s);
+ gf_ctime (date, date_len, now);
}
diff --git a/gcc-4.9/libgfortran/io/list_read.c b/gcc-4.9/libgfortran/io/list_read.c
index 2e739f2da..d871ce9be 100644
--- a/gcc-4.9/libgfortran/io/list_read.c
+++ b/gcc-4.9/libgfortran/io/list_read.c
@@ -200,7 +200,7 @@ next_char (st_parameter_dt *dtp)
{
/* Check for kind=4 internal unit. */
if (dtp->common.unit)
- length = sread (dtp->u.p.current_unit->s, &c, sizeof (gfc_char4_t));
+ length = sread (dtp->u.p.current_unit->s, &c, 1);
else
{
char cc;
@@ -265,46 +265,39 @@ eat_spaces (st_parameter_dt *dtp)
int c;
/* If internal character array IO, peak ahead and seek past spaces.
- This is an optimazation to eliminate numerous calls to
- next character unique to character arrays with large character
- lengths (PR38199). */
- if (is_array_io (dtp))
+ This is an optimization unique to character arrays with large
+ character lengths (PR38199). This code eliminates numerous calls
+ to next_character. */
+ if (is_array_io (dtp) && (dtp->u.p.last_char == EOF - 1))
{
gfc_offset offset = stell (dtp->u.p.current_unit->s);
- gfc_offset limit = dtp->u.p.current_unit->bytes_left;
+ gfc_offset i;
if (dtp->common.unit) /* kind=4 */
{
- gfc_char4_t cc;
- limit *= (sizeof (gfc_char4_t));
- do
+ for (i = 0; i < dtp->u.p.current_unit->bytes_left; i++)
{
- cc = dtp->internal_unit[offset];
- offset += (sizeof (gfc_char4_t));
- dtp->u.p.current_unit->bytes_left--;
+ if (dtp->internal_unit[(offset + i) * sizeof (gfc_char4_t)]
+ != (gfc_char4_t)' ')
+ break;
}
- while (offset < limit && (cc == (gfc_char4_t)' '
- || cc == (gfc_char4_t)'\t'));
- /* Back up, seek ahead, and fall through to complete the
- process so that END conditions are handled correctly. */
- dtp->u.p.current_unit->bytes_left++;
- sseek (dtp->u.p.current_unit->s,
- offset-(sizeof (gfc_char4_t)), SEEK_SET);
}
else
{
- do
+ for (i = 0; i < dtp->u.p.current_unit->bytes_left; i++)
{
- c = dtp->internal_unit[offset++];
- dtp->u.p.current_unit->bytes_left--;
+ if (dtp->internal_unit[offset + i] != ' ')
+ break;
}
- while (offset < limit && (c == ' ' || c == '\t'));
- /* Back up, seek ahead, and fall through to complete the
- process so that END conditions are handled correctly. */
- dtp->u.p.current_unit->bytes_left++;
- sseek (dtp->u.p.current_unit->s, offset-1, SEEK_SET);
+ }
+
+ if (i != 0)
+ {
+ sseek (dtp->u.p.current_unit->s, offset + i, SEEK_SET);
+ dtp->u.p.current_unit->bytes_left -= i;
}
}
+
/* Now skip spaces, EOF and EOL are handled in next_char. */
do
c = next_char (dtp);
diff --git a/gcc-4.9/libgfortran/io/unix.c b/gcc-4.9/libgfortran/io/unix.c
index 34c2d0cad..a2df440e2 100644
--- a/gcc-4.9/libgfortran/io/unix.c
+++ b/gcc-4.9/libgfortran/io/unix.c
@@ -412,7 +412,9 @@ raw_close (unix_stream * s)
{
int retval;
- if (s->fd != STDOUT_FILENO
+ if (s->fd == -1)
+ retval = -1;
+ else if (s->fd != STDOUT_FILENO
&& s->fd != STDERR_FILENO
&& s->fd != STDIN_FILENO)
retval = close (s->fd);
@@ -784,10 +786,10 @@ mem_read4 (stream * s, void * buf, ssize_t nbytes)
void *p;
int nb = nbytes;
- p = mem_alloc_r (s, &nb);
+ p = mem_alloc_r4 (s, &nb);
if (p)
{
- memcpy (buf, p, nb);
+ memcpy (buf, p, nb * 4);
return (ssize_t) nb;
}
else
@@ -1003,7 +1005,15 @@ fd_to_stream (int fd, bool unformatted)
/* Get the current length of the file. */
- fstat (fd, &statbuf);
+ if (fstat (fd, &statbuf) == -1)
+ {
+ s->st_dev = s->st_ino = -1;
+ s->file_length = 0;
+ if (errno == EBADF)
+ s->fd = -1;
+ raw_init (s);
+ return (stream *) s;
+ }
s->st_dev = statbuf.st_dev;
s->st_ino = statbuf.st_ino;