diff options
author | Richard Sandiford <richard.sandiford@arm.com> | 2021-04-21 09:08:44 +0100 |
---|---|---|
committer | Richard Sandiford <richard.sandiford@arm.com> | 2021-04-21 09:08:44 +0100 |
commit | b67778b59932fdc64dc89a97550349e973ca0352 (patch) | |
tree | 5d72991773b38f84f60f8f849481c986648a1212 /gcc/testsuite/c-c++-common/attr-retain-10.c | |
parent | cb60e56d4ac2958c422c003221ca0cff6a537e0b (diff) | |
download | gcc-b67778b59932fdc64dc89a97550349e973ca0352.zip gcc-b67778b59932fdc64dc89a97550349e973ca0352.tar.gz gcc-b67778b59932fdc64dc89a97550349e973ca0352.tar.bz2 |
varasm: Two SECTION_RETAIN fixes [PR100130]
switch_to_section warns if we try to output a retain decl in a
section without a retain flag, or if we try to output a non-retain
decl in a section with a retain flag. However, the warning only
applied if we were trying to “switch” to the current section.
This works if all decls that use a section are generated consecutively,
but not if there is an unrelated decl in between.
This patch makes the check unconditional, but suppresses the warning
if we're writing the section's named.decl (i.e. the decl from which
the section name and original flags were derived).
Also, the warning didn't fire for -fsection-anchors, for two reasons:
we allowed retain and non-retain decls to be put into the same block,
and we didn't pass a decl to switch_to_section.
Although these are arguably separate bugs, it isn't easy to fix them
independently without temporarily regressing -fsection-anchor targets.
gcc/
PR middle-end/100130
* varasm.c (get_block_for_decl): Make sure that any use of the
retain attribute matches the section's retain flag.
(switch_to_section): Check for retain mismatches even when
changing sections, but do not warn if the given decl is the
section's named.decl.
(output_object_block): Pass the first decl in the block (if any)
to switch_to_section.
gcc/testsuite/
PR middle-end/100130
* c-c++-common/attr-retain-10.c: New test.
* c-c++-common/attr-retain-11.c: Likewise.
Diffstat (limited to 'gcc/testsuite/c-c++-common/attr-retain-10.c')
-rw-r--r-- | gcc/testsuite/c-c++-common/attr-retain-10.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/gcc/testsuite/c-c++-common/attr-retain-10.c b/gcc/testsuite/c-c++-common/attr-retain-10.c new file mode 100644 index 0000000..0bac947 --- /dev/null +++ b/gcc/testsuite/c-c++-common/attr-retain-10.c @@ -0,0 +1,11 @@ +/* { dg-do compile { target R_flag_in_section } } */ +/* { dg-skip-if "non-ELF target" { *-*-darwin* powerpc*-*-aix* } } */ +/* { dg-options "-Wall -O2 -fno-toplevel-reorder" } */ + +int __attribute__((used,retain,section(".data.foo"))) foo2 = 2; +int between = 1; +int __attribute__((section(".data.foo"))) foo1 = 1; +/* { dg-warning "'.*' without 'retain' attribute and '.*' with 'retain' attribute are placed in a section with the same name" "" { target R_flag_in_section } .-1 } */ + +/* { dg-final { scan-assembler ".data.foo,\"aw\"" { target R_flag_in_section } } } */ +/* { dg-final { scan-assembler ".data.foo,\"awR\"" { target R_flag_in_section } } } */ |