Giter VIP home page Giter VIP logo

Comments (6)

shaleh avatar shaleh commented on May 28, 2024

@kazcw what is our alternative? How likely is this to fail in practice?

from remacs.

kazcw avatar kazcw commented on May 28, 2024

If it were just a matter of breaking rustc's invariants that might not be as bad, because rustc itself doesn't do a lot of wild optimizations; but it compiles to getelementptr inbounds { ... }, { ... }* null, ..., which is a trap value to LLVM, causing the subsequent ptrtoint to be UB, and leaving you at LLVM's mercy. LLVM's mercy tends to involve nasal demons.

In this case one option would be: instead of doing the address calculations using a hypothetical instance at NULL, use a real instance. Since this macro is only used with C structs, and Rust has no constraints on the value range of fields in C structs, the example value can be conjured with mem::zeroed. You could use a trivial trait to mark that the types it operates on can be zero-initialized safely, and then use the trait's method instead of ptr::null(). In release builds the example value will be optimized away.

from remacs.

shaleh avatar shaleh commented on May 28, 2024

Thank you for the explanation @kazcw that is very helpful.

from remacs.

shaleh avatar shaleh commented on May 28, 2024

Ok, let's try moving to https://github.com/Gilnaa/memoffset.
This does NOT fix the problem that @kazcw raises. However, it moves the problem of solving it out of our code base. They have ideas and are looking at using solutions from the RFC mentioned which has actually been more than partially implemented. Long term, there may end up being a supported macro from the Rust core and we drop the dependency. A pre-RFC exists for such a macro currently.

from remacs.

agraven avatar agraven commented on May 28, 2024

In that case I presume we need to replace the usage of offset_of! the field-offset crate in LispBufferRef::reset_local_variables as well? (I didn't realize we had our own macro when I imported that crate)

from remacs.

RalfJung avatar RalfJung commented on May 28, 2024

FWIW, the latest version of https://github.com/Gilnaa/memoffset actually works in a way that is compliant with the Rust Reference. :)

But doing * on a NULL pointer is still UB, even inside addr_of!.

from remacs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.