[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Tinycc-devel] Last two warnings
From: |
Christian Jullien |
Subject: |
Re: [Tinycc-devel] Last two warnings |
Date: |
Wed, 13 Feb 2013 07:02:20 +0100 |
Hi Grichka,
Since you last commit was about cleanup, let me insist on last warning (also a
cleanup)
tccpp.c: In function ‘macro_subst’:
tccpp.c:2803:12: warning: ‘*((void *)&cval+4)’ is used uninitialized in this
function [-Wuninitialized]
This is the only warning I have with default config on Rpi using gcc 4.7.2.
gcc -o tccpp.o -c tccpp.c -DTCC_TARGET_ARM -DWITHOUT_LIBTCC -DTCC_ARM_EABI
-DTCC_ARM_HARDFLOAT -DCONFIG_MULTIARCHDIR=\"arm-linux-gnueabihf\" -DTCC_ARM_VFP
-I. -Wall -g -O2 -fno-strict-aliasing -Wno-pointer-sign -Wno-sign-compare
Analysis of this warning (why gcc complains).
On macro_twosharps, cval is used two times:
Inside for loop at line 2810
/* we search the first '##' */
for(ptr = macro_str;;) {
TOK_GET(&t, &ptr, &cval); <-- first use
if (t == TOK_TWOSHARPS)
break;
A second time at line 2840
if (t && t != TOK_TWOSHARPS) {
TOK_GET(&t, &ptr, &cval);
/* We concatenate the two tokens */
cstr_new(&cstr);
cstr_cat(&cstr, get_tok_str(tok, &tokc));
Because gcc is unable to know if we entered the first loop (which possibly can
initialize some cval fields), it complains on line 2840 that cval might be used
uninitialized (by 2810 if we do not enter the first loop).
To me, the first use is only to find ## and we don't do anything with cval, so
it is safe to use a local declaration:
/* we search the first '##' */
for(ptr = macro_str;;) {
CValue ignored;
TOK_GET(&t, &ptr, &ignored);
if (t == TOK_TWOSHARPS)
break;
/* nothing more to do if end of string */
if (t == 0)
return NULL;
}
I tried this change with test suite and had no issues.
Christian
-----Original Message-----
From: address@hidden [mailto:address@hidden On Behalf Of grischka
Sent: mercredi 6 février 2013 23:23
To: address@hidden
Subject: Re: [Tinycc-devel] Last two warnings
Christian Jullien wrote:
> tccpp.c: In function ‘macro_subst’:
>
> tccpp.c:2803:12: warning: ‘*((void *)&cval+4)’ is used uninitialized
> in this function [-Wuninitialized]
I can't make sense from "*((void *)&cval+4)". (Is it trying to say
"cval.tab[1]"?)
Only usage of cval is "address of" here:
cstr_cat(&cstr, get_tok_str(t, &cval));
Are you maybe using -O13 or something?
> Declaring cval (two times) close to the places where it is are
> actually used, fixes the warning and does not seem break the
> regression tests
>
>
>
> /* we search the first '##' */
>
> for(ptr = macro_str;;) {
>
> CValue cval;
>
> TOK_GET(&t, &ptr, &cval);
>
> …
>
>
>
> if (t && t != TOK_TWOSHARPS) {
>
> CValue cval;
>
> TOK_GET(&t, &ptr, &cval);
>
Which doesn't make neither "cval" any more initialized !?!
Maybe just a case of acute GCC warning hysteria. In fact I see lots of
warnings (with some gcc versions) that apparently you don't see. I pass some
--extra-cflags.
--- grischka
_______________________________________________
Tinycc-devel mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/tinycc-devel