This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PR 87347] Prevent segfaults if TYPE_ARG_TYPES is NULL
- From: Martin Jambor <mjambor at suse dot cz>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Cc:
- Date: Mon, 24 Sep 2018 20:40:13 +0200
- Subject: [PR 87347] Prevent segfaults if TYPE_ARG_TYPES is NULL
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