Skip to content

Commit d0c61eb

Browse files
ICH: Add test case for extern mods.
1 parent 94ae2a2 commit d0c61eb

File tree

1 file changed

+272
-0
lines changed

1 file changed

+272
-0
lines changed
+272
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,272 @@
1+
// Copyright 2016 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+
12+
// This test case tests the incremental compilation hash (ICH) implementation
13+
// for `extern` modules.
14+
15+
// The general pattern followed here is: Change one thing between rev1 and rev2
16+
// and make sure that the hash has changed, then change nothing between rev2 and
17+
// rev3 and make sure that the hash has not changed.
18+
19+
// must-compile-successfully
20+
// revisions: cfail1 cfail2 cfail3
21+
// compile-flags: -Z query-dep-graph
22+
23+
#![allow(warnings)]
24+
#![feature(rustc_attrs)]
25+
#![feature(unboxed_closures)]
26+
#![feature(link_args)]
27+
#![crate_type="rlib"]
28+
29+
30+
// Change function name --------------------------------------------------------
31+
#[cfg(cfail1)]
32+
extern {
33+
pub fn change_function_name1(c: i64) -> i32;
34+
}
35+
36+
#[cfg(not(cfail1))]
37+
#[rustc_dirty(label="Hir", cfg="cfail2")]
38+
#[rustc_clean(label="Hir", cfg="cfail3")]
39+
#[rustc_metadata_dirty(cfg="cfail2")]
40+
#[rustc_metadata_clean(cfg="cfail3")]
41+
extern {
42+
pub fn change_function_name2(c: i64) -> i32;
43+
}
44+
45+
46+
47+
// Change parameter name -------------------------------------------------------
48+
#[cfg(cfail1)]
49+
extern {
50+
pub fn change_parameter_name(c: i64) -> i32;
51+
}
52+
53+
#[cfg(not(cfail1))]
54+
#[rustc_dirty(label="Hir", cfg="cfail2")]
55+
#[rustc_clean(label="Hir", cfg="cfail3")]
56+
#[rustc_metadata_dirty(cfg="cfail2")]
57+
#[rustc_metadata_clean(cfg="cfail3")]
58+
extern {
59+
pub fn change_parameter_name(d: i64) -> i32;
60+
}
61+
62+
63+
64+
// Change parameter type -------------------------------------------------------
65+
#[cfg(cfail1)]
66+
extern {
67+
pub fn change_parameter_type(c: i64) -> i32;
68+
}
69+
70+
#[cfg(not(cfail1))]
71+
#[rustc_dirty(label="Hir", cfg="cfail2")]
72+
#[rustc_clean(label="Hir", cfg="cfail3")]
73+
#[rustc_metadata_dirty(cfg="cfail2")]
74+
#[rustc_metadata_clean(cfg="cfail3")]
75+
extern {
76+
pub fn change_parameter_type(c: i32) -> i32;
77+
}
78+
79+
80+
81+
// Change return type ----------------------------------------------------------
82+
#[cfg(cfail1)]
83+
extern {
84+
pub fn change_return_type(c: i32) -> i32;
85+
}
86+
87+
#[cfg(not(cfail1))]
88+
#[rustc_dirty(label="Hir", cfg="cfail2")]
89+
#[rustc_clean(label="Hir", cfg="cfail3")]
90+
#[rustc_metadata_dirty(cfg="cfail2")]
91+
#[rustc_metadata_clean(cfg="cfail3")]
92+
extern {
93+
pub fn change_return_type(c: i32) -> i8;
94+
}
95+
96+
97+
98+
// Add parameter ---------------------------------------------------------------
99+
#[cfg(cfail1)]
100+
extern {
101+
pub fn add_parameter(c: i32) -> i32;
102+
}
103+
104+
#[cfg(not(cfail1))]
105+
#[rustc_dirty(label="Hir", cfg="cfail2")]
106+
#[rustc_clean(label="Hir", cfg="cfail3")]
107+
#[rustc_metadata_dirty(cfg="cfail2")]
108+
#[rustc_metadata_clean(cfg="cfail3")]
109+
extern {
110+
pub fn add_parameter(c: i32, d: i32) -> i32;
111+
}
112+
113+
114+
115+
// Add return type -------------------------------------------------------------
116+
#[cfg(cfail1)]
117+
extern {
118+
pub fn add_return_type(c: i32);
119+
}
120+
121+
#[cfg(not(cfail1))]
122+
#[rustc_dirty(label="Hir", cfg="cfail2")]
123+
#[rustc_clean(label="Hir", cfg="cfail3")]
124+
#[rustc_metadata_dirty(cfg="cfail2")]
125+
#[rustc_metadata_clean(cfg="cfail3")]
126+
extern {
127+
pub fn add_return_type(c: i32) -> i32;
128+
}
129+
130+
131+
132+
// Make function variadic ------------------------------------------------------
133+
#[cfg(cfail1)]
134+
extern {
135+
pub fn make_function_variadic(c: i32);
136+
}
137+
138+
#[cfg(not(cfail1))]
139+
#[rustc_dirty(label="Hir", cfg="cfail2")]
140+
#[rustc_clean(label="Hir", cfg="cfail3")]
141+
#[rustc_metadata_dirty(cfg="cfail2")]
142+
#[rustc_metadata_clean(cfg="cfail3")]
143+
extern {
144+
pub fn make_function_variadic(c: i32, ...);
145+
}
146+
147+
148+
149+
// Change calling convention ---------------------------------------------------
150+
#[cfg(cfail1)]
151+
extern "C" {
152+
pub fn change_calling_convention(c: i32);
153+
}
154+
155+
#[cfg(not(cfail1))]
156+
#[rustc_dirty(label="Hir", cfg="cfail2")]
157+
#[rustc_clean(label="Hir", cfg="cfail3")]
158+
#[rustc_metadata_dirty(cfg="cfail2")]
159+
#[rustc_metadata_clean(cfg="cfail3")]
160+
extern "rust-call" {
161+
pub fn change_calling_convention(c: i32);
162+
}
163+
164+
165+
166+
// Make function public --------------------------------------------------------
167+
#[cfg(cfail1)]
168+
extern {
169+
fn make_function_public(c: i32);
170+
}
171+
172+
#[cfg(not(cfail1))]
173+
#[rustc_dirty(label="Hir", cfg="cfail2")]
174+
#[rustc_clean(label="Hir", cfg="cfail3")]
175+
#[rustc_metadata_dirty(cfg="cfail2")]
176+
#[rustc_metadata_clean(cfg="cfail3")]
177+
extern {
178+
pub fn make_function_public(c: i32);
179+
}
180+
181+
182+
183+
// Add function ----------------------------------------------------------------
184+
#[cfg(cfail1)]
185+
extern {
186+
pub fn add_function1(c: i32);
187+
}
188+
189+
#[cfg(not(cfail1))]
190+
#[rustc_dirty(label="Hir", cfg="cfail2")]
191+
#[rustc_clean(label="Hir", cfg="cfail3")]
192+
#[rustc_metadata_dirty(cfg="cfail2")]
193+
#[rustc_metadata_clean(cfg="cfail3")]
194+
extern {
195+
pub fn add_function1(c: i32);
196+
pub fn add_function2();
197+
}
198+
199+
200+
201+
// Change link-args ------------------------------------------------------------
202+
#[cfg(cfail1)]
203+
#[link_args = "-foo -bar"]
204+
extern {
205+
pub fn change_link_args(c: i32);
206+
}
207+
208+
#[cfg(not(cfail1))]
209+
#[rustc_dirty(label="Hir", cfg="cfail2")]
210+
#[rustc_clean(label="Hir", cfg="cfail3")]
211+
#[rustc_metadata_dirty(cfg="cfail2")]
212+
#[rustc_metadata_clean(cfg="cfail3")]
213+
#[link_args = "-foo -bar -baz"]
214+
extern {
215+
pub fn change_link_args(c: i32);
216+
}
217+
218+
219+
220+
// Change link-name ------------------------------------------------------------
221+
#[cfg(cfail1)]
222+
#[link(name = "foo")]
223+
extern {
224+
pub fn change_link_name(c: i32);
225+
}
226+
227+
#[cfg(not(cfail1))]
228+
#[rustc_dirty(label="Hir", cfg="cfail2")]
229+
#[rustc_clean(label="Hir", cfg="cfail3")]
230+
#[rustc_metadata_dirty(cfg="cfail2")]
231+
#[rustc_metadata_clean(cfg="cfail3")]
232+
#[link(name = "bar")]
233+
extern {
234+
pub fn change_link_name(c: i32);
235+
}
236+
237+
type c_i32 = i32;
238+
type c_i64 = i64;
239+
240+
// Indirectly change parameter type --------------------------------------------
241+
mod indirectly_change_parameter_type {
242+
#[cfg(cfail1)]
243+
use super::c_i32 as c_int;
244+
#[cfg(not(cfail1))]
245+
use super::c_i64 as c_int;
246+
247+
#[rustc_dirty(label="Hir", cfg="cfail2")]
248+
#[rustc_clean(label="Hir", cfg="cfail3")]
249+
#[rustc_metadata_dirty(cfg="cfail2")]
250+
#[rustc_metadata_clean(cfg="cfail3")]
251+
extern {
252+
pub fn indirectly_change_parameter_type(c: c_int);
253+
}
254+
}
255+
256+
257+
258+
// Indirectly change return type --------------------------------------------
259+
mod indirectly_change_return_type {
260+
#[cfg(cfail1)]
261+
use super::c_i32 as c_int;
262+
#[cfg(not(cfail1))]
263+
use super::c_i64 as c_int;
264+
265+
#[rustc_dirty(label="Hir", cfg="cfail2")]
266+
#[rustc_clean(label="Hir", cfg="cfail3")]
267+
#[rustc_metadata_dirty(cfg="cfail2")]
268+
#[rustc_metadata_clean(cfg="cfail3")]
269+
extern {
270+
pub fn indirectly_change_return_type() -> c_int;
271+
}
272+
}

0 commit comments

Comments
 (0)