55 Commits

Author SHA1 Message Date
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
Timm Bäder
77aaf469a7 [clang][Interp] Implement ConditionalOperators
Differential Revision: https://reviews.llvm.org/D134801
2022-10-14 13:16:10 +02:00
Timm Bäder
d704ba26b9 [clang][Interp] Implement div opcode
Implement an opcode for division of two integrals.

Differential Revision: https://reviews.llvm.org/D134749
2022-10-14 12:57:57 +02:00
Timm Bäder
c9ad877844 [clang][Interp] Implement rem opcode
Implement an opcode to get the remainder of the divison between LHS and
RHS.

Differential Revision: https://reviews.llvm.org/D134744
2022-10-14 12:57:57 +02:00
Timm Bäder
542123465f [clang][Interp] Implement bitwise not operations
Differential Revision: https://reviews.llvm.org/D134804
2022-10-14 12:57:57 +02:00
Timm Bäder
6e83209f62 [clang][Interp] Fix copy constructors with record array members
Differential Revision: https://reviews.llvm.org/D134523
2022-10-14 11:57:26 +02:00
Timm Bäder
ae27323428 [clang][Interp] Classify ArrayInitIndexExpr type
We can't just push a uint64 unconditionally here, since on 32bit arches
we later expect a different type, e.g. uint32.

This broke e.g. these builders:
https://lab.llvm.org/buildbot#builders/171/builds/21514
https://lab.llvm.org/buildbot#builders/38/builds/6643
2022-10-14 11:10:28 +02:00
Timm Bäder
33b52836de [clang][Interp] Fix using default copy constructors
Implement ArrayInitLoopExprs, which are used in copy constructors to
copy arrays. Also fix problems encountered while doing that.

Differential Revision: https://reviews.llvm.org/D134361
2022-10-14 10:21:53 +02:00
Timm Bäder
cb5f205828 [clang][Interp] Implement nested struct initialization
Recurse into visitInitializer() if necessary.

Differential Revision: https://reviews.llvm.org/D134175
2022-10-14 10:21:53 +02:00
Timm Bäder
0ddd13acc9 [clang][Interp] Implement This pointer passing to methods
Implement passing the this pointer to member functions and constructors.
The this pointer is passed via the stack. This changes the functions to
explicitly track whether they have a RVO pointer and a this pointer.

Differential Revision: https://reviews.llvm.org/D134699
2022-10-14 10:21:53 +02:00
Timm Bäder
1942a2538b [clang][Interp] Start implementing record types
Implement simple constructors as well as member access expressions.

Differential Revision: https://reviews.llvm.org/D134057
2022-10-14 10:21:53 +02:00
Timm Bäder
773b468543 [clang][Interp][NFC] Add a TODO comment
We can ignore casts where FromT and ToT are the same type. But that's a
performance optimization that I'd like to do later. For now, this code
is doing the right thing.
2022-10-14 10:21:52 +02:00
Timm Bäder
1ecaa617e7 [clang][Interp] Handle enums
Handle DeclRefExprs of enum types. They are otherwise handled like
integers.

Differential Revision: https://reviews.llvm.org/D134020
2022-09-30 08:18:14 +02:00
Timm Bäder
f444a7cc16 Revert "[clang][Interp] Handle enums"
This reverts commit c090295916a921e809184f589c6830475e293b8b.

One of the test cases fails. Revert this until I know a way to make it
work reliably.
2022-09-29 13:45:52 +02:00
Timm Bäder
c090295916 [clang][Interp] Handle enums
Handle DeclRefExprs of enum types. They are otherwise handled like
integers.

Differential Revision: https://reviews.llvm.org/D134020
2022-09-29 12:50:56 +02:00
Timm Bäder
ee2e414d66 [clang][Interp] Handle sizeof()
Implement visiting UnaryExprOrTypeTraitExprs to handle sizeof()
expressions.

Differential Revision: https://reviews.llvm.org/D133934
2022-09-29 12:50:55 +02:00
Timm Bäder
da62ed6ceb [clang][Interp] Pass initializer when creating globals
This is dead code right now but will be used for implementing array
fillers, where we need some information from the initializer when
allocaing the Descriptors.

Differential Revision: https://reviews.llvm.org/D133856
2022-09-29 12:50:54 +02:00
Timm Bäder
bf3efa8b16 [clang][Interp] Handle DeclRefExpr of reference types
References are implemented through pointers, so we need a second deref
when encountering a DeclRefExpr of a reference type.

Differential Revision: https://reviews.llvm.org/D132997
2022-09-13 10:40:51 +02:00
Timm Bäder
3a7d476087 [clang][Interp] Implement array initializers and subscript expressions
Differential Revision: https://reviews.llvm.org/D132727
2022-09-08 07:31:07 +02:00
Timm Bäder
aa7c5c9c4e [clang][Interp] Handle missing local initializers better
This is illegal in a constexpr context. We can already figure that out,
but we'd still run into an assertion later on when trying to visit the
missing initializer or run the invalid function.

Differential Revision: https://reviews.llvm.org/D132832
2022-09-08 07:31:07 +02:00
Timm Bäder
5c4dbff0b6 [clang][Interp] Handle SubstNonTypeTemplateParmExprs
Differential Revision: https://reviews.llvm.org/D132831
2022-09-08 07:31:07 +02:00
Timm Bäder
4d700ffe67 [clang][Interp] Implement ImplicitValueInitExprs
Take the existing Zero opcode and emit it.

Differential Revision: https://reviews.llvm.org/D132829
2022-09-08 07:31:07 +02:00
Timm Bäder
95e6a407d9 [clang][Interp] Implement IntegralToBoolean casts
Redo how we do IntegralCasts and implement IntegralToBoolean casts using
the already existing cast op.

Differential Revision: https://reviews.llvm.org/D132739
2022-09-08 07:31:07 +02:00
Timm Bäder
8e41e6a4ea [clang][Interp] Implement function calls
Add Call() and CallVoid() ops and use them to call functions. Only
FunctionDecls are supported for now.

Differential Revision: https://reviews.llvm.org/D132286
2022-09-08 07:31:07 +02:00
Timm Bäder
fdfc0dfa8e [clang][Interp] Implement pointer (de)ref operators
Implement pointer references, dereferences and assignments.

Differential Revision: https://reviews.llvm.org/D132111
2022-08-25 14:20:32 +02:00
Simon Pilgrim
e41dd02052 Fix MSVC "not all control paths return a value" warning 2022-08-19 17:37:37 +01:00
Timm Bäder
80bbc05436 [clang][Interp] Implement inv and neg unary operations
Implement negating and inverting values. Also implement
IntegralToBoolean casts so the operations are easier to test.

Differential Revision: https://reviews.llvm.org/D132098
2022-08-19 16:05:00 +02:00
Timm Bäder
a2a5470fc2 [clang][Interp] Implement boolean and nullptr literals
Handle CXX bool literals as well as nullptr literals and add a few tests
for each.

Differential Revision: https://reviews.llvm.org/D131942
2022-08-18 07:11:48 +02:00
Sunho Kim
134363208b [clang] Fix gcc-6 compilation error. (NFC)
Fix https://github.com/llvm/llvm-project/issues/55626.

Differential Revision: https://reviews.llvm.org/D129049
2022-07-04 05:33:05 +09:00
Kazu Hirata
17d4bd3d78 [clang] Fix bugprone argument comments (NFC)
Identified with bugprone-argument-comment.
2022-01-09 00:19:49 -08:00
Nandor Licker
950b70dcc7 [Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.

Reviewers: Bigcheese, jfb, rsmith

Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64146

llvm-svn: 371834
2019-09-13 09:46:16 +00:00
Roman Lebedev
2c9f83cfab Revert "[Clang Interpreter] Initial patch for the constexpr interpreter"
Breaks BUILD_SHARED_LIBS build, introduces cycles in library dependency
graphs. (clangInterp depends on clangAST which depends on clangInterp)

This reverts r370839, which is an yet another recommit of D64146.

llvm-svn: 370874
2019-09-04 10:57:06 +00:00
Nandor Licker
32f82c9cba [Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.

Reviewers: Bigcheese, jfb, rsmith

Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64146

llvm-svn: 370839
2019-09-04 05:49:41 +00:00
Nandor Licker
c3bdad8c1e Revert [Clang Interpreter] Initial patch for the constexpr interpreter
This reverts r370636 (git commit 8327fed9475a14c3376b4860c75370c730e08f33)

llvm-svn: 370642
2019-09-02 11:34:47 +00:00
Nandor Licker
8327fed947 [Clang Interpreter] Initial patch for the constexpr interpreter
Summary:
This patch introduces the skeleton of the constexpr interpreter,
capable of evaluating a simple constexpr functions consisting of
if statements. The interpreter is described in more detail in the
RFC. Further patches will add more features.

Reviewers: Bigcheese, jfb, rsmith

Subscribers: bruno, uenoku, ldionne, Tyker, thegameg, tschuett, dexonsmith, mgorny, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64146

llvm-svn: 370636
2019-09-02 10:38:08 +00:00
Nandor Licker
a6bef738bf Revert [Clang Interpreter] Initial patch for the constexpr interpreter
This reverts r370584 (git commit afcb3de117265a69d21e5673356e925a454d7d02)

llvm-svn: 370588
2019-08-31 15:15:39 +00:00