[clang] [Clang] Fixed an assertion caused by Microsoft integer literals exceeding the maximum value (PR #212743)
Shengxin Pei via cfe-commits
cfe-commits at lists.llvm.org
Sun Aug 9 14:20:36 PDT 2026
https://github.com/TPPPP72 updated https://github.com/llvm/llvm-project/pull/212743
>From 703e7cfa4bd9d2218dde3e6ac0ccde0fb4c18478 Mon Sep 17 00:00:00 2001
From: Shengxin Pei <TPPPP72 at outlook.com>
Date: Thu, 30 Jul 2026 02:40:36 +0800
Subject: [PATCH 1/3] [Clang] Fixed an assertion caused by Microsoft integer
literals exceeding the maximum value
---
clang/docs/ReleaseNotes.md | 1 +
clang/lib/Sema/SemaExpr.cpp | 3 ++-
clang/test/SemaCXX/ms_integer_suffix.cpp | 4 ++++
3 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index f631d9f858f9f..4a6a67bc76572 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -352,6 +352,7 @@ features cannot lower the translation-unit ABI level;
- Fixed a bug where `__func__`, `__PRETTY_FUNCTION__` and `__FUNCTION__` were not resolving to the proper function when inside a lambda return type (#GH211811)
- Fixed USR generation for declarations whose signature mentions a class-type
non-type template parameter. (#GH212351)
+- Fixed an assertion caused by Microsoft integer literals exceeding the maximum value. (#GH212504)
#### Bug Fixes to Compiler Builtins
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index ed3d27b5adc27..200e20abb9823 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -4092,7 +4092,7 @@ ExprResult Sema::ActOnNumericConstant(const Token &Tok, Scope *UDLScope) {
!Context.getTargetInfo().hasInt128Type())
PP.Diag(Tok.getLocation(), diag::err_integer_literal_too_large)
<< Literal.isUnsigned;
- BitsNeeded = Literal.MicrosoftInteger;
+ BitsNeeded = std::max<unsigned>(BitsNeeded, Literal.MicrosoftInteger);
}
llvm::APInt ResultVal(BitsNeeded, 0);
@@ -4134,6 +4134,7 @@ ExprResult Sema::ActOnNumericConstant(const Token &Tok, Scope *UDLScope) {
Ty = Context.getIntTypeForBitwidth(Width,
/*Signed=*/!Literal.isUnsigned);
}
+ ResultVal = ResultVal.zextOrTrunc(Width);
}
// Bit-precise integer literals are automagically-sized based on the
diff --git a/clang/test/SemaCXX/ms_integer_suffix.cpp b/clang/test/SemaCXX/ms_integer_suffix.cpp
index aa2f13099d3b8..41feda129668b 100644
--- a/clang/test/SemaCXX/ms_integer_suffix.cpp
+++ b/clang/test/SemaCXX/ms_integer_suffix.cpp
@@ -18,3 +18,7 @@ static_assert(sizeof(0i32) == __SIZEOF_INT32__, "");
#ifdef __SIZEOF_INT64__
static_assert(sizeof(0i64) == __SIZEOF_INT64__, "");
#endif
+
+namespace gh212504 {
+ static_assert(1234i8, "");
+}
>From 1f18dad37cbbbc4b45a9d6bb753cbaf85b2fb13e Mon Sep 17 00:00:00 2001
From: Shengxin Pei <TPPPP72 at outlook.com>
Date: Thu, 30 Jul 2026 03:22:46 +0800
Subject: [PATCH 2/3] update test case
---
clang/test/SemaCXX/ms_integer_suffix.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/test/SemaCXX/ms_integer_suffix.cpp b/clang/test/SemaCXX/ms_integer_suffix.cpp
index 41feda129668b..288ad3cb2eb0f 100644
--- a/clang/test/SemaCXX/ms_integer_suffix.cpp
+++ b/clang/test/SemaCXX/ms_integer_suffix.cpp
@@ -20,5 +20,5 @@ static_assert(sizeof(0i64) == __SIZEOF_INT64__, "");
#endif
namespace gh212504 {
- static_assert(1234i8, "");
+ static_assert(1234i8 == -46, "");
}
>From c447eeec11932545abccccfb907836ee0693ac12 Mon Sep 17 00:00:00 2001
From: Shengxin Pei <TPPPP72 at outlook.com>
Date: Mon, 10 Aug 2026 05:15:48 +0800
Subject: [PATCH 3/3] update test
---
clang/test/SemaCXX/ms_integer_suffix.cpp | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/clang/test/SemaCXX/ms_integer_suffix.cpp b/clang/test/SemaCXX/ms_integer_suffix.cpp
index 288ad3cb2eb0f..71c9875ccfd58 100644
--- a/clang/test/SemaCXX/ms_integer_suffix.cpp
+++ b/clang/test/SemaCXX/ms_integer_suffix.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fms-extensions -verify %s
-// expected-no-diagnostics
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fms-extensions -verify=signed,expected %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fms-extensions -fno-signed-char -verify=unsigned,expected %s
#ifdef __SIZEOF_INT8__
static_assert(sizeof(0i8) == __SIZEOF_INT8__, "");
@@ -20,5 +20,9 @@ static_assert(sizeof(0i64) == __SIZEOF_INT64__, "");
#endif
namespace gh212504 {
- static_assert(1234i8 == -46, "");
+ static_assert(1234i8 == -46, ""); // unsigned-error {{static assertion failed due to requirement '210i8 == -46':}}
+ static_assert(1234i8 == 210, ""); // signed-error {{static assertion failed due to requirement '-46i8 == 210':}}
+ static_assert(1234ui8 == 210, "");
+ static_assert(18446744073709551615i8, "");
+ static_assert(18446744073709551616i8 == 0, ""); // expected-error {{integer literal is too large to be represented in any integer type}}
}
More information about the cfe-commits
mailing list