[llvm] [llubi] Add support for byval pointer arguments (PR #201852)
Antonio Frighetto via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 8 03:19:38 PDT 2026
================
@@ -1826,10 +1830,61 @@ class InstExecutor : public InstVisitor<InstExecutor, void>,
for (auto [I, Arg] : enumerate(CB.args())) {
Type *ArgTy = Arg->getType();
AnyValue &ArgVal = CalleeArgs[I];
+
// CallBase::paramHasAttr also checks parameter attributes at known
// callee. We do it explicitly to avoid duplication.
AttributeSet AttrsAtCallSite = CB.getParamAttributes(I);
AttributeSet AttrsAtCallee = Callee->getAttributes().getParamAttrs(I);
+
+ if (ArgTy->isPointerTy()) {
+ auto *ByValTy = AttrsAtCallSite.getByValType();
+ auto *ByValTyFromCallee = AttrsAtCallee.getByValType();
+ if (ByValTy != ByValTyFromCallee) {
+ reportImmediateUB()
+ << "Mismatched byval attribute between callee and callsite.";
+ return;
+ }
+ if (ByValTy) {
+ if (ArgVal.isPoison()) {
+ reportImmediateUB() << "Invalid poison byval pointer argument.";
+ return;
+ }
+
+ uint64_t Size = Ctx.getEffectiveTypeAllocSize(ByValTy);
+ MaybeAlign AllocAlign = AttrsAtCallSite.getAlignment();
+ // Ignore the alignment at the callsite when it is set on the callee.
+ if (MaybeAlign CalleeAlign = AttrsAtCallee.getAlignment())
+ AllocAlign = CalleeAlign;
+ if (!AllocAlign.has_value()) {
+ // If the alignment is not specified, we use the default ABI
+ // alignment. This is the default behavior of
+ // TargetLoweringBase::getByValTypeAlignment.
+ AllocAlign = DL.getABITypeAlign(ByValTy);
+ }
+ // Byval pointers cannot be passed via variadic arguments.
+ auto Obj = Ctx.allocate(
+ Size, AllocAlign.value().value(), Callee->getArg(I)->getName(),
----------------
antoniofrighetto wrote:
Maybe directly `AllocAlign->value()` here?
https://github.com/llvm/llvm-project/pull/201852
More information about the llvm-commits
mailing list