13004a759SMichael Buch""" 23004a759SMichael BuchTests the scenario where we evaluate expressions 33004a759SMichael Buchof two types in different modules that reference 43004a759SMichael Bucha class template instantiated with the same 53004a759SMichael Buchtemplate argument. 63004a759SMichael Buch 73004a759SMichael BuchNote that, 83004a759SMichael Buch1. Since the decls originate from modules, LLDB 93004a759SMichael Buch marks them as such and Clang doesn't create 103004a759SMichael Buch a LookupPtr map on the corresponding DeclContext. 113004a759SMichael Buch This prevents regular DeclContext::lookup from 123004a759SMichael Buch succeeding. 133004a759SMichael Buch2. Because we reference the same class template 143004a759SMichael Buch from two different modules we get a redeclaration 153004a759SMichael Buch chain for the class's ClassTemplateSpecializationDecl. 163004a759SMichael Buch The importer will import all FieldDecls into the 173004a759SMichael Buch same DeclContext on the redeclaration chain. If 183004a759SMichael Buch we don't do the bookkeeping correctly we end up 193004a759SMichael Buch with duplicate decls on the same DeclContext leading 203004a759SMichael Buch to crashes down the line. 213004a759SMichael Buch""" 223004a759SMichael Buch 233004a759SMichael Buchimport lldb 243004a759SMichael Buchfrom lldbsuite.test.decorators import * 253004a759SMichael Buchfrom lldbsuite.test.lldbtest import * 263004a759SMichael Buchfrom lldbsuite.test import lldbutil 273004a759SMichael Buch 283004a759SMichael Buch 293004a759SMichael Buchclass TestTemplateWithSameArg(TestBase): 303004a759SMichael Buch def setUp(self): 313004a759SMichael Buch TestBase.setUp(self) 323004a759SMichael Buch self.build() 333004a759SMichael Buch self.main_source_file = lldb.SBFileSpec("main.cpp") 343004a759SMichael Buch 353004a759SMichael Buch @add_test_categories(["gmodules"]) 363004a759SMichael Buch def test_same_template_arg(self): 373004a759SMichael Buch lldbutil.run_to_source_breakpoint(self, "Break here", self.main_source_file) 383004a759SMichael Buch 39*2238dcc3SJonas Devlieghere self.expect_expr( 40*2238dcc3SJonas Devlieghere "FromMod1", 41*2238dcc3SJonas Devlieghere result_type="ClassInMod1", 42*2238dcc3SJonas Devlieghere result_children=[ 43*2238dcc3SJonas Devlieghere ValueCheck( 44*2238dcc3SJonas Devlieghere name="VecInMod1", children=[ValueCheck(name="Member", value="137")] 45*2238dcc3SJonas Devlieghere ) 46*2238dcc3SJonas Devlieghere ], 47*2238dcc3SJonas Devlieghere ) 483004a759SMichael Buch 49*2238dcc3SJonas Devlieghere self.expect_expr( 50*2238dcc3SJonas Devlieghere "FromMod2", 51*2238dcc3SJonas Devlieghere result_type="ClassInMod2", 52*2238dcc3SJonas Devlieghere result_children=[ 53*2238dcc3SJonas Devlieghere ValueCheck( 54*2238dcc3SJonas Devlieghere name="VecInMod2", children=[ValueCheck(name="Member", value="42")] 55*2238dcc3SJonas Devlieghere ) 56*2238dcc3SJonas Devlieghere ], 57*2238dcc3SJonas Devlieghere ) 583004a759SMichael Buch 593004a759SMichael Buch @add_test_categories(["gmodules"]) 603004a759SMichael Buch def test_duplicate_decls(self): 613004a759SMichael Buch lldbutil.run_to_source_breakpoint(self, "Break here", self.main_source_file) 623004a759SMichael Buch 633004a759SMichael Buch self.expect_expr("(intptr_t)&FromMod1 + (intptr_t)&FromMod2") 643004a759SMichael Buch 653004a759SMichael Buch # Make sure we only have a single 'Member' decl on the AST 663004a759SMichael Buch self.filecheck("target module dump ast", __file__) 67*2238dcc3SJonas Devlieghere 68*2238dcc3SJonas Devlieghere 693004a759SMichael Buch# CHECK: ClassTemplateSpecializationDecl {{.*}} imported in Module2 struct ClassInMod3 definition 703004a759SMichael Buch# CHECK-NEXT: |-DefinitionData pass_in_registers aggregate standard_layout trivially_copyable pod trivial 713004a759SMichael Buch# CHECK-NEXT: | |-DefaultConstructor exists trivial needs_implicit 723004a759SMichael Buch# CHECK-NEXT: | |-CopyConstructor simple trivial has_const_param needs_implicit implicit_has_const_param 733004a759SMichael Buch# CHECK-NEXT: | |-MoveConstructor exists simple trivial needs_implicit 743004a759SMichael Buch# CHECK-NEXT: | |-CopyAssignment simple trivial has_const_param needs_implicit implicit_has_const_param 753004a759SMichael Buch# CHECK-NEXT: | |-MoveAssignment exists simple trivial needs_implicit 763004a759SMichael Buch# CHECK-NEXT: | `-Destructor simple irrelevant trivial needs_implicit 773004a759SMichael Buch# CHECK-NEXT: |-TemplateArgument type 'int' 783004a759SMichael Buch# CHECK-NEXT: | `-BuiltinType {{.*}} 'int' 793004a759SMichael Buch# CHECK-NEXT: `-FieldDecl {{.*}} imported in Module2 Member 'int' 80