From c5d853105026358840906145a9375af1ca238c66 Mon Sep 17 00:00:00 2001 From: Wim Lavrijsen Date: Thu, 26 Sep 2024 16:12:49 -0700 Subject: [PATCH] update ROOT/meta to LLVM16 --- cling/src/build/unix/makepchinput.py | 4 +- cling/src/core/clingutils/CMakeLists.txt | 2 +- cling/src/core/clingutils/src/TClingUtils.cxx | 124 +++++++++--------- .../src/core/dictgen/src/TModuleGenerator.cxx | 36 ++--- cling/src/core/dictgen/src/rootcling_impl.cxx | 9 +- cling/src/core/metacling/src/TCling.cxx | 76 +++++------ .../core/metacling/src/TClingCallbacks.cxx | 7 +- .../src/core/metacling/src/TClingCallbacks.h | 9 +- .../core/metacling/src/TClingMethodInfo.cxx | 9 +- .../src/TClingRdictModuleFileExtension.cxx | 10 +- .../src/TClingRdictModuleFileExtension.h | 2 +- 11 files changed, 143 insertions(+), 145 deletions(-) diff --git a/cling/src/build/unix/makepchinput.py b/cling/src/build/unix/makepchinput.py index 22b8df8f..e1af6a6b 100755 --- a/cling/src/build/unix/makepchinput.py +++ b/cling/src/build/unix/makepchinput.py @@ -324,7 +324,7 @@ def isDirForPCH(dirName, expPyROOT): def getLinesFromDict(marker, dictFileName): """ Search for the line marker - in the dictionary and save all lines until the line '0' + in the dictionary and save all lines until the line 'nullptr' Return them as List """ selectedLines = [] @@ -337,7 +337,7 @@ def getLinesFromDict(marker, dictFileName): recording = True continue - if recording and "0" == line[0]: break + if recording and "nullptr" == line[0:7]: break if recording: selectedLines.append(line[:-1]) diff --git a/cling/src/core/clingutils/CMakeLists.txt b/cling/src/core/clingutils/CMakeLists.txt index d66ca7f8..3a5b8c63 100644 --- a/cling/src/core/clingutils/CMakeLists.txt +++ b/cling/src/core/clingutils/CMakeLists.txt @@ -42,7 +42,7 @@ ROOT_INSTALL_HEADERS() set(CLANG_RESOURCE_DIR_STEM) if (builtin_clang) set(CLANG_RESOURCE_DIR_STEM ${CMAKE_BINARY_DIR}/interpreter/llvm-project/llvm/${CMAKE_CFG_INTDIR}/lib/clang) - set(CLANG_RESOURCE_DIR_VERSION ${LLVM_VERSION}) + set(CLANG_RESOURCE_DIR_VERSION ${LLVM_VERSION_MAJOR}) else () set(CLANG_RESOURCE_DIR_STEM ${LLVM_LIBRARY_DIR}/clang) # A user can define a clang version to use, otherwise find it (but will error if more than one version is present) diff --git a/cling/src/core/clingutils/src/TClingUtils.cxx b/cling/src/core/clingutils/src/TClingUtils.cxx index 95b729bc..faa22e12 100644 --- a/cling/src/core/clingutils/src/TClingUtils.cxx +++ b/cling/src/core/clingutils/src/TClingUtils.cxx @@ -121,7 +121,7 @@ static clang::NestedNameSpecifier* AddDefaultParametersNNS(const clang::ASTConte clang::NestedNameSpecifier* scope, const cling::Interpreter &interpreter, const CppyyLegacy::TMetaUtils::TNormalizedCtxt &normCtxt) { - if (!scope) return 0; + if (!scope) return nullptr; const clang::Type* scope_type = scope->getAsType(); if (scope_type) { @@ -170,7 +170,7 @@ static clang::NestedNameSpecifier* ReSubstTemplateArgNNS(const clang::ASTContext clang::NestedNameSpecifier *scope, const clang::Type *instance) { - if (!scope) return 0; + if (!scope) return nullptr; const clang::Type* scope_type = scope->getAsType(); if (scope_type) { @@ -219,8 +219,7 @@ static const clang::FieldDecl *GetDataMemberFromAll(const clang::CXXRecordDecl & return *field_iter; } } - return 0; - + return nullptr; } //////////////////////////////////////////////////////////////////////////////// @@ -696,7 +695,7 @@ bool CppyyLegacy::TMetaUtils::IsBase(const clang::FieldDecl &m, const char* base } const clang::NamedDecl *base - = ScopeSearch(basename, interp, true /*diagnose*/, 0); + = ScopeSearch(basename, interp, true /*diagnose*/, nullptr); if (base) { return IsBase(CRD, llvm::dyn_cast( base ), @@ -715,7 +714,7 @@ int CppyyLegacy::TMetaUtils::ElementStreamer(std::ostream& finalString, const char *tcl) { static const clang::CXXRecordDecl *TObject_decl - = CppyyLegacy::TMetaUtils::ScopeSearch("CppyyLegacy::TObject", interp, true /*diag*/, 0); + = CppyyLegacy::TMetaUtils::ScopeSearch("CppyyLegacy::TObject", interp, true /*diag*/, nullptr); enum { kBIT_ISTOBJECT = 0x10000000, kBIT_HASSTREAMER = 0x20000000, @@ -753,7 +752,7 @@ int CppyyLegacy::TMetaUtils::ElementStreamer(std::ostream& finalString, if (tiName == "std::string*") kase |= kBIT_ISSTRING; - if (tcl == 0) { + if (!tcl) { tcl = " internal error in rootcling "; } // if (strcmp(objType,"std::string")==0) RStl::Instance().GenerateTClassFor( "std::string", interp, normCtxt ); @@ -972,7 +971,7 @@ const clang::CXXMethodDecl *GetMethodWithProto(const clang::Decl* cinfo, namespace CppyyLegacy { namespace TMetaUtils { - RConstructorType::RConstructorType(const char *type_of_arg, const cling::Interpreter &interp) : fArgTypeName(type_of_arg),fArgType(0) + RConstructorType::RConstructorType(const char *type_of_arg, const cling::Interpreter &interp) : fArgTypeName(type_of_arg),fArgType(nullptr) { const cling::LookupHelper& lh = interp.getLookupHelper(); // We can not use findScope since the type we are given are usually, @@ -997,15 +996,14 @@ bool CppyyLegacy::TMetaUtils::HasIOConstructor(const clang::CXXRecordDecl *cl, { if (cl->isAbstract()) return false; - for (RConstructorTypes::const_iterator ctorTypeIt = ctorTypes.begin(); - ctorTypeIt!=ctorTypes.end(); ++ctorTypeIt) { + for (auto & ctorType : ctorTypes) { - auto ioCtorCat = CppyyLegacy::TMetaUtils::CheckConstructor(cl, *ctorTypeIt, interp); + auto ioCtorCat = CppyyLegacy::TMetaUtils::CheckConstructor(cl, ctorType, interp); if (EIOCtorCategory::kAbsent == ioCtorCat) continue; - std::string proto( ctorTypeIt->GetName() ); + std::string proto( ctorType.GetName() ); bool defaultCtor = proto.empty(); if (defaultCtor) { arg.clear(); @@ -1366,21 +1364,15 @@ bool CppyyLegacy::TMetaUtils::hasOpaqueTypedef(clang::QualType instanceType, con // do the template thing. const clang::TemplateSpecializationType* TST = llvm::dyn_cast(instanceType.getTypePtr()); - if (TST==0) { + if (!TST) { // std::string type_name; // type_name = GetQualifiedName( instanceType, *clxx ); // fprintf(stderr,"ERROR: Could not findS TST for %s\n",type_name.c_str()); return false; } - for(clang::TemplateSpecializationType::iterator - I = TST->begin(), E = TST->end(); - I!=E; ++I) - { - if (I->getKind() == clang::TemplateArgument::Type) { - // std::string arg; - // arg = GetQualifiedName( I->getAsType(), *clxx ); - // fprintf(stderr,"DEBUG: looking at %s\n", arg.c_str()); - result |= CppyyLegacy::TMetaUtils::hasOpaqueTypedef(I->getAsType(), normCtxt); + for (const clang::TemplateArgument &TA : TST->template_arguments()) { + if (TA.getKind() == clang::TemplateArgument::Type) { + result |= CppyyLegacy::TMetaUtils::hasOpaqueTypedef(TA.getAsType(), normCtxt); } } } @@ -1395,7 +1387,7 @@ bool CppyyLegacy::TMetaUtils::hasOpaqueTypedef(const AnnotatedRecordDecl &cl, const TNormalizedCtxt &normCtxt) { const clang::CXXRecordDecl* clxx = llvm::dyn_cast(cl.GetRecordDecl()); - if (clxx->getTemplateSpecializationKind() == clang::TSK_Undeclared) return false; + if (!clxx || clxx->getTemplateSpecializationKind() == clang::TSK_Undeclared) return false; clang::QualType instanceType = interp.getLookupHelper().findType(cl.GetNormalizedName(), cling::LookupHelper::WithDiagnostics); @@ -1539,7 +1531,7 @@ void CppyyLegacy::TMetaUtils::WriteClassInit(std::ostream& finalString, } if (HasIOConstructor(decl, args, ctorTypes, interp)) { - finalString << " static void *new_" << mappedname.c_str() << "(void *p = 0);" << "\n"; + finalString << " static void *new_" << mappedname.c_str() << "(void *p = nullptr);" << "\n"; if (args.size()==0 && NeedDestructor(decl, interp)) { @@ -1571,11 +1563,11 @@ void CppyyLegacy::TMetaUtils::WriteClassInit(std::ostream& finalString, finalString << " static TGenericClassInfo *GenerateInitInstanceLocal(const " << csymbol << "*)" << "\n" << " {" << "\n"; - finalString << " " << csymbol << " *ptr = 0;" << "\n"; + finalString << " " << csymbol << " *ptr = nullptr;" << "\n"; //fprintf(fp, " static ::CppyyLegacy::ClassInfo< %s > \n",classname.c_str()); if (ClassInfo__HasMethod(decl,"IsA",interp) ) { - finalString << " static ::CppyyLegacy::TVirtualIsAProxy* isa_proxy = new ::CppyyLegacy::TInstrumentedIsAProxy< " << csymbol << " >(0);" << "\n"; + finalString << " static ::CppyyLegacy::TVirtualIsAProxy* isa_proxy = new ::CppyyLegacy::TInstrumentedIsAProxy< " << csymbol << " >(nullptr);" << "\n"; } else { finalString << " static ::CppyyLegacy::TVirtualIsAProxy* isa_proxy = new ::CppyyLegacy::TIsAProxy(typeid(" << csymbol << "));" << "\n"; @@ -1691,7 +1683,7 @@ void CppyyLegacy::TMetaUtils::WriteClassInit(std::ostream& finalString, methodTCP="Insert"; break; } - // FIXME Workaround: for the moment we do not generate coll proxies with unique ptrs sincelast + // FIXME Workaround: for the moment we do not generate coll proxies with unique ptrs since // they imply copies and therefore do not compile. auto classNameForIO = TClassEdit::GetNameForIO(classname); finalString << " instance.AdoptCollectionProxyInfo(TCollectionProxyInfo::Generate(TCollectionProxyInfo::" << methodTCP << "< " << classNameForIO.c_str() << " >()));" << "\n"; @@ -1978,10 +1970,10 @@ bool CppyyLegacy::TMetaUtils::HasCustomOperatorNewPlacement(const char *which, c ctxtnewPlacement = operatornewPlacement->getParent(); } - if (ctxtnewPlacement == 0) { + if (!ctxtnewPlacement) { return false; } - if (ctxtnew == 0) { + if (!ctxtnew) { // Only a new with placement, no hiding return true; } @@ -1992,17 +1984,17 @@ bool CppyyLegacy::TMetaUtils::HasCustomOperatorNewPlacement(const char *which, c } const clang::CXXRecordDecl* clnew = llvm::dyn_cast(ctxtnew); const clang::CXXRecordDecl* clnewPlacement = llvm::dyn_cast(ctxtnewPlacement); - if (clnew == 0 && clnewPlacement == 0) { + if (!clnew && !clnewPlacement) { // They are both in different namespaces, I am not sure of the rules. // we probably ought to find which one is closest ... for now bail // (because rootcling was also bailing on that). return true; } - if (clnew != 0 && clnewPlacement == 0) { + if (clnew && !clnewPlacement) { // operator new is class method hiding the outer scope operator new with placement. return false; } - if (clnew == 0 && clnewPlacement != 0) { + if (!clnew && clnewPlacement) { // operator new is a not class method and can not hide new with placement which is a method return true; } @@ -2565,7 +2557,7 @@ clang::QualType CppyyLegacy::TMetaUtils::AddDefaultParameters(clang::QualType in // Treat the Scope. bool prefix_changed = false; - clang::NestedNameSpecifier* prefix = 0; + clang::NestedNameSpecifier* prefix = nullptr; clang::Qualifiers prefix_qualifiers = instanceType.getLocalQualifiers(); const clang::ElaboratedType* etype = llvm::dyn_cast(instanceType.getTypePtr()); @@ -2608,12 +2600,12 @@ clang::QualType CppyyLegacy::TMetaUtils::AddDefaultParameters(clang::QualType in unsigned int dropDefault = normCtxt.GetConfig().DropDefaultArg(*Template); llvm::SmallVector desArgs; + llvm::SmallVector canonArgs; + llvm::ArrayRef template_arguments = TST->template_arguments(); unsigned int Idecl = 0, Edecl = TSTdecl->getTemplateArgs().size(); unsigned int maxAddArg = TSTdecl->getTemplateArgs().size() - dropDefault; - for(clang::TemplateSpecializationType::iterator - I = TST->begin(), E = TST->end(); - Idecl != Edecl; - I!=E ? ++I : 0, ++Idecl, ++Param) { + for (const clang::TemplateArgument *I = template_arguments.begin(), *E = template_arguments.end(); Idecl != Edecl; + I != E ? ++I : nullptr, ++Idecl, ++Param) { if (I != E) { @@ -2635,7 +2627,10 @@ clang::QualType CppyyLegacy::TMetaUtils::AddDefaultParameters(clang::QualType in desArgs.push_back(*I); continue; } - clang::TemplateName templateNameWithNSS ( Ctx.getQualifiedTemplateName(nns, false, templateDecl) ); + clang::TemplateName UnderlyingTN(templateDecl); + if (clang::UsingShadowDecl *USD = templateName.getAsUsingShadowDecl()) + UnderlyingTN = clang::TemplateName(USD); + clang::TemplateName templateNameWithNSS ( Ctx.getQualifiedTemplateName(nns, false, UnderlyingTN) ); desArgs.push_back(clang::TemplateArgument(templateNameWithNSS)); mightHaveChanged = true; continue; @@ -2690,6 +2685,7 @@ clang::QualType CppyyLegacy::TMetaUtils::AddDefaultParameters(clang::QualType in RAngleLoc, TTP, desArgs, + canonArgs, HasDefaultArgs); // The substition can fail, in which case there would have been compilation // error printed on the screen. @@ -3004,7 +3000,7 @@ std::string CppyyLegacy::TMetaUtils::GetFileName(const clang::Decl& decl, const FileEntry *headerFE = sourceManager.getFileEntryForID(headerFID); while (includeLoc.isValid() && sourceManager.isInSystemHeader(includeLoc)) { - const DirectoryLookup *foundDir = 0; + ConstSearchDirIterator *foundDir = nullptr; // use HeaderSearch on the basename, to make sure it takes a header from // the include path (e.g. not from /usr/include/bits/) assert(headerFE && "Couldn't find FileEntry from FID!"); @@ -3053,7 +3049,7 @@ std::string CppyyLegacy::TMetaUtils::GetFileName(const clang::Decl& decl, // points to the same file as the long version. If such a short version // exists it will be returned. If it doesn't the long version is returned. bool isAbsolute = llvm::sys::path::is_absolute(headerFileName); - llvm::Optional FELong; + clang::OptionalFileEntryRef FELong; // Find the longest available match. for (llvm::sys::path::const_iterator IDir = llvm::sys::path::begin(headerFileName), @@ -3069,7 +3065,7 @@ std::string CppyyLegacy::TMetaUtils::GetFileName(const clang::Decl& decl, assert(trailingPart.data() + trailingPart.size() == headerFileName.data() + headerFileName.size() && "Mismatched partitioning of file name!"); - const DirectoryLookup* FoundDir = 0; + ConstSearchDirIterator *FoundDir = nullptr; FELong = HdrSearch.LookupFile(trailingPart, SourceLocation(), true /*isAngled*/, 0/*FromDir*/, FoundDir, ArrayRef>(), @@ -3093,7 +3089,7 @@ std::string CppyyLegacy::TMetaUtils::GetFileName(const clang::Decl& decl, assert(trailingPart.data() + trailingPart.size() == headerFileName.data() + headerFileName.size() && "Mismatched partitioning of file name!"); - const DirectoryLookup* FoundDir = 0; + ConstSearchDirIterator *FoundDir = nullptr; // Can we find it, and is it the same file as the long version? // (or are we back to the previously found spelling, which is fine, too) if (HdrSearch.LookupFile(trailingPart, SourceLocation(), @@ -3288,12 +3284,14 @@ static bool areEqualTypes(const clang::TemplateArgument& tArg, { clang::Sema& S = interp.getCI()->getSema(); cling::Interpreter::PushTransactionRAII clingRAII(const_cast(&interp)); + llvm::SmallVector canonArgs; bool HasDefaultArgs; TemplateArgumentLoc defTArgLoc = S.SubstDefaultTemplateArgumentIfAvailable(Template, TemplateLoc, LAngleLoc, ttpdPtr, preceedingTArgs, + canonArgs, HasDefaultArgs); // The substition can fail, in which case there would have been compilation // error printed on the screen. @@ -3526,7 +3524,8 @@ static void KeepNParams(clang::QualType& normalizedType, llvm::SmallVector argsToKeep; const int nArgs = tArgs.size(); - const int nNormArgs = normalizedTst->getNumArgs(); + const auto &normArgs = normalizedTst->template_arguments(); + const int nNormArgs = normArgs.size(); bool mightHaveChanged = false; @@ -3544,7 +3543,7 @@ static void KeepNParams(clang::QualType& normalizedType, if (formal == nNormArgs || inst == nNormArgs) break; const TemplateArgument& tArg = tArgs.get(formal); - TemplateArgument normTArg(normalizedTst->getArgs()[inst]); + TemplateArgument normTArg(normArgs[inst]); bool shouldKeepArg = nArgsToKeep < 0 || inst < nArgsToKeep; if (isStdDropDefault) shouldKeepArg = false; @@ -3562,7 +3561,7 @@ static void KeepNParams(clang::QualType& normalizedType, // in the template instance. So to avoid inadvertenly dropping those // arguments we just process all remaining argument and exit the main loop. for( ; inst != nNormArgs; ++inst) { - normTArg = normalizedTst->getArgs()[inst]; + normTArg = normArgs[inst]; mightHaveChanged |= RecurseKeepNParams(normTArg, tArg, interp, normCtxt, astCtxt); argsToKeep.push_back(normTArg); } @@ -4200,10 +4199,8 @@ static bool hasSomeTypedefSomewhere(const clang::Type* T) { return Visit(STST->getReplacementType().getTypePtr()); } bool VisitTemplateSpecializationType(const TemplateSpecializationType* TST) { - for (int I = 0, N = TST->getNumArgs(); I < N; ++I) { - const TemplateArgument& TA = TST->getArg(I); - if (TA.getKind() == TemplateArgument::Type - && Visit(TA.getAsType().getTypePtr())) + for (const TemplateArgument &TA : TST->template_arguments()) { + if (TA.getKind() == TemplateArgument::Type && Visit(TA.getAsType().getTypePtr())) return true; } return false; @@ -4212,7 +4209,7 @@ static bool hasSomeTypedefSomewhere(const clang::Type* T) { return false; // shrug... } bool VisitTypeOfType(const TypeOfType* TOT) { - return TOT->getUnderlyingType().getTypePtr(); + return TOT->getUnmodifiedType().getTypePtr(); } bool VisitElaboratedType(const ElaboratedType* ET) { NestedNameSpecifier* NNS = ET->getQualifier(); @@ -4374,7 +4371,7 @@ clang::QualType CppyyLegacy::TMetaUtils::ReSubstTemplateArg(clang::QualType inpu // Make sure it got replaced from this template const clang::ClassTemplateDecl *replacedCtxt = 0; - const clang::DeclContext *replacedDeclCtxt = substType->getReplacedParameter()->getDecl()->getDeclContext(); + const clang::DeclContext *replacedDeclCtxt = substType->getReplacedParameter()->getDeclContext(); const clang::CXXRecordDecl *decl = llvm::dyn_cast(replacedDeclCtxt); unsigned int index = substType->getReplacedParameter()->getIndex(); if (decl) { @@ -4434,17 +4431,22 @@ clang::QualType CppyyLegacy::TMetaUtils::ReSubstTemplateArg(clang::QualType inpu if ((replacedCtxt && replacedCtxt->getCanonicalDecl() == TSTdecl->getSpecializedTemplate()->getCanonicalDecl()) || /* the following is likely just redundant */ - substType->getReplacedParameter()->getDecl() + substType->getReplacedParameter() == TSTdecl->getSpecializedTemplate ()->getTemplateParameters()->getParam(index)) { - if ( index >= TST->getNumArgs() ) { + const auto &TAs = TST->template_arguments(); + if (index >= TAs.size()) { // The argument replaced was a default template argument that is // being listed as part of the instance ... // so we probably don't really know how to spell it ... we would need to recreate it // (See AddDefaultParameters). return input; + } else if (TAs[index].getKind() == clang::TemplateArgument::Type) { + return TAs[index].getAsType(); } else { - return TST->getArg(index).getAsType(); + // The argument is (likely) a value or expression and there is nothing for us + // to change + return input; } } } @@ -4456,16 +4458,16 @@ clang::QualType CppyyLegacy::TMetaUtils::ReSubstTemplateArg(clang::QualType inpu if (inputTST) { bool mightHaveChanged = false; llvm::SmallVector desArgs; - for(clang::TemplateSpecializationType::iterator I = inputTST->begin(), E = inputTST->end(); - I != E; ++I) { - if (I->getKind() != clang::TemplateArgument::Type) { - desArgs.push_back(*I); + for (const clang::TemplateArgument &TA : inputTST->template_arguments()) { + if (TA.getKind() != clang::TemplateArgument::Type) { + desArgs.push_back(TA); continue; } - clang::QualType SubTy = I->getAsType(); + clang::QualType SubTy = TA.getAsType(); // Check if the type needs more desugaring and recurse. - if (llvm::isa(SubTy) + if (llvm::isa(SubTy) + || llvm::isa(SubTy) || llvm::isa(SubTy)) { clang::QualType newSubTy = ReSubstTemplateArg(SubTy,instance); mightHaveChanged = SubTy != newSubTy; @@ -4473,7 +4475,7 @@ clang::QualType CppyyLegacy::TMetaUtils::ReSubstTemplateArg(clang::QualType inpu desArgs.push_back(clang::TemplateArgument(newSubTy)); } } else - desArgs.push_back(*I); + desArgs.push_back(TA); } // If desugaring happened allocate new type in the AST. diff --git a/cling/src/core/dictgen/src/TModuleGenerator.cxx b/cling/src/core/dictgen/src/TModuleGenerator.cxx index 0500c119..656b631c 100644 --- a/cling/src/core/dictgen/src/TModuleGenerator.cxx +++ b/cling/src/core/dictgen/src/TModuleGenerator.cxx @@ -78,11 +78,17 @@ TModuleGenerator::TModuleGenerator(CompilerInstance *CI, // .pcm -> .pch if (IsPCH()) fModuleFileName[fModuleFileName.length() - 1] = 'h'; - // Add a random string to the filename to avoid races - llvm::SmallString<10> resultPath("%%%%%%%%%%"); - llvm::sys::fs::getPotentiallyUniqueFileName(resultPath.str(), resultPath); - fUmbrellaName = fModuleDirName + fDictionaryName + resultPath.c_str() + "_dictUmbrella.h"; - fContentName = fModuleDirName + fDictionaryName + resultPath.c_str() + "_dictContent.h"; + // Add a random string to the filename to avoid races. + auto makeTempFile = [&](const char *suffix) { + llvm::SmallString<64> resultPath; + std::string pattern = fModuleDirName + fDictionaryName + "%%%%%%%%%%" + suffix; + llvm::sys::fs::createUniqueFile(pattern, resultPath); // NOTE: this creates the (empty) file + // Return the full buffer, so caller can use `.c_str()` on the temporary. + return resultPath; + }; + + fUmbrellaName = makeTempFile("_dictUmbrella.h").c_str(); + fContentName = makeTempFile("_dictContent.h").c_str(); } TModuleGenerator::~TModuleGenerator() @@ -112,10 +118,10 @@ TModuleGenerator::GetSourceFileKind(const char *filename) const // via the FileManager. clang::Preprocessor &PP = fCI->getPreprocessor(); clang::HeaderSearch &HdrSearch = PP.getHeaderSearchInfo(); - const clang::DirectoryLookup *CurDir = 0; + clang::ConstSearchDirIterator *CurDir = nullptr; auto hdrFileEntry = HdrSearch.LookupFile(filename, clang::SourceLocation(), - true /*isAngled*/, 0 /*FromDir*/, CurDir, + true /*isAngled*/, nullptr /*FromDir*/, CurDir, clang::ArrayRef>(), nullptr /*SearchPath*/,/*RelativePath*/ nullptr, @@ -289,7 +295,7 @@ std::ostream &TModuleGenerator::WritePPIncludes(std::ostream &out) const if (fInlineInputHeaders){ bool headerFound = FindHeader(incl,fullHeaderPath); if (!headerFound){ - CppyyLegacy::TMetaUtils::Error(0, "Cannot find header %s: cannot inline it.\n", fullHeaderPath.c_str()); + CppyyLegacy::TMetaUtils::Error(nullptr, "Cannot find header %s: cannot inline it.\n", fullHeaderPath.c_str()); continue; } @@ -313,7 +319,7 @@ std::ostream &TModuleGenerator::WriteStringVec(const std::vector &v for (auto const & theStr : vec) { out << "\"" << theStr << "\",\n"; } - out << "0" << std::endl; + out << "nullptr" << std::endl; return out; } @@ -337,7 +343,7 @@ std::ostream &TModuleGenerator::WriteStringPairVec(const StringPairVec_t &vec, } out << "\",\n"; } - out << "0" << std::endl; + out << "nullptr" << std::endl; return out; } @@ -365,7 +371,7 @@ void TModuleGenerator::WriteRegistrationSourceImpl(std::ostream& out, out << " static const char* fwdDeclCode = " << fwdDeclStringRAW << ";\n" << " static const char* payloadCode = " << payloadCodeWrapped << ";\n"; - // classesHeaders may depen on payloadCode + // classesHeaders may depend on payloadCode out << " static const char* classesHeaders[] = {\n" << headersClassesMapString << "\n};\n"; @@ -467,7 +473,7 @@ void TModuleGenerator::WriteRegistrationSource(std::ostream &out, const std::str auto findAndAddToInlineHeaders = [&](const std::string& hdrName) { bool headerFound = FindHeader(hdrName,hdrFullPath); if (!headerFound) { - CppyyLegacy::TMetaUtils::Error(0, "Cannot find header %s: cannot inline it.\n", hdrName.c_str()); + CppyyLegacy::TMetaUtils::Error(nullptr, "Cannot find header %s: cannot inline it.\n", hdrName.c_str()); } else { std::ifstream headerFile(hdrFullPath.c_str()); const std::string headerFileAsStr((std::istreambuf_iterator(headerFile)), @@ -574,12 +580,12 @@ bool TModuleGenerator::FindHeader(const std::string &hdrName, std::string &hdrFu } clang::Preprocessor &PP = fCI->getPreprocessor(); clang::HeaderSearch &HdrSearch = PP.getHeaderSearchInfo(); - const clang::DirectoryLookup *CurDir = 0; + clang::ConstSearchDirIterator *CurDir = nullptr; if (auto hdrFileEntry = HdrSearch.LookupFile(hdrName, clang::SourceLocation(), - true /*isAngled*/, 0 /*FromDir*/, CurDir, + true /*isAngled*/, nullptr /*FromDir*/, CurDir, clang::ArrayRef>(), + const clang::DirectoryEntry*>>(), nullptr /*SearchPath*/, nullptr /*RelativePath*/, nullptr /*RequestingModule*/, nullptr/*SuggestedModule*/, nullptr /*IsMapped*/, nullptr /*IsFrameworkFound*/)) { diff --git a/cling/src/core/dictgen/src/rootcling_impl.cxx b/cling/src/core/dictgen/src/rootcling_impl.cxx index a26aa624..c0b6e2d8 100644 --- a/cling/src/core/dictgen/src/rootcling_impl.cxx +++ b/cling/src/core/dictgen/src/rootcling_impl.cxx @@ -3564,9 +3564,9 @@ class TRootClingCallbacks : public cling::InterpreterCallbacks { virtual void InclusionDirective(clang::SourceLocation /*HashLoc*/, const clang::Token & /*IncludeTok*/, llvm::StringRef FileName, bool IsAngled, clang::CharSourceRange /*FilenameRange*/, - const clang::FileEntry * /*File*/, llvm::StringRef /*SearchPath*/, + clang::OptionalFileEntryRef /*File*/, llvm::StringRef /*SearchPath*/, llvm::StringRef /*RelativePath*/, const clang::Module * /*Imported*/, - clang::SrcMgr::CharacteristicKind /*FileType*/) + clang::SrcMgr::CharacteristicKind /*FileType*/) override { if (isLocked) return; if (IsAngled) return; @@ -3606,7 +3606,8 @@ class TRootClingCallbacks : public cling::InterpreterCallbacks { Preprocessor& PP = m_Interpreter->getCI()->getPreprocessor(); HeaderSearch& HS = PP.getHeaderSearchInfo(); // FIXME: Reduce to CoreLegacy.Rtypes.h. - Module* CoreModule = HS.lookupModule("CoreLegacy", /*AllowSearch*/false); + Module* CoreModule = HS.lookupModule("CoreLegacy", SourceLocation(), + /*AllowSearch*/false); assert(M && "Must have module CoreLegacy"); PP.makeModuleVisible(CoreModule, ImportLoc); } @@ -4499,7 +4500,7 @@ int RootClingMain(int argc, // Process externally passed arguments if present. llvm::Optional EnvOpt = llvm::sys::Process::GetEnv("EXTRA_CLING_ARGS"); - if (EnvOpt.hasValue()) { + if (EnvOpt.has_value()) { llvm::StringRef Env(*EnvOpt); while (!Env.empty()) { llvm::StringRef Arg; diff --git a/cling/src/core/metacling/src/TCling.cxx b/cling/src/core/metacling/src/TCling.cxx index d3d76c8f..ff58114f 100644 --- a/cling/src/core/metacling/src/TCling.cxx +++ b/cling/src/core/metacling/src/TCling.cxx @@ -444,7 +444,7 @@ void TCling::UpdateEnumConstants(TEnum* enumObj, TClass* cl) const { // Create the TEnumConstant or update it if existing TEnumConstant* enumConstant = nullptr; - TClingClassInfo* tcCInfo = (TClingClassInfo*)(cl ? cl->GetClassInfo() : 0); + TClingClassInfo* tcCInfo = (TClingClassInfo*)(cl ? cl->GetClassInfo() : nullptr); TClingDataMemberInfo* tcDmInfo = new TClingDataMemberInfo(GetInterpreterImpl(), *EDI, tcCInfo); DataMemberInfo_t* dmInfo = (DataMemberInfo_t*) tcDmInfo; if (TObject* encAsTObj = enumObj->GetConstants()->FindObject(constantName)){ @@ -481,7 +481,7 @@ TEnum* TCling::CreateEnum(void *VD, TClass *cl) const // If the enum is unnamed we do not add it to the list of enums i.e unusable. } if (buf.empty()) { - return 0; + return nullptr; } const char* name = buf.c_str(); @@ -547,7 +547,7 @@ void TCling::HandleNewDecl(const void* DV, bool isDeserialized, std::setGetListOfGlobals()->Add(new TGlobal((DataMemberInfo_t *) new TClingDataMemberInfo(GetInterpreterImpl(), - cast(ND), 0))); + cast(ND), nullptr))); } } @@ -649,11 +649,6 @@ extern "C" void TCling__SplitAclicMode(const char* fileName, string &mode, io = aclicio.Data(); fname = f.Data(); } -// Implemented in TClingCallbacks. -extern "C" void TCling__FindLoadedLibraries(std::vector> &sLibraries, - std::vector &sPaths, - cling::Interpreter &interpreter, bool searchSystem); - //______________________________________________________________________________ // // @@ -687,14 +682,6 @@ static clang::ClassTemplateDecl* FindTemplateInNamespace(clang::Decl* decl) return nullptr; // something went wrong. } -//////////////////////////////////////////////////////////////////////////////// -/// Autoload a library provided the mangled name of a missing symbol. - -void* llvmLazyFunctionCreator(const std::string& mangled_name) -{ - return ((TCling*)gCling)->LazyFunctionCreatorAutoload(mangled_name); -} - //______________________________________________________________________________ // // @@ -773,7 +760,7 @@ int TCling_GenerateDictionary(const std::vector &classes, for (it = fwdDecls.begin(); it != fwdDecls.end(); ++it) { fileContent += "class " + *it + ";\n"; } - fileContent += "#ifdef __CINT__ \n"; + fileContent += "#ifdef __CLING__ \n"; fileContent += "#pragma link C++ nestedclasses;\n"; fileContent += "#pragma link C++ nestedtypedefs;\n"; for (it = classes.begin(); it != classes.end(); ++it) { @@ -804,7 +791,7 @@ int TCling_GenerateDictionary(const std::vector &classes, //(2) prepare the file FILE* filePointer; filePointer = fopen(fileName, "w"); - if (filePointer == NULL) { + if (filePointer == nullptr) { //can't open a file return 1; } @@ -842,7 +829,7 @@ int TCling_GenerateDictionary(const std::string& className, //______________________________________________________________________________ // -void* TCling::fgSetOfSpecials = 0; +void* TCling::fgSetOfSpecials = nullptr; //______________________________________________________________________________ // @@ -853,7 +840,7 @@ namespace { // Yes, throwing exceptions in error handlers is bad. // Doing nothing is pretty terrible, too. void exceptionErrorHandler(void * /*user_data*/, - const std::string& reason, + const char* reason, bool /*gen_crash_diag*/) { throw std::runtime_error(std::string(">>> Interpreter compilation error:\n") + reason); } @@ -988,14 +975,16 @@ bool TClingLookupHelper__ExistingTypeCheck(const std::string &tname, // Check if the scope is in the list of classes if (auto scope = static_cast(gROOT->GetListOfClasses()->FindObject(scopeName))) { auto enumTable = dynamic_cast(scope->GetListOfEnums(false)); - if (enumTable && enumTable->THashList::FindObject(enName)) return true; + if (enumTable && enumTable->THashList::FindObject(enName)) + return true; } // It may still be in one of the loaded protoclasses else if (auto scope = static_cast(gClassTable->GetProtoNorm(scopeName))) { auto listOfEnums = scope->GetListOfEnums(); if (listOfEnums) { // it could be null: no enumerators in the protoclass auto enumTable = dynamic_cast(listOfEnums); - if (enumTable && enumTable->THashList::FindObject(enName)) return true; + if (enumTable && enumTable->THashList::FindObject(enName)) + return true; } } delete [] scopeName; @@ -1003,7 +992,8 @@ bool TClingLookupHelper__ExistingTypeCheck(const std::string &tname, { // We don't have any scope: this could only be a global enum auto enumTable = dynamic_cast(gROOT->GetListOfEnums()); - if (enumTable && enumTable->THashList::FindObject(inner)) return true; + if (enumTable && enumTable->THashList::FindObject(inner)) + return true; } if (gCling->GetClassSharedLibs(inner)) @@ -1238,10 +1228,14 @@ static void RegisterCxxModules(cling::Interpreter &clingInterp) { if (!clingInterp.getCI()->getLangOpts().Modules) return; - // Setup core C++ modules if we have any to setup. - // Load libc and stl first. - // Load vcruntime module for windows + // Loading of a module might deserialize. + cling::Interpreter::PushTransactionRAII deserRAII(&clingInterp); + + // Setup core C++ modules if we have any to setup. + + // Load libc and stl first. + // Load vcruntime module for windows #ifdef R__WIN32 LoadModule("vcruntime", clingInterp); LoadModule("services", clingInterp); @@ -1283,7 +1277,7 @@ static void RegisterCxxModules(cling::Interpreter &clingInterp) ; // Allow forcefully enabling/disabling the GMI. llvm::Optional envUseGMI = llvm::sys::Process::GetEnv("ROOT_USE_GMI"); - if (envUseGMI.hasValue()) { + if (envUseGMI.has_value()) { if (!envUseGMI->empty() && !CppyyLegacy::FoundationUtils::CanConvertEnvValueToBool(*envUseGMI)) CppyyLegacy::Warning("TCling__RegisterCxxModules", "Cannot convert '%s' to bool, setting to false!", @@ -1455,7 +1449,7 @@ TCling::TCling(const char *name, const char *title, const char* const argv[], vo // Process externally passed arguments if present. llvm::Optional EnvOpt = llvm::sys::Process::GetEnv("EXTRA_CLING_ARGS"); - if (EnvOpt.hasValue()) { + if (EnvOpt.has_value()) { StringRef Env(*EnvOpt); while (!Env.empty()) { StringRef Arg; @@ -1467,7 +1461,7 @@ TCling::TCling(const char *name, const char *title, const char* const argv[], vo auto GetEnvVarPath = [](const std::string &EnvVar, std::vector &Paths) { llvm::Optional EnvOpt = llvm::sys::Process::GetEnv(EnvVar); - if (EnvOpt.hasValue()) { + if (EnvOpt.has_value()) { StringRef Env(*EnvOpt); while (!Env.empty()) { StringRef Arg; @@ -1495,7 +1489,7 @@ TCling::TCling(const char *name, const char *title, const char* const argv[], vo // FIXME: This only will enable frontend timing reports. EnvOpt = llvm::sys::Process::GetEnv("ROOT_CLING_TIMING"); - if (EnvOpt.hasValue()) + if (EnvOpt.has_value()) clingArgsStorage.push_back("-ftime-report"); // Add the overlay file. Note that we cannot factor it out for both root @@ -1575,7 +1569,7 @@ TCling::TCling(const char *name, const char *title, const char* const argv[], vo // Add the Rdict module file extension. cling::Interpreter::ModuleFileExtensions extensions; EnvOpt = llvm::sys::Process::GetEnv("ROOTDEBUG_RDICT"); - if (!EnvOpt.hasValue()) + if (!EnvOpt.has_value()) extensions.push_back(std::make_shared()); // Filter -fno-plt, if any, which is added by compilation in anaconda @@ -3253,26 +3247,26 @@ Bool_t TCling::IsLoaded(const char* filename) const return kTRUE; //FIXME: We must use the cling::Interpreter::lookupFileOrLibrary iface. - const clang::DirectoryLookup *CurDir = 0; + clang::ConstSearchDirIterator *CurDir = nullptr; clang::Preprocessor &PP = fInterpreter->getCI()->getPreprocessor(); clang::HeaderSearch &HS = PP.getHeaderSearchInfo(); auto FE = HS.LookupFile(file_name.c_str(), clang::SourceLocation(), /*isAngled*/ false, - /*FromDir*/ 0, CurDir, - clang::ArrayRef>(), - /*SearchPath*/ 0, - /*RelativePath*/ 0, - /*RequestingModule*/ 0, - /*SuggestedModule*/ 0, - /*IsMapped*/ 0, + /*FromDir*/ nullptr, CurDir, + clang::ArrayRef>(), + /*SearchPath*/ nullptr, + /*RelativePath*/ nullptr, + /*RequestingModule*/ nullptr, + /*SuggestedModule*/ nullptr, + /*IsMapped*/ nullptr, /*IsFrameworkFound*/ nullptr, /*SkipCache*/ false, /*BuildSystemModule*/ false, /*OpenFile*/ false, /*CacheFail*/ false); - if (FE && FE->isValid()) { + if (FE) { // check in the source manager if the file is actually loaded clang::SourceManager &SM = fInterpreter->getCI()->getSourceManager(); // this works only with header (and source) files... diff --git a/cling/src/core/metacling/src/TClingCallbacks.cxx b/cling/src/core/metacling/src/TClingCallbacks.cxx index 45092c30..13e0b4b9 100644 --- a/cling/src/core/metacling/src/TClingCallbacks.cxx +++ b/cling/src/core/metacling/src/TClingCallbacks.cxx @@ -98,7 +98,7 @@ void TClingCallbacks::InclusionDirective(clang::SourceLocation sLoc/*HashLoc*/, llvm::StringRef FileName, bool /*IsAngled*/, clang::CharSourceRange /*FilenameRange*/, - const clang::FileEntry *FE, + const clang::OptionalFileEntryRef FE, llvm::StringRef /*SearchPath*/, llvm::StringRef /*RelativePath*/, const clang::Module * Imported, @@ -146,8 +146,7 @@ bool TClingCallbacks::LibraryLoadingFailed(const std::string& errmessage, const // Preprocessor callbacks used to handle special cases like for example: // #include "myMacro.C+" // -bool TClingCallbacks::FileNotFound(llvm::StringRef FileName, - llvm::SmallVectorImpl &RecoveryPath) { +bool TClingCallbacks::FileNotFound(llvm::StringRef FileName) { // Method called via Callbacks->FileNotFound(Filename, RecoveryPath) // in Preprocessor::HandleIncludeDirective(), initially allowing to // change the include path, and allowing us to compile code via ACLiC @@ -395,7 +394,7 @@ bool TClingCallbacks::LookupObject(clang::TagDecl* Tag) { // filename. // bool TClingCallbacks::tryAutoParseInternal(llvm::StringRef Name, LookupResult &R, - Scope *S, const FileEntry* FE /*=0*/) { + Scope *S, clang::OptionalFileEntryRef FE) { if (!fROOTSpecialNamespace) { // init error or rootcling return false; diff --git a/cling/src/core/metacling/src/TClingCallbacks.h b/cling/src/core/metacling/src/TClingCallbacks.h index 012ad0b3..456af113 100644 --- a/cling/src/core/metacling/src/TClingCallbacks.h +++ b/cling/src/core/metacling/src/TClingCallbacks.h @@ -66,15 +66,14 @@ class TClingCallbacks : public cling::InterpreterCallbacks { void InclusionDirective(clang::SourceLocation /*HashLoc*/, const clang::Token & /*IncludeTok*/, llvm::StringRef FileName, bool /*IsAngled*/, clang::CharSourceRange /*FilenameRange*/, - const clang::FileEntry * /*File*/, llvm::StringRef /*SearchPath*/, + const clang::OptionalFileEntryRef /*File*/, llvm::StringRef /*SearchPath*/, llvm::StringRef /*RelativePath*/, const clang::Module * /*Imported*/, clang::SrcMgr::CharacteristicKind /*FileType*/) override; // Preprocessor callbacks used to handle special cases like for example: // #include "myMacro.C+" // - virtual bool FileNotFound(llvm::StringRef FileName, - llvm::SmallVectorImpl& RecoveryPath); + virtual bool FileNotFound(llvm::StringRef FileName); virtual bool LookupObject(clang::LookupResult &R, clang::Scope *S); virtual bool LookupObject(const clang::DeclContext* DC, @@ -114,8 +113,8 @@ class TClingCallbacks : public cling::InterpreterCallbacks { virtual void UnlockCompilationDuringUserCodeExecution(void *StateInfo); private: - bool tryAutoParseInternal(llvm::StringRef Name, clang::LookupResult &R, - clang::Scope *S, const clang::FileEntry* FE = 0); + bool tryAutoParseInternal(llvm::StringRef Name, clang::LookupResult &R, clang::Scope *S, + clang::OptionalFileEntryRef FE = std::nullopt); bool tryFindROOTSpecialInternal(clang::LookupResult &R, clang::Scope *S); bool tryResolveAtRuntimeInternal(clang::LookupResult &R, clang::Scope *S); bool shouldResolveAtRuntime(clang::LookupResult &R, clang::Scope *S); diff --git a/cling/src/core/metacling/src/TClingMethodInfo.cxx b/cling/src/core/metacling/src/TClingMethodInfo.cxx index e3d37553..79c18c3e 100644 --- a/cling/src/core/metacling/src/TClingMethodInfo.cxx +++ b/cling/src/core/metacling/src/TClingMethodInfo.cxx @@ -359,15 +359,14 @@ GetOrInstantiateFuncTemplateWithDefaults(clang::FunctionTemplateDecl* FTDecl, SmallVector DeducedArgs; sema::TemplateDeductionInfo Info{SourceLocation()}; - Sema::InstantiatingTemplate Inst(S, Info.getLocation(), FTDecl, - defaultTemplateArgs, - Sema::CodeSynthesisContext::DeducedTemplateArgumentSubstitution, - Info); + Sema::InstantiatingTemplate Inst( + S, Info.getLocation(), FTDecl, + defaultTemplateArgs, Sema::CodeSynthesisContext::DeducedTemplateArgumentSubstitution, Info); // Collect the function arguments of the templated function, substituting // dependent types as possible. TemplateArgumentList templArgList(TemplateArgumentList::OnStack, defaultTemplateArgs); - MultiLevelTemplateArgumentList MLTAL{templArgList}; + MultiLevelTemplateArgumentList MLTAL{FTDecl, templArgList.asArray(), /*Final=*/false}; for (const clang::ParmVarDecl *param: templatedDecl->parameters()) { QualType paramType = param->getOriginalType(); diff --git a/cling/src/core/metacling/src/TClingRdictModuleFileExtension.cxx b/cling/src/core/metacling/src/TClingRdictModuleFileExtension.cxx index 74c5bdbf..2b7846b4 100644 --- a/cling/src/core/metacling/src/TClingRdictModuleFileExtension.cxx +++ b/cling/src/core/metacling/src/TClingRdictModuleFileExtension.cxx @@ -153,13 +153,11 @@ clang::ModuleFileExtensionMetadata TClingRdictModuleFileExtension::getExtensionM return {ROOT_CLING_RDICT_BLOCK_NAME, ROOT_CLING_RDICT_VERSION_MAJOR, ROOT_CLING_RDICT_VERSION_MINOR, UserInfo}; } -llvm::hash_code TClingRdictModuleFileExtension::hashExtension(llvm::hash_code Code) const +void TClingRdictModuleFileExtension::hashExtension(ExtensionHashBuilder &HBuilder) const { - Code = llvm::hash_combine(Code, ROOT_CLING_RDICT_BLOCK_NAME); - Code = llvm::hash_combine(Code, ROOT_CLING_RDICT_VERSION_MAJOR); - Code = llvm::hash_combine(Code, ROOT_CLING_RDICT_VERSION_MINOR); - - return Code; + HBuilder.add(ROOT_CLING_RDICT_BLOCK_NAME); + HBuilder.add(ROOT_CLING_RDICT_VERSION_MAJOR); + HBuilder.add(ROOT_CLING_RDICT_VERSION_MINOR); } std::unique_ptr diff --git a/cling/src/core/metacling/src/TClingRdictModuleFileExtension.h b/cling/src/core/metacling/src/TClingRdictModuleFileExtension.h index a9fefdfc..cabf6950 100644 --- a/cling/src/core/metacling/src/TClingRdictModuleFileExtension.h +++ b/cling/src/core/metacling/src/TClingRdictModuleFileExtension.h @@ -51,7 +51,7 @@ class TClingRdictModuleFileExtension : public clang::ModuleFileExtension { clang::ModuleFileExtensionMetadata getExtensionMetadata() const override; - llvm::hash_code hashExtension(llvm::hash_code Code) const override; + void hashExtension(ExtensionHashBuilder &HBuilder) const override; std::unique_ptr createExtensionWriter(clang::ASTWriter &Writer) override;