https://github.com/tgs-sc created
https://github.com/llvm/llvm-project/pull/157674
During debugging applization with __bf16 and _Float16 float types it was
discovered that lldb creates the same CompilerType for them. This can cause an
infinite recursion error, if one tries to create two struct specializations
with these types and then inherit one specialization from another. This is an
example, provided by @Michael137:
```c++
template <typename T> struct Foo;
template <> struct Foo<__bf16> {};
template <> struct Foo<_Float16> : Foo<__bf16> {};
int main() {
Foo<_Float16> f1;
return 0;
}
```
>From a7bb3bdc0ab5ac584ed5ff956e010901f9cf5d88 Mon Sep 17 00:00:00 2001
From: Timur Golubovich <[email protected]>
Date: Tue, 9 Sep 2025 13:39:33 +0000
Subject: [PATCH] [lldb][TypeSystemClang] Added unique builtins types for
__bf16 and _Float16
During debugging applization with __bf16 and _Float16 float types it
was discovered that lldb creates the same CompilerType for them. This
can cause an infinite recursion error, if one tries to create two
struct specializations with these types and then inherit one
specialization from another. This is an example, provided by @Michael137:
```c++
template <typename T> struct Foo;
template <> struct Foo<__bf16> {};
template <> struct Foo<_Float16> : Foo<__bf16> {};
int main() {
Foo<_Float16> f1;
return 0;
}
```
---
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp | 7 +++++++
.../cpp/template-arguments/TestCppTemplateArguments.py | 2 +-
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index c4a917f59fb88..804ddd042574e 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -959,6 +959,12 @@ CompilerType
TypeSystemClang::GetBuiltinTypeForDWARFEncodingAndBitSize(
if (type_name == "long double" &&
QualTypeMatchesBitSize(bit_size, ast, ast.LongDoubleTy))
return GetType(ast.LongDoubleTy);
+ if (type_name == "__bf16" &&
+ QualTypeMatchesBitSize(bit_size, ast, ast.BFloat16Ty))
+ return GetType(ast.BFloat16Ty);
+ if (type_name == "_Float16" &&
+ QualTypeMatchesBitSize(bit_size, ast, ast.Float16Ty))
+ return GetType(ast.Float16Ty);
// As Rust currently uses `TypeSystemClang`, match `f128` here as well so
it
// doesn't get misinterpreted as `long double` on targets where they are
// the same size but different formats.
@@ -1791,6 +1797,7 @@ bool TypeSystemClang::RecordHasFields(const RecordDecl
*record_decl) {
for (base_class = cxx_record_decl->bases_begin(),
base_class_end = cxx_record_decl->bases_end();
base_class != base_class_end; ++base_class) {
+ assert(record_decl != base_class->getType()->getAsCXXRecordDecl());
if (RecordHasFields(base_class->getType()->getAsCXXRecordDecl()))
return true;
}
diff --git
a/lldb/test/API/lang/cpp/template-arguments/TestCppTemplateArguments.py
b/lldb/test/API/lang/cpp/template-arguments/TestCppTemplateArguments.py
index eac7b5ef1099a..f26d382bf8582 100644
--- a/lldb/test/API/lang/cpp/template-arguments/TestCppTemplateArguments.py
+++ b/lldb/test/API/lang/cpp/template-arguments/TestCppTemplateArguments.py
@@ -82,7 +82,7 @@ def test(self):
value = self.expect_expr("temp7", result_type="Foo<__fp16, __fp16>")
self.assertFalse(value.GetType().GetTemplateArgumentValue(target, 1))
- value = self.expect_expr("temp8", result_type="Foo<__fp16, __fp16>")
+ value = self.expect_expr("temp8", result_type="Foo<__bf16, __bf16>")
self.assertFalse(value.GetType().GetTemplateArgumentValue(target, 1))
value = self.expect_expr("temp9", result_type="Bar<double,
1.200000e+00>")
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits