Skip to content

compiletest: avoid invoking rustc with absolute paths. #330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 2 additions & 21 deletions crates/rustc_codegen_spirv/src/codegen_cx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::maybe_pqp_cg_ssa as rustc_codegen_ssa;

use itertools::Itertools as _;
use rspirv::dr::{Module, Operand};
use rspirv::spirv::{Decoration, LinkageType, Op, Word};
use rspirv::spirv::{Decoration, LinkageType, Word};
use rustc_abi::{AddressSpace, HasDataLayout, TargetDataLayout};
use rustc_ast::ast::{InlineAsmOptions, InlineAsmTemplatePiece};
use rustc_codegen_ssa::mir::debuginfo::{FunctionDebugContext, VariableKind};
Expand All @@ -37,7 +37,7 @@ use rustc_target::spec::{HasTargetSpec, Target, TargetTuple};
use std::cell::RefCell;
use std::collections::BTreeSet;
use std::iter::once;
use std::path::{Path, PathBuf};
use std::path::PathBuf;
use std::rc::Rc;
use std::str::FromStr;

Expand Down Expand Up @@ -767,25 +767,6 @@ impl CodegenArgs {

if self.disassemble_globals {
for inst in module.global_inst_iter() {
// HACK: On Windows, paths are printed like `OpString "D:\\dir\\blah"`.
// Unfortunately, compiletest will only normalize `D:\dir\blah` to `$DIR/blah` -
// one backslash, not two. So, when disassembling for compiletest, check if the
// argument to OpString can be parsed as an absolute path, and if it is, replace it
// with just the filename component of the path.
if inst.class.opcode == Op::String {
let path = Path::new(inst.operands[0].unwrap_literal_string());
if path.is_absolute()
&& let Some(file_name) = path.file_name()
{
let mut inst = inst.clone();
inst.operands[0] = Operand::LiteralString(format!(
"$OPSTRING_FILENAME/{}",
file_name.to_string_lossy(),
));
eprintln!("{}", inst.disassemble());
continue;
}
}
eprintln!("{}", inst.disassemble());
}
}
Expand Down
7 changes: 7 additions & 0 deletions tests/compiletests/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ fn main() {
let deps_target_dir = original_target_dir.join("compiletest-deps");
let compiletest_build_dir = original_target_dir.join("compiletest-results");

// HACK(eddyb) force `compiletest` to pass `ui/...` relative paths to `rustc`,
// which should always end up being the same regardless of the path that the
// Rust-GPU repo is checked out at (among other things, this avoids harcoded
// `compiletest` limits being hit by e.g. users with slightly longer paths).
std::env::set_current_dir(tests_dir).unwrap();
let tests_dir = PathBuf::from("");

// Pull in rustc_codegen_spirv as a dynamic library in the same way
// spirv-builder does.
let codegen_backend_path = find_rustc_codegen_spirv();
Expand Down
3 changes: 3 additions & 0 deletions tests/compiletests/ui/dis/asm_op_decorate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
// normalize-stderr-test "OpExtension .SPV_KHR_vulkan_memory_model.\n" -> ""
// normalize-stderr-test "OpMemoryModel Logical Vulkan" -> "OpMemoryModel Logical Simple"

// HACK(eddyb) `compiletest` handles `ui\dis\`, but not `ui\\dis\\`, on Windows.
// normalize-stderr-test "ui/dis/" -> "$$DIR/"

// FIXME(eddyb) this should use revisions to track both the `vulkan1.2` output
// and the pre-`vulkan1.2` output, but per-revisions `{only,ignore}-*` directives
// are not supported in `compiletest-rs`.
Expand Down
2 changes: 1 addition & 1 deletion tests/compiletests/ui/dis/asm_op_decorate.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ OpExtension "SPV_EXT_descriptor_indexing"
OpMemoryModel Logical Simple
OpEntryPoint Fragment %1 "main"
OpExecutionMode %1 OriginUpperLeft
%2 = OpString "$OPSTRING_FILENAME/asm_op_decorate.rs"
%2 = OpString "$DIR/asm_op_decorate.rs"
OpName %3 "asm_op_decorate::main"
OpName %4 "asm_op_decorate::add_decorate"
OpDecorate %5 Binding 0
Expand Down
3 changes: 3 additions & 0 deletions tests/compiletests/ui/dis/const-float-cast-optimized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
// normalize-stderr-test "OpExtension .SPV_KHR_vulkan_memory_model.\n" -> ""
// normalize-stderr-test "OpMemoryModel Logical Vulkan" -> "OpMemoryModel Logical Simple"

// HACK(eddyb) `compiletest` handles `ui\dis\`, but not `ui\\dis\\`, on Windows.
// normalize-stderr-test "ui/dis/" -> "$$DIR/"

use spirv_std::spirv;

#[spirv(fragment)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ OpCapability Float64
OpMemoryModel Logical Simple
OpEntryPoint Fragment %1 "main" %2
OpExecutionMode %1 OriginUpperLeft
%3 = OpString "$OPSTRING_FILENAME/const-float-cast-optimized.rs"
%3 = OpString "$DIR/const-float-cast-optimized.rs"
OpName %2 "output"
OpDecorate %2 Location 0
%4 = OpTypeFloat 64
Expand Down
3 changes: 3 additions & 0 deletions tests/compiletests/ui/dis/const-float-cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
// normalize-stderr-test "OpExtension .SPV_KHR_vulkan_memory_model.\n" -> ""
// normalize-stderr-test "OpMemoryModel Logical Vulkan" -> "OpMemoryModel Logical Simple"

// HACK(eddyb) `compiletest` handles `ui\dis\`, but not `ui\\dis\\`, on Windows.
// normalize-stderr-test "ui/dis/" -> "$$DIR/"

use spirv_std::spirv;

#[spirv(fragment)]
Expand Down
2 changes: 1 addition & 1 deletion tests/compiletests/ui/dis/const-float-cast.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ OpCapability Float64
OpMemoryModel Logical Simple
OpEntryPoint Fragment %1 "main" %2
OpExecutionMode %1 OriginUpperLeft
%3 = OpString "$OPSTRING_FILENAME/const-float-cast.rs"
%3 = OpString "$DIR/const-float-cast.rs"
OpName %2 "output"
OpDecorate %2 Location 0
%4 = OpTypeFloat 32
Expand Down
3 changes: 3 additions & 0 deletions tests/compiletests/ui/dis/const-from-cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
// normalize-stderr-test "OpExtension .SPV_KHR_vulkan_memory_model.\n" -> ""
// normalize-stderr-test "OpMemoryModel Logical Vulkan" -> "OpMemoryModel Logical Simple"

// HACK(eddyb) `compiletest` handles `ui\dis\`, but not `ui\\dis\\`, on Windows.
// normalize-stderr-test "ui/dis/" -> "$$DIR/"

use spirv_std::spirv;

const K: u8 = 42;
Expand Down
2 changes: 1 addition & 1 deletion tests/compiletests/ui/dis/const-from-cast.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ OpCapability Shader
OpMemoryModel Logical Simple
OpEntryPoint Fragment %1 "main" %2
OpExecutionMode %1 OriginUpperLeft
%3 = OpString "$OPSTRING_FILENAME/const-from-cast.rs"
%3 = OpString "$DIR/const-from-cast.rs"
OpName %2 "output"
OpDecorate %2 Location 0
%4 = OpTypeInt 32 0
Expand Down
3 changes: 3 additions & 0 deletions tests/compiletests/ui/dis/const-int-cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
// normalize-stderr-test "OpExtension .SPV_KHR_vulkan_memory_model.\n" -> ""
// normalize-stderr-test "OpMemoryModel Logical Vulkan" -> "OpMemoryModel Logical Simple"

// HACK(eddyb) `compiletest` handles `ui\dis\`, but not `ui\\dis\\`, on Windows.
// normalize-stderr-test "ui/dis/" -> "$$DIR/"

use spirv_std::spirv;

const K: u8 = 20;
Expand Down
2 changes: 1 addition & 1 deletion tests/compiletests/ui/dis/const-int-cast.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ OpCapability Shader
OpMemoryModel Logical Simple
OpEntryPoint Fragment %1 "main" %2
OpExecutionMode %1 OriginUpperLeft
%3 = OpString "$OPSTRING_FILENAME/const-int-cast.rs"
%3 = OpString "$DIR/const-int-cast.rs"
OpName %2 "output"
OpDecorate %2 Location 0
%4 = OpTypeInt 32 0
Expand Down
3 changes: 3 additions & 0 deletions tests/compiletests/ui/dis/const-narrowing-cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
// normalize-stderr-test "OpExtension .SPV_KHR_vulkan_memory_model.\n" -> ""
// normalize-stderr-test "OpMemoryModel Logical Vulkan" -> "OpMemoryModel Logical Simple"

// HACK(eddyb) `compiletest` handles `ui\dis\`, but not `ui\\dis\\`, on Windows.
// normalize-stderr-test "ui/dis/" -> "$$DIR/"

use spirv_std::spirv;

#[spirv(fragment)]
Expand Down
2 changes: 1 addition & 1 deletion tests/compiletests/ui/dis/const-narrowing-cast.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ OpCapability Int8
OpMemoryModel Logical Simple
OpEntryPoint Fragment %1 "main" %2
OpExecutionMode %1 OriginUpperLeft
%3 = OpString "$OPSTRING_FILENAME/const-narrowing-cast.rs"
%3 = OpString "$DIR/const-narrowing-cast.rs"
OpName %2 "output"
OpDecorate %2 Location 0
%4 = OpTypeInt 32 0
Expand Down
3 changes: 3 additions & 0 deletions tests/compiletests/ui/dis/custom_entry_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
// normalize-stderr-test "OpExtension .SPV_KHR_vulkan_memory_model.\n" -> ""
// normalize-stderr-test "OpMemoryModel Logical Vulkan" -> "OpMemoryModel Logical Simple"

// HACK(eddyb) `compiletest` handles `ui\dis\`, but not `ui\\dis\\`, on Windows.
// normalize-stderr-test "ui/dis/" -> "$$DIR/"

use spirv_std::spirv;

#[spirv(fragment(entry_point_name = "hello_world"))]
Expand Down
2 changes: 1 addition & 1 deletion tests/compiletests/ui/dis/custom_entry_point.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ OpCapability Shader
OpMemoryModel Logical Simple
OpEntryPoint Fragment %1 "hello_world"
OpExecutionMode %1 OriginUpperLeft
%2 = OpString "$OPSTRING_FILENAME/custom_entry_point.rs"
%2 = OpString "$DIR/custom_entry_point.rs"
OpName %3 "custom_entry_point::main"
%4 = OpTypeVoid
%5 = OpTypeFunction %4
6 changes: 6 additions & 0 deletions tests/compiletests/ui/dis/generic-fn-op-name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
// normalize-stderr-test "OpSource .*\n" -> ""
// normalize-stderr-test "OpExtension .SPV_KHR_vulkan_memory_model.\n" -> ""
// normalize-stderr-test "OpMemoryModel Logical Vulkan" -> "OpMemoryModel Logical Simple"

// HACK(eddyb) `compiletest` handles `ui\dis\`, but not `ui\\dis\\`, on Windows.
// normalize-stderr-test "ui/dis/" -> "$$DIR/"

// HACK(eddyb) this comment prevents `rustfmt` from deleting the above empty line.
//
#![feature(adt_const_params)]
#![allow(incomplete_features)]

Expand Down
2 changes: 1 addition & 1 deletion tests/compiletests/ui/dis/generic-fn-op-name.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ OpCapability Shader
OpMemoryModel Logical Simple
OpEntryPoint Fragment %1 "main"
OpExecutionMode %1 OriginUpperLeft
%2 = OpString "$OPSTRING_FILENAME/generic-fn-op-name.rs"
%2 = OpString "$DIR/generic-fn-op-name.rs"
OpName %3 "generic_fn_op_name::main"
OpName %4 "generic_fn_op_name::generic::<f32, {generic_fn_op_name::Dimensionality::TwoD}>"
%5 = OpTypeVoid
Expand Down
3 changes: 3 additions & 0 deletions tests/compiletests/ui/dis/issue-723-output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
// normalize-stderr-test "OpExtension .SPV_KHR_vulkan_memory_model.\n" -> ""
// normalize-stderr-test "OpMemoryModel Logical Vulkan" -> "OpMemoryModel Logical Simple"

// HACK(eddyb) `compiletest` handles `ui\dis\`, but not `ui\\dis\\`, on Windows.
// normalize-stderr-test "ui/dis/" -> "$$DIR/"

use spirv_std::spirv;

#[spirv(fragment)]
Expand Down
2 changes: 1 addition & 1 deletion tests/compiletests/ui/dis/issue-723-output.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ OpCapability Shader
OpMemoryModel Logical Simple
OpEntryPoint Fragment %1 "main" %2
OpExecutionMode %1 OriginUpperLeft
%3 = OpString "$OPSTRING_FILENAME/issue-723-output.rs"
%3 = OpString "$DIR/issue-723-output.rs"
OpName %4 "issue_723_output::main"
OpDecorate %2 Location 0
%5 = OpTypeFloat 32
Expand Down
3 changes: 3 additions & 0 deletions tests/compiletests/ui/dis/non-writable-storage_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
// normalize-stderr-test "OpExtension .SPV_KHR_vulkan_memory_model.\n" -> ""
// normalize-stderr-test "OpMemoryModel Logical Vulkan" -> "OpMemoryModel Logical Simple"

// HACK(eddyb) `compiletest` handles `ui\dis\`, but not `ui\\dis\\`, on Windows.
// normalize-stderr-test "ui/dis/" -> "$$DIR/"

// FIXME(eddyb) this should use revisions to track both the `vulkan1.2` output
// and the pre-`vulkan1.2` output, but per-revisions `{only,ignore}-*` directives
// are not supported in `compiletest-rs`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ OpCapability Shader
OpMemoryModel Logical Simple
OpEntryPoint Fragment %1 "main"
OpExecutionMode %1 OriginUpperLeft
%2 = OpString "$OPSTRING_FILENAME/non-writable-storage_buffer.rs"
%2 = OpString "$DIR/non-writable-storage_buffer.rs"
OpName %3 "buf_imm"
OpName %4 "buf_mut"
OpName %5 "buf_interior_mut"
Expand Down
4 changes: 3 additions & 1 deletion tests/compiletests/ui/dis/panic_builtin_bounds_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
// normalize-stderr-test "OpSource .*\n" -> ""
// normalize-stderr-test "OpExtension .SPV_KHR_vulkan_memory_model.\n" -> ""
// normalize-stderr-test "OpMemoryModel Logical Vulkan" -> "OpMemoryModel Logical Simple"
// normalize-stderr-test "\S:\S*/panic_builtin_bounds_check.rs" -> "$$DIR/panic_builtin_bounds_check.rs"
// FIXME(eddyb) handle this one in the test runner.
// normalize-stderr-test "\S*/lib/rustlib/" -> "$$SYSROOT/lib/rustlib/"

// HACK(eddyb) `compiletest` handles `ui\dis\`, but not `ui\\dis\\`, on Windows.
// normalize-stderr-test "ui/dis/" -> "$$DIR/"

use spirv_std::spirv;

fn array_bounds_check(x: [u32; 4], i: usize) -> u32 {
Expand Down
8 changes: 4 additions & 4 deletions tests/compiletests/ui/dis/panic_builtin_bounds_check.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ OpDecorate %6 ArrayStride 4
%18 = OpTypePointer Function %9
%2 = OpFunction %7 None %8
%19 = OpLabel
OpLine %5 30 4
OpLine %5 32 4
%20 = OpVariable %11 Function
OpLine %5 30 23
OpLine %5 32 23
%21 = OpCompositeConstruct %6 %12 %13 %14 %15
OpLine %5 25 4
OpLine %5 27 4
OpStore %20 %21
%22 = OpULessThan %16 %17 %10
OpNoLine
Expand All @@ -41,7 +41,7 @@ OpLine %4 280 4
OpNoLine
OpReturn
%23 = OpLabel
OpLine %5 25 4
OpLine %5 27 4
%27 = OpIAdd %9 %12 %17
%28 = OpInBoundsAccessChain %18 %20 %27
%29 = OpLoad %9 %28
Expand Down
4 changes: 3 additions & 1 deletion tests/compiletests/ui/dis/panic_sequential_many.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
// normalize-stderr-test "OpSource .*\n" -> ""
// normalize-stderr-test "OpExtension .SPV_KHR_vulkan_memory_model.\n" -> ""
// normalize-stderr-test "OpMemoryModel Logical Vulkan" -> "OpMemoryModel Logical Simple"
// normalize-stderr-test "\S:\S*/panic_sequential_many.rs" -> "$$DIR/panic_sequential_many.rs"
// FIXME(eddyb) handle this one in the test runner.
// normalize-stderr-test "\S*/lib/rustlib/" -> "$$SYSROOT/lib/rustlib/"

// HACK(eddyb) `compiletest` handles `ui\dis\`, but not `ui\\dis\\`, on Windows.
// normalize-stderr-test "ui/dis/" -> "$$DIR/"

use spirv_std::spirv;

#[spirv(fragment)]
Expand Down
Loading