Skip to content

Commit

Permalink
Merge pull request #6579 from yebblies/overflowdup
Browse files Browse the repository at this point in the history
Suppress duplicate errors on integer division overflow during constfolding
merged-on-behalf-of: Andrei Alexandrescu <andralex@users.noreply.github.com>
  • Loading branch information
dlang-bot committed Feb 27, 2017
2 parents 2bf9a9d + 27fb424 commit 5a86795
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
12 changes: 8 additions & 4 deletions src/ddmd/constfold.d
Original file line number Diff line number Diff line change
Expand Up @@ -439,12 +439,14 @@ extern (C++) UnionExp Div(Loc loc, Type type, Expression e1, Expression e2)
if (n1 == 0xFFFFFFFF80000000UL && type.toBasetype().ty != Tint64)
{
e2.error("integer overflow: int.min / -1");
n2 = 1;
emplaceExp!(ErrorExp)(&ue);
return ue;
}
else if (n1 == 0x8000000000000000L) // long.min / -1
{
e2.error("integer overflow: long.min / -1");
n2 = 1;
emplaceExp!(ErrorExp)(&ue);
return ue;
}
}
if (e1.type.isunsigned() || e2.type.isunsigned())
Expand Down Expand Up @@ -501,12 +503,14 @@ extern (C++) UnionExp Mod(Loc loc, Type type, Expression e1, Expression e2)
if (n1 == 0xFFFFFFFF80000000UL && type.toBasetype().ty != Tint64)
{
e2.error("integer overflow: int.min %% -1");
n2 = 1;
emplaceExp!(ErrorExp)(&ue);
return ue;
}
else if (n1 == 0x8000000000000000L) // long.min % -1
{
e2.error("integer overflow: long.min %% -1");
n2 = 1;
emplaceExp!(ErrorExp)(&ue);
return ue;
}
}
if (e1.type.isunsigned() || e2.type.isunsigned())
Expand Down
2 changes: 2 additions & 0 deletions src/ddmd/init.d
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,8 @@ extern (C++) final class ExpInitializer : Initializer
{
exp = exp.implicitCastTo(sc, t);
}
if (!global.gag && olderrors != global.errors)
return this;
exp = exp.ctfeInterpret();
}
else
Expand Down
16 changes: 4 additions & 12 deletions test/fail_compilation/test4682.d
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
/*
TEST_OUTPUT:
----
fail_compilation/test4682.d(18): Error: integer overflow: int.min / -1
fail_compilation/test4682.d(18): Error: integer overflow: int.min / -1
fail_compilation/test4682.d(18): Error: integer overflow: int.min / -1
fail_compilation/test4682.d(19): Error: integer overflow: long.min / -1
fail_compilation/test4682.d(19): Error: integer overflow: long.min / -1
fail_compilation/test4682.d(19): Error: integer overflow: long.min / -1
fail_compilation/test4682.d(20): Error: integer overflow: int.min % -1
fail_compilation/test4682.d(20): Error: integer overflow: int.min % -1
fail_compilation/test4682.d(20): Error: integer overflow: int.min % -1
fail_compilation/test4682.d(21): Error: integer overflow: long.min % -1
fail_compilation/test4682.d(21): Error: integer overflow: long.min % -1
fail_compilation/test4682.d(21): Error: integer overflow: long.min % -1
fail_compilation/test4682.d(10): Error: integer overflow: int.min / -1
fail_compilation/test4682.d(11): Error: integer overflow: long.min / -1
fail_compilation/test4682.d(12): Error: integer overflow: int.min % -1
fail_compilation/test4682.d(13): Error: integer overflow: long.min % -1
----
*/
auto a = int.min / -1;
Expand Down

0 comments on commit 5a86795

Please sign in to comment.