diff options
author | Martin Sebor <msebor@redhat.com> | 2021-08-14 13:25:41 -0600 |
---|---|---|
committer | Martin Sebor <msebor@redhat.com> | 2021-08-14 13:25:41 -0600 |
commit | 96194a07bdbc57dd9733892a791d87dbe25f0802 (patch) | |
tree | c3414d3d61a97e5d4d9dc33abe0f09149245f760 /gcc/tree.c | |
parent | 240f07805db27cfc746276039c5edccb4c031070 (diff) | |
download | gcc-96194a07bdbc57dd9733892a791d87dbe25f0802.zip gcc-96194a07bdbc57dd9733892a791d87dbe25f0802.tar.gz gcc-96194a07bdbc57dd9733892a791d87dbe25f0802.tar.bz2 |
Diagnose mismatches between array and scalar new and delete [PR101791].
Resolves:
PR middle-end/101791 - missing warning on a mismatch between scalar and array forms of new and delete
gcc/ChangeLog:
PR middle-end/101791
* gimple-ssa-warn-access.cc (new_delete_mismatch_p): Use new argument
to valid_new_delete_pair_p.
* tree.c (valid_new_delete_pair_p): Add argument.
* tree.h (valid_new_delete_pair_p): Same.
gcc/testsuite/ChangeLog:
PR middle-end/101791
* g++.dg/warn/Wmismatched-new-delete-6.C: New test.
* g++.dg/warn/Wmismatched-new-delete-7.C: New test.
Diffstat (limited to 'gcc/tree.c')
-rw-r--r-- | gcc/tree.c | 28 |
1 files changed, 25 insertions, 3 deletions
@@ -14314,17 +14314,28 @@ verify_type_context (location_t loc, type_context_kind context, || targetm.verify_type_context (loc, context, type, silent_p)); } -/* Return that NEW_ASM and DELETE_ASM name a valid pair of new and - delete operators. */ +/* Return true if NEW_ASM and DELETE_ASM name a valid pair of new and + delete operators. Return false if they may or may not name such + a pair and, when nonnull, set *PCERTAIN to true if they certainly + do not. */ bool -valid_new_delete_pair_p (tree new_asm, tree delete_asm) +valid_new_delete_pair_p (tree new_asm, tree delete_asm, + bool *pcertain /* = NULL */) { + bool certain; + if (!pcertain) + pcertain = &certain; + const char *new_name = IDENTIFIER_POINTER (new_asm); const char *delete_name = IDENTIFIER_POINTER (delete_asm); unsigned int new_len = IDENTIFIER_LENGTH (new_asm); unsigned int delete_len = IDENTIFIER_LENGTH (delete_asm); + /* The following failures are due to invalid names so they're not + considered certain mismatches. */ + *pcertain = false; + if (new_len < 5 || delete_len < 6) return false; if (new_name[0] == '_') @@ -14337,11 +14348,19 @@ valid_new_delete_pair_p (tree new_asm, tree delete_asm) ++delete_name, --delete_len; if (new_len < 4 || delete_len < 5) return false; + + /* The following failures are due to names of user-defined operators + so they're also not considered certain mismatches. */ + /* *_len is now just the length after initial underscores. */ if (new_name[0] != 'Z' || new_name[1] != 'n') return false; if (delete_name[0] != 'Z' || delete_name[1] != 'd') return false; + + /* The following failures are certain mismatches. */ + *pcertain = true; + /* _Znw must match _Zdl, _Zna must match _Zda. */ if ((new_name[2] != 'w' || delete_name[2] != 'l') && (new_name[2] != 'a' || delete_name[2] != 'a')) @@ -14380,6 +14399,9 @@ valid_new_delete_pair_p (tree new_asm, tree delete_asm) && !memcmp (delete_name + 5, "St11align_val_tRKSt9nothrow_t", 29)) return true; } + + /* The negative result is conservative. */ + *pcertain = false; return false; } |