chipsalliance / UHDM

Universal Hardware Data Model. A complete modeling of the IEEE SystemVerilog Object Model with VPI Interface, Elaborator, Serialization, Visitor and Listener. Used as a compiled interchange format in between SystemVerilog tools. Compiles on Linux gcc, Windows msys2-gcc & msvc, OsX

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Undefined behavior shift in ExprEval.cpp

hzeller opened this issue · comments

The undefined behavior analyzer found that there is an instance around third_party/uhdm/src/ExprEval.cpp:1489 (a bit shifted in the template in ExprEval.cpp:1499
Here, a shift operation goes beyond the integer width in question, which is undefined behavior.

This can be seen when running the ParamLine regression test in Surelog:

third_party/uhdm/src/ExprEval.cpp:1489:29: runtime error: shift exponent 88 is too large for 32-bit type 'int'
    #0 0x55a273af29d3 in UHDM::ExprEval::get_value(bool&, UHDM::expr const*) third_party/uhdm/src/ExprEval.cpp:1489:29
    #1 0x55a273af6d01 in UHDM::ExprEval::reduceCompOp(UHDM::operation*, bool&, UHDM::BaseClass const*, UHDM::BaseClass const*, bool) third_party/uhdm/src/ExprEval.cpp:1090:18
    #2 0x55a273ae2198 in UHDM::ExprEval::reduceExpr(UHDM::BaseClass const*, bool&, UHDM::BaseClass const*, UHDM::BaseClass const*, bool) third_party/uhdm/src/ExprEval.cpp:2225:24
    #3 0x55a27346b42d in SURELOG::CompileHelper::reduceExpr(UHDM::BaseClass*, bool&, SURELOG::DesignComponent*, SURELOG::CompileDesign*, SURELOG::ValuedComponentI*, SURELOG::PathId, int, UHDM::BaseClass*, bool) surelog/src/DesignCompile/CompileExpression.cpp:816:20
    #4 0x55a273474b41 in SURELOG::CompileHelper::compileExpression(SURELOG::DesignComponent*, SURELOG::FileContent const*, SURELOG::NodeId, SURELOG::CompileDesign*, UHDM::BaseClass*, SURELOG::ValuedComponentI*, bool, bool) surelog/src/DesignCompile/CompileExpression.cpp:3083:16
    #5 0x55a27349714d in SURELOG::CompileHelper::getValue(bool&, SURELOG::DesignComponent*, SURELOG::FileContent const*, SURELOG::NodeId, SURELOG::CompileDesign*, UHDM::BaseClass*, SURELOG::ValuedComponentI*, bool, bool) surelog/src/DesignCompile/CompileExpression.cpp:5225:21
    #6 0x55a273594555 in SURELOG::DesignElaboration::elaborateInstance_(SURELOG::FileContent const*, SURELOG::NodeId, SURELOG::NodeId, SURELOG::ModuleInstanceFactory*, SURELOG::ModuleInstance*, SURELOG::Config*, std::__u::vector<SURELOG::ModuleInstance*, std::__u::allocator<SURELOG::ModuleInstance*>>&) surelog/src/DesignCompile/DesignElaboration.cpp:1109:24
    #7 0x55a27358bd9d in SURELOG::DesignElaboration::elaborateModule_(std::__u::basic_string<char, std::__u::char_traits<char>, std::__u::allocator<char>> const&, SURELOG::FileContent const*, bool) surelog/src/DesignCompile/DesignElaboration.cpp:549:11
    #8 0x55a27357ecae in elaborateAllModules_ surelog/src/DesignCompile/DesignElaboration.cpp:477:10
    #9 0x55a27357ecae in SURELOG::DesignElaboration::elaborate() surelog/src/DesignCompile/DesignElaboration.cpp:76:3
    #10 0x55a273521897 in SURELOG::CompileDesign::elaboration_() surelog/src/DesignCompile/CompileDesign.cpp:368:13
    #11 0x55a27352166f in SURELOG::CompileDesign::elaborate() surelog/src/DesignCompile/CompileDesign.cpp:272:11
    #12 0x55a27339e7f0 in SURELOG::Compiler::compile() surelog/src/SourceCompile/Compiler.cpp:1047:24
    #13 0x55a273300f54 in SURELOG::start_compiler(SURELOG::CommandLineParser*) surelog/src/API/Surelog.cpp:33:31
    #14 0x55a2732faa32 in executeCompilation(int, char const**, bool, bool, SURELOG::ErrorContainer::Stats*) surelog/src/main.cpp:92:36
    #15 0x55a2732fc7d8 in batchCompilation(char const*, std::__u::__fs::filesystem::path const&, std::__u::__fs::filesystem::path const&, bool) surelog/src/main.cpp:205:19
    #16 0x55a2732fd776 in main surelog/src/main.cpp:326:21

Fixed by #934