Commit Graph

681 Commits

Author SHA1 Message Date
Jonas Hahnfeld
6466a6dfe9 Only execute void expression in MultipleInterpreters.C
It was probably an accident and currently leads to an assertion (that
will be fixed in the next commit).
2023-07-20 08:44:03 +02:00
Jiang Yi
b9e8886af7 Extend test/Prompt/decls.C to test ctor, dtor and operator 2023-07-18 20:14:07 +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
Jiang Yi
a1b1c875fd startup script support
Before showing command promt or executing scripts from argv,
enumerate .C files in the directory ${CLING_HOME}/.cling.d/ in alphabetic
order then .x them.

Search order of ${CLING_HOME}:

1. ${CLING_HOME} envvar
2. ${XDG_CONFIG_HOME}/cling/
3. ${HOME}/.config/cling/
4. ${HOME}/
2023-06-16 16:29:08 +02:00
Javier Lopez-Gomez
5ca904dabd Fix DynamicLibraryManager/cached_realpath.C test
Fetching the value of `errno` only makes sense after a failed call to
`realpath()`, i.e. if the return value of the function is NULL.
2023-05-19 23:29:06 +02:00
Javier Lopez-Gomez
4d49306895 Fix DynamicLibraryManager/callable_lib_L_AB_order1.C test
`--enable-new-dtags` is needed in some toolchains to emit the new ELF dynamic
tags, i.e. RUNPATH.
Per ld(1) manual page: `By default, the new dynamic tags are not created.`
2023-05-19 23:29:06 +02:00
Javier Lopez-Gomez
e635331e85 Fix CodeUnloading/Macros.C test
Clang diagnostic verification was unhappy with the previous state of
affairs. Move affected `expected-(warning|note)` markers to `Macros.h`.

Apparently, as Jonas Hahnfeld found, this failure originated in commit
8deb57c04a5ceea96533d095092fcd4f71d1df94, but is not to be reverted
per discussion in https://github.com/root-project/root/pull/12454.
2023-05-19 23:29: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
Vassil Vassilev
5add0d7732 Rename simplisticCast to castAs. 2023-02-03 07:29:07 +01:00
Jiang Yi
1d5536fd0b Test cmd history support 2023-01-25 13:59:06 +01:00
Simeon Ehrig
0ee3ebcb5b Fixed bug in symbol linking for CUDA kernel registration with LLVM 13.
Since cling was ported to LLVM 13, it is required that the
`__cuda_register_globals` function and the `__cuda_fatbin_wrapper` and
`__cuda_gpubin_handle` variables are unique when defining a CUDA kernel.
Otherwise, the JIT is lazy and reuses the compiled version of
`__cuda_register_globals`, `__cuda_fatbin_wrapper` and `__cuda_gpubin_handle`
from the first CUDA kernel definition for all subsequent CUDA kernel
definitions, which in practice means that the PTX code from the first kernel is
re-registered each time.

Increase the default CUDA SM level to 35 because SM 20 is deprecated or
removed in the current CUDA SDK versions.
2022-12-09 08:44:19 +01:00
Jonas Hahnfeld
b721467e15 Fix emission of vtables
It is (again) necessary to call DefineUsedVTables() to enable (at
least) the emission of implicitly defined destructors overriding
the virtual destructor in a base class, see the added test.
2022-12-09 08:44:19 +01:00
Vassil Vassilev
6656a92d22 Diagnostic text changed 2022-12-09 08:44:18 +01:00
Vassil Vassilev
a656f18868 Print a<b<c> >' rather than 'a<b<c>>' in the Transform.C test.
See llvm/llvm-project@159a9f7e76
2022-12-09 08:44:18 +01:00
Axel Naumann
cf44b102bf Fix cached_realpath.C test by removing stale test dir. 2022-05-31 15:44:05 +02:00
Jonas Hahnfeld
35b71f2d93 Fix test/DynamicLibraryManager/callable_lib_L_AB_abs.C (#10542)
Just pass the absolute path, do not prefix with -l which confuses ld.
2022-05-11 09:44:06 +02:00
Javier Lopez-Gomez
9d09611d77 TransactionUnloader: ensure function instantiations are processed only once
Implicit instantiation of a function template calls
`DeclCollector::HandleCXXImplicitFunctionInstantiation()`, which appends the
FunctionDecl to the transaction.  According to clang documentation, the body of
the function has not yet been instantiated. `HandleTopLevelDecl()` will be
called again for this decl at the end of the TU, which will append it
again to the transaction - same `Decl *`, different ConsumerCallInfo.

This is by design. However, unloading of decls in the transaction should
not process the same `Decl *` twice. In particular, entries with ConsumerCallInfo
== `kCCIHandleCXXImplicitFunctionInstantiation` will omitted.

Fixes issue #9850.
2022-03-03 18:29:03 +01:00
Javier Lopez-Gomez
2ec73dd62a DeclUnloader: reset the anonymous namespace in the enclosing DC
From SemaDeclCXX.cpp:
```
C++ [namespace.unnamed]p1.  An unnamed-namespace-definition behaves as if it
were replaced by
     namespace unique { /* empty body */ }
     using namespace unique;
     namespace unique { namespace-body }
where all occurrences of 'unique' in a translation unit are replaced by the same
identifier and this identifier differs from all other identifiers in the entire
program.
```

Thus, the first declaration of an unnamed namespace creates an implicit
UsingDirectiveDecl that makes the names available in the parent DC.

If we are reverting such first declaration, make sure we reset the anonymous
namespace for the parent DeclContext so that the implicit UsingDirectiveDecl
is created again when parsing the next anonymous namespace.

Fixes issue #7483.
2022-03-01 12:59:03 +01:00
Javier Lopez-Gomez
970b844364 Add test against ROOT-9687 2022-02-22 17:59:04 +01:00
Vassil Vassilev
abe65b3bed Add forgotten comment as part of d7da914fa0 2022-02-22 15:59:06 +01:00
Vassil Vassilev
96fccb8e76 Do not alter the llvm::Module when running the static inits.
This change was from MCJIT times and now is not needed anymore. Moreover, the
orcv2 jit infrastructure considers the llvm::Module immutable after it takes
control of it via emitModule. This change will allow us to migrate easier to
orcv2.
2022-02-18 10:14:08 +01:00
Javier Lopez-Gomez
acfb998188 Improve DeclShadowing.C test
Check also the declaration context, which should be an inline namespace if the
DefinitionShadower is enabled or the TU otherwise.
2022-02-05 03:59:07 +01:00
Javier Lopez-Gomez
2766ad8421 Add test against ROOT-6095 2022-02-03 09:29:03 +01:00
Axel Naumann
52266ba5eb Turn on prtcheck for the ptrcheck tests. 2022-01-11 18:29:04 +01:00
Vassil Vassilev
884df027c3 Fix bugs in cling's tests.
Patch by Alexander Penev (@alexander-penev).
2022-01-07 16:29:03 +01:00
Vassil Vassilev
4fa39ba82f Do not resolve symbols from executables compiled with -fPIE.
Executables that are compiled with fPIE means they are compiled in a position
independent manner and are almost indistinguishable from the shared objects. A
reasonably reliable way to find if this was a `pie executable` is to check the
`DF_1_PIE` in the dynamic section of ELF.

The pseudo-code is:
```
if DT_FLAGS_1 dynamic section entry is present
  if DF_1_PIE is set in DT_FLAGS_1:
    print pie executable
  else
    print shared object
```

See https://stackoverflow.com/questions/34519521/why-does-gcc-create-a-shared-object-instead-of-an-executable-binary-according-to/34522357#34522357

Fixes root-project/root#7366

Patch by Alexander Penev (@alexander-penev)
2022-01-07 16:29:03 +01:00
Javier Lopez-Gomez
8d98340299 InputValidator::validate(): add test against ROOT-9202 2021-09-08 19:14:06 +02:00
Vassil Vassilev
d36bfe15e4 Ask for the real path in any case. 2021-08-07 09:29:07 +02:00
Vassil Vassilev
55a4e89b3b Fix ROOT-10484 by implementing dyld support for RPATH.
Some libraries are layered can depend on other libraries on a private paths.
That is, libA can depend on libB which is neither on the LD_LIBRARY_PATH nor
on a known system path. The posix linker injects "variables" such as @rpath
which is expanded at link time to resolve the libraries on a relative path.

Prior to this patch, cling's Dyld-based symbol resolution could not trace down
such cases causing failures in symbol resolution when a symbol is only defined
in libB (a private library).

This patch implements the basic posix linker substitutions allowing cling's
Dyld-based symbol resolution implementation to follow more closely the linker
rules.

Kudos Alexander Penev (@alexander-penev).
2021-08-07 09:29:07 +02:00
Vassil Vassilev
561e905b24 Use the dyld to show more meaningful message when a symbol is missing.
The dynamic library manager's dyld can search a symbol in the library path.
This patch uses that functionality to aid the 'unresolved while linking'
diagnostics.

Now we get:

cling -L lib/

****************** CLING ******************
* Type C++ code and press enter to run it *
*             Type .q to exit             *
*******************************************
[cling]$ extern int gErrorIgnoreLevel;
[cling]$ gErrorIgnoreLevel
IncrementalExecutor::executeFunction: symbol 'gErrorIgnoreLevel' unresolved while linking [cling interface function]!
Symbol found in '/.../lib/libCore.so'; did you mean to load it with .L /.../lib/libCore.so ?
[cling]$
2021-05-08 20:59:07 +02:00
Axel Naumann
2b1af22926 In failed lookup, unload only decls produced, not existing fwd decl:
Before, pre-existing fwd decls of specializations got unloaded.

OTOH, any decl produced during (failed) template instantiation must
also be unloaded; see #6331. Those are easiest identified by unloading
the whole (failed) transaction.

```
error: no member named 'value' in 'std::__and_<std::is_copy_assignable<std::__cxx11::basic_string<char> >, std::is_copy_assignable<Inner<int> > >'
                       is_copy_assignable<_T2>>::value,
                       ~~~~~~~~~~~~~~~~~~~~~~~~~~^
```

which is due to the first decl being invalid (as `Inner<int>` does not have a deinition and a `static_assert` /usr/lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/type_traits:1093 being triggered), then not unloaded, and then picked up again where we *do* have the definition for `Inner<int>`.

Add test for templt spec lookup vs unloading.
2021-03-18 19:59:03 +01:00
Axel Naumann
b921ac814a Bring vanilla-cling lit feature back:
it is needed for test/Autoloading/AutoForwarding.C.
2021-03-16 09:59:04 +01:00
Axel Naumann
897701fb24 Help test find its parts:
was failing before but due to `REQUIRES: vanilla-cling` not run.
2021-03-16 09:59:03 +01:00
Axel Naumann
608a992e5f Fix expected diags in test/Pragmas/load.C:
A failure to load the library will *not* trigger loading the
same file as a source file: `#pragma load` will cause zero or
one diagnostics, not two.

Now that the diagnostic for a missing file to be `#pragma load`ed
is "file not found", re-use the existing `expected-error@input_line_12`
line!.
2021-03-16 09:59:03 +01:00
Simeon Ehrig
be5ea3a651 Fixed CUDA mode for Clang/LLVM 9 upgrade
- fix bug, which was caused by executing a transaction in the device
interpreter
- fixed warning from the device compiler
- update test cases
2021-02-25 20:44:19 +01:00
Axel Naumann
b118f4dee3 Get rid of extra-complex built_cling:
that is anyway what we want to test, always.
And nothing seems to set the env var.
2021-02-25 20:44:18 +01:00
Axel Naumann
ffc267b9dd Import updated lit config:
Copy and adapt lit.cfg from clang.
Export the CMake variable cling needs.
Add missing, now needed call to lit.llvm.initialize.
Remove unused "loadable_module" feature.
2021-02-25 20:44:18 +01:00
Vassil Vassilev
fa7c45b1ca Orc JIT now takes the ownership of the llvm::Module.
The old JIT infrastructure assumed shared ownership of the llvm::Module
implemented via shared_ptr. This guaranteed each client can have a uniform
view of the llvm::Module. The new infrastructure claims ownership of the object
and even more transfer ownership when the llvm::Module travels through different
layers of the JIT. The claimed advantage is better thread safety.

The new logic defines away an important property which cling has been built
around, that is the shared symbol object ownership.

This patch makes the cling::Transaction the owner of the llvm::Module. The
ownership is transfered when we want the JIT to 'emit' the module. Fortunately,
there is a JIT callback which can transfer back the ownership to the transaction.

This preserves some consistency, however, makes some operations unsafe. For
example, we cannot rely on Transaction::getModule when the module is being
handed to the JIT.

This patch tries to adapt to the new infrastructure by reducing the dependency
on the transaction's llvm::Module in favor of relying more on the information
available in the execution engine (eg. at_exit handling).
2021-02-25 20:44:17 +01:00
Vassil Vassilev
2d1a60d163 Drop support of #pragma cling load header.h
llvm-mirror/clang@444665e219 says:
"Remove use of lookahead from _Pragma handling and from all other

internal lexing steps in the preprocessor.

It is not safe to use the preprocessor's token lookahead except when
operating on the final sequence of tokens that would be produced by
phase 4 of translation. Doing so corrupts the token lookahead cache used
by the parser. (See added testcase for an example.) Lookahead should
instead be viewed as a layer on top of the normal lexer.

Added assertions to catch any further incorrect uses of lookahead within
lexing actions."

This tells us that if we try to #include the header.h while processing the
2021-02-25 20:44:17 +01:00
Vassil Vassilev
401fbfdf90 Check for the expected diagnostics. 2021-02-25 20:44:17 +01:00
Vassil Vassilev
3f8a2221ed llvm9 fixes the printing of unscoped enums.
See llvm-mirror/llvm@2f52311
2021-02-25 20:44:17 +01:00
Vassil Vassilev
c32df9ba67 auto func requires c++14 2021-02-25 20:44:17 +01:00
Simeon Ehrig
e47bb75f9f Allows to configure CUDA sm level for Cling CUDA tests
- the CUDA sm level can be set via CLING_TEST_CUDA_SM_LEVEL
environment variable (e.g. "35"), before running the tests
2021-02-18 09:29:04 +01:00
Pratyush Das
e978660f35 Remove dependence on svn
LLVM repository has migrated from svn to git
2021-02-16 22:29:03 +01:00
Simeon Ehrig
b2bfd6e19f Extend the cling-test to deal with CUDA SDKs that are not in the default location
- To enable the CUDA test, lit detects the `libcudart.so` in
`LD_LIBRARY_PATH`. Now lit also set the CUDA SDK root of
`libcudart.so` as cling parameter (`--cuda-path`) in the tests.
- Pass through the environment variable `CUDA_VISIBLE_DEVICES`.
2021-02-10 15:18:14 +01:00
Jonas Hahnfeld
c7558a2c0d Reset function sections before JITting
This makes all functions end up in the same text section, which is
important for TCling on macOS to catch exceptions from constructors:
Stack unwinding requires information about program addresses to find
out which objects to destroy and what code should be called to handle
the exception. These addresses are relocated against a single __text
section when loading the produced MachO binary, which breaks if the
call sites of global constructors end up in a separate init section.

Fixes ROOT-10703 and ROOT-10962
2021-02-10 15:18:14 +01:00
Jonas Hahnfeld
173de1db30 Enable test for exceptions 2021-02-10 15:18:14 +01:00
Javier Lopez-Gomez
c054ac2840 added missing include in cling/test/CodeUnloading/DeclShadowing.C 2020-12-16 18:29:03 +01:00
Javier Lopez-Gomez
904796d2bb New interface to export Cling run-time configuration bits.
This commit allows the user to enable/disable specific interpreter capabilities
without requiring to `#include` the heavier weight `Interpreter.h` (that also
has dependencies on llvm).

The only feature covered at the moment is definition shadowing.

Closes cling issue #360.
2020-12-14 10:29:04 +01:00