[llvm] [AArch64][SVE] Tweak how SVE CFI expressions are emitted (PR #151677)

Benjamin Maxwell via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 4 03:30:18 PDT 2025


================
@@ -221,6 +221,23 @@ inline uint64_t decodeULEB128AndIncUnsafe(const uint8_t *&p) {
   return decodeULEB128AndInc(p, nullptr);
 }
 
+enum class LEB128Sign { Unsigned, Signed };
+
+template <LEB128Sign Sign, typename T, typename U = char,
+          unsigned MaxLEB128SizeBytes = 16>
+inline void appendLEB128(SmallVectorImpl<U> &Buffer, T Value) {
+  static_assert(sizeof(U) == 1, "Expected buffer of bytes");
+  unsigned LEB128ValueSize;
+  U TmpBuffer[MaxLEB128SizeBytes];
+  if constexpr (Sign == LEB128Sign::Signed)
----------------
MacDue wrote:

The two functions would be identical (including an assert -- if generalized over `char` and `uint8_t`) -- just without the `if constexpr` (which is compile-time only). 

I also find `appendLEB128<LEB128Sign::Signed>` more readable than `appendSLEB128` (tiny function name differences like `S` vs `U` are the type of thing that I sometimes just can't see without a `diff` tool).  

https://github.com/llvm/llvm-project/pull/151677


More information about the llvm-commits mailing list