@@ -2107,45 +2107,42 @@ static void writeDIGenericSubrange(raw_ostream &Out, const DIGenericSubrange *N,
2107
2107
Out << " !DIGenericSubrange(" ;
2108
2108
MDFieldPrinter Printer (Out, WriterCtx);
2109
2109
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 > {
2121
2111
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
+ if (BE->isConstant () &&
2115
+ DIExpression::SignedOrUnsignedConstant::SignedConstant ==
2116
+ *BE->isConstant ()) {
2117
+ return static_cast <int64_t >(BE->getElement (1 ));
2118
+ }
2119
+ return std::nullopt;
2123
2120
};
2124
2121
2125
2122
auto *Count = N->getRawCountNode ();
2126
- if (IsConstant (Count))
2127
- Printer.printInt (" count" , GetConstant (Count) ,
2123
+ if (auto ConstantCount = GetConstant (Count))
2124
+ Printer.printInt (" count" , *ConstantCount ,
2128
2125
/* ShouldSkipZero */ false );
2129
2126
else
2130
2127
Printer.printMetadata (" count" , Count, /* ShouldSkipNull */ true );
2131
2128
2132
2129
auto *LBound = N->getRawLowerBound ();
2133
- if (IsConstant (LBound))
2134
- Printer.printInt (" lowerBound" , GetConstant (LBound) ,
2130
+ if (auto ConstantLBound = GetConstant (LBound))
2131
+ Printer.printInt (" lowerBound" , *ConstantLBound ,
2135
2132
/* ShouldSkipZero */ false );
2136
2133
else
2137
2134
Printer.printMetadata (" lowerBound" , LBound, /* ShouldSkipNull */ true );
2138
2135
2139
2136
auto *UBound = N->getRawUpperBound ();
2140
- if (IsConstant (UBound))
2141
- Printer.printInt (" upperBound" , GetConstant (UBound) ,
2137
+ if (auto ConstantUBound = GetConstant (UBound))
2138
+ Printer.printInt (" upperBound" , *ConstantUBound ,
2142
2139
/* ShouldSkipZero */ false );
2143
2140
else
2144
2141
Printer.printMetadata (" upperBound" , UBound, /* ShouldSkipNull */ true );
2145
2142
2146
2143
auto *Stride = N->getRawStride ();
2147
- if (IsConstant (Stride))
2148
- Printer.printInt (" stride" , GetConstant (Stride) ,
2144
+ if (auto ConstantStride = GetConstant (Stride))
2145
+ Printer.printInt (" stride" , *ConstantStride ,
2149
2146
/* ShouldSkipZero */ false );
2150
2147
else
2151
2148
Printer.printMetadata (" stride" , Stride, /* ShouldSkipNull */ true );
0 commit comments