From 116e8c285c1c1271e7c7099d4d4f0d459fe794d3 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Mon, 6 Nov 2017 16:53:01 -0500 Subject: [PATCH 25/25] {[06/14], NEEDS REVIEW} v3: Strip location wrappers in operand_equal_p This replaces: "[PATCH 06/14] Fix Wsizeof-pointer-memaccess*.c" gcc/ChangeLog: * fold-const.c (operand_equal_p): Strip location wrappers if OEP_ADDRESS_OF was not requested, doing it before the special-case for equality of integer constants. * tree.c (add_expr): Strip any location wrappers if OEP_ADDRESS_OF was not requested. (selftest::test_location_wrappers): Add test coverage for the interaction of location wrappers with operand_equal_p. --- gcc/fold-const.c | 6 ++++++ gcc/tree.c | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 0f11076..70db912 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -2844,6 +2844,12 @@ operand_equal_p (const_tree arg0, const_tree arg1, unsigned int flags) != TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (arg1))))) return 0; + if (!(flags & OEP_ADDRESS_OF)) + { + STRIP_ANY_LOCATION_WRAPPER (arg0); + STRIP_ANY_LOCATION_WRAPPER (arg1); + } + /* Check equality of integer constants before bailing out due to precision differences. */ if (TREE_CODE (arg0) == INTEGER_CST && TREE_CODE (arg1) == INTEGER_CST) diff --git a/gcc/tree.c b/gcc/tree.c index 902792a..517f4a4 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -14272,6 +14272,24 @@ test_location_wrappers () check_strip_nops (wrapped_int_cst, int_cst); check_strip_nops (wrapped_string_cst, string_cst); check_strip_nops (wrapped_int_var, int_var); + + /* operand_equal_p should "see through" any location wrapper... */ + ASSERT_TRUE (operand_equal_p (int_cst, wrapped_int_cst, 0)); + ASSERT_TRUE (operand_equal_p (int_var, wrapped_int_var, 0)); + ASSERT_FALSE (operand_equal_p (int_cst, int_var, 0)); + ASSERT_FALSE (operand_equal_p (wrapped_int_cst, wrapped_int_var, 0)); + + /* ...except with flag OEP_ADDRESS_OF. */ + ASSERT_FALSE (operand_equal_p (int_cst, wrapped_int_cst, OEP_ADDRESS_OF)); + ASSERT_FALSE (operand_equal_p (int_var, wrapped_int_var, OEP_ADDRESS_OF)); + + /* operand_equal_p should check equality of integer constants *before* + bailing out due to precision differences, even with location wrappers. */ + tree char_cst = build_int_cst (char_type_node, 42); + ASSERT_TRUE (operand_equal_p (int_cst, char_cst, 0)); + tree wrapped_char_cst = maybe_wrap_with_location (char_cst, loc); + ASSERT_TRUE (location_wrapper_p (wrapped_char_cst)); + ASSERT_TRUE (operand_equal_p (wrapped_int_cst, wrapped_char_cst, 0)); } /* Run all of the selftests within this file. */ -- 1.8.5.3