aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-08-17 20:47:33 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2024-08-17 20:47:33 +0300
commit395efb9c8a0a0160a7b95769e9484bae5548bbde (patch)
treea5b4dc24dd3a2097d055b66b0cde8e23832802eb
parent2023a7b2d9656f80b00de81453348c0a66f200f7 (diff)
downloadek-395efb9c8a0a0160a7b95769e9484bae5548bbde.tar.gz
ek-395efb9c8a0a0160a7b95769e9484bae5548bbde.zip
add analyzer and fix some reported issues
-rw-r--r--Makefile6
-rw-r--r--gen/source.mk4
-rw-r--r--scripts/makefile17
-rw-r--r--src/actualize.c4
-rw-r--r--src/compiler.c13
-rw-r--r--src/debug.c2
-rw-r--r--src/lower.c5
-rw-r--r--src/res.c3
-rw-r--r--src/source.mk2
9 files changed, 41 insertions, 15 deletions
diff --git a/Makefile b/Makefile
index 9bd13a7..1a11df8 100644
--- a/Makefile
+++ b/Makefile
@@ -15,7 +15,11 @@ all: setup
.DEFAULT: setup
$(MAKE) -f scripts/makefile $<
-.PHONY:
+.PHONY: analyze
+analyze: setup
+ CC='gcc -fanalyzer' $(MAKE)
+
+.PHONY: setup
setup:
@echo -n > deps.mk
@./scripts/gen-deps -p EK -c COMPILE_EK -b ek "$(EK_SOURCES)"
diff --git a/gen/source.mk b/gen/source.mk
index 10295b2..162864f 100644
--- a/gen/source.mk
+++ b/gen/source.mk
@@ -3,3 +3,7 @@ gen/gen_parser.c: src/parser.y gen/gen_lexer.inc
gen/gen_lexer.inc: src/lexer.l
flex -o gen/gen_lexer.inc src/lexer.l
+
+build/gen/parser.o: gen/gen_parser.c
+ mkdir -p build/gen
+ $(COMPILE_EK) -fno-analyzer -c gen/gen_parser.c -o build/gen/parser.o
diff --git a/scripts/makefile b/scripts/makefile
index e247e7a..75631b7 100644
--- a/scripts/makefile
+++ b/scripts/makefile
@@ -32,9 +32,14 @@ OBJCOPY != [ "$(LLVM)" != "0" ] \
&& echo llvm-objcopy \
|| echo $(CROSS_COMPILE)objcopy
-COMPILER != [ "$(LLVM)" != "0" ] \
- && echo clang --target="$(CROSS_COMPILE)" \
- || echo $(CROSS_COMPILE)gcc
+COMPILER != [ -n "$(CROSS_COMPILE)" ] \
+ && { \
+ [ "$(LLVM)" != "0" ] \
+ && echo clang --target="$(CROSS_COMPILE)" \
+ || echo $(CROSS_COMPILE)gcc \
+ ; \
+ } \
+ || echo $(CC)
OBFLAGS := -g
@@ -60,10 +65,10 @@ COMPILE_EK = $(COMPILE) $(EK_FLAGS)
-include deps.mk
-ek: $(EK_OBJS)
- $(COMPILE_EK) $(EK_OBJS) -o $@
+ek: $(EK_OBJS) build/gen/parser.o
+ $(COMPILE_EK) $(EK_OBJS) build/gen/parser.o -o $@
# might lint some common things twice
.PHONY:
-lint: $(TRISCV_LINTS)
+lint: $(EK_LINTS)
diff --git a/src/actualize.c b/src/actualize.c
index ba5475e..aa5b398 100644
--- a/src/actualize.c
+++ b/src/actualize.c
@@ -2289,7 +2289,7 @@ static int actualize_dot(struct act_state *state,
if (!def) {
semantic_error(scope->fctx, node,
- "no such type");
+ "no such type");
return -1;
}
@@ -2305,7 +2305,7 @@ static int actualize_dot(struct act_state *state,
char *tstr = type_str(type);
semantic_error(scope->fctx, node,
"%s does not have have member",
- tstr);
+ tstr);
free(tstr);
return -1;
}
diff --git a/src/compiler.c b/src/compiler.c
index 14a838a..c29f6c7 100644
--- a/src/compiler.c
+++ b/src/compiler.c
@@ -82,21 +82,28 @@ static int process(struct scope **parent, int public, const char *file)
return -1;
struct parser *p = create_parser();
- if (!p)
+ if (!p) {
+ free((void *)buf);
return -1;
+ }
+
parse(p, file, buf);
struct ast *tree = p->tree;
bool failed = p->failed;
destroy_parser(p);
- if (failed)
+ if (failed) {
+ free((void*)buf);
return -1;
+ }
ast_dump_list(0, tree);
struct scope *scope = create_scope();
- if (!scope)
+ if (!scope) {
+ free((void *)buf);
return -1;
+ }
if (public)
scope_set_flags(scope, SCOPE_PUBLIC);
diff --git a/src/debug.c b/src/debug.c
index 32c74a2..f91accd 100644
--- a/src/debug.c
+++ b/src/debug.c
@@ -345,6 +345,8 @@ char *type_str(struct type *t)
char *buf = NULL; size_t size = 0;
/* hehe */
FILE *memstream = open_memstream(&buf, &size);
+ if (!memstream)
+ return NULL;
_type_str(memstream, t);
diff --git a/src/lower.c b/src/lower.c
index a01dd40..4093cbf 100644
--- a/src/lower.c
+++ b/src/lower.c
@@ -279,13 +279,14 @@ static int lower_param(struct lower_state *s, struct ast *p, struct vec *fixups)
assert(p->k == AST_VAR_DEF);
assert(var_init(p) == NULL);
- if (is_primitive(p->t) || p->t->k == TYPE_PTR || p->t->k == TYPE_CALLABLE) {
+ if (is_primitive(p->t) || p->t->k == TYPE_PTR ||
+ p->t->k == TYPE_CALLABLE) {
return lower_simple_param(s, p);
}
if (p->t->k != TYPE_STRUCT) {
semantic_error(p->scope->fctx, p,
- "illegal type");
+ "illegal type");
return -1;
}
diff --git a/src/res.c b/src/res.c
index 12d25ce..1d2b25b 100644
--- a/src/res.c
+++ b/src/res.c
@@ -26,6 +26,9 @@ static void res_expand(struct res *r)
struct res *res_create()
{
struct res *r = malloc(sizeof(struct res));
+ if (!r)
+ return NULL;
+
r->n = 0;
/* arbitrary number */
r->max = 1024;
diff --git a/src/source.mk b/src/source.mk
index e6e5182..703e4a8 100644
--- a/src/source.mk
+++ b/src/source.mk
@@ -1,2 +1,2 @@
SRC_LOCAL != echo src/*.c
-EK_SOURCES := $(EK_SOURCES) $(SRC_LOCAL) gen/gen_parser.c
+EK_SOURCES := $(EK_SOURCES) $(SRC_LOCAL)