3184 Commits

Author SHA1 Message Date
Jonas Hahnfeld
b1db1932ef Try to avoid crashes in llvm::identify_magic (#11174)
The overload taking a path opens the file and then mmap its contents.
This can cause bus errors when another process truncates the file
while we are trying to read it. Instead just read the first 1024 bytes,
which should be enough for identify_magic to do its work.
2022-08-12 14:29:05 +02:00
Jonas Hahnfeld
52fdb631cf Use logical operators for boolean operands (#10787)
This addresses a warning of recent Clang versions about the "use of
bitwise '|' with boolean operands [-Wbitwise-instead-of-logical]".
2022-07-27 11:44:07 +02:00
Enrico Guiraud
5f0c2a38ae Remove unused include of "llvm/Config/config.h"
Including that header from cling breaks building ROOT with
external llvm and clang (which is needed e.g. for the conda
package): `config.h` is not avaiable in that scenario.
2022-06-08 15:14:03 +02:00
Guilherme Amadio
bbc1089732 Add support for profiling/debugging interpreted/JITted code
This commit builds on previous work for getting GDB support for JITted
and interpreted code working in cling. It adds a JIT event listener as
well to create perf map files to allow profiling of interpreted/JITted
code with cling.

The functionality provided is disabled by default. The interface to
enable it has been chosen to be via environment variables to allow both
interpreted code in the prompt as well as linked code to be able to
optionally enable debugging/profiling. Using ld.so as example, where
LD_DEBUG and LD_PROFILE exist, we chose CLING_DEBUG and CLING_PROFILE
to enable these features. For the moment, setting these variables to
anything enables the feature. Later on, if support for oprofile is
added, for example, it may be better to enable specific JIT event
listeners depending on the value of the variables, for example with
CLING_PROFILE=perf or CLING_PROFILE=oprofile, respectively.
2022-06-07 21:59:05 +02:00
Simeon Ehrig
521bf307eb Fix crash, if cling is started with the arguments -xcuda -fsyntax-only
The crash occurs due to a missing guard that prevents `libcudart.so` from being
loaded. Loading a library requires an executor which is not available in
syntax-only mode.
2022-05-30 17:59:03 +02:00
Simeon Ehrig
5754b5ada3 DynamicLibraryManager::loadLibrary if the parameter resolve is false
The error occurs only when `loadLibrary()` is called with the argument `resolved = false`.
A const string reference is not possible here because a temporary copy of
lResolved would be referenced. The return type of libStem.str() has the
value type prvalue. Therefore, lResolved requires the same type and the
compiler inserts a copy constructor to satisfy this. For more details
see rule 3.3.1 here:
https://en.cppreference.com/w/cpp/language/operator_other#Conditional_operator
2022-05-19 15:29:04 +02:00
Jonas Hahnfeld
da46c747a1 Do not throw CompilationExceptions on Apple M1 (#10561)
See https://github.com/root-project/root/issues/7541 for details.

Closes #7744
2022-05-11 14:14:04 +02:00
Sergey Linev
460e7b8877 Use override syntax in cling classes 2022-05-06 20:59:03 +02:00
Axel Naumann
4d3d8b6ca3 .typedef: separate underlying and type alias name by space. 2022-04-26 14:14:02 +02:00
ferdymercury
b6e5c228bf fix missing newline also for class 2022-04-26 14:14:02 +02:00
ferdymercury
f7a3d879ac add missing newline
otherwise .typedef command shows weird format
2022-04-26 14:14:02 +02:00
ferdymercury
6486be661b Allow '.Class' command to take a class name
* make .Class the verbose equivalent of .class and take into account name passed to .Class. As it was the case in CINT.
* merge similar functions into one with a verbose arg
2022-04-25 17:44:06 +02:00
ferdymercury
877dbb58b4 Minor aesthetic fix in cling '.help' message
fix indentation
2022-04-25 17:44:06 +02:00
ferdymercury
19a2c1b73e Improve output of .help command
Co-authored-by: Javier Lopez-Gomez <javier.lopez.gomez@cern.ch>
2022-04-05 23:44:05 +02:00
ferdymercury
e359b1bacd add short version of help, as in quit (#10055)
* MetaSema: add short version of help, as in quit
Primer: join help and ?, mention .quit and .exit
TRint: mention .?
TApplication: mention .? and CINT 2 Cling

* clarify class name with ROOT7
2022-03-15 11:29:03 +01: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
Axel Naumann
b651b2bdb4 DynamicLibraryManagerSymbol.cpp formatting (NFC). 2022-02-24 18:14:07 +01:00
Axel Naumann
1eceb4880a realpath: add continue back, fixing https://github.com/root-project/root/pull/9911
(cherry picked from commit 573e70bf979a764ec2221eecb3db5b87bea2dad6)
2022-02-23 09:29:06 +01:00
Javier Lopez-Gomez
e9474a2fc9 ValuePrinter: minor readability improvement 2022-02-22 17:59:04 +01:00
Javier Lopez-Gomez
ba4ece8f3d ValuePrinter: for auto decls, we should use the deduced type
Value printing an expression of type `AutoType` ended up in calling the general
fallback `printValue(const void *)`.
To call the appropriate overload, the deduced type should be used instead.

Fixes ROOT-9687.
2022-02-22 17:59:04 +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
Axel Naumann
c20559d390 Do not skip hidden directories:
path elements starting with "." should not be ignored, only "./" itself.
Fixes issue #9697.
2022-02-17 09:59:03 +01:00
Jonas Rembser
a6e4261e51 Remove unused variables to fix build warnings on mac11arm 2022-02-15 14:59:08 +01:00
Javier Lopez-Gomez
1ebe5a8c91 Minor readability/aesthetic changes
Co-authored-by: Axel Naumann <Axel.Naumann@cern.ch>
2022-02-11 01:59:05 +01:00
Javier Lopez-Gomez
0d71789370 Diagnose shadowing of decls in the std namespace
Related to the discussion in ROOT-5971 (see https://sft.its.cern.ch/jira/browse/ROOT-5971),
this commit improves the situation by diagnosing the shadowing of declarations
in the `std` namespace.

In summary, given that ROOT issues an implicit `using namespace std;` and due to
the way `SemaLookup` works, decls that shadow something in the `std` namespace
cannot be referenced without using their fully-qualified name, i.e. `::xxx`.
Thus, we need to emit a warning for that case.
2022-02-11 01:59:05 +01:00
Javier Lopez-Gomez
2e500a3fb8 Add Interpreter::m_InputFlags
This member provides additional information about the context in which parsing
occurs.
In particular, the `kInputFromFile` and `kIFFLineByLine` flags allow to tell
whether a sequence of calls to `Interpreter::process()` is issued from
`MetaProcessor::readInputFromFile()` for the contents of an external file.
2022-02-11 01:59:05 +01:00
Javier Lopez-Gomez
56ec372a51 Extracted decls should be unconditionally moved to the parent DeclContext
Declarations extracted by DeclExtractor, regardless of their type, should be
moved to the parent declaration context (be it the `TranslationUnitDecl` or a
`NamespaceDecl` if DefinitionShadower is enabled).

This prevents the following situation:
```
root [] struct X {} foo
(struct X &) @0x7f545a5ff018
root [] .stats asttree
|-NamespaceDecl 0x5647ecc93780 <<invalid sloc>> <invalid sloc> __cling_N50 inline
| |-VarDecl 0x5647ecc89f10 <ROOT_prompt_0:1:1, col:13> col:13 used foo 'struct X':'X' callinit
| | `-CXXConstructExpr 0x5647ecc8a420 <col:13> 'struct X':'X' 'void () noexcept'
| `-FunctionDecl 0x5647ecc89bc8 <input_line_8:1:1, ROOT_prompt_0:3:1> input_line_8:1:6 __cling_Un1Qu30 'void (void *)'
...
|-CXXRecordDecl 0x5647ecc89c98 <line:1:1, col:11> col:8 struct X definition
```
2022-02-05 03:59:07 +01:00
Javier Lopez-Gomez
b20c0fba6c Make enumerators in a scopeless enum visible in the enclosing scope
A bug in DeclExtractor was preventing names introduced by an anonymous scopeless
enum to become available in the parent scope.

Fixes ROOT-6095.
2022-02-03 09:29:03 +01:00
Javier Lopez-Gomez
9ea7dd97e3 Add MetaProcessor::awaitingMoreInput()
`MetaProcessor::awaitingMoreInput()` returns whether the collected input is
incomplete, either because it contains unbalanced braces or we found a
backslash-newline (the last seen token is a `\`).

Part of a patch series to fix ROOT-5219.

Co-authored-by: Axel Naumann <Axel.Naumann@cern.ch>
2022-01-31 19:29:04 +01:00
Javier Lopez-Gomez
71cbd0a80e Add InputValidator::getLastResult() member function
`InputValidator::getLastResult()` returns the validation result of the last call
to `validate()`.
This will be used to implement `MetaProcessor::awaitingMoreInput()`.

Part of a patch series to fix ROOT-5219.
2022-01-31 19:29:04 +01:00
Javier Lopez-Gomez
288488c35b Revert "[cling] Enable -Wredundant-parens"
This reverts commit eb52895d22aaad0a88d47b8e7bb18c7f47ff35be.

As discussed, we should try to make clang parse input containing solely a
function-style cast (e.g. `bool(i)`) as an expression instead of a declaration.

In the interim, this patch is reverted to silence unwanted warnings in
third-party code.
The PR https://github.com/root-project/root/pull/9695 will also be closed.
2022-01-26 16:14:05 +01:00
Jonas Hahnfeld
b8d15115a3 Fix AutoSynthesizer on CXXTryStmt (#9691)
This was an oversight in commit 34590aeef4: After fixing the handler
blocks, the code needs to create new CXXCatchStmts to eventually
construct the CXXTryStmt.

Fixes #9664
2022-01-26 14:44:08 +01:00
Axel Naumann
5440500f0b Only add NullPtrChk if enabled. 2022-01-26 10:29:05 +01:00
Axel Naumann
c6dcc185a8 With O1 being default, also set NDEBUG. 2022-01-13 17:59:04 +01:00
Axel Naumann
c0eed39bfe Remove backtrace on invalid ptr:
As the JIT does not provide debug symbols (yet), users see
only the call frames invoking the JIT - which is not helpful
as it is unrelated to their code.

We can turn this back on (possibly restricting to JIT frames)
once we emit debug symbols in the JIT.
2022-01-12 09:29:04 +01:00
Axel Naumann
9154e98478 Introduce --ptrcheck, disabled by default:
With more focus on performance of cling, disable the pointer check by default.
Can be enabled by passing --ptrcheck to the invocation / construction.
2022-01-11 18:29:04 +01:00
Axel Naumann
bd4b710e6a Complain about __cling__ptrcheck not being on or off. 2022-01-11 18:29:04 +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
Jonas Hahnfeld
29d368ec6b Implement -mllvm for option passing to LLVM 2021-12-02 08:29:08 +01:00
Jonas Hahnfeld
f4641c0cb0 Remove unused CUDAFatbinaryArgs 2021-12-02 08:29:08 +01:00
Karel Balej
c1a6a8a634 concretize condition 2021-11-23 10:44:03 +01:00
Axel Naumann
517d7e4bca Revert "[cxxmodules] Enable a module if json is present."
This reverts commit 0cdfa69f216854d7319a6a31a61021a1e5ac45de.
We need to hide json includes: modules cannot cope with them, and it introduces a runtime requirement to find json.
2021-11-12 16:29:06 +01:00
Axel Naumann
a860c891d4 EvaluateInternal: capture ValuePrinting request early:
`RunFunction()` might trigger unloading of `lastT`, so store its setting
for "want value printing" in a local variable before calling RunFunction().

Fixes valgrind complaining about `./stressInterpreter` which is reloading
the "outer" stressInterpreter.cxx from inside `RunFunction()`.
2021-11-12 16:14:06 +01:00
Axel Naumann
3afd3b4056 ReuseExistingWeakSymbols: prevent stale symbol emission:
When determining whether a weak symbol was already emitted (and its
subsequent definition can thus be replaced by a declaration) look
for emitted symbols in the symbol table and the in-process symbols,
instead of possibly generating symbols through the JIT. This prevents
symbols being emitted that refer into
IncrementalExecutor::m_PendingModules elements that have since been
removed.
2021-11-12 16:14:06 +01:00
Axel Naumann
234772da1c Prevent traling whitespace in -isystem. 2021-11-12 16:14:06 +01:00
Axel Naumann
9fb41f09f0 Let opt of transaction decide on inlining, fixes O3. 2021-11-12 16:14:06 +01:00
Vassil Vassilev
605924e143 Enable a module if json is present. 2021-11-06 08:14:07 +01:00
Javier Lopez-Gomez
9eef0a1354 Remove unneed assert()
The case of `ExprAddresses == nullptr` seems to be naturally handled in the
lines below. Therefore, removing this assertion -as discussed with vvassilev.

Closes issue #8389.
2021-11-04 19:29:05 +01:00
Axel Naumann
9a8996f714 Remove llvm_unreachable:
This is now hit for variables on Windows (which don't see the GlobalVariable case).
Before the `#ifndef WIN32`, this case was not hit by roottest, neither on Windows
nor macOS nor Linux - so the coverage of "make it a declaration" is good.
2021-10-14 15:14:05 +02:00