Dump floating-point values as strings when dumping to JSON.

This fixes a bug where we would have an invalid JSON attribute (e.g., "value": inf). It also increases the precision of the values because they're not represented as approximate doubles with the host architecture's floating-point model.

llvm-svn: 365900
This commit is contained in:
Aaron Ballman 2019-07-12 13:57:41 +00:00
parent de54e2c4df
commit 4d08f899e3
3 changed files with 5086 additions and 5063 deletions

View File

@ -1349,7 +1349,9 @@ void JSONNodeDumper::VisitFixedPointLiteral(const FixedPointLiteral *FPL) {
JOS.attribute("value", FPL->getValueAsString(/*Radix=*/10));
}
void JSONNodeDumper::VisitFloatingLiteral(const FloatingLiteral *FL) {
JOS.attribute("value", FL->getValueAsApproximateDouble());
llvm::SmallVector<char, 16> Buffer;
FL->getValue().toString(Buffer);
JOS.attribute("value", Buffer);
}
void JSONNodeDumper::VisitStringLiteral(const StringLiteral *SL) {
std::string Buffer;

File diff suppressed because it is too large Load Diff

View File

@ -226,7 +226,7 @@ void MaterializeTemp() {
// CHECK-NEXT: "qualType": "double"
// CHECK-NEXT: },
// CHECK-NEXT: "valueCategory": "rvalue",
// CHECK-NEXT: "value": 1
// CHECK-NEXT: "value": "1"
// CHECK-NEXT: }
// CHECK-NEXT: ]
// CHECK-NEXT: }