Skip to content

Commit 7461016

Browse files
committed
[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.
1 parent 2e9494f commit 7461016

File tree

5 files changed

+45
-1
lines changed

5 files changed

+45
-1
lines changed

lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,12 @@ CompilerType TypeSystemClang::GetBuiltinTypeForDWARFEncodingAndBitSize(
959959
if (type_name == "long double" &&
960960
QualTypeMatchesBitSize(bit_size, ast, ast.LongDoubleTy))
961961
return GetType(ast.LongDoubleTy);
962+
if (type_name == "__bf16" &&
963+
QualTypeMatchesBitSize(bit_size, ast, ast.BFloat16Ty))
964+
return GetType(ast.BFloat16Ty);
965+
if (type_name == "_Float16" &&
966+
QualTypeMatchesBitSize(bit_size, ast, ast.Float16Ty))
967+
return GetType(ast.Float16Ty);
962968
// As Rust currently uses `TypeSystemClang`, match `f128` here as well so it
963969
// doesn't get misinterpreted as `long double` on targets where they are
964970
// the same size but different formats.
@@ -1791,6 +1797,8 @@ bool TypeSystemClang::RecordHasFields(const RecordDecl *record_decl) {
17911797
for (base_class = cxx_record_decl->bases_begin(),
17921798
base_class_end = cxx_record_decl->bases_end();
17931799
base_class != base_class_end; ++base_class) {
1800+
assert(record_decl != base_class->getType()->getAsCXXRecordDecl() &&
1801+
"Base can't inherit from itself.");
17941802
if (RecordHasFields(base_class->getType()->getAsCXXRecordDecl()))
17951803
return true;
17961804
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CXX_SOURCES := main.cpp
2+
3+
include Makefile.rules
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import lldb
2+
from lldbsuite.test.decorators import *
3+
from lldbsuite.test.lldbtest import *
4+
from lldbsuite.test import lldbutil
5+
6+
7+
class TestCase(TestBase):
8+
def test(self):
9+
self.build()
10+
lldbutil.run_to_source_breakpoint(
11+
self, "// break here", lldb.SBFileSpec("main.cpp", False)
12+
)
13+
14+
self.expect_expr("f0", result_type="Foo<__bf16>")
15+
self.expect_expr("f1", result_type="Foo<__fp16>")
16+
17+
# Test sizeof to ensure while computing layout we don't do
18+
# infinite recursion.
19+
v = self.frame().EvaluateExpression("sizeof(f0)")
20+
self.assertEqual(v.GetValueAsUnsigned() > 0, True)
21+
v = self.frame().EvaluateExpression("sizeof(f1)")
22+
self.assertEqual(v.GetValueAsUnsigned() > 0, True)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
template <typename T> struct Foo;
2+
3+
template <> struct Foo<__bf16> {};
4+
5+
template <> struct Foo<_Float16> : Foo<__bf16> {};
6+
7+
int main() {
8+
Foo<__bf16> f0;
9+
Foo<_Float16> f1;
10+
return 0; // break here
11+
}

lldb/test/API/lang/cpp/template-arguments/TestCppTemplateArguments.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def test(self):
8282
value = self.expect_expr("temp7", result_type="Foo<__fp16, __fp16>")
8383
self.assertFalse(value.GetType().GetTemplateArgumentValue(target, 1))
8484

85-
value = self.expect_expr("temp8", result_type="Foo<__fp16, __fp16>")
85+
value = self.expect_expr("temp8", result_type="Foo<__bf16, __bf16>")
8686
self.assertFalse(value.GetType().GetTemplateArgumentValue(target, 1))
8787

8888
value = self.expect_expr("temp9", result_type="Bar<double, 1.200000e+00>")

0 commit comments

Comments
 (0)