From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9667 invoked by alias); 14 Mar 2012 01:20:46 -0000 Received: (qmail 9659 invoked by uid 22791); 14 Mar 2012 01:20:44 -0000 X-SWARE-Spam-Status: No, hits=-2.8 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,TW_GM 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; Wed, 14 Mar 2012 01:20:32 +0000 From: "wwieser at gmx dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/52474] Regression: AVR-GCC: arithmetics produce completely wrong result Date: Wed, 14 Mar 2012 08:30:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: wwieser at gmx dot de X-Bugzilla-Status: WAITING X-Bugzilla-Priority: P4 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" 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-03/txt/msg01237.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52474 --- Comment #3 from wwieser at gmx dot de 2012-03-14 01:19:59 UTC --- OK, so talking to the debian maintainer, the GCC version I'm using is based upon patches available here: http://distribute.atmel.no/tools/opensource/avr-gcc/ Here is a test case. I'm unsure how to make a test case for code to be executed on a microcontroller because I need to make some assumptions about the board so that the result can be shown to the user somehow (flash a LED, whatever...) So, here is a test case which I believe to reproduce the bug. Please test this against the newest version of avr-gcc. Compile with: bash# avr-gcc -W -Wall -O2 -mmcu=atxmega192a3 f1.c f2.c -o f.elf We need 2 files (f1.c, f2.c) to prevent optimization of the whole computation. So, it is important to keep both files separate! ---------------------------------------------------- typedef signed short int int16; typedef signed long int int32; extern void ERROR(int16 v); extern void SUCCESS(int16 v); extern int16 QUERY(void); int main() { int16 slope = 1025 + QUERY(); int16 v = (int16)( (int32)(-800) * slope / 512L ) ; // This will compute: v=31166 instead of the correct v=-1601. if(v>0) ERROR(v); else SUCCESS(v); return(0); } ------------------------------------------------------------------- ---------------------------------------------------- typedef signed short int int16; void ERROR(int16 v) { // fill in code that signals ERROR to the user or debugger breakpoint. } void SUCCESS(int16 v) { // fill in code that signals SUCCESS to the user or debug breakpoint. } int16 QUERY(void) { return(0); } --------------------------------------------------------------