118 Commits

Author SHA1 Message Date
Timm Baeder
3dafa486a6
[clang][bytecode] Don't narrow() when dereferencing to array type (#129524)
It doesn't make sense to do this if the result is supposed to be an
array.
2025-03-03 17:14:54 +01:00
Timm Baeder
a955426a16
[clang][bytecode] Handle UsingDirectiveDecls (#128888)
By ignoring them.
2025-02-26 16:55:15 +01:00
Timm Baeder
3f648992bf
[clang][bytecode] Fix initing incomplete arrays from ImplicitValueIni… (#128729)
…tExpr

If the ImplicitValueInitExpr is of incomplete array type, we ignore it
in its Visit function. This is a special case here, so pull out the
element type and zero the elements.
2025-02-26 08:14:00 +01:00
Timm Baeder
dfa3af9255
[clang][bytecode] Expand subscript base if of pointer type (#128511)
This is similar to what we do in the AddOffset instruction when adding
an offset to a pointer.
2025-02-25 11:40:05 +01:00
Timm Baeder
19a39e98ff
[clang][bytecode] Handle non-primitive array index expressions (#128479)
By rejecting them instead of asserting in `classifyPrim()`.
2025-02-24 09:36:48 +01:00
Timm Baeder
97ed2019c4
[clang][bytecode] Use ExtendingDecl mechanism for primitives as well (#128141)
... when creating the temporary variables for a
MaterializeTemporaryExpr.
2025-02-21 09:47:08 +01:00
Timm Baeder
43e83b9405
[clang][bytecode] Fix allocating primitive arrays of unknown bound (#127788) 2025-02-19 14:29:52 +01:00
Timm Baeder
5fbb6d919d
[clang][bytecode] Allow up/down casts of nullptr (#127615)
If the target type is a pointer type.
2025-02-18 14:43:35 +01:00
Timm Baeder
f09fd94d6b
[clang][bytecode] Restructure Program::CurrentDeclaration handling (#127456)
Properly reset to the last ID and return the current ID from
getCurrentDecl().
2025-02-17 11:24:43 +01:00
Timm Baeder
36f8c8b438
[clang][bytecode] Fix rejecting non-constexpr array ctors (#127448)
We shouldn't abort here when compiling, this is happening (and properly
diagnosed) when interpreting the bytecode.
2025-02-17 08:06:12 +01:00
Timm Baeder
c3cae9d6fc
[clang][bytecode] Fix const-ness of local primitive temporary (#127405)
This used to cause certain std::range tests in libc++ to be diagnosed as
modifying a const-qualified field, because we set the IsConst flag to
true unconditionally. Check the type instead.
2025-02-17 06:24:30 +01:00
Timm Baeder
1aa48af1f8
[clang][bytecode][NFC] Discard all CastExprs uniformly (#126511) 2025-02-10 15:11:01 +01:00
Timm Baeder
199c791a1d
[clang][bytecode] Support partial initializers for CXXNewExprs (#126494)
For `new A[N]{1,2,3}`, we need to allocate N elements of type A, and
initialize the first three with the given InitListExpr elements.
However, if N is larger than 3, we need to initialize the remaining
elements with the InitListExpr array filler.

Similarly, for `new A[N];`, we need to initilize all fields with the
constructor of A. The initializer type is a CXXConstructExpr of
IncompleteArrayType in this case, which we can't generally handle.
2025-02-10 14:28:40 +01:00
Timm Baeder
a69975d834
[clang][bytecode] Remove unnecessary if statement (#126223)
This doesn't seem to do any good and breaks a few libc++ tests. Remove
the special case.
2025-02-07 14:24:15 +01:00
Timm Baeder
7ef636e1c4
[clang][bytecode] Mark IndirectFieldDecl chain links as initialized (#125869)
We only initialize the final field above, so make sure we're marking the
links in the chain on the way there as initialized as well.
2025-02-05 17:50:55 +01:00
Timm Baeder
ee25a85ccc
[clang][bytecode] Handle CXXPseudoDestructorExprs (#125835)
Make lifetime management more explicit. We're only using this for
CXXPseudoDestructorExprs for now but we need this to handle
std::construct_at/placement-new after destructor calls later anyway.
2025-02-05 12:40:30 +01:00
Timm Baeder
707e2b83a5
[clang][bytecode] Handle union move assignment operators as well (#125516) 2025-02-03 17:43:32 +01:00
Timm Baeder
21a8c920fe
[clang][bytecode] Add special handling for union copy assign operators (#125476) 2025-02-03 12:41:49 +01:00
Timm Baeder
00bdce1c37
[clang][bytecode] Ignore Namespace{Using,Alias}Decls (#125387)
These were missing here and are used in a few libc++ tests.
2025-02-02 10:43:15 +01:00
Timm Baeder
d2d8e2e030
[clang][bytecode] Handle invalid temporary descriptors (#125033)
This happens e.g. when a vector element type is not primitive.
2025-01-31 08:53:31 +01:00
Timm Baeder
51c7338cc6
[clang][bytecode] Fix dummy handling for p2280r4 (#124396)
This makes some other problems show up like the fact that we didn't
suppress diagnostics during __builtin_constant_p evaluation.
2025-01-29 09:32:35 +01:00
Timm Baeder
6972788bf3
[clang][bytecode] Fix discarding DerivedToBase casts (#123523) 2025-01-20 08:55:54 +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
0ab1f5772c
[clang][bytecode] Register decomposition holding vars (#123515) 2025-01-19 16:29:56 +01:00
Timm Baeder
90696d17f2
[clang][bytecode][NFC] Simplify visitDeclRef (#123380)
Try to reduce indentation here.
2025-01-18 06:18:46 +01:00
Timm Baeder
c7ea4c18af
[clang][bytecode] Revisit global variables separately (#123358)
Call `EvaluateAsInitializer()` explicitly here, so we don't abort the
evaluation of the `DeflRefExpr` just because the initializer of that
global variable failed.
2025-01-17 18:55:24 +01:00
Timm Baeder
0171e56ed0
[clang][bytecode] Fix rejecting invalid sizeof expressions (#123332)
Emit the invalid note instead of nothing.
2025-01-17 15:14:47 +01:00
Timm Baeder
7075eee6bd
[clang][bytecode] Add InitLinkScope for toplevel Expr temporary (#123319) 2025-01-17 12:58:15 +01:00
Timm Baeder
4cec0ba929
[clang][bytecode][NFC] Simplify VisitCXXDefaultArgExpr (#123024)
We have `discard()` these days.
2025-01-15 10:09:10 +01:00
Timm Baeder
d1d25641f4
[clang][bytecode] Handle UETT_PtrAuthTypeDiscriminator (#122941) 2025-01-15 08:41:20 +01:00
Timm Baeder
58fa55c04b
[clang][bytecode] Add init link for the RVO ptr (#122904) 2025-01-14 17:18:04 +01:00
Timm Baeder
ac857f9bdd
[clang][bytecode] Change the way we do init chains (#122871)
See the comment in Compiler<>::VisitCXXThisExpr.
We need to mark the InitList explicitly, so we later know what to refer
to when the init chain is active.
2025-01-14 10:57:36 +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
acb7dfaa01
[clang][bytecode] Create local scopes for if then/else statements (#120852)
In case those aren't compound statements.
2024-12-22 08:04:49 +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
2f9cd43a73
[clang][bytecode] Check primitive bit casts for indeterminate bits (#118954)
Record bits ranges of initialized bits and check them in
allInitialized().
2024-12-06 15:50:59 +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
7802fb5f51
[clang][bytecode] Fix __extension__ handling for vector operators (#118482)
Don't reject them, but delegate to the subexpression.
2024-12-03 14:48:55 +01:00
Timm Baeder
ff0babc917
[clang][bytecode] Fix discarded pointer subtractions (#118477)
We need to pop the value.
2024-12-03 14:34:32 +01:00
Timm Baeder
541d5d9111
[clang][bytecode][NFC] Reject invalid FromTypes in emitBuiltinBitcast (#118274)
instead of silently accepting them and failing later.
2024-12-02 11:12:20 +01:00
Timm Baeder
dd0d9561b8
[clang][bytecode] Support vector-to-vector bitcasts (#118230) 2024-12-02 08:20:41 +01:00
Timm Baeder
6f16a8bf17
[clang][bytecode] Use bitcasts to cast from integer to vector (#117547)
In C, a cast from an integer to a vector is a CK_BitCast. Implement this
using the same code we use for __builtin_bit_cast.
2024-11-25 14:51:26 +01:00
Timm Baeder
ceaf6e912a
[clang][bytecode] Support ImplicitValueInitExpr for multi-dim arrays (#117312)
The attached test case from
https://github.com/llvm/llvm-project/issues/117294 used to cause an
assertion because we called classifPrim() on an array type.

The new result doesn't crash but isn't exactly perfect either. Since the
problem arises when evaluating an ImplicitValueInitExpr, we have no
proper source location to point to. Point to the caller instead.
2024-11-25 12:15:31 +01:00
Kazu Hirata
63d9ef5e37
[AST] Migrate away from PointerUnion::{is,get} (NFC) (#117469)
Note that PointerUnion::{is,get} have been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //        isa<T>, cast<T> and the llvm::dyn_cast<T>

I'm not touching PointerUnion::dyn_cast for now because it's a bit
complicated; we could blindly migrate it to dyn_cast_if_present, but
we should probably use dyn_cast when the operand is known to be
non-null.
2024-11-24 07:28:20 -08:00
Timm Baeder
5f84b332ec
[clang][bytecode] Fix discarding __builtin_bit_cast calls (#114926)
Optionally prepare storage for the result and do the bitcast anyway, to
get the right diagnostic output.
2024-11-05 11:05:23 +01:00
Timm Baeder
2f13fbfcd1
[clang][bytecode] Support bitcasting into float fields (#114825) 2024-11-05 05:52:03 +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
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
9ae41c24b3
[clang][bytecode] Create dummy pointers for non-reference DeclRefExprs (#113202)
... with non-constant initializers.
2024-10-22 10:38:13 +02: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