From 20c1945c51e6ece5dd2cbab1cb06abd93b8778b4 Mon Sep 17 00:00:00 2001 From: Luqman Aden Date: Tue, 4 Nov 2014 22:31:20 -0500 Subject: [PATCH] librustc: Call return_type only for functions. --- src/librustc/middle/trans/build.rs | 2 +- src/test/run-fail/issue-18576.rs | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 src/test/run-fail/issue-18576.rs diff --git a/src/librustc/middle/trans/build.rs b/src/librustc/middle/trans/build.rs index 895f03ec2c7..3ae4fdf0838 100644 --- a/src/librustc/middle/trans/build.rs +++ b/src/librustc/middle/trans/build.rs @@ -655,7 +655,7 @@ pub fn _UndefReturn(cx: Block, fn_: ValueRef) -> ValueRef { unsafe { let ccx = cx.fcx.ccx; let ty = val_ty(fn_); - let retty = if ty.kind() == llvm::Integer { + let retty = if ty.kind() == llvm::Function { ty.return_type() } else { ccx.int_type() diff --git a/src/test/run-fail/issue-18576.rs b/src/test/run-fail/issue-18576.rs new file mode 100644 index 00000000000..0b82a0d8d83 --- /dev/null +++ b/src/test/run-fail/issue-18576.rs @@ -0,0 +1,23 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// error-pattern:stop + +// #18576 +// Make sure that an calling extern function pointer in an unreachable +// context doesn't cause an LLVM assertion + +#[allow(unreachable_code)] +fn main() { + panic!("stop"); + let pointer = other; + pointer(); +} +extern fn other() {}