26 Commits

Author SHA1 Message Date
Congcong Cai
cbdd14ee9d
[clang][NFC]add static for internal linkage function (#117482)
Detected by misc-use-internal-linkage
2024-11-25 06:48:33 +08:00
Timm Baeder
8951b51402
[clang][bytecode] Add more checks to _ai32_* builtins (#114412)
They are called in a few different forms that we don't support.
2024-11-01 14:19:59 +01:00
Timm Baeder
ef2a104c94
[clang][bytecode] Start implementing __builtin_bit_cast (#112126)
This is a subset of #68288, with hopefully narrower scope. It does not
support bitcasting to non-integral types yet.
Bitfields are supported, but only if they result in a full byte-sized
final buffer. It does not support casting from null-pointers yet or
casting from indeterminate bits.


The tests are from #68288 and partially from #74775.

The `BitcastBuffer` struct is currently always working in single bits,
but I plan to (try to) optimize this for the common full-byte case.
2024-10-31 18:09:40 +01:00
Timm Baeder
b46a0482f9
[clang][bytecode] Implement __builtin_arithmetic_fence (#113937) 2024-10-29 00:56:03 +01:00
Timm Baeder
615a5eb02c
[clang][bytecode] Check ai32_bextr builtins for integer args (#113128) 2024-10-21 08:15:51 +02:00
Timm Baeder
5405ba50de
[clang][bytecode] Check ia32_{pext,pdep} builtins for integer args (#113091) 2024-10-20 19:37:41 +02:00
c8ef
332ac18e31
[clang] constexpr built-in abs function. (#112539)
According to [P0533R9](https://wg21.link/P0533R9), the C++ standard
library functions corresponding to the C macros in `[c.math.abs]` are
now `constexpr`.

To implement this feature in libc++, we must make the built-in abs
function `constexpr`. This patch adds the implementation of a
`constexpr` abs function for the current constant evaluator and the new
bytecode interpreter.

It is important to note that in 2's complement systems, the absolute
value of the most negative value is out of range. In gcc, it will result
in an out-of-range error and will not be evaluated as constants. We
follow the same approach here.
2024-10-18 19:03:50 +08:00
Timm Baeder
790d986946
[clang][bytecode] Implement __builtin_f{maximum,minimum}_num (#112335) 2024-10-15 12:49:32 +02:00
Timm Baeder
80c15c48d1
[clang][bytecode] Implement __builtin_assume_aligned (#111968) 2024-10-11 11:46:33 +02:00
Timm Baeder
1fd79f105d
[clang][bytecode] Check number of addcarry/subborrow args (#111952)
Apparently this can fail as well.
2024-10-11 08:08:28 +02:00
Timm Baeder
f1eac77617
[clang][bytecode] Check new builtins for integer types (#111801)
These might also be called with vectors, but we don't support that.
2024-10-10 10:23:59 +02:00
Timm Baeder
6f8e855150
[clang][bytecode] Implement __builtin_ai32_addcarryx* (#111671) 2024-10-09 15:42:19 +02:00
Timm Baeder
235067b222
[clang][bytecode] Make sure ia32_bzhi input is an integer (#111505) 2024-10-08 13:30:40 +02:00
Timm Baeder
e1e788f423
[clang][bytecode] Protect ia32_{lzcnt,tzcnt} against non-integers (#110699)
These are also called for vectors.
2024-10-02 05:44:54 +02:00
Timm Baeder
f3baa73c8b
[clang][bytecode] Implement ia32_{pdep,pext} builtins (#110675) 2024-10-01 17:17:37 +02:00
Timm Baeder
7147e88f55
[clang][bytecode] Implement lzcnt/tzcnt/bzhi builtins (#110639) 2024-10-01 12:04:32 +02:00
Timm Baeder
8518178857
[clang][bytecode] Implement ia32_bextr builitns (#110513) 2024-09-30 20:07:28 +02:00
Timm Baeder
a024a0ceed
[clang][bytecode] Override InConstantContext flag for immediate calls (#109967)
And fix the diagnostics for __builtin_is_constant_evaluated(). We can be
in a non-constant context, but calling an immediate function always
makes the context constant for the duration of that call.
2024-09-25 16:46:46 +02:00
Timm Baeder
4b96400240
[clang][bytecode] Allow placement-new in std functions pre-C++26 (#109753) 2024-09-24 10:28:54 +02:00
Timm Baeder
898fd396b8
[clang][bytecode] Check allocation size limit for operator new (#109590) 2024-09-23 09:59:41 +02:00
Timm Baeder
78cf9b830c
[clang][bytecode] Implement using operator new/operator delete (#107679)
Reuse the __builtin_operator_{new,delete} implementations.
2024-09-07 12:17:54 +02:00
Timm Baeder
610b85395d
[clang][bytecode] Implement __builtin_operator{new,delete} (#107672) 2024-09-07 09:57:26 +02:00
Timm Baeder
f838d6b1b2
[clang][bytecode] Implement __noop (#106714)
This does nothing and returns 0.
2024-09-02 13:50:22 +02:00
yronglin
d9e7286019
[NFC][clang][bytecode] Rename clang::interp::State::getCtx to clang::interp::State::getASTContext (#106071)
The new constant interpreter's `clang::interp::InterpState` contains
both `clang::interp::Context` and `clang::ASTContext`. So using `S.Ctx`
and `S.getCtx()` was a bit confusing. This PR rename `getCtx()` to
`getASTContext` to make things more clearer.

Signed-off-by: yronglin <yronglin777@gmail.com>
2024-08-26 22:23:07 +08:00
Mital Ashok
1125934359
[Clang] constexpr builtin floating point classification / comparison functions (#94118)
As per [P0533R9](https://wg21.link/P0533R9), the corresponding C++
`[c.math.fpclass]` standard library functions for the C macros are now
`constexpr`.

The only classification function that wasn't already `constexpr` was
`__builtin_signbit`.
The floating point comparison functions `__builtin_isgreater`,
`__builtin_isgreaterequal`, `__builtin_isless`, `__builtin_islessequal`,
`__builtin_islessgreater` and `__builtin_isunordered` are now
`constexpr`.
The C23 macro `iseqsig` is not currently supported because
`__bulitin_iseqsig` doesn't exist yet (and C++26 is still currently
based on C18).

This also allows them to be constant folded in C, matching the behaviour
of GCC.
2024-08-18 13:50:42 +04:00
Timm Baeder
a07aba5d44
[clang] Rename all AST/Interp stuff to AST/ByteCode (#104552)
"Interp" clashes with the clang interpreter and people often confuse
this.
2024-08-16 17:13:12 +02:00