Skip to content

rustc_codegen_llvm should mark more of its internal methods as unsafe #131562

Open
@clarfonthey

Description

@clarfonthey

Just following up from this comment I made here: #85532 (comment)

While LLVM compiled with asserts ensures that no undefined behaviour occurs when calling methods, it does not when compiled without asserts, and this should really be reflected in the signatures for all the various internal methods that just call out to LLVM FFI.

Right now, it's very easy to trigger UB when you're writing an intrinsic, and while it's common for C functions to have all sorts of undocumented preconditions, we should not extend this habit into Rust.

For example, const_array will trivially trigger UB if any of the Values passed into it are not actually constant:

And extract_value will trigger UB if the index is out of bounds for the given Value:

Whereas something like type_i1 is fine and will always be safe to call:

Sure, this will "introduce" unsafe code to, for example, the intrinsics lowering, but the code was already unsafe, and this is just documenting that.

@rustbot label T-compiler

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.P-lowLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions