diff --git a/Makefile b/Makefile index 0b82c62..3a64d62 100644 --- a/Makefile +++ b/Makefile @@ -8,17 +8,17 @@ LTO=-flto=auto -fno-fat-lto-objects -Wl,-flto LDFLAGS= # MAKEFLAGS := --jobs=$(shell nproc) --output-sync=target CWARN=-Wall -Wextra -Wno-format -Wshadow \ - -Wpedantic \ + -Wno-pedantic \ -Wno-pointer-arith \ -Wsign-conversion -Wtype-limits -Wunused-result -Wnull-dereference \ -Walloc-zero -Walloca -Warith-conversion -Wcast-align -Wcast-align=strict \ -Wdangling-else -Wdate-time -Wdisabled-optimization -Wdouble-promotion -Wduplicated-branches \ - -Wduplicated-cond -Wexpansion-to-defined -Wfloat-equal \ + -Wduplicated-cond -Wexpansion-to-defined -Wno-float-equal \ -Wframe-address -Winline -Winvalid-pch -Wjump-misses-init \ -Wlogical-op -Wmissing-format-attribute -Wmissing-include-dirs -Wmissing-noreturn \ -Wnull-dereference -Woverlength-strings -Wpacked -Wpacked-not-aligned \ -Wredundant-decls -Wshadow -Wshadow=compatible-local -Wshadow=global -Wshadow=local \ - -Wsign-conversion -Wstack-protector -Wsuggest-attribute=const -Wsuggest-attribute=noreturn -Wsuggest-attribute=pure -Wswitch-default \ + -Wsign-conversion -Wno-stack-protector -Wsuggest-attribute=const -Wsuggest-attribute=noreturn -Wsuggest-attribute=pure -Wswitch-default \ -Wsync-nand -Wtrampolines -Wundef -Wunused -Wunused-but-set-variable \ -Wunused-const-variable -Wunused-local-typedefs -Wunused-macros -Wvariadic-macros -Wvector-operation-performance \ -Wwrite-strings @@ -26,7 +26,7 @@ OSFLAGS != case $$(uname -s) in *BSD|Darwin) echo '-D_BSD_SOURCE';; Linux) echo EXTRA= G=-ggdb O=-Og -CFLAGS=$(CCONFIG) $(EXTRA) $(CWARN) $(G) $(O) $(OSFLAGS) +CFLAGS=$(CCONFIG) $(EXTRA) $(CWARN) $(G) $(O) $(OSFLAGS) $(LTO) CFLAGS_PLACEHOLDER="$$(echo -e '\033[2m\033[m')" LDLIBS=-lgc -lcord -lm -lunistring -lgmp -ldl BUILTIN_OBJS=stdlib/siphash.o stdlib/arrays.o stdlib/bools.o stdlib/bytes.o stdlib/channels.o stdlib/nums.o stdlib/integers.o \ diff --git a/ast.h b/ast.h index fada01d..1631b0f 100644 --- a/ast.h +++ b/ast.h @@ -93,7 +93,6 @@ struct type_ast_s { file_t *file; const char *start, *end; union { -#pragma GCC diagnostic ignored "-Wpedantic" struct {} UnknownTypeAST; struct { const char *name; diff --git a/compile.c b/compile.c index 775c17d..db1255b 100644 --- a/compile.c +++ b/compile.c @@ -1778,8 +1778,10 @@ static CORD compile_string_literal(CORD literal) { CORD code = "\""; CORD_pos i; +#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wsign-conversion" CORD_FOR(i, literal) { +#pragma GCC diagnostic pop char c = CORD_pos_fetch(i); switch (c) { case '\\': code = CORD_cat(code, "\\\\"); break; @@ -1805,7 +1807,10 @@ static CORD compile_string_literal(CORD literal) static bool string_literal_is_all_ascii(CORD literal) { CORD_pos i; +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wsign-conversion" CORD_FOR(i, literal) { +#pragma GCC diagnostic pop if (!isascii(CORD_pos_fetch(i))) return false; } diff --git a/cordhelpers.c b/cordhelpers.c index 5a0066f..57189a8 100644 --- a/cordhelpers.c +++ b/cordhelpers.c @@ -20,8 +20,10 @@ public CORD CORD_quoted(CORD str) { CORD quoted = "\""; CORD_pos i; +#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wsign-conversion" CORD_FOR(i, str) { +#pragma GCC diagnostic pop char c = CORD_pos_fetch(i); switch (c) { case '\a': quoted = CORD_cat(quoted, "\\a"); break; @@ -34,7 +36,6 @@ public CORD CORD_quoted(CORD str) case '\v': quoted = CORD_cat(quoted, "\\v"); break; case '"': quoted = CORD_cat(quoted, "\\\""); break; case '\\': quoted = CORD_cat(quoted, "\\\\"); break; -#pragma GCC diagnostic ignored "-Wpedantic" case '\x00' ... '\x06': case '\x0E' ... '\x1A': case '\x1C' ... '\x1F': case '\x7F' ... '\x7F': CORD_sprintf("ed, "%r\\x%02X", quoted, c); diff --git a/parse.c b/parse.c index 73c5dc1..afaebfa 100644 --- a/parse.c +++ b/parse.c @@ -59,19 +59,19 @@ static const char *keywords[] = { enum {NORMAL_FUNCTION=0, EXTERN_FUNCTION=1}; -static inline size_t some_of(const char **pos, const char *allow); -static inline size_t some_not(const char **pos, const char *forbid); -static inline size_t spaces(const char **pos); -static inline void whitespace(const char **pos); -static inline size_t match(const char **pos, const char *target); -static inline void expect_str(parse_ctx_t *ctx, const char *start, const char **pos, const char *target, const char *fmt, ...); -static inline void expect_closing(parse_ctx_t *ctx, const char **pos, const char *target, const char *fmt, ...); -static inline size_t match_word(const char **pos, const char *word); -static inline const char* get_word(const char **pos); -static inline const char* get_id(const char **pos); -static inline bool comment(const char **pos); -static inline bool indent(parse_ctx_t *ctx, const char **pos); -static inline binop_e match_binary_operator(const char **pos); +static INLINE size_t some_of(const char **pos, const char *allow); +static INLINE size_t some_not(const char **pos, const char *forbid); +static INLINE size_t spaces(const char **pos); +static INLINE void whitespace(const char **pos); +static INLINE size_t match(const char **pos, const char *target); +static void expect_str(parse_ctx_t *ctx, const char *start, const char **pos, const char *target, const char *fmt, ...); +static void expect_closing(parse_ctx_t *ctx, const char **pos, const char *target, const char *fmt, ...); +static INLINE size_t match_word(const char **pos, const char *word); +static INLINE const char* get_word(const char **pos); +static INLINE const char* get_id(const char **pos); +static INLINE bool comment(const char **pos); +static INLINE bool indent(parse_ctx_t *ctx, const char **pos); +static INLINE binop_e match_binary_operator(const char **pos); static ast_t *parse_comprehension_suffix(parse_ctx_t *ctx, ast_t *expr); static ast_t *parse_field_suffix(parse_ctx_t *ctx, ast_t *lhs); static ast_t *parse_fncall_suffix(parse_ctx_t *ctx, ast_t *fn); @@ -180,6 +180,7 @@ static _Noreturn void parser_err(parse_ctx_t *ctx, const char *start, const char // // Convert an escape sequence like \n to a string // +#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wstack-protector" static const char *unescape(parse_ctx_t *ctx, const char **out) { const char **endpos = out; @@ -240,8 +241,9 @@ static const char *unescape(parse_ctx_t *ctx, const char **out) { return GC_strndup(escape+1, 1); } } +#pragma GCC diagnostic pop -PUREFUNC static inline int64_t get_indent(parse_ctx_t *ctx, const char *pos) +PUREFUNC static INLINE int64_t get_indent(parse_ctx_t *ctx, const char *pos) { int64_t line_num = get_line_number(ctx->file, pos); const char *line = get_line(ctx->file, line_num); @@ -296,7 +298,7 @@ size_t match(const char **pos, const char *target) { return len; } -static inline bool is_xid_continue_next(const char *pos) { +static INLINE bool is_xid_continue_next(const char *pos) { ucs4_t point = 0; u8_next(&point, (const uint8_t*)pos); return uc_is_property_xid_continue(point); @@ -741,7 +743,7 @@ PARSER(parse_num) { return NewAST(ctx->file, start, pos, Num, .n=d, .bits=bits); } -static inline bool match_separator(const char **pos) { // Either comma or newline +static INLINE bool match_separator(const char **pos) { // Either comma or newline const char *p = *pos; int separators = 0; for (;;) { diff --git a/repl.c b/repl.c index c9d518d..fca220c 100644 --- a/repl.c +++ b/repl.c @@ -330,6 +330,7 @@ void run(env_t *env, ast_t *ast) } } +#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wstack-protector" void eval(env_t *env, ast_t *ast, void *dest) { @@ -550,5 +551,6 @@ void eval(env_t *env, ast_t *ast, void *dest) errx(1, "Eval not implemented for %W", ast); } } +#pragma GCC diagnostic pop // vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0 diff --git a/stdlib/arrays.c b/stdlib/arrays.c index 9367697..6b61f5b 100644 --- a/stdlib/arrays.c +++ b/stdlib/arrays.c @@ -16,7 +16,7 @@ #include "siphash.h" #include "siphash-internals.h" -PUREFUNC static inline int64_t get_padded_item_size(const TypeInfo_t *info) +PUREFUNC static INLINE int64_t get_padded_item_size(const TypeInfo_t *info) { int64_t size = info->ArrayInfo.item->size; if (info->ArrayInfo.item->align > 1 && size % info->ArrayInfo.item->align) @@ -249,6 +249,7 @@ public Array_t Array$sorted(Array_t arr, Closure_t comparison, int64_t padded_it return arr; } +#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wstack-protector" public void Array$shuffle(Array_t *arr, int64_t padded_item_size) { @@ -263,6 +264,7 @@ public void Array$shuffle(Array_t *arr, int64_t padded_item_size) memcpy((void*)arr->data + j*padded_item_size, tmp, (size_t)padded_item_size); } } +#pragma GCC diagnostic pop public Array_t Array$shuffled(Array_t arr, int64_t padded_item_size) { @@ -583,7 +585,6 @@ public uint64_t Array$hash(const Array_t *arr, const TypeInfo_t *type) return siphashfinish_last_part(&sh, 0); } -#pragma GCC diagnostic ignored "-Wstack-protector" static void siftdown(Array_t *heap, int64_t startpos, int64_t pos, Closure_t comparison, int64_t padded_item_size) { assert(pos > 0 && pos < heap->length); diff --git a/stdlib/datetime.c b/stdlib/datetime.c index 98c23a8..b73c583 100644 --- a/stdlib/datetime.c +++ b/stdlib/datetime.c @@ -227,7 +227,7 @@ public OptionalDateTime_t DateTime$parse(Text_t text, Text_t format) return (DateTime_t){.tv_sec=t + offset - info.tm_gmtoff}; } -static inline Text_t num_format(long n, const char *unit) +static INLINE Text_t num_format(long n, const char *unit) { if (n == 0) return Text("now"); diff --git a/stdlib/functiontype.c b/stdlib/functiontype.c index 49863d8..ce07c06 100644 --- a/stdlib/functiontype.c +++ b/stdlib/functiontype.c @@ -13,7 +13,7 @@ public void register_function(void *fn, Text_t name) Table$set(&function_names, &fn, &name, Table$info(Function$info("???"), &Text$info)); } -public Text_t *get_function_name(void *fn) +PUREFUNC public Text_t *get_function_name(void *fn) { return Table$get(function_names, &fn, Table$info(Function$info("???"), &Text$info)); } diff --git a/stdlib/integers.c b/stdlib/integers.c index e6d466a..f604aa5 100644 --- a/stdlib/integers.c +++ b/stdlib/integers.c @@ -405,7 +405,6 @@ public const TypeInfo_t Int$info = { }, }; - #define DEFINE_INT_TYPE(c_type, KindOfInt, fmt, min_val, max_val, to_attr)\ public Text_t KindOfInt ## $as_text(const c_type *i, bool colorize, const TypeInfo_t *type) { \ (void)type; \ diff --git a/stdlib/integers.h b/stdlib/integers.h index a1eca95..ebbe7bb 100644 --- a/stdlib/integers.h +++ b/stdlib/integers.h @@ -37,12 +37,12 @@ c_type type_name ## $random(c_type min, c_type max); \ to_attr Range_t type_name ## $to(c_type from, c_type to); \ PUREFUNC Optional ## type_name ## _t type_name ## $from_text(Text_t text); \ - PUREFUNC static inline c_type type_name ## $clamped(c_type x, c_type min, c_type max) { \ + PUREFUNC static INLINE c_type type_name ## $clamped(c_type x, c_type min, c_type max) { \ return x < min ? min : (x > max ? max : x); \ } \ extern const c_type type_name ## $min, type_name##$max; \ extern const TypeInfo_t type_name ## $info; \ - static inline c_type type_name ## $divided_by(c_type D, c_type d) { \ + static INLINE c_type type_name ## $divided_by(c_type D, c_type d) { \ c_type q = D/d, r = D%d; \ if (r < 0) { \ if (d > 0) q = q-1; \ @@ -50,7 +50,7 @@ } \ return q; \ } \ - static inline c_type type_name ## $modulo(c_type D, c_type d) { \ + static INLINE c_type type_name ## $modulo(c_type D, c_type d) { \ c_type r = D%d; \ if (r < 0) { \ if (d > 0) r = r + d; \ @@ -58,7 +58,7 @@ } \ return r; \ } \ - static inline c_type type_name ## $modulo1(c_type D, c_type d) { \ + static INLINE c_type type_name ## $modulo1(c_type D, c_type d) { \ return type_name ## $modulo(D-1, d) + 1; \ } @@ -136,7 +136,7 @@ Int_t Int$prev_prime(Int_t x); extern const TypeInfo_t Int$info; -static inline Int_t Int$clamped(Int_t x, Int_t low, Int_t high) +static INLINE Int_t Int$clamped(Int_t x, Int_t low, Int_t high) { return (Int$compare(&x, &low, &Int$info) <= 0) ? low : (Int$compare(&x, &high, &Int$info) >= 0 ? high : x); } @@ -144,21 +144,21 @@ static inline Int_t Int$clamped(Int_t x, Int_t low, Int_t high) // Fast-path inline versions for the common case where integer arithmetic is // between two small ints. -static inline Int_t Int$plus(Int_t x, Int_t y) { +static INLINE Int_t Int$plus(Int_t x, Int_t y) { const int64_t z = (int64_t)((uint64_t)x.small + (uint64_t)y.small); if (__builtin_expect(((z|2) == (int32_t)z), 1)) return (Int_t){.small=(z-1)}; return Int$slow_plus(x, y); } -static inline Int_t Int$minus(Int_t x, Int_t y) { +static INLINE Int_t Int$minus(Int_t x, Int_t y) { const int64_t z = (int64_t)(((uint64_t)x.small ^ 3) - (uint64_t)y.small); if (__builtin_expect(((z & ~2) == (int32_t)z), 1)) return (Int_t){.small=z}; return Int$slow_minus(x, y); } -static inline Int_t Int$times(Int_t x, Int_t y) { +static INLINE Int_t Int$times(Int_t x, Int_t y) { if (__builtin_expect(((x.small & y.small) & 1) != 0, 1)) { const int64_t z = (x.small>>1) * (y.small>>1); if (__builtin_expect(z == (int32_t)z, 1)) @@ -167,7 +167,7 @@ static inline Int_t Int$times(Int_t x, Int_t y) { return Int$slow_times(x, y); } -static inline Int_t Int$divided_by(Int_t x, Int_t y) { +static INLINE Int_t Int$divided_by(Int_t x, Int_t y) { if (__builtin_expect(((x.small & y.small) & 1) != 0, 1)) { // Euclidean division, see: https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/divmodnote-letter.pdf const int64_t D = (x.small>>2); @@ -184,7 +184,7 @@ static inline Int_t Int$divided_by(Int_t x, Int_t y) { return Int$slow_divided_by(x, y); } -static inline Int_t Int$modulo(Int_t x, Int_t y) { +static INLINE Int_t Int$modulo(Int_t x, Int_t y) { if (__builtin_expect(((x.small & y.small) & 1) != 0, 1)) { // Euclidean modulus, see: https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/divmodnote-letter.pdf const int64_t D = (x.small>>2); @@ -199,7 +199,7 @@ static inline Int_t Int$modulo(Int_t x, Int_t y) { return Int$slow_modulo(x, y); } -static inline Int_t Int$modulo1(Int_t x, Int_t y) { +static INLINE Int_t Int$modulo1(Int_t x, Int_t y) { if (__builtin_expect(((x.small & y.small) & 1) != 0, 1)) { // Euclidean modulus, see: https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/divmodnote-letter.pdf const int64_t D = (x.small>>2)-1; @@ -214,7 +214,7 @@ static inline Int_t Int$modulo1(Int_t x, Int_t y) { return Int$slow_modulo1(x, y); } -static inline Int_t Int$left_shifted(Int_t x, Int_t y) { +static INLINE Int_t Int$left_shifted(Int_t x, Int_t y) { if (__builtin_expect(((x.small & y.small) & 1) != 0, 1)) { const int64_t z = ((x.small>>2) << (y.small>>2))<<2; if (__builtin_expect(z == (int32_t)z, 1)) @@ -223,7 +223,7 @@ static inline Int_t Int$left_shifted(Int_t x, Int_t y) { return Int$slow_left_shifted(x, y); } -static inline Int_t Int$right_shifted(Int_t x, Int_t y) { +static INLINE Int_t Int$right_shifted(Int_t x, Int_t y) { if (__builtin_expect(((x.small & y.small) & 1) != 0, 1)) { const int64_t z = ((x.small>>2) >> (y.small>>2))<<2; if (__builtin_expect(z == (int32_t)z, 1)) @@ -232,40 +232,40 @@ static inline Int_t Int$right_shifted(Int_t x, Int_t y) { return Int$slow_right_shifted(x, y); } -static inline Int_t Int$bit_and(Int_t x, Int_t y) { +static INLINE Int_t Int$bit_and(Int_t x, Int_t y) { const int64_t z = x.small & y.small; if (__builtin_expect((z & 1) == 1, 1)) return (Int_t){.small=z}; return Int$slow_bit_and(x, y); } -static inline Int_t Int$bit_or(Int_t x, Int_t y) { +static INLINE Int_t Int$bit_or(Int_t x, Int_t y) { if (__builtin_expect(((x.small & y.small) & 1) == 1, 1)) return (Int_t){.small=(x.small | y.small)}; return Int$slow_bit_or(x, y); } -static inline Int_t Int$bit_xor(Int_t x, Int_t y) { +static INLINE Int_t Int$bit_xor(Int_t x, Int_t y) { if (__builtin_expect(((x.small & y.small) & 1) == 1, 1)) return (Int_t){.small=(x.small ^ y.small) | 1}; return Int$slow_bit_xor(x, y); } -static inline Int_t Int$negated(Int_t x) +static INLINE Int_t Int$negated(Int_t x) { if (__builtin_expect((x.small & 1), 1)) return (Int_t){.small=(~x.small) ^ 3}; return Int$slow_negated(x); } -static inline Int_t Int$negative(Int_t x) +static INLINE Int_t Int$negative(Int_t x) { if (__builtin_expect((x.small & 1), 1)) return (Int_t){.small=((-((x.small)>>2))<<2) | 1}; return Int$slow_negative(x); } -static inline bool Int$is_negative(Int_t x) +static INLINE bool Int$is_negative(Int_t x) { if (__builtin_expect((x.small & 1), 1)) return x.small < 0; @@ -274,7 +274,7 @@ static inline bool Int$is_negative(Int_t x) // Conversion functions: -static inline Int_t Int64_to_Int(int64_t i) +static INLINE Int_t Int64_to_Int(int64_t i) { int64_t z = i<<2; if (__builtin_expect(z == (int32_t)z, 1)) @@ -288,16 +288,18 @@ static inline Int_t Int64_to_Int(int64_t i) #define Int16_to_Int(i) Int64_to_Int(i) #define Int8_to_Int(i) Int64_to_Int(i) +#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Winline" -PUREFUNC static inline Int64_t Int_to_Int64(Int_t i, bool truncate) { +PUREFUNC static INLINE Int64_t Int_to_Int64(Int_t i, bool truncate) { if (__builtin_expect(i.small & 1, 1)) return (int64_t)(i.small >> 2); if (__builtin_expect(!truncate && !mpz_fits_slong_p(*i.big), 0)) fail("Integer is too big to fit in a 64-bit integer!"); return mpz_get_si(*i.big); } +#pragma GCC diagnostic pop -PUREFUNC static inline Int32_t Int_to_Int32(Int_t i, bool truncate) { +PUREFUNC static INLINE Int32_t Int_to_Int32(Int_t i, bool truncate) { int64_t i64 = Int_to_Int64(i, truncate); int32_t i32 = (int32_t)i64; if (__builtin_expect(i64 != i32 && !truncate, 0)) @@ -305,7 +307,7 @@ PUREFUNC static inline Int32_t Int_to_Int32(Int_t i, bool truncate) { return i32; } -PUREFUNC static inline Int16_t Int_to_Int16(Int_t i, bool truncate) { +PUREFUNC static INLINE Int16_t Int_to_Int16(Int_t i, bool truncate) { int64_t i64 = Int_to_Int64(i, truncate); int16_t i16 = (int16_t)i64; if (__builtin_expect(i64 != i16 && !truncate, 0)) @@ -313,7 +315,7 @@ PUREFUNC static inline Int16_t Int_to_Int16(Int_t i, bool truncate) { return i16; } -PUREFUNC static inline Int8_t Int_to_Int8(Int_t i, bool truncate) { +PUREFUNC static INLINE Int8_t Int_to_Int8(Int_t i, bool truncate) { int64_t i64 = Int_to_Int64(i, truncate); int8_t i8 = (int8_t)i64; if (__builtin_expect(i64 != i8 && !truncate, 0)) @@ -321,14 +323,14 @@ PUREFUNC static inline Int8_t Int_to_Int8(Int_t i, bool truncate) { return i8; } -PUREFUNC static inline Int_t Num_to_Int(double n) +PUREFUNC static INLINE Int_t Num_to_Int(double n) { mpz_t result; mpz_init_set_d(result, n); return Int$from_mpz(result); } -PUREFUNC static inline double Int_to_Num(Int_t i) +PUREFUNC static INLINE double Int_to_Num(Int_t i) { if (__builtin_expect(i.small & 1, 1)) return (double)(i.small >> 2); @@ -339,7 +341,7 @@ PUREFUNC static inline double Int_to_Num(Int_t i) #define Int_to_Num32(i) (Num32_t)Int_to_Num(i) #define CONVERSION_FUNC(hi, lo) \ - PUREFUNC static inline int##lo##_t Int##hi##_to_Int##lo(int##hi##_t i, bool truncate) { \ + PUREFUNC static INLINE int##lo##_t Int##hi##_to_Int##lo(int##hi##_t i, bool truncate) { \ if (__builtin_expect(!truncate && (i != (int##lo##_t)i), 0)) \ fail("Cannot truncate the Int" #hi " %ld to an Int" #lo, (int64_t)i); \ return (int##lo##_t)i; \ @@ -353,9 +355,10 @@ CONVERSION_FUNC(32, 8) CONVERSION_FUNC(16, 8) #undef CONVERSION_FUNC +#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wfloat-equal" #define CONVERSION_FUNC(num, int_type) \ - PUREFUNC static inline int_type##_t num##_to_##int_type(num##_t n, bool truncate) { \ + PUREFUNC static INLINE int_type##_t num##_to_##int_type(num##_t n, bool truncate) { \ num##_t rounded = (num##_t)round((double)n); \ if (__builtin_expect(!truncate && (num##_t)(int_type##_t)rounded != rounded, 0)) \ fail("Cannot truncate the " #num " %g to an " #int_type, (double)rounded); \ @@ -370,6 +373,7 @@ CONVERSION_FUNC(Num32, Int64) CONVERSION_FUNC(Num32, Int32) CONVERSION_FUNC(Num32, Int16) CONVERSION_FUNC(Num32, Int8) +#pragma GCC diagnostic pop #undef CONVERSION_FUNC // vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0 diff --git a/stdlib/metamethods.c b/stdlib/metamethods.c index 0e7d348..6c8583f 100644 --- a/stdlib/metamethods.c +++ b/stdlib/metamethods.c @@ -16,6 +16,7 @@ #include "util.h" +#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wstack-protector" PUREFUNC public uint64_t generic_hash(const void *obj, const TypeInfo_t *type) { @@ -82,6 +83,7 @@ PUREFUNC public uint64_t generic_hash(const void *obj, const TypeInfo_t *type) } } } +#pragma GCC diagnostic pop PUREFUNC public int32_t generic_compare(const void *x, const void *y, const TypeInfo_t *type) { diff --git a/stdlib/optionals.c b/stdlib/optionals.c index a3b3def..cd93f93 100644 --- a/stdlib/optionals.c +++ b/stdlib/optionals.c @@ -61,6 +61,7 @@ public PUREFUNC bool is_null(const void *obj, const TypeInfo_t *non_optional_typ } } +#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wstack-protector" public Text_t Optional$as_text(const void *obj, bool colorize, const TypeInfo_t *type) { @@ -72,5 +73,6 @@ public Text_t Optional$as_text(const void *obj, bool colorize, const TypeInfo_t colorize ? Text("\x1b[m") : Text("")); return Text$concat(generic_as_text(obj, colorize, type->OptionalInfo.type), colorize ? Text("\x1b[33m?\x1b[m") : Text("?")); } +#pragma GCC diagnostic pop // vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1 diff --git a/stdlib/paths.c b/stdlib/paths.c index 8f6e135..2453394 100644 --- a/stdlib/paths.c +++ b/stdlib/paths.c @@ -106,7 +106,7 @@ public Path_t Path$cleanup(Path_t path) return cleaned_up; } -static inline Path_t Path$_expand_home(Path_t path) +static INLINE Path_t Path$_expand_home(Path_t path) { if (Text$starts_with(path, Path("~/"))) { Path_t after_tilde = Text$slice(path, I(2), I(-1)); @@ -158,7 +158,7 @@ public bool Path$exists(Path_t path) return (stat(Text$as_c_string(path), &sb) == 0); } -static inline int path_stat(Path_t path, bool follow_symlinks, struct stat *sb) +static INLINE int path_stat(Path_t path, bool follow_symlinks, struct stat *sb) { path = Path$_expand_home(path); const char *path_str = Text$as_c_string(path); diff --git a/stdlib/patterns.c b/stdlib/patterns.c index 6acb58a..b8f204f 100644 --- a/stdlib/patterns.c +++ b/stdlib/patterns.c @@ -33,7 +33,7 @@ typedef struct { }; } pat_t; -static inline void skip_whitespace(TextIter_t *state, int64_t *i) +static INLINE void skip_whitespace(TextIter_t *state, int64_t *i) { while (*i < state->text.length) { int32_t grapheme = Text$get_grapheme_fast(state, *i); @@ -43,7 +43,7 @@ static inline void skip_whitespace(TextIter_t *state, int64_t *i) } } -static inline bool match_grapheme(TextIter_t *state, int64_t *i, int32_t grapheme) +static INLINE bool match_grapheme(TextIter_t *state, int64_t *i, int32_t grapheme) { if (*i < state->text.length && Text$get_grapheme_fast(state, *i) == grapheme) { *i += 1; @@ -52,7 +52,7 @@ static inline bool match_grapheme(TextIter_t *state, int64_t *i, int32_t graphem return false; } -static inline bool match_str(TextIter_t *state, int64_t *i, const char *str) +static INLINE bool match_str(TextIter_t *state, int64_t *i, const char *str) { int64_t matched = 0; while (matched[str]) { @@ -64,7 +64,7 @@ static inline bool match_str(TextIter_t *state, int64_t *i, const char *str) return true; } -static inline bool match_property(TextIter_t *state, int64_t *i, uc_property_t prop) +static INLINE bool match_property(TextIter_t *state, int64_t *i, uc_property_t prop) { if (*i >= state->text.length) return false; uint32_t grapheme = Text$get_main_grapheme_fast(state, *i); diff --git a/stdlib/siphash-internals.h b/stdlib/siphash-internals.h index d1906be..b2b31e1 100644 --- a/stdlib/siphash-internals.h +++ b/stdlib/siphash-internals.h @@ -68,7 +68,7 @@ typedef struct siphash siphash; HALF_ROUND(v0,v1,v2,v3,13,16); \ HALF_ROUND(v2,v1,v0,v3,17,21); -static inline void siphashinit (siphash *sh, size_t src_sz) { +static INLINE void siphashinit (siphash *sh, size_t src_sz) { const uint64_t k0 = TOMO_HASH_KEY[0]; const uint64_t k1 = TOMO_HASH_KEY[1]; sh->b = (uint64_t)src_sz << 56; @@ -77,14 +77,13 @@ static inline void siphashinit (siphash *sh, size_t src_sz) { sh->v2 = k0 ^ 0x6c7967656e657261ULL; sh->v3 = k1 ^ 0x7465646279746573ULL; } -static inline void siphashadd64bits (siphash *sh, const uint64_t in) { +static INLINE void siphashadd64bits (siphash *sh, const uint64_t in) { const uint64_t mi = in; sh->v3 ^= mi; DOUBLE_ROUND(sh->v0,sh->v1,sh->v2,sh->v3); sh->v0 ^= mi; } -#pragma GCC diagnostic ignored "-Winline" -static inline uint64_t siphashfinish_last_part (siphash *sh, uint64_t t) { +static INLINE uint64_t siphashfinish_last_part (siphash *sh, uint64_t t) { sh->b |= t; sh->v3 ^= sh->b; DOUBLE_ROUND(sh->v0,sh->v1,sh->v2,sh->v3); @@ -102,7 +101,7 @@ union SipHash64_union { uint32_t u32; uint8_t u8[8]; }; -static inline uint64_t siphashfinish (siphash *sh, const uint8_t *src, size_t src_sz) { +static INLINE uint64_t siphashfinish (siphash *sh, const uint8_t *src, size_t src_sz) { union SipHash64_union t = { 0 }; switch (src_sz) { /* Falls through */ diff --git a/stdlib/siphash.c b/stdlib/siphash.c index a8e64c8..44e8b6e 100644 --- a/stdlib/siphash.c +++ b/stdlib/siphash.c @@ -49,11 +49,13 @@ public uint64_t TOMO_HASH_KEY[2] = {23, 42}; // Randomized in tomo_init() PUREFUNC public uint64_t siphash24(const uint8_t *src, size_t src_sz) { siphash sh; if ((uint64_t)src % __alignof__(uint64_t) == 0) { +#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wcast-align" const uint64_t *in = (uint64_t*)src; /* Find largest src_sz evenly divisible by 8 bytes. */ const ptrdiff_t src_sz_nearest_8bits = ((ptrdiff_t)src_sz >> 3) << 3; const uint64_t *goal = (uint64_t*)(src + src_sz_nearest_8bits); +#pragma GCC diagnostic pop siphashinit(&sh, src_sz); src_sz -= (size_t)src_sz_nearest_8bits; while (in < goal) { diff --git a/stdlib/stdlib.c b/stdlib/stdlib.c index d90f574..6e86a6d 100644 --- a/stdlib/stdlib.c +++ b/stdlib/stdlib.c @@ -129,6 +129,7 @@ static Array_t parse_array(const TypeInfo_t *item_info, int n, char *args[]) return items; } +#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wstack-protector" public void _tomo_parse_args(int argc, char *argv[], Text_t usage, Text_t help, int spec_len, cli_arg_t spec[spec_len]) { @@ -322,6 +323,7 @@ public void _tomo_parse_args(int argc, char *argv[], Text_t usage, Text_t help, } } } +#pragma GCC diagnostic pop void print_stack_trace(FILE *out, int start, int stop) { diff --git a/stdlib/tables.c b/stdlib/tables.c index 1b3759a..e55b1f5 100644 --- a/stdlib/tables.c +++ b/stdlib/tables.c @@ -59,7 +59,7 @@ const TypeInfo_t CStrToVoidStarTable = { .TableInfo={.key=&CString$info, .value=&MemoryPointer}, }; -PUREFUNC static inline size_t entry_size(const TypeInfo_t *info) +PUREFUNC static INLINE size_t entry_size(const TypeInfo_t *info) { size_t size = (size_t)info->TableInfo.key->size; if (info->TableInfo.value->align > 1 && size % (size_t)info->TableInfo.value->align) @@ -70,12 +70,12 @@ PUREFUNC static inline size_t entry_size(const TypeInfo_t *info) return size; } -PUREFUNC static inline size_t entry_align(const TypeInfo_t *info) +PUREFUNC static INLINE size_t entry_align(const TypeInfo_t *info) { return (size_t)MAX(info->TableInfo.key->align, info->TableInfo.value->align); } -PUREFUNC static inline size_t value_offset(const TypeInfo_t *info) +PUREFUNC static INLINE size_t value_offset(const TypeInfo_t *info) { size_t offset = (size_t)info->TableInfo.key->size; if ((size_t)info->TableInfo.value->align > 1 && offset % (size_t)info->TableInfo.value->align) @@ -83,7 +83,7 @@ PUREFUNC static inline size_t value_offset(const TypeInfo_t *info) return offset; } -static inline void hshow(const Table_t *t) +static INLINE void hshow(const Table_t *t) { hdebug("{"); for (uint32_t i = 0; t->bucket_info && i < t->bucket_info->count; i++) { @@ -217,6 +217,7 @@ static void hashmap_resize_buckets(Table_t *t, uint32_t new_capacity, const Type } // Return address of value +#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wstack-protector" public void *Table$reserve(Table_t *t, const void *key, const void *value, const TypeInfo_t *type) { @@ -276,6 +277,7 @@ public void *Table$reserve(Table_t *t, const void *key, const void *value, const Table$set_bucket(t, entry, entry_index, type); return entry + value_offset(type); } +#pragma GCC diagnostic pop public void Table$set(Table_t *t, const void *key, const void *value, const TypeInfo_t *type) { diff --git a/stdlib/text.c b/stdlib/text.c index 7b579f5..e8ecc78 100644 --- a/stdlib/text.c +++ b/stdlib/text.c @@ -86,7 +86,6 @@ static synthetic_grapheme_t *synthetic_graphemes = NULL; static int32_t synthetic_grapheme_capacity = 0; static int32_t num_synthetic_graphemes = 0; -#define MAIN_GRAPHEME_CODEPOINT(_g) ({ int32_t g = _g; (g) >= 0 ? (ucs4_t)(g) : synthetic_graphemes[-(g)-1].main_codepoint; }) #define NUM_GRAPHEME_CODEPOINTS(id) (synthetic_graphemes[-(id)-1].utf32_cluster[0]) #define GRAPHEME_CODEPOINTS(id) (&synthetic_graphemes[-(id)-1].utf32_cluster[1]) #define GRAPHEME_UTF8(id) (synthetic_graphemes[-(id)-1].utf8) @@ -117,6 +116,7 @@ static const TypeInfo_t GraphemeIDLookupTableInfo = { .tag=TableInfo, .TableInfo={.key=&GraphemeClusterInfo, .value=&Int32$info}, }; +#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wstack-protector" public int32_t get_synthetic_grapheme(const ucs4_t *codepoints, int64_t utf32_len) { @@ -201,6 +201,7 @@ public int32_t get_synthetic_grapheme(const ucs4_t *codepoints, int64_t utf32_le last_grapheme = grapheme_id; return grapheme_id; } +#pragma GCC diagnostic pop PUREFUNC static inline int64_t num_subtexts(Text_t t) { @@ -849,7 +850,8 @@ public int32_t Text$get_grapheme_fast(TextIter_t *state, int64_t index) public uint32_t Text$get_main_grapheme_fast(TextIter_t *state, int64_t index) { - return MAIN_GRAPHEME_CODEPOINT(Text$get_grapheme_fast(state, index)); + int32_t g = Text$get_grapheme_fast(state, index); + return (g) >= 0 ? (ucs4_t)(g) : synthetic_graphemes[-(g)-1].main_codepoint; } PUREFUNC public int32_t Text$compare(const Text_t *a, const Text_t *b) @@ -1016,7 +1018,7 @@ public int printf_text(FILE *stream, const struct printf_info *info, const void return Text$print(stream, t); } -static inline Text_t _quoted(Text_t text, bool colorize, char quote_char) +static INLINE Text_t _quoted(Text_t text, bool colorize, char quote_char) { // TODO: optimize for ASCII and short strings Array_t graphemes = {.atomic=1}; @@ -1228,7 +1230,7 @@ public Array_t Text$utf8_bytes(Text_t text) return (Array_t){.length=strlen(str), .stride=1, .atomic=1, .data=(void*)str}; } -static inline const char *codepoint_name(ucs4_t c) +static INLINE const char *codepoint_name(ucs4_t c) { char *name = GC_MALLOC_ATOMIC(UNINAME_MAX); char *found_name = unicode_character_name(c, name); diff --git a/stdlib/text.h b/stdlib/text.h index e915eef..4483c59 100644 --- a/stdlib/text.h +++ b/stdlib/text.h @@ -56,7 +56,7 @@ Text_t Text$repeat(Text_t text, Int_t count); int32_t Text$get_grapheme_fast(TextIter_t *state, int64_t index); uint32_t Text$get_main_grapheme_fast(TextIter_t *state, int64_t index); -static inline int32_t Text$get_grapheme(Text_t text, int64_t index) +static INLINE int32_t Text$get_grapheme(Text_t text, int64_t index) { TextIter_t state = {text, 0, 0}; return Text$get_grapheme_fast(&state, index); diff --git a/stdlib/types.h b/stdlib/types.h index f9b32af..a8a9b4e 100644 --- a/stdlib/types.h +++ b/stdlib/types.h @@ -53,7 +53,6 @@ struct TypeInfo_s { struct { const TypeInfo_t *type; } OptionalInfo; -#pragma GCC diagnostic ignored "-Wpedantic" struct {} OpaqueInfo; struct { const char *name; diff --git a/stdlib/util.h b/stdlib/util.h index b68e59b..9e83c2b 100644 --- a/stdlib/util.h +++ b/stdlib/util.h @@ -33,6 +33,10 @@ #define CONSTFUNC __attribute__ ((const)) #endif +#ifndef INLINE +#define INLINE inline __attribute__ ((always_inline)) +#endif + __attribute__((format(printf, 1, 2))) char *heap_strf(const char *fmt, ...); diff --git a/tomo.c b/tomo.c index a9e1172..632b4e8 100644 --- a/tomo.c +++ b/tomo.c @@ -60,6 +60,7 @@ static Text_t escape_lib_name(Text_t lib_name); static void build_library(Text_t lib_dir_name); static void compile_files(env_t *env, Array_t files, bool only_compile_arguments, Array_t *object_files, Array_t *ldlibs); +#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wstack-protector" int main(int argc, char *argv[]) { @@ -176,6 +177,7 @@ int main(int argc, char *argv[]) return 0; } } +#pragma GCC diagnostic pop Text_t escape_lib_name(Text_t lib_name) { diff --git a/typecheck.c b/typecheck.c index 6cc4121..9818ad3 100644 --- a/typecheck.c +++ b/typecheck.c @@ -20,6 +20,7 @@ type_t *parse_type_ast(env_t *env, type_ast_t *ast) { +#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wswitch-default" switch (ast->tag) { case VarTypeAST: { @@ -121,6 +122,7 @@ type_t *parse_type_ast(env_t *env, type_ast_t *ast) } case UnknownTypeAST: code_err(ast, "I don't know how to get this type"); } +#pragma GCC diagnostic pop errx(1, "Unreachable"); } @@ -478,6 +480,8 @@ type_t *get_clause_type(env_t *env, type_t *subject_t, when_clause_t *clause) type_t *get_type(env_t *env, ast_t *ast) { if (!ast) return NULL; +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wswitch-default" switch (ast->tag) { case Null: { type_t *t = parse_type_ast(env, Match(ast, Null)->type); @@ -1244,6 +1248,7 @@ type_t *get_type(env_t *env, ast_t *ast) case DateTime: return Type(DateTimeType); case Unknown: code_err(ast, "I can't figure out the type of: %W", ast); } +#pragma GCC diagnostic pop code_err(ast, "I can't figure out the type of: %W", ast); } @@ -1328,11 +1333,13 @@ PUREFUNC bool is_constant(env_t *env, ast_t *ast) case TextLiteral: { CORD literal = Match(ast, TextLiteral)->cord; CORD_pos i; +#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wsign-conversion" CORD_FOR(i, literal) { if (!isascii(CORD_pos_fetch(i))) return false; // Non-ASCII requires grapheme logic, not constant } +#pragma GCC diagnostic pop return true; // Literal ASCII string, OK } case Not: return is_constant(env, Match(ast, Not)->value); diff --git a/types.c b/types.c index 1a140a3..bcb0e9f 100644 --- a/types.c +++ b/types.c @@ -161,7 +161,7 @@ type_t *type_or_type(type_t *a, type_t *b) return NULL; } -static PUREFUNC inline double type_min_magnitude(type_t *t) +static PUREFUNC INLINE double type_min_magnitude(type_t *t) { switch (t->tag) { case BoolType: return (double)false; @@ -181,7 +181,7 @@ static PUREFUNC inline double type_min_magnitude(type_t *t) } } -static PUREFUNC inline double type_max_magnitude(type_t *t) +static PUREFUNC INLINE double type_max_magnitude(type_t *t) { switch (t->tag) { case BoolType: return (double)true; @@ -417,6 +417,7 @@ PUREFUNC size_t unpadded_struct_size(type_t *t) PUREFUNC size_t type_size(type_t *t) { +#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wswitch-default" switch (t->tag) { case UnknownType: case AbortType: case ReturnType: case VoidType: return 0; @@ -494,11 +495,14 @@ PUREFUNC size_t type_size(type_t *t) case TypeInfoType: return sizeof(TypeInfo_t); case ModuleType: return 0; } +#pragma GCC diagnostic pop errx(1, "This should not be reachable"); } PUREFUNC size_t type_align(type_t *t) { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wswitch-default" switch (t->tag) { case UnknownType: case AbortType: case ReturnType: case VoidType: return 0; case MemoryType: errx(1, "Memory has undefined type alignment"); @@ -560,6 +564,7 @@ PUREFUNC size_t type_align(type_t *t) case TypeInfoType: return __alignof__(TypeInfo_t); case ModuleType: return 0; } +#pragma GCC diagnostic pop errx(1, "This should not be reachable"); }