On 7/30/24 15:26, Jonathan M. Wilbur wrote:
Hello,

I pushed a commit (c85eface68940368f696807e97ac7d707e8a73eb) that treats undefined macro invocations as undefined. Previously, if "WUMBO" were undefined, a macro invocation such as "WUMBO(O_RDONLY)" would evaluate to "0(0)" and the compiler would report this as a syntax error. Now, any undefined macro invocation (with parameters) will just evaluated to 0 and the parameters will be ignored.

I created this changed based on a real-world need: nolibc (included with the Linux kernel source) makes use of the __has_attribute macro, which seems to be built-in to GCC, but was defined in such a way in nolibc where it would not be defined everywhere it was used. This meant that compiling nolibc with TinyCC would treat __has_attribute as 0 and its parameters as (0), as described above.

You could argue that this is undesirable behavior. I didn't know I could just push right to the mob branch, so I was expecting a little more debate and review before submitting.

The patch is attached.

Some comments:

You probably did not run 'make test'.

Tests should go into 'tests/tests2' directory.

If I compile the 'tests/undef_func_macro.c' code with gcc I get:

tests/undef_func_macro.c: In function 'main':
tests/undef_func_macro.c:4:12: error: missing binary operator before token "("
    4 | #if WUMBOED(WUMBO)
      |            ^
tests/undef_func_macro.c:8:43: error: missing binary operator before token "("
    8 | #if WUMBO && defined(WUMBOLOGY) || WUMBOED(WUMBO) && !WUMBOLOGY
      |                                           ^
tests/undef_func_macro.c:10:45: error: missing binary operator before token "("
   10 | #elif WUMBO && defined(WUMBOLOGY) || WUMBOED(WUMBO) && !WUMBOLOGY
      |

So gcc does not support this.

Looks like you have to revert the patch.
_______________________________________________
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

Reply via email to