GCC with patches for Dreamcast
修订版 | b3bab6e7cad8be89405b47c4588eb0beeed72bbd (tree) |
---|---|
时间 | 2021-09-30 03:42:47 |
作者 | Richard Sandiford <richard.sandiford@arm....> |
Commiter | alaskanemily |
Prevent -Og from deleting stores to write-only variables
This patch prevents -Og from deleting stores to write-only variables,
so that the values are still available when debugging. This seems
more convenient than forcing users to use attribute((used))
(probably conditionally, if it's not something they want in release
builds).
2019-07-29 Richard Sandiford <richard.sandiford@arm.com>
gcc/
* tree-cfg.c (execute_fixup_cfg): Don't delete stores to write-only
variables for -Og.
gcc/testsuite/
* c-c++-common/guality/Og-static-wo-1.c: New test.
* g++.dg/guality/guality.exp: Separate the c-c++-common tests into
"Og" and "general" tests. Run the latter at -O0 and -Og only.
* gcc.dg/guality/guality.exp: Likewise.
From-SVN: r273870
@@ -0,0 +1,15 @@ | ||
1 | +/* { dg-do run } */ | |
2 | +/* { dg-options "-g" } */ | |
3 | + | |
4 | +#include "../../gcc.dg/nop.h" | |
5 | + | |
6 | +static int x = 0; | |
7 | + | |
8 | +int | |
9 | +main (void) | |
10 | +{ | |
11 | + asm volatile (NOP); /* { dg-final { gdb-test . "x" "0" } } */ | |
12 | + x = 1; | |
13 | + asm volatile (NOP); /* { dg-final { gdb-test . "x" "1" } } */ | |
14 | + return 0; | |
15 | +} |
@@ -53,8 +53,22 @@ if {[check_guality " | ||
53 | 53 | return 0; |
54 | 54 | } |
55 | 55 | "]} { |
56 | - gcc-dg-runtest [lsort [glob $srcdir/$subdir/*.C]] "" "" | |
57 | - gcc-dg-runtest [lsort [glob $srcdir/c-c++-common/guality/*.c]] "" "" | |
56 | + set general [list] | |
57 | + set Og [list] | |
58 | + foreach file [lsort [glob $srcdir/c-c++-common/guality/*.c]] { | |
59 | + switch -glob -- [file tail $file] { | |
60 | + Og-* { lappend Og $file } | |
61 | + * { lappend general $file } | |
62 | + } | |
63 | + } | |
64 | + | |
65 | + gcc-dg-runtest [lsort [glob $srcdir/$subdir/*.C]] "" "" | |
66 | + gcc-dg-runtest $general "" "" | |
67 | + set-torture-options \ | |
68 | + [list "-O0" "-Og"] \ | |
69 | + [list {}] \ | |
70 | + [list "-Og -flto"] | |
71 | + gcc-dg-runtest $Og "" "" | |
58 | 72 | } |
59 | 73 | |
60 | 74 | if [info exists guality_gdb_name] { |
@@ -53,8 +53,22 @@ if {[check_guality " | ||
53 | 53 | return 0; |
54 | 54 | } |
55 | 55 | "]} { |
56 | - gcc-dg-runtest [lsort [glob $srcdir/$subdir/*.c]] "" "" | |
57 | - gcc-dg-runtest [lsort [glob $srcdir/c-c++-common/guality/*.c]] "" "-Wc++-compat" | |
56 | + set general [list] | |
57 | + set Og [list] | |
58 | + foreach file [lsort [glob $srcdir/c-c++-common/guality/*.c]] { | |
59 | + switch -glob -- [file tail $file] { | |
60 | + Og-* { lappend Og $file } | |
61 | + * { lappend general $file } | |
62 | + } | |
63 | + } | |
64 | + | |
65 | + gcc-dg-runtest [lsort [glob $srcdir/$subdir/*.c]] "" "" | |
66 | + gcc-dg-runtest $general "" "-Wc++-compat" | |
67 | + set-torture-options \ | |
68 | + [list "-O0" "-Og"] \ | |
69 | + [list {}] \ | |
70 | + [list "-Og -flto"] | |
71 | + gcc-dg-runtest $Og "" "-Wc++-compat" | |
58 | 72 | } |
59 | 73 | |
60 | 74 | if [info exists guality_gdb_name] { |
@@ -9706,7 +9706,8 @@ execute_fixup_cfg (void) | ||
9706 | 9706 | Keep access when store has side effect, i.e. in case when source |
9707 | 9707 | is volatile. */ |
9708 | 9708 | if (gimple_store_p (stmt) |
9709 | - && !gimple_has_side_effects (stmt)) | |
9709 | + && !gimple_has_side_effects (stmt) | |
9710 | + && !optimize_debug) | |
9710 | 9711 | { |
9711 | 9712 | tree lhs = get_base_address (gimple_get_lhs (stmt)); |
9712 | 9713 |