From 822a132cfb5da9f38bd970c1b2cf20e49bb5a482 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Thu, 9 Mar 2017 22:45:39 +0000 Subject: [PATCH] re PR c++/79962 (ICE nonnull_check_p on a function template with a type-dependent attribute nonnull) PR c++/79962 PR c++/79984 * c-attribs.c (handle_nonnull_attribute): Save the result of default conversion to the attribute list. * c-c++-common/nonnull-3.c: New test. * g++.dg/warn/Wnonnull3.C: New test. From-SVN: r246016 --- gcc/c-family/ChangeLog | 7 +++++++ gcc/c-family/c-attribs.c | 2 +- gcc/testsuite/ChangeLog | 7 +++++++ gcc/testsuite/c-c++-common/nonnull-3.c | 11 +++++++++++ gcc/testsuite/g++.dg/warn/Wnonnull3.C | 15 +++++++++++++++ 5 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/c-c++-common/nonnull-3.c create mode 100644 gcc/testsuite/g++.dg/warn/Wnonnull3.C diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index b14cb0d64fe..a6447738f6b 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,10 @@ +2017-03-09 Marek Polacek + + PR c++/79962 + PR c++/79984 + * c-attribs.c (handle_nonnull_attribute): Save the result of default + conversion to the attribute list. + 2017-03-09 Martin Liska * c-ada-spec.c (macro_length): Increment value instead of a pointer. diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c index 8058a6518c5..f2a88e147ba 100644 --- a/gcc/c-family/c-attribs.c +++ b/gcc/c-family/c-attribs.c @@ -2813,7 +2813,7 @@ handle_nonnull_attribute (tree *node, tree ARG_UNUSED (name), tree arg = TREE_VALUE (args); if (arg && TREE_CODE (arg) != IDENTIFIER_NODE && TREE_CODE (arg) != FUNCTION_DECL) - arg = default_conversion (arg); + TREE_VALUE (args) = arg = default_conversion (arg); if (!get_nonnull_operand (arg, &arg_num)) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index bc2bc4a5437..84d87741e5d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2017-03-09 Marek Polacek + + PR c++/79962 + PR c++/79984 + * c-c++-common/nonnull-3.c: New test. + * g++.dg/warn/Wnonnull3.C: New test. + 2017-03-09 Matthew Fortune * gcc.target/mips/lxc1-sxc1-1.c: Use -mhard-float. diff --git a/gcc/testsuite/c-c++-common/nonnull-3.c b/gcc/testsuite/c-c++-common/nonnull-3.c new file mode 100644 index 00000000000..d2ccb24f4fd --- /dev/null +++ b/gcc/testsuite/c-c++-common/nonnull-3.c @@ -0,0 +1,11 @@ +/* PR c++/79984 */ +/* { dg-do compile } */ +/* { dg-options "-Wnonnull-compare" } */ + +enum { r = 1 }; + +__attribute__ ((nonnull (r))) int +f (int *p) +{ + return p == 0; /* { dg-warning "nonnull argument 'p' compared to NULL" } */ +} diff --git a/gcc/testsuite/g++.dg/warn/Wnonnull3.C b/gcc/testsuite/g++.dg/warn/Wnonnull3.C new file mode 100644 index 00000000000..d1918ef8e90 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wnonnull3.C @@ -0,0 +1,15 @@ +// PR c++/79962 +// { dg-options "-Wnonnull" } + +template +__attribute__ ((__nonnull__ (T::i))) void f (typename T::U) { } + +struct S1 { enum { i = 1 }; typedef void* U; }; +struct S2 { static const int i = 1; typedef void* U; }; + +void +g () +{ + f(0); // { dg-warning "null argument where non-null required" } + f(0); // { dg-warning "null argument where non-null required" } +}