diff options
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"); } } |