[clang] [Clang] Make the result type of sizeof/pointer subtraction/size_t lit… (PR #136542)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 21 03:38:47 PDT 2025
================
@@ -4026,10 +4026,20 @@ ExprResult Sema::ActOnNumericConstant(const Token &Tok, Scope *UDLScope) {
// Does it fit in size_t?
if (ResultVal.isIntN(SizeTSize)) {
// Does it fit in ssize_t?
- if (!Literal.isUnsigned && ResultVal[SizeTSize - 1] == 0)
- Ty = Context.getSignedSizeType();
- else if (AllowUnsigned)
- Ty = Context.getSizeType();
+ if (!Literal.isUnsigned && ResultVal[SizeTSize - 1] == 0) {
+ auto SignedSize = Context.getSignedSizeType();
+ if (auto PtrDiff = Context.getCGlobalCXXStdNSTypedef(
+ getStdNamespace(), "ptrdiff_t");
+ Context.hasSameType(PtrDiff, SignedSize))
+ Ty = PtrDiff;
+ else if (auto SSize = Context.getCGlobalCXXStdNSTypedef(
+ getStdNamespace(), "ssize_t");
+ Context.hasSameType(SSize, SignedSize))
+ Ty = SSize;
+ } else if (AllowUnsigned) {
+ Ty = Context.getCGlobalCXXStdNSTypedef(getStdNamespace(), "size_t",
----------------
YexuanXiao wrote:
I'm looking into it.
https://github.com/llvm/llvm-project/pull/136542
More information about the cfe-commits
mailing list