aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-07-01 19:59:46 +0200
committerThomas Voss <mail@thomasvoss.com> 2024-07-01 19:59:46 +0200
commit325db44028d817942861ca98d6ed06c320fb39ae (patch)
tree9312adfc261a21ec16ddb41d46a81ef0ef3f5bde
parent0543c146ad5904e3f7ad5a6208e9f30f72f47ca5 (diff)
Disallow static undefined variables
-rw-r--r--src/analyzer.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/analyzer.c b/src/analyzer.c
index 68029fd..e7199ca 100644
--- a/src/analyzer.c
+++ b/src/analyzer.c
@@ -195,9 +195,13 @@ analyzedecl(struct azctx ctx, scope_t *scps, type_t *types, ast_t ast,
{
strview_t sv = toks.strs[ast.lexemes[i]];
- bool isstatic = ast.kinds[i] <= _AST_DECLS_END
- && aux.buf[ast.kids[i].lhs].decl.isstatic;
bool isconst = ast.kinds[i] == ASTCDECL;
+ bool isundef = aux.buf[ast.kids[i].lhs].decl.isundef;
+ bool isstatic = ast.kinds[i] <= _AST_DECLS_END
+ && aux.buf[ast.kids[i].lhs].decl.isstatic;
+
+ if (isstatic && isundef)
+ err("analyzer: Static variables may not be undefined");
if (!isconst && !isstatic) {
symval_t *sym = symtab_insert(&scps[ctx.si].map, sv, ctx.a);