From: Michel Pollet Date: Fri, 25 May 2012 12:55:11 +0000 (+0100) Subject: clang: Fixes of warning and nasty bugs X-Git-Tag: v1.0~117 X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=b73f9b6094e2c9639fded52022ec60556ae8f8de;p=sx%2Fsimavr.git clang: Fixes of warning and nasty bugs XCode 4.3 & clang fixes. Should also apply to BSD Found a nasty bug in clang with sign bit propagation Signed-off-by: Michel Pollet --- diff --git a/Makefile.common b/Makefile.common index 23dddec..d219b96 100644 --- a/Makefile.common +++ b/Makefile.common @@ -36,6 +36,8 @@ CFLAGS += -msse2 endif ifeq (${shell uname}, Darwin) +# gcc 4.2 from MacOS is really not up to scratch anymore +CC = clang AVR_ROOT := "/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/" AVR_INC := ${AVR_ROOT}/avr-4/ AVR := ${AVR_ROOT}/bin/avr- @@ -56,7 +58,7 @@ CPPFLAGS += ${patsubst %,-I%,${subst :, ,${IPATH}}} AVR_CPPFLAGS= ${CPPFLAGS} -idirafter ${AVR_INC}/include -CC = gcc +CC ?= gcc AR ?= ar RANLIB ?= ranlib MKDIR ?= mkdir -p diff --git a/examples/board_reprap/src/c3/c3geometry.h b/examples/board_reprap/src/c3/c3geometry.h index 480e246..09b47cc 100644 --- a/examples/board_reprap/src/c3/c3geometry.h +++ b/examples/board_reprap/src/c3/c3geometry.h @@ -111,7 +111,7 @@ IMPLEMENT_C_ARRAY(c3colorf_array); static inline c3geometry_type_t c3geometry_type(int type, int subtype) { - c3geometry_type_t r = { .type = type, . subtype = subtype }; + c3geometry_type_t r = { .type = type, .subtype = subtype }; return r; } diff --git a/examples/parts/uart_pty.c b/examples/parts/uart_pty.c index 8fad649..6fc3287 100644 --- a/examples/parts/uart_pty.c +++ b/examples/parts/uart_pty.c @@ -26,8 +26,12 @@ #include #include #include -#include #include +#ifdef __APPLE__ +#include +#else +#include +#endif #include "uart_pty.h" #include "avr_uart.h" diff --git a/examples/parts/uart_pty.h b/examples/parts/uart_pty.h index d82b762..f797e58 100644 --- a/examples/parts/uart_pty.h +++ b/examples/parts/uart_pty.h @@ -23,6 +23,7 @@ #ifndef __UART_PTY_H___ #define __UART_PTY_H___ +#include #include "sim_irq.h" #include "fifo_declare.h" diff --git a/simavr/sim/sim_core.c b/simavr/sim/sim_core.c index 29f8c0e..6d95fb5 100644 --- a/simavr/sim/sim_core.c +++ b/simavr/sim/sim_core.c @@ -1277,7 +1277,8 @@ avr_flashaddr_t avr_run_one(avr_t * avr) case 0xc000: { // RJMP 1100 kkkk kkkk kkkk - short o = ((short)(opcode << 4)) >> 4; +// int16_t o = ((int16_t)(opcode << 4)) >> 4; // CLANG BUG! + int16_t o = ((int16_t)((opcode << 4)&0xffff)) >> 4; STATE("rjmp .%d [%04x]\n", o, new_pc + (o << 1)); new_pc = new_pc + (o << 1); cycle++; @@ -1286,7 +1287,8 @@ avr_flashaddr_t avr_run_one(avr_t * avr) case 0xd000: { // RCALL 1100 kkkk kkkk kkkk - short o = ((short)(opcode << 4)) >> 4; +// int16_t o = ((int16_t)(opcode << 4)) >> 4; // CLANG BUG! + int16_t o = ((int16_t)((opcode << 4)&0xffff)) >> 4; STATE("rcall .%d [%04x]\n", o, new_pc + (o << 1)); _avr_push16(avr, new_pc >> 1); new_pc = new_pc + (o << 1); @@ -1311,7 +1313,7 @@ avr_flashaddr_t avr_run_one(avr_t * avr) case 0xf200: case 0xf400: case 0xf600: { // All the SREG branches - short o = ((short)(opcode << 6)) >> 9; // offset + int16_t o = ((int16_t)(opcode << 6)) >> 9; // offset uint8_t s = opcode & 7; int set = (opcode & 0x0400) == 0; // this bit means BRXC otherwise BRXS int branch = (avr->sreg[s] && set) || (!avr->sreg[s] && !set); diff --git a/tests/tests.c b/tests/tests.c index f389f4d..d502fde 100644 --- a/tests/tests.c +++ b/tests/tests.c @@ -38,6 +38,7 @@ static avr_cycle_count_t cycle_timer_longjmp_cb(struct avr_t *avr, avr_cycle_count_t when, void *param) { jmp_buf *jmp = param; longjmp(*jmp, LJR_CYCLE_TIMER); + return 0; // clear warning } static jmp_buf *special_deinit_jmpbuf = NULL;