Skip to content

Commit fecba20

Browse files
committed
[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
1 parent abd97d9 commit fecba20

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

clang/lib/AST/TemplateBase.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,14 @@ static void printIntegral(const TemplateArgument &TemplArg, raw_ostream &Out,
130130
} else
131131
Out << "(" << T->getCanonicalTypeInternal().getAsString(Policy) << ")"
132132
<< Val;
133-
} else
133+
} else {
134134
Out << Val;
135+
// Handle cases where the value is too large to fit into the underlying type
136+
// i.e. where the unsignedness matters.
137+
if (T->isBuiltinType())
138+
if (Val.isUnsigned() && Val.getBitWidth() == 64 && Val.countLeadingOnes())
139+
Out << "ULL";
140+
}
135141
}
136142

137143
static unsigned getArrayDepth(QualType type) {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %clang_cc1 -ast-print -std=c++17 -Wno-implicitly-unsigned-literal %s -o - | FileCheck %s
2+
3+
template <unsigned long long N>
4+
struct Foo {};
5+
6+
Foo<9223372036854775810> x;
7+
// CHECK: template<> struct Foo<9223372036854775810ULL> {

0 commit comments

Comments
 (0)