[Bug other/80437] large decimal numbers in diagnostics are hard to read

2018-11-01 Thread egallager at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80437

--- Comment #7 from Eric Gallager  ---
(In reply to Markus Trippelsdorf from comment #6)
> (In reply to David Malcolm from comment #4)
> > If the warning is based of a const, maybe lead with that e.g. in the 2nd
> > place here:
> > 
> > bug.c:11:5: warning: 'memset': specified size 18446744073709551611 (aka
> > 0x___fffb, 1<<64 - 5, SOME_CONST) exceeds maximum object size
> > PTRDIFF_MAX (aka 9223372036854775807, 0x7fff___, 1<<63 - 1)
> 
> Please keep it simple and don't over-engineer.
> Printing all four variants looks like overkill to me.
> 
> I would simply use decimals up to a certain cut-off and hex numbers
> (without underscores) above it.

Yeah that sounds good to me too.

[Bug other/80437] large decimal numbers in diagnostics are hard to read

2017-08-02 Thread trippels at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80437

Markus Trippelsdorf  changed:

   What|Removed |Added

 CC||trippels at gcc dot gnu.org

--- Comment #6 from Markus Trippelsdorf  ---
(In reply to David Malcolm from comment #4)
> If the warning is based of a const, maybe lead with that e.g. in the 2nd
> place here:
> 
> bug.c:11:5: warning: 'memset': specified size 18446744073709551611 (aka
> 0x___fffb, 1<<64 - 5, SOME_CONST) exceeds maximum object size
> PTRDIFF_MAX (aka 9223372036854775807, 0x7fff___, 1<<63 - 1)

Please keep it simple and don't over-engineer.
Printing all four variants looks like overkill to me.

I would simply use decimals up to a certain cut-off and hex numbers
(without underscores) above it.

[Bug other/80437] large decimal numbers in diagnostics are hard to read

2017-08-01 Thread egallager at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80437

Eric Gallager  changed:

   What|Removed |Added

 CC||egallager at gcc dot gnu.org

--- Comment #5 from Eric Gallager  ---
(In reply to David Malcolm from comment #3)
> Maybe could also make creative use of underscores in large hex values to
> make things easier on the eye e.g.:
> 
> bug.c:11:5: warning: 'memset': specified size 18446744073709551611 (aka
> 0x___fffb, 1<<64 - 5, SOME_CONST) exceeds maximum object size
> 9223372036854775807  (aka 0x7fff___, 1<<63 - 1, SOME_OTHER_CONST)

The underscores would make copying and pasting the values more difficult
though...

[Bug other/80437] large decimal numbers in diagnostics are hard to read

2017-08-01 Thread dmalcolm at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80437

--- Comment #4 from David Malcolm  ---
If the warning is based of a const, maybe lead with that e.g. in the 2nd place
here:

bug.c:11:5: warning: 'memset': specified size 18446744073709551611 (aka
0x___fffb, 1<<64 - 5, SOME_CONST) exceeds maximum object size
PTRDIFF_MAX (aka 9223372036854775807, 0x7fff___, 1<<63 - 1)

[Bug other/80437] large decimal numbers in diagnostics are hard to read

2017-08-01 Thread dmalcolm at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80437

--- Comment #3 from David Malcolm  ---
Maybe could also make creative use of underscores in large hex values to make
things easier on the eye e.g.:

bug.c:11:5: warning: 'memset': specified size 18446744073709551611 (aka
0x___fffb, 1<<64 - 5, SOME_CONST) exceeds maximum object size
9223372036854775807  (aka 0x7fff___, 1<<63 - 1, SOME_OTHER_CONST)

[Bug other/80437] large decimal numbers in diagnostics are hard to read

2017-08-01 Thread dmalcolm at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80437

--- Comment #2 from David Malcolm  ---
Maybe all four (decimal, hex, formula, and constant):

bug.c:11:5: warning: 'memset': specified size 18446744073709551611 (aka
0xfffb, 1<<64 - 5, SOME_CONST) exceeds maximum object size
9223372036854775807  (aka 0x7fff, 1<<63 - 1, SOME_OTHER_CONST)

[Bug other/80437] large decimal numbers in diagnostics are hard to read

2017-08-01 Thread dmalcolm at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80437

David Malcolm  changed:

   What|Removed |Added

 CC||dmalcolm at gcc dot gnu.org

--- Comment #1 from David Malcolm  ---
(In reply to Martin Sebor from comment #0)

[...snip...]

> bug.c:11:5: warning: 'memset': specified size 0xfffb exceeds
> maximum object size 0x [-Wstringop-overflow=]
> 
> I'm not sure that this a significant improvement.  Those already familiar
> with the -Wstringop-overflow warning will likely understand what
> 0x in this context means but only because we know the
> maximum object size limit (i.e., PTRDIFF_MAX) and realize that all printed
> values are in the [PTRDIFF_MAX + 1, SIZE_MAX] range and thus always consist
> of 16 hex digits.  Someone who's seen the warning for the first time will
> either have to guess or count the f's.  This is even more likely for the
> specified size (such as 0xfffb).  In cases where a much lower
> limit is specified by the user (e.g., via -Walloca-larger-than) it's even
> less clear how to interpret a number in any base.
> 
> I think it's possible to do better.  One approach is to print very large
> values in terms of well-known constants such as SIZE_MAX or PTRDIFF_MAX. 
> For instance, instead of printing 18446744073709551611 (i.e., -5) print
> SIZE_MAX - 4.  Another solution might be to print sizes as signed (though
> that won't help in the case of the user-specified limit).

How about printing *both* i.e.:

bug.c:11:5: warning: 'memset': specified size 0xfffb (SIZE_MAX - 4)
exceeds maximum object size 0x (PTRDIFF_MAX)
[-Wstringop-overflow=]

(I may have got the expressions wrong, but hopefully the meaning is clear)

> Since the problem of how best to present large decimal numbers is general
> and applies to all diagnostics, including warnings, errors, and notes, a
> change to how these numbers are presented should be brought up for a wider
> discussion before it's implemented consistently, for all diagnostics.

I find large decimal numbers intimidating, and find hexadecimals easier for
values close to large powers of two.

Suggestion: choose base based on a "mental effort cost":

Example 1
*
For example, if we have an overflow that occurs when x >= 2^31,
which is easier to read:

DECIMAL:
  warning: buffer overflow occurs when x >= 2147483648

HEX:
  warning: buffer overflow occurs when x >= 0x8000

FORMULA:
  warning: buffer overflow occurs when x >= 2^31

FORMULA and HEX:
  warning: buffer overflow occurs when x >= 2^31 (0x8000)

Example 2
*
an overflow that occurs when x >= 100

DECIMAL:
  warning: buffer overflow occurs when x >= 100

HEX:
  warning: buffer overflow occurs when x >= 0x64

In the above case, decimal is the easier-to-read format.

Example 3
*

an overflow that occurs when x >= 0x7fff

DECIMAL:
  warning: buffer overflow occurs when x >= 2147418112

HEX:
  warning: buffer overflow occurs when x >= 0x7fff

In this case, hexadecimal is the easier-to-read format.

Example 4
*

an overflow that occurs when x <= -8000

DECIMAL:
  warning: buffer overflow occurs when x <= -8000

HEX:
  warning: buffer overflow occurs when x <= -0x1f40


The idea


The idea is a way to choose the printed representation based on the value,
based on the number of "awkward" digits.

On implementation is to assign a cost to a digit based on closeness to zero.

For example, in decimal,
  '0' : low cost
  '1', '9': medium cost
  '2'..'8': high cost

in hexadecimal:i
  '0' : low cost
  '1', 'f': medium cost
  '2'..'e': high cost

We can weight these, say cost 10 for "high", cost 1 for "medium", cost 0 for
"low".

"Cheaper" in this sense should mean "easier for a human to understand"; a rough
measure of the amount of mental effort required by a human reader.

Hence:

example 1:
  decimal: 2147483648
10 digits, 9 high cost, 1 medium cost: cost = 91

  hexadecimal: 0x8000
8 digits; 1 high cost, 7 low cost: cost = 17

  hence hexadecimal is "cheaper", and we use it

example 2:
  decimal: 100
3 digits, 1 medium cost, 2 low cost: cost = 1

  hexadecimal: 0x64
2 high cost digits: cost = 20

  hence decimal is "cheaper", and we use it

example 3:
  decimal: 2147418112
10 digits: 4 medium cost, 6 high cost: cost = 64

  hexadecimal: 0x7fff
8 digits: 1 high cost, 3 medium cost, 4 low cost: cost = 13

  hence hexadecimal is "cheaper", and we use it

example 4:
  decimal: -8000
3 low cost digits, 1 high cost: cost = 10

  hexadecimal: -0x1f40
1 low cost, 2 medium cost, 1 high cost: cost = 12

  hence decimal is "cheaper", and we use it

I guessed at these weightings; there may be better ones.

[Bug other/80437] large decimal numbers in diagnostics are hard to read

2017-04-15 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80437

Martin Sebor  changed:

   What|Removed |Added

   Keywords||diagnostic
   Severity|normal  |enhancement