From: Martin Sebor Date: Fri, 22 Feb 2019 16:24:36 +0000 (+0000) Subject: PR c/89425 - -Wabsolute-value warns in dead subexpressions X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=3c2a70cb1414b10ab3d52286087398cd03a70413;p=gcc.git PR c/89425 - -Wabsolute-value warns in dead subexpressions gcc/c/ChangeLog: PR c/89425 * c-parser.c (sizeof_ptr_memacc_comptypes): Avoid warning in unreachable subexpressions. gcc/testsuite/ChangeLog: PR c/89425 * gcc.dg/Wabsolute-value.c: New test. From-SVN: r269121 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 41deb1c4656..42ed0dca5b0 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2019-02-22 Martin Sebor + + PR c/89425 + * c-parser.c (sizeof_ptr_memacc_comptypes): Avoid warning in + unreachable subexpressions. + 2019-02-22 H.J. Lu Hongtao Liu Sunil K Pandey diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index 22c7416ac94..ee722cc9df9 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -9374,6 +9374,10 @@ sizeof_ptr_memacc_comptypes (tree type1, tree type2) static void warn_for_abs (location_t loc, tree fndecl, tree arg) { + /* Avoid warning in unreachable subexpressions. */ + if (c_inhibit_evaluation_warnings) + return; + tree atype = TREE_TYPE (arg); /* Casts from pointers (and thus arrays and fndecls) will generate diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index cb653e3652a..8c8f4a5e3fd 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2019-02-22 Martin Sebor + PR c/89425 + * gcc.dg/Wabsolute-value.c: New test. + * gcc.dg/Wbuiltin-declaration-mismatch-12.c: New test. 2019-02-22 H.J. Lu diff --git a/gcc/testsuite/gcc.dg/Wabsolute-value.c b/gcc/testsuite/gcc.dg/Wabsolute-value.c new file mode 100644 index 00000000000..e3717f9b948 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wabsolute-value.c @@ -0,0 +1,57 @@ +/* PR c/89425 - -Wabsolute-value warns in dead subexpressions + { dg-do compile } + { dg-options "-Wabsolute-value -ftrack-macro-expansion=0" } */ + +struct Vals +{ + signed char sc; + signed short ss; + signed int si; + signed long sl; + signed long long sll; + + unsigned char uc; + unsigned short us; + unsigned int ui; + unsigned long ul; + unsigned long long ull; + + float f; + double d; + long double ld; +}; + +#define abs(x) __builtin_abs (x) +#define labs(x) __builtin_labs (x) +#define llabs(x) __builtin_llabs (x) + +#define fabsf(x) __builtin_fabsf (x) +#define fabs(x) __builtin_fabs (x) + + +void tst_warn (struct Vals *p) +{ + /* Verify that "-Wabsolute-value is issued for subexpressions + that are evaluated. */ + + p->uc = 0 ? abs (p->sc) : abs (p->uc); /* { dg-warning "\\\[-Wabsolute-value]" } */ + p->us = 0 ? abs (p->ss) : abs (p->us); /* { dg-warning "\\\[-Wabsolute-value]" } */ + p->ui = 0 ? abs (p->si) : abs (p->ui); /* { dg-warning "\\\[-Wabsolute-value]" } */ + p->ul = 0 ? labs (p->sl) : labs (p->ul); /* { dg-warning "\\\[-Wabsolute-value]" } */ + p->ull = 0 ? llabs (p->sll) : llabs (p->ull); /* { dg-warning "\\\[-Wabsolute-value]" } */ + + p->d = 0 ? fabs (p->d) : fabsf (p->d); /* { dg-warning "\\\[-Wabsolute-value]" } */ +} + +void tst_no_warn (struct Vals *p) +{ + /* Verify that "-Wabsolute-value is not issued for subexpressions + that are not evaluated. */ + + p->uc = 0 ? abs (p->uc) : abs (p->sc); + p->us = 0 ? abs (p->us) : abs (p->ss); + p->ui = 0 ? abs (p->ui) : abs (p->si); + p->ul = 0 ? labs (p->ul) : labs (p->sl); + p->ull = 0 ? llabs (p->ull) : llabs (p->sll); + p->d = 0 ? fabsf (p->d) : fabs (p->d); +}