Skip to content

Conversation

@bgergely0
Copy link
Contributor

@bgergely0 bgergely0 commented Jan 6, 2026

Several BTI-related functions are checking that a call MCInst has one
non-annotation operand.

This patch changes these checks to use MCPlus::getNumPrimeOperands,
instead of getNumOperands.

Testing: added annotations to existing gtests to serve as regression tests.
These now also explicitly check getNumOperands and getNumPrimeOperands
usage on the annotated MCInsts.

@bgergely0 bgergely0 marked this pull request as ready for review January 6, 2026 14:49
@llvmbot llvmbot added the BOLT label Jan 6, 2026
@llvmbot
Copy link
Member

llvmbot commented Jan 6, 2026

@llvm/pr-subscribers-bolt

Author: Gergely Bálint (bgergely0)

Changes

Use MCPlus::getNumPrimeOperands to check number of non-annotation
operands instead of getNumOperands.


Full diff: https://github.com/llvm/llvm-project/pull/174600.diff

1 Files Affected:

  • (modified) bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp (+2-2)
diff --git a/bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp b/bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp
index 03fb4ddc2f238..a30799d5f45d3 100644
--- a/bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp
+++ b/bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp
@@ -2818,7 +2818,7 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
     // x16 or x17. If the operand is not x16 or x17, it can be accepted by a BTI
     // j or BTI jc (and not BTI c).
     if (isIndirectBranch(Call)) {
-      assert(Call.getNumOperands() == 1 &&
+      assert(MCPlus::getNumPrimeOperands(Call) == 1 &&
              "Indirect branch needs to have 1 operand.");
       assert(Call.getOperand(0).isReg() &&
              "Indirect branch does not have a register operand.");
@@ -2856,7 +2856,7 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
     // x16 or x17. If the operand is not x16 or x17, it can be accepted by a
     // BTI j or BTI jc (and not BTI c).
     if (isIndirectBranch(Call)) {
-      assert(Call.getNumOperands() == 1 &&
+      assert(MCPlus::getNumPrimeOperands(Call) == 1 &&
              "Indirect branch needs to have 1 operand.");
       assert(Call.getOperand(0).isReg() &&
              "Indirect branch does not have a register operand.");

@bgergely0 bgergely0 changed the title [BOLT] Fix isCallCoveredByBTI and insertBTI assertions [BOLT] Fix asserts in isCallCoveredByBTI and insertBTI Jan 6, 2026
Copy link
Member

@peterwaller-arm peterwaller-arm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix sounds reasonable though it makes me wonder if other uses of getNumOperands are wrong: what about the IsExplicitBTI definition, for example?

@bgergely0
Copy link
Contributor Author

me wonder if other uses of getNumOperands are wrong: what about the IsExplicitBTI definition, for example?

that's a good point. Let me check other uses, and add a few relevant tests.

Several BTI-related functions are checking that a call MCInst has one
non-annotation operand.

This patch changes these checks to use MCPlus::getNumPrimeOperands,
instead of getNumOperands.
@bgergely0 bgergely0 force-pushed the users/bgergely0/bolt-fix-numoperands branch from 15dceca to da54184 Compare January 6, 2026 16:20
Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@bgergely0 bgergely0 changed the title [BOLT] Fix asserts in isCallCoveredByBTI and insertBTI [BOLT][BTI] Fix assertions checking getNumOperands Jan 6, 2026
Copy link
Member

@paschalis-mpeis paschalis-mpeis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thanks Gergely, can you update the commit message to note that unit tests were updated to cover this?

@bgergely0 bgergely0 merged commit 76c300c into main Jan 7, 2026
10 checks passed
@bgergely0 bgergely0 deleted the users/bgergely0/bolt-fix-numoperands branch January 7, 2026 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants