[llvm] f3139b2 - [GlobalISel] Fix wrong invocation of `getParamStackAlign` (NFC)
Momchil Velikov via llvm-commits
llvm-commits at lists.llvm.org
Mon May 10 04:17:30 PDT 2021
Author: Momchil Velikov
Date: 2021-05-10T12:16:33+01:00
New Revision: f3139b20a0bf56b3a5e20542363a799619b98ec9
URL: https://github.com/llvm/llvm-project/commit/f3139b20a0bf56b3a5e20542363a799619b98ec9
DIFF: https://github.com/llvm/llvm-project/commit/f3139b20a0bf56b3a5e20542363a799619b98ec9.diff
LOG: [GlobalISel] Fix wrong invocation of `getParamStackAlign` (NFC)
The function template `CallLowering::setArgFlags` is invoked both
for arguments and return values. In the latter case, it calls
`getParamStackAlign` with argument index `~0u`. Nothing wrong
happens now, as the argument is safely incremented back to 0
inside `getParamStackAlign` (the type is `unsigned`), but in
principle it's fragile and may become incorrect.
Differential Revision: https://reviews.llvm.org/D102004
Added:
Modified:
llvm/lib/CodeGen/GlobalISel/CallLowering.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp b/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp
index 6e2264400791..94b191b6b371 100644
--- a/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp
@@ -154,8 +154,9 @@ void CallLowering::setArgFlags(CallLowering::ArgInfo &Arg, unsigned OpIdx,
const AttributeList &Attrs = FuncInfo.getAttributes();
addArgFlagsFromAttributes(Flags, Attrs, OpIdx);
- Align MemAlign;
+ Align MemAlign = DL.getABITypeAlign(Arg.Ty);
if (Flags.isByVal() || Flags.isInAlloca() || Flags.isPreallocated()) {
+ assert(OpIdx >= AttributeList::FirstArgIndex);
Type *ElementTy = cast<PointerType>(Arg.Ty)->getElementType();
auto Ty = Attrs.getAttribute(OpIdx, Attribute::ByVal).getValueAsType();
@@ -163,16 +164,18 @@ void CallLowering::setArgFlags(CallLowering::ArgInfo &Arg, unsigned OpIdx,
// For ByVal, alignment should be passed from FE. BE will guess if
// this info is not there but there are cases it cannot get right.
- if (auto ParamAlign = FuncInfo.getParamStackAlign(OpIdx - 1))
+ if (auto ParamAlign =
+ FuncInfo.getParamStackAlign(OpIdx - AttributeList::FirstArgIndex))
MemAlign = *ParamAlign;
- else if ((ParamAlign = FuncInfo.getParamAlign(OpIdx - 1)))
+ else if ((ParamAlign =
+ FuncInfo.getParamAlign(OpIdx - AttributeList::FirstArgIndex)))
MemAlign = *ParamAlign;
else
MemAlign = Align(getTLI()->getByValTypeAlignment(ElementTy, DL));
- } else if (auto ParamAlign = FuncInfo.getParamStackAlign(OpIdx - 1)) {
- MemAlign = *ParamAlign;
- } else {
- MemAlign = Align(DL.getABITypeAlign(Arg.Ty));
+ } else if (OpIdx >= AttributeList::FirstArgIndex) {
+ if (auto ParamAlign =
+ FuncInfo.getParamStackAlign(OpIdx - AttributeList::FirstArgIndex))
+ MemAlign = *ParamAlign;
}
Flags.setMemAlign(MemAlign);
Flags.setOrigAlign(DL.getABITypeAlign(Arg.Ty));
More information about the llvm-commits
mailing list