Skip to content

LLVMRustWriteOutputFile: EC.clear() swallows DWO file open errors, making error check dead code #493

@SebTardif

Description

@SebTardif

Summary

In compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp, the function LLVMRustWriteOutputFile calls EC.clear() immediately after constructing the DWO output stream, before checking whether the file open succeeded. This makes the subsequent if (EC) check dead code.

Location

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp, line 484 (on current main at f428d12)

Bug

auto DOS = raw_fd_ostream(DwoPath, EC, sys::fs::OF_None);
EC.clear();       // BUG: clears error before checking it
if (EC)           // DEAD CODE: EC is always clear here
  ErrorInfo = EC.message();

EC.clear() unconditionally resets the std::error_code to success. The if (EC) on the next line will never be true. If the DWO output file cannot be opened (bad path, permission denied, full disk), the error is silently swallowed.

Compare with the correctly-checked primary output file 8 lines above:

auto OS = raw_fd_ostream(Path, EC, sys::fs::OF_None);
if (EC)                    // Correct: no EC.clear() before this
  ErrorInfo = EC.message();

Impact

When -Csplit-debuginfo=unpacked is used and the DWO output path is invalid, rustc succeeds with no error but produces missing or corrupted .dwo split-DWARF debug info files.

Fix

Remove the EC.clear(); line. The error check pattern should match the primary output file path above it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-codegenArea: code generationI-wrongWrong result or data corruptionP-mediumMedium impact: affects specific usage patternsbugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions