diff --git a/clang/lib/AST/TemplateBase.cpp b/clang/lib/AST/TemplateBase.cpp index 0eef8f305fcb3..934e8f1f044f5 100644 --- a/clang/lib/AST/TemplateBase.cpp +++ b/clang/lib/AST/TemplateBase.cpp @@ -130,8 +130,14 @@ static void printIntegral(const TemplateArgument &TemplArg, raw_ostream &Out, } else Out << "(" << T->getCanonicalTypeInternal().getAsString(Policy) << ")" << Val; - } else + } else { Out << Val; + // 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()) + Out << "ULL"; + } } static unsigned getArrayDepth(QualType type) { diff --git a/clang/test/AST/ast-print-integral-template-args.cpp b/clang/test/AST/ast-print-integral-template-args.cpp new file mode 100644 index 0000000000000..d1c26ca562ff0 --- /dev/null +++ b/clang/test/AST/ast-print-integral-template-args.cpp @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -ast-print -std=c++17 -Wno-implicitly-unsigned-literal %s -o - | FileCheck %s + +template +struct Foo {}; + +Foo<9223372036854775810> x; +// CHECK: template<> struct Foo<9223372036854775810ULL> {