[clang] [llvm] [ABI] Add IndirectAliased kind to abi::ArgInfo (PR #225005)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 21 01:57:37 PDT 2026
https://github.com/skc7 updated https://github.com/llvm/llvm-project/pull/225005
>From f86d33d8ab501f93a6ecfc160ef0fc99dc6a867a Mon Sep 17 00:00:00 2001
From: skc7 <Krishna.Sankisa at amd.com>
Date: Mon, 21 Sep 2026 11:10:12 +0530
Subject: [PATCH 1/3] [ABI] Add IndirectAliased kind to abi::ArgInfo
---
llvm/include/llvm/ABI/FunctionInfo.h | 23 +++++++++++--
llvm/unittests/ABI/FunctionInfoTest.cpp | 44 +++++++++++++++++++++++++
2 files changed, 64 insertions(+), 3 deletions(-)
diff --git a/llvm/include/llvm/ABI/FunctionInfo.h b/llvm/include/llvm/ABI/FunctionInfo.h
index d2e6c619a0434..a8e1e49494743 100644
--- a/llvm/include/llvm/ABI/FunctionInfo.h
+++ b/llvm/include/llvm/ABI/FunctionInfo.h
@@ -39,6 +39,9 @@ class ArgInfo {
/// Pass the argument indirectly via a hidden pointer with the specified
/// alignment and address space.
Indirect,
+ /// Like Indirect, but the pointer may alias an object referenced
+ /// elsewhere. The callee must not modify it and never treats it as byval.
+ IndirectAliased,
/// Ignore the argument (treat as void). Useful for void and empty structs.
Ignore,
};
@@ -129,6 +132,17 @@ class ArgInfo {
return AI;
}
+ /// An aliased indirect argument. It carries an address space but no byval,
+ /// since the pointer refers to an object the caller owns.
+ static ArgInfo getIndirectAliased(Align Align, unsigned AddrSpace,
+ bool Realign = false) {
+ ArgInfo AI(IndirectAliased);
+ AI.Alignment = Align;
+ AI.IndirectAttr.AddrSpace = AddrSpace;
+ AI.IndirectRealign = Realign;
+ return AI;
+ }
+
static ArgInfo getIgnore() { return ArgInfo(Ignore); }
ArgInfo &setSignExt(bool SignExtend = true) {
@@ -155,6 +169,7 @@ class ArgInfo {
Kind getKind() const { return TheKind; }
bool isDirect() const { return TheKind == Direct; }
bool isIndirect() const { return TheKind == Indirect; }
+ bool isIndirectAliased() const { return TheKind == IndirectAliased; }
bool isIgnore() const { return TheKind == Ignore; }
bool isExtend() const { return TheKind == Extend; }
@@ -169,24 +184,26 @@ class ArgInfo {
}
Align getIndirectAlign() const {
- assert(isIndirect() && "Invalid Kind!");
+ assert((isIndirect() || isIndirectAliased()) && "Invalid Kind!");
assert(Alignment.has_value() &&
"Indirect arguments must have an alignment");
return *Alignment;
}
unsigned getIndirectAddrSpace() const {
- assert(isIndirect() && "Invalid Kind!");
+ assert((isIndirect() || isIndirectAliased()) && "Invalid Kind!");
return IndirectAttr.AddrSpace;
}
+ // ByVal is meaningful only for Indirect, since an aliased pointer is never
+ // copied.
bool getIndirectByVal() const {
assert(isIndirect() && "Invalid Kind!");
return IndirectByVal;
}
bool getIndirectRealign() const {
- assert(isIndirect() && "Invalid Kind!");
+ assert((isIndirect() || isIndirectAliased()) && "Invalid Kind!");
return IndirectRealign;
}
diff --git a/llvm/unittests/ABI/FunctionInfoTest.cpp b/llvm/unittests/ABI/FunctionInfoTest.cpp
index 224faa846f57d..0a855edab9bb4 100644
--- a/llvm/unittests/ABI/FunctionInfoTest.cpp
+++ b/llvm/unittests/ABI/FunctionInfoTest.cpp
@@ -95,6 +95,43 @@ TEST_F(FunctionInfoTest, CanBeFlattenedSurvivesFunctionInfo) {
EXPECT_FALSE(Copy.Info.getCanBeFlattened());
}
+TEST_F(FunctionInfoTest, IndirectAliasedCarriesAddrSpaceAndAlign) {
+ ArgInfo Info = ArgInfo::getIndirectAliased(llvm::Align(8), /*AddrSpace=*/5,
+ /*Realign=*/true);
+ EXPECT_TRUE(Info.isIndirectAliased());
+ // Aliased is its own kind, distinct from a plain indirect.
+ EXPECT_FALSE(Info.isIndirect());
+ EXPECT_EQ(Info.getIndirectAlign(), llvm::Align(8));
+ EXPECT_EQ(Info.getIndirectAddrSpace(), 5u);
+ EXPECT_TRUE(Info.getIndirectRealign());
+}
+
+TEST_F(FunctionInfoTest, IndirectAliasedDefaultsToNoRealign) {
+ ArgInfo Info = ArgInfo::getIndirectAliased(llvm::Align(4), /*AddrSpace=*/0);
+ EXPECT_TRUE(Info.isIndirectAliased());
+ EXPECT_FALSE(Info.getIndirectRealign());
+}
+
+TEST_F(FunctionInfoTest, PlainIndirectIsNotAliased) {
+ ArgInfo Info = ArgInfo::getIndirect(llvm::Align(8), /*ByVal=*/true);
+ EXPECT_TRUE(Info.isIndirect());
+ EXPECT_FALSE(Info.isIndirectAliased());
+ EXPECT_TRUE(Info.getIndirectByVal());
+}
+
+TEST_F(FunctionInfoTest, IndirectAliasedSurvivesFunctionInfo) {
+ std::unique_ptr<FunctionInfo> FI =
+ FunctionInfo::create(llvm::CallingConv::C, TwoI64, {TwoI64});
+ FI->getArgInfo(0).Info =
+ ArgInfo::getIndirectAliased(llvm::Align(8), /*AddrSpace=*/5);
+
+ const ArgInfo &Info =
+ static_cast<const FunctionInfo &>(*FI).getArgInfo(0).Info;
+ EXPECT_TRUE(Info.isIndirectAliased());
+ EXPECT_EQ(Info.getIndirectAddrSpace(), 5u);
+ EXPECT_EQ(Info.getIndirectAlign(), llvm::Align(8));
+}
+
#if GTEST_HAS_DEATH_TEST && !defined(NDEBUG)
TEST_F(FunctionInfoTest, CanBeFlattenedIsDirectOnly) {
EXPECT_DEATH((void)ArgInfo::getIgnore().getCanBeFlattened(), "Invalid Kind");
@@ -106,6 +143,13 @@ TEST_F(FunctionInfoTest, CanBeFlattenedIsDirectOnly) {
EXPECT_DEATH((void)ArgInfo::getIgnore().setCanBeFlattened(false),
"Invalid Kind");
}
+
+TEST_F(FunctionInfoTest, IndirectAliasedHasNoByVal) {
+ EXPECT_DEATH(
+ (void)ArgInfo::getIndirectAliased(llvm::Align(8), /*AddrSpace=*/0)
+ .getIndirectByVal(),
+ "Invalid Kind");
+}
#endif
} // namespace
>From 6fc11f102d3e3c69b34f0f20f7d8f7c513651897 Mon Sep 17 00:00:00 2001
From: skc7 <Krishna.Sankisa at amd.com>
Date: Mon, 21 Sep 2026 12:01:57 +0530
Subject: [PATCH 2/3] fix ci failure
---
clang/lib/CodeGen/CGCall.cpp | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 50e04280e2a7d..cb087adb69c60 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -1060,6 +1060,14 @@ ABIArgInfo CodeGenModule::convertABIArgInfo(const llvm::abi::ArgInfo &AbiInfo,
AbiInfo.getIndirectByVal(),
AbiInfo.getIndirectRealign());
}
+ case llvm::abi::ArgInfo::IndirectAliased: {
+ // Aliased indirect carries an address space but never byval.
+ CharUnits Alignment =
+ CharUnits::fromQuantity(AbiInfo.getIndirectAlign().value());
+ return ABIArgInfo::getIndirectAliased(Alignment,
+ AbiInfo.getIndirectAddrSpace(),
+ AbiInfo.getIndirectRealign());
+ }
case llvm::abi::ArgInfo::Ignore:
return ABIArgInfo::getIgnore();
}
>From f336a43a7b8fc01c10e9dafcbc66aaa6e1faeb3a Mon Sep 17 00:00:00 2001
From: skc7 <Krishna.Sankisa at amd.com>
Date: Mon, 21 Sep 2026 14:26:58 +0530
Subject: [PATCH 3/3] update comment for getIndirectByVal
---
llvm/include/llvm/ABI/FunctionInfo.h | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/llvm/include/llvm/ABI/FunctionInfo.h b/llvm/include/llvm/ABI/FunctionInfo.h
index a8e1e49494743..3f85636dbb755 100644
--- a/llvm/include/llvm/ABI/FunctionInfo.h
+++ b/llvm/include/llvm/ABI/FunctionInfo.h
@@ -195,9 +195,8 @@ class ArgInfo {
return IndirectAttr.AddrSpace;
}
- // ByVal is meaningful only for Indirect, since an aliased pointer is never
- // copied.
bool getIndirectByVal() const {
+ // Aliased pointers are never byval.
assert(isIndirect() && "Invalid Kind!");
return IndirectByVal;
}
More information about the llvm-commits
mailing list