Commit Graph

3111 Commits

Author SHA1 Message Date
Bertrand Bellenot
e7ae55720e Fix a crash when using an undeclared identifier (Jira #ROOT-10193) 2019-09-24 15:14:12 +02:00
Vassil Vassilev
1a1a84dfcb Ignore import decls to delay the running module inits.
If we preload modules using cling::Interpreter::loadModule the
deserializations of the module initializers (such as global variables).

We want the behavior of clang::Sema::ActOnModuleImport, however, it requires
valid source locations.

This patch ignores the ImportDecls which presumably came from loadModule.
2019-09-20 13:14:06 +02:00
Vassil Vassilev
63e0a871c1 Quote the imported module.
In some cases we have dict.C which the modules system considers as two
components: one top-level module and one submodule.
2019-09-14 22:59:04 +02:00
Vassil Vassilev
d66199f99f Reland "[cxxmodules] Use common-rooted valid source location."
Original commit message:
"Over the years we have a pathological issue with cling when it calls directly
compiler API. Most of the API assume they are called from code residing in a
text file. This code has valid source locations which can be used for
comparisons and things like point of instantiation for template instantiations.

This means that whenever a clang API requires a valid source location, cling
should have an interface which gives a pseudo-valid, commonly-rooted unique
source location.

We are bitten by this fact when preloading modules as if we have diagnostics
they cannot be ordered due to the fact that the compared decls from two
different modules do not have a common includer.

This patch avoids using an API and relies on a textual form which does not have
this problem at the cost of synthesizing an extra string."
2019-09-14 07:59:43 +02:00
Axel Naumann
5446ed5a48 Allow /clang-7" -cc1 to ge found. 2019-09-10 16:29:09 +02:00
Philippe Canal
bd472f9b0a Clang-formatting 2019-09-09 19:15:34 +02:00
Philippe Canal
8b906da196 Expand StartParsingRAII
In particular the CachedTokens need to be pushed/pop or otherwise
give misleading information.

This fixes ROOT-10224.
2019-09-09 19:15:34 +02:00
Vassil Vassilev
1a53d8241d Revert "[cxxmodules] Use common-rooted valid source location."
This reverts commit 03febcbd899610de1188886a132fe78c804d3a00.

This commit broke the modules bots. Investigating...
2019-09-04 15:14:06 +02:00
Vassil Vassilev
b47bbaf546 Use common-rooted valid source location.
Over the years we have a pathological issue with cling when it calls directly
compiler API. Most of the API assume they are called from code residing in a
text file. This code has valid source locations which can be used for
comparisons and things like point of instantiation for template instantiations.

This means that whenever a clang API requires a valid source location, cling
should have an interface which gives a pseudo-valid, commonly-rooted unique
source location.

We are bitten by this fact when preloading modules as if we have diagnostics
they cannot be ordered due to the fact that the compared decls from two
different modules do not have a common includer.

This patch avoids using an API and relies on a textual form which does not have
this problem at the cost of synthesizing an extra string.
2019-09-04 12:44:07 +02:00
Axel Naumann
6a73fd08d2 Help ValuePrinter find the transaction:
If the ValuePrinter runtime header gets included,
a transaction might be emitted, and the transaction
containing the function body cannot be found anymore.
This causes roottest/root/meta/getFuncBody.C to fail
with runtime modules.
2019-09-01 09:15:17 +02:00
Stephan Hageboeck
522a43fa0e Improve help message when .x fails.
A more informative warning is issued when a macro does not
contain a function to be called.
2019-08-26 18:29:18 +02:00
Javier Lopez-Gomez
a829d76c10 Fix SIGSEGV after executing the `.stats decl' metacommand 2019-08-16 16:59:04 +02:00
Guilherme Amadio
0d3fb9dbf4 Simplify query for include directories
- Use only sed instead of awk and grep
- Use regex independent of locale settings
2019-08-14 14:59:45 +02:00
Guilherme Amadio
111fa41390 Add assertion to ensure that page_size is a power of two 2019-08-08 18:14:03 +02:00
Nikita Ermakov
4b61a2134b Little optimization for the cling pointer check.
Use precalculated PAGE_MASK which is equals to ~(page_size - 1) at
pointer check instead of recalculate it each check.
2019-08-08 17:14:46 +02:00
Guilherme Amadio
0c6588cd0c Fix cling valid pointer check
Assuming that page_size is a power of 2, the calculation of the
base address of the page can be simplified and avoid a division.

According to POSIX, either MS_SYNC or MS_ASYNC must be specified
when calling msync(). Failure to include one of these flags will
cause msync() to fail on some systems.

When msync() returns -1, the pointer is only considered invalid
when errno is set to ENOMEM. In principle, the other possible
values for errno won't happen, but if they do, that should be
considered an error, hence the assert condition needed an update.
EBUSY shouldn't happen since we do not add MS_INVALIDATE to flags,
and EINVAL shouldn't happen because we always pass a multiple of
the page size to msync(). EFAULT is only used in Linux 2.4.18 and
earlier instead of ENOMEM.
2019-08-07 16:29:14 +02:00
Nikita Ermakov
d1faf4e905 Change pointer check method to msync.
The POSIX does not contains /dev/random [1]. Moreover the /dev/random
might not have write permissions. The better way is to use an another
solution which is based on the msync system call [2]. Also this solution
reduces the number of context switching.

[1] -- https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap10.html
[2] -- https://pubs.opengroup.org/onlinepubs/009695399/functions/msync.html
2019-08-06 19:59:22 +02:00
Raphael Isemann
8446b953c2 Rename stl module to std
libc++ comes with a builtin modulemap and is using "std" as the
module name for the STL. To stay consistent we should use the same
name (and "std" is anyway a better name).
2019-07-25 17:59:15 +02:00
Bertrand Bellenot
8352541d0a Remove the -DUNICODE and -D_UNICODE definitions on Windows
Don't use Unicode in the User Interface (command prompt), it has side effects (the prompt displays empty squares instead of readable characters)
2019-07-22 11:14:11 +02:00
Vassil Vassilev
a63b8f1ec7 Mark library search paths system and user accordingly.
We have user library search paths which come from LD_LIBRARY_PATH or similar;
and system library search paths which are coming from the platform.

This patch enables external users performing symbol resolution to filter out
system search paths when they know the symbol cannot be there.

Now, TClingCallbacks can merge the modules vs non-modules code paths, where
the modules prebuilt path is essentially our LD_LIBRARY_PATH.
2019-07-18 20:59:17 +02:00
Axel Naumann
a3f236fe36 Use canary bytes to determine whether to run dtor:
If the constructor of the contained object is not run (e.g. because
assembling its arguments triggered an exception), the dtor must not
be run when destructing the cling::Value. Detect this case by imprinting
canary bytes into the contained object bytes: if they have changed,
run the dtor, if not assume that the constructor has failed.

This will cause false positives in those cases where the constructor
is not modifying the first object bytes: in these cases, the dtor
is not run even though the ctor is run. That is still better than
the other case (where the dtor crashes because no ctor was run).
2019-07-11 14:44:14 +02:00
Vassil Vassilev
da626b392d Teach ACLiC to build modules.
ACLiC now synthesizes a modulemap with a suffix _ACLiC_dict.modulemap. The file
contains the source file to be compiled and the corresponding library.

The modulemap is then passed to rootcling via -fmodule-map-file= flag to avoid
naming clashes with possibly existing other modulemap files.

This patch teaches cling to work with the -fmodule-map-file= flag.

ACLiC supports automatic inclusion of Rtypes.h (making ClassDef macro
available). Modules are built in isolation and are resilient to #include
of Rtypes.h at rootcling startup time. We make module Core (containing Rtypes.h)
visible via a newly implemented callback.
2019-07-01 13:59:14 +02:00
Axel Naumann
70df14a1c7 Create transactions only if codegen (not rootcling):
The transactions are useful to buffer Decls before sending them to CodeGen,
to verify semantic validity before emitting. If there is no codegen,
DeclCollecting them wastes CPU cycles during PCH generation time
because all headers are in one single transaction. Of course this also
speeds up regular rootcling invocations.
2019-06-28 23:59:17 +02:00
Axel Naumann
8f20c8c6a1 Remove unnecessary include (NFC). 2019-06-28 23:59:17 +02:00
Axel Naumann
ab8fcc633a Remove default-by-tokens default ctor (NFC). 2019-06-28 23:59:17 +02:00
Vassil Vassilev
74685d3725 Store rdict files as module file extensions.
This patch moves the ROOT-specific rdict.pcm optimization in the EXTENSION_BLOCK
of a C++ module file.

This reduces the generated artifacts and simplifies the loading of a rdict pcm
file as it is now part of the C++ module file. This patch paves our way to
using the global module indexing.
2019-06-19 18:59:07 +02:00
Philippe Canal
ddffe49bea Insure that the commit callbacks don't change the 'current' transaction.
This should solve the problem we have been seeing with cmsUnload.  The problem stems from the fact that TCling::AutoParseImplRecurse
uses the address of the current transactions has an index/key when registering a class in fTransactionHeadersMap.

On some platforms TInterpreter.h is parsed late, i.e. during the compilation of:

   gInterpreter->AutoParse("SiStripCluster");

consequently (as AutoParse does not create its own transaction), the transactions that contains
the parsin of TInterpreter is the last one committed before AutoParseImplRecurse is executed.

Without the parsing of TInterpreter.h then that transaction is return by fInterpreter->getCurrentTransaction().
With the parsing of TInterpreter.h, during the commit of the transaction of the callbacks are triggered
and one of the decl is a constant (kFALSE) and thus, in TCling::HandleNewDecl, provokes the execution of

       if (gROOT->GetListOfGlobals()->FindObject(ND->getNameAsString().c_str()))
         return;

which will triggered the creation of a Transaction, however since the last top level transaction was
just switch to the state 'Committed', the new transaction will not be nested and thus
IncrementalParser::endTransaction will set the current transaction to 'nullptr'.

And this value of nullptr for the key of fTransactionHeadersMap is neither guaranteed to be unique
nor handled properly by the rest of the code.

It is unclear why this problem have surfaced recently.

On a failing machine, rebuilding with a 2 month old commit (ad9e5c42cb) still exhibits the problem.
2019-06-07 08:29:45 +02:00
Vassil Vassilev
81e2eda009 Check if the triggerFunc is in a library.
This patch should fix an assert in the incrementals.
2019-06-03 15:44:13 +02:00
Vassil Vassilev
d71643dcf8 Support recursive lookup helper calls.
The implementation of class->library mapping makes a call to the
LookupHelper::findScope. This makes the recursive invocations to
LookupHelper::findScope -> ... -> LookupHelper::findScope happen more often.
2019-06-02 21:44:26 +02:00
Axel Naumann
ed64547947 Support trailing semicolon in .x foo.C(12); 2019-05-15 21:14:11 +02:00
Axel Naumann
202a2c8e89 Improve .x arg parsing (ROOT-10097):
Dropbox folders (among others) can contain parentheses.
Without this patch, ROOT and cling misinterpret those directories as arguments.
Instead, first find the end of the ".x" line.
If the previous token was a closing paren, we assume that the preceding
tokens (up to the non-nested opening paren) belong to the argument.
2019-05-15 21:14:11 +02:00
Vassil Vassilev
03c9a184ba Do not copy the FrontendOpts, we want to modify the object. 2019-05-14 08:47:27 +02:00
xloem
8acc94bfd6 Protect possibly predefined preprocessor symbol
On my systems (RHEL7 and Android Termux) PAGE_SIZE is defined to 4096 in /usr/include/sys/user.h .  The enum then produces a compile-term error.
Adding this change resolves this error for me.
2019-05-13 15:01:11 +02:00
Vassil Vassilev
ea23e15d42 Remove workaround used for ROOT. 2019-04-22 17:14:37 +02:00
Bertrand Bellenot
7fc4f8539c Add support for Visual Studio 2019 (16) 2019-04-15 12:29:37 +02:00
Vassil Vassilev
fb5a493198 Resize the memory cache before entering the loop.
This prevents the vector to be reallocated if the size exceeds the capacity of
the vector causing invalid pointer accesses.

Fixes ROOT-7749.
2019-04-09 15:29:12 +02:00
Vassil Vassilev
eab5eca3ea Optimize IsWrapper
The getNameAsString interface causes a lot of temporary allocations.
The analysis if a decl is a cling-style wrapper can work only on a
simple declarations on the global scope.

This patch filters out complex declarations (eg in namespaces) and
checks only the identifier content.

The patch reduces the memory footprint difference shown in root-project/root#3012.
2019-03-25 19:14:13 +01:00
Vassil Vassilev
27f03abc6c Typo. 2019-03-21 23:29:11 +01:00
Vassil Vassilev
e7b7b6c247 OSX does not require overlay files. 2019-03-21 23:29:11 +01:00
Vassil Vassilev
2a88ca8943 Constify. 2019-03-16 14:29:29 +01:00
Vassil Vassilev
9dd448d998 Order alphabetically includes. 2019-03-16 14:29:29 +01:00
Vassil Vassilev
0b9abc1e14 Force flush cout after execution
The user might use utilities which print on cout and expects the output
to be shown immediately.

This patch automatically flushes std::cout after each execution of a wrapper.
2019-03-16 14:29:29 +01:00
Axel Naumann
81c8b1ed2f Prevent the overlay entry from docking to .../include/c++/backward/:
This code must be replaced by a HeaderSearch of vector, stdio.h and then
use their DirectoryEntry-s as path for buildModuleMapOverlayEntry().
2019-03-11 17:29:17 +01:00
Vassil Vassilev
78c2bbaf9a Remove obsolete interface. 2019-02-22 09:46:26 +01:00
Vassil Vassilev
94dc093259 Sink the interface for loading a module in cling.
This patch prepares the infrastructure to be able to work with a
global module index.
2019-02-20 22:29:12 +01:00
Bertrand Bellenot
5a82c65dd8 Use llvm::raw_string_ostream instead of std::stringstream (thanks Axel) 2019-02-05 08:15:06 +01:00
Bertrand Bellenot
eec58c1605 Windows: Fix formatting of Interpreter::toString(const char* type, void* obj)
Make sure hexadecimal pointer values have the correct '0x' prefix (not automatic on Windows)
2019-02-05 08:15:06 +01:00
Yuka Takahashi
bc7cca6e31 Introduce virtual modulemap overlay file (#3267)
This patch includes:
- Remove existing modulemap.overlay files
  Cling now can generate virtual overlay files on-demand.
- Implement `-modulemap_overlay` flag to Cling
  This flag is used to tell Cling the location of modulemaps to be
  overlayed. (eg. stl.modulemap, libc.modulemap)
- Generate and load virtual modulemap in Cling
  It is in Interpreter constructor, happens as part of cxxmodules
  initialization step.
- Implement an interface to Clang CompilerInvocation which can take FileSystem pointer
  Previously, Clang only took a "string of filenames" which clearly doesn't
  work for our usecase. We already discussed this new interface at
  modules meeting, so this change will land upstream.
- Add a file existence check in Clang
  When compiling a pcm and when Clang saw the #include with which pcm was available
  (or being generated implicitly), Clang was putting a notation of the full path to this pcm.
  This caused an error when build directory was deleted, because the path didn't exist anymore.

This patch enables modules to be binary distributed, and to make it
work in CMSSW enviroment.
2019-01-24 10:29:21 +01:00
Axel Naumann
10828b4be5 Reduce scope of local variable. 2019-01-10 13:29:15 +01:00
Axel Naumann
e93325aeed Look up template function specializations as such (ROOT-9789). 2019-01-10 13:29:14 +01:00
Axel Naumann
d713ae033e Enable inline passes for higher (cling-runtime) opt levels. 2019-01-09 23:14:08 +01:00
Axel Naumann
a2cd159178 Disable optnone function attribute:
Allows dynamic opt level setting to have an effect on functions!
2019-01-09 23:14:08 +01:00
Yuka Takahashi
2849a2ab73 Support autoloading of dynamic symbols and callback from IncrementalExecutor
This patch contains two functionality:
1. Autoloading of dynamic symbols for system headers
   There is three kind of symbols in shared object file, which is 1
   normal symbols, 2 dynamic symbols, and 3 hidden visibility symbols.
   Linker doesn't care about 3, but should take care (of course) 1 and
   2. For system headers, often symbols are defined in .dynsym section
   which means they are 2 dynamic symbols. This patch adds support of
   autoloading those symbols. We fallback to resolving dynamic symbols
   from system headers only if we couldn't resolve from normal symbol
   table, as the initialization of header search is expensive (iterating
   through all system headers)
2. Register callback from IncrementalExecutor
   Previously, LazyFunctionCreatorAutoload was getting callback only
   from DynamicLibraryManager::loadLibrary. This was enough for fixing
   tests, but is insufficient to handle "symbol <something> unresolved
   while linking function" errors as those errors are emitted from
   IncrementalExecutor. Adding a callback from IncrementalExecutor
   enables us to unresolved symbols.

It fixes these kind of errors:
`IncrementalExecutor::executeFunction: symbol '_ZN7TCanvasC1EPKcS1_iiii' unresolved while linking function '_GLOBAL__sub_I_cling_module_8'!`
2018-12-13 10:29:32 +01:00
Vassil Vassilev
f83498c6a0 Handle the case if the plugin is passed as a shared object.
When cling is embedded and the plugins are linked statically we can rely
on the initialization of the Preprocessor to register the pragmas.

Currently, due to the current implementation deficiency we cannot rely
on the same mechanism when loading the plugins as shared objects.

This patch fixes the failing cling test.
2018-11-20 10:50:54 +01:00
Vassil Vassilev
60a08fd97a Further delay the lazy initialization of dynamic lookup.
This optimizes the ROOT startup for C++ Modules by avoiding
deserialization of redundant declarations.
2018-11-20 10:50:54 +01:00
Vassil Vassilev
04601bd1bf Add a FIXME. 2018-11-15 23:44:56 +01:00
Bertrand Bellenot
a75d9436bc Fix potential issue with Unicode
Fix potential compilation error C2664: 'HANDLE CreateFileW(LPCWSTR,DWORD,DWORD,LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE)': cannot convert argument 1 from 'const char [8]' to 'LPCWSTR' with Unicode/MBCS, as reported here: https://github.com/root-project/cling/issues/186#issuecomment-404902026
2018-11-15 15:39:52 +01:00
Vassil Vassilev
13cbf38ae0 Do not re-register plugin pragmas.
The clang::Preprocessor::RegisterBuiltinPragmas already registered them

This patch avoids an assertion when re-adding the same pragma twice.
2018-11-06 11:59:41 +01:00
Axel Naumann
56186d6a2a Fix unused var warning. 2018-10-31 17:14:05 +01:00
Axel Naumann
c35914068e Veto ptrcheck for decls annotated with __cling__ptrcheck(off). 2018-10-31 08:44:39 +01:00
Axel Naumann
10a79e146e Do not check *this, even if implicitly cast.
(cherry picked from commit 1dd7ac75cf5ecc1ef91c5aa1cc2ba65c46e8d585)
2018-10-31 08:44:39 +01:00
Axel Naumann
778c416dc0 DynScopes: escape up to Stmt level (ROOT-9738). 2018-10-30 15:29:08 +01:00
Vassil Vassilev
69f1d35dd6 Revert "Revert "[cxxmodules] Publish MetaLexer too.""
This reverts commit 0f583c7ef0173fba1caa7680188e7bc767f5d97d.

We need this change because whoever uses MetaParser.h will not be
able to compile their program. MetaParser.h includes MetaLexer.h.
2018-10-30 15:14:45 +01:00
Vassil Vassilev
07d84fcec1 Revert "[cxxmodules] Publish MetaLexer too."
This reverts commit 20d116e723018bae496c7fb78fbeec22543d14c6.

We will have to debug the exact cxxmodules failure.
2018-10-30 09:59:09 +01:00
Vassil Vassilev
c178d80217 Enable timing counters in clang's frontend.
This feature can be enabled by setting an env variable ROOT_CLING_TIMING.
It prints some information about how much time different parts of clang
take.
2018-10-26 22:14:11 +02:00
Vassil Vassilev
084e96df4c Add a dependency on clangSema to clingInterpreter.
We use the target clingInterpreter in a few places as a
general dependency rule making sure the cling infrastructure is
already built.

In some cases, such as clad, the highly parallel builds trigger
build of clad before clangSema, clangBasic and clangAST are built.

This patch ensures the right dependencies are in order.
2018-10-26 09:44:19 +02:00
Vassil Vassilev
a47da9e9cd Publish MetaLexer too.
This fixes our cxxmodules builds.
2018-10-24 21:45:01 +02:00
Sylvain Corlay
7677fbc562 Make Meta Processor requirements public 2018-10-23 12:14:20 +02:00
Vassil Vassilev
cc57c1e08e 80 cols. 2018-10-16 16:59:55 +02:00
Philippe Canal
ad59359390 Fix cling::Interpreter::compileFunction getting confused by trailing transactions.
This fixes https://sft.its.cern.ch/jira/browse/ROOT-9672 by having
cling::Interpreter::DeclareCFunction return the transaction containing the
compiled code.

With the previous code, cling::Interpreter::compileFunction will get confused by
transaction created during the callbacks executed during the
cling::IncrementalParser::commitTransaction of the main transaction.

Reproducer:

With a main composed of 'only':

int main(int argc, char ** argv)
{
  char const * class_string = (argc == 2) ? argv[1] : "std::vector<int>";
  auto const result [[gnu::unused]] = TClass::GetClass(class_string);
  return 0;
}

which is a representation of real use case (in a more complex setup) in ART.
We were getting:

Error in <TClingCallFunc::make_wrapper>: Failed to compile
  ==== SOURCE BEGIN ====
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-security"
__attribute__((used)) extern "C" void __cf_0(void* obj, int nargs, void** args, void* ret)
{
   if (ret) {
      (*(TStreamerInfo**)ret) = new TStreamerInfo();
      return;
   }
   else {
      new TStreamerInfo();
      return;
   }
}
#pragma clang diagnostic pop
  ==== SOURCE END ====
Error in <TClingCallFunc::ExecT>: Called with no wrapper, not implemented!
Error in <TVirtualStreamerInfo::Factory>: The plugin handler for TVirtualStreamerInfo was found but failed to create the factory object!

The reason is that during TClingCallFunc::make_wrapper, the call to cling::Interpreter::compileFunction ends with:

    if (const llvm::GlobalValue* GV
        = getLastTransaction()->getModule()->getNamedValue(name))

However in the 'broken' case, the getLastTransaction does not return the transaction for the code being compiled by DeclareCFunction but instead the one used/created at:

#0  cling::IncrementalParser::endTransaction (this=0x4a2980, T=0x8c0fb0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/IncrementalParser.cpp:345
#1  0x00007fffeebc7899 in cling::Interpreter::PushTransactionRAII::pop (this=0x7fffffffcb00) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:111
#2  0x00007fffeebc785e in cling::Interpreter::PushTransactionRAII::~PushTransactionRAII (this=0x7fffffffcb00, __in_chrg=<optimized out>)
    at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:106
#3  0x00007fffeebeb659 in cling::LookupHelper::findScope (this=0x4a9dd0, className=..., diagOnOff=cling::LookupHelper::NoDiagnostics, resultType=0x7fffffffcd08, instantiateTemplate=false)
    at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/LookupHelper.cpp:466
#4  0x00007fffeeabe0df in TCling::CheckClassInfo (this=0x4a0550, name=<optimized out>, autoload=<optimized out>, isClassOrNamespaceOnly=<optimized out>)
    at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TCling.cxx:3630
#5  0x00007ffff7c3040d in TClass::Init (this=this@entry=0xdafd20, name=name@entry=0x7ffff7cb7638 "TGlobal", cversion=cversion@entry=2, typeinfo=typeinfo@entry=0x7ffff7d8b6d8 <typeinfo for TGlobal>, isa=isa@entry=0x477430,
    dfil=dfil@entry=0x7ffff7cb8cab "TGlobal.h", ifil=<optimized out>, dl=<optimized out>, il=<optimized out>, givenInfo=<optimized out>, silent=<optimized out>)
    at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TClass.cxx:1431
#6  0x00007ffff7c3a1b8 in TClass::TClass (this=0xdafd20, name=0x7ffff7cb7638 "TGlobal", cversion=<optimized out>, info=..., isa=0x477430, dfil=0x7ffff7cb8cab "TGlobal.h",
    ifil=0x7ffff7cccf88 "/local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TGlobal.cxx", dl=27, il=25, silent=false) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TClass.cxx:1273
#7  0x00007ffff7c3a72a in ROOT::CreateClass (cname=0x7ffff7cb7638 "TGlobal", id=id@entry=2, info=..., isa=isa@entry=0x477430, dfil=dfil@entry=0x7ffff7cb8cab "TGlobal.h",
    ifil=ifil@entry=0x7ffff7cccf88 "/local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TGlobal.cxx", dl=27, il=25) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TClass.cxx:5607
#8  0x00007ffff7c4b552 in ROOT::Internal::TDefaultInitBehavior::CreateClass (il=25, dl=27, ifil=0x7ffff7cccf88 "/local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TGlobal.cxx", dfil=0x7ffff7cb8cab "TGlobal.h",
    isa=0x477430, info=..., id=2, cname=<optimized out>, this=0x7ffff7da7508 <ROOT::Internal::DefineBehavior(void*, void*)::theDefault>) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/Rtypes.h:176
#9  ROOT::TGenericClassInfo::GetClass (this=0x7ffff7dab660 <ROOT::GenerateInitInstanceLocal(TGlobal const*)::instance>) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TGenericClassInfo.cxx:250
#10 0x00007ffff7b1a2d8 in TGlobal::Class () at /home/pcanal/root_builds/v6-14-00-patches/opt/core/base/G__Core.cxx:17156
#11 0x00007ffff7ac01de in TGlobal::IsA (this=0xee3bc0) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/TGlobal.h:48
#12 TGlobal::CheckTObjectHashConsistency (this=0xee3bc0) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/TGlobal.h:48
#13 0x00007ffff7be9dcd in TObject::CheckedHash (this=0xee3bc0) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/TObject.h:314
#14 THashTable::GetCheckedHashValue (this=0xe65a20, obj=0xee3bc0) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/THashTable.h:94
#15 THashTable::Add (this=0xe65a20, obj=0xee3bc0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/cont/src/THashTable.cxx:96
#16 0x00007ffff7be6bf1 in THashList::AddLast (this=this@entry=0x5be690, obj=obj@entry=0xee3bc0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/cont/src/THashList.cxx:100
#17 0x00007ffff7c4e0d1 in TListOfDataMembers::AddLast (this=0x5be690, obj=0xee3bc0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TListOfDataMembers.cxx:103
#18 0x00007ffff7ab8785 in TList::Add (obj=0xee3bc0, this=0x5be690) at /home/pcanal/root_builds/v6-14-00-patches/opt/include/TList.h:87
#19 TROOT::GetListOfGlobals (this=0x7ffff7da7a60 <ROOT::Internal::GetROOT1()::alloc>, load=load@entry=false) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/base/src/TROOT.cxx:1767
#20 0x00007fffeeab1058 in TCling::HandleNewDecl (this=0x4a0550, DV=0xedf238, isDeserialized=isDeserialized@entry=true, modifiedTClasses=...) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TCling.cxx:555
#21 0x00007fffeeabb785 in TCling::UpdateListsOnCommitted (this=0x4a0550, T=...) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TCling.cxx:6115
#22 0x00007fffeebd0103 in cling::MultiplexInterpreterCallbacks::TransactionCommitted (this=0x57fe20, T=...) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/MultiplexInterpreterCallbacks.h:76
#23 0x00007fffeed05d71 in cling::IncrementalParser::commitTransaction (this=0x4a2980, PRT=..., ClearDiagClient=true) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/IncrementalParser.cpp:532
#24 0x00007fffeed06399 in cling::IncrementalParser::Compile (this=0x4a2980, input=..., Opts=...) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/IncrementalParser.cpp:663
#25 0x00007fffeebcbc4e in cling::Interpreter::DeclareInternal (this=0x4a0f30, input=..., CO=..., T=0x7fffffffd680) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:1195
#26 0x00007fffeebca8e8 in cling::Interpreter::declare (this=0x4a0f30, input=..., T=0x7fffffffd680) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:823
#27 0x00007fffeebcb560 in cling::Interpreter::DeclareCFunction (this=0x4a0f30, name=..., code=..., withAccessControl=true) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:1096
#28 0x00007fffeebcb862 in cling::Interpreter::compileFunction (this=0x4a0f30, name=..., code=..., ifUnique=false, withAccessControl=true)
    at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/interpreter/cling/lib/Interpreter/Interpreter.cpp:1140
#29 0x00007fffeeafb83c in TClingCallFunc::compile_wrapper (withAccessControl=true, wrapper=..., wrapper_name=..., this=0xcf3c10) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TClingCallFunc.cxx:270
#30 TClingCallFunc::make_wrapper (this=this@entry=0xcf3c10) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TClingCallFunc.cxx:1096
#31 0x00007fffeeafbcb8 in TClingCallFunc::IFacePtr (this=this@entry=0xcf3c10) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TClingCallFunc.cxx:2233
#32 0x00007fffeeafbe83 in TClingCallFunc::ExecT<long> (address=0x0, this=0xcf3c10) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TClingCallFunc.cxx:2045
#33 TClingCallFunc::ExecInt (this=0xcf3c10, address=0x0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/metacling/src/TClingCallFunc.cxx:2065
#34 0x00007ffff7c56e8d in TMethodCall::Execute (this=0xd97710, object=<optimized out>, retLong=@0x7fffffffd958: 0) at /local2/pcanal/cint_working/rootcling/v6-14-00-patches/core/meta/src/TMethodCall.cxx:457
#35 0x0000000000401009 in TMethodCall::Execute(long&) ()
#36 0x00000000004010ea in long TPluginHandler::ExecPluginImpl<>() ()
#37 0x000000000040106d in long TPluginHandler::ExecPlugin<>(int) ()
#38 0x0000000000400e21 in mytest() ()
#39 0x0000000000400e92 in main ()
2018-10-12 00:29:48 +02:00
Vassil Vassilev
38eb2b89ba Allow plugins to handle custom pragmas.
This will help clad implement pattern such as:
#pragma clad on
// code which needs derivation
#pragma clad off
2018-10-08 21:44:55 +02:00
Vassil Vassilev
8b925f1c64 Fix a potential null dereference.
The bug was discovered by running runarray1 test in runtime_cxxmodules mode.
2018-10-06 14:43:29 +02:00
Yuka Takahashi
9c7abadde0 Implement toString interface to gInterpreter
This is the final version of "printValue" discussion.

We agreed that printValue interface should be altered to ToString
interface, which can be invoked `gInterpreter->ToString(XYZ)`. (ToString is in TCling and toString is in Interpreter :D)

This patch contains:

- Implementation of toString in Interpreter.cpp
- Re-Implementation of ClingPrintValue to use ToString because I changed to use Evaluate some time ago.
- Removing of RVec version of printValue which wasn't used at all
- Fix test/vecops_rvec.cxx, printValue is never supposed to be called by a normal user.
2018-10-04 17:13:34 +02:00
Bertrand Bellenot
2fbb8cb0f1 Don't use VirtualQuery to check if the memory is valid
Calling VirtualQuery() is very expansive. For example, the testUnfold5a.C tutorial (interpreted) times out after 3600 seconds, and runs in about 60 seconds without calling VirtualQuery(). So just bypass it and return true for the time being
2018-10-03 17:43:41 +02:00
Axel Naumann
c23abbc88b Force the OSX SDK to be the one at build time:
Fixes builds with command line tools and macos 10.14.
2018-09-26 20:29:22 +02:00
Axel Naumann
2847412de4 Use TLS for pointer check cache:
With 16 threads, the cache is simply too small.
These are thread specific values anyway.
2018-09-26 11:44:10 +02:00
Bertrand Bellenot
4ed58df12d Fix lookup of Visual Studio directories + improve error messages
Visual Studio 2017 doesn't use the registry anymore, so no need to try to find keys. This prevent picking wrong directories in the case there is another version installed on the computer, and prevent also the following errors when starting ROOT:
  RegQueryValueEx: returned 2: The system cannot find the file specified.
  RegOpenKeyEx: returned 2: The system cannot find the file specified.
2018-09-25 15:29:09 +02:00
Danilo Piparo
7499f98cf9 Avoid symbol of helper function to be exposed, code-quality. 2018-09-22 09:14:48 +02:00
Danilo Piparo
65cea92ce8 Fix ROOT-6967: add helper functions to lookup tags
efficiently and not variables.
2018-09-22 09:14:48 +02:00
Yuka Takahashi
230031c4cb Implement parsing cache for the LookupHelper.
The operations done by the LookupHelper are costly in both memory and
performance. Almost every operation requires memory allocation and parsing
of often non-trivial C++ code.

Unfortunately, the LookupHelper is used very intensively by rootcling and
ROOT. The callers usually do not use any caching mechanisms and redo the
expensive operations over and over even though the answer is known to be
the same as before. For instance, building the dictionary of shows:

```
MathCore:
  Cached entries: 217
  Total parse requests: 54051
  Cache hits: 53834
TreePlayer:
  Cached entries: 183
  Total parse requests: 57697
  Cache hits: 57514
```

This patch introduces the first set of caching functionality. In
particular, each LookupHelper::find* function allocates a memory buffer
which is then stored in the clang::SourceManager. We hash the buffer
content and keep a mapping between a hash and FileID and next time we
encounter the same content we do not allocate a new FileID but reuse the
old one. We see decrease in memory footprint by 7% for non-cxxmodules ROOT.

For cxxmodules we see significant reduction of the pcm sizes (by half)
which translates into rss improvements:

```
  master before:
    cpu  time = 0.291462 seconds
    sys  time = 0.064409 seconds
    res  memory = 345.816 Mbytes
    vir  memory = 573.508 Mbytes
  master after:
   cpu  time = 0.235828 seconds
   sys  time = 0.098327 seconds
   res  memory = 260.012 Mbytes
   vir  memory = 377.945 Mbytes
```

Patch by Yuka Takahashi and me.
2018-08-24 23:59:47 +02:00
Vassil Vassilev
272905eced Implement clang plugin support.
Clang allows third party shared libraries to provide user-defined
extensions. For example, a custom libTemplateInstantiation.so can
visualize all template instantiation chains in clang. To enable it
one needs to pass a set of options such as -fplugin.

Cling should be able to inherently work with clang plugins. However,
cling still does not make full use of the clang driver where the plugin
setup is handled.

This patch enables plugins in cling and extends them in some aspects.
In particular, cling allows loading of plugins from shared libraries
but also if they are linked to the same library where cling is. This is
very useful in cases where cling runs itself in a shared library (eg
libCling). Users of libCling (such as ROOT) prefer to keep all llvm and
clang related symbols local to avoid symbol clashes if there is another
version of clang and llvm linked against a package. This can be done by
dlopen-ing libCling with RTLD_LOCAL visibility mode. Then the only way
for clang plugins to work in this scenario is to be linked to libCling.

Patch by Aleksandr Efremov and me.
2018-07-28 13:17:44 +02:00
Axel Naumann
0b22602686 Forward inlining level to CGOpts.setInlining(). 2018-07-25 14:59:21 +02:00
Simeon Ehrig
2101f08450 Fix doxygen error. 2018-06-27 11:15:27 +02:00
Axel Naumann
ee37473807 Check file is C_User before hitting disk. Thanks, Vassil! 2018-06-26 13:44:18 +02:00
Axel Naumann
18bd806414 Only check pointers for Decls from writable dirs (ROOT-9377). 2018-06-25 12:59:56 +02:00
Axel Naumann
72feb2cc20 Move NullDerefProtectionTransformer into unnamed namesp. 2018-06-25 12:59:56 +02:00
Axel Naumann
4d17a6d9e2 Add GCC fallthrough comment, 80cols. 2018-06-25 11:29:07 +02:00
Axel Naumann
a0674d2d91 Add GCC fallthrough comment. 2018-06-25 11:29:07 +02:00
Simeon Ehrig
8c14ae786d Forgot header for clang build. 2018-06-25 08:29:08 +02:00
Simeon Ehrig
2e89e3a8ee Reformated the source code with clang-format. 2018-06-25 08:29:07 +02:00
Simeon Ehrig
8f832942fb Fix cuda template specialization bug.
Problem:
If a c++ statement with a concrete template parameter will type in, cling pass the (unwrapped) input line and the specialization of the statement, generated by compilerinstance to the clang nvptx. This causes an  explicit-specialization-after-instantiation-error.

Solution:
Template specialization declaration will be save two times at a transaction. Once with the type kCCIHandleCXXImplicitFunctionInstantiation and once with the type kCCIHandleTopLevelDecl. To avoid sending a template specialization to the clang nvptx and causing an explicit-specialization-after-instantiation-error it have to check, which kCCIHandleTopLevelDecl declaration is also a kCCIHandleCXXImplicitFunctionInstantiation declaration.
2018-06-25 08:29:07 +02:00
Simeon Ehrig
7c954c6273 Change clang nvptx input code selection.
As input of clang nvptx there are two possible sources. The raw input of `IncrementalParser::parseInternal()` or the AST-Printer of the `llvm::module`. Now, to decide, which input source should be use, I use the value `Transaction::ConsumerCallInfo::kCCIHandleTopLevelDecl`. This allows more C++ constructs to use.

Fixed a small bug. The AST-printer prints `setValueNoAlloc()` without the scope `cling::runtime::internal`. This caused an error, because clang could not find the declaration in the global space. The solution are dummy declaration in the global space.

At the moment, templates doesn't works.
2018-06-25 08:29:07 +02:00
Simeon Ehrig
9a4418b3c0 Improvements for Pull Request #240
- little changes at comments and code style
- try to use const in IncrementalCUDADeviceCompiler, where is possible
- move CUDA device code compiler instance to IncrementalParser
- change the members of CuArgs to const and adjust the setCuArgs method
- use std::vector<string> instead llvm::Smallvector<const char *> to build argv for executeAndWait
- improve the error messages of generatePCH(), generatePTX() and generateFatbinary()
- replace m_Counter with a copy in IncrementalCUDADeviceCompiler to avoid involuntary changes
2018-06-25 08:29:07 +02:00
Simeon Ehrig
309cebff41 Add function, to save faulty .cu files of CUDA device compiler.
Before this commit, the CUDA device code Compiler class overwrited source code .cu files, if the translation get wrong. Now, it renames the faulty files, so you can check, which source code cause compiler errors.
2018-06-25 08:29:07 +02:00
Simeon Ehrig
68cffbb853 Improve CUDA device code testcases. 2018-06-25 08:29:07 +02:00
Simeon Ehrig
d14ab2daec Improve the search of the clang instance for CUDA.
Before, it was not possible to find the clang++, which is contained in the cling, if we don't start the clang from the bin folder ('./cling -xcuda'). Now, for example it is possible to start the cling with 'bin/cling -xcuda' .

Fix a Bug, which avoid to start './cling -xcuda -fsyntax-only'.
2018-06-25 08:29:07 +02:00
Simeon Ehrig
2b61966c0d Fix temp-path bug.
In some cases, the path of the cling temp folder contains some non printable chars at the end.
Change the handling of the path string, to solve this problem.
2018-06-25 08:29:07 +02:00
simeon
b87dfcf9b1 Improve Error Message. 2018-06-25 08:29:07 +02:00
Simeon Ehrig
eb5cfc5f3f The CUDA compiler can handle variable declarations from the prompt.
Now, it is possible to declare variables on the prompt, which are visible for other statements.

The problems was, that cling wrapped all statements in a function, to get valid input. So, every variable is just visible inside in its own wrapper function. To solve the problem, cling change the local variable declaration to a global declaration.

The implementation for the CUDA compiler checks, if the unwrapping is happened. If it happened, the c++ code of the unwrapped variable declaration (AST-printer) instead the raw input will be written to the .cu-file.
2018-06-25 08:29:07 +02:00
Simeon Ehrig
c18f074cbd Add workaround for clang PCH-bug
At the moment, to extend the AST-tree of the device code, we use PCH-files to extend the exist device code with new lines of code. In detail, if we want to create a new PTX-file, we use the CUDA code (.cu file) and a PCH-file with the existing AST as input and generate an new PCH-file, which contains the whole AST. Then, the PCH-file will compiled to a PTX-file.

A bug in clang prevent, that we can’t generate more than 5 new PCH-files. The bug is not easy to fix, so I write a small workaround. Instead using a PCH-file, which contains the AST, we generate a new complete AST from all .cu-files every time.

The workaround is temporary and should removed, if clang is patched.
2018-06-25 08:29:07 +02:00
Simeon Ehrig
454c359c51 Setting the arguments of cling to clang nvptx and fatbinary are possible.
Now, it is possible to set some arguments of the clang nvptx and fatbinary via arguments at cling start. The arguments are filtered. So not every argument is possible at the moment. The Arguments can’t changed during runtime, because the PCH-files forbid it. For Example, the calng nvptx use the optimization level, which is set at start of cling.

At the moment, the debug options of clang nvptx are simple. If any debug option is detected, just a -g will add to the clang nvptx.

Additional PTX options for clang nvptx doesn’t works at the moment. There is a problem at parsing at the start of cling.
2018-06-25 08:29:07 +02:00
Simeon Ehrig
4882fbe886 Overwork of the include path handling of the CUDA device compiler.
I replaced copies of the include paths with a pointer to the headerSearchOptions. Now, explicit handling of the include paths is not more necessary. Add include paths, which was declared via argument at start also works.
2018-06-25 08:29:07 +02:00
Simeon Ehrig
58d99cf4f9 CUDA device compiler can use include paths from cling runtime.
This new function allows the CUDA device compiler to search after headers in folders, which was declared at runtime vie .I command.
2018-06-25 08:29:07 +02:00
Simeon Ehrig
6652d1a7c9 Add CUDA device compiler, which allows to generate CUDA PTX Code on runtime.
The class IncrementalCUDADeviceCompiler use external tools to generate PTX and cuda fatbin files. It runs the tools clang and fatbinary via llvm::sys::ExecuteAndWait. The class also handle to include new code in existing code. The steps of the compiler pipeline are:
- clang: CUDA C++ + previous PCH -> PCH
- clang: PCH -> PTX
- fatbinary: PTX -> fatbin

There is no selection of code. Every input of the cling will pass to the  IncrementalCUDADeviceCompiler.
2018-06-25 08:29:07 +02:00
Simeon Ehrig
90454f964a Added function to detect c++ attributes at function definition.
Now, it is possible to define functions with c++ attributes without the .rawInput mode. For example functions like `[[ noreturn ]] foo() { ... }` or `[[deprecated]] [[nodiscard]] int bar(){ … }`.
2018-06-19 13:44:58 +02:00
Yuka Takahashi
891b279bcc Revert "Revert "Add the cwg to the prebuilt module cache path." (#2160)"
This reverts commit 011aa8200277cd31957e222afd9b37415458b31f.

This is a revert of revert. I reverted the first commit because adding
"." to prebuiltmodulepath was causing failure in runtime modules, but
now we're skipping "." in TCling::LazyFunctionCreatorAutoloadForModule so
doesn't matter even if we have ".".
2018-06-12 22:59:08 +02:00
Yuka Takahashi
befa982fe3 Fix nightlies by autoload dependency libraries
We had test failures in runtime nightlies such as this one:
https://epsft-jenkins.cern.ch/view/ROOT/job/root-nightly-runtime-cxxmodules/95/BUILDTYPE=Debug,COMPILER=gcc62,LABEL=slc6/testReport/junit/projectroot.roottest.root.math/smatrix/roottest_root_math_smatrix_testKalman/

Failures were due to what @pcanal commented in #2135, that some so files in
roottest doesn't have external linkage. (It means that if you call
    dlopen(libfoo.so), linux kernel can't find dependency libraries and it
    emits "undefined symbol" error when they try to initialize global
    variables in libfoo.so but couldn't find symbol definition)
With pch, rootmap files were providing information about the depending library.

However we stopped generating rootmap files in #2127 and that's why we
got these failures. To fix this issue, I implemented a callback to
TCling which gets called when DynamicLibraryManager fails. The callback
pass error message to TCling and it handles message if it contains "undefined error".
2018-06-12 22:59:08 +02:00
Saagar Jha
d57fbe37d5 Handle Control+C and Control+D (mostly) correctly 2018-06-12 08:41:07 +02:00
Saagar Jha
68c93f9743 Fix unfortunate typo 2018-06-12 08:41:03 +02:00
Guilherme Amadio
cbaac95d07 Replace deprecated std::ptr_fun and std::mem_fun with equivalent code
Removed in C++17. No functionality change intended.
2018-06-12 08:40:00 +02:00
Bertrand Bellenot
a561c61888 disable unicode (UTF-8) in the console for the time being, since it causes problems on Windows 10 2018-06-12 08:40:00 +02:00
Raphael Isemann
345a13cef6 Don't assume fileno is a function.
This otherwise leads to compilation errors when we do `::fileno`
as OpenBSD implemented fileno as a macro (which seems to be allowed).
2018-06-12 08:40:00 +02:00
Bertrand Bellenot
ed135557e7 disambiguate the else branch 2018-06-12 08:40:00 +02:00
Bertrand Bellenot
c4990cff45 Fix uninitialized fDefaultAttributes (makes terminal black on black) 2018-06-12 08:40:00 +02:00
Yuka Takahashi
0d478d0fc4 Revert "Add the cwg to the prebuilt module cache path." (#2160)
This reverts commit 5298b418eec4129351888f41cb7c3bfc90161e22.

This commit was mistakenly committed. PR was opened in #1730, but it was
closed and moved to #1761. I didn't notice this and created another PR
in #1980.

This change was causing 100+ failures in runtime cxxmodules nightlies.
(Eg. https://epsft-jenkins.cern.ch/job/root-pullrequests-build/29183/testReport/junit/projectroot/runtutorials/tutorial_fit_FittingDemo/)
We want to have **proper** PrebuildModulesPaths which information were
extracted from LD_LIBRARY_PATH and DYLD_LIBRARY_PATH, not a random ".".

Because of this commit, we were trying to autoload libraries generated
by roottest on-demand (for example "./h1analysisTreeReader_C.so") This
is not an intentional behavior, these autogenerated libraries are
already loaded by roottest and what we want to do is to load **proper**
libraries like libHist.so instead.
2018-06-07 15:59:45 +02:00
Yuka Takahashi
35a8988d50 Autoload less libraries
In previous allmodules&autoloading patch, we used callback from
DeserializationListener to get Decl and loaded corresponding libraries.
It worked, but the performance was bad because ROOT was loading
excessive libraries.

In this patch, we use TCling::LazyFunctionCreatorAutoloadForModule. This
function gets callback when "mangled_name" was not found in loaded
libraries thus we have to the load corresponding library and lookup
again.

I used unordered_map to store mangled identifier and library pair. I'm
doing an optimization by hashing mangled name and storing library not by
name but by uint8 and hold uint8-name information in another vector.
Also tried std::map but unorderd_map was more performant. There are
better hash table like:
https://probablydance.com/2018/05/28/a-new-fast-hash-table-in-response-to-googles-new-fast-hash-table/
we can try to use them if this part gets crucial.

With this patch:
```
Processing tutorials/hsimple.C...
hsimple   : Real Time =   0.04 seconds Cpu Time =   0.03 seconds
(TFile *) 0x562b37a14fe0
Processing /home/yuka/CERN/ROOT/memory.C...
cpu  time = 0.362307 seconds
sys  time = 0.039741 seconds
res  memory = 278.215 Mbytes
vir  memory = 448.973 Mbytes
```

W/o this patch:
```
Processing tutorials/hsimple.C...
hsimple   : Real Time =   0.08 seconds Cpu Time =   0.07 seconds
(TFile *) 0x5563018a1d30
Processing /home/yuka/CERN/ROOT/memory.C...
cpu  time = 1.524314 seconds
sys  time = 0.157075 seconds
res  memory = 546.867 Mbytes
vir  memory = 895.184 Mbytes
```

So it improves time by 4x times and memory by 2x.
2018-06-02 10:44:38 +02:00
Axel Naumann
eb9fbe9f2c Unroll the pointer-check cache loop. 2018-05-24 23:14:32 +02:00
Axel Naumann
332a707e55 Allow passing of cling::Interpreter constructor flags. 2018-05-22 23:29:52 +02:00
Axel Naumann
7682a69042 Do not override preproc (un)defines if already set. 2018-05-22 23:29:52 +02:00
Axel Naumann
673a1d63a4 cling PR 233 (#2038)
Add llvm module pass to generate unique cuda module ctor/dtor names.

This llvm module pass address the follow problem. Every llvm module has a cuda ctor and dtor (if a cuda fatbinary exist), with at least a function call to register the fatbinary. The ctor/dtor can also include function calls to register global functions and variables at runtime, depending on user's code. The lazy compilation detects functions by the name. If the name (symbol) already exists it uses the existing translation. Otherwise it translates the function on first use (but it never translates twice). Without the module pass, Cling will always use the translation of the first module.

The testcase use the reflection of the gCling interpreter object. It takes two random modules and compare the symbols of the cuda module ctor and dtor.

Also add function, which change the symbol of the cuda module ctor and dtor to preprocessor compliant symbols.
2018-05-18 11:14:07 +02:00
Yuka Takahashi
98719ad352 Preloading modules and autoloading libraries by deserialized decls
Preloading all the modules has several advantages. 1. We do not have to
rely on rootmap files which don't support some features (namespaces and
templates) 2. Lookup would be faster because we don't have to do
trampoline via rootmap files.

Autoloading libraries when decls are deserialized gives us correctness.
However we still need to optimize the performance by reducing the amount
of loaded libraries and improving Clang performance.
2018-05-18 10:14:30 +02:00
Axel Naumann
3b7919436c Do not unload enum fwd decl but silence redecl diag (ROOT-9363 ROOT-9114).
Unloading the enum forward decl has tragic consequences e.g. for template
specializations relying on that decl (as template type parameter): the
enum definition will not be associated with teh forward decl, and any
subsequent template specialization will not recognize the type identity
of the enum forward declaration and its definition.

Instead, silence the diagnostic. This is not nice, but will be fixed by
C++ modules.
2018-05-16 16:00:04 +02:00
Axel Naumann
d3e070c663 Revert "Move enum attributes after "enum class X: int" (ROOT-9114)."
This reverts commit 42f889c02436107da57d45192951176892666083.
2018-05-16 16:00:04 +02:00
Vassil Vassilev
806c5685c7 Add the cwg to the prebuilt module cache path.
Some modules (produced by rootcling) are located in the cwg and they
should be resolved from there without being rebuilt.
2018-05-09 22:14:39 +02:00
Bertrand Bellenot
01fa534b71 Fix compilation errors on Windows
Fix compilation errors with the latest version of Visual Studio (15.7.0)
- Prevent compilation error G47C585C4: STL1000: Unexpected compiler version, expected Clang 6 or newer
- Fix exported symbols
2018-05-09 10:14:21 +02:00
Oksana Shadura
f8b6afcbb0 Fixing linking of Clang libraries for Cling and rootcling_stage1 in case of builtin_clang=OFF 2018-05-02 11:29:42 +02:00
Axel Naumann
2a60e2a750 Implicit array decay, some printValue-s need arrays! Fix value pointer calculation. 2018-04-30 16:29:42 +02:00
Axel Naumann
47dde3b27f Cache result of type transform. 2018-04-30 16:29:42 +02:00
Axel Naumann
ef2fc34520 Also allow char16, char32 for string value printing. 2018-04-26 12:14:31 +02:00
Axel Naumann
9d3e144814 Allow "same types" to be printed as const char*.
Fixes printing of std::string::c_str().
2018-04-26 12:14:31 +02:00
Axel Naumann
0793802867 Fix const char* printing, take 2. 2018-04-25 22:00:16 +02:00
Axel Naumann
edef97f368 Fix const char* printing! 2018-04-25 21:29:08 +02:00
Axel Naumann
9883aad403 Fix valgrind error in CIFactory/AddRuntimeIncludePaths. 2018-04-25 20:59:33 +02:00
Axel Naumann
ea4efd2a75 Generate the value string through AST manipulation (ROOT-8897). 2018-04-25 16:44:05 +02:00
Vassil Vassilev
4a226ee47a Desugar auto types allowing to print the full qualification of a type. 2018-04-19 17:59:08 +02:00
Vassil Vassilev
a53b0325db Complete the list of used libraries.
Fixes -Dbuiltin_clang=Off -Dclingtest=On builds.
2018-04-19 14:29:07 +02:00
Axel Naumann
452bafc917 Report failure for missing symbols! 2018-04-17 15:59:38 +02:00
Axel Naumann
697fd50363 Handle empty / unknown ABI version. 2018-04-17 13:59:31 +02:00
Axel Naumann
443bd1723f Relax stdlib ABI check; fix libc++ ABI check. 2018-04-11 21:29:05 +02:00
Bertrand Bellenot
4f2d4a8477 Initialize the token kind to "tok::eof" to prevent potential infinite loop 2018-04-11 09:59:09 +02:00
Bertrand Bellenot
119b70b8f8 From Axel: Empty token queue for late parsed templates also for pending instantiations.
Late parsed templated are parsed from a token chain, as if expanding a macro. This confuses subsequent parses. Make sure that the token quere is emptied, which is exactly what ParseInternal() does after parsing.
2018-04-11 09:59:09 +02:00
Wolf Behrenhoff
ace18e2b02 Add const& to foreach loops
In case of TProtoClass.cxx, all the loop was doing
is to copy the collection (loop body with comments
only - and those don't compile when removing the //.
Thus comment out the whole loop.

In TDFNodes.cxx remove the redundant get() as well.
2018-04-10 16:29:10 +02:00
Bertrand Bellenot
129e60ab4b Add comment referencing where the 0x2C value is coming from 2018-04-09 15:45:00 +02:00
Bertrand Bellenot
252dd842df Inject the "_tls_array" constant (0x2C) to avoid unresolved symbol error when JITting 2018-04-09 15:45:00 +02:00
Vassil Vassilev
5367e13c15 Restore removed dependency.
For in-tree builds we need Options.inc to be tablegen-ed before
building clingInterpreter library.
2018-04-01 20:44:18 +02:00
Vassil Vassilev
6c74a386ba Enable ROOT to be built with prebuilt clang and llvm.
To do so one needs to pass -Dbuiltin_llvm=Off -Dbuiltin_clang=Off and the
PATH should contain the path to llvm-config.

Note this is not enabling ROOT to work with vanilla clang!

This patch allows ROOT to be built against a prebuilt clang and llvm from
https://root.cern.ch/git/{llvm.git,clang.git}. It allows to reduce ROOT's
build times (in cases when cmake decides to rebuild the in-tree llvm for
no good reason). It moves the common denominator of different ROOT builds
in one place to save space. It also allows easy switch between LLVM in
debug and release mode.

To build the external clang and llvm exactly in the same way as the
in-tree builds use:

CMAKE_FLAGS="\
            -DLLVM_ENABLE_WARNINGS=OFF                   \
            -DLLVM_INCLUDE_TESTS=OFF                     \
            -DCLANG_INCLUDE_TESTS=OFF                    \
            -DLLVM_INCLUDE_EXAMPLES=OFF                  \
            -DCLANG_BUILD_TOOLS=OFF                      \
            -DCLANG_TOOL_ARCMT_TEST_BUILD=OFF            \
            -DCLANG_TOOL_CLANG_CHECK_BUILD=OFF           \
            -DCLANG_TOOL_CLANG_FORMAT_BUILD=OFF          \
            -DCLANG_TOOL_CLANG_FORMAT_VS_BUILD=OFF       \
            -DCLANG_TOOL_CLANG_FUZZER_BUILD=OFF          \
            -DCLANG_TOOL_CLANG_IMPORT_TEST_BUILD=OFF     \
            -DCLANG_TOOL_CLANG_OFFLOAD_BUNDLER_BUILD=OFF \
            -DCLANG_TOOL_CLANG_RENAME_BUILD=OFF          \
            -DCLANG_TOOL_C_ARCMT_TEST_BUILD=OFF          \
            -DCLANG_TOOL_C_INDEX_TEST_BUILD=OFF          \
            -DCLANG_TOOL_DIAGTOOL_BUILD=OFF              \
            -DCLANG_TOOL_LIBCLANG_BUILD=OFF              \
            -DCLANG_TOOL_SCAN_BUILD_BUILD=OFF            \
            -DCLANG_TOOL_SCAN_VIEW_BUILD=OFF             \
            -DLLVM_BUILD_TOOLS=OFF                       \
            -DLLVM_TOOL_LLVM_AR_BUILD=OFF                \
            -DCLANG_TOOL_CLANG_OFFLOAD_BUNDLER_BUILD=OFF \
            -DLLVM_FORCE_USE_OLD_TOOLCHAIN=ON            \
            -DCLANG_ENABLE_STATIC_ANALYZER=OFF           \
            -DCLANG_ENABLE_ARCMT=OFF                     \
            -DCLANG_ENABLE_FORMAT=OFF                    \
            -DLLVM_TARGETS_TO_BUILD=host                 \
            -DLLVM_ABI_BREAKING_CHECKS=FORCE_OFF         \
            -DLLVM_ENABLE_ABI_BREAKING_CHECKS=OFF        \
            -DCMAKE_INSTALL_PREFIX=..                    \
            -DCMAKE_BUILD_TYPE=Debug"

cmake "$CMAKE_FLAGS"   ../../../sources/root-llvm/
2018-03-28 19:29:10 +02:00
Simeon Ehrig
3b656d1d3f add automatic load of libcudart.so at start of cling -xcuda 2018-03-23 18:29:07 +01:00
Simeon Ehrig
4f73d1b93d reduce arguments at start of cling -xcling
the argument --cuda-host-only and the default c++ stardard will be set at start of cling -xcuda
2018-03-23 18:29:07 +01:00
Simeon Ehrig
757fca022f allow to enable the cuda mode of the compilerInstance
set the AuxTarget, if the LangOpt CUDA is true and enable the compilation of cuda runtime code
needs a preload of the libcudart.so and the arguments -std=c++11 and --cuda-host-only at start of cling
2018-03-23 18:29:06 +01:00
Simeon Ehrig
83e3eafc44 fix CMakeFiles to allow cling build with shared libraries 2018-03-22 15:59:06 +01:00
Bertrand Bellenot
e128adbcca Fix cling on Windows (there is no Emulated TLS on Windows) 2018-03-13 18:44:11 +01:00
Vassil Vassilev
7919b1c9c2 We do not need to use std::addressof. Clang has a builtin analog. 2018-03-12 00:14:06 +01:00
Vassil Vassilev
d45d26ae1d Revert "Use a stable way to determine the address of printed objects."
This reverts commit 56b56bf25e5a4ef29555c2f7e9ea30bf76b9000e.
2018-03-12 00:14:06 +01:00
Vassil Vassilev
7b70052776 Add forgotten to commit protection and check clause.
This should have landed in 7554be9571.
2018-03-10 10:29:05 +01:00
Vassil Vassilev
01dbb6d9d5 Use a stable way to determine the address of printed objects.
Using unary operator address of (eg. MyClass m; &m) takes into account
overloaded operators which may not give us the precide address of the
allocated storage.

This patch teaches cling to use std::addressof instead.
2018-03-08 22:44:16 +01:00
Vassil Vassilev
c2a28b097f Remove redundant include. 2018-02-20 13:44:05 +01:00
Bertrand Bellenot
52028886df remove -fno-threadsafe-statics
this will have to be investigated/fixed in the JIT
2018-02-20 13:29:03 +01:00
Bertrand Bellenot
619d59ca32 Add comment
Windows requires std::ifstream::binary to properly handle
 CRLF and LF line endings
2018-02-20 13:29:03 +01:00
Bertrand Bellenot
67fc6cba13 inconditionally provide the std::ifstream::binary flag 2018-02-20 13:29:03 +01:00
Bertrand Bellenot
7c3649035f Several fixes for Windows
in CIFactory:
- Add -fno-threadsafe-statics flag (for Windows only), to prevent potential unresolved symbols at run-time

in MetaProcessor::readInputFromFile:
- add required std::ifstream::binary flag when opening the std::ifstream
- add missing backslashes

in PlatformWin:
- properly format error messages
- in IsDLL(): check and return false if the file size is 0
- fix _CxxThrowException symbol name (not fully understood - to be reviewed)
- filter out a couple of system dlls when looking for symbols
2018-02-20 13:29:03 +01:00
Vassil Vassilev
47aa5c23ef Find clang's binary include paths.
In cases where we do not have 'installed' clang we should try to find the
relevant include directories.
2018-02-20 10:59:12 +01:00
Vassil Vassilev
bfb4168dc9 Implement basic plugin support in cling.
We rely on clang's plugin infrastructure for loading, argument processing
and unloading plugins.

This patch teaches cling to work with clang plugins such as clad -- a
clang plugin implementing automatic differentiation facilities.
2018-02-20 10:59:12 +01:00
Vassil Vassilev
e13c60a010 Reduce extra char -> llvm::StringRef conversions. 2018-02-17 11:44:06 +01:00
Vassil Vassilev
847d280aac Use the regular lookup mechanisms in cling.
TClingClassInfo has a constructor that is supposed to be used for TU
scope lookups. However, it iterates over decls and causes lots of
deserializations. It does not respect the C++ lookup rules because it
returns the first decl with the name it finds.

This patch tries to keep the original behavior by first trying to do
a regular lookup and if the result is unambigious it returns the found
decl. If the result was ambiguous we try to disambiguate it (by turning
off the using directives) and return the found result.
2018-02-15 22:29:11 +01:00
Vassil Vassilev
3a82a25051 Do not rely on getSpecializations.
The getSpecialization interface now deserializes lazily template
specializations. While unloading we trigger creation of new specializations
which does not make sense.
2018-01-21 09:14:46 +01:00
Guilherme Amadio
50a795610f Match declarations of at_quick_exit and __cxa_atexit symbols for libc++ and C++17
On Linux, the same adjustments are needed as for libstdc++ and libc++,
so turn the condition into just #ifdef __linux__. However, since the
__cxa_atexit function is declared as extern "C" in libc++, we cannot
add "noexcept" to it, as is done for libstdc++.
2017-12-09 11:59:37 +01:00
Axel Naumann
9168e7d9ab Move enum attributes after "enum class X: int" (ROOT-9114).
With the attribute after "enum" and before the name, the name itself gets annotated
and subsequent lookups fail to identify the front-end token.
By moving the attribute behind the decl, the identifier is unmodified.
2017-12-07 17:00:35 +01:00
Axel Naumann
1193463c6f Revert "Address ROOT-9114 (Issues with dictionary's enum forward decl)"
This reverts commit 59c69dc2ce449eff8cabcf73405b04b07aaf9eb3.
Let's try to find the underlying issue...
2017-12-07 17:00:35 +01:00
Axel Naumann
2264e8c66f Mark compiler include paths as -cxx-isystem (ROOT-8991). 2017-12-06 15:29:30 +01:00
Axel Naumann
b55066ffea Claim #include <auto-parse-hdr> to remember the full path (ROOT-8863). 2017-12-06 05:59:06 +01:00
Axel Naumann
56b0e8e184 Print float with number of signif digits, double with 8. 2017-12-05 15:40:37 +01:00
Axel Naumann
582af5e250 Print "1.000000" for a double 1 instead of "1", as in 6.10.
Uses the # modifier to printf using the "alternate form".
2017-12-05 15:40:37 +01:00
Vassil Vassilev
fdca86db1d Set the SourceManager flag to enable -fmodules-embed-all-files.
This marks all files in the PCH/PCM transient. This allows clang to
stream them back within the zip in the PCH rather than requiring the
files to be physically present on disk.

This should resolve an introduced regression which materializes if
the files are moved/deleted after the generation of the PCH.
2017-11-30 14:52:08 +01:00
Bertrand Bellenot
92213e719a Switch object format from ELF to COFF and fix symbols lookup
- Switch object format from ELF (Linux) to COFF (Windows)
- Fix mangled symbols lookup on Windows: remove leading '_' and use malloc to simulate __imp_ variables (that are indirection pointers)
2017-11-29 22:30:07 +01:00
vagrant
54dbb830b3 Disable module file validation.
We need to disable the validation of PCM files because rootcling
serializes what it sees. For instance, we even serialize in the PCM
file some temporary lookup buffers and the contents of the module maps.

We disable the PCH validation but that is not sufficient for PCM. The
TCling code `fInterpreter->getCI()->getPreprocessorOpts().DisablePCHValidation = true`
is not enough because we rely more on the clang driver to setup correctly
our modules-aware interpreter.

This patch just uses the correct flag when setting up cling.

A proper fix to this issue is thoroughly described in RE-0003 (rootcling
refactor proposal).
2017-11-20 17:14:55 +01:00
Philippe Canal
8ca438b0d1 Address ROOT-9114 (Issues with dictionary's enum forward decl)
For now, do not decorate enums, this leads to some errors, likely
due to incorrect merging.  See https://sft.its.cern.ch/jira/browse/ROOT-9114

Note: that passing the set of forward declare and then actual declaration
to clang (both official and ROOT's custom version), there is no problem
seen.
2017-11-18 01:06:27 +01:00
Vassil Vassilev
c513776350 Fix typo, we want to suppress diag not enable it. 2017-11-14 04:13:43 +01:00
Vassil Vassilev
5abbe64ffd Work around an issue being resolved in PR1306. 2017-11-12 14:31:56 +01:00
Raphael Isemann
c41a49dabb Multiplex the ExternalASTSource in cling
We need to respect the existing ExternalASTSource when setting up the
interpreter. Otherwise the ASTReader (which is the existing source)
doesn't receive the required callbacks to properly load C++ modules.

This patch now creates a multiplexer that contains our new
ASTSource and the existing one if it's necessary. We also
no longer attach the existing sema source which seemingly
was only a workaround that only works for the special case
were the external sema source and the external AST source
are the same object.
2017-11-07 05:39:07 +01:00
Raphael Isemann
62eac4d1d2 Fix formatting of the TLS commit 2017-11-07 03:57:48 +01:00
Raphael Isemann
89c6351e3a Fix thread local storage in the cling JIT
TLS is currently not suppored in the JIT on some platforms.

However, it's possible to enable emulated TLS support in LLVM
which means that we now support TLS across many architectures.
The performance downsides of this are the overhead of accessing
the variable due to the additional indirection by the emulation.

However, this overhead is minimal and shouldn't affect most
programs. It also can be easily worked around from the user side.
This can be donefFor example by wrapping TLS variables into a single
TLS struct variable that then contains the other variables. Or just
minimizing referencing the TLS variable and use a normal copy of
the variable instead and write it back later.

Patch created with a lot of help from Lang Hames and Pavel Labath!
2017-11-07 03:57:48 +01:00
Axel Naumann
3bf7bc1a48 Use %g instead of %f, to preserve precision. 2017-11-06 21:20:19 +01:00
Vassil Vassilev
c912c9437d Switch back to O0.
We have a suboptimal behavior in the way cling optimizes code in O2 mode.
Disable it until the issue is understood and fixed.
2017-11-03 16:19:32 +01:00
Axel Naumann
3256a1dc1f Spelling. 2017-11-02 20:14:18 +01:00
Vassil Vassilev
e488ba8466 Rely on Azog to allocate the memory in an exception-aware manner. 2017-11-02 17:59:25 +01:00
Vassil Vassilev
985b2c8740 LLVM 5.0 comes with special library lookup ordering options.
Force using the old behavior and explain why it is not so good idea.
2017-11-02 17:59:25 +01:00
Vassil Vassilev
d6fe62edaf Return 0 if we cannot find an address.
Add an llvm_unreachable to handle potential errors.
2017-11-02 17:59:25 +01:00
Vassil Vassilev
5f3494f950 Do not forget to return from the function.
This was probably due to non-proprely merged conflict.
2017-11-02 17:59:25 +01:00
Vassil Vassilev
dfc5cf657d The annotation token became a special one.
We can only consume it with calling a special interface or calling ConsumeAnyToken.
2017-11-02 17:59:25 +01:00
Vassil Vassilev
8bfa1b52c6 Make this code path unreachable.
If we cannot return an address we should assert and handle the diags.
2017-11-02 17:59:25 +01:00
Vassil Vassilev
88c3d07bb9 Follow recent LLVM changes.
The orc jit API evolved as follows:
  * Use better error handling via llvm::Error and llvm::Expected<>
  * Switch back to the single llvm::Module concept as opposed to sets.
  * Use more expressive ownership model: extensive use of smart ptrs.
2017-11-02 17:59:25 +01:00
Vassil Vassilev
6e1865dafb Do not prevent copy elision. 2017-11-02 17:59:24 +01:00
Vassil Vassilev
97f45536c3 Use the setter. 2017-11-02 17:59:24 +01:00
Vassil Vassilev
16c99f41f6 Follow recent changes in the OptTable.
LLVM 5.0 introduces a field to describe possible allowed option values. This
aids the auto completion machanisms.
2017-11-02 17:59:24 +01:00
Vassil Vassilev
1a35776759 file_magic went into its own header file. 2017-11-02 17:59:24 +01:00
Vassil Vassilev
628c1fbc86 BBVectorize flag was unused and went away in LLVM 5.0 2017-11-02 17:59:24 +01:00
Raphael Isemann
00a59858a5 Manually initialize the module manager before callbacks.
Initializing the module manager overwrites the external Sema/AST sources
with the ASTReader.

As we are using our own sources in cling, we should manually initalize
the module manager when we are in the module mode before we set our
own custom sources (which respect any existing sources like the ones
created by the module manager).
2017-11-02 10:10:48 +01:00
Raphael Isemann
016eaa7620 Prepone callback initialization in cling.
We should setup our callbacks for ExternalASTSource/ExternalSemaSource
before we parse *any* code to prevent that any part of the code
stores a reference to a non-cling external sources. If this happens,
then the clang data structures such redecl chain could go out of
sync if they reference different sources and produce errors like failing
to merge declarations correctly or creating invalid redecl chains.

To fix this, we move this initalization before the initalization of
the incremental parser which is the first part that can generate
any AST nodes. We only do this for the modules case because in
the non-modules case the clang PCH overwrites our callback
in the ExternalASTSource and therefore would destroy our external
source.
2017-11-02 10:10:48 +01:00
Raphael Isemann
d411ed7885 Enable interpreter callbacks again
We actually need those callbacks as they are responsible for
loading decls from unresolved identifiers, which then actually
triggers the loading of the specific header (or in our case
the specific C++ modules).

For now we need this as long as the modules are based on the
rootmap mechanism.
2017-11-02 10:10:48 +01:00
Raphael Isemann
a03e320a33 Revert "[cxxmodules] Prepone callback initialization in cling."
This reverts commit 62fc3e9eddc6c7e78c3becf60092143607cddf50.
2017-11-01 15:33:02 +01:00
Raphael Isemann
8165c1c800 Revert "[cxxmodules] Manually initialize the module manager before callbacks."
This reverts commit 6b3f5a1f04afff77089d39c905b29ce0a411d683.
2017-11-01 15:33:02 +01:00
Raphael Isemann
e20f8edbec Manually initialize the module manager before callbacks.
Initializing the module manager overwrites the external Sema/AST sources
with the ASTReader.

As we are using our own sources in cling, we should manually initalize
the module manager when we are in the module mode before we set our
own custom sources (which respect any existing sources like the ones
created by the module manager).
2017-11-01 15:33:02 +01:00
Raphael Isemann
1ebf53715c Prepone callback initialization in cling.
We should setup our callbacks for ExternalASTSource/ExternalSemaSource
before we parse *any* code to prevent that any part of the code
stores a reference to a non-cling external sources. If this happens,
then the clang data structures such redecl chain could go out of
sync if they reference different sources and produce errors like failing
to merge declarations correctly or creating invalid redecl chains.

To fix this, we move this initalization before the initalization of
the incremental parser which is the first part that can generate
any AST nodes.
2017-11-01 15:33:02 +01:00
Raphael Isemann
0f16f1ac15 Don't always generate a module in CIFactory
Right now we always start generating a module in the CIFactory
when modules are enabled. However, we should only do that when
we actually want to generate a module according to the COpts
(e.g. the user has given a module that we should generate).
2017-10-29 14:14:46 +01:00
Vassil Vassilev
8647fad06d Ask Sema if we enabled modules.
That fixes an issue when running hsimple.C with modules on.
2017-10-28 16:29:08 +02:00
Raphael Isemann
99d1df55ae Fix assert failure with duplicate decls.
When generating the GQt module in rootcling, we hit the assertions
in forceAppend assertions about "Duplicates?!" with this declaration:

```
CXXRecordDecl 0x55555643fae8 </usr/include/qt4/QtCore/qglobal.h:1658:1, line:1794:1> line:1658:21 in GQt.TGQt.h hidden class QSysInfo definition
|-also in GQt.TQtClientWidget.h
|-CXXRecordDecl 0x55555643fc30 <col:1, col:21> col:21 in GQt.TGQt.h hidden implicit class QSysInfo
|-AccessSpecDecl 0x55555643fce8 <line:1659:1, col:7> col:1 in GQt.TGQt.h public
|-EnumDecl 0x55555643fd18 <line:1660:5, line:1662:5> line:1660:10 in GQt.TGQt.h hidden Sizes
| `-EnumConstantDecl 0x55555643fe98 <line:1661:9, col:38> col:9 in GQt.TGQt.h hidden WordSize 'enum QSysInfo::Sizes'
|   `-ImplicitCastExpr 0x55555643fee0 <col:20, col:38> 'unsigned int' <IntegralCast>
|     `-ParenExpr 0x55555643fe70 <col:20, col:38> 'unsigned long'
|       `-BinaryOperator 0x55555643fe48 <col:21, col:37> 'unsigned long' '<<'
|         |-UnaryExprOrTypeTraitExpr 0x55555643fe08 <col:21, col:34> 'unsigned long' sizeof 'void *'
|         `-IntegerLiteral 0x55555643fe28 <col:37> 'int' 3
`-EnumDecl 0x55555643ff00 <line:1672:5, line:1685:5> line:1672:10 in GQt.TGQt.h hidden Endian
  |-EnumConstantDecl 0x55555643ffd8 <line:1673:9> col:9 in GQt.TGQt.h hidden referenced BigEndian 'enum QSysInfo::Endian'
  |-EnumConstantDecl 0x555556440028 <line:1674:9> col:9 in GQt.TGQt.h hidden referenced LittleEndian 'enum QSysInfo::Endian'
  `-EnumConstantDecl 0x5555564400a0 <line:1681:11, col:23> col:11 in GQt.TGQt.h hidden ByteOrder 'enum QSysInfo::Endian'
    `-ImplicitCastExpr 0x5555564400e8 <col:23> 'unsigned int' <IntegralCast>
      `-DeclRefExpr 0x555556440070 <col:23> 'int' EnumConstant 0x555556440028 'LittleEndian' 'enum QSysInfo::Endian'
```

The reason for this is that we have QSysInfo both in the TQtClientWidget
and TGQt submodules and our current translation (which is supposed to
parse all header in the module) sees them both in one transaction.

As we also don't recognize that this decl is from a module, the code
fires the assert even though duplictes are expected with modules.

The reason why we don't recognize it as a declaration form an ASTFile
which disables the assert is that FromASTFile for the decls is
not set. This is because they haven't been loaded by the ASTFileReader
but are directly parsed as submodules in our special case where we
directly parse a module content from rootcling to generate it.

We just workaround in this patch by checking that if the decl is from
the currently generated module, we are pretending it's as if it was
loaded from an AST file.
2017-10-27 10:52:41 +02:00
Danilo Piparo
f081e145e8 Revert "Revert 548eca7 to bring back optimisation level of interpreter to O0"
This reverts commit 79ed4963868c758757c25b7d93ef98fac0e34774.
The commit tried to bring back the optimisation level to O0 but 2 tests fail
if this is done:
- roottest-cling-specialobj-reread
- roottest-root-io-datamodelevolution-make
2017-10-19 21:14:24 +02:00
Danilo Piparo
fde4b32b7c Revert 548eca7 to bring back optimisation level of interpreter to O0
Revert https://github.com/root-project/root/commit/548eca7 bringing back
optimisation level to O0 given the very long time needed to JIT simple
pieces of code.
This takes tens of seconds versus a few seconds:

using namespace ROOT::Experimental;
int test() {
   // build a TDF with 1 event and 1 column "x" that is always equal 42
   TDataFrame dd(1);
   auto d = dd.Define("x", []() { return 42; });

   // book nHistos histograms
   // all with the same cut and filled with the same variable in this simple example
   std::vector<TDF::TResultProxy<TH1D>> histos;
   const auto nHistos = 1000u;
   histos.reserve(nHistos);
   for (auto i = 0u; i < nHistos; ++i)
      histos.emplace_back(d.Histo1D("x"));

   // run event loop, print something to be sure everything is ok
   std::cout << histos.front()->GetMean() << std::endl;
   return 0;
}
2017-10-19 19:28:42 +02:00
Bertrand Bellenot
f8d746464b Silent many warnings on Windows 2017-10-17 15:44:31 +02:00
Axel Naumann
b1e4381dd5 Use the result of find(). 2017-10-11 21:56:45 +02:00
Vassil Vassilev
2a4be7cd70 Simplify llvm::Module emission in the JIT.
This teaches again the IncrementalExecutor to emit only one module at a time.
In the old MCJIT days, the API worked with module sets and cling assumed llvm's
jit infrastructure is moving in this direction.

LLVM 5.0 moves away from this concept and works with single llvm::Modules. This
patch will make the upgrade to LLVM 5.0 smoother.
2017-10-10 18:32:58 +02:00
Vassil Vassilev
fca3ee5f64 Disable a little to restrictive assert.
We are not quite ready to control that precisely the ownership.
2017-10-05 22:31:07 +02:00
Bertrand Bellenot
6bfd18bbc4 formatting (clang-format) 2017-10-05 17:59:08 +02:00
Bertrand Bellenot
988e5b00f2 Fix the Visual Studio 2017 directory location (quick and dirty hack). To be reviewed
The Visual Studio 2017 path is very different than the previous versions, and even the registry entries are completely different, so for now let's try the trivial way first (using the %VCToolsInstallDir% environment variable)
2017-10-05 17:59:08 +02:00
Vassil Vassilev
dfc0e8a2d4 shared_ptr-ize the llvm::Module*.
This is in prepare for the upcoming llvm upgrade. The future orc jit compile
layer needs a std::shared_ptr<llvm::Module>. The current design passes a
llvm::Module* around and any conversions to a shared_ptr cause the
destruction of the llvm::Module which is a long-lived object in cling.
2017-10-05 17:59:08 +02:00
Raphael Isemann
b24a3f704c clang-formated ForwardDeclPrinter::prettyPrintAttributes 2017-10-02 11:27:19 +02:00
Raphael Isemann
5a45b2f93d Fix assert failure when printing fwd delcs
With C++ modules we fail here because we get this extra 'include '
text before the actual header. As the header itself is correct
it seems, we just skip this extra text with modules enabled as
this code is anyway supposed to be replaced with modules
functionality.
2017-10-02 11:27:19 +02:00
Raphael Isemann
016c1fd372 Use clang's method for checking if we are in std::* 2017-09-27 10:24:51 +02:00
Raphael Isemann
b7783cf7a9 Remove unnecessary assert
After some discussion with Axel we decided that there is no point to
assert here. This feature here is not related to C++ modules.
2017-09-25 10:29:21 +02:00
Danilo Piparo
6dbdd2ab18 Fix ROOT-8359: the first compiler we look for is the one the path
then the one that was used to build cling and finally the one
in the absolute path (e.g. usr/bin/g++)
2017-09-22 08:29:26 +02:00
Raphael Isemann
246ce867e6 Print stacktrace before aborting on a missing exception.
We will probably see an increasing amount of these failures with
C++ modules as we now deserialize all declarations instead of just
the PCH ones. To safe us a lot of debugging time on where to push
the needed transaction, let's directly print the stack trace here
in the rare case that we crash here.
2017-09-20 22:44:21 +02:00
Raphael Isemann
779e64646e Don't overrite the DeserializationListener.
With the module generation in rootcling Clang rlies on AST consumers
to do the module generation work for it. Right now this doesn't work
however with the interpreter, as we just overwrite the deserialization
listener that clang added which will cause strange errors during
the module generation (the most prompinent error is that the number
of recorded submodules will be incorrect, as this it the first thing
that Clang checks before writing a module and which is recorded by
an ASTDeserializationListener).

This patch just adds a multiplexer here that allows us to keep the
old listener while also adding the one we have.
2017-09-20 13:55:20 +02:00
Axel Naumann
e88b4a338b Use lambda to avoid default ction of Value (thanks, Philippe!) 2017-09-18 14:29:05 +02:00
Axel Naumann
48e0ed72fe Add note to future self on multiplexing synchonization callbacks. 2017-09-18 14:29:05 +02:00
Axel Naumann
f033d3024f RAII, not RTTI: rename class and #includes. 2017-09-18 14:29:05 +02:00
Axel Naumann
1cb22ab987 RAII, not RTTI: rename file. 2017-09-18 14:29:05 +02:00
Axel Naumann
363deeffa1 Use LockCompilationDuringUserCodeExecutionRAII when compiling during user code execution. 2017-09-18 14:29:05 +02:00
Axel Naumann
5a7c0d122c Add RAII for LockCompilationDuringUserCodeExecution. 2017-09-18 14:29:05 +02:00
Axel Naumann
f195e8f2fd Add (Un)LockCompilationDuringUserCodeExecution() callback. 2017-09-18 14:29:05 +02:00
Raphael Isemann
bfe05be443 Now configuring C++ modules in CIFactory on -fmodules.
This patch adds support for writing out modules to the CIFactory.
If the user has passed -fmodule-name and -fmodules, we start
extending the CI instance with support for C++ modules and also
optionally setup AST consumers for writing out modules files
alongside the interpreter.
2017-09-14 13:29:20 +02:00
Raphael Isemann
d9475011ca Extended InvocationOptions with C++ modules flags.
This makes it easier for cling to check if -fmodules and/or
-fmodule-name is passed so that we can act on these flags in the
CIFactory.
2017-09-14 13:29:20 +02:00
Axel Naumann
eaa02cc638 Missing return statement! 2017-09-13 18:00:09 +02:00
Frederich Munch
da655d2e8e TextInput: Remove unused method. 2017-09-13 17:16:13 +02:00
Axel Naumann
bb161feccb Also recognize templates as identifier. 2017-09-13 17:14:08 +02:00
Axel Naumann
7f105f4ad5 Assume valid pointers for declare(). 2017-09-13 13:14:06 +02:00
Axel Naumann
89a7a1ead0 Only disable ptr checker, not all AST transformers! 2017-09-13 13:14:06 +02:00
Axel Naumann
5baa770702 Throw an interpreter exception when encountering a dynamic expression error.
Without throwing cling cannot communicate to the caller that the code has failed,
as the user code is currently running when failing the dynamic expression evaluation.
Fixes gROOT->ProcessLine("doesNotExist", &res) not signalling any error through res.
Well, it still does not set res to an error - but at least it now throws.
2017-09-13 13:03:03 +02:00
Raphael Isemann
84e413a1cb Use unique_ptr to better display ownership in CIFactory::createCI. 2017-09-10 13:59:13 +02:00
Axel Naumann
4681e8014f Do not diagnose instantiation failures during function lookup.
Fixes an issue for ATLAS, where Property<string>::Property<string&> cannot be instantiated by ROOT.
ROOT is trying to do that because the function is templated, with all template parameters having defaults.
(This "let us instantiate if all template params have defaults" is needed e.g. to see pair::pair() which is sfinae protected.)
2017-09-05 10:59:25 +02:00
Raphael Isemann
7efc518a7e Refactor resource path code into own function.
This is a preparation because we want to ship module configuration
files in the future in the cling resource directory (Clang VFS overlay
files and modulemaps). This means that we will need to know this path
in a few other places (e.g. where we specify the -ivfsoverlayPATH
arguments and potential -fmodule-map-file=PATH args)

It also makes this giant function a bit easier on the eyes.
2017-09-01 18:47:47 +02:00
Axel Naumann
15a4056c56 Whitespace. 2017-08-31 08:44:16 +02:00
Axel Naumann
62bcd0aa3b Use local lock reset state instead of a global stack.
Fixes threading issues: multiple threads storing and restoring mutex state, the
stack being modified concurrently etc.
2017-08-31 08:44:16 +02:00
Axel Naumann
8cfa532b72 Interpreter callback is created after Interpreter ctor. 2017-08-31 08:44:15 +02:00
Axel Naumann
63e3937b23 Add new interface to MultiplexInterpreterCallbacks. 2017-08-31 08:44:15 +02:00
Axel Naumann
4f41d10b0c Inform callback upon invoking functions / static init. 2017-08-31 08:44:15 +02:00
Axel Naumann
2a0b7a6495 Wrap enter/leave user code into RAII. 2017-08-31 08:44:15 +02:00
Axel Naumann
0f8914316e Rename executeInitOrWrapper to jitInitOrWrapper: it does not execute. 2017-08-31 08:44:15 +02:00
Bertrand Bellenot
5d4a7b51a7 Add support for Visual Studio 2017 2017-08-29 15:21:36 +02:00
Philippe Canal
6c368913e7 clang-format suggestion 2017-08-24 17:03:58 +02:00
Frederich Munch
38c4b902cf Fix registration of other atexit functions during an atexit handler. Recursive registration of atexit handlers is legal and should be handled, not ignored. 2017-08-24 17:03:58 +02:00