Skip to content
This repository has been archived by the owner on Feb 4, 2025. It is now read-only.

[ICE] Incorrect memcpy for struct when alignment < size #278

Closed
jyn514 opened this issue Feb 16, 2020 · 2 comments · Fixed by #309
Closed

[ICE] Incorrect memcpy for struct when alignment < size #278

jyn514 opened this issue Feb 16, 2020 · 2 comments · Fixed by #309
Labels
bug Something isn't working codegen Involves generating Cranelift IR good first issue Good for newcomers ICE Internal Compiler Error (panic)

Comments

@jyn514
Copy link
Owner

jyn514 commented Feb 16, 2020

Expected behavior
RCC should memcpy the whole struct up to the nearest multiple of the alignment.

Actual Behavior
RCC only copies the size of the struct, without the padding bits.

Code

int main() {
	struct S { int *y, z; } s, ss;
	s = ss;
}
The application panicked (crashed).
Message:  `size` is smaller than `dest` and `src`'s alignment value.
Location: /home/joshua/.local/lib/cargo/registry/src/github.com-1ecc6299db9ec823/cranelift-frontend-0.58.0/src/frontend.rs:820
Backtrace
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ BACKTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
                          (4 post panic frames hidden)                          
 4: cranelift_frontend::frontend::FunctionBuilder::emit_small_memmove::ha82eaace5e0d7fa5
    at /home/joshua/.local/lib/cargo/registry/src/github.com-1ecc6299db9ec823/cranelift-frontend-0.58.0/src/frontend.rs:820
 5: rcc::ir::expr::<impl rcc::ir::Compiler>::assignment::hba6a3763c064d501
    at src/ir/expr.rs:511
 6: rcc::ir::expr::<impl rcc::ir::Compiler>::compile_expr::hf2862280ec6077e1
    at src/ir/expr.rs:102
 7: rcc::ir::stmt::<impl rcc::ir::Compiler>::compile_stmt::h7e24c153b5470ada
    at src/ir/stmt.rs:37
 8: rcc::ir::stmt::<impl rcc::ir::Compiler>::compile_all::hf59a3cda5830301d
    at src/ir/stmt.rs:15
 9: rcc::ir::Compiler::compile_func::hff5573813724a524
    at src/ir/mod.rs:321
10: rcc::ir::compile::h9967cd2f3830dff1
    at src/ir/mod.rs:75
11: rcc::compile::h56c7e62b242f942d
    at src/lib.rs:179
12: rcc::real_main::h6aa73fa5e305122a
    at src/main.rs:109
13: rcc::main::hd71a6cc32e4b0a3f
    at src/main.rs:172

Thanks to @Byter09 for the fuzzing.

@jyn514 jyn514 added bug Something isn't working ICE Internal Compiler Error (panic) codegen Involves generating Cranelift IR labels Feb 16, 2020
@jyn514
Copy link
Owner Author

jyn514 commented Feb 26, 2020

Hmm ... maybe the issue here is that the size should be rounded up to the nearest multiple of the alignment?

@jyn514
Copy link
Owner Author

jyn514 commented Feb 27, 2020

Instructions:

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working codegen Involves generating Cranelift IR good first issue Good for newcomers ICE Internal Compiler Error (panic)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant