-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[clang] Add builtin to clear padding bytes (prework for P0528R3) #75371
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
base: main
Are you sure you want to change the base?
Changes from all commits
b783c62
13e7fe1
9cd8a8b
7560053
ae8a877
2366faa
26b92c8
90b3ba7
3207acf
4c8ac8a
2c1107e
faafd64
cf5df19
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 |
|---|---|---|
|
|
@@ -2899,7 +2899,37 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID, | |
| return BuiltinIsWithinLifetime(*this, TheCall); | ||
| case Builtin::BI__builtin_trivially_relocate: | ||
| return BuiltinTriviallyRelocate(*this, TheCall); | ||
| case Builtin::BI__builtin_clear_padding: { | ||
| const auto numArgs = TheCall->getNumArgs(); | ||
| if (numArgs < 1) { | ||
| Diag(TheCall->getEndLoc(), diag::err_typecheck_call_too_few_args_one) | ||
| << 0 /*function call*/ << "T*" << 0; | ||
| return ExprError(); | ||
| } | ||
| if (numArgs > 1) { | ||
| Diag(TheCall->getEndLoc(), diag::err_typecheck_call_too_many_args_one) | ||
| << 0 /*function call*/ << "T*" << numArgs << 0; | ||
| return ExprError(); | ||
| } | ||
|
|
||
| const Expr *PtrArg = TheCall->getArg(0); | ||
| const QualType PtrArgType = PtrArg->getType(); | ||
| if (!PtrArgType->isPointerType()) { | ||
| Diag(PtrArg->getBeginLoc(), diag::err_typecheck_convert_incompatible) | ||
| << PtrArgType << "pointer" << 1 << 0 << 3 << 1 << PtrArgType | ||
| << "pointer"; | ||
| return ExprError(); | ||
| } | ||
| if (PtrArgType->getPointeeType().isConstQualified()) { | ||
| Diag(PtrArg->getBeginLoc(), diag::err_typecheck_assign_const) | ||
| << TheCall->getSourceRange() << 5 /*ConstUnknown*/; | ||
| return ExprError(); | ||
| } | ||
| if (RequireCompleteType(PtrArg->getBeginLoc(), PtrArgType->getPointeeType(), | ||
| diag::err_typecheck_decl_incomplete_type)) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please define an error message that explains what's actually going wrong here, instead of reusing err_typecheck_decl_incomplete_type. (The other errors could also be improved a bit.)
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
hmm. the current error message looks like this In my opinion, the error is quite clear. It suggested the user that it does not work with incomplete type. |
||
| return ExprError(); | ||
| break; | ||
huixie90 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| case Builtin::BI__sync_fetch_and_add: | ||
| case Builtin::BI__sync_fetch_and_add_1: | ||
| case Builtin::BI__sync_fetch_and_add_2: | ||
|
|
||
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 think we should expose this in C mode as well. Did you have any particular implementation-reason to restrict to C++?
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.
Thanks for bringing this up. The reason I am creating this patch is to implement a C++ paper https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0528r3.html
I am not familiar with the C standard and not sure if this operation is needed. And the implementation is trying to access the Cxx record and I am not sure how easy to make it work for C.