diff options
author | Michael Liao <michael.hliao@gmail.com> | 2020-05-05 00:55:13 -0400 |
---|---|---|
committer | Michael Liao <michael.hliao@gmail.com> | 2020-05-05 15:31:51 -0400 |
commit | 9142c0b46bfea13d9348ab3d1d706a10ad9e5c8e (patch) | |
tree | 815717f34ae7c8c95f4874935a5575036cd6a87d /clang/lib/CodeGen/CGCall.cpp | |
parent | 276c8dde0b58cfe29035448a27e16eff9fcf2a5a (diff) | |
download | llvm-9142c0b46bfea13d9348ab3d1d706a10ad9e5c8e.zip llvm-9142c0b46bfea13d9348ab3d1d706a10ad9e5c8e.tar.gz llvm-9142c0b46bfea13d9348ab3d1d706a10ad9e5c8e.tar.bz2 |
[clang][codegen] Hoist parameter attribute setting in function prolog.
Summary:
- If the coerced type is still a pointer, it should be set with proper
parameter attributes, such as `noalias`, `nonnull`, and etc. Hoist
that (pointer) parameter attribute setting so that the coerced pointer
parameter could be marked properly.
Depends on D79394
Reviewers: rjmccall, kerbowa, yaxunl
Subscribers: jvesely, nhaehnle, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D79395
Diffstat (limited to 'clang/lib/CodeGen/CGCall.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGCall.cpp | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 44f2988..e336741 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -2425,15 +2425,18 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI, case ABIArgInfo::Extend: case ABIArgInfo::Direct: { - - // If we have the trivial case, handle it with no muss and fuss. - if (!isa<llvm::StructType>(ArgI.getCoerceToType()) && - ArgI.getCoerceToType() == ConvertType(Ty) && - ArgI.getDirectOffset() == 0) { + auto AI = Fn->getArg(FirstIRArg); + llvm::Type *LTy = ConvertType(Arg->getType()); + + // Prepare parameter attributes. So far, only attributes for pointer + // parameters are prepared. See + // http://llvm.org/docs/LangRef.html#paramattrs. + if (ArgI.getDirectOffset() == 0 && LTy->isPointerTy() && + ArgI.getCoerceToType()->isPointerTy()) { assert(NumIRArgs == 1); - auto AI = Fn->getArg(FirstIRArg); if (const ParmVarDecl *PVD = dyn_cast<ParmVarDecl>(Arg)) { + // Set `nonnull` attribute if any. if (getNonNullAttr(CurCodeDecl, PVD, PVD->getType(), PVD->getFunctionScopeIndex()) && !CGM.getCodeGenOpts().NullPointerIsValid) @@ -2471,6 +2474,7 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI, AI->addAttr(llvm::Attribute::NonNull); } + // Set `align` attribute if any. const auto *AVAttr = PVD->getAttr<AlignValueAttr>(); if (!AVAttr) if (const auto *TOTy = dyn_cast<TypedefType>(OTy)) @@ -2488,8 +2492,17 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI, } } + // Set 'noalias' if an argument type has the `restrict` qualifier. if (Arg->getType().isRestrictQualified()) AI->addAttr(llvm::Attribute::NoAlias); + } + + // Prepare the argument value. If we have the trivial case, handle it + // with no muss and fuss. + if (!isa<llvm::StructType>(ArgI.getCoerceToType()) && + ArgI.getCoerceToType() == ConvertType(Ty) && + ArgI.getDirectOffset() == 0) { + assert(NumIRArgs == 1); // LLVM expects swifterror parameters to be used in very restricted // ways. Copy the value into a less-restricted temporary. |