aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2017-08-09 08:51:20 +0000
committerMarek Polacek <mpolacek@gcc.gnu.org>2017-08-09 08:51:20 +0000
commita32c8316ff282ec3eb60e222e91fb19998c12f46 (patch)
tree5c9606b760b22332192173cec1c9c8ba76d9dcb4 /gcc/testsuite/gcc.dg
parentbc47a525cbd41692135f24607a52bd42e93400cb (diff)
downloadgcc-a32c8316ff282ec3eb60e222e91fb19998c12f46.zip
gcc-a32c8316ff282ec3eb60e222e91fb19998c12f46.tar.gz
gcc-a32c8316ff282ec3eb60e222e91fb19998c12f46.tar.bz2
re PR c/81417 (-Wsign-compare should print types being compared)
PR c/81417 * c-array-notation.c (fix_builtin_array_notation_fn): Update calls to build_conditional_expr. * c-parser.c (c_parser_conditional_expression): Create locations for EXP1 and EXP2 from their source ranges. Pass the locations down to build_conditional_expr. * c-tree.h (build_conditional_expr): Update declaration. * c-typeck.c (build_conditional_expr): Add location_t parameters. For -Wsign-compare, also print the types. * input.c (make_location): New overload. * input.h (make_location): Declare. * objc-next-runtime-abi-02.c (build_v2_build_objc_method_call): Update a call to build_conditional_expr. * Wsign-compare-1.c: New test. * gcc.dg/compare1.c: Adjust dg-bogus. * gcc.dg/compare2.c: Likewise. * gcc.dg/compare3.c: Likewise. * gcc.dg/compare7.c: Likewise. * gcc.dg/compare8.c: Likewise. * gcc.dg/compare9.c: Likewise. * gcc.dg/pr11492.c: Likewise. From-SVN: r250984
Diffstat (limited to 'gcc/testsuite/gcc.dg')
-rw-r--r--gcc/testsuite/gcc.dg/Wsign-compare-1.c83
-rw-r--r--gcc/testsuite/gcc.dg/compare1.c6
-rw-r--r--gcc/testsuite/gcc.dg/compare2.c24
-rw-r--r--gcc/testsuite/gcc.dg/compare3.c88
-rw-r--r--gcc/testsuite/gcc.dg/compare7.c2
-rw-r--r--gcc/testsuite/gcc.dg/compare8.c6
-rw-r--r--gcc/testsuite/gcc.dg/compare9.c8
-rw-r--r--gcc/testsuite/gcc.dg/pr11492.c2
8 files changed, 151 insertions, 68 deletions
diff --git a/gcc/testsuite/gcc.dg/Wsign-compare-1.c b/gcc/testsuite/gcc.dg/Wsign-compare-1.c
new file mode 100644
index 0000000..be3bd2f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wsign-compare-1.c
@@ -0,0 +1,83 @@
+/* PR c/81417 */
+/* { dg-do compile } */
+/* { dg-options "-Wsign-compare -fdiagnostics-show-caret" } */
+
+unsigned int
+f0 (int x, unsigned int y)
+{
+ return x ? y : -1; /* { dg-warning "18:operand of \\?: changes signedness from 'int' to 'unsigned int'" } */
+/* { dg-begin-multiline-output "" }
+ return x ? y : -1;
+ ^~
+ { dg-end-multiline-output "" } */
+}
+
+unsigned int
+f1 (int xxx, unsigned int yyy)
+{
+ return xxx ? yyy : -1; /* { dg-warning "22:operand of \\?: changes signedness from 'int' to 'unsigned int'" } */
+/* { dg-begin-multiline-output "" }
+ return xxx ? yyy : -1;
+ ^~
+ { dg-end-multiline-output "" } */
+}
+
+unsigned int
+f2 (int xxx, unsigned int yyy)
+{
+ return xxx ? -1 : yyy; /* { dg-warning "16:operand of \\?: changes signedness from 'int' to 'unsigned int'" } */
+/* { dg-begin-multiline-output "" }
+ return xxx ? -1 : yyy;
+ ^~
+ { dg-end-multiline-output "" } */
+}
+
+unsigned int
+f3 (unsigned int yyy)
+{
+ return yyy ?: -1; /* { dg-warning "17:operand of \\?: changes signedness from 'int' to 'unsigned int'" } */
+/* { dg-begin-multiline-output "" }
+ return yyy ?: -1;
+ ^~
+ { dg-end-multiline-output "" } */
+}
+
+unsigned int
+f4 (int xxx, unsigned yyy, short uuu)
+{
+ return xxx ? yyy : uuu; /* { dg-warning "22:operand of \\?: changes signedness from 'short int' to 'unsigned int'" } */
+/* { dg-begin-multiline-output "" }
+ return xxx ? yyy : uuu;
+ ^~~
+ { dg-end-multiline-output "" } */
+}
+
+unsigned int
+f5 (int xxx, unsigned yyy, short uuu)
+{
+ return xxx ? uuu : yyy; /* { dg-warning "16:operand of \\?: changes signedness from 'short int' to 'unsigned int'" } */
+/* { dg-begin-multiline-output "" }
+ return xxx ? uuu : yyy;
+ ^~~
+ { dg-end-multiline-output "" } */
+}
+
+unsigned int
+f6 (int xxx, unsigned yyy, signed char uuu)
+{
+ return xxx ? yyy : uuu; /* { dg-warning "22:operand of \\?: changes signedness from 'signed char' to 'unsigned int'" } */
+/* { dg-begin-multiline-output "" }
+ return xxx ? yyy : uuu;
+ ^~~
+ { dg-end-multiline-output "" } */
+}
+
+unsigned int
+f7 (int xxx, unsigned yyy, signed char uuu)
+{
+ return xxx ? uuu : yyy; /* { dg-warning "16:operand of \\?: changes signedness from 'signed char' to 'unsigned int'" } */
+/* { dg-begin-multiline-output "" }
+ return xxx ? uuu : yyy;
+ ^~~
+ { dg-end-multiline-output "" } */
+}
diff --git a/gcc/testsuite/gcc.dg/compare1.c b/gcc/testsuite/gcc.dg/compare1.c
index 7becfbdb..ebab8c2 100644
--- a/gcc/testsuite/gcc.dg/compare1.c
+++ b/gcc/testsuite/gcc.dg/compare1.c
@@ -22,17 +22,17 @@ enum mm2
int f(enum mm1 x)
{
- return x == (tf?DI:SI); /* { dg-bogus "signed and unsigned" "case 1" } */
+ return x == (tf?DI:SI); /* { dg-bogus "changes signedness" "case 1" } */
}
int g(enum mm1 x)
{
- return x == (tf?DI:-1); /* { dg-bogus "signed and unsigned" "case 2" } */
+ return x == (tf?DI:-1); /* { dg-bogus "changes signedness" "case 2" } */
}
int h(enum mm2 x)
{
- return x == (tf?DI2:SI2); /* { dg-bogus "signed and unsigned" "case 3" } */
+ return x == (tf?DI2:SI2); /* { dg-bogus "changes signedness" "case 3" } */
}
int i(enum mm2 x)
diff --git a/gcc/testsuite/gcc.dg/compare2.c b/gcc/testsuite/gcc.dg/compare2.c
index c309f1d..cfadacc 100644
--- a/gcc/testsuite/gcc.dg/compare2.c
+++ b/gcc/testsuite/gcc.dg/compare2.c
@@ -9,35 +9,35 @@ int tf = 1;
void f(int x, unsigned int y)
{
/* ?: branches are constants. */
- x > (tf?64:128); /* { dg-bogus "signed and unsigned" "case 1" } */
- y > (tf?64:128); /* { dg-bogus "signed and unsigned" "case 2" } */
+ x > (tf?64:128); /* { dg-bogus "changes signedness" "case 1" } */
+ y > (tf?64:128); /* { dg-bogus "changes signedness" "case 2" } */
/* ?: branches are (recursively) constants. */
- x > (tf?64:(tf?128:256)); /* { dg-bogus "signed and unsigned" "case 3" } */
- y > (tf?64:(tf?128:256)); /* { dg-bogus "signed and unsigned" "case 4" } */
+ x > (tf?64:(tf?128:256)); /* { dg-bogus "changes signedness" "case 3" } */
+ y > (tf?64:(tf?128:256)); /* { dg-bogus "changes signedness" "case 4" } */
/* ?: branches are signed constants. */
- x > (tf?64:-1); /* { dg-bogus "signed and unsigned" "case 5" } */
+ x > (tf?64:-1); /* { dg-bogus "changes signedness" "case 5" } */
y > (tf?64:-1); /* { dg-warning "different signedness" "case 6" } */
/* ?: branches are (recursively) signed constants. */
- x > (tf?64:(tf?128:-1)); /* { dg-bogus "signed and unsigned" "case 7" } */
+ x > (tf?64:(tf?128:-1)); /* { dg-bogus "changes signedness" "case 7" } */
y > (tf?64:(tf?128:-1)); /* { dg-warning "different signedness" "case 8" } */
/* Statement expression. */
- x > ({tf; 64;}); /* { dg-bogus "signed and unsigned" "case 9" } */
- y > ({tf; 64;}); /* { dg-bogus "signed and unsigned" "case 10" } */
+ x > ({tf; 64;}); /* { dg-bogus "changes signedness" "case 9" } */
+ y > ({tf; 64;}); /* { dg-bogus "changes signedness" "case 10" } */
/* Statement expression with recursive ?: . */
- x > ({tf; tf?64:(tf?128:256);}); /* { dg-bogus "signed and unsigned" "case 11" } */
- y > ({tf; tf?64:(tf?128:256);}); /* { dg-bogus "signed and unsigned" "case 12" } */
+ x > ({tf; tf?64:(tf?128:256);}); /* { dg-bogus "changes signedness" "case 11" } */
+ y > ({tf; tf?64:(tf?128:256);}); /* { dg-bogus "changes signedness" "case 12" } */
/* Statement expression with signed ?:. */
- x > ({tf; tf?64:-1;}); /* { dg-bogus "signed and unsigned" "case 13" } */
+ x > ({tf; tf?64:-1;}); /* { dg-bogus "changes signedness" "case 13" } */
y > ({tf; tf?64:-1;}); /* { dg-warning "different signedness" "case 14" } */
/* Statement expression with recursive signed ?:. */
- x > ({tf; tf?64:(tf?128:-1);}); /* { dg-bogus "signed and unsigned" "case 15" } */
+ x > ({tf; tf?64:(tf?128:-1);}); /* { dg-bogus "changes signedness" "case 15" } */
y > ({tf; tf?64:(tf?128:-1);}); /* { dg-warning "different signedness" "case 16" } */
/* ?: branches are constants. */
diff --git a/gcc/testsuite/gcc.dg/compare3.c b/gcc/testsuite/gcc.dg/compare3.c
index eda3faf..836231f 100644
--- a/gcc/testsuite/gcc.dg/compare3.c
+++ b/gcc/testsuite/gcc.dg/compare3.c
@@ -11,49 +11,49 @@ void f(int x, unsigned int y)
/* Test comparing conditional expressions containing truth values.
This can occur explicitly, or e.g. when (foo?2:(bar?1:0)) is
optimized into (foo?2:(bar!=0)). */
- x > (tf?64:(tf!=x)); /* { dg-bogus "signed and unsigned" "case 1" } */
- y > (tf?64:(tf!=x)); /* { dg-bogus "signed and unsigned" "case 2" } */
- x > (tf?(tf!=x):64); /* { dg-bogus "signed and unsigned" "case 3" } */
- y > (tf?(tf!=x):64); /* { dg-bogus "signed and unsigned" "case 4" } */
-
- x > (tf?64:(tf==x)); /* { dg-bogus "signed and unsigned" "case 5" } */
- y > (tf?64:(tf==x)); /* { dg-bogus "signed and unsigned" "case 6" } */
- x > (tf?(tf==x):64); /* { dg-bogus "signed and unsigned" "case 7" } */
- y > (tf?(tf==x):64); /* { dg-bogus "signed and unsigned" "case 8" } */
-
- x > (tf?64:(tf>x)); /* { dg-bogus "signed and unsigned" "case 9" } */
- y > (tf?64:(tf>x)); /* { dg-bogus "signed and unsigned" "case 10" } */
- x > (tf?(tf>x):64); /* { dg-bogus "signed and unsigned" "case 11" } */
- y > (tf?(tf>x):64); /* { dg-bogus "signed and unsigned" "case 12" } */
-
- x < (tf?64:(tf<x)); /* { dg-bogus "signed and unsigned" "case 13" } */
- y < (tf?64:(tf<x)); /* { dg-bogus "signed and unsigned" "case 14" } */
- x < (tf?(tf<x):64); /* { dg-bogus "signed and unsigned" "case 15" } */
- y < (tf?(tf<x):64); /* { dg-bogus "signed and unsigned" "case 16" } */
-
- x > (tf?64:(tf>=x)); /* { dg-bogus "signed and unsigned" "case 17" } */
- y > (tf?64:(tf>=x)); /* { dg-bogus "signed and unsigned" "case 18" } */
- x > (tf?(tf>=x):64); /* { dg-bogus "signed and unsigned" "case 19" } */
- y > (tf?(tf>=x):64); /* { dg-bogus "signed and unsigned" "case 20" } */
-
- x > (tf?64:(tf<=x)); /* { dg-bogus "signed and unsigned" "case 21" } */
- y > (tf?64:(tf<=x)); /* { dg-bogus "signed and unsigned" "case 22" } */
- x > (tf?(tf<=x):64); /* { dg-bogus "signed and unsigned" "case 23" } */
- y > (tf?(tf<=x):64); /* { dg-bogus "signed and unsigned" "case 24" } */
-
- x > (tf?64:(tf&&x)); /* { dg-bogus "signed and unsigned" "case 25" } */
- y > (tf?64:(tf&&x)); /* { dg-bogus "signed and unsigned" "case 26" } */
- x > (tf?(tf&&x):64); /* { dg-bogus "signed and unsigned" "case 27" } */
- y > (tf?(tf&&x):64); /* { dg-bogus "signed and unsigned" "case 28" } */
-
- x > (tf?64:(tf||x)); /* { dg-bogus "signed and unsigned" "case 29" } */
- y > (tf?64:(tf||x)); /* { dg-bogus "signed and unsigned" "case 30" } */
- x > (tf?(tf||x):64); /* { dg-bogus "signed and unsigned" "case 31" } */
- y > (tf?(tf||x):64); /* { dg-bogus "signed and unsigned" "case 32" } */
-
- x > (tf?64:(!tf)); /* { dg-bogus "signed and unsigned" "case 33" } */
- y > (tf?64:(!tf)); /* { dg-bogus "signed and unsigned" "case 34" } */
- x > (tf?(!tf):64); /* { dg-bogus "signed and unsigned" "case 35" } */
- y > (tf?(!tf):64); /* { dg-bogus "signed and unsigned" "case 36" } */
+ x > (tf?64:(tf!=x)); /* { dg-bogus "changes signedness" "case 1" } */
+ y > (tf?64:(tf!=x)); /* { dg-bogus "changes signedness" "case 2" } */
+ x > (tf?(tf!=x):64); /* { dg-bogus "changes signedness" "case 3" } */
+ y > (tf?(tf!=x):64); /* { dg-bogus "changes signedness" "case 4" } */
+
+ x > (tf?64:(tf==x)); /* { dg-bogus "changes signedness" "case 5" } */
+ y > (tf?64:(tf==x)); /* { dg-bogus "changes signedness" "case 6" } */
+ x > (tf?(tf==x):64); /* { dg-bogus "changes signedness" "case 7" } */
+ y > (tf?(tf==x):64); /* { dg-bogus "changes signedness" "case 8" } */
+
+ x > (tf?64:(tf>x)); /* { dg-bogus "changes signedness" "case 9" } */
+ y > (tf?64:(tf>x)); /* { dg-bogus "changes signedness" "case 10" } */
+ x > (tf?(tf>x):64); /* { dg-bogus "changes signedness" "case 11" } */
+ y > (tf?(tf>x):64); /* { dg-bogus "changes signedness" "case 12" } */
+
+ x < (tf?64:(tf<x)); /* { dg-bogus "changes signedness" "case 13" } */
+ y < (tf?64:(tf<x)); /* { dg-bogus "changes signedness" "case 14" } */
+ x < (tf?(tf<x):64); /* { dg-bogus "changes signedness" "case 15" } */
+ y < (tf?(tf<x):64); /* { dg-bogus "changes signedness" "case 16" } */
+
+ x > (tf?64:(tf>=x)); /* { dg-bogus "changes signedness" "case 17" } */
+ y > (tf?64:(tf>=x)); /* { dg-bogus "changes signedness" "case 18" } */
+ x > (tf?(tf>=x):64); /* { dg-bogus "changes signedness" "case 19" } */
+ y > (tf?(tf>=x):64); /* { dg-bogus "changes signedness" "case 20" } */
+
+ x > (tf?64:(tf<=x)); /* { dg-bogus "changes signedness" "case 21" } */
+ y > (tf?64:(tf<=x)); /* { dg-bogus "changes signedness" "case 22" } */
+ x > (tf?(tf<=x):64); /* { dg-bogus "changes signedness" "case 23" } */
+ y > (tf?(tf<=x):64); /* { dg-bogus "changes signedness" "case 24" } */
+
+ x > (tf?64:(tf&&x)); /* { dg-bogus "changes signedness" "case 25" } */
+ y > (tf?64:(tf&&x)); /* { dg-bogus "changes signedness" "case 26" } */
+ x > (tf?(tf&&x):64); /* { dg-bogus "changes signedness" "case 27" } */
+ y > (tf?(tf&&x):64); /* { dg-bogus "changes signedness" "case 28" } */
+
+ x > (tf?64:(tf||x)); /* { dg-bogus "changes signedness" "case 29" } */
+ y > (tf?64:(tf||x)); /* { dg-bogus "changes signedness" "case 30" } */
+ x > (tf?(tf||x):64); /* { dg-bogus "changes signedness" "case 31" } */
+ y > (tf?(tf||x):64); /* { dg-bogus "changes signedness" "case 32" } */
+
+ x > (tf?64:(!tf)); /* { dg-bogus "changes signedness" "case 33" } */
+ y > (tf?64:(!tf)); /* { dg-bogus "changes signedness" "case 34" } */
+ x > (tf?(!tf):64); /* { dg-bogus "changes signedness" "case 35" } */
+ y > (tf?(!tf):64); /* { dg-bogus "changes signedness" "case 36" } */
}
diff --git a/gcc/testsuite/gcc.dg/compare7.c b/gcc/testsuite/gcc.dg/compare7.c
index e2fbc04..b6fe6e7 100644
--- a/gcc/testsuite/gcc.dg/compare7.c
+++ b/gcc/testsuite/gcc.dg/compare7.c
@@ -6,5 +6,5 @@
int f(unsigned a, int b)
{
- return a < b; /* { dg-bogus "signed and unsigned" } */
+ return a < b; /* { dg-bogus "changes signedness" } */
}
diff --git a/gcc/testsuite/gcc.dg/compare8.c b/gcc/testsuite/gcc.dg/compare8.c
index d723c45..d09b69c 100644
--- a/gcc/testsuite/gcc.dg/compare8.c
+++ b/gcc/testsuite/gcc.dg/compare8.c
@@ -4,18 +4,18 @@
int
f(unsigned short a1, unsigned short a2, unsigned int b)
{
- return ((a1+a2)|5) > b ? 2 : 3; /* { dg-bogus "signed and unsigned" } */
+ return ((a1+a2)|5) > b ? 2 : 3; /* { dg-bogus "changes signedness" } */
}
int
g(unsigned short a1, unsigned short a2, unsigned int b)
{
- return ((a1+a2)&5) > b ? 2 : 3; /* { dg-bogus "signed and unsigned" } */
+ return ((a1+a2)&5) > b ? 2 : 3; /* { dg-bogus "changes signedness" } */
}
int
h(unsigned short a1, unsigned short a2, unsigned int b)
{
- return ((a1+a2)^5) > b ? 2 : 3; /* { dg-bogus "signed and unsigned" } */
+ return ((a1+a2)^5) > b ? 2 : 3; /* { dg-bogus "changes signedness" } */
}
diff --git a/gcc/testsuite/gcc.dg/compare9.c b/gcc/testsuite/gcc.dg/compare9.c
index 02150cb..fba61e4 100644
--- a/gcc/testsuite/gcc.dg/compare9.c
+++ b/gcc/testsuite/gcc.dg/compare9.c
@@ -22,20 +22,20 @@ enum mm2
int f(enum mm1 x)
{
- return x == (tf?DI:SI); /* { dg-bogus "signed and unsigned" "case 1" } */
+ return x == (tf?DI:SI); /* { dg-bogus "changes signedness" "case 1" } */
}
int g(enum mm1 x)
{
- return x == (tf?DI:-1); /* { dg-bogus "signed and unsigned" "case 2" } */
+ return x == (tf?DI:-1); /* { dg-bogus "changes signedness" "case 2" } */
}
int h(enum mm2 x)
{
- return x == (tf?DI2:SI2); /* { dg-bogus "signed and unsigned" "case 3" } */
+ return x == (tf?DI2:SI2); /* { dg-bogus "changes signedness" "case 3" } */
}
int i(enum mm2 x)
{
- return x == (tf?DI2:-1); /* { dg-bogus "signed and unsigned" "case 4" } */
+ return x == (tf?DI2:-1); /* { dg-bogus "changes signedness" "case 4" } */
}
diff --git a/gcc/testsuite/gcc.dg/pr11492.c b/gcc/testsuite/gcc.dg/pr11492.c
index cf17712..86435a8 100644
--- a/gcc/testsuite/gcc.dg/pr11492.c
+++ b/gcc/testsuite/gcc.dg/pr11492.c
@@ -5,7 +5,7 @@ int main( void )
{
unsigned int a;
unsigned char b;
- for ( a = 0, b = 2; a > b * 100; a++ ) /* { dg-bogus "comparison between signed and unsigned integer" } */
+ for ( a = 0, b = 2; a > b * 100; a++ ) /* { dg-bogus "comparison of integer expressions of different signedness" } */
{ ; }
return 0;