aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2017-05-29 04:25:56 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-09-06 01:37:32 +0200
commit15fa4d60ebba3025495bb34f0718764336d3dfe0 (patch)
tree8181fe37ffeb90f76f72da3363ba97ff75cb084c
parent448a527590b1446f7625d8b3280eb94c9a757702 (diff)
downloadsparse-dev-15fa4d60ebba3025495bb34f0718764336d3dfe0.tar.gz
topasm: top-level asm is special
Top-level ASM statements are parsed as fake anonymous functions. Obviously, they have few in common with functions (for example, they don't have a return type) and mixing the two makes things more complicated than needed (for example, to detect a top-level ASM, we had to check that the corresponding symbol (name) had a null ident). Avoid potential problems by special casing them and return early in linearize_fn(). As consequence, they now don't have anymore an OP_ENTRY as first instructions and can be detected by testing ep->entry. Note: It would be more logical to catch them even erlier, in linearize_symbol() but they also need an entrypoint and an active BB so that we can generate the single statement. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--linearize.c8
-rw-r--r--sparse.c2
-rw-r--r--validation/linear/asm-toplevel.c (renamed from validation/asm-toplevel.c)0
3 files changed, 7 insertions, 3 deletions
diff --git a/linearize.c b/linearize.c
index d657af82..441a4735 100644
--- a/linearize.c
+++ b/linearize.c
@@ -2429,12 +2429,16 @@ static struct entrypoint *linearize_fn(struct symbol *sym, struct symbol *base_t
return NULL;
ep = alloc_entrypoint();
- bb = alloc_basic_block(ep, sym->pos);
-
ep->name = sym;
sym->ep = ep;
+ bb = alloc_basic_block(ep, sym->pos);
set_activeblock(ep, bb);
+ if (stmt->type == STMT_ASM) { // top-level asm
+ linearize_asm_statement(ep, stmt);
+ return ep;
+ }
+
entry = alloc_instruction(OP_ENTRY, 0);
add_one_insn(ep, entry);
ep->entry = entry;
diff --git a/sparse.c b/sparse.c
index 6a445a17..975c0a4b 100644
--- a/sparse.c
+++ b/sparse.c
@@ -315,7 +315,7 @@ static void check_symbols(struct symbol_list *list)
expand_symbol(sym);
ep = linearize_symbol(sym);
- if (ep) {
+ if (ep && ep->entry) {
if (dbg_entry)
show_entry(ep);
diff --git a/validation/asm-toplevel.c b/validation/linear/asm-toplevel.c
index 8bdd7fc1..8bdd7fc1 100644
--- a/validation/asm-toplevel.c
+++ b/validation/linear/asm-toplevel.c