Skip to content

Commit 19727c8

Browse files
committed
rustc: Move a comment to the right spot in trans
I believe this comment here is mostly talking about the `ptrcast` function call below, so move the comment down to that block.
1 parent afb85cf commit 19727c8

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

src/librustc_trans/callee.rs

+23-24
Original file line numberDiff line numberDiff line change
@@ -53,35 +53,34 @@ pub fn get_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
5353
let sym = tcx.symbol_name(instance);
5454
debug!("get_fn({:?}: {:?}) => {}", instance, fn_ty, sym);
5555

56-
// This is subtle and surprising, but sometimes we have to bitcast
57-
// the resulting fn pointer. The reason has to do with external
58-
// functions. If you have two crates that both bind the same C
59-
// library, they may not use precisely the same types: for
60-
// example, they will probably each declare their own structs,
61-
// which are distinct types from LLVM's point of view (nominal
62-
// types).
63-
//
64-
// Now, if those two crates are linked into an application, and
65-
// they contain inlined code, you can wind up with a situation
66-
// where both of those functions wind up being loaded into this
67-
// application simultaneously. In that case, the same function
68-
// (from LLVM's point of view) requires two types. But of course
69-
// LLVM won't allow one function to have two types.
70-
//
71-
// What we currently do, therefore, is declare the function with
72-
// one of the two types (whichever happens to come first) and then
73-
// bitcast as needed when the function is referenced to make sure
74-
// it has the type we expect.
75-
//
76-
// This can occur on either a crate-local or crate-external
77-
// reference. It also occurs when testing libcore and in some
78-
// other weird situations. Annoying.
79-
8056
// Create a fn pointer with the substituted signature.
8157
let fn_ptr_ty = tcx.mk_fn_ptr(common::ty_fn_sig(ccx, fn_ty));
8258
let llptrty = type_of::type_of(ccx, fn_ptr_ty);
8359

8460
let llfn = if let Some(llfn) = declare::get_declared_value(ccx, &sym) {
61+
// This is subtle and surprising, but sometimes we have to bitcast
62+
// the resulting fn pointer. The reason has to do with external
63+
// functions. If you have two crates that both bind the same C
64+
// library, they may not use precisely the same types: for
65+
// example, they will probably each declare their own structs,
66+
// which are distinct types from LLVM's point of view (nominal
67+
// types).
68+
//
69+
// Now, if those two crates are linked into an application, and
70+
// they contain inlined code, you can wind up with a situation
71+
// where both of those functions wind up being loaded into this
72+
// application simultaneously. In that case, the same function
73+
// (from LLVM's point of view) requires two types. But of course
74+
// LLVM won't allow one function to have two types.
75+
//
76+
// What we currently do, therefore, is declare the function with
77+
// one of the two types (whichever happens to come first) and then
78+
// bitcast as needed when the function is referenced to make sure
79+
// it has the type we expect.
80+
//
81+
// This can occur on either a crate-local or crate-external
82+
// reference. It also occurs when testing libcore and in some
83+
// other weird situations. Annoying.
8584
if common::val_ty(llfn) != llptrty {
8685
debug!("get_fn: casting {:?} to {:?}", llfn, llptrty);
8786
consts::ptrcast(llfn, llptrty)

0 commit comments

Comments
 (0)