[libcxx-commits] [clang] [libcxx] [clang] Add builtin to clear padding bytes (prework for P0528R3) (PR #75371)
via libcxx-commits
libcxx-commits at lists.llvm.org
Sat May 31 03:38:01 PDT 2025
================
@@ -2327,6 +2327,25 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
}
case Builtin::BI__builtin_launder:
return SemaBuiltinLaunder(*this, TheCall);
+ case Builtin::BI__builtin_clear_padding: {
+ const Expr *PtrArg = TheCall->getArg(0)->IgnoreParenImpCasts();
+ 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))
----------------
huixie90 wrote:
> 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.)
hmm. the current error message looks like this
```
/tmp/a.cpp:5:29: error: variable has incomplete type 'A'
5 | __builtin_clear_padding(a);
| ^
/tmp/a.cpp:1:8: note: forward declaration of 'A'
1 | struct A;
```
In my opinion, the error is quite clear. It suggested the user that it does not work with incomplete type.
https://github.com/llvm/llvm-project/pull/75371
More information about the libcxx-commits
mailing list