summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
authorGeorge Burgess IV <george.burgess.iv@gmail.com>2015-10-29 00:28:52 +0000
committerGeorge Burgess IV <george.burgess.iv@gmail.com>2015-10-29 00:28:52 +0000
commit148e0d3d5d8dcb673b27509a3c4673fe204e5daa (patch)
treece9e4e3ae21552a117c079c972a8535318364fad /clang/test
parent69c3387bcc99e2886e921f9eef51d0c08ccdb272 (diff)
downloadbcm5719-llvm-148e0d3d5d8dcb673b27509a3c4673fe204e5daa.tar.gz
bcm5719-llvm-148e0d3d5d8dcb673b27509a3c4673fe204e5daa.zip
[Sema] Implement -Wdouble-promotion for clang.
GCC has a warning called -Wdouble-promotion, which warns you when an implicit conversion increases the width of a floating point type. This is useful when writing code for architectures that can perform hardware FP ops on floats, but must fall back to software emulation for larger types (i.e. double, long double). This fixes PR15109 <https://llvm.org/bugs/show_bug.cgi?id=15109>. Thanks to Carl Norum for the patch! llvm-svn: 251588
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/Sema/warn-double-promotion.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/clang/test/Sema/warn-double-promotion.c b/clang/test/Sema/warn-double-promotion.c
new file mode 100644
index 00000000000..b6fd0c5ec62
--- /dev/null
+++ b/clang/test/Sema/warn-double-promotion.c
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -verify -fsyntax-only %s -Wdouble-promotion
+
+float ReturnFloatFromDouble(double d) {
+ return d;
+}
+
+float ReturnFloatFromLongDouble(long double ld) {
+ return ld;
+}
+
+double ReturnDoubleFromLongDouble(long double ld) {
+ return ld;
+}
+
+double ReturnDoubleFromFloat(float f) {
+ return f; //expected-warning{{implicit conversion increases floating-point precision: 'float' to 'double'}}
+}
+
+long double ReturnLongDoubleFromFloat(float f) {
+ return f; //expected-warning{{implicit conversion increases floating-point precision: 'float' to 'long double'}}
+}
+
+long double ReturnLongDoubleFromDouble(double d) {
+ return d; //expected-warning{{implicit conversion increases floating-point precision: 'double' to 'long double'}}
+}
+
+void Convert(float f, double d, long double ld) {
+ d = f; //expected-warning{{implicit conversion increases floating-point precision: 'float' to 'double'}}
+ ld = f; //expected-warning{{implicit conversion increases floating-point precision: 'float' to 'long double'}}
+ ld = d; //expected-warning{{implicit conversion increases floating-point precision: 'double' to 'long double'}}
+ f = d;
+ f = ld;
+ d = ld;
+}
OpenPOWER on IntegriCloud