Skip to content

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

Closed

Description

@jyn514

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

Activity

  1. added
    A-debuginfoArea: Debugging information in compiled programs (DWARF, PDB, etc.)
    A-diagnosticsArea: Messages for errors, warnings, and lints
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    C-bugCategory: This is a bug.
    on Mar 10, 2018
  2. jyn514 commented on Mar 10, 2018

    @jyn514
    MemberAuthor

    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.

  3. varkor commented on Mar 10, 2018

    @varkor
    Contributor

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

  4. jyn514 commented on Mar 10, 2018

    @jyn514
    MemberAuthor

    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
    
  5. varkor commented on Mar 10, 2018

    @varkor
    Contributor

    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];
    }
  6. jyn514 commented on Mar 11, 2018

    @jyn514
    MemberAuthor

    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?

  7. sfackler commented on Mar 11, 2018

    @sfackler
    Member

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

  8. varkor commented on Mar 11, 2018

    @varkor
    Contributor

    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.

  9. varkor commented on Mar 11, 2018

    @varkor
    Contributor

    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?

  10. steveklabnik commented on Oct 21, 2019

    @steveklabnik
    Contributor

    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!

  11. added
    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)
    on Dec 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)A-debuginfoArea: Debugging information in compiled programs (DWARF, PDB, etc.)A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions