56 Commits

Author SHA1 Message Date
Timm Baeder
c38befd94f
[clang][bytecode] Fix delete[] dtor order (#128411)
As always, call array dtors in reverse order.
2025-02-23 11:32:35 +01:00
Timm Baeder
6db96c9ecc
[clang][bytecode] Always reject ctors of invalid parent decls (#128295)
The copy constructor of an invalid declaration might still be perfectly
valid, but we still need to reject it.
2025-02-22 22:04:44 +01:00
Timm Baeder
2c00b3b859
[clang][bytecode] Silently reject ctors of invalid decls (#128290)
The follow-up diagnostic would otherwise be:

array.cpp:111:33: note: undefined constructor '(unnamed struct at
array.cpp:111:11)' cannot be used in a constant expression
array.cpp:111:11: note: declared here
  111 | constexpr struct { Unknown U; } InvalidCtor;
      |           ^

... and complaining about the undefined constructor of a class that is
invalid anyway doesn't make much sense.
2025-02-22 08:01:56 +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
09d14149f6
[clang][bytecode] Fix return value of array CXXNewExprs (#127526)
Just like with the __builtin_operator_new version, we need to point to
the first array element, not the array element itself.
2025-02-18 02:41:25 +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
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
c475356603
[clang][bytecode][NFC] Only call getSource() when necessary (#125419) 2025-02-03 08:51:30 +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
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
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
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
ce1587346b
[clang][bytecode] Allow checking builtin functions... (#119328)
... in checkingPotentialConstantExpression mode. This is what the
current interpreter does, yet it doesn't do so for
`__builtin_operator_new`.
2024-12-10 07:42:13 +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
a9731dff0a
[clang][bytecode][NFC] Avoid a getSource() call (#117311)
This is only needed when we actually emit a diagnostic, so move the
getSource() after the early return.
2024-11-22 14:00:10 +01:00
smanna12
95f4aa44ae
[clang][bytecode] Add assert to ensure correct state restoration in CallBI function (#115496)
This commit adds an assert statement to the CallBI function to ensure
that the interpreter state (S.Current) is correctly reset to the
previous frame (FrameBefore) after InterpretBuiltin returns true. This
helps catch any potential issues during development and debugging.
2024-11-21 08:45:34 -06:00
Simon Pilgrim
d800ea7cb1
Adjust MSVC disabled optimization pragmas to be _MSC_VER only (#116704)
Alter the #ifdef values from #110986 and #115292 to use _MSC_VER instead of _WIN32 to stop the pragmas being used on gcc/mingw builds

Noticed by @mstorsjo
2024-11-21 13:33:13 +00:00
Kazu Hirata
dec6324cb0
[AST] Remove unused includes (NFC) (#116549)
Identified with misc-include-cleaner.
2024-11-17 09:36:48 -08: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
f0b9a0ba06
[clang][bytecode] Diagnose delete with non-virtual dtor (#114373)
... in the base class.
2024-10-31 10:13:40 +01:00
Timm Baeder
87b6ec3be6
[clang][bytecode] Diagnose placement-new construction to inactive field (#114047)
We can reuse CheckActive() for this.
2024-10-29 15:08:41 +01:00
Timm Baeder
7b88e7530d
[clang][bytecode][NFC] Make CheckVolatile static (#113785) 2024-10-27 05:06:47 +01:00
Timm Baeder
d5b42db00f
[clang][bytecode][NFC] Only do CheckConstant checks for global pointers (#113786)
We can check isStatic() early here and save ourselves some work.
2024-10-27 04:56:53 +01:00
Timm Baeder
46ad7ff4b7
[clang][bytecode] Diagnose non-const initialiers in diagnoseUnknownDecl (#113276)
This is more similar to the diagnostic output of the current interpreter
2024-10-23 05:50:30 +02:00
Timm Bäder
1251687448 [clang][bytecode][NFC] Remove a leftover dump call 2024-10-17 12:40:14 +02:00
yronglin
8079a2c578
[clang][bytecode] Diagnose reference to non-constexpr variable of const type in C23 constexpr (#112211)
```cpp
const int V33 = 4;
const int V34 = 0;
const int V35 = 2;

constexpr int V36 = V33 / V34;
// expected-error@-1 {{constexpr variable 'V36' must be initialized by a constant expression}}
constexpr int V37 = V33 / V35;
// expected-error@-1 {{constexpr variable 'V37' must be initialized by a constant expression}}
```

---------

Signed-off-by: yronglin <yronglin777@gmail.com>
2024-10-16 00:11:12 +08: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
bd1976bris
d2051919bb
[MSVC] work-around for compile time issue 102513 (#110986)
Disable optimizations when building clang/lib/AST/ByteCode/Interp.cpp
with Microsoft's compiler as it has a bug that causes excessive build
times. We do this only when NDEBUG is not defined on the assumption that
building without asserts indicates that a user is strongly invested in
runtime performance.

Partially addresses: https://github.com/llvm/llvm-project/issues/102513.

Once the bug is addressed in the Microsoft compiler this can be removed.

Co-authored-by: dyung
2024-10-04 14:59:41 +01: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
d9b377d8b1
[clang][bytecode] Don't produce a null type when checking new exprs (#110252)
getType() might give us the right type already, so use that instead of
calling getPointeeType() for all CXXNewExprs.
2024-09-27 17:48:43 +02:00
Timm Baeder
09cd5a8673
[clang][bytecode] Refuse to contruct objects with virtual bases (#110142) 2024-09-27 05:56:12 +02:00
Timm Baeder
a024a0ceed
[clang][bytecode] Override InConstantContext flag for immediate calls (#109967)
And fix the diagnostics for __builtin_is_constant_evaluated(). We can be
in a non-constant context, but calling an immediate function always
makes the context constant for the duration of that call.
2024-09-25 16:46:46 +02:00
Timm Baeder
4bd3a62cd6
[clang][bytecode] Fix diagnosing std::construct_at with wrong type (#109828)
We can't make the assumption that types are always fine in std
functions.
2024-09-25 08:00:32 +02:00
Timm Baeder
4b96400240
[clang][bytecode] Allow placement-new in std functions pre-C++26 (#109753) 2024-09-24 10:28:54 +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
c57b9f5a13
[clang][bytecode] Fix reporting non-constant variables in C (#109516)
We need to call FFDiag() to get the usual "invalid subexpression"
diagnostic.
2024-09-21 09:58:56 +02:00
Timm Baeder
97aa8cc94d
[clang][bytecode] Diagnose weak reads in final load (#109515)
They aren't allowed here either.
2024-09-21 09:10:31 +02:00
Timm Baeder
d267daa9eb
[clang][bytecode] Diagnose loads from weak variables (#109256) 2024-09-19 11:59:38 +02:00
Timm Baeder
f22a8d1822
[clang][bytecode] Fix modify_global diagnostics in C++11 (#108358)
We shouldn't emit this until C++14.
2024-09-12 13:25:25 +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
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
e4f3b56dae
[clang][bytecode] Fix diagnosing reads from temporaries (#106868)
Fix the DeclID not being set in global temporaries and use the same
strategy for deciding if a temporary is readable as the current
interpreter.
2024-09-01 07:40:43 +02:00