-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[Clang] Make the result type of sizeof/pointer subtraction/size_t lit… #136542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
b9cc919
af5749a
2541841
b223539
0eabf72
73db8f6
0005883
0e7470f
b7098ff
ec69d58
5febef5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4026,10 +4026,22 @@ 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"); | ||
| !PtrDiff.isNull() && Context.hasSameType(PtrDiff, SignedSize)) | ||
| Ty = PtrDiff; | ||
| else if (auto SSize = Context.getCGlobalCXXStdNSTypedef( | ||
| getStdNamespace(), "ssize_t"); | ||
| !SSize.isNull() && Context.hasSameType(SSize, SignedSize)) | ||
| Ty = SSize; | ||
| else | ||
| Ty=SignedSize; | ||
| } else if (AllowUnsigned) { | ||
| Ty = Context.getCGlobalCXXStdNSTypedef(getStdNamespace(), "size_t", | ||
| Context.getSizeType()); | ||
| } | ||
| Width = SizeTSize; | ||
| } | ||
| } | ||
|
|
@@ -4702,7 +4714,10 @@ ExprResult Sema::CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo *TInfo, | |
|
|
||
| // C99 6.5.3.4p4: the type (an unsigned integer type) is size_t. | ||
| return new (Context) UnaryExprOrTypeTraitExpr( | ||
| ExprKind, TInfo, Context.getSizeType(), OpLoc, R.getEnd()); | ||
| ExprKind, TInfo, | ||
| Context.getCGlobalCXXStdNSTypedef(getStdNamespace(), "size_t", | ||
| Context.getSizeType()), | ||
| OpLoc, R.getEnd()); | ||
| } | ||
|
|
||
| ExprResult | ||
|
|
@@ -4745,7 +4760,10 @@ Sema::CreateUnaryExprOrTypeTraitExpr(Expr *E, SourceLocation OpLoc, | |
|
|
||
| // C99 6.5.3.4p4: the type (an unsigned integer type) is size_t. | ||
| return new (Context) UnaryExprOrTypeTraitExpr( | ||
| ExprKind, E, Context.getSizeType(), OpLoc, E->getSourceRange().getEnd()); | ||
| ExprKind, E, | ||
| Context.getCGlobalCXXStdNSTypedef(getStdNamespace(), "size_t", | ||
| Context.getSizeType()), | ||
| OpLoc, E->getSourceRange().getEnd()); | ||
|
||
| } | ||
|
|
||
| ExprResult | ||
|
|
@@ -11353,8 +11371,10 @@ QualType Sema::CheckSubtractionOperands(ExprResult &LHS, ExprResult &RHS, | |
| } | ||
| } | ||
|
|
||
| if (CompLHSTy) *CompLHSTy = LHS.get()->getType(); | ||
| return Context.getPointerDiffType(); | ||
| if (CompLHSTy) | ||
| *CompLHSTy = LHS.get()->getType(); | ||
| return Context.getCGlobalCXXStdNSTypedef(getStdNamespace(), "ptrdiff_t", | ||
| Context.getPointerDiffType()); | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a test file to verify that
size_tis shown instead ofunsigned long/unsigned long long?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm looking into it.