1b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher// RUN: %clang_cc1 -emit-llvm -g %s -o - | FileCheck %s 2b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher// Require the template function declaration refer to the correct filename. 3b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher// First, locate the function decl in metadata, and pluck out the file handle: 43ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar// CHECK: !MDSubprogram(name: "extract_dwarf_data_from_header 53ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar// CHECK-SAME: file: [[FILE:![0-9]+]] 6b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher// Second: Require that filehandle refer to the correct filename: 73ea9e33ea25e0c2b12db56418ba3f994eb662c04Pirama Arumuga Nainar// CHECK: [[FILE]] = !MDFile(filename: "decl_should_be_here.hpp" 8b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christophertypedef long unsigned int __darwin_size_t; 9b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christophertypedef __darwin_size_t size_t; 10b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christophertypedef unsigned char uint8_t; 11b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christophertypedef unsigned int uint32_t; 12b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christophertypedef unsigned long long uint64_t; 13b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christophernamespace std { 14b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher template<typename _Tp> class auto_ptr { 15b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher _Tp* _M_ptr; 16b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher public: 17b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher typedef _Tp element_type; 18b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher auto_ptr(element_type* __p = 0) throw() : _M_ptr(__p) { } 19b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher element_type& operator*() const throw() { } 20b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher }; 21b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher} 22b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopherclass Pointer32 { 23b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopherpublic: 24b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher typedef uint32_t ptr_t; 25b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher typedef uint32_t size_t; 26b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher}; 27b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopherclass Pointer64 { 28b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopherpublic: 29b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher typedef uint64_t ptr_t; 30b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher typedef uint64_t size_t; 31b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher}; 32b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopherclass BigEndian {}; 33b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopherclass LittleEndian {}; 34b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christophertemplate <typename _SIZE, typename _ENDIANNESS> class SizeAndEndianness { 35b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopherpublic: 36b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher typedef _SIZE SIZE; 37b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher}; 38b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christophertypedef SizeAndEndianness<Pointer32, LittleEndian> ISA32Little; 39b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christophertypedef SizeAndEndianness<Pointer32, BigEndian> ISA32Big; 40b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christophertypedef SizeAndEndianness<Pointer64, LittleEndian> ISA64Little; 41b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christophertypedef SizeAndEndianness<Pointer64, BigEndian> ISA64Big; 42b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christophertemplate <typename SIZE> class TRange { 43b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopherprotected: 44b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher typename SIZE::ptr_t _location; 45b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher typename SIZE::size_t _length; 46b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher TRange(typename SIZE::ptr_t location, typename SIZE::size_t length) : _location(location), _length(length) { } 47b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher}; 48b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christophertemplate <typename SIZE, typename T> class TRangeValue : public TRange<SIZE> { 49b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher T _value; 50b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopherpublic: 51b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher TRangeValue(typename SIZE::ptr_t location, typename SIZE::size_t length, T value) : TRange<SIZE>(location, length), _value(value) {}; 52b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher}; 53b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christophertemplate <typename SIZE> class TAddressRelocator {}; 54b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopherclass CSCppSymbolOwner{}; 55b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopherclass CSCppSymbolOwnerData{}; 56b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christophertemplate <typename SIZE> class TRawSymbolOwnerData 57b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher{ 58b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher TRangeValue< SIZE, uint8_t* > _TEXT_text_section; 59b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher const char* _dsym_path; 60b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher uint32_t _dylib_current_version; 61b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher uint32_t _dylib_compatibility_version; 62b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopherpublic: 63b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher TRawSymbolOwnerData() : 64b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher _TEXT_text_section(0, 0, __null), _dsym_path(__null), _dylib_current_version(0), _dylib_compatibility_version(0) {} 65b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher}; 66b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christophertemplate <typename SIZE_AND_ENDIANNESS> class TExtendedMachOHeader {}; 67b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher# 16 "decl_should_be_here.hpp" 68b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christophertemplate <typename SIZE_AND_ENDIANNESS> void extract_dwarf_data_from_header(TExtendedMachOHeader<SIZE_AND_ENDIANNESS>& header, 69b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher TRawSymbolOwnerData<typename SIZE_AND_ENDIANNESS::SIZE>& symbol_owner_data, 70b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher TAddressRelocator<typename SIZE_AND_ENDIANNESS::SIZE>* address_relocator) {} 71b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopherstruct CSCppSymbolOwnerHashFunctor { 72b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher size_t operator()(const CSCppSymbolOwner& symbol_owner) const { 73b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher# 97 "wrong_place_for_decl.cpp" 74b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher } 75b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher}; 76b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christophertemplate <typename SIZE_AND_ENDIANNESS> CSCppSymbolOwnerData* create_symbol_owner_data_arch_specific(CSCppSymbolOwner* symbol_owner, const char* dsym_path) { 77b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher typedef typename SIZE_AND_ENDIANNESS::SIZE SIZE; 78b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher std::auto_ptr< TRawSymbolOwnerData<SIZE> > data(new TRawSymbolOwnerData<SIZE>()); 79b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher std::auto_ptr< TExtendedMachOHeader<SIZE_AND_ENDIANNESS> > header; 80b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher extract_dwarf_data_from_header(*header, *data, (TAddressRelocator<typename SIZE_AND_ENDIANNESS::SIZE>*)__null); 81b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher} 82b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric ChristopherCSCppSymbolOwnerData* create_symbol_owner_data2(CSCppSymbolOwner* symbol_owner, const char* dsym_path) { 83b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher create_symbol_owner_data_arch_specific< ISA32Little >(symbol_owner, dsym_path); 84b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher create_symbol_owner_data_arch_specific< ISA32Big >(symbol_owner, dsym_path); 85b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher create_symbol_owner_data_arch_specific< ISA64Little >(symbol_owner, dsym_path); 86b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher create_symbol_owner_data_arch_specific< ISA64Big >(symbol_owner, dsym_path); 87b7f124c7452fb81fe869dc9eb0b4f58a81c067caEric Christopher} 88