Size cast errors in the AVR port Topic is solved

ChibiOS public support forum for topics related to the Atmel AVR family of micro-controllers.

Moderators: utzig, tfAteba

User avatar
igor
Posts: 50
Joined: Sun Aug 16, 2015 7:24 pm
Location: Helsinki, Finland
Has thanked: 1 time

Size cast errors in the AVR port

Postby igor » Tue Oct 25, 2016 4:57 pm

Hi,
I added -Werror to the Makefile and I noticed these (I'm building for 328p):

Compiling C: ../ChibiOS/os/rt/src/chstats.c
avr-gcc -c -mmcu=atmega328p -I. -gdwarf-2 -DF_CPU=16000000UL -O2 -funsigned-char -fdata-sections -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wundef -Werror -Wunreachable-code -Wsign-compare -Wa,-adhlns=./../ChibiOS/os/rt/src/chstats.lst -I../ChibiOS/os/common/ports/AVR -I../ChibiOS/os/common/ports/AVR/compilers/GCC -I../ChibiOS/os/rt/include -I../ChibiOS/os/common/oslib/include -I../ChibiOS/os/hal/include -I../ChibiOS/os/hal/osal/rt -I../ChibiOS/os/hal/ports/AVR -I../ChibiOS/os/hal/boards/SPARKFUN_PRO_MICRO -I../ChibiOS/os/license -I../ChibiOS/os/various -I../lib -I../lib/motors -std=gnu11 -MMD -MP -MF .dep/chstats.o.d ../ChibiOS/os/rt/src/chstats.c -o ../ChibiOS/os/rt/src/chstats.o
In file included from ../ChibiOS/os/rt/include/ch.h:81:0,
from ../ChibiOS/os/rt/src/chthreads.c:51:
../ChibiOS/os/rt/src/chthreads.c: In function 'chThdCreateSuspendedI':
../ChibiOS/os/common/ports/AVR/chcore.h:265:21: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
tp->ctx.sp->r2 = (uint8_t)(pf); \
^
../ChibiOS/os/rt/src/chthreads.c:190:3: note: in expansion of macro 'PORT_SETUP_CONTEXT'
PORT_SETUP_CONTEXT(tp, tdp->wbase, tp, tdp->funcp, tdp->arg);
^
../ChibiOS/os/common/ports/AVR/chcore.h:267:21: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
tp->ctx.sp->r4 = (uint8_t)(arg); \
^
../ChibiOS/os/rt/src/chthreads.c:190:3: note: in expansion of macro 'PORT_SETUP_CONTEXT'
PORT_SETUP_CONTEXT(tp, tdp->wbase, tp, tdp->funcp, tdp->arg);
^
../ChibiOS/os/common/ports/AVR/chcore.h:270:21: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
tp->ctx.sp->pch = (uint8_t)_port_thread_start; \
^
../ChibiOS/os/rt/src/chthreads.c:190:3: note: in expansion of macro 'PORT_SETUP_CONTEXT'
PORT_SETUP_CONTEXT(tp, tdp->wbase, tp, tdp->funcp, tdp->arg);
^
../ChibiOS/os/rt/src/chthreads.c: In function 'chThdCreateStatic':
../ChibiOS/os/common/ports/AVR/chcore.h:265:21: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
tp->ctx.sp->r2 = (uint8_t)(pf); \
^
../ChibiOS/os/rt/src/chthreads.c:358:3: note: in expansion of macro 'PORT_SETUP_CONTEXT'
PORT_SETUP_CONTEXT(tp, wsp, tp, pf, arg);
^
../ChibiOS/os/common/ports/AVR/chcore.h:267:21: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
tp->ctx.sp->r4 = (uint8_t)(arg); \
^
../ChibiOS/os/rt/src/chthreads.c:358:3: note: in expansion of macro 'PORT_SETUP_CONTEXT'
PORT_SETUP_CONTEXT(tp, wsp, tp, pf, arg);
^
../ChibiOS/os/common/ports/AVR/chcore.h:270:21: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
tp->ctx.sp->pch = (uint8_t)_port_thread_start; \
^
../ChibiOS/os/rt/src/chthreads.c:358:3: note: in expansion of macro 'PORT_SETUP_CONTEXT'
PORT_SETUP_CONTEXT(tp, wsp, tp, pf, arg);
^


Assuming the upper byte is empty and can be disregarded, this patch fixes the warning.
Attachments
cast_warning.zip
(1.01 KiB) Downloaded 69 times

User avatar
tfAteba
Posts: 526
Joined: Fri Oct 16, 2015 11:03 pm
Location: Chartres, France
Has thanked: 80 times
Been thanked: 46 times

Re: Size cast errors in the AVR port

Postby tfAteba » Tue Oct 25, 2016 7:14 pm

Hi,

Just a confirmation, that I have the same warning, when I use trunk to build for MEGA2560.

But the warning disappear when I use ChibiOS_16.1.5.
regards,

Theo.

utzig
Posts: 355
Joined: Sat Jan 07, 2012 6:22 pm
Location: Brazil
Has thanked: 1 time
Been thanked: 19 times
Contact:

Re: Size cast errors in the AVR port

Postby utzig » Tue Oct 25, 2016 8:35 pm

Patch applied! Btw, it only fixes the warnings for two-byte sized PC AVRs (which excludes basically the ATmega2560). I will check that one tomorrow and re-apply the changes on it.

Cheers,
Fabio Utzig

User avatar
igor
Posts: 50
Joined: Sun Aug 16, 2015 7:24 pm
Location: Helsinki, Finland
Has thanked: 1 time

Re: Size cast errors in the AVR port

Postby igor » Wed Oct 26, 2016 12:56 am

utzig wrote:Patch applied! Btw, it only fixes the warnings for two-byte sized PC AVRs (which excludes basically the ATmega2560). I will check that one tomorrow and re-apply the changes on it.

Cheers,
Fabio Utzig


Yes, probably I left that out, sorry. As I wrote in another post, I use only 328p, so that's the only target I could test.

User avatar
tfAteba
Posts: 526
Joined: Fri Oct 16, 2015 11:03 pm
Location: Chartres, France
Has thanked: 80 times
Been thanked: 46 times

Re: Size cast errors in the AVR port

Postby tfAteba » Wed Oct 26, 2016 3:44 pm

Hi Igor,

Don't worry, I will also test on mega2560 when changes will be made.
regards,

Theo.

utzig
Posts: 355
Joined: Sat Jan 07, 2012 6:22 pm
Location: Brazil
Has thanked: 1 time
Been thanked: 19 times
Contact:

Re: Size cast errors in the AVR port

Postby utzig » Thu Oct 27, 2016 5:10 pm

I applied the changes also for 3-byte PC models (aka ATmega2560).

User avatar
tfAteba
Posts: 526
Joined: Fri Oct 16, 2015 11:03 pm
Location: Chartres, France
Has thanked: 80 times
Been thanked: 46 times

Re: Size cast errors in the AVR port  Topic is solved

Postby tfAteba » Thu Oct 27, 2016 10:16 pm

Hi,

I just made the test with my arduino mega (2560), every thing is fine for me.

Thanks the great job :) .
regards,

Theo.


Return to “AVR Support”

Who is online

Users browsing this forum: No registered users and 2 guests