From: Martin Jambor <mjambor@suse.cz>
To: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: [PR 87347] Prevent segfaults if TYPE_ARG_TYPES is NULL
Date: Mon, 24 Sep 2018 18:46:00 -0000 [thread overview]
Message-ID: <ri6worahh82.fsf@suse.cz> (raw)
Hi,
the warning for suspicious calls of abs-like functions segfaults if a
user declared their own parameter-less-ish variant of abs like in the
testcase below. Fixed by looking whether there is any TYPE_ARG_TYPES
before trying to compare the actual argument with it.
Bootstrapped and tested on x86_64-linux and aarch64-linux, the same on
i686-linux is pending.
OK for trunk?
Thanks,
Martin
2018-09-24 Martin Jambor <mjambor@suse.cz>
PR c/87347
c/
* c-parser.c (warn_for_abs): Bail out if TYPE_ARG_TYPES is NULL.
testsuite/
* gcc.dg/pr87347.c: New test.
---
gcc/c/c-parser.c | 7 ++++---
gcc/testsuite/gcc.dg/pr87347.c | 6 ++++++
2 files changed, 10 insertions(+), 3 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/pr87347.c
diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index 1766a256633..a96d15fef1d 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -9116,9 +9116,10 @@ warn_for_abs (location_t loc, tree fndecl, tree arg)
-Wint-conversion warnings. Most other wrong types hopefully lead to type
mismatch errors. TODO: Think about what to do with FIXED_POINT_TYPE_P
types and possibly other exotic types. */
- if (!INTEGRAL_TYPE_P (atype)
- && !SCALAR_FLOAT_TYPE_P (atype)
- && TREE_CODE (atype) != COMPLEX_TYPE)
+ if ((!INTEGRAL_TYPE_P (atype)
+ && !SCALAR_FLOAT_TYPE_P (atype)
+ && TREE_CODE (atype) != COMPLEX_TYPE)
+ || !TYPE_ARG_TYPES (TREE_TYPE (fndecl)))
return;
enum built_in_function fcode = DECL_FUNCTION_CODE (fndecl);
diff --git a/gcc/testsuite/gcc.dg/pr87347.c b/gcc/testsuite/gcc.dg/pr87347.c
new file mode 100644
index 00000000000..d0bdf2a9fec
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr87347.c
@@ -0,0 +1,6 @@
+/* {dg-do compile} */
+/* { dg-options "-Wabsolute-value" } */
+
+int a;
+int abs();
+void b() { abs(a); }
--
2.18.0
next reply other threads:[~2018-09-24 18:40 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-24 18:46 Martin Jambor [this message]
2018-09-25 9:25 ` Jakub Jelinek
2018-09-25 15:50 ` Martin Jambor
2018-09-25 16:10 ` Jakub Jelinek
2018-09-25 23:19 ` Joseph Myers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ri6worahh82.fsf@suse.cz \
--to=mjambor@suse.cz \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).