Skip to content

Commit 0204fdd

Browse files
hahnjodevajithvs
andcommitted
[TClingUtils] Fix normalization of variadic template classes
template_arguments() has the types, but getTemplateArgs() has the pack argument, so their counts may be different. Add test for failing CMS build with LLVM 20. Co-authored-by: Devajith Valaparambil Sreeramaswamy <devajith.valaparambil.sreeramaswamy@cern.ch>
1 parent ee83882 commit 0204fdd

4 files changed

Lines changed: 28 additions & 1 deletion

File tree

core/clingutils/src/TClingUtils.cxx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3105,7 +3105,12 @@ clang::QualType ROOT::TMetaUtils::AddDefaultParameters(clang::QualType instanceT
31053105
llvm::SmallVector<clang::TemplateArgument, 4> canonArgs;
31063106
llvm::ArrayRef<clang::TemplateArgument> template_arguments = TST->template_arguments();
31073107
unsigned int Idecl = 0, Edecl = TSTdecl->getTemplateArgs().size();
3108-
unsigned int maxAddArg = TSTdecl->getTemplateArgs().size() - dropDefault;
3108+
// If we have more arguments than the TSTdecl, it is a variadic template
3109+
// and we want all template arguments.
3110+
if (template_arguments.size() > Edecl) {
3111+
Edecl = template_arguments.size();
3112+
}
3113+
unsigned int maxAddArg = Edecl - dropDefault;
31093114
for (const clang::TemplateArgument *I = template_arguments.begin(), *E = template_arguments.end(); Idecl != Edecl;
31103115
I != E ? ++I : nullptr, ++Idecl, ++Param) {
31113116

roottest/root/meta/rootcling/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,7 @@ ROOTTEST_ADD_TEST(streamerInfoStdFunction
4848
ROOTTEST_ADD_TEST(selectTemplateInvalidArg
4949
COMMAND ${ROOT_rootcling_CMD} -f selectTemplateInvalidArg.Dict.cc ${CMAKE_CURRENT_SOURCE_DIR}/selectTemplateInvalidArg.h ${CMAKE_CURRENT_SOURCE_DIR}/selectTemplateInvalidArg.LinkDef.h
5050
ERRREF selectTemplateInvalidArg.ref)
51+
52+
# Test reproducing a failure seen in CMS builds with LLVM 20
53+
# ROOT get confused normalizing variadic template arguments
54+
ROOTTEST_GENERATE_DICTIONARY(VariadicTemplateConflict variadicTemplate.h LINKDEF variadicTemplate.xml)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// The problem appears when generating dictionaries for variadic templates with 2 vs. 3 arguments
2+
// Mostly copied and adapted from CMSSW
3+
template <int A = 64, bool B = false>
4+
struct TestSoALayout {};
5+
6+
template <typename T0, typename... Args>
7+
struct PortableHostMultiCollection {};
8+
9+
using TestSoA = TestSoALayout<>;
10+
11+
namespace portabletest {
12+
using TestHostMultiCollection2 = PortableHostMultiCollection<TestSoA, TestSoA>;
13+
using TestHostMultiCollection3 = PortableHostMultiCollection<TestSoA, TestSoA, TestSoA>;
14+
} // namespace portabletest
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<lcgdict>
2+
<class name="portabletest::TestHostMultiCollection2"/>
3+
<class name="portabletest::TestHostMultiCollection3"/>
4+
</lcgdict>

0 commit comments

Comments
 (0)