Commit Graph

292 Commits

Author SHA1 Message Date
Timm Baeder
20506a0a15 [clang][bytecode] Fix operator new source expression (#126870)
... for composite element types. Looks like I forgot this in
e6030d3895
2025-02-12 10:05:49 +01:00
Timm Baeder
9387fd9631 [clang][bytecode] Fix diagnosing replaceable global allocator functions (#126717)
Don't return true here in InvalidNewDeleteExpr just because we are in
C++26 mode. This invalid there as well.

Testcase reduced from
libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.create/make_unique_for_overwrite.pass.cpp
2025-02-11 16:51:21 +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
Kazu Hirata
2fee5ef235 [ByteCode] Avoid repeated hash lookups (NFC) (#126379) 2025-02-08 11:35:45 -08: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
16c721f2d1 [clang][bytecode] Destroy local variables in reverse order (#125727)
See the attached test case.
2025-02-05 08:09:13 +01:00
Timm Baeder
e90f9b4027 [clang][bytecode] Print desriptor PrimType in dump() (#125726) 2025-02-05 08:04:59 +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
f7f3dfce3d [clang][bytecode] Refactor Program::createGlobalString (#125467)
Remove unnecesary narrow() calls, rename a variable and initialize the
array as a whole instead of each element individually.
2025-02-03 09:42:12 +01:00
Timm Baeder
c475356603 [clang][bytecode][NFC] Only call getSource() when necessary (#125419) 2025-02-03 08:51:30 +01:00
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
cf893baf02 [clang][bytecode][NFC] Add a FunctionKind enum (#125391)
Some function types are special to us, so add an enum and determinte the
function kind once when creating the function, instead of looking at the
Decl every time we need the information.
2025-02-02 12:09:30 +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
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
6b8d076b1f [clang][bytecode] Return failure for dead non-temporary pointers (#125247)
... even when we're not performing a lvalue-to-rvalue conversion.
2025-01-31 20:06:29 +01:00
Timm Baeder
46befd7209 [clang][bytecode][NFC] Remove unused function (#125201)
... and an unused include.
2025-01-31 15:03:15 +01:00
Timm Baeder
3c8dfce3de [clang][bytecode][NFC] Use RetPC in InterpFrame::getExpr() as well (#125200)
Both getLocation() and getRange() use the RetPC if the current function
doesn't have a usable body. Using PC here was just a typo.
2025-01-31 12:54:42 +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
a34a087fc5 [clang][bytecode] Handle non-primitive vector element types (#124926)
By rejecting them. We would crash before.
2025-01-29 16:39:02 +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
2c934dc5e1 [clang][bytecode] Always compile most recent function decl (#124722) 2025-01-28 11:43:02 +01:00
Timm Baeder
e6030d3895 [clang][bytecode] Use std::allocator calls for Descriptor source (#123900)
... for the dynamic blocks created for operator new calls. This way we
get the type of memory allocated right. As a side-effect, the
diagnostics now point to the std::allocator calls, which is an
improvement.
2025-01-24 11:50:56 +01:00
Kazu Hirata
b4ef11d0e2 [AST] Migrate away from PointerUnion::dyn_cast (NFC) (#124228)
Note that PointerUnion::dyn_cast has 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>

Literal migration would result in dyn_cast_if_present (see the
definition of PointerUnion::dyn_cast), but this patch uses dyn_cast
because we expect Source to be nonnull.
2025-01-24 01:12:30 -08: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
d70f54f248 [clang][bytecode] Fix reporting failed local constexpr initializers (#123588)
We need to emit the 'initializer of X is not a constant expression' note
for local constexpr variables as well.
2025-01-20 13:25:50 +01:00
Timm Baeder
1be64c27f1 [clang][bytecode] Fix diagnostic mismatch with current interpreter (#123571)
Don't report dead pointers if we've checking for a potential constant
expression.
2025-01-20 10:48:38 +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
Kazu Hirata
80e0cbafba [ByteCode] Migrate away from PointerUnion::dyn_cast (NFC) (#123445)
Note that PointerUnion::dyn_cast has 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>

Literal migration would result in dyn_cast_if_present (see the
definition of PointerUnion::dyn_cast), but this patch uses dyn_cast
because we expect D to be nonnull.
2025-01-18 09:43:17 -08: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
Kazu Hirata
3f07af93dc [AST] Migrate away from PointerUnion::dyn_cast (NFC) (#123283)
Note that PointerUnion::dyn_cast has 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>

Literal migration would result in dyn_cast_if_present (see the
definition of PointerUnion::dyn_cast), but this patch uses dyn_cast
because we expect Source to be nonnull.
2025-01-17 08:46:16 -08: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
Kazu Hirata
2b961b0643 [AST] Migrate away from PointerUnion::dyn_cast (NFC) (#122854)
Note that PointerUnion::dyn_cast has 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>

Literal migration would result in dyn_cast_if_present (see the
definition of PointerUnion::dyn_cast), but this patch uses dyn_cast
because we expect Source to be nonnull.
2025-01-14 15:25:08 -08:00
Timm Bäder
a0bd40e5a3 Revert "[clang][bytecode] Mark global decls with diagnostics invalid (#122895)"
This reverts commit c1de9b9209.

It looks like this breaks the memory-sanitizer builder:
https://lab.llvm.org/buildbot/#/builders/94/builds/3745
2025-01-14 18:37:36 +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
c1de9b9209 [clang][bytecode] Mark global decls with diagnostics invalid (#122895)
Even if their evaluation succeeds, mark them as invalid. This fixes some
long standing differences to the ast walker interpeter.
2025-01-14 15:10:48 +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
cfe26358e3 Reapply "[clang] Avoid re-evaluating field bitwidth" (#122289) 2025-01-11 07:12:37 +01:00