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