Skip to content

Commit 043caf1

Browse files
authored
Fix Issue 23173 - "Error: signed integer overflow" for compiler generated string of long.min (#14218)
1 parent 10d62fc commit 043caf1

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

compiler/src/dmd/hdrgen.d

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1890,7 +1890,17 @@ private void expressionPrettyPrint(Expression e, OutBuffer* buf, HdrGenState* hg
18901890
buf.printf("%uu", cast(uint)v);
18911891
break;
18921892
case Tint64:
1893-
buf.printf("%lldL", v);
1893+
if (v == long.min)
1894+
{
1895+
// https://issues.dlang.org/show_bug.cgi?id=23173
1896+
// This is a special case because - is not part of the
1897+
// integer literal and 9223372036854775808L overflows a long
1898+
buf.writestring("cast(long)-9223372036854775808");
1899+
}
1900+
else
1901+
{
1902+
buf.printf("%lldL", v);
1903+
}
18941904
break;
18951905
case Tuns64:
18961906
buf.printf("%lluLU", v);

test/compilable/test23173.d

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// REQUIRED_ARGS: -o-
2+
// https://issues.dlang.org/show_bug.cgi?id=23173
3+
4+
mixin("long l = ", long.min, ";");
5+
static assert(mixin(long.min) == long.min);
6+
static assert(is(typeof(mixin(long.min)) == long));

0 commit comments

Comments
 (0)