diff options
Diffstat (limited to 'clang/lib/CodeGen/CGCall.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGCall.cpp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 946772f..b665e67 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -2319,7 +2319,7 @@ void CodeGenModule::ConstructAttributeList(StringRef Name, llvm::AttributeSet::get(getLLVMContext(), Attrs); } - // Apply `nonnull` and `dereferencable(N)` to the `this` argument, + // Apply `nonnull`, `dereferencable(N)` and `align N` to the `this` argument, // unless this is a thunk function. // FIXME: fix this properly, https://reviews.llvm.org/D100388 if (FI.isInstanceMethod() && !IRFunctionArgs.hasInallocaArg() && @@ -2330,13 +2330,13 @@ void CodeGenModule::ConstructAttributeList(StringRef Name, llvm::AttrBuilder Attrs; + QualType ThisTy = + FI.arg_begin()->type.castAs<PointerType>()->getPointeeType(); + if (!CodeGenOpts.NullPointerIsValid && getContext().getTargetAddressSpace(FI.arg_begin()->type) == 0) { Attrs.addAttribute(llvm::Attribute::NonNull); - Attrs.addDereferenceableAttr( - getMinimumObjectSize( - FI.arg_begin()->type.castAs<PointerType>()->getPointeeType()) - .getQuantity()); + Attrs.addDereferenceableAttr(getMinimumObjectSize(ThisTy).getQuantity()); } else { // FIXME dereferenceable should be correct here, regardless of // NullPointerIsValid. However, dereferenceable currently does not always @@ -2348,6 +2348,12 @@ void CodeGenModule::ConstructAttributeList(StringRef Name, .getQuantity()); } + llvm::Align Alignment = + getNaturalTypeAlignment(ThisTy, /*BaseInfo=*/nullptr, + /*TBAAInfo=*/nullptr, /*forPointeeType=*/true) + .getAsAlign(); + Attrs.addAlignmentAttr(Alignment); + ArgAttrs[IRArgs.first] = llvm::AttributeSet::get(getLLVMContext(), Attrs); } |