public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/21834] New: Error when passing unsigned long long as function arguments
@ 2005-05-31  1:22 ulyssesric at yahoo dot com dot tw
  2005-05-31  3:35 ` [Bug target/21834] " pinskia at gcc dot gnu dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: ulyssesric at yahoo dot com dot tw @ 2005-05-31  1:22 UTC (permalink / raw)
  To: gcc-bugs

I have a function that takes two usigned-long-long variables and two unsigned-char variables as 
argument.  Here is the sample code:

typedef unsigned char byte_t;
typedef unsigned long long qword_t;
void foo(
    byte_t state,
    qword_t srcAddr,
    byte_t routeOptions,
    qword_t dstAddr
) {
    ...
}
void main(void) {
    ....
    foo(0x00,0x1234ll,0x01, 0x5678ll);
    ....
}

Compiled with avr-gcc 3.4.3, for Atmega 128:

avr-gcc -mmcu=atmega128 -g -Os -Wall -Wa,-adhlns=func1.o -std=gnu99 -funsigned-char 
-funsigned-bitfields -fpack-struct -fshort-enums -ffreestanding -c func1.c -o func1.o

When I tried to check the values of variable srcAddr and dstAddr within foo() using UART, they are not 
what they should be. srcAddr is something like 0xDE00000000001A6D,  and dstAddr is 
0x7800000000000056.

However, If I change the order of these arguments to :

void foo(
    qword_t srcAddr,
    qword_t dstAddr,
    byte_t state,
    byte_t routeOptions
) {
    ...
}

and the result would be correct.

-- 
           Summary: Error when passing unsigned long long as function
                    arguments
           Product: gcc
           Version: 3.4.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ulyssesric at yahoo dot com dot tw
                CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: X86 (Linux, Win32) and PowerPC (Darwin)
GCC target triplet: AVR, Atmega128


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21834


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug target/21834] Error when passing unsigned long long as function arguments
  2005-05-31  1:22 [Bug c/21834] New: Error when passing unsigned long long as function arguments ulyssesric at yahoo dot com dot tw
@ 2005-05-31  3:35 ` pinskia at gcc dot gnu dot org
  2005-05-31  3:38 ` ulyssesric at yahoo dot com dot tw
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-31  3:35 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-05-31 02:50 -------
Did you read: <http://gcc.gnu.org/bugs.html> because it says we don't want source with "...".

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c                           |target
           Keywords|                            |wrong-code


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21834


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug target/21834] Error when passing unsigned long long as function arguments
  2005-05-31  1:22 [Bug c/21834] New: Error when passing unsigned long long as function arguments ulyssesric at yahoo dot com dot tw
  2005-05-31  3:35 ` [Bug target/21834] " pinskia at gcc dot gnu dot org
@ 2005-05-31  3:38 ` ulyssesric at yahoo dot com dot tw
  2005-05-31  3:41 ` ulyssesric at yahoo dot com dot tw
  2005-06-19 14:02 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: ulyssesric at yahoo dot com dot tw @ 2005-05-31  3:38 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From ulyssesric at yahoo dot com dot tw  2005-05-31 03:35 -------
Fine, I'll list all codes if you insist:

#include <avr/io.h>

typedef unsigned char           byte_t;
typedef unsigned long long      qword_t;

void uart_init(void)
{
    // 115200 & 8N1
    UBRR1H = 0x00;
    UBRR1L = 0x08;
    UCSR1A |= (0x01<<U2X1);
    UCSR1C = 0x06;
    UCSR1B &= ~0x04;
    UCSR1B |= ((0x01<<RXEN1) | (0x01<<TXEN1));
}

void uart_putchar(byte_t octet)
{
    UDR1 = octet;
    while (!(UCSR1A & (0x01<<UDRE1)));
}

void uart_write(byte_t *octet, uint8_t len)
{
    while (len--) {
        UDR1 = *octet++;
        while (!(UCSR1A & (0x01<<UDRE1)));
    }
}

void foo( byte_t state, qword_t srcAddr, byte_t routeOptions, qword_t dstAddr )
{
    uart_putchar(state);
    uart_write((byte_t *)(&srcAddr),8);
    uart_putchar(routeOptions);
    uart_write((byte_t *)(&dstAddr),8);
}

void main(void) {
    uart_init();
    foo(0x00,0x1234ll,0x01, 0x5678ll);
    while(1);
}

and the output is:

D1,
34,12,D1,D1,D1,D1,D1,D1,
01,
AB,CD,00,CF,00,80,00,78

in hexdecimal format. Obviously it's incorrect.

If I change the code to:

#include <avr/io.h>

typedef unsigned char           byte_t;
typedef unsigned long long      qword_t;

void uart_init(void)
{
    // 115200 & 8N1
    UBRR1H = 0x00;
    UBRR1L = 0x08;
    UCSR1A |= (0x01<<U2X1);
    UCSR1C = 0x06;
    UCSR1B &= ~0x04;
    UCSR1B |= ((0x01<<RXEN1) | (0x01<<TXEN1));
}

void uart_putchar(byte_t octet)
{
    UDR1 = octet;
    while (!(UCSR1A & (0x01<<UDRE1)));
}

void uart_write(byte_t *octet, uint8_t len)
{
    while (len--) {
        UDR1 = *octet++;
        while (!(UCSR1A & (0x01<<UDRE1)));
    }
}

void foo( qword_t srcAddr, qword_t dstAddr, byte_t state, byte_t routeOptions )
{
    uart_putchar(state);
    uart_write((byte_t *)(&srcAddr),8);
    uart_putchar(routeOptions);
    uart_write((byte_t *)(&dstAddr),8);
}

void main(void) {
    uart_init();
    foo(0x1234ll,0x5678ll,0x00,0x01);
    while(1);
}

And the output will be:

00,
34,12,00,00,00,00,00,00,
01,
78,56,00,00,00,00,00,00

Compiling Procedure:

avr-gcc -mmcu=atmega128 -g -Os -Wall -Wa,-adhlns=main.lst -std=gnu99 -funsigned-char 
-funsigned-bitfields -fpack-struct -fshort-enums -ffreestanding -Wl,-Map=main.map -Wl,--cref  
main.c -o main.elf
avr-objcopy -O ihex -R .eeprom test.elf test.hex
avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 
-O ihex test.elf test.eep
avr-objdump -h -S test.elf > test.lss
avr-nm -n test.elf > test.sym

Programming with AVR Studio 4.11 build 401, JTAGICE mkII


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21834


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug target/21834] Error when passing unsigned long long as function arguments
  2005-05-31  1:22 [Bug c/21834] New: Error when passing unsigned long long as function arguments ulyssesric at yahoo dot com dot tw
  2005-05-31  3:35 ` [Bug target/21834] " pinskia at gcc dot gnu dot org
  2005-05-31  3:38 ` ulyssesric at yahoo dot com dot tw
@ 2005-05-31  3:41 ` ulyssesric at yahoo dot com dot tw
  2005-06-19 14:02 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: ulyssesric at yahoo dot com dot tw @ 2005-05-31  3:41 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From ulyssesric at yahoo dot com dot tw  2005-05-31 03:38 -------
Sorry, typo. Compile Procedure:

avr-gcc -mmcu=atmega128 -g -Os -Wall -Wa,-adhlns=test.lst -std=gnu99 -funsigned-char 
-funsigned-bitfields -fpack-struct -fshort-enums -ffreestanding -Wl,-Map=test.map -Wl,--cref  test.c 
-o test.elf
avr-objcopy -O ihex -R .eeprom test.elf test.hex
avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 
-O ihex test.elf test.eep
avr-objdump -h -S test.elf > test.lss
avr-nm -n test.elf > test.sym


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21834


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug target/21834] Error when passing unsigned long long as function arguments
  2005-05-31  1:22 [Bug c/21834] New: Error when passing unsigned long long as function arguments ulyssesric at yahoo dot com dot tw
                   ` (2 preceding siblings ...)
  2005-05-31  3:41 ` ulyssesric at yahoo dot com dot tw
@ 2005-06-19 14:02 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-06-19 14:02 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
   GCC host triplet|X86 (Linux, Win32) and      |
                   |PowerPC (Darwin)            |
           Keywords|                            |ABI


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21834


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-06-19 14:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-31  1:22 [Bug c/21834] New: Error when passing unsigned long long as function arguments ulyssesric at yahoo dot com dot tw
2005-05-31  3:35 ` [Bug target/21834] " pinskia at gcc dot gnu dot org
2005-05-31  3:38 ` ulyssesric at yahoo dot com dot tw
2005-05-31  3:41 ` ulyssesric at yahoo dot com dot tw
2005-06-19 14:02 ` pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).