File tree 18 files changed +502
-0
lines changed
18 files changed +502
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Copyright 2012 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
+ #[ no_mangle]
12
+ pub extern "C" fn foo ( ) -> uint {
13
+ 1234
14
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright 2012 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
+ #[ inline]
12
+ pub fn cci_fn ( ) -> uint {
13
+ 1200
14
+ }
15
+
16
+ #[ inline]
17
+ pub static CCI_STATIC : uint = 34 ;
Original file line number Diff line number Diff line change
1
+ // Copyright 2012 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-flags: -C codegen-units=3 --crate-type=rlib,dylib
12
+
13
+ pub mod a {
14
+ pub fn one ( ) -> uint {
15
+ 1
16
+ }
17
+ }
18
+
19
+ pub mod b {
20
+ pub fn two ( ) -> uint {
21
+ 2
22
+ }
23
+ }
24
+
25
+ pub mod c {
26
+ use a:: one;
27
+ use b:: two;
28
+ pub fn three ( ) -> uint {
29
+ one ( ) + two ( )
30
+ }
31
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright 2012 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
+ // Make sure we give a sane error message when the user requests LTO with a
12
+ // library built with -C codegen-units > 1.
13
+
14
+ // aux-build:sepcomp_lib.rs
15
+ // compile-flags: -Z lto
16
+ // error-pattern:missing compressed bytecode
17
+ // no-prefer-dynamic
18
+
19
+ extern crate sepcomp_lib;
20
+ use sepcomp_lib:: a:: one;
21
+ use sepcomp_lib:: b:: two;
22
+ use sepcomp_lib:: c:: three;
23
+
24
+ fn main ( ) {
25
+ assert_eq ! ( one( ) , 1 ) ;
26
+ assert_eq ! ( two( ) , 2 ) ;
27
+ assert_eq ! ( three( ) , 3 ) ;
28
+ }
Original file line number Diff line number Diff line change
1
+ -include ../tools.mk
2
+
3
+ # Check that cross-crate inlined items are inlined in all compilation units
4
+ # that refer to them, and not in any other compilation units.
5
+
6
+ all :
7
+ $(RUSTC ) cci_lib.rs
8
+ $(RUSTC ) foo.rs --emit=ir -C codegen-units=3
9
+ [ " $$ (cat " $( TMPDIR) " /foo.?.ll | grep -c define\ .*cci_fn)" -eq " 2" ]
10
+ [ " $$ (cat " $( TMPDIR) " /foo.?.ll | grep -c CCI_STATIC.*=.*constant)" -eq " 2" ]
Original file line number Diff line number Diff line change
1
+ // Copyright 2012 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
+ #![ crate_type = "rlib" ]
12
+
13
+ #[ inline]
14
+ pub fn cci_fn ( ) -> uint {
15
+ 1234
16
+ }
17
+
18
+ #[ inline]
19
+ pub static CCI_STATIC : uint = 2345 ;
Original file line number Diff line number Diff line change
1
+ // Copyright 2014 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
+ extern crate cci_lib;
12
+ use cci_lib:: { cci_fn, CCI_STATIC } ;
13
+
14
+ fn call1 ( ) -> uint {
15
+ cci_fn ( ) + CCI_STATIC
16
+ }
17
+
18
+ mod a {
19
+ use cci_lib:: cci_fn;
20
+ pub fn call2 ( ) -> uint {
21
+ cci_fn ( )
22
+ }
23
+ }
24
+
25
+ mod b {
26
+ use cci_lib:: CCI_STATIC ;
27
+ pub fn call3 ( ) -> uint {
28
+ CCI_STATIC
29
+ }
30
+ }
31
+
32
+ fn main ( ) {
33
+ call1 ( ) ;
34
+ a:: call2 ( ) ;
35
+ b:: call3 ( ) ;
36
+ }
Original file line number Diff line number Diff line change
1
+ -include ../tools.mk
2
+
3
+ # Test that #[inline(always)] functions still get inlined across compilation
4
+ # unit boundaries. Compilation should produce three IR files, with each one
5
+ # containing a definition of the inlined function. Also, the non-#[inline]
6
+ # function should be defined in only one compilation unit.
7
+
8
+ all :
9
+ $(RUSTC ) foo.rs --emit=ir -C codegen-units=3
10
+ [ " $$ (cat " $( TMPDIR) " /foo.?.ll | grep -c define\ i32\ .*inlined)" -eq " 1" ]
11
+ [ " $$ (cat " $( TMPDIR) " /foo.?.ll | grep -c define\ available_externally\ i32\ .*inlined)" -eq " 2" ]
12
+ [ " $$ (cat " $( TMPDIR) " /foo.?.ll | grep -c define\ i32\ .*normal)" -eq " 1" ]
13
+ [ " $$ (cat " $( TMPDIR) " /foo.?.ll | grep -c declare\ i32\ .*normal)" -eq " 2" ]
Original file line number Diff line number Diff line change
1
+ // Copyright 2014 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
+ #[ inline]
12
+ fn inlined ( ) -> u32 {
13
+ 1234
14
+ }
15
+
16
+ fn normal ( ) -> u32 {
17
+ 2345
18
+ }
19
+
20
+ mod a {
21
+ pub fn f ( ) -> u32 {
22
+ :: inlined ( ) + :: normal ( )
23
+ }
24
+ }
25
+
26
+ mod b {
27
+ pub fn f ( ) -> u32 {
28
+ :: inlined ( ) + :: normal ( )
29
+ }
30
+ }
31
+
32
+ fn main ( ) {
33
+ a:: f ( ) ;
34
+ b:: f ( ) ;
35
+ }
Original file line number Diff line number Diff line change
1
+ -include ../tools.mk
2
+
3
+ # Test that separate compilation actually puts code into separate compilation
4
+ # units. `foo.rs` defines `magic_fn` in three different modules, which should
5
+ # wind up in three different compilation units.
6
+
7
+ all :
8
+ $(RUSTC ) foo.rs --emit=ir -C codegen-units=3
9
+ [ " $$ (cat " $( TMPDIR) " /foo.?.ll | grep -c define\ .*magic_fn)" -eq " 3" ]
Original file line number Diff line number Diff line change
1
+ // Copyright 2014 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
+ fn magic_fn ( ) -> uint {
12
+ 1234
13
+ }
14
+
15
+ mod a {
16
+ pub fn magic_fn ( ) -> uint {
17
+ 2345
18
+ }
19
+ }
20
+
21
+ mod b {
22
+ pub fn magic_fn ( ) -> uint {
23
+ 3456
24
+ }
25
+ }
26
+
27
+ fn main ( ) { }
Original file line number Diff line number Diff line change
1
+ // Copyright 2012 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-flags: -C codegen-units=3
12
+ // aux-build:sepcomp_cci_lib.rs
13
+
14
+ // Test accessing cross-crate inlined items from multiple compilation units.
15
+
16
+ extern crate sepcomp_cci_lib;
17
+ use sepcomp_cci_lib:: { cci_fn, CCI_STATIC } ;
18
+
19
+ fn call1 ( ) -> uint {
20
+ cci_fn ( ) + CCI_STATIC
21
+ }
22
+
23
+ mod a {
24
+ use sepcomp_cci_lib:: { cci_fn, CCI_STATIC } ;
25
+ pub fn call2 ( ) -> uint {
26
+ cci_fn ( ) + CCI_STATIC
27
+ }
28
+ }
29
+
30
+ mod b {
31
+ use sepcomp_cci_lib:: { cci_fn, CCI_STATIC } ;
32
+ pub fn call3 ( ) -> uint {
33
+ cci_fn ( ) + CCI_STATIC
34
+ }
35
+ }
36
+
37
+ fn main ( ) {
38
+ assert_eq ! ( call1( ) , 1234 ) ;
39
+ assert_eq ! ( a:: call2( ) , 1234 ) ;
40
+ assert_eq ! ( b:: call3( ) , 1234 ) ;
41
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright 2012 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-flags: -C codegen-units=3
12
+ // aux-build:sepcomp-extern-lib.rs
13
+
14
+ // Test accessing external items from multiple compilation units.
15
+
16
+ #[ link( name = "sepcomp-extern-lib" ) ]
17
+ extern {
18
+ #[ allow( ctypes) ]
19
+ fn foo ( ) -> uint ;
20
+ }
21
+
22
+ fn call1 ( ) -> uint {
23
+ unsafe { foo ( ) }
24
+ }
25
+
26
+ mod a {
27
+ pub fn call2 ( ) -> uint {
28
+ unsafe { :: foo ( ) }
29
+ }
30
+ }
31
+
32
+ mod b {
33
+ pub fn call3 ( ) -> uint {
34
+ unsafe { :: foo ( ) }
35
+ }
36
+ }
37
+
38
+ fn main ( ) {
39
+ assert_eq ! ( call1( ) , 1234 ) ;
40
+ assert_eq ! ( a:: call2( ) , 1234 ) ;
41
+ assert_eq ! ( b:: call3( ) , 1234 ) ;
42
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright 2012 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-flags: -C codegen-units=3
12
+
13
+ // Test references to items that haven't been translated yet.
14
+
15
+ // Generate some code in the first compilation unit before declaring any
16
+ // modules. This ensures that the first module doesn't go into the same
17
+ // compilation unit as the top-level module.
18
+ fn pad ( ) -> uint { 0 }
19
+
20
+ mod b {
21
+ pub fn three ( ) -> uint {
22
+ :: one ( ) + :: a:: two ( )
23
+ }
24
+ }
25
+
26
+ mod a {
27
+ pub fn two ( ) -> uint {
28
+ :: one ( ) + :: one ( )
29
+ }
30
+ }
31
+
32
+ fn one ( ) -> uint {
33
+ 1
34
+ }
35
+
36
+ fn main ( ) {
37
+ assert_eq ! ( one( ) , 1 ) ;
38
+ assert_eq ! ( a:: two( ) , 2 ) ;
39
+ assert_eq ! ( b:: three( ) , 3 ) ;
40
+ }
41
+
You can’t perform that action at this time.
0 commit comments