Path: utzoo!telly!ddsw1!mcdchg!rutgers!labrea!bloom-beacon!tut.cis.ohio-state.edu!cs.utexas.edu!bunda From: bunda@cs.utexas.edu (John Bunda) Newsgroups: gnu.gcc.bug Subject: mode confusion bug in 1.30 Keywords: HImode, extern Message-ID: <3914@cs.utexas.edu> Date: 11 Nov 88 03:48:12 GMT Sender: news@cs.utexas.edu Lines: 132 This bug occurs in my port to our experimental machine (METRIC), I haven't checked to see if it occurs for other little-endian memory machines. The problem occurs when a global memory reference is used in a shorter mode than its natural one; in this case, when adding a global int to a local short. The program test.c: extern int x; bad_load() { register short y = 5; y += x; return y; } TRULY_NOOP_TRUNCATION is defined as 0, and truncation insns are defined only on The code generated for my machine with incorrect code noted: %% Metric gcc output %% gcc level 1.30 11/10/88 .text .align 2 LC0: .long _x .align 1 .globl _test _test: % test (C function) % stack usage: 0 bytes argument overflow % 32 bytes register save % 0 bytes local stack frame .using _test,r2 stm r1,r8,-128(r4) move r2,r25 lda r3,-128(r4) lda r4,-128(r4) ldi r6,5 ld r7,LC0 <----- load address of x (declared extern int) ldh r8,0(r7) <----- but load wrong halfword - should be 2(r7) move r7,r6 shli r7,16 shrai r7,16 shli r8,16 shrai r8,16 add r7,r8 move r6,r7 move r26,r6 shli r26,16 shrai r26,16 j L1 L1: ldm r1,r8,0(r3) return .drop r2 % End of function test % ******* Here is the RTL from: gcc -S -dr test.c ******* ;; Function test (note 1 0 2 "" -1) (note 2 1 3 "" -2) (insn 3 2 4 (use (reg/v:HI 32)) -1 (nil) (nil)) (insn 4 3 5 (set (reg/v:HI 32) (const_int 5)) -1 (nil) (nil)) (insn 5 4 6 (set (reg:SI 33) (mem:SI (symbol_ref/u:SI ("*LC0")))) -1 (nil) (expr_list:SI (symbol_ref:SI ("x")) (nil))) (insn 6 5 7 (set (reg:HI 34) (mem:HI (reg:SI 33))) -1 (nil) <- note ref of memory in wrong mode here (nil)) (insn 7 6 8 (set (reg:SI 35) (sign_extend:SI (reg/v:HI 32))) -1 (nil) (nil)) (insn 8 7 10 (set (reg:SI 36) (sign_extend:SI (reg:HI 34))) -1 (nil) (nil)) (insn 10 8 11 (set (reg:SI 37) (plus:SI (reg:SI 35) (reg:SI 36))) -1 (nil) (nil)) (insn 11 10 12 (set (reg/v:HI 32) (subreg:HI (reg:SI 37) 0)) -1 (nil) (nil)) (insn 12 11 13 (set (reg/i:SI 26) (sign_extend:SI (reg/v:HI 32))) -1 (nil) (nil)) (insn 13 12 14 (use (reg/i:SI 26)) -1 (nil) (nil)) (jump_insn 14 13 15 (set (pc) (label_ref 19)) -1 (nil) (nil)) (barrier 15 14 16) (note 16 15 17 "" -3) (insn 17 16 18 (use (reg/v:HI 32)) -1 (nil) (nil)) (note 18 17 19 "" -6) (code_label 19 18 0 1) **** end of RTL **** Thanks! -John .................................. John Bunda UT CS Dept. bunda@cs.utexas.edu Austin, Texas