Skip to content

Mir: translation of indexing is incorrect #30474

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
nagisa opened this issue Dec 19, 2015 · 3 comments
Closed

Mir: translation of indexing is incorrect #30474

nagisa opened this issue Dec 19, 2015 · 3 comments
Labels
A-codegen Area: Code generation A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html

Comments

@nagisa
Copy link
Member

nagisa commented Dec 19, 2015

const C: [u32; 5] = [0, 42, 112, 212, 433];

#[rustc_mir(graphviz="foo.gv")]
fn mir() {
    C[3];
}

fn main(){}

will fail to compile with an LLVM abort:

Stored value type does not match pointer operand type!
  store [5 x i32] %4, i32* %temp1, align 4
 i32Invalid bitcast
i8 addrspace(9)* bitcast (%str_slice { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @str3466, i32 0, i32 0), i64 7 } to i8 addrspace(9)*)

Seems to be a mis-translation of indexing (trans/mir/lvalue at ProjectionElem::Index).

@luqmana luqmana added A-codegen Area: Code generation A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html labels Dec 19, 2015
@nagisa
Copy link
Member Author

nagisa commented Dec 19, 2015

This is not related to #30479.

According to @eddyb we might do something incorrectly with GEPs.

@eddyb
Copy link
Member

eddyb commented Dec 19, 2015

That was my first guess, but it seems that C[3] is an rvalue with the type [u32; 5], suggesting C itself was loaded.

@eddyb
Copy link
Member

eddyb commented Dec 19, 2015

Oh, my first guess was right: all GEPs are build::InBoundsGEP(bcx, tr_base.llval, &[llindex]) but that's not enough.
You see, GEP's first index is for the pointer itself. C[3] currently gets (mistakenly) translated as *(&C).offset(3) instead of the (correct) *(&C[0]).offset(3).
All GEP calls should use 0 as the first index and then the index of the array element/struct field.

nagisa added a commit to nagisa/rust that referenced this issue Dec 19, 2015
bors added a commit that referenced this issue Dec 21, 2015
jroesch pushed a commit to jroesch/rust that referenced this issue Jan 4, 2016
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-codegen Area: Code generation A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html
Projects
None yet
Development

No branches or pull requests

3 participants