diff options
author | Jakub Jelinek <jakub@redhat.com> | 2019-01-30 08:49:58 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2019-01-30 08:49:58 +0100 |
commit | fe509359cf5ff58edd84bb1f28323af6dc4dd4b4 (patch) | |
tree | 8b48e406dd9b023b4e99192f8c9d245457c2b4fe /gcc | |
parent | 2ab6839bccb22a04c6df2000858c36d0ffa313ce (diff) | |
download | gcc-fe509359cf5ff58edd84bb1f28323af6dc4dd4b4.zip gcc-fe509359cf5ff58edd84bb1f28323af6dc4dd4b4.tar.gz gcc-fe509359cf5ff58edd84bb1f28323af6dc4dd4b4.tar.bz2 |
re PR c/89061 (GCC 9 introduces false positive in -Wjump-misses-init)
PR c/89061
* c-tree.h (C_DECL_COMPOUND_LITERAL_P): Define.
* c-decl.c (decl_jump_unsafe): Return false for
C_DECL_COMPOUND_LITERAL_P decls.
(build_compound_literal): Set C_DECL_COMPOUND_LITERAL_P.
* gcc.dg/pr89061.c: New test.
From-SVN: r268381
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/c/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/c/c-decl.c | 9 | ||||
-rw-r--r-- | gcc/c/c-tree.h | 4 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr89061.c | 27 |
5 files changed, 53 insertions, 0 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index dcb3f21..b215758 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,11 @@ +2019-01-30 Jakub Jelinek <jakub@redhat.com> + + PR c/89061 + * c-tree.h (C_DECL_COMPOUND_LITERAL_P): Define. + * c-decl.c (decl_jump_unsafe): Return false for + C_DECL_COMPOUND_LITERAL_P decls. + (build_compound_literal): Set C_DECL_COMPOUND_LITERAL_P. + 2019-01-29 Jakub Jelinek <jakub@redhat.com> PR c/89045 diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index 02a9323..5170e92 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -659,6 +659,14 @@ decl_jump_unsafe (tree decl) if (error_operand_p (decl)) return false; + /* Don't warn for compound literals. If a goto statement crosses + their initialization, it should cross also all the places where + the complit is used or where the complit address might be saved + into some variable, so code after the label to which goto jumps + should not be able to refer to the compound literal. */ + if (VAR_P (decl) && C_DECL_COMPOUND_LITERAL_P (decl)) + return false; + /* Always warn about crossing variably modified types. */ if ((VAR_P (decl) || TREE_CODE (decl) == TYPE_DECL) && variably_modified_type_p (TREE_TYPE (decl), NULL_TREE)) @@ -5486,6 +5494,7 @@ build_compound_literal (location_t loc, tree type, tree init, bool non_const, DECL_READ_P (decl) = 1; DECL_ARTIFICIAL (decl) = 1; DECL_IGNORED_P (decl) = 1; + C_DECL_COMPOUND_LITERAL_P (decl) = 1; TREE_TYPE (decl) = type; c_apply_type_quals_to_decl (TYPE_QUALS (strip_array_types (type)), decl); if (alignas_align) diff --git a/gcc/c/c-tree.h b/gcc/c/c-tree.h index 0070f0d..b69ef33 100644 --- a/gcc/c/c-tree.h +++ b/gcc/c/c-tree.h @@ -96,6 +96,10 @@ along with GCC; see the file COPYING3. If not see #pragma omp threadprivate. */ #define C_DECL_THREADPRIVATE_P(DECL) DECL_LANG_FLAG_3 (VAR_DECL_CHECK (DECL)) +/* Set on VAR_DECLs for compound literals. */ +#define C_DECL_COMPOUND_LITERAL_P(DECL) \ + DECL_LANG_FLAG_5 (VAR_DECL_CHECK (DECL)) + /* Nonzero for a decl which either doesn't exist or isn't a prototype. N.B. Could be simplified if all built-in decls had complete prototypes (but this is presently difficult because some of them need FILE*). */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b7566db..d60389f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-01-30 Jakub Jelinek <jakub@redhat.com> + + PR c/89061 + * gcc.dg/pr89061.c: New test. + 2019-01-29 Martin Sebor <msebor@redhat.com> PR c/88956 diff --git a/gcc/testsuite/gcc.dg/pr89061.c b/gcc/testsuite/gcc.dg/pr89061.c new file mode 100644 index 0000000..6b5d913 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr89061.c @@ -0,0 +1,27 @@ +/* PR c/89061 */ +/* { dg-do compile } */ +/* { dg-options "-Wjump-misses-init" } */ + +struct S { int s; }; + +int +foo (int x) +{ + struct S s = { 0 }; + if ((s.s = x) == 0) + goto cleanup; /* { dg-bogus "jump skips variable initialization" } */ + s = (struct S) { .s = 42 }; + cleanup: + return s.s; +} + +int +bar (int x) +{ + struct S *s = &(struct S) { 0 }; + if ((s->s = x) == 0) + goto cleanup; /* { dg-bogus "jump skips variable initialization" } */ + s = &(struct S) { .s = 42 }; + cleanup: + return s->s; +} |