Page 1 of 1

Strange Problems

Posted: 01 August 2008, 20:27 PM
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?

Posted: 02 August 2008, 9:05 AM
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

Posted: 02 August 2008, 12:07 PM
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.

Re: Strange Problems

Posted: 23 September 2008, 16:53 PM
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.

Re: Strange Problems

Posted: 23 September 2008, 19:45 PM
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.