bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug gas/143] sprint_value prints small constants in hex on 64-bit targe


From: nickc at redhat dot com
Subject: [Bug gas/143] sprint_value prints small constants in hex on 64-bit targets
Date: 5 May 2004 17:23:57 -0000

------- Additional Comments From nickc at redhat dot com  2004-05-05 17:23 
-------
Subject: Re:  New: sprint_value prints small constants in hex
 on     64-bit targets

Hi

>sprint_value() prints small constants (for example, operands that are out of
>range) in hex on targets where sizeof (valueT) > sizeof (long).  This leads to
>confusing errors like:
>
>foo.s:2: Error: operand out of range (0000000000000020 not between 0 and 31)
>  
>
How about this patch to fix the problem ?  It creates a new function 
called as_warn_value_out_of_range() which is responsible for printing a 
reasonable warning message.  It checks the range of the values and uses 
decimals if they are small enough, otherwise it used hexadecimals.  
Either way, it is consistent about the format it uses to print the 
numbers.  The patch also includes a version of the function which 
generates an error instead of a warning, and it also has the benefit of 
eliminating a small amount of duplicated code found in several ports.

Cheers
  Nick

gas/ChangeLog
2004-05-05  Nick Clifton  <address@hidden>

    * messages (as_internal_value_out_of_range): Print a message about
    a value being out of range.  Be consistent about whether the
    values are printed in decimal or hexadecimal.
    (as_warn_value_out_of_range): Generate a warning message about an
    out of range value.
    (as_bad_value_out_of_range): Generate an error message about an
    out of range value.
    * as.h: Prototype the new functions.
    * config/tc-alpha.c (insert_operand): Use new function.
    * config/tc-arc.c (arc_insert_operand): Likewise.
    * config/tc-mn10200.c (mn10200_insert_operand): Likewise.
    * config/tc-mn10300.c (mn10300_insert_operand): Likewise.
    * config/tc-ppc.c (ppc_insert_operand): Likewise.
    * config/tc-s390.c (s390_insert_operand): Likewise.
    * config/tc-v850.c (v850_insert_operand): Likewise.

1
Index: gas/as.h
===================================================================
RCS file: /cvs/src/src/gas/as.h,v
retrieving revision 1.37
diff -c -3 -p -r1.37 as.h
*** gas/as.h    23 Nov 2003 02:14:21 -0000      1.37
--- gas/as.h    5 May 2004 17:13:05 -0000
*************** void sprint_value (char *buf, addressT v
*** 562,567 ****
--- 562,570 ----
  int had_errors (void);
  int had_warnings (void);
  
+ void as_warn_value_out_of_range (char *, offsetT, offsetT, offsetT, char *, 
unsigned);
+ void as_bad_value_out_of_range (char *, offsetT, offsetT, offsetT, char *, 
unsigned);
+ 
  void print_version_id (void);
  char *app_push (void);
  char *atof_ieee (char *str, int what_kind, LITTLENUM_TYPE * words);
Index: gas/messages.c
===================================================================
RCS file: /cvs/src/src/gas/messages.c,v
retrieving revision 1.8
diff -c -3 -p -r1.8 messages.c
*** gas/messages.c      19 Dec 2003 15:23:40 -0000      1.8
--- gas/messages.c      5 May 2004 17:13:05 -0000
*************** sprint_value (char *buf, valueT val)
*** 503,505 ****
--- 503,586 ----
  #endif
    abort ();
  }
+ 
+ #define HEX_MAX_THRESHOLD     1024
+ #define HEX_MIN_THRESHOLD     -(HEX_MAX_THRESHOLD)
+ 
+ static void
+ as_internal_value_out_of_range (char *      prefix,
+                               offsetT     val,
+                               offsetT     min,
+                               offsetT     max,
+                               char *      file,
+                               unsigned    line,
+                               bfd_boolean bad)
+ {
+   const char * err;
+ 
+   if (prefix == NULL)
+     prefix = "";
+ 
+ #ifdef BFD_ASSEMBLER
+   if (   val < HEX_MAX_THRESHOLD
+       && min < HEX_MAX_THRESHOLD
+       && max < HEX_MAX_THRESHOLD
+       && val > HEX_MIN_THRESHOLD
+       && min > HEX_MIN_THRESHOLD
+       && max > HEX_MIN_THRESHOLD)
+ #endif
+     {
+       /* xgettext:c-format  */
+       err = _("%s out of range (%d is not between %d and %d)");
+ 
+       if (bad)
+       as_bad_where (file, line, err, prefix, val, min, max);
+       else
+       as_warn_where (file, line, err, prefix, val, min, max);
+     }
+ #ifdef BFD_ASSEMBLER
+   else
+     {
+       char val_buf [sizeof (val) * 3 + 2];
+       char min_buf [sizeof (val) * 3 + 2];
+       char max_buf [sizeof (val) * 3 + 2];
+ 
+       if (sizeof (val) > sizeof (bfd_vma))
+       abort ();
+ 
+       sprintf_vma (val_buf, val);
+       sprintf_vma (min_buf, min);
+       sprintf_vma (max_buf, max);
+ 
+       /* xgettext:c-format  */
+       err = _("%s out of range (0x%s is not between 0x%s and 0x%s)");
+ 
+       if (bad)
+       as_bad_where (file, line, err, prefix, val_buf, min_buf, max_buf);
+       else
+       as_warn_where (file, line, err, prefix, val_buf, min_buf, max_buf);
+     }
+ #endif
+ }
+ 
+ void
+ as_warn_value_out_of_range (char *   prefix,
+                          offsetT  value,
+                          offsetT  min,
+                          offsetT  max,
+                          char *   file,
+                          unsigned line)
+ {
+   as_internal_value_out_of_range (prefix, value, min, max, file, line, FALSE);
+ }
+ 
+ void
+ as_bad_value_out_of_range (char *   prefix,
+                          offsetT  value,
+                          offsetT  min,
+                          offsetT  max,
+                          char *   file,
+                          unsigned line)
+ {
+   as_internal_value_out_of_range (prefix, value, min, max, file, line, TRUE);
+ }
Index: gas/config/tc-alpha.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-alpha.c,v
retrieving revision 1.61
diff -c -3 -p -r1.61 tc-alpha.c
*** gas/config/tc-alpha.c       10 Dec 2003 06:41:08 -0000      1.61
--- gas/config/tc-alpha.c       5 May 2004 17:13:10 -0000
*************** insert_operand (insn, operand, val, file
*** 2373,2389 ****
        }
  
        if (val < min || val > max)
!       {
!         const char *err =
!           _("operand out of range (%s not between %d and %d)");
!         char buf[sizeof (val) * 3 + 2];
! 
!         sprint_value (buf, val);
!         if (file)
!           as_warn_where (file, line, err, buf, min, max);
!         else
!           as_warn (err, buf, min, max);
!       }
      }
  
    if (operand->insert)
--- 2373,2379 ----
        }
  
        if (val < min || val > max)
!       as_warn_value_out_of_range (_("operand"), val, min, max, file, line);
      }
  
    if (operand->insert)
Index: gas/config/tc-arc.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-arc.c,v
retrieving revision 1.26
diff -c -3 -p -r1.26 tc-arc.c
*** gas/config/tc-arc.c 18 Mar 2004 13:31:04 -0000      1.26
--- gas/config/tc-arc.c 5 May 2004 17:13:12 -0000
*************** arc_insert_operand (insn, operand, mods,
*** 328,344 ****
        test = val;
  
        if (test < (offsetT) min || test > (offsetT) max)
!       {
!         const char *err =
!           "operand out of range (%s not between %ld and %ld)";
!         char buf[100];
! 
!         sprint_value (buf, test);
!         if (file == (char *) NULL)
!           as_warn (err, buf, min, max);
!         else
!           as_warn_where (file, line, err, buf, min, max);
!       }
      }
  
    if (operand->insert)
--- 328,334 ----
        test = val;
  
        if (test < (offsetT) min || test > (offsetT) max)
!       as_warn_value_out_of_range (_("operand"), test, (offsetT) min, 
(offsetT) max, file, line);
      }
  
    if (operand->insert)
Index: gas/config/tc-mn10200.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-mn10200.c,v
retrieving revision 1.12
diff -c -3 -p -r1.12 tc-mn10200.c
*** gas/config/tc-mn10200.c     11 Jun 2003 06:11:45 -0000      1.12
--- gas/config/tc-mn10200.c     5 May 2004 17:13:13 -0000
*************** mn10200_insert_operand (insnp, extension
*** 1342,1358 ****
        test = val;
  
        if (test < (offsetT) min || test > (offsetT) max)
!         {
!           const char *err =
!             _("operand out of range (%s not between %ld and %ld)");
!           char buf[100];
! 
!           sprint_value (buf, test);
!           if (file == (char *) NULL)
!             as_warn (err, buf, min, max);
!           else
!             as_warn_where (file, line, err, buf, min, max);
!         }
      }
  
    if ((operand->flags & MN10200_OPERAND_EXTENDED) == 0)
--- 1342,1348 ----
        test = val;
  
        if (test < (offsetT) min || test > (offsetT) max)
!       as_warn_value_out_of_range (_("operand"), test, (offsetT) min, 
(offsetT) max, file, line);
      }
  
    if ((operand->flags & MN10200_OPERAND_EXTENDED) == 0)
Index: gas/config/tc-mn10300.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-mn10300.c,v
retrieving revision 1.45
diff -c -3 -p -r1.45 tc-mn10300.c
*** gas/config/tc-mn10300.c     10 Jul 2003 04:44:56 -0000      1.45
--- gas/config/tc-mn10300.c     5 May 2004 17:13:15 -0000
*************** mn10300_insert_operand (insnp, extension
*** 2584,2600 ****
        test = val;
  
        if (test < (offsetT) min || test > (offsetT) max)
!       {
!         const char *err =
!           _("operand out of range (%s not between %ld and %ld)");
!         char buf[100];
! 
!         sprint_value (buf, test);
!         if (file == (char *) NULL)
!           as_warn (err, buf, min, max);
!         else
!           as_warn_where (file, line, err, buf, min, max);
!       }
      }
  
    if ((operand->flags & MN10300_OPERAND_SPLIT) != 0)
--- 2584,2590 ----
        test = val;
  
        if (test < (offsetT) min || test > (offsetT) max)
!       as_warn_value_out_of_range (_("operand"), test, (offsetT) min, 
(offsetT) max, file, line);
      }
  
    if ((operand->flags & MN10300_OPERAND_SPLIT) != 0)
Index: gas/config/tc-ppc.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-ppc.c,v
retrieving revision 1.87
diff -c -3 -p -r1.87 tc-ppc.c
*** gas/config/tc-ppc.c 7 Apr 2004 04:50:15 -0000       1.87
--- gas/config/tc-ppc.c 5 May 2004 17:13:23 -0000
*************** ppc_insert_operand (insn, operand, val, 
*** 1457,1470 ****
        test = val;
  
        if (test < (offsetT) min || test > (offsetT) max)
!       {
!         const char *err =
!           _("operand out of range (%s not between %ld and %ld)");
!         char buf[100];
! 
!         sprint_value (buf, test);
!         as_bad_where (file, line, err, buf, min, max);
!       }
      }
  
    if (operand->insert)
--- 1457,1463 ----
        test = val;
  
        if (test < (offsetT) min || test > (offsetT) max)
!       as_bad_value_out_of_range (_("operand"), test, (offsetT) min, (offsetT) 
max, file, line);
      }
  
    if (operand->insert)
Index: gas/config/tc-s390.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-s390.c,v
retrieving revision 1.37
diff -c -3 -p -r1.37 tc-s390.c
*** gas/config/tc-s390.c        27 Feb 2004 12:33:11 -0000      1.37
--- gas/config/tc-s390.c        5 May 2004 17:13:23 -0000
*************** s390_insert_operand (insn, operand, val,
*** 614,634 ****
        /* Check for underflow / overflow.  */
        if (uval < min || uval > max)
        {
-         const char *err =
-           "operand out of range (%s not between %ld and %ld)";
-         char buf[100];
- 
          if (operand->flags & S390_OPERAND_LENGTH)
            {
              uval++;
              min++;
              max++;
            }
!         sprint_value (buf, uval);
!         if (file == (char *) NULL)
!           as_bad (err, buf, (int) min, (int) max);
!         else
!           as_bad_where (file, line, err, buf, (int) min, (int) max);
          return;
        }
      }
--- 614,628 ----
        /* Check for underflow / overflow.  */
        if (uval < min || uval > max)
        {
          if (operand->flags & S390_OPERAND_LENGTH)
            {
              uval++;
              min++;
              max++;
            }
! 
!         as_bad_value_out_of_range (_("operand"), test, (offsetT) min, 
(offsetT) max, file, line);
! 
          return;
        }
      }
Index: gas/config/tc-v850.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-v850.c,v
retrieving revision 1.37
diff -c -3 -p -r1.37 tc-v850.c
*** gas/config/tc-v850.c        22 Nov 2003 15:32:28 -0000      1.37
--- gas/config/tc-v850.c        5 May 2004 17:13:24 -0000
*************** v850_insert_operand (insn, operand, val,
*** 1618,1627 ****
  
          if (val < (offsetT) min || val > (offsetT) max)
            {
!             /* xgettext:c-format  */
!             const char *err =
!               _("operand out of range (%s not between %ld and %ld)");
!             char buf[100];
  
              /* Restore min and mix to expected values for decimal ranges.  */
              if ((operand->flags & V850_OPERAND_SIGNED)
--- 1618,1624 ----
  
          if (val < (offsetT) min || val > (offsetT) max)
            {
!             char buf [128];
  
              /* Restore min and mix to expected values for decimal ranges.  */
              if ((operand->flags & V850_OPERAND_SIGNED)
*************** v850_insert_operand (insn, operand, val,
*** 1633,1650 ****
                min = 0;
  
              if (str)
!               {
!                 sprintf (buf, "%s: ", str);
! 
!                 sprint_value (buf + strlen (buf), val);
!               }
              else
!               sprint_value (buf, val);
  
!             if (file == (char *) NULL)
!               as_warn (err, buf, min, max);
!             else
!               as_warn_where (file, line, err, buf, min, max);
            }
        }
  
--- 1630,1641 ----
                min = 0;
  
              if (str)
!               sprintf (buf, "%s: ", str);
              else
!               buf[0] = 0;
!             strcat (buf, _("operand"));
  
!             as_bad_value_out_of_range (buf, test, (offsetT) min, (offsetT) 
max, file, line);
            }
        }
  


-- 


http://sources.redhat.com/bugzilla/show_bug.cgi?id=143

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]