summaryrefslogtreecommitdiff
path: root/test/Sema/unary-minus-integer-impcast.c
diff options
context:
space:
mode:
authorDavid Bolvansky <david.bolvansky@gmail.com>2018-10-02 06:02:30 +0000
committerDavid Bolvansky <david.bolvansky@gmail.com>2018-10-02 06:02:30 +0000
commit92e9c12e91148506062d9cad9dc81d308e8f96f9 (patch)
tree530a3c1c07c9a3dca8b3670efdc949f0be9e6ca0 /test/Sema/unary-minus-integer-impcast.c
parentc8e27aaeeeeac7172dafaab0e7829ba20d33855f (diff)
downloadclang-92e9c12e91148506062d9cad9dc81d308e8f96f9.tar.gz
Added warning for unary minus used with unsigned type
Summary: Inspired by MSVC, which found some occurrences of this expression on our code base. Fixes PR38950 Reviewers: rsmith, craig.topper, spatel, RKSimon, aaron.ballman, thakis Reviewed By: rsmith Subscribers: joerg, Quuxplusone, lebedev.ri, craig.topper, RKSimon, cfe-commits Differential Revision: https://reviews.llvm.org/D52137 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@343560 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Sema/unary-minus-integer-impcast.c')
-rw-r--r--test/Sema/unary-minus-integer-impcast.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/test/Sema/unary-minus-integer-impcast.c b/test/Sema/unary-minus-integer-impcast.c
new file mode 100644
index 0000000000..0eb4401758
--- /dev/null
+++ b/test/Sema/unary-minus-integer-impcast.c
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 %s -verify -Wconversion -fsyntax-only -triple x86_64-pc-linux-gnu
+// RUN: %clang_cc1 %s -verify -Wconversion -fsyntax-only -triple i386-pc-linux-gnu
+
+void test(void) {
+ unsigned int a = 1;
+
+ unsigned long long b = -a; // expected-warning {{higher order bits are zeroes after implicit conversion}}
+ long long c = -a; // expected-warning {{the resulting value is always non-negative after implicit conversion}}
+
+ unsigned long b2 = -a;
+#ifdef __x86_64__
+// expected-warning@-2 {{higher order bits are zeroes after implicit conversion}}
+#endif
+ long c2 = -a;
+#ifdef __x86_64__
+// expected-warning@-2 {{the resulting value is always non-negative after implicit conversion}}
+#else
+// expected-warning@-4 {{implicit conversion changes signedness: 'unsigned int' to 'long'}}
+#endif
+}