@@ -2124,45 +2124,42 @@ static void writeDIGenericSubrange(raw_ostream &Out, const DIGenericSubrange *N,
2124
2124
Out << " !DIGenericSubrange(" ;
2125
2125
MDFieldPrinter Printer (Out, WriterCtx);
2126
2126
2127
- auto IsConstant = [&](Metadata *Bound) -> bool {
2128
- if (auto *BE = dyn_cast_or_null<DIExpression>(Bound)) {
2129
- return BE->isConstant () &&
2130
- DIExpression::SignedOrUnsignedConstant::SignedConstant ==
2131
- *BE->isConstant ();
2132
- }
2133
- return false ;
2134
- };
2135
-
2136
- auto GetConstant = [&](Metadata *Bound) -> int64_t {
2137
- assert (IsConstant (Bound) && " Expected constant" );
2127
+ auto GetConstant = [&](Metadata *Bound) -> std::optional<int64_t > {
2138
2128
auto *BE = dyn_cast_or_null<DIExpression>(Bound);
2139
- return static_cast <int64_t >(BE->getElement (1 ));
2129
+ if (!BE)
2130
+ return std::nullopt;
2131
+ if (BE->isConstant () &&
2132
+ DIExpression::SignedOrUnsignedConstant::SignedConstant ==
2133
+ *BE->isConstant ()) {
2134
+ return static_cast <int64_t >(BE->getElement (1 ));
2135
+ }
2136
+ return std::nullopt;
2140
2137
};
2141
2138
2142
2139
auto *Count = N->getRawCountNode ();
2143
- if (IsConstant (Count))
2144
- Printer.printInt (" count" , GetConstant (Count) ,
2140
+ if (auto ConstantCount = GetConstant (Count))
2141
+ Printer.printInt (" count" , *ConstantCount ,
2145
2142
/* ShouldSkipZero */ false );
2146
2143
else
2147
2144
Printer.printMetadata (" count" , Count, /* ShouldSkipNull */ true );
2148
2145
2149
2146
auto *LBound = N->getRawLowerBound ();
2150
- if (IsConstant (LBound))
2151
- Printer.printInt (" lowerBound" , GetConstant (LBound) ,
2147
+ if (auto ConstantLBound = GetConstant (LBound))
2148
+ Printer.printInt (" lowerBound" , *ConstantLBound ,
2152
2149
/* ShouldSkipZero */ false );
2153
2150
else
2154
2151
Printer.printMetadata (" lowerBound" , LBound, /* ShouldSkipNull */ true );
2155
2152
2156
2153
auto *UBound = N->getRawUpperBound ();
2157
- if (IsConstant (UBound))
2158
- Printer.printInt (" upperBound" , GetConstant (UBound) ,
2154
+ if (auto ConstantUBound = GetConstant (UBound))
2155
+ Printer.printInt (" upperBound" , *ConstantUBound ,
2159
2156
/* ShouldSkipZero */ false );
2160
2157
else
2161
2158
Printer.printMetadata (" upperBound" , UBound, /* ShouldSkipNull */ true );
2162
2159
2163
2160
auto *Stride = N->getRawStride ();
2164
- if (IsConstant (Stride))
2165
- Printer.printInt (" stride" , GetConstant (Stride) ,
2161
+ if (auto ConstantStride = GetConstant (Stride))
2162
+ Printer.printInt (" stride" , *ConstantStride ,
2166
2163
/* ShouldSkipZero */ false );
2167
2164
else
2168
2165
Printer.printMetadata (" stride" , Stride, /* ShouldSkipNull */ true );
0 commit comments