summaryrefslogtreecommitdiff
path: root/lldb/test/API/lang/cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/test/API/lang/cpp')
-rw-r--r--lldb/test/API/lang/cpp/abi_tag_structors/TestAbiTagStructors.py33
-rw-r--r--lldb/test/API/lang/cpp/expr-definition-in-dylib/TestExprDefinitionInDylib.py20
-rw-r--r--lldb/test/API/lang/cpp/floating-types-specialization/Makefile3
-rw-r--r--lldb/test/API/lang/cpp/floating-types-specialization/TestCppFloatingTypesSpecialization.py37
-rw-r--r--lldb/test/API/lang/cpp/floating-types-specialization/main.cpp11
-rw-r--r--lldb/test/API/lang/cpp/function-call-from-object-file/Makefile3
-rw-r--r--lldb/test/API/lang/cpp/function-call-from-object-file/TestFunctionCallFromObjectFile.py29
-rw-r--r--lldb/test/API/lang/cpp/function-call-from-object-file/common.h8
-rw-r--r--lldb/test/API/lang/cpp/function-call-from-object-file/lib1.cpp8
-rw-r--r--lldb/test/API/lang/cpp/function-call-from-object-file/lib2.cpp6
-rw-r--r--lldb/test/API/lang/cpp/function-call-from-object-file/main.cpp10
-rw-r--r--lldb/test/API/lang/cpp/structured-binding/TestStructuredBinding.py31
-rw-r--r--lldb/test/API/lang/cpp/template-arguments/TestCppTemplateArguments.py9
13 files changed, 186 insertions, 22 deletions
diff --git a/lldb/test/API/lang/cpp/abi_tag_structors/TestAbiTagStructors.py b/lldb/test/API/lang/cpp/abi_tag_structors/TestAbiTagStructors.py
index 87d8adb42b82..2d3e4f7cdd47 100644
--- a/lldb/test/API/lang/cpp/abi_tag_structors/TestAbiTagStructors.py
+++ b/lldb/test/API/lang/cpp/abi_tag_structors/TestAbiTagStructors.py
@@ -10,6 +10,11 @@ from lldbsuite.test import lldbutil
class AbiTagStructorsTestCase(TestBase):
+ @skipIf(
+ compiler="clang",
+ compiler_version=["<", "22"],
+ bugnumber="Required Clang flag not supported",
+ )
@expectedFailureAll(oslist=["windows"])
def test_with_structor_linkage_names(self):
self.build(dictionary={"CXXFLAGS_EXTRAS": "-gstructor-decl-linkage-names"})
@@ -73,7 +78,16 @@ class AbiTagStructorsTestCase(TestBase):
Test that without linkage names on structor declarations we can't call
ABI-tagged structors.
"""
- self.build(dictionary={"CXXFLAGS_EXTRAS": "-gno-structor-decl-linkage-names"})
+ # In older versions of Clang the -gno-structor-decl-linkage-names
+ # behaviour was the default.
+ if self.expectedCompiler(["clang"]) and self.expectedCompilerVersion(
+ [">=", "22.0"]
+ ):
+ self.build(
+ dictionary={"CXXFLAGS_EXTRAS": "-gno-structor-decl-linkage-names"}
+ )
+ else:
+ self.build()
lldbutil.run_to_source_breakpoint(
self, "Break here", lldb.SBFileSpec("main.cpp", False)
@@ -105,12 +119,23 @@ class AbiTagStructorsTestCase(TestBase):
"expression TaggedLocal()", error=True, substrs=["Couldn't look up symbols"]
)
+ @skipIf(compiler="clang", compiler_version=["<", "22"])
@expectedFailureAll(oslist=["windows"])
- def test_nested_no_structor_linkage_names(self):
+ def test_nested_with_structor_linkage_names(self):
self.build(dictionary={"CXXFLAGS_EXTRAS": "-gstructor-decl-linkage-names"})
self.do_nested_structor_test()
@expectedFailureAll(oslist=["windows"])
- def test_nested_with_structor_linkage_names(self):
- self.build(dictionary={"CXXFLAGS_EXTRAS": "-gno-structor-decl-linkage-names"})
+ def test_nested_no_structor_linkage_names(self):
+ # In older versions of Clang the -gno-structor-decl-linkage-names
+ # behaviour was the default.
+ if self.expectedCompiler(["clang"]) and self.expectedCompilerVersion(
+ [">=", "22.0"]
+ ):
+ self.build(
+ dictionary={"CXXFLAGS_EXTRAS": "-gno-structor-decl-linkage-names"}
+ )
+ else:
+ self.build()
+
self.do_nested_structor_test()
diff --git a/lldb/test/API/lang/cpp/expr-definition-in-dylib/TestExprDefinitionInDylib.py b/lldb/test/API/lang/cpp/expr-definition-in-dylib/TestExprDefinitionInDylib.py
index c0545c70c84e..b3bed43c7587 100644
--- a/lldb/test/API/lang/cpp/expr-definition-in-dylib/TestExprDefinitionInDylib.py
+++ b/lldb/test/API/lang/cpp/expr-definition-in-dylib/TestExprDefinitionInDylib.py
@@ -6,6 +6,11 @@ from lldbsuite.test import lldbutil
class ExprDefinitionInDylibTestCase(TestBase):
+ @skipIf(
+ compiler="clang",
+ compiler_version=["<", "22"],
+ bugnumber="Required Clang flag not supported",
+ )
@skipIfWindows
def test_with_structor_linkage_names(self):
"""
@@ -74,7 +79,16 @@ class ExprDefinitionInDylibTestCase(TestBase):
Tests that if structor declarations don't have linkage names, we can't
call ABI-tagged constructors. But non-tagged ones are fine.
"""
- self.build(dictionary={"CXXFLAGS_EXTRAS": "-gno-structor-decl-linkage-names"})
+ # In older versions of Clang the -gno-structor-decl-linkage-names
+ # behaviour was the default.
+ if self.expectedCompiler(["clang"]) and self.expectedCompilerVersion(
+ [">=", "22.0"]
+ ):
+ self.build(
+ dictionary={"CXXFLAGS_EXTRAS": "-gno-structor-decl-linkage-names"}
+ )
+ else:
+ self.build()
target = self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
self.assertTrue(target, VALID_TARGET)
@@ -95,6 +109,6 @@ class ExprDefinitionInDylibTestCase(TestBase):
self.expect_expr("Foo(10)", result_type="Foo")
- self.expect("Base()", error=True)
+ self.expect("expr Base()", error=True)
- self.expect("Bar()", error=True)
+ self.expect("expr Bar()", error=True)
diff --git a/lldb/test/API/lang/cpp/floating-types-specialization/Makefile b/lldb/test/API/lang/cpp/floating-types-specialization/Makefile
new file mode 100644
index 000000000000..99998b20bcb0
--- /dev/null
+++ b/lldb/test/API/lang/cpp/floating-types-specialization/Makefile
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp
+
+include Makefile.rules
diff --git a/lldb/test/API/lang/cpp/floating-types-specialization/TestCppFloatingTypesSpecialization.py b/lldb/test/API/lang/cpp/floating-types-specialization/TestCppFloatingTypesSpecialization.py
new file mode 100644
index 000000000000..979391f3681f
--- /dev/null
+++ b/lldb/test/API/lang/cpp/floating-types-specialization/TestCppFloatingTypesSpecialization.py
@@ -0,0 +1,37 @@
+import lldb
+import lldbsuite.test.lldbplatformutil as lldbplatformutil
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class TestCase(TestBase):
+ @skipIf(compiler="clang", compiler_version=["<", "17.0"])
+ def test(self):
+ self.build()
+ lldbutil.run_to_source_breakpoint(
+ self, "// break here", lldb.SBFileSpec("main.cpp", False)
+ )
+
+ # On 32-bit Arm, you have to have the bfloat16 extension, or an FPU while
+ # not using the soft float mode. The target we assume has none of that
+ # so instead of __bf16 we get __fp16.
+ is_arm_32_bit = lldbplatformutil.getArchitecture() == "arm"
+
+ self.expect_expr(
+ "f0", result_type=("Foo<__fp16>" if is_arm_32_bit else "Foo<__bf16>")
+ )
+
+ # When __bf16 is actually __fp16, f1 looks like it inherits from itself.
+ # Which clang allows but LLDB fails to evaluate.
+ if not is_arm_32_bit:
+ self.expect_expr("f1", result_type="Foo<__fp16>")
+
+ # Test sizeof to ensure while computing layout we don't do
+ # infinite recursion.
+ v = self.frame().EvaluateExpression("sizeof(f0)")
+ self.assertEqual(v.GetValueAsUnsigned() > 0, True)
+
+ if not is_arm_32_bit:
+ v = self.frame().EvaluateExpression("sizeof(f1)")
+ self.assertEqual(v.GetValueAsUnsigned() > 0, True)
diff --git a/lldb/test/API/lang/cpp/floating-types-specialization/main.cpp b/lldb/test/API/lang/cpp/floating-types-specialization/main.cpp
new file mode 100644
index 000000000000..e3e8a3767fef
--- /dev/null
+++ b/lldb/test/API/lang/cpp/floating-types-specialization/main.cpp
@@ -0,0 +1,11 @@
+template <typename T> struct Foo;
+
+template <> struct Foo<__bf16> {};
+
+template <> struct Foo<_Float16> : Foo<__bf16> {};
+
+int main() {
+ Foo<__bf16> f0;
+ Foo<_Float16> f1;
+ return 0; // break here
+}
diff --git a/lldb/test/API/lang/cpp/function-call-from-object-file/Makefile b/lldb/test/API/lang/cpp/function-call-from-object-file/Makefile
new file mode 100644
index 000000000000..285bbfbbca4f
--- /dev/null
+++ b/lldb/test/API/lang/cpp/function-call-from-object-file/Makefile
@@ -0,0 +1,3 @@
+CXX_SOURCES := main.cpp lib1.cpp lib2.cpp
+
+include Makefile.rules
diff --git a/lldb/test/API/lang/cpp/function-call-from-object-file/TestFunctionCallFromObjectFile.py b/lldb/test/API/lang/cpp/function-call-from-object-file/TestFunctionCallFromObjectFile.py
new file mode 100644
index 000000000000..f0a7aef182a6
--- /dev/null
+++ b/lldb/test/API/lang/cpp/function-call-from-object-file/TestFunctionCallFromObjectFile.py
@@ -0,0 +1,29 @@
+"""
+Tests that we can call functions that have definitions in multiple
+CUs in the debug-info (which is the case for functions defined in headers).
+The linker will most likely de-duplicate the functiond definitions when linking
+the final executable. On Darwin, this will create a debug-map that LLDB will use
+to fix up object file addresses to addresses in the linked executable. However,
+if we parsed the DIE from the object file whose functiond definition got stripped
+by the linker, LLDB needs to ensure it can still resolve the function symbol it
+got for it.
+"""
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class TestFunctionCallFromObjectFile(TestBase):
+ def test_lib1(self):
+ self.build()
+ lldbutil.run_to_name_breakpoint(self, "lib1_func")
+
+ self.expect_expr("Foo{}.foo()", result_type="int", result_value="15")
+
+ def test_lib2(self):
+ self.build()
+ lldbutil.run_to_name_breakpoint(self, "lib2_func")
+
+ self.expect_expr("Foo{}.foo()", result_type="int", result_value="15")
diff --git a/lldb/test/API/lang/cpp/function-call-from-object-file/common.h b/lldb/test/API/lang/cpp/function-call-from-object-file/common.h
new file mode 100644
index 000000000000..76e23be6b97a
--- /dev/null
+++ b/lldb/test/API/lang/cpp/function-call-from-object-file/common.h
@@ -0,0 +1,8 @@
+#ifndef COMMON_H_IN
+#define COMMON_H_IN
+
+struct Foo {
+ int foo() { return 15; }
+};
+
+#endif // COMMON_H_IN
diff --git a/lldb/test/API/lang/cpp/function-call-from-object-file/lib1.cpp b/lldb/test/API/lang/cpp/function-call-from-object-file/lib1.cpp
new file mode 100644
index 000000000000..b97bcc1b712b
--- /dev/null
+++ b/lldb/test/API/lang/cpp/function-call-from-object-file/lib1.cpp
@@ -0,0 +1,8 @@
+#include "common.h"
+
+// Parameter "Foo*" forces LLDB to parse "Foo" from the object
+// file that it is stopped in.
+void lib1_func(Foo *) {
+ // Force definition into lib1.o debug-info.
+ Foo{}.foo();
+}
diff --git a/lldb/test/API/lang/cpp/function-call-from-object-file/lib2.cpp b/lldb/test/API/lang/cpp/function-call-from-object-file/lib2.cpp
new file mode 100644
index 000000000000..2f9d81a8bdf4
--- /dev/null
+++ b/lldb/test/API/lang/cpp/function-call-from-object-file/lib2.cpp
@@ -0,0 +1,6 @@
+#include "common.h"
+
+void lib2_func(Foo *) {
+ // Force definition into lib2.o debug-info.
+ Foo{}.foo();
+}
diff --git a/lldb/test/API/lang/cpp/function-call-from-object-file/main.cpp b/lldb/test/API/lang/cpp/function-call-from-object-file/main.cpp
new file mode 100644
index 000000000000..61ca798daf1d
--- /dev/null
+++ b/lldb/test/API/lang/cpp/function-call-from-object-file/main.cpp
@@ -0,0 +1,10 @@
+struct Foo;
+
+extern void lib1_func(Foo *);
+extern void lib2_func(Foo *);
+
+int main() {
+ lib1_func(nullptr);
+ lib2_func(nullptr);
+ return 0;
+}
diff --git a/lldb/test/API/lang/cpp/structured-binding/TestStructuredBinding.py b/lldb/test/API/lang/cpp/structured-binding/TestStructuredBinding.py
index 5f939ecfbef2..882c91d1ce8c 100644
--- a/lldb/test/API/lang/cpp/structured-binding/TestStructuredBinding.py
+++ b/lldb/test/API/lang/cpp/structured-binding/TestStructuredBinding.py
@@ -99,16 +99,21 @@ class TestStructuredBinding(TestBase):
self.expect_expr("ty2", result_value="'z'")
self.expect_expr("tz2", result_value="10")
- self.expect(
- "frame variable",
- substrs=[
- "tx1 =",
- "ty1 =",
- "tz1 =",
- "tx2 =",
- "ty2 =",
- "tz2 =",
- "mp1 =",
- "mp2 =",
- ],
- )
+ # Older versions of Clang marked structured binding variables
+ # as artificial, and thus LLDB wouldn't display them.
+ if self.expectedCompiler(["clang"]) and self.expectedCompilerVersion(
+ [">=", "22.0"]
+ ):
+ self.expect(
+ "frame variable",
+ substrs=[
+ "tx1 =",
+ "ty1 =",
+ "tz1 =",
+ "tx2 =",
+ "ty2 =",
+ "tz2 =",
+ "mp1 =",
+ "mp2 =",
+ ],
+ )
diff --git a/lldb/test/API/lang/cpp/template-arguments/TestCppTemplateArguments.py b/lldb/test/API/lang/cpp/template-arguments/TestCppTemplateArguments.py
index eac7b5ef1099..83c057220410 100644
--- a/lldb/test/API/lang/cpp/template-arguments/TestCppTemplateArguments.py
+++ b/lldb/test/API/lang/cpp/template-arguments/TestCppTemplateArguments.py
@@ -1,4 +1,5 @@
import lldb
+import lldbsuite.test.lldbplatformutil as lldbplatformutil
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
@@ -82,8 +83,12 @@ class TestCase(TestBase):
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>")
- self.assertFalse(value.GetType().GetTemplateArgumentValue(target, 1))
+ # The target we use when evaluating these expressions for Arm leads to there
+ # not being a __bf16 type in the AST so we fall back to __fp16 and evaluating
+ # this fails.
+ if lldbplatformutil.getArchitecture() != "arm":
+ 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>")
template_param_value = value.GetType().GetTemplateArgumentValue(target, 1)