From patchwork Thu Jan 14 19:44:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lu, Hongjiu" X-Patchwork-Id: 10385 Received: (qmail 72236 invoked by alias); 14 Jan 2016 19:44:46 -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 72221 invoked by uid 89); 14 Jan 2016 19:44:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=1.6 required=5.0 tests=AWL, BAYES_50, KAM_LAZY_DOMAIN_SECURITY, NO_DNS_FOR_FROM, RP_MATCHES_RCVD autolearn=no version=3.3.2 spammy=1368, 997, alarm, UD:.fd40ab7 X-HELO: mga01.intel.com X-ExtLoop1: 1 Date: Thu, 14 Jan 2016 11:44:39 -0800 From: "H.J. Lu" To: GNU C Library Subject: [PATCH] Use TIME_T_MAX and TIME_T_MIN in tst-mktime2.c Message-ID: <20160114194439.GA25187@intel.com> Reply-To: "H.J. Lu" MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) 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. Tested on x86-64. OK for trunk? H.J. --- [BZ #19466] * time/tst-mktime2.c (TYPE_SIGNED): New. (TYPE_MINIMUM): Likewise. (TYPE_MAXIMUM): Likewise. (TIME_T_MIN): Likewise. (TIME_T_MAX): Likewise. (do_test): Initialize time_t_max and time_t_min with TIME_T_MAX and TIME_T_MIN. --- time/tst-mktime2.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/time/tst-mktime2.c b/time/tst-mktime2.c index bc7cc58..fd40ab7 100644 --- a/time/tst-mktime2.c +++ b/time/tst-mktime2.c @@ -5,6 +5,29 @@ #include #include +/* 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 + static time_t time_t_max; static time_t time_t_min; @@ -113,12 +136,8 @@ 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; + time_t_max = TIME_T_MAX; + time_t_min = TIME_T_MIN; delta = time_t_max / 997; /* a suitable prime number */ for (i = 0; i < N_STRINGS; i++) {