@@ -2107,45 +2107,43 @@ 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
+
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;
2123
2121
};
2124
2122
2125
2123
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 ,
2128
2126
/* ShouldSkipZero */ false );
2129
2127
else
2130
2128
Printer.printMetadata (" count" , Count, /* ShouldSkipNull */ true );
2131
2129
2132
2130
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 ,
2135
2133
/* ShouldSkipZero */ false );
2136
2134
else
2137
2135
Printer.printMetadata (" lowerBound" , LBound, /* ShouldSkipNull */ true );
2138
2136
2139
2137
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 ,
2142
2140
/* ShouldSkipZero */ false );
2143
2141
else
2144
2142
Printer.printMetadata (" upperBound" , UBound, /* ShouldSkipNull */ true );
2145
2143
2146
2144
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 ,
2149
2147
/* ShouldSkipZero */ false );
2150
2148
else
2151
2149
Printer.printMetadata (" stride" , Stride, /* ShouldSkipNull */ true );
0 commit comments