[clang] MSan: poison the default-init allocation before calling constructors (PR #188001)

via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 31 05:51:52 PDT 2026


================
@@ -1553,6 +1557,86 @@ static void EnterNewDeleteCleanup(CodeGenFunction &CGF, const CXXNewExpr *E,
   CGF.initFullExprCleanup();
 }
 
+namespace {
+void PoisonTrivialField(CodeGenFunction &CGF, QualType const &Ty,
+                        Address Dest) {
+  CharUnits Size = CGF.getContext().getTypeSizeInChars(Ty);
+  llvm::Value *SizeVal = CGF.CGM.getSize(Size);
+  llvm::Value *PoisonByte = llvm::PoisonValue::get(CGF.Builder.getInt8Ty());
+  CGF.Builder.CreateMemSet(Dest, PoisonByte, SizeVal, Ty.isVolatileQualified());
----------------
dingxiangfei2009 wrote:

Hmm, I probably tested something wrong. Apparently indeed `memset` with `undef` does not work reliably because they can get optimised away. It looks like poisoning is the only way so far.

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


More information about the cfe-commits mailing list