Skip to content

[Coverity] Non-local variable isn't restored #3414

@AlexeySachkov

Description

@AlexeySachkov

The issue was discovered by Coverity scan that we do at intel/llvm repo, you can view the scan and request access here: https://scan.coverity.com/projects/intel-llvm?tab=overview

CID 546125:

if (!BM->getFnVarSpvOut().empty()) {
auto SaveOpt = SPIRVUseTextFormat;
auto OFSSpv = std::ofstream(BM->getFnVarSpvOut(), std::ios::binary);
SPIRVUseTextFormat = false;
OFSSpv << *BM;
if (BM->getError(ErrMsg) != SPIRVEC_Success) {
return false;
}
SPIRVUseTextFormat = SaveOpt;
}

SPIRVUseTextFormat value is not restored to its original value in case of errors.

Whilst I don't know if there is a practical use case for this, this is technically a problem, because readSpirv is part of the public translator API:

/// \brief Load SPIR-V from istream and translate to LLVM module.
/// \returns true if succeeds.
bool readSpirv(LLVMContext &C, const SPIRV::TranslatorOpts &Opts,
std::istream &IS, Module *&M, std::string &ErrMsg);

As such, there could exist an application which calls it multiple times where some invocations may produce unexpected results

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions