Commit Graph

4337 Commits

Author SHA1 Message Date
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
b639a0d53c Finish the revert in root-project/root@533dd5e50d
Duplicating Cling_Runtime and Cling_Runtime_Extra in both module.modulemap
and module.modulemap.build causes redefinition errors if -Dbuiltin_clang=Off.
We should not duplicate the cling runtime modules in both modulemaps.
2019-03-23 10:15:28 +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
1cb36481ba Add missing dependency. 2019-03-17 08:15:02 +01:00
Vassil Vassilev
daeaa6d9fb Fix failing test. 2019-03-17 08:15:02 +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
Oksana Shadura
59a46d513b Fixing compile time installation of clad in CMAKE_INSTALL_PATH
[ROOT-9924] Installing headers for clad
2019-02-05 11:44:03 +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
76fac41c28 test lookup of template function specialization (ROOT-9789). 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
5789f5b2eb Build clingDemoPlugin when testing. 2018-11-21 17:15:14 +01:00
Vassil Vassilev
51a83f543d Reduce the libraries we link to. 2018-11-21 17:15:14 +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
ce34bd7abf We do not need to mark explicitly funtions defined in a class inline.
See [dcl.inline].4: "A function defined within a class definition is an inline
function."
2018-11-16 16:43:58 +01:00
Vassil Vassilev
4336ae74c7 Standalone function definitions in headers must be marked inline. 2018-11-16 16:43:58 +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
Vassil Vassilev
fc33c22f45 Bump clad version to v0.4.
The new release includes some improvements in both Forward and
Reverse mode:
  * Support `x += y`, `x -= y`, `x *= y`, `x /= y`, `x++`, `x--`, `++x`, `--x`
    in forward mode.
  * Reduce emission of unused expressions
  * Add a special `#pragma clad ON/OFF/DEFAULT` to annotate regions which
    contain derivatives
  * Various small optimizations

See more at: https://github.com/vgvassilev/clad/blob/v0.4/docs/ReleaseNotes.md
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
7330bcb819 Change the linkage of functions and template specializations.
static, static inline, always_inline, and extern inline functions can
always be deferred. Normal inline functions can be deferred in C99/C++.
Implicit template instantiations can also be deferred in C++.

This patch changes the linkage of the declarations from strong to weak.
It allows clang to defer the deserialization from pch/pcm until their use.
2018-10-26 09:44:18 +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
Sylvain Corlay
7116e7239c Add missing libraries 2018-10-19 00:30:04 +02:00
Vassil Vassilev
cc57c1e08e 80 cols. 2018-10-16 16:59:55 +02:00
Yuka Takahashi
80fa13b41e Fix print.C
Remove semicolon to print out
2018-10-12 14:30:16 +02:00
Yuka Takahashi
d77a3252dc Fix print.C
ToString takes typename and an object pointer
2018-10-12 08:44:07 +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
Yuka Takahashi
53476daf4b Fix printing test in Cling
Testsuit was actually looking at '"' for match, comparing literal 21
should be enough.
2018-10-10 14:59:07 +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