📄 400-mips-pr17565.patch
字号:
[committed] Fix target/17565: asms in delay slots * From: Richard Sandiford <rsandifo at redhat dot com> * To: gcc-patches at gcc dot gnu dot org * Date: Mon, 20 Sep 2004 07:55:58 +0100 * Subject: [committed] Fix target/17565: asms in delay slotsThe MIPS port was allowing asms to be put into delay slots if thecompiler guesses they are only one instruction long. This is wrongbecause of the possibility of it containing macros.The problem can be reproduced as an assembler warningin the following testcase:int foo (int n){ register int k asm ("$16") = n; if (k > 0) { bar (); asm ("li %0,0x12345678" : "=r" (k)); } return k;}because the multi-instruction asm statement goes into the delayslot of the call to bar().This is reduced from a much more serious linux problem. Linux is fondof using empty asm statements, and since gcc estimates empty asms to beone instruction long, they too might be put into delay slots. Thisactually has the effect of putting the following instruction into thedelay slot instead. Since there's no assembler warning, the problem wasonly detected as a run-time failure.The fix is simple: set the asm value of "can_delay" to "no".Tested on mipsisa64-elf, applied to mainline.This problem goes back to at least 2.95, so it isn't technically aregression. On the other hand, it's the kind of bug that could triggerfor different types of code in different releases, so I'm sure there'sa testcase that fails (say) in 3.4 and not in 2.95. Will probably askMark for permission to backport to 3.4.Richard PR target/17565 * config/mips/mips.md (define_asm_attributes): Set can_delay to no.testsuite/ * gcc.target/mips/asm-1.c: New test.Index: config/mips/mips.md===================================================================RCS file: /cvs/gcc/gcc/gcc/config/mips/mips.md,vretrieving revision 1.306diff -c -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.306 mips.md*** gcc/gcc/config/mips/mips.md 13 Sep 2004 19:32:05 -0000 1.306--- gcc/gcc/config/mips/mips.md 20 Sep 2004 06:52:31 -0000*************** (define_attr "may_clobber_hilo" "no,yes"*** 266,272 **** ;; Describe a user's asm statement. (define_asm_attributes! [(set_attr "type" "multi")]) ;; ......................... ;;--- 266,273 ---- ;; Describe a user's asm statement. (define_asm_attributes! [(set_attr "type" "multi")! (set_attr "can_delay" "no")]) ;; ......................... ;;Index: testsuite/gcc.target/mips/asm-1.c===================================================================RCS file: testsuite/gcc.target/mips/asm-1.cdiff -N testsuite/gcc.target/mips/asm-1.c*** gcc/gcc/testsuite/gcc.target/mips/asm-1.c 1 Jan 1970 00:00:00 -0000--- gcc/gcc/testsuite/gcc.target/mips/asm-1.c 20 Sep 2004 06:52:31 -0000****************** 0 ****--- 1,14 ----+ /* PR target/17565. GCC used to put the asm into the delay slot+ of the call. */+ /* { dg-do assemble } */+ /* { dg-options "-O" } */+ int foo (int n)+ {+ register int k asm ("$16") = n;+ if (k > 0)+ {+ bar ();+ asm ("li %0,0x12345678" : "=r" (k));+ }+ return k;+ }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -