tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tinycc-devel] [Patch] Implement __has_* operators


From: Alvarito050506
Subject: [Tinycc-devel] [Patch] Implement __has_* operators
Date: Wed, 11 Aug 2021 14:20:44 -0300

Hello,

In a previous thread [1], it was discussed the possibility to
implement __has_attribute/builtin (GCC, Clang) and
__has_feature/extension (Clang only), since it's a relatively
standardized way to check for features that are implemented by some
modern compilers. This patch implements them trying to respect their
behavior in GCC/Clang [2][3][4]:
 + `#ifdef __has_*` and `defined(__has_*)` are evaluated to 1.
 + `#if __has_*(operand)` is evaluated to 1 if `operand` is
implemented, and to 0 otherwise.
 + `#if __has_*` is invalid.
 + `__has_builtin` detects only builtin "pseudo-functions", not macros.
 + `__has_*` is not expanded in any other context.

The main difference is in __has_feature/extension, since Clang has
multiple profiles, but TCC has only one, so passing any of the
available features as operands to any of these operators will evaluate
to 1. The other difference is that unprefixed feature detection
(`alignas` instead of `c_alignas`, etc.) is not implemented, because
it has been deprecated in Clang a while ago, so it has no real use
nowadays. (This last part could be easily changed though)

About the missing __has_include/next_include, there seems to be a
dummy implementation of the first, and I'm working on a patch to
correctly implement them, but it might take a while because I'm still
trying to familiarize myself with the source code.

The patch isn't great (it abuses macros, for example) so suggestions,
criticism, and feedback in general would be appreciated.

Thanks,
Álvaro.

[1]: https://lists.nongnu.org/archive/html/tinycc-devel/2021-08/msg00008.html
[2]: https://gcc.gnu.org/onlinedocs/cpp/_005f_005fhas_005fattribute.html
[3]: https://gcc.gnu.org/onlinedocs/cpp/_005f_005fhas_005fbuiltin.html
[4]: https://clang.llvm.org/docs/LanguageExtensions.html

Attachment: tcc_has_00.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]