[clang] [clang] Only set the trailing bytes to zero when filling a partially … (PR #79502)
Eli Friedman via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 30 00:08:04 PST 2024
================
@@ -1209,8 +1301,21 @@ static void emitStoresForConstant(CodeGenModule &CGM, const VarDecl &D,
// If the initializer is all or mostly the same, codegen with bzero / memset
// then do a few stores afterward.
if (shouldUseBZeroPlusStoresToInitialize(constant, ConstantSize)) {
- auto *I = Builder.CreateMemSet(Loc, llvm::ConstantInt::get(CGM.Int8Ty, 0),
- SizeVal, isVolatile);
+ size_t LeadingNonNullBytes =
+ CountLeadingNonNullBytes(CGM.getDataLayout(), constant);
----------------
efriedma-quic wrote:
I don't like the way this duplicates the logic. You aren't really trying to count bytes that are "non-null"; you're trying to find the offset of the first byte that isn't overwritten by emitStoresForInitAfterBZero. The best place to compute that is emitStoresForInitAfterBZero itself.
https://github.com/llvm/llvm-project/pull/79502
More information about the cfe-commits
mailing list