Merge "Let header-abi-dumper declare unknown types automatically"
diff --git a/vndk/tools/definition-tool/datasets/vndk-lib-extra-list-current.txt b/vndk/tools/definition-tool/datasets/vndk-lib-extra-list-current.txt
index fbc8f4c..370301f 100644
--- a/vndk/tools/definition-tool/datasets/vndk-lib-extra-list-current.txt
+++ b/vndk/tools/definition-tool/datasets/vndk-lib-extra-list-current.txt
@@ -8,6 +8,16 @@
 LLNDK: libclang_rt.asan-mips64-android.so
 LLNDK: libclang_rt.asan-x86_64-android.so
 
+VNDK-core: libclang_rt.scudo-aarch64-android.so
+VNDK-core: libclang_rt.scudo-arm-android.so
+VNDK-core: libclang_rt.scudo-i686-android.so
+VNDK-core: libclang_rt.scudo-x86_64-android.so
+
+VNDK-core: libclang_rt.scudo_minimal-aarch64-android.so
+VNDK-core: libclang_rt.scudo_minimal-arm-android.so
+VNDK-core: libclang_rt.scudo_minimal-i686-android.so
+VNDK-core: libclang_rt.scudo_minimal-x86_64-android.so
+
 VNDK-core: libclang_rt.ubsan_standalone-aarch64-android.so
 VNDK-core: libclang_rt.ubsan_standalone-arm-android.so
 VNDK-core: libclang_rt.ubsan_standalone-i686-android.so
diff --git a/vndk/tools/definition-tool/tools/update_dataset.py b/vndk/tools/definition-tool/tools/update_dataset.py
index d08ea7d..4c86062 100755
--- a/vndk/tools/definition-tool/tools/update_dataset.py
+++ b/vndk/tools/definition-tool/tools/update_dataset.py
@@ -222,19 +222,22 @@
         update_tag(prefix_vendor + name, 'VNDK-SP-Private',
                    'Workaround for degenerated VDNK')
 
-    # Workaround for libclang_rt.asan
-    prefix = 'libclang_rt.asan'
-    if any(name.startswith(prefix) for name in llndk):
-        for path in list(data.keys()):
-            if os.path.basename(path).startswith(prefix):
-                update_tag(path, 'LL-NDK')
-
-    # Workaround for libclang_rt.ubsan_standalone
-    prefix = 'libclang_rt.ubsan_standalone'
-    if any(name.startswith(prefix) for name in vndk):
-        for path in list(data.keys()):
-            if os.path.basename(path).startswith(prefix):
-                update_tag(path, 'VNDK')
+    # Workaround for libclang_rt.*.so
+    lib_sets = {
+        'LL-NDK': llndk,
+        'VNDK': vndk,
+    }
+    prefixes = {
+        'libclang_rt.asan': 'LL-NDK',
+        'libclang_rt.hwasan': 'LL-NDK',
+        'libclang_rt.scudo': 'VNDK',
+        'libclang_rt.ubsan_standalone': 'VNDK',
+    }
+    for prefix, tag in prefixes.items():
+        if any(name.startswith(prefix) for name in lib_sets[tag]):
+            for path in list(data.keys()):
+                if os.path.basename(path).startswith(prefix):
+                    update_tag(path, tag)
 
     # Merge regular expression patterns into final dataset
     for regex in regex_patterns:
diff --git a/vndk/tools/header-checker/header-abi-linker/src/header_abi_linker.cpp b/vndk/tools/header-checker/header-abi-linker/src/header_abi_linker.cpp
index cb3fcb0..3b81b9a 100644
--- a/vndk/tools/header-checker/header-abi-linker/src/header_abi_linker.cpp
+++ b/vndk/tools/header-checker/header-abi-linker/src/header_abi_linker.cpp
@@ -106,9 +106,13 @@
                 const abi_util::AbiElementMap<T> &src,
                 const std::function<bool(const std::string &)> &symbol_filter);
 
-  bool ParseVersionScriptFiles();
+  std::unique_ptr<abi_util::TextFormatToIRReader> ReadInputDumpFiles();
 
-  bool ParseSoFile();
+  bool ReadExportedSymbols();
+
+  bool ReadExportedSymbolsFromVersionScript();
+
+  bool ReadExportedSymbolsFromSharedObjectFile();
 
   bool LinkTypes(const abi_util::TextFormatToIRReader *ir_reader,
                  abi_util::IRDumper *ir_dumper);
@@ -119,8 +123,7 @@
   bool LinkGlobalVars(const abi_util::TextFormatToIRReader *ir_reader,
                       abi_util::IRDumper *ir_dumper);
 
-  bool AddElfSymbols(abi_util::IRDumper *ir_dumper);
-
+  bool LinkExportedSymbols(abi_util::IRDumper *ir_dumper);
 
  private:
   const std::vector<std::string> &dump_files_;
@@ -142,23 +145,6 @@
   std::regex globvars_vs_regex_;
 };
 
-template <typename T>
-static bool AddElfSymbols(abi_util::IRDumper *dst,
-                          const std::map<std::string, T> &symbols) {
-  for (auto &&symbol : symbols) {
-    if (!dst->AddElfSymbolMessageIR(&(symbol.second))) {
-      return false;
-    }
-  }
-  return true;
-}
-
-// To be called right after parsing the .so file / version script.
-bool HeaderAbiLinker::AddElfSymbols(abi_util::IRDumper *ir_dumper) {
-  return ::AddElfSymbols(ir_dumper, function_decl_map_) &&
-         ::AddElfSymbols(ir_dumper, globvar_decl_map_);
-}
-
 static void DeDuplicateAbiElementsThread(
     const std::vector<std::string> &dump_files,
     const std::set<std::string> *exported_headers,
@@ -167,6 +153,7 @@
   std::unique_ptr<abi_util::TextFormatToIRReader> local_reader =
       abi_util::TextFormatToIRReader::CreateTextFormatToIRReader(
           input_format, exported_headers);
+
   auto begin_it = dump_files.begin();
   std::size_t num_sources = dump_files.size();
   while (1) {
@@ -188,36 +175,20 @@
       local_reader->MergeGraphs(*reader);
     }
   }
+
   std::lock_guard<std::mutex> lock(*greader_lock);
   greader->MergeGraphs(*local_reader);
 }
 
-bool HeaderAbiLinker::LinkAndDump() {
-  // If the user specifies that a version script should be used, use that.
-  if (!so_file_.empty()) {
-    exported_headers_ =
-        abi_util::CollectAllExportedHeaders(exported_header_dirs_);
-    if (!ParseSoFile()) {
-      llvm::errs() << "Couldn't parse so file\n";
-      return false;
-    }
-  } else if (!ParseVersionScriptFiles()) {
-    llvm::errs() << "Failed to parse stub files for exported symbols\n";
-    return false;
-  }
-  std::unique_ptr<abi_util::IRDumper> ir_dumper =
-      abi_util::IRDumper::CreateIRDumper(output_format, out_dump_name_);
-  assert(ir_dumper != nullptr);
-  AddElfSymbols(ir_dumper.get());
-  // Create a reader, on which we never actually call ReadDump(), since multiple
-  // dump files are associated with it.
+std::unique_ptr<abi_util::TextFormatToIRReader>
+HeaderAbiLinker::ReadInputDumpFiles() {
   std::unique_ptr<abi_util::TextFormatToIRReader> greader =
       abi_util::TextFormatToIRReader::CreateTextFormatToIRReader(
           input_format, &exported_headers_);
+
   std::size_t max_threads = std::thread::hardware_concurrency();
   std::size_t num_threads = kSourcesPerBatchThread < dump_files_.size() ?
-                    std::min(dump_files_.size() / kSourcesPerBatchThread,
-                             max_threads) : 0;
+      std::min(dump_files_.size() / kSourcesPerBatchThread, max_threads) : 0;
   std::vector<std::thread> threads;
   std::atomic<std::size_t> cnt(0);
   std::mutex greader_lock;
@@ -232,16 +203,42 @@
     thread.join();
   }
 
+  return greader;
+}
+
+bool HeaderAbiLinker::LinkAndDump() {
+  // Extract exported functions and variables from a shared lib or a version
+  // script.
+  if (!ReadExportedSymbols()) {
+    return false;
+  }
+
+  // Construct the list of exported headers for source location filtering.
+  exported_headers_ =
+      abi_util::CollectAllExportedHeaders(exported_header_dirs_);
+
+  // Read all input ABI dumps.
+  auto greader = ReadInputDumpFiles();
+
+  // Link input ABI dumps.
+  std::unique_ptr<abi_util::IRDumper> ir_dumper =
+      abi_util::IRDumper::CreateIRDumper(output_format, out_dump_name_);
+  assert(ir_dumper != nullptr);
+
+  LinkExportedSymbols(ir_dumper.get());
+
   if (!LinkTypes(greader.get(), ir_dumper.get()) ||
       !LinkFunctions(greader.get(), ir_dumper.get()) ||
       !LinkGlobalVars(greader.get(), ir_dumper.get())) {
     llvm::errs() << "Failed to link elements\n";
     return false;
   }
+
   if (!ir_dumper->Dump()) {
-    llvm::errs() << "Serialization to ostream failed\n";
+    llvm::errs() << "Failed to serialize the linked output to ostream\n";
     return false;
   }
+
   return true;
 }
 
@@ -345,15 +342,56 @@
   return LinkDecl(ir_dumper, reader->GetGlobalVariables(), symbol_filter);
 }
 
-bool HeaderAbiLinker::ParseVersionScriptFiles() {
+template <typename T>
+static bool LinkExportedSymbols(abi_util::IRDumper *dst,
+                                const std::map<std::string, T> &symbols) {
+  for (auto &&symbol : symbols) {
+    if (!dst->AddElfSymbolMessageIR(&(symbol.second))) {
+      return false;
+    }
+  }
+  return true;
+}
+
+// To be called right after parsing the .so file / version script.
+bool HeaderAbiLinker::LinkExportedSymbols(abi_util::IRDumper *ir_dumper) {
+  return ::LinkExportedSymbols(ir_dumper, function_decl_map_) &&
+         ::LinkExportedSymbols(ir_dumper, globvar_decl_map_);
+}
+
+bool HeaderAbiLinker::ReadExportedSymbols() {
+  if (!so_file_.empty()) {
+    if (!ReadExportedSymbolsFromSharedObjectFile()) {
+      llvm::errs() << "Failed to parse the shared library (.so file): "
+                   << so_file_ << "\n";
+      return false;
+    }
+    return true;
+  }
+
+  if (!version_script_.empty()) {
+    if (!ReadExportedSymbolsFromVersionScript()) {
+      llvm::errs() << "Failed to parse the version script: " << version_script_
+                   << "\n";
+      return false;
+    }
+    return true;
+  }
+
+  llvm::errs() << "Either shared lib or version script must be specified.\n";
+  return false;
+}
+
+bool HeaderAbiLinker::ReadExportedSymbolsFromVersionScript() {
   abi_util::VersionScriptParser version_script_parser(
       version_script_, arch_, api_);
   if (!version_script_parser.Parse()) {
-    llvm::errs() << "Failed to parse version script\n";
     return false;
   }
+
   function_decl_map_ = version_script_parser.GetFunctions();
   globvar_decl_map_ = version_script_parser.GetGlobVars();
+
   std::set<std::string> function_regexs =
       version_script_parser.GetFunctionRegexs();
   std::set<std::string> globvar_regexs =
@@ -363,27 +401,13 @@
   return true;
 }
 
-bool HeaderAbiLinker::ParseSoFile() {
-  auto Binary = llvm::object::createBinary(so_file_);
-
-  if (!Binary) {
-    llvm::errs() << "Couldn't really create object File \n";
-    return false;
-  }
-  llvm::object::ObjectFile *objfile =
-      llvm::dyn_cast<llvm::object::ObjectFile>(&(*Binary.get().getBinary()));
-  if (!objfile) {
-    llvm::errs() << "Not an object file\n";
-    return false;
-  }
-
+bool HeaderAbiLinker::ReadExportedSymbolsFromSharedObjectFile() {
   std::unique_ptr<abi_util::SoFileParser> so_parser =
-      abi_util::SoFileParser::Create(objfile);
-  if (so_parser == nullptr) {
-    llvm::errs() << "Couldn't create soFile Parser\n";
+      abi_util::SoFileParser::Create(so_file_);
+  if (!so_parser) {
     return false;
   }
-  so_parser->GetSymbols();
+
   function_decl_map_ = so_parser->GetFunctions();
   globvar_decl_map_ = so_parser->GetGlobVars();
   return true;
diff --git a/vndk/tools/header-checker/header-abi-util/include/ir_representation.h b/vndk/tools/header-checker/header-abi-util/include/ir_representation.h
index 7235248..886c39e 100644
--- a/vndk/tools/header-checker/header-abi-util/include/ir_representation.h
+++ b/vndk/tools/header-checker/header-abi-util/include/ir_representation.h
@@ -933,18 +933,6 @@
 
   virtual bool ReadDump(const std::string &dump_file) = 0;
 
-  template <typename Iterator>
-  bool ReadDumps(Iterator begin, Iterator end) {
-    Iterator it = begin;
-    while (it != end) {
-      if (!ReadDump(*it)) {
-        return false;
-      }
-      ++it;
-    }
-    return true;
-  }
-
   void Merge(TextFormatToIRReader &&addend) {
     MergeElements(&functions_, std::move(addend.functions_));
     MergeElements(&global_variables_, std::move(addend.global_variables_));
diff --git a/vndk/tools/header-checker/header-abi-util/include/so_file_parser.h b/vndk/tools/header-checker/header-abi-util/include/so_file_parser.h
index 9c035bd..b19b8f3 100644
--- a/vndk/tools/header-checker/header-abi-util/include/so_file_parser.h
+++ b/vndk/tools/header-checker/header-abi-util/include/so_file_parser.h
@@ -17,9 +17,6 @@
 
 #include "ir_representation.h"
 
-#include <llvm/Object/ELFObjectFile.h>
-#include <llvm/Object/ELFTypes.h>
-
 #include <memory>
 #include <map>
 #include <string>
@@ -28,38 +25,13 @@
 
 class SoFileParser {
  public:
+  static std::unique_ptr<SoFileParser> Create(const std::string &so_file_path);
+
   virtual ~SoFileParser() {}
 
-  static std::unique_ptr<SoFileParser> Create(
-      const llvm::object::ObjectFile *obj);
-
   virtual const std::map<std::string, ElfFunctionIR> &GetFunctions() const = 0;
+
   virtual const std::map<std::string, ElfObjectIR> &GetGlobVars() const = 0;
-  virtual void GetSymbols() = 0;
-};
-
-template<typename T>
-class ELFSoFileParser : public SoFileParser {
- private:
-  LLVM_ELF_IMPORT_TYPES_ELFT(T)
-  typedef llvm::object::ELFFile<T> ELFO;
-  typedef typename ELFO::Elf_Sym Elf_Sym;
-
- public:
-  ELFSoFileParser(const llvm::object::ELFObjectFile<T> *obj) : obj_(obj) {}
-  ~ELFSoFileParser() override {}
-
-  const std::map<std::string, ElfFunctionIR> &GetFunctions() const override;
-  const std::map<std::string, ElfObjectIR> &GetGlobVars() const override;
-  void GetSymbols() override;
-
- private:
-  const llvm::object::ELFObjectFile<T> *obj_;
-  std::map<std::string, abi_util::ElfFunctionIR> functions_;
-  std::map<std::string, abi_util::ElfObjectIR> globvars_;
-
- private:
-  bool IsSymbolExported(const Elf_Sym *elf_sym) const;
 };
 
 }  // namespace abi_util
diff --git a/vndk/tools/header-checker/header-abi-util/src/collect_exported_headers.cpp b/vndk/tools/header-checker/header-abi-util/src/collect_exported_headers.cpp
index 39b3f64..0b6b079 100644
--- a/vndk/tools/header-checker/header-abi-util/src/collect_exported_headers.cpp
+++ b/vndk/tools/header-checker/header-abi-util/src/collect_exported_headers.cpp
@@ -50,7 +50,8 @@
   llvm::sys::fs::recursive_directory_iterator end;
   for ( ; walker != end; walker.increment(ec)) {
     if (ec) {
-      llvm::errs() << "Failed to walk dir : " << dir_name << "\n";
+      llvm::errs() << "Failed to walk directory: " << dir_name << ": "
+                   << ec.message() << "\n";
       return false;
     }
 
@@ -67,7 +68,7 @@
 
     llvm::ErrorOr<llvm::sys::fs::basic_file_status> status = walker->status();
     if (!status) {
-      llvm::errs() << "Failed to stat file : " << file_path << "\n";
+      llvm::errs() << "Failed to stat file: " << file_path << "\n";
       return false;
     }
 
diff --git a/vndk/tools/header-checker/header-abi-util/src/so_file_parser.cpp b/vndk/tools/header-checker/header-abi-util/src/so_file_parser.cpp
index 5750c32..fa4d975 100644
--- a/vndk/tools/header-checker/header-abi-util/src/so_file_parser.cpp
+++ b/vndk/tools/header-checker/header-abi-util/src/so_file_parser.cpp
@@ -21,65 +21,71 @@
 #include <llvm/Object/ELFTypes.h>
 #include <llvm/Object/SymbolSize.h>
 
-using llvm::ELF::STB_GLOBAL;
-using llvm::ELF::STB_WEAK;
-using llvm::ELF::STV_DEFAULT;
-using llvm::ELF::STV_PROTECTED;
-using llvm::dyn_cast;
-using llvm::object::ELF32BEObjectFile;
-using llvm::object::ELF32LEObjectFile;
-using llvm::object::ELF64BEObjectFile;
-using llvm::object::ELF64LEObjectFile;
-
 namespace abi_util {
 
 template <typename T>
-static inline T UnWrap(llvm::Expected<T> ValueOrError) {
-  if (!ValueOrError) {
-    llvm::errs() << "\nError: " << llvm::toString(ValueOrError.takeError())
+static inline T UnWrap(llvm::Expected<T> value_or_error) {
+  if (!value_or_error) {
+    llvm::errs() << "\nerror: " << llvm::toString(value_or_error.takeError())
                  << ".\n";
     llvm::errs().flush();
     exit(1);
   }
-  return std::move(ValueOrError.get());
-}
-
-template<typename T>
-const std::map<std::string, abi_util::ElfFunctionIR> &
-ELFSoFileParser<T>::GetFunctions() const {
-  return functions_;
-}
-
-template<typename T>
-const std::map<std::string, abi_util::ElfObjectIR> &
-ELFSoFileParser<T>::GetGlobVars() const {
-  return globvars_;
-}
-
-template<typename T>
-bool ELFSoFileParser<T>::IsSymbolExported(const Elf_Sym *elf_sym) const {
-  unsigned char visibility = elf_sym->getVisibility();
-  unsigned char binding = elf_sym->getBinding();
-  return (binding == STB_GLOBAL || binding == STB_WEAK) &&
-         (visibility == STV_DEFAULT || visibility == STV_PROTECTED);
+  return std::move(value_or_error.get());
 }
 
 static abi_util::ElfSymbolIR::ElfSymbolBinding
 LLVMToIRSymbolBinding(unsigned char binding) {
   switch (binding) {
-    case STB_GLOBAL:
+    case llvm::ELF::STB_GLOBAL:
       return abi_util::ElfSymbolIR::ElfSymbolBinding::Global;
-    case STB_WEAK:
+    case llvm::ELF::STB_WEAK:
       return abi_util::ElfSymbolIR::ElfSymbolBinding::Weak;
   }
   assert(0);
 }
 
 template<typename T>
-void ELFSoFileParser<T>::GetSymbols() {
-  assert(obj_ != nullptr);
-  for (auto symbol_it : obj_->getDynamicSymbolIterators()) {
-    const Elf_Sym *elf_sym = obj_->getSymbol(symbol_it.getRawDataRefImpl());
+class ELFSoFileParser : public SoFileParser {
+ private:
+  LLVM_ELF_IMPORT_TYPES_ELFT(T)
+  typedef llvm::object::ELFFile<T> ELFO;
+  typedef typename ELFO::Elf_Sym Elf_Sym;
+
+ public:
+  ELFSoFileParser(const llvm::object::ELFObjectFile<T> *obj);
+
+  ~ELFSoFileParser() override {}
+
+  const std::map<std::string, ElfFunctionIR> &GetFunctions() const override {
+    return functions_;
+  }
+
+  const std::map<std::string, ElfObjectIR> &GetGlobVars() const override {
+    return globvars_;
+  }
+
+ private:
+  bool IsSymbolExported(const Elf_Sym *elf_sym) const {
+    unsigned char visibility = elf_sym->getVisibility();
+    unsigned char binding = elf_sym->getBinding();
+    return ((binding == llvm::ELF::STB_GLOBAL ||
+             binding == llvm::ELF::STB_WEAK) &&
+            (visibility == llvm::ELF::STV_DEFAULT ||
+             visibility == llvm::ELF::STV_PROTECTED));
+  }
+
+ private:
+  const llvm::object::ELFObjectFile<T> *obj_;
+  std::map<std::string, abi_util::ElfFunctionIR> functions_;
+  std::map<std::string, abi_util::ElfObjectIR> globvars_;
+};
+
+template<typename T>
+ELFSoFileParser<T>::ELFSoFileParser(const llvm::object::ELFObjectFile<T> *obj) {
+  assert(obj != nullptr);
+  for (auto symbol_it : obj->getDynamicSymbolIterators()) {
+    const Elf_Sym *elf_sym = obj->getSymbol(symbol_it.getRawDataRefImpl());
     assert (elf_sym != nullptr);
     if (!IsSymbolExported(elf_sym) || elf_sym->isUndefined()) {
       continue;
@@ -104,26 +110,42 @@
 }
 
 std::unique_ptr<SoFileParser> SoFileParser::Create(
-    const llvm::object::ObjectFile *objfile) {
+    const std::string &so_file_path) {
+  auto binary = llvm::object::createBinary(so_file_path);
+  if (!binary) {
+    return nullptr;
+  }
+
+  llvm::object::ObjectFile *obj_file =
+      llvm::dyn_cast<llvm::object::ObjectFile>(binary.get().getBinary());
+  if (!obj_file) {
+    return nullptr;
+  }
+
   // Little-endian 32-bit
-  if (const ELF32LEObjectFile *ELFObj = dyn_cast<ELF32LEObjectFile>(objfile)) {
-    return CreateELFSoFileParser(ELFObj);
+  if (auto elf_obj_file =
+          llvm::dyn_cast<llvm::object::ELF32LEObjectFile>(obj_file)) {
+    return CreateELFSoFileParser(elf_obj_file);
   }
 
   // Big-endian 32-bit
-  if (const ELF32BEObjectFile *ELFObj = dyn_cast<ELF32BEObjectFile>(objfile)) {
-    return CreateELFSoFileParser(ELFObj);
+  if (auto elf_obj_file =
+          llvm::dyn_cast<llvm::object::ELF32BEObjectFile>(obj_file)) {
+    return CreateELFSoFileParser(elf_obj_file);
   }
 
   // Little-endian 64-bit
-  if (const ELF64LEObjectFile *ELFObj = dyn_cast<ELF64LEObjectFile>(objfile)) {
-    return CreateELFSoFileParser(ELFObj);
+  if (auto elf_obj_file =
+          llvm::dyn_cast<llvm::object::ELF64LEObjectFile>(obj_file)) {
+    return CreateELFSoFileParser(elf_obj_file);
   }
 
   // Big-endian 64-bit
-  if (const ELF64BEObjectFile *ELFObj = dyn_cast<ELF64BEObjectFile>(objfile)) {
-    return CreateELFSoFileParser(ELFObj);
+  if (auto elf_obj_file =
+          llvm::dyn_cast<llvm::object::ELF64BEObjectFile>(obj_file)) {
+    return CreateELFSoFileParser(elf_obj_file);
   }
+
   return nullptr;
 }
 
diff --git a/vndk/tools/header-checker/tests/expected/example1.h b/vndk/tools/header-checker/tests/expected/example1.h
index 810159c..13ae403 100644
--- a/vndk/tools/header-checker/tests/expected/example1.h
+++ b/vndk/tools/header-checker/tests/expected/example1.h
@@ -201,10 +201,10 @@
     name: "Hello::(anonymous struct at /development/vndk/tools/header-checker/tests/input/example1.h:19:3)::(anonymous struct at /development/vndk/tools/header-checker/tests/input/example1.h:22:5) at /development/vndk/tools/header-checker/tests/input/example1.h:22:5"
     size: 4
     alignment: 4
-    referenced_type: "type-22"
+    referenced_type: "type-24"
     source_file: "/development/vndk/tools/header-checker/tests/input/example1.h"
     linker_set_key: "Hello::(anonymous struct at /development/vndk/tools/header-checker/tests/input/example1.h:19:3)::(anonymous struct at /development/vndk/tools/header-checker/tests/input/example1.h:22:5) at /development/vndk/tools/header-checker/tests/input/example1.h:22:5"
-    self_type: "type-22"
+    self_type: "type-24"
   }
   fields {
     referenced_type: "type-2"
@@ -224,10 +224,10 @@
     name: "Hello::(anonymous struct at /development/vndk/tools/header-checker/tests/input/example1.h:19:3) at /development/vndk/tools/header-checker/tests/input/example1.h:19:3"
     size: 12
     alignment: 4
-    referenced_type: "type-21"
+    referenced_type: "type-23"
     source_file: "/development/vndk/tools/header-checker/tests/input/example1.h"
     linker_set_key: "Hello::(anonymous struct at /development/vndk/tools/header-checker/tests/input/example1.h:19:3) at /development/vndk/tools/header-checker/tests/input/example1.h:19:3"
-    self_type: "type-21"
+    self_type: "type-23"
   }
   fields {
     referenced_type: "type-2"
@@ -242,7 +242,7 @@
     access: public_access
   }
   fields {
-    referenced_type: "type-22"
+    referenced_type: "type-24"
     field_offset: 64
     field_name: ""
     access: public_access
@@ -259,10 +259,10 @@
     name: "Hello"
     size: 32
     alignment: 4
-    referenced_type: "type-19"
+    referenced_type: "type-21"
     source_file: "/development/vndk/tools/header-checker/tests/input/example1.h"
     linker_set_key: "Hello"
-    self_type: "type-19"
+    self_type: "type-21"
   }
   fields {
     referenced_type: "type-2"
@@ -277,7 +277,7 @@
     access: public_access
   }
   fields {
-    referenced_type: "type-20"
+    referenced_type: "type-22"
     field_offset: 64
     field_name: "d"
     access: public_access
@@ -295,7 +295,7 @@
     access: public_access
   }
   fields {
-    referenced_type: "type-21"
+    referenced_type: "type-23"
     field_offset: 160
     field_name: ""
     access: public_access
@@ -311,19 +311,19 @@
     name: "CPPHello"
     size: 56
     alignment: 8
-    referenced_type: "type-23"
+    referenced_type: "type-25"
     source_file: "/development/vndk/tools/header-checker/tests/input/example1.h"
     linker_set_key: "CPPHello"
-    self_type: "type-23"
+    self_type: "type-25"
   }
   fields {
-    referenced_type: "type-24"
+    referenced_type: "type-26"
     field_offset: 352
     field_name: "cpp_foo"
     access: public_access
   }
   fields {
-    referenced_type: "type-25"
+    referenced_type: "type-27"
     field_offset: 384
     field_name: "cpp_bar"
     access: public_access
@@ -381,13 +381,13 @@
     name: "List<float>"
     size: 8
     alignment: 8
-    referenced_type: "type-31"
+    referenced_type: "type-34"
     source_file: "/development/vndk/tools/header-checker/tests/input/example1.h"
     linker_set_key: "List<float>"
-    self_type: "type-31"
+    self_type: "type-34"
   }
   fields {
-    referenced_type: "type-33"
+    referenced_type: "type-36"
     field_offset: 0
     field_name: "middle"
     access: public_access
@@ -408,10 +408,10 @@
     name: "List<float>::_Node"
     size: 24
     alignment: 8
-    referenced_type: "type-32"
+    referenced_type: "type-35"
     source_file: "/development/vndk/tools/header-checker/tests/input/example1.h"
     linker_set_key: "List<float>::_Node"
-    self_type: "type-32"
+    self_type: "type-35"
   }
   fields {
     referenced_type: "type-3"
@@ -420,13 +420,13 @@
     access: private_access
   }
   fields {
-    referenced_type: "type-33"
+    referenced_type: "type-36"
     field_offset: 64
     field_name: "mpPrev"
     access: private_access
   }
   fields {
-    referenced_type: "type-33"
+    referenced_type: "type-36"
     field_offset: 128
     field_name: "mpNext"
     access: private_access
@@ -442,13 +442,13 @@
     name: "List<int>"
     size: 8
     alignment: 8
-    referenced_type: "type-35"
+    referenced_type: "type-41"
     source_file: "/development/vndk/tools/header-checker/tests/input/example1.h"
     linker_set_key: "List<int>"
-    self_type: "type-35"
+    self_type: "type-41"
   }
   fields {
-    referenced_type: "type-37"
+    referenced_type: "type-43"
     field_offset: 0
     field_name: "middle"
     access: public_access
@@ -517,10 +517,10 @@
     name: "CPPHello::Bla"
     size: 4
     alignment: 4
-    referenced_type: "type-27"
+    referenced_type: "type-29"
     source_file: "/development/vndk/tools/header-checker/tests/input/example1.h"
     linker_set_key: "CPPHello::Bla"
-    self_type: "type-27"
+    self_type: "type-29"
   }
   underlying_type: "type-9"
   enum_fields {
@@ -545,13 +545,24 @@
 }
 pointer_types {
   type_info {
+    name: "ForwardDeclaration *"
+    size: 8
+    alignment: 8
+    referenced_type: "type-19"
+    source_file: "/development/vndk/tools/header-checker/tests/input/example1.h"
+    linker_set_key: "ForwardDeclaration *"
+    self_type: "type-20"
+  }
+}
+pointer_types {
+  type_info {
     name: "CPPHello *"
     size: 8
     alignment: 8
-    referenced_type: "type-23"
+    referenced_type: "type-25"
     source_file: "/development/vndk/tools/header-checker/tests/input/example1.h"
     linker_set_key: "CPPHello *"
-    self_type: "type-26"
+    self_type: "type-28"
   }
 }
 pointer_types {
@@ -562,7 +573,7 @@
     referenced_type: "type-2"
     source_file: "/development/vndk/tools/header-checker/tests/input/example1.h"
     linker_set_key: "int *"
-    self_type: "type-29"
+    self_type: "type-31"
   }
 }
 pointer_types {
@@ -573,7 +584,7 @@
     referenced_type: "type-3"
     source_file: "/development/vndk/tools/header-checker/tests/input/example1.h"
     linker_set_key: "float *"
-    self_type: "type-30"
+    self_type: "type-33"
   }
 }
 pointer_types {
@@ -581,10 +592,21 @@
     name: "List<float>::_Node *"
     size: 8
     alignment: 8
-    referenced_type: "type-32"
+    referenced_type: "type-35"
     source_file: "/development/vndk/tools/header-checker/tests/input/example1.h"
     linker_set_key: "List<float>::_Node *"
-    self_type: "type-33"
+    self_type: "type-36"
+  }
+}
+pointer_types {
+  type_info {
+    name: "const List<float>::_Node *"
+    size: 8
+    alignment: 8
+    referenced_type: "type-39"
+    source_file: "/development/vndk/tools/header-checker/tests/input/example1.h"
+    linker_set_key: "const List<float>::_Node *"
+    self_type: "type-40"
   }
 }
 pointer_types {
@@ -592,10 +614,32 @@
     name: "List<int>::_Node *"
     size: 8
     alignment: 8
-    referenced_type: "type-36"
+    referenced_type: "type-42"
     source_file: "/development/vndk/tools/header-checker/tests/input/example1.h"
     linker_set_key: "List<int>::_Node *"
-    self_type: "type-37"
+    self_type: "type-43"
+  }
+}
+pointer_types {
+  type_info {
+    name: "List<int> *"
+    size: 8
+    alignment: 8
+    referenced_type: "type-41"
+    source_file: "/development/vndk/tools/header-checker/tests/input/example1.h"
+    linker_set_key: "List<int> *"
+    self_type: "type-44"
+  }
+}
+pointer_types {
+  type_info {
+    name: "StackNode<int> *"
+    size: 8
+    alignment: 8
+    referenced_type: "type-45"
+    source_file: "/development/vndk/tools/header-checker/tests/input/example1.h"
+    linker_set_key: "StackNode<int> *"
+    self_type: "type-46"
   }
 }
 pointer_types {
@@ -603,10 +647,21 @@
     name: "const char *"
     size: 8
     alignment: 8
-    referenced_type: "type-38"
+    referenced_type: "type-47"
     source_file: "/development/vndk/tools/header-checker/tests/input/example1.h"
     linker_set_key: "const char *"
-    self_type: "type-39"
+    self_type: "type-48"
+  }
+}
+lvalue_reference_types {
+  type_info {
+    name: "int &"
+    size: 8
+    alignment: 8
+    referenced_type: "type-2"
+    source_file: "/development/vndk/tools/header-checker/tests/input/example1.h"
+    linker_set_key: "int &"
+    self_type: "type-30"
   }
 }
 lvalue_reference_types {
@@ -614,10 +669,21 @@
     name: "const float &"
     size: 8
     alignment: 8
-    referenced_type: "type-25"
+    referenced_type: "type-27"
     source_file: "/development/vndk/tools/header-checker/tests/input/example1.h"
     linker_set_key: "const float &"
-    self_type: "type-34"
+    self_type: "type-37"
+  }
+}
+lvalue_reference_types {
+  type_info {
+    name: "float &"
+    size: 8
+    alignment: 8
+    referenced_type: "type-3"
+    source_file: "/development/vndk/tools/header-checker/tests/input/example1.h"
+    linker_set_key: "float &"
+    self_type: "type-38"
   }
 }
 builtin_types {
@@ -703,10 +769,10 @@
     name: "wchar_t"
     size: 4
     alignment: 4
-    referenced_type: "type-20"
+    referenced_type: "type-22"
     source_file: ""
     linker_set_key: "wchar_t"
-    self_type: "type-20"
+    self_type: "type-22"
   }
   is_unsigned: false
   is_integral: true
@@ -716,10 +782,10 @@
     name: "char"
     size: 1
     alignment: 1
-    referenced_type: "type-40"
+    referenced_type: "type-49"
     source_file: ""
     linker_set_key: "char"
-    self_type: "type-40"
+    self_type: "type-49"
   }
   is_unsigned: false
   is_integral: true
@@ -746,7 +812,7 @@
     referenced_type: "type-2"
     source_file: "/development/vndk/tools/header-checker/tests/input/example1.h"
     linker_set_key: "const int"
-    self_type: "type-24"
+    self_type: "type-26"
   }
   is_const: true
   is_volatile: false
@@ -760,7 +826,7 @@
     referenced_type: "type-3"
     source_file: "/development/vndk/tools/header-checker/tests/input/example1.h"
     linker_set_key: "const float"
-    self_type: "type-25"
+    self_type: "type-27"
   }
   is_const: true
   is_volatile: false
@@ -771,10 +837,24 @@
     name: "const CPPHello"
     size: 56
     alignment: 8
-    referenced_type: "type-23"
+    referenced_type: "type-25"
     source_file: "/development/vndk/tools/header-checker/tests/input/example1.h"
     linker_set_key: "const CPPHello"
-    self_type: "type-28"
+    self_type: "type-32"
+  }
+  is_const: true
+  is_volatile: false
+  is_restricted: false
+}
+qualified_types {
+  type_info {
+    name: "const List<float>::_Node"
+    size: 24
+    alignment: 8
+    referenced_type: "type-35"
+    source_file: "/development/vndk/tools/header-checker/tests/input/example1.h"
+    linker_set_key: "const List<float>::_Node"
+    self_type: "type-39"
   }
   is_const: true
   is_volatile: false
@@ -785,10 +865,10 @@
     name: "const char"
     size: 1
     alignment: 1
-    referenced_type: "type-40"
+    referenced_type: "type-49"
     source_file: "/development/vndk/tools/header-checker/tests/input/example1.h"
     linker_set_key: "const char"
-    self_type: "type-38"
+    self_type: "type-47"
   }
   is_const: true
   is_volatile: false
@@ -855,10 +935,22 @@
 }
 functions {
   return_type: "type-2"
+  function_name: "uses_forward_decl"
+  source_file: "/development/vndk/tools/header-checker/tests/input/example1.h"
+  parameters {
+    referenced_type: "type-20"
+    default_arg: false
+    is_this_ptr: false
+  }
+  linker_set_key: "uses_forward_decl"
+  access: public_access
+}
+functions {
+  return_type: "type-2"
   function_name: "CPPHello::again"
   source_file: "/development/vndk/tools/header-checker/tests/input/example1.h"
   parameters {
-    referenced_type: "type-26"
+    referenced_type: "type-28"
     default_arg: false
     is_this_ptr: true
   }
@@ -870,7 +962,7 @@
   function_name: "CPPHello::CPPHello"
   source_file: "/development/vndk/tools/header-checker/tests/input/example1.h"
   parameters {
-    referenced_type: "type-26"
+    referenced_type: "type-28"
     default_arg: false
     is_this_ptr: true
   }
@@ -882,7 +974,7 @@
   function_name: "CPPHello::CPPHello"
   source_file: "/development/vndk/tools/header-checker/tests/input/example1.h"
   parameters {
-    referenced_type: "type-26"
+    referenced_type: "type-28"
     default_arg: false
     is_this_ptr: true
   }
@@ -894,7 +986,7 @@
   function_name: "CPPHello::test_enum"
   source_file: "/development/vndk/tools/header-checker/tests/input/example1.h"
   parameters {
-    referenced_type: "type-26"
+    referenced_type: "type-28"
     default_arg: false
     is_this_ptr: true
   }
@@ -902,21 +994,38 @@
   access: public_access
 }
 functions {
+  return_type: "type-6"
+  function_name: "fooVariadic"
+  source_file: "/development/vndk/tools/header-checker/tests/input/example1.h"
+  parameters {
+    referenced_type: "type-30"
+    default_arg: false
+    is_this_ptr: false
+  }
+  parameters {
+    referenced_type: "type-31"
+    default_arg: false
+    is_this_ptr: false
+  }
+  linker_set_key: "_Z11fooVariadicRiPiz"
+  access: public_access
+}
+functions {
   return_type: "type-2"
   function_name: "boo"
   source_file: "/development/vndk/tools/header-checker/tests/input/example1.h"
   parameters {
-    referenced_type: "type-28"
+    referenced_type: "type-32"
     default_arg: false
     is_this_ptr: false
   }
   parameters {
-    referenced_type: "type-29"
+    referenced_type: "type-31"
     default_arg: false
     is_this_ptr: false
   }
   parameters {
-    referenced_type: "type-30"
+    referenced_type: "type-33"
     default_arg: false
     is_this_ptr: false
   }
@@ -928,12 +1037,12 @@
   function_name: "List<float>::_Node::_Node"
   source_file: "/development/vndk/tools/header-checker/tests/input/example1.h"
   parameters {
-    referenced_type: "type-33"
+    referenced_type: "type-36"
     default_arg: false
     is_this_ptr: true
   }
   parameters {
-    referenced_type: "type-34"
+    referenced_type: "type-37"
     default_arg: false
     is_this_ptr: false
   }
@@ -945,12 +1054,12 @@
   function_name: "List<float>::_Node::_Node"
   source_file: "/development/vndk/tools/header-checker/tests/input/example1.h"
   parameters {
-    referenced_type: "type-33"
+    referenced_type: "type-36"
     default_arg: false
     is_this_ptr: true
   }
   parameters {
-    referenced_type: "type-34"
+    referenced_type: "type-37"
     default_arg: false
     is_this_ptr: false
   }
@@ -962,7 +1071,7 @@
   function_name: "List<float>::_Node::~_Node"
   source_file: "/development/vndk/tools/header-checker/tests/input/example1.h"
   parameters {
-    referenced_type: "type-33"
+    referenced_type: "type-36"
     default_arg: false
     is_this_ptr: true
   }
@@ -974,7 +1083,7 @@
   function_name: "List<float>::_Node::~_Node"
   source_file: "/development/vndk/tools/header-checker/tests/input/example1.h"
   parameters {
-    referenced_type: "type-33"
+    referenced_type: "type-36"
     default_arg: false
     is_this_ptr: true
   }
@@ -982,16 +1091,69 @@
   access: public_access
 }
 functions {
-  return_type: "type-31"
-  function_name: "castInterface"
+  return_type: "type-38"
+  function_name: "List<float>::_Node::getRef"
   source_file: "/development/vndk/tools/header-checker/tests/input/example1.h"
   parameters {
-    referenced_type: "type-31"
+    referenced_type: "type-36"
+    default_arg: false
+    is_this_ptr: true
+  }
+  linker_set_key: "_ZN4ListIfE5_Node6getRefEv"
+  access: public_access
+}
+functions {
+  return_type: "type-37"
+  function_name: "List<float>::_Node::getRef"
+  source_file: "/development/vndk/tools/header-checker/tests/input/example1.h"
+  parameters {
+    referenced_type: "type-40"
+    default_arg: false
+    is_this_ptr: true
+  }
+  linker_set_key: "_ZNK4ListIfE5_Node6getRefEv"
+  access: public_access
+}
+functions {
+  return_type: "type-6"
+  function_name: "List<float>::_Node::PrivateNode"
+  source_file: "/development/vndk/tools/header-checker/tests/input/example1.h"
+  parameters {
+    referenced_type: "type-36"
+    default_arg: false
+    is_this_ptr: true
+  }
+  linker_set_key: "_ZN4ListIfE5_Node11PrivateNodeEv"
+  access: private_access
+}
+functions {
+  return_type: "type-2"
+  function_name: "ListMangle"
+  source_file: "/development/vndk/tools/header-checker/tests/input/example1.h"
+  parameters {
+    referenced_type: "type-44"
     default_arg: false
     is_this_ptr: false
   }
   parameters {
-    referenced_type: "type-39"
+    referenced_type: "type-46"
+    default_arg: false
+    is_this_ptr: false
+  }
+  linker_set_key: "_Z10ListMangleP4ListIiEP9StackNodeIiE"
+  access: public_access
+}
+functions {
+  return_type: "type-34"
+  function_name: "castInterface"
+  source_file: "/development/vndk/tools/header-checker/tests/input/example1.h"
+  parameters {
+    referenced_type: "type-34"
+    default_arg: false
+    is_this_ptr: false
+  }
+  parameters {
+    referenced_type: "type-48"
     default_arg: false
     is_this_ptr: false
   }
@@ -1056,20 +1218,20 @@
   name: "float_list_test"
   source_file: "/development/vndk/tools/header-checker/tests/input/example1.h"
   linker_set_key: "float_list_test"
-  referenced_type: "type-31"
+  referenced_type: "type-34"
   access: public_access
 }
 global_vars {
   name: "int_list_test"
   source_file: "/development/vndk/tools/header-checker/tests/input/example1.h"
   linker_set_key: "int_list_test"
-  referenced_type: "type-35"
+  referenced_type: "type-41"
   access: public_access
 }
 global_vars {
   name: "node"
   source_file: "/development/vndk/tools/header-checker/tests/input/example1.h"
   linker_set_key: "node"
-  referenced_type: "type-32"
+  referenced_type: "type-35"
   access: public_access
 }
diff --git a/vndk/tools/header-checker/tests/expected/example2.h b/vndk/tools/header-checker/tests/expected/example2.h
index 3a46a95..316441c 100644
--- a/vndk/tools/header-checker/tests/expected/example2.h
+++ b/vndk/tools/header-checker/tests/expected/example2.h
@@ -124,10 +124,10 @@
     name: "test3::ByeAgain<float>"
     size: 8
     alignment: 4
-    referenced_type: "type-15"
+    referenced_type: "type-16"
     source_file: "/development/vndk/tools/header-checker/tests/input/example2.h"
     linker_set_key: "test3::ByeAgain<float>"
-    self_type: "type-15"
+    self_type: "type-16"
   }
   fields {
     referenced_type: "type-3"
@@ -157,10 +157,10 @@
     name: "test3::Outer"
     size: 4
     alignment: 4
-    referenced_type: "type-17"
+    referenced_type: "type-19"
     source_file: "/development/vndk/tools/header-checker/tests/input/example2.h"
     linker_set_key: "test3::Outer"
-    self_type: "type-17"
+    self_type: "type-19"
   }
   fields {
     referenced_type: "type-2"
@@ -179,10 +179,10 @@
     name: "test3::Outer::Inner"
     size: 4
     alignment: 4
-    referenced_type: "type-18"
+    referenced_type: "type-20"
     source_file: "/development/vndk/tools/header-checker/tests/input/example2.h"
     linker_set_key: "test3::Outer::Inner"
-    self_type: "type-18"
+    self_type: "type-20"
   }
   fields {
     referenced_type: "type-2"
@@ -225,10 +225,10 @@
     name: "test3::Kind"
     size: 4
     alignment: 4
-    referenced_type: "type-16"
+    referenced_type: "type-18"
     source_file: "/development/vndk/tools/header-checker/tests/input/example2.h"
     linker_set_key: "test3::Kind"
-    self_type: "type-16"
+    self_type: "type-18"
   }
   underlying_type: "type-9"
   enum_fields {
@@ -252,7 +252,29 @@
     referenced_type: "type-4"
     source_file: "/development/vndk/tools/header-checker/tests/input/example2.h"
     linker_set_key: "test2::HelloAgain *"
-    self_type: "type-7"
+    self_type: "type-6"
+  }
+}
+pointer_types {
+  type_info {
+    name: "test3::ByeAgain<double> *"
+    size: 8
+    alignment: 8
+    referenced_type: "type-13"
+    source_file: "/development/vndk/tools/header-checker/tests/input/example2.h"
+    linker_set_key: "test3::ByeAgain<double> *"
+    self_type: "type-15"
+  }
+}
+pointer_types {
+  type_info {
+    name: "test3::ByeAgain<float> *"
+    size: 8
+    alignment: 8
+    referenced_type: "type-16"
+    source_file: "/development/vndk/tools/header-checker/tests/input/example2.h"
+    linker_set_key: "test3::ByeAgain<float> *"
+    self_type: "type-17"
   }
 }
 builtin_types {
@@ -286,10 +308,10 @@
     name: "void"
     size: 0
     alignment: 0
-    referenced_type: "type-6"
+    referenced_type: "type-7"
     source_file: ""
     linker_set_key: "void"
-    self_type: "type-6"
+    self_type: "type-7"
   }
   is_unsigned: false
   is_integral: false
@@ -359,11 +381,23 @@
   }
 }
 functions {
-  return_type: "type-6"
+  return_type: "type-2"
+  function_name: "test2::HelloAgain::again"
+  source_file: "/development/vndk/tools/header-checker/tests/input/example2.h"
+  parameters {
+    referenced_type: "type-6"
+    default_arg: false
+    is_this_ptr: true
+  }
+  linker_set_key: "_ZN5test210HelloAgain5againEv"
+  access: public_access
+}
+functions {
+  return_type: "type-7"
   function_name: "test2::HelloAgain::~HelloAgain"
   source_file: "/development/vndk/tools/header-checker/tests/input/example2.h"
   parameters {
-    referenced_type: "type-7"
+    referenced_type: "type-6"
     default_arg: false
     is_this_ptr: true
   }
@@ -371,11 +405,11 @@
   access: public_access
 }
 functions {
-  return_type: "type-6"
+  return_type: "type-7"
   function_name: "test2::HelloAgain::~HelloAgain"
   source_file: "/development/vndk/tools/header-checker/tests/input/example2.h"
   parameters {
-    referenced_type: "type-7"
+    referenced_type: "type-6"
     default_arg: false
     is_this_ptr: true
   }
@@ -383,11 +417,11 @@
   access: public_access
 }
 functions {
-  return_type: "type-6"
+  return_type: "type-7"
   function_name: "test2::HelloAgain::~HelloAgain"
   source_file: "/development/vndk/tools/header-checker/tests/input/example2.h"
   parameters {
-    referenced_type: "type-7"
+    referenced_type: "type-6"
     default_arg: false
     is_this_ptr: true
   }
@@ -395,6 +429,70 @@
   access: public_access
 }
 functions {
+  return_type: "type-14"
+  function_name: "test3::ByeAgain<double>::method_foo"
+  source_file: "/development/vndk/tools/header-checker/tests/input/example2.h"
+  parameters {
+    referenced_type: "type-15"
+    default_arg: false
+    is_this_ptr: true
+  }
+  parameters {
+    referenced_type: "type-14"
+    default_arg: false
+    is_this_ptr: false
+  }
+  linker_set_key: "_ZN5test38ByeAgainIdE10method_fooEd"
+  access: public_access
+}
+functions {
+  return_type: "type-3"
+  function_name: "test3::ByeAgain<float>::method_foo"
+  source_file: "/development/vndk/tools/header-checker/tests/input/example2.h"
+  parameters {
+    referenced_type: "type-17"
+    default_arg: false
+    is_this_ptr: true
+  }
+  parameters {
+    referenced_type: "type-2"
+    default_arg: false
+    is_this_ptr: false
+  }
+  linker_set_key: "_ZN5test38ByeAgainIfE10method_fooEi"
+  access: public_access
+}
+functions {
+  return_type: "type-12"
+  function_name: "test3::Begin"
+  source_file: "/development/vndk/tools/header-checker/tests/input/example2.h"
+  parameters {
+    referenced_type: "type-3"
+    default_arg: false
+    is_this_ptr: false
+  }
+  parameters {
+    referenced_type: "type-2"
+    default_arg: false
+    is_this_ptr: false
+  }
+  parameters {
+    referenced_type: "type-2"
+    default_arg: false
+    is_this_ptr: false
+  }
+  template_info {
+    elements {
+      referenced_type: "type-3"
+    }
+    elements {
+      referenced_type: "type-2"
+    }
+  }
+  linker_set_key: "_ZN5test35BeginIfiEEbT_T0_i"
+  access: public_access
+}
+functions {
   return_type: "type-12"
   function_name: "test3::End"
   source_file: "/development/vndk/tools/header-checker/tests/input/example2.h"
@@ -406,6 +504,18 @@
   linker_set_key: "_ZN5test33EndEf"
   access: public_access
 }
+functions {
+  return_type: "type-21"
+  function_name: "test3::Dummy"
+  source_file: "/development/vndk/tools/header-checker/tests/input/example2.h"
+  parameters {
+    referenced_type: "type-2"
+    default_arg: false
+    is_this_ptr: false
+  }
+  linker_set_key: "_ZN5test35DummyEi"
+  access: public_access
+}
 global_vars {
   name: "test2::HelloAgain::hello_forever"
   source_file: "/development/vndk/tools/header-checker/tests/input/example2.h"
diff --git a/vndk/tools/header-checker/tests/expected/example4.h b/vndk/tools/header-checker/tests/expected/example4.h
deleted file mode 100644
index 2d0a935..0000000
--- a/vndk/tools/header-checker/tests/expected/example4.h
+++ /dev/null
@@ -1,96 +0,0 @@
-record_types {
-  type_info {
-    name: "Test"
-    size: 16
-    alignment: 8
-    referenced_type: "type-1"
-    source_file: "/development/vndk/tools/header-checker/tests/input/example4.h"
-    linker_set_key: "Test"
-    self_type: "type-1"
-  }
-  fields {
-    referenced_type: "type-2"
-    field_offset: 64
-    field_name: "c"
-    access: private_access
-  }
-  vtable_layout {
-    vtable_components {
-      kind: OffsetToTop
-      mangled_component_name: ""
-      component_value: 0
-    }
-    vtable_components {
-      kind: RTTI
-      mangled_component_name: "_ZTI4Test"
-      component_value: 0
-    }
-    vtable_components {
-      kind: FunctionPointer
-      mangled_component_name: "_ZN4Test3fooEv"
-      component_value: 0
-    }
-  }
-  access: public_access
-  record_kind: class_kind
-  tag_info {
-    unique_id: "_ZTS4Test"
-  }
-}
-record_types {
-  type_info {
-    name: "TestChild"
-    size: 16
-    alignment: 8
-    referenced_type: "type-3"
-    source_file: "/development/vndk/tools/header-checker/tests/input/example4.h"
-    linker_set_key: "TestChild"
-    self_type: "type-3"
-  }
-  fields {
-    referenced_type: "type-2"
-    field_offset: 96
-    field_name: "d"
-    access: private_access
-  }
-  base_specifiers {
-    referenced_type: "type-1"
-    is_virtual: false
-    access: public_access
-  }
-  vtable_layout {
-    vtable_components {
-      kind: OffsetToTop
-      mangled_component_name: ""
-      component_value: 0
-    }
-    vtable_components {
-      kind: RTTI
-      mangled_component_name: "_ZTI9TestChild"
-      component_value: 0
-    }
-    vtable_components {
-      kind: FunctionPointer
-      mangled_component_name: "_ZN9TestChild3fooEv"
-      component_value: 0
-    }
-  }
-  access: public_access
-  record_kind: class_kind
-  tag_info {
-    unique_id: "_ZTS9TestChild"
-  }
-}
-builtin_types {
-  type_info {
-    name: "int"
-    size: 4
-    alignment: 4
-    referenced_type: "type-2"
-    source_file: ""
-    linker_set_key: "int"
-    self_type: "type-2"
-  }
-  is_unsigned: false
-  is_integral: true
-}
diff --git a/vndk/tools/header-checker/tests/expected/func_decl_no_args.h b/vndk/tools/header-checker/tests/expected/func_decl_no_args.h
deleted file mode 100644
index e69de29..0000000
--- a/vndk/tools/header-checker/tests/expected/func_decl_no_args.h
+++ /dev/null
diff --git a/vndk/tools/header-checker/tests/expected/func_decl_one_arg.h b/vndk/tools/header-checker/tests/expected/func_decl_one_arg.h
deleted file mode 100644
index e69de29..0000000
--- a/vndk/tools/header-checker/tests/expected/func_decl_one_arg.h
+++ /dev/null
diff --git a/vndk/tools/header-checker/tests/expected/func_decl_one_arg_ret.h b/vndk/tools/header-checker/tests/expected/func_decl_one_arg_ret.h
deleted file mode 100644
index e69de29..0000000
--- a/vndk/tools/header-checker/tests/expected/func_decl_one_arg_ret.h
+++ /dev/null
diff --git a/vndk/tools/header-checker/tests/expected/func_decl_two_args.h b/vndk/tools/header-checker/tests/expected/func_decl_two_args.h
deleted file mode 100644
index e69de29..0000000
--- a/vndk/tools/header-checker/tests/expected/func_decl_two_args.h
+++ /dev/null
diff --git a/vndk/tools/header-checker/tests/gen_expected_output.py b/vndk/tools/header-checker/tests/gen_expected_output.py
deleted file mode 100755
index f285183..0000000
--- a/vndk/tools/header-checker/tests/gen_expected_output.py
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/usr/bin/env python3
-
-import sys
-from utils import run_header_abi_dumper
-
-def main():
-    sys.stdout.write(run_header_abi_dumper(sys.argv[1], True, sys.argv[2:]))
-    return 0
-
-if __name__ == '__main__':
-    sys.exit(main())
diff --git a/vndk/tools/header-checker/tests/input/example1.h b/vndk/tools/header-checker/tests/input/example1.h
index b93eccc..a278d32 100644
--- a/vndk/tools/header-checker/tests/input/example1.h
+++ b/vndk/tools/header-checker/tests/input/example1.h
@@ -37,6 +37,7 @@
   cfloat_type cpp_bar;
   virtual int again() { return 0; }
   CPPHello() : cpp_foo(20), cpp_bar(1.234) {}
+  CPPHello(CPPHello &) = delete;
   enum Bla{BLA = 1};
   int test_enum() {return CPPHello::BLA;}
 };
diff --git a/vndk/tools/header-checker/tests/input/func_decl_no_args.h b/vndk/tools/header-checker/tests/input/func_decl_no_args.h
deleted file mode 100644
index b4bc10f..0000000
--- a/vndk/tools/header-checker/tests/input/func_decl_no_args.h
+++ /dev/null
@@ -1,40 +0,0 @@
-#ifndef FUNC_DECL_NO_ARGS_H_
-#define FUNC_DECL_NO_ARGS_H_
-
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-extern void test_void();
-
-extern char test_char();
-
-extern short test_short();
-
-extern int test_int();
-
-extern long test_long();
-
-extern long long test_long_long();
-
-extern unsigned char test_unsigned_char();
-
-extern unsigned short test_unsigned_short();
-
-extern unsigned int test_unsigned_int();
-
-extern unsigned long test_unsigned_long();
-
-extern unsigned long long test_unsigned_long_long();
-
-extern float test_float();
-
-extern double test_double();
-
-extern long double test_long_double();
-
-#if defined(__cplusplus)
-}  // extern "C"
-#endif
-
-#endif  // FUNC_DECL_NO_ARGS_H_
diff --git a/vndk/tools/header-checker/tests/input/func_decl_one_arg.h b/vndk/tools/header-checker/tests/input/func_decl_one_arg.h
deleted file mode 100644
index e1c9796..0000000
--- a/vndk/tools/header-checker/tests/input/func_decl_one_arg.h
+++ /dev/null
@@ -1,38 +0,0 @@
-#ifndef FUNC_DECL_ONE_ARG_H_
-#define FUNC_DECL_ONE_ARG_H_
-
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-extern void test_char(char);
-
-extern void test_short(short);
-
-extern void test_int(int);
-
-extern void test_long(long);
-
-extern void test_long_long(long long);
-
-extern void test_unsigned_char(unsigned char);
-
-extern void test_unsigned_short(unsigned short);
-
-extern void test_unsigned_int(unsigned int);
-
-extern void test_unsigned_long(unsigned long);
-
-extern void test_unsigned_long_long(unsigned long long);
-
-extern void test_float(float);
-
-extern void test_double(double);
-
-extern void test_long_double(long double);
-
-#if defined(__cplusplus)
-}  // extern "C"
-#endif
-
-#endif  // FUNC_DECL_ONE_ARG_H_
diff --git a/vndk/tools/header-checker/tests/input/func_decl_one_arg_ret.h b/vndk/tools/header-checker/tests/input/func_decl_one_arg_ret.h
deleted file mode 100644
index 84d2c63..0000000
--- a/vndk/tools/header-checker/tests/input/func_decl_one_arg_ret.h
+++ /dev/null
@@ -1,38 +0,0 @@
-#ifndef FUNC_DECL_ONE_ARG_RET_H_
-#define FUNC_DECL_ONE_ARG_RET_H_
-
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-extern char test_char(char);
-
-extern short test_short(short);
-
-extern int test_int(int);
-
-extern long test_long(long);
-
-extern long long test_long_long(long long);
-
-extern unsigned char test_unsigned_char(unsigned char);
-
-extern unsigned short test_unsigned_short(unsigned short);
-
-extern unsigned int test_unsigned_int(unsigned int);
-
-extern unsigned long test_unsigned_long(unsigned long);
-
-extern unsigned long long test_unsigned_long_long(unsigned long long);
-
-extern float test_float(float);
-
-extern double test_double(double);
-
-extern long double test_long_double(long double);
-
-#if defined(__cplusplus)
-}  // extern "C"
-#endif
-
-#endif  // FUNC_DECL_ONE_ARG_RET_H_
diff --git a/vndk/tools/header-checker/tests/input/func_decl_two_args.h b/vndk/tools/header-checker/tests/input/func_decl_two_args.h
deleted file mode 100644
index 5b4c8a3..0000000
--- a/vndk/tools/header-checker/tests/input/func_decl_two_args.h
+++ /dev/null
@@ -1,38 +0,0 @@
-#ifndef FUNC_DECL_TWO_ARGS_H_
-#define FUNC_DECL_TWO_ARGS_H_
-
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-extern void test_char(int, char);
-
-extern void test_short(int, short);
-
-extern void test_int(int, int);
-
-extern void test_long(int, long);
-
-extern void test_long_long(int, long long);
-
-extern void test_unsigned_char(int, unsigned char);
-
-extern void test_unsigned_short(int, unsigned short);
-
-extern void test_unsigned_int(int, unsigned int);
-
-extern void test_unsigned_long(int, unsigned long);
-
-extern void test_unsigned_long_long(int, unsigned long long);
-
-extern void test_unsigned_float(int, float);
-
-extern void test_unsigned_double(int, double);
-
-extern void test_unsigned_long_double(int, long double);
-
-#if defined(__cplusplus)
-}  // extern "C"
-#endif
-
-#endif  // FUNC_DECL_TWO_ARGS_H_
diff --git a/vndk/tools/header-checker/tests/test.py b/vndk/tools/header-checker/tests/test.py
index da0fc6c..ad2db84 100755
--- a/vndk/tools/header-checker/tests/test.py
+++ b/vndk/tools/header-checker/tests/test.py
@@ -97,22 +97,18 @@
                     read_output_content(old_ref_dump_path, AOSP_DIR),
                     read_output_content(new_ref_dump_path, AOSP_DIR))
 
-    def test_func_decl_no_args(self):
-        self.run_and_compare_name_c_cpp('func_decl_no_args.h')
+    def test_example1_cpp(self):
+        self.run_and_compare_name_cpp('example1.cpp')
 
-    def test_func_decl_one_arg(self):
-        self.run_and_compare_name_c_cpp('func_decl_one_arg.h')
-
-    def test_func_decl_two_args(self):
-        self.run_and_compare_name_c_cpp('func_decl_two_args.h')
-
-    def test_func_decl_one_arg_ret(self):
-        self.run_and_compare_name_c_cpp('func_decl_one_arg_ret.h')
-
-    def test_example1(self):
+    def test_example1_h(self):
         self.run_and_compare_name_cpp('example1.h')
+
+    def test_example2_h(self):
         self.run_and_compare_name_cpp('example2.h')
 
+    def test_example3_h(self):
+        self.run_and_compare_name_cpp('example3.h')
+
     def test_libc_and_cpp(self):
         self.prepare_and_run_abi_diff_all_archs(
             "libc_and_cpp", "libc_and_cpp", 0)
diff --git a/vndk/tools/header-checker/utils/utils.py b/vndk/tools/header-checker/utils/utils.py
index 989af99..fbccbeb 100644
--- a/vndk/tools/header-checker/utils/utils.py
+++ b/vndk/tools/header-checker/utils/utils.py
@@ -19,7 +19,7 @@
 BUILTIN_HEADERS_DIR = (
     os.path.join(AOSP_DIR, 'bionic', 'libc', 'include'),
     os.path.join(AOSP_DIR, 'external', 'libcxx', 'include'),
-    os.path.join(AOSP_DIR, 'prebuilts', 'sdk', 'renderscript', 'clang-include'),
+    os.path.join(AOSP_DIR, 'prebuilts', 'clang-tools', 'linux-x86', 'clang-headers'),
 )
 
 EXPORTED_HEADERS_DIR = (
@@ -35,6 +35,7 @@
 
 DEFAULT_CPPFLAGS = ['-x', 'c++', '-std=c++11']
 DEFAULT_CFLAGS = ['-std=gnu99']
+DEFAULT_HEADER_FLAGS = ["-dump-function-declarations"]
 DEFAULT_FORMAT = 'ProtobufTextFormat'
 
 TARGET_ARCHS = ['arm', 'arm64', 'x86', 'x86_64', 'mips', 'mips64']
@@ -120,6 +121,8 @@
     cmd += flags
     if '-output-format' not in flags:
         cmd += ['-output-format', DEFAULT_FORMAT]
+    if input_ext == ".h":
+        cmd += DEFAULT_HEADER_FLAGS
     cmd += ['--']
     cmd += cflags
     if input_ext in ('.cpp', '.cc', '.h'):