diff options
author | Eli Friedman <efriedma@quicinc.com> | 2020-07-30 17:32:39 -0700 |
---|---|---|
committer | Eli Friedman <efriedma@quicinc.com> | 2020-08-18 12:51:16 -0700 |
commit | 673dbe1b5eef09db39783c828a84f1213a47bad0 (patch) | |
tree | 16044c41a5de76b999cc9d3ea5710c1c25d3232a /clang/lib/CodeGen/CGCall.cpp | |
parent | 6b1f9f2bd4437910804d571284b7c5bb66eac250 (diff) | |
download | llvm-673dbe1b5eef09db39783c828a84f1213a47bad0.zip llvm-673dbe1b5eef09db39783c828a84f1213a47bad0.tar.gz llvm-673dbe1b5eef09db39783c828a84f1213a47bad0.tar.bz2 |
[clang codegen] Use IR "align" attribute for static array arguments.
Without the "align" attribute, marking the argument dereferenceable is
basically useless. See also D80166.
Fixes https://bugs.llvm.org/show_bug.cgi?id=46876 .
Differential Revision: https://reviews.llvm.org/D84992
Diffstat (limited to 'clang/lib/CodeGen/CGCall.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGCall.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 9d225b2..98ba1ef 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -2520,6 +2520,9 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI, // bytes). if (ArrTy->getSizeModifier() == ArrayType::Static) { QualType ETy = ArrTy->getElementType(); + llvm::Align Alignment = + CGM.getNaturalTypeAlignment(ETy).getAsAlign(); + AI->addAttrs(llvm::AttrBuilder().addAlignmentAttr(Alignment)); uint64_t ArrSize = ArrTy->getSize().getZExtValue(); if (!ETy->isIncompleteType() && ETy->isConstantSizeType() && ArrSize) { @@ -2539,10 +2542,15 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI, // For C99 VLAs with the static keyword, we don't know the size so // we can't use the dereferenceable attribute, but in addrspace(0) // we know that it must be nonnull. - if (ArrTy->getSizeModifier() == VariableArrayType::Static && - !getContext().getTargetAddressSpace(ArrTy->getElementType()) && - !CGM.getCodeGenOpts().NullPointerIsValid) - AI->addAttr(llvm::Attribute::NonNull); + if (ArrTy->getSizeModifier() == VariableArrayType::Static) { + QualType ETy = ArrTy->getElementType(); + llvm::Align Alignment = + CGM.getNaturalTypeAlignment(ETy).getAsAlign(); + AI->addAttrs(llvm::AttrBuilder().addAlignmentAttr(Alignment)); + if (!getContext().getTargetAddressSpace(ETy) && + !CGM.getCodeGenOpts().NullPointerIsValid) + AI->addAttr(llvm::Attribute::NonNull); + } } // Set `align` attribute if any. |