53 Commits

Author SHA1 Message Date
Timm Baeder
5b32c5954b
[clang][bytecode] Implement bitcasts to floating-point values (#114485) (#114712)
This time I tested on big-endian hosts.
2024-11-03 19:42:26 +01:00
Timm Bäder
c2a892f49a Revert "[clang][bytecode] Implement bitcasts to floating-point values (#114485)"
This reverts commit c752efbdcc1ebd81f879633d6b798248064e2ae2.

This broke bots:
 - https://lab.llvm.org/buildbot/#/builders/13/builds/3268
 - https://lab.llvm.org/buildbot/#/builders/42/builds/1718
2024-11-02 01:54:38 +01:00
Timm Baeder
c752efbdcc
[clang][bytecode] Implement bitcasts to floating-point values (#114485) 2024-11-01 14:58:19 +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
ccb7cc319f
[clang][bytecode] Diagnose negative array sizes differently (#114380)
We have a special diagnostic ID for this.
2024-10-31 10:59:53 +01:00
Timm Baeder
159f253017
[clang][bytecode] Diagnose invalid declrefs differently if we've... (#113140)
... tried their initializer already. In that case, diagnose the
non-const initializer instead of the reference to a non-constexpr
variable later. This is used in a lot of openmp tests.
2024-10-21 12:07:09 +02:00
Timm Baeder
923b8eea64
[clang][bytecode] Allow ArrayElemPtr ops on null pointers (#113132)
This regresses one of the _Complex test cases a bit, but since the
diagnostic output wasn't very good here in the first place, let's ignore
it.
2024-10-21 09:52:07 +02:00
Timm Baeder
3eaf4a9d1a
[clang][bytecode] Check for memory leaks after destroying global scope (#112868)
The global scope we create when evaluating expressions might free some
of the dynamic memory allocations, so we can't check for memory leaks
before destroying it.
2024-10-18 13:03:13 +02:00
Timm Baeder
5d08625347
[clang][bytecode] Activate pointers in Init{,Pop} (#112832) 2024-10-18 07:38:22 +02:00
Timm Baeder
03888a9046
[clang][bytecode] Handle non-arrays in initElem{,Pop} (#112719)
... provided the given index is 0. Skip the atIndex() in that case.
2024-10-17 19:07:47 +02:00
Timm Baeder
f93258e4ac
[clang][bytecode] Diagnose class-specific operator delete calls (#111700) 2024-10-10 08:40:14 +02:00
Timm Baeder
e637a5c9fe
[clang][bytecode] Only allow lossless ptr-to-int casts (#111669)
Only allow those casts if the bitwidth of the two types match.
2024-10-09 17:13:22 +02:00
Timm Baeder
fed8695bb8
[clang][bytecode] Emit better diagnostic for invalid shufflevector index (#111643) 2024-10-09 09:56:37 +02:00
Timm Baeder
55c70f6d89
[clang][bytecode] Check GetPtrBase ops for null pointers (#110673) 2024-10-01 17:09:26 +02:00
Timm Baeder
79382eb97a
[clang][bytecode] Remove superfluous check from fixed-point div (#110478)
We shouldn't do this check for fixed-point values, at least the current
interpreter doesn't do it.
2024-09-30 12:13:21 +02:00
Timm Baeder
6f04e65c3c
[clang][bytecode] Implement fixed-point shifts (#110429) 2024-09-29 20:56:17 +02:00
Timm Baeder
5c811ccc4d
[clang][bytecode] Implement more binary operators for fixed point types (#110423) 2024-09-29 17:36:17 +02:00
Timm Baeder
95ce78b742
[clang][bytecode] Implement fixed-point-to-int casts (#110417)
And some cleanups around overflow handling.
2024-09-29 13:31:44 +02:00
Timm Baeder
1714b11384
[clang][bytcode] Convert Fixed Point values to target semantics... (#110411)
... after a binary operation. The Result of the operation is in the
common semantics of RHS and LHS, so we need to convert that to the
semantics of the BinaryOperator expression.
2024-09-29 10:01:21 +02:00
Timm Baeder
c2a37e41b9
[clang][bytecode] Implement fixed point casts (#110409) 2024-09-29 08:58:21 +02:00
Timm Baeder
3a5b9da115
[clang][bytecode] Implement fixed-point-to-float casts (#110369) 2024-09-28 19:11:49 +02:00
Timm Baeder
6cbd8a3094
[clang][bytecode] Implement floating-to-fixed-point casts (#110361) 2024-09-28 17:24:28 +02:00
Timm Baeder
641b4d5370
[clang][bytecode] Implement integral-to-fixed-point casts (#110350) 2024-09-28 13:10:23 +02:00
Timm Baeder
048bc67276
[clang][bytecode] Start implementing fixed point types (#110216)
Add the primitive type and implement to-bool casts.
2024-09-27 11:32:43 +02:00
Timm Baeder
e1365ce222
[clang][bytecode][NFC] Add type assertions to ArrayElem{,Pop} (#109829)
So we don't accidentally try to use those with the wrong type.
2024-09-25 07:44:05 +02:00
Timm Baeder
c712ab829b
[clang][bytecode] Implement placement-new (#107033)
If we have a placement-new destination already, use that instead of
allocating a new one.
Tests are partially based on
`test/SemaCXX/cxx2c-constexpr-placement-new.cpp`.
2024-09-23 13:26:49 +02:00
Timm Baeder
f86050de73
[clang][bytecode] Don't call checkLiteralType() in visitInitializer() (#109530)
We were calling checkLiteralType() too many time and rejecting some
things we shouldn't. Add The calls manually when handling
MaterializeTemporaryExprs. Maybe we should call it in other places as
well, but adding more calls is easier than removing them from a generic
code path.
2024-09-21 20:01:21 +02:00
Timm Baeder
9a32f28366
[clang][bytecode] Fix a problem with array size limits (#109383)
Descriptor::MaxArrayElemBytes is an unsigned value, which might overflow
the SizeT we have in CheckArraySize.
2024-09-20 11:26:58 +02:00
Timm Baeder
0050503b7a
[clang][bytecode] Allow right-shift of negative values (#108987)
We used to incorrectly diagnose this as a "left shift of negative
value".
2024-09-17 18:25:16 +02:00
Timm Baeder
43fd2c401e
[clang][bytecode] Implement base casts on integral pointers (#108340)
Get the right offset to apply from the RecordLayout.
2024-09-12 17:19:37 +02:00
Timm Bäder
46870175c5 [clang][bytecode][NFC] Fix CallBI function signature
This doesn't modify the PC, so pass OpPC as a copy.
2024-09-10 13:32:25 +02:00
Timm Baeder
d6d60707ec
[clang][bytecode] Fix two-pointer-style std::initializer_lists (#107682)
The first pointer needs to point to the first element of the underlying
array. This requires some changes to how we handle array expansion
2024-09-07 14:27:09 +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
83fea8b809
[clang][bytecode] Allow continuing when discarded MemberExpr Base fails (#107231)
We don't need the value in this case, since we're discarding it anyway.
Allow continuing the interpretation but note the side effect.
2024-09-07 09:33:27 +02:00
Timm Baeder
f70ccdaeb4
[clang][bytecode][NFC] Move Call ops into Interp.cpp (#107104)
They are quite long and not templated.
2024-09-03 16:15:58 +02:00
Timm Baeder
0f5f440f24
[clang][bytecode] Pass FPOptions to floating point ops (#107063)
So we don't have to retrieve them from the InterpFrame, which is slow.
2024-09-03 14:24:11 +02:00
Timm Baeder
6f81c878ec
[clang][bytecode][NFC] Implement MemberPointer::toDiagnosticString() (#106825) 2024-08-31 07:26:02 +02:00
Timm Baeder
360e4abfc8
[clang][bytecode] Diagnose comparisons with literals (#106734)
This requires adding a new opcode for PointerToBoolean casts, since we
otherwise emit too many diagnostics. But that fixes an older problem
when casting weak pointers to bool.
2024-08-31 06:24:36 +02:00
Timm Baeder
df11ee213e
[clang][bytecode] Diagnose member calls on deleted blocks (#106529)
This requires a bit of restructuring of ctor calls when checking for a
potential constant expression.
2024-08-29 15:22:59 +02:00
Timm Baeder
40db261551
[clang][bytecode] Fix #55390 here as well (#106395)
Ignore the multiplication overflow but report the 0 denominator.
2024-08-28 19:09:12 +02:00
Timm Baeder
f7a74ece5a
[clang][bytecode] Diagnose array-to-pointer decays of dummy pointers (#106366)
We have type information for them now, so we can do this.
2024-08-28 13:41:01 +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
Timm Baeder
99b85cae62
[clang][bytecode][NFC] Add an additional assertion (#105927)
Since this must be true, add an assertion instead of just documenting it
via the comment.
2024-08-24 09:23:25 +02:00
Timm Baeder
b9c4c4ccf9
[clang][bytecode] Fix 'if consteval' in non-constant contexts (#104707)
The previous code made this a compile-time decision but it's not.
2024-08-22 19:06:09 +02:00
Timm Baeder
db94852b9b
[clang][bytecode] Allow adding offsets to function pointers (#105641)
Convert them to Pointers, do the offset calculation and then convert
them back to function pointers.
2024-08-22 15:23:50 +02:00
Timm Baeder
a14c730990
[clang][bytecode] Fix diagnostic in final ltor cast (#105292)
Don't diagnose volatile reads but diagnose a few other accesses earlier.
2024-08-21 08:08:32 +02:00
Timm Baeder
ba7dadf0e9
[clang][bytecode] Fix initializing base casts (#104901)
Use delegate() there. To fix a follow-up problem, abort when a cast ends
up on a valid Pointer that isn't a base class.
2024-08-20 11:44:30 +02:00
Timm Baeder
ca148b2150
[clang][bytecode] Support ObjC blocks (#104551)
I started out by adding a new pointer type for blocks, and I was fully
prepared to compile their AST to bytecode and later call them.

... then I found out that the current interpreter doesn't support
calling blocks at all. So we reuse `Function` to support sources other
than `FunctionDecl`s and classify `BlockPointerType` as `PT_FnPtr`.
2024-08-20 06:08:53 +02:00
Timm Bäder
d082f1f37d [clang][bytecode] Only booleans can be inverted
No need to have the Inv() function be templated.
2024-08-18 16:02:32 +02:00