public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Adhemerval Zanella <azanella@sourceware.org>
To: glibc-cvs@sourceware.org
Subject: [glibc/azanella/clang] Suppress clang -Wtautological-constant-out-of-range-compare on strtod_l.c
Date: Tue,  4 Oct 2022 12:59:51 +0000 (GMT)	[thread overview]
Message-ID: <20221004125951.930063858297@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=6e6fe047aba5da8ec7a7298ad8a89337e849ccb4

commit 6e6fe047aba5da8ec7a7298ad8a89337e849ccb4
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Tue Jul 26 08:38:48 2022 -0300

    Suppress clang -Wtautological-constant-out-of-range-compare on strtod_l.c
    
    Clang emits:
    
      strtod_l.c:874:18: error: result of comparison of constant
      9223372036854775807 with expression of type 'size_t' (aka 'unsigned
                        int') is always true
      [-Werror,-Wtautological-constant-out-of-range-compare]
        assert (dig_no <= (uintmax_t) INTMAX_MAX);
        ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
      ../assert/assert.h:106:11: note: expanded from macro 'assert'
            if (expr)
      \
                ^~~~

Diff:
---
 stdlib/strtod_l.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/stdlib/strtod_l.c b/stdlib/strtod_l.c
index 3ebb491e22..ab04c52e8c 100644
--- a/stdlib/strtod_l.c
+++ b/stdlib/strtod_l.c
@@ -85,6 +85,7 @@ extern double ____strtod_l_internal (const char *, char **, int, locale_t);
 #include "fpioconst.h"
 
 #include <assert.h>
+#include <libc-diag.h>
 
 
 /* We use this code for the extended locale handling where the
@@ -871,7 +872,11 @@ ____STRTOF_INTERNAL (const STRING_TYPE *nptr, STRING_TYPE **endptr, int group,
 	  c = *++cp;
 	}
     }
+
+  DIAG_PUSH_NEEDS_COMMENT_CLANG;
+  DIAG_IGNORE_NEEDS_COMMENT_CLANG (13.0, "-Wtautological-constant-out-of-range-compare");
   assert (dig_no <= (uintmax_t) INTMAX_MAX);
+  DIAG_POP_NEEDS_COMMENT_CLANG;
 
   /* Remember start of exponent (if any).  */
   expp = cp;
@@ -901,16 +906,22 @@ ____STRTOF_INTERNAL (const STRING_TYPE *nptr, STRING_TYPE **endptr, int group,
 	    {
 	      if (exp_negative)
 		{
+		  DIAG_PUSH_NEEDS_COMMENT_CLANG;
+		  DIAG_IGNORE_NEEDS_COMMENT_CLANG (13.0, "-Wtautological-constant-out-of-range-compare");
 		  assert (int_no <= (uintmax_t) (INTMAX_MAX
 						 + MIN_EXP - MANT_DIG) / 4);
+		  DIAG_POP_NEEDS_COMMENT_CLANG;
 		  exp_limit = -MIN_EXP + MANT_DIG + 4 * (intmax_t) int_no;
 		}
 	      else
 		{
 		  if (int_no)
 		    {
+		      DIAG_PUSH_NEEDS_COMMENT_CLANG;
+		      DIAG_IGNORE_NEEDS_COMMENT_CLANG (13.0, "-Wtautological-constant-out-of-range-compare");
 		      assert (lead_zero == 0
 			      && int_no <= (uintmax_t) INTMAX_MAX / 4);
+		      DIAG_POP_NEEDS_COMMENT_CLANG;
 		      exp_limit = MAX_EXP - 4 * (intmax_t) int_no + 3;
 		    }
 		  else if (lead_zero == (size_t) -1)
@@ -921,8 +932,11 @@ ____STRTOF_INTERNAL (const STRING_TYPE *nptr, STRING_TYPE **endptr, int group,
 		    }
 		  else
 		    {
+		      DIAG_PUSH_NEEDS_COMMENT_CLANG;
+		      DIAG_IGNORE_NEEDS_COMMENT_CLANG (13.0, "-Wtautological-constant-out-of-range-compare");
 		      assert (lead_zero
 			      <= (uintmax_t) (INTMAX_MAX - MAX_EXP - 3) / 4);
+		      DIAG_POP_NEEDS_COMMENT_CLANG;
 		      exp_limit = (MAX_EXP
 				   + 4 * (intmax_t) lead_zero
 				   + 3);
@@ -933,16 +947,22 @@ ____STRTOF_INTERNAL (const STRING_TYPE *nptr, STRING_TYPE **endptr, int group,
 	    {
 	      if (exp_negative)
 		{
+		  DIAG_PUSH_NEEDS_COMMENT_CLANG;
+		  DIAG_IGNORE_NEEDS_COMMENT_CLANG (13.0, "-Wtautological-constant-out-of-range-compare");
 		  assert (int_no
 			  <= (uintmax_t) (INTMAX_MAX + MIN_10_EXP - MANT_DIG));
+		  DIAG_POP_NEEDS_COMMENT_CLANG;
 		  exp_limit = -MIN_10_EXP + MANT_DIG + (intmax_t) int_no;
 		}
 	      else
 		{
 		  if (int_no)
 		    {
+		      DIAG_PUSH_NEEDS_COMMENT_CLANG;
+		      DIAG_IGNORE_NEEDS_COMMENT_CLANG (13.0, "-Wtautological-constant-out-of-range-compare");
 		      assert (lead_zero == 0
 			      && int_no <= (uintmax_t) INTMAX_MAX);
+		      DIAG_POP_NEEDS_COMMENT_CLANG;
 		      exp_limit = MAX_10_EXP - (intmax_t) int_no + 1;
 		    }
 		  else if (lead_zero == (size_t) -1)
@@ -953,8 +973,11 @@ ____STRTOF_INTERNAL (const STRING_TYPE *nptr, STRING_TYPE **endptr, int group,
 		    }
 		  else
 		    {
+		      DIAG_PUSH_NEEDS_COMMENT_CLANG;
+		      DIAG_IGNORE_NEEDS_COMMENT_CLANG (13.0, "-Wtautological-constant-out-of-range-compare");
 		      assert (lead_zero
 			      <= (uintmax_t) (INTMAX_MAX - MAX_10_EXP - 1));
+		      DIAG_POP_NEEDS_COMMENT_CLANG;
 		      exp_limit = MAX_10_EXP + (intmax_t) lead_zero + 1;
 		    }
 		}

             reply	other threads:[~2022-10-04 12:59 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-04 12:59 Adhemerval Zanella [this message]
2022-10-28 17:42 Adhemerval Zanella
2023-02-09 19:48 Adhemerval Zanella
2023-08-30 12:36 Adhemerval Zanella

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221004125951.930063858297@sourceware.org \
    --to=azanella@sourceware.org \
    --cc=glibc-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).