From 3d058de9cc8e58081d6c0eda410183388e26b85c Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Wed, 12 Jun 2024 01:15:26 +0200 Subject: Strip U+0027 APOSTROPHE from integer literals MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/codegen.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/codegen.c b/src/codegen.c index 410f68e..7f5d010 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -106,7 +106,17 @@ codegenexpr(LLVMBuilderRef builder, struct ast ast, struct lexemes toks, case ASTNUMLIT: { /* TODO: Arbitrary precision? */ struct strview sv = toks.strs[ast.lexemes[i]]; - *v = LLVMConstIntOfStringAndSize(LLVMInt64Type(), sv.p, sv.len, 10); + + /* TODO: Temporary one-time-use allocator? */ + size_t len = 0; + char *p = bufalloc(NULL, sv.len, 1); + for (size_t i = 0; i < sv.len; i++) { + if (sv.p[i] != '\'') + p[len++] = sv.p[i]; + } + + *v = LLVMConstIntOfStringAndSize(LLVMInt64Type(), p, len, 10); + free(p); return i + 1; } } -- cgit v1.2.3