[lldb][NFC] Add test for C99 and GCC complex types
authorRaphael Isemann <teemperor@gmail.com>
Fri, 19 Jun 2020 12:47:15 +0000 (14:47 +0200)
committerRaphael Isemann <teemperor@gmail.com>
Fri, 19 Jun 2020 14:22:16 +0000 (16:22 +0200)
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.

lldb/test/API/lang/c/complex/Makefile [new file with mode: 0644]
lldb/test/API/lang/c/complex/TestComplexC99.py [new file with mode: 0644]
lldb/test/API/lang/c/complex/main.c [new file with mode: 0644]
lldb/test/API/lang/c/complex_int/Makefile [new file with mode: 0644]
lldb/test/API/lang/c/complex_int/TestComplexInt.py [new file with mode: 0644]
lldb/test/API/lang/c/complex_int/main.c [new file with mode: 0644]

diff --git a/lldb/test/API/lang/c/complex/Makefile b/lldb/test/API/lang/c/complex/Makefile
new file mode 100644 (file)
index 0000000..695335e
--- /dev/null
@@ -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 (file)
index 0000000..c30fcbc
--- /dev/null
@@ -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 (file)
index 0000000..eadc896
--- /dev/null
@@ -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 (file)
index 0000000..1049594
--- /dev/null
@@ -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 (file)
index 0000000..8d9344e
--- /dev/null
@@ -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 (file)
index 0000000..fe88c6c
--- /dev/null
@@ -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
+}