Commit graph

68 commits

Author SHA1 Message Date
cinap_lenrek d6a91e0ae4 cc: set unspecified elements to zero in local variable initializers
the compiler used to skip zero initialization when initializer
list was given not covering unspecified elements. now we zero
all non explicitely initialized elements. for example:

typedef struct F F;
struct F
{
	int a;
	int b;
	int c;
};

void
main(void)
{
	char a[16] = { 1, 2, 3 };	/* a[3..15] initialized to zero */
	F f = { .b = 1 };			/* f.a, f.c initialized to zero */
}
2015-05-26 19:25:06 +02:00
cinap_lenrek 0d87019a9b cc: handle unaligned data in = {0} local initializer
the emited code that initializes local variables did not handle
unaligned data causing stack corruption, affecting code like:

void main(void)
{
	char a[9] = {0};
}

this change will emit code that does byte stores for the unaligned
bytes and also handles small objects (<= 16 bytes) without branches.
2015-05-25 01:57:18 +02:00
cinap_lenrek c1ff805e23 cc: fix non constant pointer initializer for other compilers than 8c/6c
i made a mistake here as this change breaks the arm and mips compilers
which lack an optimiation in xcom() that folds constant pointer arithmetic
into the offset. on arm, the a node is a complex expression with op OADD of
type TIND but the test rejected the (valid) pointer arithmetic.

instead, we now test for the operations which cannot be constant instead
of using the type as a proxy.
2015-04-23 05:12:57 +02:00
cinap_lenrek 433b18ec2b cc: catch non constant pointer initializers
char	FOO[] = "abc";	/* ok */
char	*BAR = FOO;		/* ok */
char	*BAZ = BAR;		/* wrong */
2015-04-16 14:32:42 +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 2750062701 cc: correct out-of-bounds references in funct.c (thanks charles forsyth) 2014-03-02 21:08:48 +01:00
cinap_lenrek 37de63aec3 cc: emit right acid format for address
we could use 'A' here but then it would require the new acid.
2014-02-10 23:10:47 +01:00
cinap_lenrek cc24222672 fixes for new setmalloctag() prototype 2014-02-01 10:29:14 +01:00
cinap_lenrek ee67552c4b cc: fix include array overflow handling 2013-07-11 19:01:03 +02:00
cinap_lenrek 58533c35fb cc: accept 24 bit numeric runes 2013-05-01 16:55:11 +02:00
ftrvxmtrx 0b212ed505 cc/lex: do not crash on -I without arg 2013-02-02 16:54:09 +01:00
cinap_lenrek 6cadd03bbe fix utf and rune handling in preparation for 32bit runes 2012-12-31 21:09:46 +01:00
cinap_lenrek 76c102e548 apply sources patch cc-cpp-c99-comm
When running "?c -p ...", ensure the backend cpp recognizes C++ comments.

2c(1) states that the compilers recognize // comments, and the bare compilers
do.  But if you invoke the compiler with '-p', the backend cpp process
doesn't handle // comments properly unless you also give ?c the undocumented
'-+' option (which it passes through to cpp).
2012-10-03 18:09:53 +02:00
cinap_lenrek 4f33c88a51 import updated compilers from sources 2012-07-30 19:11:16 +02:00
aiju 9f31fa9d8e have compiler error out if read fails 2011-07-12 17:51:34 +02:00
aiju 5f7f366e73 fixed issue #47 2011-05-25 10:14:30 +00: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