Bug type: crash
Component: Instrumentation
Bug location: llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp: NumericalStabilitySanitizer::createShadowValueWithOperandsAvailable
Issue title: ICE:  Unimplemented support for freeze compiling with numerical sanitizer
Labels: crash-on-valid
compiler-rt:nsan
Reported by: VinInn

```
fatal error: error in backend: Unimplemented support for freeze
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: /afs/cern.ch/user/i/innocent/w5/bin/clang++ -c -DGNU_GCC -D_GNU_SOURCE -DTBB_USE_GLIBCXX_VERSION=120301 -DTBB_SUPPRESS_DEPRECATED_MESSAGES -DTBB_PREVIEW_RESUMABLE_TASKS=1 -DTBB_PREVIEW_TASK_GROUP_EXTENSIONS=1 -DBOOST_SPIRIT_THREADSAFE -DPHOENIX_THREADSAFE -DBOOST_MATH_DISABLE_STD_FPCLASSIFY -DBOOST_UUID_RANDOM_PROVIDER_FORCE_POSIX -DCMSSW_GIT_HASH=\"CMSSW_14_1_CLANG_X_2024-07-07-2300\" -DPROJECT_NAME=\"CMSSW\" -DPROJECT_VERSION=\"CMSSW_14_1_CLANG_X_2024-07-07-2300\" -Isrc -I/cvmfs/cms-ib.cern.ch/sw/x86_64/week1/el8_amd64_gcc12/cms/cmssw/CMSSW_14_1_CLANG_X_2024-07-07-2300/src -I/cvmfs/cms-ib.cern.ch/sw/x86_64/nweek-02845/el8_amd64_gcc12/external/alpaka/1.1.0-0a6641b4bfdf883c8da5b9e8620be504/include -I/cvmfs/cms-ib.cern.ch/sw/x86_64/nweek-02845/el8_amd64_gcc12/external/pcre/8.43-e34796d17981e9b6d174328c69446455/include -isystem/cvmfs/cms-ib.cern.ch/sw/x86_64/nweek-02845/el8_amd64_gcc12/external/boost/1.80.0-a1544032d9d65904ac2112b6d35bba55/include -I/cvmfs/cms-ib.cern.ch/sw/x86_64/nweek-02845/el8_amd64_gcc12/external/bz2lib/1.0.6-d065ccd79984efc6d4660f410e4c81de/include -isystem/cvmfs/cms-ib.cern.ch/sw/x86_64/nweek-02845/el8_amd64_gcc12/external/clhep/2.4.7.1-8e40efd27b7394c1fa4e9c7e432d85cd/include -I/cvmfs/cms-ib.cern.ch/sw/x86_64/nweek-02845/el8_amd64_gcc12/external/gsl/2.6-5e2ce72ea2977ff21a2344bbb52daf5c/include -isystem/cvmfs/cms-ib.cern.ch/sw/x86_64/nweek-02845/el8_amd64_gcc12/external/hls/2019.08-0e37f055a3ed22611ce5edecb14d0695/include -I/cvmfs/cms-ib.cern.ch/sw/x86_64/nweek-02845/el8_amd64_gcc12/external/libuuid/2.34-27ce4c3579b5b1de2808ea9c4cd8ed29/include -isystem/cvmfs/cms-ib.cern.ch/sw/x86_64/nweek-02845/el8_amd64_gcc12/lcg/root/6.30.07-5b5d83179d6ed7bc60aa7a5006899eba/include -isystem/cvmfs/cms-ib.cern.ch/sw/x86_64/nweek-02845/el8_amd64_gcc12/external/tbb/v2021.9.0-1dc6d66b4b014f4ae4733b04914ce7d4/include -I/cvmfs/cms-ib.cern.ch/sw/x86_64/nweek-02845/el8_amd64_gcc12/cms/vdt/0.4.3-f094bee80112624813c07f9336e08d7d/include -I/cvmfs/cms-ib.cern.ch/sw/x86_64/nweek-02845/el8_amd64_gcc12/external/xz/5.2.5-6f3f49b07db84e10c9be594a1176c114/include -I/cvmfs/cms-ib.cern.ch/sw/x86_64/nweek-02845/el8_amd64_gcc12/external/zlib/1.2.11-1a082fc322b0051b504cc023f21df178/include -I/cvmfs/cms-ib.cern.ch/sw/x86_64/nweek-02845/el8_amd64_gcc12/external/eigen/3bb6a48d8c171cf20b5f8e48bfb4e424fbd4f79e-3ca740c03e68b1a067f3ed0679234a78/include/eigen3 -I/cvmfs/cms-ib.cern.ch/sw/x86_64/nweek-02845/el8_amd64_gcc12/external/fmt/8.0.1-258b4791803c34b7e98cf43693e54d87/include -I/cvmfs/cms-ib.cern.ch/sw/x86_64/nweek-02845/el8_amd64_gcc12/external/md5/1.0.0-5b594b264e04ae51e893b1d69a797ec6/include -I/cvmfs/cms-ib.cern.ch/sw/x86_64/nweek-02845/el8_amd64_gcc12/external/OpenBLAS/0.3.15-c877ab57fa7b04ce290093588c6c5717/include -I/cvmfs/cms-ib.cern.ch/sw/x86_64/nweek-02845/el8_amd64_gcc12/external/tinyxml2/6.2.0-88fe0ec301baf763fa3c485e5b67ed91/include -O3 -pthread -pipe -Werror=main -Werror=pointer-arith -Werror=overlength-strings -Wno-vla -Werror=overflow -std=c++17 -ftree-vectorize -Werror=array
-bounds -Werror=type-limits -fvisibility-inlines-hidden -fno-math-errno --param vect-max-version-for-alias-checks=50 -Xassembler --compress-debug-sections -Wno-error=array-bounds -Warray-bounds -fuse-ld=bfd -march=x86-
64-v2 -felide-constructors -fmessage-length=0 -Wall -Wno-long-long -Wreturn-type -Wextra -Wpessimizing-move -Wclass-memaccess -Wno-cast-function-type -Wno-unused-but-set-parameter -Wno-ignored-qualifiers -Wno-unused-pa
rameter -Wunused -Wparentheses -Werror=return-type -Werror=missing-braces -Werror=unused-value -Werror=unused-label -Werror=address -Werror=format -Werror=sign-compare -Werror=write-strings -Werror=delete-non-virtual-d
tor -Werror=strict-aliasing -Werror=narrowing -Werror=reorder -Werror=unused-variable -Werror=conversion-null -Wnon-virtual-dtor -Werror=switch -fdiagnostics-show-option -Wno-unused-local-typedefs -Wno-attributes -Wno-
psabi -Wno-c99-extensions -Wno-c++11-narrowing -D__STRICT_ANSI__ -Wno-unused-private-field -Wno-unknown-pragmas -Wno-unused-command-line-argument -Wno-unknown-warning-option -ftemplate-depth=1024 -Wno-error=potentially
-evaluated-expression -Wno-tautological-type-limit-compare -Wno-vla-cxx-extension -fsized-deallocation --gcc-toolchain=/afs/cern.ch/work/i/innocent/public/w5 -Ofast -fno-reciprocal-math -mrecip=none -DEIGEN_DONT_PARALL
ELIZE -DEIGEN_MAX_ALIGN_BYTES=64 -Wno-error=unused-variable -DALPAKA_DEFAULT_HOST_MEMORY_ALIGNMENT=128 -DALPAKA_DISABLE_VENDOR_RNG -DBOOST_DISABLE_ASSERTS -g -fsanitize=numerical -fPIC -MMD -MF tmp/el8_amd64_gcc12/src/
TrackingTools/TrajectoryState/src/TrackingToolsTrajectoryState/BasicTrajectoryState.cc.d src/TrackingTools/TrajectoryState/src/BasicTrajectoryState.cc -o tmp/el8_amd64_gcc12/src/TrackingTools/TrajectoryState/src/Tracki
ngToolsTrajectoryState/BasicTrajectoryState.cc.o
1.      <eof> parser at end of file
2.      Optimizer
3.      Running pass "nsan" on module "src/TrackingTools/TrajectoryState/src/BasicTrajectoryState.cc"
 #0 0x000000000389df7b llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/afs/cern.ch/user/i/innocent/w5/bin/clang+++0x389df7b)
 #1 0x000000000389bd04 llvm::sys::CleanupOnSignal(unsigned long) (/afs/cern.ch/user/i/innocent/w5/bin/clang+++0x389bd04)
 #2 0x00000000037dc354 llvm::CrashRecoveryContext::HandleExit(int) (/afs/cern.ch/user/i/innocent/w5/bin/clang+++0x37dc354)
 #3 0x0000000003892523 llvm::sys::Process::Exit(int, bool) (/afs/cern.ch/user/i/innocent/w5/bin/clang+++0x3892523)
 #4 0x0000000000be52a7 (/afs/cern.ch/user/i/innocent/w5/bin/clang+++0xbe52a7)
 #5 0x00000000037e7dea llvm::report_fatal_error(llvm::Twine const&, bool) (/afs/cern.ch/user/i/innocent/w5/bin/clang+++0x37e7dea)
 #6 0x0000000004fbbf2c (anonymous namespace)::NumericalStabilitySanitizer::createShadowValueWithOperandsAvailable(llvm::Instruction&, llvm::TargetLibraryInfo const&, (anonymous namespace)::ValueToShadowMap const&) Nume
ricalStabilitySanitizer.cpp:0:0
 #7 0x0000000004fbcd55 llvm::NumericalStabilitySanitizerPass::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/afs/cern.ch/user/i/innocent/w5/bin/clang+++0x4fbcd55)
 #8 0x0000000003b38ac2 llvm::detail::PassModel<llvm::Module, llvm::NumericalStabilitySanitizerPass, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/afs/cern.ch/user/i/in
nocent/w5/bin/clang+++0x3b38ac2)
 #9 0x0000000003229bad llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/afs/cern.ch/user/i/innocent/w5/bin/clang+++0x3229bad)
#10 0x0000000003b46c3e (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<l
lvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&, clang::BackendConsumer*) BackendUtil.cpp:0:0
#11 0x0000000003b4a1ef (anonymous namespace)::EmitAssemblyHelper::EmitAssembly(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) Back
endUtil.cpp:0:0
#12 0x0000000003b4acc1 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm:
:Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/afs/cern.ch/user/i/inn
ocent/w5/bin/clang+++0x3b4acc1)
#13 0x0000000004168f3b clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/afs/cern.ch/user/i/innocent/w5/bin/clang+++0x4168f3b)
#14 0x0000000005bd82cc clang::ParseAST(clang::Sema&, bool, bool) (/afs/cern.ch/user/i/innocent/w5/bin/clang+++0x5bd82cc)
#15 0x0000000004430459 clang::FrontendAction::Execute() (/afs/cern.ch/user/i/innocent/w5/bin/clang+++0x4430459)
#16 0x00000000043b1c9b clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/afs/cern.ch/user/i/innocent/w5/bin/clang+++0x43b1c9b)
#17 0x0000000004500ae7 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/afs/cern.ch/user/i/innocent/w5/bin/clang+++0x4500ae7)
#18 0x0000000000be70c4 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/afs/cern.ch/user/i/innocent/w5/bin/clang+++0xbe70c4)
#19 0x0000000000be0aac ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#20 0x00000000041b6519 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allo
cator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#21 0x00000000037dc253 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/afs/cern.ch/user/i/innocent/w5/bin/clang+++0x37dc253)
#22 0x00000000041b6d16 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:
0:0
#23 0x000000000417b1db clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/afs/cern.ch/user/i/innocent/w5/bin/clang+++0x417b1db)
#24 0x000000000417bbee clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/afs/cern.ch/user/i/innocent/w5/bin/clan
g+++0x417bbee)
#25 0x000000000418e11c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/afs/cern.ch/user/i/innocent/w5/bin/clang+++0x418e11
c)
#26 0x0000000000be40ae clang_main(int, char**, llvm::ToolContext const&) (/afs/cern.ch/user/i/innocent/w5/bin/clang+++0xbe40ae)
#27 0x0000000000aad1af main (/afs/cern.ch/user/i/innocent/w5/bin/clang+++0xaad1af)
#28 0x00007f2127913d85 __libc_start_main (/usr/lib64/libc.so.6+0x3ad85)
#29 0x0000000000be04fe _start (/afs/cern.ch/user/i/innocent/w5/bin/clang+++0xbe04fe)
clang++: error: clang frontend command failed with exit code 70 (use -v to see invocation)
clang version 19.0.0git (git@github.com:llvm/llvm-project.git 857700ff6fb9f9f653c3788445df06db07e7bb59)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /afs/cern.ch/work/i/innocent/public/w5/bin
clang++: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang++: note: diagnostic msg: tmp/el8_amd64_gcc12/src/TrackingTools/TrajectoryState/src/TrackingToolsTrajectoryState/BasicTrajectoryState-33393f.cpp
clang++: note: diagnostic msg: tmp/el8_amd64_gcc12/src/TrackingTools/TrajectoryState/src/TrackingToolsTrajectoryState/BasicTrajectoryState-33393f.sh
clang++: note: diagnostic msg:
```
[nsanCrash.tgz](https://github.com/user-attachments/files/16142152/nsanCrash.tgz)


Comments: author: dtcxzyw
body: cc @alexander-shaposhnikov 
author: VinInn
body: compilation is stiill failing with
```clang version 20.0.0git (git@github.com:llvm/llvm-project.git ba8126b6fef79bd344a247f6291aaec7b67bdff0)```
with the same error message "fatal error: error in backend: Unimplemented support for freeze"


Fix patch:
commit 70a9535f714e2fdb84af243a1a316012c8019049
Author: Alexander Shaposhnikov <ashaposhnikov@google.com>
Date:   Thu Jul 25 21:34:08 2024 -0700

    [Instrumentation][nsan] Add support for Freeze instruction (#100490)
    
    Add support for Freeze.
    
    This fixes https://github.com/llvm/llvm-project/issues/98143 .

diff --git a/llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp b/llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp
index b382fedde027..832506f639a7 100644
--- a/llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp
@@ -1725,6 +1725,9 @@ Value *NumericalStabilitySanitizer::createShadowValueWithOperandsAvailable(
                                 Map.getShadow(S->getTrueValue()),
                                 Map.getShadow(S->getFalseValue()));
 
+  if (auto *Freeze = dyn_cast<FreezeInst>(&Inst))
+    return Builder.CreateFreeze(Map.getShadow(Freeze->getOperand(0)));
+
   if (auto *Extract = dyn_cast<ExtractElementInst>(&Inst))
     return Builder.CreateExtractElement(
         Map.getShadow(Extract->getVectorOperand()), Extract->getIndexOperand());


Regression tests:
file: llvm/test/Instrumentation/NumericalStabilitySanitizer/basic.ll
commands: opt -passes=nsan -nsan-shadow-type-mapping=dqq -nsan-truncate-fcmp-eq=false -S %s
opt -passes=nsan -nsan-shadow-type-mapping=dlq -nsan-truncate-fcmp-eq=false -S %s
tests: test_name: freeze_vector_insert
test_body: target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"

; Function Attrs: sanitize_numerical_stability
define void @freeze_vector_insert(<2 x float> %vec, i32 %idx, float %scalar) #0 {
entry:
  %0 = insertelement <2 x float> %vec, float %scalar, i32 %idx
  %frozen = freeze <2 x float> %0
  ret void
}

attributes #0 = { sanitize_numerical_stability }

test_name: vector_shuffle
test_body: target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"

; Function Attrs: sanitize_numerical_stability
define void @vector_shuffle(<2 x float> %0) #0 {
entry:
  %1 = shufflevector <2 x float> %0, <2 x float> splat (float 1.000000e+00), <2 x i32> <i32 1, i32 3>
  ret void
}

attributes #0 = { sanitize_numerical_stability }