From 14a02f58dffc0e34f2cea914f207d9d37773b759 Mon Sep 17 00:00:00 2001 From: Richard-Qin-X Date: Sat, 29 Aug 2026 00:28:29 +0800 Subject: [GlobalISel] Assert vector element type invariants --- backend/lib/CodeGen/GlobalISel/Utils.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'backend/lib/CodeGen') diff --git a/backend/lib/CodeGen/GlobalISel/Utils.cpp b/backend/lib/CodeGen/GlobalISel/Utils.cpp index 0f8d638..f9d6b0a 100644 --- a/backend/lib/CodeGen/GlobalISel/Utils.cpp +++ b/backend/lib/CodeGen/GlobalISel/Utils.cpp @@ -11,6 +11,7 @@ #include "rcc/CodeGen/MachineRegisterInfo.h" #include "rcc/CodeGen/TargetDescription.h" +#include #include #include #include @@ -89,7 +90,9 @@ namespace { "vector part extraction requires a fixed vector and a nonzero element count"); } - const LowLevelType ElementType = *RegisterType->scalarElementType(); + const std::optional ElementTypeValue = RegisterType->scalarElementType(); + assert(ElementTypeValue && "validated vector type must have an element type"); + const LowLevelType ElementType = *ElementTypeValue; auto NarrowType = makeVectorType(ElementCount, false, ElementType); if (!NarrowType) return std::unexpected(NarrowType.error()); @@ -325,8 +328,9 @@ Expected extractParts(Register Reg, LowLevelType RegisterType, LowLevelTyp if (LeftoverElementCount > 1 && MainElementCount % LeftoverElementCount == 0 && RegisterElementCount % LeftoverElementCount == 0 && RegisterType.scalarBitWidth() == MainType.scalarBitWidth()) { - auto Candidate = - LowLevelType::makeFixedVector(LeftoverElementCount, *RegisterType.scalarElementType()); + const std::optional ElementType = RegisterType.scalarElementType(); + assert(ElementType && "validated vector type must have an element type"); + auto Candidate = LowLevelType::makeFixedVector(LeftoverElementCount, *ElementType); if (!Candidate) return std::unexpected(Candidate.error()); LeftoverType = *Candidate; -- cgit v1.2.3