Commit graph

14 commits

Author SHA1 Message Date
Ori Bernstein 52dc943702 fix ccom idempotency
ccom may be called multiple times on the same
node, via 'goto loop' calls from the commute
label, OADD, and a few other places.

Casts to void could null out the LHS of the
node, which would cause the compiler to crash
if the cast was revisited due to one of these
cases, because we tried frobbing n->left.

Now, if n->left is nil, we just return.w
2020-03-15 15:08:04 -07:00
Ori Bernstein 3df95385bc fix special case for null pointer constants in cond expressions
Section 6.5.15 of the C99 spec requires that if
	one argument of a ?: expression is a null pointer
	constant, and the other has a pointer type T*, then
	the type of the expression is T*.

	We were attempting to follow this rule, however,
	we only handled literal expressions when checking
	for null pointers.

	This change looks through casts, so 'nil' and 'NULL',
	and their expansion '(void*)0' are all detected as
	null pointer constants.
2020-02-27 15:09:10 -05:00
cinap_lenrek 766a641d25 cc: fix void cast crash
the following code reproduces the crash:

void
foo(void)
{
}

void
main(int argc, char **argv)
{
	(void)(1 ? (void)0 : foo());
}

the problem is that side() gives a false positive on the OCOND
with later constant folding eleminating the acutal side effect
and OCAST ending up with two nested OCATS with the nested one
being zapped (type == T).
2019-09-07 02:11:18 +02:00
cinap_lenrek 63191949b9 cc: remove nullwarn() from OCAST codegen, zap void casts
implicit casts would cause spurious "result of operation not used"
warnings such as ape's stdio putc() macro.

make (void) casts non-ops when the casted expression has no
side effects. this avoid spurious warning with ape's assert()
macro.
2019-06-19 23:50:33 +02:00
Ori Bernstein ff344562db Import compiler warnings and bugfixes from Charles.
This change imports a few warnings and minor fixes from Charles branch
here: https://bitbucket.org/plan9-from-bell-labs/plan9.

The changes included here:


	changeset:   1374:9185dc017be0
	summary:     declare castucom; move a declaration into order;
	             use cast instead of ULL suffix
	changeset:   1353:5fe8380b1818
	summary:     supporting functions:
	             1. castucom to match unlikely mask operation;
  	             2. be sure to snap both sides of pointer subtraction completely;
	             3. add extra operators as side-effect free
	changeset:   1352:90058c092d66
	summary:     1. correct result type for mixed-mode assignment operators
	             2. detect divide by zero (erik);
	             3. detect masks misformed by sign-extension;
	             4. diagnose mixed old/new prototypes
2019-06-18 22:17:19 -07:00
aiju b5f7e27f44 kencc: make "function not declared" a warning unless compiling with -T 2018-12-02 11:36:58 +00:00
aiju d9b9e15d6b kencc: turn "function args not checked" warning into "function not declared" error if appropriate 2018-12-01 11:39:49 +00:00
cinap_lenrek 485a3301e6 cc: fix wrong "useless or misleading comparison" warning
to reproduce:

 	u8int x, y;

 	x = 0xff;
 	y = 0xc0;
 	if((s8int)(x & y) >= 0)
 		print("help\n");

compiles correctly but prints a warning

warning: test.c:11 useless or misleading comparison: UINT >= 0

the issue is that compar() unconditionally skipped over
all left casts ignoring the case when a cast would sign
extend the value.

the new code only skips over the cast when the original
type with is smaller than the cast result or when they
are equal width and types have same signedness. so the
effective left hand side type is the last truncation
or sign extension.
2018-11-18 20:42:45 +01:00
cinap_lenrek bfd0cb0db4 cc/6c: fix return type of mixed asop expressions, preserve type for moves so fixed<->float conversions work correctly 2015-10-04 20:02:58 +02:00
cinap_lenrek 3426459ab5 cc: fix spurious warning on comparsion with scope redeclared variable (thanks aiju)
> warning: a.c:9 useless or misleading comparison: UINT < 0

the error can be observed by compiling the following code
with warnings enabled:

#include <u.h>
#include <libc.h>

uint r;

void
main(int argc, char *argv[])
{
	int r;

	if(r < 0){
		exits(0);
	}
}

the offending code in the compiler is:

-	if(l->op == ONAME && l->sym->type){
-		lt = l->sym->type;
-		if(lt->etype == TARRAY)
-			lt = lt->link;
-	}

compiler handles scope by overwritin and reverting
symbols while parsing. in the ccom phase, the nodes symbol
(n->sym) is not in the right scope and we wrongly think r
is uint instead of int.

it is not clear to me what this code tried to accomplish in
the first place nor could anyone answer me this question.

the risk is small as this change doesnt affect the compiled
program, only the warning, so removing the offending code.
2014-05-06 21:36:28 +02:00
cinap_lenrek 6cadd03bbe fix utf and rune handling in preparation for 32bit runes 2012-12-31 21:09:46 +01:00
cinap_lenrek 4f33c88a51 import updated compilers from sources 2012-07-30 19:11:16 +02:00
Taru Karttunen a9060cc06b Import sources from 2011-03-30 iso image - lib 2011-03-30 19:35:09 +03:00
Taru Karttunen e5888a1ffd Import sources from 2011-03-30 iso image 2011-03-30 15:46:40 +03:00