diff options
Diffstat (limited to 'tests/run-make')
57 files changed, 893 insertions, 35 deletions
diff --git a/tests/run-make/comment-section/Makefile b/tests/run-make/comment-section/Makefile new file mode 100644 index 000000000..9f810063c --- /dev/null +++ b/tests/run-make/comment-section/Makefile @@ -0,0 +1,15 @@ +include ../tools.mk + +# only-linux + +all: + echo 'fn main(){}' | $(RUSTC) - --emit=link,obj -Csave-temps --target=$(TARGET) + + # Check linked output has a `.comment` section with the expected content. + readelf -p '.comment' $(TMPDIR)/rust_out | $(CGREP) -F 'rustc version 1.' + + # Check all object files (including temporary outputs) have a `.comment` + # section with the expected content. + set -e; for f in $(TMPDIR)/*.o; do \ + readelf -p '.comment' $$f | $(CGREP) -F 'rustc version 1.'; \ + done diff --git a/tests/run-make/coverage-llvmir/filecheck.testprog.txt b/tests/run-make/coverage-llvmir/filecheck.testprog.txt index b3a8808df..9d63fabd7 100644 --- a/tests/run-make/coverage-llvmir/filecheck.testprog.txt +++ b/tests/run-make/coverage-llvmir/filecheck.testprog.txt @@ -39,10 +39,10 @@ CHECK-NOT: [[DEFINE_INTERNAL]] 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]+]] +CHECK: declare void @llvm.instrprof.increment(ptr, i64, i32, i32) #[[LLVM_INSTRPROF_INCREMENT_ATTR:[0-9]+]] WINDOWS: define linkonce_odr hidden i32 @__llvm_profile_runtime_user() #[[LLVM_PROFILE_RUNTIME_USER_ATTR:[0-9]+]] comdat { -WINDOWS-NEXT: %1 = load i32, {{i32\*|ptr}} @__llvm_profile_runtime +WINDOWS-NEXT: %1 = load i32, ptr @__llvm_profile_runtime WINDOWS-NEXT: ret i32 %1 WINDOWS-NEXT: } diff --git a/tests/run-make/doctests-keep-binaries/Makefile b/tests/run-make/doctests-keep-binaries/Makefile index 6254e93d3..2c647851a 100644 --- a/tests/run-make/doctests-keep-binaries/Makefile +++ b/tests/run-make/doctests-keep-binaries/Makefile @@ -3,7 +3,9 @@ include ../tools.mk # Check that valid binaries are persisted by running them, regardless of whether the --run or --no-run option is used. -all: run no_run +MY_SRC_DIR := ${CURDIR} + +all: run no_run test_run_directory run: mkdir -p $(TMPDIR)/doctests @@ -20,3 +22,12 @@ no_run: $(TMPDIR)/doctests/t_rs_2_0/rust_out $(TMPDIR)/doctests/t_rs_8_0/rust_out rm -rf $(TMPDIR)/doctests + +# Behavior with --test-run-directory with relative paths. +test_run_directory: + mkdir -p $(TMPDIR)/doctests + mkdir -p $(TMPDIR)/rundir + $(RUSTC) --crate-type rlib t.rs + ( cd $(TMPDIR); \ + $(RUSTDOC) -Zunstable-options --test --persist-doctests doctests --test-run-directory rundir --extern t=libt.rlib $(MY_SRC_DIR)/t.rs ) + rm -rf $(TMPDIR)/doctests $(TMPDIR)/rundir diff --git a/tests/run-make/doctests-runtool/Makefile b/tests/run-make/doctests-runtool/Makefile new file mode 100644 index 000000000..7d5df1e30 --- /dev/null +++ b/tests/run-make/doctests-runtool/Makefile @@ -0,0 +1,20 @@ +# ignore-cross-compile +include ../tools.mk + +# Tests behavior of rustdoc --runtool + +MY_SRC_DIR := ${CURDIR} + +all: with_test_run_directory + +# Behavior with --runtool with relative paths and --test-run-directory. +with_test_run_directory: + mkdir -p $(TMPDIR)/rundir + mkdir -p $(TMPDIR)/runtool + $(RUSTC) --crate-type rlib t.rs + $(RUSTC) runtool.rs -o $(TMPDIR)/runtool/runtool + ( cd $(TMPDIR); \ + $(RUSTDOC) -Zunstable-options --test --test-run-directory rundir \ + --runtool runtool/runtool --extern t=libt.rlib $(MY_SRC_DIR)/t.rs \ + ) + rm -rf $(TMPDIR)/rundir $(TMPDIR)/runtool diff --git a/tests/run-make/doctests-runtool/runtool.rs b/tests/run-make/doctests-runtool/runtool.rs new file mode 100644 index 000000000..f5e3afdf2 --- /dev/null +++ b/tests/run-make/doctests-runtool/runtool.rs @@ -0,0 +1,3 @@ +fn main() { + eprintln!("{:?}", std::env::args().collect::<Vec<_>>()); +} diff --git a/tests/run-make/doctests-runtool/t.rs b/tests/run-make/doctests-runtool/t.rs new file mode 100644 index 000000000..c38cf0a0b --- /dev/null +++ b/tests/run-make/doctests-runtool/t.rs @@ -0,0 +1,11 @@ +/// Fungle the foople. +/// ``` +/// t::foople(); +/// ``` +pub fn foople() {} + +/// Flomble the florp +/// ``` +/// t::florp(); +/// ``` +pub fn florp() {} diff --git a/tests/run-make/dump-ice-to-disk/Makefile b/tests/run-make/dump-ice-to-disk/Makefile new file mode 100644 index 000000000..23006fc09 --- /dev/null +++ b/tests/run-make/dump-ice-to-disk/Makefile @@ -0,0 +1,10 @@ +include ../tools.mk + +# ignore-windows + +export RUSTC := $(RUSTC_ORIGINAL) +export LD_LIBRARY_PATH := $(HOST_RPATH_DIR) +export TMPDIR := $(TMPDIR) + +all: + bash check.sh diff --git a/tests/run-make/dump-ice-to-disk/check.sh b/tests/run-make/dump-ice-to-disk/check.sh new file mode 100644 index 000000000..ab6f9ab60 --- /dev/null +++ b/tests/run-make/dump-ice-to-disk/check.sh @@ -0,0 +1,58 @@ +#!/bin/sh + +# Default nightly behavior (write ICE to current directory) +# FIXME(estebank): these are failing on CI, but passing locally. +# $RUSTC src/lib.rs -Z treat-err-as-bug=1 1>$TMPDIR/rust-test-default.log 2>&1 +# default=$(cat ./rustc-ice-*.txt | wc -l) +# rm ./rustc-ice-*.txt + +# Explicit directory set +export RUSTC_ICE=$TMPDIR +$RUSTC src/lib.rs -Z treat-err-as-bug=1 1>$TMPDIR/rust-test-default-set.log 2>&1 +default_set=$(cat $TMPDIR/rustc-ice-*.txt | wc -l) +content=$(cat $TMPDIR/rustc-ice-*.txt) +rm $TMPDIR/rustc-ice-*.txt +RUST_BACKTRACE=short $RUSTC src/lib.rs -Z treat-err-as-bug=1 1>$TMPDIR/rust-test-short.log 2>&1 +short=$(cat $TMPDIR/rustc-ice-*.txt | wc -l) +rm $TMPDIR/rustc-ice-*.txt +RUST_BACKTRACE=full $RUSTC src/lib.rs -Z treat-err-as-bug=1 1>$TMPDIR/rust-test-full.log 2>&1 +full=$(cat $TMPDIR/rustc-ice-*.txt | wc -l) +rm $TMPDIR/rustc-ice-*.txt + +# Explicitly disabling ICE dump +export RUSTC_ICE=0 +$RUSTC src/lib.rs -Z treat-err-as-bug=1 1>$TMPDIR/rust-test-disabled.log 2>&1 +should_be_empty_tmp=$(ls -l $TMPDIR/rustc-ice-*.txt 2>/dev/null | wc -l) +should_be_empty_dot=$(ls -l ./rustc-ice-*.txt 2>/dev/null | wc -l) + +echo "#### ICE Dump content:" +echo $content +echo "#### default length:" +echo $default +echo "#### short length:" +echo $short +echo "#### default_set length:" +echo $default_set +echo "#### full length:" +echo $full +echo "#### should_be_empty_dot length:" +echo $should_be_empty_dot +echo "#### should_be_empty_tmp length:" +echo $should_be_empty_tmp + +## Verify that a the ICE dump file is created in the appropriate directories, that +## their lengths are the same regardless of other backtrace configuration options, +## that the file is not created when asked to (RUSTC_ICE=0) and that the file +## contains at least part of the expected content. +if [ $short -eq $default_set ] && + #[ $default -eq $short ] && + [ $default_set -eq $full ] && + [[ $content == *"thread 'rustc' panicked at "* ]] && + [[ $content == *"stack backtrace:"* ]] && + #[ $default -gt 0 ] && + [ $should_be_empty_dot -eq 0 ] && + [ $should_be_empty_tmp -eq 0 ]; then + exit 0 +else + exit 1 +fi diff --git a/tests/run-make/dump-ice-to-disk/src/lib.rs b/tests/run-make/dump-ice-to-disk/src/lib.rs new file mode 100644 index 000000000..b23b7f830 --- /dev/null +++ b/tests/run-make/dump-ice-to-disk/src/lib.rs @@ -0,0 +1,7 @@ +fn func(s: &str) { + println!("{}", s); +} + +fn main() { + func(1); +} diff --git a/tests/run-make/exit-code/Makefile b/tests/run-make/exit-code/Makefile index 6458b7168..155e5cd11 100644 --- a/tests/run-make/exit-code/Makefile +++ b/tests/run-make/exit-code/Makefile @@ -5,7 +5,7 @@ all: $(RUSTC) success.rs; [ $$? -eq 0 ] $(RUSTC) --invalid-arg-foo; [ $$? -eq 1 ] $(RUSTC) compile-error.rs; [ $$? -eq 1 ] - $(RUSTC) -Ztreat-err-as-bug compile-error.rs; [ $$? -eq 101 ] + RUSTC_ICE=0 $(RUSTC) -Ztreat-err-as-bug compile-error.rs; [ $$? -eq 101 ] $(RUSTDOC) -o $(TMPDIR)/exit-code success.rs; [ $$? -eq 0 ] $(RUSTDOC) --invalid-arg-foo; [ $$? -eq 1 ] $(RUSTDOC) compile-error.rs; [ $$? -eq 1 ] diff --git a/tests/run-make/extern-flag-pathless/Makefile b/tests/run-make/extern-flag-pathless/Makefile index 701bfcd28..36b374e0d 100644 --- a/tests/run-make/extern-flag-pathless/Makefile +++ b/tests/run-make/extern-flag-pathless/Makefile @@ -3,17 +3,32 @@ include ../tools.mk # Test mixing pathless --extern with paths. +# Test for static linking by checking that the binary runs if the dylib +# is removed and test for dynamic linking by checking that the binary +# fails to run if the dylib is removed. + all: - $(RUSTC) bar-static.rs --crate-name=bar --crate-type=rlib - $(RUSTC) bar-dynamic.rs --crate-name=bar --crate-type=dylib -C prefer-dynamic + $(RUSTC) bar.rs --crate-type=rlib --crate-type=dylib -Cprefer-dynamic + # rlib preferred over dylib $(RUSTC) foo.rs --extern bar - $(call RUN,foo) | $(CGREP) 'static' + mv $(call DYLIB,bar) $(TMPDIR)/bar.tmp + $(call RUN,foo) + mv $(TMPDIR)/bar.tmp $(call DYLIB,bar) + $(RUSTC) foo.rs --extern bar=$(TMPDIR)/libbar.rlib --extern bar - $(call RUN,foo) | $(CGREP) 'static' + mv $(call DYLIB,bar) $(TMPDIR)/bar.tmp + $(call RUN,foo) + mv $(TMPDIR)/bar.tmp $(call DYLIB,bar) + # explicit --extern overrides pathless $(RUSTC) foo.rs --extern bar=$(call DYLIB,bar) --extern bar - $(call RUN,foo) | $(CGREP) 'dynamic' + mv $(call DYLIB,bar) $(TMPDIR)/bar.tmp + $(call FAIL,foo) + mv $(TMPDIR)/bar.tmp $(call DYLIB,bar) + # prefer-dynamic does what it says $(RUSTC) foo.rs --extern bar -C prefer-dynamic - $(call RUN,foo) | $(CGREP) 'dynamic' + mv $(call DYLIB,bar) $(TMPDIR)/bar.tmp + $(call FAIL,foo) + mv $(TMPDIR)/bar.tmp $(call DYLIB,bar) diff --git a/tests/run-make/extern-flag-pathless/bar-dynamic.rs b/tests/run-make/extern-flag-pathless/bar-dynamic.rs deleted file mode 100644 index e2d68d517..000000000 --- a/tests/run-make/extern-flag-pathless/bar-dynamic.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub fn f() { - println!("dynamic"); -} diff --git a/tests/run-make/extern-flag-pathless/bar-static.rs b/tests/run-make/extern-flag-pathless/bar-static.rs deleted file mode 100644 index 240d8bde4..000000000 --- a/tests/run-make/extern-flag-pathless/bar-static.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub fn f() { - println!("static"); -} diff --git a/tests/run-make/extern-flag-pathless/bar.rs b/tests/run-make/extern-flag-pathless/bar.rs new file mode 100644 index 000000000..cdc6c27d8 --- /dev/null +++ b/tests/run-make/extern-flag-pathless/bar.rs @@ -0,0 +1 @@ +pub fn f() {} diff --git a/tests/run-make/extern-fn-explicit-align/Makefile b/tests/run-make/extern-fn-explicit-align/Makefile new file mode 100644 index 000000000..3cbbf3839 --- /dev/null +++ b/tests/run-make/extern-fn-explicit-align/Makefile @@ -0,0 +1,6 @@ +# ignore-cross-compile +include ../tools.mk + +all: $(call NATIVE_STATICLIB,test) + $(RUSTC) test.rs + $(call RUN,test) || exit 1 diff --git a/tests/run-make/extern-fn-explicit-align/test.c b/tests/run-make/extern-fn-explicit-align/test.c new file mode 100644 index 000000000..a3db3442a --- /dev/null +++ b/tests/run-make/extern-fn-explicit-align/test.c @@ -0,0 +1,93 @@ +#include <assert.h> +#include <stdbool.h> +#include <stdint.h> +#include <string.h> + +struct BoolAndU32 +{ + bool a; + uint32_t b; +}; + +#ifdef _MSC_VER +__declspec(align(16)) +struct TwoU64s +{ + uint64_t a; + uint64_t b; +}; +#else +struct __attribute__((aligned(16))) TwoU64s +{ + uint64_t a; + uint64_t b; +}; +#endif + +struct WrappedU64s +{ + struct TwoU64s a; +}; + +#ifdef _MSC_VER +__declspec(align(1)) +struct LowerAlign +{ + uint64_t a; + uint64_t b; +}; +#else +struct __attribute__((aligned(1))) LowerAlign +{ + uint64_t a; + uint64_t b; +}; +#endif + +#pragma pack(push, 1) +struct Packed +{ + uint64_t a; + uint64_t b; +}; +#pragma pack(pop) + +int32_t many_args( + void *a, + void *b, + const char *c, + uint64_t d, + bool e, + struct BoolAndU32 f, + void *g, + struct TwoU64s h, + void *i, + struct WrappedU64s j, + void *k, + struct LowerAlign l, + void *m, + struct Packed n, + const char *o) +{ + assert(!a); + assert(!b); + assert(!c); + assert(d == 42); + assert(e); + assert(f.a); + assert(f.b == 1337); + assert(!g); + assert(h.a == 1); + assert(h.b == 2); + assert(!i); + assert(j.a.a == 3); + assert(j.a.b == 4); + assert(!k); + assert(l.a == 5); + assert(l.b == 6); + assert(!m); + assert(n.a == 7); + assert(n.b == 8); + assert(strcmp(o, "Hello world") == 0); + return 0; +} diff --git a/tests/run-make/extern-fn-explicit-align/test.rs b/tests/run-make/extern-fn-explicit-align/test.rs new file mode 100644 index 000000000..846622de3 --- /dev/null +++ b/tests/run-make/extern-fn-explicit-align/test.rs @@ -0,0 +1,89 @@ +// Issue #80127: Passing structs via FFI should work with explicit alignment. + +use std::ffi::{CStr, c_char}; +use std::ptr::null_mut; + +#[repr(C)] +pub struct BoolAndU32 { + pub a: bool, + pub b: u32, +} + +#[repr(C)] +#[repr(align(16))] +pub struct TwoU64s { + pub a: u64, + pub b: u64, +} + +#[repr(C)] +pub struct WrappedU64s { + pub a: TwoU64s +} + +#[repr(C)] +// Even though requesting align 1 can never change the alignment, it still affects the ABI +// on some platforms like i686-windows. +#[repr(align(1))] +pub struct LowerAlign { + pub a: u64, + pub b: u64, +} + +#[repr(C)] +#[repr(packed)] +pub struct Packed { + pub a: u64, + pub b: u64, +} + +#[link(name = "test", kind = "static")] +extern "C" { + fn many_args( + a: *mut (), + b: *mut (), + c: *const c_char, + d: u64, + e: bool, + f: BoolAndU32, + g: *mut (), + h: TwoU64s, + i: *mut (), + j: WrappedU64s, + k: *mut (), + l: LowerAlign, + m: *mut (), + n: Packed, + o: *const c_char, + ) -> i32; +} + +const STRING: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"Hello world\0") }; + +fn main() { + let bool_and_u32 = BoolAndU32 { a: true, b: 1337 }; + let two_u64s = TwoU64s { a: 1, b: 2 }; + let wrapped = WrappedU64s { a: TwoU64s { a: 3, b: 4 } }; + let lower = LowerAlign { a: 5, b: 6 }; + let packed = Packed { a: 7, b: 8 }; + let string = STRING; + unsafe { + many_args( + null_mut(), + null_mut(), + null_mut(), + 42, + true, + bool_and_u32, + null_mut(), + two_u64s, + null_mut(), + wrapped, + null_mut(), + lower, + null_mut(), + packed, + string.as_ptr(), + ); + } +} diff --git a/tests/run-make/extern-fn-struct-passing-abi/test.c b/tests/run-make/extern-fn-struct-passing-abi/test.c index 136b07129..2cff776d8 100644 --- a/tests/run-make/extern-fn-struct-passing-abi/test.c +++ b/tests/run-make/extern-fn-struct-passing-abi/test.c @@ -28,6 +28,14 @@ struct Huge { int32_t e; }; +struct Huge64 { + int64_t a; + int64_t b; + int64_t c; + int64_t d; + int64_t e; +}; + struct FloatPoint { double x; double y; @@ -152,6 +160,21 @@ void byval_rect_with_many_huge(struct Huge a, struct Huge b, struct Huge c, assert(g.d == 420); } +// System V x86_64 ABI: +// a, b, d, e, f should be byval pointer (on the stack) +// g passed via register (fixes #41375) +// +// i686-windows ABI: +// a, b, d, e, f, g should be byval pointer +void byval_rect_with_many_huge64(struct Huge64 a, struct Huge64 b, struct Huge64 c, + struct Huge64 d, struct Huge64 e, struct Huge64 f, + struct Rect g) { + assert(g.a == 1234); + assert(g.b == 4567); + assert(g.c == 7890); + assert(g.d == 4209); +} + // System V x86_64 & Win64 ABI: // a, b should be in registers // s should be split across 2 integer registers @@ -279,6 +302,19 @@ struct Huge huge_struct(struct Huge s) { return s; } +// System V x86_64 & i686-windows ABI: +// s should be byval pointer +// return should in a hidden sret pointer +struct Huge64 huge64_struct(struct Huge64 s) { + assert(s.a == 1234); + assert(s.b == 1335); + assert(s.c == 1436); + assert(s.d == 1537); + assert(s.e == 1638); + + return s; +} + // System V x86_64 ABI: // p should be in registers // return should be in registers diff --git a/tests/run-make/extern-fn-struct-passing-abi/test.rs b/tests/run-make/extern-fn-struct-passing-abi/test.rs index afe0f52ef..99e079f98 100644 --- a/tests/run-make/extern-fn-struct-passing-abi/test.rs +++ b/tests/run-make/extern-fn-struct-passing-abi/test.rs @@ -38,6 +38,16 @@ struct Huge { #[derive(Clone, Copy, Debug, PartialEq)] #[repr(C)] +struct Huge64 { + a: i64, + b: i64, + c: i64, + d: i64, + e: i64, +} + +#[derive(Clone, Copy, Debug, PartialEq)] +#[repr(C)] struct FloatPoint { x: f64, y: f64, @@ -79,6 +89,12 @@ extern "C" { fn byval_rect_with_many_huge(a: Huge, b: Huge, c: Huge, d: Huge, e: Huge, f: Huge, g: Rect); + fn byval_rect_with_many_huge64( + a: Huge64, b: Huge64, c: Huge64, + d: Huge64, e: Huge64, f: Huge64, + g: Rect, + ); + fn split_rect(a: i32, b: i32, s: Rect); fn split_rect_floats(a: f32, b: f32, s: FloatRect); @@ -95,6 +111,8 @@ extern "C" { fn huge_struct(s: Huge) -> Huge; + fn huge64_struct(s: Huge64) -> Huge64; + fn float_point(p: FloatPoint) -> FloatPoint; fn float_one(f: FloatOne) -> FloatOne; @@ -107,6 +125,7 @@ fn main() { let t = BiggerRect { s: s, a: 27834, b: 7657 }; let u = FloatRect { a: 3489, b: 3490, c: 8. }; let v = Huge { a: 5647, b: 5648, c: 5649, d: 5650, e: 5651 }; + let w = Huge64 { a: 1234, b: 1335, c: 1436, d: 1537, e: 1638 }; let p = FloatPoint { x: 5., y: -3. }; let f1 = FloatOne { x: 7. }; let i = IntOdd { a: 1, b: 2, c: 3 }; @@ -117,12 +136,14 @@ fn main() { byval_rect_floats(1., 2., 3., 4., 5., 6., 7., s, u); byval_rect_with_float(1, 2, 3.0, 4, 5, 6, s); byval_rect_with_many_huge(v, v, v, v, v, v, Rect { a: 123, b: 456, c: 789, d: 420 }); + byval_rect_with_many_huge64(w, w, w, w, w, w, Rect { a: 1234, b: 4567, c: 7890, d: 4209 }); split_rect(1, 2, s); split_rect_floats(1., 2., u); split_rect_with_floats(1, 2, 3.0, 4, 5.0, 6, s); split_and_byval_rect(1, 2, 3, s, s); split_rect(1, 2, s); assert_eq!(huge_struct(v), v); + assert_eq!(huge64_struct(w), w); assert_eq!(split_ret_byval_struct(1, 2, s), s); assert_eq!(sret_byval_struct(1, 2, 3, 4, s), t); assert_eq!(sret_split_struct(1, 2, s), t); diff --git a/tests/run-make/libtest-json/output-default.json b/tests/run-make/libtest-json/output-default.json index ad22b66ed..01710f59e 100644 --- a/tests/run-make/libtest-json/output-default.json +++ b/tests/run-make/libtest-json/output-default.json @@ -2,7 +2,7 @@ { "type": "test", "event": "started", "name": "a" } { "type": "test", "name": "a", "event": "ok" } { "type": "test", "event": "started", "name": "b" } -{ "type": "test", "name": "b", "event": "failed", "stdout": "thread 'b' panicked at 'assertion failed: false', f.rs:9:5\nnote: run with `RUST_BACKTRACE=1` environment variable to display a backtrace\n" } +{ "type": "test", "name": "b", "event": "failed", "stdout": "thread 'b' panicked at f.rs:9:5:\nassertion failed: false\nnote: run with `RUST_BACKTRACE=1` environment variable to display a backtrace\n" } { "type": "test", "event": "started", "name": "c" } { "type": "test", "name": "c", "event": "ok" } { "type": "test", "event": "started", "name": "d" } diff --git a/tests/run-make/libtest-json/output-stdout-success.json b/tests/run-make/libtest-json/output-stdout-success.json index ec98172eb..878eb6c7c 100644 --- a/tests/run-make/libtest-json/output-stdout-success.json +++ b/tests/run-make/libtest-json/output-stdout-success.json @@ -2,9 +2,9 @@ { "type": "test", "event": "started", "name": "a" } { "type": "test", "name": "a", "event": "ok", "stdout": "print from successful test\n" } { "type": "test", "event": "started", "name": "b" } -{ "type": "test", "name": "b", "event": "failed", "stdout": "thread 'b' panicked at 'assertion failed: false', f.rs:9:5\nnote: run with `RUST_BACKTRACE=1` environment variable to display a backtrace\n" } +{ "type": "test", "name": "b", "event": "failed", "stdout": "thread 'b' panicked at f.rs:9:5:\nassertion failed: false\nnote: run with `RUST_BACKTRACE=1` environment variable to display a backtrace\n" } { "type": "test", "event": "started", "name": "c" } -{ "type": "test", "name": "c", "event": "ok", "stdout": "thread 'c' panicked at 'assertion failed: false', f.rs:15:5\n" } +{ "type": "test", "name": "c", "event": "ok", "stdout": "thread 'c' panicked at f.rs:15:5:\nassertion failed: false\n" } { "type": "test", "event": "started", "name": "d" } { "type": "test", "name": "d", "event": "ignored", "message": "msg" } { "type": "suite", "event": "failed", "passed": 2, "failed": 1, "ignored": 1, "measured": 0, "filtered_out": 0, "exec_time": $TIME } diff --git a/tests/run-make/libtest-junit/output-default.xml b/tests/run-make/libtest-junit/output-default.xml index d59e07b8a..58a9a2874 100644 --- a/tests/run-make/libtest-junit/output-default.xml +++ b/tests/run-make/libtest-junit/output-default.xml @@ -1 +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> +<?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 f.rs:10:5:]]>
<![CDATA[assertion failed: false]]>
<![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 index 0c300611e..723816a4a 100644 --- a/tests/run-make/libtest-junit/output-stdout-success.xml +++ b/tests/run-make/libtest-junit/output-stdout-success.xml @@ -1 +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> +<?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 f.rs:10:5:]]>
<![CDATA[assertion failed: false]]>
<![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 f.rs:16:5:]]>
<![CDATA[assertion failed: false]]>
<![CDATA[]]></system-out></testcase><system-out/><system-err/></testsuite></testsuites> diff --git a/tests/run-make/llvm-ident/Makefile b/tests/run-make/llvm-ident/Makefile new file mode 100644 index 000000000..e583e6018 --- /dev/null +++ b/tests/run-make/llvm-ident/Makefile @@ -0,0 +1,19 @@ +include ../tools.mk + +# only-linux + +all: + # `-Ccodegen-units=16 -Copt-level=2` is used here to trigger thin LTO + # across codegen units to test deduplication of the named metadata + # (see `LLVMRustPrepareThinLTOImport` for details). + echo 'fn main(){}' | $(RUSTC) - --emit=link,obj -Csave-temps -Ccodegen-units=16 -Copt-level=2 --target=$(TARGET) + + # `llvm-dis` is used here since `--emit=llvm-ir` does not emit LLVM IR + # for temporary outputs. + "$(LLVM_BIN_DIR)"/llvm-dis $(TMPDIR)/*.bc + + # Check LLVM IR files (including temporary outputs) have `!llvm.ident` + # named metadata, reusing the related codegen test. + set -e; for f in $(TMPDIR)/*.ll; do \ + $(LLVM_FILECHECK) --input-file $$f ../../codegen/llvm-ident.rs; \ + done diff --git a/tests/run-make/mixing-libs/Makefile b/tests/run-make/mixing-libs/Makefile index e8262b284..459db0dfd 100644 --- a/tests/run-make/mixing-libs/Makefile +++ b/tests/run-make/mixing-libs/Makefile @@ -2,9 +2,7 @@ include ../tools.mk all: - $(RUSTC) rlib.rs - $(RUSTC) dylib.rs - $(RUSTC) rlib.rs --crate-type=dylib - $(RUSTC) dylib.rs - $(call REMOVE_DYLIBS,rlib) + $(RUSTC) rlib.rs --crate-type=rlib --crate-type=dylib + $(RUSTC) dylib.rs # no -Cprefer-dynamic so statically linking librlib.rlib + $(call REMOVE_DYLIBS,rlib) # remove librlib.so to test that prog.rs doesn't get confused about the removed dylib version of librlib $(RUSTC) prog.rs && exit 1 || exit 0 diff --git a/tests/run-make/no-builtins-attribute/Makefile b/tests/run-make/no-builtins-attribute/Makefile new file mode 100644 index 000000000..0ce95faca --- /dev/null +++ b/tests/run-make/no-builtins-attribute/Makefile @@ -0,0 +1,9 @@ +include ../tools.mk + +# We want to check if `no-builtins` is also added to the function declarations in the used crate. + +all: + $(RUSTC) no_builtins.rs --emit=link + $(RUSTC) main.rs --emit=llvm-ir + + cat "$(TMPDIR)"/main.ll | "$(LLVM_FILECHECK)" filecheck.main.txt diff --git a/tests/run-make/no-builtins-attribute/filecheck.main.txt b/tests/run-make/no-builtins-attribute/filecheck.main.txt new file mode 100644 index 000000000..ecd650bdc --- /dev/null +++ b/tests/run-make/no-builtins-attribute/filecheck.main.txt @@ -0,0 +1,5 @@ +CHECK: declare void @foo() +CHECK-SAME: #[[ATTR_3:[0-9]+]] + +CHECK: attributes #[[ATTR_3]] +CHECK-SAME: no-builtins diff --git a/tests/run-make/no-builtins-attribute/main.rs b/tests/run-make/no-builtins-attribute/main.rs new file mode 100644 index 000000000..77754b37e --- /dev/null +++ b/tests/run-make/no-builtins-attribute/main.rs @@ -0,0 +1,10 @@ +extern crate no_builtins; + +#[no_mangle] +fn call_foo() { + no_builtins::foo(); +} + +fn main() { + call_foo(); +} diff --git a/tests/run-make/no-builtins-attribute/no_builtins.rs b/tests/run-make/no-builtins-attribute/no_builtins.rs new file mode 100644 index 000000000..8ca862d2f --- /dev/null +++ b/tests/run-make/no-builtins-attribute/no_builtins.rs @@ -0,0 +1,5 @@ +#![crate_type = "lib"] +#![no_builtins] + +#[no_mangle] +pub fn foo() {} diff --git a/tests/run-make/no-cdylib-as-rdylib/Makefile b/tests/run-make/no-cdylib-as-rdylib/Makefile new file mode 100644 index 000000000..4d2be0aea --- /dev/null +++ b/tests/run-make/no-cdylib-as-rdylib/Makefile @@ -0,0 +1,16 @@ +# ignore-cross-compile +include ../tools.mk + +# Test that rustc will not attempt to link against a cdylib as if +# it is a rust dylib when an rlib for the same crate is available. +# Previously rustc didn't actually check if any further formats of +# a crate which has been loaded are of the same version and if +# they are actually valid. This caused a cdylib to be interpreted +# as rust dylib as soon as the corresponding rlib was loaded. As +# cdylibs don't export any rust symbols, linking would fail if +# rustc decides to link against the cdylib rather than the rlib. + +all: + $(RUSTC) bar.rs --crate-type=rlib --crate-type=cdylib + $(RUSTC) foo.rs -C prefer-dynamic + $(call RUN,foo) diff --git a/tests/run-make/no-cdylib-as-rdylib/bar.rs b/tests/run-make/no-cdylib-as-rdylib/bar.rs new file mode 100644 index 000000000..c5c0bc606 --- /dev/null +++ b/tests/run-make/no-cdylib-as-rdylib/bar.rs @@ -0,0 +1 @@ +pub fn bar() {} diff --git a/tests/run-make/no-cdylib-as-rdylib/foo.rs b/tests/run-make/no-cdylib-as-rdylib/foo.rs new file mode 100644 index 000000000..8d68535e3 --- /dev/null +++ b/tests/run-make/no-cdylib-as-rdylib/foo.rs @@ -0,0 +1,5 @@ +extern crate bar; + +fn main() { + bar::bar(); +} diff --git a/tests/run-make/optimization-remarks-dir-pgo/Makefile b/tests/run-make/optimization-remarks-dir-pgo/Makefile new file mode 100644 index 000000000..3bc3d7d14 --- /dev/null +++ b/tests/run-make/optimization-remarks-dir-pgo/Makefile @@ -0,0 +1,21 @@ +# needs-profiler-support +# ignore-windows-gnu +# ignore-cross-compile + +# FIXME(mati865): MinGW GCC miscompiles compiler-rt profiling library but with Clang it works +# properly. Since we only have GCC on the CI ignore the test for now. + +include ../tools.mk + +PROFILE_DIR=$(TMPDIR)/profiles + +check_hotness: + $(RUSTC) -Cprofile-generate="$(TMPDIR)"/profdata -O foo.rs -o$(TMPDIR)/foo + $(TMPDIR)/foo + "$(LLVM_BIN_DIR)"/llvm-profdata merge \ + -o "$(TMPDIR)"/merged.profdata \ + "$(TMPDIR)"/profdata/*.profraw + $(RUSTC) -Cprofile-use=$(TMPDIR)/merged.profdata -O foo.rs -Cremark=all -Zremark-dir=$(PROFILE_DIR) + + # Check that PGO hotness is included in the remark files + cat $(PROFILE_DIR)/*.opt.yaml | $(CGREP) -e "Hotness" diff --git a/tests/run-make/optimization-remarks-dir-pgo/foo.rs b/tests/run-make/optimization-remarks-dir-pgo/foo.rs new file mode 100644 index 000000000..f7ca18263 --- /dev/null +++ b/tests/run-make/optimization-remarks-dir-pgo/foo.rs @@ -0,0 +1,6 @@ +#[inline(never)] +pub fn bar() {} + +fn main() { + bar(); +} diff --git a/tests/run-make/panic-abort-eh_frame/Makefile b/tests/run-make/panic-abort-eh_frame/Makefile index 1cb7bf575..7020455b7 100644 --- a/tests/run-make/panic-abort-eh_frame/Makefile +++ b/tests/run-make/panic-abort-eh_frame/Makefile @@ -6,5 +6,5 @@ include ../tools.mk all: - $(RUSTC) foo.rs --crate-type=lib --emit=obj=$(TMPDIR)/foo.o -Cpanic=abort + $(RUSTC) foo.rs --crate-type=lib --emit=obj=$(TMPDIR)/foo.o -Cpanic=abort --edition 2021 -Z validate-mir objdump --dwarf=frames $(TMPDIR)/foo.o | $(CGREP) -v 'DW_CFA' diff --git a/tests/run-make/panic-abort-eh_frame/foo.rs b/tests/run-make/panic-abort-eh_frame/foo.rs index e18535294..e2274d469 100644 --- a/tests/run-make/panic-abort-eh_frame/foo.rs +++ b/tests/run-make/panic-abort-eh_frame/foo.rs @@ -1,5 +1,13 @@ #![no_std] +use core::future::Future; + +pub struct NeedsDrop; + +impl Drop for NeedsDrop { + fn drop(&mut self) {} +} + #[panic_handler] fn handler(_: &core::panic::PanicInfo<'_>) -> ! { loop {} @@ -8,3 +16,19 @@ fn handler(_: &core::panic::PanicInfo<'_>) -> ! { pub unsafe fn oops(x: *const u32) -> u32 { *x } + +pub async fn foo(_: NeedsDrop) { + async fn bar() {} + bar().await; +} + +pub fn poll_foo(x: &mut core::task::Context<'_>) { + let _g = NeedsDrop; + let mut p = core::pin::pin!(foo(NeedsDrop)); + let _ = p.as_mut().poll(x); + let _ = p.as_mut().poll(x); +} + +pub fn drop_foo() { + drop(foo(NeedsDrop)); +} diff --git a/tests/run-make/pgo-indirect-call-promotion/filecheck-patterns.txt b/tests/run-make/pgo-indirect-call-promotion/filecheck-patterns.txt index e19c78350..2b058faaf 100644 --- a/tests/run-make/pgo-indirect-call-promotion/filecheck-patterns.txt +++ b/tests/run-make/pgo-indirect-call-promotion/filecheck-patterns.txt @@ -2,7 +2,7 @@ CHECK: define void @call_a_bunch_of_functions({{.*}} { # Make sure that indirect call promotion inserted a check against the most # frequently called function. -CHECK: %{{.*}} = icmp eq {{void \(\)\*|ptr}} %{{.*}}, @function_called_always +CHECK: %{{.*}} = icmp eq ptr %{{.*}}, @function_called_always # Check that the call to `function_called_always` was inlined, so that we # directly call `opaque_f1` from the upstream crate. @@ -12,5 +12,5 @@ CHECK: call void @opaque_f1() # Same checks as above, repeated for the trait object case CHECK: define void @call_a_bunch_of_trait_methods({{.*}} -CHECK: %{{.*}} = icmp eq {{void \(\{\}\*\)\*|ptr}} %{{.*}}, {{.*}}@foo +CHECK: %{{.*}} = icmp eq ptr %{{.*}}, {{.*}}@foo CHECK: tail call void @opaque_f2() diff --git a/tests/run-make/pretty-print-with-dep-file/Makefile b/tests/run-make/pretty-print-with-dep-file/Makefile new file mode 100644 index 000000000..fa8089eb6 --- /dev/null +++ b/tests/run-make/pretty-print-with-dep-file/Makefile @@ -0,0 +1,9 @@ +include ../tools.mk + +all: + $(RUSTC) --emit=dep-info -Zunpretty=expanded with-dep.rs + $(CGREP) "with-dep.rs" < $(TMPDIR)/with-dep.d + -rm $(TMPDIR)/with-dep.d + + $(RUSTC) --emit=dep-info -Zunpretty=normal with-dep.rs + ! test -f $(TMPDIR)/with-dep.d diff --git a/tests/run-make/pretty-print-with-dep-file/with-dep.rs b/tests/run-make/pretty-print-with-dep-file/with-dep.rs new file mode 100644 index 000000000..f328e4d9d --- /dev/null +++ b/tests/run-make/pretty-print-with-dep-file/with-dep.rs @@ -0,0 +1 @@ +fn main() {} diff --git a/tests/run-make/print-cfg/Makefile b/tests/run-make/print-cfg/Makefile index 126f5768c..654c303b3 100644 --- a/tests/run-make/print-cfg/Makefile +++ b/tests/run-make/print-cfg/Makefile @@ -2,7 +2,7 @@ include ../tools.mk -all: default +all: default output_to_file $(RUSTC) --target x86_64-pc-windows-gnu --print cfg | $(CGREP) windows $(RUSTC) --target x86_64-pc-windows-gnu --print cfg | $(CGREP) x86_64 $(RUSTC) --target i686-pc-windows-msvc --print cfg | $(CGREP) msvc @@ -11,6 +11,23 @@ all: default $(RUSTC) --target arm-unknown-linux-gnueabihf --print cfg | $(CGREP) target_abi= $(RUSTC) --target arm-unknown-linux-gnueabihf --print cfg | $(CGREP) eabihf +output_to_file: + # Backend-independent, printed by rustc_driver_impl/src/lib.rs + $(RUSTC) --target x86_64-pc-windows-gnu --print cfg=$(TMPDIR)/cfg.txt -Z unstable-options + $(CGREP) windows < $(TMPDIR)/cfg.txt + + # Printed from CodegenBackend trait impl in rustc_codegen_llvm/src/lib.rs + $(RUSTC) --print relocation-models=$(TMPDIR)/relocation-models.txt -Z unstable-options + $(CGREP) dynamic-no-pic < $(TMPDIR)/relocation-models.txt + + # Printed by compiler/rustc_codegen_llvm/src/llvm_util.rs + $(RUSTC) --target wasm32-unknown-unknown --print target-features=$(TMPDIR)/target-features.txt -Z unstable-options + $(CGREP) reference-types < $(TMPDIR)/target-features.txt + + # Printed by C++ code in rustc_llvm/llvm-wrapper/PassWrapper.cpp + $(RUSTC) --target wasm32-unknown-unknown --print target-cpus=$(TMPDIR)/target-cpus.txt -Z unstable-options + $(CGREP) generic < $(TMPDIR)/target-cpus.txt + ifdef IS_WINDOWS default: $(RUSTC) --print cfg | $(CGREP) windows diff --git a/tests/run-make/print-native-static-libs/Makefile b/tests/run-make/print-native-static-libs/Makefile index 98e72d769..a16c8b0f2 100644 --- a/tests/run-make/print-native-static-libs/Makefile +++ b/tests/run-make/print-native-static-libs/Makefile @@ -5,7 +5,7 @@ include ../tools.mk all: $(RUSTC) --crate-type rlib -lbar_cli bar.rs - $(RUSTC) foo.rs -lfoo_cli --crate-type staticlib --print native-static-libs 2>&1 \ + $(RUSTC) foo.rs -lfoo_cli -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 @@ -13,3 +13,7 @@ all: 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" + + # make sure that foo_cli and glib-2.0 are not consecutively present + cat $(TMPDIR)/libs.txt | grep -Fv "foo_cli -lfoo_cli" + cat $(TMPDIR)/libs.txt | grep -Fv "glib-2.0 -lglib-2.0" diff --git a/tests/run-make/print-native-static-libs/bar.rs b/tests/run-make/print-native-static-libs/bar.rs index a563bbc2a..cd9c1c453 100644 --- a/tests/run-make/print-native-static-libs/bar.rs +++ b/tests/run-make/print-native-static-libs/bar.rs @@ -3,6 +3,7 @@ pub extern "C" fn my_bar_add(left: i32, right: i32) -> i32 { // Obviously makes no sense but... unsafe { g_free(std::ptr::null_mut()); + g_free2(std::ptr::null_mut()); } left + right } @@ -11,3 +12,8 @@ pub extern "C" fn my_bar_add(left: i32, right: i32) -> i32 { extern "C" { fn g_free(p: *mut ()); } + +#[link(name = "glib-2.0")] +extern "C" { + fn g_free2(p: *mut ()); +} diff --git a/tests/run-make/rmeta-preferred/Makefile b/tests/run-make/rmeta-preferred/Makefile new file mode 100644 index 000000000..3bf12cced --- /dev/null +++ b/tests/run-make/rmeta-preferred/Makefile @@ -0,0 +1,16 @@ +# ignore-cross-compile +include ../tools.mk + +# Test that using rlibs and rmeta dep crates work together. Specifically, that +# there can be both an rmeta and an rlib file and rustc will prefer the rmeta +# file. +# +# This behavior is simply making sure this doesn't accidentally change; in this +# case we want to make sure that the rlib isn't being used as that would cause +# bugs in -Zbinary-dep-depinfo (see #68298). + +all: + $(RUSTC) rmeta_aux.rs --crate-type=rlib --emit link,metadata + $(RUSTC) lib.rs --crate-type=rlib --emit dep-info -Zbinary-dep-depinfo + $(CGREP) "librmeta_aux.rmeta" < $(TMPDIR)/lib.d + $(CGREP) -v "librmeta_aux.rlib" < $(TMPDIR)/lib.d diff --git a/tests/run-make/rmeta-preferred/lib.rs b/tests/run-make/rmeta-preferred/lib.rs new file mode 100644 index 000000000..d0b81a062 --- /dev/null +++ b/tests/run-make/rmeta-preferred/lib.rs @@ -0,0 +1,14 @@ +// Test that using rlibs and rmeta dep crates work together. Specifically, that +// there can be both an rmeta and an rlib file and rustc will prefer the rmeta +// file. +// +// This behavior is simply making sure this doesn't accidentally change; in this +// case we want to make sure that the rlib isn't being used as that would cause +// bugs in -Zbinary-dep-depinfo (see #68298). + +extern crate rmeta_aux; +use rmeta_aux::Foo; + +pub fn foo() { + let _ = Foo { field: 42 }; +} diff --git a/tests/run-make/rmeta-preferred/rmeta_aux.rs b/tests/run-make/rmeta-preferred/rmeta_aux.rs new file mode 100644 index 000000000..3f7a12b50 --- /dev/null +++ b/tests/run-make/rmeta-preferred/rmeta_aux.rs @@ -0,0 +1,3 @@ +pub struct Foo { + pub field: i32, +} diff --git a/tests/run-make/short-ice/Makefile b/tests/run-make/short-ice/Makefile index 4f33d5902..23006fc09 100644 --- a/tests/run-make/short-ice/Makefile +++ b/tests/run-make/short-ice/Makefile @@ -3,6 +3,7 @@ include ../tools.mk # ignore-windows export RUSTC := $(RUSTC_ORIGINAL) +export LD_LIBRARY_PATH := $(HOST_RPATH_DIR) export TMPDIR := $(TMPDIR) all: diff --git a/tests/run-make/short-ice/check.sh b/tests/run-make/short-ice/check.sh index 96cd8fe86..56babd214 100644 --- a/tests/run-make/short-ice/check.sh +++ b/tests/run-make/short-ice/check.sh @@ -1,5 +1,5 @@ #!/bin/sh - +export RUSTC_ICE=0 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 @@ -28,8 +28,8 @@ echo "rustc_query_count_full: $rustc_query_count_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 + [ $(($rustc_query_count + 5)) -lt $rustc_query_count_full ] && + [ $rustc_query_count_full -gt 5 ]; then exit 0 else exit 1 diff --git a/tests/run-make/tools.mk b/tests/run-make/tools.mk index ea06b620c..6121a91e9 100644 --- a/tests/run-make/tools.mk +++ b/tests/run-make/tools.mk @@ -8,7 +8,7 @@ TARGET_RPATH_ENV = \ RUSTC_ORIGINAL := $(RUSTC) BARE_RUSTC := $(HOST_RPATH_ENV) '$(RUSTC)' BARE_RUSTDOC := $(HOST_RPATH_ENV) '$(RUSTDOC)' -RUSTC := $(BARE_RUSTC) --out-dir $(TMPDIR) -L $(TMPDIR) $(RUSTFLAGS) +RUSTC := $(BARE_RUSTC) --out-dir $(TMPDIR) -L $(TMPDIR) $(RUSTFLAGS) -Ainternal_features RUSTDOC := $(BARE_RUSTDOC) -L $(TARGET_RPATH_DIR) ifdef RUSTC_LINKER RUSTC := $(RUSTC) -Clinker='$(RUSTC_LINKER)' diff --git a/tests/run-make/unknown-mod-stdin/Makefile b/tests/run-make/unknown-mod-stdin/Makefile new file mode 100644 index 000000000..c19317653 --- /dev/null +++ b/tests/run-make/unknown-mod-stdin/Makefile @@ -0,0 +1,15 @@ +# ignore-windows + +include ../tools.mk + +all: + echo 'mod unknown;' | $(RUSTC) --crate-type rlib - >$(TMPDIR)/unknown-mod.stdout 2>$(TMPDIR)/unknown-mod.stderr || echo "failed successfully" + +# Bless like this: RUSTC_BLESS_TEST=1 ./x.py test tests/run-make/unknown-mod-stdin +ifdef RUSTC_BLESS_TEST + cp "$(TMPDIR)"/unknown-mod.stdout unknown-mod.stdout + cp "$(TMPDIR)"/unknown-mod.stderr unknown-mod.stderr +else + $(DIFF) unknown-mod.stdout "$(TMPDIR)"/unknown-mod.stdout + $(DIFF) unknown-mod.stderr "$(TMPDIR)"/unknown-mod.stderr +endif diff --git a/tests/run-make/unknown-mod-stdin/unknown-mod.stderr b/tests/run-make/unknown-mod-stdin/unknown-mod.stderr new file mode 100644 index 000000000..d7258fe4f --- /dev/null +++ b/tests/run-make/unknown-mod-stdin/unknown-mod.stderr @@ -0,0 +1,11 @@ +error[E0583]: file not found for module `unknown` + --> <anon>:1:1 + | +1 | mod unknown; + | ^^^^^^^^^^^^ + | + = help: to create the module `unknown`, create file "unknown.rs" or "unknown/mod.rs" + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0583`. diff --git a/tests/run-make/unknown-mod-stdin/unknown-mod.stdout b/tests/run-make/unknown-mod-stdin/unknown-mod.stdout new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/run-make/unknown-mod-stdin/unknown-mod.stdout diff --git a/tests/run-make/wasm-exceptions-nostd/Makefile b/tests/run-make/wasm-exceptions-nostd/Makefile new file mode 100644 index 000000000..34755ec14 --- /dev/null +++ b/tests/run-make/wasm-exceptions-nostd/Makefile @@ -0,0 +1,12 @@ +include ../tools.mk + +# only-wasm32-bare + +# Add a few command line args to make exceptions work +RUSTC := $(RUSTC) -C llvm-args=-wasm-enable-eh +RUSTC := $(RUSTC) -C target-feature=+exception-handling +RUSTC := $(RUSTC) -C panic=unwind + +all: + $(RUSTC) src/lib.rs --target wasm32-unknown-unknown + $(NODE) verify.mjs $(TMPDIR)/lib.wasm diff --git a/tests/run-make/wasm-exceptions-nostd/src/arena_alloc.rs b/tests/run-make/wasm-exceptions-nostd/src/arena_alloc.rs new file mode 100644 index 000000000..572d25330 --- /dev/null +++ b/tests/run-make/wasm-exceptions-nostd/src/arena_alloc.rs @@ -0,0 +1,67 @@ +use core::alloc::{GlobalAlloc, Layout}; +use core::cell::UnsafeCell; + +#[global_allocator] +static ALLOCATOR: ArenaAllocator = ArenaAllocator::new(); + +/// Very simple allocator which never deallocates memory +/// +/// Based on the example from +/// https://doc.rust-lang.org/stable/std/alloc/trait.GlobalAlloc.html +pub struct ArenaAllocator { + arena: UnsafeCell<Arena>, +} + +impl ArenaAllocator { + pub const fn new() -> Self { + Self { + arena: UnsafeCell::new(Arena::new()), + } + } +} + +/// Safe because we are singlethreaded +unsafe impl Sync for ArenaAllocator {} + +unsafe impl GlobalAlloc for ArenaAllocator { + unsafe fn alloc(&self, layout: Layout) -> *mut u8 { + let arena = &mut *self.arena.get(); + arena.alloc(layout) + } + + unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {} +} + +const ARENA_SIZE: usize = 64 * 1024; // more than enough + +#[repr(C, align(4096))] +struct Arena { + buf: [u8; ARENA_SIZE], // aligned at 4096 + allocated: usize, +} + +impl Arena { + pub const fn new() -> Self { + Self { + buf: [0x55; ARENA_SIZE], + allocated: 0, + } + } + + pub unsafe fn alloc(&mut self, layout: Layout) -> *mut u8 { + if layout.align() > 4096 || layout.size() > ARENA_SIZE { + return core::ptr::null_mut(); + } + + let align_minus_one = layout.align() - 1; + let start = (self.allocated + align_minus_one) & !align_minus_one; // round up + let new_cursor = start + layout.size(); + + if new_cursor >= ARENA_SIZE { + return core::ptr::null_mut(); + } + + self.allocated = new_cursor; + self.buf.as_mut_ptr().add(start) + } +} diff --git a/tests/run-make/wasm-exceptions-nostd/src/lib.rs b/tests/run-make/wasm-exceptions-nostd/src/lib.rs new file mode 100644 index 000000000..7049d2fd9 --- /dev/null +++ b/tests/run-make/wasm-exceptions-nostd/src/lib.rs @@ -0,0 +1,60 @@ +#![no_std] +#![crate_type = "cdylib"] + +// Allow a few unstable features because we create a panic +// runtime for native wasm exceptions from scratch + +#![feature(core_intrinsics)] +#![feature(lang_items)] +#![feature(link_llvm_intrinsics)] +#![feature(panic_info_message)] + +extern crate alloc; + +/// This module allows us to use `Box`, `String`, ... even in no-std +mod arena_alloc; + +/// This module allows logging text, even in no-std +mod logging; + +/// This module allows exceptions, even in no-std +#[cfg(target_arch = "wasm32")] +mod panicking; + +use alloc::boxed::Box; +use alloc::string::String; + +struct LogOnDrop; + +impl Drop for LogOnDrop { + fn drop(&mut self) { + logging::log_str("Dropped"); + } +} + +#[allow(unreachable_code)] +#[allow(unconditional_panic)] +#[no_mangle] +pub extern "C" fn start() -> usize { + let data = 0x1234usize as *mut u8; // Something to recognize + + unsafe { + core::intrinsics::r#try(|data: *mut u8| { + let _log_on_drop = LogOnDrop; + + logging::log_str(&alloc::format!("`r#try` called with ptr {:?}", data)); + let x = [12]; + let _ = x[4]; // should panic + + logging::log_str("This line should not be visible! :("); + }, data, |data, exception| { + let exception = *Box::from_raw(exception as *mut String); + logging::log_str("Caught something!"); + logging::log_str(&alloc::format!(" data : {:?}", data)); + logging::log_str(&alloc::format!(" exception: {:?}", exception)); + }); + } + + logging::log_str("This program terminates correctly."); + 0 +} diff --git a/tests/run-make/wasm-exceptions-nostd/src/logging.rs b/tests/run-make/wasm-exceptions-nostd/src/logging.rs new file mode 100644 index 000000000..569d03ec8 --- /dev/null +++ b/tests/run-make/wasm-exceptions-nostd/src/logging.rs @@ -0,0 +1,9 @@ +extern "C" { + fn __log_utf8(ptr: *const u8, size: usize); +} + +pub fn log_str(text: &str) { + unsafe { + __log_utf8(text.as_ptr(), text.len()); + } +} diff --git a/tests/run-make/wasm-exceptions-nostd/src/panicking.rs b/tests/run-make/wasm-exceptions-nostd/src/panicking.rs new file mode 100644 index 000000000..4a8923fd4 --- /dev/null +++ b/tests/run-make/wasm-exceptions-nostd/src/panicking.rs @@ -0,0 +1,29 @@ +#[lang = "eh_personality"] +fn eh_personality() {} + +mod internal { + extern "C" { + #[link_name = "llvm.wasm.throw"] + pub fn wasm_throw(tag: i32, ptr: *mut u8) -> !; + } +} + +unsafe fn wasm_throw(ptr: *mut u8) -> ! { + internal::wasm_throw(0, ptr); +} + +#[panic_handler] +fn panic_handler(info: &core::panic::PanicInfo<'_>) -> ! { + use alloc::boxed::Box; + use alloc::string::ToString; + + let msg = info + .message() + .map(|msg| msg.to_string()) + .unwrap_or("(no message)".to_string()); + let exception = Box::new(msg.to_string()); + unsafe { + let exception_raw = Box::into_raw(exception); + wasm_throw(exception_raw as *mut u8); + } +} diff --git a/tests/run-make/wasm-exceptions-nostd/verify.mjs b/tests/run-make/wasm-exceptions-nostd/verify.mjs new file mode 100644 index 000000000..e6c44d89d --- /dev/null +++ b/tests/run-make/wasm-exceptions-nostd/verify.mjs @@ -0,0 +1,75 @@ +import fs from 'fs'; + +const dec = new TextDecoder("utf-8"); + +if (process.argv.length != 3) { + console.log("Usage: node verify.mjs <wasm-file>"); + process.exit(0); +} + +const wasmfile = process.argv[2]; +if (!fs.existsSync(wasmfile)) { + console.log("Error: File not found:", wasmfile); + process.exit(1); +} + +const wasmBuffer = fs.readFileSync(wasmfile); + +async function main() { + + let memory = new ArrayBuffer(0) // will be changed after instantiate + + const captured_output = []; + + const imports = { + env: { + __log_utf8: (ptr, size) => { + const str = dec.decode(new DataView(memory, ptr, size)); + captured_output.push(str); + console.log(str); + } + } + }; + + const wasmModule = await WebAssembly.instantiate(wasmBuffer, imports); + memory = wasmModule.instance.exports.memory.buffer; + + const start = wasmModule.instance.exports.start; + const return_code = start(); + + console.log("Return-Code:", return_code); + + if (return_code !== 0) { + console.error("Expected return code 0"); + process.exit(return_code); + } + + const expected_output = [ + '`r#try` called with ptr 0x1234', + 'Dropped', + 'Caught something!', + ' data : 0x1234', + ' exception: "index out of bounds: the len is 1 but the index is 4"', + 'This program terminates correctly.', + ]; + + assert_equal(captured_output, expected_output); +} + +function assert_equal(captured_output, expected_output) { + if (captured_output.length != expected_output.length) { + console.error("Unexpected number of output lines. Got", captured_output.length, "but expected", expected_output.length); + process.exit(1); // exit with error + } + + for (let idx = 0; idx < expected_output.length; ++idx) { + if (captured_output[idx] !== expected_output[idx]) { + console.error("Unexpected output"); + console.error("[got] ", captured_output[idx]); + console.error("[expected]", expected_output[idx]); + process.exit(2); // exit with error + } + } +} + +await main();
\ No newline at end of file |