aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorJan Hubicka <hubicka@ucw.cz>2014-07-14 00:12:54 +0200
committerJan Hubicka <hubicka@gcc.gnu.org>2014-07-13 22:12:54 +0000
commit893306188659dafdd4fe386235039b0ec4b8c4c8 (patch)
tree205f9c439effd6b0b1d8538404e92216504a3f4c /gcc/fold-const.c
parent69dc8208ee905dbc2a6d04faa4cec7211874745e (diff)
downloadgcc-893306188659dafdd4fe386235039b0ec4b8c4c8.zip
gcc-893306188659dafdd4fe386235039b0ec4b8c4c8.tar.gz
gcc-893306188659dafdd4fe386235039b0ec4b8c4c8.tar.bz2
cgraph.h (symtab_node): Add nonzero_address.
* cgraph.h (symtab_node): Add nonzero_address. (decl_in_symtab_p): Break out from ... (symtab_get_node): ... here. * fold-const.c: Include cgraph.h (tree_single_nonzero_warnv_p): Use symtab to determine if symbol is non-zero. * symtab.c (symtab_node::nonzero_address): New method. * gcc.dg/pr36901.h: Simplify because non-zero symbol folding no longer happens during parsing. * gcc.dg/pr44024.c: Update template. * g++.dg/tree-ssa/nonzero-2.C: New testcase. * g++.dg/tree-ssa/nonzero-1.C: New testcase. * gcc.dg/tree-ssa/nonzero-1.c: New testcase. From-SVN: r212499
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c29
1 files changed, 21 insertions, 8 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index d51bda7..6a1c502 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -69,6 +69,7 @@ along with GCC; see the file COPYING3. If not see
#include "tree-dfa.h"
#include "hash-table.h" /* Required for ENABLE_FOLD_CHECKING. */
#include "builtins.h"
+#include "cgraph.h"
/* Nonzero if we are folding constants inside an initializer; zero
otherwise. */
@@ -16020,21 +16021,33 @@ tree_single_nonzero_warnv_p (tree t, bool *strict_overflow_p)
case ADDR_EXPR:
{
tree base = TREE_OPERAND (t, 0);
+
if (!DECL_P (base))
base = get_base_address (base);
if (!base)
return false;
- /* Weak declarations may link to NULL. Other things may also be NULL
- so protect with -fdelete-null-pointer-checks; but not variables
- allocated on the stack. */
+ /* For objects in symbol table check if we know they are non-zero.
+ Don't do anything for variables and functions before symtab is built;
+ it is quite possible that they will be declared weak later. */
+ if (DECL_P (base) && decl_in_symtab_p (base))
+ {
+ struct symtab_node *symbol;
+
+ symbol = symtab_get_node (base);
+ if (symbol)
+ return symbol->nonzero_address ();
+ else
+ return false;
+ }
+
+ /* Function local objects are never NULL. */
if (DECL_P (base)
- && (flag_delete_null_pointer_checks
- || (DECL_CONTEXT (base)
- && TREE_CODE (DECL_CONTEXT (base)) == FUNCTION_DECL
- && auto_var_in_fn_p (base, DECL_CONTEXT (base)))))
- return !VAR_OR_FUNCTION_DECL_P (base) || !DECL_WEAK (base);
+ && (DECL_CONTEXT (base)
+ && TREE_CODE (DECL_CONTEXT (base)) == FUNCTION_DECL
+ && auto_var_in_fn_p (base, DECL_CONTEXT (base))))
+ return true;
/* Constants are never weak. */
if (CONSTANT_CLASS_P (base))