From patchwork Thu Jan 14 23:19:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 10388 Received: (qmail 92540 invoked by alias); 14 Jan 2016 23:19:36 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 92518 invoked by uid 89); 14 Jan 2016 23:19:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=997, type_signed, alarm, TYPE_SIGNED X-HELO: mail-qk0-f193.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=OG1d2DOlgxGUCFbRtEC7NKkn1VJitS42zAGwE+8utLI=; b=Lp6EuGSF1QUp+osLFUa3uENA3Kc8l7w9KEDIxyOTRVtjAx91a4J3+xrpZBGxtxlluL Say+rcsJBkU2NunEsu0CvhnqJa3pcW4jcq7kGOBwRq91O/Yylwdh+YLAdRovM1wa38No TviA5ZCsCg/Pv/9w2n6vhLPsJ54T+nadpi9pi3kipakmyT1iVdFwuUCV5btSEWl4TNQw CaqWOBHYIHT8dOe4o0PLw6kTQOF9PyV+YJDQFyEKdD/u0gIGL9nKITtcfFMq3Z7cnrEg UUfmkkrQ9pmlesmATD7jb/YJGYY9LfGjcwFDdWZPS5wvYBf2tI5gP5bZGJnh6W7KEb5I CGMg== X-Gm-Message-State: ALoCoQn6Lr2NW/iz9lwNzX734tyPOEdcWI4Wp3b/gVpZU38SF6PgA9Ok4vVb5h+QxJCKCGLtol7ATys50KNi2f/zgDQVpDgt0g== MIME-Version: 1.0 X-Received: by 10.55.214.76 with SMTP id t73mr9065063qki.98.1452813571962; Thu, 14 Jan 2016 15:19:31 -0800 (PST) In-Reply-To: <56980C1F.1090707@cs.ucla.edu> References: <20160114194439.GA25187@intel.com> <56980C1F.1090707@cs.ucla.edu> Date: Thu, 14 Jan 2016 15:19:31 -0800 Message-ID: Subject: Re: [PATCH] Use TIME_T_MAX and TIME_T_MIN in tst-mktime2.c From: "H.J. Lu" To: Paul Eggert Cc: GNU C Library On Thu, Jan 14, 2016 at 12:59 PM, Paul Eggert wrote: > On 01/14/2016 11:44 AM, H.J. Lu wrote: >> >> +#ifndef TIME_T_MIN >> +# define TIME_T_MIN TYPE_MINIMUM (time_t) >> +#endif >> +#ifndef TIME_T_MAX >> +# define TIME_T_MAX TYPE_MAXIMUM (time_t) >> +#endif >> + >> static time_t time_t_max; >> static time_t time_t_min; > > > Please get rid of the lower-case variables, and replace all uses of them > with the new (upper-case) macros. Done. OK for trunk? From 5882b44fe08566fc92a086c1a58752dd729c131c Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Thu, 14 Jan 2016 04:15:03 -0800 Subject: [PATCH] Use TIME_T_MAX and TIME_T_MIN in tst-mktime2.c GCC 5.3 compiles for (time_t_max = 1; 0 < time_t_max; time_t_max *= 2) continue; into an infinite loop with -Os. We can copy TIME_T_MAX and TIME_T_MIN from time/mktime.c. [BZ #19466] * time/tst-mktime2.c (time_t_max): Removed. (time_t_min): Likewise. (TYPE_SIGNED): New. (TYPE_MINIMUM): Likewise. (TYPE_MAXIMUM): Likewise. (TIME_T_MIN): Likewise. (TIME_T_MAX): Likewise. (mktime_test): Replace time_t_max and time_t_min with TIME_T_MAX and TIME_T_MIN. (do_test): Likewise. --- time/tst-mktime2.c | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/time/tst-mktime2.c b/time/tst-mktime2.c index bc7cc58..c41db3e 100644 --- a/time/tst-mktime2.c +++ b/time/tst-mktime2.c @@ -5,8 +5,28 @@ #include #include -static time_t time_t_max; -static time_t time_t_min; +/* True if the arithmetic type T is signed. */ +#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1)) + +/* The maximum and minimum values for the integer type T. These + macros have undefined behavior if T is signed and has padding bits. + If this is a problem for you, please let us know how to fix it for + your host. */ +#define TYPE_MINIMUM(t) \ + ((t) (! TYPE_SIGNED (t) \ + ? (t) 0 \ + : ~ TYPE_MAXIMUM (t))) +#define TYPE_MAXIMUM(t) \ + ((t) (! TYPE_SIGNED (t) \ + ? (t) -1 \ + : ((((t) 1 << (sizeof (t) * CHAR_BIT - 2)) - 1) * 2 + 1))) + +#ifndef TIME_T_MIN +# define TIME_T_MIN TYPE_MINIMUM (time_t) +#endif +#ifndef TIME_T_MAX +# define TIME_T_MAX TYPE_MAXIMUM (time_t) +#endif /* Values we'll use to set the TZ environment variable. */ static const char *tz_strings[] = @@ -53,8 +73,8 @@ static void mktime_test (time_t now) { mktime_test1 (now); - mktime_test1 ((time_t) (time_t_max - now)); - mktime_test1 ((time_t) (time_t_min + now)); + mktime_test1 ((time_t) (TIME_T_MAX - now)); + mktime_test1 ((time_t) (TIME_T_MIN + now)); } static void @@ -113,19 +133,13 @@ do_test (void) isn't worth using anyway. */ alarm (60); - for (time_t_max = 1; 0 < time_t_max; time_t_max *= 2) - continue; - time_t_max--; - if ((time_t) -1 < 0) - for (time_t_min = -1; (time_t) (time_t_min * 2) < 0; time_t_min *= 2) - continue; - delta = time_t_max / 997; /* a suitable prime number */ + delta = TIME_T_MAX / 997; /* a suitable prime number */ for (i = 0; i < N_STRINGS; i++) { if (tz_strings[i]) setenv ("TZ", tz_strings[i], 1); - for (t = 0; t <= time_t_max - delta; t += delta) + for (t = 0; t <= TIME_T_MAX - delta; t += delta) mktime_test (t); mktime_test ((time_t) 1); mktime_test ((time_t) (60 * 60)); -- 2.5.0