Skip to content

Commit

Permalink
Fix Issue 23173 - "Error: signed integer overflow" for compiler gener…
Browse files Browse the repository at this point in the history
…ated string of `long.min` (#14218)
  • Loading branch information
dkorpel committed Jul 29, 2022
1 parent 10d62fc commit 043caf1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
12 changes: 11 additions & 1 deletion compiler/src/dmd/hdrgen.d
Original file line number Diff line number Diff line change
Expand Up @@ -1890,7 +1890,17 @@ private void expressionPrettyPrint(Expression e, OutBuffer* buf, HdrGenState* hg
buf.printf("%uu", cast(uint)v);
break;
case Tint64:
buf.printf("%lldL", v);
if (v == long.min)
{
// https://issues.dlang.org/show_bug.cgi?id=23173
// This is a special case because - is not part of the
// integer literal and 9223372036854775808L overflows a long
buf.writestring("cast(long)-9223372036854775808");
}
else
{
buf.printf("%lldL", v);
}
break;
case Tuns64:
buf.printf("%lluLU", v);
Expand Down
6 changes: 6 additions & 0 deletions test/compilable/test23173.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// REQUIRED_ARGS: -o-
// https://issues.dlang.org/show_bug.cgi?id=23173

mixin("long l = ", long.min, ";");
static assert(mixin(long.min) == long.min);
static assert(is(typeof(mixin(long.min)) == long));

0 comments on commit 043caf1

Please sign in to comment.