Fix up some GCC compiler flag options for LTO and inlining

This commit is contained in:
Bruce Hill 2024-10-29 23:14:31 -04:00
parent 3e019df9f4
commit 9ebb039a81
26 changed files with 119 additions and 78 deletions

View File

@ -8,17 +8,17 @@ LTO=-flto=auto -fno-fat-lto-objects -Wl,-flto
LDFLAGS= LDFLAGS=
# MAKEFLAGS := --jobs=$(shell nproc) --output-sync=target # MAKEFLAGS := --jobs=$(shell nproc) --output-sync=target
CWARN=-Wall -Wextra -Wno-format -Wshadow \ CWARN=-Wall -Wextra -Wno-format -Wshadow \
-Wpedantic \ -Wno-pedantic \
-Wno-pointer-arith \ -Wno-pointer-arith \
-Wsign-conversion -Wtype-limits -Wunused-result -Wnull-dereference \ -Wsign-conversion -Wtype-limits -Wunused-result -Wnull-dereference \
-Walloc-zero -Walloca -Warith-conversion -Wcast-align -Wcast-align=strict \ -Walloc-zero -Walloca -Warith-conversion -Wcast-align -Wcast-align=strict \
-Wdangling-else -Wdate-time -Wdisabled-optimization -Wdouble-promotion -Wduplicated-branches \ -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 \ -Wframe-address -Winline -Winvalid-pch -Wjump-misses-init \
-Wlogical-op -Wmissing-format-attribute -Wmissing-include-dirs -Wmissing-noreturn \ -Wlogical-op -Wmissing-format-attribute -Wmissing-include-dirs -Wmissing-noreturn \
-Wnull-dereference -Woverlength-strings -Wpacked -Wpacked-not-aligned \ -Wnull-dereference -Woverlength-strings -Wpacked -Wpacked-not-aligned \
-Wredundant-decls -Wshadow -Wshadow=compatible-local -Wshadow=global -Wshadow=local \ -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 \ -Wsync-nand -Wtrampolines -Wundef -Wunused -Wunused-but-set-variable \
-Wunused-const-variable -Wunused-local-typedefs -Wunused-macros -Wvariadic-macros -Wvector-operation-performance \ -Wunused-const-variable -Wunused-local-typedefs -Wunused-macros -Wvariadic-macros -Wvector-operation-performance \
-Wwrite-strings -Wwrite-strings
@ -26,7 +26,7 @@ OSFLAGS != case $$(uname -s) in *BSD|Darwin) echo '-D_BSD_SOURCE';; Linux) echo
EXTRA= EXTRA=
G=-ggdb G=-ggdb
O=-Og O=-Og
CFLAGS=$(CCONFIG) $(EXTRA) $(CWARN) $(G) $(O) $(OSFLAGS) CFLAGS=$(CCONFIG) $(EXTRA) $(CWARN) $(G) $(O) $(OSFLAGS) $(LTO)
CFLAGS_PLACEHOLDER="$$(echo -e '\033[2m<flags...>\033[m')" CFLAGS_PLACEHOLDER="$$(echo -e '\033[2m<flags...>\033[m')"
LDLIBS=-lgc -lcord -lm -lunistring -lgmp -ldl 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 \ BUILTIN_OBJS=stdlib/siphash.o stdlib/arrays.o stdlib/bools.o stdlib/bytes.o stdlib/channels.o stdlib/nums.o stdlib/integers.o \

1
ast.h
View File

@ -93,7 +93,6 @@ struct type_ast_s {
file_t *file; file_t *file;
const char *start, *end; const char *start, *end;
union { union {
#pragma GCC diagnostic ignored "-Wpedantic"
struct {} UnknownTypeAST; struct {} UnknownTypeAST;
struct { struct {
const char *name; const char *name;

View File

@ -1778,8 +1778,10 @@ static CORD compile_string_literal(CORD literal)
{ {
CORD code = "\""; CORD code = "\"";
CORD_pos i; CORD_pos i;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-conversion" #pragma GCC diagnostic ignored "-Wsign-conversion"
CORD_FOR(i, literal) { CORD_FOR(i, literal) {
#pragma GCC diagnostic pop
char c = CORD_pos_fetch(i); char c = CORD_pos_fetch(i);
switch (c) { switch (c) {
case '\\': code = CORD_cat(code, "\\\\"); break; 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) static bool string_literal_is_all_ascii(CORD literal)
{ {
CORD_pos i; CORD_pos i;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-conversion"
CORD_FOR(i, literal) { CORD_FOR(i, literal) {
#pragma GCC diagnostic pop
if (!isascii(CORD_pos_fetch(i))) if (!isascii(CORD_pos_fetch(i)))
return false; return false;
} }

View File

@ -20,8 +20,10 @@ public CORD CORD_quoted(CORD str)
{ {
CORD quoted = "\""; CORD quoted = "\"";
CORD_pos i; CORD_pos i;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-conversion" #pragma GCC diagnostic ignored "-Wsign-conversion"
CORD_FOR(i, str) { CORD_FOR(i, str) {
#pragma GCC diagnostic pop
char c = CORD_pos_fetch(i); char c = CORD_pos_fetch(i);
switch (c) { switch (c) {
case '\a': quoted = CORD_cat(quoted, "\\a"); break; 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 '\v': quoted = CORD_cat(quoted, "\\v"); break;
case '"': quoted = CORD_cat(quoted, "\\\""); break; case '"': quoted = CORD_cat(quoted, "\\\""); 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 '\x00' ... '\x06': case '\x0E' ... '\x1A':
case '\x1C' ... '\x1F': case '\x7F' ... '\x7F': case '\x1C' ... '\x1F': case '\x7F' ... '\x7F':
CORD_sprintf(&quoted, "%r\\x%02X", quoted, c); CORD_sprintf(&quoted, "%r\\x%02X", quoted, c);

34
parse.c
View File

@ -59,19 +59,19 @@ static const char *keywords[] = {
enum {NORMAL_FUNCTION=0, EXTERN_FUNCTION=1}; enum {NORMAL_FUNCTION=0, EXTERN_FUNCTION=1};
static inline size_t some_of(const char **pos, const char *allow); 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 some_not(const char **pos, const char *forbid);
static inline size_t spaces(const char **pos); static INLINE size_t spaces(const char **pos);
static inline void whitespace(const char **pos); static INLINE void whitespace(const char **pos);
static inline size_t match(const char **pos, const char *target); 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 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 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 size_t match_word(const char **pos, const char *word);
static inline const char* get_word(const char **pos); static INLINE const char* get_word(const char **pos);
static inline const char* get_id(const char **pos); static INLINE const char* get_id(const char **pos);
static inline bool comment(const char **pos); static INLINE bool comment(const char **pos);
static inline bool indent(parse_ctx_t *ctx, 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 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_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_field_suffix(parse_ctx_t *ctx, ast_t *lhs);
static ast_t *parse_fncall_suffix(parse_ctx_t *ctx, ast_t *fn); 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 // Convert an escape sequence like \n to a string
// //
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstack-protector" #pragma GCC diagnostic ignored "-Wstack-protector"
static const char *unescape(parse_ctx_t *ctx, const char **out) { static const char *unescape(parse_ctx_t *ctx, const char **out) {
const char **endpos = 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); 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); int64_t line_num = get_line_number(ctx->file, pos);
const char *line = get_line(ctx->file, line_num); const char *line = get_line(ctx->file, line_num);
@ -296,7 +298,7 @@ size_t match(const char **pos, const char *target) {
return len; 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; ucs4_t point = 0;
u8_next(&point, (const uint8_t*)pos); u8_next(&point, (const uint8_t*)pos);
return uc_is_property_xid_continue(point); 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); 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; const char *p = *pos;
int separators = 0; int separators = 0;
for (;;) { for (;;) {

2
repl.c
View File

@ -330,6 +330,7 @@ void run(env_t *env, ast_t *ast)
} }
} }
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstack-protector" #pragma GCC diagnostic ignored "-Wstack-protector"
void eval(env_t *env, ast_t *ast, void *dest) 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); 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 // vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0

View File

@ -16,7 +16,7 @@
#include "siphash.h" #include "siphash.h"
#include "siphash-internals.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; int64_t size = info->ArrayInfo.item->size;
if (info->ArrayInfo.item->align > 1 && size % info->ArrayInfo.item->align) 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; return arr;
} }
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstack-protector" #pragma GCC diagnostic ignored "-Wstack-protector"
public void Array$shuffle(Array_t *arr, int64_t padded_item_size) 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); 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) 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); 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) 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); assert(pos > 0 && pos < heap->length);

View File

@ -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}; 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) if (n == 0)
return Text("now"); return Text("now");

View File

@ -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)); 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)); return Table$get(function_names, &fn, Table$info(Function$info("???"), &Text$info));
} }

View File

@ -405,7 +405,6 @@ public const TypeInfo_t Int$info = {
}, },
}; };
#define DEFINE_INT_TYPE(c_type, KindOfInt, fmt, min_val, max_val, to_attr)\ #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) { \ public Text_t KindOfInt ## $as_text(const c_type *i, bool colorize, const TypeInfo_t *type) { \
(void)type; \ (void)type; \

View File

@ -37,12 +37,12 @@
c_type type_name ## $random(c_type min, c_type max); \ c_type type_name ## $random(c_type min, c_type max); \
to_attr Range_t type_name ## $to(c_type from, c_type to); \ 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 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); \ return x < min ? min : (x > max ? max : x); \
} \ } \
extern const c_type type_name ## $min, type_name##$max; \ extern const c_type type_name ## $min, type_name##$max; \
extern const TypeInfo_t type_name ## $info; \ 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; \ c_type q = D/d, r = D%d; \
if (r < 0) { \ if (r < 0) { \
if (d > 0) q = q-1; \ if (d > 0) q = q-1; \
@ -50,7 +50,7 @@
} \ } \
return q; \ 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; \ c_type r = D%d; \
if (r < 0) { \ if (r < 0) { \
if (d > 0) r = r + d; \ if (d > 0) r = r + d; \
@ -58,7 +58,7 @@
} \ } \
return r; \ 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; \ 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; 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); 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 // Fast-path inline versions for the common case where integer arithmetic is
// between two small ints. // 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); const int64_t z = (int64_t)((uint64_t)x.small + (uint64_t)y.small);
if (__builtin_expect(((z|2) == (int32_t)z), 1)) if (__builtin_expect(((z|2) == (int32_t)z), 1))
return (Int_t){.small=(z-1)}; return (Int_t){.small=(z-1)};
return Int$slow_plus(x, y); 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); const int64_t z = (int64_t)(((uint64_t)x.small ^ 3) - (uint64_t)y.small);
if (__builtin_expect(((z & ~2) == (int32_t)z), 1)) if (__builtin_expect(((z & ~2) == (int32_t)z), 1))
return (Int_t){.small=z}; return (Int_t){.small=z};
return Int$slow_minus(x, y); 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)) { if (__builtin_expect(((x.small & y.small) & 1) != 0, 1)) {
const int64_t z = (x.small>>1) * (y.small>>1); const int64_t z = (x.small>>1) * (y.small>>1);
if (__builtin_expect(z == (int32_t)z, 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); 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)) { 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 // 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); 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); 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)) { 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 // 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); 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); 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)) { 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 // 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; 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); 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)) { if (__builtin_expect(((x.small & y.small) & 1) != 0, 1)) {
const int64_t z = ((x.small>>2) << (y.small>>2))<<2; const int64_t z = ((x.small>>2) << (y.small>>2))<<2;
if (__builtin_expect(z == (int32_t)z, 1)) 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); 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)) { if (__builtin_expect(((x.small & y.small) & 1) != 0, 1)) {
const int64_t z = ((x.small>>2) >> (y.small>>2))<<2; const int64_t z = ((x.small>>2) >> (y.small>>2))<<2;
if (__builtin_expect(z == (int32_t)z, 1)) 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); 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; const int64_t z = x.small & y.small;
if (__builtin_expect((z & 1) == 1, 1)) if (__builtin_expect((z & 1) == 1, 1))
return (Int_t){.small=z}; return (Int_t){.small=z};
return Int$slow_bit_and(x, y); 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)) if (__builtin_expect(((x.small & y.small) & 1) == 1, 1))
return (Int_t){.small=(x.small | y.small)}; return (Int_t){.small=(x.small | y.small)};
return Int$slow_bit_or(x, y); 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)) if (__builtin_expect(((x.small & y.small) & 1) == 1, 1))
return (Int_t){.small=(x.small ^ y.small) | 1}; return (Int_t){.small=(x.small ^ y.small) | 1};
return Int$slow_bit_xor(x, y); 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)) if (__builtin_expect((x.small & 1), 1))
return (Int_t){.small=(~x.small) ^ 3}; return (Int_t){.small=(~x.small) ^ 3};
return Int$slow_negated(x); 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)) if (__builtin_expect((x.small & 1), 1))
return (Int_t){.small=((-((x.small)>>2))<<2) | 1}; return (Int_t){.small=((-((x.small)>>2))<<2) | 1};
return Int$slow_negative(x); 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)) if (__builtin_expect((x.small & 1), 1))
return x.small < 0; return x.small < 0;
@ -274,7 +274,7 @@ static inline bool Int$is_negative(Int_t x)
// Conversion functions: // 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; int64_t z = i<<2;
if (__builtin_expect(z == (int32_t)z, 1)) 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 Int16_to_Int(i) Int64_to_Int(i)
#define Int8_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" #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)) if (__builtin_expect(i.small & 1, 1))
return (int64_t)(i.small >> 2); return (int64_t)(i.small >> 2);
if (__builtin_expect(!truncate && !mpz_fits_slong_p(*i.big), 0)) if (__builtin_expect(!truncate && !mpz_fits_slong_p(*i.big), 0))
fail("Integer is too big to fit in a 64-bit integer!"); fail("Integer is too big to fit in a 64-bit integer!");
return mpz_get_si(*i.big); 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); int64_t i64 = Int_to_Int64(i, truncate);
int32_t i32 = (int32_t)i64; int32_t i32 = (int32_t)i64;
if (__builtin_expect(i64 != i32 && !truncate, 0)) 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; 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); int64_t i64 = Int_to_Int64(i, truncate);
int16_t i16 = (int16_t)i64; int16_t i16 = (int16_t)i64;
if (__builtin_expect(i64 != i16 && !truncate, 0)) 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; 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); int64_t i64 = Int_to_Int64(i, truncate);
int8_t i8 = (int8_t)i64; int8_t i8 = (int8_t)i64;
if (__builtin_expect(i64 != i8 && !truncate, 0)) 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; 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_t result;
mpz_init_set_d(result, n); mpz_init_set_d(result, n);
return Int$from_mpz(result); 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)) if (__builtin_expect(i.small & 1, 1))
return (double)(i.small >> 2); 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 Int_to_Num32(i) (Num32_t)Int_to_Num(i)
#define CONVERSION_FUNC(hi, lo) \ #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)) \ if (__builtin_expect(!truncate && (i != (int##lo##_t)i), 0)) \
fail("Cannot truncate the Int" #hi " %ld to an Int" #lo, (int64_t)i); \ fail("Cannot truncate the Int" #hi " %ld to an Int" #lo, (int64_t)i); \
return (int##lo##_t)i; \ return (int##lo##_t)i; \
@ -353,9 +355,10 @@ CONVERSION_FUNC(32, 8)
CONVERSION_FUNC(16, 8) CONVERSION_FUNC(16, 8)
#undef CONVERSION_FUNC #undef CONVERSION_FUNC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal" #pragma GCC diagnostic ignored "-Wfloat-equal"
#define CONVERSION_FUNC(num, int_type) \ #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); \ num##_t rounded = (num##_t)round((double)n); \
if (__builtin_expect(!truncate && (num##_t)(int_type##_t)rounded != rounded, 0)) \ if (__builtin_expect(!truncate && (num##_t)(int_type##_t)rounded != rounded, 0)) \
fail("Cannot truncate the " #num " %g to an " #int_type, (double)rounded); \ 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, Int32)
CONVERSION_FUNC(Num32, Int16) CONVERSION_FUNC(Num32, Int16)
CONVERSION_FUNC(Num32, Int8) CONVERSION_FUNC(Num32, Int8)
#pragma GCC diagnostic pop
#undef CONVERSION_FUNC #undef CONVERSION_FUNC
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0 // vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0

View File

@ -16,6 +16,7 @@
#include "util.h" #include "util.h"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstack-protector" #pragma GCC diagnostic ignored "-Wstack-protector"
PUREFUNC public uint64_t generic_hash(const void *obj, const TypeInfo_t *type) 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) PUREFUNC public int32_t generic_compare(const void *x, const void *y, const TypeInfo_t *type)
{ {

View File

@ -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" #pragma GCC diagnostic ignored "-Wstack-protector"
public Text_t Optional$as_text(const void *obj, bool colorize, const TypeInfo_t *type) 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("")); colorize ? Text("\x1b[m") : Text(""));
return Text$concat(generic_as_text(obj, colorize, type->OptionalInfo.type), colorize ? Text("\x1b[33m?\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 // vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1

View File

@ -106,7 +106,7 @@ public Path_t Path$cleanup(Path_t path)
return cleaned_up; 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("~/"))) { if (Text$starts_with(path, Path("~/"))) {
Path_t after_tilde = Text$slice(path, I(2), I(-1)); 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); 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); path = Path$_expand_home(path);
const char *path_str = Text$as_c_string(path); const char *path_str = Text$as_c_string(path);

View File

@ -33,7 +33,7 @@ typedef struct {
}; };
} pat_t; } 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) { while (*i < state->text.length) {
int32_t grapheme = Text$get_grapheme_fast(state, *i); 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) { if (*i < state->text.length && Text$get_grapheme_fast(state, *i) == grapheme) {
*i += 1; *i += 1;
@ -52,7 +52,7 @@ static inline bool match_grapheme(TextIter_t *state, int64_t *i, int32_t graphem
return false; 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; int64_t matched = 0;
while (matched[str]) { while (matched[str]) {
@ -64,7 +64,7 @@ static inline bool match_str(TextIter_t *state, int64_t *i, const char *str)
return true; 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; if (*i >= state->text.length) return false;
uint32_t grapheme = Text$get_main_grapheme_fast(state, *i); uint32_t grapheme = Text$get_main_grapheme_fast(state, *i);

View File

@ -68,7 +68,7 @@ typedef struct siphash siphash;
HALF_ROUND(v0,v1,v2,v3,13,16); \ HALF_ROUND(v0,v1,v2,v3,13,16); \
HALF_ROUND(v2,v1,v0,v3,17,21); 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 k0 = TOMO_HASH_KEY[0];
const uint64_t k1 = TOMO_HASH_KEY[1]; const uint64_t k1 = TOMO_HASH_KEY[1];
sh->b = (uint64_t)src_sz << 56; 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->v2 = k0 ^ 0x6c7967656e657261ULL;
sh->v3 = k1 ^ 0x7465646279746573ULL; 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; const uint64_t mi = in;
sh->v3 ^= mi; sh->v3 ^= mi;
DOUBLE_ROUND(sh->v0,sh->v1,sh->v2,sh->v3); DOUBLE_ROUND(sh->v0,sh->v1,sh->v2,sh->v3);
sh->v0 ^= mi; 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->b |= t;
sh->v3 ^= sh->b; sh->v3 ^= sh->b;
DOUBLE_ROUND(sh->v0,sh->v1,sh->v2,sh->v3); DOUBLE_ROUND(sh->v0,sh->v1,sh->v2,sh->v3);
@ -102,7 +101,7 @@ union SipHash64_union {
uint32_t u32; uint32_t u32;
uint8_t u8[8]; 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 }; union SipHash64_union t = { 0 };
switch (src_sz) { switch (src_sz) {
/* Falls through */ /* Falls through */

View File

@ -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) { PUREFUNC public uint64_t siphash24(const uint8_t *src, size_t src_sz) {
siphash sh; siphash sh;
if ((uint64_t)src % __alignof__(uint64_t) == 0) { if ((uint64_t)src % __alignof__(uint64_t) == 0) {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-align" #pragma GCC diagnostic ignored "-Wcast-align"
const uint64_t *in = (uint64_t*)src; const uint64_t *in = (uint64_t*)src;
/* Find largest src_sz evenly divisible by 8 bytes. */ /* Find largest src_sz evenly divisible by 8 bytes. */
const ptrdiff_t src_sz_nearest_8bits = ((ptrdiff_t)src_sz >> 3) << 3; const ptrdiff_t src_sz_nearest_8bits = ((ptrdiff_t)src_sz >> 3) << 3;
const uint64_t *goal = (uint64_t*)(src + src_sz_nearest_8bits); const uint64_t *goal = (uint64_t*)(src + src_sz_nearest_8bits);
#pragma GCC diagnostic pop
siphashinit(&sh, src_sz); siphashinit(&sh, src_sz);
src_sz -= (size_t)src_sz_nearest_8bits; src_sz -= (size_t)src_sz_nearest_8bits;
while (in < goal) { while (in < goal) {

View File

@ -129,6 +129,7 @@ static Array_t parse_array(const TypeInfo_t *item_info, int n, char *args[])
return items; return items;
} }
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstack-protector" #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]) 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) void print_stack_trace(FILE *out, int start, int stop)
{ {

View File

@ -59,7 +59,7 @@ const TypeInfo_t CStrToVoidStarTable = {
.TableInfo={.key=&CString$info, .value=&MemoryPointer}, .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; size_t size = (size_t)info->TableInfo.key->size;
if (info->TableInfo.value->align > 1 && size % (size_t)info->TableInfo.value->align) 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; 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); 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; size_t offset = (size_t)info->TableInfo.key->size;
if ((size_t)info->TableInfo.value->align > 1 && offset % (size_t)info->TableInfo.value->align) 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; return offset;
} }
static inline void hshow(const Table_t *t) static INLINE void hshow(const Table_t *t)
{ {
hdebug("{"); hdebug("{");
for (uint32_t i = 0; t->bucket_info && i < t->bucket_info->count; i++) { 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 // Return address of value
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstack-protector" #pragma GCC diagnostic ignored "-Wstack-protector"
public void *Table$reserve(Table_t *t, const void *key, const void *value, const TypeInfo_t *type) 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); Table$set_bucket(t, entry, entry_index, type);
return entry + value_offset(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) public void Table$set(Table_t *t, const void *key, const void *value, const TypeInfo_t *type)
{ {

View File

@ -86,7 +86,6 @@ static synthetic_grapheme_t *synthetic_graphemes = NULL;
static int32_t synthetic_grapheme_capacity = 0; static int32_t synthetic_grapheme_capacity = 0;
static int32_t num_synthetic_graphemes = 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 NUM_GRAPHEME_CODEPOINTS(id) (synthetic_graphemes[-(id)-1].utf32_cluster[0])
#define GRAPHEME_CODEPOINTS(id) (&synthetic_graphemes[-(id)-1].utf32_cluster[1]) #define GRAPHEME_CODEPOINTS(id) (&synthetic_graphemes[-(id)-1].utf32_cluster[1])
#define GRAPHEME_UTF8(id) (synthetic_graphemes[-(id)-1].utf8) #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}, .tag=TableInfo, .TableInfo={.key=&GraphemeClusterInfo, .value=&Int32$info},
}; };
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstack-protector" #pragma GCC diagnostic ignored "-Wstack-protector"
public int32_t get_synthetic_grapheme(const ucs4_t *codepoints, int64_t utf32_len) 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; last_grapheme = grapheme_id;
return grapheme_id; return grapheme_id;
} }
#pragma GCC diagnostic pop
PUREFUNC static inline int64_t num_subtexts(Text_t t) 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) 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) 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); 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 // TODO: optimize for ASCII and short strings
Array_t graphemes = {.atomic=1}; 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}; 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 *name = GC_MALLOC_ATOMIC(UNINAME_MAX);
char *found_name = unicode_character_name(c, name); char *found_name = unicode_character_name(c, name);

View File

@ -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); 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); 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}; TextIter_t state = {text, 0, 0};
return Text$get_grapheme_fast(&state, index); return Text$get_grapheme_fast(&state, index);

View File

@ -53,7 +53,6 @@ struct TypeInfo_s {
struct { struct {
const TypeInfo_t *type; const TypeInfo_t *type;
} OptionalInfo; } OptionalInfo;
#pragma GCC diagnostic ignored "-Wpedantic"
struct {} OpaqueInfo; struct {} OpaqueInfo;
struct { struct {
const char *name; const char *name;

View File

@ -33,6 +33,10 @@
#define CONSTFUNC __attribute__ ((const)) #define CONSTFUNC __attribute__ ((const))
#endif #endif
#ifndef INLINE
#define INLINE inline __attribute__ ((always_inline))
#endif
__attribute__((format(printf, 1, 2))) __attribute__((format(printf, 1, 2)))
char *heap_strf(const char *fmt, ...); char *heap_strf(const char *fmt, ...);

2
tomo.c
View File

@ -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 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); 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" #pragma GCC diagnostic ignored "-Wstack-protector"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
@ -176,6 +177,7 @@ int main(int argc, char *argv[])
return 0; return 0;
} }
} }
#pragma GCC diagnostic pop
Text_t escape_lib_name(Text_t lib_name) Text_t escape_lib_name(Text_t lib_name)
{ {

View File

@ -20,6 +20,7 @@
type_t *parse_type_ast(env_t *env, type_ast_t *ast) type_t *parse_type_ast(env_t *env, type_ast_t *ast)
{ {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wswitch-default" #pragma GCC diagnostic ignored "-Wswitch-default"
switch (ast->tag) { switch (ast->tag) {
case VarTypeAST: { 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"); case UnknownTypeAST: code_err(ast, "I don't know how to get this type");
} }
#pragma GCC diagnostic pop
errx(1, "Unreachable"); 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) type_t *get_type(env_t *env, ast_t *ast)
{ {
if (!ast) return NULL; if (!ast) return NULL;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wswitch-default"
switch (ast->tag) { switch (ast->tag) {
case Null: { case Null: {
type_t *t = parse_type_ast(env, Match(ast, Null)->type); 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 DateTime: return Type(DateTimeType);
case Unknown: code_err(ast, "I can't figure out the type of: %W", ast); 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); 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: { case TextLiteral: {
CORD literal = Match(ast, TextLiteral)->cord; CORD literal = Match(ast, TextLiteral)->cord;
CORD_pos i; CORD_pos i;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-conversion" #pragma GCC diagnostic ignored "-Wsign-conversion"
CORD_FOR(i, literal) { CORD_FOR(i, literal) {
if (!isascii(CORD_pos_fetch(i))) if (!isascii(CORD_pos_fetch(i)))
return false; // Non-ASCII requires grapheme logic, not constant return false; // Non-ASCII requires grapheme logic, not constant
} }
#pragma GCC diagnostic pop
return true; // Literal ASCII string, OK return true; // Literal ASCII string, OK
} }
case Not: return is_constant(env, Match(ast, Not)->value); case Not: return is_constant(env, Match(ast, Not)->value);

View File

@ -161,7 +161,7 @@ type_t *type_or_type(type_t *a, type_t *b)
return NULL; 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) { switch (t->tag) {
case BoolType: return (double)false; 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) { switch (t->tag) {
case BoolType: return (double)true; 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) PUREFUNC size_t type_size(type_t *t)
{ {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wswitch-default" #pragma GCC diagnostic ignored "-Wswitch-default"
switch (t->tag) { switch (t->tag) {
case UnknownType: case AbortType: case ReturnType: case VoidType: return 0; 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 TypeInfoType: return sizeof(TypeInfo_t);
case ModuleType: return 0; case ModuleType: return 0;
} }
#pragma GCC diagnostic pop
errx(1, "This should not be reachable"); errx(1, "This should not be reachable");
} }
PUREFUNC size_t type_align(type_t *t) PUREFUNC size_t type_align(type_t *t)
{ {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wswitch-default"
switch (t->tag) { switch (t->tag) {
case UnknownType: case AbortType: case ReturnType: case VoidType: return 0; case UnknownType: case AbortType: case ReturnType: case VoidType: return 0;
case MemoryType: errx(1, "Memory has undefined type alignment"); 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 TypeInfoType: return __alignof__(TypeInfo_t);
case ModuleType: return 0; case ModuleType: return 0;
} }
#pragma GCC diagnostic pop
errx(1, "This should not be reachable"); errx(1, "This should not be reachable");
} }