268 Commits

Author SHA1 Message Date
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 c1de9b920935e7d2fcc8dd7b39c1b7285783e948.

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
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
Chandler Carruth
dc3cd2e95e
Factor common code for quoting a builtin name (#120835)
This shows up in several places in order to match the quoting of other
uses of the same diagnostic. Handling it centrally simplifies the code
and reduces changes if the storage for builtin names changes.

This refactoring is extracted out of #120534 as requested in code
review.
2025-01-03 19:23:42 -08:00
Timm Baeder
02b30128e8
[clang][bytecode] Always return false for invalid bcp results (#121467) 2025-01-02 13:44:45 +01:00
Timm Baeder
34097c07e1
[clang][bytecode] Consider unknown-size arrays in memcpy/memcmp (#121462)
When emitting diagnostics for the number of elements.
2025-01-02 10:59:08 +01:00
Timm Baeder
d5c8af492f
[clang][bytecode] Consider start index when copying composite array (#121461)
... elements.
2025-01-02 10:31:49 +01:00
Timm Baeder
45e874e390
[clang][bytecode] Check for memcpy/memmove dummy pointers earlier (#121453) 2025-01-02 09:15:14 +01:00
Timm Baeder
f0d60170cc
[clang][bytecode] Check memove/memcpy for available elements (#121383)
Both destination and source pointer need to have at least as many
elements as requested.
2024-12-31 12:14:27 +01:00
Timm Bäder
3496e96f78 [clang][bytecode] Add a missing break 2024-12-28 14:17:06 +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
39e8953f89
[clang][bytecode] Move a local variable to a later point (#121250)
We don't need `E` before.
2024-12-28 07:43:15 +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
1f2d934525
[clang][bytecode] Support pointers in __builtin_mem{move,cpy} (#120560)
Unfortunately, that means we can't use the __builtin_bit_cast
implementation for this.
2024-12-19 16:38:58 +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 Baeder
dd6f6a096a
[clang][bytecode] Handle builtin_wmemcmp (#120070) 2024-12-16 13:41: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
30cbd09f4b
[clang][bytecode] Fix memcmp/bcmp failures on big-endian hosts (#119851)
See the discussion in

https://github.com/llvm/llvm-project/pull/119678#issuecomment-2539680746
and
https://github.com/llvm/llvm-project/pull/119544#issuecomment-2539678561
2024-12-13 12:19:27 +01:00
Timm Baeder
98470c0b2e
[clang][bytecode] Handle __builtin_bcmp (#119678)
... the same as `__builtin_memcmp`. Also fix a bug we still had when we
couldn't find a difference in the two inputs after `Size` bytes.
2024-12-12 10:57:39 +01:00
Timm Bäder
cfad8f14f8 [clang][bytecode] Fix a build failure on aarch64
This broke e.g.
https://lab.llvm.org/buildbot/#/builders/190/builds/11216
2024-12-12 09:08:30 +01:00
Timm Baeder
8713914d76
[clang][bytecode] Handle __builtin_memcmp (#119544) 2024-12-12 08:59:35 +01:00
Timm Baeder
d416cae180
[clang][bytecode][NFC] Use Pointer::pointToSameBlock (#119552)
block() requires the pointer to be a block pointer.
2024-12-11 16:14:19 +01:00