Forum Index
Strange Problems

 
Author Message
mikep



Joined: 24 Sep 2005
Location: Austin, TX

Posted: 02 August 2008, 3:27 AM    Post subject: Strange Problems

I am seeing some strange problems with some of my native mode code. Here are two examples:

1. Doesn't Work
Code:
      If msgTotal = 0 And previousMsgTotal <> 0 Then
            ' do work
      End If
Works
Code:
      If msgTotal = 0 Then
         If previousMsgTotal <> 0 Then
            ' do work
            End If
      End If

2. Doesn't Work
Code:
      If seqNumber <> 0 Then
         packet(2) = controllerType
         packet(4) = HiByte(seqNumber)
         'Debug.Print CStrHex(seqNumber); " Sent"          
         packet(5) = LoByte(seqNumber)
         Call sendPayload(packet, 5)
      End If
Works
Code:
      If seqNumber <> 0 Then
         packet(2) = controllerType
         packet(4) = HiByte(seqNumber)
         Debug.Print CStrHex(seqNumber); " Sent"          
         packet(5) = LoByte(seqNumber)
         Call sendPayload(packet, 5)
      End If
In this second example if the Debug statement is commented out then the whole block is not executed. If the Debug statement is moved down a couple of lines then the whole block is not executed.

The generated code looks ok. The stack all seems ok. Trying to generate a simpler example is unsuccessful. It seems like this could be the GCC compiler. I have seen it generate "over-optimized" code before. Has anyone else seen "inexplicable" problems like this?
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Location: Portland, OR

Posted: 02 August 2008, 16:05 PM    Post subject:

I've seen discussion of over-aggressive optimization on the AVR Freaks list but I've never observed it myself. It is difficult to diagnose the actual problem without a test case that exhibits the problem.

You mentioned that the generated C code looks OK so it is unlikely to be a ZBasic optimization problem. You can add an option to your .pjt file to see if it is a gcc optimization problem. For example, to turn off all optimization by the gcc back end, use the sequence below. The options that you specify are placed on the gcc compiler invocation line after all "standard" options.
Code:
--gcc-opts=-O0
Back to top
mikep



Joined: 24 Sep 2005
Location: Austin, TX

Posted: 02 August 2008, 19:07 PM    Post subject:

dkinzer wrote:
You can add an option to your .pjt file to see if it is a gcc optimization problem.
I turned off GCC compiler optimization and tried example 1 again. Unfortunately it still fails so I'm going to have to investigation further.
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Location: Portland, OR

Posted: 23 September 2008, 23:53 PM    Post subject: Re: Strange Problems

mikep wrote:
I am seeing some strange problems with some of my native mode code.
This problem was determined to be caused by incorrect code being generated (native mode only). A new version of the compiler has been posted (see the announcement at the top of this forum) that corrects the deficiency.
Back to top
mikep



Joined: 24 Sep 2005
Location: Austin, TX

Posted: 24 September 2008, 2:45 AM    Post subject: Re: Strange Problems

dkinzer wrote:
This problem was determined to be caused by incorrect code being generated (native mode only). A new version of the compiler has been posted (see the announcement at the top of this forum) that corrects the deficiency.
To be exact, the new version of the compiler (2.6.1) resolves problem 1 as reported in this thread. Problem 2 may or may not still exist. For now let's close this thread and I will start a new one when I can find code that reproduces problem 2.
Back to top
Display posts from previous:   
Page 1 of 1

 



ZBasic Microcontrollers Home
All content Copyright © 2005, 2006, 2007, 2008 Elba Corp. All Rights Reserved.
Opinions expressed in posts are those of the author and not necessarily those of Elba Corp.
Powered by phpBB © 2001, 2005 phpBB Group