Strange Problems

Discussion of issues related specifically to writing code for native mode devices. This includes ZBasic code as well as assembly language code and C code, both inline and standalone.
Post Reply
mikep
Posts: 796
Joined: 24 September 2005, 15:54 PM

Strange Problems

Post by mikep »

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

1. Doesn't Work

Code: Select all

		If msgTotal = 0 And previousMsgTotal <> 0 Then
				' do work
		End If
Works

Code: Select all

		If msgTotal = 0 Then
			If previousMsgTotal <> 0 Then
				' do work
				End If
		End If
2. Doesn't Work

Code: Select all

		If seqNumber <> 0 Then
			packet&#40;2&#41; = controllerType
			packet&#40;4&#41; = HiByte&#40;seqNumber&#41;
			'Debug.Print CStrHex&#40;seqNumber&#41;; " Sent" 			
			packet&#40;5&#41; = LoByte&#40;seqNumber&#41;
			Call sendPayload&#40;packet, 5&#41;
		End If
Works

Code: Select all

		If seqNumber <> 0 Then
			packet&#40;2&#41; = controllerType
			packet&#40;4&#41; = HiByte&#40;seqNumber&#41;
			Debug.Print CStrHex&#40;seqNumber&#41;; " Sent" 			
			packet&#40;5&#41; = LoByte&#40;seqNumber&#41;
			Call sendPayload&#40;packet, 5&#41;
		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?
Mike Perks
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

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: Select all

--gcc-opts=-O0
- Don Kinzer
mikep
Posts: 796
Joined: 24 September 2005, 15:54 PM

Post by mikep »

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.
Mike Perks
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: Strange Problems

Post by dkinzer »

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.
- Don Kinzer
mikep
Posts: 796
Joined: 24 September 2005, 15:54 PM

Re: Strange Problems

Post by mikep »

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.
Mike Perks
Post Reply