Tool News
 
 
 

Tool News

Products Info
Downloads
Tools FAQs
MAEC TOOL NEWS: MAECT-M3T-NC308WA-020501D

Notes on C Compilers
M3T-NC308WA, M3T-NC30WA, and M3T-NC79WA

Please take note of the following problems in using C compilers (with an assembler and integrated development environment) M3T-NC308WA, M3T-NC30WA, and M3T-NC79WA:
  • On testing bit fields in an if construct
  • On conditional expressions containing a subtraction


  1. Problem on Testing Bit Fields in an if Construct
    1.1 Products and Versions Concerned
    C compiler for the M32C/80 and M16C/80 series MCUs :
    M3T-NC308WA V.2.00 Release 1 -- V.3.10 Release 3
    C compiler for the M16C/60, M16C/30, M16C/20, and M16C/10 series MCUs :
    M3T-NC30WA V.3.20 Release 1 -- V.5.00 Release 1
    C compiler for the 79xx series MCUs :
    M3T-NC79WA V.3.20 Release 1 -- V.4.10 Release 1

    1.2 Description
    When in the conditional expression of an if construct are included two (or more) expressions that are logically ANDed one another and each of which tests a bit field, incorrect code will be generated.

    1.3 Conditions
    This problem occurs if the following six conditions are satisfied:
    (1) Optimizing option "-OR" is used along with "-O5" or "-O4".
    (2) Two (or more) expressions testing a bit field (stored in one bit) are included in the conditional expression of an if construct.
    (3) All the expressions in (2) test equality only (with operator "==").
    (4) More than one expression in (2) tests equality between a bit field and an immediate value of 1.
    (5) All the expressions in (2) are logically ANDed one another (with operator &&).
    (6) The program statement of the if construct is non or an unconditional jump.

    1.4 Example
    ---------------------------------------------------------------------
    struct bitf {
            int     b0:1;
            int     b1:1;
            int     b2:1;
    }bit;
    int i;
    void func1(void){
            if((bit.b0 == 1)&&(bit.b2 == 1)){   /* Conditions (2)--(5) */
                    ;                           /* Conditions (6) */
            }else{
                    i = 1;
            }
    }
    void func2(void){
            if((bit.b0 == 1)&&(bit.b2 == 1)){   /* Conditions (2)--(5) */
                    goto L1;                    /* Conditions (6) */
            }
            i = 1;
    L1:;
    }
    ----------------------------------------------------------------------
    1.5 Workaround
    Use option "-Ono_logical_or_combine" (-ONLOC) at compilation.

    1.6 Schedule of Fixing the Problem
    We plan to fix this problem in our next release.


    Notes on C Compilers M3T-NC308WA, M3T-NC30WA, and M3T-NC79WA
    MAECT-M3T-NC308WA-020501D

  2. Problem on conditional expressions containing a subtraction
    2.1 Product and Version Concerned
    C compiler for the M16C/60, M16C/30, M16C/20, and M16C/10 series MCUs:
    M3T-NC30WA V.5.00 Release 1

    2.2 Description
    When the result of a subtraction involving one or two variables of type unsigned is compared with 0 in a conditional expression, incorrect code will be generated.

    2.3 Conditions
    This problem occurs if the following four conditions are satisfied:
    (1) The conditional expression contains a subtraction.
    (2) The combination of minuend and subtrahend in the subtraction above is any of those, a, b, and c, shown below.

    MinuendSubtrahend
    a.VariableVariable
    b.VariableImmediate value greater than 8
    c.Immediate valueVariable
    (3) The variables in (2) are of type unsigned int or unsigned char.
    (4) The result of the subtraction is:
    1. less than 0 (< 0) or
    2. less than or equal to 0 (<= 0)

    2.4 Examples
    In Example 2 below, if the high-order bit is set to 1 by subtracting an immediate value from a variable of type unsigned, the result is interpreted as positive according to the rules of C language. Then, though the less-than-0 condition is always FALSE, it is assumed to be TRUE if the problem arises.
    ----------------------------------------------------------------------
       void func(void)
       {
               unsigned int i1,i2;             /* Condition (3)*/
               unsigned char c1;               /* Condition (3)*/
    
               //  Example 1: The program statement in TRUE executed
               i1 = 1;
               c1 = 2;
               if((i1 - c1) < 0){              /* Conditions (1)--(4)*/
                       i2 = -1;
               }else{
                       i2 = 1;
               }
    
               //  Example 2: The program statement in TRUE executed
               if((i1 - 10) < 0){              /* Conditions (1)--(4)*/
                       i2 = -1;
               }else{
                       i2 = 1;
               }
    
               //  Example 3: The program statement in TRUE executed
               i1 = 10;
               if((3 - i1) < 0){               /* Conditions (1)--(4)*/
                       i2 = -1;
               }else{
                       i2 = 1;
               }
       }
    ----------------------------------------------------------------------
    2.5 Workaround
    Cast the unsigned value(s) used in the subtraction in the conditional expression to a signed value.
    [Examples]
    ----------------------------------------------------------------------
       void func(void)
       {
               unsigned int i1,i2;
               unsigned char c1;
    
               //  Example 1:
               i1 = 1;
               c1 = 2;
               if(((int)i1 - c1) <= 0){      /* Cast to a signed value */
                       i2 = -1;
               }else{
                       i2 = 1;
               }
    
               //  Example 2:
               if(((int)i1 - 10) <= 0){      /* Cast to a signed value */
                       i2 = -1;
               }else{
                       i2 = 1;
               }
    
               //  Example 3:
               i1 = 10;
               if((3 - (int)i1) <= 0){       /* Cast to a signed value */
                       i2 = -1;
               }else{
                       i2 = 1;
               }
       }
    ----------------------------------------------------------------------
    2.6 Schedule of Fixing the Problem
    We plan to fix this problem in our next release.




© 2008. Renesas Technology Corp., All rights reserved. Privacy | Legal