bugAVR C Runtime Library - Bugs: bug #40003, Integer type promotion leads to...


bug #40003: Integer type promotion leads to inefficent code in wdt.h

Submitted by:  Joey Morin <joeymorin>
Submitted on:  Wed 11 Sep 2013 03:15:33 PM UTC  
Category: LibrarySeverity: 3 - Normal
Priority: 5 - NormalItem Group: Header files
Status: FixedPercent Complete: 0%
Assigned to: Pitchumani <pitchumani>Open/Closed: Open
Release: 1.8.0Fixed Release: None

Add a New Comment(Rich Markup)

You are not logged in

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


Mon 28 Apr 2014 01:40:15 PM UTC, comment #2:

committed the changes.

Pitchumani <pitchumani>
Project MemberIn charge of this item.
Wed 11 Sep 2013 03:23:28 PM UTC, comment #1:

Forgot to add an example:

In the case of wdt_enable(WDTO_15MS), the assembled output for targets such as the ATtiny85:
ldi r18, 0x08
ldi r24, 0x18
ldi r25, 0x00
in r0, 0x3f
out 0x21, r24
out 0x3f, r0
out 0x21, r18

With the patch in place:
ldi r25, 0x08
ldi r24, 0x18
in r0, 0x3f
out 0x21, r24
out 0x3f, r0
out 0x21, r25

Joey Morin <joeymorin>
Wed 11 Sep 2013 03:15:33 PM UTC, original submission:

Operands constructed in this fashion:
"r" (_BV(_WD_CHANGE_BIT) | _BV(WDE)),

...result in the use of two registers, one of which is loaded with 0x00 and never used.

Seems as though integer type promotion is responsible. A fix is as simple as casting to an 8-bit type:
"r" ((uint8_t)(_BV(_WD_CHANGE_BIT) | _BV(WDE))),

Indeed, most _asm_ statements in wdt.h are already taking this approach, but a couple are not.

Attached is a patch to resolve the issue.

I'm aware this is a minor issue, but as it is easy to resolve, I hope it will be accepted :)


Joey Morin <joeymorin>


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

Attach File(s):

Attached Files
file #29105:  wdt.h.patch added by joeymorin (802B - text/x-patch)


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -unavailable- added by pitchumani (Updated the item)
  • -unavailable- added by joeymorin (Submitted the item)

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



    Follow 4 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Mon 28 Apr 2014 01:40:15 PM UTCpitchumaniStatusConfirmed=>Fixed
    Mon 28 Apr 2014 08:21:59 AM UTCpitchumaniStatusNone=>Confirmed
      Assigned toNone=>pitchumani
    Wed 11 Sep 2013 03:15:33 PM UTCjoeymorinAttached File-=>Added wdt.h.patch, #29105

    Back to the top

    Powered by Savane 3.1-cleanup1