@@ -2107,45 +2107,43 @@ static void writeDIGenericSubrange(raw_ostream &Out, const DIGenericSubrange *N,
21072107 Out << " !DIGenericSubrange(" ;
21082108 MDFieldPrinter Printer (Out, WriterCtx);
21092109
2110- auto IsConstant = [&](Metadata *Bound) -> bool {
2111- if (auto *BE = dyn_cast_or_null<DIExpression>(Bound)) {
2112- return BE->isConstant () &&
2113- DIExpression::SignedOrUnsignedConstant::SignedConstant ==
2114- *BE->isConstant ();
2115- }
2116- return false ;
2117- };
2118-
2119- auto GetConstant = [&](Metadata *Bound) -> int64_t {
2120- assert (IsConstant (Bound) && " Expected constant" );
2110+ auto GetConstant = [&](Metadata *Bound) -> std::optional<int64_t > {
21212111 auto *BE = dyn_cast_or_null<DIExpression>(Bound);
2122- return static_cast <int64_t >(BE->getElement (1 ));
2112+ if (!BE)
2113+ return std::nullopt ;
2114+
2115+ if (BE->isConstant () &&
2116+ DIExpression::SignedOrUnsignedConstant::SignedConstant == *BE->isConstant ()) {
2117+ return static_cast <int64_t >(BE->getElement (1 ));
2118+ }
2119+
2120+ return std::nullopt ;
21232121 };
21242122
21252123 auto *Count = N->getRawCountNode ();
2126- if (IsConstant (Count))
2127- Printer.printInt (" count" , GetConstant (Count) ,
2124+ if (auto ConstantCount = GetConstant (Count))
2125+ Printer.printInt (" count" , *ConstantCount ,
21282126 /* ShouldSkipZero */ false );
21292127 else
21302128 Printer.printMetadata (" count" , Count, /* ShouldSkipNull */ true );
21312129
21322130 auto *LBound = N->getRawLowerBound ();
2133- if (IsConstant (LBound))
2134- Printer.printInt (" lowerBound" , GetConstant (LBound) ,
2131+ if (auto ConstantLBound = GetConstant (LBound))
2132+ Printer.printInt (" lowerBound" , *ConstantLBound ,
21352133 /* ShouldSkipZero */ false );
21362134 else
21372135 Printer.printMetadata (" lowerBound" , LBound, /* ShouldSkipNull */ true );
21382136
21392137 auto *UBound = N->getRawUpperBound ();
2140- if (IsConstant (UBound))
2141- Printer.printInt (" upperBound" , GetConstant (UBound) ,
2138+ if (auto ConstantUBound = GetConstant (UBound))
2139+ Printer.printInt (" upperBound" , *ConstantUBound ,
21422140 /* ShouldSkipZero */ false );
21432141 else
21442142 Printer.printMetadata (" upperBound" , UBound, /* ShouldSkipNull */ true );
21452143
21462144 auto *Stride = N->getRawStride ();
2147- if (IsConstant (Stride))
2148- Printer.printInt (" stride" , GetConstant (Stride) ,
2145+ if (auto ConstantStride = GetConstant (Stride))
2146+ Printer.printInt (" stride" , *ConstantStride ,
21492147 /* ShouldSkipZero */ false );
21502148 else
21512149 Printer.printMetadata (" stride" , Stride, /* ShouldSkipNull */ true );
0 commit comments