|
18 | 18 | #include "TargetInfo.h"
|
19 | 19 | #include "clang/AST/Attr.h"
|
20 | 20 | #include "clang/AST/CXXInheritance.h"
|
| 21 | +#include "clang/AST/CharUnits.h" |
21 | 22 | #include "clang/AST/DeclTemplate.h"
|
22 | 23 | #include "clang/AST/EvaluatedExprVisitor.h"
|
23 | 24 | #include "clang/AST/RecordLayout.h"
|
@@ -1729,37 +1730,35 @@ namespace {
|
1729 | 1730 | /// \param layoutEndOffset index of the ASTRecordLayout field to
|
1730 | 1731 | /// end poisoning (exclusive)
|
1731 | 1732 | void PoisonMembers(CodeGenFunction &CGF, unsigned layoutStartOffset,
|
1732 |
| - unsigned layoutEndOffset) { |
| 1733 | + unsigned layoutEndOffset) { |
1733 | 1734 | ASTContext &Context = CGF.getContext();
|
1734 | 1735 | const ASTRecordLayout &Layout =
|
1735 | 1736 | Context.getASTRecordLayout(Dtor->getParent());
|
1736 | 1737 |
|
1737 |
| - llvm::ConstantInt *OffsetSizePtr = llvm::ConstantInt::get( |
1738 |
| - CGF.SizeTy, |
1739 |
| - Context.toCharUnitsFromBits(Layout.getFieldOffset(layoutStartOffset)) |
1740 |
| - .getQuantity()); |
| 1738 | + // It's a first trivia field so it should be at the begining of char, |
| 1739 | + // still round up start offset just in case. |
| 1740 | + CharUnits PoisonStart = |
| 1741 | + Context.toCharUnitsFromBits(Layout.getFieldOffset(layoutStartOffset) + |
| 1742 | + Context.getCharWidth() - 1); |
| 1743 | + llvm::ConstantInt *OffsetSizePtr = |
| 1744 | + llvm::ConstantInt::get(CGF.SizeTy, PoisonStart.getQuantity()); |
1741 | 1745 |
|
1742 | 1746 | llvm::Value *OffsetPtr = CGF.Builder.CreateGEP(
|
1743 | 1747 | CGF.Builder.CreateBitCast(CGF.LoadCXXThis(), CGF.Int8PtrTy),
|
1744 | 1748 | OffsetSizePtr);
|
1745 | 1749 |
|
1746 |
| - CharUnits::QuantityType PoisonSize; |
| 1750 | + CharUnits PoisonEnd; |
1747 | 1751 | if (layoutEndOffset >= Layout.getFieldCount()) {
|
1748 |
| - PoisonSize = Layout.getNonVirtualSize().getQuantity() - |
1749 |
| - Context.toCharUnitsFromBits( |
1750 |
| - Layout.getFieldOffset(layoutStartOffset)) |
1751 |
| - .getQuantity(); |
| 1752 | + PoisonEnd = Layout.getNonVirtualSize(); |
1752 | 1753 | } else {
|
1753 |
| - PoisonSize = Context.toCharUnitsFromBits( |
1754 |
| - Layout.getFieldOffset(layoutEndOffset) - |
1755 |
| - Layout.getFieldOffset(layoutStartOffset)) |
1756 |
| - .getQuantity(); |
| 1754 | + PoisonEnd = |
| 1755 | + Context.toCharUnitsFromBits(Layout.getFieldOffset(layoutEndOffset)); |
1757 | 1756 | }
|
1758 |
| - |
1759 |
| - if (PoisonSize == 0) |
| 1757 | + CharUnits PoisonSize = PoisonEnd - PoisonStart; |
| 1758 | + if (!PoisonSize.isPositive()) |
1760 | 1759 | return;
|
1761 | 1760 |
|
1762 |
| - EmitSanitizerDtorCallback(CGF, OffsetPtr, PoisonSize); |
| 1761 | + EmitSanitizerDtorCallback(CGF, OffsetPtr, PoisonSize.getQuantity()); |
1763 | 1762 | }
|
1764 | 1763 | };
|
1765 | 1764 |
|
|
0 commit comments