ir_value* ir_value_vector_member(ir_value *self, unsigned int member)
{
+ char *name;
+ size_t len;
ir_value *m;
if (member >= 3)
return NULL;
if (self->members[member])
return self->members[member];
+ len = strlen(self->name);
+ name = (char*)mem_a(len + 3);
+ memcpy(name, self->name, len);
+ name[len+0] = '_';
+ name[len+1] = 'x' + member;
+ name[len+2] = '\0';
if (self->vtype == TYPE_VECTOR)
{
- m = ir_value_var(self->name, self->store, TYPE_FLOAT);
+ m = ir_value_var(name, self->store, TYPE_FLOAT);
+ mem_d(name);
if (!m)
return NULL;
m->context = self->context;
{
if (self->fieldtype != TYPE_VECTOR)
return NULL;
- m = ir_value_var(self->name, self->store, TYPE_FIELD);
+ m = ir_value_var(name, self->store, TYPE_FIELD);
+ mem_d(name);
if (!m)
return NULL;
m->fieldtype = TYPE_FLOAT;
*IR main operations
*/
+static bool ir_check_unreachable(ir_block *self)
+{
+ /* The IR should never have to deal with unreachable code */
+ if (!self->final/* || OPTS_FLAG(ALLOW_UNREACHABLE_CODE)*/)
+ return true;
+ irerror(self->context, "unreachable statement (%s)", self->label);
+ return false;
+}
+
bool ir_block_create_store_op(ir_block *self, lex_ctx ctx, int op, ir_value *target, ir_value *what)
{
ir_instr *in;
- if (self->final) {
- irerror(self->context, "unreachable statement (%s)", self->label);
+ if (!ir_check_unreachable(self))
return false;
- }
if (target->store == store_value &&
(op < INSTR_STOREP_F || op > INSTR_STOREP_FNC))
bool ir_block_create_return(ir_block *self, lex_ctx ctx, ir_value *v)
{
ir_instr *in;
- if (self->final) {
- irerror(self->context, "unreachable statement (%s)", self->label);
+ if (!ir_check_unreachable(self))
return false;
- }
self->final = true;
self->is_return = true;
in = ir_instr_new(ctx, self, INSTR_RETURN);
ir_block *ontrue, ir_block *onfalse)
{
ir_instr *in;
- if (self->final) {
- irerror(self->context, "unreachable statement (%s)", self->label);
+ if (!ir_check_unreachable(self))
return false;
- }
self->final = true;
/*in = ir_instr_new(ctx, self, (v->vtype == TYPE_STRING ? INSTR_IF_S : INSTR_IF_F));*/
in = ir_instr_new(ctx, self, VINSTR_COND);
bool ir_block_create_jump(ir_block *self, lex_ctx ctx, ir_block *to)
{
ir_instr *in;
- if (self->final) {
- irerror(self->context, "unreachable statement (%s)", self->label);
+ if (!ir_check_unreachable(self))
return false;
- }
self->final = true;
in = ir_instr_new(ctx, self, VINSTR_JUMP);
if (!in)
bool ir_block_create_goto(ir_block *self, lex_ctx ctx, ir_block *to)
{
ir_instr *in;
- if (self->final) {
- irerror(self->context, "unreachable statement (%s)", self->label);
+ if (!ir_check_unreachable(self))
return false;
- }
self->final = true;
in = ir_instr_new(ctx, self, INSTR_GOTO);
if (!in)
{
ir_value *out;
ir_instr *in;
+ if (!ir_check_unreachable(self))
+ return false;
in = ir_instr_new(ctx, self, VINSTR_PHI);
if (!in)
return NULL;
{
ir_value *out;
ir_instr *in;
+ if (!ir_check_unreachable(self))
+ return false;
in = ir_instr_new(ctx, self, (noreturn ? VINSTR_NRCALL : INSTR_CALL0));
if (!in)
return NULL;
+ /*
+ if (noreturn) {
+ self->final = true;
+ self->is_return = true;
+ }
+ */
out = ir_value_out(self->owner, label, (func->outtype == TYPE_VOID) ? store_return : store_value, func->outtype);
if (!out) {
ir_instr_delete(in);
return NULL;
}
vec_push(self->instr, in);
+ if (noreturn) {
+ if (!ir_block_create_return(self, ctx, NULL)) {
+ compile_error(ctx, "internal error: failed to generate dummy-return instruction");
+ ir_instr_delete(in);
+ return NULL;
+ }
+ }
return in;
}
ir_block *block = self->blocks[0];
for (i = 0; i < vec_size(block->living); ++i) {
ir_value *v = block->living[i];
- if (v->memberof || v->store != store_local)
+ if (v->store != store_local)
continue;
+ if ((v->members[0] && v->members[1] && v->members[2])) {
+ /* all vector members have been accessed - only treat this as uninitialized
+ * if any of them is also uninitialized.
+ */
+ if (!vec_ir_value_find(block->living, v->members[0], NULL) &&
+ !vec_ir_value_find(block->living, v->members[1], NULL) &&
+ !vec_ir_value_find(block->living, v->members[2], NULL))
+ {
+ continue;
+ }
+ }
+ if (v->memberof) {
+ /* A member is only uninitialized if the whole vector is also uninitialized */
+ if (!vec_ir_value_find(block->living, v->memberof, NULL))
+ continue;
+ }
if (irwarning(v->context, WARN_USED_UNINITIALIZED,
"variable `%s` may be used uninitialized in this function", v->name))
{
for (p = 0; p < vec_size(instr->phi); ++p)
{
value = instr->phi[p].value;
- if (value->memberof)
- value = value->memberof;
if (!vec_ir_value_find(self->living, value, NULL))
vec_push(self->living, value);
}
for (p = 0; p < vec_size(instr->params); ++p)
{
value = instr->params[p];
- if (value->memberof)
- value = value->memberof;
if (!vec_ir_value_find(self->living, value, NULL))
vec_push(self->living, value);
}
continue;
value = instr->_ops[o];
- if (value->memberof)
- value = value->memberof;
/* We only care about locals */
/* we also calculate parameter liferanges so that locals
#define IND_BUFSZ 1024
-#ifdef WIN32
-# define strncat(dst, src, sz) strncat_s(dst, sz, src, _TRUNCATE)
+#ifdef _MSC_VER
+# define strncat(dst, src, sz) strncat_s(dst, sz, src, _TRUNCATE)
#endif
const char *qc_opname(int op)