summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2019-10-27 01:05:35 -0400
committerLeo Tenenbaum <pommicket@gmail.com>2019-10-27 01:05:35 -0400
commitf726c7b6628b44f55b9047e6423afa588f2ff4d5 (patch)
tree63b9a84bba8ac0be74663599583ec054d9a18b8a
parentcc17665ae2fcaa5efae55dcc78b905f0e7432faa (diff)
minor fixes to silence warnings when building release
-rw-r--r--arr.c2
-rw-r--r--blockarr.c2
-rwxr-xr-xbuild.sh14
-rw-r--r--cgen.c2
-rw-r--r--parse.c4
-rw-r--r--toc.c2
6 files changed, 21 insertions, 5 deletions
diff --git a/arr.c b/arr.c
index c87cf6f..0e67eb3 100644
--- a/arr.c
+++ b/arr.c
@@ -140,6 +140,7 @@ You shouldn't rely on this, though, e.g. by doing
#define arr_foreach(arr, type, var) for (type *var = arr_len(arr) ? arr : NULL, *var##_foreach_end = arr_last(arr); var; var == var##_foreach_end ? var = NULL : var++)
#define arr_remove_last(arr) arr_remove_last_((void **)(arr), sizeof **(arr))
+#ifdef TOC_DEBUG
static void arr_test(void) {
int *foos = NULL;
for (int i = 0; i < 1000; i++) {
@@ -155,3 +156,4 @@ static void arr_test(void) {
}
arr_clear(&foos);
}
+#endif
diff --git a/blockarr.c b/blockarr.c
index cc06774..eea2f80 100644
--- a/blockarr.c
+++ b/blockarr.c
@@ -47,6 +47,7 @@ static void block_arr_free(BlockArr *arr) {
arr_clear(&arr->blocks);
}
+#ifdef TOC_DEBUG
static void block_arr_test(void) {
BlockArr a;
int *ps[100];
@@ -61,3 +62,4 @@ static void block_arr_test(void) {
}
block_arr_free(&a);
}
+#endif
diff --git a/build.sh b/build.sh
index 9290a15..865313a 100755
--- a/build.sh
+++ b/build.sh
@@ -1,6 +1,10 @@
#!/bin/sh
if [ "$CC" = "" ]; then
- CC=gcc
+ if [ "$1" = "release" ]; then
+ CC=clang
+ else
+ CC=gcc
+ fi
fi
@@ -21,6 +25,12 @@ fi
DEBUG_FLAGS="-O0 -g3 $WARNINGS -std=c11 -DTOC_DEBUG"
RELEASE_FLAGS="-O3 -s -DNDEBUG $WARNINGS -std=c11"
-COMMAND="$CC $DEBUG_FLAGS $ADDITIONAL_FLAGS -o toc main.c"
+if [ "$1" = "release" ]; then
+ FLAGS="$RELEASE_FLAGS $ADDITIONAL_FLAGS"
+else
+ FLAGS="$DEBUG_FLAGS $ADDITIONAL_FLAGS"
+fi
+
+COMMAND="$CC $FLAGS -o toc main.c"
echo $COMMAND
$COMMAND || exit 1
diff --git a/cgen.c b/cgen.c
index e98224b..ec4c6ab 100644
--- a/cgen.c
+++ b/cgen.c
@@ -564,7 +564,7 @@ static bool cgen_new_slice(CGenerator *g, Type *t, IdentID id, Location where) {
}
static bool cgen_expr_pre(CGenerator *g, Expression *e) {
- IdentID id;
+ IdentID id = 0;
char ret_name[64];
switch (e->kind) {
case EXPR_IF:
diff --git a/parse.c b/parse.c
index 652f1bc..9061e12 100644
--- a/parse.c
+++ b/parse.c
@@ -838,7 +838,7 @@ static bool parse_expr(Parser *p, Expression *e, Token *end) {
int lowest_precedence = NOT_AN_OP;
/* e.g. (5+3) */
bool entirely_within_parentheses = token_is_kw(t->token, KW_LPAREN);
- Token *lowest_precedence_op;
+ Token *lowest_precedence_op = NULL;
for (Token *token = t->token; token < end; token++) {
if (token->kind == TOKEN_KW) {
switch (token->kw) {
@@ -1346,7 +1346,7 @@ static bool parse_decl(Parser *p, Declaration *d, DeclEndKind ends_with, uint16_
}
d->type = type;
}
- const char *end_str;
+ const char *end_str = NULL;
switch (ends_with) {
case DECL_END_SEMICOLON: end_str = "';'"; break;
case DECL_END_RPAREN_COMMA: end_str = "')' or ','"; break;
diff --git a/toc.c b/toc.c
index b6bc2a2..c25c489 100644
--- a/toc.c
+++ b/toc.c
@@ -27,4 +27,6 @@
#include "cgen.c"
#include "decls_cgen.c"
+#ifdef TOC_DEBUG
#include "tests.c"
+#endif