https://github.com/devajithvs created https://github.com/llvm/llvm-project/pull/129235
Clang omits the `ULL` suffix when printing large unsigned 64-bit template arguments. This patch ensures that values with the high bit set are explicitly printed with `ULL`.` Based on the original patch by Axel Naumann >From 423e8dcdade91bf4b30c9757eb6a6a0fee719b99 Mon Sep 17 00:00:00 2001 From: Devajith Valaparambil Sreeramaswamy <devajith.valaparambil.sreeramasw...@cern.ch> Date: Fri, 28 Feb 2025 13:13:16 +0100 Subject: [PATCH] [AST] Fix printing of large 64-bit unsigned template arguments Clang omits the `ULL` suffix when printing large unsigned 64-bit template arguments. This patch ensures that values with the high bit set are explicitly printed with `ULL`.` Based on the original patch by Axel Naumann --- clang/lib/AST/TemplateBase.cpp | 8 +++++++- clang/test/AST/ast-print-integral-template-args.cpp | 7 +++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 clang/test/AST/ast-print-integral-template-args.cpp 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..7bec0557a4304 --- /dev/null +++ b/clang/test/AST/ast-print-integral-template-args.cpp @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -ast-print -std=c++17 %s -o - | FileCheck %s + +template <unsigned long long N> +struct Foo {}; + +Foo<9223372036854775810> x; +// CHECK: template<> struct Foo<9223372036854775810ULL> { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits