[llvm] InstCombine: Don't read first argument of call until checking intrinsic ID. (PR #195195)
Peter Collingbourne via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 30 16:11:07 PDT 2026
https://github.com/pcc created https://github.com/llvm/llvm-project/pull/195195
If llvm.ptrauth.* is called on the result of a call with no arguments
InstCombine will hit an assertion failure due to reading the non-existent
first argument. Fix it.
Assisted-by: gemini (wrote test)
>From d351f1f4f3d2528b75fe9c7757dce2deb707fdb7 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne <peter at pcc.me.uk>
Date: Thu, 30 Apr 2026 16:10:52 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
=?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.6-beta.1
---
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp | 2 +-
.../test/Transforms/InstCombine/ptrauth-intrinsics.ll | 11 +++++++++++
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index 131982ad7c1d2..3bcec0827e9a1 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -3314,7 +3314,6 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
if (DS != OtherDS)
break;
- BasePtr = CI->getArgOperand(0);
if (CI->getIntrinsicID() == Intrinsic::ptrauth_sign) {
if (CI->getArgOperand(1) != Key || CI->getArgOperand(2) != Disc)
break;
@@ -3327,6 +3326,7 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
AuthDisc = CI->getArgOperand(2);
} else
break;
+ BasePtr = CI->getArgOperand(0);
} else if (const auto *PtrToInt = dyn_cast<PtrToIntOperator>(Ptr)) {
// ptrauth constants are equivalent to a call to @llvm.ptrauth.sign for
// our purposes, so check for that too.
diff --git a/llvm/test/Transforms/InstCombine/ptrauth-intrinsics.ll b/llvm/test/Transforms/InstCombine/ptrauth-intrinsics.ll
index 784d2c90645b2..cc4be6dfb30d3 100644
--- a/llvm/test/Transforms/InstCombine/ptrauth-intrinsics.ll
+++ b/llvm/test/Transforms/InstCombine/ptrauth-intrinsics.ll
@@ -222,6 +222,17 @@ define i64 @test_ptrauth_nop_ds_constant() {
ret i64 %authed
}
+define i64 @test_ptrauth_auth_call_no_args() {
+; CHECK-LABEL: @test_ptrauth_auth_call_no_args(
+; CHECK-NEXT: [[CALL:%.*]] = call i64 @foo()
+; CHECK-NEXT: [[AUTHED:%.*]] = call i64 @llvm.ptrauth.auth(i64 [[CALL]], i32 1, i64 1234)
+; CHECK-NEXT: ret i64 [[AUTHED]]
+;
+ %call = call i64 @foo()
+ %authed = call i64 @llvm.ptrauth.auth(i64 %call, i32 1, i64 1234)
+ ret i64 %authed
+}
+
declare i64 @llvm.ptrauth.auth(i64, i32, i64)
declare i64 @llvm.ptrauth.sign(i64, i32, i64)
declare i64 @llvm.ptrauth.resign(i64, i32, i64, i32, i64)
More information about the llvm-commits
mailing list