From 60c7254a378af70bb45e47881bfd0c02fc75c51b Mon Sep 17 00:00:00 2001 From: borutr Date: Sun, 13 Jan 2008 07:54:32 +0000 Subject: [PATCH] *src/SDCCicode.c: fixed bug #1870216 - Error 122: dividing by zero git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4992 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 7 +++++++ src/SDCCicode.c | 33 +++++++++++++++++---------------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index db1f68bb..12700a1b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,13 @@ 2008-01-13 Borut Razem * support/scripts/sdcc.nsi: added Uninstall/reinstall page, ... + *src/SDCCicode.c: fixed bug #1870216 - Error 122: dividing by zero + +2007-12-30 Borut Razem + + * src/pic16/gen.c: fixed implementation of bitwise operations for + pic16targer + * support/regression/tests/bitwise.c: added test cases 2007-12-29 Borut Razem diff --git a/src/SDCCicode.c b/src/SDCCicode.c index aa2c62cc..17552764 100644 --- a/src/SDCCicode.c +++ b/src/SDCCicode.c @@ -1226,28 +1226,29 @@ operandOperation (operand * left, operand * right, operandLitValue (right))); break; case '/': - if ((TYPE_TARGET_ULONG) double2ul (operandLitValue (right)) == 0) + if (IS_UNSIGNED (type)) { - werror (E_DIVIDE_BY_ZERO); - retval = right; - + if ((TYPE_TARGET_ULONG) double2ul (operandLitValue (right)) == 0) + { + werror (E_DIVIDE_BY_ZERO); + retval = right; + } + SPEC_USIGN (let) = 1; + SPEC_USIGN (ret) = 1; + retval = operandFromValue (valCastLiteral (type, + (TYPE_TARGET_ULONG) double2ul (operandLitValue (left)) / + (TYPE_TARGET_ULONG) double2ul (operandLitValue (right)))); } else { - if (IS_UNSIGNED (type)) + if (operandLitValue (right) == 0) { - SPEC_USIGN (let) = 1; - SPEC_USIGN (ret) = 1; - retval = operandFromValue (valCastLiteral (type, - (TYPE_TARGET_ULONG) double2ul (operandLitValue (left)) / - (TYPE_TARGET_ULONG) double2ul (operandLitValue (right)))); - } - else - { - retval = operandFromValue (valCastLiteral (type, - operandLitValue (left) / - operandLitValue (right))); + werror (E_DIVIDE_BY_ZERO); + retval = right; } + retval = operandFromValue (valCastLiteral (type, + operandLitValue (left) / + operandLitValue (right))); } break; case '%': -- 2.30.2