[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
Mon Apr 27 05:20:55 PDT 2026


================
@@ -2592,6 +2595,281 @@ static RValue EmitHipStdParUnsupportedBuiltin(CodeGenFunction *CGF,
   return RValue::get(CGF->Builder.CreateCall(UBF, Args));
 }
 
+namespace {
+
+// PaddingClearer is a utility class that clears padding bits in a
+// c++ type. It traverses the type recursively, collecting occupied
+// bit intervals, and then compute the padding intervals.
+// In the end, it clears the padding bits by writing zeros
+// to the padding intervals bytes-by-bytes. If a byte only contains
+// some padding bits, it writes zeros to only those bits. This is
+// the case for bit-fields.
+struct PaddingClearer {
----------------
gonzalobg wrote:

I agree with the assumption that for most types we'll never need this information, so storing it seems wasteful, but I also see the point that this may be early micro-optimization and just keeping the code as part of record layout would be clearer. 

I don't mind either way; it seems like an implementation detail that can be tweaked later and should not block landing this intrinsic.

https://github.com/llvm/llvm-project/pull/75371


More information about the libcxx-commits mailing list