diff options
author | Wim Taymans <wtaymans@redhat.com> | 2014-09-17 16:06:35 +0200 |
---|---|---|
committer | Wim Taymans <wtaymans@redhat.com> | 2014-09-17 16:06:35 +0200 |
commit | 45957a71c26285ee097029706100e8555ff6189f (patch) | |
tree | ebdfa41a731d60827af8d646a38c47a2aee9eb88 /orc/orcprogram-c.c | |
parent | 4a7f1c0c1d9418e7d220110c5a0ec732f755c284 (diff) | |
download | orc-45957a71c26285ee097029706100e8555ff6189f.tar.gz |
opcodes: avoid undefined operations on signed ints
Cast to unsigned int when doing addition and subtraction that can
overflow.
Cast to unsigned int when doing the lower part of a multiplication.
Cast to unsigned int when doing left shifts into the sign bit.
Regenerate the emulation code. This should avoid multiple warnings
reported with clang and -fsanitize=undefined.
See https://bugzilla.gnome.org/show_bug.cgi?id=728738
Diffstat (limited to 'orc/orcprogram-c.c')
-rw-r--r-- | orc/orcprogram-c.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/orc/orcprogram-c.c b/orc/orcprogram-c.c index 2afb0cf..02b5aa8 100644 --- a/orc/orcprogram-c.c +++ b/orc/orcprogram-c.c @@ -441,8 +441,8 @@ orc_compiler_c_assemble (OrcCompiler *compiler) ORC_ASM_CODE(compiler," *%s = %s;\n", varnames[i], varname); } else if (compiler->target_flags & ORC_TARGET_C_OPCODE) { - ORC_ASM_CODE(compiler," ((orc_union32 *)ex->dest_ptrs[%d])->i += %s;\n", - i - ORC_VAR_A1, varname); + ORC_ASM_CODE(compiler," ((orc_union32 *)ex->dest_ptrs[%d])->i += (orc_uint%d)%s;\n", + i - ORC_VAR_A1, var->size * 8, varname); } else { ORC_ASM_CODE(compiler," ex->accumulators[%d] = %s;\n", i - ORC_VAR_A1, varname); @@ -1009,7 +1009,7 @@ c_rule_accl (OrcCompiler *p, void *user, OrcInstruction *insn) c_get_name_int (dest, p, insn, insn->dest_args[0]); c_get_name_int (src1, p, insn, insn->src_args[0]); - ORC_ASM_CODE(p," %s = %s + %s;\n", dest, dest, src1); + ORC_ASM_CODE(p," %s = ((orc_uint32)%s) + ((orc_uint32)%s);\n", dest, dest, src1); } static void @@ -1187,7 +1187,8 @@ c_rule_splatbl (OrcCompiler *p, void *user, OrcInstruction *insn) c_get_name_int (src, p, insn, insn->src_args[0]); ORC_ASM_CODE(p, - " %s = ((%s&0xff) << 24) | ((%s&0xff)<<16) | ((%s&0xff) << 8) | (%s&0xff);\n", + " %s = ((((orc_uint32)%s)&0xff) << 24) | ((((orc_uint32)%s)&0xff)<<16)" + " | ((((orc_uint32)%s)&0xff) << 8) | (((orc_uint32)%s)&0xff);\n", dest, src, src, src, src); } |