Author: Raphael Isemann Date: 2020-06-19T16:22:16+02:00 New Revision: 3e66bd291f1fbf381c3e0cac528ed4f6030cf714
URL: https://github.com/llvm/llvm-project/commit/3e66bd291f1fbf381c3e0cac528ed4f6030cf714 DIFF: https://github.com/llvm/llvm-project/commit/3e66bd291f1fbf381c3e0cac528ed4f6030cf714.diff LOG: [lldb][NFC] Add test for C99 and GCC complex types LLDB has a lot of code for supporting complex types but we don't have a single test for it. This adds some basic tests and documents the found bugs. Added: lldb/test/API/lang/c/complex/Makefile lldb/test/API/lang/c/complex/TestComplexC99.py lldb/test/API/lang/c/complex/main.c lldb/test/API/lang/c/complex_int/Makefile lldb/test/API/lang/c/complex_int/TestComplexInt.py lldb/test/API/lang/c/complex_int/main.c Modified: Removed: ################################################################################ diff --git a/lldb/test/API/lang/c/complex/Makefile b/lldb/test/API/lang/c/complex/Makefile new file mode 100644 index 000000000000..695335e068c0 --- /dev/null +++ b/lldb/test/API/lang/c/complex/Makefile @@ -0,0 +1,4 @@ +C_SOURCES := main.c +CFLAGS_EXTRAS := -std=c99 + +include Makefile.rules diff --git a/lldb/test/API/lang/c/complex/TestComplexC99.py b/lldb/test/API/lang/c/complex/TestComplexC99.py new file mode 100644 index 000000000000..c30fcbc5118b --- /dev/null +++ b/lldb/test/API/lang/c/complex/TestComplexC99.py @@ -0,0 +1,29 @@ +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class TestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @no_debug_info_test + def test(self): + self.build() + lldbutil.run_to_source_breakpoint(self, "// break here", lldb.SBFileSpec("main.c")) + + self.expect_expr("complex_float", result_type="_Complex float", result_value="-1.5 + -2.5i") + self.expect_expr("complex_float + (2.0f + 3.5fi)", result_type="_Complex float", result_value="0.5 + 1i") + + self.expect_expr("complex_double", result_type="_Complex double", result_value="-1.5 + -2.5i") + self.expect_expr("complex_double + (2.0 + 3.5i)", result_type="_Complex double", result_value="0.5 + 1i") + + @no_debug_info_test + # FIXME: LLDB fails to read the imaginary part of the number. + @expectedFailureAll() + def test_long_double(self): + self.build() + lldbutil.run_to_source_breakpoint(self, "// break here", lldb.SBFileSpec("main.c")) + + self.expect_expr("complex_long_double", result_type="_Complex long double", result_value="-1.5 + 1i") + self.expect_expr("complex_long_double + (2.0L + 3.5Li)", result_type="_Complex long double", result_value="0.5 + 1i") diff --git a/lldb/test/API/lang/c/complex/main.c b/lldb/test/API/lang/c/complex/main.c new file mode 100644 index 000000000000..eadc896ea231 --- /dev/null +++ b/lldb/test/API/lang/c/complex/main.c @@ -0,0 +1,8 @@ +#include <complex.h> + +int main() { + float complex complex_float = -1.5f + -2.5f * I; + double complex complex_double = -1.5 + -2.5 * I; + long double complex complex_long_double = -1.5L + -2.5L * I; + return 0; // break here +} diff --git a/lldb/test/API/lang/c/complex_int/Makefile b/lldb/test/API/lang/c/complex_int/Makefile new file mode 100644 index 000000000000..10495940055b --- /dev/null +++ b/lldb/test/API/lang/c/complex_int/Makefile @@ -0,0 +1,3 @@ +C_SOURCES := main.c + +include Makefile.rules diff --git a/lldb/test/API/lang/c/complex_int/TestComplexInt.py b/lldb/test/API/lang/c/complex_int/TestComplexInt.py new file mode 100644 index 000000000000..8d9344ee0f7a --- /dev/null +++ b/lldb/test/API/lang/c/complex_int/TestComplexInt.py @@ -0,0 +1,34 @@ +""" +Tests GCC's complex integer types. +""" + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class TestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @no_debug_info_test + def test(self): + self.build() + lldbutil.run_to_source_breakpoint(self, "// break here", lldb.SBFileSpec("main.c")) + + # FIXME: LLDB treats all complex ints as unsigned, so the value is wrong. + self.expect_expr("complex_int", result_type="_Complex int", result_value="4294967295 + 4294967294i") + self.expect_expr("complex_long", result_type="_Complex long") + + self.expect_expr("complex_unsigned", result_type="_Complex int", result_value="1 + 2i") + self.expect_expr("complex_unsigned_long", result_type="_Complex long", result_value="1 + 2i") + + @no_debug_info_test + def test_long_long(self): + self.build() + lldbutil.run_to_source_breakpoint(self, "// break here", lldb.SBFileSpec("main.c")) + + # FIXME: We get the type wrong if long has the same size as long long. + # FIXME: LLDB treats all complex ints as unsigned, so the value is wrong. + self.expect_expr("complex_long_long", result_type="_Complex long") + self.expect_expr("complex_unsigned_long_long", result_type="_Complex long", result_value="1 + 2i") diff --git a/lldb/test/API/lang/c/complex_int/main.c b/lldb/test/API/lang/c/complex_int/main.c new file mode 100644 index 000000000000..fe88c6cf6c8a --- /dev/null +++ b/lldb/test/API/lang/c/complex_int/main.c @@ -0,0 +1,12 @@ +#include <complex.h> + +int main() { + int complex complex_int = -1 + -2 * I; + long complex complex_long = -1 + -2 * I; + long long complex complex_long_long = -1 + -2 * I; + + unsigned complex complex_unsigned = 1 + 2 * I; + unsigned long complex complex_unsigned_long = 1 + 2 * I; + unsigned long long complex complex_unsigned_long_long = 1 + 2 * I; + return 0; // break here +} _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits