@@ -53,35 +53,34 @@ pub fn get_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
53
53
let sym = tcx. symbol_name ( instance) ;
54
54
debug ! ( "get_fn({:?}: {:?}) => {}" , instance, fn_ty, sym) ;
55
55
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
-
80
56
// Create a fn pointer with the substituted signature.
81
57
let fn_ptr_ty = tcx. mk_fn_ptr ( common:: ty_fn_sig ( ccx, fn_ty) ) ;
82
58
let llptrty = type_of:: type_of ( ccx, fn_ptr_ty) ;
83
59
84
60
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.
85
84
if common:: val_ty ( llfn) != llptrty {
86
85
debug ! ( "get_fn: casting {:?} to {:?}" , llfn, llptrty) ;
87
86
consts:: ptrcast ( llfn, llptrty)
0 commit comments