-
Notifications
You must be signed in to change notification settings - Fork 77
error 094: division by zero #538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This issue has been automatically marked as stale because it has not had recent activity. |
f13ccf5
to
313b071
Compare
Not sure if you noticed, but I force-pushed the commit that adds the tests with |
I did see, yes. Thank you. |
Ah, OK, I was just wondering why you only approved the PR and didn't merge it, that's all. |
I was doing all the merges locally on my PC, easier to go through conflicts and run tests. I always try building my YSI test suite with new compiler versions, just because it covers so many weird corners of the compiler. |
I guess we should provide more info about stuff like that: /* If we're handling a division operation, make sure the divisor is not zero. */
if ((oper == os_div || oper == os_mod)) {
printf("%s is | %d\n", lval2->sym && lval2->sym->name ? lval2->sym->name : "unknown", lval2->sym ? lval2->sym->usage & uWRITTEN : 0);
if (lval2->ident == iCONSTEXPR && lval2->constval == 0 || lval2->sym && (lval2->sym->usage & uWRITTEN) == 0 && lval2 value == 0...)
error(94); /* TODO: implement proper description, 94 */ /* division by zero */
} but there's a problem, i guess usage not properly resetted before final parsing, so, this code will never... func1(&var) {
var = 1;
}
main()
{
// Case 1: Both operands are compile-time constants
new a = 1 / 0; // error 094 - ok
new b = 1 % 0; // error 094 - ok
new c = 1 / 1; // - ok
new d = 1 % 1; // - ok
new var = 0;
new a1 = 0 / var; // Where's error? - not ok?
--var; // variable changed
var++; // variable changed
var+=-1; // variable changed
var+=1; // variable changed
// etc...
func1(var); // variable changed
new a2 = 0 % var; // no errors
new a3 = var / 1;
new a4 = var % 1;
const var2 = 0;
new a11 = var2 / 0; // error 094 - ok
new a22 = var2 % 0; // error 094 - ok
new a33 = var / 1;
new a44 = var % 1;
new a111 = var / var2; // error 094
new a222 = var % var2; // error 094
new a333 = var2 / 1;
new a444 = var2 % 1;
new a6 = 1 / var; // No error, but should...
new a7 = 1 % var; // Same here
#pragma unused a,b,c,d,a1,a2,a3,a4,a6,a7,a11,a22,a33,a44,a111,a222,a333,a444
} @Y-Less is that possible to improve? |
What this PR does / why we need it:
This PR does the following:
invalid expression, assumed zero
), as first suggested in New warnings/errors? #528.Previously the check for zero division was located in function
flooreddiv()
(filesc3.c
) that calculated the result of division when both operands are compile-time constants, which means that the check only worked when the dividend was constant.Which issue(s) this PR fixes:
Fixes #
What kind of pull this is:
Additional Documentation: