diff --git a/llvm/docs/TableGen/ProgRef.rst b/llvm/docs/TableGen/ProgRef.rst --- a/llvm/docs/TableGen/ProgRef.rst +++ b/llvm/docs/TableGen/ProgRef.rst @@ -1623,8 +1623,8 @@ ``(op a1-value:$name1, a2-value:$name2, ?:$name3)``. ``!div(``\ *a*\ ``,`` *b*\ ``)`` - This operator divides *a* and *b*, and produces the quotient. - Division by 0 produces an error. + This operator preforms signed division of *a* by *b*, and produces the quotient. + Division by 0 produces an error. Division by INT64_MIN produces an error. ``!empty(``\ *a*\ ``)`` This operator produces 1 if the string, list, or DAG *a* is empty; 0 otherwise. diff --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp --- a/llvm/lib/TableGen/Record.cpp +++ b/llvm/lib/TableGen/Record.cpp @@ -1187,7 +1187,10 @@ case DIV: if (RHSv == 0) PrintFatalError(CurRec->getLoc(), - Twine("Illegal operation: division by zero")); + "Illegal operation: division by zero"); + else if (LHSv == INT64_MIN && RHSv == -1) + PrintFatalError(CurRec->getLoc(), + "Illegal operation: INT64_MIN / -1"); else Result = LHSv / RHSv; break; diff --git a/llvm/test/TableGen/math.td b/llvm/test/TableGen/math.td --- a/llvm/test/TableGen/math.td +++ b/llvm/test/TableGen/math.td @@ -1,5 +1,6 @@ // RUN: llvm-tblgen %s | FileCheck %s // RUN: not llvm-tblgen -DERROR1 %s 2>&1 | FileCheck --check-prefix=ERROR1 %s +// RUN: not llvm-tblgen -DERROR2 %s 2>&1 | FileCheck --check-prefix=ERROR2 %s // XFAIL: vg_leak // CHECK: def shifts @@ -73,6 +74,11 @@ def v18 : Int; #endif +#ifdef ERROR2 +// ERROR2: error: Illegal operation: INT64_MIN / -1 +def v19 : Int; +#endif + // CHECK: def v1a // CHECK: Value = 1