Skip to content
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

Emit an error if -Zdwarf-version=1 is requested #136746

Merged
merged 1 commit into from
Feb 10, 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
3 changes: 2 additions & 1 deletion compiler/rustc_session/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ session_unstable_virtual_function_elimination = `-Zvirtual-function-elimination`
session_unsupported_crate_type_for_target =
dropping unsupported crate type `{$crate_type}` for target `{$target_triple}`

session_unsupported_dwarf_version = requested DWARF version {$dwarf_version} is greater than 5
session_unsupported_dwarf_version = requested DWARF version {$dwarf_version} is not supported
session_unsupported_dwarf_version_help = supported DWARF versions are 2, 3, 4 and 5

session_unsupported_reg_struct_return_arch = `-Zreg-struct-return` is only supported on x86
session_unsupported_regparm = `-Zregparm={$regparm}` is unsupported (valid values 0-3)
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_session/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ pub(crate) struct UnstableVirtualFunctionElimination;

#[derive(Diagnostic)]
#[diag(session_unsupported_dwarf_version)]
#[help(session_unsupported_dwarf_version_help)]
pub(crate) struct UnsupportedDwarfVersion {
pub(crate) dwarf_version: u32,
}
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1251,7 +1251,8 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
}

if let Some(dwarf_version) = sess.opts.unstable_opts.dwarf_version {
if dwarf_version > 5 {
// DWARF 1 is not supported by LLVM and DWARF 6 is not yet finalized.
if dwarf_version < 2 || dwarf_version > 5 {
sess.dcx().emit_err(errors::UnsupportedDwarfVersion { dwarf_version });
}
}
Expand Down
6 changes: 6 additions & 0 deletions tests/ui/debuginfo/dwarf-versions.one.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
error: requested DWARF version 1 is not supported
|
= help: supported DWARF versions are 2, 3, 4 and 5

error: aborting due to 1 previous error

38 changes: 38 additions & 0 deletions tests/ui/debuginfo/dwarf-versions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// This test verifies the expected behavior of various options passed to
// `-Zdwarf-version`: 2 - 5 (valid) with all other options being invalid.

//@ revisions: zero one two three four five six

//@[zero] compile-flags: -Zdwarf-version=0
//@[zero] error-pattern: requested DWARF version 0 is not supported

//@[one] compile-flags: -Zdwarf-version=1
wesleywiser marked this conversation as resolved.
Show resolved Hide resolved
//@[one] error-pattern: requested DWARF version 1 is not supported

//@[two] compile-flags: -Zdwarf-version=2
//@[two] check-pass

//@[three] compile-flags: -Zdwarf-version=3
//@[three] check-pass

//@[four] compile-flags: -Zdwarf-version=4
//@[four] check-pass

//@[five] compile-flags: -Zdwarf-version=5
//@[five] check-pass

//@[six] compile-flags: -Zdwarf-version=6
wesleywiser marked this conversation as resolved.
Show resolved Hide resolved
//@[six] error-pattern: requested DWARF version 6 is not supported

//@ compile-flags: -g --target x86_64-unknown-linux-gnu --crate-type cdylib
//@ needs-llvm-components: x86

#![feature(no_core, lang_items)]

#![no_core]
#![no_std]

#[lang = "sized"]
pub trait Sized {}

pub fn foo() {}
6 changes: 6 additions & 0 deletions tests/ui/debuginfo/dwarf-versions.six.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
error: requested DWARF version 6 is not supported
|
= help: supported DWARF versions are 2, 3, 4 and 5

error: aborting due to 1 previous error

6 changes: 6 additions & 0 deletions tests/ui/debuginfo/dwarf-versions.zero.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
error: requested DWARF version 0 is not supported
|
= help: supported DWARF versions are 2, 3, 4 and 5

error: aborting due to 1 previous error

Loading