Author: shafik Date: Wed May 1 15:23:06 2019 New Revision: 359732 URL: http://llvm.org/viewvc/llvm-project?rev=359732&view=rev Log: Set a CXXRecordDecl to not be passed in registers if DW_CC_pass_by_reference when loading from DWARF
Summary: This will fix a bug where during expression parsing we are not setting a CXXRecordDecl to not be passed in registers and the resulting code generation is wrong. The DWARF attribute DW_CC_pass_by_reference tells us that we should not be passing in registers i.e. RAA_Indirect. This change depends this clang change which fixes the fact that the ASTImporter does not copy RecordDeclBits for CXXRecordDecl: https://reviews.llvm.org/D61140 Differential Revision: https://reviews.llvm.org/D61146 Added: lldb/trunk/packages/Python/lldbsuite/test/expression_command/argument_passing_restrictions/ lldb/trunk/packages/Python/lldbsuite/test/expression_command/argument_passing_restrictions/Makefile lldb/trunk/packages/Python/lldbsuite/test/expression_command/argument_passing_restrictions/TestArgumentPassingRestrictions.py lldb/trunk/packages/Python/lldbsuite/test/expression_command/argument_passing_restrictions/main.cpp Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp Added: lldb/trunk/packages/Python/lldbsuite/test/expression_command/argument_passing_restrictions/Makefile URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/expression_command/argument_passing_restrictions/Makefile?rev=359732&view=auto ============================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/argument_passing_restrictions/Makefile (added) +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/argument_passing_restrictions/Makefile Wed May 1 15:23:06 2019 @@ -0,0 +1,5 @@ +LEVEL = ../../make + +CXX_SOURCES := main.cpp + +include $(LEVEL)/Makefile.rules Added: lldb/trunk/packages/Python/lldbsuite/test/expression_command/argument_passing_restrictions/TestArgumentPassingRestrictions.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/expression_command/argument_passing_restrictions/TestArgumentPassingRestrictions.py?rev=359732&view=auto ============================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/argument_passing_restrictions/TestArgumentPassingRestrictions.py (added) +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/argument_passing_restrictions/TestArgumentPassingRestrictions.py Wed May 1 15:23:06 2019 @@ -0,0 +1,32 @@ +""" +This is a test to ensure that both lldb is reconstructing the right +calling convention for a CXXRecordDecl as represented by: + + DW_CC_pass_by_reference + DW_CC_pass_by_value + +and to also make sure that the ASTImporter is copying over this +setting when importing the CXXRecordDecl via setArgPassingRestrictions. +""" + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class TestArgumentPassingRestrictions(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def test_argument_passing_restrictions(self): + self.build() + + lldbutil.run_to_source_breakpoint(self, '// break here', + lldb.SBFileSpec("main.cpp")) + + self.expect("expr returnPassByRef()", + substrs=['(PassByRef)', '= 11223344']) + + self.expect("expr takePassByRef(p)", + substrs=['(int)', '= 42']) Added: lldb/trunk/packages/Python/lldbsuite/test/expression_command/argument_passing_restrictions/main.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/expression_command/argument_passing_restrictions/main.cpp?rev=359732&view=auto ============================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/expression_command/argument_passing_restrictions/main.cpp (added) +++ lldb/trunk/packages/Python/lldbsuite/test/expression_command/argument_passing_restrictions/main.cpp Wed May 1 15:23:06 2019 @@ -0,0 +1,19 @@ +// This structure has a non-trivial copy constructor so +// it needs to be passed by reference. +struct PassByRef { + PassByRef() = default; + PassByRef(const PassByRef &p){x = p.x;}; + + int x = 11223344; +}; + +PassByRef returnPassByRef() { return PassByRef(); } +int takePassByRef(PassByRef p) { + return p.x; +} + +int main() { + PassByRef p = returnPassByRef(); + p.x = 42; + return takePassByRef(p); // break here +} Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp?rev=359732&r1=359731&r2=359732&view=diff ============================================================================== --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp (original) +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp Wed May 1 15:23:06 2019 @@ -959,6 +959,14 @@ TypeSP DWARFASTParserClang::ParseTypeFro } } + if (calling_convention == llvm::dwarf::DW_CC_pass_by_reference) { + clang::CXXRecordDecl *record_decl = + m_ast.GetAsCXXRecordDecl(clang_type.GetOpaqueQualType()); + if (record_decl) + record_decl->setArgPassingRestrictions( + clang::RecordDecl::APK_CannotPassInRegs); + } + } break; case DW_TAG_enumeration_type: { _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits