Skip to content

"fatal error: unknown codeview register H1" when using @llvm.dbg.value on a half float parameter on aarch64-windows #56484

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
andrewrk opened this issue Jul 11, 2022 · 8 comments
Labels
backend:AArch64 bug Indicates an unexpected problem or unintended behavior debuginfo platform:windows

Comments

@andrewrk
Copy link
Member

andrewrk commented Jul 11, 2022

Repro

Tested with 14.0.6.

$ ~/local/llvm14-release/bin/clang-14 reduced.ll -target aarch64-windows-gnu
fatal error: error in backend: unknown codeview register H1
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: /home/andy/local/llvm14-release/bin/clang-14 -c test2.ll -target aarch64-windows-gnu
1.	Code generation
2.	Running pass 'Function Pass Manager' on module 'test2.ll'.
3.	Running pass 'AArch64 Assembly Printer' on function '@test2.isNan__anon_222'
 #0 0x0000000002f2bd20 PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
 #1 0x0000000002f29c5c llvm::sys::CleanupOnSignal(unsigned long) (/home/andy/local/llvm14-release/bin/clang-14+0x2f29c5c)
 #2 0x0000000002e67b84 llvm::CrashRecoveryContext::HandleExit(int) (/home/andy/local/llvm14-release/bin/clang-14+0x2e67b84)
 #3 0x0000000002f2226e llvm::sys::Process::Exit(int, bool) (/home/andy/local/llvm14-release/bin/clang-14+0x2f2226e)
 #4 0x0000000000a5b123 (/home/andy/local/llvm14-release/bin/clang-14+0xa5b123)
 #5 0x0000000002e6e5c2 llvm::report_fatal_error(llvm::Twine const&, bool) (/home/andy/local/llvm14-release/bin/clang-14+0x2e6e5c2)
 #6 0x0000000002af595c llvm::MCRegisterInfo::getCodeViewRegNum(llvm::MCRegister) const (/home/andy/local/llvm14-release/bin/clang-14+0x2af595c)
 #7 0x0000000003c7415a llvm::CodeViewDebug::calculateRanges(llvm::CodeViewDebug::LocalVariable&, llvm::SmallVector<llvm::DbgValueHistoryMap::Entry, 4u> const&) (/home/andy/local/llvm14-release/bin/clang-14+0x3c7415a)
 #8 0x0000000003c89fbc llvm::CodeViewDebug::collectVariableInfo(llvm::DISubprogram const*) (/home/andy/local/llvm14-release/bin/clang-14+0x3c89fbc)
 #9 0x0000000003c8a111 llvm::CodeViewDebug::endFunctionImpl(llvm::MachineFunction const*) (/home/andy/local/llvm14-release/bin/clang-14+0x3c8a111)
#10 0x0000000003c23677 llvm::DebugHandlerBase::endFunction(llvm::MachineFunction const*) (/home/andy/local/llvm14-release/bin/clang-14+0x3c23677)
#11 0x0000000003c1e591 llvm::AsmPrinter::emitFunctionBody() (/home/andy/local/llvm14-release/bin/clang-14+0x3c1e591)
#12 0x0000000000a6a6f8 (anonymous namespace)::AArch64AsmPrinter::runOnMachineFunction(llvm::MachineFunction&) AArch64AsmPrinter.cpp:0:0
#13 0x00000000021cdb14 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/home/andy/local/llvm14-release/bin/clang-14+0x21cdb14)
#14 0x0000000002638a00 llvm::FPPassManager::runOnFunction(llvm::Function&) (/home/andy/local/llvm14-release/bin/clang-14+0x2638a00)
#15 0x0000000002638b6c llvm::FPPassManager::runOnModule(llvm::Module&) (/home/andy/local/llvm14-release/bin/clang-14+0x2638b6c)
#16 0x000000000263a4f1 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/home/andy/local/llvm14-release/bin/clang-14+0x263a4f1)
#17 0x000000000325f2e1 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream> >) (/home/andy/local/llvm14-release/bin/clang-14+0x325f2e1)
#18 0x0000000003f6d0f8 clang::CodeGenAction::ExecuteAction() (/home/andy/local/llvm14-release/bin/clang-14+0x3f6d0f8)
#19 0x000000000391b219 clang::FrontendAction::Execute() (/home/andy/local/llvm14-release/bin/clang-14+0x391b219)
#20 0x00000000038aba6b clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/andy/local/llvm14-release/bin/clang-14+0x38aba6b)
#21 0x00000000039cb820 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/andy/local/llvm14-release/bin/clang-14+0x39cb820)
#22 0x0000000000a5c51c cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/andy/local/llvm14-release/bin/clang-14+0xa5c51c)
#23 0x0000000000a59479 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#24 0x00000000037325a5 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#25 0x0000000002e67a13 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/home/andy/local/llvm14-release/bin/clang-14+0x2e67a13)
#26 0x0000000003732904 clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, bool*) const (.part.0) Job.cpp:0:0
#27 0x0000000003705556 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&) const (/home/andy/local/llvm14-release/bin/clang-14+0x3705556)
#28 0x0000000003705f09 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) const (/home/andy/local/llvm14-release/bin/clang-14+0x3705f09)
#29 0x0000000003715409 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) (/home/andy/local/llvm14-release/bin/clang-14+0x3715409)

reduced.ll

define internal fastcc i1 @test2.isNan__anon_222(half %0) !dbg !33 {
Entry:
  call void @llvm.dbg.value(metadata half %0, metadata !40, metadata !DIExpression()), !dbg !42
  %1 = fcmp une half 0xH0000, %0, !dbg !43
  ret i1 %1
}

; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
declare void @llvm.dbg.value(metadata, metadata, metadata) #0

attributes #0 = { nofree nosync nounwind readnone speculatable willreturn }

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

!0 = !{i32 2, !"Debug Info Version", i32 3}
!1 = !{i32 2, !"CodeView", i32 1}
!2 = !{i32 7, !"PIC Level", i32 2}
!3 = distinct !DICompileUnit(language: DW_LANG_C99, file: !4, producer: "zig 0.10.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !5, globals: !27)
!4 = !DIFile(filename: "test2", directory: ".")
!5 = !{!6, !21}
!6 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "builtin.CompilerBackend", scope: !7, file: !7, line: 1222, baseType: !8, size: 64, align: 64, elements: !9)
!7 = !DIFile(filename: "builtin.zig", directory: "/home/andy/dev/zig/lib/std")
!8 = !DIBasicType(name: "u64", size: 64, encoding: DW_ATE_unsigned)
!9 = !{!10, !11, !12, !13, !14, !15, !16, !17, !18, !19, !20}
!10 = !DIEnumerator(name: "other", value: 0)
!11 = !DIEnumerator(name: "stage1", value: 1)
!12 = !DIEnumerator(name: "stage2_llvm", value: 2)
!13 = !DIEnumerator(name: "stage2_c", value: 3)
!14 = !DIEnumerator(name: "stage2_wasm", value: 4)
!15 = !DIEnumerator(name: "stage2_arm", value: 5)
!16 = !DIEnumerator(name: "stage2_x86_64", value: 6)
!17 = !DIEnumerator(name: "stage2_aarch64", value: 7)
!18 = !DIEnumerator(name: "stage2_x86", value: 8)
!19 = !DIEnumerator(name: "stage2_riscv64", value: 9)
!20 = !DIEnumerator(name: "stage2_sparc64", value: 10)
!21 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "builtin.OutputMode", scope: !7, file: !7, line: 533, baseType: !22, size: 8, align: 8, elements: !23)
!22 = !DIBasicType(name: "u2", size: 2, encoding: DW_ATE_unsigned)
!23 = !{!24, !25, !26}
!24 = !DIEnumerator(name: "Exe", value: 0)
!25 = !DIEnumerator(name: "Lib", value: 1)
!26 = !DIEnumerator(name: "Obj", value: 2)
!27 = !{!28, !31}
!28 = !DIGlobalVariableExpression(var: !29, expr: !DIExpression())
!29 = distinct !DIGlobalVariable(name: "zig_backend", linkageName: "builtin.zig_backend", scope: !30, file: !30, line: 5, type: !6, isLocal: true, isDefinition: true)
!30 = !DIFile(filename: "builtin.zig", directory: "zig-cache/o/dad7b6fae1ca78a1c1cb52547270f805")
!31 = !DIGlobalVariableExpression(var: !32, expr: !DIExpression())
!32 = distinct !DIGlobalVariable(name: "output_mode", linkageName: "builtin.output_mode", scope: !30, file: !30, line: 9, type: !21, isLocal: true, isDefinition: true)
!33 = distinct !DISubprogram(name: "isNan__anon_222", linkageName: "test2.isNan__anon_222", scope: !34, file: !34, line: 32, type: !35, scopeLine: 32, flags: DIFlagStaticMember, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !3, retainedNodes: !39)
!34 = !DIFile(filename: "test2.zig", directory: ".")
!35 = !DISubroutineType(types: !36)
!36 = !{!37, !38}
!37 = !DIBasicType(name: "bool", size: 1, encoding: DW_ATE_boolean)
!38 = !DIBasicType(name: "f16", size: 16, encoding: DW_ATE_float)
!39 = !{!40}
!40 = !DILocalVariable(name: "x", arg: 1, scope: !41, file: !34, line: 32, type: !38)
!41 = distinct !DILexicalBlock(scope: !33, file: !34, line: 32, column: 1)
!42 = !DILocation(line: 32, column: 31, scope: !41)
!43 = !DILocation(line: 33, column: 5, scope: !44)
!44 = distinct !DILexicalBlock(scope: !41, file: !34)
@andrewrk andrewrk added bug Indicates an unexpected problem or unintended behavior backend:AArch64 debuginfo platform:windows labels Jul 11, 2022
@llvmbot
Copy link
Member

llvmbot commented Jul 11, 2022

@llvm/issue-subscribers-bug

@llvmbot
Copy link
Member

llvmbot commented Jul 11, 2022

@llvm/issue-subscribers-backend-aarch64

@llvmbot
Copy link
Member

llvmbot commented Jul 11, 2022

@llvm/issue-subscribers-debuginfo

andrewrk added a commit to ziglang/zig that referenced this issue Jul 11, 2022
LLVM does not properly handle debug info for f16 on the aarch64-windows
target, causing "fatal error: unknown codeview register H1". The
previous workaround checked only for f16 but was still vulnerable if a
type was a byval struct or tuple which had an f16 field in it.

Now I have filed an upstream issue (see
llvm/llvm-project#56484) and broadened the
workaround to always skip debug values for this target.
andrewrk added a commit to ziglang/zig that referenced this issue Jul 12, 2022
LLVM does not properly handle debug info for f16 on the aarch64-windows
target, causing "fatal error: unknown codeview register H1". The
previous workaround checked only for f16 but was still vulnerable if a
type was a byval struct or tuple which had an f16 field in it.

Now I have filed an upstream issue (see
llvm/llvm-project#56484) and broadened the
workaround to always skip debug values for this target.
@DavidSpickett
Copy link
Collaborator

Still present on main as of 00797b88e0113aeea03045b18b3f63332f850dfe.

Picking H1 makes sense because half float is 16 bit. Then we're trying to get the codeview register number for that. Except codeview only has the 32 bit (S) and and 64 bit (D) registers. (llvm/include/llvm/DebugInfo/CodeView/CodeViewRegisters.def)

It's the same over in Microsoft's repo https://github.com/microsoft/microsoft-pdb/blob/master/include/cvconst.h#L1603. Though there's always a chance that isn't up to date I suppose.

I looked for half float support in msvc but I don't think it has it beyond https://docs.microsoft.com/en-us/windows/win32/dxmath/half-data-type but even if you use that I don't know that it would put it in a float register. None of the type names listed in https://clang.llvm.org/docs/LanguageExtensions.html#half-precision-floating-point work either.

But regardless it seems like it'd be fine to use the number for S1 instead. Any debugger would know the type of the variable anyway, just like if you have a uint16_t in a 64 bit register.

x86 puts the value in an XMM register which is along the same lines (maybe there is some special name for XMM as 16 bit elements but I don't know it).

Only problem is that the codeview mappings are put into a case statement in one place, so it'll need some refactoring to avoid duplicate values in that.

andrewrk added a commit to ziglang/zig that referenced this issue Jul 13, 2022
LLVM does not properly handle debug info for f16 on the aarch64-windows
target, causing "fatal error: unknown codeview register H1". The
previous workaround checked only for f16 but was still vulnerable if a
type was a byval struct or tuple which had an f16 field in it.

Now I have filed an upstream issue (see
llvm/llvm-project#56484) and broadened the
workaround to always skip debug values for this target.
vrischmann pushed a commit to vrischmann/zig that referenced this issue Jul 13, 2022
LLVM does not properly handle debug info for f16 on the aarch64-windows
target, causing "fatal error: unknown codeview register H1". The
previous workaround checked only for f16 but was still vulnerable if a
type was a byval struct or tuple which had an f16 field in it.

Now I have filed an upstream issue (see
llvm/llvm-project#56484) and broadened the
workaround to always skip debug values for this target.
@majnemer
Copy link
Contributor

ISTM that Microsoft has mappings for the half precision registers here.

@DavidSpickett
Copy link
Collaborator

Thanks! Also now I see from microsoft/microsoft-pdb#51 that that repo isn't up to date.

I'll fix the H registers at least. There's also B register mappings but I'm not sure I can get clang to emit them so I'll probably leave them out.

@DavidSpickett DavidSpickett self-assigned this Jul 14, 2022
@DavidSpickett
Copy link
Collaborator

And there'll be some changes to lldb but separate to the llvm change.

@DavidSpickett
Copy link
Collaborator

andrewrk added a commit to ziglang/zig that referenced this issue Jul 19, 2022
LLVM does not properly handle debug info for f16 on the aarch64-windows
target, causing "fatal error: unknown codeview register H1". The
previous workaround checked only for f16 but was still vulnerable if a
type was a byval struct or tuple which had an f16 field in it.

Now I have filed an upstream issue (see
llvm/llvm-project#56484) and broadened the
workaround to always skip debug values for this target.
wooster0 pushed a commit to wooster0/zig that referenced this issue Jul 24, 2022
LLVM does not properly handle debug info for f16 on the aarch64-windows
target, causing "fatal error: unknown codeview register H1". The
previous workaround checked only for f16 but was still vulnerable if a
type was a byval struct or tuple which had an f16 field in it.

Now I have filed an upstream issue (see
llvm/llvm-project#56484) and broadened the
workaround to always skip debug values for this target.
mem-frob pushed a commit to draperlaboratory/hope-llvm-project that referenced this issue Oct 7, 2022
Fixes llvm/llvm-project#56484

H registers are 16 bit views of AArch64's Neon registers and
B are the 8 bit views.

msvc does not support 16 bit float (some mention in DirectX but I
couldn't find a way to get to it) so for lack of a better reference
I'm using:
https://github.com/MicrosoftEdge/JsDbg/blob/85c9b41b33bb8f3496dbe400d912c32bb7cc496b/server/references/dia/include/cvconst.h
(the other microsoft-pdb repo is no longer up to date)

Luckily clang does support fp16 so a test is added for that.

There is no 8 bit float type so I had to get creative with the
test case. We're not testing for correct debug info here just
that we can select the B register and not crash in the process.

For FPCR it's never going to be passed as an argument so I've
not added a test for it. It is included to keep our list looking
the same as the reference.

Reviewed By: majnemer

Differential Revision: https://reviews.llvm.org/D129774
compnerd pushed a commit to swiftlang/llvm-project that referenced this issue Jan 6, 2023
Fixes llvm#56484

H registers are 16 bit views of AArch64's Neon registers and
B are the 8 bit views.

msvc does not support 16 bit float (some mention in DirectX but I
couldn't find a way to get to it) so for lack of a better reference
I'm using:
https://github.com/MicrosoftEdge/JsDbg/blob/85c9b41b33bb8f3496dbe400d912c32bb7cc496b/server/references/dia/include/cvconst.h
(the other microsoft-pdb repo is no longer up to date)

Luckily clang does support fp16 so a test is added for that.

There is no 8 bit float type so I had to get creative with the
test case. We're not testing for correct debug info here just
that we can select the B register and not crash in the process.

For FPCR it's never going to be passed as an argument so I've
not added a test for it. It is included to keep our list looking
the same as the reference.

Reviewed By: majnemer

Differential Revision: https://reviews.llvm.org/D129774

(cherry picked from commit 5d14873)
@DavidSpickett DavidSpickett removed their assignment Oct 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:AArch64 bug Indicates an unexpected problem or unintended behavior debuginfo platform:windows
Projects
None yet
Development

No branches or pull requests

4 participants