[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 Dec 13 03:10:24 PST 2025


================
@@ -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 {
----------------
huixie90 wrote:

> This seems to be redoing a lot of work; I wonder if forming the record layout itself should calculate the ranges of padding bits explicitly. It already has to know that information anyway, so why not leverage that?

Indeed. However, if we conditionally stores the padding information during creating the layouts, it might be wasteful as in most of the cases, the builtin function is never called. Wdyt?

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


More information about the libcxx-commits mailing list