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

Compiling with -C debuginfo=2 reduces warnings unexpectedly #48900

Closed
jyn514 opened this issue Mar 10, 2018 · 9 comments
Closed

Compiling with -C debuginfo=2 reduces warnings unexpectedly #48900

jyn514 opened this issue Mar 10, 2018 · 9 comments
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jyn514
Copy link
Member

jyn514 commented Mar 10, 2018

Passing -C debuginfo=2 to rustc gives fewer warnings than debuginfo={0,1}. I expected to see the same output regardless of debug symbols.

Example

 % rustc src/main.rs -C debuginfo=1
warning: this expression will panic at run-time
 --> src/main.rs:4:19
  |
4 |     let element = a[index];
  |                   ^^^^^^^^ index out of bounds: the len is 3 but the index is 10
 % rustc src/main.rs -C debuginfo=2
 % rustc src/main.rs               
warning: this expression will panic at run-time
 --> src/main.rs:4:19
  |
4 |     let element = a[index];
  |                   ^^^^^^^^ index out of bounds: the len is 3 but the index is 10

Version

% rustc --version --verbose
rustc 1.24.1 (d3ae9a9e0 2018-02-27)
binary: rustc
commit-hash: d3ae9a9e08edf12de0ed82af57ba2a56c26496ea
commit-date: 2018-02-27
host: x86_64-unknown-linux-gnu
release: 1.24.1
LLVM version: 4.0
@kennytm kennytm added A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-const-fn C-bug Category: This is a bug. labels Mar 10, 2018
@jyn514
Copy link
Member Author

jyn514 commented Mar 10, 2018

By the way, this must have existed for quite some time, because the second version of the Book does something similar without a warning from rustc.

@varkor
Copy link
Member

varkor commented Mar 10, 2018

I can't reproduce this on 1.26.0 — are you able to check it still occurs on nightly?

@jyn514
Copy link
Member Author

jyn514 commented Mar 10, 2018

Definitely present on 1.26.0.

 % rustup show
Default host: x86_64-unknown-linux-gnu

installed toolchains
--------------------

stable-x86_64-unknown-linux-gnu
nightly-2017-12-21-x86_64-unknown-linux-gnu
nightly-x86_64-unknown-linux-gnu (default)

active toolchain
----------------

nightly-x86_64-unknown-linux-gnu (default)
rustc 1.26.0-nightly (2789b067d 2018-03-06)

 % cat src/main.rs
fn main() {
    let a = [1, 2, 3];
    let index = 10;
    let element = a[index];
    println!("element is {}", element);
}
 % rustc src/main.rs -C debuginfo=2
 % rustc src/main.rs -C debuginfo=1
warning: this expression will panic at run-time
 --> src/main.rs:4:19
  |
4 |     let element = a[index];
  |                   ^^^^^^^^ index out of bounds: the len is 3 but the index is 10

@varkor
Copy link
Member

varkor commented Mar 10, 2018

Ah, interesting: it occurs for your test program, but not for this one (i.e. here the warning is always displayed):

fn main() {
    let a: [i32; 1] = [0; 1];
    a[1];
}

@jyn514
Copy link
Member Author

jyn514 commented Mar 11, 2018

Afraid I'm new to rust - is that a type annotation that a is an array of length 1 and type i32? Isn't the right side assigning an array of length 2?

@sfackler
Copy link
Member

[0; 1] means "an array of length 1 filled with 0 values".

@varkor
Copy link
Member

varkor commented Mar 11, 2018

Just from a little looking around, the check here seems to be the cause:

let dbg = debug_scope.is_valid() && bx.sess().opts.debuginfo == FullDebugInfo;
if !memory_locals.contains(local.index()) && !dbg {
debug!("alloc: {:?} ({}) -> operand", local, name);
return LocalRef::new_operand(bx.cx, layout);
}
debug!("alloc: {:?} ({}) -> place", local, name);
let place = PlaceRef::alloca(&bx, layout, &name.as_str());
if dbg {
let (scope, span) = fx.debug_loc(decl.source_info);
declare_local(&bx, &fx.debug_context, name, layout.ty, scope,
VariableAccess::DirectVariable { alloca: place.llval },
VariableKind::LocalVariable, span);
}
LocalRef::Place(place)

If dbg == false (i.e. debuginfo != 2), then the first return is hit and everything works. Otherwise, the returned value is constructed differently (LocalRef::Place(place)) and the warnings henceforth do not appear.

@varkor
Copy link
Member

varkor commented Mar 11, 2018

My suspicion is that this issue is specific to the old constant evaluation system, which has recently been completely replaced by miri. It's hard to be completely sure, because the array indexing warning has not yet been implemented in miri, but it seems very likely.

Have you spotted any other kinds of warnings that also disappear for debuginfo = 2?

@steveklabnik
Copy link
Member

This example doesn't warn, but the one from #48920 does; and does so regardless of debuginfo level. Given @varkor's comment above, I believe that to be true as well, and so I'm closing. Let me know if you've found this behavior elsewhere!

@RalfJung RalfJung added the A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) label Dec 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants