Skip to content

genreflex crash in TMetaUtils::ReSubstTemplateArg with gcc12 headers #11259

@scott-snyder

Description

@scott-snyder
  • Checked for duplicates

hi -

We've been seing a crash in genreflex/rootcling in root-6.26.06-patches
when processing gcc12 headers. (See ATEAM-854.)

To reproduce:

sel.xml:

<lcgdict>
  <class pattern="*iterator<*pair<const*,const*"/>
</lcgdict>

x.h:

#include <string>
#include <map>
void foo (std::map<unsigned, std::string>& m, const std::string& s)
{
  m.emplace (0, s);
}

On lxplus7:

$ export LCGPROJECTPATH=/cvmfs/sft-nightlies.cern.ch/lcg/nightlies/dev4/Thu # Adjust if needed.
$ . $LCGPROJECTPATH/gcc/12.1.0/x86_64-centos7/setup.sh
$ . $LCGPROJECTPATH/ROOT/v6-26-00-patches/x86_64-centos7-gcc12-dbg/ROOT-env.sh 
$ genreflex x.h --selection_file=sel.xml -o x_gen.cxx
genreflex: /build/jenkins/workspace/lcg_nightly_pipeline/build/projects/ROOT-v6-26-00-patches/src/ROOT/v6-26-00-patches/interpreter/llvm/src/tools/clang/include/clang/AST/TemplateBase.h:257: clang::QualType clang::TemplateArgument::getAsType() const: Assertion `getKind() == Type && "Unexpected kind"' failed.

It also crashes in the opt build, just a bit further on.

Stack trace:

#4  0x00007ffff2f71cf3 in clang::TemplateArgument::getAsType (
    this=0x7fffef6df2e8)
    at /build/jenkins/workspace/lcg_nightly_pipeline/build/projects/ROOT-v6-26-00-patches/src/ROOT/v6-26-00-patches/interpreter/llvm/src/tools/clang/include/clang/AST/TemplateBase.h:257
#5  0x00007ffff2f85aeb in ROOT::TMetaUtils::ReSubstTemplateArg (input=..., 
    instance=0x7fffef6df2c0)
    at /build/jenkins/workspace/lcg_nightly_pipeline/build/projects/ROOT-v6-26-00-patches/src/ROOT/v6-26-00-patches/core/clingutils/src/TClingUtils.cxx:4768
#6  0x00007ffff2f85c07 in ROOT::TMetaUtils::ReSubstTemplateArg (input=..., 
    instance=0x7fffef6df2c0)
    at /build/jenkins/workspace/lcg_nightly_pipeline/build/projects/ROOT-v6-26-00-patches/src/ROOT/v6-26-00-patches/core/clingutils/src/TClingUtils.cxx:4791
#7  0x00007ffff32362a4 in TClingBaseClassInfo::InternalNext (
    this=0x7fffffff4430, onlyDirect=1)
    at /build/jenkins/workspace/lcg_nightly_pipeline/build/projects/ROOT-v6-26-00-patches/src/ROOT/v6-26-00-patches/core/metacling/src/TClingBaseClassInfo.cxx:341
#8  0x00007ffff323636e in TClingBaseClassInfo::Next (this=0x7fffffff4430, 
    onlyDirect=1)
    at /build/jenkins/workspace/lcg_nightly_pipeline/build/projects/ROOT-v6-26-00-patches/src/ROOT/v6-26-00-patches/core/metacling/src/TClingBaseClassInfo.cxx:350
#9  0x00007ffff323638d in TClingBaseClassInfo::Next (this=0x7fffffff4430)
    at /build/jenkins/workspace/lcg_nightly_pipeline/build/projects/ROOT-v6-26-00-patches/src/ROOT/v6-26-00-patches/core/metacling/src/TClingBaseClassInfo.cxx:355
#10 0x00007ffff30f8681 in TCling::CreateListOfBaseClasses (this=0x4b6670, 
    cl=0x32e8cc0)
    at /build/jenkins/workspace/lcg_nightly_pipeline/build/projects/ROOT-v6-26-00-patches/src/ROOT/v6-26-00-patches/core/metacling/src/TCling.cxx:4292
#11 0x00007ffff260dc29 in TClass::GetListOfBases (this=0x32e8cc0)
    at /build/jenkins/workspace/lcg_nightly_pipeline/build/projects/ROOT-v6-26-00-patches/src/ROOT/v6-26-00-patches/core/meta/src/TClass.cxx:3649
#12 0x00007ffff260a96e in TClass::GetBaseClass (this=0x32e8cc0, cl=0x235be20)
    at /build/jenkins/workspace/lcg_nightly_pipeline/build/projects/ROOT-v6-26-00-patches/src/ROOT/v6-26-00-patches/core/meta/src/TClass.cxx:2679
#13 0x00007ffff260a9f6 in TClass::GetBaseClass (this=0x2c3e4b0, cl=0x235be20)
    at /build/jenkins/workspace/lcg_nightly_pipeline/build/projects/ROOT-v6-26-00-patches/src/ROOT/v6-26-00-patches/core/meta/src/TClass.cxx:2688
#14 0x00007ffff2611f76 in TClass::InheritsFrom (this=0x2c3e4b0, cl=0x235be20)
    at /build/jenkins/workspace/lcg_nightly_pipeline/build/projects/ROOT-v6-26-00-patches/src/ROOT/v6-26-00-patches/core/meta/src/TClass.cxx:4891
#15 0x00007ffff26163d7 in TClass::Property (this=0x2c3e4b0)
    at /build/jenkins/workspace/lcg_nightly_pipeline/build/projects/ROOT-v6-26-00-patches/src/ROOT/v6-26-00-patches/core/meta/src/TClass.cxx:6097
#16 0x00007ffff261a27d in TClass::IsClassStructOrUnion (this=0x2c3e4b0)
    at /build/jenkins/workspace/lcg_nightly_pipeline/build/projects/ROOT-v6-26-00-patches/src/ROOT/v6-26-00-patches/core/meta/inc/TClass.h:352
#17 0x00007ffff260e309 in TClass::GetListOfDataMembers (this=0x2c3e4b0, 
    load=true)
    at /build/jenkins/workspace/lcg_nightly_pipeline/build/projects/ROOT-v6-26-00-patches/src/ROOT/v6-26-00-patches/core/meta/src/TClass.cxx:3759
#18 0x00007ffff7d132ac in CloseStreamerInfoROOTFile (writeEmptyRootPCM=false)
    at /build/jenkins/workspace/lcg_nightly_pipeline/build/projects/ROOT-v6-26-00-patches/src/ROOT/v6-26-00-patches/io/rootpcm/src/rootclingIO.cxx:162
#19 0x00007ffff305e2a7 in FinalizeStreamerInfoWriting (interp=..., 
    writeEmptyRootPCM=false)
    at /build/jenkins/workspace/lcg_nightly_pipeline/build/projects/ROOT-v6-26-00-patches/src/ROOT/v6-26-00-patches/core/dictgen/src/rootcling_impl.cxx:2632
#20 0x00007ffff305ecd8 in GenerateFullDict (dictStream=..., interp=..., 
    scan=..., ctorTypes=..., isSplit=false, isGenreflex=true, 
    writeEmptyRootPCM=false)
    at /build/jenkins/workspace/lcg_nightly_pipeline/build/projects/ROOT-v6-26-00-patches/src/ROOT/v6-26-00-patches/core/dictgen/src/rootcling_impl.cxx:2784
#21 0x00007ffff306ba57 in RootClingMain (argc=7, argv=0x4a4f10, 
    isGenreflex=true)
    at /build/jenkins/workspace/lcg_nightly_pipeline/build/projects/ROOT-v6-26-00-patches/src/ROOT/v6-26-00-patches/core/dictgen/src/rootcling_impl.cxx:4906
#22 0x00007ffff306f44b in genreflex::invokeRootCling (verbosity=..., 
    selectionFileName=..., targetLibName=..., multiDict=false, pcmsNames=..., 
    includes=..., preprocDefines=..., preprocUndefines=..., warnings=..., 
    rootmapFileName=..., rootmapLibName=..., interpreteronly=false, 
    doSplit=false, isCxxmodule=false, writeEmptyRootPCM=false, 
    selSyntaxOnly=false, noIncludePaths=false, noGlobalUsingStd=false, 
    headersNames=..., failOnWarnings=false, ofilename=...)
    at /build/jenkins/workspace/lcg_nightly_pipeline/build/projects/ROOT-v6-26-00-patches/src/ROOT/v6-26-00-patches/core/dictgen/src/rootcling_impl.cxx:5371
#23 0x00007ffff307131c in GenReflexMain (argc=3, argv=0x7fffffff8d40)
    at /build/jenkins/workspace/lcg_nightly_pipeline/build/projects/ROOT-v6-26-00-patches/src/ROOT/v6-26-00-patches/core/dictgen/src/rootcling_impl.cxx:6071
#24 0x00007ffff30717b3 in ROOT_rootcling_Driver (argc=5, argv=0x7fffffff8d38, 
    config=...)
    at /build/jenkins/workspace/lcg_nightly_pipeline/build/projects/ROOT-v6-26-00-patches/src/ROOT/v6-26-00-patches/core/dictgen/src/rootcling_impl.cxx:6148
#25 0x0000000000401269 in main (argc=5, argv=0x7fffffff8d38)
    at /build/jenkins/workspace/lcg_nightly_pipeline/build/projects/ROOT-v6-26-00-patches/src/ROOT/v6-26-00-patches/main/src/rootcling.cxx:43

The crash occurs here in TClingUtils.cxx:

        } else {
            return TST->getArg(index).getAsType();
        }

because the Kind of this argument is clang::TemplateArgument::Expression,
not Type.

This change fixes the crash for me:

diff --git a/core/clingutils/src/TClingUtils.cxx b/core/clingutils/src/TClingUtils.cxx
index 2373f0c..ee0cf7c 100644
--- a/core/clingutils/src/TClingUtils.cxx
+++ b/core/clingutils/src/TClingUtils.cxx
@@ -4765,7 +4765,8 @@ clang::QualType ROOT::TMetaUtils::ReSubstTemplateArg(clang::QualType input, cons
             // (See AddDefaultParameters).
             return input;
          } else {
-            return TST->getArg(index).getAsType();
+           if (TST->getArg(index).getKind() == clang::TemplateArgument::Type)
+             return TST->getArg(index).getAsType();
          }
       }
    }

This is a blocker for ATLAS testing with gcc12.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions