From patchwork Fri Mar 4 19:09:01 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Janne Blomqvist X-Patchwork-Id: 85433 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id C0044B70F0 for ; Sat, 5 Mar 2011 06:09:44 +1100 (EST) Received: (qmail 7512 invoked by alias); 4 Mar 2011 19:09:40 -0000 Received: (qmail 7495 invoked by uid 22791); 4 Mar 2011 19:09:39 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW X-Spam-Check-By: sourceware.org Received: from mail-iy0-f175.google.com (HELO mail-iy0-f175.google.com) (209.85.210.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 04 Mar 2011 19:09:31 +0000 Received: by iyb26 with SMTP id 26so2480885iyb.20 for ; Fri, 04 Mar 2011 11:09:29 -0800 (PST) MIME-Version: 1.0 Received: by 10.231.204.16 with SMTP id fk16mr705272ibb.49.1299265741535; Fri, 04 Mar 2011 11:09:01 -0800 (PST) Received: by 10.231.160.16 with HTTP; Fri, 4 Mar 2011 11:09:01 -0800 (PST) In-Reply-To: <20110304180627.GK30899@tyan-ft48-01.lab.bos.redhat.com> References: <20110304180627.GK30899@tyan-ft48-01.lab.bos.redhat.com> Date: Fri, 4 Mar 2011 21:09:01 +0200 Message-ID: Subject: Re: [Patch, libfortran, committed] PR 47802 Hack around POSIX draft localtime_r From: Janne Blomqvist To: Jakub Jelinek Cc: Fortran List , GCC Patches Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org On Fri, Mar 4, 2011 at 20:06, Jakub Jelinek wrote: > On Fri, Mar 04, 2011 at 07:54:29PM +0200, Janne Blomqvist wrote: >> This should fix the problem reported on HP-UX 10.2. Committed as obvious: > > Well, it is not so obvious, you shouldn't be ignoring the return value from > strftime, because if it fails, ltm will contain raondom undefined values. > If there are different return values, you should just > __builtin_choose_expr (__builtin_classify_type (localtime_r (timep, <m)) == 5, >                       failed = localtime_r (timep, <m) == NULL, >                       failed = localtime_r (timep, <m) != 0); > if (failed) >  return 0; > or something similar. Fair enough, that does the trick. Patch that I just committed below. Index: intrinsics/ctime.c =================================================================== --- intrinsics/ctime.c (revision 170680) +++ intrinsics/ctime.c (working copy) @@ -40,11 +40,16 @@ strctime (char *s, size_t max, const tim { #ifdef HAVE_STRFTIME struct tm ltm; - /* Note: We can't use the return value of localtime_r, as some - targets provide localtime_r based on a draft of the POSIX + int failed; + /* 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*. */ - localtime_r (timep, <m); + __builtin_choose_expr (__builtin_classify_type (localtime_r (timep, <m)) + == 5, + failed = localtime_r (timep, <m) == NULL, + failed = localtime_r (timep, <m) != 0); + if (failed) + return 0; return strftime (s, max, "%c", <m); #else return 0; Index: ChangeLog =================================================================== --- ChangeLog (revision 170680) +++ ChangeLog (working copy) @@ -1,6 +1,12 @@ 2011-03-04 Janne Blomqvist PR libfortran/47802 + * intrinsics/ctime.c (strctime): Use builtins to check localtime_r + return value. + +2011-03-04 Janne Blomqvist + + PR libfortran/47802 * intrinsics/ctime.c (strctime): Don't use return value of localtime_r.