diff options
author | Martin Sebor <msebor@redhat.com> | 2021-07-15 10:11:23 -0600 |
---|---|---|
committer | Martin Sebor <msebor@redhat.com> | 2021-07-15 10:22:06 -0600 |
commit | 98f1f9f38c45218c06200feb1939c9433a2ab6ca (patch) | |
tree | 37cd9c520dba216ab5078e1ae64e83b50ec28c88 /gcc/fold-const.c | |
parent | 07bd2703047d222ed7ff189d86350e73c5cc2c9e (diff) | |
download | gcc-98f1f9f38c45218c06200feb1939c9433a2ab6ca.zip gcc-98f1f9f38c45218c06200feb1939c9433a2ab6ca.tar.gz gcc-98f1f9f38c45218c06200feb1939c9433a2ab6ca.tar.bz2 |
Avoid -Wvla-parameter for nontrivial bounds [PR97548].
Resolves:
PR c/101289 - bogus -Wvla-paramater warning when using const for vla param
PR c/97548 - bogus -Wvla-parameter on a bound expression involving a parameter
gcc/c-family/ChangeLog:
PR c/101289
PR c/97548
* c-warn.c (warn_parm_array_mismatch): Use OEP_DECL_NAME.
gcc/c/ChangeLog:
PR c/101289
PR c/97548
* c-decl.c (get_parm_array_spec): Strip nops.
gcc/ChangeLog:
PR c/101289
PR c/97548
* fold-const.c (operand_compare::operand_equal_p): Handle OEP_DECL_NAME.
(operand_compare::verify_hash_value): Same.
* tree-core.h (OEP_DECL_NAME): New.
gcc/testsuite/ChangeLog:
* gcc.dg/Wvla-parameter-12.c: New test.
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r-- | gcc/fold-const.c | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c index e0cdb75..7dcecc9 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -3499,11 +3499,26 @@ operand_compare::operand_equal_p (const_tree arg0, const_tree arg1, case tcc_declaration: /* Consider __builtin_sqrt equal to sqrt. */ - return (TREE_CODE (arg0) == FUNCTION_DECL - && fndecl_built_in_p (arg0) && fndecl_built_in_p (arg1) - && DECL_BUILT_IN_CLASS (arg0) == DECL_BUILT_IN_CLASS (arg1) - && (DECL_UNCHECKED_FUNCTION_CODE (arg0) - == DECL_UNCHECKED_FUNCTION_CODE (arg1))); + if (TREE_CODE (arg0) == FUNCTION_DECL) + return (fndecl_built_in_p (arg0) && fndecl_built_in_p (arg1) + && DECL_BUILT_IN_CLASS (arg0) == DECL_BUILT_IN_CLASS (arg1) + && (DECL_UNCHECKED_FUNCTION_CODE (arg0) + == DECL_UNCHECKED_FUNCTION_CODE (arg1))); + + if (DECL_P (arg0) + && (flags & OEP_DECL_NAME) + && (flags & OEP_LEXICOGRAPHIC)) + { + /* Consider decls with the same name equal. The caller needs + to make sure they refer to the same entity (such as a function + formal parameter). */ + tree a0name = DECL_NAME (arg0); + tree a1name = DECL_NAME (arg1); + const char *a0ns = a0name ? IDENTIFIER_POINTER (a0name) : NULL; + const char *a1ns = a1name ? IDENTIFIER_POINTER (a1name) : NULL; + return a0ns && a1ns && strcmp (a0ns, a1ns) == 0; + } + return false; case tcc_exceptional: if (TREE_CODE (arg0) == CONSTRUCTOR) @@ -3914,14 +3929,14 @@ bool operand_compare::verify_hash_value (const_tree arg0, const_tree arg1, unsigned int flags, bool *ret) { - /* When checking, verify at the outermost operand_equal_p call that - if operand_equal_p returns non-zero then ARG0 and ARG1 has the same - hash value. */ + /* When checking and unless comparing DECL names, verify that if + the outermost operand_equal_p call returns non-zero then ARG0 + and ARG1 have the same hash value. */ if (flag_checking && !(flags & OEP_NO_HASH_CHECK)) { if (operand_equal_p (arg0, arg1, flags | OEP_NO_HASH_CHECK)) { - if (arg0 != arg1) + if (arg0 != arg1 && !(flags & OEP_DECL_NAME)) { inchash::hash hstate0 (0), hstate1 (0); hash_operand (arg0, hstate0, flags | OEP_HASH_CHECK); |