Commit Graph

3362 Commits

Author SHA1 Message Date
Jonas Hahnfeld
dbb34a4450 Use standard way to set up OverlayFS
This makes it possible to drop our custom CompilerInvocation::addOverlay
functionality (but the rest of the patch that introduced it is still
needed with LLVM 13, so it cannot be reverted for now).
2023-07-11 11:59:07 +02:00
Vassil Vassilev
c2562c72b1 ParseTypeName might trigger deserialization. 2023-07-04 19:29:05 +02:00
Jonas Hahnfeld
4c7a2f1ba7 Add API to iterate already loaded specializations
This avoids deserialization if necessary, for example in DeclUnloader.

See also https://reviews.llvm.org/D154328
2023-07-04 19:29:05 +02:00
Maksymilian Graczyk
67235e8a2a Add jitlink to LLVM_LINK_COMPONENTS in relevant cling parts 2023-07-01 12:44:07 +02:00
Jonas Hahnfeld
30e1bd3c7d Remove checks for deprecated _REENTRANT macro
According to feature_test_macros, this macro is obsolete and "glibc
has been thread-safe by default for many years." Other platforms
don't use it at all, for example FreeBSD.

Some parts of ROOT used it to determine if we are compiling with
-pthread, but this is essentially unused these days because the
CMake build always enables threading support and there exists no
option to turn it off.
2023-06-30 11:14:03 +02:00
Jonas Hahnfeld
95cdce8055 Adopt upstream llvm-project monorepo directory layout (#13049)
This will be required for future LLVM upgrades that rely on a common
cmake/ directory next to clang/ and llvm/.

The bulk of this change is the result of the following commands:
 $ mkdir interpreter/llvm-project/
 $ git mv interpreter/llvm/src/tools/clang/ interpreter/llvm-project/clang/
 $ git mv interpreter/llvm/src/ interpreter/llvm-project/llvm/
 $ git mv interpreter/llvm/llvm-project.tag interpreter/llvm-project/llvm-project.tag
2023-06-25 13:44:07 +02:00
Mikolaj Krzewicki
acb2334131 Initial support for building on FreeBSD (#12996)
Co-authored-by: Mikolaj Krzewicki <Mikolaj Krzewicki mkrzewicki@gmail.com>
2023-06-22 11:14:05 +02:00
Jiang Yi
42e296f28c meta cmd .x should not crash if no arg is given 2023-06-07 21:59:06 +02:00
Javier Lopez-Gomez
1cca2f0f7e Restore symbol lookup in child interpreters
Prior to the upgrade to LLVM13, child interpreters used to also lookup symbols
in their parent.
This commit introduces a `DefinitionGenerator` that allows for symbol lookup
across different `IncrementalJIT` instances, which restores the old behavior.

This change fixes the following tests:
- CodeUnloading/AtExit.C
- MultipleInterpreters/MultipleInterpreters.C

Fixes #12455.
2023-05-31 21:29:03 +02:00
Javier Lopez-Gomez
09fe1fd2b3 DeclExtractor: use BuildReturnStmt() instead
Do not use `ActOnReturnStmt()`, given that the scope returned by
`m_Sema->getCurScope()` might be == m_Sema->TUScope which obviously is
not a function scope.

This fixes the following crash:
```
1:  #3 0x0000556b6a50389e clang::Sema::ActOnReturnStmt(clang::SourceLocation, clang::Expr*, clang::Scope*) (/home/jalopezg/CERN/repos/root/_build/interpreter/llvm/src/bin/cling+0x225389e)
1:  #4 0x0000556b69215c56 cling::DeclExtractor::EnforceInitOrder(llvm::SmallVector<clang::Stmt*>&) (/home/jalopezg/CERN/repos/root/_build/interpreter/llvm/src/bin/cling+0xf65c56)
1:  #5 0x0000556b69216788 cling::DeclExtractor::ExtractDecl(clang::FunctionDecl*) (/home/jalopezg/CERN/repos/root/_build/interpreter/llvm/src/bin/cling+0xf66788)
1:  #6 0x0000556b69216a75 cling::DeclExtractor::Transform(clang::Decl*) (/home/jalopezg/CERN/repos/root/_build/interpreter/llvm/src/bin/cling+0xf66a75)
```
2023-05-31 21:29:03 +02:00
Javier Lopez-Gomez
ef943ddcfa Always promote warn_falloff_nonvoid_function to error
This diagnostic should always be promoted to error, regardless of the ignoring
state in `FilteringDiagConsumer`.
This fixes the SourceCall/ErrorMacro.C test.

The failure became visible after merging
https://github.com/root-project/root/pull/12654, given that `IgnorePromptDiags`
now defaults to 0 in `makeDefaultCompilationOptions()`.
2023-05-19 23:29:06 +02:00
Javier Lopez-Gomez
11a1a348f8 DeclUnloader: remove TagDecls after all other decls
The order in which declarations are removed makes a difference, e.g.
`MaybeRemoveDeclFromModule()` may require access to type information to
make up the mangled name.

Thus, we segregate declarations to be removed in `TagDecl`s (i.e., struct
/ union / class / enum) and other declarations.  Removal of `TagDecl`s
is deferred until all the other declarations have been processed.
Declarations in each group are iterated in reverse order.

Fixes #12457.
2023-05-19 23:14:06 +02:00
Javier Lopez-Gomez
5f576a2ba8 DefinitionShadower: fix crash with C++20 concepts
In principle, for a TemplateDecl, `isDefinition()` issues a recursive
call passing the templated decl as a parameter.  A `ConceptDecl` is
derived from `TemplateDecl`, however, it should always be considered
a definition.

Also, update the DeclShadowing test incorporating a C++20 concept.

Fixes #12779.
2023-05-08 00:14:05 +02:00
Javier Lopez-Gomez
a0d186073b Ignore -Wunused-result in wrapped code
Make `FilteringDiagConsumer` also ignore -Wunused-result. Whether or not
such diagnostic is filtered depends on `CompilationOptions::IgnorePromptDiags`.

In particular, `IgnorePromptDiags` should _only_ be enabled for code parsed
via `Interpreter::EvaluateInternal()`.  Thus, as of this commit `IgnorePromptDiags`
defaults to 0 in `makeDefaultCompilationOpts()`

The observable effect of this change is ignoring `-Wunused-result` for
wrapped code, e.g.
```c++
[[nodiscard]] int f() { return 0; }

// This yields `warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result]`
void g() { f(); }

f(); // but this should not
```
2023-04-20 15:14:04 +02:00
Axel Naumann
eaaf95f5c8 Pass isysroot to clang when determining stdlib incpath:
isysroot influences where clang will pick up libc++. Without this, and with
Xcode 14.3, cling will use libc++ from Xcode (or the command line tools) rather
than stdc++ from the macOS SDK, as clang would normally use. Passing the isysroot
(which point to the SDK) fixes this.

This solves build errors such as:
```
While building module 'Core':
While building module 'std' imported from input_line_1:1:
In file included from <module-includes>:17:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/math.h:309:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/type_traits:462:1: error: cannot template a using declaration
using _BoolConstant _LIBCPP_NODEBUG_TYPE = integral_constant<bool, _Val>;
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/type_traits:462:21: error: C++ requires a type specifier for all declarations
using _BoolConstant _LIBCPP_NODEBUG_TYPE = integral_constant<bool, _Val>;
                    ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/type_traits:462:68: error: use of undeclared identifier '_Val'
using _BoolConstant _LIBCPP_NODEBUG_TYPE = integral_constant<bool, _Val>;
                                                                   ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/type_traits:462:73: error: expected '(' for function-style cast or type construction
using _BoolConstant _LIBCPP_NODEBUG_TYPE = integral_constant<bool, _Val>;
                                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
```
2023-04-06 13:59:05 +02:00
Jonas Hahnfeld
1499c8c74f Use compiled Module for stored states
Since the upgrade to LLVM 13, the JIT infrastructure takes ownership
of the Module. After JIT compilation, we get back a (const) pointer
to the compiled module.

This fixes the Cling test ErrorRecovery/StoredState.C.
2023-03-09 11:14:07 +01:00
Axel Naumann
33de07df48 Do not try to find runtime headers in ./:
These headers are part of cling, not user code, so starting
with the current directory is pointless and can actually be
counterproductive.

This helps with https://github.com/root-project/root/issues/12409
but not enough; any dictionary header will still try to access "./".
2023-03-03 17:59:05 +01:00
Jonas Hahnfeld
8c3b18f683 Forward ABIName to MCTargetOptions
This is required on RISC-V where Linux uses the lp64d ABI that allows
the usage of floating point registers to pass arguments. It seems to
work out-of-the-box upstream in clang-repl which passes through the
function initTargetOptions in clang/lib/CodeGen/BackendUtil.cpp with
the same effect.
2023-03-01 19:14:06 +01:00
Jonas Hahnfeld
eb82dc505a Use JITLink on RISC-V
RuntimeDyld does not support RISC-V, so it makes sense to enable
JITLink by default. This also makes relocations work without support
for a large code model.

See the equivalent change upstream in https://reviews.llvm.org/D129092,
committed for LLVM 15 in a4e2c1f762
2023-03-01 19:14:06 +01:00
Jonas Hahnfeld
e65614cb92 Disable outline-atomics on AArch64
The routines __aarch64_* are defined in the static library libgcc.a
and not necessarily included in libCling or otherwise present in the
process, so the interpreter has a hard time finding them.

Fixes #12294
2023-02-20 22:14:04 +01:00
Jonas Hahnfeld
75930f9dfd Set DataLayout from our TargetMachine (#12335)
Otherwise LLJIT's constructor will ask the LLJITBuilder's JTMB to
create a DataLayout. As we don't propagate the JTMB (yet -- we
probably should!), this will be wrong if target features influence
the DataLayout.

This should fix #12293.
2023-02-16 20:44:03 +01:00
Axel Naumann
e122c6dcc6 Revert "Disable GlobalISel on AArch64":
This reverts fcab0add4a79379b5087fe786261f4ab0cc9776a which is not
needed anymore since llvm13 / ORCv2 / JITLink.
2023-02-16 17:14:03 +01:00
Jonas Hahnfeld
38154308df Switch back to large code model for macOS on AArch64
It results in relocation targets that are out-of-range.
2023-02-07 08:59:05 +01:00
Jonas Hahnfeld
1d93ee8d58 Simplify creation of TargetMachine
We know exactly which target triple and features the CompilerInstance
wants, we don't need to (and probably must not) second-guess that. This
brings us closer to upstream clang-repl and also includes the change of
https://reviews.llvm.org/D128853 which is crucial for RISC-V.
2023-02-05 12:59:03 +01:00
Jonas Hahnfeld
1603be8b87 Set up TargetMachine for JITLink
I missed this in commit 3ff7c1e8e2 and it seems to work by chance on
macOS, but this is needed on Linux: Before, CLING_JTLINK=1 on x86_64
complained about "Unspported personality pointer encoding 0x00" and
crashed entirely on RISC-V.
2023-02-05 12:59:03 +01:00
Vassil Vassilev
6ef68e5512 Fix potential pre-existing issue for big endian 2023-02-03 07:29:07 +01:00
Vassil Vassilev
643cfe84ab Improve performance by allowing most of cling::Value to inline.
We introduce an enum which mirrors the type kind and we use it in the getAs and
castAs operations to allow the compiler/interpreter to see all of the functions
and potentially inline them.

This patch brings the performance to similar levels with what we have in the
master.
2023-02-03 07:29:07 +01:00
Vassil Vassilev
afadc28b05 Mark m_Storage as a const ref. 2023-02-03 07:29:07 +01:00
Vassil Vassilev
632aba9c56 Implement a rigorous type checking when we call getX and setX.
These interfaces assume we know the type and we should compare if the underlying
type is the one we expect when using the setters and getters. Unfortunately,
this is not the case and we need to further investigate.
2023-02-03 07:29:07 +01:00
Vassil Vassilev
5add0d7732 Rename simplisticCast to castAs. 2023-02-03 07:29:07 +01:00
Vassil Vassilev
320d63785f Improve the templated Create interface to capture compile-time types.
This interface allows us to set a value and deduce its corresponding type very
efficiently. This is useful when we use cling::Value to model input arguments
for a function call in the JIT (eg. via TClingCallFunc).

That patch essentially makes cling::Value to hold a value and a type that
correctly models the compiled code.
2023-02-03 07:29:07 +01:00
Vassil Vassilev
07c4469328 Improve consistency in cling::Value.
The improvements are:
  * We provide getX and setX interfaces instead of returning the address for the
    non const methods. This allows us to be more consistent in terms of
    lifetimes as now users cannot take the address of block of memory which can
    be freed by the cling::Value.
  * We remove the storage types and we rely on the clang::Type which we have in
    the cling::Value.
2023-02-03 07:29:07 +01:00
Vassil Vassilev
e18104aa12 Make function file static to reduce includes 2023-02-03 07:29:07 +01:00
Vassil Vassilev
44cac5e3af Implement more robust conversion via getAs in cling::Value.
Here we enumerate most of the builtin types and we the generate template
specializations for all of them which are capable to perform the correct
conversions.
2023-02-03 07:29:07 +01:00
Jonas Hahnfeld
dc6ee2401b Add back basic support for JITLink
The custom memory manager is only needed to avoid freeing the memory
segments; the default InProcessMemoryManager (which is mostly copied)
already does slab allocation to keep all segments together which is
needed for exception handling support.

A limitation of this rudimentary support is that CLING_DEBUG and
CLING_PROFILE do not work, they need to be registered as plugins.
2023-02-01 13:44:06 +01:00
Vassil Vassilev
93e72c9d88 Revert "[cling] Add dedicated C++20 stl-modulemap:"
This reverts commit 82f1619a7179088c61bedd2f5d38d158957c7bde.
2023-02-01 08:29:04 +01:00
Axel Naumann
b8edc28315 Add dedicated C++20 stl-modulemap:
The bits/ headers have different include behavior (mostly due to ranges)
that makes it significantly harder to find a configuration working for
C++14, 17, and 20. Instead, create a dedicated modulemap for C++20.
2023-02-01 08:29:04 +01:00
Axel Naumann
f2b325b312 Keep private symbols private:
llvm IR naming of private constants (CodeGenModule::createUnnamedGlobalFrom(),
line 1136) will name private symbols without caring about possible name clashes.
We will create these name clashes by marking such private symbols as weak ones,
re-using previously emitted symbols (e.g. in JITDylib::defineImpl() where they
get added to MUDefsOverridden and thus re-used instead of re-emitted).

Let me see what happens when we keep private symbols private. In principle, the
interpreter should have no means fo accessing them from another transaction -
private symbols seem to be function-local ones.

Fixes https://github.com/root-project/root/pull/12183
2023-01-31 22:59:06 +01:00
Jiang Yi
da57784037 Set history size to ${CLING_HISTSIZE}
It was left unset. Then the default hist size was

static_cast<size_t>(-1), which is practically equivalent to unlimited

history size.
2023-01-30 10:29:07 +01:00
ferdymercury
c3dd723262 fix some more warnings in core 2023-01-30 10:29:07 +01:00
Sergey Linev
f4d11176e6 Use nullptr in core/textinput classes 2023-01-30 10:29:07 +01:00
ferdymercury
a78c5a41eb Implement .help edit (show line editor keybindings)
Co-authored-by: Javier Lopez-Gomez <javier.lopez.gomez@cern.ch>
Co-authored-by: Olivier Couet <Olivier.Couet@cern.ch>
2023-01-30 10:29:07 +01:00
Javier Lopez-Gomez
401f877780 Do not assign ESC a special meaning on history search mode
UNIX terminals, e.g. vt100, send escape sequences for many special
key combinations. Entering the history search mode assigned a specific
meaning to the ESC character and disabled the processing of escape
sequences, thus accidentally printing some characters that are part
of a CSI.

As a workaround, avoid changing the meaning of ESC; users can still
use the well-known `ESC ESC` sequence (or any other editor command,
e.g. move left/right) to exit the history search mode.

This change only affects UNIX terminals.

Closes issue #10209.
2023-01-30 10:29:07 +01:00
ferdymercury
0d46b6dead Implement forward history search
Co-authored-by: Javier Lopez-Gomez <javier.lopez.gomez@cern.ch>

Fixes #10137
2023-01-30 10:29:07 +01:00
Javier Lopez-Gomez
07120b98da Clear undo buffer after taking an input line
The undo buffer should only be kept for the current line (as in GNU readline).

Fixes #10182.
2023-01-30 10:29:07 +01:00
ferdymercury
97166bc3b2 prevent accessing empty vector
Fixes https://github.com/root-project/root/issues/10180
2023-01-30 10:29:07 +01:00
Javier Lopez-Gomez
a575990cfc Fix implementation of the kCmdWordTo{Lower,Upper} editor commands
These commands, bound respectively to `ESC l` and `ESC u`, should {lower,upper}case
the next word; however, only the first character was changed.

Fixes #10136.
2023-01-30 10:29:07 +01:00
Javier Lopez-Gomez
01ffa06f0a Add a missing new-line after .q if quitting a ROOT session via Ctrl+D (EOF)
Fixes #10135.
2023-01-30 10:29:07 +01:00
Javier Lopez-Gomez
2dd8debdfb Fix implementation of kCmdSwapThisAndLeftThenMoveRight
This editor command (usually binded to Ctrl+T), transposes the character located
at the cursor and the one to its left.
However, its behavior was incorrect if the cursor was at end of the line,
invoking `std::string::operator[]()` passing an index that is out of bounds.

In that case, as per GNU Readline behavior, it should swap the two last
characters.

Closes #10133.
2023-01-30 10:29:07 +01:00
Javier Lopez-Gomez
3914be144e Bind Ctrl+Del to Editor::kCmdCutNextWord (kill next word)
This change is equivalent to the popular GNU Readline keybinding
```
"\e[3;5~": kill-word
```

As a requirement, the `[3;5~` CSI was added in StreamReaderUnix.cpp. No
additional changes required to StreamReaderWin.cpp.
2023-01-30 10:29:07 +01:00