Files
clang-p2996/lldb/test/API/lang/c/calling-conventions/TestCCallingConventions.py
Raphael Isemann 3256aa8fe6 [lldb] Add support for DW_AT_calling_convention to the DWARF parser
This adds support for parsing DW_AT_calling_convention in the DWARF parser.

The generic DWARF parsing code already support extracting this attribute from A
DIE and TypeSystemClang already offers a parameter to add a calling convention
to a function type (as the PDB parser supports calling convention parsing), so
this patch just converts the DWARF enum value to the Clang enum value and adds a
few tests.

There are two tests in this patch.:

* A unit test for the added DWARF parsing code that should run on all platforms.

* An API tests that covers the whole expression evaluation machinery by trying
to call functions with non-standard calling conventions. The specific subtests
are target specific as some calling conventions only work on e.g. win32 (or, if
they work on other platforms they only really have observable differences on a
specific target).  The tests are also highly compiler-specific, so if GCC or
Clang tell us that they don't support a specific calling convention then we just
skip the test.

Note that some calling conventions are supported by Clang but aren't implemented
in LLVM (e.g. `pascal`), so there we just test that if this ever gets
implemented in LLVM that LLDB works too. There are also some more tricky/obscure
conventions that are left out such as the different swift* conventions, some
planned Obj-C conventions (`Preserve*`), AAPCS* conventions (as the DWARF->Clang
conversion is ambiguous for AAPCS and APPCS-VFP) and conventions only used for
OpenCL etc.

Reviewed By: aprantl

Differential Revision: https://reviews.llvm.org/D108629
2021-10-11 13:44:10 +02:00

79 lines
2.9 KiB
Python

import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
from lldbsuite.test_event.build_exception import BuildError
class TestCase(TestBase):
mydir = TestBase.compute_mydir(__file__)
NO_DEBUG_INFO_TESTCASE = True
def build_and_run(self, test_file):
"""
Tries building the given test source and runs to the first breakpoint.
Returns false if the file fails to build due to an unsupported calling
convention on the current test target. Returns true if building and
running to the breakpoint succeeded.
"""
try:
self.build(dictionary={
"C_SOURCES" : test_file,
"CFLAGS_EXTRAS" : "-Werror"
})
except BuildError as e:
# Test source failed to build. Check if it failed because the
# calling convention argument is unsupported/unknown in which case
# the test should be skipped.
error_msg = str(e)
# Clang gives an explicit error when a calling convention is
# not supported.
if "calling convention is not supported for this target" in error_msg:
return False
# GCC's has two different generic warnings it can emit.
if "attribute ignored" in error_msg:
return False
if "attribute directive ignored " in error_msg:
return False
# We got a different build error, so raise it again to fail the
# test.
raise
lldbutil.run_to_source_breakpoint(self, "// break here", lldb.SBFileSpec(test_file))
return True
def test_regcall(self):
if not self.build_and_run("regcall.c"):
return
self.expect_expr("func(1, 2, 3, 4)", result_type="int", result_value="10")
def test_ms_abi(self):
if not self.build_and_run("ms_abi.c"):
return
self.expect_expr("func(1, 2, 3, 4)", result_type="int", result_value="10")
def test_stdcall(self):
if not self.build_and_run("stdcall.c"):
return
self.expect_expr("func(1, 2, 3, 4)", result_type="int", result_value="10")
def test_vectorcall(self):
if not self.build_and_run("vectorcall.c"):
return
self.expect_expr("func(1.0)", result_type="int", result_value="1")
def test_fastcall(self):
if not self.build_and_run("fastcall.c"):
return
self.expect_expr("func(1, 2, 3, 4)", result_type="int", result_value="10")
def test_pascal(self):
if not self.build_and_run("pascal.c"):
return
self.expect_expr("func(1, 2, 3, 4)", result_type="int", result_value="10")
def test_sysv_abi(self):
if not self.build_and_run("sysv_abi.c"):
return
self.expect_expr("func(1, 2, 3, 4)", result_type="int", result_value="10")