Skip to content

Commit

Permalink
[cling][FIXME:REWORK] Use AlwaysIncludeTypeForTemplateArgument only…
Browse files Browse the repository at this point in the history
… for large values
  • Loading branch information
devajithvs committed Mar 7, 2025
1 parent 28a9ef5 commit 70787ce
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 0 additions & 1 deletion core/clingutils/src/TClingUtils.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -4164,7 +4164,6 @@ void ROOT::TMetaUtils::GetNormalizedName(std::string &norm_name, const clang::Qu
policy.SuppressTagKeyword = true; // Never get the class or struct keyword
policy.SuppressScope = true; // Force the scope to be coming from a clang::ElaboratedType.
policy.AnonymousTagLocations = false; // Do not extract file name + line number for anonymous types.
policy.AlwaysIncludeTypeForTemplateArgument = true; // Always include type for template arguments
// The scope suppression is required for getting rid of the anonymous part of the name of a class defined in an anonymous namespace.
// This gives us more control vs not using the clang::ElaboratedType and relying on the Policy.SuppressUnwrittenScope which would
// strip both the anonymous and the inline namespace names (and we probably do not want the later to be suppressed).
Expand Down
13 changes: 12 additions & 1 deletion interpreter/cling/lib/Utils/AST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,18 @@ namespace utils {
ASTContext &mutableCtx( const_cast<ASTContext&>(Ctx) );
arg = TemplateArgument::CreatePackCopy(mutableCtx, desArgs);
}
} else if (arg.getKind() == TemplateArgument::Integral) {

const llvm::APSInt &Val = arg.getAsIntegral();
QualType T = arg.getIntegralType();

// Handle cases where the value is too large to fit into the underlying type
// i.e. where the unsignedness matters.
if (T->isBuiltinType()) {
if (Val.isUnsigned() && Val.getBitWidth() == 64 && Val.countLeadingOnes()) {
const_cast<clang::PrintingPolicy &>(Ctx.getPrintingPolicy()).AlwaysIncludeTypeForTemplateArgument = true;
}
}
}
return changed;
}
Expand Down Expand Up @@ -1760,7 +1772,6 @@ namespace utils {
PrintingPolicy Policy(Ctx.getPrintingPolicy());
Policy.SuppressScope = false;
Policy.AnonymousTagLocations = false;
Policy.AlwaysIncludeTypeForTemplateArgument = true;
return FQQT.getAsString(Policy);
}

Expand Down

0 comments on commit 70787ce

Please sign in to comment.