Repository: pytorch
Issue: addcmul, byte_channels_last fail test_nnc_correctness opinfo tests under UBSAN
Labels: module: sanitizers,NNC

### 🐛 Describe the bug

Note: these are marked as `@slowTest` so to run them you need to set an environment variable `PYTORCH_TEST_WITH_SLOW=1` . `__ubsan_ignore_undefined__` also needs to be removed from `castValues(...)` in eval.cpp in order for UBSAN to run in this function. See [this comment](https://github.com/pytorch/pytorch/pull/70465#issuecomment-1023791406) for more details on repro.

addcmul (appears to be NNC-related):
```
  test_nnc_correctness_addcmul_cpu_int8 (__main__.TestNNCOpInfoCPU) ... /var/lib/jenkins/workspace/torch/csrc/jit/tensorexpr/eval.cpp:465:44: runtime error: -145.72 is outside the range of representable values of type 'signed char'
    #0 0x7f4230ef0d14 in std::vector<signed char, std::allocator<signed char> > torch::jit::tensorexpr::SimpleIREvaluatorImpl::castValues<double, signed char>(torch::jit::tensorexpr::Dtype const&, torch::jit::tensorexpr::InterpValue const&) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so+0x13237d14)
    #1 0x7f4230ed2b6b in void torch::jit::tensorexpr::SimpleIREvaluatorImpl::doCastFromSrc<double>(torch::jit::tensorexpr::Dtype const&, torch::jit::tensorexpr::Dtype const&, torch::jit::tensorexpr::InterpValue const&) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so+0x13219b6b)
    #2 0x7f4230dbc8fa in torch::jit::tensorexpr::SimpleIREvaluatorImpl::visit(std::shared_ptr<torch::jit::tensorexpr::Cast>) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so+0x131038fa)
    #3 0x7f424b7d5a18 in torch::jit::tensorexpr::ExprNode<torch::jit::tensorexpr::Cast, torch::jit::tensorexpr::Expr>::accept(torch::jit::tensorexpr::IRVisitor*) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_python.so+0x2ff6a18)
    #4 0x7f4230dcfa55 in torch::jit::tensorexpr::SimpleIREvaluatorImpl::visit(std::shared_ptr<torch::jit::tensorexpr::Store>) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so+0x13116a55)
    #5 0x7f42310068f7 in torch::jit::tensorexpr::StmtNode<torch::jit::tensorexpr::Store>::accept(torch::jit::tensorexpr::IRVisitor*) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so+0x1334d8f7)
    #6 0x7f4230dccae2 in torch::jit::tensorexpr::SimpleIREvaluatorImpl::visit(std::shared_ptr<torch::jit::tensorexpr::Block>) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so+0x13113ae2)
    #7 0x7f424b83ea68 in torch::jit::tensorexpr::StmtNode<torch::jit::tensorexpr::Block>::accept(torch::jit::tensorexpr::IRVisitor*) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_python.so+0x305fa68)
    #8 0x7f4230dcc111 in torch::jit::tensorexpr::SimpleIREvaluatorImpl::visit(std::shared_ptr<torch::jit::tensorexpr::For>) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so+0x13113111)
    #9 0x7f424b849b18 in torch::jit::tensorexpr::StmtNode<torch::jit::tensorexpr::For>::accept(torch::jit::tensorexpr::IRVisitor*) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_python.so+0x306ab18)
    #10 0x7f4230dccae2 in torch::jit::tensorexpr::SimpleIREvaluatorImpl::visit(std::shared_ptr<torch::jit::tensorexpr::Block>) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so+0x13113ae2)
    #11 0x7f424b83ea68 in torch::jit::tensorexpr::StmtNode<torch::jit::tensorexpr::Block>::accept(torch::jit::tensorexpr::IRVisitor*) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_python.so+0x305fa68)
    #12 0x7f4230dcc111 in torch::jit::tensorexpr::SimpleIREvaluatorImpl::visit(std::shared_ptr<torch::jit::tensorexpr::For>) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so+0x13113111)
    #13 0x7f424b849b18 in torch::jit::tensorexpr::StmtNode<torch::jit::tensorexpr::For>::accept(torch::jit::tensorexpr::IRVisitor*) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_python.so+0x306ab18)
    #14 0x7f4230dccae2 in torch::jit::tensorexpr::SimpleIREvaluatorImpl::visit(std::shared_ptr<torch::jit::tensorexpr::Block>) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so+0x13113ae2)
    #15 0x7f424b83ea68 in torch::jit::tensorexpr::StmtNode<torch::jit::tensorexpr::Block>::accept(torch::jit::tensorexpr::IRVisitor*) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_python.so+0x305fa68)
    #16 0x7f4230da21a0 in torch::jit::tensorexpr::SimpleIREvaluator::call_raw(std::vector<void*, std::allocator<void*> > const&) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so+0x130e91a0)
    #17 0x7f4230da19d4 in torch::jit::tensorexpr::SimpleIREvaluator::call(std::vector<torch::jit::tensorexpr::CodeGen::CallArg, std::allocator<torch::jit::tensorexpr::CodeGen::CallArg> > const&) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so+0x130e89d4)
    #18 0x7f42311b6bc8 in torch::jit::tensorexpr::TensorExprKernel::runKernel(std::vector<c10::IValue, std::allocator<c10::IValue> >&) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so+0x134fdbc8)
    #19 0x7f42308a5156 in std::_Function_handler<void (std::vector<c10::IValue, std::allocator<c10::IValue> >&), torch::jit::createTensorExprOp(torch::jit::Node const*)::$_1>::_M_invoke(std::_Any_data const&, std::vector<c10::IValue, std::allocator<c10::IValue> >&) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so+0x12bec156)
    #20 0x7f42309921a2 in torch::jit::InterpreterStateImpl::runImpl(std::vector<c10::IValue, std::allocator<c10::IValue> >&) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so+0x12cd91a2)
    #21 0x7f423096cb5d in torch::jit::InterpreterStateImpl::run(std::vector<c10::IValue, std::allocator<c10::IValue> >&) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so+0x12cb3b5d)
    #22 0x7f423093e8c3 in torch::jit::GraphExecutorImplBase::run(std::vector<c10::IValue, std::allocator<c10::IValue> >&) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so+0x12c858c3)
    #23 0x7f424b2bbfed in torch::jit::runAndInsertCall(torch::jit::Function&, torch::jit::tuple_slice const&, pybind11::kwargs const&, c10::optional<c10::IValue>, std::function<torch::jit::Value* (torch::jit::Graph&, torch::jit::MatchedSchema const&)> const&) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_python.so+0x2adcfed)
    #24 0x7f424b2c1629 in torch::jit::invokeScriptFunctionFromPython(torch::jit::Function&, torch::jit::tuple_slice const&, pybind11::kwargs const&) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_python.so+0x2ae2629)
    #25 0x7f424b498563 in void pybind11::cpp_function::initialize<torch::jit::initJitScriptBindings(_object*)::$_49, pybind11::object, pybind11::args, pybind11::kwargs, pybind11::name, pybind11::is_method, pybind11::sibling>(torch::jit::initJitScriptBindings(_object*)::$_49&&, pybind11::object (*)(pybind11::args, pybind11::kwargs), pybind11::name const&, pybind11::is_method const&, pybind11::sibling const&)::'lambda'(pybind11::detail::function_call&)::__invoke(pybind11::detail::function_call&) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_python.so+0x2cb9563)
    #26 0x7f424a53c6bc in pybind11::cpp_function::dispatcher(_object*, _object*, _object*) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_python.so+0x1d5d6bc)
```

byte_channels_last:
```
  test_nnc_correctness_byte_channels_last_cpu_float32 (__main__.TestNNCOpInfoCPU) ... /var/lib/jenkins/workspace/torch/csrc/jit/tensorexpr/eval.cpp:465:44: runtime error: -6.92491 is outside the range of representable values of type 'unsigned char'
    #0 0x7fd9faf0704a in std::vector<unsigned char, std::allocator<unsigned char> > torch::jit::tensorexpr::SimpleIREvaluatorImpl::castValues<float, unsigned char>(torch::jit::tensorexpr::Dtype const&, torch::jit::tensorexpr::InterpValue const&) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so+0x1323504a)
    #1 0x7fd9faee8ee1 in void torch::jit::tensorexpr::SimpleIREvaluatorImpl::doCastFromSrc<float>(torch::jit::tensorexpr::Dtype const&, torch::jit::tensorexpr::Dtype const&, torch::jit::tensorexpr::InterpValue const&) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so+0x13216ee1)
    #2 0x7fd9fadd5b2e in torch::jit::tensorexpr::SimpleIREvaluatorImpl::visit(std::shared_ptr<torch::jit::tensorexpr::Cast>) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so+0x13103b2e)
    #3 0x7fda157eea18 in torch::jit::tensorexpr::ExprNode<torch::jit::tensorexpr::Cast, torch::jit::tensorexpr::Expr>::accept(torch::jit::tensorexpr::IRVisitor*) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_python.so+0x2ff6a18)
    #4 0x7fd9fade78f5 in torch::jit::tensorexpr::SimpleIREvaluatorImpl::visit(std::shared_ptr<torch::jit::tensorexpr::Store>) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so+0x131158f5)
    #5 0x7fd9fb01f8f7 in torch::jit::tensorexpr::StmtNode<torch::jit::tensorexpr::Store>::accept(torch::jit::tensorexpr::IRVisitor*) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so+0x1334d8f7)
    #6 0x7fd9fade5ae2 in torch::jit::tensorexpr::SimpleIREvaluatorImpl::visit(std::shared_ptr<torch::jit::tensorexpr::Block>) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so+0x13113ae2)
    #7 0x7fda15857a68 in torch::jit::tensorexpr::StmtNode<torch::jit::tensorexpr::Block>::accept(torch::jit::tensorexpr::IRVisitor*) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_python.so+0x305fa68)
    #8 0x7fd9fade5111 in torch::jit::tensorexpr::SimpleIREvaluatorImpl::visit(std::shared_ptr<torch::jit::tensorexpr::For>) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so+0x13113111)
    #9 0x7fda15862b18 in torch::jit::tensorexpr::StmtNode<torch::jit::tensorexpr::For>::accept(torch::jit::tensorexpr::IRVisitor*) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_python.so+0x306ab18)
    #10 0x7fd9fade5ae2 in torch::jit::tensorexpr::SimpleIREvaluatorImpl::visit(std::shared_ptr<torch::jit::tensorexpr::Block>) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so+0x13113ae2)
    #11 0x7fda15857a68 in torch::jit::tensorexpr::StmtNode<torch::jit::tensorexpr::Block>::accept(torch::jit::tensorexpr::IRVisitor*) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_python.so+0x305fa68)
    #12 0x7fd9fade5111 in torch::jit::tensorexpr::SimpleIREvaluatorImpl::visit(std::shared_ptr<torch::jit::tensorexpr::For>) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so+0x13113111)
    #13 0x7fda15862b18 in torch::jit::tensorexpr::StmtNode<torch::jit::tensorexpr::For>::accept(torch::jit::tensorexpr::IRVisitor*) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_python.so+0x306ab18)
    #14 0x7fd9fade5ae2 in torch::jit::tensorexpr::SimpleIREvaluatorImpl::visit(std::shared_ptr<torch::jit::tensorexpr::Block>) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so+0x13113ae2)
    #15 0x7fda15857a68 in torch::jit::tensorexpr::StmtNode<torch::jit::tensorexpr::Block>::accept(torch::jit::tensorexpr::IRVisitor*) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_python.so+0x305fa68)
    #16 0x7fd9fade5111 in torch::jit::tensorexpr::SimpleIREvaluatorImpl::visit(std::shared_ptr<torch::jit::tensorexpr::For>) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so+0x13113111)
    #17 0x7fda15862b18 in torch::jit::tensorexpr::StmtNode<torch::jit::tensorexpr::For>::accept(torch::jit::tensorexpr::IRVisitor*) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_python.so+0x306ab18)
    #18 0x7fd9fade5ae2 in torch::jit::tensorexpr::SimpleIREvaluatorImpl::visit(std::shared_ptr<torch::jit::tensorexpr::Block>) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so+0x13113ae2)
    #19 0x7fda15857a68 in torch::jit::tensorexpr::StmtNode<torch::jit::tensorexpr::Block>::accept(torch::jit::tensorexpr::IRVisitor*) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_python.so+0x305fa68)
    #20 0x7fd9fade5111 in torch::jit::tensorexpr::SimpleIREvaluatorImpl::visit(std::shared_ptr<torch::jit::tensorexpr::For>) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so+0x13113111)
    #21 0x7fda15862b18 in torch::jit::tensorexpr::StmtNode<torch::jit::tensorexpr::For>::accept(torch::jit::tensorexpr::IRVisitor*) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_python.so+0x306ab18)
    #22 0x7fd9fade5ae2 in torch::jit::tensorexpr::SimpleIREvaluatorImpl::visit(std::shared_ptr<torch::jit::tensorexpr::Block>) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so+0x13113ae2)
    #23 0x7fda15857a68 in torch::jit::tensorexpr::StmtNode<torch::jit::tensorexpr::Block>::accept(torch::jit::tensorexpr::IRVisitor*) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_python.so+0x305fa68)
    #24 0x7fd9fadbb1a0 in torch::jit::tensorexpr::SimpleIREvaluator::call_raw(std::vector<void*, std::allocator<void*> > const&) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so+0x130e91a0)
    #25 0x7fd9fadba9d4 in torch::jit::tensorexpr::SimpleIREvaluator::call(std::vector<torch::jit::tensorexpr::CodeGen::CallArg, std::allocator<torch::jit::tensorexpr::CodeGen::CallArg> > const&) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so+0x130e89d4)
    #26 0x7fd9fb1cfbc8 in torch::jit::tensorexpr::TensorExprKernel::runKernel(std::vector<c10::IValue, std::allocator<c10::IValue> >&) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so+0x134fdbc8)
    #27 0x7fd9fa8be156 in std::_Function_handler<void (std::vector<c10::IValue, std::allocator<c10::IValue> >&), torch::jit::createTensorExprOp(torch::jit::Node const*)::$_1>::_M_invoke(std::_Any_data const&, std::vector<c10::IValue, std::allocator<c10::IValue> >&) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so+0x12bec156)
    #28 0x7fd9fa9ab1a2 in torch::jit::InterpreterStateImpl::runImpl(std::vector<c10::IValue, std::allocator<c10::IValue> >&) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so+0x12cd91a2)
    #29 0x7fd9fa985b5d in torch::jit::InterpreterStateImpl::run(std::vector<c10::IValue, std::allocator<c10::IValue> >&) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so+0x12cb3b5d)
    #30 0x7fd9fa9578c3 in torch::jit::GraphExecutorImplBase::run(std::vector<c10::IValue, std::allocator<c10::IValue> >&) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so+0x12c858c3)
    #31 0x7fda152d4fed in torch::jit::runAndInsertCall(torch::jit::Function&, torch::jit::tuple_slice const&, pybind11::kwargs const&, c10::optional<c10::IValue>, std::function<torch::jit::Value* (torch::jit::Graph&, torch::jit::MatchedSchema const&)> const&) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_python.so+0x2adcfed)
    #32 0x7fda152da629 in torch::jit::invokeScriptFunctionFromPython(torch::jit::Function&, torch::jit::tuple_slice const&, pybind11::kwargs const&) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_python.so+0x2ae2629)
    #33 0x7fda154b1563 in void pybind11::cpp_function::initialize<torch::jit::initJitScriptBindings(_object*)::$_49, pybind11::object, pybind11::args, pybind11::kwargs, pybind11::name, pybind11::is_method, pybind11::sibling>(torch::jit::initJitScriptBindings(_object*)::$_49&&, pybind11::object (*)(pybind11::args, pybind11::kwargs), pybind11::name const&, pybind11::is_method const&, pybind11::sibling const&)::'lambda'(pybind11::detail::function_call&)::__invoke(pybind11::detail::function_call&) (/opt/conda/lib/python3.7/site-packages/torch/lib/libtorch_python.so+0x2cb9563)
```

### Versions

ASAN CI builds
addcmul: https://github.com/pytorch/pytorch/runs/4945454087?check_suite_focus=true
addcdiv: https://github.com/pytorch/pytorch/runs/4901392578?check_suite_focus=true
byte_channels_last: https://github.com/pytorch/pytorch/runs/4948623446?check_suite_focus=true