diff options
| author | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-12 02:30:19 +0800 |
|---|---|---|
| committer | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-12 02:30:19 +0800 |
| commit | 0e73b1821cacb453c307cc1b9f35e989321b8e42 (patch) | |
| tree | d9c59378c840bc7b49bcc9458fb0fc3a04aa28e2 | |
| parent | 5ee4740bc864a8aaddb50e8e7a43cb5a18df0fcf (diff) | |
| download | rcc-project-0e73b1821cacb453c307cc1b9f35e989321b8e42.tar.gz rcc-project-0e73b1821cacb453c307cc1b9f35e989321b8e42.tar.xz | |
[CodeGen] Preserve variable-sized stack object offsets
| -rw-r--r-- | backend/lib/CodeGen/MachineFrameInfo.cpp | 8 | ||||
| -rw-r--r-- | backend/unittests/CodeGen/MachineFrameInfoTest.cpp | 6 |
2 files changed, 8 insertions, 6 deletions
diff --git a/backend/lib/CodeGen/MachineFrameInfo.cpp b/backend/lib/CodeGen/MachineFrameInfo.cpp index 8c3e6e5..80e1ee0 100644 --- a/backend/lib/CodeGen/MachineFrameInfo.cpp +++ b/backend/lib/CodeGen/MachineFrameInfo.cpp @@ -114,9 +114,9 @@ Expected<void> MachineFrameInfo::verifyDescription(const StackObjectDesc &Descri const bool IsVariable = Description.Kind == StackObjectKind::VariableSized || Description.Kind == StackObjectKind::DynamicAlloca; if (IsVariable) { - if (Description.Size || Description.Offset) { + if (Description.Size) { return makeUnexpected(ErrorCode::InvalidArgument, - "variable-sized stack objects cannot have a fixed size or offset"); + "variable-sized stack objects cannot have a fixed size"); } } else if (!Description.Size) { return makeUnexpected(ErrorCode::InvalidArgument, @@ -254,10 +254,6 @@ Expected<void> MachineFrameInfo::setObjectOffset(FrameIndex Index, std::int64_t "live stack object unexpectedly lacks a description"); } StackObjectDesc Description = *CurrentDescription; - if ((*Object)->isVariableSized()) { - return makeUnexpected(ErrorCode::InvalidArgument, - "variable-sized stack object cannot have a fixed offset"); - } Description.Offset = Offset; (*Object)->Description.emplace<StackObjectDesc>(std::move(Description)); return {}; diff --git a/backend/unittests/CodeGen/MachineFrameInfoTest.cpp b/backend/unittests/CodeGen/MachineFrameInfoTest.cpp index 78987c0..b0464a6 100644 --- a/backend/unittests/CodeGen/MachineFrameInfoTest.cpp +++ b/backend/unittests/CodeGen/MachineFrameInfoTest.cpp @@ -57,6 +57,8 @@ void testObjectLifecycle(TestContext &Context) { rcc::StackObjectDesc VariableDescription; VariableDescription.Kind = rcc::StackObjectKind::VariableSized; VariableDescription.Align = *rcc::Alignment::create(32); + VariableDescription.Offset = 0; + VariableDescription.LocalOffset = 0; auto Variable = Frame.createObject(VariableDescription); Context.expect(Local && Fixed && Spill && Variable, "valid stack object kinds must be created"); @@ -72,10 +74,14 @@ void testObjectLifecycle(TestContext &Context) { Context.expect(Frame.setObjectOffset(*Local, -8).has_value() && Frame.setObjectOffset(*Spill, -16).has_value() && + Frame.setObjectOffset(*Variable, -64).has_value() && Frame.markObjectDead(*Spill).has_value(), "live stack objects must support controlled pre-freeze updates"); Context.expect(Frame.object(*Spill)->description()->IsDead, "dead stack object state must remain explicit"); + Context.expect(Frame.object(*Variable)->description()->Offset == -64 && + Frame.object(*Variable)->description()->LocalOffset == 0, + "variable-sized stack objects must preserve LLVM MIR frame offsets"); Context.expect(Frame.eraseObject(*Fixed).has_value() && Frame.object(*Fixed) == nullptr && Frame.liveObjectCount() == 3, |
