diff options
author | Michael Matz <matz@suse.de> | 2005-05-02 04:22:45 +0000 |
---|---|---|
committer | Michael Matz <matz@gcc.gnu.org> | 2005-05-02 04:22:45 +0000 |
commit | b2f97e4a12858733fc4977859febecd144acb8dd (patch) | |
tree | 81e0ec0700839598638506aadcfb471636db87e6 /gcc/c-common.c | |
parent | f8f9fb4526bea97382af2024b7b268725d544239 (diff) | |
download | gcc-b2f97e4a12858733fc4977859febecd144acb8dd.zip gcc-b2f97e4a12858733fc4977859febecd144acb8dd.tar.gz gcc-b2f97e4a12858733fc4977859febecd144acb8dd.tar.bz2 |
re PR c++/19542 (attribute(sentinel) has problems with C++ __null)
PR c++/19542
* c-common.c (c_common_nodes_and_builtins): Create global null_node.
(warn_strict_null_sentinel): Define.
(check_function_sentinel): Check for null_node as valid sentinel too.
* c-common.h (c_tree_index): Added CTI_NULL.
(null_node) Define global_tree[CTI_NULL].
(warn_strict_null_sentinel): Declare.
* c-opts.c: (c_common_handle_option): Handle -Wstrict-null-sentinel.
* c.opt: (Wstrict-null-sentinel): New C++ option.
* doc/invoke.texi (C++ Options): Document -Wstrict-null-sentinel.
* cp-tree.h (cp_tree_index): Remove CPTI_NULL, to be defined in C
common frontend.
(null_node): Remove.
* lex.c (cxx_init): Move null_node initialisation to C common frontend.
* g++.dg/warn/sentinel.C: New testcase for __null sentinels added.
From-SVN: r99091
Diffstat (limited to 'gcc/c-common.c')
-rw-r--r-- | gcc/c-common.c | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/gcc/c-common.c b/gcc/c-common.c index 8aa0aea..22aa82e 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -284,6 +284,12 @@ int warn_unknown_pragmas; /* Tri state variable. */ int warn_format; +/* Warn about using __null (as NULL in C++) as sentinel. For code compiled + with GCC this doesn't matter as __null is guaranteed to have the right + size. */ + +int warn_strict_null_sentinel; + /* Zero means that faster, ...NonNil variants of objc_msgSend... calls will be used in ObjC; passing nil receivers to such calls will most likely result in crashes. */ @@ -3279,6 +3285,11 @@ c_common_nodes_and_builtins (void) mudflap_init (); main_identifier_node = get_identifier ("main"); + + /* Create the built-in __null node. It is important that this is + not shared. */ + null_node = make_node (INTEGER_CST); + TREE_TYPE (null_node) = c_common_type_for_size (POINTER_SIZE, 0); } /* Look up the function in built_in_decls that corresponds to DECL @@ -5134,8 +5145,15 @@ check_function_sentinel (tree attrs, tree params) } /* Validate the sentinel. */ - if (!POINTER_TYPE_P (TREE_TYPE (TREE_VALUE (sentinel))) - || !integer_zerop (TREE_VALUE (sentinel))) + if ((!POINTER_TYPE_P (TREE_TYPE (TREE_VALUE (sentinel))) + || !integer_zerop (TREE_VALUE (sentinel))) + /* Although __null (in C++) is only an integer we allow it + nevertheless, as we are guaranteed that it's exactly + as wide as a pointer, and we don't want to force + users to cast the NULL they have written there. + We warn with -Wstrict-null-sentinel, though. */ + && (warn_strict_null_sentinel + || null_node != TREE_VALUE (sentinel))) warning (0, "missing sentinel in function call"); } } |