some more kernel patch shrinking
[openwrt.git] / openwrt / toolchain / gcc / 3.4.2 / 400-mips-pr17565.patch
1 [committed] Fix target/17565: asms in delay slots
2
3 * From: Richard Sandiford <rsandifo at redhat dot com>
4 * To: gcc-patches at gcc dot gnu dot org
5 * Date: Mon, 20 Sep 2004 07:55:58 +0100
6 * Subject: [committed] Fix target/17565: asms in delay slots
7
8 The MIPS port was allowing asms to be put into delay slots if the
9 compiler guesses they are only one instruction long. This is wrong
10 because of the possibility of it containing macros.
11
12 The problem can be reproduced as an assembler warning
13 in the following testcase:
14
15 int foo (int n)
16 {
17 register int k asm ("$16") = n;
18 if (k > 0)
19 {
20 bar ();
21 asm ("li %0,0x12345678" : "=r" (k));
22 }
23 return k;
24 }
25
26 because the multi-instruction asm statement goes into the delay
27 slot of the call to bar().
28
29 This is reduced from a much more serious linux problem. Linux is fond
30 of using empty asm statements, and since gcc estimates empty asms to be
31 one instruction long, they too might be put into delay slots. This
32 actually has the effect of putting the following instruction into the
33 delay slot instead. Since there's no assembler warning, the problem was
34 only detected as a run-time failure.
35
36 The fix is simple: set the asm value of "can_delay" to "no".
37 Tested on mipsisa64-elf, applied to mainline.
38
39 This problem goes back to at least 2.95, so it isn't technically a
40 regression. On the other hand, it's the kind of bug that could trigger
41 for different types of code in different releases, so I'm sure there's
42 a testcase that fails (say) in 3.4 and not in 2.95. Will probably ask
43 Mark for permission to backport to 3.4.
44
45 Richard
46
47
48 PR target/17565
49 * config/mips/mips.md (define_asm_attributes): Set can_delay to no.
50
51 testsuite/
52 * gcc.target/mips/asm-1.c: New test.
53
54 Index: config/mips/mips.md
55 ===================================================================
56 RCS file: /cvs/gcc/gcc/gcc/config/mips/mips.md,v
57 retrieving revision 1.306
58 diff -c -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.306 mips.md
59 *** gcc/gcc/config/mips/mips.md 13 Sep 2004 19:32:05 -0000 1.306
60 --- gcc/gcc/config/mips/mips.md 20 Sep 2004 06:52:31 -0000
61 *************** (define_attr "may_clobber_hilo" "no,yes"
62 *** 266,272 ****
63
64 ;; Describe a user's asm statement.
65 (define_asm_attributes
66 ! [(set_attr "type" "multi")])
67 \f
68 ;; .........................
69 ;;
70 --- 266,273 ----
71
72 ;; Describe a user's asm statement.
73 (define_asm_attributes
74 ! [(set_attr "type" "multi")
75 ! (set_attr "can_delay" "no")])
76 \f
77 ;; .........................
78 ;;
79 Index: testsuite/gcc.target/mips/asm-1.c
80 ===================================================================
81 RCS file: testsuite/gcc.target/mips/asm-1.c
82 diff -N testsuite/gcc.target/mips/asm-1.c
83 *** gcc/gcc/testsuite/gcc.target/mips/asm-1.c 1 Jan 1970 00:00:00 -0000
84 --- gcc/gcc/testsuite/gcc.target/mips/asm-1.c 20 Sep 2004 06:52:31 -0000
85 ***************
86 *** 0 ****
87 --- 1,14 ----
88 + /* PR target/17565. GCC used to put the asm into the delay slot
89 + of the call. */
90 + /* { dg-do assemble } */
91 + /* { dg-options "-O" } */
92 + int foo (int n)
93 + {
94 + register int k asm ("$16") = n;
95 + if (k > 0)
96 + {
97 + bar ();
98 + asm ("li %0,0x12345678" : "=r" (k));
99 + }
100 + return k;
101 + }
102
This page took 0.052179 seconds and 5 git commands to generate.