the following program gives a
"useless or misleading comparison: UINT < 0".
#include <u.h>
#include <libc.h>
uint r[]; // <-- unsigned array
void
main(int argc, char *argv[])
{
int r; // <--- signed
r = 0;
if(r < 0){
exits(0);
}
}
term% 6c -TVFwy /tmp/a.c
....
decl "r": C=GLOBL [B=0:O=0] T=ARRAY[0] UINT
decl "a": C=GLOBL [B=0:O=0] T=INT
decl "main": C=GLOBL [B=0:O=0] T=FUNC(INT, IND IND CHAR) VOID
decl "argc": C=PARAM [B=1:O=0] T=INT
decl "argv": C=PARAM [B=1:O=8] T=IND IND CHAR
decl "r": C=AUTO [B=1:O=-4] T=INT
revert1 "r"
revert1 "argv"
revert1 "argc"
== strange ==
LT INT /tmp/a.c:13
NAME "r" -4 <1> INT /tmp/a.c:13
CONST "0" INT /tmp/a.c:13
all types seem fine here.
the reason is the following code in /sys/src/cmd/cc/com.c:^compar
/*
* Skip over left casts to find out the original expression range.
*/
while(l->op == OCAST)
l = l->left;
if(l->op == OCONST)
return 0;
lt = l->type;
if(l->op == ONAME && l->sym->type){
lt = l->sym->type;
// <------ here
if(lt->etype == TARRAY)
lt = lt->link;
}
note how we take the type from l->sym (which has been reverted).
why do we use the type from the sym instead of using the type
from the node?
--
cinap