From 5944e9cc5188955b60fa7701c1fb8081ccb8280e Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Sat, 10 Nov 2012 20:11:10 +0100 Subject: [PATCH] Correctly zero out real padding in struct literals. Fixes the std.variant unit tests on x86_64. --- gen/toir.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/gen/toir.cpp b/gen/toir.cpp index 0da3fbfa..edd7f2d4 100644 --- a/gen/toir.cpp +++ b/gen/toir.cpp @@ -2991,6 +2991,17 @@ DValue* StructLiteralExp::toElem(IRState* p) // store the initializer there DtoAssign(loc, &field, val, TOKconstruct); + // Also zero out padding bytes counted as being part of the type in DMD + // but not in LLVM; e.g. real/x86_fp80. + int implicitPadding = + vd->type->size() - gDataLayout->getTypeStoreSize(DtoType(vd->type)); + assert(implicitPadding >= 0); + if (implicitPadding > 0) + { + Logger::println("zeroing %d padding bytes", implicitPadding); + voidptr = write_zeroes(voidptr, offset - implicitPadding, offset); + } + #if DMDV2 Type *tb = vd->type->toBasetype(); if (tb->ty == Tstruct)