Jump to content

Invalid If(...) Code Generated


Recommended Posts

Bug description:

If a conditional assignment statement is used in an if statement the code generator produces code that always executes the true condition.

 

Steps to reproduce:

I used a macro in my example but it is basically this:

if( (test_bit(protb,4)?1:0) )

 

#include <system.h>

#define SENSE_DATA()   (test_bit(portb,4) ? 1 : 0)

unsigned char Bummer(void)
{
    if(SENSE_DATA())
       return(1);
    else
    return(0);
}

unsigned char Happy(void)
{
   return(SENSE_DATA());
}

void main()
{
   while(1){
       if(Bummer()) set_bit(portb,2);  else clear_bit(portb,2);
       if(Happy()) set_bit(portb,2);  else clear_bit(portb,2);
   }
}

 

The function Bummer is compiled wrong:

 

unsigned char Bummer(void)

{
    if(SENSE_DATA())
000C  1283 	 BCF STATUS, RP0
000D  1303 	 BCF STATUS, RP1
000E  1A06 	 BTFSC gbl_portb,4
000F  2810 	 GOTO	label268436492
0010        label268436492

       return(1);
0010  3001 	 MOVLW 0x01
0011  00A0 	 MOVWF CompTempVarRet0

    else
    return(0);

}
0012  0008 	 RETURN


unsigned char Happy(void)

{
   return(SENSE_DATA());
0003  1283 	 BCF STATUS, RP0
0004  1303 	 BCF STATUS, RP1
0005  1E06 	 BTFSS gbl_portb,4
0006  280A 	 GOTO	label268436503
0007  3001 	 MOVLW 0x01
0008  00A0 	 MOVWF CompTempVarRet0
000A        label268436503
000A  01A0 	 CLRF CompTempVarRet0

}
0009  0008 	 RETURN
000B  0008 	 RETURN

 

Expected behaviour:

The skipped instruction should not jump to the next instruction.

 

Is the problem 100% reproduceable:

Yes

 

IDE version: 6.35

Compiler: BoostC

Compiler version: 6.35

Target device: PIC16F876A

OS: WinXp

 

Comments:

Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...