Skip to content

Commit ca8c27e

Browse files
committed
Ensure llvm doesn't trigger an assert for crazy transmutes
1 parent bc3ba91 commit ca8c27e

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

src/librustc_codegen_llvm/mir/constant.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,8 @@ pub fn scalar_to_llvm(cx: &CodegenCx,
7070
&C_usize(cx, ptr.offset.bytes()),
7171
1,
7272
) };
73-
if layout.value != layout::Pointer {
74-
unsafe { llvm::LLVMConstPtrToInt(llval, llty.to_ref()) }
75-
} else {
76-
consts::bitcast(llval, llty)
77-
}
73+
let llval = unsafe { llvm::LLVMConstPtrToInt(llval, llty.to_ref()) };
74+
consts::bitcast(llval, llty)
7875
}
7976
}
8077
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
//compile-pass
12+
13+
fn main() {}
14+
15+
static FOO: u32 = 42;
16+
17+
union Foo {
18+
f: Float,
19+
r: &'static u32,
20+
}
21+
22+
#[cfg(target_pointer_width="64")]
23+
type Float = f64;
24+
25+
#[cfg(target_pointer_width="32")]
26+
type Float = f32;
27+
28+
static BAR: Float = unsafe { Foo { r: &FOO }.f };

0 commit comments

Comments
 (0)