45 Commits

Author SHA1 Message Date
Timm Bäder
1c8c5a89c5 [clang][Interp][NFC] Merge two if statements 2023-07-04 16:16:17 +02:00
Takuya Shimizu
dfb85c3ce0 [Clang][Interp] Diagnose uninitialized ctor of global record arrays
This patch adds a check for uninitialized subobjects of global variables that are record arrays.
e.g. `constexpr Foo f[2];`

Reviewed By: tbaeder

Differential Revision: https://reviews.llvm.org/D152548
2023-06-21 19:03:01 +09:00
Timm Bäder
459f495f49 [clang][Interp] Check inc/dec family of ops for initialization
Differential Revision: https://reviews.llvm.org/D149846
2023-06-16 15:19:23 +02:00
Timm Bäder
da836b36bc [clang][Interp] Track frame depth
Save the depth of each InterpFrame and bail out if we're too deep.

Differential Revision: https://reviews.llvm.org/D148614
2023-05-31 12:08:03 +02:00
Timm Bäder
40c26ec48c [clang][Interp] Fix diagnosing uninitialized ctor record arrays
Differential Revision: https://reviews.llvm.org/D143334
2023-05-31 11:39:40 +02:00
Takuya Shimizu
456d072405 Reland: [clang][AST] Print name instead of type when diagnosing uninitialized subobject in constexpr variables
This patch improves the diagnostic on uninitialized subobjects in constexpr variables by modifying the diagnostic message to display the subobject's name instead of its type.

Fixes https://github.com/llvm/llvm-project/issues/58601
Differential Revision: https://reviews.llvm.org/D146358
2023-05-24 21:31:25 +09:00
Erich Keane
34e49d3e85 Revert "[clang][AST] Print name instead of type when diagnosing uninitialized subobject in constexpr variables"
This reverts commit 0e167fc0a2147c9b673b8afd5fea001b0d127781.

This patch causes its assertion to fire when doing AST-dump, so
reverting so that the author has time to fix this.
2023-05-18 06:44:39 -07:00
Takuya Shimizu
0e167fc0a2 [clang][AST] Print name instead of type when diagnosing uninitialized subobject in constexpr variables
This patch improves the diagnostic on uninitialized subobjects in constexpr variables by modifying the diagnostic message to display the subobject's name instead of its type.

Fixes https://github.com/llvm/llvm-project/issues/58601
Differential Revision: https://reviews.llvm.org/D146358
2023-05-16 21:49:57 +09:00
Timm Bäder
db3dcdc08c [clang][Interp] Fix initializing base class members
For the given test case, we were trying to initialize a member of C,
which doesn't have any. Get the proper base pointer instead and
initialize the members there.

Differential Revision: https://reviews.llvm.org/D143466
2023-04-03 13:51:04 +02:00
Timm Bäder
569222e172 [clang][Interp] Only check constructors for global variables
Local variables may be partially initialized.

Differential Revision: https://reviews.llvm.org/D140723
2023-03-02 09:13:47 +01:00
Timm Bäder
8d09bd616b [clang][Interp] This pointers are writable in de-/constructors
This is possible in C++20, so we need to check this when doing stores.

Differential Revision: https://reviews.llvm.org/D136751
2023-03-01 15:41:10 +01:00
Timm Bäder
760136ff13 [clang][Interp] Implement __builtin_assume
Just ignore it.

As part of this, move the Ret and RetVoid implementation to Interp.h, so
they can be shared with InterpBuiltin.cpp.

Differential Revision: https://reviews.llvm.org/D141193
2023-01-27 07:54:37 +01:00
Timm Bäder
cb703434cb [clang][Interp] Add back Run() call
We need to run the functions we compiled immediately after to check if
they can ever be a constant expression.

Differential Revision: https://reviews.llvm.org/D140724
2023-01-25 17:01:55 +01:00
Timm Bäder
5de6b94f85 [clang][Interp][NFC] Replace remaining dyn_cast_or_null uses 2023-01-25 16:39:26 +01:00
Timm Bäder
cb7f582211 Re-apply "[clang][Interp] Support floating-point values"
Don't move the Repr struct into Integral this time.

Differential Revision: https://reviews.llvm.org/D134859
2023-01-25 15:13:09 +01:00
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
85acfc6425 Revert "[clang][Interp][NFC] Remove shift error checking code duplication"
This reverts commit fddf6418e8492a544c9bfdb42a4dbc949d9dc2ee.

Apparently this also breaks some builders:

/usr/bin/ld: EvalEmitter.cpp:(.text._ZN5clang6interp11EvalEmitter7emitShlENS0_8PrimTypeES2_RKNS0_10SourceInfoE+0x1f54): undefined reference to `bool clang::interp::CheckShift<clang::interp::Integral<16u, true> >(clang::interp::InterpState&, clang::interp::CodePtr, clang::interp::Integral<16u, true> const&, unsigned int)'
/usr/bin/ld: EvalEmitter.cpp:(.text._ZN5clang6interp11EvalEmitter7emitShlENS0_8PrimTypeES2_RKNS0_10SourceInfoE+0x1fd4): undefined reference to `bool clang::interp::CheckShift<clang::interp::Integral<32u, true> >(clang::interp::InterpState&, clang::interp::CodePtr, clang::interp::Integral<32u, true> const&, unsigned int)'
/usr/bin/ld: EvalEmitter.cpp:(.text._ZN5clang6interp11EvalEmitter7emitShlENS0_8PrimTypeES2_RKNS0_10SourceInfoE+0x2058): undefined reference to `bool clang::interp::CheckShift<clang::interp::Integral<32u, true> >(clang::interp::InterpState&, clang::interp::CodePtr, clang::interp::Integral<32u, true> const&, unsigned int)'

(etc)
2023-01-19 13:03:20 +01:00
Timm Bäder
2dbcfd298f Revert "[clang][Interp][NFC] Move CheckDivRem() implementation into Interp.cpp"
This reverts commit 9ee0d7494eb35f5addefcb730cdf5c002ddeacd2.
2023-01-19 12:37:20 +01:00
Timm Bäder
9ee0d7494e [clang][Interp][NFC] Move CheckDivRem() implementation into Interp.cpp
Just like we do with all the other Check* functions.
2023-01-19 12:18:34 +01:00
Timm Bäder
fddf6418e8 [clang][Interp][NFC] Remove shift error checking code duplication 2023-01-19 12:18:26 +01:00
Timm Bäder
9308014195 [clang][Interp] Diagnose uninitialized array record fields
Just like we do for record members, diagnose uninitialized array record
fields.

Differential Revision: https://reviews.llvm.org/D136828
2023-01-19 11:07:51 +01:00
Timm Bäder
6b0cd497b0 [clang][Interp] Check Field initialization after constructor call
Differential Revision: https://reviews.llvm.org/D136694
2023-01-19 09:42:22 +01:00
Timm Bäder
48655f72f9 [clang][Interp][NFC] Fix typo in comment 2022-12-28 12:08:29 +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
c8341a6615 [clang][Interp][NFC] Avoid a getSource() call in the common case
In the common (successful) case, we don't need the getSource() call, so
move it to the two if statement bodies instead.
2022-11-07 09:42:41 +01:00
Timm Bäder
6e7f421e55 [clang][Interp][NFC] Fix a file header comment 2022-10-28 12:49:38 +02: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
cc79ddb52c [clang][Interp] Check instance pointers before calling functions on them
Remove the double Call() implementation to reduce code duplication. Then
fix Function::getSource() so we can diagnose instance pointers being
null.

Differential Revision: https://reviews.llvm.org/D135513
2022-10-22 10:32:05 +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
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
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
Aaron Ballman
6a30894391 C++2a -> C++20 in some identifiers; NFC. 2020-04-21 15:37:19 -04:00
Richard Smith
2b4fa5348e For P0784R7: compute whether a variable has constant destruction if it
has a constexpr destructor.

For constexpr variables, reject if the variable does not have constant
destruction. In all cases, do not emit runtime calls to the destructor
for variables with constant destruction.

llvm-svn: 373159
2019-09-29 05:08:46 +00: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
Nandor Licker
afcb3de117 [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: 370584
2019-08-31 15:00:38 +00:00
Nandor Licker
0300c3536a Revert [Clang Interpreter] Initial patch for the constexpr interpreter
This reverts r370531 (git commit d4c1002e0bbbbab50f6891cdd2f5bd3a8f3a3584)

llvm-svn: 370535
2019-08-30 21:32:00 +00:00
Nandor Licker
d4c1002e0b [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: 370531
2019-08-30 21:17:03 +00:00
Nandor Licker
5c8b94a672 Revert [Clang Interpreter] Initial patch for the constexpr interpreter
This reverts r370476 (git commit a5590950549719d0d9ea69ed164b0c8c0f4e02e6)

llvm-svn: 370481
2019-08-30 15:41:45 +00:00
Nandor Licker
a559095054 [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: 370476
2019-08-30 15:02:09 +00:00