63 Commits

Author SHA1 Message Date
Timm Bäder
ec40097db2 [clang][Interp] Implement __builtin_{ctz,clz}g 2024-04-10 12:27:33 +02:00
Timm Bäder
5143a12413 [clang][Interp] Add __builtin_is_constant_evaluated warnings
Add the same warnings the current interpreter emits.
2024-03-17 18:07:51 +01:00
Timm Bäder
ca876711ae [clang][Interp][NFC] Make local pointer const 2024-03-17 18:07:51 +01:00
Timm Bäder
0a739eb75f [clang][Interp] Implement __builtin___{CF,NS}StringMakeConstantString
By doing the same thing the current interpreter does: Just passing on
the first parameter.
2024-03-15 08:46:13 +01:00
Timm Bäder
65c0143296 [clang][Interp] Fix rotate builtins with differently-typed arguments
We were assuming (and asserting) that both arguments have the same
type, but at least for the ms versions, that's not always the case.
2024-03-14 16:34:07 +01:00
Jie Fu
611d5aec1d [clang] Fix -Wunused-variable in InterpBuiltin.cpp (NFC)
llvm-project/clang/lib/AST/Interp/InterpBuiltin.cpp:1332:21:
error: unused variable 'SrcDesc' [-Werror,-Wunused-variable]
  const Descriptor *SrcDesc = Src.getFieldDesc();
                    ^
1 error generated.
2024-03-14 21:55:23 +08:00
Timm Bäder
b97c12936d [clang][Interp] Fix non-primitive ltor casts
This doesn't happen in C++ since it will instead call the
struct's copy constructor. However, in C, this needs to work.
2024-03-14 13:55:55 +01:00
OverMighty
e95040f0f0
[clang][Interp] Implement __builtin_popcountg (#84500)
The previous code would truncate IntegerAPs wider than 64 bits.
2024-03-10 06:54:03 +01:00
Timm Bäder
89e41e2965 [clang][Interp] Implement __builtin_complex 2024-03-04 17:15:42 +01:00
Timm Bäder
f25debe58b [clang][Interp][NFC] Remove some leftover debug output 2024-03-02 18:56:43 +01:00
Timm Bäder
dfb8a1531c [clang][Interp][NFC] Make a local variable const 2024-03-02 18:56:35 +01:00
Timm Bäder
b901b0d3ed [clang][Interp] Reject dummy pointers from __builtin_strcmp()
We can't load anything from them, so reject them here.
2024-03-02 18:28:51 +01:00
Timm Bäder
a30ba2ca21 [clang][Interp][NFC] Emit diagnostic for unknown builtins
Instead of just returning false.
2024-03-02 18:28:12 +01:00
Timm Bäder
a28a7d41ef [clang][Interp][NFC] Remove leftover comments 2024-02-27 14:15:22 +01:00
Timm Bäder
78275ef0a3 [clang][Interp] Pick the right APInt constructor on Windows
The second parameter needs to be a uint64_t and nothing else.
This broke windows builders, see
264d828ea6
2024-02-26 18:23:41 +01:00
Timm Bäder
264d828ea6 [clang][Interp][NFC] Redo returning values from builtin functions
Instead of having retInt/retLong/retSizeT/etc., just add retInteger,
which takes an APSInt and returns it in form of the given QualType.
This makes the code a little neater, but is also necessary since
some builtins have a different return type with -fms-extensions.
2024-02-26 16:46:23 +01:00
Timm Bäder
a35599b9ae [clang][Interp] Implement a few _is_lock_free builtins
Implementation looks similar to the one in the current interpreter.
Except for three static assertions, test/Sema/atomic-ops.c works.
2024-02-26 13:56:37 +01:00
Timm Bäder
b3e4686af3 [clang][Interp] Implement __builtin_{ctz,clz,bswap} 2024-02-20 11:55:20 +01:00
Timm Bäder
7f45acfbfe [clang][Interp] Implement various overflow and carry builtins
Enough so we can enable SemaCXX/builtin-overflow.cpp.
2024-02-16 19:00:40 +01:00
Timm Bäder
67282077ea [clang][Interp] Implement __builtin_launder
Just forward the pointer.
Copy tests from SemaCXX
2024-02-16 08:08:42 +01:00
Timm Bäder
5d8a7318b2 [clang][Interp] Support __builtin_eh_return_data_regno 2024-02-07 15:29:43 +01:00
Timm Bäder
66cd768504 [clang][Interp] Handle __assume like __builtin_assume. 2024-02-05 17:33:08 +01:00
Timm Baeder
47df391296
[clang][Interp] Handle std::move etc. builtins (#70772) 2024-01-31 15:57:23 +01:00
Timm Baeder
e3993e044e
[clang][Interp] Implement __builtin_addressof (#77303)
We don't need to do anything here, since the input is already a Pointer.
The only complexity is that we pre-classify the parameters as PT_Ptr,
but they might end up being of a different pointer type, e.g. PT_FnPtr.
2024-01-11 09:02:24 +01:00
Timm Baeder
d9671bba3e
[clang][Interp] Implement __builtin_ffs (#72988) 2023-12-12 15:59:39 +01:00
Timm Baeder
43e6aec145
[clang][Interp] Implement __builtin_rotate{right,left} (#72984) 2023-12-12 10:48:00 +01:00
Timm Baeder
d5e2cbd01a
[clang][Interp] Implement builtin_expect (#69713) 2023-12-08 14:46:25 +01:00
Timm Baeder
965d301dff
[clang][Interp] Implement __builtin_classify_type (#71972)
This adds some infrastructure for unevaluated builtin calls, and uses the implementation from ExprConstant.cpp
2023-11-17 16:13:23 +01:00
Timm Baeder
3defe8facc
[clang][Interp] Implement __builtin_bitreverse (#71687)
Since the return value of this function is slightly more involved than
the void/bool/int/size_t return values we've seen so far, also refactor
this.
2023-11-17 08:29:13 +01:00
Timm Baeder
bffa8e1d1a
[clang][Interp] Implement __builtin_clrsb (#72243) 2023-11-16 07:30:54 +01:00
Timm Baeder
0f8c51a523
[clang][Interp] Implement __builtin_parity (#71662) 2023-11-16 06:24:04 +01:00
Serge Pavlov
fc7198b799
[clang] Additional FP classification functions (#69041)
C language standard defined library functions `iszero`, `issignaling`
and `issubnormal`, which did not have counterparts among clang builtin
functions. This change adds new functions:

    __builtin_iszero
    __builtin_issubnormal
    __builtin_issignaling

They provide builtin implementation for the missing standard functions.

Pull request: https://github.com/llvm/llvm-project/pull/69041
2023-11-01 12:10:54 +07:00
Timm Baeder
7f677fe310
[clang][Interp] Add explicit dummy descriptors (#68888)
Instead of (ab)using incomplete array types for this, add a 'Dummy' bit
to Descriptor. We need to be able to differentiate between the two when
adding an offset.
2023-10-26 15:15:25 +02:00
Timm Baeder
26d9f851cf
[clang][Interp] Add basic support for _BitInt (#68069)
Make sure we pass the expected bitwidth around when casting to
IntAP/IntAPS.

This makes it easier to test the `IntegralAP` code for different bit
widths than 128.
2023-10-11 08:53:21 +02:00
Timm Baeder
9aedb60c70
[clang][Interp] Implement __builtin_popcount() (#67929) 2023-10-02 17:14:31 +02:00
Timm Baeder
512739ebbb
[clang][Interp] Three-way comparisons (#65901) 2023-09-29 09:41:58 +02:00
Timm Bäder
87461d6696 [clang][Interp] Implement __builtin_offsetof
Differential Revision: https://reviews.llvm.org/D156400
2023-09-11 12:03:47 +02:00
Timm Bäder
673ef8ceae Re-land "[clang][Interp] Make sure we push integers of the correct size"
This also re-reverts the commit implementing __builtin_strlen.

I was unable to reproduce the msan issue with an msan-enabled build (for
infrastructure reasons), but I think fixing the target-dependent int
sizes in the implementation of __builtin_fpclassify should work.
2023-08-18 10:25:54 +02:00
Vitaly Buka
e03686f4a3 Revert "[clang][Interp] Make sure we push integers of the correct size"
Revert "[clang][Interp] Implement __builtin_strlen"

Fails Msan. Details in https://reviews.llvm.org/D155568

This reverts commit d425720aed48fd2c058a126ac961576d48c9732b.
This reverts commit 91af0d0a669880918eda2d2bd2d6185b2903a402.
2023-08-17 18:12:02 -07:00
Timm Bäder
d425720aed [clang][Interp] Implement __builtin_strlen
Differential Revision: https://reviews.llvm.org/D156042
2023-08-17 13:10:46 +02:00
Timm Bäder
91af0d0a66 [clang][Interp] Make sure we push integers of the correct size
Integers might not be 32 bits wide, so check the TargetInfo for their
size.

Differential Revision: https://reviews.llvm.org/D155568
2023-08-17 10:36:06 +02:00
Timm Bäder
8a25145058 [clang][Interp] Pass CallExpr to builtin functions
For some builtins, we need to do quite a bit of type checking ourselves,
so pass the call expression along. This way we can inspect arguments,
expected return value, etc.

Differential Revision: https://reviews.llvm.org/D155545
2023-08-17 10:20:58 +02:00
Timm Bäder
89e44e33ed [clang][Interp] Implement __builtin_fmax
Differential Revision: https://reviews.llvm.org/D155401
2023-08-01 17:45:24 +02:00
Timm Bäder
1684406e63 [clang][Interp] Implement __builtin_fabs()
Differential Revision: https://reviews.llvm.org/D155400
2023-08-01 16:32:29 +02:00
Timm Bäder
5821351343 [clang][Interp] Implement __builtin_fpclassify
Differential Revision: https://reviews.llvm.org/D155394
2023-08-01 16:02:15 +02:00
Timm Bäder
6ba4b21334 [clang][Interp] Implement __builtin_isfpclass 2023-08-01 15:25:22 +02:00
Timm Bäder
d37f1e9965 [clang][Interp] Implement __builtin_isnormal
Differential Revision: https://reviews.llvm.org/D155374
2023-07-31 09:14:16 +02:00
Timm Bäder
f444f39686 [clang][Interp] Implement __builtin_isfinite
Differential Revision: https://reviews.llvm.org/D155372
2023-07-31 09:12:32 +02:00
Timm Bäder
72450a7793 [clang][Interp] Implement __builtin_isinf
Differential Revision: https://reviews.llvm.org/D155371
2023-07-31 08:49:22 +02:00
Timm Bäder
ff80fc0ea2 [clang][Interp] Implement __builtin_isnan()
The previous version was using llvm::reverse(CallExpr::arguments()),
which causes problems when clang is compiled with GCC.

Differential Revision: https://reviews.llvm.org/D155369
2023-07-29 10:48:10 +02:00