diff options
Diffstat (limited to 'tests/run-make')
85 files changed, 708 insertions, 66 deletions
diff --git a/tests/run-make/CURRENT_RUSTC_VERSION/Makefile b/tests/run-make/CURRENT_RUSTC_VERSION/Makefile new file mode 100644 index 000000000..7940dae20 --- /dev/null +++ b/tests/run-make/CURRENT_RUSTC_VERSION/Makefile @@ -0,0 +1,6 @@ +include ../tools.mk + +all: + $(RUSTC) --emit=metadata --crate-type lib stable.rs + $(RUSTC) --emit=metadata --extern stable=$(TMPDIR)/libstable.rmeta main.rs 2>&1 >/dev/null \ + | $(CGREP) -e "stable since $$(cat $(S)/src/version)(-[a-zA-Z]+)?" diff --git a/tests/run-make/CURRENT_RUSTC_VERSION/main.rs b/tests/run-make/CURRENT_RUSTC_VERSION/main.rs new file mode 100644 index 000000000..466aaa82b --- /dev/null +++ b/tests/run-make/CURRENT_RUSTC_VERSION/main.rs @@ -0,0 +1,4 @@ +#![feature(foo)] +extern crate stable; + +fn main() {} diff --git a/tests/run-make/CURRENT_RUSTC_VERSION/stable.rs b/tests/run-make/CURRENT_RUSTC_VERSION/stable.rs new file mode 100644 index 000000000..2fd09aded --- /dev/null +++ b/tests/run-make/CURRENT_RUSTC_VERSION/stable.rs @@ -0,0 +1,5 @@ +#![feature(staged_api)] +#![stable(since = "1.0.0", feature = "rust1")] + +#[stable(since = "CURRENT_RUSTC_VERSION", feature = "foo")] +pub fn foo() {} diff --git a/tests/run-make/allocator-shim-circular-deps/Makefile b/tests/run-make/allocator-shim-circular-deps/Makefile new file mode 100644 index 000000000..4624b8468 --- /dev/null +++ b/tests/run-make/allocator-shim-circular-deps/Makefile @@ -0,0 +1,7 @@ +# ignore-cross-compile +include ../tools.mk + +all: + rm -rf $(TMPDIR) && mkdir $(TMPDIR) + $(RUSTC) my_lib.rs + $(RUSTC) main.rs --test --extern my_lib=$(TMPDIR)/libmy_lib.rlib diff --git a/tests/run-make/allocator-shim-circular-deps/main.rs b/tests/run-make/allocator-shim-circular-deps/main.rs new file mode 100644 index 000000000..e317c6571 --- /dev/null +++ b/tests/run-make/allocator-shim-circular-deps/main.rs @@ -0,0 +1,5 @@ +#![crate_type = "bin"] + +fn main() { + my_lib::do_something(); +} diff --git a/tests/run-make/allocator-shim-circular-deps/my_lib.rs b/tests/run-make/allocator-shim-circular-deps/my_lib.rs new file mode 100644 index 000000000..095b10361 --- /dev/null +++ b/tests/run-make/allocator-shim-circular-deps/my_lib.rs @@ -0,0 +1,10 @@ +#![crate_type = "lib"] + +use std::alloc::System; + +#[global_allocator] +static ALLOCATOR: System = System; + +pub fn do_something() { + format!("allocating a string!"); +} diff --git a/tests/run-make/branch-protection-check-IBT/Makefile b/tests/run-make/branch-protection-check-IBT/Makefile new file mode 100644 index 000000000..cabe951e1 --- /dev/null +++ b/tests/run-make/branch-protection-check-IBT/Makefile @@ -0,0 +1,15 @@ +# Check for GNU Property Note + +include ../tools.mk + +# How to run this +# python3 x.py test --target x86_64-unknown-linux-gnu tests/run-make/branch-protection-check-IBT/ + +# only-x86_64 + +all: +ifeq ($(filter x86,$(LLVM_COMPONENTS)),x86_64) + $(RUSTC) --target x86_64-unknown-linux-gnu -Z cf-protection=branch -L$(TMPDIR) -C link-args='-nostartfiles' -C save-temps ./main.rs -o $(TMPDIR)/rsmain + readelf -nW $(TMPDIR)/rsmain | $(CGREP) -e ".note.gnu.property" +endif + diff --git a/tests/run-make/branch-protection-check-IBT/main.rs b/tests/run-make/branch-protection-check-IBT/main.rs new file mode 100644 index 000000000..ad379d6ea --- /dev/null +++ b/tests/run-make/branch-protection-check-IBT/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("hello world"); +} diff --git a/tests/run-make/c-unwind-abi-catch-lib-panic/Makefile b/tests/run-make/c-unwind-abi-catch-lib-panic/Makefile index 9c41a5a71..b8e0e9483 100644 --- a/tests/run-make/c-unwind-abi-catch-lib-panic/Makefile +++ b/tests/run-make/c-unwind-abi-catch-lib-panic/Makefile @@ -1,4 +1,5 @@ # ignore-cross-compile +# needs-unwind include ../tools.mk all: archive diff --git a/tests/run-make/c-unwind-abi-catch-lib-panic/main.rs b/tests/run-make/c-unwind-abi-catch-lib-panic/main.rs index 78a71219c..42d3efa82 100644 --- a/tests/run-make/c-unwind-abi-catch-lib-panic/main.rs +++ b/tests/run-make/c-unwind-abi-catch-lib-panic/main.rs @@ -2,7 +2,6 @@ //! //! This test triggers a panic in a Rust library that our foreign function invokes. This shows //! that we can unwind through the C code in that library, and catch the underlying panic. -#![feature(c_unwind)] use std::panic::{catch_unwind, AssertUnwindSafe}; diff --git a/tests/run-make/c-unwind-abi-catch-lib-panic/panic.rs b/tests/run-make/c-unwind-abi-catch-lib-panic/panic.rs index a99a04d5c..9e7bc3e53 100644 --- a/tests/run-make/c-unwind-abi-catch-lib-panic/panic.rs +++ b/tests/run-make/c-unwind-abi-catch-lib-panic/panic.rs @@ -1,5 +1,4 @@ #![crate_type = "staticlib"] -#![feature(c_unwind)] /// This function will panic if `x` is greater than 10. /// diff --git a/tests/run-make/c-unwind-abi-catch-panic/Makefile b/tests/run-make/c-unwind-abi-catch-panic/Makefile index 4398ac2ee..1760ddb30 100644 --- a/tests/run-make/c-unwind-abi-catch-panic/Makefile +++ b/tests/run-make/c-unwind-abi-catch-panic/Makefile @@ -1,4 +1,5 @@ # ignore-cross-compile +# needs-unwind include ../tools.mk all: $(call NATIVE_STATICLIB,add) diff --git a/tests/run-make/c-unwind-abi-catch-panic/main.rs b/tests/run-make/c-unwind-abi-catch-panic/main.rs index 15d38d721..1903be956 100644 --- a/tests/run-make/c-unwind-abi-catch-panic/main.rs +++ b/tests/run-make/c-unwind-abi-catch-panic/main.rs @@ -1,7 +1,6 @@ //! A test for calling `C-unwind` functions across foreign function boundaries. //! //! This test triggers a panic when calling a foreign function that calls *back* into Rust. -#![feature(c_unwind)] use std::panic::{catch_unwind, AssertUnwindSafe}; diff --git a/tests/run-make/const-prop-lint/Makefile b/tests/run-make/const-prop-lint/Makefile new file mode 100644 index 000000000..f29f282f7 --- /dev/null +++ b/tests/run-make/const-prop-lint/Makefile @@ -0,0 +1,9 @@ +include ../tools.mk + +# Test that emitting an error because of arithmetic +# overflow lint does not leave .o files around +# because of interrupted codegen. + +all: + $(RUSTC) input.rs; test $$? -eq 1 + ls *.o; test $$? -ne 0 diff --git a/tests/run-make/const-prop-lint/input.rs b/tests/run-make/const-prop-lint/input.rs new file mode 100644 index 000000000..ccbdfb8d5 --- /dev/null +++ b/tests/run-make/const-prop-lint/input.rs @@ -0,0 +1,5 @@ +#![deny(arithmetic_overflow)] + +fn main() { + let x = 255u8 + 1; +} diff --git a/tests/run-make/const_fn_mir/Makefile b/tests/run-make/const_fn_mir/Makefile index b2c268f04..6d72c1227 100644 --- a/tests/run-make/const_fn_mir/Makefile +++ b/tests/run-make/const_fn_mir/Makefile @@ -1,3 +1,4 @@ +# needs-unwind -Cpanic=abort gives different MIR output include ../tools.mk all: diff --git a/tests/run-make/core-no-oom-handling/Makefile b/tests/run-make/core-no-oom-handling/Makefile new file mode 100644 index 000000000..28c5261ff --- /dev/null +++ b/tests/run-make/core-no-oom-handling/Makefile @@ -0,0 +1,6 @@ +include ../tools.mk + +FAKEROOT=$(TMPDIR)/fakeroot + +all: + $(RUSTC) --edition=2021 -Dwarnings --crate-type=rlib ../../../library/core/src/lib.rs --sysroot=$(FAKEROOT) --cfg no_global_oom_handling diff --git a/tests/run-make/coverage-llvmir/filecheck.testprog.txt b/tests/run-make/coverage-llvmir/filecheck.testprog.txt index c943261d7..b3a8808df 100644 --- a/tests/run-make/coverage-llvmir/filecheck.testprog.txt +++ b/tests/run-make/coverage-llvmir/filecheck.testprog.txt @@ -36,7 +36,7 @@ CHECK-SAME: section "llvm.metadata" CHECK: [[DEFINE_INTERNAL]] { {{.*}} } @_R{{[a-zA-Z0-9_]+}}testprog14will_be_called() unnamed_addr #{{[0-9]+}} { CHECK-NEXT: start: CHECK-NOT: [[DEFINE_INTERNAL]] -CHECK: %pgocount = load i64, {{i64\*|ptr}} +CHECK: atomicrmw add ptr CHECK-SAME: @__profc__R{{[a-zA-Z0-9_]+}}testprog14will_be_called, CHECK: declare void @llvm.instrprof.increment({{i8\*|ptr}}, i64, i32, i32) #[[LLVM_INSTRPROF_INCREMENT_ATTR:[0-9]+]] diff --git a/tests/run-make/coverage-reports/Makefile b/tests/run-make/coverage-reports/Makefile index d06cd9c6a..0ae409c41 100644 --- a/tests/run-make/coverage-reports/Makefile +++ b/tests/run-make/coverage-reports/Makefile @@ -138,6 +138,7 @@ endif ) \ 2> "$(TMPDIR)"/show_coverage_stderr.$@.txt \ | "$(PYTHON)" $(BASEDIR)/normalize_paths.py \ + | "$(PYTHON)" $(BASEDIR)/sort_subviews.py \ > "$(TMPDIR)"/actual_show_coverage.$@.txt || \ ( status=$$? ; \ >&2 cat "$(TMPDIR)"/show_coverage_stderr.$@.txt ; \ @@ -158,23 +159,15 @@ ifdef RUSTC_BLESS_TEST else # Compare the show coverage output (`--bless` refreshes `typical` files). # - # FIXME(richkadel): None of the Rust test source samples have the - # `// ignore-llvm-cov-show-diffs` anymore. This directive exists to work around a limitation - # with `llvm-cov show`. When reporting coverage for multiple instantiations of a generic function, - # with different type substitutions, `llvm-cov show` prints these in a non-deterministic order, - # breaking the `diff` comparison. + # `llvm-cov show` normally prints instantiation groups in an unpredictable + # order, but we have used `sort_subviews.py` to sort them, so we can still + # check the output directly with `diff`. # - # A partial workaround is implemented below, with `diff --ignore-matching-lines=RE` - # to ignore each line prefixing each generic instantiation coverage code region. - # - # This workaround only works if the coverage counts are identical across all reported - # instantiations. If there is no way to ensure this, you may need to apply the - # `// ignore-llvm-cov-show-diffs` directive, and check for differences using the - # `.json` files to validate that results have not changed. (Until then, the JSON - # files are redundant, so there is no need to generate `expected_*.json` files or - # compare actual JSON results.) - - $(DIFF) --ignore-matching-lines='^ | .*::<.*>.*:$$' --ignore-matching-lines='^ | <.*>::.*:$$' \ + # Some of the test cases are currently not working (since #110393) and have + # been marked with `// ignore-llvm-cov-show-diffs` so that they don't fail + # the build. + + $(DIFF) \ expected_show_coverage.$@.txt "$(TMPDIR)"/actual_show_coverage.$@.txt || \ ( grep -q '^\/\/ ignore-llvm-cov-show-diffs' $(SOURCEDIR)/$@.rs && \ >&2 echo 'diff failed, but suppressed with `// ignore-llvm-cov-show-diffs` in $(SOURCEDIR)/$@.rs' \ diff --git a/tests/run-make/coverage-reports/expected_show_coverage.async.txt b/tests/run-make/coverage-reports/expected_show_coverage.async.txt index 87ccb6c43..93c1535b0 100644 --- a/tests/run-make/coverage-reports/expected_show_coverage.async.txt +++ b/tests/run-make/coverage-reports/expected_show_coverage.async.txt @@ -41,9 +41,9 @@ 41| 1| // executed asynchronously. 42| 1| match x { 43| 1| y if c(x).await == y + 1 => { d().await; } - ^0 ^0 ^0 ^0 + ^0 ^0 ^0 ^0 44| 1| y if f().await == y + 1 => (), - ^0 ^0 ^0 + ^0 ^0 ^0 45| 1| _ => (), 46| | } 47| 1|} diff --git a/tests/run-make/coverage-reports/expected_show_coverage.generics.txt b/tests/run-make/coverage-reports/expected_show_coverage.generics.txt index 48983ba43..7eb33a29a 100644 --- a/tests/run-make/coverage-reports/expected_show_coverage.generics.txt +++ b/tests/run-make/coverage-reports/expected_show_coverage.generics.txt @@ -11,16 +11,16 @@ 11| 3| self.strength = new_strength; 12| 3| } ------------------ - | <generics::Firework<i32>>::set_strength: - | 10| 1| fn set_strength(&mut self, new_strength: T) { - | 11| 1| self.strength = new_strength; - | 12| 1| } - ------------------ | <generics::Firework<f64>>::set_strength: | 10| 2| fn set_strength(&mut self, new_strength: T) { | 11| 2| self.strength = new_strength; | 12| 2| } ------------------ + | <generics::Firework<i32>>::set_strength: + | 10| 1| fn set_strength(&mut self, new_strength: T) { + | 11| 1| self.strength = new_strength; + | 12| 1| } + ------------------ 13| |} 14| | 15| |impl<T> Drop for Firework<T> where T: Copy + std::fmt::Display { diff --git a/tests/run-make/coverage-reports/expected_show_coverage.sort_groups.txt b/tests/run-make/coverage-reports/expected_show_coverage.sort_groups.txt new file mode 100644 index 000000000..81468cb35 --- /dev/null +++ b/tests/run-make/coverage-reports/expected_show_coverage.sort_groups.txt @@ -0,0 +1,49 @@ + 1| |// compile-flags: --edition=2021 + 2| | + 3| |// Demonstrate that `sort_subviews.py` can sort instantiation groups into a + 4| |// predictable order, while preserving their heterogeneous contents. + 5| | + 6| 1|fn main() { + 7| 1| let cond = std::env::args().len() > 1; + 8| 1| generic_fn::<()>(cond); + 9| 1| generic_fn::<&'static str>(!cond); + 10| 1| if false { + 11| 0| generic_fn::<char>(cond); + 12| 1| } + 13| 1| generic_fn::<i32>(cond); + 14| 1| other_fn(); + 15| 1|} + 16| | + 17| 3|fn generic_fn<T>(cond: bool) { + 18| 3| if cond { + 19| 1| println!("{}", std::any::type_name::<T>()); + 20| 2| } + 21| 3|} + ------------------ + | Unexecuted instantiation: sort_groups::generic_fn::<char> + ------------------ + | sort_groups::generic_fn::<&str>: + | 17| 1|fn generic_fn<T>(cond: bool) { + | 18| 1| if cond { + | 19| 1| println!("{}", std::any::type_name::<T>()); + | 20| 1| } + | ^0 + | 21| 1|} + ------------------ + | sort_groups::generic_fn::<()>: + | 17| 1|fn generic_fn<T>(cond: bool) { + | 18| 1| if cond { + | 19| 0| println!("{}", std::any::type_name::<T>()); + | 20| 1| } + | 21| 1|} + ------------------ + | sort_groups::generic_fn::<i32>: + | 17| 1|fn generic_fn<T>(cond: bool) { + | 18| 1| if cond { + | 19| 0| println!("{}", std::any::type_name::<T>()); + | 20| 1| } + | 21| 1|} + ------------------ + 22| | + 23| 1|fn other_fn() {} + diff --git a/tests/run-make/coverage-reports/expected_show_coverage.test_harness.txt b/tests/run-make/coverage-reports/expected_show_coverage.test_harness.txt new file mode 100644 index 000000000..93bd1cfcb --- /dev/null +++ b/tests/run-make/coverage-reports/expected_show_coverage.test_harness.txt @@ -0,0 +1,11 @@ + 1| |// Verify that the entry point injected by the test harness doesn't cause + 2| |// weird artifacts in the coverage report (e.g. issue #10749). + 3| | + 4| |// compile-flags: --test + 5| | + 6| |#[allow(dead_code)] + 7| 0|fn unused() {} + 8| | + 9| 1|#[test] + 10| 1|fn my_test() {} + diff --git a/tests/run-make/coverage-reports/expected_show_coverage.uses_crate.txt b/tests/run-make/coverage-reports/expected_show_coverage.uses_crate.txt index 65eb1008d..412f4a93b 100644 --- a/tests/run-make/coverage-reports/expected_show_coverage.uses_crate.txt +++ b/tests/run-make/coverage-reports/expected_show_coverage.uses_crate.txt @@ -19,29 +19,29 @@ 18| 2| println!("used_only_from_bin_crate_generic_function with {:?}", arg); 19| 2|} ------------------ - | used_crate::used_only_from_bin_crate_generic_function::<&str>: + | Unexecuted instantiation: used_crate::used_only_from_bin_crate_generic_function::<_> + ------------------ + | used_crate::used_only_from_bin_crate_generic_function::<&alloc::vec::Vec<i32>>: | 17| 1|pub fn used_only_from_bin_crate_generic_function<T: Debug>(arg: T) { | 18| 1| println!("used_only_from_bin_crate_generic_function with {:?}", arg); | 19| 1|} ------------------ - | used_crate::used_only_from_bin_crate_generic_function::<&alloc::vec::Vec<i32>>: + | used_crate::used_only_from_bin_crate_generic_function::<&str>: | 17| 1|pub fn used_only_from_bin_crate_generic_function<T: Debug>(arg: T) { | 18| 1| println!("used_only_from_bin_crate_generic_function with {:?}", arg); | 19| 1|} ------------------ - | Unexecuted instantiation: used_crate::used_only_from_bin_crate_generic_function::<_> - ------------------ 20| |// Expect for above function: `Unexecuted instantiation` (see below) 21| 2|pub fn used_only_from_this_lib_crate_generic_function<T: Debug>(arg: T) { 22| 2| println!("used_only_from_this_lib_crate_generic_function with {:?}", arg); 23| 2|} ------------------ - | used_crate::used_only_from_this_lib_crate_generic_function::<alloc::vec::Vec<i32>>: + | used_crate::used_only_from_this_lib_crate_generic_function::<&str>: | 21| 1|pub fn used_only_from_this_lib_crate_generic_function<T: Debug>(arg: T) { | 22| 1| println!("used_only_from_this_lib_crate_generic_function with {:?}", arg); | 23| 1|} ------------------ - | used_crate::used_only_from_this_lib_crate_generic_function::<&str>: + | used_crate::used_only_from_this_lib_crate_generic_function::<alloc::vec::Vec<i32>>: | 21| 1|pub fn used_only_from_this_lib_crate_generic_function<T: Debug>(arg: T) { | 22| 1| println!("used_only_from_this_lib_crate_generic_function with {:?}", arg); | 23| 1|} @@ -51,12 +51,12 @@ 26| 2| println!("used_from_bin_crate_and_lib_crate_generic_function with {:?}", arg); 27| 2|} ------------------ - | used_crate::used_from_bin_crate_and_lib_crate_generic_function::<alloc::vec::Vec<i32>>: + | used_crate::used_from_bin_crate_and_lib_crate_generic_function::<&str>: | 25| 1|pub fn used_from_bin_crate_and_lib_crate_generic_function<T: Debug>(arg: T) { | 26| 1| println!("used_from_bin_crate_and_lib_crate_generic_function with {:?}", arg); | 27| 1|} ------------------ - | used_crate::used_from_bin_crate_and_lib_crate_generic_function::<&str>: + | used_crate::used_from_bin_crate_and_lib_crate_generic_function::<alloc::vec::Vec<i32>>: | 25| 1|pub fn used_from_bin_crate_and_lib_crate_generic_function<T: Debug>(arg: T) { | 26| 1| println!("used_from_bin_crate_and_lib_crate_generic_function with {:?}", arg); | 27| 1|} diff --git a/tests/run-make/coverage-reports/expected_show_coverage.uses_inline_crate.txt b/tests/run-make/coverage-reports/expected_show_coverage.uses_inline_crate.txt index 748343885..66ca9e80a 100644 --- a/tests/run-make/coverage-reports/expected_show_coverage.uses_inline_crate.txt +++ b/tests/run-make/coverage-reports/expected_show_coverage.uses_inline_crate.txt @@ -42,6 +42,8 @@ 40| 2| println!("used_only_from_bin_crate_generic_function with {:?}", arg); 41| 2|} ------------------ + | Unexecuted instantiation: used_inline_crate::used_only_from_bin_crate_generic_function::<_> + ------------------ | used_inline_crate::used_only_from_bin_crate_generic_function::<&alloc::vec::Vec<i32>>: | 39| 1|pub fn used_only_from_bin_crate_generic_function<T: Debug>(arg: T) { | 40| 1| println!("used_only_from_bin_crate_generic_function with {:?}", arg); @@ -52,8 +54,6 @@ | 40| 1| println!("used_only_from_bin_crate_generic_function with {:?}", arg); | 41| 1|} ------------------ - | Unexecuted instantiation: used_inline_crate::used_only_from_bin_crate_generic_function::<_> - ------------------ 42| |// Expect for above function: `Unexecuted instantiation` (see notes in `used_crate.rs`) 43| | 44| |#[inline(always)] @@ -77,16 +77,16 @@ 51| 3| println!("used_from_bin_crate_and_lib_crate_generic_function with {:?}", arg); 52| 3|} ------------------ - | used_inline_crate::used_from_bin_crate_and_lib_crate_generic_function::<alloc::vec::Vec<i32>>: - | 50| 1|pub fn used_from_bin_crate_and_lib_crate_generic_function<T: Debug>(arg: T) { - | 51| 1| println!("used_from_bin_crate_and_lib_crate_generic_function with {:?}", arg); - | 52| 1|} - ------------------ | used_inline_crate::used_from_bin_crate_and_lib_crate_generic_function::<&str>: | 50| 2|pub fn used_from_bin_crate_and_lib_crate_generic_function<T: Debug>(arg: T) { | 51| 2| println!("used_from_bin_crate_and_lib_crate_generic_function with {:?}", arg); | 52| 2|} ------------------ + | used_inline_crate::used_from_bin_crate_and_lib_crate_generic_function::<alloc::vec::Vec<i32>>: + | 50| 1|pub fn used_from_bin_crate_and_lib_crate_generic_function<T: Debug>(arg: T) { + | 51| 1| println!("used_from_bin_crate_and_lib_crate_generic_function with {:?}", arg); + | 52| 1|} + ------------------ 53| | 54| |#[inline(always)] 55| 3|pub fn used_with_same_type_from_bin_crate_and_lib_crate_generic_function<T: Debug>(arg: T) { diff --git a/tests/run-make/coverage-reports/sort_subviews.py b/tests/run-make/coverage-reports/sort_subviews.py new file mode 100644 index 000000000..10cfc51d4 --- /dev/null +++ b/tests/run-make/coverage-reports/sort_subviews.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python3 + +# `llvm-cov show` prints grouped subviews (e.g. for generic functions) in an +# unstable order, which is inconvenient when checking output snapshots with +# `diff`. To work around that, this script detects consecutive subviews in its +# piped input, and sorts them while preserving their contents. + +from __future__ import print_function + +import sys + + +def main(): + subviews = [] + + def flush_subviews(): + if not subviews: + return + + # The last "subview" should be just a boundary line on its own, so + # temporarily remove it before sorting the accumulated subviews. + terminator = subviews.pop() + subviews.sort() + subviews.append(terminator) + + for view in subviews: + for line in view: + print(line, end="") + + subviews.clear() + + for line in sys.stdin: + if line.startswith(" ------------------"): + # This is a subview boundary line, so start a new subview. + subviews.append([line]) + elif line.startswith(" |"): + # Add this line to the current subview. + subviews[-1].append(line) + else: + # This line is not part of a subview, so sort and print any + # accumulated subviews, and then print the line as-is. + flush_subviews() + print(line, end="") + + flush_subviews() + assert not subviews + + +if __name__ == "__main__": + main() diff --git a/tests/run-make/coverage/sort_groups.rs b/tests/run-make/coverage/sort_groups.rs new file mode 100644 index 000000000..f89f9f3ec --- /dev/null +++ b/tests/run-make/coverage/sort_groups.rs @@ -0,0 +1,23 @@ +// compile-flags: --edition=2021 + +// Demonstrate that `sort_subviews.py` can sort instantiation groups into a +// predictable order, while preserving their heterogeneous contents. + +fn main() { + let cond = std::env::args().len() > 1; + generic_fn::<()>(cond); + generic_fn::<&'static str>(!cond); + if false { + generic_fn::<char>(cond); + } + generic_fn::<i32>(cond); + other_fn(); +} + +fn generic_fn<T>(cond: bool) { + if cond { + println!("{}", std::any::type_name::<T>()); + } +} + +fn other_fn() {} diff --git a/tests/run-make/coverage/test_harness.rs b/tests/run-make/coverage/test_harness.rs new file mode 100644 index 000000000..12a755734 --- /dev/null +++ b/tests/run-make/coverage/test_harness.rs @@ -0,0 +1,10 @@ +// Verify that the entry point injected by the test harness doesn't cause +// weird artifacts in the coverage report (e.g. issue #10749). + +// compile-flags: --test + +#[allow(dead_code)] +fn unused() {} + +#[test] +fn my_test() {} diff --git a/tests/run-make/coverage/uses_crate.rs b/tests/run-make/coverage/uses_crate.rs index 20cb05fe5..1ee8037a1 100644 --- a/tests/run-make/coverage/uses_crate.rs +++ b/tests/run-make/coverage/uses_crate.rs @@ -1,3 +1,6 @@ +// FIXME #110395 +// ignore-llvm-cov-show-diffs + #![allow(unused_assignments, unused_variables)] // compile-flags: -C opt-level=3 # validates coverage now works with optimizations extern crate used_crate; diff --git a/tests/run-make/coverage/uses_inline_crate.rs b/tests/run-make/coverage/uses_inline_crate.rs index a7fe8532b..f7aff3c3f 100644 --- a/tests/run-make/coverage/uses_inline_crate.rs +++ b/tests/run-make/coverage/uses_inline_crate.rs @@ -1,3 +1,6 @@ +// FIXME #110395 +// ignore-llvm-cov-show-diffs + #![allow(unused_assignments, unused_variables)] // compile-flags: -C opt-level=3 # validates coverage now works with optimizations diff --git a/tests/run-make/debug-assertions/Makefile b/tests/run-make/debug-assertions/Makefile index e83337c59..4501459e9 100644 --- a/tests/run-make/debug-assertions/Makefile +++ b/tests/run-make/debug-assertions/Makefile @@ -1,4 +1,5 @@ # ignore-cross-compile +# needs-unwind include ../tools.mk all: diff --git a/tests/run-make/debugger-visualizer-dep-info/Makefile b/tests/run-make/debugger-visualizer-dep-info/Makefile new file mode 100644 index 000000000..0877998a7 --- /dev/null +++ b/tests/run-make/debugger-visualizer-dep-info/Makefile @@ -0,0 +1,9 @@ +include ../tools.mk + +# This test makes sure that files referenced via #[debugger_visualizer] are +# included in `--emit dep-info` output. + +all: + $(RUSTC) --emit dep-info main.rs + $(CGREP) "foo.py" < $(TMPDIR)/main.d + $(CGREP) "my_visualizers/bar.natvis" < $(TMPDIR)/main.d diff --git a/tests/run-make/debugger-visualizer-dep-info/foo.py b/tests/run-make/debugger-visualizer-dep-info/foo.py new file mode 100644 index 000000000..1bb8bf6d7 --- /dev/null +++ b/tests/run-make/debugger-visualizer-dep-info/foo.py @@ -0,0 +1 @@ +# empty diff --git a/tests/run-make/debugger-visualizer-dep-info/main.rs b/tests/run-make/debugger-visualizer-dep-info/main.rs new file mode 100644 index 000000000..3aede2215 --- /dev/null +++ b/tests/run-make/debugger-visualizer-dep-info/main.rs @@ -0,0 +1,12 @@ +#![debugger_visualizer(gdb_script_file = "foo.py")] + +fn main() { + const _UNUSED: u32 = { + mod inner { + #![debugger_visualizer(natvis_file = "my_visualizers/bar.natvis")] + pub const XYZ: u32 = 123; + } + + inner::XYZ + 1 + }; +} diff --git a/tests/run-make/debugger-visualizer-dep-info/my_visualizers/bar.natvis b/tests/run-make/debugger-visualizer-dep-info/my_visualizers/bar.natvis new file mode 100644 index 000000000..c341a4039 --- /dev/null +++ b/tests/run-make/debugger-visualizer-dep-info/my_visualizers/bar.natvis @@ -0,0 +1 @@ +<!-- empty --> diff --git a/tests/run-make/forced-unwind-terminate-pof/Makefile b/tests/run-make/forced-unwind-terminate-pof/Makefile new file mode 100644 index 000000000..871621520 --- /dev/null +++ b/tests/run-make/forced-unwind-terminate-pof/Makefile @@ -0,0 +1,9 @@ +# ignore-cross-compile +# only-linux +include ../tools.mk + +all: foo + $(call RUN,foo) | $(CGREP) -v "cannot unwind" + +foo: foo.rs + $(RUSTC) $< diff --git a/tests/run-make/forced-unwind-terminate-pof/foo.rs b/tests/run-make/forced-unwind-terminate-pof/foo.rs new file mode 100644 index 000000000..0a5128731 --- /dev/null +++ b/tests/run-make/forced-unwind-terminate-pof/foo.rs @@ -0,0 +1,17 @@ +// Tests that forced unwind through POF Rust frames wouldn't trigger our terminating guards. + +#![feature(c_unwind)] +#![no_main] + +extern "C-unwind" { + fn pthread_exit(v: *mut core::ffi::c_void) -> !; +} + +unsafe extern "C" fn call_pthread_exit() { + pthread_exit(core::ptr::null_mut()); +} + +#[no_mangle] +unsafe extern "C-unwind" fn main(_argc: core::ffi::c_int, _argv: *mut *mut core::ffi::c_char) { + call_pthread_exit(); +} diff --git a/tests/run-make/foreign-double-unwind/Makefile b/tests/run-make/foreign-double-unwind/Makefile index f20fe3ce6..b5e52808d 100644 --- a/tests/run-make/foreign-double-unwind/Makefile +++ b/tests/run-make/foreign-double-unwind/Makefile @@ -1,4 +1,5 @@ # ignore-cross-compile +# needs-unwind include ../tools.mk all: foo diff --git a/tests/run-make/foreign-double-unwind/foo.rs b/tests/run-make/foreign-double-unwind/foo.rs index cae8aa940..c085480b4 100644 --- a/tests/run-make/foreign-double-unwind/foo.rs +++ b/tests/run-make/foreign-double-unwind/foo.rs @@ -1,8 +1,6 @@ // Tests that C++ double unwinding through Rust code will be properly guarded // against instead of exhibiting undefined behaviour. -#![feature(c_unwind)] - extern "C-unwind" { fn throw_cxx_exception(); fn cxx_catch_callback(cb: extern "C-unwind" fn()); diff --git a/tests/run-make/foreign-exceptions/Makefile b/tests/run-make/foreign-exceptions/Makefile index a8e20ffb1..56c41b274 100644 --- a/tests/run-make/foreign-exceptions/Makefile +++ b/tests/run-make/foreign-exceptions/Makefile @@ -1,4 +1,5 @@ # ignore-cross-compile +# needs-unwind include ../tools.mk all: foo diff --git a/tests/run-make/foreign-exceptions/foo.rs b/tests/run-make/foreign-exceptions/foo.rs index dd3b7c76f..ccf858d85 100644 --- a/tests/run-make/foreign-exceptions/foo.rs +++ b/tests/run-make/foreign-exceptions/foo.rs @@ -2,8 +2,6 @@ // are caught by catch_unwind. Also tests that Rust panics can unwind through // C++ code. -#![feature(c_unwind)] - use std::panic::{catch_unwind, AssertUnwindSafe}; struct DropCheck<'a>(&'a mut bool); diff --git a/tests/run-make/foreign-rust-exceptions/Makefile b/tests/run-make/foreign-rust-exceptions/Makefile index 0d007bf1c..59cee2842 100644 --- a/tests/run-make/foreign-rust-exceptions/Makefile +++ b/tests/run-make/foreign-rust-exceptions/Makefile @@ -1,5 +1,6 @@ # ignore-cross-compile # ignore-i686-pc-windows-gnu +# needs-unwind # This test doesn't work on 32-bit MinGW as cdylib has its own copy of unwinder # so cross-DLL unwinding does not work. diff --git a/tests/run-make/foreign-rust-exceptions/bar.rs b/tests/run-make/foreign-rust-exceptions/bar.rs index 5f9efe323..1d865b429 100644 --- a/tests/run-make/foreign-rust-exceptions/bar.rs +++ b/tests/run-make/foreign-rust-exceptions/bar.rs @@ -1,5 +1,4 @@ #![crate_type = "cdylib"] -#![feature(c_unwind)] #[no_mangle] extern "C-unwind" fn panic() { diff --git a/tests/run-make/foreign-rust-exceptions/foo.rs b/tests/run-make/foreign-rust-exceptions/foo.rs index 266987c5b..38942c55b 100644 --- a/tests/run-make/foreign-rust-exceptions/foo.rs +++ b/tests/run-make/foreign-rust-exceptions/foo.rs @@ -1,5 +1,3 @@ -#![feature(c_unwind)] - #[cfg_attr(not(windows), link(name = "bar"))] #[cfg_attr(windows, link(name = "bar.dll"))] extern "C-unwind" { diff --git a/tests/run-make/inaccessible-temp-dir/Makefile b/tests/run-make/inaccessible-temp-dir/Makefile new file mode 100644 index 000000000..abdba4eb8 --- /dev/null +++ b/tests/run-make/inaccessible-temp-dir/Makefile @@ -0,0 +1,32 @@ +# only-linux +# ignore-arm - linker error on `armhf-gnu` + +include ../tools.mk + +# Issue #66530: We would ICE if someone compiled with `-o /dev/null`, +# because we would try to generate auxiliary files in `/dev/` (which +# at least the OS X file system rejects). +# +# An attempt to `-Ztemps-dir` into a directory we cannot write into should +# indeed be an error; but not an ICE. +# +# However, some folks run tests as root, which can write `/dev/` and end +# up clobbering `/dev/null`. Instead we'll use an inaccessible path, which +# also used to ICE, but even root can't magically write there. +# +# Note that `-Ztemps-dir` uses `create_dir_all` so it is not sufficient to +# use a directory with non-existing parent like `/does-not-exist/output`. + +all: + # Create an inaccessible directory + mkdir $(TMPDIR)/inaccessible + chmod 000 $(TMPDIR)/inaccessible + + # Run rustc with `-Ztemps-dir` set to a directory + # *inside* the inaccessible one, so that it can't create it + $(RUSTC) program.rs -Ztemps-dir=$(TMPDIR)/inaccessible/tmp 2>&1 \ + | $(CGREP) 'failed to find or create the directory specified by `--temps-dir`' + + # Make the inaccessible directory accessible, + # so that compiletest can delete the temp dir + chmod +rw $(TMPDIR)/inaccessible diff --git a/tests/run-make/inaccessible-temp-dir/program.rs b/tests/run-make/inaccessible-temp-dir/program.rs new file mode 100644 index 000000000..f328e4d9d --- /dev/null +++ b/tests/run-make/inaccessible-temp-dir/program.rs @@ -0,0 +1 @@ +fn main() {} diff --git a/tests/run-make/incremental-debugger-visualizer/Makefile b/tests/run-make/incremental-debugger-visualizer/Makefile new file mode 100644 index 000000000..8cfe41597 --- /dev/null +++ b/tests/run-make/incremental-debugger-visualizer/Makefile @@ -0,0 +1,49 @@ +include ../tools.mk + +# This test makes sure that changes to files referenced via #[debugger_visualizer] +# are picked up when compiling incrementally. + +# We have to copy the source to $(TMPDIR) because Github CI mounts the source +# directory as readonly. We need to apply modifications to some of the source +# file. +SRC_DIR := $(TMPDIR)/src +INCR_CACHE_DIR := $(TMPDIR)/incremental + +all: + rm -rf $(TMPDIR)/* + mkdir $(SRC_DIR) + cp ./foo.rs $(SRC_DIR) + echo "GDB script v1" > $(SRC_DIR)/foo.py + echo "Natvis v1" > $(SRC_DIR)/foo.natvis + $(RUSTC) $(SRC_DIR)/foo.rs \ + --crate-type=rlib \ + --emit metadata \ + -C incremental=$(INCR_CACHE_DIR) \ + -Z incremental-verify-ich + $(CGREP) "GDB script v1" < $(TMPDIR)/libfoo.rmeta + $(CGREP) "Natvis v1" < $(TMPDIR)/libfoo.rmeta + + # Change only the GDB script and check that the change has been picked up + echo "GDB script v2" > $(SRC_DIR)/foo.py + $(RUSTC) $(SRC_DIR)/foo.rs \ + --crate-type=rlib \ + --emit metadata \ + -C incremental=$(INCR_CACHE_DIR) \ + -Z incremental-verify-ich + + $(CGREP) "GDB script v2" < $(TMPDIR)/libfoo.rmeta + $(CGREP) -v "GDB script v1" < $(TMPDIR)/libfoo.rmeta + $(CGREP) "Natvis v1" < $(TMPDIR)/libfoo.rmeta + + # Now change the Natvis version and check that the change has been picked up + echo "Natvis v2" > $(SRC_DIR)/foo.natvis + $(RUSTC) $(SRC_DIR)/foo.rs \ + --crate-type=rlib \ + --emit metadata \ + -C incremental=$(INCR_CACHE_DIR) \ + -Z incremental-verify-ich + + $(CGREP) "GDB script v2" < $(TMPDIR)/libfoo.rmeta + $(CGREP) -v "GDB script v1" < $(TMPDIR)/libfoo.rmeta + $(CGREP) "Natvis v2" < $(TMPDIR)/libfoo.rmeta + $(CGREP) -v "Natvis v1" < $(TMPDIR)/libfoo.rmeta diff --git a/tests/run-make/incremental-debugger-visualizer/foo.rs b/tests/run-make/incremental-debugger-visualizer/foo.rs new file mode 100644 index 000000000..8daa36a12 --- /dev/null +++ b/tests/run-make/incremental-debugger-visualizer/foo.rs @@ -0,0 +1,6 @@ +#![debugger_visualizer(natvis_file = "./foo.natvis")] +#![debugger_visualizer(gdb_script_file = "./foo.py")] + +pub struct Foo { + pub x: u32, +} diff --git a/tests/run-make/issue-107094/Makefile b/tests/run-make/issue-107094/Makefile new file mode 100644 index 000000000..d614e3e10 --- /dev/null +++ b/tests/run-make/issue-107094/Makefile @@ -0,0 +1,7 @@ +# needs-git-hash + +include ../tools.mk + +all: + $(BARE_RUSTC) --version --verbose | $(CGREP) -i -e "commit-hash: [0-9a-f]{40}" "commit-date: [0-9]{4}-[0-9]{2}-[0-9]{2}" + $(BARE_RUSTDOC) --version --verbose | $(CGREP) -i -e "commit-hash: [0-9a-f]{40}" "commit-date: [0-9]{4}-[0-9]{2}-[0-9]{2}" diff --git a/tests/run-make/issue-83045/Makefile b/tests/run-make/issue-83045/Makefile index 7053da00f..b76e184b6 100644 --- a/tests/run-make/issue-83045/Makefile +++ b/tests/run-make/issue-83045/Makefile @@ -29,5 +29,5 @@ all: --crate-type=rlib \ --edition=2018 \ c.rs 2>&1 | tee $(TMPDIR)/output.txt || exit 0 - $(CGREP) E0519 < $(TMPDIR)/output.txt + $(CGREP) E0463 < $(TMPDIR)/output.txt $(CGREP) -v "internal compiler error" < $(TMPDIR)/output.txt diff --git a/tests/run-make/libtest-json/Makefile b/tests/run-make/libtest-json/Makefile index 417637cf0..c8bc7b5dd 100644 --- a/tests/run-make/libtest-json/Makefile +++ b/tests/run-make/libtest-json/Makefile @@ -1,4 +1,5 @@ # ignore-cross-compile +# needs-unwind include ../tools.mk # Test expected libtest's JSON output diff --git a/tests/run-make/libtest-junit/Makefile b/tests/run-make/libtest-junit/Makefile new file mode 100644 index 000000000..d97cafccf --- /dev/null +++ b/tests/run-make/libtest-junit/Makefile @@ -0,0 +1,19 @@ +# ignore-cross-compile +include ../tools.mk + +# Test expected libtest's junit output + +OUTPUT_FILE_DEFAULT := $(TMPDIR)/libtest-junit-output-default.xml +OUTPUT_FILE_STDOUT_SUCCESS := $(TMPDIR)/libtest-junit-output-stdout-success.xml + +all: f.rs validate_junit.py output-default.xml output-stdout-success.xml + $(RUSTC) --test f.rs + RUST_BACKTRACE=0 $(call RUN,f) -Z unstable-options --test-threads=1 --format=junit > $(OUTPUT_FILE_DEFAULT) || true + RUST_BACKTRACE=0 $(call RUN,f) -Z unstable-options --test-threads=1 --format=junit --show-output > $(OUTPUT_FILE_STDOUT_SUCCESS) || true + + cat $(OUTPUT_FILE_DEFAULT) | "$(PYTHON)" validate_junit.py + cat $(OUTPUT_FILE_STDOUT_SUCCESS) | "$(PYTHON)" validate_junit.py + + # Normalize the actual output and compare to expected output file + cat $(OUTPUT_FILE_DEFAULT) | sed 's/time="[0-9.]*"/time="$$TIME"/g' | diff output-default.xml - + cat $(OUTPUT_FILE_STDOUT_SUCCESS) | sed 's/time="[0-9.]*"/time="$$TIME"/g' | diff output-stdout-success.xml - diff --git a/tests/run-make/libtest-junit/f.rs b/tests/run-make/libtest-junit/f.rs new file mode 100644 index 000000000..d360d7731 --- /dev/null +++ b/tests/run-make/libtest-junit/f.rs @@ -0,0 +1,23 @@ +#[test] +fn a() { + println!("print from successful test"); + // Should pass +} + +#[test] +fn b() { + println!("print from failing test"); + assert!(false); +} + +#[test] +#[should_panic] +fn c() { + assert!(false); +} + +#[test] +#[ignore = "msg"] +fn d() { + assert!(false); +} diff --git a/tests/run-make/libtest-junit/output-default.xml b/tests/run-make/libtest-junit/output-default.xml new file mode 100644 index 000000000..d59e07b8a --- /dev/null +++ b/tests/run-make/libtest-junit/output-default.xml @@ -0,0 +1 @@ +<?xml version="1.0" encoding="UTF-8"?><testsuites><testsuite name="test" package="test" id="0" errors="0" failures="1" tests="4" skipped="1" ><testcase classname="unknown" name="a" time="$TIME"/><testcase classname="unknown" name="b" time="$TIME"><failure type="assert"/><system-out><![CDATA[print from failing test]]>
<![CDATA[thread 'b' panicked at 'assertion failed: false', f.rs:10:5]]>
<![CDATA[note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace]]>
<![CDATA[]]></system-out></testcase><testcase classname="unknown" name="c" time="$TIME"/><system-out/><system-err/></testsuite></testsuites> diff --git a/tests/run-make/libtest-junit/output-stdout-success.xml b/tests/run-make/libtest-junit/output-stdout-success.xml new file mode 100644 index 000000000..0c300611e --- /dev/null +++ b/tests/run-make/libtest-junit/output-stdout-success.xml @@ -0,0 +1 @@ +<?xml version="1.0" encoding="UTF-8"?><testsuites><testsuite name="test" package="test" id="0" errors="0" failures="1" tests="4" skipped="1" ><testcase classname="unknown" name="a" time="$TIME"><system-out><![CDATA[print from successful test]]>
<![CDATA[]]></system-out></testcase><testcase classname="unknown" name="b" time="$TIME"><failure type="assert"/><system-out><![CDATA[print from failing test]]>
<![CDATA[thread 'b' panicked at 'assertion failed: false', f.rs:10:5]]>
<![CDATA[note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace]]>
<![CDATA[]]></system-out></testcase><testcase classname="unknown" name="c" time="$TIME"><system-out><![CDATA[thread 'c' panicked at 'assertion failed: false', f.rs:16:5]]>
<![CDATA[]]></system-out></testcase><system-out/><system-err/></testsuite></testsuites> diff --git a/tests/run-make/libtest-junit/validate_junit.py b/tests/run-make/libtest-junit/validate_junit.py new file mode 100755 index 000000000..47a8e70cc --- /dev/null +++ b/tests/run-make/libtest-junit/validate_junit.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python + +import sys +import xml.etree.ElementTree as ET + +# Try to decode line in order to ensure it is a valid XML document +for line in sys.stdin: + try: + ET.fromstring(line) + except ET.ParseError as pe: + print("Invalid xml: %r" % line) + raise diff --git a/tests/run-make/no-alloc-shim/Makefile b/tests/run-make/no-alloc-shim/Makefile new file mode 100644 index 000000000..568e3f9ba --- /dev/null +++ b/tests/run-make/no-alloc-shim/Makefile @@ -0,0 +1,24 @@ +include ../tools.mk + +# ignore-cross-compile +# ignore-msvc FIXME(bjorn3) can't figure out how to link with the MSVC toolchain + +TARGET_LIBDIR = $$($(RUSTC) --print target-libdir) + +all: + $(RUSTC) foo.rs --crate-type bin --emit obj -Cpanic=abort +ifdef IS_MSVC + $(CC) $(CFLAGS) $(TMPDIR)/foo.o $(call OUT_EXE,foo) /link $(TARGET_LIBDIR)/liballoc-*.rlib $(TARGET_LIBDIR)/libcore-*.rlib $(TARGET_LIBDIR)/libcompiler_builtins-*.rlib + $(call OUT_EXE,foo) +else + $(CC) $(CFLAGS) $(TMPDIR)/foo.o $(TARGET_LIBDIR)/liballoc-*.rlib $(TARGET_LIBDIR)/libcore-*.rlib $(TARGET_LIBDIR)/libcompiler_builtins-*.rlib -o $(call RUN_BINFILE,foo) + $(call RUN_BINFILE,foo) +endif + + # Check that linking without __rust_no_alloc_shim_is_unstable defined fails + $(RUSTC) foo.rs --crate-type bin --emit obj -Cpanic=abort --cfg check_feature_gate +ifdef IS_MSVC + $(CC) $(CFLAGS) $(TMPDIR)/foo.o $(call OUT_EXE,foo) /link $(TARGET_LIBDIR)/liballoc-*.rlib $(TARGET_LIBDIR)/libcore-*.rlib $(TARGET_LIBDIR)/libcompiler_builtins-*.rlib || exit 0 && exit 1 +else + $(CC) $(CFLAGS) $(TMPDIR)/foo.o $(TARGET_LIBDIR)/liballoc-*.rlib $(TARGET_LIBDIR)/libcore-*.rlib $(TARGET_LIBDIR)/libcompiler_builtins-*.rlib -o $(call RUN_BINFILE,foo) || exit 0 && exit 1 +endif diff --git a/tests/run-make/no-alloc-shim/foo.rs b/tests/run-make/no-alloc-shim/foo.rs new file mode 100644 index 000000000..a3daec3db --- /dev/null +++ b/tests/run-make/no-alloc-shim/foo.rs @@ -0,0 +1,44 @@ +#![feature(default_alloc_error_handler)] +#![no_std] +#![no_main] + +extern crate alloc; + +use alloc::alloc::{GlobalAlloc, Layout}; + +#[panic_handler] +fn panic_handler(_: &core::panic::PanicInfo) -> ! { + loop {} +} + +#[no_mangle] +extern "C" fn rust_eh_personality() { + loop {} +} + +#[global_allocator] +static ALLOC: Alloc = Alloc; + +struct Alloc; + +unsafe impl GlobalAlloc for Alloc { + unsafe fn alloc(&self, _: Layout) -> *mut u8 { + core::ptr::null_mut() + } + unsafe fn dealloc(&self, _: *mut u8, _: Layout) { + todo!() + } +} + +#[cfg(not(check_feature_gate))] +#[no_mangle] +static __rust_no_alloc_shim_is_unstable: u8 = 0; + +#[no_mangle] +extern "C" fn main(_argc: usize, _argv: *const *const i8) -> i32 { + unsafe { + assert_eq!(alloc::alloc::alloc(Layout::new::<()>()), core::ptr::null_mut()); + } + + 0 +} diff --git a/tests/run-make/pointer-auth-link-with-c/Makefile b/tests/run-make/pointer-auth-link-with-c/Makefile index 7acea0380..dffbd3035 100644 --- a/tests/run-make/pointer-auth-link-with-c/Makefile +++ b/tests/run-make/pointer-auth-link-with-c/Makefile @@ -5,10 +5,10 @@ include ../tools.mk all: $(COMPILE_OBJ) $(TMPDIR)/test.o test.c $(AR) rcs $(TMPDIR)/libtest.a $(TMPDIR)/test.o - $(RUSTC) -Z branch-protection=bti,pac-ret,leaf test.rs + $(RUSTC) --target $(TARGET) -Z branch-protection=bti,pac-ret,leaf test.rs $(call RUN,test) $(COMPILE_OBJ) $(TMPDIR)/test.o test.c -mbranch-protection=bti+pac-ret+leaf $(AR) rcs $(TMPDIR)/libtest.a $(TMPDIR)/test.o - $(RUSTC) -Z branch-protection=bti,pac-ret,leaf test.rs + $(RUSTC) --target $(TARGET) -Z branch-protection=bti,pac-ret,leaf test.rs $(call RUN,test) diff --git a/tests/run-make/print-native-static-libs/Makefile b/tests/run-make/print-native-static-libs/Makefile new file mode 100644 index 000000000..98e72d769 --- /dev/null +++ b/tests/run-make/print-native-static-libs/Makefile @@ -0,0 +1,15 @@ +include ../tools.mk + +# ignore-cross-compile +# ignore-wasm + +all: + $(RUSTC) --crate-type rlib -lbar_cli bar.rs + $(RUSTC) foo.rs -lfoo_cli --crate-type staticlib --print native-static-libs 2>&1 \ + | grep 'note: native-static-libs: ' \ + | sed 's/note: native-static-libs: \(.*\)/\1/' > $(TMPDIR)/libs.txt + + cat $(TMPDIR)/libs.txt | grep -F "glib-2.0" # in bar.rs + cat $(TMPDIR)/libs.txt | grep -F "systemd" # in foo.rs + cat $(TMPDIR)/libs.txt | grep -F "bar_cli" + cat $(TMPDIR)/libs.txt | grep -F "foo_cli" diff --git a/tests/run-make/print-native-static-libs/bar.rs b/tests/run-make/print-native-static-libs/bar.rs new file mode 100644 index 000000000..a563bbc2a --- /dev/null +++ b/tests/run-make/print-native-static-libs/bar.rs @@ -0,0 +1,13 @@ +#[no_mangle] +pub extern "C" fn my_bar_add(left: i32, right: i32) -> i32 { + // Obviously makes no sense but... + unsafe { + g_free(std::ptr::null_mut()); + } + left + right +} + +#[link(name = "glib-2.0")] +extern "C" { + fn g_free(p: *mut ()); +} diff --git a/tests/run-make/print-native-static-libs/foo.rs b/tests/run-make/print-native-static-libs/foo.rs new file mode 100644 index 000000000..6acaee20e --- /dev/null +++ b/tests/run-make/print-native-static-libs/foo.rs @@ -0,0 +1,15 @@ +extern crate bar; + +#[no_mangle] +pub extern "C" fn my_foo_add(left: i32, right: i32) -> i32 { + // Obviously makes no sense but... + unsafe { + init(std::ptr::null_mut()); + } + bar::my_bar_add(left, right) +} + +#[link(name = "systemd")] +extern "C" { + fn init(p: *mut ()); +} diff --git a/tests/run-make/raw-dylib-alt-calling-convention/lib.rs b/tests/run-make/raw-dylib-alt-calling-convention/lib.rs index 22f222c12..dcb5fee9e 100644 --- a/tests/run-make/raw-dylib-alt-calling-convention/lib.rs +++ b/tests/run-make/raw-dylib-alt-calling-convention/lib.rs @@ -1,5 +1,4 @@ #![feature(abi_vectorcall)] -#![cfg_attr(target_arch = "x86", feature(raw_dylib))] #[repr(C)] #[derive(Clone)] diff --git a/tests/run-make/raw-dylib-c/lib.rs b/tests/run-make/raw-dylib-c/lib.rs index 5fb120403..f17125f30 100644 --- a/tests/run-make/raw-dylib-c/lib.rs +++ b/tests/run-make/raw-dylib-c/lib.rs @@ -1,5 +1,3 @@ -#![feature(raw_dylib)] - #[link(name = "extern_1.dll", kind = "raw-dylib", modifiers = "+verbatim")] extern { fn extern_fn_1(); diff --git a/tests/run-make/raw-dylib-cross-compilation/lib.rs b/tests/run-make/raw-dylib-cross-compilation/lib.rs index 51bf2ec6b..3338ac0a0 100644 --- a/tests/run-make/raw-dylib-cross-compilation/lib.rs +++ b/tests/run-make/raw-dylib-cross-compilation/lib.rs @@ -1,4 +1,3 @@ -#![feature(raw_dylib)] #![feature(no_core, lang_items)] #![no_std] #![no_core] diff --git a/tests/run-make/raw-dylib-custom-dlltool/Makefile b/tests/run-make/raw-dylib-custom-dlltool/Makefile new file mode 100644 index 000000000..f5d5360a3 --- /dev/null +++ b/tests/run-make/raw-dylib-custom-dlltool/Makefile @@ -0,0 +1,11 @@ +# Test using -Cdlltool to change where raw-dylib looks for the dlltool binary. + +# only-windows +# only-gnu +# needs-dlltool + +include ../tools.mk + +all: + $(RUSTC) --crate-type lib --crate-name raw_dylib_test lib.rs -Cdlltool=$(CURDIR)/script.cmd + $(DIFF) output.txt "$(TMPDIR)"/output.txt diff --git a/tests/run-make/raw-dylib-custom-dlltool/lib.rs b/tests/run-make/raw-dylib-custom-dlltool/lib.rs new file mode 100644 index 000000000..2f3f497a0 --- /dev/null +++ b/tests/run-make/raw-dylib-custom-dlltool/lib.rs @@ -0,0 +1,10 @@ +#[link(name = "extern_1", kind = "raw-dylib")] +extern { + fn extern_fn_1(); +} + +pub fn library_function() { + unsafe { + extern_fn_1(); + } +} diff --git a/tests/run-make/raw-dylib-custom-dlltool/output.txt b/tests/run-make/raw-dylib-custom-dlltool/output.txt new file mode 100644 index 000000000..6dd9466d2 --- /dev/null +++ b/tests/run-make/raw-dylib-custom-dlltool/output.txt @@ -0,0 +1 @@ +Called dlltool via script.cmd diff --git a/tests/run-make/raw-dylib-custom-dlltool/script.cmd b/tests/run-make/raw-dylib-custom-dlltool/script.cmd new file mode 100644 index 000000000..95f85c61c --- /dev/null +++ b/tests/run-make/raw-dylib-custom-dlltool/script.cmd @@ -0,0 +1,2 @@ +echo Called dlltool via script.cmd> %TMPDIR%\output.txt +dlltool.exe %* diff --git a/tests/run-make/raw-dylib-import-name-type/driver.rs b/tests/run-make/raw-dylib-import-name-type/driver.rs index 9a3cd9ebe..6c1c212f1 100644 --- a/tests/run-make/raw-dylib-import-name-type/driver.rs +++ b/tests/run-make/raw-dylib-import-name-type/driver.rs @@ -1,4 +1,3 @@ -#![feature(raw_dylib)] #![feature(abi_vectorcall)] #[link(name = "extern", kind = "raw-dylib", import_name_type = "undecorated")] diff --git a/tests/run-make/raw-dylib-inline-cross-dylib/driver.rs b/tests/run-make/raw-dylib-inline-cross-dylib/driver.rs index f72ded7d9..0c3125be6 100644 --- a/tests/run-make/raw-dylib-inline-cross-dylib/driver.rs +++ b/tests/run-make/raw-dylib-inline-cross-dylib/driver.rs @@ -1,5 +1,3 @@ -#![feature(raw_dylib)] - extern crate raw_dylib_test; extern crate raw_dylib_test_wrapper; diff --git a/tests/run-make/raw-dylib-inline-cross-dylib/lib.rs b/tests/run-make/raw-dylib-inline-cross-dylib/lib.rs index 00c2c1c42..4877cb80a 100644 --- a/tests/run-make/raw-dylib-inline-cross-dylib/lib.rs +++ b/tests/run-make/raw-dylib-inline-cross-dylib/lib.rs @@ -1,5 +1,3 @@ -#![feature(raw_dylib)] - #[link(name = "extern_1", kind = "raw-dylib")] extern { fn extern_fn_1(); diff --git a/tests/run-make/raw-dylib-link-ordinal/lib.rs b/tests/run-make/raw-dylib-link-ordinal/lib.rs index bb25ac64c..1bbb45bbc 100644 --- a/tests/run-make/raw-dylib-link-ordinal/lib.rs +++ b/tests/run-make/raw-dylib-link-ordinal/lib.rs @@ -1,5 +1,3 @@ -#![cfg_attr(target_arch = "x86", feature(raw_dylib))] - #[link(name = "exporter", kind = "raw-dylib")] extern { #[link_ordinal(13)] diff --git a/tests/run-make/raw-dylib-stdcall-ordinal/lib.rs b/tests/run-make/raw-dylib-stdcall-ordinal/lib.rs index b7921396a..74c5c7f82 100644 --- a/tests/run-make/raw-dylib-stdcall-ordinal/lib.rs +++ b/tests/run-make/raw-dylib-stdcall-ordinal/lib.rs @@ -1,5 +1,3 @@ -#![cfg_attr(target_arch = "x86", feature(raw_dylib))] - #[link(name = "exporter", kind = "raw-dylib")] extern "stdcall" { #[link_ordinal(15)] diff --git a/tests/run-make/short-ice/Makefile b/tests/run-make/short-ice/Makefile new file mode 100644 index 000000000..4f33d5902 --- /dev/null +++ b/tests/run-make/short-ice/Makefile @@ -0,0 +1,9 @@ +include ../tools.mk + +# ignore-windows + +export RUSTC := $(RUSTC_ORIGINAL) +export TMPDIR := $(TMPDIR) + +all: + bash check.sh diff --git a/tests/run-make/short-ice/check.sh b/tests/run-make/short-ice/check.sh new file mode 100644 index 000000000..96cd8fe86 --- /dev/null +++ b/tests/run-make/short-ice/check.sh @@ -0,0 +1,36 @@ +#!/bin/sh + +RUST_BACKTRACE=1 $RUSTC src/lib.rs -Z treat-err-as-bug=1 1>$TMPDIR/rust-test-1.log 2>&1 +RUST_BACKTRACE=full $RUSTC src/lib.rs -Z treat-err-as-bug=1 1>$TMPDIR/rust-test-2.log 2>&1 + +short=$(cat $TMPDIR/rust-test-1.log | wc -l) +full=$(cat $TMPDIR/rust-test-2.log | wc -l) +rustc_query_count=$(cat $TMPDIR/rust-test-1.log | grep rustc_query_ | wc -l) +rustc_query_count_full=$(cat $TMPDIR/rust-test-2.log | grep rustc_query_ | wc -l) + +begin_count=$(cat $TMPDIR/rust-test-2.log | grep __rust_begin_short_backtrace | wc -l) +end_count=$(cat $TMPDIR/rust-test-2.log | grep __rust_end_short_backtrace | wc -l) + +cat $TMPDIR/rust-test-1.log +echo "=====================" +cat $TMPDIR/rust-test-2.log +echo "=====================" + +echo "short backtrace: $short" +echo "full backtrace: $full" +echo "begin_count: $begin_count" +echo "end_count : $end_count" +echo "rustc_query_count: $rustc_query_count" +echo "rustc_query_count_full: $rustc_query_count_full" + +## backtraces to vary a bit depending on platform and configuration options, +## here we make sure that the short backtrace of rustc_query is shorter than the full, +## and marks are in pairs. +if [ $short -lt $full ] && + [ $begin_count -eq $end_count ] && + [ $(($rustc_query_count + 10)) -lt $rustc_query_count_full ] && + [ $rustc_query_count_full -gt 10 ]; then + exit 0 +else + exit 1 +fi diff --git a/tests/run-make/short-ice/src/lib.rs b/tests/run-make/short-ice/src/lib.rs new file mode 100644 index 000000000..b23b7f830 --- /dev/null +++ b/tests/run-make/short-ice/src/lib.rs @@ -0,0 +1,7 @@ +fn func(s: &str) { + println!("{}", s); +} + +fn main() { + func(1); +} diff --git a/tests/run-make/static-unwinding/Makefile b/tests/run-make/static-unwinding/Makefile index dec94fb16..4b093f936 100644 --- a/tests/run-make/static-unwinding/Makefile +++ b/tests/run-make/static-unwinding/Makefile @@ -1,4 +1,5 @@ # ignore-cross-compile +# needs-unwind include ../tools.mk all: diff --git a/tests/run-make/staticlib-dylib-linkage/Makefile b/tests/run-make/staticlib-dylib-linkage/Makefile new file mode 100644 index 000000000..a1e86a7ce --- /dev/null +++ b/tests/run-make/staticlib-dylib-linkage/Makefile @@ -0,0 +1,21 @@ +include ../tools.mk + +# ignore-cross-compile +# ignore-msvc FIXME(bjorn3) can't figure out how to link with the MSVC toolchain +# ignore-wasm wasm doesn't support dynamic libraries + +all: + $(RUSTC) -C prefer-dynamic bar.rs + $(RUSTC) foo.rs --crate-type staticlib --print native-static-libs \ + -Z staticlib-allow-rdylib-deps 2>&1 | grep 'note: native-static-libs: ' \ + | sed 's/note: native-static-libs: \(.*\)/\1/' > $(TMPDIR)/libs.txt + cat $(TMPDIR)/libs.txt + +ifdef IS_MSVC + $(CC) $(CFLAGS) /c foo.c /Fo:$(TMPDIR)/foo.o + $(RUSTC_LINKER) $(TMPDIR)/foo.o $(TMPDIR)/foo.lib $$(cat $(TMPDIR)/libs.txt) $(call OUT_EXE,foo) +else + $(CC) $(CFLAGS) foo.c -L $(TMPDIR) -lfoo $$(cat $(TMPDIR)/libs.txt) -o $(call RUN_BINFILE,foo) +endif + + $(call RUN,foo) diff --git a/tests/run-make/staticlib-dylib-linkage/bar.rs b/tests/run-make/staticlib-dylib-linkage/bar.rs new file mode 100644 index 000000000..b3a7539ab --- /dev/null +++ b/tests/run-make/staticlib-dylib-linkage/bar.rs @@ -0,0 +1,5 @@ +#![crate_type = "dylib"] + +pub fn bar() { + println!("hello!"); +} diff --git a/tests/run-make/staticlib-dylib-linkage/foo.c b/tests/run-make/staticlib-dylib-linkage/foo.c new file mode 100644 index 000000000..154f9682e --- /dev/null +++ b/tests/run-make/staticlib-dylib-linkage/foo.c @@ -0,0 +1,10 @@ +#include <assert.h> + +extern void foo(); +extern unsigned bar(unsigned a, unsigned b); + +int main() { + foo(); + assert(bar(1, 2) == 3); + return 0; +} diff --git a/tests/run-make/staticlib-dylib-linkage/foo.rs b/tests/run-make/staticlib-dylib-linkage/foo.rs new file mode 100644 index 000000000..af439391c --- /dev/null +++ b/tests/run-make/staticlib-dylib-linkage/foo.rs @@ -0,0 +1,13 @@ +#![crate_type = "staticlib"] + +extern crate bar; + +#[no_mangle] +pub extern "C" fn foo() { + bar::bar(); +} + +#[no_mangle] +pub extern "C" fn bar(a: u32, b: u32) -> u32 { + a + b +} diff --git a/tests/run-make/test-benches/Makefile b/tests/run-make/test-benches/Makefile index 0253a5263..11aed2e4c 100644 --- a/tests/run-make/test-benches/Makefile +++ b/tests/run-make/test-benches/Makefile @@ -1,6 +1,7 @@ include ../tools.mk # ignore-cross-compile +# needs-unwind #[bench] and -Zpanic-abort-tests can't be combined all: # Smoke-test that `#[bench]` isn't entirely broken. diff --git a/tests/run-make/translation/Makefile b/tests/run-make/translation/Makefile index 0acf64e5d..07e0547cf 100644 --- a/tests/run-make/translation/Makefile +++ b/tests/run-make/translation/Makefile @@ -46,6 +46,8 @@ sysroot: test.rs working.ftl rm -f $(FAKEROOT)/lib/rustlib/src mkdir $(FAKEROOT)/lib/rustlib/src ln -s $(SYSROOT)/lib/rustlib/src/* $(FAKEROOT)/lib/rustlib/src + # When download-rustc is enabled, `$(SYSROOT)` will have a share directory. Delete the link to it. + rm -f $(FAKEROOT)/share mkdir -p $(FAKEROOT)/share/locale/zh-CN/ ln -s $(CURDIR)/working.ftl $(FAKEROOT)/share/locale/zh-CN/basic-translation.ftl $(RUSTC) $< --sysroot $(FAKEROOT) -Ztranslate-lang=zh-CN 2>&1 | $(CGREP) "this is a test message" diff --git a/tests/run-make/valid-print-requests/valid-print-requests.stderr b/tests/run-make/valid-print-requests/valid-print-requests.stderr index bea6ce067..4f57550c2 100644 --- a/tests/run-make/valid-print-requests/valid-print-requests.stderr +++ b/tests/run-make/valid-print-requests/valid-print-requests.stderr @@ -1,2 +1,2 @@ -error: unknown print request `uwu`. Valid print requests are: `crate-name`, `file-names`, `sysroot`, `target-libdir`, `cfg`, `calling-conventions`, `target-list`, `target-cpus`, `target-features`, `relocation-models`, `code-models`, `tls-models`, `native-static-libs`, `stack-protector-strategies`, `target-spec-json`, `all-target-specs-json`, `link-args`, `split-debuginfo` +error: unknown print request `uwu`. Valid print requests are: `crate-name`, `file-names`, `sysroot`, `target-libdir`, `cfg`, `calling-conventions`, `target-list`, `target-cpus`, `target-features`, `relocation-models`, `code-models`, `tls-models`, `native-static-libs`, `stack-protector-strategies`, `target-spec-json`, `all-target-specs-json`, `link-args`, `split-debuginfo`, `deployment-target` |