74 Commits

Author SHA1 Message Date
Timm Baeder
642e84f001
[clang][bytecode][NFC] Only get expr when checking for UB (#125397)
The Expr and its Type were unused otherwise.
2025-02-02 12:25:08 +01:00
Timm Baeder
06130ed341
Reapply "[clang][bytecode] Stack-allocate bottom function frame" (#12… (#125349)
…5325)

Move the BottomFrame to InterpState instead.
2025-02-01 18:12:35 +01:00
Jorge Gorbe Moya
386af4a5c6
Revert "[clang][bytecode] Stack-allocate bottom function frame" (#125325)
Reverts llvm/llvm-project#125253

It introduced an msan failure. Caught by a buildbot here:
https://lab.llvm.org/buildbot/#/builders/164/builds/6922/steps/17/logs/stdio
2025-01-31 20:09:14 -08:00
Timm Baeder
f3549814f8
[clang][bytecode] Stack-allocate bottom function frame (#125253)
Instead of heap-allocating it. This is similar to what the current
interpeter does. In C, we have no function calls, so the extra heap
allocation never makes sense.
2025-01-31 20:08:58 +01:00
Timm Baeder
e8674af6f4
[clang][bytecode] Diagnose IntegralToPointer casts to non-void (#123619)
But keep evaluating. This is what the current interpreter does as well.
2025-01-20 17:41:18 +01:00
Timm Baeder
b5c9cba3f3
[clang][bytecode] Don't memcpy() FixedPoint values (#123599)
llvm::FixedPoint is not trivially copyable.
2025-01-20 15:10:12 +01:00
Timm Baeder
046b064df0
[clang][bytecode][NFC] Use FixedPoint opaque int API (#123522)
Now that we have it, use it.
2025-01-20 08:44:59 +01:00
Timm Baeder
cfe26358e3
Reapply "[clang] Avoid re-evaluating field bitwidth" (#122289) 2025-01-11 07:12:37 +01:00
Timm Bäder
59bdea24b0 Revert "[clang] Avoid re-evaluating field bitwidth (#117732)"
This reverts commit 81fc3add1e627c23b7270fe2739cdacc09063e54.

This breaks some LLDB tests, e.g.
SymbolFile/DWARF/x86/no_unique_address-with-bitfields.cpp:

lldb: ../llvm-project/clang/lib/AST/Decl.cpp:4604: unsigned int clang::FieldDecl::getBitWidthValue() const: Assertion `isa<ConstantExpr>(getBitWidth())' failed.
2025-01-08 15:09:52 +01:00
Timm Baeder
81fc3add1e
[clang] Avoid re-evaluating field bitwidth (#117732)
Save the bitwidth value as a `ConstantExpr` with the value set. Remove
the `ASTContext` parameter from `getBitWidthValue()`, so the latter
simply returns the value from the `ConstantExpr` instead of
constant-evaluating the bitwidth expression every time it is called.
2025-01-08 14:45:19 +01:00
Timm Baeder
e86b68ff56
[clang][bytecode] Add support for typeid pointers (#121251)
Add it as another kind of pointer, saving both a `Type*` for the result
of the typeid() expression as well as one for the type of the typeid
expression.
2024-12-28 14:07:01 +01:00
Timm Baeder
56fd46edb3
[clang][bytecode] Remove a bitcast nullptr_t special case (#120188)
We still need to check the input pointer, so let this go through
BitCastPrim.
2024-12-17 13:23:14 +01:00
Timm Baeder
056cd12284
[clang][bytecode] Don't check returned pointers for liveness (#120107)
We're supposed to let them through and then later diagnose reading from
them, but returning dead pointers is fine.
2024-12-17 06:20:14 +01:00
Timm Bäder
2503a66596 Reapply "[clang][bytecode] Fix some shift edge cases (#119895)"
This reverts commit a6636ce4d124176856c3913d4bf6c3ceff1f5a1f.

This original commit failed on hosts with signed wchar_t. Care for
this in the test.
2024-12-16 10:01:46 +01:00
Timm Bäder
a6636ce4d1 Revert "[clang][bytecode] Fix some shift edge cases (#119895)"
This reverts commit 49c2207f21c0922aedb6c70471f8ea068977eb30.

This breaks on big-endian, again:
https://lab.llvm.org/buildbot/#/builders/154/builds/9018
2024-12-14 06:28:12 +01:00
Timm Baeder
49c2207f21
[clang][bytecode] Fix some shift edge cases (#119895)
Around shifting negative values.
2024-12-14 06:15:56 +01:00
Timm Baeder
1fbbf4c418
[clang][bytecode] Pass (float) BitWidth to DoBitCast (#119119)
In certain cases (i.e. long double on x86), the bit with we get from the
floating point semantics is different than the type size we compute for
the BitCast instruction. Pass this along to DoBitCast, so in there we
can check only the relevant bits for being initialized.

This also fixes a weirdness we still had in DoBitCast.
2024-12-08 18:54:08 +01:00
Timm Baeder
44be794658
[clang][bytecode] Not all null pointers are 0 (#118601)
Get the Value from the ASTContext instead.
2024-12-05 06:03:50 +01:00
Timm Baeder
82ed9c0319
[clang][bytecode][NFC] Remove APValue Result argument where unnecessary (#118199)
This is unneeded in almost all circumstances. We only return an APValue
back to clang when the evaluation is finished, and that is always done
by an EvalEmitter - which has its own implementation of the Ret
instructions.
2024-12-01 17:36:19 +01:00
Timm Baeder
1425fa915d
[clang][bytecode] Check FromPtr in BitCastPtr (#117142) 2024-11-21 13:21:00 +01:00
Timm Baeder
2588b8be56
[clang][bytecode] Implement bitcasts to composite types (#114776)
Only fixed-size, non-bitfield integral fields for now.
2024-11-04 15:10:10 +01:00
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