va_end(ap);
}
+static bool irwarning(lex_ctx ctx, int warntype, const char *fmt, ...)
+{
+ va_list ap;
+ int lvl = LVL_WARNING;
+
+ if (!OPTS_WARN(warntype))
+ return false;
+
+ if (opts_werror)
+ lvl = LVL_ERROR;
+
+ va_start(ap, fmt);
+ vprintmsg(lvl, ctx.file, ctx.line, "warning", fmt, ap);
+ va_end(ap);
+
+ return opts_werror;
+}
+
/***********************************************************************
*IR Builder
*/
if (param &&
self->locals_count &&
self->locals[self->locals_count-1]->store != store_param) {
- irerror(self->context, "cannot add parameters after adding locals\n");
+ irerror(self->context, "cannot add parameters after adding locals");
return NULL;
}
self->members[0] = NULL;
self->members[1] = NULL;
self->members[2] = NULL;
+ self->memberof = NULL;
MEM_VECTOR_INIT(self, life);
return self;
}
else
{
- irerror(self->context, "invalid member access on %s\n", self->name);
+ irerror(self->context, "invalid member access on %s", self->name);
return NULL;
}
+ m->memberof = self;
return m;
}
/* check if the entries overlap, for that,
* both must start before the other one ends.
*/
-#if defined(LIFE_RANGE_WITHOUT_LAST_READ)
- if (la->start <= lb->end &&
- lb->start <= la->end)
-#else
- if (la->start < lb->end &&
- lb->start < la->end)
-#endif
+ if (la->start < lb->end &&
+ lb->start < la->end)
{
return true;
}
if (target->store == store_value &&
(op < INSTR_STOREP_F || op > INSTR_STOREP_FNC))
{
- irerror(self->context, "cannot store to an SSA value\n");
- irerror(self->context, "trying to store: %s <- %s\n", target->name, what->name);
- irerror(self->context, "instruction: %s\n", asm_instr[op].m);
+ irerror(self->context, "cannot store to an SSA value");
+ irerror(self->context, "trying to store: %s <- %s", target->name, what->name);
+ irerror(self->context, "instruction: %s", asm_instr[op].m);
return false;
}
{
ir_instr *in;
if (self->final) {
- irerror(self->context, "block already ended (%s)\n", self->label);
+ irerror(self->context, "block already ended (%s)", self->label);
return false;
}
self->final = true;
{
ir_instr *in;
if (self->final) {
- irerror(self->context, "block already ended (%s)\n", self->label);
+ irerror(self->context, "block already ended (%s)", self->label);
return false;
}
self->final = true;
{
ir_instr *in;
if (self->final) {
- irerror(self->context, "block already ended (%s)\n", self->label);
+ irerror(self->context, "block already ended (%s)", self->label);
return false;
}
self->final = true;
{
ir_instr *in;
if (self->final) {
- irerror(self->context, "block already ended (%s)\n", self->label);
+ irerror(self->context, "block already ended (%s)", self->label);
return false;
}
self->final = true;
/* Must not be possible to cause this, otherwise the AST
* is doing something wrong.
*/
- irerror(self->context, "Invalid entry block for PHI\n");
+ irerror(self->context, "Invalid entry block for PHI");
abort();
}
}
}
} while (changed);
+ if (self->blocks_count) {
+ ir_block *block = self->blocks[0];
+ for (i = 0; i < block->living_count; ++i) {
+ ir_value *v = block->living[i];
+ if (v->memberof || v->store != store_local)
+ continue;
+ if (irwarning(v->context, WARN_USED_UNINITIALIZED,
+ "variable `%s` may be used uninitialized in this function", v->name))
+ {
+ return false;
+ }
+ }
+ }
return true;
}
tempbool = ir_value_life_merge(self->living[i], eid);
/* debug
if (tempbool)
- irerror(self->context, "block_living_add_instr() value instruction added %s: %i\n", self->living[i]->_name, (int)eid);
+ irerror(self->context, "block_living_add_instr() value instruction added %s: %i", self->living[i]->_name, (int)eid);
*/
changed = changed || tempbool;
}
if (!ir_block_living_add(self, prev->living[i]))
return false;
/*
- irerror(self->contextt from prev: %s\n", self->label, prev->living[i]->_name);
+ irerror(self->contextt from prev: %s", self->label, prev->living[i]->_name);
*/
}
return true;
size_t i, o, p;
/* bitmasks which operands are read from or written to */
size_t read, write;
-#if defined(LIFE_RANGE_WITHOUT_LAST_READ)
- size_t rd;
- new_reads_t new_reads;
-#endif
char dbg_ind[16] = { '#', '0' };
(void)dbg_ind;
-#if defined(LIFE_RANGE_WITHOUT_LAST_READ)
- MEM_VECTOR_INIT(&new_reads, v);
-#endif
-
if (prev)
{
if (!ir_block_life_prop_previous(self, prev, changed))
for (p = 0; p < instr->phi_count; ++p)
{
value = instr->phi[p].value;
-#if ! defined(LIFE_RANGE_WITHOUT_LAST_READ)
+ if (value->memberof)
+ value = value->memberof;
if (!ir_block_living_find(self, value, NULL) &&
!ir_block_living_add(self, value))
{
- goto on_error;
- }
-#else
- if (!new_reads_t_v_find(&new_reads, value, NULL))
- {
- if (!new_reads_t_v_add(&new_reads, value))
- goto on_error;
+ return false;
}
-#endif
}
/* call params are read operands too */
for (p = 0; p < instr->params_count; ++p)
{
value = instr->params[p];
-#if ! defined(LIFE_RANGE_WITHOUT_LAST_READ)
+ if (value->memberof)
+ value = value->memberof;
if (!ir_block_living_find(self, value, NULL) &&
!ir_block_living_add(self, value))
{
- goto on_error;
- }
-#else
- if (!new_reads_t_v_find(&new_reads, value, NULL))
- {
- if (!new_reads_t_v_add(&new_reads, value))
- goto on_error;
+ return false;
}
-#endif
}
/* See which operands are read and write operands */
continue;
value = instr->_ops[o];
+ if (value->memberof)
+ value = value->memberof;
/* We only care about locals */
/* we also calculate parameter liferanges so that locals
/* read operands */
if (read & (1<<o))
{
-#if ! defined(LIFE_RANGE_WITHOUT_LAST_READ)
if (!ir_block_living_find(self, value, NULL) &&
!ir_block_living_add(self, value))
{
- goto on_error;
- }
-#else
- /* fprintf(stderr, "read: %s\n", value->_name); */
- if (!new_reads_t_v_find(&new_reads, value, NULL))
- {
- if (!new_reads_t_v_add(&new_reads, value))
- goto on_error;
+ return false;
}
-#endif
}
/* write operands */
{
size_t idx;
bool in_living = ir_block_living_find(self, value, &idx);
-#if defined(LIFE_RANGE_WITHOUT_LAST_READ)
- size_t readidx;
- bool in_reads = new_reads_t_v_find(&new_reads, value, &readidx);
- if (!in_living && !in_reads)
-#else
if (!in_living)
-#endif
{
/* If the value isn't alive it hasn't been read before... */
/* TODO: See if the warning can be emitted during parsing or AST processing
*/
*changed = *changed || tempbool;
/* Then remove */
-#if ! defined(LIFE_RANGE_WITHOUT_LAST_READ)
if (!ir_block_living_remove(self, idx))
- goto on_error;
-#else
- if (in_reads)
- {
- if (!new_reads_t_v_remove(&new_reads, readidx))
- goto on_error;
- }
-#endif
+ return false;
}
}
}
/*fprintf(stderr, "living added values\n");*/
*changed = *changed || tempbool;
-#if defined(LIFE_RANGE_WITHOUT_LAST_READ)
- /* new reads: */
- for (rd = 0; rd < new_reads.v_count; ++rd)
- {
- if (!ir_block_living_find(self, new_reads.v[rd], NULL)) {
- if (!ir_block_living_add(self, new_reads.v[rd]))
- goto on_error;
- }
- if (!i && !self->entries_count) {
- /* fix the top */
- *changed = *changed || ir_value_life_merge(new_reads.v[rd], instr->eid);
- }
- }
- MEM_VECTOR_CLEAR(&new_reads, v);
-#endif
}
if (self->run_id == self->owner->run_id)
}
return true;
-on_error:
-#if defined(LIFE_RANGE_WITHOUT_LAST_READ)
- MEM_VECTOR_CLEAR(&new_reads, v);
-#endif
- return false;
}
/***********************************************************************
{
ir_value *fld = global->constval.vpointer;
if (!fld) {
- irerror(global->context, "Invalid field constant with no field: %s\n", global->name);
+ irerror(global->context, "Invalid field constant with no field: %s", global->name);
return false;
}
* for functions... might as well support that here.
*/
if (!fld->code.globaladdr) {
- irerror(global->context, "FIXME: Relocation support\n");
+ irerror(global->context, "FIXME: Relocation support");
return false;
}
{
ir_value *target = global->constval.vpointer;
if (!target) {
- irerror(global->context, "Invalid pointer constant: %s\n", global->name);
+ irerror(global->context, "Invalid pointer constant: %s", global->name);
/* NULL pointers are pointing to the NULL constant, which also
* sits at address 0, but still has an ir_value for itself.
*/
/* FIXME: Check for the constant nullptr ir_value!
* because then code.globaladdr being 0 is valid.
*/
- irerror(global->context, "FIXME: Relocation support\n");
+ irerror(global->context, "FIXME: Relocation support");
return false;
}
instr = block->instr[i];
if (instr->opcode == VINSTR_PHI) {
- irerror(block->context, "cannot generate virtual instruction (phi)\n");
+ irerror(block->context, "cannot generate virtual instruction (phi)");
return false;
}
}
if (instr->opcode == INSTR_STATE) {
- irerror(block->context, "TODO: state instruction\n");
+ irerror(block->context, "TODO: state instruction");
return false;
}
* for now. Dead blocks will not be translated obviously.
*/
if (!self->blocks_count) {
- irerror(self->context, "Function '%s' declared without body.\n", self->name);
+ irerror(self->context, "Function '%s' declared without body.", self->name);
return false;
}
return true;
if (!gen_blocks_recursive(self, block)) {
- irerror(self->context, "failed to generate blocks for '%s'\n", self->name);
+ irerror(self->context, "failed to generate blocks for '%s'", self->name);
return false;
}
if (!global->isconst || (!global->constval.vfunc))
{
- irerror(global->context, "Invalid state of function-global: not constant: %s\n", global->name);
+ irerror(global->context, "Invalid state of function-global: not constant: %s", global->name);
return false;
}
return true;
default:
/* refuse to create 'void' type or any other fancy business. */
- irerror(global->context, "Invalid type for global variable %s\n", global->name);
+ irerror(global->context, "Invalid type for global variable `%s`: %s",
+ global->name, type_name[global->vtype]);
return false;
}
}
* bytes is more than enough for a variable/field name
*/
if (len+2 >= sizeof(name)) {
- irerror(field->context, "invalid field name size: %u\n", (unsigned int)len);
+ irerror(field->context, "invalid field name size: %u", (unsigned int)len);
return false;
}
fld.type = field->fieldtype;
if (fld.type == TYPE_VOID) {
- irerror(field->context, "field is missing a type: %s - don't know its size\n", field->name);
+ irerror(field->context, "field is missing a type: %s - don't know its size", field->name);
return false;
}