@@ -2061,7 +2061,8 @@ void AsmPrinter::Impl::printLocationInternal(LocationAttr loc, bool pretty,
2061
2061
2062
2062
// / Print a floating point value in a way that the parser will be able to
2063
2063
// / round-trip losslessly.
2064
- static void printFloatValue (const APFloat &apValue, raw_ostream &os) {
2064
+ static void printFloatValue (const APFloat &apValue, raw_ostream &os,
2065
+ bool *printedHex = nullptr ) {
2065
2066
// We would like to output the FP constant value in exponential notation,
2066
2067
// but we cannot do this if doing so will lose precision. Check here to
2067
2068
// make sure that we only output it in exponential format if we can parse
@@ -2102,6 +2103,8 @@ static void printFloatValue(const APFloat &apValue, raw_ostream &os) {
2102
2103
2103
2104
// Print special values in hexadecimal format. The sign bit should be included
2104
2105
// in the literal.
2106
+ if (printedHex)
2107
+ *printedHex = true ;
2105
2108
SmallVector<char , 16 > str;
2106
2109
APInt apInt = apValue.bitcastToAPInt ();
2107
2110
apInt.toString (str, /* Radix=*/ 16 , /* Signed=*/ false ,
@@ -2275,10 +2278,12 @@ void AsmPrinter::Impl::printAttributeImpl(Attribute attr,
2275
2278
return ;
2276
2279
2277
2280
} else if (auto floatAttr = llvm::dyn_cast<FloatAttr>(attr)) {
2278
- printFloatValue (floatAttr.getValue (), os);
2281
+ bool printedHex = false ;
2282
+ printFloatValue (floatAttr.getValue (), os, &printedHex);
2279
2283
2280
2284
// FloatAttr elides the type if F64.
2281
- if (typeElision == AttrTypeElision::May && floatAttr.getType ().isF64 ())
2285
+ if (typeElision == AttrTypeElision::May && floatAttr.getType ().isF64 () &&
2286
+ !printedHex)
2282
2287
return ;
2283
2288
2284
2289
} else if (auto strAttr = llvm::dyn_cast<StringAttr>(attr)) {
0 commit comments