jingoro2112 / wrench

practical embedded script interpreter
MIT License
106 stars 9 forks source link

Segmentation fault at the end of the function execution. #9

Closed glebnovodran closed 1 year ago

glebnovodran commented 1 year ago

Hello,

A reduced test case for getting it crashed is:

function faulty_func() {
    t = 1.0;
    x = t * 4.0;  // <-- any arithmetic operation involving a literal
    // can be x = 1.0 + 2.0;
    z = x * t; // <-- any binary operation on two variables
    return z;
}

The function should contain an arithmetic operation involving a numeric literal followed by a binary arithmetic operation on two variables.

Debugging it, I figured out that this line z = x * t; produces WR_ERR_bad_expression when the expression is being resolved. It happens here . resolves != startedWith for some reason.

Ultimately, it crashes at the end of the function execution.

jingoro2112 commented 1 year ago

I will put some time into this asap to get to the bottom

On Mon, May 29, 2023 at 2:04 PM Glib Novodran @.***> wrote:

Hello,

A reduced test case for getting it crashed is:

function faulty_func() { t = 1.0; x = t 4.0; // <-- any arithmetic operation involving a literal // can be x = 1.0 + 2.0; z = x t; // <-- any binary operation on two variables return z; }

The function should contain an arithmetic operation involving a numeric literal followed by a binary arithmetic operation on two variables.

Debugging it, I figured out that this line z = x * t; produces WR_ERR_bad_expression when the expression is being resolved. It happens here https://github.com/jingoro2112/wrench/blob/3838502c04fba683b4c0741bf370b8ca46615e19/src/wrench.cpp#L5135 . resolves != startedWith for some reason.

Ultimately, it crashes at the end of the function execution.

— Reply to this email directly, view it on GitHub https://github.com/jingoro2112/wrench/issues/9, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALIKA3NLZ34UENOSRARJIDXITQJPANCNFSM6AAAAAAYTBIUWY . You are receiving this because you are subscribed to this thread.Message ID: @.***>

jingoro2112 commented 1 year ago

This turned out to be an unclean state in the keyhole optimizer, which has been fixed and regressed.

Thank you so much for taking the time to report it!

glebnovodran commented 1 year ago

Glad to help.