static void sanitize_assert(const out_val *cond, out_ctx *octx, const char *desc) { out_blk *land = out_blk_new(octx, "san_end"); out_blk *blk_undef = out_blk_new(octx, "san_bad"); out_ctrl_branch(octx, cond, land, blk_undef); out_current_blk(octx, blk_undef); out_comment(octx, "sanitizer for %s", desc); if(cc1_sanitize_handler_fn) { type *voidty = type_nav_btype(cc1_type_nav, type_void); funcargs *args = funcargs_new(); type *fnty_noptr = type_func_of(voidty, args, NULL); type *fnty_ptr = type_ptr_to(fnty_noptr); char *mangled = func_mangle(cc1_sanitize_handler_fn, fnty_noptr); const out_val *fn = out_new_lbl(octx, fnty_ptr, mangled, 0); out_val_release(octx, out_call(octx, fn, NULL, fnty_ptr)); if(mangled != cc1_sanitize_handler_fn) free(mangled); } out_ctrl_end_undefined(octx); out_current_blk(octx, land); }
static void check_implicit_funcall(expr *e, symtable *stab, char **const psp) { struct symtab_entry ent; funcargs *args; decl *df, *owning_func; type *func_ty; if(e->expr->in_parens || !expr_kind(e->expr, identifier) /* not folded yet, hence no 'e->expr->bits.ident.type != IDENT_NORM' */ /* get the spel that parse stashes in the identifier expr: */ || !((*psp) = e->expr->bits.ident.bits.ident.spel)) { return; } /* check for implicit function */ if(symtab_search(stab, *psp, NULL, &ent) && ent.type == SYMTAB_ENT_DECL) { e->expr->bits.ident.bits.ident.sym = ent.bits.decl->sym; return; } args = funcargs_new(); /* set up the funcargs as if it's "x()" - i.e. any args */ funcargs_empty(args); func_ty = type_func_of( type_nav_btype(cc1_type_nav, type_int), args, symtab_new(stab, &e->where) /*new symtable for args*/); cc1_warn_at(&e->expr->where, implicit_func, "implicit declaration of function \"%s\"", *psp); df = decl_new(); memcpy_safe(&df->where, &e->where); df->ref = func_ty; df->spel = e->expr->bits.ident.bits.ident.spel; df->flags |= DECL_FLAGS_IMPLICIT; fold_decl(df, stab); /* update calling conv, for e.g. */ df->sym->type = sym_global; e->expr->bits.ident.bits.ident.sym = df->sym; e->expr->tree_type = func_ty; owning_func = symtab_func(stab); if(owning_func) symtab_insert_before(symtab_root(stab), owning_func, df); else symtab_add_to_scope(symtab_root(stab), df); /* function call at global scope */ }