diff --git a/src/common.mk b/src/common.mk index 5087288f3..68f1f6490 100644 --- a/src/common.mk +++ b/src/common.mk @@ -82,13 +82,39 @@ endif QUOTE_NATIVE = $(call QUOTE_ARG,$(call NATIVEPATH,$1)) ROOT_DIR := $(dir $(realpath $(call NATIVEPATH,$(lastword $(MAKEFILE_LIST))))) -EZCFLAGS := -S -fno-autolink -fno-addrsig -fno-math-errno -ffunction-sections -fdata-sections -ffreestanding -EZCFLAGS += -Wall -Wextra -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Oz -EZCFLAGS += -D_EZ80 -D__TICE__=1 -EZCFLAGS += -isystem $(call NATIVEPATH,$(ROOT_DIR)libc/include) -I$(call NATIVEPATH,$(ROOT_DIR)ce/include) -I$(call NATIVEPATH,$(ROOT_DIR)fileioc) -EZCFLAGS += -mllvm -profile-guided-section-prefix=false -mllvm -z80-gas-style -EZCXXFLAGS := $(EZCFLAGS) -fno-exceptions -fno-rtti -EZCXXFLAGS += -isystem $(call NATIVEPATH,$(ROOT_DIR)libcxx/include) +EZLLVMFLAGS := +EZLLVMFLAGS += -fno-autolink +EZLLVMFLAGS += -fno-addrsig +EZLLVMFLAGS += -fno-threadsafe-statics +EZLLVMFLAGS += -mllvm -profile-guided-section-prefix=false +EZLLVMFLAGS += -mllvm -z80-gas-style +EZLLVMFLAGS += -ffunction-sections +EZLLVMFLAGS += -fdata-sections +EZLLVMFLAGS += -fno-math-errno + +EZCOMMONFLAGS := -S +EZCOMMONFLAGS += -ffreestanding +EZCOMMONFLAGS += $(EZLLVMFLAGS) +EZCOMMONFLAGS += -Oz +EZCOMMONFLAGS += -Wall -Wextra -Wshadow +EZCOMMONFLAGS += -Wimplicit-float-conversion -Wimplicit-int-float-conversion +EZCOMMONFLAGS += -Wimplicit-int-conversion +EZCOMMONFLAGS += -D_EZ80 -D__TICE__=1 + +EZLIBCINCLUDE := -isystem $(call NATIVEPATH,$(ROOT_DIR)libc/include) +EZLIBCINCLUDE += -I$(call NATIVEPATH,$(ROOT_DIR)ce/include) +EZLIBCINCLUDE += -I$(call NATIVEPATH,$(ROOT_DIR)fileioc) + +EZLIBCXXINCLUDE := -isystem $(call NATIVEPATH,$(ROOT_DIR)libcxx/include) + +EZCFLAGS := $(EZCOMMONFLAGS) $(EZLIBCINCLUDE) + +# The C++ standard requires libcxx headers to be searched before libc headers +# this means include/c++/math.h must be included before include/math.h +EZCXXFLAGS := $(EZCOMMONFLAGS) $(EZLIBCXXINCLUDE) $(EZLIBCINCLUDE) +EZCXXFLAGS += -fno-exceptions +EZCXXFLAGS += -fno-rtti + EZASFLAGS := -march=ez80+full EZASFLAGS += --defsym __TICE__=1 diff --git a/src/crt/lltof.c b/src/crt/lltof.c index 4d5c9a84a..b475d6ddf 100644 --- a/src/crt/lltof.c +++ b/src/crt/lltof.c @@ -4,7 +4,7 @@ float _lltof_c(long long x) { - uint8_t exponent = x ? __builtin_clrsbll(x) : LLONG_WIDTH - 1; + uint8_t exponent = x ? ((uint8_t)__builtin_clrsbll(x)) : LLONG_WIDTH - 1; if (exponent >= LLONG_WIDTH - LONG_WIDTH) { return (float)((long)x); } diff --git a/src/crt/ulltof.c b/src/crt/ulltof.c index 568ad7ddd..058a78c9c 100644 --- a/src/crt/ulltof.c +++ b/src/crt/ulltof.c @@ -4,7 +4,7 @@ float _ulltof_c(unsigned long long x) { - uint8_t exponent = x ? __builtin_clzll(x) : ULLONG_WIDTH; + uint8_t exponent = x ? ((uint8_t)__builtin_clzll(x)) : ULLONG_WIDTH; if (exponent >= ULLONG_WIDTH - ULONG_WIDTH) { return (float)((unsigned long)x); } diff --git a/src/libc/fgetc.c b/src/libc/fgetc.c index feaa5e9ab..6a0f395c7 100644 --- a/src/libc/fgetc.c +++ b/src/libc/fgetc.c @@ -5,9 +5,12 @@ int __attribute__((weak)) fgetc(FILE *stream) { int c; - if (stream == NULL || - stream == stdout || - stream == stderr) + if (stream == NULL) + { + return EOF; + } + + if (stream == stdout || stream == stderr) { c = EOF; } diff --git a/src/libc/fgets.c b/src/libc/fgets.c index 7a9d82f47..bd39b4200 100644 --- a/src/libc/fgets.c +++ b/src/libc/fgets.c @@ -18,7 +18,7 @@ char* __attribute__((weak)) fgets(char *__restrict str, int num, FILE *__restric { break; } - *p++ = c; + *p++ = (char)c; if (c == '\n') { break; diff --git a/src/libc/float64_rounding.c b/src/libc/float64_rounding.c index 592dbdcd7..11236835e 100644 --- a/src/libc/float64_rounding.c +++ b/src/libc/float64_rounding.c @@ -75,7 +75,7 @@ long long llroundl(long double x) { FE_UPWARD == softfloat_round_max) // assumes fenv.h macros match softfloat_roundingModes -#define GET_FENV_SOFTFLOAT_ROUNDING() (fegetround()) +#define GET_FENV_SOFTFLOAT_ROUNDING() ((uint_fast8_t)fegetround()) #else static uint_fast8_t GET_FENV_SOFTFLOAT_ROUNDING(void) { diff --git a/src/libc/fputc.c b/src/libc/fputc.c index c2b575bcf..78dc905ed 100644 --- a/src/libc/fputc.c +++ b/src/libc/fputc.c @@ -5,7 +5,12 @@ int __attribute__((weak)) fputc(int c, FILE *stream) { int ret; - if (stream == NULL || stream == stdin) + if (stream == NULL) + { + return EOF; + } + + if (stream == stdin) { ret = EOF; } diff --git a/src/libc/fread.c b/src/libc/fread.c index af2f63191..4fdac1179 100644 --- a/src/libc/fread.c +++ b/src/libc/fread.c @@ -24,7 +24,7 @@ size_t __attribute__((weak)) fread(void *ptr, size_t size, size_t count, FILE *_ { break; } - *p++ = c; + *p++ = (char)c; } return count; diff --git a/src/libc/gmtime.c b/src/libc/gmtime.c index 0a99ddd8d..270328f3f 100644 --- a/src/libc/gmtime.c +++ b/src/libc/gmtime.c @@ -82,7 +82,7 @@ struct tm *gmtime(const time_t *tp) tm2.tm_min++; } - tm2.tm_sec = t; + tm2.tm_sec = (int)t; return &tm2; } diff --git a/src/libc/printf/nanoprintf.c b/src/libc/printf/nanoprintf.c index 628236740..3365b1b15 100644 --- a/src/libc/printf/nanoprintf.c +++ b/src/libc/printf/nanoprintf.c @@ -18,7 +18,7 @@ static void npf_putc_std(int c, void *ctx) { (void)ctx; - outchar(c); + outchar((char)c); } static void npf_fputc_std(int c, void *ctx) { diff --git a/src/libc/printf/nanoprintf.h b/src/libc/printf/nanoprintf.h index 9ecde52f8..99d06fc7c 100644 --- a/src/libc/printf/nanoprintf.h +++ b/src/libc/printf/nanoprintf.h @@ -766,9 +766,9 @@ static npf_cnt_putc_ctx_t pc_cnt; #endif static void npf_putc_cnt(int c, void *ctx) { - npf_cnt_putc_ctx_t *pc_cnt = (npf_cnt_putc_ctx_t *)ctx; - ++pc_cnt->n; - pc_cnt->pc(c, pc_cnt->ctx); // sibling-call optimization + npf_cnt_putc_ctx_t *pc_putc_cnt = (npf_cnt_putc_ctx_t *)ctx; + ++pc_putc_cnt->n; + pc_putc_cnt->pc(c, pc_putc_cnt->ctx); // sibling-call optimization } #ifdef NANOPRINTF_STATIC_GLOBALS diff --git a/src/libc/strftime.c b/src/libc/strftime.c index 1c08e5637..126a55c8a 100644 --- a/src/libc/strftime.c +++ b/src/libc/strftime.c @@ -81,7 +81,7 @@ size_t strftime(char *__restrict s, size_t n, const char *__restrict f, const st while (s + 1 < e && *f) { - int c = *f++; + char c = *f++; int val; if (c != '%') diff --git a/src/makefile.mk b/src/makefile.mk index 2b453fc38..777e7499d 100644 --- a/src/makefile.mk +++ b/src/makefile.mk @@ -314,10 +314,39 @@ MATH_ERRNO = -fno-math-errno endif # define the compiler/assembler flags -EZLLVMFLAGS = -mllvm -profile-guided-section-prefix=false -mllvm -z80-gas-style -ffunction-sections -fdata-sections -fno-addrsig -fno-autolink -fno-threadsafe-statics $(MATH_ERRNO) -EZCOMMONFLAGS = -nostdinc -isystem $(call QUOTE_ARG,$(call FORWARD_PATH,$(CEDEV_TOOLCHAIN)/include)) -I$(SRCDIR) -Xclang -fforce-mangle-main-argc-argv $(EZLLVMFLAGS) -D__TICE__=1 $(CC_CUSTOMFILE) -EZCFLAGS = $(EZCOMMONFLAGS) $(CFLAGS) $(CC_DEBUG) -EZCXXFLAGS = $(EZCOMMONFLAGS) -isystem $(call QUOTE_ARG,$(call FORWARD_PATH,$(CEDEV_TOOLCHAIN)/include/c++)) -fno-exceptions -fno-use-cxa-atexit $(CXXFLAGS) $(CC_DEBUG) + +EZLLVMFLAGS = +EZLLVMFLAGS += -fno-autolink +EZLLVMFLAGS += -fno-addrsig +EZLLVMFLAGS += -fno-threadsafe-statics +EZLLVMFLAGS += -mllvm -profile-guided-section-prefix=false +EZLLVMFLAGS += -mllvm -z80-gas-style +EZLLVMFLAGS += -ffunction-sections +EZLLVMFLAGS += -fdata-sections +EZLLVMFLAGS += $(MATH_ERRNO) + +EZCOMMONFLAGS = +EZCOMMONFLAGS += -nostdinc +EZCOMMONFLAGS += -Xclang -fforce-mangle-main-argc-argv +EZCOMMONFLAGS += $(EZLLVMFLAGS) +EZCOMMONFLAGS += -D__TICE__=1 +EZCOMMONFLAGS += $(CC_CUSTOMFILE) + +EZLIBCINCLUDE = -isystem $(call QUOTE_ARG,$(call FORWARD_PATH,$(CEDEV_TOOLCHAIN)/include)) +EZLIBCINCLUDE += -I$(SRCDIR) + +EZLIBCXXINCLUDE = -isystem $(call QUOTE_ARG,$(call FORWARD_PATH,$(CEDEV_TOOLCHAIN)/include/c++)) + +EZCFLAGS = $(EZCOMMONFLAGS) $(EZLIBCINCLUDE) +EZCFLAGS += $(CFLAGS) $(CC_DEBUG) + +# The C++ standard requires libcxx headers to be searched before libc headers +# this means include/c++/math.h must be included before include/math.h +EZCXXFLAGS = $(EZCOMMONFLAGS) $(EZLIBCXXINCLUDE) $(EZLIBCINCLUDE) +EZCXXFLAGS += -fno-exceptions +EZCXXFLAGS += -fno-use-cxa-atexit +EZCXXFLAGS += $(CXXFLAGS) $(CC_DEBUG) + EZLTOFLAGS = $(EZLLVMFLAGS) $(LTOFLAGS) EZASFLAGS = -march=ez80+full $(ASFLAGS)