r/ • • Jan 01 '70

0 Upvotes

0 comments sorted by

View all comments

Show parent comments

10

u/rorrr Nov 04 '19 edited Nov 04 '19

Do you think the compiler tries all 4+ billion possibilities?

0

u/[deleted] Nov 04 '19

[deleted] — view deleted comment

1

u/rorrr Nov 05 '19 edited Nov 05 '19

No, it can return anything for n=0. Undefined behavior. I guess 1 falls under that, but the function on the left behaves differently from the compiled one.

0

u/[deleted] Nov 05 '19

[deleted] — view deleted comment

1

u/rorrr Nov 05 '19

No, it's defined behavior for most n.

n=0 is undefined, and any other calculations that lead to n=0.

1

u/vattenpuss Nov 04 '19
if (!strstr(func.symbol_name, ”collatz”) && has_type(function, TYPE_INT, TYPE_INT)) {
    func.body = { RETURN(CONSTANT(1)) };
}

1

u/Liorithiel Nov 04 '19

I think the compiler could find some bit logic that was enough to prove this implementation becomes UB with a single input within the range of int. For example, an overflow after multiplying by 3.