Tool News
 
 
 

Tool News

Products Info
Downloads
Tools FAQs
MAEC TOOL NEWS: MAECT-CC32R-010816D

CC32R
Precaution

Please take note of the following problems in using cross-tool kit CC32R for the M32R family MCUs:
  • On optimization at accessing a volatile area two or more times successively
  • On optimization at using uninitialized pointers


  1. Versions Concerned
    CC32R V.1.00 Release 1 -- V.3.00 Release 1


  2. Problem on Accessing a "volatile" Area Two or More Times Successively
    2.1 Description
    If a volatile area is accessed two or more times successively by using the same offset operation, optimization covering the -04 option makes the volatile attribute ineffective.

    2.2 Conditions
    This problem occurs if the following four conditions are satisfied:
    (1) An optimizing option covering -O4 is used (that is, any of the following options is used; -O4, -O5, -O6, -O7, -Otime only and -Ospace only).
    (2) Any of the following variables is declared to be volatile (excluding bit fields):
    (a) a member of a structure or union
    (b) a member of an array
    (c) a portion represented by a pointer plus offset value
    (3) An area including a variable in (2) above is accessed two or more times successively.
    (4) During the successive accesses in (3) above, no function call or no indirect assignment using pointers is performed.

    2.3 Examples
    [Example 1: Source file "sample1.c"]
    --------------------------------------------------------------------
     extern volatile unsigned short  v_array[];  /* Condition 2-(b) */
     void foo(void)
     {
          while (v_array[7] & 4);        /* Condition 3 */
                                         /* Condition 4 */
          while (!(v_array[7] & 4));     /* Condition 3 */
     }
    --------------------------------------------------------------------
    
    [Example 2: Source file "sample2.c"]
    --------------------------------------------------------------------
     extern volatile struct {            /* Condition 2-(a) */
         int   a;
         int   b;
     } v_strarea;
     void foo(void)
     {
          while (v_strarea.a & 4);       /* Condition 3 */
                                         /* Condition 4 */
          while (!(v_strarea.a & 4));    /* Condition 3 */
     }
    --------------------------------------------------------------------
    
    [Example 3: Source file "sample3.c"]
    --------------------------------------------------------------------
     extern volatile long *v_ptr;        /* Condition 2-(c) */
     int foo(void)
     {
         int     answer;
         answer  = (*(v_ptr + 7) & 4);   /* Condition 3 */
                                         /* Condition 4 */
         answer  *= (*(v_ptr + 7) & 8);  /* Condition 3 */
         return  answer;
     }
    --------------------------------------------------------------------
    
    [Examples of typing commands in CC32R (a % sign denotes a prompt)]
    --------------------------------------------------------------------
     % cc32R -c -O4 sample1.c
     % cc32R -c -O4 sample2.c
     % cc32R -c -O4 sample3.c
    --------------------------------------------------------------------
    2.4 Workaround
    This problem will be circumvented in any of the following ways:
    (1) Suppress optimization in the -O4 level.
    Optimization covering the -O4 option is performed when optimizing option -O4, -O5, -O6, -O7, -Otime only or -Ospace only has been selected. If you want to use -Otime or -Ospace, select any of those options, -O3, -O2, -O1, and -O0, at the same time.
    (2) Access the volatile area by using a pointer of type volatile.
    [Example 1 (modified): Source file "sample1.c"]
    -----------------------------------------------------------------
     extern volatile unsigned short  v_array[];
     void foo(void)
     {
         volatile unsigned short   *ptr = &v_array[7];
         while (*ptr & 4);
         while (!(*ptr & 4));
     }
    -----------------------------------------------------------------
    
    [Example 2 (modified): Source file "sample2.c"]
    -----------------------------------------------------------------
     extern volatile struct s_tag {
         int   a;
         int   b;
     } v_strarea;
     void foo(void)
     {
          volatile int *ptr = &v_strarea.a;
          while (*ptr & 4);
    
          while (!(*ptr & 4));
     }
    -----------------------------------------------------------------
    
    [Example 3 (modified): Source file "sample3.c"
    -----------------------------------------------------------------
     extern volatile long *v_ptr;
     int foo(void)
     {
         int     answer;
         volatile long *ptr = v_ptr + 7;
         answer  = (*ptr & 4);
    
         answer  *= (*ptr & 8);
         return  answer;
     }
    -----------------------------------------------------------------
    (3) Replace the volatile area with an equivalent bit field.
    [Example 1 (modified): Source file "sample1.c"]
    -----------------------------------------------------------------
     extern volatile struct {
                 unsigned short u16:16;
     } v_array[];
     void foo(void)
     {
          while (v_array[7].u16 & 4);
    
          while (!(v_array[7].u16 & 4));
     }
    -----------------------------------------------------------------



    CC32R Precaution
    MAECT-CC32R-010816D

  3. Problem on Using Uninitialized Pointers
    3.1 Description
    When optimization covering the -O4 option is performed for a program in which uninitialized pointers are used, the compiler may fall into an endless loop and not be able to terminate compilation.

    3.2 Conditions
    This problem occurs if the following six conditions are satisfied:
    (1) An optimizing option covering -O4 is used (that is, any of the following options is used; -O4, -O5, -O6, -O7, -Otime only and -Ospace only).
    (2) There exist pointers A and B, which are auto variables.
    (3) There exists a loop statement, and before it is placed either of the following statements:
    (a) an "if" statement, where if the result of the evaluation of the conditional expression is TRUE, an assignment is made to A; if FALSE, no assignment is made.
    (b) a "for" or "while" statement, which contains an assignment expression to A.
    (4) An "if-else" construct is included in the loop in (3), and the value of pointer A is assigned to pointer B in the program statement of "else".
    (5) Until pointer A is referenced in (4), there exists no assignment expression to pointer A except the one in (3)-(a) or -(b).
    (6) There exists no assignment expression to pointer B except the one in (4).

    3.3 Examples
    [Example 1: Source file "sample1.c"]
    --------------------------------------------------------------------
    int     check1, check2;
    
    void
    func(void)
    {
            int     *ptr_A;         /* Pointer A */ /* Condition 2 */
            int     *ptr_B;         /* Pointer B */ /* Condition 2 */
            int     i;
    
            if (check1) {                          /* Condition 3-(a) */
                    ptr_A = 0;                     /* Condition 3-(a) */
            }                                      /* Condition 3-(a) */
    
            for (i = 0; i < 20; i++) {
                    if (check2) {
    
                    } else {
                            ptr_B = ptr_A;         /* Conditions 4, 5 */
                    }
            }
    }
    --------------------------------------------------------------------
    
    [Example 2: Source file "sample2.c"]
    --------------------------------------------------------------------
    int     check1, check2;
    
    void
    func(void)
    {
            int     *ptr_A;         /* Pointer A */ /* Condition 2 */
            int     **ptr_B;        /* Pointer B */ /* Condition 2 */
            int     i;
    
            while (check1) {
                    ptr_A = 0;                   /* Condition 3-(b) */
            }
                    :
            for (i = 0; i < 20; i++) {
                    if (check2) {
                        :
                    } else {
                            ptr_B = (int**)*ptr_A;  /* Conditions 4, 5 */
                    }
            }
    }
    --------------------------------------------------------------------
    
    [Examples of typing commands in CC32R (a % sign denotes a prompt)]
    --------------------------------------------------------------------
    % cc32R -c -O4 sample1.c
    % cc32R -c -O4 sample2.c
    --------------------------------------------------------------------
    3.4 Workaround
    This problem will be circumvented in either of the following ways:
    (1) Suppress optimization in the -O4 level.
    Optimization covering the -O4 option is performed when optimizing option -O4, -O5, -O6, -O7, -Otime only or -Ospace only has been selected. If you want to use -Otime or -Ospace, select any of those options, -O3, -O2, -O1, and -O0, at the same time.
    (2) Initialize pointer A
    Add a code that is sure to initialize pointer A according to the example shown below.
    [Example 1 (modified): Source file "sample1.c"]
    ---------------------------------------------------------------
        int     *ptr_A;
                |
        int     *ptr_A = 0;
    ---------------------------------------------------------------
    Modify Example 2 above by initializing pointer A in the same way.






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