60
60
#include "llvm/Support/ScopedPrinter.h"
61
61
#include "llvm/TargetParser/AArch64TargetParser.h"
62
62
#include "llvm/TargetParser/X86TargetParser.h"
63
+ #include <algorithm>
63
64
#include <optional>
64
65
#include <sstream>
65
66
@@ -2468,7 +2469,12 @@ void ClearPaddingStruct(CodeGenFunction &CGF, Value *Ptr, QualType Ty, StructTyp
2468
2469
size_t CurrentStartOffset, size_t &RunningOffset, T&& WriteZeroAtOffset) {
2469
2470
std::cerr << "\n struct! " << ST->getName().data() << std::endl;
2470
2471
auto SL = CGF.CGM.getModule().getDataLayout().getStructLayout(ST);
2471
- auto R = cast<CXXRecordDecl>(Ty->getAsRecordDecl());
2472
+
2473
+ auto R = dyn_cast<CXXRecordDecl>(Ty->getAsRecordDecl());
2474
+ if(!R) {
2475
+ std::cerr << "\n not a CXXRecordDecl" << std::endl;
2476
+
2477
+ }
2472
2478
const ASTRecordLayout &ASTLayout = CGF.getContext().getASTRecordLayout(R);
2473
2479
for (auto Base : R->bases()) {
2474
2480
std::cerr << "\n\n base!" << std::endl;
@@ -2546,16 +2552,18 @@ void RecursivelyClearPaddingImpl(CodeGenFunction &CGF, Value *Ptr, QualType Ty,
2546
2552
if (auto *AT = dyn_cast<ConstantArrayType>(Ty)) {
2547
2553
ClearPaddingConstantArray(CGF, Ptr, Type, AT, CurrentStartOffset, RunningOffset, WriteZeroAtOffset);
2548
2554
}
2549
- else if (auto *ST = dyn_cast<StructType>(Type)) {
2555
+ else if (auto *ST = dyn_cast<StructType>(Type); ST && Ty->isRecordType() ) {
2550
2556
ClearPaddingStruct(CGF, Ptr, Ty, ST, CurrentStartOffset, RunningOffset, WriteZeroAtOffset);
2557
+ } else if (Ty->isAtomicType()) {
2558
+ RecursivelyClearPaddingImpl(CGF, Ptr, Ty.getAtomicUnqualifiedType(), CurrentStartOffset, RunningOffset, WriteZeroAtOffset);
2551
2559
} else {
2552
2560
std::cerr << "\n\n increment running offset from: " << RunningOffset << " to " << RunningOffset + Size << std::endl;
2553
- RunningOffset += Size;
2561
+ RunningOffset = std::max(RunningOffset, CurrentStartOffset + static_cast<size_t>( Size)) ;
2554
2562
}
2555
2563
2556
2564
}
2557
2565
2558
- static void RecursivelyZeroNonValueBits (CodeGenFunction &CGF, Value *Ptr,
2566
+ static void RecursivelyClearPadding (CodeGenFunction &CGF, Value *Ptr,
2559
2567
QualType Ty) {
2560
2568
auto *I8Ptr = CGF.Builder.CreateBitCast(Ptr, CGF.Int8PtrTy);
2561
2569
auto *Zero = ConstantInt::get(CGF.Int8Ty, 0);
@@ -2577,8 +2585,8 @@ static void RecursivelyZeroNonValueBits(CodeGenFunction &CGF, Value *Ptr,
2577
2585
2578
2586
auto Size = CGF.CGM.getModule()
2579
2587
.getDataLayout()
2580
- .getTypeSizeInBits (Type)
2581
- .getKnownMinValue() / 8 ;
2588
+ .getTypeAllocSize (Type)
2589
+ .getKnownMinValue();
2582
2590
2583
2591
std::cerr << "\n\n zero tail padding ["<< RunningOffset << ", " << Size << ")"<< std::endl;
2584
2592
for (; RunningOffset < Size; ++RunningOffset) {
@@ -4445,11 +4453,11 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
4445
4453
4446
4454
return RValue::get(Ptr);
4447
4455
}
4448
- case Builtin::BI__builtin_zero_non_value_bits : {
4456
+ case Builtin::BI__builtin_clear_padding : {
4449
4457
const Expr *Op = E->getArg(0);
4450
4458
Value *Address = EmitScalarExpr(Op);
4451
4459
auto PointeeTy = Op->getType()->getPointeeType();
4452
- RecursivelyZeroNonValueBits (*this, Address, PointeeTy);
4460
+ RecursivelyClearPadding (*this, Address, PointeeTy);
4453
4461
return RValue::get(nullptr);
4454
4462
}
4455
4463
case Builtin::BI__sync_fetch_and_add:
0 commit comments