435 Commits

Author SHA1 Message Date
Timm Bäder
e096b282cc [clang][Interp] Fix CXXUuidOfExprs with incomplete record types
Create a dummy variable for those cases.
2024-06-27 08:53:20 +02:00
Timm Bäder
e5e0d8739d [clang][Interp] Implement CXXStdInitializerListExprs 2024-06-26 15:40:54 +02:00
Timm Bäder
b7768c5485 [clang][Interp][NFC] Use delegate() to delegate to only initlist item 2024-06-25 17:50:53 +02:00
Timm Bäder
ae1c564d15 [clang][Interp] Cast dummy pointers to other pointer type if necessary 2024-06-24 16:17:03 +02:00
Timm Bäder
6b41de3605 [clang][Interp] Implement ptrauth builtins 2024-06-24 13:02:55 +02:00
Timm Bäder
33676ba543 [clang][Interp] Fix variable initialization in inactive regions
When the EvalEmitter is inactive, it will simply not evaluate
any of the operations we emit via emit*. However, it will still
allocate variables. So the variables will be allocated, but we
won't evaluate their initializer, so later when we see the variable
again, it is uninitialized.

Stop creating variables in that case.
2024-06-24 10:18:05 +02:00
Timm Bäder
170c194ec1 [clang][Interp] Fix CFStringMakeConstantString etc. evaluation
We're ultimately expected to return an APValue simply pointing to
the CallExpr, not any useful value. Do that by creating a global
variable for the call.
2024-06-22 18:54:42 +02:00
Timm Bäder
c7c636189a [clang][Interp] Don't try to decay non-pointers to pointers 2024-06-21 13:15:35 +02:00
Timm Bäder
99f5fcb0d1 [clang][Interp] Try to fix #embed on big-endian machines
Insert a cast to the proper value.
2024-06-20 20:29:27 +02:00
Timm Bäder
67f5312c41 [clang][Interp] Nested ThisExprs that don't refer to the frame this ptr
Use a series of ops in that case, getting us to the right declaration
field.
2024-06-20 16:34:34 +02:00
Mariya Podchishchaeva
41c6e43792
Reland [clang][Sema, Lex, Parse] Preprocessor embed in C and C++ (#95802)
This commit implements the entirety of the now-accepted [N3017
-Preprocessor
Embed](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3017.htm) and
its sister C++ paper [p1967](https://wg21.link/p1967). It implements
everything in the specification, and includes an implementation that
drastically improves the time it takes to embed data in specific
scenarios (the initialization of character type arrays). The mechanisms
used to do this are used under the "as-if" rule, and in general when the
system cannot detect it is initializing an array object in a variable
declaration, will generate EmbedExpr AST node which will be expanded by
AST consumers (CodeGen or constant expression evaluators) or expand
embed directive as a comma expression.

This reverts commit
682d461d5a.

---------

Co-authored-by: The Phantom Derpstorm <phdofthehouse@gmail.com>
Co-authored-by: Aaron Ballman <aaron@aaronballman.com>
Co-authored-by: cor3ntin <corentinjabot@gmail.com>
Co-authored-by: H. Vetinari <h.vetinari@gmx.com>
2024-06-20 14:38:46 +02:00
Timm Bäder
e0b66a4d68 [clang][Interp][NFC] Loosen an assertion 2024-06-19 18:31:25 +02:00
Timm Bäder
498757e710 [clang][Interp][NFC] Fix initializing union APValues
The InitElem op assumes an array.
2024-06-19 18:31:25 +02:00
Timm Baeder
4d7d45e8ba
[clang][Interp] Implement complex division (#94892)
Share the implementation with the current interpreter.
2024-06-18 13:49:02 +02:00
Timm Bäder
4b4aaf1e79 [clang][Interp] Fix non-initializing CK_VectorSplat casts
Create the usual local variable to fill.
2024-06-18 09:05:28 +02:00
Timm Bäder
18000feec0 [clang][Interp][NFC] Reject non-floating CK_FloatingCast casts
We need the types to be floating types. Rejecting the HLSL vector
casts here is also what the current interpreter does.
2024-06-18 08:30:43 +02:00
Timm Bäder
2d38becda8 [clang][Interp][NFC] Don't create variables in non-constant contexts
When the evaluation in a contant context fails, we would otherwise try
to access and use that variable later in a (maybe) non-constant context.
If the evaluation succeeds in the non-constant context, we never
reported success because we reported failure from the first time
we visited the variable.
2024-06-18 08:30:43 +02:00
Timm Baeder
4bf160e396
[clang][Interp] Implement Complex-complex multiplication (#94891)
Share the implementation for floating-point complex-complex
multiplication with the current interpreter. This means we need a new
opcode for this, but there's no good way around that.
2024-06-17 16:07:58 +02:00
Timm Bäder
8e95454158 [clang][Interp] Support ExtVectorElementExprs 2024-06-15 15:12:36 +02:00
Timm Bäder
3e8f2170bb [clang][Interp][NFC] Handle AddressSpaceConversion casts
Ignore them. No test yet, but this will be useful in a future commit.
2024-06-15 15:12:35 +02:00
Timm Bäder
904c53d53e [clang][Interp] Use different inline descriptors for global variables
Most of the InlineDescriptor fields were unused for global variables.
But more importantly, we need to differentiate between global variables
that are uninitialized because they didn't have an initializer when we
originally created them, and ones that are uninitialized because they
DID have an initializer, but evaluating it failed.
2024-06-15 05:41:59 +02:00
Timm Bäder
ae73706075 [clang][Interp] Fix references to objects
The previous commit tried to handle this in a way that's too general.
Move the !Initializing case down to the array type.
2024-06-13 15:31:24 +02:00
Timm Bäder
ffab938f50 [clang][Interp] Handle BooleanToSignedIntegral casts 2024-06-13 13:49:20 +02:00
Timm Bäder
5563d914a7 [clang][Interp] Prepare return value for composite InitListExprs 2024-06-13 12:34:11 +02:00
Timm Bäder
64c9a1e126 [clang][Interp] Also revisit references to const types
Neither isConstant() not isConstQualified() return true for these.
2024-06-13 06:55:07 +02:00
Vitaly Buka
682d461d5a
Revert " [Sema, Lex, Parse] Preprocessor embed in C and C++ (and Obj-C and Obj-C++ by-proxy)" (#95299)
Reverts llvm/llvm-project#68620

Introduce or expose a memory leak and UB, see llvm/llvm-project#68620
2024-06-12 13:14:26 -07:00
Timm Bäder
8ad82b419b [clang][Interp] Fix re-visiting OpenCL variables of in constant AS
We need to use isConstant() here, isConstQualified() is not enough.
2024-06-12 09:53:33 +02:00
The Phantom Derpstorm
5989450e00
[clang][Sema, Lex, Parse] Preprocessor embed in C and C++ (and Obj-C and Obj-C++ by-proxy) (#68620)
This commit implements the entirety of the now-accepted [N3017 -
Preprocessor
Embed](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3017.htm) and
its sister C++ paper [p1967](https://wg21.link/p1967). It implements
everything in the specification, and includes an implementation that
drastically improves the time it takes to embed data in specific
scenarios (the initialization of character type arrays). The mechanisms
used to do this are used under the "as-if" rule, and in general when the
system cannot detect it is initializing an array object in a variable
declaration, will generate EmbedExpr AST node which will be expanded
by AST consumers (CodeGen or constant expression evaluators) or
expand embed directive as a comma expression.

---------

Co-authored-by: Aaron Ballman <aaron@aaronballman.com>
Co-authored-by: cor3ntin <corentinjabot@gmail.com>
Co-authored-by: H. Vetinari <h.vetinari@gmx.com>
Co-authored-by: Podchishchaeva, Mariya <mariya.podchishchaeva@intel.com>
2024-06-12 09:16:02 +02:00
Timm Bäder
93d4fb032e [clang][Interp] Support floats in APValues 2024-06-12 08:15:36 +02:00
Timm Bäder
4cf607fa15 [clang][Interp] Fix visiting non-FieldDecl MemberExprs
Ignore the base and visit the Member decl like a regular DeclRefExpr.
2024-06-11 18:13:28 +02:00
Timm Bäder
e805b77107 [clang][Interp] Support ObjCEncodeExprs 2024-06-11 15:07:28 +02:00
Timm Bäder
529b43c1fd [clang][Interp] Refine diagnostics for casts from void*
This is still not perfect, but an improvement in general.
2024-06-11 11:19:06 +02:00
Timm Bäder
c0b65a2491 [clang][Interp] Diagnose casts from void pointers 2024-06-10 10:18:57 +02:00
Timm Bäder
5bb9c08d88 [clang][Interp] Reject compound assign operators pre-C++14 2024-06-09 14:58:21 +02:00
Timm Bäder
69cd2d288d [clang][Interp] Handle __extension__ for complex values 2024-06-09 14:29:12 +02:00
Timm Bäder
cb8e9360d8 [clang][Interp] Implement ~ operator for complex values 2024-06-09 14:29:12 +02:00
Timm Bäder
b8cc85b318 [clang][Interp] Limit lambda capture lazy visting to actual captures
Check this by looking at the VarDecl.
2024-06-07 13:29:23 +02:00
Timm Bäder
3a31eaeac8 [clang][Interp] Fix refers_to_enclosing_variable_or_capture DREs
They do not count into lambda captures, so visit them lazily.
2024-06-07 11:48:44 +02:00
Timm Bäder
c15b86731b [clang][Interp][NFC] Add GetPtrFieldPop opcode
And change the previous GetPtrField to only peek() the base pointer.
We can get rid of a whole bunch of DupPtr ops this way.
2024-06-07 09:40:26 +02:00
Timm Bäder
0b8acc06c4 [clang][Interp] Improve APValue machinery
Handle lvalues pointing to declarations, unions and member pointers.
2024-06-07 08:16:39 +02:00
Timm Baeder
a86c1e7175
[clang][Interp] Member Pointers (#91303)
This adds a `MemberPointer` class along with a `PT_MemberPtr` primitive
type.

A `MemberPointer` has a `Pointer` Base as well as a `Decl*` (could be
`ValueDecl*`?) decl it points to.
For the actual logic, this mainly changes the way we handle `PtrMemOp`s
in `VisitBinaryOperator`.
2024-06-06 11:17:48 +02:00
Timm Bäder
f1e78f7769 [clang][Interp] Handle lvalue APValues in visitAPValueInitializer() 2024-06-06 10:24:26 +02:00
Timm Bäder
1ea568895a [clang][Interp][NFC] Mark failed globals as uninitialized
This happens automatically if anything _before_ the Ret op fails,
but in this case we have to un-initialize it again.
2024-06-05 13:10:18 +02:00
Timm Bäder
49b760ff2c [clang][Interp] Fix calling virtual CXXOperatorCallExprs 2024-05-27 16:01:30 +02:00
Timm Bäder
6a197b35db [clang][Interp] Fix returning references to functions
Previously, we pushed a pointer to the stack and later tried to use
it as if it was a function pointer, which doesn't work.
2024-05-27 15:43:12 +02:00
Timm Bäder
4447461bc4 [clang][Interp] Don't try to dereference a null type 2024-05-27 12:59:25 +02:00
Timm Bäder
d0bb917390 [clang][Interp] Handle ObjCBoxedExprs 2024-05-26 10:50:45 +02:00
Timm Bäder
5220b7bea8 [clang][Interp] Handle objc strings 2024-05-26 10:50:44 +02:00
Timm Bäder
5c40db1da3 [clang][Interp] Don't retry weak declarations 2024-05-24 20:00:54 +02:00
Timm Bäder
f35aac6991 [clang][Interp] Fix zero-initializing unions
Only with primitive fields for now.
2024-05-24 15:15:40 +02:00