[llvm] [CodeGen] Allow negative frame indicies in Register class. (PR #164459)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 4 12:02:39 PST 2025


================
@@ -0,0 +1,36 @@
+//===- RegisterTest.cpp -----------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/CodeGen/Register.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+
+namespace {
+TEST(RegisterTest, Idx2StackSlot) {
+  EXPECT_EQ(Register::index2StackSlot(0), Register::StackSlotZero);
+  EXPECT_EQ(Register::index2StackSlot(1), Register::StackSlotZero | 1);
+  EXPECT_EQ(Register::index2StackSlot(-1),
+            Register::StackSlotZero | Register::StackSlotMask);
+  int MaxPowOf2 = 1 << (Register::MaxFrameIndexBitwidth - 1);
+  // check that we do not crash on the highest possible value of frame index.
+  EXPECT_NO_FATAL_FAILURE(Register::index2StackSlot(MaxPowOf2 - 1));
----------------
arsenm wrote:

Why EXPECT_NO_FATAL_FAILURE instead of just checking the actual value? 

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


More information about the llvm-commits mailing list