bugAVR C Runtime Library - Bugs: bug #39875, Warning 1 unused variable...

 
 

bug #39875: Warning 1 unused variable '__ticks' [-Wunused-variable] C:\PROGRA~2\Atmel\ATMELT~1\AVR8GC~1\Native\342~1.939\AVR8-G~1\av

Submitted by:  None
Submitted on:  Tue 27 Aug 2013 06:01:43 AM UTC  
 
Category: LibrarySeverity: 3 - Normal
Priority: 5 - NormalItem Group: libc code
Status: Need InfoPercent Complete: 0%
Assigned to: NoneOriginator Email: -unavailable-
Open/Closed: OpenRelease: 1.8.0
Fixed Release: None

Add a New Comment (Rich MarkupRich Markup):
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Tue 27 Aug 2013 11:22:23 AM UTC, comment #2:

I did see #38904, and I thought that this was different. In my experience, if there is any mystery about the "may be used uninitialized" error mentioned in #38904, then it is often caused by an unexpected interaction with a macro. The OP might want to take a look at the preprocessor expansion in the listing file.

The fix that I suggested below does get rid of the "unused variable" warning message from the compiler. I don't think that the change would have any effect on #38904. It seems to me that the bug that I'm complaining about is a simple oversight and who ever introduced the bug failed to test both code paths of the preprocessor conditional.

Mike Ady <farquahrsen>
Tue 27 Aug 2013 06:23:11 AM UTC, comment #1:

I think this is a duplicate for bug #38904, even though the
warning message is different.

What do you think about it?

Joerg Wunsch <joerg_wunsch>
Project Administrator
Tue 27 Aug 2013 06:01:43 AM UTC, original submission:

_delay_ms has the following definition:

void
_delay_ms(double __ms)
{
uint16_t __ticks;
double __tmp ;
#if _HAS_DELAY_CYCLES && defined(__OPTIMIZE_) && \
!defined(_DELAY_BACKWARD_COMPATIBLE_) && \
_STDC_HOSTED_
uint32_t __ticks_dc;
extern void __builtin_avr_delay_cycles(unsigned long);
__tmp = ((F_CPU) / 1e3) * __ms;

#if defined(_DELAY_ROUND_DOWN_)
__ticks_dc = (uint32_t)fabs(__tmp);

#elif defined(_DELAY_ROUND_CLOSEST_)
__ticks_dc = (uint32_t)(fabs(__tmp)+0.5);

#else
//round up by default
__ticks_dc = (uint32_t)(ceil(fabs(__tmp)));
#endif

__builtin_avr_delay_cycles(__ticks_dc);

#else
__tmp = ((F_CPU) / 4e3) * __ms;
if (__tmp < 1.0)
__ticks = 1;
else if (__tmp > 65535)
{
// __ticks = requested delay in 1/10 ms
__ticks = (uint16_t) (__ms * 10.0);
while(__ticks)
{
// wait 1/10 ms
_delay_loop_2(((F_CPU) / 4e3) / 10);
__ticks --;
}
return;
}
else
__ticks = (uint16_t)__tmp;
_delay_loop_2(__ticks);
#endif
}

If it is possible for the first half of the conditional to be true (it was for me) then the definitions of _delay_ms and _delay_us are obviously incorrect. (__ticks is not referenced before the #else clause.) I suggest moving the declaration of __ticks to the #else clause, as follows:

void
_delay_ms(double __ms)
{
double __tmp ;
#if _HAS_DELAY_CYCLES && defined(__OPTIMIZE_) && \
!defined(_DELAY_BACKWARD_COMPATIBLE_) && \
_STDC_HOSTED_
uint32_t __ticks_dc;
extern void __builtin_avr_delay_cycles(unsigned long);
__tmp = ((F_CPU) / 1e3) * __ms;

#if defined(_DELAY_ROUND_DOWN_)
__ticks_dc = (uint32_t)fabs(__tmp);

#elif defined(_DELAY_ROUND_CLOSEST_)
__ticks_dc = (uint32_t)(fabs(__tmp)+0.5);

#else
//round up by default
__ticks_dc = (uint32_t)(ceil(fabs(__tmp)));
#endif

__builtin_avr_delay_cycles(__ticks_dc);

#else
uint16_t __ticks;

__tmp = ((F_CPU) / 4e3) * __ms;
if (__tmp < 1.0)
__ticks = 1;
else if (__tmp > 65535)
{
// __ticks = requested delay in 1/10 ms
__ticks = (uint16_t) (__ms * 10.0);
while(__ticks)
{
// wait 1/10 ms
_delay_loop_2(((F_CPU) / 4e3) / 10);
__ticks --;
}
return;
}
else
__ticks = (uint16_t)__tmp;
_delay_loop_2(__ticks);
#endif
}

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by farquahrsen (Posted a comment)
  • -unavailable- added by joerg_wunsch (Posted a comment)
  • -unavailable- added by None (Submitted the item)
  •  

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 2 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Tue 27 Aug 2013 06:23:11 AM UTCjoerg_wunschStatusNone=>Need Info
      SummaryWarning 1 unused variable \'__ticks\' [-Wunused-variable] C:\\PROGRA~2\\Atmel\\ATMELT~1\\AVR8GC~1\\Native\\342~1.939\\AVR8-G~1\\av=>Warning 1 unused variable '__ticks' [-Wunused-variable] C:\PROGRA~2\Atmel\ATMELT~1\AVR8GC~1\Native\342~1.939\AVR8-G~1\av

    Back to the top


    Powered by Savane 3.1-cleanup