forked from OSchip/llvm-project
[NFC][Alignment] Use MaybeAlign in CGCleanup/CGExpr
This commit is contained in:
parent
77bba68de6
commit
d9b8d13f8b
|
@ -182,6 +182,12 @@ namespace clang {
|
|||
/// Beware llvm::Align assumes power of two 8-bit bytes.
|
||||
llvm::Align getAsAlign() const { return llvm::Align(Quantity); }
|
||||
|
||||
/// getAsMaybeAlign - Returns Quantity as a valid llvm::Align or
|
||||
/// llvm::None, Beware llvm::MaybeAlign assumes power of two 8-bit bytes.
|
||||
llvm::MaybeAlign getAsMaybeAlign() const {
|
||||
return llvm::MaybeAlign(Quantity);
|
||||
}
|
||||
|
||||
/// alignTo - Returns the next integer (mod 2**64) that is
|
||||
/// greater than or equal to this quantity and is a multiple of \p Align.
|
||||
/// Align must be non-zero.
|
||||
|
|
|
@ -77,7 +77,7 @@ RValue DominatingValue<RValue>::saved_type::restore(CodeGenFunction &CGF) {
|
|||
auto getSavingAddress = [&](llvm::Value *value) {
|
||||
auto *AI = cast<llvm::AllocaInst>(value);
|
||||
return Address(value, AI->getAllocatedType(),
|
||||
CharUnits::fromQuantity(AI->getAlignment()));
|
||||
CharUnits::fromQuantity(AI->getAlign().value()));
|
||||
};
|
||||
switch (K) {
|
||||
case ScalarLiteral:
|
||||
|
|
|
@ -757,23 +757,23 @@ void CodeGenFunction::EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc,
|
|||
}
|
||||
}
|
||||
|
||||
uint64_t AlignVal = 0;
|
||||
llvm::MaybeAlign AlignVal;
|
||||
llvm::Value *PtrAsInt = nullptr;
|
||||
|
||||
if (SanOpts.has(SanitizerKind::Alignment) &&
|
||||
!SkippedChecks.has(SanitizerKind::Alignment)) {
|
||||
AlignVal = Alignment.getQuantity();
|
||||
AlignVal = Alignment.getAsMaybeAlign();
|
||||
if (!Ty->isIncompleteType() && !AlignVal)
|
||||
AlignVal = CGM.getNaturalTypeAlignment(Ty, nullptr, nullptr,
|
||||
/*ForPointeeType=*/true)
|
||||
.getQuantity();
|
||||
.getAsMaybeAlign();
|
||||
|
||||
// The glvalue must be suitably aligned.
|
||||
if (AlignVal > 1 &&
|
||||
(!PtrToAlloca || PtrToAlloca->getAlignment() < AlignVal)) {
|
||||
if (AlignVal && *AlignVal > llvm::Align(1) &&
|
||||
(!PtrToAlloca || PtrToAlloca->getAlign() < *AlignVal)) {
|
||||
PtrAsInt = Builder.CreatePtrToInt(Ptr, IntPtrTy);
|
||||
llvm::Value *Align = Builder.CreateAnd(
|
||||
PtrAsInt, llvm::ConstantInt::get(IntPtrTy, AlignVal - 1));
|
||||
PtrAsInt, llvm::ConstantInt::get(IntPtrTy, AlignVal->value() - 1));
|
||||
llvm::Value *Aligned =
|
||||
Builder.CreateICmpEQ(Align, llvm::ConstantInt::get(IntPtrTy, 0));
|
||||
if (Aligned != True)
|
||||
|
@ -782,12 +782,9 @@ void CodeGenFunction::EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc,
|
|||
}
|
||||
|
||||
if (Checks.size() > 0) {
|
||||
// Make sure we're not losing information. Alignment needs to be a power of
|
||||
// 2
|
||||
assert(!AlignVal || (uint64_t)1 << llvm::Log2_64(AlignVal) == AlignVal);
|
||||
llvm::Constant *StaticData[] = {
|
||||
EmitCheckSourceLocation(Loc), EmitCheckTypeDescriptor(Ty),
|
||||
llvm::ConstantInt::get(Int8Ty, AlignVal ? llvm::Log2_64(AlignVal) : 1),
|
||||
llvm::ConstantInt::get(Int8Ty, AlignVal ? llvm::Log2(*AlignVal) : 1),
|
||||
llvm::ConstantInt::get(Int8Ty, TCK)};
|
||||
EmitCheck(Checks, SanitizerHandler::TypeMismatch, StaticData,
|
||||
PtrAsInt ? PtrAsInt : Ptr);
|
||||
|
|
Loading…
Reference in New Issue