Re: [Tinycc-devel] [PATCH] tcc: remove buggy nodata_wanted optimization
Hi, On Thu, 22 Feb 2018, grischka wrote: However NODATA_WANTED does more than that, for example it also suppresses the "hello" with if (0) puts("hello"); Therefor I'd suggest a less radical change, such as: @@ -6916,7 +6916,7 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, align = 1; } -if (NODATA_WANTED) +if (!v && NODATA_WANTED) size = 0, align = 1; if ((r & VT_VALMASK) == VT_LOCAL) { Thus variable space will be allocated always but initializers are still suppressed. (Bypassing initializers with goto is not allowed). For statics it is. E.g. the following program is valid and must print 42: #include int main() { goto doit; if (0) { static int a = 42; doit: printf ("%d\n", a); } } But the idea of supressing only nameless entities is a good one I think. Ciao, Michael. ___ Tinycc-devel mailing list Tinycc-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/tinycc-devel
Re: [Tinycc-devel] [PATCH] tcc: remove buggy nodata_wanted optimization
Hi, On Thu, 22 Feb 2018, Mikulas Patocka wrote: > I think that that nodata_wanted misoptimization should be removed at all > - in the C language, you can jump to any location in the function with > goto or switch-case statement - thus reasoning such as "all the > variables behind if (0) are unreachable" is incorrect. > > If you wanted to do that optimization correctly, you'd need to build > control flow graph, and tcc is just too simple to do that. You're right that as implemented the non-allocation of variables is wrong. But a full CFG isn't needed to fix this, the allocation merely needs to be postponed to the first real use. Unfortunately that is somewhat complicated when there are initializers (which matter only for static vars in this case, but still). So, yeah, the easy fix is to remove it, but with more work the optimization (or parts of it) could be retained, grischka? Ciao, Michael. ___ Tinycc-devel mailing list Tinycc-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/tinycc-devel