since this case was completely deleted, can someone
tell me where is this case caught now?
- erik
----
com.c:1032,1055 - /mnt/term/usr/quanstro/nix//sys/src/cmd/cc/com.c:1032,1037
case OASADD:
ccom(l);
ccom(r);
- if(n->op == OASMOD || n->op == OASLMOD || n->op == OASDIV || n->op == OASLDIV)
- if(r->op == OCONST){
- if(!typefd[r->type->etype] && r->vconst == 0) {
- if(n->op == OASMOD || n->op == OASLMOD)
- diag(n, "modulo by zero");
- else
- diag(n, "divide by zero");
- r->vconst = ~0;
- }
- if(typefd[r->type->etype] && r->fconst == 0.) {
- if(n->op == OASMOD || n->op == OASLMOD)
- diag(n, "modulo by zero");
- else
- diag(n, "divide by zero");
- r->fconst = 1e10;
- }
- }
-
if(n->op == OASLSHR || n->op == OASASHR || n->op == OASASHL)
if(r->op == OCONST) {
t = n->type->width * 8; /* bits per byte */
> that was not in Plan 9
you're right. why not? i couldn't find my test code,
and my naive test gets caught by scon.
i think i added this code after somebody crashed the
compiler.
- erik
; cat ccbug.c
#include <u.h>
#include <libc.h>
void
main(void)
{
uvlong v;
v = 0;
v /= 1 / 100;
v %= 1/100;
}
ladd; /n/sources/plan9/386/bin/8c ccbug.c
ladd; 8c ccbug.c
ccbug.c:10 divide by zero
ccbug.c:11 modulo by zero
charles, did you come to a conclusion on this?
i've become partial to this warning message
(as it prevents angry c compiler users), so i'm keeping
it regardless.
- erik
> People do that a lot? Unlike (say) silent overflow, div or mod by zero
> immediately produces a trap.
> It seemed to me that if anything, the diagnostic ought to be for 1/100,
> nothing
> to do with the application of the result.
remember this is a clarified example. the original code had some defines
or enums which occulted the actual arithmetic in question. then in a
header file, the constant used as the divisor was changed in a seemingly
sensible way. the results unfortunately, were surprising and not sensible.
> i'd have thought as many problems arise from mixed-mode arithmetic:
> v * (1/100)
> which currently won't be diagnosed either.
it could be.
- erik