about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/run-make/pdb-buildinfo-cl-cmd/rmake.rs20
-rw-r--r--tests/run-make/pgo-indirect-call-promotion/Makefile23
-rw-r--r--tests/run-make/pgo-indirect-call-promotion/rmake.rs33
3 files changed, 45 insertions, 31 deletions
diff --git a/tests/run-make/pdb-buildinfo-cl-cmd/rmake.rs b/tests/run-make/pdb-buildinfo-cl-cmd/rmake.rs
index 347b3d67a25..2ab9057b24c 100644
--- a/tests/run-make/pdb-buildinfo-cl-cmd/rmake.rs
+++ b/tests/run-make/pdb-buildinfo-cl-cmd/rmake.rs
@@ -7,7 +7,7 @@
 //@ only-windows-msvc
 // Reason: pdb files are unique to this architecture
 
-use run_make_support::{assert_contains, env_var, rfs, rustc};
+use run_make_support::{assert_contains, bstr, env_var, rfs, rustc};
 
 fn main() {
     rustc()
@@ -17,19 +17,23 @@ fn main() {
         .crate_type("bin")
         .metadata("dc9ef878b0a48666")
         .run();
-    assert_contains(rfs::read_to_string("my_crate_name.pdb"), env_var("RUSTC_ORIGINAL"));
-    let strings = [
+    let tests = [
+        &env_var("RUSTC"),
         r#""main.rs""#,
         r#""-g""#,
         r#""--crate-name""#,
         r#""my_crate_name""#,
         r#""--crate-type""#,
         r#""bin""#,
-        r#""-C""#,
-        r#""metadata=dc9ef878b0a48666""#,
-        r#""--out-dir""#,
+        r#""-Cmetadata=dc9ef878b0a48666""#,
     ];
-    for string in strings {
-        assert_contains(rfs::read_to_string("my_crate_name.pdb"), string);
+    for test in tests {
+        assert_pdb_contains(test);
     }
 }
+
+fn assert_pdb_contains(needle: &str) {
+    let needle = needle.as_bytes();
+    use bstr::ByteSlice;
+    assert!(&rfs::read("my_crate_name.pdb").find(needle).is_some());
+}
diff --git a/tests/run-make/pgo-indirect-call-promotion/Makefile b/tests/run-make/pgo-indirect-call-promotion/Makefile
deleted file mode 100644
index 8d1e69c4aba..00000000000
--- a/tests/run-make/pgo-indirect-call-promotion/Makefile
+++ /dev/null
@@ -1,23 +0,0 @@
-# needs-profiler-support
-# ignore-cross-compile
-
-include ../tools.mk
-
-all:
-	# We don't compile `opaque` with either optimizations or instrumentation.
-	# We don't compile `opaque` with either optimizations or instrumentation.
-	$(RUSTC) $(COMMON_FLAGS) opaque.rs
-	# Compile the test program with instrumentation
-	mkdir -p "$(TMPDIR)"/prof_data_dir
-	$(RUSTC) $(COMMON_FLAGS) interesting.rs \
-		-Cprofile-generate="$(TMPDIR)"/prof_data_dir -O -Ccodegen-units=1
-	$(RUSTC) $(COMMON_FLAGS) main.rs -Cprofile-generate="$(TMPDIR)"/prof_data_dir -O
-	# The argument below generates to the expected branch weights
-	$(call RUN,main) || exit 1
-	"$(LLVM_BIN_DIR)"/llvm-profdata merge \
-		-o "$(TMPDIR)"/prof_data_dir/merged.profdata \
-		"$(TMPDIR)"/prof_data_dir
-	$(RUSTC) $(COMMON_FLAGS) interesting.rs \
-		-Cprofile-use="$(TMPDIR)"/prof_data_dir/merged.profdata -O \
-		-Ccodegen-units=1 --emit=llvm-ir
-	cat "$(TMPDIR)"/interesting.ll | "$(LLVM_FILECHECK)" filecheck-patterns.txt
diff --git a/tests/run-make/pgo-indirect-call-promotion/rmake.rs b/tests/run-make/pgo-indirect-call-promotion/rmake.rs
new file mode 100644
index 00000000000..d0ccfd8a4d7
--- /dev/null
+++ b/tests/run-make/pgo-indirect-call-promotion/rmake.rs
@@ -0,0 +1,33 @@
+// This test checks that indirect call promotion is performed. The test
+// programs calls the same function a thousand times through a function pointer.
+// Only PGO data provides the information that it actually always is the same
+// function. We verify that the indirect call promotion pass inserts a check
+// whether it can make a direct call instead of the indirect call.
+// See https://github.com/rust-lang/rust/pull/66631
+
+//@ needs-profiler-support
+// Reason: llvm_profdata is used
+//@ ignore-cross-compile
+// Reason: the compiled binary is executed
+
+use run_make_support::{llvm_filecheck, llvm_profdata, rfs, run, rustc};
+
+fn main() {
+    // We don't compile `opaque` with either optimizations or instrumentation.
+    rustc().input("opaque.rs").run();
+    // Compile the test program with instrumentation
+    rfs::create_dir("prof_data_dir");
+    rustc().input("interesting.rs").profile_generate("prof_data_dir").opt().codegen_units(1).run();
+    rustc().input("main.rs").profile_generate("prof_data_dir").opt().run();
+    // The argument below generates to the expected branch weights
+    run("main");
+    llvm_profdata().merge().output("prof_data_dir/merged.profdata").input("prof_data_dir").run();
+    rustc()
+        .input("interesting.rs")
+        .profile_use("prof_data_dir/merged.profdata")
+        .opt()
+        .codegen_units(1)
+        .emit("llvm-ir")
+        .run();
+    llvm_filecheck().patterns("filecheck-patterns.txt").stdin(rfs::read("interesting.ll")).run();
+}