[llvm] [llubi] Add support for byval pointer arguments (PR #201852)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 24 02:19:25 PDT 2026
================
@@ -1826,10 +1830,62 @@ 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;
----------------
nikic wrote:
Not sure I get why we can just ignore the call-site alignment. Like if we have call-site align 128 and callee align 1 won't we fail to verify that the incoming value is aligned to 128?
Maybe we should just enforce that the alignments are equal? For byval the alignment is also an ABI property.
(We might want to have a separate error reporting kind for ABI mismatches instead of using reportImmediateUB -- just to be clear that it's not *always* UB, it's just very likely, and we can't verify it more precisely.)
https://github.com/llvm/llvm-project/pull/201852
More information about the llvm-commits
mailing list