[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

Georg-Johann Lay-3
URL:
  <https://savannah.nongnu.org/bugs/?56093>

                 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

    _______________________________________________________

Details:

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:

  <https://savannah.nongnu.org/bugs/?56093>

_______________________________________________
  Message sent via Savannah
  https://savannah.nongnu.org/


_______________________________________________
AVR-libc-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/avr-libc-dev