From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8126 invoked by alias); 16 Aug 2012 12:46:28 -0000 Received: (qmail 8108 invoked by uid 22791); 16 Aug 2012 12:46:26 -0000 X-SWARE-Spam-Status: No, hits=-3.6 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,TW_BJ X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 16 Aug 2012 12:46:13 +0000 From: "jguillaumes at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/54282] New: GCC generates incorrect code for the PDP-11 target when -Os or -O2 is specified Date: Thu, 16 Aug 2012 12:46:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Keywords: X-Bugzilla-Severity: major X-Bugzilla-Who: jguillaumes at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-08/txt/msg01052.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D54282 Bug #: 54282 Summary: GCC generates incorrect code for the PDP-11 target when -Os or -O2 is specified Classification: Unclassified Product: gcc Version: 4.6.4 Status: UNCONFIRMED Severity: major Priority: P3 Component: c AssignedTo: unassigned@gcc.gnu.org ReportedBy: jguillaumes@gmail.com Created attachment 28029 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=3D28029 Compiler generated file When doing an indirect function call (using a function pointer table), GCC generates incorrectly the JSR instruction. Assuming than R0 contains the address of the pointer to the function to call, the correct instruction wou= ld be: JSR PC,@(R0) The compiler generates instead: JSR PC,(R0) That causes the machine to jump to the pointer address instead of jumping to the function address. Oddly enough, the assembly (*.s) file generated it I specify the -S option = is right: mov _trap_table.1213+02(r0), -(sp) add $_trap_table.1213, r0 jsr pc, @(r0) But the compiled code in the *.o file, shown using the objdump utility is wrong: 66: 1066 mov r1, -(sp) 68: 1c26 0082 mov 202(r0), -(sp) 6c: 65c0 0080 add $200, r0 70: 09c8 jsr pc, (r0) Compiler output: Usant especificacions internes. COLLECT_GCC=3Dpdp11-aout-gcc COLLECT_LTO_WRAPPER=3D/usr/local/libexec/gcc/pdp11-aout/4.6.4/lto-wrapper Target: pdp11-aout Configurat amb: ../gcc/configure --enable-languages=3Dc --target=3Dpdp11-ao= ut --with-newlib Model de fils: single gcc version 4.6.4 20120725 (prerelease) (GCC)=20 COLLECT_GCC_OPTIONS=3D'-v' '-save-temps' '-c' '-S' '-Os' '-Wall' '-Wextra' /usr/local/libexec/gcc/pdp11-aout/4.6.4/cc1 -E -quiet -v indirect_call_tab= le.c -Wall -Wextra -Os -fpch-preprocess -o indirect_call_table.i ignorant el directori inexistent "/usr/local/lib/gcc/pdp11-aout/4.6.4/../../../../pdp11-aout/sys-include" la recerca de #include "..." s'inicia aqu=C3=AD: la recerca de #include <...> s'inicia aqu=C3=AD: /usr/local/lib/gcc/pdp11-aout/4.6.4/include /usr/local/lib/gcc/pdp11-aout/4.6.4/include-fixed /usr/local/lib/gcc/pdp11-aout/4.6.4/../../../../pdp11-aout/include Fi de la llista de recerca. COLLECT_GCC_OPTIONS=3D'-v' '-save-temps' '-c' '-S' '-Os' '-Wall' '-Wextra' /usr/local/libexec/gcc/pdp11-aout/4.6.4/cc1 -fpreprocessed indirect_call_table.i -quiet -dumpbase indirect_call_table.c -auxbase indirect_call_table -Os -Wall -Wextra -version -o indirect_call_table.s GNU C (GCC) version 4.6.4 20120725 (prerelease) (pdp11-aout) compiled by GNU C version 4.6.3, GMP version 5.0.2, MPFR version 3.1.0-= p3, MPC version 0.9 GGC heuristics: --param ggc-min-expand=3D100 --param ggc-min-heapsize=3D131= 072 GNU C (GCC) version 4.6.4 20120725 (prerelease) (pdp11-aout) compiled by GNU C version 4.6.3, GMP version 5.0.2, MPFR version 3.1.0-= p3, MPC version 0.9 GGC heuristics: --param ggc-min-expand=3D100 --param ggc-min-heapsize=3D131= 072 Compiler executable checksum: 4e94c29ebf077b5bb93c64c5b111b8f7 indirect_call_table.c: In function =E2=80=98muxx_systrap_handler=E2=80=99: indirect_call_table.c:30:7: av=C3=ADs: variable =E2=80=98rc=E2=80=99 set bu= t not used [-Wunused-but-set-variable] indirect_call_table.c: In function =E2=80=98muxx_svc_conputc=E2=80=99: indirect_call_table.c:48:1: av=C3=ADs: no hi ha una declaraci=C3=B3 de reto= rn en una funci=C3=B3 que retorna "non-void" [-Wreturn-type] indirect_call_table.c:44:33: av=C3=ADs: unused parameter =E2=80=98np=E2=80= =99 [-Wunused-parameter] indirect_call_table.c: In function =E2=80=98muxx_svc_muxxhlt=E2=80=99: indirect_call_table.c:52:1: av=C3=ADs: no hi ha una declaraci=C3=B3 de reto= rn en una funci=C3=B3 que retorna "non-void" [-Wreturn-type] indirect_call_table.c:50:33: av=C3=ADs: unused parameter =E2=80=98np=E2=80= =99 [-Wunused-parameter] indirect_call_table.c:50:45: av=C3=ADs: unused parameter =E2=80=98args=E2= =80=99 [-Wunused-parameter] indirect_call_table.c: In function =E2=80=98muxx_unimpl=E2=80=99: indirect_call_table.c:55:28: av=C3=ADs: unused parameter =E2=80=98np=E2=80= =99 [-Wunused-parameter] indirect_call_table.c:55:40: av=C3=ADs: unused parameter =E2=80=98args=E2= =80=99 [-Wunused-parameter] indirect_call_table.c: In function =E2=80=98muxx_systrap_handler=E2=80=99: indirect_call_table.c:42:1: av=C3=ADs: el control arriba a el final d'una f= unci=C3=B3 que no =C3=A9s void [-Wreturn-type] COMPILER_PATH=3D/usr/local/libexec/gcc/pdp11-aout/4.6.4/:/usr/local/libexec= /gcc/pdp11-aout/4.6.4/:/usr/local/libexec/gcc/pdp11-aout/:/usr/local/lib/gc= c/pdp11-aout/4.6.4/:/usr/local/lib/gcc/pdp11-aout/:/usr/local/lib/gcc/pdp11= -aout/4.6.4/../../../../pdp11-aout/bin/ LIBRARY_PATH=3D/usr/local/lib/gcc/pdp11-aout/4.6.4/:/usr/local/lib/gcc/pdp1= 1-aout/4.6.4/../../../../pdp11-aout/lib/ COLLECT_GCC_OPTIONS=3D'-v' '-save-temps' '-c' '-S' '-Os' '-Wall' '-Wextra'