Hi; I happened across this issue while trying to build SQLite. I've attached a test case. To summarise: * Start off with a function pointer, correctly assigned to a function that has attributes, but cast to a void* (or indeed anything except the correct function pointer type) * Cast this void* to the correct function pointer type, and call it * Observe that one cast+call syntax works correctly, and another results in a misparse: * tcc thinks the type of the entire expression (cast+call) is a pointer, instead of the correct return type of the called function (here, an integer). * gcc happily accepts both syntaxes * This breaks compilation of the sqlite.c amalgamation, at least on 32-bit windows
The failing syntax is perhaps unusual. It might actually be deliberately unsupported, but in that case: * sqlite will not build without modifications * tcc should stop here with an error instead of erroneously treating the expression as a pointer Hope someone can take a look at this. It can be worked around with some modifications to sqlite.
#include <stdio.h> // stdcall is not important, can be any attribute #define ATTR __attribute__((__stdcall__)) // problem does not occur if there are no attributes // #define ATTR int ATTR actual_function() { return 42; } void* function_pointer; int main() { function_pointer = &actual_function; // compiles correctly int a = ((ATTR int(*) (void)) function_pointer)(); // => 42 printf("%i\n", a); // tcc thinks the result of this expression is a pointer // "warning: assignment makes integer from pointer without a cast" int b = ( (int(ATTR *)(void)) function_pointer)(); // compilation continues, but binary // crashes at runtime before it reaches this line printf("%i\n", b); return 0; }
_______________________________________________ Tinycc-devel mailing list Tinycc-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/tinycc-devel