[bug #56093] Wrong constraint in pgmspace.h::pgm_get_far_address

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

[bug #56093] Wrong constraint in pgmspace.h::pgm_get_far_address

Kevin Cuzner-2

                 Summary: Wrong constraint in pgmspace.h::pgm_get_far_address
                 Project: AVR C Runtime Library
            Submitted by: gjlayde
            Submitted on: Sun 07 Apr 2019 01:00:58 PM UTC
                Category: Header
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Header files
                  Status: None
        Percent Complete: 0%
             Assigned to: None
        Originator Email:
             Open/Closed: Open
         Discussion Lock: Any
                 Release: 2.0.0
           Fixed Release: None



Macro pgm_get_far_address() from avr/pgmspace.h has a wrong constraint for
operand %1: Is must be "ni" (known at compile-time (n) or known ar assembly
time or later (i)) instead of "p".

Moreover, the asm is not volatile, hence the "volatile" can be dropped.

The "tmp" should also be recplaced by an identifier from implementation space
like __tmp.

Last not least, the macro should come with "extension" so that it will work in
strict C mode (and not only with GNU-C which valued blocks are).

Putting everything together, the macro should read

#define pgm_get_far_address(var)                      \
(__extension__({                                      \
    uint_farptr_t __tmp;                              \
    __asm__ (                                         \
            "ldi    %A0, lo8(%1)"           "\n\t"    \
            "ldi    %B0, hi8(%1)"           "\n\t"    \
            "ldi    %C0, hh8(%1)"           "\n\t"    \
            "clr    %D0"                    "\n\t"    \
        : "=d" (__tmp)                                \
        : "ni" (&(var))                               \
    );                                                \
    __tmp;                                            \


Reply to this item at:


  Message sent via Savannah

AVR-libc-dev mailing list
[hidden email]