r189625 - Adjust clang for change to APFloat::toString.
Eli Friedman
eli.friedman at gmail.com
Thu Aug 29 16:44:44 PDT 2013
Author: efriedma
Date: Thu Aug 29 18:44:43 2013
New Revision: 189625
URL: http://llvm.org/viewvc/llvm-project?rev=189625&view=rev
Log:
Adjust clang for change to APFloat::toString.
I changed the diagnostic printing code because it's probably better
to cut off a digit from DBL_MAX than to print something like
1.300000001 when the user wrote 1.3.
Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/PCH/floating-literal.c
cfe/trunk/test/PCH/objc_literals.m
cfe/trunk/test/Rewriter/objc-modern-boxing.mm
cfe/trunk/test/Rewriter/objc-modern-numeric-literal.mm
Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=189625&r1=189624&r2=189625&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Thu Aug 29 18:44:43 2013
@@ -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;
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=189625&r1=189624&r2=189625&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Thu Aug 29 18:44:43 2013
@@ -5058,8 +5058,16 @@ void DiagnoseFloatingLiteralImpCast(Sema
== 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";
Modified: cfe/trunk/test/PCH/floating-literal.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/floating-literal.c?rev=189625&r1=189624&r2=189625&view=diff
==============================================================================
--- cfe/trunk/test/PCH/floating-literal.c (original)
+++ cfe/trunk/test/PCH/floating-literal.c Thu Aug 29 18:44:43 2013
@@ -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;
Modified: cfe/trunk/test/PCH/objc_literals.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/objc_literals.m?rev=189625&r1=189624&r2=189625&view=diff
==============================================================================
--- cfe/trunk/test/PCH/objc_literals.m (original)
+++ cfe/trunk/test/PCH/objc_literals.m Thu Aug 29 18:44:43 2013
@@ -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" };
}
Modified: cfe/trunk/test/Rewriter/objc-modern-boxing.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/objc-modern-boxing.mm?rev=189625&r1=189624&r2=189625&view=diff
==============================================================================
--- cfe/trunk/test/Rewriter/objc-modern-boxing.mm (original)
+++ cfe/trunk/test/Rewriter/objc-modern-boxing.mm Thu Aug 29 18:44:43 2013
@@ -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")));
Modified: cfe/trunk/test/Rewriter/objc-modern-numeric-literal.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/objc-modern-numeric-literal.mm?rev=189625&r1=189624&r2=189625&view=diff
==============================================================================
--- cfe/trunk/test/Rewriter/objc-modern-numeric-literal.mm (original)
+++ cfe/trunk/test/Rewriter/objc-modern-numeric-literal.mm Thu Aug 29 18:44:43 2013
@@ -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);
More information about the cfe-commits
mailing list