 |
|
 |
MAEC TOOL NEWS:
MAECT-CC32R-010916D
Please take note of the following problem in using cross-tool kit CC32R for the M32R family MCUs:
- On optimization at accessing an area declared to be both const and volatile two or more times successively
- Versions Concerned
CC32R V.1.00 Release 1 -- V.3.00 Release 1
- Description
If an area of type const and volatile is accessed two or more times successively using the same offset operation, optimization covering the -O4 option may result in an internal error.
- 2.1 Conditions
- This problem occurs if the following five 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 both const and volatile (excluding bit fields):
- (a) a member of a structure or union
- (b) a member of an array
- (c) an area pointed to 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.
- (5) Expressions for successive accesses in (3) above include a common term standing for only a const and volatile area.
- [Examples]
- When array "a" is of type const and volatile,
- expressions a[5] + 3 and a[5] + 4 satisfy Condition (5) because only the term standing for an area a[5] is common to these expressions, while expressions a[5] + 3 and a[5] + 3 do not because the one standing for an area plus offset a[5] + 3 is common.
- [NOTICE]
- Even if all the above conditions except (5) are satisfied, the problem "On Accessing a Volatile Area Two or More Times Successively" will occur, which was notified in MAEC TOOL NEWS "CC32R Precaution" issued on August 16, 2001 (MAECT-CC32R-010816D).
- 2.2 Examples
Example 1: Source file "sample1.c"
-----------------------------------------------------------------------
extern const volatile struct {
int a;
int b;
} v_strarea;
void foo(void)
{
while (v_strarea.a & 4); /* Conditions (2)-(a), (3) and (5) */
/* Condition (4) */
while (!(v_strarea.a & 8)); /* Conditions (2)-(a), (3) and (5) */
}
-----------------------------------------------------------------------
Example 2: Source file "sample2.c"
-----------------------------------------------------------------------
extern const volatile unsigned short v_array[];
void foo(void)
{
while (v_array[7] & 4); /* Conditions (2)-(b), (3) and (5) */
/* Condition (4) */
while (!(v_array[7] & 8)); /* Conditions (2)-(b), (3) and (5) */
}
-----------------------------------------------------------------------
Example 3: Source file "sample3.c"
-----------------------------------------------------------------------
extern const volatile long *v_ptr;
int foo(void)
{
int answer;
answer = (*(v_ptr + 7) & 4); /* Conditions (2)-(c), (3) and (5) */
/* Condition (4) */
answer *= (*(v_ptr + 7) & 8); /* Conditions (2)-(c), (3) and (5) */
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
-----------------------------------------------------------------------
- Workaround
- This problem will be circumvented in any of the following ways:
- (1) Suppress optimization in -O4's 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 area concerned by using a pointer of type volatile.
Example 1 (modified): Source file "sample1.c"
------------------------------------------------------------------------
extern const volatile struct s_tag {
int a;
int b;
} v_strarea;
void foo(void)
{
const volatile int *ptr = &v_strarea.a;
while (*ptr & 4);
while (!(*ptr & 8));
}
-----------------------------------------------------------------------
Example 2 (modified): Source file "sample2.c"
-----------------------------------------------------------------------
extern const volatile unsigned short v_array[];
void
foo(void)
{
const volatile unsigned short *ptr = &v_array[7];
while (*ptr & 4);
while (!(*ptr & 8));
}
-----------------------------------------------------------------------
Example 3 (modified): Source file "sample3.c"
-----------------------------------------------------------------------
extern const volatile long *v_ptr;
int foo(void)
{
int answer;
const volatile long *ptr = v_ptr + 7;
answer = (*ptr & 4);
answer *= (*ptr & 8);
return answer;
}
-----------------------------------------------------------------------
|
 |