Skip to content

Conversation

@googlewalt
Copy link
Contributor

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Oct 23, 2025

@llvm/pr-subscribers-backend-arm

Author: Walter Lee (googlewalt)

Changes

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

1 Files Affected:

  • (modified) llvm/lib/Target/ARM/ARMAsmPrinter.cpp (+2)
diff --git a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
index 8e35cadb75857..958a595874b9c 100644
--- a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
+++ b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
@@ -1640,7 +1640,9 @@ void ARMAsmPrinter::EmitKCFI_CHECK_Thumb2(Register AddrReg, int64_t Type,
     bool isLast = (i == 3);
 
     // Verify the immediate can be encoded as Thumb2 modified immediate.
+#ifndef NDEBUG
     int T2SOImmVal = ARM_AM::getT2SOImmVal(imm);
+#endif // NDEBUG
     assert(T2SOImmVal != -1 &&
            "Cannot encode immediate as Thumb2 modified immediate");
 

Copy link
Contributor

@boomanaiden154 boomanaiden154 left a comment

Choose a reason for hiding this comment

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

See https://llvm.org/docs/CodingStandards.html#assert-liberally.

We normally prefer [[maybe_unused]] in these cases.

@googlewalt
Copy link
Contributor Author

Is that the consensus? There are a dozen such usage in this directory already, and I have gotten push back for [[maybe_unused]] also.

Copy link
Contributor

@boomanaiden154 boomanaiden154 left a comment

Choose a reason for hiding this comment

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

Actually, looking at this case, the guidelines in the coding standards are to inline the call. So we just end up with:

    assert(ARM_AM::getT2SOImmVal(imm) != -1 &&
           "Cannot encode immediate as Thumb2 modified immediate");

This was changed recently (discourse post should be easy enough to find). But NDEBUG ifdefs I don't think were ever preferred in most areas of the repo.

@rnk
Copy link
Collaborator

rnk commented Oct 23, 2025

I like this as-written. I don't think inlining the call into the assert harms the readability, and it's arguably more efficient, i.e. we don't do the encoding function call at all. It's not clear to me if the optimizer can remove that.

@googlewalt googlewalt merged commit b08bbe5 into llvm:main Oct 23, 2025
7 of 9 checks passed
dvbuka pushed a commit to dvbuka/llvm-project that referenced this pull request Oct 27, 2025
dvbuka pushed a commit to dvbuka/llvm-project that referenced this pull request Oct 27, 2025
Lukacma pushed a commit to Lukacma/llvm-project that referenced this pull request Oct 29, 2025
aokblast pushed a commit to aokblast/llvm-project that referenced this pull request Oct 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants