Skip to content

Commit

Permalink
Fix transmute/compare ordered char
Browse files Browse the repository at this point in the history
  • Loading branch information
nickmqb committed Apr 7, 2019
1 parent dd8bf68 commit bb27528
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 8 additions & 0 deletions compiler/c_generator.mu
Expand Up @@ -1324,6 +1324,14 @@ CGenerator {
genLiftingBinaryOperator(c, op, e.lhs, e.rhs, sb, uni)
} else if (lhs.ti.flags & TypeFlags.pointer_) != 0 {
genBasicBinaryOperator(c, op, e, sb)
} else if lhs.ti == c.tags.char_.ti {
sb.write("((unsigned char)(")
genExpression(c, e.lhs, sb)
sb.write(")) ")
sb.write(op)
sb.write(" ((unsigned char)(")
genExpression(c, e.rhs, sb)
sb.write("))")
} else if lhs.ti == c.tags.string_.ti {
sb.write("string__compare__(")
genExpression(c, e.lhs, sb)
Expand Down
6 changes: 5 additions & 1 deletion compiler/c_generator_builtin.mu
Expand Up @@ -388,7 +388,11 @@ CGenerator {
if (from.ti.flags & (TypeFlags.anyPointerExceptTaggedPointer | TypeFlags.char_)) != 0 && (to.ti.flags & TypeFlags.intval) != 0 {
rb.write("(")
writeTag(rb, to)
rb.write(")(uintptr_t)(")
if (from.ti.flags & (TypeFlags.char_)) != 0 {
rb.write(")(unsigned char)(")
} else {
rb.write(")(uintptr_t)(")
}
genExpression(c, e.args[0], rb)
rb.write(")")
return
Expand Down

0 comments on commit bb27528

Please sign in to comment.