diff options
-rw-r--r-- | clang/lib/AST/ExprConstant.cpp | 11 | ||||
-rw-r--r-- | clang/lib/Sema/SemaChecking.cpp | 10 | ||||
-rw-r--r-- | clang/test/PCH/floating-literal.c | 4 | ||||
-rw-r--r-- | clang/test/PCH/objc_literals.m | 6 | ||||
-rw-r--r-- | clang/test/Rewriter/objc-modern-boxing.mm | 4 | ||||
-rw-r--r-- | clang/test/Rewriter/objc-modern-numeric-literal.mm | 4 |
6 files changed, 28 insertions, 11 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 15c4a21..b660214 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -367,8 +367,17 @@ namespace { OptionalDiagnostic &operator<<(const APFloat &F) { if (Diag) { + // FIXME: Force the precision of the source value down so we don't + // print digits which are usually useless (we don't really care here if + // we truncate a digit by accident in edge cases). Ideally, + // APFloat::toString would automatically print the shortest + // representation which rounds to the correct value, but it's a bit + // tricky to implement. + unsigned precision = + llvm::APFloat::semanticsPrecision(F.getSemantics()); + precision = (precision * 59 + 195) / 196; SmallVector<char, 32> Buffer; - F.toString(Buffer); + F.toString(Buffer, precision); *Diag << StringRef(Buffer.data(), Buffer.size()); } return *this; diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 7978292..499c21c 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -5058,8 +5058,16 @@ void DiagnoseFloatingLiteralImpCast(Sema &S, FloatingLiteral *FL, QualType T, == llvm::APFloat::opOK && isExact) return; + // FIXME: Force the precision of the source value down so we don't print + // digits which are usually useless (we don't really care here if we + // truncate a digit by accident in edge cases). Ideally, APFloat::toString + // would automatically print the shortest representation, but it's a bit + // tricky to implement. SmallString<16> PrettySourceValue; - Value.toString(PrettySourceValue); + unsigned precision = llvm::APFloat::semanticsPrecision(Value.getSemantics()); + precision = (precision * 59 + 195) / 196; + Value.toString(PrettySourceValue, precision); + SmallString<16> PrettyTargetValue; if (T->isSpecificBuiltinType(BuiltinType::Bool)) PrettyTargetValue = IntegerValue == 0 ? "false" : "true"; diff --git a/clang/test/PCH/floating-literal.c b/clang/test/PCH/floating-literal.c index 7bf10d4..738e45a 100644 --- a/clang/test/PCH/floating-literal.c +++ b/clang/test/PCH/floating-literal.c @@ -7,12 +7,12 @@ // targets with 128-bit IEEE long doubles. long double foo = 1.0E4000L; -// CHECK: long double foo = 1.0E+4000L; +// CHECK: long double foo = 1.00000000000000000000000000000000004E+4000L; // Just as well check the others are still sane while we're here... double bar = 1.0E300; -// CHECK: double bar = 1.0E+300; +// CHECK: double bar = 1.0000000000000001E+300; float wibble = 1.0E40; // CHECK: float wibble = 1.0E+40; diff --git a/clang/test/PCH/objc_literals.m b/clang/test/PCH/objc_literals.m index 3a6ec89..f96d4af 100644 --- a/clang/test/PCH/objc_literals.m +++ b/clang/test/PCH/objc_literals.m @@ -44,18 +44,18 @@ static inline void test_numeric_literals() { // CHECK-PRINT: id intlit = @17 // CHECK-IR: {{call.*17}} id intlit = @17; - // CHECK-PRINT: id floatlit = @17.45 + // CHECK-PRINT: id floatlit = @17.449999999999999 // CHECK-IR: {{call.*1.745}} id floatlit = @17.45; } static inline void test_array_literals() { - // CHECK-PRINT: id arraylit = @[ @17, @17.45 + // CHECK-PRINT: id arraylit = @[ @17, @17.449999999999999 id arraylit = @[@17, @17.45]; } static inline void test_dictionary_literals() { - // CHECK-PRINT: id dictlit = @{ @17 : {{@17.45[^,]*}}, @"hello" : @"world" }; + // CHECK-PRINT: id dictlit = @{ @17 : {{@17.449999999999999[^,]*}}, @"hello" : @"world" }; id dictlit = @{@17 : @17.45, @"hello" : @"world" }; } diff --git a/clang/test/Rewriter/objc-modern-boxing.mm b/clang/test/Rewriter/objc-modern-boxing.mm index 4997c24..40eeafb 100644 --- a/clang/test/Rewriter/objc-modern-boxing.mm +++ b/clang/test/Rewriter/objc-modern-boxing.mm @@ -66,7 +66,7 @@ int main(int argc, const char *argv[]) { // CHECK: NSNumber *fortyTwoUnsigned = ((NSNumber *(*)(id, SEL, unsigned int))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithUnsignedInt:"), (42U)); // CHECK: NSNumber *fortyTwoLong = ((NSNumber *(*)(id, SEL, long))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithLong:"), (42L)); // CHECK: NSNumber *fortyTwoLongLong = ((NSNumber *(*)(id, SEL, long long))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithLongLong:"), (42LL)); -// CHECK: NSNumber *piFloat = ((NSNumber *(*)(id, SEL, float))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithFloat:"), (3.1415927F)); -// CHECK: NSNumber *piDouble = ((NSNumber *(*)(id, SEL, double))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithDouble:"), (3.1415926535)); +// CHECK: NSNumber *piFloat = ((NSNumber *(*)(id, SEL, float))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithFloat:"), (3.14159274F)); +// CHECK: NSNumber *piDouble = ((NSNumber *(*)(id, SEL, double))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithDouble:"), (3.1415926535000001)); // CHECK: NSNumber *nsb = ((NSNumber *(*)(id, SEL, BOOL))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithBool:"), (BOOL)(b)); // CHECK: NSString *duplicateString = ((NSString *(*)(id, SEL, const char *))(void *)objc_msgSend)(objc_getClass("NSString"), sel_registerName("stringWithUTF8String:"), (const char *)(strdup("Hello"))); diff --git a/clang/test/Rewriter/objc-modern-numeric-literal.mm b/clang/test/Rewriter/objc-modern-numeric-literal.mm index 5f63d8c..57f7ca2 100644 --- a/clang/test/Rewriter/objc-modern-numeric-literal.mm +++ b/clang/test/Rewriter/objc-modern-numeric-literal.mm @@ -61,8 +61,8 @@ int main(int argc, const char *argv[]) { // CHECK: NSNumber *fortyTwoUnsigned = ((NSNumber *(*)(id, SEL, unsigned int))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithUnsignedInt:"), 42U); // CHECK: NSNumber *fortyTwoLong = ((NSNumber *(*)(id, SEL, long))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithLong:"), 42L); // CHECK: NSNumber *fortyTwoLongLong = ((NSNumber *(*)(id, SEL, long long))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithLongLong:"), 42LL); -// CHECK: NSNumber *piFloat = ((NSNumber *(*)(id, SEL, float))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithFloat:"), 3.1415927F); -// CHECK: NSNumber *piDouble = ((NSNumber *(*)(id, SEL, double))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithDouble:"), 3.1415926535); +// CHECK: NSNumber *piFloat = ((NSNumber *(*)(id, SEL, float))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithFloat:"), 3.14159274F); +// CHECK: NSNumber *piDouble = ((NSNumber *(*)(id, SEL, double))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithDouble:"), 3.1415926535000001); // CHECK: NSNumber *yesNumber = ((NSNumber *(*)(id, SEL, BOOL))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithBool:"), true); // CHECK: NSNumber *noNumber = ((NSNumber *(*)(id, SEL, BOOL))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithBool:"), false); // CHECK: NSNumber *trueNumber = ((NSNumber *(*)(id, SEL, BOOL))(void *)objc_msgSend)(objc_getClass("NSNumber"), sel_registerName("numberWithBool:"), true); |