Bug type: crash
Component: ValueMapper
Bug location: llvm/lib/Transforms/Utils/ValueMapper.cpp: Mapper::remapDPValue
Issue title: Clang frontend command failed to build lib/vsprintf.c in Linux kernel
Labels: crash
llvm:transforms
Reported by: eve2023

```
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: clang -Wp,-MMD,lib/.vsprintf.o.d -nostdinc -I./arch/x86/include -I./arch/x86/include/generated -I./include -I./arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/compiler-version.h -include ./include/linux/kconfig.h -include ./include/linux/compiler_types.h -D__KERNEL__ --target=x86_64-linux-gnu -fintegrated-as -Werror=unknown-warning-option -Werror=ignored-optimization-argument -Werror=option-ignored -Werror=unused-command-line-argument -fmacro-prefix-map=./= -std=gnu11 -fshort-wchar -funsigned-char -fno-common -fno-PIE -fno-strict-aliasing -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -fcf-protection=none -m64 -falign-loops=1 -mno-80387 -mno-fp-ret-in-387 -mstack-alignment=8 -mskip-rax-setup -mtune=generic -mno-red-zone -mcmodel=kernel -Wno-sign-compare -fno-asynchronous-unwind-tables -mretpoline-external-thunk -mindirect-branch-cs-prefix -mfunction-return=thunk-extern -mharden-sls=all -fpatchable-function-entry=16,16 -fno-delete-null-pointer-checks -O2 -fstack-protector-strong -fno-omit-frame-pointer -fno-optimize-sibling-calls -ftrivial-auto-var-init=zero -fno-stack-clash-protection -fzero-call-used-regs=used-gpr -DCC_USING_NOP_MCOUNT -DCC_USING_FENTRY -falign-functions=16 -fstrict-flex-arrays=3 -fno-strict-overflow -fno-stack-check -Wall -Wundef -Werror=implicit-function-declaration -Werror=implicit-int -Werror=return-type -Werror=strict-prototypes -Wno-format-security -Wno-trigraphs -Wno-frame-address -Wno-address-of-packed-member -Wmissing-declarations -Wmissing-prototypes -Wframe-larger-than=1024 -Wno-gnu -Wno-unused-but-set-variable -Wno-unused-const-variable -Wvla -Wno-pointer-sign -Wcast-function-type -Wimplicit-fallthrough -Werror=date-time -Werror=incompatible-pointer-types -Wenum-conversion -Wno-unused-but-set-variable -Wno-unused-const-variable -Wno-format-overflow -Wno-format-truncation -Wno-pointer-to-enum-cast -Wno-tautological-constant-out-of-range-compare -Wno-unaligned-access -Wno-cast-function-type-strict -Wno-missing-field-initializers -Wno-type-limits -Wno-shift-negative-value -Wno-initializer-overrides -Wno-sign-compare -g -gdwarf-5 -fsanitize=array-bounds -fsanitize=shift -fsanitize=bool -fsanitize=enum -DKBUILD_MODFILE=\"lib/vsprintf\" -DKBUILD_BASENAME=\"vsprintf\" -DKBUILD_MODNAME=\"vsprintf\" -D__KBUILD_MODNAME=kmod_vsprintf -c -o lib/vsprintf.o lib/vsprintf.c
1.	<eof> parser at end of file
2.	Code generation
3.	Running pass 'Function Pass Manager' on module 'lib/vsprintf.c'.
4.	Running pass 'Assignment Tracking Analysis' on function '@ip4_string'
 #0 0x000055fc39a6be88 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/eve/Downloads/llvm-project/build2/bin/clang-19+0x2d82e88)
 #1 0x000055fc39a69c6e llvm::sys::RunSignalHandlers() (/home/eve/Downloads/llvm-project/build2/bin/clang-19+0x2d80c6e)
 #2 0x000055fc399e7729 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f7639a42990 (/lib/x86_64-linux-gnu/libc.so.6+0x42990)
 #4 0x000055fc39484775 (anonymous namespace)::AssignmentTrackingLowering::run(FunctionVarLocsBuilder*) AssignmentTrackingAnalysis.cpp:0:0
 #5 0x000055fc3947f3fe analyzeFunction(llvm::Function&, llvm::DataLayout const&, FunctionVarLocsBuilder*) AssignmentTrackingAnalysis.cpp:0:0
 #6 0x000055fc3947fdcd llvm::AssignmentTrackingAnalysis::runOnFunction(llvm::Function&) (/home/eve/Downloads/llvm-project/build2/bin/clang-19+0x2796dcd)
 #7 0x000055fc395bab96 llvm::FPPassManager::runOnFunction(llvm::Function&) (/home/eve/Downloads/llvm-project/build2/bin/clang-19+0x28d1b96)
 #8 0x000055fc395c1a23 llvm::FPPassManager::runOnModule(llvm::Module&) (/home/eve/Downloads/llvm-project/build2/bin/clang-19+0x28d8a23)
 #9 0x000055fc395bb807 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/home/eve/Downloads/llvm-project/build2/bin/clang-19+0x28d2807)
#10 0x000055fc39c161b6 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*) (/home/eve/Downloads/llvm-project/build2/bin/clang-19+0x2f2d1b6)
#11 0x000055fc3a09fed5 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/home/eve/Downloads/llvm-project/build2/bin/clang-19+0x33b6ed5)
#12 0x000055fc3b7248f6 clang::ParseAST(clang::Sema&, bool, bool) (/home/eve/Downloads/llvm-project/build2/bin/clang-19+0x4a3b8f6)
#13 0x000055fc3a316d86 clang::FrontendAction::Execute() (/home/eve/Downloads/llvm-project/build2/bin/clang-19+0x362dd86)
#14 0x000055fc3a28c654 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/eve/Downloads/llvm-project/build2/bin/clang-19+0x35a3654)
#15 0x000055fc3a3d293e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/eve/Downloads/llvm-project/build2/bin/clang-19+0x36e993e)
#16 0x000055fc37b20c3c cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/eve/Downloads/llvm-project/build2/bin/clang-19+0xe37c3c)
#17 0x000055fc37b1dc71 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#18 0x000055fc3a0e9eb9 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::allocator<char>>*, bool*) const::$_0>(long) Job.cpp:0:0
#19 0x000055fc399e750c llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/home/eve/Downloads/llvm-project/build2/bin/clang-19+0x2cfe50c)
#20 0x000055fc3a0e9906 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (/home/eve/Downloads/llvm-project/build2/bin/clang-19+0x3400906)
#21 0x000055fc3a0abd57 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/home/eve/Downloads/llvm-project/build2/bin/clang-19+0x33c2d57)
#22 0x000055fc3a0ac1fe clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/home/eve/Downloads/llvm-project/build2/bin/clang-19+0x33c31fe)
#23 0x000055fc3a0ca5df clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/home/eve/Downloads/llvm-project/build2/bin/clang-19+0x33e15df)
#24 0x000055fc37b1d338 clang_main(int, char**, llvm::ToolContext const&) (/home/eve/Downloads/llvm-project/build2/bin/clang-19+0xe34338)
#25 0x000055fc37b2b8d7 main (/home/eve/Downloads/llvm-project/build2/bin/clang-19+0xe428d7)
#26 0x00007f7639a28150 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#27 0x00007f7639a28209 call_init ./csu/../csu/libc-start.c:128:20
#28 0x00007f7639a28209 __libc_start_main ./csu/../csu/libc-start.c:347:5
#29 0x000055fc37b1a4b5 _start (/home/eve/Downloads/llvm-project/build2/bin/clang-19+0xe314b5)
clang: error: clang frontend command failed with exit code 139 (use -v to see invocation)
clang version 19.0.0git (https://github.com/llvm/llvm-project.git 3bdc4c702dfdd1f2fb513943f034d49bb79ded29)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/eve/Downloads/llvm-project/build2/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/vsprintf-e230c3.c
clang: note: diagnostic msg: /tmp/vsprintf-e230c3.sh
clang: note: diagnostic msg: 

********************

```
[vsprintf-e230c3.zip](https://github.com/llvm/llvm-project/files/14254556/vsprintf-e230c3.zip)

This issue occurs at commit:
```
commit 3bdc4c702dfdd1f2fb513943f034d49bb79ded29 (HEAD -> main, origin/main, origin/HEAD)
Author: Kevin Frei <kevinfrei@users.noreply.github.com>
Date:   Mon Feb 12 16:57:02 2024 -0800
```

This issue does not occur at commit:
```
commit 63b414e4977d6e19f05947c88f57cd127fa328e3
Author: Vlad Serebrennikov <serebrennikov.vladislav@gmail.com>
Date:   Sun Feb 11 15:01:18 2024 +0300
```
Edit: this issue also occurs at commit:
```
commit 13d60ce2f262ef9055389908b63824e53b3054a1 (HEAD)
Author: Amir Ayupov <aaupov@fb.com>
Date:   Mon Feb 12 14:51:15 2024 -0800
```
This issue does not occur at commit:
```
commit f5fd0deb2371d0bae3bef2563f50e005a140fc6d (HEAD)
Author: Joseph Huber <huberjn@outlook.com>
Date:   Mon Feb 12 08:14:54 2024 -0600
```

Comments: author: ms178
body: CC'ing @nathanchance for awareness.
author: nathanchance
body: Caused by 5c9f7682b090124d9a8b69f92d3f7c269dca25fc, which was reverted in bc66e0cf9feb8f3c38fa2e33850b6c6e5477fb21 and forward fixed by 97088b2ab2184ad4bd64f59fba0b92b70468b10d. I can confirm that there is no crash at 5e3c7e3aa48356a62a4b70d5d9d3e4ddd055a390.

Fix patch:
commit 97088b2ab2184ad4bd64f59fba0b92b70468b10d
Author: Orlando Cazalet-Hyams <orlando.hyams@sony.com>
Date:   Tue Feb 13 11:35:28 2024 +0000

    [RemoveDIs][ValueMapper] Remap DIAssignIDs in DPValues  (#81595)
    
    Fix crash raised in comments for 5c9f7682b090124d9a8b69f92d3f7c269dca25fc

diff --git a/llvm/lib/Transforms/Utils/ValueMapper.cpp b/llvm/lib/Transforms/Utils/ValueMapper.cpp
index a8ae3ee3b251..93a4c829df06 100644
--- a/llvm/lib/Transforms/Utils/ValueMapper.cpp
+++ b/llvm/lib/Transforms/Utils/ValueMapper.cpp
@@ -552,6 +552,7 @@ void Mapper::remapDPValue(DPValue &V) {
       V.setKillAddress();
     else if (NewAddr)
       V.setAddress(NewAddr);
+    V.setAssignId(cast<DIAssignID>(mapMetadata(V.getAssignID())));
   }
 
   // Find Value operands and remap those.


Regression tests:
file: llvm/test/DebugInfo/Generic/ipsccp-remap-assign-id.ll
commands: opt -passes=ipsccp %s -S -o -
opt --try-experimental-debuginfo-iterators -passes=ipsccp %s -S -o -
tests: test_name: <module>
test_body: 
;; Check the dbg.assign DIAssignID operand gets remapped after cloning.

;

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare void @llvm.dbg.declare(metadata, metadata, metadata)

define void @inv_txfm_add_dct_dct_4x4_c() {
entry:
  call void @inv_txfm_add_c(ptr @dav1d_inv_dct4_1d_c)
  ret void
}

declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg)

; Function Attrs: noinline
define void @inv_txfm_add_c(ptr %first_1d_fn) #2 {
entry:
  %tmp = alloca [4096 x i32], i32 0, align 16, !DIAssignID !5
  tail call void @llvm.dbg.assign(metadata i1 undef, metadata !6, metadata !DIExpression(), metadata !5, metadata ptr %tmp, metadata !DIExpression()), !dbg !16
  call void @llvm.memset.p0.i64(ptr %tmp, i8 0, i64 0, i1 false), !DIAssignID !17
  call void %first_1d_fn(ptr null, i64 0, i32 0, i32 0)
  ret void
}

declare void @dav1d_inv_dct4_1d_c(ptr, i64, i32, i32)

declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata)

attributes #2 = { noinline }

!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!3, !4}

!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !2, splitDebugInlining: false, nameTableKind: GNU)
!1 = !DIFile(filename: "itx_tmpl.c", directory: ".")
!2 = !{}
!3 = !{i32 2, !"Debug Info Version", i32 3}
!4 = !{i32 7, !"debug-info-assignment-tracking", i1 true}
!5 = distinct !DIAssignID()
!6 = !DILocalVariable(name: "tmp", scope: !7, file: !1, line: 78, type: !10)
!7 = distinct !DISubprogram(name: "inv_txfm_add_c", scope: !1, file: !1, line: 41, type: !8, scopeLine: 45, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
!8 = distinct !DISubroutineType(types: !9)
!9 = !{null}
!10 = !DICompositeType(tag: DW_TAG_array_type, baseType: !11, size: 131072, elements: !2)
!11 = !DIDerivedType(tag: DW_TAG_typedef, name: "int32_t", file: !12, line: 26, baseType: !13)
!12 = !DIFile(filename: "stdint-intn.h", directory: ".")
!13 = !DIDerivedType(tag: DW_TAG_typedef, name: "__int32_t", file: !14, line: 41, baseType: !15)
!14 = !DIFile(filename: "types.h", directory: ".")
!15 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!16 = !DILocation(line: 0, scope: !7)
!17 = distinct !DIAssignID()