90 Commits

Author SHA1 Message Date
Timm Bäder
b3b1d86137 Revert "[clang][Interp] Support floating-point values"
This reverts commit 62f43c3eae2460d4ca3da7897fd2d7c56920638c.

This breaks a couple of builders, e.g.

https://lab.llvm.org/buildbot/#/builders/139/builds/34925
2023-01-25 14:48:39 +01:00
Timm Bäder
62f43c3eae [clang][Interp] Support floating-point values
Add a new Floating type and a few new opcodes to support floating point
values.

Differential Revision: https://reviews.llvm.org/D134859
2023-01-25 14:41:26 +01:00
Timm Bäder
0a3243de62 [clang][Interp] Array initialization via string literal
Differential Revision: https://reviews.llvm.org/D137488
2023-01-25 14:22:05 +01:00
Timm Bäder
a7a4463acb [clang][Interp] Start implementing builtin functions
Differential Revision: https://reviews.llvm.org/D137487
2023-01-25 14:08:03 +01:00
Timm Bäder
f4a6842c5a [clang][Interp] Reject invalid declarations and expressions
Reject them early, since we will run into problems and/or assertions
later on anyway.

Differential Revision: https://reviews.llvm.org/D137386
2023-01-25 12:52:44 +01:00
Timm Bäder
2725e2c032 [clang][Interp] Fix ImplicitValueInitExprs for pointer types
This previously ran into an "unknown type" assertion when trying to emit
a 'Zero' op for a pointer type. Emit a NullPtr op instead.

Differential Revision: https://reviews.llvm.org/D137235
2023-01-25 12:31:49 +01:00
Timm Bäder
7348bb36c5 [clang][Interp] Support inc/dec operators for pointers
Differential Revision: https://reviews.llvm.org/D137232
2023-01-25 11:57:05 +01:00
Timm Bäder
902140dd38 [clang][Interp] Re-apply "Implement missing compound assign operators"
Implement mul, div, rem, etc. compound assign operators.

Differential Revision: https://reviews.llvm.org/D137071
2023-01-25 10:24:50 +01:00
Timm Bäder
de3a3cb987 [clang][Interp] Fix compound assign operator types
Just like we do (or will do) for floating types, we need to take into
acocunt that the LHSComputationType, ResultType and type of the
expression (what we ultimately store) might be different.

Do this by emitting cast ops before and after doing the computation.

This fixes the test failures introduced by
490e8214fca48824beda8b508d6d6bbbf3d8d9a7 on big endian machines.

Differential Revision: https://reviews.llvm.org/D142328
2023-01-25 10:12:26 +01:00
Timm Bäder
6469281100 [clang][Interp][NFC] Remove InitFn code
This is unused.
2023-01-23 12:19:36 +01:00
Timm Bäder
284bd95e80 [clang][Interp][NFC] Remove unused using alias 2023-01-23 10:19:34 +01:00
Timm Bäder
3665da3d00 Re-commit "[clang][Interp] Unify visiting variable declarations"
We often visit the same variable multiple times, e.g. once when checking
its initializer and later when compiling the function. Unify both of
those in visitVarDecl() and do the returning of the value in
visitDecl().

This time, use a VariableScope instead of a DeclScope for local
variables. This way, we don't emit Destroy ops for the local variables
immediately after creating them.

Differential Revision: https://reviews.llvm.org/D136815
2023-01-21 10:23:53 +01:00
Timm Bäder
8df7e818de Revert "[clang][Interp] Unify visiting variable declarations"
This reverts commit 5b54cf1a2892767fe949826a32d7820732028a38.

This breaks a builder: https://lab.llvm.org/buildbot/#/builders/5/builds/30854
2023-01-19 13:52:47 +01:00
Timm Bäder
f6ea1af9a4 Revert "[clang][Interp] Implement missing compound assign operators"
This reverts commit 490e8214fca48824beda8b508d6d6bbbf3d8d9a7.

This breaks a builder: https://lab.llvm.org/buildbot/#/builders/214/builds/5415
2023-01-19 13:52:47 +01:00
Timm Bäder
490e8214fc [clang][Interp] Implement missing compound assign operators
Implement mul, div, rem, etc. compound assign operators.

Differential Revision: https://reviews.llvm.org/D137071
2023-01-19 12:24:56 +01:00
Timm Bäder
5b54cf1a28 [clang][Interp] Unify visiting variable declarations
We often visit the same variable multiple times, e.g. once when checking
its initializer and later when compiling the function. Unify both of
those in visitVarDecl() and do the returning of the value in
visitDecl().

Differential Revision: https://reviews.llvm.org/D136815
2023-01-19 10:46:16 +01:00
Timm Bäder
865094746e [clang][Interp] Track initialization state of local variables
Use an InlineDescriptor per local variable to track whether locals
have been initialized or not. This way we can support uninitialized
local variables in constexpr functions.

Differential Revision: https://reviews.llvm.org/D135750
2023-01-18 16:55:02 +01:00
Timm Bäder
78a9ee7834 [clang][Interp][NFC] Remove code duplication in VisitRecordInitializer
We can just use the regular VisitCallExpr logic here, since we have the
pointer to initialize already on the stack.
2023-01-11 13:08:51 +01:00
Timm Bäder
d4f1f35978 [clang][Interp][NFC] Move to std::optional 2022-12-05 17:31:49 +01:00
Timm Bäder
c3380c32f8 [clang][Interp] Handle undefined functions better
Differential Revision: https://reviews.llvm.org/D136936
2022-11-30 10:09:52 +01:00
Timm Bäder
8095b090db [clang][Interp] Array initialization via CXXConstructExpr
Differential Revision: https://reviews.llvm.org/D136920
2022-11-30 10:09:52 +01:00
Timm Bäder
afa60d08a2 [clang][Interp] Fix discarding non-primitive function call return values
Differential Revision: https://reviews.llvm.org/D136457
2022-11-30 09:18:28 +01:00
Timm Bäder
0dcfd0ce02 [clang][Interp] Support alignof()
Support alignof() and __alignof() expressions.

Fixes #58816

Differential Revision: https://reviews.llvm.org/D137240
2022-11-11 08:38:06 +01:00
Timm Bäder
7863646fd2 [clang][Interp] DerivedToBase casts
Differential Revision: https://reviews.llvm.org/D137545
2022-11-11 08:38:06 +01:00
Timm Bäder
f4707af294 [clang][Interp][NFCI] Cleanup emitConst()
Before, when emitting a regular integer constant, we went:

Int -> APInt -> int -> emit

Fix this by using regular integer constants in emitConst() and instead
converting APInt to those once.
2022-11-07 09:05:29 +01:00
Timm Bäder
05a113e188 [clang][Interp][NFC] Handle discarded ArraySubscriptExprs
This is not exactly a common case, so just pop the pointer at the end if
necessary.
2022-11-07 08:37:43 +01:00
Timm Bäder
9a3b969d1f [clang][Interp][NFC] Make InitField() not pop the pointer
This was confusing. InitElem peeks a pointer, while InitElemPop will
pop the pointer. However, for fields, InitField would pop the pointer
and no InitFieldPop exists. At least make InitField and InitElem behave
the same.
2022-11-07 08:30:43 +01:00
Timm Bäder
7c0a2d9cda [clang][Interp][NFC] Use StorePop for assignments with DiscardResult
If we don't need the result anyway, use StorePop, instead of a Store+Pop
combination. That way we save one instruction and not using the result
is the common case anyway.
2022-11-07 07:56:25 +01:00
Timm Bäder
10483ac743 [clang][Interp] Support pointer arithmethic in binary operators
Differential Revision: https://reviews.llvm.org/D135858
2022-11-07 07:47:19 +01:00
Timm Bäder
74fb770de9 [clang][Interp] Implement bitXor opcode
Differential Revision: https://reviews.llvm.org/D136956
2022-10-30 09:23:33 +01:00
Timm Bäder
6d965c94ba [clang][Interp] Implement left and right shifts
Differential Revision: https://reviews.llvm.org/D136532
2022-10-30 08:59:55 +01:00
Timm Bäder
881547db03 [clang][Interp] Implement add and sub compound assign operators
Differential Revision: https://reviews.llvm.org/D136528
2022-10-30 08:11:04 +01:00
Timm Bäder
f79f64b8d0 [clang][Interp] Implement inc and dec operators
Differential Revision: https://reviews.llvm.org/D136423
2022-10-28 17:47:32 +02:00
Timm Bäder
ddec89670d [clang][Interp][NFC] Use right visit() function
visit (lowercase V) sets DiscardValue to false and calls Visit
(uppercase V). So we can't just call Visit (uppercase V) ourselves,
since then we aren't handling DiscardValue correctly.
This is currently irrelevant but will make a difference later.

Also, the naming isn't my fault and might change later.
2022-10-28 17:44:53 +02:00
Timm Bäder
38ffc89c87 [clang][Interp] Fix ignoring expression return values
Randomly noticed this. We need to honor DiscardResult here.

Differential Revision: https://reviews.llvm.org/D136013
2022-10-28 16:45:38 +02:00
Timm Bäder
0ccff030f3 [clang][Interp] Fix record members of reference type
When assigning to them, we can't classify the expression type, because
that doesn't contain the right information.

And when reading from them, we need to do the extra deref, just like we
do when reading from a DeclRefExpr.

Differential Revision: https://reviews.llvm.org/D136012
2022-10-28 16:34:45 +02:00
Timm Bäder
8b87cb4853 [clang][Interp] Remove unused getGlobalIdx()
Remove the only use with the version we already use in
VisitDeclRefExpr().
2022-10-28 16:34:29 +02:00
Timm Bäder
52ba50c24c [clang][Interp] Implement String- and CharacterLiterals
Differential Revision: https://reviews.llvm.org/D135366
2022-10-28 15:05:21 +02:00
Timm Bäder
63e3fe1088 Revert "[clang][Interp] Implement String- and CharacterLiterals"
This reverts commit 6fa1795d1fd4770f9f5c00f5a30937d68c3feb17.

This breaks a windows builder:

../../clang/lib/AST/Interp/ByteCodeExprGen.h(236,11): error: call to constructor of 'clang::interp::APInt' (aka 'llvm::APInt') is ambiguous
    APInt WrappedValue(getIntWidth(Ty), Value, std::is_signed<T>::value);
          ^            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../clang/lib/AST/Interp/ByteCodeExprGen.cpp(409,16): note: in instantiation of function template specialization 'clang::interp::ByteCodeExprGen<clang::interp::ByteCodeEmitter>::emitConst<unsigned int>' requested here
  return this->emitConst(E, E->getValue());
               ^
../../clang/lib/AST/Interp/ByteCodeExprGen.cpp(1149,16): note: in instantiation of member function 'clang::interp::ByteCodeExprGen<clang::interp::ByteCodeEmitter>::VisitCharacterLiteral' requested here
template class ByteCodeExprGen<ByteCodeEmitter>;
               ^
../../llvm/include\llvm/ADT/APInt.h(108,3): note: candidate constructor
  APInt(unsigned numBits, uint64_t val, bool isSigned = false)
  ^
../../llvm/include\llvm/ADT/APInt.h(134,3): note: candidate constructor
  APInt(unsigned numBits, unsigned numWords, const uint64_t bigVal[]);
  ^
2022-10-28 13:34:37 +02:00
Timm Bäder
6fa1795d1f [clang][Interp] Implement String- and CharacterLiterals
Differential Revision: https://reviews.llvm.org/D135366
2022-10-28 12:49:38 +02:00
Timm Bäder
ea2596692f [clang][Interp][NFC] Simplify generated code for references
Instead of getting a pointer to a pointer to a value, followed by
dereferencing once, leaving us with a pointer to a value, we can instead
just get the pointer to the value (the reference in question) directly.
This simplifies (and shrinks) the generated bytecode somewhat.
2022-10-26 08:49:11 +02:00
Kazu Hirata
f92980c726 [clang] Fix a warning
This patch fixes:

  clang/lib/AST/Interp/ByteCodeExprGen.cpp:978:24: warning: variable
  ‘T’ set but not used [-Wunused-but-set-variable]

T and ReturnType were introduced on August 19, 2022 in commit
8e41e6a4eafa2b667ec37ece33a85493fe0156c2.

Their last uses were removed on October 13, 2022 in commit
0e754cfadc9487282d9b6119c41962c5c6c3660f.
2022-10-23 09:34:49 -07:00
Timm Bäder
0e754cfadc [clang][Interp][NFC] Unify Call() implementations
The type parameter we used to pass to call() was unused. Use the same
implementation for void and value-returning function calls.
2022-10-22 10:32:05 +02:00
Timm Bäder
9cb4e90e72 [clang][Interp] Support base class constructors
Differential Revision: https://reviews.llvm.org/D135025
2022-10-21 10:49:45 +02:00
Timm Bäder
09bbc903a5 [clang][Interp] Array initialization via ImplicitValueInitExpr
Differential Revision: https://reviews.llvm.org/D135013
2022-10-21 10:49:45 +02:00
Timm Bäder
6fad7127cb [clang][Interp][NFC] Remove unused parameter from emitConst() 2022-10-14 14:41:05 +02:00
Timm Bäder
ce4d5ae9dc [clang][Interp] Implement bitwise Or operations
Analogous to the bitAnd implementation, do the same for bitwise or.

Differential Revision: https://reviews.llvm.org/D135361
2022-10-14 14:15:08 +02:00
Timm Bäder
62a58050ba [clang][Interp] Implement bitwise and operations
Differential Revision: https://reviews.llvm.org/D135012
2022-10-14 14:00:07 +02:00
Timm Bäder
11f3604695 [clang][Interp][NFC] Remove an unnecessary local variable 2022-10-14 13:33:04 +02:00
Timm Bäder
9b2f2d8463 [clang][Interp][NFC] Remove unused function 2022-10-14 13:32:00 +02:00