clang: Fixes of warning and nasty bugs
authorMichel Pollet <buserror@gmail.com>
Fri, 25 May 2012 12:55:11 +0000 (13:55 +0100)
committerMichel Pollet <buserror@gmail.com>
Fri, 25 May 2012 12:55:11 +0000 (13:55 +0100)
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 <buserror@gmail.com>
Makefile.common
examples/board_reprap/src/c3/c3geometry.h
examples/parts/uart_pty.c
examples/parts/uart_pty.h
simavr/sim/sim_core.c
tests/tests.c

index 23dddec..d219b96 100644 (file)
@@ -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
index 480e246..09b47cc 100644 (file)
@@ -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;
 }
 
index 8fad649..6fc3287 100644 (file)
 #include <stdio.h>
 #include <errno.h>
 #include <unistd.h>
-#include <pty.h>
 #include <signal.h>
+#ifdef __APPLE__
+#include <util.h>
+#else
+#include <pty.h>
+#endif
 
 #include "uart_pty.h"
 #include "avr_uart.h"
index d82b762..f797e58 100644 (file)
@@ -23,6 +23,7 @@
 #ifndef __UART_PTY_H___
 #define __UART_PTY_H___
 
+#include <pthread.h>
 #include "sim_irq.h"
 #include "fifo_declare.h"
 
index 29f8c0e..6d95fb5 100644 (file)
@@ -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);
index f389f4d..d502fde 100644 (file)
@@ -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;