| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 1 | //===- ASTWriter.cpp - AST File Writer ------------------------------------===// | 
| Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2 | // | 
| Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | 
|  | 4 | // See https://llvm.org/LICENSE.txt for license information. | 
|  | 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | 
| Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 6 | // | 
|  | 7 | //===----------------------------------------------------------------------===// | 
|  | 8 | // | 
| Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 9 | //  This file defines the ASTWriter class, which writes AST files. | 
| Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 10 | // | 
|  | 11 | //===----------------------------------------------------------------------===// | 
|  | 12 |  | 
| Alexey Bataev | b6e7084 | 2019-12-16 15:54:17 -0500 | [diff] [blame] | 13 | #include "clang/AST/OpenMPClause.h" | 
| John McCall | 2ac702a | 2019-12-14 03:17:03 -0500 | [diff] [blame] | 14 | #include "clang/Serialization/ASTRecordWriter.h" | 
| Argyrios Kyrtzidis | 4bd9710 | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 15 | #include "ASTCommon.h" | 
| Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 16 | #include "ASTReaderInternals.h" | 
|  | 17 | #include "MultiOnDiskHashTable.h" | 
| John McCall | d505e57 | 2019-12-13 21:54:44 -0500 | [diff] [blame] | 18 | #include "clang/AST/AbstractTypeWriter.h" | 
| Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 19 | #include "clang/AST/ASTContext.h" | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 20 | #include "clang/AST/ASTUnresolvedSet.h" | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 21 | #include "clang/AST/Attr.h" | 
| Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 22 | #include "clang/AST/Decl.h" | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 23 | #include "clang/AST/DeclBase.h" | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 24 | #include "clang/AST/DeclCXX.h" | 
| Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 25 | #include "clang/AST/DeclContextInternals.h" | 
| Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 26 | #include "clang/AST/DeclFriend.h" | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 27 | #include "clang/AST/DeclObjC.h" | 
| Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 28 | #include "clang/AST/DeclTemplate.h" | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 29 | #include "clang/AST/DeclarationName.h" | 
| Douglas Gregor | feb84b0 | 2009-04-14 21:18:50 +0000 | [diff] [blame] | 30 | #include "clang/AST/Expr.h" | 
| John McCall | bfd822c | 2010-08-24 07:32:53 +0000 | [diff] [blame] | 31 | #include "clang/AST/ExprCXX.h" | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 32 | #include "clang/AST/LambdaCapture.h" | 
|  | 33 | #include "clang/AST/NestedNameSpecifier.h" | 
|  | 34 | #include "clang/AST/RawCommentList.h" | 
|  | 35 | #include "clang/AST/TemplateName.h" | 
| Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 36 | #include "clang/AST/Type.h" | 
| John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 37 | #include "clang/AST/TypeLocVisitor.h" | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 38 | #include "clang/Basic/Diagnostic.h" | 
| Benjamin Kramer | f3ca2698 | 2014-05-10 16:31:55 +0000 | [diff] [blame] | 39 | #include "clang/Basic/DiagnosticOptions.h" | 
| Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 40 | #include "clang/Basic/FileManager.h" | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 41 | #include "clang/Basic/FileSystemOptions.h" | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 42 | #include "clang/Basic/IdentifierTable.h" | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 43 | #include "clang/Basic/LLVM.h" | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 44 | #include "clang/Basic/Lambda.h" | 
| Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 45 | #include "clang/Basic/LangOptions.h" | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 46 | #include "clang/Basic/Module.h" | 
|  | 47 | #include "clang/Basic/ObjCRuntime.h" | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 48 | #include "clang/Basic/OpenCLOptions.h" | 
|  | 49 | #include "clang/Basic/SourceLocation.h" | 
| Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 50 | #include "clang/Basic/SourceManager.h" | 
| Douglas Gregor | 4c7626e | 2009-04-13 16:31:14 +0000 | [diff] [blame] | 51 | #include "clang/Basic/SourceManagerInternals.h" | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 52 | #include "clang/Basic/Specifiers.h" | 
| Douglas Gregor | bfbde53 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 53 | #include "clang/Basic/TargetInfo.h" | 
| Douglas Gregor | cb177f1 | 2012-10-16 23:40:58 +0000 | [diff] [blame] | 54 | #include "clang/Basic/TargetOptions.h" | 
| Douglas Gregor | 7b71e63 | 2009-04-27 22:23:34 +0000 | [diff] [blame] | 55 | #include "clang/Basic/Version.h" | 
| Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 56 | #include "clang/Lex/HeaderSearch.h" | 
|  | 57 | #include "clang/Lex/HeaderSearchOptions.h" | 
|  | 58 | #include "clang/Lex/MacroInfo.h" | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 59 | #include "clang/Lex/ModuleMap.h" | 
| Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 60 | #include "clang/Lex/PreprocessingRecord.h" | 
|  | 61 | #include "clang/Lex/Preprocessor.h" | 
|  | 62 | #include "clang/Lex/PreprocessorOptions.h" | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 63 | #include "clang/Lex/Token.h" | 
| Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 64 | #include "clang/Sema/IdentifierResolver.h" | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 65 | #include "clang/Sema/ObjCMethodList.h" | 
| Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 66 | #include "clang/Sema/Sema.h" | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 67 | #include "clang/Sema/Weak.h" | 
| Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 68 | #include "clang/Serialization/ASTReader.h" | 
| Duncan P. N. Exon Smith | 8bef5cd | 2019-03-09 17:33:56 +0000 | [diff] [blame] | 69 | #include "clang/Serialization/InMemoryModuleCache.h" | 
| Duncan P. N. Exon Smith | f7170d1 | 2019-11-21 18:49:05 -0800 | [diff] [blame] | 70 | #include "clang/Serialization/ModuleFile.h" | 
| Mehdi Amini | 9670f84 | 2016-07-18 19:02:11 +0000 | [diff] [blame] | 71 | #include "clang/Serialization/ModuleFileExtension.h" | 
| Richard Smith | b5aaf5a | 2015-09-01 02:35:58 +0000 | [diff] [blame] | 72 | #include "clang/Serialization/SerializationDiagnostic.h" | 
| Douglas Gregor | e0a3a51 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 73 | #include "llvm/ADT/APFloat.h" | 
|  | 74 | #include "llvm/ADT/APInt.h" | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 75 | #include "llvm/ADT/APSInt.h" | 
|  | 76 | #include "llvm/ADT/ArrayRef.h" | 
|  | 77 | #include "llvm/ADT/DenseMap.h" | 
| Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 78 | #include "llvm/ADT/Hashing.h" | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 79 | #include "llvm/ADT/Optional.h" | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 80 | #include "llvm/ADT/PointerIntPair.h" | 
| Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 81 | #include "llvm/ADT/STLExtras.h" | 
| Ilya Biryukov | 4564310 | 2018-07-09 11:33:23 +0000 | [diff] [blame] | 82 | #include "llvm/ADT/ScopeExit.h" | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 83 | #include "llvm/ADT/SmallSet.h" | 
|  | 84 | #include "llvm/ADT/SmallString.h" | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 85 | #include "llvm/ADT/SmallVector.h" | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 86 | #include "llvm/ADT/StringMap.h" | 
|  | 87 | #include "llvm/ADT/StringRef.h" | 
| Francis Visoiu Mistrih | e030827 | 2019-07-03 22:40:07 +0000 | [diff] [blame] | 88 | #include "llvm/Bitstream/BitCodes.h" | 
|  | 89 | #include "llvm/Bitstream/BitstreamWriter.h" | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 90 | #include "llvm/Support/Casting.h" | 
| Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 91 | #include "llvm/Support/Compression.h" | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 92 | #include "llvm/Support/DJB.h" | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 93 | #include "llvm/Support/Endian.h" | 
| Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 94 | #include "llvm/Support/EndianStream.h" | 
| George Rimar | c39f549 | 2017-01-17 15:45:31 +0000 | [diff] [blame] | 95 | #include "llvm/Support/Error.h" | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 96 | #include "llvm/Support/ErrorHandling.h" | 
| Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 97 | #include "llvm/Support/MemoryBuffer.h" | 
| Justin Bogner | bb094f0 | 2014-04-18 19:57:06 +0000 | [diff] [blame] | 98 | #include "llvm/Support/OnDiskHashTable.h" | 
| Michael J. Spencer | 8aaf499 | 2010-11-29 18:12:39 +0000 | [diff] [blame] | 99 | #include "llvm/Support/Path.h" | 
| Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 100 | #include "llvm/Support/SHA1.h" | 
| Pavel Labath | d8c6290 | 2018-06-11 10:28:04 +0000 | [diff] [blame] | 101 | #include "llvm/Support/VersionTuple.h" | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 102 | #include "llvm/Support/raw_ostream.h" | 
| Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 103 | #include <algorithm> | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 104 | #include <cassert> | 
|  | 105 | #include <cstdint> | 
|  | 106 | #include <cstdlib> | 
|  | 107 | #include <cstring> | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 108 | #include <ctime> | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 109 | #include <deque> | 
|  | 110 | #include <limits> | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 111 | #include <memory> | 
|  | 112 | #include <queue> | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 113 | #include <tuple> | 
| Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 114 | #include <utility> | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 115 | #include <vector> | 
| Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 116 |  | 
| Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 117 | using namespace clang; | 
| Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 118 | using namespace clang::serialization; | 
| Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 119 |  | 
| Sebastian Redl | 3df5a08 | 2010-07-30 17:03:48 +0000 | [diff] [blame] | 120 | template <typename T, typename Allocator> | 
| Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 121 | static StringRef bytes(const std::vector<T, Allocator> &v) { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 122 | if (v.empty()) return StringRef(); | 
|  | 123 | return StringRef(reinterpret_cast<const char*>(&v[0]), | 
| Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 124 | sizeof(T) * v.size()); | 
| Sebastian Redl | 3df5a08 | 2010-07-30 17:03:48 +0000 | [diff] [blame] | 125 | } | 
| Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 126 |  | 
|  | 127 | template <typename T> | 
| Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 128 | static StringRef bytes(const SmallVectorImpl<T> &v) { | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 129 | return StringRef(reinterpret_cast<const char*>(v.data()), | 
| Benjamin Kramer | d47a12a | 2011-04-24 17:44:50 +0000 | [diff] [blame] | 130 | sizeof(T) * v.size()); | 
| Sebastian Redl | 3df5a08 | 2010-07-30 17:03:48 +0000 | [diff] [blame] | 131 | } | 
|  | 132 |  | 
| Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 133 | //===----------------------------------------------------------------------===// | 
|  | 134 | // Type serialization | 
|  | 135 | //===----------------------------------------------------------------------===// | 
| Chris Lattner | 7099dbc | 2009-04-27 06:16:06 +0000 | [diff] [blame] | 136 |  | 
| John McCall | d505e57 | 2019-12-13 21:54:44 -0500 | [diff] [blame] | 137 | static TypeCode getTypeCodeForTypeClass(Type::TypeClass id) { | 
|  | 138 | switch (id) { | 
|  | 139 | #define TYPE_BIT_CODE(CLASS_ID, CODE_ID, CODE_VALUE) \ | 
|  | 140 | case Type::CLASS_ID: return TYPE_##CODE_ID; | 
|  | 141 | #include "clang/Serialization/TypeBitCodes.def" | 
|  | 142 | case Type::Builtin: | 
|  | 143 | llvm_unreachable("shouldn't be serializing a builtin type this way"); | 
| Sebastian Redl | fa453cf | 2011-03-12 11:50:43 +0000 | [diff] [blame] | 144 | } | 
| John McCall | d505e57 | 2019-12-13 21:54:44 -0500 | [diff] [blame] | 145 | llvm_unreachable("bad type kind"); | 
| Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 146 | } | 
|  | 147 |  | 
| John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 148 | namespace { | 
|  | 149 |  | 
| John McCall | d505e57 | 2019-12-13 21:54:44 -0500 | [diff] [blame] | 150 | class ASTTypeWriter { | 
|  | 151 | ASTWriter &Writer; | 
|  | 152 | ASTWriter::RecordData Record; | 
|  | 153 | ASTRecordWriter BasicWriter; | 
|  | 154 |  | 
|  | 155 | public: | 
|  | 156 | ASTTypeWriter(ASTWriter &Writer) | 
|  | 157 | : Writer(Writer), BasicWriter(Writer, Record) {} | 
|  | 158 |  | 
|  | 159 | uint64_t write(QualType T) { | 
|  | 160 | if (T.hasLocalNonFastQualifiers()) { | 
|  | 161 | Qualifiers Qs = T.getLocalQualifiers(); | 
|  | 162 | BasicWriter.writeQualType(T.getLocalUnqualifiedType()); | 
|  | 163 | BasicWriter.writeQualifiers(Qs); | 
|  | 164 | return BasicWriter.Emit(TYPE_EXT_QUAL, Writer.getTypeExtQualAbbrev()); | 
|  | 165 | } | 
|  | 166 |  | 
|  | 167 | const Type *typePtr = T.getTypePtr(); | 
|  | 168 | serialization::AbstractTypeWriter<ASTRecordWriter> atw(BasicWriter); | 
|  | 169 | atw.write(typePtr); | 
|  | 170 | return BasicWriter.Emit(getTypeCodeForTypeClass(typePtr->getTypeClass()), | 
|  | 171 | /*abbrev*/ 0); | 
|  | 172 | } | 
|  | 173 | }; | 
|  | 174 |  | 
| John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 175 | class TypeLocWriter : public TypeLocVisitor<TypeLocWriter> { | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 176 | ASTRecordWriter &Record; | 
| John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 177 |  | 
|  | 178 | public: | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 179 | TypeLocWriter(ASTRecordWriter &Record) : Record(Record) {} | 
| John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 180 |  | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 181 | #define ABSTRACT_TYPELOC(CLASS, PARENT) | 
| John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 182 | #define TYPELOC(CLASS, PARENT) \ | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 183 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); | 
| John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 184 | #include "clang/AST/TypeLocNodes.def" | 
|  | 185 |  | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 186 | void VisitArrayTypeLoc(ArrayTypeLoc TyLoc); | 
|  | 187 | void VisitFunctionTypeLoc(FunctionTypeLoc TyLoc); | 
| John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 188 | }; | 
|  | 189 |  | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 190 | } // namespace | 
| John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 191 |  | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 192 | void TypeLocWriter::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { | 
|  | 193 | // nothing to do | 
| John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 194 | } | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 195 |  | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 196 | void TypeLocWriter::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 197 | Record.AddSourceLocation(TL.getBuiltinLoc()); | 
| Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 198 | if (TL.needsExtraLocalData()) { | 
| Faisal Vali | 090da2d | 2018-01-01 18:23:28 +0000 | [diff] [blame] | 199 | Record.push_back(TL.getWrittenTypeSpec()); | 
|  | 200 | Record.push_back(TL.getWrittenSignSpec()); | 
|  | 201 | Record.push_back(TL.getWrittenWidthSpec()); | 
| Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 202 | Record.push_back(TL.hasModeAttr()); | 
|  | 203 | } | 
| John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 204 | } | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 205 |  | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 206 | void TypeLocWriter::VisitComplexTypeLoc(ComplexTypeLoc TL) { | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 207 | Record.AddSourceLocation(TL.getNameLoc()); | 
| John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 208 | } | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 209 |  | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 210 | void TypeLocWriter::VisitPointerTypeLoc(PointerTypeLoc TL) { | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 211 | Record.AddSourceLocation(TL.getStarLoc()); | 
| John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 212 | } | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 213 |  | 
| Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 214 | void TypeLocWriter::VisitDecayedTypeLoc(DecayedTypeLoc TL) { | 
|  | 215 | // nothing to do | 
|  | 216 | } | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 217 |  | 
| Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 218 | void TypeLocWriter::VisitAdjustedTypeLoc(AdjustedTypeLoc TL) { | 
|  | 219 | // nothing to do | 
|  | 220 | } | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 221 |  | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 222 | void TypeLocWriter::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 223 | Record.AddSourceLocation(TL.getCaretLoc()); | 
| John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 224 | } | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 225 |  | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 226 | void TypeLocWriter::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 227 | Record.AddSourceLocation(TL.getAmpLoc()); | 
| John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 228 | } | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 229 |  | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 230 | void TypeLocWriter::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 231 | Record.AddSourceLocation(TL.getAmpAmpLoc()); | 
| John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 232 | } | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 233 |  | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 234 | void TypeLocWriter::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 235 | Record.AddSourceLocation(TL.getStarLoc()); | 
|  | 236 | Record.AddTypeSourceInfo(TL.getClassTInfo()); | 
| John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 237 | } | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 238 |  | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 239 | void TypeLocWriter::VisitArrayTypeLoc(ArrayTypeLoc TL) { | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 240 | Record.AddSourceLocation(TL.getLBracketLoc()); | 
|  | 241 | Record.AddSourceLocation(TL.getRBracketLoc()); | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 242 | Record.push_back(TL.getSizeExpr() ? 1 : 0); | 
|  | 243 | if (TL.getSizeExpr()) | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 244 | Record.AddStmt(TL.getSizeExpr()); | 
| John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 245 | } | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 246 |  | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 247 | void TypeLocWriter::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { | 
|  | 248 | VisitArrayTypeLoc(TL); | 
|  | 249 | } | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 250 |  | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 251 | void TypeLocWriter::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { | 
|  | 252 | VisitArrayTypeLoc(TL); | 
|  | 253 | } | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 254 |  | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 255 | void TypeLocWriter::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { | 
|  | 256 | VisitArrayTypeLoc(TL); | 
|  | 257 | } | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 258 |  | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 259 | void TypeLocWriter::VisitDependentSizedArrayTypeLoc( | 
|  | 260 | DependentSizedArrayTypeLoc TL) { | 
|  | 261 | VisitArrayTypeLoc(TL); | 
|  | 262 | } | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 263 |  | 
| Andrew Gozillon | 572bbb0 | 2017-10-02 06:25:51 +0000 | [diff] [blame] | 264 | void TypeLocWriter::VisitDependentAddressSpaceTypeLoc( | 
|  | 265 | DependentAddressSpaceTypeLoc TL) { | 
|  | 266 | Record.AddSourceLocation(TL.getAttrNameLoc()); | 
|  | 267 | SourceRange range = TL.getAttrOperandParensRange(); | 
|  | 268 | Record.AddSourceLocation(range.getBegin()); | 
|  | 269 | Record.AddSourceLocation(range.getEnd()); | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 270 | Record.AddStmt(TL.getAttrExprOperand()); | 
| Andrew Gozillon | 572bbb0 | 2017-10-02 06:25:51 +0000 | [diff] [blame] | 271 | } | 
|  | 272 |  | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 273 | void TypeLocWriter::VisitDependentSizedExtVectorTypeLoc( | 
|  | 274 | DependentSizedExtVectorTypeLoc TL) { | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 275 | Record.AddSourceLocation(TL.getNameLoc()); | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 276 | } | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 277 |  | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 278 | void TypeLocWriter::VisitVectorTypeLoc(VectorTypeLoc TL) { | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 279 | Record.AddSourceLocation(TL.getNameLoc()); | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 280 | } | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 281 |  | 
| Erich Keane | f702b02 | 2018-07-13 19:46:04 +0000 | [diff] [blame] | 282 | void TypeLocWriter::VisitDependentVectorTypeLoc( | 
|  | 283 | DependentVectorTypeLoc TL) { | 
|  | 284 | Record.AddSourceLocation(TL.getNameLoc()); | 
|  | 285 | } | 
|  | 286 |  | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 287 | void TypeLocWriter::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 288 | Record.AddSourceLocation(TL.getNameLoc()); | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 289 | } | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 290 |  | 
| Florian Hahn | 1065869 | 2020-05-11 17:45:51 +0100 | [diff] [blame] | 291 | void TypeLocWriter::VisitConstantMatrixTypeLoc(ConstantMatrixTypeLoc TL) { | 
|  | 292 | Record.AddSourceLocation(TL.getAttrNameLoc()); | 
|  | 293 | SourceRange range = TL.getAttrOperandParensRange(); | 
|  | 294 | Record.AddSourceLocation(range.getBegin()); | 
|  | 295 | Record.AddSourceLocation(range.getEnd()); | 
|  | 296 | Record.AddStmt(TL.getAttrRowOperand()); | 
|  | 297 | Record.AddStmt(TL.getAttrColumnOperand()); | 
|  | 298 | } | 
|  | 299 |  | 
|  | 300 | void TypeLocWriter::VisitDependentSizedMatrixTypeLoc( | 
|  | 301 | DependentSizedMatrixTypeLoc TL) { | 
|  | 302 | Record.AddSourceLocation(TL.getAttrNameLoc()); | 
|  | 303 | SourceRange range = TL.getAttrOperandParensRange(); | 
|  | 304 | Record.AddSourceLocation(range.getBegin()); | 
|  | 305 | Record.AddSourceLocation(range.getEnd()); | 
|  | 306 | Record.AddStmt(TL.getAttrRowOperand()); | 
|  | 307 | Record.AddStmt(TL.getAttrColumnOperand()); | 
|  | 308 | } | 
|  | 309 |  | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 310 | void TypeLocWriter::VisitFunctionTypeLoc(FunctionTypeLoc TL) { | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 311 | Record.AddSourceLocation(TL.getLocalRangeBegin()); | 
|  | 312 | Record.AddSourceLocation(TL.getLParenLoc()); | 
|  | 313 | Record.AddSourceLocation(TL.getRParenLoc()); | 
| Malcolm Parsons | a3220ce | 2017-01-12 16:11:28 +0000 | [diff] [blame] | 314 | Record.AddSourceRange(TL.getExceptionSpecRange()); | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 315 | Record.AddSourceLocation(TL.getLocalRangeEnd()); | 
| Alp Toker | b3fd5cf | 2014-01-21 00:32:38 +0000 | [diff] [blame] | 316 | for (unsigned i = 0, e = TL.getNumParams(); i != e; ++i) | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 317 | Record.AddDeclRef(TL.getParam(i)); | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 318 | } | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 319 |  | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 320 | void TypeLocWriter::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { | 
|  | 321 | VisitFunctionTypeLoc(TL); | 
|  | 322 | } | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 323 |  | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 324 | void TypeLocWriter::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { | 
|  | 325 | VisitFunctionTypeLoc(TL); | 
|  | 326 | } | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 327 |  | 
| John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 328 | void TypeLocWriter::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 329 | Record.AddSourceLocation(TL.getNameLoc()); | 
| John McCall | b96ec56 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 330 | } | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 331 |  | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 332 | void TypeLocWriter::VisitTypedefTypeLoc(TypedefTypeLoc TL) { | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 333 | Record.AddSourceLocation(TL.getNameLoc()); | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 334 | } | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 335 |  | 
| Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 336 | void TypeLocWriter::VisitObjCTypeParamTypeLoc(ObjCTypeParamTypeLoc TL) { | 
|  | 337 | if (TL.getNumProtocols()) { | 
|  | 338 | Record.AddSourceLocation(TL.getProtocolLAngleLoc()); | 
|  | 339 | Record.AddSourceLocation(TL.getProtocolRAngleLoc()); | 
|  | 340 | } | 
|  | 341 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) | 
|  | 342 | Record.AddSourceLocation(TL.getProtocolLoc(i)); | 
|  | 343 | } | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 344 |  | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 345 | void TypeLocWriter::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 346 | Record.AddSourceLocation(TL.getTypeofLoc()); | 
|  | 347 | Record.AddSourceLocation(TL.getLParenLoc()); | 
|  | 348 | Record.AddSourceLocation(TL.getRParenLoc()); | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 349 | } | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 350 |  | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 351 | void TypeLocWriter::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 352 | Record.AddSourceLocation(TL.getTypeofLoc()); | 
|  | 353 | Record.AddSourceLocation(TL.getLParenLoc()); | 
|  | 354 | Record.AddSourceLocation(TL.getRParenLoc()); | 
|  | 355 | Record.AddTypeSourceInfo(TL.getUnderlyingTInfo()); | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 356 | } | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 357 |  | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 358 | void TypeLocWriter::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 359 | Record.AddSourceLocation(TL.getNameLoc()); | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 360 | } | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 361 |  | 
| Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 362 | void TypeLocWriter::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 363 | Record.AddSourceLocation(TL.getKWLoc()); | 
|  | 364 | Record.AddSourceLocation(TL.getLParenLoc()); | 
|  | 365 | Record.AddSourceLocation(TL.getRParenLoc()); | 
|  | 366 | Record.AddTypeSourceInfo(TL.getUnderlyingTInfo()); | 
| Alexis Hunt | e852b10 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 367 | } | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 368 |  | 
| Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 369 | void TypeLocWriter::VisitAutoTypeLoc(AutoTypeLoc TL) { | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 370 | Record.AddSourceLocation(TL.getNameLoc()); | 
| Saar Raz | b481f02 | 2020-01-22 02:03:05 +0200 | [diff] [blame] | 371 | Record.push_back(TL.isConstrained()); | 
|  | 372 | if (TL.isConstrained()) { | 
|  | 373 | Record.AddNestedNameSpecifierLoc(TL.getNestedNameSpecifierLoc()); | 
|  | 374 | Record.AddSourceLocation(TL.getTemplateKWLoc()); | 
|  | 375 | Record.AddSourceLocation(TL.getConceptNameLoc()); | 
|  | 376 | Record.AddDeclRef(TL.getFoundDecl()); | 
|  | 377 | Record.AddSourceLocation(TL.getLAngleLoc()); | 
|  | 378 | Record.AddSourceLocation(TL.getRAngleLoc()); | 
|  | 379 | for (unsigned I = 0; I < TL.getNumArgs(); ++I) | 
|  | 380 | Record.AddTemplateArgumentLocInfo(TL.getTypePtr()->getArg(I).getKind(), | 
|  | 381 | TL.getArgLocInfo(I)); | 
|  | 382 | } | 
| Richard Smith | 30482bc | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 383 | } | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 384 |  | 
| Richard Smith | 600b526 | 2017-01-26 20:40:47 +0000 | [diff] [blame] | 385 | void TypeLocWriter::VisitDeducedTemplateSpecializationTypeLoc( | 
|  | 386 | DeducedTemplateSpecializationTypeLoc TL) { | 
|  | 387 | Record.AddSourceLocation(TL.getTemplateNameLoc()); | 
|  | 388 | } | 
|  | 389 |  | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 390 | void TypeLocWriter::VisitRecordTypeLoc(RecordTypeLoc TL) { | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 391 | Record.AddSourceLocation(TL.getNameLoc()); | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 392 | } | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 393 |  | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 394 | void TypeLocWriter::VisitEnumTypeLoc(EnumTypeLoc TL) { | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 395 | Record.AddSourceLocation(TL.getNameLoc()); | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 396 | } | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 397 |  | 
| John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 398 | void TypeLocWriter::VisitAttributedTypeLoc(AttributedTypeLoc TL) { | 
| Richard Smith | e43e2b3 | 2018-08-20 21:47:29 +0000 | [diff] [blame] | 399 | Record.AddAttr(TL.getAttr()); | 
| John McCall | 8190451 | 2011-01-06 01:58:22 +0000 | [diff] [blame] | 400 | } | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 401 |  | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 402 | void TypeLocWriter::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 403 | Record.AddSourceLocation(TL.getNameLoc()); | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 404 | } | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 405 |  | 
| John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 406 | void TypeLocWriter::VisitSubstTemplateTypeParmTypeLoc( | 
|  | 407 | SubstTemplateTypeParmTypeLoc TL) { | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 408 | Record.AddSourceLocation(TL.getNameLoc()); | 
| John McCall | cebee16 | 2009-10-18 09:09:24 +0000 | [diff] [blame] | 409 | } | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 410 |  | 
| Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 411 | void TypeLocWriter::VisitSubstTemplateTypeParmPackTypeLoc( | 
|  | 412 | SubstTemplateTypeParmPackTypeLoc TL) { | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 413 | Record.AddSourceLocation(TL.getNameLoc()); | 
| Douglas Gregor | ada4b79 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 414 | } | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 415 |  | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 416 | void TypeLocWriter::VisitTemplateSpecializationTypeLoc( | 
|  | 417 | TemplateSpecializationTypeLoc TL) { | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 418 | Record.AddSourceLocation(TL.getTemplateKeywordLoc()); | 
|  | 419 | Record.AddSourceLocation(TL.getTemplateNameLoc()); | 
|  | 420 | Record.AddSourceLocation(TL.getLAngleLoc()); | 
|  | 421 | Record.AddSourceLocation(TL.getRAngleLoc()); | 
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 422 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 423 | Record.AddTemplateArgumentLocInfo(TL.getArgLoc(i).getArgument().getKind(), | 
|  | 424 | TL.getArgLoc(i).getLocInfo()); | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 425 | } | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 426 |  | 
| Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 427 | void TypeLocWriter::VisitParenTypeLoc(ParenTypeLoc TL) { | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 428 | Record.AddSourceLocation(TL.getLParenLoc()); | 
|  | 429 | Record.AddSourceLocation(TL.getRParenLoc()); | 
| Abramo Bagnara | 924a8f3 | 2010-12-10 16:29:40 +0000 | [diff] [blame] | 430 | } | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 431 |  | 
| Leonard Chan | c72aaf6 | 2019-05-07 03:20:17 +0000 | [diff] [blame] | 432 | void TypeLocWriter::VisitMacroQualifiedTypeLoc(MacroQualifiedTypeLoc TL) { | 
|  | 433 | Record.AddSourceLocation(TL.getExpansionLoc()); | 
|  | 434 | } | 
|  | 435 |  | 
| Abramo Bagnara | 6150c88 | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 436 | void TypeLocWriter::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 437 | Record.AddSourceLocation(TL.getElaboratedKeywordLoc()); | 
|  | 438 | Record.AddNestedNameSpecifierLoc(TL.getQualifierLoc()); | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 439 | } | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 440 |  | 
| John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 441 | void TypeLocWriter::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 442 | Record.AddSourceLocation(TL.getNameLoc()); | 
| John McCall | e78aac4 | 2010-03-10 03:28:59 +0000 | [diff] [blame] | 443 | } | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 444 |  | 
| Douglas Gregor | c1d2d8a | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 445 | void TypeLocWriter::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 446 | Record.AddSourceLocation(TL.getElaboratedKeywordLoc()); | 
|  | 447 | Record.AddNestedNameSpecifierLoc(TL.getQualifierLoc()); | 
|  | 448 | Record.AddSourceLocation(TL.getNameLoc()); | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 449 | } | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 450 |  | 
| John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 451 | void TypeLocWriter::VisitDependentTemplateSpecializationTypeLoc( | 
|  | 452 | DependentTemplateSpecializationTypeLoc TL) { | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 453 | Record.AddSourceLocation(TL.getElaboratedKeywordLoc()); | 
|  | 454 | Record.AddNestedNameSpecifierLoc(TL.getQualifierLoc()); | 
|  | 455 | Record.AddSourceLocation(TL.getTemplateKeywordLoc()); | 
|  | 456 | Record.AddSourceLocation(TL.getTemplateNameLoc()); | 
|  | 457 | Record.AddSourceLocation(TL.getLAngleLoc()); | 
|  | 458 | Record.AddSourceLocation(TL.getRAngleLoc()); | 
| John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 459 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 460 | Record.AddTemplateArgumentLocInfo(TL.getArgLoc(I).getArgument().getKind(), | 
|  | 461 | TL.getArgLoc(I).getLocInfo()); | 
| John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 462 | } | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 463 |  | 
| Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 464 | void TypeLocWriter::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 465 | Record.AddSourceLocation(TL.getEllipsisLoc()); | 
| Douglas Gregor | d2fa766 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 466 | } | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 467 |  | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 468 | void TypeLocWriter::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 469 | Record.AddSourceLocation(TL.getNameLoc()); | 
| John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 470 | } | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 471 |  | 
| John McCall | 8b07ec2 | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 472 | void TypeLocWriter::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { | 
|  | 473 | Record.push_back(TL.hasBaseTypeAsWritten()); | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 474 | Record.AddSourceLocation(TL.getTypeArgsLAngleLoc()); | 
|  | 475 | Record.AddSourceLocation(TL.getTypeArgsRAngleLoc()); | 
| Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 476 | for (unsigned i = 0, e = TL.getNumTypeArgs(); i != e; ++i) | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 477 | Record.AddTypeSourceInfo(TL.getTypeArgTInfo(i)); | 
|  | 478 | Record.AddSourceLocation(TL.getProtocolLAngleLoc()); | 
|  | 479 | Record.AddSourceLocation(TL.getProtocolRAngleLoc()); | 
| John McCall | 1700197 | 2009-10-18 01:05:36 +0000 | [diff] [blame] | 480 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 481 | Record.AddSourceLocation(TL.getProtocolLoc(i)); | 
| John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 482 | } | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 483 |  | 
| John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 484 | void TypeLocWriter::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 485 | Record.AddSourceLocation(TL.getStarLoc()); | 
| John McCall | fc93cf9 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 486 | } | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 487 |  | 
| Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 488 | void TypeLocWriter::VisitAtomicTypeLoc(AtomicTypeLoc TL) { | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 489 | Record.AddSourceLocation(TL.getKWLoc()); | 
|  | 490 | Record.AddSourceLocation(TL.getLParenLoc()); | 
|  | 491 | Record.AddSourceLocation(TL.getRParenLoc()); | 
| Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 492 | } | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 493 |  | 
| Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 494 | void TypeLocWriter::VisitPipeTypeLoc(PipeTypeLoc TL) { | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 495 | Record.AddSourceLocation(TL.getKWLoc()); | 
| Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 496 | } | 
| John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 497 |  | 
| Erich Keane | 5f0903e | 2020-04-17 10:44:19 -0700 | [diff] [blame] | 498 | void TypeLocWriter::VisitExtIntTypeLoc(clang::ExtIntTypeLoc TL) { | 
|  | 499 | Record.AddSourceLocation(TL.getNameLoc()); | 
|  | 500 | } | 
|  | 501 | void TypeLocWriter::VisitDependentExtIntTypeLoc( | 
|  | 502 | clang::DependentExtIntTypeLoc TL) { | 
|  | 503 | Record.AddSourceLocation(TL.getNameLoc()); | 
|  | 504 | } | 
|  | 505 |  | 
| Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 506 | void ASTWriter::WriteTypeAbbrevs() { | 
|  | 507 | using namespace llvm; | 
|  | 508 |  | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 509 | std::shared_ptr<BitCodeAbbrev> Abv; | 
| Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 510 |  | 
|  | 511 | // Abbreviation for TYPE_EXT_QUAL | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 512 | Abv = std::make_shared<BitCodeAbbrev>(); | 
| Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 513 | Abv->Add(BitCodeAbbrevOp(serialization::TYPE_EXT_QUAL)); | 
|  | 514 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));   // Type | 
|  | 515 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 3));   // Quals | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 516 | TypeExtQualAbbrev = Stream.EmitAbbrev(std::move(Abv)); | 
| Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 517 |  | 
|  | 518 | // Abbreviation for TYPE_FUNCTION_PROTO | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 519 | Abv = std::make_shared<BitCodeAbbrev>(); | 
| Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 520 | Abv->Add(BitCodeAbbrevOp(serialization::TYPE_FUNCTION_PROTO)); | 
|  | 521 | // FunctionType | 
|  | 522 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));   // ReturnType | 
|  | 523 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // NoReturn | 
|  | 524 | Abv->Add(BitCodeAbbrevOp(0));                         // HasRegParm | 
|  | 525 | Abv->Add(BitCodeAbbrevOp(0));                         // RegParm | 
|  | 526 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4)); // CC | 
|  | 527 | Abv->Add(BitCodeAbbrevOp(0));                         // ProducesResult | 
| Oren Ben Simhon | 318a6ea | 2017-04-27 12:01:00 +0000 | [diff] [blame] | 528 | Abv->Add(BitCodeAbbrevOp(0));                         // NoCallerSavedRegs | 
| Oren Ben Simhon | 220671a | 2018-03-17 13:31:35 +0000 | [diff] [blame] | 529 | Abv->Add(BitCodeAbbrevOp(0));                         // NoCfCheck | 
| Momchil Velikov | 080d046 | 2020-03-24 09:32:51 +0000 | [diff] [blame] | 530 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // CmseNSCall | 
| Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 531 | // FunctionProtoType | 
|  | 532 | Abv->Add(BitCodeAbbrevOp(0));                         // IsVariadic | 
|  | 533 | Abv->Add(BitCodeAbbrevOp(0));                         // HasTrailingReturn | 
|  | 534 | Abv->Add(BitCodeAbbrevOp(0));                         // TypeQuals | 
|  | 535 | Abv->Add(BitCodeAbbrevOp(0));                         // RefQualifier | 
|  | 536 | Abv->Add(BitCodeAbbrevOp(EST_None));                  // ExceptionSpec | 
|  | 537 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));   // NumParams | 
|  | 538 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); | 
|  | 539 | Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));   // Params | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 540 | TypeFunctionProtoAbbrev = Stream.EmitAbbrev(std::move(Abv)); | 
| Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 541 | } | 
|  | 542 |  | 
| Chris Lattner | 19cea4e | 2009-04-22 05:57:30 +0000 | [diff] [blame] | 543 | //===----------------------------------------------------------------------===// | 
| Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 544 | // ASTWriter Implementation | 
| Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 545 | //===----------------------------------------------------------------------===// | 
|  | 546 |  | 
| Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 547 | static void EmitBlockID(unsigned ID, const char *Name, | 
|  | 548 | llvm::BitstreamWriter &Stream, | 
| Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 549 | ASTWriter::RecordDataImpl &Record) { | 
| Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 550 | Record.clear(); | 
|  | 551 | Record.push_back(ID); | 
|  | 552 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETBID, Record); | 
|  | 553 |  | 
|  | 554 | // Emit the block name if present. | 
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 555 | if (!Name || Name[0] == 0) | 
|  | 556 | return; | 
| Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 557 | Record.clear(); | 
|  | 558 | while (*Name) | 
|  | 559 | Record.push_back(*Name++); | 
|  | 560 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_BLOCKNAME, Record); | 
|  | 561 | } | 
|  | 562 |  | 
|  | 563 | static void EmitRecordID(unsigned ID, const char *Name, | 
|  | 564 | llvm::BitstreamWriter &Stream, | 
| Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 565 | ASTWriter::RecordDataImpl &Record) { | 
| Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 566 | Record.clear(); | 
|  | 567 | Record.push_back(ID); | 
|  | 568 | while (*Name) | 
|  | 569 | Record.push_back(*Name++); | 
|  | 570 | Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETRECORDNAME, Record); | 
| Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 571 | } | 
|  | 572 |  | 
|  | 573 | static void AddStmtsExprs(llvm::BitstreamWriter &Stream, | 
| Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 574 | ASTWriter::RecordDataImpl &Record) { | 
| Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 575 | #define RECORD(X) EmitRecordID(X, #X, Stream, Record) | 
| Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 576 | RECORD(STMT_STOP); | 
|  | 577 | RECORD(STMT_NULL_PTR); | 
| Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 578 | RECORD(STMT_REF_PTR); | 
| Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 579 | RECORD(STMT_NULL); | 
|  | 580 | RECORD(STMT_COMPOUND); | 
|  | 581 | RECORD(STMT_CASE); | 
|  | 582 | RECORD(STMT_DEFAULT); | 
|  | 583 | RECORD(STMT_LABEL); | 
| Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 584 | RECORD(STMT_ATTRIBUTED); | 
| Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 585 | RECORD(STMT_IF); | 
|  | 586 | RECORD(STMT_SWITCH); | 
|  | 587 | RECORD(STMT_WHILE); | 
|  | 588 | RECORD(STMT_DO); | 
|  | 589 | RECORD(STMT_FOR); | 
|  | 590 | RECORD(STMT_GOTO); | 
|  | 591 | RECORD(STMT_INDIRECT_GOTO); | 
|  | 592 | RECORD(STMT_CONTINUE); | 
|  | 593 | RECORD(STMT_BREAK); | 
|  | 594 | RECORD(STMT_RETURN); | 
|  | 595 | RECORD(STMT_DECL); | 
| Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 596 | RECORD(STMT_GCCASM); | 
| Chad Rosier | e30d499 | 2012-08-24 23:51:02 +0000 | [diff] [blame] | 597 | RECORD(STMT_MSASM); | 
| Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 598 | RECORD(EXPR_PREDEFINED); | 
|  | 599 | RECORD(EXPR_DECL_REF); | 
|  | 600 | RECORD(EXPR_INTEGER_LITERAL); | 
| Vince Bridgers | 161fc1d | 2020-04-07 14:46:08 -0500 | [diff] [blame] | 601 | RECORD(EXPR_FIXEDPOINT_LITERAL); | 
| Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 602 | RECORD(EXPR_FLOATING_LITERAL); | 
|  | 603 | RECORD(EXPR_IMAGINARY_LITERAL); | 
|  | 604 | RECORD(EXPR_STRING_LITERAL); | 
|  | 605 | RECORD(EXPR_CHARACTER_LITERAL); | 
|  | 606 | RECORD(EXPR_PAREN); | 
| Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 607 | RECORD(EXPR_PAREN_LIST); | 
| Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 608 | RECORD(EXPR_UNARY_OPERATOR); | 
|  | 609 | RECORD(EXPR_SIZEOF_ALIGN_OF); | 
|  | 610 | RECORD(EXPR_ARRAY_SUBSCRIPT); | 
|  | 611 | RECORD(EXPR_CALL); | 
|  | 612 | RECORD(EXPR_MEMBER); | 
|  | 613 | RECORD(EXPR_BINARY_OPERATOR); | 
|  | 614 | RECORD(EXPR_COMPOUND_ASSIGN_OPERATOR); | 
|  | 615 | RECORD(EXPR_CONDITIONAL_OPERATOR); | 
|  | 616 | RECORD(EXPR_IMPLICIT_CAST); | 
|  | 617 | RECORD(EXPR_CSTYLE_CAST); | 
|  | 618 | RECORD(EXPR_COMPOUND_LITERAL); | 
|  | 619 | RECORD(EXPR_EXT_VECTOR_ELEMENT); | 
|  | 620 | RECORD(EXPR_INIT_LIST); | 
|  | 621 | RECORD(EXPR_DESIGNATED_INIT); | 
| Yunzhong Gao | cb77930 | 2015-06-10 00:27:52 +0000 | [diff] [blame] | 622 | RECORD(EXPR_DESIGNATED_INIT_UPDATE); | 
| Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 623 | RECORD(EXPR_IMPLICIT_VALUE_INIT); | 
| Yunzhong Gao | cb77930 | 2015-06-10 00:27:52 +0000 | [diff] [blame] | 624 | RECORD(EXPR_NO_INIT); | 
| Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 625 | RECORD(EXPR_VA_ARG); | 
|  | 626 | RECORD(EXPR_ADDR_LABEL); | 
|  | 627 | RECORD(EXPR_STMT); | 
| Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 628 | RECORD(EXPR_CHOOSE); | 
|  | 629 | RECORD(EXPR_GNU_NULL); | 
|  | 630 | RECORD(EXPR_SHUFFLE_VECTOR); | 
|  | 631 | RECORD(EXPR_BLOCK); | 
| Peter Collingbourne | 9114759 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 632 | RECORD(EXPR_GENERIC_SELECTION); | 
| Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 633 | RECORD(EXPR_OBJC_STRING_LITERAL); | 
| Patrick Beard | 0caa394 | 2012-04-19 00:25:12 +0000 | [diff] [blame] | 634 | RECORD(EXPR_OBJC_BOXED_EXPRESSION); | 
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 635 | RECORD(EXPR_OBJC_ARRAY_LITERAL); | 
|  | 636 | RECORD(EXPR_OBJC_DICTIONARY_LITERAL); | 
| Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 637 | RECORD(EXPR_OBJC_ENCODE); | 
|  | 638 | RECORD(EXPR_OBJC_SELECTOR_EXPR); | 
|  | 639 | RECORD(EXPR_OBJC_PROTOCOL_EXPR); | 
|  | 640 | RECORD(EXPR_OBJC_IVAR_REF_EXPR); | 
|  | 641 | RECORD(EXPR_OBJC_PROPERTY_REF_EXPR); | 
|  | 642 | RECORD(EXPR_OBJC_KVC_REF_EXPR); | 
|  | 643 | RECORD(EXPR_OBJC_MESSAGE_EXPR); | 
| Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 644 | RECORD(STMT_OBJC_FOR_COLLECTION); | 
|  | 645 | RECORD(STMT_OBJC_CATCH); | 
|  | 646 | RECORD(STMT_OBJC_FINALLY); | 
|  | 647 | RECORD(STMT_OBJC_AT_TRY); | 
|  | 648 | RECORD(STMT_OBJC_AT_SYNCHRONIZED); | 
|  | 649 | RECORD(STMT_OBJC_AT_THROW); | 
| Ted Kremenek | e65b086 | 2012-03-06 20:05:56 +0000 | [diff] [blame] | 650 | RECORD(EXPR_OBJC_BOOL_LITERAL); | 
| Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 651 | RECORD(STMT_CXX_CATCH); | 
|  | 652 | RECORD(STMT_CXX_TRY); | 
|  | 653 | RECORD(STMT_CXX_FOR_RANGE); | 
| Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 654 | RECORD(EXPR_CXX_OPERATOR_CALL); | 
| Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 655 | RECORD(EXPR_CXX_MEMBER_CALL); | 
| Richard Smith | 778dc0f | 2019-10-19 00:04:38 +0000 | [diff] [blame] | 656 | RECORD(EXPR_CXX_REWRITTEN_BINARY_OPERATOR); | 
| Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 657 | RECORD(EXPR_CXX_CONSTRUCT); | 
| Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 658 | RECORD(EXPR_CXX_TEMPORARY_OBJECT); | 
| Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 659 | RECORD(EXPR_CXX_STATIC_CAST); | 
|  | 660 | RECORD(EXPR_CXX_DYNAMIC_CAST); | 
|  | 661 | RECORD(EXPR_CXX_REINTERPRET_CAST); | 
|  | 662 | RECORD(EXPR_CXX_CONST_CAST); | 
|  | 663 | RECORD(EXPR_CXX_FUNCTIONAL_CAST); | 
| Richard Smith | c67fdd4 | 2012-03-07 08:35:16 +0000 | [diff] [blame] | 664 | RECORD(EXPR_USER_DEFINED_LITERAL); | 
| Richard Smith | cc1b96d | 2013-06-12 22:31:48 +0000 | [diff] [blame] | 665 | RECORD(EXPR_CXX_STD_INITIALIZER_LIST); | 
| Sam Weinig | e83b3ac | 2010-02-07 06:32:43 +0000 | [diff] [blame] | 666 | RECORD(EXPR_CXX_BOOL_LITERAL); | 
|  | 667 | RECORD(EXPR_CXX_NULL_PTR_LITERAL); | 
| Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 668 | RECORD(EXPR_CXX_TYPEID_EXPR); | 
|  | 669 | RECORD(EXPR_CXX_TYPEID_TYPE); | 
| Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 670 | RECORD(EXPR_CXX_THIS); | 
|  | 671 | RECORD(EXPR_CXX_THROW); | 
|  | 672 | RECORD(EXPR_CXX_DEFAULT_ARG); | 
| Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 673 | RECORD(EXPR_CXX_DEFAULT_INIT); | 
| Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 674 | RECORD(EXPR_CXX_BIND_TEMPORARY); | 
|  | 675 | RECORD(EXPR_CXX_SCALAR_VALUE_INIT); | 
|  | 676 | RECORD(EXPR_CXX_NEW); | 
|  | 677 | RECORD(EXPR_CXX_DELETE); | 
|  | 678 | RECORD(EXPR_CXX_PSEUDO_DESTRUCTOR); | 
|  | 679 | RECORD(EXPR_EXPR_WITH_CLEANUPS); | 
|  | 680 | RECORD(EXPR_CXX_DEPENDENT_SCOPE_MEMBER); | 
|  | 681 | RECORD(EXPR_CXX_DEPENDENT_SCOPE_DECL_REF); | 
|  | 682 | RECORD(EXPR_CXX_UNRESOLVED_CONSTRUCT); | 
|  | 683 | RECORD(EXPR_CXX_UNRESOLVED_MEMBER); | 
|  | 684 | RECORD(EXPR_CXX_UNRESOLVED_LOOKUP); | 
| Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 685 | RECORD(EXPR_CXX_EXPRESSION_TRAIT); | 
| Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 686 | RECORD(EXPR_CXX_NOEXCEPT); | 
|  | 687 | RECORD(EXPR_OPAQUE_VALUE); | 
| Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 688 | RECORD(EXPR_BINARY_CONDITIONAL_OPERATOR); | 
|  | 689 | RECORD(EXPR_TYPE_TRAIT); | 
|  | 690 | RECORD(EXPR_ARRAY_TYPE_TRAIT); | 
| Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 691 | RECORD(EXPR_PACK_EXPANSION); | 
|  | 692 | RECORD(EXPR_SIZEOF_PACK); | 
| Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 693 | RECORD(EXPR_SUBST_NON_TYPE_TEMPLATE_PARM); | 
| Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 694 | RECORD(EXPR_SUBST_NON_TYPE_TEMPLATE_PARM_PACK); | 
| Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 695 | RECORD(EXPR_FUNCTION_PARM_PACK); | 
|  | 696 | RECORD(EXPR_MATERIALIZE_TEMPORARY); | 
| Peter Collingbourne | 41f8546 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 697 | RECORD(EXPR_CUDA_KERNEL_CALL); | 
| Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 698 | RECORD(EXPR_CXX_UUIDOF_EXPR); | 
|  | 699 | RECORD(EXPR_CXX_UUIDOF_TYPE); | 
|  | 700 | RECORD(EXPR_LAMBDA); | 
| Chris Lattner | ccac3a6 | 2009-04-27 00:49:53 +0000 | [diff] [blame] | 701 | #undef RECORD | 
| Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 702 | } | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 703 |  | 
| Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 704 | void ASTWriter::WriteBlockInfoBlock() { | 
| Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 705 | RecordData Record; | 
| Peter Collingbourne | d3a6c70 | 2016-11-01 01:18:57 +0000 | [diff] [blame] | 706 | Stream.EnterBlockInfoBlock(); | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 707 |  | 
| Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 708 | #define BLOCK(X) EmitBlockID(X ## _ID, #X, Stream, Record) | 
|  | 709 | #define RECORD(X) EmitRecordID(X, #X, Stream, Record) | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 710 |  | 
| Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 711 | // Control Block. | 
|  | 712 | BLOCK(CONTROL_BLOCK); | 
|  | 713 | RECORD(METADATA); | 
| Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 714 | RECORD(MODULE_NAME); | 
| Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 715 | RECORD(MODULE_DIRECTORY); | 
| Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 716 | RECORD(MODULE_MAP_FILE); | 
| Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 717 | RECORD(IMPORTS); | 
| Douglas Gregor | fad10d8 | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 718 | RECORD(ORIGINAL_FILE); | 
| Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 719 | RECORD(ORIGINAL_PCH_DIR); | 
| Argyrios Kyrtzidis | 5259524 | 2012-11-15 18:57:27 +0000 | [diff] [blame] | 720 | RECORD(ORIGINAL_FILE_ID); | 
| Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 721 | RECORD(INPUT_FILE_OFFSETS); | 
| Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 722 |  | 
|  | 723 | BLOCK(OPTIONS_BLOCK); | 
|  | 724 | RECORD(LANGUAGE_OPTIONS); | 
|  | 725 | RECORD(TARGET_OPTIONS); | 
| Douglas Gregor | c6317db | 2012-10-24 15:49:58 +0000 | [diff] [blame] | 726 | RECORD(FILE_SYSTEM_OPTIONS); | 
| Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 727 | RECORD(HEADER_SEARCH_OPTIONS); | 
| Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 728 | RECORD(PREPROCESSOR_OPTIONS); | 
|  | 729 |  | 
| Douglas Gregor | 108cb22 | 2012-10-19 00:45:00 +0000 | [diff] [blame] | 730 | BLOCK(INPUT_FILES_BLOCK); | 
|  | 731 | RECORD(INPUT_FILE); | 
| Bruno Cardoso Lopes | 1731fc8 | 2019-10-15 14:23:55 +0000 | [diff] [blame] | 732 | RECORD(INPUT_FILE_HASH); | 
| Douglas Gregor | 108cb22 | 2012-10-19 00:45:00 +0000 | [diff] [blame] | 733 |  | 
| Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 734 | // AST Top-Level Block. | 
|  | 735 | BLOCK(AST_BLOCK); | 
| Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 736 | RECORD(TYPE_OFFSET); | 
|  | 737 | RECORD(DECL_OFFSET); | 
| Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 738 | RECORD(IDENTIFIER_OFFSET); | 
|  | 739 | RECORD(IDENTIFIER_TABLE); | 
| Ben Langmuir | 332aafe | 2014-01-31 01:06:56 +0000 | [diff] [blame] | 740 | RECORD(EAGERLY_DESERIALIZED_DECLS); | 
| David Blaikie | 9ffe5a3 | 2017-01-30 05:00:26 +0000 | [diff] [blame] | 741 | RECORD(MODULAR_CODEGEN_DECLS); | 
| Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 742 | RECORD(SPECIAL_TYPES); | 
|  | 743 | RECORD(STATISTICS); | 
|  | 744 | RECORD(TENTATIVE_DEFINITIONS); | 
| Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 745 | RECORD(SELECTOR_OFFSETS); | 
|  | 746 | RECORD(METHOD_POOL); | 
|  | 747 | RECORD(PP_COUNTER_VALUE); | 
| Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 748 | RECORD(SOURCE_LOCATION_OFFSETS); | 
|  | 749 | RECORD(SOURCE_LOCATION_PRELOADS); | 
| Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 750 | RECORD(EXT_VECTOR_DECLS); | 
| Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 751 | RECORD(UNUSED_FILESCOPED_DECLS); | 
| Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 752 | RECORD(PPD_ENTITIES_OFFSETS); | 
| Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 753 | RECORD(VTABLE_USES); | 
| Cameron Desrochers | b60f1b6 | 2018-01-15 19:14:16 +0000 | [diff] [blame] | 754 | RECORD(PPD_SKIPPED_RANGES); | 
| Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 755 | RECORD(REFERENCED_SELECTOR_POOL); | 
| Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 756 | RECORD(TU_UPDATE_LEXICAL); | 
| Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 757 | RECORD(SEMA_DECL_REFS); | 
|  | 758 | RECORD(WEAK_UNDECLARED_IDENTIFIERS); | 
|  | 759 | RECORD(PENDING_IMPLICIT_INSTANTIATIONS); | 
| Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 760 | RECORD(UPDATE_VISIBLE); | 
|  | 761 | RECORD(DECL_UPDATE_OFFSETS); | 
|  | 762 | RECORD(DECL_UPDATES); | 
| Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 763 | RECORD(CUDA_SPECIAL_DECL_REFS); | 
| Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 764 | RECORD(HEADER_SEARCH_TABLE); | 
| Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 765 | RECORD(FP_PRAGMA_OPTIONS); | 
|  | 766 | RECORD(OPENCL_EXTENSIONS); | 
| Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 767 | RECORD(OPENCL_EXTENSION_TYPES); | 
|  | 768 | RECORD(OPENCL_EXTENSION_DECLS); | 
| Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 769 | RECORD(DELEGATING_CTORS); | 
| Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 770 | RECORD(KNOWN_NAMESPACES); | 
| Douglas Gregor | 78d0b57 | 2011-08-04 16:39:39 +0000 | [diff] [blame] | 771 | RECORD(MODULE_OFFSET_MAP); | 
|  | 772 | RECORD(SOURCE_MANAGER_LINE_TABLE); | 
| Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 773 | RECORD(OBJC_CATEGORIES_MAP); | 
| Douglas Gregor | 66e4add | 2011-12-19 21:09:25 +0000 | [diff] [blame] | 774 | RECORD(FILE_SORTED_DECLS); | 
|  | 775 | RECORD(IMPORTED_MODULES); | 
| Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 776 | RECORD(OBJC_CATEGORIES); | 
| Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 777 | RECORD(MACRO_OFFSET); | 
| Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 778 | RECORD(INTERESTING_IDENTIFIERS); | 
|  | 779 | RECORD(UNDEFINED_BUT_USED); | 
| Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 780 | RECORD(LATE_PARSED_TEMPLATE); | 
| Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 781 | RECORD(OPTIMIZE_PRAGMA_OPTIONS); | 
| Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 782 | RECORD(MSSTRUCT_PRAGMA_OPTIONS); | 
| Nico Weber | 4293231 | 2016-03-03 00:17:35 +0000 | [diff] [blame] | 783 | RECORD(POINTERS_TO_MEMBERS_PRAGMA_OPTIONS); | 
| Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 784 | RECORD(UNUSED_LOCAL_TYPEDEF_NAME_CANDIDATES); | 
| Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 785 | RECORD(DELETE_EXPRS_TO_ANALYZE); | 
| Justin Lebar | 67a78a6 | 2016-10-08 22:15:58 +0000 | [diff] [blame] | 786 | RECORD(CUDA_PRAGMA_FORCE_HOST_DEVICE_DEPTH); | 
| Erik Verbruggen | b34c79f | 2017-05-30 11:54:55 +0000 | [diff] [blame] | 787 | RECORD(PP_CONDITIONAL_STACK); | 
| Yaxun (Sam) Liu | b670ab7 | 2020-02-26 10:57:39 -0500 | [diff] [blame] | 788 | RECORD(DECLS_TO_CHECK_FOR_DEFERRED_DIAGS); | 
| Douglas Gregor | 358cd44 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 789 |  | 
| Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 790 | // SourceManager Block. | 
| Chris Lattner | 6403198 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 791 | BLOCK(SOURCE_MANAGER_BLOCK); | 
| Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 792 | RECORD(SM_SLOC_FILE_ENTRY); | 
|  | 793 | RECORD(SM_SLOC_BUFFER_ENTRY); | 
|  | 794 | RECORD(SM_SLOC_BUFFER_BLOB); | 
| Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 795 | RECORD(SM_SLOC_BUFFER_BLOB_COMPRESSED); | 
| Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 796 | RECORD(SM_SLOC_EXPANSION_ENTRY); | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 797 |  | 
| Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 798 | // Preprocessor Block. | 
| Chris Lattner | 6403198 | 2009-04-27 00:40:25 +0000 | [diff] [blame] | 799 | BLOCK(PREPROCESSOR_BLOCK); | 
| Richard Smith | ec21650 | 2015-02-13 19:48:37 +0000 | [diff] [blame] | 800 | RECORD(PP_MACRO_DIRECTIVE_HISTORY); | 
| Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 801 | RECORD(PP_MACRO_FUNCTION_LIKE); | 
| Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 802 | RECORD(PP_MACRO_OBJECT_LIKE); | 
|  | 803 | RECORD(PP_MODULE_MACRO); | 
| Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 804 | RECORD(PP_TOKEN); | 
| Richard Smith | ec21650 | 2015-02-13 19:48:37 +0000 | [diff] [blame] | 805 |  | 
| Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 806 | // Submodule Block. | 
|  | 807 | BLOCK(SUBMODULE_BLOCK); | 
|  | 808 | RECORD(SUBMODULE_METADATA); | 
|  | 809 | RECORD(SUBMODULE_DEFINITION); | 
|  | 810 | RECORD(SUBMODULE_UMBRELLA_HEADER); | 
|  | 811 | RECORD(SUBMODULE_HEADER); | 
|  | 812 | RECORD(SUBMODULE_TOPHEADER); | 
|  | 813 | RECORD(SUBMODULE_UMBRELLA_DIR); | 
|  | 814 | RECORD(SUBMODULE_IMPORTS); | 
|  | 815 | RECORD(SUBMODULE_EXPORTS); | 
|  | 816 | RECORD(SUBMODULE_REQUIRES); | 
|  | 817 | RECORD(SUBMODULE_EXCLUDED_HEADER); | 
|  | 818 | RECORD(SUBMODULE_LINK_LIBRARY); | 
|  | 819 | RECORD(SUBMODULE_CONFIG_MACRO); | 
|  | 820 | RECORD(SUBMODULE_CONFLICT); | 
|  | 821 | RECORD(SUBMODULE_PRIVATE_HEADER); | 
|  | 822 | RECORD(SUBMODULE_TEXTUAL_HEADER); | 
|  | 823 | RECORD(SUBMODULE_PRIVATE_TEXTUAL_HEADER); | 
| Richard Smith | dc1f042 | 2016-07-20 19:10:16 +0000 | [diff] [blame] | 824 | RECORD(SUBMODULE_INITIALIZERS); | 
| Douglas Gregor | f0b11de | 2017-09-14 23:38:44 +0000 | [diff] [blame] | 825 | RECORD(SUBMODULE_EXPORT_AS); | 
| Richard Smith | fa71565 | 2015-08-31 22:43:10 +0000 | [diff] [blame] | 826 |  | 
|  | 827 | // Comments Block. | 
|  | 828 | BLOCK(COMMENTS_BLOCK); | 
|  | 829 | RECORD(COMMENTS_RAW_COMMENT); | 
|  | 830 |  | 
| Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 831 | // Decls and Types block. | 
|  | 832 | BLOCK(DECLTYPES_BLOCK); | 
| Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 833 | RECORD(TYPE_EXT_QUAL); | 
| Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 834 | RECORD(TYPE_COMPLEX); | 
|  | 835 | RECORD(TYPE_POINTER); | 
|  | 836 | RECORD(TYPE_BLOCK_POINTER); | 
|  | 837 | RECORD(TYPE_LVALUE_REFERENCE); | 
|  | 838 | RECORD(TYPE_RVALUE_REFERENCE); | 
|  | 839 | RECORD(TYPE_MEMBER_POINTER); | 
|  | 840 | RECORD(TYPE_CONSTANT_ARRAY); | 
|  | 841 | RECORD(TYPE_INCOMPLETE_ARRAY); | 
|  | 842 | RECORD(TYPE_VARIABLE_ARRAY); | 
|  | 843 | RECORD(TYPE_VECTOR); | 
|  | 844 | RECORD(TYPE_EXT_VECTOR); | 
| Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 845 | RECORD(TYPE_FUNCTION_NO_PROTO); | 
| Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 846 | RECORD(TYPE_FUNCTION_PROTO); | 
| Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 847 | RECORD(TYPE_TYPEDEF); | 
|  | 848 | RECORD(TYPE_TYPEOF_EXPR); | 
|  | 849 | RECORD(TYPE_TYPEOF); | 
|  | 850 | RECORD(TYPE_RECORD); | 
|  | 851 | RECORD(TYPE_ENUM); | 
|  | 852 | RECORD(TYPE_OBJC_INTERFACE); | 
| Steve Naroff | fb4330f | 2009-06-17 22:40:22 +0000 | [diff] [blame] | 853 | RECORD(TYPE_OBJC_OBJECT_POINTER); | 
| Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 854 | RECORD(TYPE_DECLTYPE); | 
|  | 855 | RECORD(TYPE_ELABORATED); | 
|  | 856 | RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM); | 
|  | 857 | RECORD(TYPE_UNRESOLVED_USING); | 
|  | 858 | RECORD(TYPE_INJECTED_CLASS_NAME); | 
|  | 859 | RECORD(TYPE_OBJC_OBJECT); | 
|  | 860 | RECORD(TYPE_TEMPLATE_TYPE_PARM); | 
|  | 861 | RECORD(TYPE_TEMPLATE_SPECIALIZATION); | 
|  | 862 | RECORD(TYPE_DEPENDENT_NAME); | 
|  | 863 | RECORD(TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION); | 
|  | 864 | RECORD(TYPE_DEPENDENT_SIZED_ARRAY); | 
|  | 865 | RECORD(TYPE_PAREN); | 
| Leonard Chan | c72aaf6 | 2019-05-07 03:20:17 +0000 | [diff] [blame] | 866 | RECORD(TYPE_MACRO_QUALIFIED); | 
| Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 867 | RECORD(TYPE_PACK_EXPANSION); | 
|  | 868 | RECORD(TYPE_ATTRIBUTED); | 
|  | 869 | RECORD(TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK); | 
| Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 870 | RECORD(TYPE_AUTO); | 
|  | 871 | RECORD(TYPE_UNARY_TRANSFORM); | 
| Eli Friedman | 0dfb889 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 872 | RECORD(TYPE_ATOMIC); | 
| Richard Smith | f1b4b8b | 2014-07-27 04:29:04 +0000 | [diff] [blame] | 873 | RECORD(TYPE_DECAYED); | 
|  | 874 | RECORD(TYPE_ADJUSTED); | 
| Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 875 | RECORD(TYPE_OBJC_TYPE_PARAM); | 
| Richard Smith | d61d4ac | 2015-08-22 20:13:39 +0000 | [diff] [blame] | 876 | RECORD(LOCAL_REDECLARATIONS); | 
| Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 877 | RECORD(DECL_TYPEDEF); | 
| Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 878 | RECORD(DECL_TYPEALIAS); | 
| Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 879 | RECORD(DECL_ENUM); | 
|  | 880 | RECORD(DECL_RECORD); | 
|  | 881 | RECORD(DECL_ENUM_CONSTANT); | 
|  | 882 | RECORD(DECL_FUNCTION); | 
|  | 883 | RECORD(DECL_OBJC_METHOD); | 
|  | 884 | RECORD(DECL_OBJC_INTERFACE); | 
|  | 885 | RECORD(DECL_OBJC_PROTOCOL); | 
|  | 886 | RECORD(DECL_OBJC_IVAR); | 
|  | 887 | RECORD(DECL_OBJC_AT_DEFS_FIELD); | 
| Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 888 | RECORD(DECL_OBJC_CATEGORY); | 
|  | 889 | RECORD(DECL_OBJC_CATEGORY_IMPL); | 
|  | 890 | RECORD(DECL_OBJC_IMPLEMENTATION); | 
|  | 891 | RECORD(DECL_OBJC_COMPATIBLE_ALIAS); | 
|  | 892 | RECORD(DECL_OBJC_PROPERTY); | 
|  | 893 | RECORD(DECL_OBJC_PROPERTY_IMPL); | 
| Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 894 | RECORD(DECL_FIELD); | 
| John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 895 | RECORD(DECL_MS_PROPERTY); | 
| Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 896 | RECORD(DECL_VAR); | 
| Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 897 | RECORD(DECL_IMPLICIT_PARAM); | 
| Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 898 | RECORD(DECL_PARM_VAR); | 
| Chris Lattner | db397b6 | 2009-04-26 22:32:16 +0000 | [diff] [blame] | 899 | RECORD(DECL_FILE_SCOPE_ASM); | 
|  | 900 | RECORD(DECL_BLOCK); | 
|  | 901 | RECORD(DECL_CONTEXT_LEXICAL); | 
|  | 902 | RECORD(DECL_CONTEXT_VISIBLE); | 
| Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 903 | RECORD(DECL_NAMESPACE); | 
|  | 904 | RECORD(DECL_NAMESPACE_ALIAS); | 
|  | 905 | RECORD(DECL_USING); | 
|  | 906 | RECORD(DECL_USING_SHADOW); | 
|  | 907 | RECORD(DECL_USING_DIRECTIVE); | 
|  | 908 | RECORD(DECL_UNRESOLVED_USING_VALUE); | 
|  | 909 | RECORD(DECL_UNRESOLVED_USING_TYPENAME); | 
|  | 910 | RECORD(DECL_LINKAGE_SPEC); | 
|  | 911 | RECORD(DECL_CXX_RECORD); | 
|  | 912 | RECORD(DECL_CXX_METHOD); | 
|  | 913 | RECORD(DECL_CXX_CONSTRUCTOR); | 
|  | 914 | RECORD(DECL_CXX_DESTRUCTOR); | 
|  | 915 | RECORD(DECL_CXX_CONVERSION); | 
|  | 916 | RECORD(DECL_ACCESS_SPEC); | 
|  | 917 | RECORD(DECL_FRIEND); | 
|  | 918 | RECORD(DECL_FRIEND_TEMPLATE); | 
|  | 919 | RECORD(DECL_CLASS_TEMPLATE); | 
|  | 920 | RECORD(DECL_CLASS_TEMPLATE_SPECIALIZATION); | 
|  | 921 | RECORD(DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION); | 
| Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 922 | RECORD(DECL_VAR_TEMPLATE); | 
|  | 923 | RECORD(DECL_VAR_TEMPLATE_SPECIALIZATION); | 
|  | 924 | RECORD(DECL_VAR_TEMPLATE_PARTIAL_SPECIALIZATION); | 
| Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 925 | RECORD(DECL_FUNCTION_TEMPLATE); | 
|  | 926 | RECORD(DECL_TEMPLATE_TYPE_PARM); | 
|  | 927 | RECORD(DECL_NON_TYPE_TEMPLATE_PARM); | 
|  | 928 | RECORD(DECL_TEMPLATE_TEMPLATE_PARM); | 
| Saar Raz | d7aae33 | 2019-07-10 21:25:49 +0000 | [diff] [blame] | 929 | RECORD(DECL_CONCEPT); | 
| Saar Raz | a0f50d7 | 2020-01-18 09:11:43 +0200 | [diff] [blame] | 930 | RECORD(DECL_REQUIRES_EXPR_BODY); | 
| Richard Smith | efc884a | 2016-04-13 07:41:35 +0000 | [diff] [blame] | 931 | RECORD(DECL_TYPE_ALIAS_TEMPLATE); | 
| Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 932 | RECORD(DECL_STATIC_ASSERT); | 
|  | 933 | RECORD(DECL_CXX_BASE_SPECIFIERS); | 
| Richard Smith | efc884a | 2016-04-13 07:41:35 +0000 | [diff] [blame] | 934 | RECORD(DECL_CXX_CTOR_INITIALIZERS); | 
| Douglas Gregor | 0beaec0 | 2011-02-08 16:34:17 +0000 | [diff] [blame] | 935 | RECORD(DECL_INDIRECTFIELD); | 
|  | 936 | RECORD(DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK); | 
| Richard Smith | efc884a | 2016-04-13 07:41:35 +0000 | [diff] [blame] | 937 | RECORD(DECL_EXPANDED_TEMPLATE_TEMPLATE_PARM_PACK); | 
|  | 938 | RECORD(DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION); | 
|  | 939 | RECORD(DECL_IMPORT); | 
|  | 940 | RECORD(DECL_OMP_THREADPRIVATE); | 
|  | 941 | RECORD(DECL_EMPTY); | 
|  | 942 | RECORD(DECL_OBJC_TYPE_PARAM); | 
|  | 943 | RECORD(DECL_OMP_CAPTUREDEXPR); | 
|  | 944 | RECORD(DECL_PRAGMA_COMMENT); | 
|  | 945 | RECORD(DECL_PRAGMA_DETECT_MISMATCH); | 
|  | 946 | RECORD(DECL_OMP_DECLARE_REDUCTION); | 
| Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 947 | RECORD(DECL_OMP_ALLOCATE); | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 948 |  | 
| Douglas Gregor | 03412ba | 2011-06-03 02:27:19 +0000 | [diff] [blame] | 949 | // Statements and Exprs can occur in the Decls and Types block. | 
|  | 950 | AddStmtsExprs(Stream, Record); | 
|  | 951 |  | 
| Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 952 | BLOCK(PREPROCESSOR_DETAIL_BLOCK); | 
| Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 953 | RECORD(PPD_MACRO_EXPANSION); | 
| Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 954 | RECORD(PPD_MACRO_DEFINITION); | 
|  | 955 | RECORD(PPD_INCLUSION_DIRECTIVE); | 
| Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 956 |  | 
|  | 957 | // Decls and Types block. | 
|  | 958 | BLOCK(EXTENSION_BLOCK); | 
|  | 959 | RECORD(EXTENSION_METADATA); | 
|  | 960 |  | 
| Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 961 | BLOCK(UNHASHED_CONTROL_BLOCK); | 
|  | 962 | RECORD(SIGNATURE); | 
|  | 963 | RECORD(DIAGNOSTIC_OPTIONS); | 
|  | 964 | RECORD(DIAG_PRAGMA_MAPPINGS); | 
|  | 965 |  | 
| Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 966 | #undef RECORD | 
|  | 967 | #undef BLOCK | 
|  | 968 | Stream.ExitBlock(); | 
|  | 969 | } | 
|  | 970 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 971 | /// Prepares a path for being written to an AST file by converting it | 
| Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 972 | /// to an absolute path and removing nested './'s. | 
|  | 973 | /// | 
|  | 974 | /// \return \c true if the path was changed. | 
| Benjamin Kramer | 6a96ae5 | 2015-02-06 18:36:04 +0000 | [diff] [blame] | 975 | static bool cleanPathForOutput(FileManager &FileMgr, | 
|  | 976 | SmallVectorImpl<char> &Path) { | 
| Argyrios Kyrtzidis | 403cbcb | 2015-07-31 01:39:23 +0000 | [diff] [blame] | 977 | bool Changed = FileMgr.makeAbsolutePath(Path); | 
| Mike Aizatsky | aeb9dd9 | 2015-11-09 19:12:18 +0000 | [diff] [blame] | 978 | return Changed | llvm::sys::path::remove_dots(Path); | 
| Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 979 | } | 
|  | 980 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 981 | /// Adjusts the given filename to only write out the portion of the | 
| Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 982 | /// filename that is not part of the system root directory. | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 983 | /// | 
| Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 984 | /// \param Filename the file name to adjust. | 
|  | 985 | /// | 
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 986 | /// \param BaseDir When non-NULL, the PCH file is a relocatable AST file and | 
|  | 987 | /// the returned filename will be adjusted by this root directory. | 
| Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 988 | /// | 
|  | 989 | /// \returns either the original filename (if it needs no adjustment) or the | 
|  | 990 | /// adjusted filename (which points into the @p Filename parameter). | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 991 | static const char * | 
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 992 | adjustFilenameForRelocatableAST(const char *Filename, StringRef BaseDir) { | 
| Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 993 | assert(Filename && "No file name to adjust?"); | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 994 |  | 
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 995 | if (BaseDir.empty()) | 
| Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 996 | return Filename; | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 997 |  | 
| Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 998 | // Verify that the filename and the system root have the same prefix. | 
|  | 999 | unsigned Pos = 0; | 
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1000 | for (; Filename[Pos] && Pos < BaseDir.size(); ++Pos) | 
|  | 1001 | if (Filename[Pos] != BaseDir[Pos]) | 
| Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1002 | return Filename; // Prefixes don't match. | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1003 |  | 
| Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1004 | // We hit the end of the filename before we hit the end of the system root. | 
|  | 1005 | if (!Filename[Pos]) | 
|  | 1006 | return Filename; | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1007 |  | 
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1008 | // If there's not a path separator at the end of the base directory nor | 
|  | 1009 | // immediately after it, then this isn't within the base directory. | 
|  | 1010 | if (!llvm::sys::path::is_separator(Filename[Pos])) { | 
|  | 1011 | if (!llvm::sys::path::is_separator(BaseDir.back())) | 
|  | 1012 | return Filename; | 
|  | 1013 | } else { | 
|  | 1014 | // If the file name has a '/' at the current position, skip over the '/'. | 
|  | 1015 | // We distinguish relative paths from absolute paths by the | 
|  | 1016 | // absence of '/' at the beginning of relative paths. | 
|  | 1017 | // | 
|  | 1018 | // FIXME: This is wrong. We distinguish them by asking if the path is | 
|  | 1019 | // absolute, which isn't the same thing. And there might be multiple '/'s | 
|  | 1020 | // in a row. Use a better mechanism to indicate whether we have emitted an | 
|  | 1021 | // absolute or relative path. | 
| Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1022 | ++Pos; | 
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1023 | } | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1024 |  | 
| Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1025 | return Filename + Pos; | 
|  | 1026 | } | 
| Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 1027 |  | 
| Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 1028 | ASTFileSignature ASTWriter::createSignature(StringRef Bytes) { | 
|  | 1029 | // Calculate the hash till start of UNHASHED_CONTROL_BLOCK. | 
|  | 1030 | llvm::SHA1 Hasher; | 
|  | 1031 | Hasher.update(ArrayRef<uint8_t>(Bytes.bytes_begin(), Bytes.size())); | 
|  | 1032 | auto Hash = Hasher.result(); | 
|  | 1033 |  | 
|  | 1034 | // Convert to an array [5*i32]. | 
|  | 1035 | ASTFileSignature Signature; | 
|  | 1036 | auto LShift = [&](unsigned char Val, unsigned Shift) { | 
|  | 1037 | return (uint32_t)Val << Shift; | 
|  | 1038 | }; | 
|  | 1039 | for (int I = 0; I != 5; ++I) | 
|  | 1040 | Signature[I] = LShift(Hash[I * 4 + 0], 24) | LShift(Hash[I * 4 + 1], 16) | | 
|  | 1041 | LShift(Hash[I * 4 + 2], 8) | LShift(Hash[I * 4 + 3], 0); | 
|  | 1042 |  | 
|  | 1043 | return Signature; | 
|  | 1044 | } | 
|  | 1045 |  | 
|  | 1046 | ASTFileSignature ASTWriter::writeUnhashedControlBlock(Preprocessor &PP, | 
|  | 1047 | ASTContext &Context) { | 
|  | 1048 | // Flush first to prepare the PCM hash (signature). | 
|  | 1049 | Stream.FlushToWord(); | 
|  | 1050 | auto StartOfUnhashedControl = Stream.GetCurrentBitNo() >> 3; | 
|  | 1051 |  | 
|  | 1052 | // Enter the block and prepare to write records. | 
|  | 1053 | RecordData Record; | 
|  | 1054 | Stream.EnterSubblock(UNHASHED_CONTROL_BLOCK_ID, 5); | 
|  | 1055 |  | 
|  | 1056 | // For implicit modules, write the hash of the PCM as its signature. | 
|  | 1057 | ASTFileSignature Signature; | 
|  | 1058 | if (WritingModule && | 
|  | 1059 | PP.getHeaderSearchInfo().getHeaderSearchOpts().ModulesHashContent) { | 
|  | 1060 | Signature = createSignature(StringRef(Buffer.begin(), StartOfUnhashedControl)); | 
|  | 1061 | Record.append(Signature.begin(), Signature.end()); | 
|  | 1062 | Stream.EmitRecord(SIGNATURE, Record); | 
|  | 1063 | Record.clear(); | 
| Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 1064 | } | 
| Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 1065 |  | 
|  | 1066 | // Diagnostic options. | 
|  | 1067 | const auto &Diags = Context.getDiagnostics(); | 
|  | 1068 | const DiagnosticOptions &DiagOpts = Diags.getDiagnosticOptions(); | 
|  | 1069 | #define DIAGOPT(Name, Bits, Default) Record.push_back(DiagOpts.Name); | 
|  | 1070 | #define ENUM_DIAGOPT(Name, Type, Bits, Default)                                \ | 
|  | 1071 | Record.push_back(static_cast<unsigned>(DiagOpts.get##Name())); | 
|  | 1072 | #include "clang/Basic/DiagnosticOptions.def" | 
|  | 1073 | Record.push_back(DiagOpts.Warnings.size()); | 
|  | 1074 | for (unsigned I = 0, N = DiagOpts.Warnings.size(); I != N; ++I) | 
|  | 1075 | AddString(DiagOpts.Warnings[I], Record); | 
|  | 1076 | Record.push_back(DiagOpts.Remarks.size()); | 
|  | 1077 | for (unsigned I = 0, N = DiagOpts.Remarks.size(); I != N; ++I) | 
|  | 1078 | AddString(DiagOpts.Remarks[I], Record); | 
|  | 1079 | // Note: we don't serialize the log or serialization file names, because they | 
|  | 1080 | // are generally transient files and will almost always be overridden. | 
|  | 1081 | Stream.EmitRecord(DIAGNOSTIC_OPTIONS, Record); | 
|  | 1082 |  | 
|  | 1083 | // Write out the diagnostic/pragma mappings. | 
| Rui Ueyama | 49a3ad2 | 2019-07-16 04:46:31 +0000 | [diff] [blame] | 1084 | WritePragmaDiagnosticMappings(Diags, /* isModule = */ WritingModule); | 
| Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 1085 |  | 
|  | 1086 | // Leave the options block. | 
|  | 1087 | Stream.ExitBlock(); | 
|  | 1088 | return Signature; | 
| Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 1089 | } | 
|  | 1090 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1091 | /// Write the control block. | 
| Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 1092 | void ASTWriter::WriteControlBlock(Preprocessor &PP, ASTContext &Context, | 
|  | 1093 | StringRef isysroot, | 
|  | 1094 | const std::string &OutputFile) { | 
| Douglas Gregor | bfbde53 | 2009-04-10 21:16:55 +0000 | [diff] [blame] | 1095 | using namespace llvm; | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 1096 |  | 
| Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1097 | Stream.EnterSubblock(CONTROL_BLOCK_ID, 5); | 
| Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1098 | RecordData Record; | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 1099 |  | 
| Douglas Gregor | 0086a5a | 2009-07-07 00:12:59 +0000 | [diff] [blame] | 1100 | // Metadata | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1101 | auto MetadataAbbrev = std::make_shared<BitCodeAbbrev>(); | 
| Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1102 | MetadataAbbrev->Add(BitCodeAbbrevOp(METADATA)); | 
|  | 1103 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Major | 
|  | 1104 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Minor | 
|  | 1105 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang maj. | 
|  | 1106 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 16)); // Clang min. | 
|  | 1107 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Relocatable | 
| Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1108 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Timestamps | 
| Hans Wennborg | 08c5a7b | 2018-06-25 13:23:49 +0000 | [diff] [blame] | 1109 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // PCHHasObjectFile | 
| Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1110 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Errors | 
|  | 1111 | MetadataAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // SVN branch/tag | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1112 | unsigned MetadataAbbrevCode = Stream.EmitAbbrev(std::move(MetadataAbbrev)); | 
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1113 | assert((!WritingModule || isysroot.empty()) && | 
|  | 1114 | "writing module as a relocatable PCH?"); | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1115 | { | 
| Hans Wennborg | 08c5a7b | 2018-06-25 13:23:49 +0000 | [diff] [blame] | 1116 | RecordData::value_type Record[] = { | 
|  | 1117 | METADATA, | 
|  | 1118 | VERSION_MAJOR, | 
|  | 1119 | VERSION_MINOR, | 
|  | 1120 | CLANG_VERSION_MAJOR, | 
|  | 1121 | CLANG_VERSION_MINOR, | 
|  | 1122 | !isysroot.empty(), | 
|  | 1123 | IncludeTimestamps, | 
|  | 1124 | Context.getLangOpts().BuildingPCHWithObjectFile, | 
|  | 1125 | ASTHasCompilerErrors}; | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1126 | Stream.EmitRecordWithBlob(MetadataAbbrevCode, Record, | 
|  | 1127 | getClangFullRepositoryVersion()); | 
|  | 1128 | } | 
| Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 1129 |  | 
| Richard Smith | 8b70610 | 2017-05-31 20:56:55 +0000 | [diff] [blame] | 1130 | if (WritingModule) { | 
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1131 | // Module name | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1132 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); | 
| Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1133 | Abbrev->Add(BitCodeAbbrevOp(MODULE_NAME)); | 
|  | 1134 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1135 | unsigned AbbrevCode = Stream.EmitAbbrev(std::move(Abbrev)); | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1136 | RecordData::value_type Record[] = {MODULE_NAME}; | 
| Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1137 | Stream.EmitRecordWithBlob(AbbrevCode, Record, WritingModule->Name); | 
|  | 1138 | } | 
|  | 1139 |  | 
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1140 | if (WritingModule && WritingModule->Directory) { | 
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1141 | SmallString<128> BaseDir(WritingModule->Directory->getName()); | 
| Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 1142 | cleanPathForOutput(Context.getSourceManager().getFileManager(), BaseDir); | 
| Richard Smith | f7b4137 | 2015-08-13 23:47:44 +0000 | [diff] [blame] | 1143 |  | 
|  | 1144 | // If the home of the module is the current working directory, then we | 
|  | 1145 | // want to pick up the cwd of the build process loading the module, not | 
|  | 1146 | // our cwd, when we load this module. | 
|  | 1147 | if (!PP.getHeaderSearchInfo() | 
|  | 1148 | .getHeaderSearchOpts() | 
|  | 1149 | .ModuleMapFileHomeIsCwd || | 
|  | 1150 | WritingModule->Directory->getName() != StringRef(".")) { | 
|  | 1151 | // Module directory. | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1152 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); | 
| Richard Smith | f7b4137 | 2015-08-13 23:47:44 +0000 | [diff] [blame] | 1153 | Abbrev->Add(BitCodeAbbrevOp(MODULE_DIRECTORY)); | 
|  | 1154 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Directory | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1155 | unsigned AbbrevCode = Stream.EmitAbbrev(std::move(Abbrev)); | 
| Richard Smith | f7b4137 | 2015-08-13 23:47:44 +0000 | [diff] [blame] | 1156 |  | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1157 | RecordData::value_type Record[] = {MODULE_DIRECTORY}; | 
| Richard Smith | f7b4137 | 2015-08-13 23:47:44 +0000 | [diff] [blame] | 1158 | Stream.EmitRecordWithBlob(AbbrevCode, Record, BaseDir); | 
|  | 1159 | } | 
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1160 |  | 
|  | 1161 | // Write out all other paths relative to the base directory if possible. | 
|  | 1162 | BaseDirectory.assign(BaseDir.begin(), BaseDir.end()); | 
|  | 1163 | } else if (!isysroot.empty()) { | 
|  | 1164 | // Write out paths relative to the sysroot if possible. | 
| Benjamin Kramer | adcd026 | 2020-01-28 20:23:46 +0100 | [diff] [blame] | 1165 | BaseDirectory = std::string(isysroot); | 
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1166 | } | 
|  | 1167 |  | 
| Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1168 | // Module map file | 
| Richard Smith | d19389a | 2017-07-05 07:47:11 +0000 | [diff] [blame] | 1169 | if (WritingModule && WritingModule->Kind == Module::ModuleMapModule) { | 
| Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1170 | Record.clear(); | 
| Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1171 |  | 
| Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 1172 | auto &Map = PP.getHeaderSearchInfo().getModuleMap(); | 
| Richard Smith | 8b70610 | 2017-05-31 20:56:55 +0000 | [diff] [blame] | 1173 | AddPath(WritingModule->PresumedModuleMapFile.empty() | 
|  | 1174 | ? Map.getModuleMapFileForUniquing(WritingModule)->getName() | 
|  | 1175 | : StringRef(WritingModule->PresumedModuleMapFile), | 
|  | 1176 | Record); | 
| Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 1177 |  | 
|  | 1178 | // Additional module map files. | 
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1179 | if (auto *AdditionalModMaps = | 
|  | 1180 | Map.getAdditionalModuleMapFiles(WritingModule)) { | 
| Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 1181 | Record.push_back(AdditionalModMaps->size()); | 
|  | 1182 | for (const FileEntry *F : *AdditionalModMaps) | 
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1183 | AddPath(F->getName(), Record); | 
| Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 1184 | } else { | 
|  | 1185 | Record.push_back(0); | 
|  | 1186 | } | 
|  | 1187 |  | 
|  | 1188 | Stream.EmitRecord(MODULE_MAP_FILE, Record); | 
| Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1189 | } | 
|  | 1190 |  | 
| Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1191 | // Imports | 
| Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1192 | if (Chain) { | 
| Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1193 | serialization::ModuleManager &Mgr = Chain->getModuleManager(); | 
| Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1194 | Record.clear(); | 
| Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1195 |  | 
| Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 1196 | for (ModuleFile &M : Mgr) { | 
| Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1197 | // Skip modules that weren't directly imported. | 
| Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 1198 | if (!M.isDirectlyImported()) | 
| Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1199 | continue; | 
|  | 1200 |  | 
| Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 1201 | Record.push_back((unsigned)M.Kind); // FIXME: Stable encoding | 
|  | 1202 | AddSourceLocation(M.ImportLoc, Record); | 
| Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 1203 |  | 
|  | 1204 | // If we have calculated signature, there is no need to store | 
|  | 1205 | // the size or timestamp. | 
|  | 1206 | Record.push_back(M.Signature ? 0 : M.File->getSize()); | 
|  | 1207 | Record.push_back(M.Signature ? 0 : getTimestampForOutput(M.File)); | 
|  | 1208 |  | 
|  | 1209 | for (auto I : M.Signature) | 
|  | 1210 | Record.push_back(I); | 
|  | 1211 |  | 
| Boris Kolpackov | d30446f | 2017-08-31 06:26:43 +0000 | [diff] [blame] | 1212 | AddString(M.ModuleName, Record); | 
| Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 1213 | AddPath(M.FileName, Record); | 
| Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 1214 | } | 
| Douglas Gregor | 29cc642 | 2011-08-17 21:07:30 +0000 | [diff] [blame] | 1215 | Stream.EmitRecord(IMPORTS, Record); | 
|  | 1216 | } | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1217 |  | 
| Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 1218 | // Write the options block. | 
|  | 1219 | Stream.EnterSubblock(OPTIONS_BLOCK_ID, 4); | 
|  | 1220 |  | 
| Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1221 | // Language options. | 
| Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1222 | Record.clear(); | 
| Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1223 | const LangOptions &LangOpts = Context.getLangOpts(); | 
|  | 1224 | #define LANGOPT(Name, Bits, Default, Description) \ | 
|  | 1225 | Record.push_back(LangOpts.Name); | 
|  | 1226 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ | 
|  | 1227 | Record.push_back(static_cast<unsigned>(LangOpts.get##Name())); | 
| Alexey Samsonov | edf99a9 | 2014-11-07 22:29:38 +0000 | [diff] [blame] | 1228 | #include "clang/Basic/LangOptions.def" | 
|  | 1229 | #define SANITIZER(NAME, ID)                                                    \ | 
|  | 1230 | Record.push_back(LangOpts.Sanitize.has(SanitizerKind::ID)); | 
| Will Dietz | f54319c | 2013-01-18 11:30:38 +0000 | [diff] [blame] | 1231 | #include "clang/Basic/Sanitizers.def" | 
| Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1232 |  | 
| Ben Langmuir | cd98cb7 | 2015-06-23 18:20:18 +0000 | [diff] [blame] | 1233 | Record.push_back(LangOpts.ModuleFeatures.size()); | 
|  | 1234 | for (StringRef Feature : LangOpts.ModuleFeatures) | 
|  | 1235 | AddString(Feature, Record); | 
|  | 1236 |  | 
| Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1237 | Record.push_back((unsigned) LangOpts.ObjCRuntime.getKind()); | 
|  | 1238 | AddVersionTuple(LangOpts.ObjCRuntime.getVersion(), Record); | 
| Ben Langmuir | d4a667a | 2015-06-23 18:20:23 +0000 | [diff] [blame] | 1239 |  | 
|  | 1240 | AddString(LangOpts.CurrentModule, Record); | 
| Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 1241 |  | 
|  | 1242 | // Comment options. | 
|  | 1243 | Record.push_back(LangOpts.CommentOpts.BlockCommandNames.size()); | 
| Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1244 | for (const auto &I : LangOpts.CommentOpts.BlockCommandNames) { | 
|  | 1245 | AddString(I, Record); | 
| Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 1246 | } | 
| Dmitri Gribenko | a7d16ce | 2013-04-10 15:35:17 +0000 | [diff] [blame] | 1247 | Record.push_back(LangOpts.CommentOpts.ParseAllComments); | 
| Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 1248 |  | 
| Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 1249 | // OpenMP offloading options. | 
|  | 1250 | Record.push_back(LangOpts.OMPTargetTriples.size()); | 
|  | 1251 | for (auto &T : LangOpts.OMPTargetTriples) | 
|  | 1252 | AddString(T.getTriple(), Record); | 
|  | 1253 |  | 
|  | 1254 | AddString(LangOpts.OMPHostIRFile, Record); | 
|  | 1255 |  | 
| Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1256 | Stream.EmitRecord(LANGUAGE_OPTIONS, Record); | 
|  | 1257 |  | 
| Douglas Gregor | 4d3611c | 2012-10-18 17:58:09 +0000 | [diff] [blame] | 1258 | // Target options. | 
|  | 1259 | Record.clear(); | 
| Douglas Gregor | 0aa21c9 | 2012-10-18 18:27:37 +0000 | [diff] [blame] | 1260 | const TargetInfo &Target = Context.getTargetInfo(); | 
|  | 1261 | const TargetOptions &TargetOpts = Target.getTargetOpts(); | 
| Douglas Gregor | 4d3611c | 2012-10-18 17:58:09 +0000 | [diff] [blame] | 1262 | AddString(TargetOpts.Triple, Record); | 
|  | 1263 | AddString(TargetOpts.CPU, Record); | 
|  | 1264 | AddString(TargetOpts.ABI, Record); | 
| Douglas Gregor | 4d3611c | 2012-10-18 17:58:09 +0000 | [diff] [blame] | 1265 | Record.push_back(TargetOpts.FeaturesAsWritten.size()); | 
|  | 1266 | for (unsigned I = 0, N = TargetOpts.FeaturesAsWritten.size(); I != N; ++I) { | 
|  | 1267 | AddString(TargetOpts.FeaturesAsWritten[I], Record); | 
|  | 1268 | } | 
|  | 1269 | Record.push_back(TargetOpts.Features.size()); | 
|  | 1270 | for (unsigned I = 0, N = TargetOpts.Features.size(); I != N; ++I) { | 
|  | 1271 | AddString(TargetOpts.Features[I], Record); | 
|  | 1272 | } | 
|  | 1273 | Stream.EmitRecord(TARGET_OPTIONS, Record); | 
|  | 1274 |  | 
| Douglas Gregor | c6317db | 2012-10-24 15:49:58 +0000 | [diff] [blame] | 1275 | // File system options. | 
|  | 1276 | Record.clear(); | 
| Yaron Keren | 8dec46c | 2015-08-26 08:10:22 +0000 | [diff] [blame] | 1277 | const FileSystemOptions &FSOpts = | 
|  | 1278 | Context.getSourceManager().getFileManager().getFileSystemOpts(); | 
| Douglas Gregor | c6317db | 2012-10-24 15:49:58 +0000 | [diff] [blame] | 1279 | AddString(FSOpts.WorkingDir, Record); | 
|  | 1280 | Stream.EmitRecord(FILE_SYSTEM_OPTIONS, Record); | 
|  | 1281 |  | 
| Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1282 | // Header search options. | 
|  | 1283 | Record.clear(); | 
|  | 1284 | const HeaderSearchOptions &HSOpts | 
|  | 1285 | = PP.getHeaderSearchInfo().getHeaderSearchOpts(); | 
|  | 1286 | AddString(HSOpts.Sysroot, Record); | 
|  | 1287 |  | 
|  | 1288 | // Include entries. | 
|  | 1289 | Record.push_back(HSOpts.UserEntries.size()); | 
|  | 1290 | for (unsigned I = 0, N = HSOpts.UserEntries.size(); I != N; ++I) { | 
|  | 1291 | const HeaderSearchOptions::Entry &Entry = HSOpts.UserEntries[I]; | 
|  | 1292 | AddString(Entry.Path, Record); | 
|  | 1293 | Record.push_back(static_cast<unsigned>(Entry.Group)); | 
| Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1294 | Record.push_back(Entry.IsFramework); | 
|  | 1295 | Record.push_back(Entry.IgnoreSysRoot); | 
| Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1296 | } | 
|  | 1297 |  | 
|  | 1298 | // System header prefixes. | 
|  | 1299 | Record.push_back(HSOpts.SystemHeaderPrefixes.size()); | 
|  | 1300 | for (unsigned I = 0, N = HSOpts.SystemHeaderPrefixes.size(); I != N; ++I) { | 
|  | 1301 | AddString(HSOpts.SystemHeaderPrefixes[I].Prefix, Record); | 
|  | 1302 | Record.push_back(HSOpts.SystemHeaderPrefixes[I].IsSystemHeader); | 
|  | 1303 | } | 
|  | 1304 |  | 
|  | 1305 | AddString(HSOpts.ResourceDir, Record); | 
|  | 1306 | AddString(HSOpts.ModuleCachePath, Record); | 
| Argyrios Kyrtzidis | 1594c15 | 2014-03-03 08:12:05 +0000 | [diff] [blame] | 1307 | AddString(HSOpts.ModuleUserBuildPath, Record); | 
| Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1308 | Record.push_back(HSOpts.DisableModuleHash); | 
| Richard Smith | 1893475 | 2017-06-06 00:32:01 +0000 | [diff] [blame] | 1309 | Record.push_back(HSOpts.ImplicitModuleMaps); | 
|  | 1310 | Record.push_back(HSOpts.ModuleMapFileHomeIsCwd); | 
| Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1311 | Record.push_back(HSOpts.UseBuiltinIncludes); | 
|  | 1312 | Record.push_back(HSOpts.UseStandardSystemIncludes); | 
|  | 1313 | Record.push_back(HSOpts.UseStandardCXXIncludes); | 
|  | 1314 | Record.push_back(HSOpts.UseLibcxx); | 
| Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 1315 | // Write out the specific module cache path that contains the module files. | 
|  | 1316 | AddString(PP.getHeaderSearchInfo().getModuleCachePath(), Record); | 
| Douglas Gregor | 2d30236 | 2012-10-24 16:50:34 +0000 | [diff] [blame] | 1317 | Stream.EmitRecord(HEADER_SEARCH_OPTIONS, Record); | 
|  | 1318 |  | 
| Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1319 | // Preprocessor options. | 
|  | 1320 | Record.clear(); | 
|  | 1321 | const PreprocessorOptions &PPOpts = PP.getPreprocessorOpts(); | 
|  | 1322 |  | 
|  | 1323 | // Macro definitions. | 
|  | 1324 | Record.push_back(PPOpts.Macros.size()); | 
|  | 1325 | for (unsigned I = 0, N = PPOpts.Macros.size(); I != N; ++I) { | 
|  | 1326 | AddString(PPOpts.Macros[I].first, Record); | 
|  | 1327 | Record.push_back(PPOpts.Macros[I].second); | 
|  | 1328 | } | 
|  | 1329 |  | 
|  | 1330 | // Includes | 
|  | 1331 | Record.push_back(PPOpts.Includes.size()); | 
|  | 1332 | for (unsigned I = 0, N = PPOpts.Includes.size(); I != N; ++I) | 
|  | 1333 | AddString(PPOpts.Includes[I], Record); | 
|  | 1334 |  | 
|  | 1335 | // Macro includes | 
|  | 1336 | Record.push_back(PPOpts.MacroIncludes.size()); | 
|  | 1337 | for (unsigned I = 0, N = PPOpts.MacroIncludes.size(); I != N; ++I) | 
|  | 1338 | AddString(PPOpts.MacroIncludes[I], Record); | 
|  | 1339 |  | 
| Douglas Gregor | b636875 | 2012-10-24 23:41:50 +0000 | [diff] [blame] | 1340 | Record.push_back(PPOpts.UsePredefines); | 
| Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 1341 | // Detailed record is important since it is used for the module cache hash. | 
|  | 1342 | Record.push_back(PPOpts.DetailedRecord); | 
| Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1343 | AddString(PPOpts.ImplicitPCHInclude, Record); | 
| Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1344 | Record.push_back(static_cast<unsigned>(PPOpts.ObjCXXARCStandardLibrary)); | 
|  | 1345 | Stream.EmitRecord(PREPROCESSOR_OPTIONS, Record); | 
|  | 1346 |  | 
| Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 1347 | // Leave the options block. | 
|  | 1348 | Stream.ExitBlock(); | 
|  | 1349 |  | 
| Douglas Gregor | a3b2026 | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 1350 | // Original file name and file ID | 
| Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1351 | SourceManager &SM = Context.getSourceManager(); | 
|  | 1352 | if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) { | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1353 | auto FileAbbrev = std::make_shared<BitCodeAbbrev>(); | 
| Douglas Gregor | fad10d8 | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 1354 | FileAbbrev->Add(BitCodeAbbrevOp(ORIGINAL_FILE)); | 
|  | 1355 | FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // File ID | 
| Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1356 | FileAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1357 | unsigned FileAbbrevCode = Stream.EmitAbbrev(std::move(FileAbbrev)); | 
| Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1358 |  | 
| Douglas Gregor | b6af6c2 | 2012-10-24 20:05:57 +0000 | [diff] [blame] | 1359 | Record.clear(); | 
| Douglas Gregor | fad10d8 | 2012-10-18 18:36:53 +0000 | [diff] [blame] | 1360 | Record.push_back(ORIGINAL_FILE); | 
| Douglas Gregor | a3b2026 | 2011-05-06 21:43:30 +0000 | [diff] [blame] | 1361 | Record.push_back(SM.getMainFileID().getOpaqueValue()); | 
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1362 | EmitRecordWithPath(FileAbbrevCode, Record, MainFile->getName()); | 
| Douglas Gregor | 45fe036 | 2009-05-12 01:31:05 +0000 | [diff] [blame] | 1363 | } | 
| Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 1364 |  | 
| Argyrios Kyrtzidis | 5259524 | 2012-11-15 18:57:27 +0000 | [diff] [blame] | 1365 | Record.clear(); | 
|  | 1366 | Record.push_back(SM.getMainFileID().getOpaqueValue()); | 
|  | 1367 | Stream.EmitRecord(ORIGINAL_FILE_ID, Record); | 
|  | 1368 |  | 
| Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1369 | // Original PCH directory | 
|  | 1370 | if (!OutputFile.empty() && OutputFile != "-") { | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1371 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); | 
| Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1372 | Abbrev->Add(BitCodeAbbrevOp(ORIGINAL_PCH_DIR)); | 
|  | 1373 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1374 | unsigned AbbrevCode = Stream.EmitAbbrev(std::move(Abbrev)); | 
| Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1375 |  | 
| Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1376 | SmallString<128> OutputPath(OutputFile); | 
| Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1377 |  | 
| Argyrios Kyrtzidis | c56419e | 2015-07-31 00:58:32 +0000 | [diff] [blame] | 1378 | SM.getFileManager().makeAbsolutePath(OutputPath); | 
| Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1379 | StringRef origDir = llvm::sys::path::parent_path(OutputPath); | 
|  | 1380 |  | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1381 | RecordData::value_type Record[] = {ORIGINAL_PCH_DIR}; | 
| Argyrios Kyrtzidis | 10b2368 | 2011-02-15 17:54:22 +0000 | [diff] [blame] | 1382 | Stream.EmitRecordWithBlob(AbbrevCode, Record, origDir); | 
|  | 1383 | } | 
|  | 1384 |  | 
| Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1385 | WriteInputFiles(Context.SourceMgr, | 
|  | 1386 | PP.getHeaderSearchInfo().getHeaderSearchOpts(), | 
| Douglas Gregor | a3dd900 | 2013-07-22 20:48:33 +0000 | [diff] [blame] | 1387 | PP.getLangOpts().Modules); | 
| Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1388 | Stream.ExitBlock(); | 
|  | 1389 | } | 
|  | 1390 |  | 
| Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1391 | namespace  { | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 1392 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1393 | /// An input file. | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 1394 | struct InputFileEntry { | 
|  | 1395 | const FileEntry *File; | 
|  | 1396 | bool IsSystemFile; | 
|  | 1397 | bool IsTransient; | 
|  | 1398 | bool BufferOverridden; | 
|  | 1399 | bool IsTopLevelModuleMap; | 
| Bruno Cardoso Lopes | 1731fc8 | 2019-10-15 14:23:55 +0000 | [diff] [blame] | 1400 | uint32_t ContentHash[2]; | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 1401 | }; | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 1402 |  | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 1403 | } // namespace | 
| Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1404 |  | 
|  | 1405 | void ASTWriter::WriteInputFiles(SourceManager &SourceMgr, | 
|  | 1406 | HeaderSearchOptions &HSOpts, | 
| Douglas Gregor | a3dd900 | 2013-07-22 20:48:33 +0000 | [diff] [blame] | 1407 | bool Modules) { | 
| Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1408 | using namespace llvm; | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 1409 |  | 
| Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1410 | Stream.EnterSubblock(INPUT_FILES_BLOCK_ID, 4); | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1411 |  | 
| Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1412 | // Create input-file abbreviation. | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1413 | auto IFAbbrev = std::make_shared<BitCodeAbbrev>(); | 
| Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1414 | IFAbbrev->Add(BitCodeAbbrevOp(INPUT_FILE)); | 
| Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1415 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ID | 
| Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1416 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 12)); // Size | 
|  | 1417 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 32)); // Modification time | 
| Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1418 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Overridden | 
| Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 1419 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Transient | 
| Richard Smith | f3f8461 | 2017-06-29 02:19:42 +0000 | [diff] [blame] | 1420 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Module map | 
| Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1421 | IFAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // File name | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1422 | unsigned IFAbbrevCode = Stream.EmitAbbrev(std::move(IFAbbrev)); | 
| Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1423 |  | 
| Bruno Cardoso Lopes | 1731fc8 | 2019-10-15 14:23:55 +0000 | [diff] [blame] | 1424 | // Create input file hash abbreviation. | 
|  | 1425 | auto IFHAbbrev = std::make_shared<BitCodeAbbrev>(); | 
|  | 1426 | IFHAbbrev->Add(BitCodeAbbrevOp(INPUT_FILE_HASH)); | 
|  | 1427 | IFHAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); | 
|  | 1428 | IFHAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); | 
|  | 1429 | unsigned IFHAbbrevCode = Stream.EmitAbbrev(std::move(IFHAbbrev)); | 
|  | 1430 |  | 
| Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1431 | // Get all ContentCache objects for files, sorted by whether the file is a | 
|  | 1432 | // system one or not. System files go at the back, users files at the front. | 
| Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1433 | std::deque<InputFileEntry> SortedFiles; | 
| Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1434 | for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size(); I != N; ++I) { | 
|  | 1435 | // Get this source location entry. | 
|  | 1436 | const SrcMgr::SLocEntry *SLoc = &SourceMgr.getLocalSLocEntry(I); | 
| NAKAMURA Takumi | deca50f | 2012-10-19 01:53:57 +0000 | [diff] [blame] | 1437 | assert(&SourceMgr.getSLocEntry(FileID::get(I)) == SLoc); | 
| Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1438 |  | 
|  | 1439 | // We only care about file entries that were not overridden. | 
|  | 1440 | if (!SLoc->isFile()) | 
|  | 1441 | continue; | 
| Richard Smith | f3f8461 | 2017-06-29 02:19:42 +0000 | [diff] [blame] | 1442 | const SrcMgr::FileInfo &File = SLoc->getFile(); | 
|  | 1443 | const SrcMgr::ContentCache *Cache = File.getContentCache(); | 
| Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1444 | if (!Cache->OrigEntry) | 
| Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1445 | continue; | 
|  | 1446 |  | 
| Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1447 | InputFileEntry Entry; | 
|  | 1448 | Entry.File = Cache->OrigEntry; | 
| Duncan P. N. Exon Smith | f584819 | 2019-08-26 20:32:05 +0000 | [diff] [blame] | 1449 | Entry.IsSystemFile = isSystem(File.getFileCharacteristic()); | 
| Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 1450 | Entry.IsTransient = Cache->IsTransient; | 
| Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1451 | Entry.BufferOverridden = Cache->BufferOverridden; | 
| Richard Smith | f3f8461 | 2017-06-29 02:19:42 +0000 | [diff] [blame] | 1452 | Entry.IsTopLevelModuleMap = isModuleMap(File.getFileCharacteristic()) && | 
|  | 1453 | File.getIncludeLoc().isInvalid(); | 
| Bruno Cardoso Lopes | 1731fc8 | 2019-10-15 14:23:55 +0000 | [diff] [blame] | 1454 |  | 
|  | 1455 | auto ContentHash = hash_code(-1); | 
|  | 1456 | if (PP->getHeaderSearchInfo() | 
|  | 1457 | .getHeaderSearchOpts() | 
|  | 1458 | .ValidateASTInputFilesContent) { | 
|  | 1459 | auto *MemBuff = Cache->getRawBuffer(); | 
|  | 1460 | if (MemBuff) | 
|  | 1461 | ContentHash = hash_value(MemBuff->getBuffer()); | 
|  | 1462 | else | 
|  | 1463 | // FIXME: The path should be taken from the FileEntryRef. | 
|  | 1464 | PP->Diag(SourceLocation(), diag::err_module_unable_to_hash_content) | 
|  | 1465 | << Entry.File->getName(); | 
|  | 1466 | } | 
|  | 1467 | auto CH = llvm::APInt(64, ContentHash); | 
|  | 1468 | Entry.ContentHash[0] = | 
|  | 1469 | static_cast<uint32_t>(CH.getLoBits(32).getZExtValue()); | 
|  | 1470 | Entry.ContentHash[1] = | 
|  | 1471 | static_cast<uint32_t>(CH.getHiBits(32).getZExtValue()); | 
|  | 1472 |  | 
| Duncan P. N. Exon Smith | f584819 | 2019-08-26 20:32:05 +0000 | [diff] [blame] | 1473 | if (Entry.IsSystemFile) | 
| Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1474 | SortedFiles.push_back(Entry); | 
| Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1475 | else | 
| Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1476 | SortedFiles.push_front(Entry); | 
|  | 1477 | } | 
|  | 1478 |  | 
| Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1479 | unsigned UserFilesNum = 0; | 
|  | 1480 | // Write out all of the input files. | 
| Richard Smith | ec21650 | 2015-02-13 19:48:37 +0000 | [diff] [blame] | 1481 | std::vector<uint64_t> InputFileOffsets; | 
| Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1482 | for (const auto &Entry : SortedFiles) { | 
| Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1483 | uint32_t &InputFileID = InputFileIDs[Entry.File]; | 
| Argyrios Kyrtzidis | e65856f | 2012-12-11 07:48:08 +0000 | [diff] [blame] | 1484 | if (InputFileID != 0) | 
|  | 1485 | continue; // already recorded this file. | 
|  | 1486 |  | 
| Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1487 | // Record this entry's offset. | 
|  | 1488 | InputFileOffsets.push_back(Stream.GetCurrentBitNo()); | 
| Argyrios Kyrtzidis | e65856f | 2012-12-11 07:48:08 +0000 | [diff] [blame] | 1489 |  | 
|  | 1490 | InputFileID = InputFileOffsets.size(); | 
| Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1491 |  | 
| Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1492 | if (!Entry.IsSystemFile) | 
| Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1493 | ++UserFilesNum; | 
|  | 1494 |  | 
| Douglas Gregor | 72be390 | 2012-10-19 00:38:02 +0000 | [diff] [blame] | 1495 | // Emit size/modification time for this file. | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1496 | // And whether this file was overridden. | 
| Bruno Cardoso Lopes | 1731fc8 | 2019-10-15 14:23:55 +0000 | [diff] [blame] | 1497 | { | 
|  | 1498 | RecordData::value_type Record[] = { | 
|  | 1499 | INPUT_FILE, | 
|  | 1500 | InputFileOffsets.size(), | 
|  | 1501 | (uint64_t)Entry.File->getSize(), | 
|  | 1502 | (uint64_t)getTimestampForOutput(Entry.File), | 
|  | 1503 | Entry.BufferOverridden, | 
|  | 1504 | Entry.IsTransient, | 
|  | 1505 | Entry.IsTopLevelModuleMap}; | 
| Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1506 |  | 
| Bruno Cardoso Lopes | 1731fc8 | 2019-10-15 14:23:55 +0000 | [diff] [blame] | 1507 | // FIXME: The path should be taken from the FileEntryRef. | 
|  | 1508 | EmitRecordWithPath(IFAbbrevCode, Record, Entry.File->getName()); | 
|  | 1509 | } | 
|  | 1510 |  | 
|  | 1511 | // Emit content hash for this file. | 
|  | 1512 | { | 
|  | 1513 | RecordData::value_type Record[] = {INPUT_FILE_HASH, Entry.ContentHash[0], | 
|  | 1514 | Entry.ContentHash[1]}; | 
|  | 1515 | Stream.EmitRecordWithAbbrev(IFHAbbrevCode, Record); | 
|  | 1516 | } | 
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1517 | } | 
| Douglas Gregor | 49491f7 | 2013-03-15 22:15:07 +0000 | [diff] [blame] | 1518 |  | 
| Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 1519 | Stream.ExitBlock(); | 
| Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1520 |  | 
|  | 1521 | // Create input file offsets abbreviation. | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1522 | auto OffsetsAbbrev = std::make_shared<BitCodeAbbrev>(); | 
| Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1523 | OffsetsAbbrev->Add(BitCodeAbbrevOp(INPUT_FILE_OFFSETS)); | 
|  | 1524 | OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # input files | 
| Argyrios Kyrtzidis | 7d23857 | 2013-03-06 18:12:50 +0000 | [diff] [blame] | 1525 | OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # non-system | 
|  | 1526 | //   input files | 
| Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1527 | OffsetsAbbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));   // Array | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1528 | unsigned OffsetsAbbrevCode = Stream.EmitAbbrev(std::move(OffsetsAbbrev)); | 
| Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1529 |  | 
|  | 1530 | // Write input file offsets. | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1531 | RecordData::value_type Record[] = {INPUT_FILE_OFFSETS, | 
|  | 1532 | InputFileOffsets.size(), UserFilesNum}; | 
| Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 1533 | Stream.EmitRecordWithBlob(OffsetsAbbrevCode, Record, bytes(InputFileOffsets)); | 
| Douglas Gregor | 55abb23 | 2009-04-10 20:39:37 +0000 | [diff] [blame] | 1534 | } | 
|  | 1535 |  | 
| Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1536 | //===----------------------------------------------------------------------===// | 
|  | 1537 | // Source Manager Serialization | 
|  | 1538 | //===----------------------------------------------------------------------===// | 
|  | 1539 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1540 | /// Create an abbreviation for the SLocEntry that refers to a | 
| Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1541 | /// file. | 
| Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1542 | static unsigned CreateSLocFileAbbrev(llvm::BitstreamWriter &Stream) { | 
| Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1543 | using namespace llvm; | 
| Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1544 |  | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1545 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); | 
| Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1546 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_FILE_ENTRY)); | 
| Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1547 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset | 
|  | 1548 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location | 
| Richard Smith | f3f8461 | 2017-06-29 02:19:42 +0000 | [diff] [blame] | 1549 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Characteristic | 
| Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1550 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives | 
| Douglas Gregor | b41ca8f | 2010-03-21 22:49:54 +0000 | [diff] [blame] | 1551 | // FileEntry fields. | 
| Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1552 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Input File ID | 
| Argyrios Kyrtzidis | 61ef3db | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1553 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // NumCreatedFIDs | 
| Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1554 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 24)); // FirstDeclIndex | 
|  | 1555 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // NumDecls | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1556 | return Stream.EmitAbbrev(std::move(Abbrev)); | 
| Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1557 | } | 
|  | 1558 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1559 | /// Create an abbreviation for the SLocEntry that refers to a | 
| Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1560 | /// buffer. | 
| Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 1561 | static unsigned CreateSLocBufferAbbrev(llvm::BitstreamWriter &Stream) { | 
| Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1562 | using namespace llvm; | 
| Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1563 |  | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1564 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); | 
| Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1565 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_BUFFER_ENTRY)); | 
| Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1566 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset | 
|  | 1567 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location | 
| Richard Smith | f3f8461 | 2017-06-29 02:19:42 +0000 | [diff] [blame] | 1568 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Characteristic | 
| Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1569 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives | 
|  | 1570 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Buffer name blob | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1571 | return Stream.EmitAbbrev(std::move(Abbrev)); | 
| Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1572 | } | 
|  | 1573 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1574 | /// Create an abbreviation for the SLocEntry that refers to a | 
| Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1575 | /// buffer's blob. | 
| Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1576 | static unsigned CreateSLocBufferBlobAbbrev(llvm::BitstreamWriter &Stream, | 
|  | 1577 | bool Compressed) { | 
| Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1578 | using namespace llvm; | 
| Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1579 |  | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1580 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); | 
| Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1581 | Abbrev->Add(BitCodeAbbrevOp(Compressed ? SM_SLOC_BUFFER_BLOB_COMPRESSED | 
|  | 1582 | : SM_SLOC_BUFFER_BLOB)); | 
|  | 1583 | if (Compressed) | 
|  | 1584 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Uncompressed size | 
| Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1585 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Blob | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1586 | return Stream.EmitAbbrev(std::move(Abbrev)); | 
| Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1587 | } | 
|  | 1588 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1589 | /// Create an abbreviation for the SLocEntry that refers to a macro | 
| Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1590 | /// expansion. | 
|  | 1591 | static unsigned CreateSLocExpansionAbbrev(llvm::BitstreamWriter &Stream) { | 
| Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1592 | using namespace llvm; | 
| Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1593 |  | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1594 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); | 
| Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1595 | Abbrev->Add(BitCodeAbbrevOp(SM_SLOC_EXPANSION_ENTRY)); | 
| Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1596 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Offset | 
|  | 1597 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Spelling location | 
|  | 1598 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Start location | 
|  | 1599 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // End location | 
| Richard Smith | b5f8171 | 2018-04-30 05:25:48 +0000 | [diff] [blame] | 1600 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Is token range | 
| Douglas Gregor | 8324327 | 2009-04-15 18:05:10 +0000 | [diff] [blame] | 1601 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Token length | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1602 | return Stream.EmitAbbrev(std::move(Abbrev)); | 
| Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1603 | } | 
|  | 1604 |  | 
| Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1605 | namespace { | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 1606 |  | 
| Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1607 | // Trait used for the on-disk hash table of header search information. | 
|  | 1608 | class HeaderFileInfoTrait { | 
|  | 1609 | ASTWriter &Writer; | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 1610 |  | 
| Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1611 | // Keep track of the framework names we've used during serialization. | 
|  | 1612 | SmallVector<char, 128> FrameworkStringData; | 
|  | 1613 | llvm::StringMap<unsigned> FrameworkNameOffset; | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 1614 |  | 
| Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1615 | public: | 
| Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1616 | HeaderFileInfoTrait(ASTWriter &Writer) : Writer(Writer) {} | 
|  | 1617 |  | 
| Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1618 | struct key_type { | 
| Mehdi Amini | 004b9c7 | 2016-10-10 22:52:47 +0000 | [diff] [blame] | 1619 | StringRef Filename; | 
| Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1620 | off_t Size; | 
|  | 1621 | time_t ModTime; | 
| Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1622 | }; | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 1623 | using key_type_ref = const key_type &; | 
| Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1624 |  | 
|  | 1625 | using UnresolvedModule = | 
|  | 1626 | llvm::PointerIntPair<Module *, 2, ModuleMap::ModuleHeaderRole>; | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 1627 |  | 
| Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1628 | struct data_type { | 
|  | 1629 | const HeaderFileInfo &HFI; | 
|  | 1630 | ArrayRef<ModuleMap::KnownHeader> KnownHeaders; | 
|  | 1631 | UnresolvedModule Unresolved; | 
|  | 1632 | }; | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 1633 | using data_type_ref = const data_type &; | 
| Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1634 |  | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 1635 | using hash_value_type = unsigned; | 
|  | 1636 | using offset_type = unsigned; | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 1637 |  | 
| Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1638 | hash_value_type ComputeHash(key_type_ref key) { | 
| Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1639 | // The hash is based only on size/time of the file, so that the reader can | 
|  | 1640 | // match even when symlinking or excess path elements ("foo/../", "../") | 
|  | 1641 | // change the form of the name. However, complete path is still the key. | 
| Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1642 | return llvm::hash_combine(key.Size, key.ModTime); | 
| Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1643 | } | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 1644 |  | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 1645 | std::pair<unsigned, unsigned> | 
| Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1646 | EmitKeyDataLength(raw_ostream& Out, key_type_ref key, data_type_ref Data) { | 
| Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1647 | using namespace llvm::support; | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 1648 |  | 
| Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 1649 | endian::Writer LE(Out, little); | 
| Mehdi Amini | 004b9c7 | 2016-10-10 22:52:47 +0000 | [diff] [blame] | 1650 | unsigned KeyLen = key.Filename.size() + 1 + 8 + 8; | 
| Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1651 | LE.write<uint16_t>(KeyLen); | 
| Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1652 | unsigned DataLen = 1 + 2 + 4 + 4; | 
| Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1653 | for (auto ModInfo : Data.KnownHeaders) | 
| Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1654 | if (Writer.getLocalOrImportedSubmoduleID(ModInfo.getModule())) | 
|  | 1655 | DataLen += 4; | 
| Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1656 | if (Data.Unresolved.getPointer()) | 
|  | 1657 | DataLen += 4; | 
| Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1658 | LE.write<uint8_t>(DataLen); | 
| Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1659 | return std::make_pair(KeyLen, DataLen); | 
| Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1660 | } | 
| Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1661 |  | 
| Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1662 | void EmitKey(raw_ostream& Out, key_type_ref key, unsigned KeyLen) { | 
| Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1663 | using namespace llvm::support; | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 1664 |  | 
| Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 1665 | endian::Writer LE(Out, little); | 
| Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1666 | LE.write<uint64_t>(key.Size); | 
| Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1667 | KeyLen -= 8; | 
| Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1668 | LE.write<uint64_t>(key.ModTime); | 
| Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1669 | KeyLen -= 8; | 
| Mehdi Amini | 004b9c7 | 2016-10-10 22:52:47 +0000 | [diff] [blame] | 1670 | Out.write(key.Filename.data(), KeyLen); | 
| Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1671 | } | 
| Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1672 |  | 
| Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1673 | void EmitData(raw_ostream &Out, key_type_ref key, | 
| Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1674 | data_type_ref Data, unsigned DataLen) { | 
| Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1675 | using namespace llvm::support; | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 1676 |  | 
| Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 1677 | endian::Writer LE(Out, little); | 
| Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1678 | uint64_t Start = Out.tell(); (void)Start; | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 1679 |  | 
| Richard Smith | f3f8461 | 2017-06-29 02:19:42 +0000 | [diff] [blame] | 1680 | unsigned char Flags = (Data.HFI.isImport << 5) | 
|  | 1681 | | (Data.HFI.isPragmaOnce << 4) | 
| Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1682 | | (Data.HFI.DirInfo << 1) | 
|  | 1683 | | Data.HFI.IndexHeaderMapHeader; | 
| Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1684 | LE.write<uint8_t>(Flags); | 
| Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1685 | LE.write<uint16_t>(Data.HFI.NumIncludes); | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 1686 |  | 
| Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1687 | if (!Data.HFI.ControllingMacro) | 
|  | 1688 | LE.write<uint32_t>(Data.HFI.ControllingMacroID); | 
| Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1689 | else | 
| Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1690 | LE.write<uint32_t>(Writer.getIdentifierRef(Data.HFI.ControllingMacro)); | 
|  | 1691 |  | 
| Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1692 | unsigned Offset = 0; | 
| Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1693 | if (!Data.HFI.Framework.empty()) { | 
| Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1694 | // If this header refers into a framework, save the framework name. | 
|  | 1695 | llvm::StringMap<unsigned>::iterator Pos | 
| Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1696 | = FrameworkNameOffset.find(Data.HFI.Framework); | 
| Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1697 | if (Pos == FrameworkNameOffset.end()) { | 
|  | 1698 | Offset = FrameworkStringData.size() + 1; | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 1699 | FrameworkStringData.append(Data.HFI.Framework.begin(), | 
| Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1700 | Data.HFI.Framework.end()); | 
| Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1701 | FrameworkStringData.push_back(0); | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 1702 |  | 
| Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1703 | FrameworkNameOffset[Data.HFI.Framework] = Offset; | 
| Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1704 | } else | 
|  | 1705 | Offset = Pos->second; | 
|  | 1706 | } | 
| Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1707 | LE.write<uint32_t>(Offset); | 
| Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1708 |  | 
| Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1709 | auto EmitModule = [&](Module *M, ModuleMap::ModuleHeaderRole Role) { | 
|  | 1710 | if (uint32_t ModID = Writer.getLocalOrImportedSubmoduleID(M)) { | 
|  | 1711 | uint32_t Value = (ModID << 2) | (unsigned)Role; | 
| Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1712 | assert((Value >> 2) == ModID && "overflow in header module info"); | 
|  | 1713 | LE.write<uint32_t>(Value); | 
|  | 1714 | } | 
| Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1715 | }; | 
|  | 1716 |  | 
|  | 1717 | // FIXME: If the header is excluded, we should write out some | 
|  | 1718 | // record of that fact. | 
|  | 1719 | for (auto ModInfo : Data.KnownHeaders) | 
|  | 1720 | EmitModule(ModInfo.getModule(), ModInfo.getRole()); | 
|  | 1721 | if (Data.Unresolved.getPointer()) | 
|  | 1722 | EmitModule(Data.Unresolved.getPointer(), Data.Unresolved.getInt()); | 
| Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1723 |  | 
| Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1724 | assert(Out.tell() - Start == DataLen && "Wrong data length"); | 
|  | 1725 | } | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 1726 |  | 
| Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1727 | const char *strings_begin() const { return FrameworkStringData.begin(); } | 
|  | 1728 | const char *strings_end() const { return FrameworkStringData.end(); } | 
| Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1729 | }; | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 1730 |  | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 1731 | } // namespace | 
| Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1732 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1733 | /// Write the header search block for the list of files that | 
| Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1734 | /// | 
|  | 1735 | /// \param HS The header search structure to save. | 
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1736 | void ASTWriter::WriteHeaderSearch(const HeaderSearch &HS) { | 
| Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1737 | HeaderFileInfoTrait GeneratorTrait(*this); | 
|  | 1738 | llvm::OnDiskChainedHashTableGenerator<HeaderFileInfoTrait> Generator; | 
|  | 1739 | SmallVector<const char *, 4> SavedStrings; | 
|  | 1740 | unsigned NumHeaderSearchEntries = 0; | 
|  | 1741 |  | 
|  | 1742 | // Find all unresolved headers for the current module. We generally will | 
|  | 1743 | // have resolved them before we get here, but not necessarily: we might be | 
|  | 1744 | // compiling a preprocessed module, where there is no requirement for the | 
|  | 1745 | // original files to exist any more. | 
| Benjamin Kramer | ee021d5 | 2017-06-02 17:30:24 +0000 | [diff] [blame] | 1746 | const HeaderFileInfo Empty; // So we can take a reference. | 
| Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1747 | if (WritingModule) { | 
|  | 1748 | llvm::SmallVector<Module *, 16> Worklist(1, WritingModule); | 
|  | 1749 | while (!Worklist.empty()) { | 
|  | 1750 | Module *M = Worklist.pop_back_val(); | 
| Richard Smith | 6bc7502 | 2020-04-17 20:25:15 -0700 | [diff] [blame] | 1751 | // We don't care about headers in unimportable submodules. | 
|  | 1752 | if (M->isUnimportable()) | 
| Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1753 | continue; | 
|  | 1754 |  | 
|  | 1755 | // Map to disk files where possible, to pick up any missing stat | 
|  | 1756 | // information. This also means we don't need to check the unresolved | 
|  | 1757 | // headers list when emitting resolved headers in the first loop below. | 
|  | 1758 | // FIXME: It'd be preferable to avoid doing this if we were given | 
|  | 1759 | // sufficient stat information in the module map. | 
|  | 1760 | HS.getModuleMap().resolveHeaderDirectives(M); | 
|  | 1761 |  | 
|  | 1762 | // If the file didn't exist, we can still create a module if we were given | 
|  | 1763 | // enough information in the module map. | 
|  | 1764 | for (auto U : M->MissingHeaders) { | 
|  | 1765 | // Check that we were given enough information to build a module | 
|  | 1766 | // without this file existing on disk. | 
|  | 1767 | if (!U.Size || (!U.ModTime && IncludeTimestamps)) { | 
|  | 1768 | PP->Diag(U.FileNameLoc, diag::err_module_no_size_mtime_for_header) | 
|  | 1769 | << WritingModule->getFullModuleName() << U.Size.hasValue() | 
|  | 1770 | << U.FileName; | 
|  | 1771 | continue; | 
|  | 1772 | } | 
|  | 1773 |  | 
|  | 1774 | // Form the effective relative pathname for the file. | 
|  | 1775 | SmallString<128> Filename(M->Directory->getName()); | 
|  | 1776 | llvm::sys::path::append(Filename, U.FileName); | 
|  | 1777 | PreparePathForOutput(Filename); | 
|  | 1778 |  | 
|  | 1779 | StringRef FilenameDup = strdup(Filename.c_str()); | 
|  | 1780 | SavedStrings.push_back(FilenameDup.data()); | 
|  | 1781 |  | 
|  | 1782 | HeaderFileInfoTrait::key_type Key = { | 
|  | 1783 | FilenameDup, *U.Size, IncludeTimestamps ? *U.ModTime : 0 | 
|  | 1784 | }; | 
|  | 1785 | HeaderFileInfoTrait::data_type Data = { | 
| Benjamin Kramer | ee021d5 | 2017-06-02 17:30:24 +0000 | [diff] [blame] | 1786 | Empty, {}, {M, ModuleMap::headerKindToRole(U.Kind)} | 
| Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1787 | }; | 
|  | 1788 | // FIXME: Deal with cases where there are multiple unresolved header | 
|  | 1789 | // directives in different submodules for the same header. | 
|  | 1790 | Generator.insert(Key, Data, GeneratorTrait); | 
|  | 1791 | ++NumHeaderSearchEntries; | 
|  | 1792 | } | 
|  | 1793 |  | 
|  | 1794 | Worklist.append(M->submodule_begin(), M->submodule_end()); | 
|  | 1795 | } | 
|  | 1796 | } | 
|  | 1797 |  | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1798 | SmallVector<const FileEntry *, 16> FilesByUID; | 
| Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1799 | HS.getFileMgr().GetUniqueIDMapping(FilesByUID); | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 1800 |  | 
| Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1801 | if (FilesByUID.size() > HS.header_file_size()) | 
|  | 1802 | FilesByUID.resize(HS.header_file_size()); | 
| Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1803 |  | 
| Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1804 | for (unsigned UID = 0, LastUID = FilesByUID.size(); UID != LastUID; ++UID) { | 
|  | 1805 | const FileEntry *File = FilesByUID[UID]; | 
|  | 1806 | if (!File) | 
|  | 1807 | continue; | 
|  | 1808 |  | 
| Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1809 | // Get the file info. This will load info from the external source if | 
|  | 1810 | // necessary. Skip emitting this file if we have no information on it | 
|  | 1811 | // as a header file (in which case HFI will be null) or if it hasn't | 
|  | 1812 | // changed since it was loaded. Also skip it if it's for a modular header | 
|  | 1813 | // from a different module; in that case, we rely on the module(s) | 
|  | 1814 | // containing the header to provide this information. | 
| Richard Smith | d8879c8 | 2015-08-24 21:59:32 +0000 | [diff] [blame] | 1815 | const HeaderFileInfo *HFI = | 
|  | 1816 | HS.getExistingFileInfo(File, /*WantExternal*/!Chain); | 
|  | 1817 | if (!HFI || (HFI->isModuleHeader && !HFI->isCompilingModuleHeader)) | 
| Argyrios Kyrtzidis | 6f722b4 | 2013-05-08 23:46:46 +0000 | [diff] [blame] | 1818 | continue; | 
| Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1819 |  | 
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1820 | // Massage the file path into an appropriate form. | 
| Mehdi Amini | 004b9c7 | 2016-10-10 22:52:47 +0000 | [diff] [blame] | 1821 | StringRef Filename = File->getName(); | 
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1822 | SmallString<128> FilenameTmp(Filename); | 
|  | 1823 | if (PreparePathForOutput(FilenameTmp)) { | 
|  | 1824 | // If we performed any translation on the file name at all, we need to | 
|  | 1825 | // save this string, since the generator will refer to it later. | 
| Mehdi Amini | 004b9c7 | 2016-10-10 22:52:47 +0000 | [diff] [blame] | 1826 | Filename = StringRef(strdup(FilenameTmp.c_str())); | 
|  | 1827 | SavedStrings.push_back(Filename.data()); | 
| Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1828 | } | 
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1829 |  | 
| Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1830 | HeaderFileInfoTrait::key_type Key = { | 
|  | 1831 | Filename, File->getSize(), getTimestampForOutput(File) | 
|  | 1832 | }; | 
|  | 1833 | HeaderFileInfoTrait::data_type Data = { | 
| Richard Smith | 0a088ea | 2020-04-28 18:22:34 -0700 | [diff] [blame] | 1834 | *HFI, HS.getModuleMap().findResolvedModulesForHeader(File), {} | 
| Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1835 | }; | 
|  | 1836 | Generator.insert(Key, Data, GeneratorTrait); | 
| Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1837 | ++NumHeaderSearchEntries; | 
|  | 1838 | } | 
| Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 1839 |  | 
| Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1840 | // Create the on-disk hash table in a buffer. | 
| Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 1841 | SmallString<4096> TableData; | 
| Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1842 | uint32_t BucketOffset; | 
|  | 1843 | { | 
| Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 1844 | using namespace llvm::support; | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 1845 |  | 
| Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1846 | llvm::raw_svector_ostream Out(TableData); | 
|  | 1847 | // Make sure that no bucket is at offset 0 | 
| Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 1848 | endian::write<uint32_t>(Out, 0, little); | 
| Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1849 | BucketOffset = Generator.Emit(Out, GeneratorTrait); | 
|  | 1850 | } | 
|  | 1851 |  | 
|  | 1852 | // Create a blob abbreviation | 
|  | 1853 | using namespace llvm; | 
| Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 1854 |  | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1855 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); | 
| Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1856 | Abbrev->Add(BitCodeAbbrevOp(HEADER_SEARCH_TABLE)); | 
|  | 1857 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); | 
|  | 1858 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); | 
| Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1859 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); | 
| Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1860 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 1861 | unsigned TableAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 1862 |  | 
| Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1863 | // Write the header search table | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 1864 | RecordData::value_type Record[] = {HEADER_SEARCH_TABLE, BucketOffset, | 
|  | 1865 | NumHeaderSearchEntries, TableData.size()}; | 
| Douglas Gregor | 4b123cb | 2011-07-28 04:50:02 +0000 | [diff] [blame] | 1866 | TableData.append(GeneratorTrait.strings_begin(),GeneratorTrait.strings_end()); | 
| Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 1867 | Stream.EmitRecordWithBlob(TableAbbrev, Record, TableData); | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 1868 |  | 
| Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1869 | // Free all of the strings we had to duplicate. | 
|  | 1870 | for (unsigned I = 0, N = SavedStrings.size(); I != N; ++I) | 
| David Greene | bae0e35 | 2013-01-15 22:09:43 +0000 | [diff] [blame] | 1871 | free(const_cast<char *>(SavedStrings[I])); | 
| Douglas Gregor | 09b6989 | 2011-02-10 17:09:37 +0000 | [diff] [blame] | 1872 | } | 
|  | 1873 |  | 
| George Rimar | c39f549 | 2017-01-17 15:45:31 +0000 | [diff] [blame] | 1874 | static void emitBlob(llvm::BitstreamWriter &Stream, StringRef Blob, | 
|  | 1875 | unsigned SLocBufferBlobCompressedAbbrv, | 
|  | 1876 | unsigned SLocBufferBlobAbbrv) { | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 1877 | using RecordDataType = ASTWriter::RecordData::value_type; | 
| George Rimar | c39f549 | 2017-01-17 15:45:31 +0000 | [diff] [blame] | 1878 |  | 
|  | 1879 | // Compress the buffer if possible. We expect that almost all PCM | 
|  | 1880 | // consumers will not want its contents. | 
|  | 1881 | SmallString<0> CompressedBuffer; | 
|  | 1882 | if (llvm::zlib::isAvailable()) { | 
|  | 1883 | llvm::Error E = llvm::zlib::compress(Blob.drop_back(1), CompressedBuffer); | 
|  | 1884 | if (!E) { | 
|  | 1885 | RecordDataType Record[] = {SM_SLOC_BUFFER_BLOB_COMPRESSED, | 
|  | 1886 | Blob.size() - 1}; | 
|  | 1887 | Stream.EmitRecordWithBlob(SLocBufferBlobCompressedAbbrv, Record, | 
|  | 1888 | CompressedBuffer); | 
|  | 1889 | return; | 
|  | 1890 | } | 
|  | 1891 | llvm::consumeError(std::move(E)); | 
|  | 1892 | } | 
|  | 1893 |  | 
|  | 1894 | RecordDataType Record[] = {SM_SLOC_BUFFER_BLOB}; | 
|  | 1895 | Stream.EmitRecordWithBlob(SLocBufferBlobAbbrv, Record, Blob); | 
|  | 1896 | } | 
|  | 1897 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1898 | /// Writes the block containing the serialized form of the | 
| Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1899 | /// source manager. | 
|  | 1900 | /// | 
|  | 1901 | /// TODO: We should probably use an on-disk hash table (stored in a | 
|  | 1902 | /// blob), indexed based on the file name, so that we only create | 
|  | 1903 | /// entries for files that we actually need. In the common case (no | 
|  | 1904 | /// errors), we probably won't have to create file entries for any of | 
|  | 1905 | /// the files in the AST. | 
| Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 1906 | void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr, | 
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1907 | const Preprocessor &PP) { | 
| Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1908 | RecordData Record; | 
|  | 1909 |  | 
| Chris Lattner | 0910e3b | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 1910 | // Enter the source manager block. | 
| Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1911 | Stream.EnterSubblock(SOURCE_MANAGER_BLOCK_ID, 4); | 
| Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1912 |  | 
|  | 1913 | // Abbreviations for the various kinds of source-location entries. | 
| Chris Lattner | c4976c73 | 2009-04-27 19:03:22 +0000 | [diff] [blame] | 1914 | unsigned SLocFileAbbrv = CreateSLocFileAbbrev(Stream); | 
|  | 1915 | unsigned SLocBufferAbbrv = CreateSLocBufferAbbrev(Stream); | 
| Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1916 | unsigned SLocBufferBlobAbbrv = CreateSLocBufferBlobAbbrev(Stream, false); | 
|  | 1917 | unsigned SLocBufferBlobCompressedAbbrv = | 
|  | 1918 | CreateSLocBufferBlobAbbrev(Stream, true); | 
| Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1919 | unsigned SLocExpansionAbbrv = CreateSLocExpansionAbbrev(Stream); | 
| Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 1920 |  | 
| Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1921 | // Write out the source location entry table. We skip the first | 
|  | 1922 | // entry, which is always the same dummy entry. | 
| Chris Lattner | 12d61d3 | 2009-04-27 19:01:47 +0000 | [diff] [blame] | 1923 | std::vector<uint32_t> SLocEntryOffsets; | 
| Dmitry Polukhin | a7afb21 | 2020-04-16 09:24:46 -0700 | [diff] [blame] | 1924 | uint64_t SLocEntryOffsetsBase = Stream.GetCurrentBitNo(); | 
| Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1925 | RecordData PreloadSLocs; | 
| Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1926 | SLocEntryOffsets.reserve(SourceMgr.local_sloc_entry_size() - 1); | 
|  | 1927 | for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size(); | 
| Sebastian Redl | 5c415f3 | 2010-07-22 17:01:13 +0000 | [diff] [blame] | 1928 | I != N; ++I) { | 
| Douglas Gregor | 8655e88 | 2009-10-16 22:46:09 +0000 | [diff] [blame] | 1929 | // Get this source location entry. | 
| Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1930 | const SrcMgr::SLocEntry *SLoc = &SourceMgr.getLocalSLocEntry(I); | 
| Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 1931 | FileID FID = FileID::get(I); | 
|  | 1932 | assert(&SourceMgr.getSLocEntry(FID) == SLoc); | 
| Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 1933 |  | 
| Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1934 | // Record the offset of this source-location entry. | 
| Dmitry Polukhin | a7afb21 | 2020-04-16 09:24:46 -0700 | [diff] [blame] | 1935 | uint64_t Offset = Stream.GetCurrentBitNo() - SLocEntryOffsetsBase; | 
|  | 1936 | assert((Offset >> 32) == 0 && "SLocEntry offset too large"); | 
|  | 1937 | SLocEntryOffsets.push_back(Offset); | 
| Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1938 |  | 
|  | 1939 | // Figure out which record code to use. | 
|  | 1940 | unsigned Code; | 
|  | 1941 | if (SLoc->isFile()) { | 
| Douglas Gregor | 9dc3212 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1942 | const SrcMgr::ContentCache *Cache = SLoc->getFile().getContentCache(); | 
|  | 1943 | if (Cache->OrigEntry) { | 
| Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1944 | Code = SM_SLOC_FILE_ENTRY; | 
| Argyrios Kyrtzidis | 92dd466 | 2011-06-02 20:01:46 +0000 | [diff] [blame] | 1945 | } else | 
| Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 1946 | Code = SM_SLOC_BUFFER_ENTRY; | 
| Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1947 | } else | 
| Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 1948 | Code = SM_SLOC_EXPANSION_ENTRY; | 
| Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1949 | Record.clear(); | 
|  | 1950 | Record.push_back(Code); | 
|  | 1951 |  | 
| Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 1952 | // Starting offset of this entry within this module, so skip the dummy. | 
|  | 1953 | Record.push_back(SLoc->getOffset() - 2); | 
| Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1954 | if (SLoc->isFile()) { | 
|  | 1955 | const SrcMgr::FileInfo &File = SLoc->getFile(); | 
| Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 1956 | AddSourceLocation(File.getIncludeLoc(), Record); | 
| Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1957 | Record.push_back(File.getFileCharacteristic()); // FIXME: stable encoding | 
|  | 1958 | Record.push_back(File.hasLineDirectives()); | 
|  | 1959 |  | 
|  | 1960 | const SrcMgr::ContentCache *Content = File.getContentCache(); | 
| Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1961 | bool EmitBlob = false; | 
| Argyrios Kyrtzidis | 11e6f0a | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 1962 | if (Content->OrigEntry) { | 
|  | 1963 | assert(Content->OrigEntry == Content->ContentsEntry && | 
| Douglas Gregor | 9dc3212 | 2011-11-16 20:05:18 +0000 | [diff] [blame] | 1964 | "Writing to AST an overridden file is not supported"); | 
| Argyrios Kyrtzidis | 11e6f0a | 2011-03-05 01:03:53 +0000 | [diff] [blame] | 1965 |  | 
| Douglas Gregor | 3120d2c | 2012-10-22 18:42:04 +0000 | [diff] [blame] | 1966 | // The source location entry is a file. Emit input file ID. | 
|  | 1967 | assert(InputFileIDs[Content->OrigEntry] != 0 && "Missed file entry"); | 
|  | 1968 | Record.push_back(InputFileIDs[Content->OrigEntry]); | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1969 |  | 
| Argyrios Kyrtzidis | 61ef3db | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 1970 | Record.push_back(File.NumCreatedFIDs); | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 1971 |  | 
| Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 1972 | FileDeclIDsTy::iterator FDI = FileDeclIDs.find(FID); | 
| Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 1973 | if (FDI != FileDeclIDs.end()) { | 
|  | 1974 | Record.push_back(FDI->second->FirstDeclIndex); | 
|  | 1975 | Record.push_back(FDI->second->DeclIDs.size()); | 
|  | 1976 | } else { | 
|  | 1977 | Record.push_back(0); | 
|  | 1978 | Record.push_back(0); | 
|  | 1979 | } | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 1980 |  | 
| Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1981 | Stream.EmitRecordWithAbbrev(SLocFileAbbrv, Record); | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 1982 |  | 
| Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1983 | if (Content->BufferOverridden || Content->IsTransient) | 
|  | 1984 | EmitBlob = true; | 
| Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1985 | } else { | 
|  | 1986 | // The source location entry is a buffer. The blob associated | 
|  | 1987 | // with this entry contains the contents of the buffer. | 
|  | 1988 |  | 
|  | 1989 | // We add one to the size so that we capture the trailing NULL | 
|  | 1990 | // that is required by llvm::MemoryBuffer::getMemBuffer (on | 
|  | 1991 | // the reader side). | 
| Duncan P. N. Exon Smith | f584819 | 2019-08-26 20:32:05 +0000 | [diff] [blame] | 1992 | const llvm::MemoryBuffer *Buffer = | 
|  | 1993 | Content->getBuffer(PP.getDiagnostics(), PP.getFileManager()); | 
| Mehdi Amini | 99d1b29 | 2016-10-01 16:38:28 +0000 | [diff] [blame] | 1994 | StringRef Name = Buffer->getBufferIdentifier(); | 
| Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 1995 | Stream.EmitRecordWithBlob(SLocBufferAbbrv, Record, | 
| Mehdi Amini | 99d1b29 | 2016-10-01 16:38:28 +0000 | [diff] [blame] | 1996 | StringRef(Name.data(), Name.size() + 1)); | 
| Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1997 | EmitBlob = true; | 
| Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 1998 |  | 
| Mehdi Amini | 99d1b29 | 2016-10-01 16:38:28 +0000 | [diff] [blame] | 1999 | if (Name == "<built-in>") | 
| Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2000 | PreloadSLocs.push_back(SLocEntryOffsets.size()); | 
| Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2001 | } | 
| Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 2002 |  | 
|  | 2003 | if (EmitBlob) { | 
|  | 2004 | // Include the implicit terminating null character in the on-disk buffer | 
|  | 2005 | // if we're writing it uncompressed. | 
|  | 2006 | const llvm::MemoryBuffer *Buffer = | 
| Duncan P. N. Exon Smith | f584819 | 2019-08-26 20:32:05 +0000 | [diff] [blame] | 2007 | Content->getBuffer(PP.getDiagnostics(), PP.getFileManager()); | 
| Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 2008 | StringRef Blob(Buffer->getBufferStart(), Buffer->getBufferSize() + 1); | 
| George Rimar | c39f549 | 2017-01-17 15:45:31 +0000 | [diff] [blame] | 2009 | emitBlob(Stream, Blob, SLocBufferBlobCompressedAbbrv, | 
|  | 2010 | SLocBufferBlobAbbrv); | 
| Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 2011 | } | 
| Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2012 | } else { | 
| Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 2013 | // The source location entry is a macro expansion. | 
| Chandler Carruth | ee4c1d1 | 2011-07-26 04:56:51 +0000 | [diff] [blame] | 2014 | const SrcMgr::ExpansionInfo &Expansion = SLoc->getExpansion(); | 
| Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 2015 | AddSourceLocation(Expansion.getSpellingLoc(), Record); | 
|  | 2016 | AddSourceLocation(Expansion.getExpansionLocStart(), Record); | 
|  | 2017 | AddSourceLocation(Expansion.isMacroArgExpansion() | 
|  | 2018 | ? SourceLocation() | 
|  | 2019 | : Expansion.getExpansionLocEnd(), | 
|  | 2020 | Record); | 
| Richard Smith | b5f8171 | 2018-04-30 05:25:48 +0000 | [diff] [blame] | 2021 | Record.push_back(Expansion.isExpansionTokenRange()); | 
| Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2022 |  | 
|  | 2023 | // Compute the token length for this macro expansion. | 
| Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2024 | unsigned NextOffset = SourceMgr.getNextLocalOffset(); | 
| Douglas Gregor | 8655e88 | 2009-10-16 22:46:09 +0000 | [diff] [blame] | 2025 | if (I + 1 != N) | 
| Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2026 | NextOffset = SourceMgr.getLocalSLocEntry(I + 1).getOffset(); | 
| Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2027 | Record.push_back(NextOffset - SLoc->getOffset() - 1); | 
| Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 2028 | Stream.EmitRecordWithAbbrev(SLocExpansionAbbrv, Record); | 
| Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2029 | } | 
|  | 2030 | } | 
|  | 2031 |  | 
| Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2032 | Stream.ExitBlock(); | 
| Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2033 |  | 
|  | 2034 | if (SLocEntryOffsets.empty()) | 
|  | 2035 | return; | 
|  | 2036 |  | 
| Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2037 | // Write the source-location offsets table into the AST block. This | 
| Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2038 | // table is used for lazily loading source-location information. | 
|  | 2039 | using namespace llvm; | 
| Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2040 |  | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2041 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); | 
| Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2042 | Abbrev->Add(BitCodeAbbrevOp(SOURCE_LOCATION_OFFSETS)); | 
| Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2043 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // # of slocs | 
| Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2044 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 16)); // total size | 
| Dmitry Polukhin | a7afb21 | 2020-04-16 09:24:46 -0700 | [diff] [blame] | 2045 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 32)); // base offset | 
| Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2046 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // offsets | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2047 | unsigned SLocOffsetsAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2048 | { | 
|  | 2049 | RecordData::value_type Record[] = { | 
|  | 2050 | SOURCE_LOCATION_OFFSETS, SLocEntryOffsets.size(), | 
| Dmitry Polukhin | a7afb21 | 2020-04-16 09:24:46 -0700 | [diff] [blame] | 2051 | SourceMgr.getNextLocalOffset() - 1 /* skip dummy */, | 
|  | 2052 | SLocEntryOffsetsBase}; | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2053 | Stream.EmitRecordWithBlob(SLocOffsetsAbbrev, Record, | 
|  | 2054 | bytes(SLocEntryOffsets)); | 
|  | 2055 | } | 
| Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2056 | // Write the source location entry preloads array, telling the AST | 
| Douglas Gregor | 258ae54 | 2009-04-27 06:38:32 +0000 | [diff] [blame] | 2057 | // reader which source locations entries it should load eagerly. | 
| Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2058 | Stream.EmitRecord(SOURCE_LOCATION_PRELOADS, PreloadSLocs); | 
| Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2059 |  | 
|  | 2060 | // Write the line table. It depends on remapping working, so it must come | 
|  | 2061 | // after the source location offsets. | 
|  | 2062 | if (SourceMgr.hasLineTable()) { | 
|  | 2063 | LineTableInfo &LineTable = SourceMgr.getLineTable(); | 
|  | 2064 |  | 
|  | 2065 | Record.clear(); | 
| Richard Smith | 6307849 | 2015-09-01 07:41:55 +0000 | [diff] [blame] | 2066 |  | 
|  | 2067 | // Emit the needed file names. | 
|  | 2068 | llvm::DenseMap<int, int> FilenameMap; | 
| Hans Wennborg | 1448736 | 2017-12-04 22:28:45 +0000 | [diff] [blame] | 2069 | FilenameMap[-1] = -1; // For unspecified filenames. | 
| Richard Smith | 6307849 | 2015-09-01 07:41:55 +0000 | [diff] [blame] | 2070 | for (const auto &L : LineTable) { | 
|  | 2071 | if (L.first.ID < 0) | 
|  | 2072 | continue; | 
|  | 2073 | for (auto &LE : L.second) { | 
|  | 2074 | if (FilenameMap.insert(std::make_pair(LE.FilenameID, | 
| Hans Wennborg | 1448736 | 2017-12-04 22:28:45 +0000 | [diff] [blame] | 2075 | FilenameMap.size() - 1)).second) | 
| Richard Smith | 6307849 | 2015-09-01 07:41:55 +0000 | [diff] [blame] | 2076 | AddPath(LineTable.getFilename(LE.FilenameID), Record); | 
|  | 2077 | } | 
|  | 2078 | } | 
|  | 2079 | Record.push_back(0); | 
| Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2080 |  | 
|  | 2081 | // Emit the line entries | 
| Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2082 | for (const auto &L : LineTable) { | 
| Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2083 | // Only emit entries for local files. | 
| Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2084 | if (L.first.ID < 0) | 
| Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2085 | continue; | 
|  | 2086 |  | 
|  | 2087 | // Emit the file ID | 
| Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2088 | Record.push_back(L.first.ID); | 
| Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2089 |  | 
|  | 2090 | // Emit the line entries | 
| Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2091 | Record.push_back(L.second.size()); | 
|  | 2092 | for (const auto &LE : L.second) { | 
|  | 2093 | Record.push_back(LE.FileOffset); | 
|  | 2094 | Record.push_back(LE.LineNo); | 
|  | 2095 | Record.push_back(FilenameMap[LE.FilenameID]); | 
|  | 2096 | Record.push_back((unsigned)LE.FileKind); | 
|  | 2097 | Record.push_back(LE.IncludeOffset); | 
| Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2098 | } | 
|  | 2099 | } | 
| Richard Smith | 6307849 | 2015-09-01 07:41:55 +0000 | [diff] [blame] | 2100 |  | 
| Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 2101 | Stream.EmitRecord(SOURCE_MANAGER_LINE_TABLE, Record); | 
|  | 2102 | } | 
| Douglas Gregor | a7f71a9 | 2009-04-10 03:52:48 +0000 | [diff] [blame] | 2103 | } | 
|  | 2104 |  | 
| Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2105 | //===----------------------------------------------------------------------===// | 
|  | 2106 | // Preprocessor Serialization | 
|  | 2107 | //===----------------------------------------------------------------------===// | 
|  | 2108 |  | 
| Argyrios Kyrtzidis | 0aef0f0 | 2013-03-15 22:43:10 +0000 | [diff] [blame] | 2109 | static bool shouldIgnoreMacro(MacroDirective *MD, bool IsModule, | 
|  | 2110 | const Preprocessor &PP) { | 
| Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 2111 | if (MacroInfo *MI = MD->getMacroInfo()) | 
|  | 2112 | if (MI->isBuiltinMacro()) | 
|  | 2113 | return true; | 
| Argyrios Kyrtzidis | 0aef0f0 | 2013-03-15 22:43:10 +0000 | [diff] [blame] | 2114 |  | 
|  | 2115 | if (IsModule) { | 
|  | 2116 | SourceLocation Loc = MD->getLocation(); | 
|  | 2117 | if (Loc.isInvalid()) | 
|  | 2118 | return true; | 
|  | 2119 | if (PP.getSourceManager().getFileID(Loc) == PP.getPredefinesFileID()) | 
|  | 2120 | return true; | 
|  | 2121 | } | 
|  | 2122 |  | 
|  | 2123 | return false; | 
|  | 2124 | } | 
|  | 2125 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2126 | /// Writes the block containing the serialized form of the | 
| Chris Lattner | eeffaef | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 2127 | /// preprocessor. | 
| Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 2128 | void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) { | 
| Dmitry Polukhin | a7afb21 | 2020-04-16 09:24:46 -0700 | [diff] [blame] | 2129 | uint64_t MacroOffsetsBase = Stream.GetCurrentBitNo(); | 
|  | 2130 |  | 
| Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2131 | PreprocessingRecord *PPRec = PP.getPreprocessingRecord(); | 
|  | 2132 | if (PPRec) | 
| Dmitry Polukhin | a7afb21 | 2020-04-16 09:24:46 -0700 | [diff] [blame] | 2133 | WritePreprocessorDetail(*PPRec, MacroOffsetsBase); | 
| Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2134 |  | 
| Chris Lattner | baa52f4 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 2135 | RecordData Record; | 
| Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2136 | RecordData ModuleMacroRecord; | 
| Chris Lattner | 0910e3b | 2009-04-10 17:16:57 +0000 | [diff] [blame] | 2137 |  | 
| Chris Lattner | 0af3ba1 | 2009-04-13 01:29:17 +0000 | [diff] [blame] | 2138 | // If the preprocessor __COUNTER__ value has been bumped, remember it. | 
|  | 2139 | if (PP.getCounterValue() != 0) { | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2140 | RecordData::value_type Record[] = {PP.getCounterValue()}; | 
| Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2141 | Stream.EmitRecord(PP_COUNTER_VALUE, Record); | 
| Douglas Gregor | eda6a89 | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2142 | } | 
|  | 2143 |  | 
| Erik Verbruggen | b34c79f | 2017-05-30 11:54:55 +0000 | [diff] [blame] | 2144 | if (PP.isRecordingPreamble() && PP.hasRecordedPreamble()) { | 
|  | 2145 | assert(!IsModule); | 
| Erik Verbruggen | 4d1eb2d | 2017-11-03 09:40:07 +0000 | [diff] [blame] | 2146 | auto SkipInfo = PP.getPreambleSkipInfo(); | 
|  | 2147 | if (SkipInfo.hasValue()) { | 
|  | 2148 | Record.push_back(true); | 
|  | 2149 | AddSourceLocation(SkipInfo->HashTokenLoc, Record); | 
|  | 2150 | AddSourceLocation(SkipInfo->IfTokenLoc, Record); | 
|  | 2151 | Record.push_back(SkipInfo->FoundNonSkipPortion); | 
|  | 2152 | Record.push_back(SkipInfo->FoundElse); | 
|  | 2153 | AddSourceLocation(SkipInfo->ElseLoc, Record); | 
|  | 2154 | } else { | 
|  | 2155 | Record.push_back(false); | 
|  | 2156 | } | 
| Erik Verbruggen | b34c79f | 2017-05-30 11:54:55 +0000 | [diff] [blame] | 2157 | for (const auto &Cond : PP.getPreambleConditionalStack()) { | 
|  | 2158 | AddSourceLocation(Cond.IfLoc, Record); | 
|  | 2159 | Record.push_back(Cond.WasSkipping); | 
|  | 2160 | Record.push_back(Cond.FoundNonSkip); | 
|  | 2161 | Record.push_back(Cond.FoundElse); | 
|  | 2162 | } | 
|  | 2163 | Stream.EmitRecord(PP_CONDITIONAL_STACK, Record); | 
|  | 2164 | Record.clear(); | 
|  | 2165 | } | 
|  | 2166 |  | 
| Douglas Gregor | eda6a89 | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2167 | // Enter the preprocessor block. | 
| Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 2168 | Stream.EnterSubblock(PREPROCESSOR_BLOCK_ID, 3); | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2169 |  | 
| Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2170 | // If the AST file contains __DATE__ or __TIME__ emit a warning about this. | 
| Richard Smith | b5aaf5a | 2015-09-01 02:35:58 +0000 | [diff] [blame] | 2171 | // FIXME: Include a location for the use, and say which one was used. | 
| Douglas Gregor | eda6a89 | 2009-04-26 00:07:37 +0000 | [diff] [blame] | 2172 | if (PP.SawDateOrTime()) | 
| Richard Smith | b5aaf5a | 2015-09-01 02:35:58 +0000 | [diff] [blame] | 2173 | PP.Diag(SourceLocation(), diag::warn_module_uses_date_time) << IsModule; | 
| Douglas Gregor | 796d76a | 2010-10-20 22:00:55 +0000 | [diff] [blame] | 2174 |  | 
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2175 | // Loop over all the macro directives that are live at the end of the file, | 
| Chris Lattner | baa52f4 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 2176 | // emitting each to the PP section. | 
| Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2177 |  | 
| Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2178 | // Construct the list of identifiers with macro directives that need to be | 
|  | 2179 | // serialized. | 
|  | 2180 | SmallVector<const IdentifierInfo *, 128> MacroIdentifiers; | 
|  | 2181 | for (auto &Id : PP.getIdentifierTable()) | 
|  | 2182 | if (Id.second->hadMacroDefinition() && | 
|  | 2183 | (!Id.second->isFromAST() || | 
|  | 2184 | Id.second->hasChangedSinceDeserialization())) | 
|  | 2185 | MacroIdentifiers.push_back(Id.second); | 
| Douglas Gregor | 2e5571d | 2011-02-10 18:20:09 +0000 | [diff] [blame] | 2186 | // Sort the set of macro definitions that need to be serialized by the | 
|  | 2187 | // name of the macro, to provide a stable ordering. | 
| Benjamin Kramer | cd2bae3 | 2019-08-22 17:32:16 +0000 | [diff] [blame] | 2188 | llvm::sort(MacroIdentifiers, llvm::deref<std::less<>>()); | 
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2189 |  | 
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2190 | // Emit the macro directives as a list and associate the offset with the | 
|  | 2191 | // identifier they belong to. | 
| Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2192 | for (const IdentifierInfo *Name : MacroIdentifiers) { | 
|  | 2193 | MacroDirective *MD = PP.getLocalMacroDirectiveHistory(Name); | 
| Dmitry Polukhin | a7afb21 | 2020-04-16 09:24:46 -0700 | [diff] [blame] | 2194 | uint64_t StartOffset = Stream.GetCurrentBitNo() - MacroOffsetsBase; | 
|  | 2195 | assert((StartOffset >> 32) == 0 && "Macro identifiers offset too large"); | 
| Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2196 |  | 
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2197 | // Emit the macro directives in reverse source order. | 
|  | 2198 | for (; MD; MD = MD->getPrevious()) { | 
| Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2199 | // Once we hit an ignored macro, we're done: the rest of the chain | 
|  | 2200 | // will all be ignored macros. | 
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2201 | if (shouldIgnoreMacro(MD, IsModule, PP)) | 
| Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2202 | break; | 
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2203 |  | 
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2204 | AddSourceLocation(MD->getLocation(), Record); | 
| Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 2205 | Record.push_back(MD->getKind()); | 
| Richard Smith | daa69e0 | 2014-07-25 04:40:03 +0000 | [diff] [blame] | 2206 | if (auto *DefMD = dyn_cast<DefMacroDirective>(MD)) { | 
| Richard Smith | 3981b17 | 2015-04-30 02:16:23 +0000 | [diff] [blame] | 2207 | Record.push_back(getMacroRef(DefMD->getInfo(), Name)); | 
| Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 2208 | } else if (auto *VisMD = dyn_cast<VisibilityMacroDirective>(MD)) { | 
| Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 2209 | Record.push_back(VisMD->isPublic()); | 
|  | 2210 | } | 
| Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 2211 | } | 
| Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2212 |  | 
| Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 2213 | // Write out any exported module macros. | 
| Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2214 | bool EmittedModuleMacros = false; | 
| Manman Ren | 33d8029 | 2016-05-31 18:19:32 +0000 | [diff] [blame] | 2215 | // We write out exported module macros for PCH as well. | 
|  | 2216 | auto Leafs = PP.getLeafModuleMacros(Name); | 
|  | 2217 | SmallVector<ModuleMacro*, 8> Worklist(Leafs.begin(), Leafs.end()); | 
|  | 2218 | llvm::DenseMap<ModuleMacro*, unsigned> Visits; | 
|  | 2219 | while (!Worklist.empty()) { | 
|  | 2220 | auto *Macro = Worklist.pop_back_val(); | 
| Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2221 |  | 
| Manman Ren | 33d8029 | 2016-05-31 18:19:32 +0000 | [diff] [blame] | 2222 | // Emit a record indicating this submodule exports this macro. | 
|  | 2223 | ModuleMacroRecord.push_back( | 
|  | 2224 | getSubmoduleID(Macro->getOwningModule())); | 
|  | 2225 | ModuleMacroRecord.push_back(getMacroRef(Macro->getMacroInfo(), Name)); | 
|  | 2226 | for (auto *M : Macro->overrides()) | 
|  | 2227 | ModuleMacroRecord.push_back(getSubmoduleID(M->getOwningModule())); | 
| Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2228 |  | 
| Manman Ren | 33d8029 | 2016-05-31 18:19:32 +0000 | [diff] [blame] | 2229 | Stream.EmitRecord(PP_MODULE_MACRO, ModuleMacroRecord); | 
|  | 2230 | ModuleMacroRecord.clear(); | 
| Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2231 |  | 
| Manman Ren | 33d8029 | 2016-05-31 18:19:32 +0000 | [diff] [blame] | 2232 | // Enqueue overridden macros once we've visited all their ancestors. | 
|  | 2233 | for (auto *M : Macro->overrides()) | 
|  | 2234 | if (++Visits[M] == M->getNumOverridingMacros()) | 
|  | 2235 | Worklist.push_back(M); | 
| Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2236 |  | 
| Manman Ren | 33d8029 | 2016-05-31 18:19:32 +0000 | [diff] [blame] | 2237 | EmittedModuleMacros = true; | 
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2238 | } | 
| Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2239 |  | 
| Richard Smith | ee97793 | 2015-05-01 21:22:17 +0000 | [diff] [blame] | 2240 | if (Record.empty() && !EmittedModuleMacros) | 
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2241 | continue; | 
|  | 2242 |  | 
| Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2243 | IdentMacroDirectivesOffsetMap[Name] = StartOffset; | 
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2244 | Stream.EmitRecord(PP_MACRO_DIRECTIVE_HISTORY, Record); | 
|  | 2245 | Record.clear(); | 
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2246 | } | 
| Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 2247 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2248 | /// Offsets of each of the macros into the bitstream, indexed by | 
| Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2249 | /// the local macro ID | 
|  | 2250 | /// | 
|  | 2251 | /// For each identifier that is associated with a macro, this map | 
|  | 2252 | /// provides the offset into the bitstream where that macro is | 
|  | 2253 | /// defined. | 
|  | 2254 | std::vector<uint32_t> MacroOffsets; | 
|  | 2255 |  | 
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2256 | for (unsigned I = 0, N = MacroInfosToEmit.size(); I != N; ++I) { | 
|  | 2257 | const IdentifierInfo *Name = MacroInfosToEmit[I].Name; | 
|  | 2258 | MacroInfo *MI = MacroInfosToEmit[I].MI; | 
|  | 2259 | MacroID ID = MacroInfosToEmit[I].ID; | 
| Douglas Gregor | eb114da | 2010-10-01 01:03:07 +0000 | [diff] [blame] | 2260 |  | 
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2261 | if (ID < FirstMacroID) { | 
|  | 2262 | assert(0 && "Loaded MacroInfo entered MacroInfosToEmit ?"); | 
|  | 2263 | continue; | 
| Chris Lattner | 2199f5b | 2009-04-10 18:08:30 +0000 | [diff] [blame] | 2264 | } | 
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2265 |  | 
|  | 2266 | // Record the local offset of this macro. | 
|  | 2267 | unsigned Index = ID - FirstMacroID; | 
| Dmitry Polukhin | a7afb21 | 2020-04-16 09:24:46 -0700 | [diff] [blame] | 2268 | if (Index >= MacroOffsets.size()) | 
|  | 2269 | MacroOffsets.resize(Index + 1); | 
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2270 |  | 
| Dmitry Polukhin | a7afb21 | 2020-04-16 09:24:46 -0700 | [diff] [blame] | 2271 | uint64_t Offset = Stream.GetCurrentBitNo() - MacroOffsetsBase; | 
|  | 2272 | assert((Offset >> 32) == 0 && "Macro offset too large"); | 
|  | 2273 | MacroOffsets[Index] = Offset; | 
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2274 |  | 
|  | 2275 | AddIdentifierRef(Name, Record); | 
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2276 | AddSourceLocation(MI->getDefinitionLoc(), Record); | 
|  | 2277 | AddSourceLocation(MI->getDefinitionEndLoc(), Record); | 
|  | 2278 | Record.push_back(MI->isUsed()); | 
| Argyrios Kyrtzidis | 9ef53ce | 2014-04-09 18:21:23 +0000 | [diff] [blame] | 2279 | Record.push_back(MI->isUsedForHeaderGuard()); | 
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2280 | unsigned Code; | 
|  | 2281 | if (MI->isObjectLike()) { | 
|  | 2282 | Code = PP_MACRO_OBJECT_LIKE; | 
|  | 2283 | } else { | 
|  | 2284 | Code = PP_MACRO_FUNCTION_LIKE; | 
|  | 2285 |  | 
|  | 2286 | Record.push_back(MI->isC99Varargs()); | 
|  | 2287 | Record.push_back(MI->isGNUVarargs()); | 
|  | 2288 | Record.push_back(MI->hasCommaPasting()); | 
| Faisal Vali | ac506d7 | 2017-07-17 17:18:43 +0000 | [diff] [blame] | 2289 | Record.push_back(MI->getNumParams()); | 
|  | 2290 | for (const IdentifierInfo *Param : MI->params()) | 
|  | 2291 | AddIdentifierRef(Param, Record); | 
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2292 | } | 
|  | 2293 |  | 
|  | 2294 | // If we have a detailed preprocessing record, record the macro definition | 
|  | 2295 | // ID that corresponds to this macro. | 
|  | 2296 | if (PPRec) | 
|  | 2297 | Record.push_back(MacroDefinitions[PPRec->findMacroDefinition(MI)]); | 
|  | 2298 |  | 
|  | 2299 | Stream.EmitRecord(Code, Record); | 
|  | 2300 | Record.clear(); | 
|  | 2301 |  | 
|  | 2302 | // Emit the tokens array. | 
|  | 2303 | for (unsigned TokNo = 0, e = MI->getNumTokens(); TokNo != e; ++TokNo) { | 
|  | 2304 | // Note that we know that the preprocessor does not have any annotation | 
|  | 2305 | // tokens in it because they are created by the parser, and thus can't | 
|  | 2306 | // be in a macro definition. | 
|  | 2307 | const Token &Tok = MI->getReplacementToken(TokNo); | 
| John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 2308 | AddToken(Tok, Record); | 
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2309 | Stream.EmitRecord(PP_TOKEN, Record); | 
|  | 2310 | Record.clear(); | 
|  | 2311 | } | 
|  | 2312 | ++NumMacros; | 
| Chris Lattner | baa52f4 | 2009-04-10 18:00:12 +0000 | [diff] [blame] | 2313 | } | 
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2314 |  | 
| Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2315 | Stream.ExitBlock(); | 
| Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2316 |  | 
|  | 2317 | // Write the offsets table for macro IDs. | 
|  | 2318 | using namespace llvm; | 
| Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2319 |  | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2320 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); | 
| Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2321 | Abbrev->Add(BitCodeAbbrevOp(MACRO_OFFSET)); | 
|  | 2322 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of macros | 
|  | 2323 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID | 
| Dmitry Polukhin | a7afb21 | 2020-04-16 09:24:46 -0700 | [diff] [blame] | 2324 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 32));   // base offset | 
| Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 2325 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); | 
|  | 2326 |  | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2327 | unsigned MacroOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2328 | { | 
|  | 2329 | RecordData::value_type Record[] = {MACRO_OFFSET, MacroOffsets.size(), | 
| Dmitry Polukhin | a7afb21 | 2020-04-16 09:24:46 -0700 | [diff] [blame] | 2330 | FirstMacroID - NUM_PREDEF_MACRO_IDS, | 
|  | 2331 | MacroOffsetsBase}; | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2332 | Stream.EmitRecordWithBlob(MacroOffsetAbbrev, Record, bytes(MacroOffsets)); | 
|  | 2333 | } | 
| Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2334 | } | 
|  | 2335 |  | 
| Dmitry Polukhin | a7afb21 | 2020-04-16 09:24:46 -0700 | [diff] [blame] | 2336 | void ASTWriter::WritePreprocessorDetail(PreprocessingRecord &PPRec, | 
|  | 2337 | uint64_t MacroOffsetsBase) { | 
| Argyrios Kyrtzidis | 7f44836 | 2011-09-19 20:40:42 +0000 | [diff] [blame] | 2338 | if (PPRec.local_begin() == PPRec.local_end()) | 
| Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2339 | return; | 
| Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2340 |  | 
| Argyrios Kyrtzidis | 64f6381 | 2011-09-19 20:40:25 +0000 | [diff] [blame] | 2341 | SmallVector<PPEntityOffset, 64> PreprocessedEntityOffsets; | 
| Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2342 |  | 
| Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2343 | // Enter the preprocessor block. | 
|  | 2344 | Stream.EnterSubblock(PREPROCESSOR_DETAIL_BLOCK_ID, 3); | 
| Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2345 |  | 
| Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2346 | // If the preprocessor has a preprocessing record, emit it. | 
|  | 2347 | unsigned NumPreprocessingRecords = 0; | 
| Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2348 | using namespace llvm; | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2349 |  | 
|  | 2350 | // Set up the abbreviation for | 
| Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2351 | unsigned InclusionAbbrev = 0; | 
|  | 2352 | { | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2353 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); | 
| Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2354 | Abbrev->Add(BitCodeAbbrevOp(PPD_INCLUSION_DIRECTIVE)); | 
| Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2355 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // filename length | 
|  | 2356 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // in quotes | 
|  | 2357 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // kind | 
| Argyrios Kyrtzidis | f590e09 | 2012-10-02 16:10:46 +0000 | [diff] [blame] | 2358 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // imported module | 
| Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2359 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2360 | InclusionAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); | 
| Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2361 | } | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2362 |  | 
|  | 2363 | unsigned FirstPreprocessorEntityID | 
|  | 2364 | = (Chain ? PPRec.getNumLoadedPreprocessedEntities() : 0) | 
| Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2365 | + NUM_PREDEF_PP_ENTITY_IDS; | 
|  | 2366 | unsigned NextPreprocessorEntityID = FirstPreprocessorEntityID; | 
| Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2367 | RecordData Record; | 
| Argyrios Kyrtzidis | 7f44836 | 2011-09-19 20:40:42 +0000 | [diff] [blame] | 2368 | for (PreprocessingRecord::iterator E = PPRec.local_begin(), | 
|  | 2369 | EEnd = PPRec.local_end(); | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2370 | E != EEnd; | 
| Douglas Gregor | 0d4b431 | 2011-08-04 17:06:18 +0000 | [diff] [blame] | 2371 | (void)++E, ++NumPreprocessingRecords, ++NextPreprocessorEntityID) { | 
| Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2372 | Record.clear(); | 
| Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2373 |  | 
| Dmitry Polukhin | a7afb21 | 2020-04-16 09:24:46 -0700 | [diff] [blame] | 2374 | uint64_t Offset = Stream.GetCurrentBitNo() - MacroOffsetsBase; | 
|  | 2375 | assert((Offset >> 32) == 0 && "Preprocessed entity offset too large"); | 
| Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 2376 | PreprocessedEntityOffsets.push_back( | 
| Dmitry Polukhin | a7afb21 | 2020-04-16 09:24:46 -0700 | [diff] [blame] | 2377 | PPEntityOffset((*E)->getSourceRange(), Offset)); | 
| Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2378 |  | 
| Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2379 | if (auto *MD = dyn_cast<MacroDefinitionRecord>(*E)) { | 
| Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2380 | // Record this macro definition's ID. | 
|  | 2381 | MacroDefinitions[MD] = NextPreprocessorEntityID; | 
| Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 2382 |  | 
| Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2383 | AddIdentifierRef(MD->getName(), Record); | 
| Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2384 | Stream.EmitRecord(PPD_MACRO_DEFINITION, Record); | 
|  | 2385 | continue; | 
| Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2386 | } | 
| Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2387 |  | 
| Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2388 | if (auto *ME = dyn_cast<MacroExpansion>(*E)) { | 
| Argyrios Kyrtzidis | 80f78b9 | 2011-09-08 17:18:41 +0000 | [diff] [blame] | 2389 | Record.push_back(ME->isBuiltinMacro()); | 
|  | 2390 | if (ME->isBuiltinMacro()) | 
|  | 2391 | AddIdentifierRef(ME->getName(), Record); | 
|  | 2392 | else | 
| Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2393 | Record.push_back(MacroDefinitions[ME->getDefinition()]); | 
| Chandler Carruth | f92ac9e | 2011-07-15 07:25:21 +0000 | [diff] [blame] | 2394 | Stream.EmitRecord(PPD_MACRO_EXPANSION, Record); | 
| Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2395 | continue; | 
|  | 2396 | } | 
|  | 2397 |  | 
| Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2398 | if (auto *ID = dyn_cast<InclusionDirective>(*E)) { | 
| Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2399 | Record.push_back(PPD_INCLUSION_DIRECTIVE); | 
| Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2400 | Record.push_back(ID->getFileName().size()); | 
|  | 2401 | Record.push_back(ID->wasInQuotes()); | 
|  | 2402 | Record.push_back(static_cast<unsigned>(ID->getKind())); | 
| Argyrios Kyrtzidis | f590e09 | 2012-10-02 16:10:46 +0000 | [diff] [blame] | 2403 | Record.push_back(ID->importedModule()); | 
| Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 2404 | SmallString<64> Buffer; | 
| Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2405 | Buffer += ID->getFileName(); | 
| Argyrios Kyrtzidis | 8dbcfc3 | 2012-03-08 01:08:28 +0000 | [diff] [blame] | 2406 | // Check that the FileEntry is not null because it was not resolved and | 
|  | 2407 | // we create a PCH even with compiler errors. | 
|  | 2408 | if (ID->getFile()) | 
|  | 2409 | Buffer += ID->getFile()->getName(); | 
| Mehdi Amini | 5ae4a85 | 2015-09-09 20:35:37 +0000 | [diff] [blame] | 2410 | Stream.EmitRecordWithBlob(InclusionAbbrev, Record, Buffer); | 
| Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2411 | continue; | 
|  | 2412 | } | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2413 |  | 
| Douglas Gregor | 92a96f5 | 2011-02-08 21:58:10 +0000 | [diff] [blame] | 2414 | llvm_unreachable("Unhandled PreprocessedEntity in ASTWriter"); | 
|  | 2415 | } | 
| Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2416 | Stream.ExitBlock(); | 
| Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2417 |  | 
| Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2418 | // Write the offsets table for the preprocessing record. | 
|  | 2419 | if (NumPreprocessingRecords > 0) { | 
| Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2420 | assert(PreprocessedEntityOffsets.size() == NumPreprocessingRecords); | 
|  | 2421 |  | 
| Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2422 | // Write the offsets table for identifier IDs. | 
|  | 2423 | using namespace llvm; | 
| Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2424 |  | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2425 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); | 
| Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2426 | Abbrev->Add(BitCodeAbbrevOp(PPD_ENTITIES_OFFSETS)); | 
| Douglas Gregor | 2f555fc | 2011-08-04 18:56:47 +0000 | [diff] [blame] | 2427 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first pp entity | 
| Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2428 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2429 | unsigned PPEOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); | 
| Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 2430 |  | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2431 | RecordData::value_type Record[] = {PPD_ENTITIES_OFFSETS, | 
|  | 2432 | FirstPreprocessorEntityID - | 
|  | 2433 | NUM_PREDEF_PP_ENTITY_IDS}; | 
| Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 2434 | Stream.EmitRecordWithBlob(PPEOffsetAbbrev, Record, | 
| Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 2435 | bytes(PreprocessedEntityOffsets)); | 
| Douglas Gregor | aae9224 | 2010-03-19 21:51:54 +0000 | [diff] [blame] | 2436 | } | 
| Cameron Desrochers | b60f1b6 | 2018-01-15 19:14:16 +0000 | [diff] [blame] | 2437 |  | 
|  | 2438 | // Write the skipped region table for the preprocessing record. | 
|  | 2439 | ArrayRef<SourceRange> SkippedRanges = PPRec.getSkippedRanges(); | 
|  | 2440 | if (SkippedRanges.size() > 0) { | 
|  | 2441 | std::vector<PPSkippedRange> SerializedSkippedRanges; | 
|  | 2442 | SerializedSkippedRanges.reserve(SkippedRanges.size()); | 
|  | 2443 | for (auto const& Range : SkippedRanges) | 
|  | 2444 | SerializedSkippedRanges.emplace_back(Range); | 
|  | 2445 |  | 
|  | 2446 | using namespace llvm; | 
|  | 2447 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); | 
|  | 2448 | Abbrev->Add(BitCodeAbbrevOp(PPD_SKIPPED_RANGES)); | 
|  | 2449 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); | 
|  | 2450 | unsigned PPESkippedRangeAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); | 
|  | 2451 |  | 
|  | 2452 | Record.clear(); | 
|  | 2453 | Record.push_back(PPD_SKIPPED_RANGES); | 
|  | 2454 | Stream.EmitRecordWithBlob(PPESkippedRangeAbbrev, Record, | 
|  | 2455 | bytes(SerializedSkippedRanges)); | 
|  | 2456 | } | 
| Chris Lattner | eeffaef | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 2457 | } | 
|  | 2458 |  | 
| Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 2459 | unsigned ASTWriter::getLocalOrImportedSubmoduleID(Module *Mod) { | 
| Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2460 | if (!Mod) | 
|  | 2461 | return 0; | 
|  | 2462 |  | 
| Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2463 | llvm::DenseMap<Module *, unsigned>::iterator Known = SubmoduleIDs.find(Mod); | 
|  | 2464 | if (Known != SubmoduleIDs.end()) | 
|  | 2465 | return Known->second; | 
| Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 2466 |  | 
| Richard Smith | dc1f042 | 2016-07-20 19:10:16 +0000 | [diff] [blame] | 2467 | auto *Top = Mod->getTopLevelModule(); | 
|  | 2468 | if (Top != WritingModule && | 
| Bruno Cardoso Lopes | 17da34d | 2017-02-07 21:54:57 +0000 | [diff] [blame] | 2469 | (getLangOpts().CompilingPCH || | 
|  | 2470 | !Top->fullModuleNameIs(StringRef(getLangOpts().CurrentModule)))) | 
| Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 2471 | return 0; | 
|  | 2472 |  | 
| Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2473 | return SubmoduleIDs[Mod] = NextSubmoduleID++; | 
|  | 2474 | } | 
|  | 2475 |  | 
| Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 2476 | unsigned ASTWriter::getSubmoduleID(Module *Mod) { | 
|  | 2477 | // FIXME: This can easily happen, if we have a reference to a submodule that | 
|  | 2478 | // did not result in us loading a module file for that submodule. For | 
|  | 2479 | // instance, a cross-top-level-module 'conflict' declaration will hit this. | 
|  | 2480 | unsigned ID = getLocalOrImportedSubmoduleID(Mod); | 
|  | 2481 | assert((ID || !Mod) && | 
|  | 2482 | "asked for module ID for non-local, non-imported module"); | 
|  | 2483 | return ID; | 
| Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 2484 | } | 
|  | 2485 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2486 | /// Compute the number of modules within the given tree (including the | 
| Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2487 | /// given module). | 
|  | 2488 | static unsigned getNumberOfModules(Module *Mod) { | 
|  | 2489 | unsigned ChildModules = 0; | 
| Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2490 | for (auto Sub = Mod->submodule_begin(), SubEnd = Mod->submodule_end(); | 
| Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2491 | Sub != SubEnd; ++Sub) | 
| Douglas Gregor | eb90e83 | 2012-01-04 23:32:19 +0000 | [diff] [blame] | 2492 | ChildModules += getNumberOfModules(*Sub); | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2493 |  | 
| Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2494 | return ChildModules + 1; | 
|  | 2495 | } | 
|  | 2496 |  | 
| Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2497 | void ASTWriter::WriteSubmodules(Module *WritingModule) { | 
| Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2498 | // Enter the submodule description block. | 
| Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2499 | Stream.EnterSubblock(SUBMODULE_BLOCK_ID, /*bits for abbreviations*/5); | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2500 |  | 
| Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2501 | // Write the abbreviations needed for the submodules block. | 
|  | 2502 | using namespace llvm; | 
| Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2503 |  | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2504 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); | 
| Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2505 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_DEFINITION)); | 
| Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2506 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ID | 
| Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2507 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Parent | 
| Richard Smith | dd8b533 | 2017-09-04 05:37:53 +0000 | [diff] [blame] | 2508 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Kind | 
| Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2509 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFramework | 
|  | 2510 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsExplicit | 
| Richard Smith | 9bca298 | 2014-03-08 00:03:56 +0000 | [diff] [blame] | 2511 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsSystem | 
|  | 2512 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsExternC | 
| Douglas Gregor | a686e1b | 2012-01-27 19:52:33 +0000 | [diff] [blame] | 2513 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferSubmodules... | 
| Douglas Gregor | 7344109 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 2514 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferExplicit... | 
| Douglas Gregor | 7344109 | 2011-12-05 22:27:44 +0000 | [diff] [blame] | 2515 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InferExportWild... | 
| Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2516 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ConfigMacrosExh... | 
| Jordan Rose | 90b0a1f | 2018-04-20 17:16:04 +0000 | [diff] [blame] | 2517 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ModuleMapIsPriv... | 
| Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2518 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2519 | unsigned DefinitionAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); | 
| Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2520 |  | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2521 | Abbrev = std::make_shared<BitCodeAbbrev>(); | 
| Douglas Gregor | 524e33e | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2522 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_UMBRELLA_HEADER)); | 
| Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2523 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2524 | unsigned UmbrellaAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); | 
| Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2525 |  | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2526 | Abbrev = std::make_shared<BitCodeAbbrev>(); | 
| Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2527 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_HEADER)); | 
|  | 2528 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2529 | unsigned HeaderAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); | 
| Douglas Gregor | 524e33e | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2530 |  | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2531 | Abbrev = std::make_shared<BitCodeAbbrev>(); | 
| Argyrios Kyrtzidis | c597c8c | 2012-10-05 00:22:33 +0000 | [diff] [blame] | 2532 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_TOPHEADER)); | 
|  | 2533 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2534 | unsigned TopHeaderAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); | 
| Argyrios Kyrtzidis | c597c8c | 2012-10-05 00:22:33 +0000 | [diff] [blame] | 2535 |  | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2536 | Abbrev = std::make_shared<BitCodeAbbrev>(); | 
| Douglas Gregor | 524e33e | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2537 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_UMBRELLA_DIR)); | 
|  | 2538 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2539 | unsigned UmbrellaDirAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); | 
| Douglas Gregor | 524e33e | 2011-12-08 19:11:24 +0000 | [diff] [blame] | 2540 |  | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2541 | Abbrev = std::make_shared<BitCodeAbbrev>(); | 
| Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2542 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_REQUIRES)); | 
| Richard Smith | a3feee2 | 2013-10-28 22:18:19 +0000 | [diff] [blame] | 2543 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // State | 
|  | 2544 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));     // Feature | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2545 | unsigned RequiresAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); | 
| Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2546 |  | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2547 | Abbrev = std::make_shared<BitCodeAbbrev>(); | 
| Douglas Gregor | 5952766 | 2012-10-15 06:28:11 +0000 | [diff] [blame] | 2548 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_EXCLUDED_HEADER)); | 
|  | 2549 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2550 | unsigned ExcludedHeaderAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); | 
| Douglas Gregor | 5952766 | 2012-10-15 06:28:11 +0000 | [diff] [blame] | 2551 |  | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2552 | Abbrev = std::make_shared<BitCodeAbbrev>(); | 
| Richard Smith | 306d892 | 2014-10-22 23:50:56 +0000 | [diff] [blame] | 2553 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_TEXTUAL_HEADER)); | 
|  | 2554 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2555 | unsigned TextualHeaderAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); | 
| Richard Smith | 306d892 | 2014-10-22 23:50:56 +0000 | [diff] [blame] | 2556 |  | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2557 | Abbrev = std::make_shared<BitCodeAbbrev>(); | 
| Lawrence Crowl | b53e548 | 2013-06-20 21:14:14 +0000 | [diff] [blame] | 2558 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_PRIVATE_HEADER)); | 
|  | 2559 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2560 | unsigned PrivateHeaderAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); | 
| Lawrence Crowl | b53e548 | 2013-06-20 21:14:14 +0000 | [diff] [blame] | 2561 |  | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2562 | Abbrev = std::make_shared<BitCodeAbbrev>(); | 
| Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2563 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_PRIVATE_TEXTUAL_HEADER)); | 
|  | 2564 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Name | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2565 | unsigned PrivateTextualHeaderAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); | 
| Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2566 |  | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2567 | Abbrev = std::make_shared<BitCodeAbbrev>(); | 
| Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2568 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_LINK_LIBRARY)); | 
|  | 2569 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFramework | 
|  | 2570 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));     // Name | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2571 | unsigned LinkLibraryAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); | 
| Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2572 |  | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2573 | Abbrev = std::make_shared<BitCodeAbbrev>(); | 
| Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2574 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_CONFIG_MACRO)); | 
|  | 2575 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));    // Macro name | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2576 | unsigned ConfigMacroAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); | 
| Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2577 |  | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2578 | Abbrev = std::make_shared<BitCodeAbbrev>(); | 
| Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 2579 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_CONFLICT)); | 
|  | 2580 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));  // Other module | 
|  | 2581 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));    // Message | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2582 | unsigned ConflictAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); | 
| Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 2583 |  | 
| Douglas Gregor | f0b11de | 2017-09-14 23:38:44 +0000 | [diff] [blame] | 2584 | Abbrev = std::make_shared<BitCodeAbbrev>(); | 
|  | 2585 | Abbrev->Add(BitCodeAbbrevOp(SUBMODULE_EXPORT_AS)); | 
|  | 2586 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));    // Macro name | 
|  | 2587 | unsigned ExportAsAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); | 
|  | 2588 |  | 
| Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2589 | // Write the submodule metadata block. | 
| Richard Smith | 145e15a | 2017-04-24 23:12:30 +0000 | [diff] [blame] | 2590 | RecordData::value_type Record[] = { | 
|  | 2591 | getNumberOfModules(WritingModule), | 
| Richard Smith | dd8b533 | 2017-09-04 05:37:53 +0000 | [diff] [blame] | 2592 | FirstSubmoduleID - NUM_PREDEF_SUBMODULE_IDS}; | 
| Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 2593 | Stream.EmitRecord(SUBMODULE_METADATA, Record); | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2594 |  | 
| Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2595 | // Write all of the submodules. | 
| Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2596 | std::queue<Module *> Q; | 
| Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2597 | Q.push(WritingModule); | 
| Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2598 | while (!Q.empty()) { | 
| Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2599 | Module *Mod = Q.front(); | 
| Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2600 | Q.pop(); | 
| Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 2601 | unsigned ID = getSubmoduleID(Mod); | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2602 |  | 
|  | 2603 | uint64_t ParentID = 0; | 
| Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2604 | if (Mod->Parent) { | 
|  | 2605 | assert(SubmoduleIDs[Mod->Parent] && "Submodule parent not written?"); | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2606 | ParentID = SubmoduleIDs[Mod->Parent]; | 
| Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2607 | } | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2608 |  | 
|  | 2609 | // Emit the definition of the block. | 
|  | 2610 | { | 
| David Blaikie | 9ffe5a3 | 2017-01-30 05:00:26 +0000 | [diff] [blame] | 2611 | RecordData::value_type Record[] = {SUBMODULE_DEFINITION, | 
|  | 2612 | ID, | 
|  | 2613 | ParentID, | 
| Simon Pilgrim | f331a66 | 2017-09-04 10:54:39 +0000 | [diff] [blame] | 2614 | (RecordData::value_type)Mod->Kind, | 
| David Blaikie | 9ffe5a3 | 2017-01-30 05:00:26 +0000 | [diff] [blame] | 2615 | Mod->IsFramework, | 
|  | 2616 | Mod->IsExplicit, | 
|  | 2617 | Mod->IsSystem, | 
|  | 2618 | Mod->IsExternC, | 
|  | 2619 | Mod->InferSubmodules, | 
|  | 2620 | Mod->InferExplicitSubmodules, | 
|  | 2621 | Mod->InferExportWildcard, | 
| Jordan Rose | 90b0a1f | 2018-04-20 17:16:04 +0000 | [diff] [blame] | 2622 | Mod->ConfigMacrosExhaustive, | 
|  | 2623 | Mod->ModuleMapIsPrivate}; | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2624 | Stream.EmitRecordWithBlob(DefinitionAbbrev, Record, Mod->Name); | 
|  | 2625 | } | 
|  | 2626 |  | 
| Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2627 | // Emit the requirements. | 
| Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2628 | for (const auto &R : Mod->Requirements) { | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2629 | RecordData::value_type Record[] = {SUBMODULE_REQUIRES, R.second}; | 
| Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2630 | Stream.EmitRecordWithBlob(RequiresAbbrev, Record, R.first); | 
| Douglas Gregor | 1fb5c3a | 2011-12-31 04:05:44 +0000 | [diff] [blame] | 2631 | } | 
|  | 2632 |  | 
| Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2633 | // Emit the umbrella header, if there is one. | 
| Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 2634 | if (auto UmbrellaHeader = Mod->getUmbrellaHeader()) { | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2635 | RecordData::value_type Record[] = {SUBMODULE_UMBRELLA_HEADER}; | 
| Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 2636 | Stream.EmitRecordWithBlob(UmbrellaAbbrev, Record, | 
|  | 2637 | UmbrellaHeader.NameAsWritten); | 
|  | 2638 | } else if (auto UmbrellaDir = Mod->getUmbrellaDir()) { | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2639 | RecordData::value_type Record[] = {SUBMODULE_UMBRELLA_DIR}; | 
|  | 2640 | Stream.EmitRecordWithBlob(UmbrellaDirAbbrev, Record, | 
| Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 2641 | UmbrellaDir.NameAsWritten); | 
| Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2642 | } | 
| Richard Smith | 306d892 | 2014-10-22 23:50:56 +0000 | [diff] [blame] | 2643 |  | 
| Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2644 | // Emit the headers. | 
| Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2645 | struct { | 
| Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2646 | unsigned RecordKind; | 
| Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2647 | unsigned Abbrev; | 
| Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2648 | Module::HeaderKind HeaderKind; | 
| Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2649 | } HeaderLists[] = { | 
| Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2650 | {SUBMODULE_HEADER, HeaderAbbrev, Module::HK_Normal}, | 
|  | 2651 | {SUBMODULE_TEXTUAL_HEADER, TextualHeaderAbbrev, Module::HK_Textual}, | 
|  | 2652 | {SUBMODULE_PRIVATE_HEADER, PrivateHeaderAbbrev, Module::HK_Private}, | 
| Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2653 | {SUBMODULE_PRIVATE_TEXTUAL_HEADER, PrivateTextualHeaderAbbrev, | 
| Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2654 | Module::HK_PrivateTextual}, | 
|  | 2655 | {SUBMODULE_EXCLUDED_HEADER, ExcludedHeaderAbbrev, Module::HK_Excluded} | 
| Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 2656 | }; | 
|  | 2657 | for (auto &HL : HeaderLists) { | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2658 | RecordData::value_type Record[] = {HL.RecordKind}; | 
| Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2659 | for (auto &H : Mod->Headers[HL.HeaderKind]) | 
|  | 2660 | Stream.EmitRecordWithBlob(HL.Abbrev, Record, H.NameAsWritten); | 
|  | 2661 | } | 
|  | 2662 |  | 
|  | 2663 | // Emit the top headers. | 
|  | 2664 | { | 
|  | 2665 | auto TopHeaders = Mod->getTopHeaders(PP->getFileManager()); | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2666 | RecordData::value_type Record[] = {SUBMODULE_TOPHEADER}; | 
| Richard Smith | 3c1a41a | 2014-12-02 00:08:08 +0000 | [diff] [blame] | 2667 | for (auto *H : TopHeaders) | 
|  | 2668 | Stream.EmitRecordWithBlob(TopHeaderAbbrev, Record, H->getName()); | 
| Argyrios Kyrtzidis | c597c8c | 2012-10-05 00:22:33 +0000 | [diff] [blame] | 2669 | } | 
| Douglas Gregor | 0093b3c | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2670 |  | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2671 | // Emit the imports. | 
| Douglas Gregor | 0093b3c | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2672 | if (!Mod->Imports.empty()) { | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2673 | RecordData Record; | 
| Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2674 | for (auto *I : Mod->Imports) | 
|  | 2675 | Record.push_back(getSubmoduleID(I)); | 
| Douglas Gregor | 0093b3c | 2011-12-05 16:33:54 +0000 | [diff] [blame] | 2676 | Stream.EmitRecord(SUBMODULE_IMPORTS, Record); | 
|  | 2677 | } | 
|  | 2678 |  | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2679 | // Emit the exports. | 
| Douglas Gregor | 24bb923 | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2680 | if (!Mod->Exports.empty()) { | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2681 | RecordData Record; | 
| Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2682 | for (const auto &E : Mod->Exports) { | 
|  | 2683 | // FIXME: This may fail; we don't require that all exported modules | 
|  | 2684 | // are local or imported. | 
|  | 2685 | Record.push_back(getSubmoduleID(E.getPointer())); | 
|  | 2686 | Record.push_back(E.getInt()); | 
| Douglas Gregor | 24bb923 | 2011-12-02 18:58:38 +0000 | [diff] [blame] | 2687 | } | 
|  | 2688 | Stream.EmitRecord(SUBMODULE_EXPORTS, Record); | 
|  | 2689 | } | 
| Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2690 |  | 
| Daniel Jasper | ba7f2f7 | 2013-09-24 09:14:14 +0000 | [diff] [blame] | 2691 | //FIXME: How do we emit the 'use'd modules?  They may not be submodules. | 
|  | 2692 | // Might be unnecessary as use declarations are only used to build the | 
|  | 2693 | // module itself. | 
|  | 2694 |  | 
| Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2695 | // Emit the link libraries. | 
| Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2696 | for (const auto &LL : Mod->LinkLibraries) { | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2697 | RecordData::value_type Record[] = {SUBMODULE_LINK_LIBRARY, | 
|  | 2698 | LL.IsFramework}; | 
| Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2699 | Stream.EmitRecordWithBlob(LinkLibraryAbbrev, Record, LL.Library); | 
| Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 2700 | } | 
|  | 2701 |  | 
| Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 2702 | // Emit the conflicts. | 
| Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2703 | for (const auto &C : Mod->Conflicts) { | 
| Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2704 | // FIXME: This may fail; we don't require that all conflicting modules | 
|  | 2705 | // are local or imported. | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2706 | RecordData::value_type Record[] = {SUBMODULE_CONFLICT, | 
|  | 2707 | getSubmoduleID(C.Other)}; | 
| Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2708 | Stream.EmitRecordWithBlob(ConflictAbbrev, Record, C.Message); | 
| Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 2709 | } | 
|  | 2710 |  | 
| Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2711 | // Emit the configuration macros. | 
| Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2712 | for (const auto &CM : Mod->ConfigMacros) { | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2713 | RecordData::value_type Record[] = {SUBMODULE_CONFIG_MACRO}; | 
| Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2714 | Stream.EmitRecordWithBlob(ConfigMacroAbbrev, Record, CM); | 
| Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 2715 | } | 
|  | 2716 |  | 
| Richard Smith | dc1f042 | 2016-07-20 19:10:16 +0000 | [diff] [blame] | 2717 | // Emit the initializers, if any. | 
|  | 2718 | RecordData Inits; | 
|  | 2719 | for (Decl *D : Context->getModuleInitializers(Mod)) | 
|  | 2720 | Inits.push_back(GetDeclRef(D)); | 
|  | 2721 | if (!Inits.empty()) | 
|  | 2722 | Stream.EmitRecord(SUBMODULE_INITIALIZERS, Inits); | 
|  | 2723 |  | 
| Douglas Gregor | f0b11de | 2017-09-14 23:38:44 +0000 | [diff] [blame] | 2724 | // Emit the name of the re-exported module, if any. | 
|  | 2725 | if (!Mod->ExportAsModule.empty()) { | 
|  | 2726 | RecordData::value_type Record[] = {SUBMODULE_EXPORT_AS}; | 
|  | 2727 | Stream.EmitRecordWithBlob(ExportAsAbbrev, Record, Mod->ExportAsModule); | 
|  | 2728 | } | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2729 |  | 
| Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2730 | // Queue up the submodules of this module. | 
| Richard Smith | 080056b | 2015-08-18 21:53:42 +0000 | [diff] [blame] | 2731 | for (auto *M : Mod->submodules()) | 
|  | 2732 | Q.push(M); | 
| Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2733 | } | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2734 |  | 
| Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2735 | Stream.ExitBlock(); | 
| Richard Smith | 23d8d03 | 2015-05-14 00:45:20 +0000 | [diff] [blame] | 2736 |  | 
| Richard Smith | 23d8d03 | 2015-05-14 00:45:20 +0000 | [diff] [blame] | 2737 | assert((NextSubmoduleID - FirstSubmoduleID == | 
|  | 2738 | getNumberOfModules(WritingModule)) && | 
|  | 2739 | "Wrong # of submodules; found a reference to a non-local, " | 
|  | 2740 | "non-imported submodule?"); | 
| Douglas Gregor | 6902197 | 2011-11-30 17:33:56 +0000 | [diff] [blame] | 2741 | } | 
|  | 2742 |  | 
| Argyrios Kyrtzidis | 0f06b98 | 2013-03-27 17:17:23 +0000 | [diff] [blame] | 2743 | void ASTWriter::WritePragmaDiagnosticMappings(const DiagnosticsEngine &Diag, | 
|  | 2744 | bool isModule) { | 
| Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2745 | llvm::SmallDenseMap<const DiagnosticsEngine::DiagState *, unsigned, 64> | 
|  | 2746 | DiagStateIDMap; | 
|  | 2747 | unsigned CurrID = 0; | 
| Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2748 | RecordData Record; | 
| Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2749 |  | 
| Richard Smith | e37391c | 2017-05-03 00:28:49 +0000 | [diff] [blame] | 2750 | auto EncodeDiagStateFlags = | 
|  | 2751 | [](const DiagnosticsEngine::DiagState *DS) -> unsigned { | 
|  | 2752 | unsigned Result = (unsigned)DS->ExtBehavior; | 
|  | 2753 | for (unsigned Val : | 
| Daniel Jasper | ba9aefc | 2017-05-03 07:48:27 +0000 | [diff] [blame] | 2754 | {(unsigned)DS->IgnoreAllWarnings, (unsigned)DS->EnableAllWarnings, | 
|  | 2755 | (unsigned)DS->WarningsAsErrors, (unsigned)DS->ErrorsAsFatal, | 
|  | 2756 | (unsigned)DS->SuppressSystemWarnings}) | 
| Richard Smith | e37391c | 2017-05-03 00:28:49 +0000 | [diff] [blame] | 2757 | Result = (Result << 1) | Val; | 
|  | 2758 | return Result; | 
|  | 2759 | }; | 
|  | 2760 |  | 
|  | 2761 | unsigned Flags = EncodeDiagStateFlags(Diag.DiagStatesByLoc.FirstDiagState); | 
|  | 2762 | Record.push_back(Flags); | 
|  | 2763 |  | 
| Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 2764 | auto AddDiagState = [&](const DiagnosticsEngine::DiagState *State, | 
|  | 2765 | bool IncludeNonPragmaStates) { | 
| Richard Smith | e37391c | 2017-05-03 00:28:49 +0000 | [diff] [blame] | 2766 | // Ensure that the diagnostic state wasn't modified since it was created. | 
|  | 2767 | // We will not correctly round-trip this information otherwise. | 
|  | 2768 | assert(Flags == EncodeDiagStateFlags(State) && | 
|  | 2769 | "diag state flags vary in single AST file"); | 
|  | 2770 |  | 
| Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 2771 | unsigned &DiagStateID = DiagStateIDMap[State]; | 
| Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2772 | Record.push_back(DiagStateID); | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 2773 |  | 
| Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2774 | if (DiagStateID == 0) { | 
|  | 2775 | DiagStateID = ++CurrID; | 
| Duncan P. N. Exon Smith | 3cb183b | 2017-03-14 19:31:27 +0000 | [diff] [blame] | 2776 |  | 
|  | 2777 | // Add a placeholder for the number of mappings. | 
|  | 2778 | auto SizeIdx = Record.size(); | 
|  | 2779 | Record.emplace_back(); | 
| Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 2780 | for (const auto &I : *State) { | 
|  | 2781 | if (I.second.isPragma() || IncludeNonPragmaStates) { | 
| Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 2782 | Record.push_back(I.first); | 
| Richard Smith | e37391c | 2017-05-03 00:28:49 +0000 | [diff] [blame] | 2783 | Record.push_back(I.second.serialize()); | 
| Argyrios Kyrtzidis | efaa54a | 2012-10-30 00:27:21 +0000 | [diff] [blame] | 2784 | } | 
| Argyrios Kyrtzidis | 243aedb | 2011-01-14 20:54:07 +0000 | [diff] [blame] | 2785 | } | 
| Duncan P. N. Exon Smith | 3cb183b | 2017-03-14 19:31:27 +0000 | [diff] [blame] | 2786 | // Update the placeholder. | 
|  | 2787 | Record[SizeIdx] = (Record.size() - SizeIdx) / 2; | 
| Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 2788 | } | 
|  | 2789 | }; | 
|  | 2790 |  | 
|  | 2791 | AddDiagState(Diag.DiagStatesByLoc.FirstDiagState, isModule); | 
| Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 2792 |  | 
| Duncan P. N. Exon Smith | a351c10 | 2017-04-12 03:45:32 +0000 | [diff] [blame] | 2793 | // Reserve a spot for the number of locations with state transitions. | 
|  | 2794 | auto NumLocationsIdx = Record.size(); | 
|  | 2795 | Record.emplace_back(); | 
|  | 2796 |  | 
|  | 2797 | // Emit the state transitions. | 
|  | 2798 | unsigned NumLocations = 0; | 
| Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 2799 | for (auto &FileIDAndFile : Diag.DiagStatesByLoc.Files) { | 
|  | 2800 | if (!FileIDAndFile.first.isValid() || | 
|  | 2801 | !FileIDAndFile.second.HasLocalTransitions) | 
|  | 2802 | continue; | 
| Duncan P. N. Exon Smith | a351c10 | 2017-04-12 03:45:32 +0000 | [diff] [blame] | 2803 | ++NumLocations; | 
| Richard Smith | 6c2b5a8 | 2018-02-09 01:15:13 +0000 | [diff] [blame] | 2804 |  | 
|  | 2805 | SourceLocation Loc = Diag.SourceMgr->getComposedLoc(FileIDAndFile.first, 0); | 
|  | 2806 | assert(!Loc.isInvalid() && "start loc for valid FileID is invalid"); | 
|  | 2807 | AddSourceLocation(Loc, Record); | 
|  | 2808 |  | 
| Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 2809 | Record.push_back(FileIDAndFile.second.StateTransitions.size()); | 
|  | 2810 | for (auto &StatePoint : FileIDAndFile.second.StateTransitions) { | 
|  | 2811 | Record.push_back(StatePoint.Offset); | 
|  | 2812 | AddDiagState(StatePoint.State, false); | 
| Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2813 | } | 
|  | 2814 | } | 
|  | 2815 |  | 
| Duncan P. N. Exon Smith | a351c10 | 2017-04-12 03:45:32 +0000 | [diff] [blame] | 2816 | // Backpatch the number of locations. | 
|  | 2817 | Record[NumLocationsIdx] = NumLocations; | 
|  | 2818 |  | 
|  | 2819 | // Emit CurDiagStateLoc.  Do it last in order to match source order. | 
| Duncan P. N. Exon Smith | 900f817 | 2017-04-12 03:58:58 +0000 | [diff] [blame] | 2820 | // | 
|  | 2821 | // This also protects against a hypothetical corner case with simulating | 
|  | 2822 | // -Werror settings for implicit modules in the ASTReader, where reading | 
|  | 2823 | // CurDiagState out of context could change whether warning pragmas are | 
|  | 2824 | // treated as errors. | 
| Duncan P. N. Exon Smith | a351c10 | 2017-04-12 03:45:32 +0000 | [diff] [blame] | 2825 | AddSourceLocation(Diag.DiagStatesByLoc.CurDiagStateLoc, Record); | 
|  | 2826 | AddDiagState(Diag.DiagStatesByLoc.CurDiagState, false); | 
|  | 2827 |  | 
| Duncan P. N. Exon Smith | f2435b9 | 2017-04-12 02:31:17 +0000 | [diff] [blame] | 2828 | Stream.EmitRecord(DIAG_PRAGMA_MAPPINGS, Record); | 
| Argyrios Kyrtzidis | 452707c | 2010-11-05 22:10:18 +0000 | [diff] [blame] | 2829 | } | 
|  | 2830 |  | 
| Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2831 | //===----------------------------------------------------------------------===// | 
|  | 2832 | // Type Serialization | 
|  | 2833 | //===----------------------------------------------------------------------===// | 
| Chris Lattner | eeffaef | 2009-04-10 17:15:23 +0000 | [diff] [blame] | 2834 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2835 | /// Write the representation of a type to the AST stream. | 
| Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2836 | void ASTWriter::WriteType(QualType T) { | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 2837 | TypeIdx &IdxRef = TypeIdxs[T]; | 
|  | 2838 | if (IdxRef.getIndex() == 0) // we haven't seen this type before. | 
|  | 2839 | IdxRef = TypeIdx(NextTypeID++); | 
|  | 2840 | TypeIdx Idx = IdxRef; | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2841 |  | 
| Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 2842 | assert(Idx.getIndex() >= FirstTypeID && "Re-writing a type from a prior AST"); | 
| Douglas Gregor | dc72caa | 2010-10-04 18:21:45 +0000 | [diff] [blame] | 2843 |  | 
| Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2844 | // Emit the type's representation. | 
| John McCall | d505e57 | 2019-12-13 21:54:44 -0500 | [diff] [blame] | 2845 | uint64_t Offset = ASTTypeWriter(*this).write(T); | 
| John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2846 |  | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 2847 | // Record the offset for this type. | 
|  | 2848 | unsigned Index = Idx.getIndex() - FirstTypeID; | 
|  | 2849 | if (TypeOffsets.size() == Index) | 
| Dmitry Polukhin | a7afb21 | 2020-04-16 09:24:46 -0700 | [diff] [blame] | 2850 | TypeOffsets.emplace_back(Offset); | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 2851 | else if (TypeOffsets.size() < Index) { | 
|  | 2852 | TypeOffsets.resize(Index + 1); | 
| Dmitry Polukhin | a7afb21 | 2020-04-16 09:24:46 -0700 | [diff] [blame] | 2853 | TypeOffsets[Index].setBitOffset(Offset); | 
| John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 2854 | } else { | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 2855 | llvm_unreachable("Types emitted in wrong order"); | 
| Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2856 | } | 
| Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2857 | } | 
|  | 2858 |  | 
| Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2859 | //===----------------------------------------------------------------------===// | 
|  | 2860 | // Declaration Serialization | 
|  | 2861 | //===----------------------------------------------------------------------===// | 
|  | 2862 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2863 | /// Write the block containing all of the declaration IDs | 
| Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2864 | /// lexically declared within the given DeclContext. | 
|  | 2865 | /// | 
|  | 2866 | /// \returns the offset of the DECL_CONTEXT_LEXICAL block within the | 
| Alexander Kornienko | 2a8c18d | 2018-04-06 15:14:32 +0000 | [diff] [blame] | 2867 | /// bitstream, or 0 if no block was written. | 
| Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2868 | uint64_t ASTWriter::WriteDeclContextLexicalBlock(ASTContext &Context, | 
| Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2869 | DeclContext *DC) { | 
| Argyrios Kyrtzidis | cfbfe78 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 2870 | if (DC->decls_empty()) | 
| Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2871 | return 0; | 
|  | 2872 |  | 
| Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 2873 | uint64_t Offset = Stream.GetCurrentBitNo(); | 
| Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 2874 | SmallVector<uint32_t, 128> KindDeclPairs; | 
|  | 2875 | for (const auto *D : DC->decls()) { | 
|  | 2876 | KindDeclPairs.push_back(D->getKind()); | 
|  | 2877 | KindDeclPairs.push_back(GetDeclRef(D)); | 
|  | 2878 | } | 
| Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2879 |  | 
| Douglas Gregor | a57c3ab | 2009-04-22 22:34:57 +0000 | [diff] [blame] | 2880 | ++NumLexicalDeclContexts; | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2881 | RecordData::value_type Record[] = {DECL_CONTEXT_LEXICAL}; | 
| Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 2882 | Stream.EmitRecordWithBlob(DeclContextLexicalAbbrev, Record, | 
|  | 2883 | bytes(KindDeclPairs)); | 
| Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 2884 | return Offset; | 
|  | 2885 | } | 
|  | 2886 |  | 
| Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2887 | void ASTWriter::WriteTypeDeclOffsets() { | 
| Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2888 | using namespace llvm; | 
| Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2889 |  | 
|  | 2890 | // Write the type offsets array | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2891 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); | 
| Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2892 | Abbrev->Add(BitCodeAbbrevOp(TYPE_OFFSET)); | 
| Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2893 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of types | 
| Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 2894 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // base type index | 
| Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2895 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // types block | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2896 | unsigned TypeOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2897 | { | 
|  | 2898 | RecordData::value_type Record[] = {TYPE_OFFSET, TypeOffsets.size(), | 
|  | 2899 | FirstTypeID - NUM_PREDEF_TYPE_IDS}; | 
|  | 2900 | Stream.EmitRecordWithBlob(TypeOffsetAbbrev, Record, bytes(TypeOffsets)); | 
|  | 2901 | } | 
| Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2902 |  | 
|  | 2903 | // Write the declaration offsets array | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2904 | Abbrev = std::make_shared<BitCodeAbbrev>(); | 
| Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2905 | Abbrev->Add(BitCodeAbbrevOp(DECL_OFFSET)); | 
| Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2906 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of declarations | 
| Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 2907 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // base decl ID | 
| Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2908 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // declarations block | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2909 | unsigned DeclOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2910 | { | 
|  | 2911 | RecordData::value_type Record[] = {DECL_OFFSET, DeclOffsets.size(), | 
|  | 2912 | FirstDeclID - NUM_PREDEF_DECL_IDS}; | 
|  | 2913 | Stream.EmitRecordWithBlob(DeclOffsetAbbrev, Record, bytes(DeclOffsets)); | 
|  | 2914 | } | 
| Sebastian Redl | 1ea025b | 2010-07-16 16:36:56 +0000 | [diff] [blame] | 2915 | } | 
|  | 2916 |  | 
| Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2917 | void ASTWriter::WriteFileDeclIDsMap() { | 
|  | 2918 | using namespace llvm; | 
| Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2919 |  | 
| David Blaikie | 409df39 | 2020-04-28 18:05:28 -0700 | [diff] [blame] | 2920 | SmallVector<std::pair<FileID, DeclIDInFileInfo *>, 64> SortedFileDeclIDs; | 
|  | 2921 | SortedFileDeclIDs.reserve(FileDeclIDs.size()); | 
|  | 2922 | for (const auto &P : FileDeclIDs) | 
|  | 2923 | SortedFileDeclIDs.push_back(std::make_pair(P.first, P.second.get())); | 
| Fangrui Song | 55fab26 | 2018-09-26 22:16:28 +0000 | [diff] [blame] | 2924 | llvm::sort(SortedFileDeclIDs, llvm::less_first()); | 
| Chandler Carruth | b306d73 | 2015-03-27 00:31:20 +0000 | [diff] [blame] | 2925 |  | 
| Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2926 | // Join the vectors of DeclIDs from all files. | 
| Chandler Carruth | b306d73 | 2015-03-27 00:31:20 +0000 | [diff] [blame] | 2927 | SmallVector<DeclID, 256> FileGroupedDeclIDs; | 
|  | 2928 | for (auto &FileDeclEntry : SortedFileDeclIDs) { | 
|  | 2929 | DeclIDInFileInfo &Info = *FileDeclEntry.second; | 
|  | 2930 | Info.FirstDeclIndex = FileGroupedDeclIDs.size(); | 
|  | 2931 | for (auto &LocDeclEntry : Info.DeclIDs) | 
|  | 2932 | FileGroupedDeclIDs.push_back(LocDeclEntry.second); | 
| Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2933 | } | 
|  | 2934 |  | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2935 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); | 
| Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2936 | Abbrev->Add(BitCodeAbbrevOp(FILE_SORTED_DECLS)); | 
| Argyrios Kyrtzidis | 10e7846 | 2012-10-02 21:09:13 +0000 | [diff] [blame] | 2937 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); | 
| Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2938 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 2939 | unsigned AbbrevCode = Stream.EmitAbbrev(std::move(Abbrev)); | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 2940 | RecordData::value_type Record[] = {FILE_SORTED_DECLS, | 
|  | 2941 | FileGroupedDeclIDs.size()}; | 
| Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 2942 | Stream.EmitRecordWithBlob(AbbrevCode, Record, bytes(FileGroupedDeclIDs)); | 
| Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 2943 | } | 
|  | 2944 |  | 
| Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2945 | void ASTWriter::WriteComments() { | 
|  | 2946 | Stream.EnterSubblock(COMMENTS_BLOCK_ID, 3); | 
| Ilya Biryukov | 4564310 | 2018-07-09 11:33:23 +0000 | [diff] [blame] | 2947 | auto _ = llvm::make_scope_exit([this] { Stream.ExitBlock(); }); | 
|  | 2948 | if (!PP->getPreprocessorOpts().WriteCommentListToPCH) | 
|  | 2949 | return; | 
| Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2950 | RecordData Record; | 
| Jan Korous | f31d8df | 2019-08-13 18:11:44 +0000 | [diff] [blame] | 2951 | for (const auto &FO : Context->Comments.OrderedComments) { | 
|  | 2952 | for (const auto &OC : FO.second) { | 
|  | 2953 | const RawComment *I = OC.second; | 
|  | 2954 | Record.clear(); | 
|  | 2955 | AddSourceRange(I->getSourceRange(), Record); | 
|  | 2956 | Record.push_back(I->getKind()); | 
|  | 2957 | Record.push_back(I->isTrailingComment()); | 
|  | 2958 | Record.push_back(I->isAlmostTrailingComment()); | 
|  | 2959 | Stream.EmitRecord(COMMENTS_RAW_COMMENT, Record); | 
|  | 2960 | } | 
| Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2961 | } | 
| Dmitri Gribenko | aab8383 | 2012-06-20 00:34:58 +0000 | [diff] [blame] | 2962 | } | 
|  | 2963 |  | 
| Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 2964 | //===----------------------------------------------------------------------===// | 
|  | 2965 | // Global Method Pool and Selector Serialization | 
|  | 2966 | //===----------------------------------------------------------------------===// | 
|  | 2967 |  | 
| Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 2968 | namespace { | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 2969 |  | 
| Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2970 | // Trait used for the on-disk hash table used in the method pool. | 
| Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 2971 | class ASTMethodPoolTrait { | 
| Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 2972 | ASTWriter &Writer; | 
| Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2973 |  | 
|  | 2974 | public: | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 2975 | using key_type = Selector; | 
|  | 2976 | using key_type_ref = key_type; | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2977 |  | 
| Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2978 | struct data_type { | 
| Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 2979 | SelectorID ID; | 
| Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 2980 | ObjCMethodList Instance, Factory; | 
|  | 2981 | }; | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 2982 | using data_type_ref = const data_type &; | 
| Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2983 |  | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 2984 | using hash_value_type = unsigned; | 
|  | 2985 | using offset_type = unsigned; | 
| Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 2986 |  | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 2987 | explicit ASTMethodPoolTrait(ASTWriter &Writer) : Writer(Writer) {} | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2988 |  | 
| Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 2989 | static hash_value_type ComputeHash(Selector Sel) { | 
| Argyrios Kyrtzidis | 4bd9710 | 2010-08-20 16:03:52 +0000 | [diff] [blame] | 2990 | return serialization::ComputeHash(Sel); | 
| Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2991 | } | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2992 |  | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 2993 | std::pair<unsigned, unsigned> | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2994 | EmitKeyDataLength(raw_ostream& Out, Selector Sel, | 
| Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2995 | data_type_ref Methods) { | 
| Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 2996 | using namespace llvm::support; | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 2997 |  | 
| Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 2998 | endian::Writer LE(Out, little); | 
| Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 2999 | unsigned KeyLen = 2 + (Sel.getNumArgs()? Sel.getNumArgs() * 4 : 4); | 
| Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3000 | LE.write<uint16_t>(KeyLen); | 
| Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3001 | unsigned DataLen = 4 + 2 + 2; // 2 bytes for each of the method counts | 
|  | 3002 | for (const ObjCMethodList *Method = &Methods.Instance; Method; | 
| Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3003 | Method = Method->getNext()) | 
| Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3004 | if (Method->getMethod()) | 
| Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3005 | DataLen += 4; | 
| Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3006 | for (const ObjCMethodList *Method = &Methods.Factory; Method; | 
| Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3007 | Method = Method->getNext()) | 
| Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3008 | if (Method->getMethod()) | 
| Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3009 | DataLen += 4; | 
| Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3010 | LE.write<uint16_t>(DataLen); | 
| Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3011 | return std::make_pair(KeyLen, DataLen); | 
|  | 3012 | } | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3013 |  | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3014 | void EmitKey(raw_ostream& Out, Selector Sel, unsigned) { | 
| Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3015 | using namespace llvm::support; | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3016 |  | 
| Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 3017 | endian::Writer LE(Out, little); | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3018 | uint64_t Start = Out.tell(); | 
| Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3019 | assert((Start >> 32) == 0 && "Selector key offset too large"); | 
|  | 3020 | Writer.SetSelectorOffset(Sel, Start); | 
| Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3021 | unsigned N = Sel.getNumArgs(); | 
| Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3022 | LE.write<uint16_t>(N); | 
| Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3023 | if (N == 0) | 
|  | 3024 | N = 1; | 
|  | 3025 | for (unsigned I = 0; I != N; ++I) | 
| Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3026 | LE.write<uint32_t>( | 
|  | 3027 | Writer.getIdentifierRef(Sel.getIdentifierInfoForSlot(I))); | 
| Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3028 | } | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3029 |  | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3030 | void EmitData(raw_ostream& Out, key_type_ref, | 
| Douglas Gregor | 4647cfa | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 3031 | data_type_ref Methods, unsigned DataLen) { | 
| Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3032 | using namespace llvm::support; | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3033 |  | 
| Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 3034 | endian::Writer LE(Out, little); | 
| Douglas Gregor | 4647cfa | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 3035 | uint64_t Start = Out.tell(); (void)Start; | 
| Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3036 | LE.write<uint32_t>(Methods.ID); | 
| Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3037 | unsigned NumInstanceMethods = 0; | 
| Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3038 | for (const ObjCMethodList *Method = &Methods.Instance; Method; | 
| Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3039 | Method = Method->getNext()) | 
| Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3040 | if (Method->getMethod()) | 
| Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3041 | ++NumInstanceMethods; | 
|  | 3042 |  | 
|  | 3043 | unsigned NumFactoryMethods = 0; | 
| Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3044 | for (const ObjCMethodList *Method = &Methods.Factory; Method; | 
| Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3045 | Method = Method->getNext()) | 
| Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3046 | if (Method->getMethod()) | 
| Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3047 | ++NumFactoryMethods; | 
|  | 3048 |  | 
| Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3049 | unsigned InstanceBits = Methods.Instance.getBits(); | 
|  | 3050 | assert(InstanceBits < 4); | 
| Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 3051 | unsigned InstanceHasMoreThanOneDeclBit = | 
|  | 3052 | Methods.Instance.hasMoreThanOneDecl(); | 
|  | 3053 | unsigned FullInstanceBits = (NumInstanceMethods << 3) | | 
|  | 3054 | (InstanceHasMoreThanOneDeclBit << 2) | | 
|  | 3055 | InstanceBits; | 
| Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3056 | unsigned FactoryBits = Methods.Factory.getBits(); | 
|  | 3057 | assert(FactoryBits < 4); | 
| Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 3058 | unsigned FactoryHasMoreThanOneDeclBit = | 
|  | 3059 | Methods.Factory.hasMoreThanOneDecl(); | 
|  | 3060 | unsigned FullFactoryBits = (NumFactoryMethods << 3) | | 
|  | 3061 | (FactoryHasMoreThanOneDeclBit << 2) | | 
|  | 3062 | FactoryBits; | 
|  | 3063 | LE.write<uint16_t>(FullInstanceBits); | 
|  | 3064 | LE.write<uint16_t>(FullFactoryBits); | 
| Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3065 | for (const ObjCMethodList *Method = &Methods.Instance; Method; | 
| Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3066 | Method = Method->getNext()) | 
| Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3067 | if (Method->getMethod()) | 
|  | 3068 | LE.write<uint32_t>(Writer.getDeclID(Method->getMethod())); | 
| Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3069 | for (const ObjCMethodList *Method = &Methods.Factory; Method; | 
| Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3070 | Method = Method->getNext()) | 
| Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3071 | if (Method->getMethod()) | 
|  | 3072 | LE.write<uint32_t>(Writer.getDeclID(Method->getMethod())); | 
| Douglas Gregor | 4647cfa | 2009-04-24 21:49:02 +0000 | [diff] [blame] | 3073 |  | 
|  | 3074 | assert(Out.tell() - Start == DataLen && "Data length is wrong"); | 
| Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3075 | } | 
|  | 3076 | }; | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 3077 |  | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3078 | } // namespace | 
| Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3079 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3080 | /// Write ObjC data: selectors and the method pool. | 
| Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3081 | /// | 
|  | 3082 | /// The method pool contains both instance and factory methods, stored | 
| Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3083 | /// in an on-disk hash table indexed by the selector. The hash table also | 
|  | 3084 | /// contains an empty entry for every other selector known to Sema. | 
| Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3085 | void ASTWriter::WriteSelectors(Sema &SemaRef) { | 
| Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3086 | using namespace llvm; | 
|  | 3087 |  | 
| Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3088 | // Do we have to do anything at all? | 
| Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3089 | if (SemaRef.MethodPool.empty() && SelectorIDs.empty()) | 
| Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3090 | return; | 
| Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3091 | unsigned NumTableEntries = 0; | 
| Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3092 | // Create and write out the blob that contains selectors and the method pool. | 
| Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3093 | { | 
| Justin Bogner | bb094f0 | 2014-04-18 19:57:06 +0000 | [diff] [blame] | 3094 | llvm::OnDiskChainedHashTableGenerator<ASTMethodPoolTrait> Generator; | 
| Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3095 | ASTMethodPoolTrait Trait(*this); | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3096 |  | 
| Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3097 | // Create the on-disk hash table representation. We walk through every | 
|  | 3098 | // selector we've seen and look it up in the method pool. | 
| Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3099 | SelectorOffsets.resize(NextSelectorID - FirstSelectorID); | 
| Chandler Carruth | acbbeb9 | 2015-03-27 00:47:43 +0000 | [diff] [blame] | 3100 | for (auto &SelectorAndID : SelectorIDs) { | 
|  | 3101 | Selector S = SelectorAndID.first; | 
|  | 3102 | SelectorID ID = SelectorAndID.second; | 
| Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 3103 | Sema::GlobalMethodPool::iterator F = SemaRef.MethodPool.find(S); | 
| Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3104 | ASTMethodPoolTrait::data_type Data = { | 
| Chandler Carruth | acbbeb9 | 2015-03-27 00:47:43 +0000 | [diff] [blame] | 3105 | ID, | 
| Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 3106 | ObjCMethodList(), | 
|  | 3107 | ObjCMethodList() | 
|  | 3108 | }; | 
|  | 3109 | if (F != SemaRef.MethodPool.end()) { | 
|  | 3110 | Data.Instance = F->second.first; | 
|  | 3111 | Data.Factory = F->second.second; | 
|  | 3112 | } | 
| Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3113 | // Only write this selector if it's not in an existing AST or something | 
| Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3114 | // changed. | 
| Chandler Carruth | acbbeb9 | 2015-03-27 00:47:43 +0000 | [diff] [blame] | 3115 | if (Chain && ID < FirstSelectorID) { | 
| Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3116 | // Selector already exists. Did it change? | 
|  | 3117 | bool changed = false; | 
| Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3118 | for (ObjCMethodList *M = &Data.Instance; | 
|  | 3119 | !changed && M && M->getMethod(); M = M->getNext()) { | 
|  | 3120 | if (!M->getMethod()->isFromASTFile()) | 
| Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3121 | changed = true; | 
|  | 3122 | } | 
| Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3123 | for (ObjCMethodList *M = &Data.Factory; !changed && M && M->getMethod(); | 
| Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3124 | M = M->getNext()) { | 
| Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3125 | if (!M->getMethod()->isFromASTFile()) | 
| Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3126 | changed = true; | 
|  | 3127 | } | 
|  | 3128 | if (!changed) | 
|  | 3129 | continue; | 
| Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3130 | } else if (Data.Instance.getMethod() || Data.Factory.getMethod()) { | 
| Sebastian Redl | 6e1a2a0 | 2010-08-04 21:22:45 +0000 | [diff] [blame] | 3131 | // A new method pool entry. | 
|  | 3132 | ++NumTableEntries; | 
| Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 3133 | } | 
| Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3134 | Generator.insert(S, Data, Trait); | 
| Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3135 | } | 
|  | 3136 |  | 
| Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3137 | // Create the on-disk hash table in a buffer. | 
| Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3138 | SmallString<4096> MethodPool; | 
| Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3139 | uint32_t BucketOffset; | 
|  | 3140 | { | 
| Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3141 | using namespace llvm::support; | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3142 |  | 
| Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3143 | ASTMethodPoolTrait Trait(*this); | 
| Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3144 | llvm::raw_svector_ostream Out(MethodPool); | 
|  | 3145 | // Make sure that no bucket is at offset 0 | 
| Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 3146 | endian::write<uint32_t>(Out, 0, little); | 
| Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3147 | BucketOffset = Generator.Emit(Out, Trait); | 
|  | 3148 | } | 
|  | 3149 |  | 
|  | 3150 | // Create a blob abbreviation | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3151 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); | 
| Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3152 | Abbrev->Add(BitCodeAbbrevOp(METHOD_POOL)); | 
| Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3153 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); | 
| Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3154 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); | 
| Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3155 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3156 | unsigned MethodPoolAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); | 
| Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3157 |  | 
| Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3158 | // Write the method pool | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3159 | { | 
|  | 3160 | RecordData::value_type Record[] = {METHOD_POOL, BucketOffset, | 
|  | 3161 | NumTableEntries}; | 
|  | 3162 | Stream.EmitRecordWithBlob(MethodPoolAbbrev, Record, MethodPool); | 
|  | 3163 | } | 
| Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3164 |  | 
|  | 3165 | // Create a blob abbreviation for the selector table offsets. | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3166 | Abbrev = std::make_shared<BitCodeAbbrev>(); | 
| Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3167 | Abbrev->Add(BitCodeAbbrevOp(SELECTOR_OFFSETS)); | 
| Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3168 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // size | 
| Douglas Gregor | 8f364fb | 2011-08-03 23:28:44 +0000 | [diff] [blame] | 3169 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID | 
| Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3170 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3171 | unsigned SelectorOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); | 
| Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 3172 |  | 
|  | 3173 | // Write the selector offsets table. | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3174 | { | 
|  | 3175 | RecordData::value_type Record[] = { | 
|  | 3176 | SELECTOR_OFFSETS, SelectorOffsets.size(), | 
|  | 3177 | FirstSelectorID - NUM_PREDEF_SELECTOR_IDS}; | 
|  | 3178 | Stream.EmitRecordWithBlob(SelectorOffsetAbbrev, Record, | 
|  | 3179 | bytes(SelectorOffsets)); | 
|  | 3180 | } | 
| Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3181 | } | 
|  | 3182 | } | 
|  | 3183 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3184 | /// Write the selectors referenced in @selector expression into AST file. | 
| Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 3185 | void ASTWriter::WriteReferencedSelectorsPool(Sema &SemaRef) { | 
| Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3186 | using namespace llvm; | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3187 |  | 
| Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3188 | if (SemaRef.ReferencedSelectors.empty()) | 
|  | 3189 | return; | 
| Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3190 |  | 
| Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3191 | RecordData Record; | 
| Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 3192 | ASTRecordWriter Writer(*this, Record); | 
| Sebastian Redl | ada023c | 2010-08-04 20:40:17 +0000 | [diff] [blame] | 3193 |  | 
| Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3194 | // Note: this writes out all references even for a dependent AST. But it is | 
| Sebastian Redl | 51c79d8 | 2010-08-04 22:21:29 +0000 | [diff] [blame] | 3195 | // very tricky to fix, and given that @selector shouldn't really appear in | 
|  | 3196 | // headers, probably not worth it. It's not a correctness issue. | 
| Chandler Carruth | 12c8f65 | 2015-03-27 00:55:05 +0000 | [diff] [blame] | 3197 | for (auto &SelectorAndLocation : SemaRef.ReferencedSelectors) { | 
|  | 3198 | Selector Sel = SelectorAndLocation.first; | 
|  | 3199 | SourceLocation Loc = SelectorAndLocation.second; | 
| Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 3200 | Writer.AddSelectorRef(Sel); | 
|  | 3201 | Writer.AddSourceLocation(Loc); | 
| Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3202 | } | 
| Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 3203 | Writer.Emit(REFERENCED_SELECTOR_POOL); | 
| Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 3204 | } | 
|  | 3205 |  | 
| Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3206 | //===----------------------------------------------------------------------===// | 
|  | 3207 | // Identifier Table Serialization | 
|  | 3208 | //===----------------------------------------------------------------------===// | 
|  | 3209 |  | 
| Richard Smith | b376191 | 2015-02-05 23:08:52 +0000 | [diff] [blame] | 3210 | /// Determine the declaration that should be put into the name lookup table to | 
|  | 3211 | /// represent the given declaration in this module. This is usually D itself, | 
|  | 3212 | /// but if D was imported and merged into a local declaration, we want the most | 
|  | 3213 | /// recent local declaration instead. The chosen declaration will be the most | 
|  | 3214 | /// recent declaration in any module that imports this one. | 
|  | 3215 | static NamedDecl *getDeclForLocalLookup(const LangOptions &LangOpts, | 
|  | 3216 | NamedDecl *D) { | 
|  | 3217 | if (!LangOpts.Modules || !D->isFromASTFile()) | 
|  | 3218 | return D; | 
|  | 3219 |  | 
|  | 3220 | if (Decl *Redecl = D->getPreviousDecl()) { | 
|  | 3221 | // For Redeclarable decls, a prior declaration might be local. | 
|  | 3222 | for (; Redecl; Redecl = Redecl->getPreviousDecl()) { | 
| Richard Smith | d49941b | 2016-04-26 23:40:43 +0000 | [diff] [blame] | 3223 | // If we find a local decl, we're done. | 
|  | 3224 | if (!Redecl->isFromASTFile()) { | 
|  | 3225 | // Exception: in very rare cases (for injected-class-names), not all | 
|  | 3226 | // redeclarations are in the same semantic context. Skip ones in a | 
|  | 3227 | // different context. They don't go in this lookup table at all. | 
|  | 3228 | if (!Redecl->getDeclContext()->getRedeclContext()->Equals( | 
|  | 3229 | D->getDeclContext()->getRedeclContext())) | 
|  | 3230 | continue; | 
| Richard Smith | b376191 | 2015-02-05 23:08:52 +0000 | [diff] [blame] | 3231 | return cast<NamedDecl>(Redecl); | 
| Richard Smith | d49941b | 2016-04-26 23:40:43 +0000 | [diff] [blame] | 3232 | } | 
|  | 3233 |  | 
| Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 3234 | // If we find a decl from a (chained-)PCH stop since we won't find a | 
| Richard Smith | b376191 | 2015-02-05 23:08:52 +0000 | [diff] [blame] | 3235 | // local one. | 
| Richard Smith | d49941b | 2016-04-26 23:40:43 +0000 | [diff] [blame] | 3236 | if (Redecl->getOwningModuleID() == 0) | 
| Richard Smith | b376191 | 2015-02-05 23:08:52 +0000 | [diff] [blame] | 3237 | break; | 
|  | 3238 | } | 
|  | 3239 | } else if (Decl *First = D->getCanonicalDecl()) { | 
|  | 3240 | // For Mergeable decls, the first decl might be local. | 
|  | 3241 | if (!First->isFromASTFile()) | 
|  | 3242 | return cast<NamedDecl>(First); | 
|  | 3243 | } | 
|  | 3244 |  | 
|  | 3245 | // All declarations are imported. Our most recent declaration will also be | 
|  | 3246 | // the most recent one in anyone who imports us. | 
|  | 3247 | return D; | 
|  | 3248 | } | 
|  | 3249 |  | 
| Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3250 | namespace { | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 3251 |  | 
| Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3252 | class ASTIdentifierTableTrait { | 
|  | 3253 | ASTWriter &Writer; | 
|  | 3254 | Preprocessor &PP; | 
|  | 3255 | IdentifierResolver &IdResolver; | 
| Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3256 | bool IsModule; | 
| Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3257 | bool NeedDecls; | 
| Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3258 | ASTWriter::RecordData *InterestingIdentifierOffsets; | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 3259 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3260 | /// Determines whether this is an "interesting" identifier that needs a | 
| Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3261 | /// full IdentifierInfo structure written into the hash table. Notably, this | 
|  | 3262 | /// doesn't check whether the name has macros defined; use PublicMacroIterator | 
|  | 3263 | /// to check that. | 
| Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3264 | bool isInterestingIdentifier(const IdentifierInfo *II, uint64_t MacroOffset) { | 
| Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3265 | if (MacroOffset || | 
|  | 3266 | II->isPoisoned() || | 
| Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3267 | (IsModule ? II->hasRevertedBuiltin() : II->getObjCOrBuiltinID()) || | 
| Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3268 | II->hasRevertedTokenIDToIdentifier() || | 
| Bruno Ricci | 366ba73 | 2018-09-21 12:53:22 +0000 | [diff] [blame] | 3269 | (NeedDecls && II->getFETokenInfo())) | 
| Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3270 | return true; | 
|  | 3271 |  | 
|  | 3272 | return false; | 
|  | 3273 | } | 
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 3274 |  | 
| Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3275 | public: | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3276 | using key_type = IdentifierInfo *; | 
|  | 3277 | using key_type_ref = key_type; | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3278 |  | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3279 | using data_type = IdentID; | 
|  | 3280 | using data_type_ref = data_type; | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3281 |  | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3282 | using hash_value_type = unsigned; | 
|  | 3283 | using offset_type = unsigned; | 
| Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 3284 |  | 
| Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3285 | ASTIdentifierTableTrait(ASTWriter &Writer, Preprocessor &PP, | 
| Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3286 | IdentifierResolver &IdResolver, bool IsModule, | 
|  | 3287 | ASTWriter::RecordData *InterestingIdentifierOffsets) | 
| Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3288 | : Writer(Writer), PP(PP), IdResolver(IdResolver), IsModule(IsModule), | 
| Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3289 | NeedDecls(!IsModule || !Writer.getLangOpts().CPlusPlus), | 
|  | 3290 | InterestingIdentifierOffsets(InterestingIdentifierOffsets) {} | 
| Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3291 |  | 
| Richard Smith | d79514e | 2016-02-05 19:03:40 +0000 | [diff] [blame] | 3292 | bool needDecls() const { return NeedDecls; } | 
|  | 3293 |  | 
| Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 3294 | static hash_value_type ComputeHash(const IdentifierInfo* II) { | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 3295 | return llvm::djbHash(II->getName()); | 
| Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3296 | } | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3297 |  | 
| Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3298 | bool isInterestingIdentifier(const IdentifierInfo *II) { | 
|  | 3299 | auto MacroOffset = Writer.getMacroDirectivesOffset(II); | 
|  | 3300 | return isInterestingIdentifier(II, MacroOffset); | 
|  | 3301 | } | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 3302 |  | 
| Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3303 | bool isInterestingNonMacroIdentifier(const IdentifierInfo *II) { | 
|  | 3304 | return isInterestingIdentifier(II, 0); | 
|  | 3305 | } | 
|  | 3306 |  | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3307 | std::pair<unsigned, unsigned> | 
| Douglas Gregor | 935bc7a2 | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 3308 | EmitKeyDataLength(raw_ostream& Out, IdentifierInfo* II, IdentID ID) { | 
| Daniel Dunbar | 2c422dc9 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 3309 | unsigned KeyLen = II->getLength() + 1; | 
| Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 3310 | unsigned DataLen = 4; // 4 bytes for the persistent ID << 1 | 
| Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3311 | auto MacroOffset = Writer.getMacroDirectivesOffset(II); | 
|  | 3312 | if (isInterestingIdentifier(II, MacroOffset)) { | 
| Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3313 | DataLen += 2; // 2 bytes for builtin ID | 
|  | 3314 | DataLen += 2; // 2 bytes for flags | 
| Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3315 | if (MacroOffset) | 
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 3316 | DataLen += 4; // MacroDirectives offset. | 
| Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3317 |  | 
| Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3318 | if (NeedDecls) { | 
|  | 3319 | for (IdentifierResolver::iterator D = IdResolver.begin(II), | 
|  | 3320 | DEnd = IdResolver.end(); | 
|  | 3321 | D != DEnd; ++D) | 
|  | 3322 | DataLen += 4; | 
|  | 3323 | } | 
| Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 3324 | } | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3325 |  | 
| Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3326 | using namespace llvm::support; | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3327 |  | 
| Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 3328 | endian::Writer LE(Out, little); | 
| Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3329 |  | 
| Richard Smith | df8a831 | 2015-03-13 04:05:01 +0000 | [diff] [blame] | 3330 | assert((uint16_t)DataLen == DataLen && (uint16_t)KeyLen == KeyLen); | 
| Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3331 | LE.write<uint16_t>(DataLen); | 
| Douglas Gregor | ab4df58 | 2009-04-28 20:01:51 +0000 | [diff] [blame] | 3332 | // We emit the key length after the data length so that every | 
|  | 3333 | // string is preceded by a 16-bit length. This matches the PTH | 
|  | 3334 | // format for storing identifiers. | 
| Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3335 | LE.write<uint16_t>(KeyLen); | 
| Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3336 | return std::make_pair(KeyLen, DataLen); | 
|  | 3337 | } | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3338 |  | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 3339 | void EmitKey(raw_ostream& Out, const IdentifierInfo* II, | 
| Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3340 | unsigned KeyLen) { | 
|  | 3341 | // Record the location of the key data.  This is used when generating | 
|  | 3342 | // the mapping from persistent IDs to strings. | 
|  | 3343 | Writer.SetIdentifierOffset(II, Out.tell()); | 
| Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3344 |  | 
|  | 3345 | // Emit the offset of the key/data length information to the interesting | 
|  | 3346 | // identifiers table if necessary. | 
|  | 3347 | if (InterestingIdentifierOffsets && isInterestingIdentifier(II)) | 
|  | 3348 | InterestingIdentifierOffsets->push_back(Out.tell() - 4); | 
|  | 3349 |  | 
| Daniel Dunbar | 2c422dc9 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 3350 | Out.write(II->getNameStart(), KeyLen); | 
| Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3351 | } | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3352 |  | 
| Douglas Gregor | 4a69c2e | 2011-09-01 17:04:32 +0000 | [diff] [blame] | 3353 | void EmitData(raw_ostream& Out, IdentifierInfo* II, | 
| Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3354 | IdentID ID, unsigned) { | 
| Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3355 | using namespace llvm::support; | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3356 |  | 
| Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 3357 | endian::Writer LE(Out, little); | 
| Richard Smith | cf97cf6 | 2015-04-19 01:34:23 +0000 | [diff] [blame] | 3358 |  | 
| Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3359 | auto MacroOffset = Writer.getMacroDirectivesOffset(II); | 
|  | 3360 | if (!isInterestingIdentifier(II, MacroOffset)) { | 
| Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3361 | LE.write<uint32_t>(ID << 1); | 
| Douglas Gregor | 1d583f2 | 2009-04-28 21:18:29 +0000 | [diff] [blame] | 3362 | return; | 
|  | 3363 | } | 
| Douglas Gregor | b925652 | 2009-04-28 21:32:13 +0000 | [diff] [blame] | 3364 |  | 
| Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3365 | LE.write<uint32_t>((ID << 1) | 0x01); | 
| Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3366 | uint32_t Bits = (uint32_t)II->getObjCOrBuiltinID(); | 
|  | 3367 | assert((Bits & 0xffff) == Bits && "ObjCOrBuiltinID too big for ASTReader."); | 
| Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3368 | LE.write<uint16_t>(Bits); | 
| Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3369 | Bits = 0; | 
| Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3370 | bool HadMacroDefinition = MacroOffset != 0; | 
| Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3371 | Bits = (Bits << 1) | unsigned(HadMacroDefinition); | 
| Daniel Dunbar | 91b640a | 2009-12-18 20:58:47 +0000 | [diff] [blame] | 3372 | Bits = (Bits << 1) | unsigned(II->isExtensionToken()); | 
|  | 3373 | Bits = (Bits << 1) | unsigned(II->isPoisoned()); | 
| Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3374 | Bits = (Bits << 1) | unsigned(II->hasRevertedBuiltin()); | 
| Argyrios Kyrtzidis | 3084a61 | 2010-08-11 22:55:12 +0000 | [diff] [blame] | 3375 | Bits = (Bits << 1) | unsigned(II->hasRevertedTokenIDToIdentifier()); | 
| Daniel Dunbar | 91b640a | 2009-12-18 20:58:47 +0000 | [diff] [blame] | 3376 | Bits = (Bits << 1) | unsigned(II->isCPlusPlusOperatorKeyword()); | 
| Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3377 | LE.write<uint16_t>(Bits); | 
| Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3378 |  | 
| Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 3379 | if (HadMacroDefinition) | 
|  | 3380 | LE.write<uint32_t>(MacroOffset); | 
| Alexander Kornienko | 1d26c02 | 2012-09-25 17:18:14 +0000 | [diff] [blame] | 3381 |  | 
| Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 3382 | if (NeedDecls) { | 
|  | 3383 | // Emit the declaration IDs in reverse order, because the | 
|  | 3384 | // IdentifierResolver provides the declarations as they would be | 
|  | 3385 | // visible (e.g., the function "stat" would come before the struct | 
|  | 3386 | // "stat"), but the ASTReader adds declarations to the end of the list | 
|  | 3387 | // (so we need to see the struct "stat" before the function "stat"). | 
|  | 3388 | // Only emit declarations that aren't from a chained PCH, though. | 
|  | 3389 | SmallVector<NamedDecl *, 16> Decls(IdResolver.begin(II), | 
|  | 3390 | IdResolver.end()); | 
|  | 3391 | for (SmallVectorImpl<NamedDecl *>::reverse_iterator D = Decls.rbegin(), | 
|  | 3392 | DEnd = Decls.rend(); | 
|  | 3393 | D != DEnd; ++D) | 
|  | 3394 | LE.write<uint32_t>( | 
|  | 3395 | Writer.getDeclID(getDeclForLocalLookup(PP.getLangOpts(), *D))); | 
|  | 3396 | } | 
| Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3397 | } | 
|  | 3398 | }; | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 3399 |  | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3400 | } // namespace | 
| Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3401 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3402 | /// Write the identifier table into the AST file. | 
| Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3403 | /// | 
|  | 3404 | /// The identifier table consists of a blob containing string data | 
|  | 3405 | /// (the actual identifiers themselves) and a separate "offsets" index | 
|  | 3406 | /// that maps identifier IDs to locations within the blob. | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 3407 | void ASTWriter::WriteIdentifierTable(Preprocessor &PP, | 
| Douglas Gregor | 935bc7a2 | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 3408 | IdentifierResolver &IdResolver, | 
|  | 3409 | bool IsModule) { | 
| Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3410 | using namespace llvm; | 
|  | 3411 |  | 
| Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3412 | RecordData InterestingIdents; | 
|  | 3413 |  | 
| Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3414 | // Create and write out the blob that contains the identifier | 
|  | 3415 | // strings. | 
| Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3416 | { | 
| Justin Bogner | bb094f0 | 2014-04-18 19:57:06 +0000 | [diff] [blame] | 3417 | llvm::OnDiskChainedHashTableGenerator<ASTIdentifierTableTrait> Generator; | 
| Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3418 | ASTIdentifierTableTrait Trait( | 
|  | 3419 | *this, PP, IdResolver, IsModule, | 
|  | 3420 | (getLangOpts().CPlusPlus && IsModule) ? &InterestingIdents : nullptr); | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3421 |  | 
| Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 3422 | // Look for any identifiers that were named while processing the | 
|  | 3423 | // headers, but are otherwise not needed. We add these to the hash | 
|  | 3424 | // table to enable checking of the predefines buffer in the case | 
| Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 3425 | // where the user adds new macro definitions when building the AST | 
| Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 3426 | // file. | 
| Chandler Carruth | 8440c98 | 2015-03-26 23:54:15 +0000 | [diff] [blame] | 3427 | SmallVector<const IdentifierInfo *, 128> IIs; | 
| Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3428 | for (const auto &ID : PP.getIdentifierTable()) | 
|  | 3429 | IIs.push_back(ID.second); | 
| Chandler Carruth | 8440c98 | 2015-03-26 23:54:15 +0000 | [diff] [blame] | 3430 | // Sort the identifiers lexicographically before getting them references so | 
|  | 3431 | // that their order is stable. | 
| Benjamin Kramer | cd2bae3 | 2019-08-22 17:32:16 +0000 | [diff] [blame] | 3432 | llvm::sort(IIs, llvm::deref<std::less<>>()); | 
| Chandler Carruth | 8440c98 | 2015-03-26 23:54:15 +0000 | [diff] [blame] | 3433 | for (const IdentifierInfo *II : IIs) | 
| Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 3434 | if (Trait.isInterestingNonMacroIdentifier(II)) | 
|  | 3435 | getIdentifierRef(II); | 
| Douglas Gregor | e6648fb | 2009-04-28 20:33:11 +0000 | [diff] [blame] | 3436 |  | 
| Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 3437 | // Create the on-disk hash table representation. We only store offsets | 
|  | 3438 | // for identifiers that appear here for the first time. | 
|  | 3439 | IdentifierOffsets.resize(NextIdentID - FirstIdentID); | 
| Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 3440 | for (auto IdentIDPair : IdentifierIDs) { | 
| Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3441 | auto *II = const_cast<IdentifierInfo *>(IdentIDPair.first); | 
| Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 3442 | IdentID ID = IdentIDPair.second; | 
|  | 3443 | assert(II && "NULL identifier in identifier table"); | 
| Vassil Vassilev | 262f41e | 2016-03-30 20:16:03 +0000 | [diff] [blame] | 3444 | // Write out identifiers if either the ID is local or the identifier has | 
|  | 3445 | // changed since it was loaded. | 
|  | 3446 | if (ID >= FirstIdentID || !Chain || !II->isFromAST() | 
|  | 3447 | || II->hasChangedSinceDeserialization() || | 
| Richard Smith | d79514e | 2016-02-05 19:03:40 +0000 | [diff] [blame] | 3448 | (Trait.needDecls() && | 
|  | 3449 | II->hasFETokenInfoChangedSinceDeserialization())) | 
| Chandler Carruth | 885e78c | 2015-03-24 21:18:10 +0000 | [diff] [blame] | 3450 | Generator.insert(II, ID, Trait); | 
| Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3451 | } | 
| Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3452 |  | 
| Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3453 | // Create the on-disk hash table in a buffer. | 
| Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3454 | SmallString<4096> IdentifierTable; | 
| Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3455 | uint32_t BucketOffset; | 
| Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3456 | { | 
| Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3457 | using namespace llvm::support; | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3458 |  | 
| Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3459 | llvm::raw_svector_ostream Out(IdentifierTable); | 
| Douglas Gregor | c78d346 | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 3460 | // Make sure that no bucket is at offset 0 | 
| Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 3461 | endian::write<uint32_t>(Out, 0, little); | 
| Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3462 | BucketOffset = Generator.Emit(Out, Trait); | 
| Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3463 | } | 
|  | 3464 |  | 
|  | 3465 | // Create a blob abbreviation | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3466 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); | 
| Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3467 | Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_TABLE)); | 
| Douglas Gregor | a868bbd | 2009-04-21 22:25:48 +0000 | [diff] [blame] | 3468 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); | 
| Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 3469 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3470 | unsigned IDTableAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); | 
| Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3471 |  | 
|  | 3472 | // Write the identifier table | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3473 | RecordData::value_type Record[] = {IDENTIFIER_TABLE, BucketOffset}; | 
| Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 3474 | Stream.EmitRecordWithBlob(IDTableAbbrev, Record, IdentifierTable); | 
| Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3475 | } | 
|  | 3476 |  | 
|  | 3477 | // Write the offsets table for identifier IDs. | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3478 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); | 
| Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3479 | Abbrev->Add(BitCodeAbbrevOp(IDENTIFIER_OFFSET)); | 
| Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3480 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // # of identifiers | 
| Douglas Gregor | 1ab036c | 2011-08-03 21:49:18 +0000 | [diff] [blame] | 3481 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // first ID | 
| Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3482 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 3483 | unsigned IdentifierOffsetAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); | 
| Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3484 |  | 
| Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 3485 | #ifndef NDEBUG | 
|  | 3486 | for (unsigned I = 0, N = IdentifierOffsets.size(); I != N; ++I) | 
|  | 3487 | assert(IdentifierOffsets[I] && "Missing identifier offset?"); | 
|  | 3488 | #endif | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3489 |  | 
|  | 3490 | RecordData::value_type Record[] = {IDENTIFIER_OFFSET, | 
|  | 3491 | IdentifierOffsets.size(), | 
|  | 3492 | FirstIdentID - NUM_PREDEF_IDENT_IDS}; | 
| Douglas Gregor | 0e14997 | 2009-04-25 19:10:14 +0000 | [diff] [blame] | 3493 | Stream.EmitRecordWithBlob(IdentifierOffsetAbbrev, Record, | 
| Reid Kleckner | 012665e | 2015-05-21 00:13:09 +0000 | [diff] [blame] | 3494 | bytes(IdentifierOffsets)); | 
| Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3495 |  | 
|  | 3496 | // In C++, write the list of interesting identifiers (those that are | 
|  | 3497 | // defined as macros, poisoned, or similar unusual things). | 
|  | 3498 | if (!InterestingIdents.empty()) | 
|  | 3499 | Stream.EmitRecord(INTERESTING_IDENTIFIERS, InterestingIdents); | 
| Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 3500 | } | 
|  | 3501 |  | 
| Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 3502 | //===----------------------------------------------------------------------===// | 
| Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3503 | // DeclContext's Name Lookup Table Serialization | 
|  | 3504 | //===----------------------------------------------------------------------===// | 
|  | 3505 |  | 
|  | 3506 | namespace { | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 3507 |  | 
| Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3508 | // Trait used for the on-disk hash table used in the method pool. | 
|  | 3509 | class ASTDeclContextNameLookupTrait { | 
|  | 3510 | ASTWriter &Writer; | 
| Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3511 | llvm::SmallVector<DeclID, 64> DeclIDs; | 
| Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3512 |  | 
|  | 3513 | public: | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3514 | using key_type = DeclarationNameKey; | 
|  | 3515 | using key_type_ref = key_type; | 
| Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3516 |  | 
| Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3517 | /// A start and end index into DeclIDs, representing a sequence of decls. | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3518 | using data_type = std::pair<unsigned, unsigned>; | 
|  | 3519 | using data_type_ref = const data_type &; | 
| Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3520 |  | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3521 | using hash_value_type = unsigned; | 
|  | 3522 | using offset_type = unsigned; | 
| Justin Bogner | 25463f1 | 2014-04-18 20:27:24 +0000 | [diff] [blame] | 3523 |  | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3524 | explicit ASTDeclContextNameLookupTrait(ASTWriter &Writer) : Writer(Writer) {} | 
| Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3525 |  | 
| Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3526 | template<typename Coll> | 
|  | 3527 | data_type getData(const Coll &Decls) { | 
|  | 3528 | unsigned Start = DeclIDs.size(); | 
|  | 3529 | for (NamedDecl *D : Decls) { | 
|  | 3530 | DeclIDs.push_back( | 
|  | 3531 | Writer.GetDeclRef(getDeclForLocalLookup(Writer.getLangOpts(), D))); | 
|  | 3532 | } | 
|  | 3533 | return std::make_pair(Start, DeclIDs.size()); | 
|  | 3534 | } | 
|  | 3535 |  | 
|  | 3536 | data_type ImportData(const reader::ASTDeclContextNameLookupTrait::data_type &FromReader) { | 
|  | 3537 | unsigned Start = DeclIDs.size(); | 
|  | 3538 | for (auto ID : FromReader) | 
|  | 3539 | DeclIDs.push_back(ID); | 
|  | 3540 | return std::make_pair(Start, DeclIDs.size()); | 
|  | 3541 | } | 
|  | 3542 |  | 
|  | 3543 | static bool EqualKey(key_type_ref a, key_type_ref b) { | 
|  | 3544 | return a == b; | 
|  | 3545 | } | 
|  | 3546 |  | 
| Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3547 | hash_value_type ComputeHash(DeclarationNameKey Name) { | 
|  | 3548 | return Name.getHash(); | 
| Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3549 | } | 
|  | 3550 |  | 
| Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3551 | void EmitFileRef(raw_ostream &Out, ModuleFile *F) const { | 
|  | 3552 | assert(Writer.hasChain() && | 
|  | 3553 | "have reference to loaded module file but no chain?"); | 
|  | 3554 |  | 
|  | 3555 | using namespace llvm::support; | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3556 |  | 
| Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 3557 | endian::write<uint32_t>(Out, Writer.getChain()->getModuleFileID(F), little); | 
| Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3558 | } | 
|  | 3559 |  | 
| Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3560 | std::pair<unsigned, unsigned> EmitKeyDataLength(raw_ostream &Out, | 
|  | 3561 | DeclarationNameKey Name, | 
|  | 3562 | data_type_ref Lookup) { | 
| Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3563 | using namespace llvm::support; | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3564 |  | 
| Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 3565 | endian::Writer LE(Out, little); | 
| Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3566 | unsigned KeyLen = 1; | 
| Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3567 | switch (Name.getKind()) { | 
| Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3568 | case DeclarationName::Identifier: | 
|  | 3569 | case DeclarationName::ObjCZeroArgSelector: | 
|  | 3570 | case DeclarationName::ObjCOneArgSelector: | 
|  | 3571 | case DeclarationName::ObjCMultiArgSelector: | 
| Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3572 | case DeclarationName::CXXLiteralOperatorName: | 
| Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 3573 | case DeclarationName::CXXDeductionGuideName: | 
| Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3574 | KeyLen += 4; | 
|  | 3575 | break; | 
|  | 3576 | case DeclarationName::CXXOperatorName: | 
|  | 3577 | KeyLen += 1; | 
|  | 3578 | break; | 
| Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 3579 | case DeclarationName::CXXConstructorName: | 
|  | 3580 | case DeclarationName::CXXDestructorName: | 
|  | 3581 | case DeclarationName::CXXConversionFunctionName: | 
| Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3582 | case DeclarationName::CXXUsingDirective: | 
|  | 3583 | break; | 
|  | 3584 | } | 
| Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3585 | LE.write<uint16_t>(KeyLen); | 
| Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3586 |  | 
| Richard Smith | f02662d | 2015-07-30 03:17:16 +0000 | [diff] [blame] | 3587 | // 4 bytes for each DeclID. | 
| Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3588 | unsigned DataLen = 4 * (Lookup.second - Lookup.first); | 
|  | 3589 | assert(uint16_t(DataLen) == DataLen && | 
|  | 3590 | "too many decls for serialized lookup result"); | 
| Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3591 | LE.write<uint16_t>(DataLen); | 
| Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3592 |  | 
|  | 3593 | return std::make_pair(KeyLen, DataLen); | 
|  | 3594 | } | 
|  | 3595 |  | 
| Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3596 | void EmitKey(raw_ostream &Out, DeclarationNameKey Name, unsigned) { | 
| Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3597 | using namespace llvm::support; | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3598 |  | 
| Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 3599 | endian::Writer LE(Out, little); | 
| Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3600 | LE.write<uint8_t>(Name.getKind()); | 
|  | 3601 | switch (Name.getKind()) { | 
| Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3602 | case DeclarationName::Identifier: | 
| Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3603 | case DeclarationName::CXXLiteralOperatorName: | 
| Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 3604 | case DeclarationName::CXXDeductionGuideName: | 
| Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3605 | LE.write<uint32_t>(Writer.getIdentifierRef(Name.getIdentifier())); | 
| Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3606 | return; | 
| Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3607 | case DeclarationName::ObjCZeroArgSelector: | 
|  | 3608 | case DeclarationName::ObjCOneArgSelector: | 
|  | 3609 | case DeclarationName::ObjCMultiArgSelector: | 
| Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3610 | LE.write<uint32_t>(Writer.getSelectorRef(Name.getSelector())); | 
| Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3611 | return; | 
| Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3612 | case DeclarationName::CXXOperatorName: | 
| Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3613 | assert(Name.getOperatorKind() < NUM_OVERLOADED_OPERATORS && | 
| Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3614 | "Invalid operator?"); | 
| Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3615 | LE.write<uint8_t>(Name.getOperatorKind()); | 
| Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3616 | return; | 
| Douglas Gregor | 3b65ed0 | 2011-08-02 18:32:54 +0000 | [diff] [blame] | 3617 | case DeclarationName::CXXConstructorName: | 
|  | 3618 | case DeclarationName::CXXDestructorName: | 
|  | 3619 | case DeclarationName::CXXConversionFunctionName: | 
| Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3620 | case DeclarationName::CXXUsingDirective: | 
| Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3621 | return; | 
| Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3622 | } | 
| Benjamin Kramer | 53750b1 | 2012-09-19 13:40:40 +0000 | [diff] [blame] | 3623 |  | 
|  | 3624 | llvm_unreachable("Invalid name kind?"); | 
| Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3625 | } | 
|  | 3626 |  | 
| Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 3627 | void EmitData(raw_ostream &Out, key_type_ref, data_type Lookup, | 
|  | 3628 | unsigned DataLen) { | 
| Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 3629 | using namespace llvm::support; | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3630 |  | 
| Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 3631 | endian::Writer LE(Out, little); | 
| Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3632 | uint64_t Start = Out.tell(); (void)Start; | 
| Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3633 | for (unsigned I = Lookup.first, N = Lookup.second; I != N; ++I) | 
|  | 3634 | LE.write<uint32_t>(DeclIDs[I]); | 
| Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3635 | assert(Out.tell() - Start == DataLen && "Data length is wrong"); | 
|  | 3636 | } | 
|  | 3637 | }; | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 3638 |  | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 3639 | } // namespace | 
| Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 3640 |  | 
| Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3641 | bool ASTWriter::isLookupResultExternal(StoredDeclsList &Result, | 
|  | 3642 | DeclContext *DC) { | 
| Erich Keane | f92f31c | 2018-08-01 20:48:16 +0000 | [diff] [blame] | 3643 | return Result.hasExternalDecls() && | 
|  | 3644 | DC->hasNeedToReconcileExternalVisibleStorage(); | 
| Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3645 | } | 
|  | 3646 |  | 
|  | 3647 | bool ASTWriter::isLookupResultEntirelyExternal(StoredDeclsList &Result, | 
|  | 3648 | DeclContext *DC) { | 
|  | 3649 | for (auto *D : Result.getLookupResult()) | 
|  | 3650 | if (!getDeclForLocalLookup(getLangOpts(), D)->isFromASTFile()) | 
|  | 3651 | return false; | 
|  | 3652 |  | 
|  | 3653 | return true; | 
|  | 3654 | } | 
|  | 3655 |  | 
| Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3656 | void | 
| Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3657 | ASTWriter::GenerateNameLookupTable(const DeclContext *ConstDC, | 
| Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3658 | llvm::SmallVectorImpl<char> &LookupTable) { | 
| Erich Keane | f92f31c | 2018-08-01 20:48:16 +0000 | [diff] [blame] | 3659 | assert(!ConstDC->hasLazyLocalLexicalLookups() && | 
|  | 3660 | !ConstDC->hasLazyExternalLexicalLookups() && | 
| Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 3661 | "must call buildLookups first"); | 
| Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3662 |  | 
| Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3663 | // FIXME: We need to build the lookups table, which is logically const. | 
| Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3664 | auto *DC = const_cast<DeclContext*>(ConstDC); | 
| Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3665 | assert(DC == DC->getPrimaryContext() && "only primary DC has lookup table"); | 
|  | 3666 |  | 
|  | 3667 | // Create the on-disk hash table representation. | 
| Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3668 | MultiOnDiskHashTableGenerator<reader::ASTDeclContextNameLookupTrait, | 
|  | 3669 | ASTDeclContextNameLookupTrait> Generator; | 
| Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3670 | ASTDeclContextNameLookupTrait Trait(*this); | 
|  | 3671 |  | 
| Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3672 | // The first step is to collect the declaration names which we need to | 
|  | 3673 | // serialize into the name lookup table, and to collect them in a stable | 
|  | 3674 | // order. | 
|  | 3675 | SmallVector<DeclarationName, 16> Names; | 
| Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3676 |  | 
| Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3677 | // We also build up small sets of the constructor and conversion function | 
|  | 3678 | // names which are visible. | 
|  | 3679 | llvm::SmallSet<DeclarationName, 8> ConstructorNameSet, ConversionNameSet; | 
| Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3680 |  | 
| Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3681 | for (auto &Lookup : *DC->buildLookup()) { | 
|  | 3682 | auto &Name = Lookup.first; | 
|  | 3683 | auto &Result = Lookup.second; | 
|  | 3684 |  | 
| Douglas Gregor | 7dd37e5 | 2015-11-03 01:20:54 +0000 | [diff] [blame] | 3685 | // If there are no local declarations in our lookup result, we | 
|  | 3686 | // don't need to write an entry for the name at all. If we can't | 
|  | 3687 | // write out a lookup set without performing more deserialization, | 
|  | 3688 | // just skip this entry. | 
|  | 3689 | if (isLookupResultExternal(Result, DC) && | 
| Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3690 | isLookupResultEntirelyExternal(Result, DC)) | 
|  | 3691 | continue; | 
|  | 3692 |  | 
|  | 3693 | // We also skip empty results. If any of the results could be external and | 
|  | 3694 | // the currently available results are empty, then all of the results are | 
|  | 3695 | // external and we skip it above. So the only way we get here with an empty | 
|  | 3696 | // results is when no results could have been external *and* we have | 
|  | 3697 | // external results. | 
|  | 3698 | // | 
|  | 3699 | // FIXME: While we might want to start emitting on-disk entries for negative | 
|  | 3700 | // lookups into a decl context as an optimization, today we *have* to skip | 
|  | 3701 | // them because there are names with empty lookup results in decl contexts | 
|  | 3702 | // which we can't emit in any stable ordering: we lookup constructors and | 
|  | 3703 | // conversion functions in the enclosing namespace scope creating empty | 
|  | 3704 | // results for them. This in almost certainly a bug in Clang's name lookup, | 
|  | 3705 | // but that is likely to be hard or impossible to fix and so we tolerate it | 
|  | 3706 | // here by omitting lookups with empty results. | 
|  | 3707 | if (Lookup.second.getLookupResult().empty()) | 
|  | 3708 | continue; | 
|  | 3709 |  | 
|  | 3710 | switch (Lookup.first.getNameKind()) { | 
|  | 3711 | default: | 
|  | 3712 | Names.push_back(Lookup.first); | 
|  | 3713 | break; | 
|  | 3714 |  | 
| Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3715 | case DeclarationName::CXXConstructorName: | 
| Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3716 | assert(isa<CXXRecordDecl>(DC) && | 
|  | 3717 | "Cannot have a constructor name outside of a class!"); | 
|  | 3718 | ConstructorNameSet.insert(Name); | 
|  | 3719 | break; | 
| Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3720 |  | 
|  | 3721 | case DeclarationName::CXXConversionFunctionName: | 
| Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3722 | assert(isa<CXXRecordDecl>(DC) && | 
|  | 3723 | "Cannot have a conversion function name outside of a class!"); | 
|  | 3724 | ConversionNameSet.insert(Name); | 
| Rafael Espindola | c606b3e | 2015-03-25 04:43:15 +0000 | [diff] [blame] | 3725 | break; | 
| Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3726 | } | 
| Chandler Carruth | 75c9f13 | 2015-03-25 00:34:51 +0000 | [diff] [blame] | 3727 | } | 
| Chandler Carruth | 75c9f13 | 2015-03-25 00:34:51 +0000 | [diff] [blame] | 3728 |  | 
| Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3729 | // Sort the names into a stable order. | 
| Fangrui Song | 55fab26 | 2018-09-26 22:16:28 +0000 | [diff] [blame] | 3730 | llvm::sort(Names); | 
| Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3731 |  | 
| Chandler Carruth | ffbf705 | 2015-03-26 22:27:09 +0000 | [diff] [blame] | 3732 | if (auto *D = dyn_cast<CXXRecordDecl>(DC)) { | 
| Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3733 | // We need to establish an ordering of constructor and conversion function | 
| Chandler Carruth | ffbf705 | 2015-03-26 22:27:09 +0000 | [diff] [blame] | 3734 | // names, and they don't have an intrinsic ordering. | 
| Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3735 |  | 
| Chandler Carruth | ffbf705 | 2015-03-26 22:27:09 +0000 | [diff] [blame] | 3736 | // First we try the easy case by forming the current context's constructor | 
|  | 3737 | // name and adding that name first. This is a very useful optimization to | 
|  | 3738 | // avoid walking the lexical declarations in many cases, and it also | 
|  | 3739 | // handles the only case where a constructor name can come from some other | 
|  | 3740 | // lexical context -- when that name is an implicit constructor merged from | 
|  | 3741 | // another declaration in the redecl chain. Any non-implicit constructor or | 
|  | 3742 | // conversion function which doesn't occur in all the lexical contexts | 
|  | 3743 | // would be an ODR violation. | 
|  | 3744 | auto ImplicitCtorName = Context->DeclarationNames.getCXXConstructorName( | 
|  | 3745 | Context->getCanonicalType(Context->getRecordType(D))); | 
|  | 3746 | if (ConstructorNameSet.erase(ImplicitCtorName)) | 
|  | 3747 | Names.push_back(ImplicitCtorName); | 
| Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3748 |  | 
| Chandler Carruth | ffbf705 | 2015-03-26 22:27:09 +0000 | [diff] [blame] | 3749 | // If we still have constructors or conversion functions, we walk all the | 
|  | 3750 | // names in the decl and add the constructors and conversion functions | 
|  | 3751 | // which are visible in the order they lexically occur within the context. | 
|  | 3752 | if (!ConstructorNameSet.empty() || !ConversionNameSet.empty()) | 
|  | 3753 | for (Decl *ChildD : cast<CXXRecordDecl>(DC)->decls()) | 
|  | 3754 | if (auto *ChildND = dyn_cast<NamedDecl>(ChildD)) { | 
|  | 3755 | auto Name = ChildND->getDeclName(); | 
|  | 3756 | switch (Name.getNameKind()) { | 
|  | 3757 | default: | 
|  | 3758 | continue; | 
|  | 3759 |  | 
|  | 3760 | case DeclarationName::CXXConstructorName: | 
|  | 3761 | if (ConstructorNameSet.erase(Name)) | 
|  | 3762 | Names.push_back(Name); | 
|  | 3763 | break; | 
|  | 3764 |  | 
|  | 3765 | case DeclarationName::CXXConversionFunctionName: | 
|  | 3766 | if (ConversionNameSet.erase(Name)) | 
|  | 3767 | Names.push_back(Name); | 
|  | 3768 | break; | 
|  | 3769 | } | 
|  | 3770 |  | 
|  | 3771 | if (ConstructorNameSet.empty() && ConversionNameSet.empty()) | 
|  | 3772 | break; | 
| Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3773 | } | 
|  | 3774 |  | 
| Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3775 | assert(ConstructorNameSet.empty() && "Failed to find all of the visible " | 
|  | 3776 | "constructors by walking all the " | 
|  | 3777 | "lexical members of the context."); | 
|  | 3778 | assert(ConversionNameSet.empty() && "Failed to find all of the visible " | 
|  | 3779 | "conversion functions by walking all " | 
|  | 3780 | "the lexical members of the context."); | 
| Richard Smith | 961eae5 | 2014-03-25 01:14:22 +0000 | [diff] [blame] | 3781 | } | 
|  | 3782 |  | 
| Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3783 | // Next we need to do a lookup with each name into this decl context to fully | 
|  | 3784 | // populate any results from external sources. We don't actually use the | 
|  | 3785 | // results of these lookups because we only want to use the results after all | 
|  | 3786 | // results have been loaded and the pointers into them will be stable. | 
|  | 3787 | for (auto &Name : Names) | 
|  | 3788 | DC->lookup(Name); | 
|  | 3789 |  | 
|  | 3790 | // Now we need to insert the results for each name into the hash table. For | 
|  | 3791 | // constructor names and conversion function names, we actually need to merge | 
|  | 3792 | // all of the results for them into one list of results each and insert | 
|  | 3793 | // those. | 
|  | 3794 | SmallVector<NamedDecl *, 8> ConstructorDecls; | 
|  | 3795 | SmallVector<NamedDecl *, 8> ConversionDecls; | 
|  | 3796 |  | 
|  | 3797 | // Now loop over the names, either inserting them or appending for the two | 
|  | 3798 | // special cases. | 
|  | 3799 | for (auto &Name : Names) { | 
|  | 3800 | DeclContext::lookup_result Result = DC->noload_lookup(Name); | 
|  | 3801 |  | 
|  | 3802 | switch (Name.getNameKind()) { | 
|  | 3803 | default: | 
| Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3804 | Generator.insert(Name, Trait.getData(Result), Trait); | 
| Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3805 | break; | 
|  | 3806 |  | 
|  | 3807 | case DeclarationName::CXXConstructorName: | 
|  | 3808 | ConstructorDecls.append(Result.begin(), Result.end()); | 
|  | 3809 | break; | 
|  | 3810 |  | 
|  | 3811 | case DeclarationName::CXXConversionFunctionName: | 
|  | 3812 | ConversionDecls.append(Result.begin(), Result.end()); | 
|  | 3813 | break; | 
|  | 3814 | } | 
|  | 3815 | } | 
|  | 3816 |  | 
|  | 3817 | // Handle our two special cases if we ended up having any. We arbitrarily use | 
|  | 3818 | // the first declaration's name here because the name itself isn't part of | 
|  | 3819 | // the key, only the kind of name is used. | 
|  | 3820 | if (!ConstructorDecls.empty()) | 
|  | 3821 | Generator.insert(ConstructorDecls.front()->getDeclName(), | 
| Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3822 | Trait.getData(ConstructorDecls), Trait); | 
| Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3823 | if (!ConversionDecls.empty()) | 
|  | 3824 | Generator.insert(ConversionDecls.front()->getDeclName(), | 
| Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3825 | Trait.getData(ConversionDecls), Trait); | 
| Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3826 |  | 
| Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3827 | // Create the on-disk hash table. Also emit the existing imported and | 
|  | 3828 | // merged table if there is one. | 
|  | 3829 | auto *Lookups = Chain ? Chain->getLoadedLookupTables(DC) : nullptr; | 
|  | 3830 | Generator.emit(LookupTable, Trait, Lookups ? &Lookups->Table : nullptr); | 
| Richard Smith | 961eae5 | 2014-03-25 01:14:22 +0000 | [diff] [blame] | 3831 | } | 
|  | 3832 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3833 | /// Write the block containing all of the declaration IDs | 
| Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3834 | /// visible from the given DeclContext. | 
|  | 3835 | /// | 
|  | 3836 | /// \returns the offset of the DECL_CONTEXT_VISIBLE block within the | 
| Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3837 | /// bitstream, or 0 if no block was written. | 
| Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3838 | uint64_t ASTWriter::WriteDeclContextVisibleBlock(ASTContext &Context, | 
|  | 3839 | DeclContext *DC) { | 
| Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 3840 | // If we imported a key declaration of this namespace, write the visible | 
|  | 3841 | // lookup results as an update record for it rather than including them | 
|  | 3842 | // on this declaration. We will only look at key declarations on reload. | 
|  | 3843 | if (isa<NamespaceDecl>(DC) && Chain && | 
|  | 3844 | Chain->getKeyDeclaration(cast<Decl>(DC))->isFromASTFile()) { | 
|  | 3845 | // Only do this once, for the first local declaration of the namespace. | 
| Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 3846 | for (auto *Prev = cast<NamespaceDecl>(DC)->getPreviousDecl(); Prev; | 
| Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 3847 | Prev = Prev->getPreviousDecl()) | 
|  | 3848 | if (!Prev->isFromASTFile()) | 
|  | 3849 | return 0; | 
|  | 3850 |  | 
|  | 3851 | // Note that we need to emit an update record for the primary context. | 
|  | 3852 | UpdatedDeclContexts.insert(DC->getPrimaryContext()); | 
|  | 3853 |  | 
|  | 3854 | // Make sure all visible decls are written. They will be recorded later. We | 
|  | 3855 | // do this using a side data structure so we can sort the names into | 
|  | 3856 | // a deterministic order. | 
|  | 3857 | StoredDeclsMap *Map = DC->getPrimaryContext()->buildLookup(); | 
|  | 3858 | SmallVector<std::pair<DeclarationName, DeclContext::lookup_result>, 16> | 
|  | 3859 | LookupResults; | 
|  | 3860 | if (Map) { | 
|  | 3861 | LookupResults.reserve(Map->size()); | 
|  | 3862 | for (auto &Entry : *Map) | 
|  | 3863 | LookupResults.push_back( | 
|  | 3864 | std::make_pair(Entry.first, Entry.second.getLookupResult())); | 
|  | 3865 | } | 
|  | 3866 |  | 
| Fangrui Song | 55fab26 | 2018-09-26 22:16:28 +0000 | [diff] [blame] | 3867 | llvm::sort(LookupResults, llvm::less_first()); | 
| Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 3868 | for (auto &NameAndResult : LookupResults) { | 
|  | 3869 | DeclarationName Name = NameAndResult.first; | 
|  | 3870 | DeclContext::lookup_result Result = NameAndResult.second; | 
|  | 3871 | if (Name.getNameKind() == DeclarationName::CXXConstructorName || | 
|  | 3872 | Name.getNameKind() == DeclarationName::CXXConversionFunctionName) { | 
|  | 3873 | // We have to work around a name lookup bug here where negative lookup | 
|  | 3874 | // results for these names get cached in namespace lookup tables (these | 
|  | 3875 | // names should never be looked up in a namespace). | 
|  | 3876 | assert(Result.empty() && "Cannot have a constructor or conversion " | 
|  | 3877 | "function name in a namespace!"); | 
|  | 3878 | continue; | 
|  | 3879 | } | 
|  | 3880 |  | 
|  | 3881 | for (NamedDecl *ND : Result) | 
|  | 3882 | if (!ND->isFromASTFile()) | 
|  | 3883 | GetDeclRef(ND); | 
|  | 3884 | } | 
|  | 3885 |  | 
|  | 3886 | return 0; | 
|  | 3887 | } | 
|  | 3888 |  | 
| Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3889 | if (DC->getPrimaryContext() != DC) | 
|  | 3890 | return 0; | 
|  | 3891 |  | 
| Chandler Carruth | e972c36 | 2015-03-26 03:11:40 +0000 | [diff] [blame] | 3892 | // Skip contexts which don't support name lookup. | 
|  | 3893 | if (!DC->isLookupContext()) | 
| Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3894 | return 0; | 
|  | 3895 |  | 
|  | 3896 | // If not in C++, we perform name lookup for the translation unit via the | 
|  | 3897 | // IdentifierInfo chains, don't bother to build a visible-declarations table. | 
| David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 3898 | if (DC->isTranslationUnit() && !Context.getLangOpts().CPlusPlus) | 
| Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3899 | return 0; | 
|  | 3900 |  | 
| Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3901 | // Serialize the contents of the mapping used for lookup. Note that, | 
|  | 3902 | // although we have two very different code paths, the serialized | 
|  | 3903 | // representation is the same for both cases: a declaration name, | 
|  | 3904 | // followed by a size, followed by references to the visible | 
|  | 3905 | // declarations that have that name. | 
|  | 3906 | uint64_t Offset = Stream.GetCurrentBitNo(); | 
| Richard Smith | f634c90 | 2012-03-16 06:12:59 +0000 | [diff] [blame] | 3907 | StoredDeclsMap *Map = DC->buildLookup(); | 
| Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3908 | if (!Map || Map->empty()) | 
|  | 3909 | return 0; | 
|  | 3910 |  | 
| Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3911 | // Create the on-disk hash table in a buffer. | 
| Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3912 | SmallString<4096> LookupTable; | 
| Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3913 | GenerateNameLookupTable(DC, LookupTable); | 
| Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3914 |  | 
|  | 3915 | // Write the lookup table | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3916 | RecordData::value_type Record[] = {DECL_CONTEXT_VISIBLE}; | 
| Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3917 | Stream.EmitRecordWithBlob(DeclContextVisibleLookupAbbrev, Record, | 
| Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 3918 | LookupTable); | 
| Argyrios Kyrtzidis | ba88bfa | 2010-08-20 16:04:35 +0000 | [diff] [blame] | 3919 | ++NumVisibleDeclContexts; | 
|  | 3920 | return Offset; | 
|  | 3921 | } | 
|  | 3922 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3923 | /// Write an UPDATE_VISIBLE block for the given context. | 
| Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3924 | /// | 
|  | 3925 | /// UPDATE_VISIBLE blocks contain the declarations that are added to an existing | 
|  | 3926 | /// DeclContext in a dependent AST file. As such, they only exist for the TU | 
| Richard Smith | f634c90 | 2012-03-16 06:12:59 +0000 | [diff] [blame] | 3927 | /// (in C++), for namespaces, and for classes with forward-declared unscoped | 
|  | 3928 | /// enumeration members (in C++11). | 
| Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3929 | void ASTWriter::WriteDeclContextVisibleUpdate(const DeclContext *DC) { | 
| Richard Smith | 961eae5 | 2014-03-25 01:14:22 +0000 | [diff] [blame] | 3930 | StoredDeclsMap *Map = DC->getLookupPtr(); | 
| Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3931 | if (!Map || Map->empty()) | 
|  | 3932 | return; | 
|  | 3933 |  | 
| Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3934 | // Create the on-disk hash table in a buffer. | 
| Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 3935 | SmallString<4096> LookupTable; | 
| Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 3936 | GenerateNameLookupTable(DC, LookupTable); | 
| Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3937 |  | 
| Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 3938 | // If we're updating a namespace, select a key declaration as the key for the | 
|  | 3939 | // update record; those are the only ones that will be checked on reload. | 
|  | 3940 | if (isa<NamespaceDecl>(DC)) | 
|  | 3941 | DC = cast<DeclContext>(Chain->getKeyDeclaration(cast<Decl>(DC))); | 
|  | 3942 |  | 
| Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3943 | // Write the lookup table | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 3944 | RecordData::value_type Record[] = {UPDATE_VISIBLE, getDeclID(cast<Decl>(DC))}; | 
| Yaron Keren | 92e1b62 | 2015-03-18 10:17:07 +0000 | [diff] [blame] | 3945 | Stream.EmitRecordWithBlob(UpdateVisibleAbbrev, Record, LookupTable); | 
| Sebastian Redl | a4071b4 | 2010-08-24 00:50:09 +0000 | [diff] [blame] | 3946 | } | 
|  | 3947 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3948 | /// Write an FP_PRAGMA_OPTIONS block for the given FPOptions. | 
| Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3949 | void ASTWriter::WriteFPPragmaOptions(const FPOptions &Opts) { | 
| Melanie Blower | 2ba4e3a | 2020-04-10 13:34:46 -0700 | [diff] [blame] | 3950 | RecordData::value_type Record[] = {Opts.getAsOpaqueInt()}; | 
| Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3951 | Stream.EmitRecord(FP_PRAGMA_OPTIONS, Record); | 
|  | 3952 | } | 
|  | 3953 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3954 | /// Write an OPENCL_EXTENSIONS block for the given OpenCLOptions. | 
| Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3955 | void ASTWriter::WriteOpenCLExtensions(Sema &SemaRef) { | 
| David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 3956 | if (!SemaRef.Context.getLangOpts().OpenCL) | 
| Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3957 | return; | 
|  | 3958 |  | 
|  | 3959 | const OpenCLOptions &Opts = SemaRef.getOpenCLOptions(); | 
|  | 3960 | RecordData Record; | 
| Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 3961 | for (const auto &I:Opts.OptMap) { | 
|  | 3962 | AddString(I.getKey(), Record); | 
|  | 3963 | auto V = I.getValue(); | 
| Yaxun Liu | cc2741c | 2016-12-18 06:35:06 +0000 | [diff] [blame] | 3964 | Record.push_back(V.Supported ? 1 : 0); | 
|  | 3965 | Record.push_back(V.Enabled ? 1 : 0); | 
| Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 3966 | Record.push_back(V.Avail); | 
|  | 3967 | Record.push_back(V.Core); | 
|  | 3968 | } | 
| Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 3969 | Stream.EmitRecord(OPENCL_EXTENSIONS, Record); | 
|  | 3970 | } | 
|  | 3971 |  | 
| Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 3972 | void ASTWriter::WriteOpenCLExtensionTypes(Sema &SemaRef) { | 
|  | 3973 | if (!SemaRef.Context.getLangOpts().OpenCL) | 
|  | 3974 | return; | 
|  | 3975 |  | 
| Bruno Ricci | 2751b69 | 2019-04-18 15:13:27 +0000 | [diff] [blame] | 3976 | // Sort the elements of the map OpenCLTypeExtMap by TypeIDs, | 
|  | 3977 | // without copying them. | 
|  | 3978 | const llvm::DenseMap<const Type *, std::set<std::string>> &OpenCLTypeExtMap = | 
|  | 3979 | SemaRef.OpenCLTypeExtMap; | 
|  | 3980 | using ElementTy = std::pair<TypeID, const std::set<std::string> *>; | 
|  | 3981 | llvm::SmallVector<ElementTy, 8> StableOpenCLTypeExtMap; | 
|  | 3982 | StableOpenCLTypeExtMap.reserve(OpenCLTypeExtMap.size()); | 
|  | 3983 |  | 
|  | 3984 | for (const auto &I : OpenCLTypeExtMap) | 
|  | 3985 | StableOpenCLTypeExtMap.emplace_back( | 
|  | 3986 | getTypeID(I.first->getCanonicalTypeInternal()), &I.second); | 
|  | 3987 |  | 
|  | 3988 | auto CompareByTypeID = [](const ElementTy &E1, const ElementTy &E2) -> bool { | 
|  | 3989 | return E1.first < E2.first; | 
|  | 3990 | }; | 
|  | 3991 | llvm::sort(StableOpenCLTypeExtMap, CompareByTypeID); | 
|  | 3992 |  | 
| Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 3993 | RecordData Record; | 
| Bruno Ricci | 2751b69 | 2019-04-18 15:13:27 +0000 | [diff] [blame] | 3994 | for (const ElementTy &E : StableOpenCLTypeExtMap) { | 
|  | 3995 | Record.push_back(E.first); // TypeID | 
|  | 3996 | const std::set<std::string> *ExtSet = E.second; | 
|  | 3997 | Record.push_back(static_cast<unsigned>(ExtSet->size())); | 
|  | 3998 | for (const std::string &Ext : *ExtSet) | 
| Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 3999 | AddString(Ext, Record); | 
|  | 4000 | } | 
| Bruno Ricci | 2751b69 | 2019-04-18 15:13:27 +0000 | [diff] [blame] | 4001 |  | 
| Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 4002 | Stream.EmitRecord(OPENCL_EXTENSION_TYPES, Record); | 
|  | 4003 | } | 
|  | 4004 |  | 
|  | 4005 | void ASTWriter::WriteOpenCLExtensionDecls(Sema &SemaRef) { | 
|  | 4006 | if (!SemaRef.Context.getLangOpts().OpenCL) | 
|  | 4007 | return; | 
|  | 4008 |  | 
| Bruno Ricci | 2751b69 | 2019-04-18 15:13:27 +0000 | [diff] [blame] | 4009 | // Sort the elements of the map OpenCLDeclExtMap by DeclIDs, | 
|  | 4010 | // without copying them. | 
|  | 4011 | const llvm::DenseMap<const Decl *, std::set<std::string>> &OpenCLDeclExtMap = | 
|  | 4012 | SemaRef.OpenCLDeclExtMap; | 
|  | 4013 | using ElementTy = std::pair<DeclID, const std::set<std::string> *>; | 
|  | 4014 | llvm::SmallVector<ElementTy, 8> StableOpenCLDeclExtMap; | 
|  | 4015 | StableOpenCLDeclExtMap.reserve(OpenCLDeclExtMap.size()); | 
|  | 4016 |  | 
|  | 4017 | for (const auto &I : OpenCLDeclExtMap) | 
|  | 4018 | StableOpenCLDeclExtMap.emplace_back(getDeclID(I.first), &I.second); | 
|  | 4019 |  | 
|  | 4020 | auto CompareByDeclID = [](const ElementTy &E1, const ElementTy &E2) -> bool { | 
|  | 4021 | return E1.first < E2.first; | 
|  | 4022 | }; | 
|  | 4023 | llvm::sort(StableOpenCLDeclExtMap, CompareByDeclID); | 
|  | 4024 |  | 
| Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 4025 | RecordData Record; | 
| Bruno Ricci | 2751b69 | 2019-04-18 15:13:27 +0000 | [diff] [blame] | 4026 | for (const ElementTy &E : StableOpenCLDeclExtMap) { | 
|  | 4027 | Record.push_back(E.first); // DeclID | 
|  | 4028 | const std::set<std::string> *ExtSet = E.second; | 
|  | 4029 | Record.push_back(static_cast<unsigned>(ExtSet->size())); | 
|  | 4030 | for (const std::string &Ext : *ExtSet) | 
| Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 4031 | AddString(Ext, Record); | 
|  | 4032 | } | 
| Bruno Ricci | 2751b69 | 2019-04-18 15:13:27 +0000 | [diff] [blame] | 4033 |  | 
| Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 4034 | Stream.EmitRecord(OPENCL_EXTENSION_DECLS, Record); | 
|  | 4035 | } | 
|  | 4036 |  | 
| Justin Lebar | 67a78a6 | 2016-10-08 22:15:58 +0000 | [diff] [blame] | 4037 | void ASTWriter::WriteCUDAPragmas(Sema &SemaRef) { | 
|  | 4038 | if (SemaRef.ForceCUDAHostDeviceDepth > 0) { | 
|  | 4039 | RecordData::value_type Record[] = {SemaRef.ForceCUDAHostDeviceDepth}; | 
|  | 4040 | Stream.EmitRecord(CUDA_PRAGMA_FORCE_HOST_DEVICE_DEPTH, Record); | 
|  | 4041 | } | 
|  | 4042 | } | 
|  | 4043 |  | 
| Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4044 | void ASTWriter::WriteObjCCategories() { | 
| Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 4045 | SmallVector<ObjCCategoriesInfo, 2> CategoriesMap; | 
| Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4046 | RecordData Categories; | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 4047 |  | 
| Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4048 | for (unsigned I = 0, N = ObjCClassesWithCategories.size(); I != N; ++I) { | 
|  | 4049 | unsigned Size = 0; | 
|  | 4050 | unsigned StartIndex = Categories.size(); | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 4051 |  | 
| Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4052 | ObjCInterfaceDecl *Class = ObjCClassesWithCategories[I]; | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 4053 |  | 
| Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4054 | // Allocate space for the size. | 
|  | 4055 | Categories.push_back(0); | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 4056 |  | 
| Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4057 | // Add the categories. | 
| Douglas Gregor | 048fbfa | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 4058 | for (ObjCInterfaceDecl::known_categories_iterator | 
|  | 4059 | Cat = Class->known_categories_begin(), | 
|  | 4060 | CatEnd = Class->known_categories_end(); | 
|  | 4061 | Cat != CatEnd; ++Cat, ++Size) { | 
|  | 4062 | assert(getDeclID(*Cat) != 0 && "Bogus category"); | 
|  | 4063 | AddDeclRef(*Cat, Categories); | 
| Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4064 | } | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 4065 |  | 
| Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4066 | // Update the size. | 
|  | 4067 | Categories[StartIndex] = Size; | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 4068 |  | 
| Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4069 | // Record this interface -> category map. | 
|  | 4070 | ObjCCategoriesInfo CatInfo = { getDeclID(Class), StartIndex }; | 
|  | 4071 | CategoriesMap.push_back(CatInfo); | 
|  | 4072 | } | 
|  | 4073 |  | 
|  | 4074 | // Sort the categories map by the definition ID, since the reader will be | 
|  | 4075 | // performing binary searches on this information. | 
|  | 4076 | llvm::array_pod_sort(CategoriesMap.begin(), CategoriesMap.end()); | 
|  | 4077 |  | 
|  | 4078 | // Emit the categories map. | 
|  | 4079 | using namespace llvm; | 
| Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4080 |  | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4081 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); | 
| Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4082 | Abbrev->Add(BitCodeAbbrevOp(OBJC_CATEGORIES_MAP)); | 
|  | 4083 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // # of entries | 
|  | 4084 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4085 | unsigned AbbrevID = Stream.EmitAbbrev(std::move(Abbrev)); | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4086 |  | 
|  | 4087 | RecordData::value_type Record[] = {OBJC_CATEGORIES_MAP, CategoriesMap.size()}; | 
|  | 4088 | Stream.EmitRecordWithBlob(AbbrevID, Record, | 
|  | 4089 | reinterpret_cast<char *>(CategoriesMap.data()), | 
| Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4090 | CategoriesMap.size() * sizeof(ObjCCategoriesInfo)); | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4091 |  | 
| Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4092 | // Emit the category lists. | 
|  | 4093 | Stream.EmitRecord(OBJC_CATEGORIES, Categories); | 
|  | 4094 | } | 
|  | 4095 |  | 
| Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 4096 | void ASTWriter::WriteLateParsedTemplates(Sema &SemaRef) { | 
|  | 4097 | Sema::LateParsedTemplateMapT &LPTMap = SemaRef.LateParsedTemplateMap; | 
|  | 4098 |  | 
|  | 4099 | if (LPTMap.empty()) | 
|  | 4100 | return; | 
|  | 4101 |  | 
|  | 4102 | RecordData Record; | 
| Justin Lebar | 28f09c5 | 2016-10-10 16:26:08 +0000 | [diff] [blame] | 4103 | for (auto &LPTMapEntry : LPTMap) { | 
| Chandler Carruth | 52cee4d | 2015-03-26 09:08:15 +0000 | [diff] [blame] | 4104 | const FunctionDecl *FD = LPTMapEntry.first; | 
| Justin Lebar | 28f09c5 | 2016-10-10 16:26:08 +0000 | [diff] [blame] | 4105 | LateParsedTemplate &LPT = *LPTMapEntry.second; | 
| Chandler Carruth | 52cee4d | 2015-03-26 09:08:15 +0000 | [diff] [blame] | 4106 | AddDeclRef(FD, Record); | 
| Justin Lebar | 28f09c5 | 2016-10-10 16:26:08 +0000 | [diff] [blame] | 4107 | AddDeclRef(LPT.D, Record); | 
|  | 4108 | Record.push_back(LPT.Toks.size()); | 
| Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 4109 |  | 
| Justin Lebar | 28f09c5 | 2016-10-10 16:26:08 +0000 | [diff] [blame] | 4110 | for (const auto &Tok : LPT.Toks) { | 
| Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4111 | AddToken(Tok, Record); | 
| Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 4112 | } | 
|  | 4113 | } | 
|  | 4114 | Stream.EmitRecord(LATE_PARSED_TEMPLATE, Record); | 
|  | 4115 | } | 
|  | 4116 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4117 | /// Write the state of 'pragma clang optimize' at the end of the module. | 
| Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 4118 | void ASTWriter::WriteOptimizePragmaOptions(Sema &SemaRef) { | 
|  | 4119 | RecordData Record; | 
|  | 4120 | SourceLocation PragmaLoc = SemaRef.getOptimizeOffPragmaLocation(); | 
|  | 4121 | AddSourceLocation(PragmaLoc, Record); | 
|  | 4122 | Stream.EmitRecord(OPTIMIZE_PRAGMA_OPTIONS, Record); | 
|  | 4123 | } | 
|  | 4124 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4125 | /// Write the state of 'pragma ms_struct' at the end of the module. | 
| Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 4126 | void ASTWriter::WriteMSStructPragmaOptions(Sema &SemaRef) { | 
|  | 4127 | RecordData Record; | 
|  | 4128 | Record.push_back(SemaRef.MSStructPragmaOn ? PMSST_ON : PMSST_OFF); | 
|  | 4129 | Stream.EmitRecord(MSSTRUCT_PRAGMA_OPTIONS, Record); | 
|  | 4130 | } | 
|  | 4131 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4132 | /// Write the state of 'pragma pointers_to_members' at the end of the | 
| Nico Weber | 4293231 | 2016-03-03 00:17:35 +0000 | [diff] [blame] | 4133 | //module. | 
|  | 4134 | void ASTWriter::WriteMSPointersToMembersPragmaOptions(Sema &SemaRef) { | 
|  | 4135 | RecordData Record; | 
|  | 4136 | Record.push_back(SemaRef.MSPointerToMemberRepresentationMethod); | 
|  | 4137 | AddSourceLocation(SemaRef.ImplicitMSInheritanceAttrLoc, Record); | 
|  | 4138 | Stream.EmitRecord(POINTERS_TO_MEMBERS_PRAGMA_OPTIONS, Record); | 
|  | 4139 | } | 
|  | 4140 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4141 | /// Write the state of 'pragma pack' at the end of the module. | 
| Alex Lorenz | 7d7e1e0 | 2017-03-31 15:36:21 +0000 | [diff] [blame] | 4142 | void ASTWriter::WritePackPragmaOptions(Sema &SemaRef) { | 
| Duncan P. N. Exon Smith | 03df14c | 2017-04-15 00:07:57 +0000 | [diff] [blame] | 4143 | // Don't serialize pragma pack state for modules, since it should only take | 
|  | 4144 | // effect on a per-submodule basis. | 
|  | 4145 | if (WritingModule) | 
|  | 4146 | return; | 
|  | 4147 |  | 
| Alex Lorenz | 7d7e1e0 | 2017-03-31 15:36:21 +0000 | [diff] [blame] | 4148 | RecordData Record; | 
|  | 4149 | Record.push_back(SemaRef.PackStack.CurrentValue); | 
|  | 4150 | AddSourceLocation(SemaRef.PackStack.CurrentPragmaLocation, Record); | 
|  | 4151 | Record.push_back(SemaRef.PackStack.Stack.size()); | 
|  | 4152 | for (const auto &StackEntry : SemaRef.PackStack.Stack) { | 
|  | 4153 | Record.push_back(StackEntry.Value); | 
|  | 4154 | AddSourceLocation(StackEntry.PragmaLocation, Record); | 
| Alex Lorenz | 45b4014 | 2017-07-28 14:41:21 +0000 | [diff] [blame] | 4155 | AddSourceLocation(StackEntry.PragmaPushLocation, Record); | 
| Alex Lorenz | 7d7e1e0 | 2017-03-31 15:36:21 +0000 | [diff] [blame] | 4156 | AddString(StackEntry.StackSlotLabel, Record); | 
|  | 4157 | } | 
|  | 4158 | Stream.EmitRecord(PACK_PRAGMA_OPTIONS, Record); | 
|  | 4159 | } | 
|  | 4160 |  | 
| Melanie Blower | f5360d4 | 2020-05-01 10:32:06 -0700 | [diff] [blame] | 4161 | /// Write the state of 'pragma float_control' at the end of the module. | 
|  | 4162 | void ASTWriter::WriteFloatControlPragmaOptions(Sema &SemaRef) { | 
|  | 4163 | // Don't serialize pragma float_control state for modules, | 
|  | 4164 | // since it should only take effect on a per-submodule basis. | 
|  | 4165 | if (WritingModule) | 
|  | 4166 | return; | 
|  | 4167 |  | 
|  | 4168 | RecordData Record; | 
|  | 4169 | Record.push_back(SemaRef.FpPragmaStack.CurrentValue); | 
|  | 4170 | AddSourceLocation(SemaRef.FpPragmaStack.CurrentPragmaLocation, Record); | 
|  | 4171 | Record.push_back(SemaRef.FpPragmaStack.Stack.size()); | 
|  | 4172 | for (const auto &StackEntry : SemaRef.FpPragmaStack.Stack) { | 
|  | 4173 | Record.push_back(StackEntry.Value); | 
|  | 4174 | AddSourceLocation(StackEntry.PragmaLocation, Record); | 
|  | 4175 | AddSourceLocation(StackEntry.PragmaPushLocation, Record); | 
|  | 4176 | AddString(StackEntry.StackSlotLabel, Record); | 
|  | 4177 | } | 
|  | 4178 | Stream.EmitRecord(FLOAT_CONTROL_PRAGMA_OPTIONS, Record); | 
|  | 4179 | } | 
|  | 4180 |  | 
| Douglas Gregor | 8f64ca1 | 2015-12-08 22:43:32 +0000 | [diff] [blame] | 4181 | void ASTWriter::WriteModuleFileExtension(Sema &SemaRef, | 
|  | 4182 | ModuleFileExtensionWriter &Writer) { | 
| Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4183 | // Enter the extension block. | 
|  | 4184 | Stream.EnterSubblock(EXTENSION_BLOCK_ID, 4); | 
|  | 4185 |  | 
|  | 4186 | // Emit the metadata record abbreviation. | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4187 | auto Abv = std::make_shared<llvm::BitCodeAbbrev>(); | 
| Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4188 | Abv->Add(llvm::BitCodeAbbrevOp(EXTENSION_METADATA)); | 
|  | 4189 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); | 
|  | 4190 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); | 
|  | 4191 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); | 
|  | 4192 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); | 
|  | 4193 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4194 | unsigned Abbrev = Stream.EmitAbbrev(std::move(Abv)); | 
| Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4195 |  | 
|  | 4196 | // Emit the metadata record. | 
|  | 4197 | RecordData Record; | 
|  | 4198 | auto Metadata = Writer.getExtension()->getExtensionMetadata(); | 
|  | 4199 | Record.push_back(EXTENSION_METADATA); | 
|  | 4200 | Record.push_back(Metadata.MajorVersion); | 
|  | 4201 | Record.push_back(Metadata.MinorVersion); | 
|  | 4202 | Record.push_back(Metadata.BlockName.size()); | 
|  | 4203 | Record.push_back(Metadata.UserInfo.size()); | 
|  | 4204 | SmallString<64> Buffer; | 
|  | 4205 | Buffer += Metadata.BlockName; | 
|  | 4206 | Buffer += Metadata.UserInfo; | 
|  | 4207 | Stream.EmitRecordWithBlob(Abbrev, Record, Buffer); | 
|  | 4208 |  | 
|  | 4209 | // Emit the contents of the extension block. | 
| Douglas Gregor | 8f64ca1 | 2015-12-08 22:43:32 +0000 | [diff] [blame] | 4210 | Writer.writeExtensionContents(SemaRef, Stream); | 
| Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4211 |  | 
|  | 4212 | // Exit the extension block. | 
|  | 4213 | Stream.ExitBlock(); | 
|  | 4214 | } | 
|  | 4215 |  | 
| Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 4216 | //===----------------------------------------------------------------------===// | 
| Douglas Gregor | c504683 | 2009-04-27 18:38:38 +0000 | [diff] [blame] | 4217 | // General Serialization Routines | 
|  | 4218 | //===----------------------------------------------------------------------===// | 
|  | 4219 |  | 
| Richard Smith | e43e2b3 | 2018-08-20 21:47:29 +0000 | [diff] [blame] | 4220 | void ASTRecordWriter::AddAttr(const Attr *A) { | 
| Reid Kleckner | 11f9f8a | 2018-08-14 01:55:37 +0000 | [diff] [blame] | 4221 | auto &Record = *this; | 
| Richard Smith | e43e2b3 | 2018-08-20 21:47:29 +0000 | [diff] [blame] | 4222 | if (!A) | 
|  | 4223 | return Record.push_back(0); | 
|  | 4224 | Record.push_back(A->getKind() + 1); // FIXME: stable encoding, target attrs | 
| Erich Keane | 6a24e80 | 2019-09-13 17:39:31 +0000 | [diff] [blame] | 4225 |  | 
|  | 4226 | Record.AddIdentifierRef(A->getAttrName()); | 
|  | 4227 | Record.AddIdentifierRef(A->getScopeName()); | 
| Richard Smith | e43e2b3 | 2018-08-20 21:47:29 +0000 | [diff] [blame] | 4228 | Record.AddSourceRange(A->getRange()); | 
| Erich Keane | 6a24e80 | 2019-09-13 17:39:31 +0000 | [diff] [blame] | 4229 | Record.AddSourceLocation(A->getScopeLoc()); | 
|  | 4230 | Record.push_back(A->getParsedKind()); | 
|  | 4231 | Record.push_back(A->getSyntax()); | 
|  | 4232 | Record.push_back(A->getAttributeSpellingListIndexRaw()); | 
| Reid Kleckner | 11f9f8a | 2018-08-14 01:55:37 +0000 | [diff] [blame] | 4233 |  | 
|  | 4234 | #include "clang/Serialization/AttrPCHWrite.inc" | 
| Richard Smith | e43e2b3 | 2018-08-20 21:47:29 +0000 | [diff] [blame] | 4235 | } | 
|  | 4236 |  | 
|  | 4237 | /// Emit the list of attributes to the specified record. | 
|  | 4238 | void ASTRecordWriter::AddAttributes(ArrayRef<const Attr *> Attrs) { | 
|  | 4239 | push_back(Attrs.size()); | 
|  | 4240 | for (const auto *A : Attrs) | 
|  | 4241 | AddAttr(A); | 
| Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4242 | } | 
|  | 4243 |  | 
| John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 4244 | void ASTWriter::AddToken(const Token &Tok, RecordDataImpl &Record) { | 
|  | 4245 | AddSourceLocation(Tok.getLocation(), Record); | 
|  | 4246 | Record.push_back(Tok.getLength()); | 
|  | 4247 |  | 
|  | 4248 | // FIXME: When reading literal tokens, reconstruct the literal pointer | 
|  | 4249 | // if it is needed. | 
|  | 4250 | AddIdentifierRef(Tok.getIdentifierInfo(), Record); | 
|  | 4251 | // FIXME: Should translate token kind to a stable encoding. | 
|  | 4252 | Record.push_back(Tok.getKind()); | 
|  | 4253 | // FIXME: Should translate token flags to a stable encoding. | 
|  | 4254 | Record.push_back(Tok.getFlags()); | 
|  | 4255 | } | 
|  | 4256 |  | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 4257 | void ASTWriter::AddString(StringRef Str, RecordDataImpl &Record) { | 
| Douglas Gregor | bc8a78d5 | 2009-04-15 21:30:51 +0000 | [diff] [blame] | 4258 | Record.push_back(Str.size()); | 
|  | 4259 | Record.insert(Record.end(), Str.begin(), Str.end()); | 
|  | 4260 | } | 
|  | 4261 |  | 
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4262 | bool ASTWriter::PreparePathForOutput(SmallVectorImpl<char> &Path) { | 
| Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 4263 | assert(Context && "should have context when outputting path"); | 
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4264 |  | 
| Richard Smith | 54cc3c2 | 2014-12-11 20:50:24 +0000 | [diff] [blame] | 4265 | bool Changed = | 
|  | 4266 | cleanPathForOutput(Context->getSourceManager().getFileManager(), Path); | 
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4267 |  | 
|  | 4268 | // Remove a prefix to make the path relative, if relevant. | 
|  | 4269 | const char *PathBegin = Path.data(); | 
|  | 4270 | const char *PathPtr = | 
|  | 4271 | adjustFilenameForRelocatableAST(PathBegin, BaseDirectory); | 
|  | 4272 | if (PathPtr != PathBegin) { | 
|  | 4273 | Path.erase(Path.begin(), Path.begin() + (PathPtr - PathBegin)); | 
|  | 4274 | Changed = true; | 
|  | 4275 | } | 
|  | 4276 |  | 
|  | 4277 | return Changed; | 
|  | 4278 | } | 
|  | 4279 |  | 
|  | 4280 | void ASTWriter::AddPath(StringRef Path, RecordDataImpl &Record) { | 
|  | 4281 | SmallString<128> FilePath(Path); | 
|  | 4282 | PreparePathForOutput(FilePath); | 
|  | 4283 | AddString(FilePath, Record); | 
|  | 4284 | } | 
|  | 4285 |  | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4286 | void ASTWriter::EmitRecordWithPath(unsigned Abbrev, RecordDataRef Record, | 
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4287 | StringRef Path) { | 
|  | 4288 | SmallString<128> FilePath(Path); | 
|  | 4289 | PreparePathForOutput(FilePath); | 
|  | 4290 | Stream.EmitRecordWithBlob(Abbrev, Record, FilePath); | 
|  | 4291 | } | 
|  | 4292 |  | 
| Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 4293 | void ASTWriter::AddVersionTuple(const VersionTuple &Version, | 
|  | 4294 | RecordDataImpl &Record) { | 
|  | 4295 | Record.push_back(Version.getMajor()); | 
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4296 | if (Optional<unsigned> Minor = Version.getMinor()) | 
| Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 4297 | Record.push_back(*Minor + 1); | 
|  | 4298 | else | 
|  | 4299 | Record.push_back(0); | 
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 4300 | if (Optional<unsigned> Subminor = Version.getSubminor()) | 
| Douglas Gregor | 20b2ebd | 2011-03-23 00:50:03 +0000 | [diff] [blame] | 4301 | Record.push_back(*Subminor + 1); | 
|  | 4302 | else | 
|  | 4303 | Record.push_back(0); | 
|  | 4304 | } | 
|  | 4305 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4306 | /// Note that the identifier II occurs at the given offset | 
| Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 4307 | /// within the identifier table. | 
| Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4308 | void ASTWriter::SetIdentifierOffset(const IdentifierInfo *II, uint32_t Offset) { | 
| Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4309 | IdentID ID = IdentifierIDs[II]; | 
| Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 4310 | // Only store offsets new to this AST file. Other identifier names are looked | 
| Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 4311 | // up earlier in the chain and thus don't need an offset. | 
|  | 4312 | if (ID >= FirstIdentID) | 
|  | 4313 | IdentifierOffsets[ID - FirstIdentID] = Offset; | 
| Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 4314 | } | 
|  | 4315 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4316 | /// Note that the selector Sel occurs at the given offset | 
| Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4317 | /// within the method pool/selector table. | 
| Sebastian Redl | 55c0ad5 | 2010-08-18 23:56:21 +0000 | [diff] [blame] | 4318 | void ASTWriter::SetSelectorOffset(Selector Sel, uint32_t Offset) { | 
| Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4319 | unsigned ID = SelectorIDs[Sel]; | 
|  | 4320 | assert(ID && "Unknown selector"); | 
| Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 4321 | // Don't record offsets for selectors that are also available in a different | 
|  | 4322 | // file. | 
|  | 4323 | if (ID < FirstSelectorID) | 
|  | 4324 | return; | 
|  | 4325 | SelectorOffsets[ID - FirstSelectorID] = Offset; | 
| Douglas Gregor | 95c13f5 | 2009-04-25 17:48:32 +0000 | [diff] [blame] | 4326 | } | 
|  | 4327 |  | 
| David Blaikie | 61137e1 | 2017-01-05 18:23:18 +0000 | [diff] [blame] | 4328 | ASTWriter::ASTWriter(llvm::BitstreamWriter &Stream, | 
| Duncan P. N. Exon Smith | 8bef5cd | 2019-03-09 17:33:56 +0000 | [diff] [blame] | 4329 | SmallVectorImpl<char> &Buffer, | 
|  | 4330 | InMemoryModuleCache &ModuleCache, | 
| David Blaikie | 61137e1 | 2017-01-05 18:23:18 +0000 | [diff] [blame] | 4331 | ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions, | 
|  | 4332 | bool IncludeTimestamps) | 
| Duncan P. N. Exon Smith | 8bef5cd | 2019-03-09 17:33:56 +0000 | [diff] [blame] | 4333 | : Stream(Stream), Buffer(Buffer), ModuleCache(ModuleCache), | 
| Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 4334 | IncludeTimestamps(IncludeTimestamps) { | 
| Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4335 | for (const auto &Ext : Extensions) { | 
|  | 4336 | if (auto Writer = Ext->createExtensionWriter(*this)) | 
|  | 4337 | ModuleFileExtensionWriters.push_back(std::move(Writer)); | 
|  | 4338 | } | 
|  | 4339 | } | 
| Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4340 |  | 
| David Blaikie | 409df39 | 2020-04-28 18:05:28 -0700 | [diff] [blame] | 4341 | ASTWriter::~ASTWriter() = default; | 
| Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4342 |  | 
| Richard Smith | b376191 | 2015-02-05 23:08:52 +0000 | [diff] [blame] | 4343 | const LangOptions &ASTWriter::getLangOpts() const { | 
|  | 4344 | assert(WritingAST && "can't determine lang opts when not writing AST"); | 
|  | 4345 | return Context->getLangOpts(); | 
|  | 4346 | } | 
|  | 4347 |  | 
| Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 4348 | time_t ASTWriter::getTimestampForOutput(const FileEntry *E) const { | 
|  | 4349 | return IncludeTimestamps ? E->getModificationTime() : 0; | 
|  | 4350 | } | 
|  | 4351 |  | 
| Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4352 | ASTFileSignature ASTWriter::WriteAST(Sema &SemaRef, | 
|  | 4353 | const std::string &OutputFile, | 
|  | 4354 | Module *WritingModule, StringRef isysroot, | 
| Duncan P. N. Exon Smith | 70d759b | 2019-03-12 18:38:04 +0000 | [diff] [blame] | 4355 | bool hasErrors, | 
|  | 4356 | bool ShouldCacheASTInMemory) { | 
| Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4357 | WritingAST = true; | 
| Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4358 |  | 
| Argyrios Kyrtzidis | 4a280ff | 2012-03-07 01:51:17 +0000 | [diff] [blame] | 4359 | ASTHasCompilerErrors = hasErrors; | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 4360 |  | 
| Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4361 | // Emit the file header. | 
| Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 4362 | Stream.Emit((unsigned)'C', 8); | 
|  | 4363 | Stream.Emit((unsigned)'P', 8); | 
|  | 4364 | Stream.Emit((unsigned)'C', 8); | 
|  | 4365 | Stream.Emit((unsigned)'H', 8); | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4366 |  | 
| Chris Lattner | 28fa4e6 | 2009-04-26 22:26:21 +0000 | [diff] [blame] | 4367 | WriteBlockInfoBlock(); | 
| Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4368 |  | 
| Douglas Gregor | eda8e12 | 2011-08-09 15:13:55 +0000 | [diff] [blame] | 4369 | Context = &SemaRef.Context; | 
| Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 4370 | PP = &SemaRef.PP; | 
| Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 4371 | this->WritingModule = WritingModule; | 
| Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4372 | ASTFileSignature Signature = | 
|  | 4373 | WriteASTCore(SemaRef, isysroot, OutputFile, WritingModule); | 
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4374 | Context = nullptr; | 
|  | 4375 | PP = nullptr; | 
|  | 4376 | this->WritingModule = nullptr; | 
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4377 | this->BaseDirectory.clear(); | 
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4378 |  | 
| Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 4379 | WritingAST = false; | 
| Duncan P. N. Exon Smith | 70d759b | 2019-03-12 18:38:04 +0000 | [diff] [blame] | 4380 | if (ShouldCacheASTInMemory) { | 
| Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 4381 | // Construct MemoryBuffer and update buffer manager. | 
| Rumeet Dhindsa | 57a2eaf | 2020-03-10 10:59:26 -0700 | [diff] [blame] | 4382 | ModuleCache.addBuiltPCM(OutputFile, | 
| Duncan P. N. Exon Smith | 0a2be46 | 2019-03-09 17:44:01 +0000 | [diff] [blame] | 4383 | llvm::MemoryBuffer::getMemBufferCopy( | 
|  | 4384 | StringRef(Buffer.begin(), Buffer.size()))); | 
| Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 4385 | } | 
| Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4386 | return Signature; | 
| Sebastian Redl | 143413f | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 4387 | } | 
|  | 4388 |  | 
| Douglas Gregor | a94a154 | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 4389 | template<typename Vector> | 
|  | 4390 | static void AddLazyVectorDecls(ASTWriter &Writer, Vector &Vec, | 
|  | 4391 | ASTWriter::RecordData &Record) { | 
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4392 | for (typename Vector::iterator I = Vec.begin(nullptr, true), E = Vec.end(); | 
|  | 4393 | I != E; ++I) { | 
| Douglas Gregor | a94a154 | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 4394 | Writer.AddDeclRef(*I, Record); | 
|  | 4395 | } | 
|  | 4396 | } | 
|  | 4397 |  | 
| Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4398 | ASTFileSignature ASTWriter::WriteASTCore(Sema &SemaRef, StringRef isysroot, | 
|  | 4399 | const std::string &OutputFile, | 
|  | 4400 | Module *WritingModule) { | 
| Sebastian Redl | 143413f | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 4401 | using namespace llvm; | 
|  | 4402 |  | 
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4403 | bool isModule = WritingModule != nullptr; | 
| Argyrios Kyrtzidis | ffb3558 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 4404 |  | 
| Douglas Gregor | cf68c58 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 4405 | // Make sure that the AST reader knows to finalize itself. | 
|  | 4406 | if (Chain) | 
|  | 4407 | Chain->finalizeForWriting(); | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 4408 |  | 
| Sebastian Redl | 143413f | 2010-07-12 22:02:52 +0000 | [diff] [blame] | 4409 | ASTContext &Context = SemaRef.Context; | 
|  | 4410 | Preprocessor &PP = SemaRef.PP; | 
|  | 4411 |  | 
| Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4412 | // Set up predefined declaration IDs. | 
| Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 4413 | auto RegisterPredefDecl = [&] (Decl *D, PredefinedDeclIDs ID) { | 
|  | 4414 | if (D) { | 
|  | 4415 | assert(D->isCanonicalDecl() && "predefined decl is not canonical"); | 
|  | 4416 | DeclIDs[D] = ID; | 
| Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 4417 | } | 
|  | 4418 | }; | 
|  | 4419 | RegisterPredefDecl(Context.getTranslationUnitDecl(), | 
|  | 4420 | PREDEF_DECL_TRANSLATION_UNIT_ID); | 
|  | 4421 | RegisterPredefDecl(Context.ObjCIdDecl, PREDEF_DECL_OBJC_ID_ID); | 
|  | 4422 | RegisterPredefDecl(Context.ObjCSelDecl, PREDEF_DECL_OBJC_SEL_ID); | 
|  | 4423 | RegisterPredefDecl(Context.ObjCClassDecl, PREDEF_DECL_OBJC_CLASS_ID); | 
|  | 4424 | RegisterPredefDecl(Context.ObjCProtocolClassDecl, | 
|  | 4425 | PREDEF_DECL_OBJC_PROTOCOL_ID); | 
|  | 4426 | RegisterPredefDecl(Context.Int128Decl, PREDEF_DECL_INT_128_ID); | 
|  | 4427 | RegisterPredefDecl(Context.UInt128Decl, PREDEF_DECL_UNSIGNED_INT_128_ID); | 
|  | 4428 | RegisterPredefDecl(Context.ObjCInstanceTypeDecl, | 
|  | 4429 | PREDEF_DECL_OBJC_INSTANCETYPE_ID); | 
|  | 4430 | RegisterPredefDecl(Context.BuiltinVaListDecl, PREDEF_DECL_BUILTIN_VA_LIST_ID); | 
| Richard Smith | 9b88a4c | 2015-07-27 05:40:23 +0000 | [diff] [blame] | 4431 | RegisterPredefDecl(Context.VaListTagDecl, PREDEF_DECL_VA_LIST_TAG); | 
| Charles Davis | c7d5c94 | 2015-09-17 20:55:33 +0000 | [diff] [blame] | 4432 | RegisterPredefDecl(Context.BuiltinMSVaListDecl, | 
|  | 4433 | PREDEF_DECL_BUILTIN_MS_VA_LIST_ID); | 
| Richard Smith | bab6df8 | 2020-04-11 22:15:29 -0700 | [diff] [blame] | 4434 | RegisterPredefDecl(Context.MSGuidTagDecl, | 
|  | 4435 | PREDEF_DECL_BUILTIN_MS_GUID_ID); | 
| Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 4436 | RegisterPredefDecl(Context.ExternCContext, PREDEF_DECL_EXTERN_C_CONTEXT_ID); | 
| David Majnemer | d9b1a4f | 2015-11-04 03:40:30 +0000 | [diff] [blame] | 4437 | RegisterPredefDecl(Context.MakeIntegerSeqDecl, | 
|  | 4438 | PREDEF_DECL_MAKE_INTEGER_SEQ_ID); | 
| Quentin Colombet | 043406b | 2016-02-03 22:41:00 +0000 | [diff] [blame] | 4439 | RegisterPredefDecl(Context.CFConstantStringTypeDecl, | 
|  | 4440 | PREDEF_DECL_CF_CONSTANT_STRING_ID); | 
| Ben Langmuir | f541674 | 2016-02-04 00:55:24 +0000 | [diff] [blame] | 4441 | RegisterPredefDecl(Context.CFConstantStringTagDecl, | 
|  | 4442 | PREDEF_DECL_CF_CONSTANT_STRING_TAG_ID); | 
| Eric Fiselier | 6ad6855 | 2016-07-01 01:24:09 +0000 | [diff] [blame] | 4443 | RegisterPredefDecl(Context.TypePackElementDecl, | 
|  | 4444 | PREDEF_DECL_TYPE_PACK_ELEMENT_ID); | 
| Meador Inge | 5d3fb22 | 2012-06-16 03:34:49 +0000 | [diff] [blame] | 4445 |  | 
| Chris Lattner | 0c79736 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 4446 | // Build a record containing all of the tentative definitions in this file, in | 
| Sebastian Redl | 35351a9 | 2010-01-31 22:27:38 +0000 | [diff] [blame] | 4447 | // TentativeDefinitions order.  Generally, this record will be empty for | 
| Chris Lattner | 0c79736 | 2009-09-08 18:19:27 +0000 | [diff] [blame] | 4448 | // headers. | 
| Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4449 | RecordData TentativeDefinitions; | 
| Douglas Gregor | a94a154 | 2011-07-27 21:45:57 +0000 | [diff] [blame] | 4450 | AddLazyVectorDecls(*this, SemaRef.TentativeDefinitions, TentativeDefinitions); | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 4451 |  | 
| Argyrios Kyrtzidis | 35672e7 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 4452 | // Build a record containing all of the file scoped decls in this file. | 
|  | 4453 | RecordData UnusedFileScopedDecls; | 
| Argyrios Kyrtzidis | 5985236 | 2013-03-14 04:45:00 +0000 | [diff] [blame] | 4454 | if (!isModule) | 
|  | 4455 | AddLazyVectorDecls(*this, SemaRef.UnusedFileScopedDecls, | 
|  | 4456 | UnusedFileScopedDecls); | 
| Sebastian Redl | 08aca9025 | 2010-08-05 18:21:25 +0000 | [diff] [blame] | 4457 |  | 
| Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4458 | // Build a record containing all of the delegating constructors we still need | 
|  | 4459 | // to resolve. | 
| Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 4460 | RecordData DelegatingCtorDecls; | 
| Argyrios Kyrtzidis | ffb3558 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 4461 | if (!isModule) | 
|  | 4462 | AddLazyVectorDecls(*this, SemaRef.DelegatingCtorDecls, DelegatingCtorDecls); | 
| Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 4463 |  | 
| Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4464 | // Write the set of weak, undeclared identifiers. We always write the | 
|  | 4465 | // entire table, since later PCH files in a PCH chain are only interested in | 
|  | 4466 | // the results at the end of the chain. | 
| Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 4467 | RecordData WeakUndeclaredIdentifiers; | 
| Chandler Carruth | f85d982 | 2015-03-26 08:32:49 +0000 | [diff] [blame] | 4468 | for (auto &WeakUndeclaredIdentifier : SemaRef.WeakUndeclaredIdentifiers) { | 
|  | 4469 | IdentifierInfo *II = WeakUndeclaredIdentifier.first; | 
|  | 4470 | WeakInfo &WI = WeakUndeclaredIdentifier.second; | 
|  | 4471 | AddIdentifierRef(II, WeakUndeclaredIdentifiers); | 
|  | 4472 | AddIdentifierRef(WI.getAlias(), WeakUndeclaredIdentifiers); | 
|  | 4473 | AddSourceLocation(WI.getLocation(), WeakUndeclaredIdentifiers); | 
|  | 4474 | WeakUndeclaredIdentifiers.push_back(WI.getUsed()); | 
| Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 4475 | } | 
| Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 4476 |  | 
| Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 4477 | // Build a record containing all of the ext_vector declarations. | 
|  | 4478 | RecordData ExtVectorDecls; | 
| Douglas Gregor | b7098a3 | 2011-07-28 00:39:29 +0000 | [diff] [blame] | 4479 | AddLazyVectorDecls(*this, SemaRef.ExtVectorDecls, ExtVectorDecls); | 
| Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 4480 |  | 
| Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4481 | // Build a record containing all of the VTable uses information. | 
|  | 4482 | RecordData VTableUses; | 
| Argyrios Kyrtzidis | edee67f | 2010-08-03 17:29:52 +0000 | [diff] [blame] | 4483 | if (!SemaRef.VTableUses.empty()) { | 
| Argyrios Kyrtzidis | edee67f | 2010-08-03 17:29:52 +0000 | [diff] [blame] | 4484 | for (unsigned I = 0, N = SemaRef.VTableUses.size(); I != N; ++I) { | 
|  | 4485 | AddDeclRef(SemaRef.VTableUses[I].first, VTableUses); | 
|  | 4486 | AddSourceLocation(SemaRef.VTableUses[I].second, VTableUses); | 
|  | 4487 | VTableUses.push_back(SemaRef.VTablesUsed[SemaRef.VTableUses[I].first]); | 
|  | 4488 | } | 
| Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4489 | } | 
|  | 4490 |  | 
| Nico Weber | 7288943 | 2014-09-06 01:25:55 +0000 | [diff] [blame] | 4491 | // Build a record containing all of the UnusedLocalTypedefNameCandidates. | 
|  | 4492 | RecordData UnusedLocalTypedefNameCandidates; | 
|  | 4493 | for (const TypedefNameDecl *TD : SemaRef.UnusedLocalTypedefNameCandidates) | 
|  | 4494 | AddDeclRef(TD, UnusedLocalTypedefNameCandidates); | 
|  | 4495 |  | 
| Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 4496 | // Build a record containing all of pending implicit instantiations. | 
| Chandler Carruth | 5408017 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 4497 | RecordData PendingInstantiations; | 
| Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4498 | for (const auto &I : SemaRef.PendingInstantiations) { | 
|  | 4499 | AddDeclRef(I.first, PendingInstantiations); | 
|  | 4500 | AddSourceLocation(I.second, PendingInstantiations); | 
| Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 4501 | } | 
|  | 4502 | assert(SemaRef.PendingLocalImplicitInstantiations.empty() && | 
|  | 4503 | "There are local ones at end of translation unit!"); | 
|  | 4504 |  | 
| Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4505 | // Build a record containing some declaration references. | 
|  | 4506 | RecordData SemaDeclRefs; | 
| Richard Smith | 96269c5 | 2016-09-29 22:49:46 +0000 | [diff] [blame] | 4507 | if (SemaRef.StdNamespace || SemaRef.StdBadAlloc || SemaRef.StdAlignValT) { | 
| Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4508 | AddDeclRef(SemaRef.getStdNamespace(), SemaDeclRefs); | 
|  | 4509 | AddDeclRef(SemaRef.getStdBadAlloc(), SemaDeclRefs); | 
| Richard Smith | 96269c5 | 2016-09-29 22:49:46 +0000 | [diff] [blame] | 4510 | AddDeclRef(SemaRef.getStdAlignValT(), SemaDeclRefs); | 
| Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4511 | } | 
|  | 4512 |  | 
| Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 4513 | RecordData CUDASpecialDeclRefs; | 
|  | 4514 | if (Context.getcudaConfigureCallDecl()) { | 
|  | 4515 | AddDeclRef(Context.getcudaConfigureCallDecl(), CUDASpecialDeclRefs); | 
|  | 4516 | } | 
|  | 4517 |  | 
| Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4518 | // Build a record containing all of the known namespaces. | 
|  | 4519 | RecordData KnownNamespaces; | 
| Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4520 | for (const auto &I : SemaRef.KnownNamespaces) { | 
|  | 4521 | if (!I.second) | 
|  | 4522 | AddDeclRef(I.first, KnownNamespaces); | 
| Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4523 | } | 
| Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 4524 |  | 
| Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 4525 | // Build a record of all used, undefined objects that require definitions. | 
|  | 4526 | RecordData UndefinedButUsed; | 
| Nick Lewycky | f0f5616 | 2013-01-31 03:23:57 +0000 | [diff] [blame] | 4527 |  | 
|  | 4528 | SmallVector<std::pair<NamedDecl *, SourceLocation>, 16> Undefined; | 
| Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 4529 | SemaRef.getUndefinedButUsed(Undefined); | 
| Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4530 | for (const auto &I : Undefined) { | 
|  | 4531 | AddDeclRef(I.first, UndefinedButUsed); | 
|  | 4532 | AddSourceLocation(I.second, UndefinedButUsed); | 
| Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 4533 | } | 
|  | 4534 |  | 
| Ismail Pazarbasi | e5768d1 | 2015-05-18 19:59:11 +0000 | [diff] [blame] | 4535 | // Build a record containing all delete-expressions that we would like to | 
|  | 4536 | // analyze later in AST. | 
|  | 4537 | RecordData DeleteExprsToAnalyze; | 
|  | 4538 |  | 
| Richard Smith | f5262c6 | 2018-06-28 01:57:04 +0000 | [diff] [blame] | 4539 | if (!isModule) { | 
|  | 4540 | for (const auto &DeleteExprsInfo : | 
|  | 4541 | SemaRef.getMismatchingDeleteExpressions()) { | 
|  | 4542 | AddDeclRef(DeleteExprsInfo.first, DeleteExprsToAnalyze); | 
|  | 4543 | DeleteExprsToAnalyze.push_back(DeleteExprsInfo.second.size()); | 
|  | 4544 | for (const auto &DeleteLoc : DeleteExprsInfo.second) { | 
|  | 4545 | AddSourceLocation(DeleteLoc.first, DeleteExprsToAnalyze); | 
|  | 4546 | DeleteExprsToAnalyze.push_back(DeleteLoc.second); | 
|  | 4547 | } | 
| Ismail Pazarbasi | e5768d1 | 2015-05-18 19:59:11 +0000 | [diff] [blame] | 4548 | } | 
|  | 4549 | } | 
|  | 4550 |  | 
| Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 4551 | // Write the control block | 
| Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4552 | WriteControlBlock(PP, Context, isysroot, OutputFile); | 
| Douglas Gregor | 112b907 | 2012-10-18 05:31:06 +0000 | [diff] [blame] | 4553 |  | 
| Sebastian Redl | 42a0f6a | 2010-08-18 23:56:27 +0000 | [diff] [blame] | 4554 | // Write the remaining AST contents. | 
| Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4555 | Stream.EnterSubblock(AST_BLOCK_ID, 5); | 
| Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4556 |  | 
| Argyrios Kyrtzidis | 3960540 | 2012-12-13 21:38:23 +0000 | [diff] [blame] | 4557 | // This is so that older clang versions, before the introduction | 
|  | 4558 | // of the control block, can read and reject the newer PCH format. | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4559 | { | 
|  | 4560 | RecordData Record = {VERSION_MAJOR}; | 
|  | 4561 | Stream.EmitRecord(METADATA_OLD_FORMAT, Record); | 
|  | 4562 | } | 
| Argyrios Kyrtzidis | 3960540 | 2012-12-13 21:38:23 +0000 | [diff] [blame] | 4563 |  | 
| Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4564 | // Create a lexical update block containing all of the declarations in the | 
|  | 4565 | // translation unit that do not come from other AST files. | 
|  | 4566 | const TranslationUnitDecl *TU = Context.getTranslationUnitDecl(); | 
| Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 4567 | SmallVector<uint32_t, 128> NewGlobalKindDeclPairs; | 
|  | 4568 | for (const auto *D : TU->noload_decls()) { | 
|  | 4569 | if (!D->isFromASTFile()) { | 
|  | 4570 | NewGlobalKindDeclPairs.push_back(D->getKind()); | 
|  | 4571 | NewGlobalKindDeclPairs.push_back(GetDeclRef(D)); | 
|  | 4572 | } | 
| Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4573 | } | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 4574 |  | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4575 | auto Abv = std::make_shared<BitCodeAbbrev>(); | 
| Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4576 | Abv->Add(llvm::BitCodeAbbrevOp(TU_UPDATE_LEXICAL)); | 
|  | 4577 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4578 | unsigned TuUpdateLexicalAbbrev = Stream.EmitAbbrev(std::move(Abv)); | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4579 | { | 
|  | 4580 | RecordData::value_type Record[] = {TU_UPDATE_LEXICAL}; | 
|  | 4581 | Stream.EmitRecordWithBlob(TuUpdateLexicalAbbrev, Record, | 
|  | 4582 | bytes(NewGlobalKindDeclPairs)); | 
|  | 4583 | } | 
|  | 4584 |  | 
| Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4585 | // And a visible updates block for the translation unit. | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4586 | Abv = std::make_shared<BitCodeAbbrev>(); | 
| Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4587 | Abv->Add(llvm::BitCodeAbbrevOp(UPDATE_VISIBLE)); | 
|  | 4588 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::VBR, 6)); | 
| Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4589 | Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)); | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4590 | UpdateVisibleAbbrev = Stream.EmitAbbrev(std::move(Abv)); | 
| Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4591 | WriteDeclContextVisibleUpdate(TU); | 
| Richard Smith | f19e127 | 2015-03-07 00:04:49 +0000 | [diff] [blame] | 4592 |  | 
|  | 4593 | // If we have any extern "C" names, write out a visible update for them. | 
|  | 4594 | if (Context.ExternCContext) | 
|  | 4595 | WriteDeclContextVisibleUpdate(Context.ExternCContext); | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 4596 |  | 
| Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4597 | // If the translation unit has an anonymous namespace, and we don't already | 
|  | 4598 | // have an update block for it, write it as an update block. | 
| Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4599 | // FIXME: Why do we not do this if there's already an update block? | 
| Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4600 | if (NamespaceDecl *NS = TU->getAnonymousNamespace()) { | 
|  | 4601 | ASTWriter::UpdateRecord &Record = DeclUpdates[TU]; | 
| Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4602 | if (Record.empty()) | 
| Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4603 | Record.push_back(DeclUpdate(UPD_CXX_ADDED_ANONYMOUS_NAMESPACE, NS)); | 
| Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4604 | } | 
| Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4605 |  | 
| Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4606 | // Add update records for all mangling numbers and static local numbers. | 
|  | 4607 | // These aren't really update records, but this is a convenient way of | 
|  | 4608 | // tagging this rare extra data onto the declarations. | 
|  | 4609 | for (const auto &Number : Context.MangleNumbers) | 
|  | 4610 | if (!Number.first->isFromASTFile()) | 
| Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4611 | DeclUpdates[Number.first].push_back(DeclUpdate(UPD_MANGLING_NUMBER, | 
|  | 4612 | Number.second)); | 
| Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4613 | for (const auto &Number : Context.StaticLocalNumbers) | 
|  | 4614 | if (!Number.first->isFromASTFile()) | 
| Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4615 | DeclUpdates[Number.first].push_back(DeclUpdate(UPD_STATIC_LOCAL_NUMBER, | 
|  | 4616 | Number.second)); | 
| Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4617 |  | 
| Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4618 | // Make sure visible decls, added to DeclContexts previously loaded from | 
| Richard Smith | c26d974 | 2016-10-06 20:30:51 +0000 | [diff] [blame] | 4619 | // an AST file, are registered for serialization. Likewise for template | 
|  | 4620 | // specializations added to imported templates. | 
|  | 4621 | for (const auto *I : DeclsToEmitEvenIfUnreferenced) { | 
| Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4622 | GetDeclRef(I); | 
| Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 4623 | } | 
|  | 4624 |  | 
| Argyrios Kyrtzidis | acfbbd7 | 2013-08-07 21:17:33 +0000 | [diff] [blame] | 4625 | // Make sure all decls associated with an identifier are registered for | 
| Richard Smith | 79bf920 | 2015-08-24 03:33:22 +0000 | [diff] [blame] | 4626 | // serialization, if we're storing decls with identifiers. | 
|  | 4627 | if (!WritingModule || !getLangOpts().CPlusPlus) { | 
|  | 4628 | llvm::SmallVector<const IdentifierInfo*, 256> IIs; | 
| Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 4629 | for (const auto &ID : PP.getIdentifierTable()) { | 
|  | 4630 | const IdentifierInfo *II = ID.second; | 
| Richard Smith | 79bf920 | 2015-08-24 03:33:22 +0000 | [diff] [blame] | 4631 | if (!Chain || !II->isFromAST() || II->hasChangedSinceDeserialization()) | 
|  | 4632 | IIs.push_back(II); | 
|  | 4633 | } | 
|  | 4634 | // Sort the identifiers to visit based on their name. | 
| Benjamin Kramer | cd2bae3 | 2019-08-22 17:32:16 +0000 | [diff] [blame] | 4635 | llvm::sort(IIs, llvm::deref<std::less<>>()); | 
| Richard Smith | 79bf920 | 2015-08-24 03:33:22 +0000 | [diff] [blame] | 4636 | for (const IdentifierInfo *II : IIs) { | 
|  | 4637 | for (IdentifierResolver::iterator D = SemaRef.IdResolver.begin(II), | 
|  | 4638 | DEnd = SemaRef.IdResolver.end(); | 
|  | 4639 | D != DEnd; ++D) { | 
|  | 4640 | GetDeclRef(*D); | 
|  | 4641 | } | 
| Argyrios Kyrtzidis | acfbbd7 | 2013-08-07 21:17:33 +0000 | [diff] [blame] | 4642 | } | 
|  | 4643 | } | 
|  | 4644 |  | 
| Manman Ren | a0f31a0 | 2016-04-29 19:04:05 +0000 | [diff] [blame] | 4645 | // For method pool in the module, if it contains an entry for a selector, | 
|  | 4646 | // the entry should be complete, containing everything introduced by that | 
|  | 4647 | // module and all modules it imports. It's possible that the entry is out of | 
|  | 4648 | // date, so we need to pull in the new content here. | 
|  | 4649 |  | 
|  | 4650 | // It's possible that updateOutOfDateSelector can update SelectorIDs. To be | 
|  | 4651 | // safe, we copy all selectors out. | 
|  | 4652 | llvm::SmallVector<Selector, 256> AllSelectors; | 
|  | 4653 | for (auto &SelectorAndID : SelectorIDs) | 
|  | 4654 | AllSelectors.push_back(SelectorAndID.first); | 
|  | 4655 | for (auto &Selector : AllSelectors) | 
|  | 4656 | SemaRef.updateOutOfDateSelector(Selector); | 
|  | 4657 |  | 
| Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4658 | // Form the record of special types. | 
|  | 4659 | RecordData SpecialTypes; | 
| Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4660 | AddTypeRef(Context.getRawCFConstantStringType(), SpecialTypes); | 
| Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4661 | AddTypeRef(Context.getFILEType(), SpecialTypes); | 
|  | 4662 | AddTypeRef(Context.getjmp_bufType(), SpecialTypes); | 
|  | 4663 | AddTypeRef(Context.getsigjmp_bufType(), SpecialTypes); | 
|  | 4664 | AddTypeRef(Context.ObjCIdRedefinitionType, SpecialTypes); | 
|  | 4665 | AddTypeRef(Context.ObjCClassRedefinitionType, SpecialTypes); | 
| Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4666 | AddTypeRef(Context.ObjCSelRedefinitionType, SpecialTypes); | 
| Rafael Espindola | 6cfa82b | 2011-11-13 21:51:09 +0000 | [diff] [blame] | 4667 | AddTypeRef(Context.getucontext_tType(), SpecialTypes); | 
| Douglas Gregor | a28bcdd | 2011-12-01 02:07:58 +0000 | [diff] [blame] | 4668 |  | 
| Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4669 | if (Chain) { | 
|  | 4670 | // Write the mapping information describing our module dependencies and how | 
|  | 4671 | // each of those modules were mapped into our own offset/ID space, so that | 
|  | 4672 | // the reader can build the appropriate mapping to its own offset/ID space. | 
|  | 4673 | // The map consists solely of a blob with the following format: | 
| Boris Kolpackov | d30446f | 2017-08-31 06:26:43 +0000 | [diff] [blame] | 4674 | // *(module-kind:i8 | 
|  | 4675 | //   module-name-len:i16 module-name:len*i8 | 
| Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4676 | //   source-location-offset:i32 | 
|  | 4677 | //   identifier-id:i32 | 
|  | 4678 | //   preprocessed-entity-id:i32 | 
|  | 4679 | //   macro-definition-id:i32 | 
| Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 4680 | //   submodule-id:i32 | 
| Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4681 | //   selector-id:i32 | 
|  | 4682 | //   declaration-id:i32 | 
|  | 4683 | //   c++-base-specifiers-id:i32 | 
|  | 4684 | //   type-id:i32) | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 4685 | // | 
| Boris Kolpackov | d30446f | 2017-08-31 06:26:43 +0000 | [diff] [blame] | 4686 | // module-kind is the ModuleKind enum value. If it is MK_PrebuiltModule or | 
|  | 4687 | // MK_ExplicitModule, then the module-name is the module name. Otherwise, | 
|  | 4688 | // it is the module file name. | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4689 | auto Abbrev = std::make_shared<BitCodeAbbrev>(); | 
| Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4690 | Abbrev->Add(BitCodeAbbrevOp(MODULE_OFFSET_MAP)); | 
|  | 4691 | Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); | 
| David Blaikie | b44f0bf | 2017-01-04 22:36:43 +0000 | [diff] [blame] | 4692 | unsigned ModuleOffsetMapAbbrev = Stream.EmitAbbrev(std::move(Abbrev)); | 
| Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 4693 | SmallString<2048> Buffer; | 
| Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4694 | { | 
|  | 4695 | llvm::raw_svector_ostream Out(Buffer); | 
| Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 4696 | for (ModuleFile &M : Chain->ModuleMgr) { | 
| Justin Bogner | e1c147c | 2014-03-28 22:03:19 +0000 | [diff] [blame] | 4697 | using namespace llvm::support; | 
| Eugene Zelenko | b7d8910 | 2017-11-11 00:08:50 +0000 | [diff] [blame] | 4698 |  | 
| Peter Collingbourne | e3f6529 | 2018-05-18 19:46:24 +0000 | [diff] [blame] | 4699 | endian::Writer LE(Out, little); | 
| Boris Kolpackov | d30446f | 2017-08-31 06:26:43 +0000 | [diff] [blame] | 4700 | LE.write<uint8_t>(static_cast<uint8_t>(M.Kind)); | 
|  | 4701 | StringRef Name = | 
|  | 4702 | M.Kind == MK_PrebuiltModule || M.Kind == MK_ExplicitModule | 
|  | 4703 | ? M.ModuleName | 
|  | 4704 | : M.FileName; | 
|  | 4705 | LE.write<uint16_t>(Name.size()); | 
|  | 4706 | Out.write(Name.data(), Name.size()); | 
| Ben Langmuir | fe971d9 | 2014-08-16 04:54:18 +0000 | [diff] [blame] | 4707 |  | 
| Ben Langmuir | 785180e | 2014-10-20 16:27:30 +0000 | [diff] [blame] | 4708 | // Note: if a base ID was uint max, it would not be possible to load | 
|  | 4709 | // another module after it or have more than one entity inside it. | 
|  | 4710 | uint32_t None = std::numeric_limits<uint32_t>::max(); | 
|  | 4711 |  | 
|  | 4712 | auto writeBaseIDOrNone = [&](uint32_t BaseID, bool ShouldWrite) { | 
|  | 4713 | assert(BaseID < std::numeric_limits<uint32_t>::max() && "base id too high"); | 
|  | 4714 | if (ShouldWrite) | 
|  | 4715 | LE.write<uint32_t>(BaseID); | 
|  | 4716 | else | 
|  | 4717 | LE.write<uint32_t>(None); | 
|  | 4718 | }; | 
|  | 4719 |  | 
| Ben Langmuir | fe971d9 | 2014-08-16 04:54:18 +0000 | [diff] [blame] | 4720 | // These values should be unique within a chain, since they will be read | 
|  | 4721 | // as keys into ContinuousRangeMaps. | 
| Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 4722 | writeBaseIDOrNone(M.SLocEntryBaseOffset, M.LocalNumSLocEntries); | 
|  | 4723 | writeBaseIDOrNone(M.BaseIdentifierID, M.LocalNumIdentifiers); | 
|  | 4724 | writeBaseIDOrNone(M.BaseMacroID, M.LocalNumMacros); | 
|  | 4725 | writeBaseIDOrNone(M.BasePreprocessedEntityID, | 
|  | 4726 | M.NumPreprocessedEntities); | 
|  | 4727 | writeBaseIDOrNone(M.BaseSubmoduleID, M.LocalNumSubmodules); | 
|  | 4728 | writeBaseIDOrNone(M.BaseSelectorID, M.LocalNumSelectors); | 
|  | 4729 | writeBaseIDOrNone(M.BaseDeclID, M.LocalNumDecls); | 
|  | 4730 | writeBaseIDOrNone(M.BaseTypeIndex, M.LocalNumTypes); | 
| Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4731 | } | 
|  | 4732 | } | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4733 | RecordData::value_type Record[] = {MODULE_OFFSET_MAP}; | 
| Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 4734 | Stream.EmitRecordWithBlob(ModuleOffsetMapAbbrev, Record, | 
|  | 4735 | Buffer.data(), Buffer.size()); | 
|  | 4736 | } | 
| Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4737 |  | 
| Yaxun (Sam) Liu | b670ab7 | 2020-02-26 10:57:39 -0500 | [diff] [blame] | 4738 | // Build a record containing all of the DeclsToCheckForDeferredDiags. | 
|  | 4739 | RecordData DeclsToCheckForDeferredDiags; | 
|  | 4740 | for (auto *D : SemaRef.DeclsToCheckForDeferredDiags) | 
|  | 4741 | AddDeclRef(D, DeclsToCheckForDeferredDiags); | 
|  | 4742 |  | 
| Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4743 | RecordData DeclUpdatesOffsetsRecord; | 
|  | 4744 |  | 
| Richard Smith | 59442b4 | 2014-03-20 20:07:19 +0000 | [diff] [blame] | 4745 | // Keep writing types, declarations, and declaration update records | 
|  | 4746 | // until we've emitted all of them. | 
| Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 4747 | Stream.EnterSubblock(DECLTYPES_BLOCK_ID, /*bits for abbreviations*/5); | 
|  | 4748 | WriteTypeAbbrevs(); | 
|  | 4749 | WriteDeclAbbrevs(); | 
| Richard Smith | 59442b4 | 2014-03-20 20:07:19 +0000 | [diff] [blame] | 4750 | do { | 
|  | 4751 | WriteDeclUpdatesBlocks(DeclUpdatesOffsetsRecord); | 
|  | 4752 | while (!DeclTypesToEmit.empty()) { | 
|  | 4753 | DeclOrType DOT = DeclTypesToEmit.front(); | 
|  | 4754 | DeclTypesToEmit.pop(); | 
|  | 4755 | if (DOT.isType()) | 
|  | 4756 | WriteType(DOT.getType()); | 
|  | 4757 | else | 
|  | 4758 | WriteDecl(Context, DOT.getDecl()); | 
|  | 4759 | } | 
|  | 4760 | } while (!DeclUpdates.empty()); | 
| Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4761 | Stream.ExitBlock(); | 
|  | 4762 |  | 
| Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4763 | DoneWritingDeclsAndTypes = true; | 
|  | 4764 |  | 
|  | 4765 | // These things can only be done once we've written out decls and types. | 
|  | 4766 | WriteTypeDeclOffsets(); | 
| Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4767 | if (!DeclUpdatesOffsetsRecord.empty()) | 
|  | 4768 | Stream.EmitRecord(DECL_UPDATE_OFFSETS, DeclUpdatesOffsetsRecord); | 
| Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4769 | WriteFileDeclIDsMap(); | 
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4770 | WriteSourceManagerBlock(Context.getSourceManager(), PP); | 
| Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4771 | WriteComments(); | 
| Argyrios Kyrtzidis | ffb3558 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 4772 | WritePreprocessor(PP, isModule); | 
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4773 | WriteHeaderSearch(PP.getHeaderSearchInfo()); | 
| Sebastian Redl | a19a67f | 2010-08-03 21:58:15 +0000 | [diff] [blame] | 4774 | WriteSelectors(SemaRef); | 
| Fariborz Jahanian | c51609a | 2010-07-23 19:11:11 +0000 | [diff] [blame] | 4775 | WriteReferencedSelectorsPool(SemaRef); | 
| Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 4776 | WriteLateParsedTemplates(SemaRef); | 
| Argyrios Kyrtzidis | ffb3558 | 2013-03-14 04:44:56 +0000 | [diff] [blame] | 4777 | WriteIdentifierTable(PP, SemaRef.IdResolver, isModule); | 
| Melanie Blower | 8812b0c | 2020-04-16 08:45:26 -0700 | [diff] [blame] | 4778 | WriteFPPragmaOptions(SemaRef.getCurFPFeatures()); | 
| Peter Collingbourne | 5df20e0 | 2011-02-15 19:46:30 +0000 | [diff] [blame] | 4779 | WriteOpenCLExtensions(SemaRef); | 
| Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 4780 | WriteOpenCLExtensionTypes(SemaRef); | 
| Justin Lebar | 67a78a6 | 2016-10-08 22:15:58 +0000 | [diff] [blame] | 4781 | WriteCUDAPragmas(SemaRef); | 
| Douglas Gregor | 652d82a | 2009-04-18 05:55:16 +0000 | [diff] [blame] | 4782 |  | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 4783 | // If we're emitting a module, write out the submodule information. | 
| Douglas Gregor | a89c5ac | 2011-12-06 01:10:29 +0000 | [diff] [blame] | 4784 | if (WritingModule) | 
|  | 4785 | WriteSubmodules(WritingModule); | 
|  | 4786 |  | 
| Andrew Savonichev | 52d674d | 2018-10-29 11:14:01 +0000 | [diff] [blame] | 4787 | // We need to have information about submodules to correctly deserialize | 
|  | 4788 | // decls from OpenCLExtensionDecls block | 
|  | 4789 | WriteOpenCLExtensionDecls(SemaRef); | 
|  | 4790 |  | 
| Douglas Gregor | 5204bde | 2011-08-02 16:26:37 +0000 | [diff] [blame] | 4791 | Stream.EmitRecord(SPECIAL_TYPES, SpecialTypes); | 
|  | 4792 |  | 
| Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4793 | // Write the record containing external, unnamed definitions. | 
| Ben Langmuir | 332aafe | 2014-01-31 01:06:56 +0000 | [diff] [blame] | 4794 | if (!EagerlyDeserializedDecls.empty()) | 
|  | 4795 | Stream.EmitRecord(EAGERLY_DESERIALIZED_DECLS, EagerlyDeserializedDecls); | 
| Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4796 |  | 
| David Blaikie | f63556d | 2017-04-12 20:58:33 +0000 | [diff] [blame] | 4797 | if (!ModularCodegenDecls.empty()) | 
| David Blaikie | 9ffe5a3 | 2017-01-30 05:00:26 +0000 | [diff] [blame] | 4798 | Stream.EmitRecord(MODULAR_CODEGEN_DECLS, ModularCodegenDecls); | 
|  | 4799 |  | 
| Douglas Gregor | d4df865 | 2009-04-22 22:02:47 +0000 | [diff] [blame] | 4800 | // Write the record containing tentative definitions. | 
|  | 4801 | if (!TentativeDefinitions.empty()) | 
| Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4802 | Stream.EmitRecord(TENTATIVE_DEFINITIONS, TentativeDefinitions); | 
| Douglas Gregor | acfc76c | 2009-04-22 22:18:58 +0000 | [diff] [blame] | 4803 |  | 
| Argyrios Kyrtzidis | 35672e7 | 2010-08-13 18:42:17 +0000 | [diff] [blame] | 4804 | // Write the record containing unused file scoped decls. | 
|  | 4805 | if (!UnusedFileScopedDecls.empty()) | 
| Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4806 | Stream.EmitRecord(UNUSED_FILESCOPED_DECLS, UnusedFileScopedDecls); | 
| Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 4807 |  | 
| Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 4808 | // Write the record containing weak undeclared identifiers. | 
|  | 4809 | if (!WeakUndeclaredIdentifiers.empty()) | 
| Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4810 | Stream.EmitRecord(WEAK_UNDECLARED_IDENTIFIERS, | 
| Argyrios Kyrtzidis | ee1afa3 | 2010-08-05 09:48:08 +0000 | [diff] [blame] | 4811 | WeakUndeclaredIdentifiers); | 
|  | 4812 |  | 
| Douglas Gregor | 61cac2b | 2009-04-27 20:06:05 +0000 | [diff] [blame] | 4813 | // Write the record containing ext_vector type names. | 
|  | 4814 | if (!ExtVectorDecls.empty()) | 
| Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4815 | Stream.EmitRecord(EXT_VECTOR_DECLS, ExtVectorDecls); | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 4816 |  | 
| Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4817 | // Write the record containing VTable uses information. | 
|  | 4818 | if (!VTableUses.empty()) | 
| Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4819 | Stream.EmitRecord(VTABLE_USES, VTableUses); | 
| Argyrios Kyrtzidis | af2eac2 | 2010-07-06 15:37:04 +0000 | [diff] [blame] | 4820 |  | 
| Nico Weber | 7288943 | 2014-09-06 01:25:55 +0000 | [diff] [blame] | 4821 | // Write the record containing potentially unused local typedefs. | 
|  | 4822 | if (!UnusedLocalTypedefNameCandidates.empty()) | 
|  | 4823 | Stream.EmitRecord(UNUSED_LOCAL_TYPEDEF_NAME_CANDIDATES, | 
|  | 4824 | UnusedLocalTypedefNameCandidates); | 
|  | 4825 |  | 
| Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 4826 | // Write the record containing pending implicit instantiations. | 
| Chandler Carruth | 5408017 | 2010-08-25 08:44:16 +0000 | [diff] [blame] | 4827 | if (!PendingInstantiations.empty()) | 
|  | 4828 | Stream.EmitRecord(PENDING_IMPLICIT_INSTANTIATIONS, PendingInstantiations); | 
| Argyrios Kyrtzidis | 7f76d11 | 2010-08-05 09:48:16 +0000 | [diff] [blame] | 4829 |  | 
| Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4830 | // Write the record containing declaration references of Sema. | 
|  | 4831 | if (!SemaDeclRefs.empty()) | 
| Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4832 | Stream.EmitRecord(SEMA_DECL_REFS, SemaDeclRefs); | 
| Argyrios Kyrtzidis | 2d68810 | 2010-08-02 07:14:54 +0000 | [diff] [blame] | 4833 |  | 
| Yaxun (Sam) Liu | b670ab7 | 2020-02-26 10:57:39 -0500 | [diff] [blame] | 4834 | // Write the record containing decls to be checked for deferred diags. | 
|  | 4835 | if (!DeclsToCheckForDeferredDiags.empty()) | 
|  | 4836 | Stream.EmitRecord(DECLS_TO_CHECK_FOR_DEFERRED_DIAGS, | 
|  | 4837 | DeclsToCheckForDeferredDiags); | 
|  | 4838 |  | 
| Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 4839 | // Write the record containing CUDA-specific declaration references. | 
|  | 4840 | if (!CUDASpecialDeclRefs.empty()) | 
|  | 4841 | Stream.EmitRecord(CUDA_SPECIAL_DECL_REFS, CUDASpecialDeclRefs); | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 4842 |  | 
| Alexis Hunt | 27a761d | 2011-05-04 23:29:54 +0000 | [diff] [blame] | 4843 | // Write the delegating constructors. | 
|  | 4844 | if (!DelegatingCtorDecls.empty()) | 
|  | 4845 | Stream.EmitRecord(DELEGATING_CTORS, DelegatingCtorDecls); | 
| Peter Collingbourne | 9e2c81f | 2011-02-09 21:04:32 +0000 | [diff] [blame] | 4846 |  | 
| Douglas Gregor | c2fa169 | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 4847 | // Write the known namespaces. | 
|  | 4848 | if (!KnownNamespaces.empty()) | 
|  | 4849 | Stream.EmitRecord(KNOWN_NAMESPACES, KnownNamespaces); | 
| Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 4850 |  | 
| Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 4851 | // Write the undefined internal functions and variables, and inline functions. | 
|  | 4852 | if (!UndefinedButUsed.empty()) | 
|  | 4853 | Stream.EmitRecord(UNDEFINED_BUT_USED, UndefinedButUsed); | 
| Ismail Pazarbasi | e5768d1 | 2015-05-18 19:59:11 +0000 | [diff] [blame] | 4854 |  | 
|  | 4855 | if (!DeleteExprsToAnalyze.empty()) | 
|  | 4856 | Stream.EmitRecord(DELETE_EXPRS_TO_ANALYZE, DeleteExprsToAnalyze); | 
|  | 4857 |  | 
| Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4858 | // Write the visible updates to DeclContexts. | 
| Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4859 | for (auto *DC : UpdatedDeclContexts) | 
|  | 4860 | WriteDeclContextVisibleUpdate(DC); | 
| Douglas Gregor | 851443c | 2011-08-12 01:39:19 +0000 | [diff] [blame] | 4861 |  | 
| Douglas Gregor | 959bb06 | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 4862 | if (!WritingModule) { | 
|  | 4863 | // Write the submodules that were imported, if any. | 
| Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4864 | struct ModuleInfo { | 
|  | 4865 | uint64_t ID; | 
|  | 4866 | Module *M; | 
|  | 4867 | ModuleInfo(uint64_t ID, Module *M) : ID(ID), M(M) {} | 
|  | 4868 | }; | 
| Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4869 | llvm::SmallVector<ModuleInfo, 64> Imports; | 
| Aaron Ballman | bbc3121 | 2014-03-14 20:59:21 +0000 | [diff] [blame] | 4870 | for (const auto *I : Context.local_imports()) { | 
| Douglas Gregor | 959bb06 | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 4871 | assert(SubmoduleIDs.find(I->getImportedModule()) != SubmoduleIDs.end()); | 
| Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 4872 | Imports.push_back(ModuleInfo(SubmoduleIDs[I->getImportedModule()], | 
|  | 4873 | I->getImportedModule())); | 
| Douglas Gregor | 959bb06 | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 4874 | } | 
| Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4875 |  | 
|  | 4876 | if (!Imports.empty()) { | 
|  | 4877 | auto Cmp = [](const ModuleInfo &A, const ModuleInfo &B) { | 
|  | 4878 | return A.ID < B.ID; | 
|  | 4879 | }; | 
| Ben Langmuir | 5f95c8f | 2014-09-08 20:36:26 +0000 | [diff] [blame] | 4880 | auto Eq = [](const ModuleInfo &A, const ModuleInfo &B) { | 
|  | 4881 | return A.ID == B.ID; | 
|  | 4882 | }; | 
| Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4883 |  | 
|  | 4884 | // Sort and deduplicate module IDs. | 
| Fangrui Song | 55fab26 | 2018-09-26 22:16:28 +0000 | [diff] [blame] | 4885 | llvm::sort(Imports, Cmp); | 
| Ben Langmuir | 5f95c8f | 2014-09-08 20:36:26 +0000 | [diff] [blame] | 4886 | Imports.erase(std::unique(Imports.begin(), Imports.end(), Eq), | 
| Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4887 | Imports.end()); | 
|  | 4888 |  | 
|  | 4889 | RecordData ImportedModules; | 
|  | 4890 | for (const auto &Import : Imports) { | 
|  | 4891 | ImportedModules.push_back(Import.ID); | 
|  | 4892 | // FIXME: If the module has macros imported then later has declarations | 
|  | 4893 | // imported, this location won't be the right one as a location for the | 
|  | 4894 | // declaration imports. | 
| Richard Smith | 10434f3 | 2015-05-02 02:08:26 +0000 | [diff] [blame] | 4895 | AddSourceLocation(PP.getModuleImportLoc(Import.M), ImportedModules); | 
| Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4896 | } | 
|  | 4897 |  | 
| Douglas Gregor | 959bb06 | 2011-12-03 01:15:29 +0000 | [diff] [blame] | 4898 | Stream.EmitRecord(IMPORTED_MODULES, ImportedModules); | 
|  | 4899 | } | 
| Douglas Gregor | 0a83913 | 2011-12-03 00:59:55 +0000 | [diff] [blame] | 4900 | } | 
| Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 4901 |  | 
| Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4902 | WriteObjCCategories(); | 
| Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 4903 | if(!WritingModule) { | 
| Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 4904 | WriteOptimizePragmaOptions(SemaRef); | 
| Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 4905 | WriteMSStructPragmaOptions(SemaRef); | 
| Nico Weber | 4293231 | 2016-03-03 00:17:35 +0000 | [diff] [blame] | 4906 | WriteMSPointersToMembersPragmaOptions(SemaRef); | 
| Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 4907 | } | 
| Alex Lorenz | 7d7e1e0 | 2017-03-31 15:36:21 +0000 | [diff] [blame] | 4908 | WritePackPragmaOptions(SemaRef); | 
| Melanie Blower | f5360d4 | 2020-05-01 10:32:06 -0700 | [diff] [blame] | 4909 | WriteFloatControlPragmaOptions(SemaRef); | 
| Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 4910 |  | 
| Douglas Gregor | 08f0129 | 2009-04-17 22:13:46 +0000 | [diff] [blame] | 4911 | // Some simple statistics | 
| Mehdi Amini | 57a4191 | 2015-09-10 01:46:39 +0000 | [diff] [blame] | 4912 | RecordData::value_type Record[] = { | 
|  | 4913 | NumStatements, NumMacros, NumLexicalDeclContexts, NumVisibleDeclContexts}; | 
| Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 4914 | Stream.EmitRecord(STATISTICS, Record); | 
| Douglas Gregor | 8f45df5 | 2009-04-16 22:23:12 +0000 | [diff] [blame] | 4915 | Stream.ExitBlock(); | 
| Adrian Prantl | adbd2b1 | 2015-09-22 23:26:31 +0000 | [diff] [blame] | 4916 |  | 
| Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4917 | // Write the module file extension blocks. | 
|  | 4918 | for (const auto &ExtWriter : ModuleFileExtensionWriters) | 
| Douglas Gregor | 8f64ca1 | 2015-12-08 22:43:32 +0000 | [diff] [blame] | 4919 | WriteModuleFileExtension(SemaRef, *ExtWriter); | 
| Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4920 |  | 
| Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4921 | return writeUnhashedControlBlock(PP, Context); | 
| Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 4922 | } | 
|  | 4923 |  | 
| Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 4924 | void ASTWriter::WriteDeclUpdatesBlocks(RecordDataImpl &OffsetsRecord) { | 
| Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4925 | if (DeclUpdates.empty()) | 
|  | 4926 | return; | 
|  | 4927 |  | 
| Richard Smith | 59442b4 | 2014-03-20 20:07:19 +0000 | [diff] [blame] | 4928 | DeclUpdateMap LocalUpdates; | 
|  | 4929 | LocalUpdates.swap(DeclUpdates); | 
|  | 4930 |  | 
| Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4931 | for (auto &DeclUpdate : LocalUpdates) { | 
|  | 4932 | const Decl *D = DeclUpdate.first; | 
| Argyrios Kyrtzidis | 3ba70b8 | 2010-10-24 17:26:46 +0000 | [diff] [blame] | 4933 |  | 
| Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 4934 | bool HasUpdatedBody = false; | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4935 | RecordData RecordData; | 
|  | 4936 | ASTRecordWriter Record(*this, RecordData); | 
| Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4937 | for (auto &Update : DeclUpdate.second) { | 
|  | 4938 | DeclUpdateKind Kind = (DeclUpdateKind)Update.getKind(); | 
|  | 4939 |  | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4940 | // An updated body is emitted last, so that the reader doesn't need | 
|  | 4941 | // to skip over the lazy body to reach statements for other records. | 
|  | 4942 | if (Kind == UPD_CXX_ADDED_FUNCTION_DEFINITION) | 
|  | 4943 | HasUpdatedBody = true; | 
|  | 4944 | else | 
|  | 4945 | Record.push_back(Kind); | 
|  | 4946 |  | 
| Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4947 | switch (Kind) { | 
|  | 4948 | case UPD_CXX_ADDED_IMPLICIT_MEMBER: | 
|  | 4949 | case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION: | 
|  | 4950 | case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: | 
| Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4951 | assert(Update.getDecl() && "no decl to add?"); | 
| Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 4952 | Record.push_back(GetDeclRef(Update.getDecl())); | 
|  | 4953 | break; | 
|  | 4954 |  | 
| Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 4955 | case UPD_CXX_ADDED_FUNCTION_DEFINITION: | 
| Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 4956 | break; | 
|  | 4957 |  | 
| Richard Smith | 891fc7f | 2017-12-05 01:31:47 +0000 | [diff] [blame] | 4958 | case UPD_CXX_POINT_OF_INSTANTIATION: | 
|  | 4959 | // FIXME: Do we need to also save the template specialization kind here? | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4960 | Record.AddSourceLocation(Update.getLoc()); | 
| Richard Smith | 891fc7f | 2017-12-05 01:31:47 +0000 | [diff] [blame] | 4961 | break; | 
|  | 4962 |  | 
|  | 4963 | case UPD_CXX_ADDED_VAR_DEFINITION: { | 
|  | 4964 | const VarDecl *VD = cast<VarDecl>(D); | 
| Richard Smith | f501759 | 2017-11-02 01:06:00 +0000 | [diff] [blame] | 4965 | Record.push_back(VD->isInline()); | 
|  | 4966 | Record.push_back(VD->isInlineSpecified()); | 
| Richard Smith | 05a2135 | 2017-06-22 22:18:46 +0000 | [diff] [blame] | 4967 | if (VD->getInit()) { | 
|  | 4968 | Record.push_back(!VD->isInitKnownICE() ? 1 | 
|  | 4969 | : (VD->isInitICE() ? 3 : 2)); | 
|  | 4970 | Record.AddStmt(const_cast<Expr*>(VD->getInit())); | 
|  | 4971 | } else { | 
|  | 4972 | Record.push_back(0); | 
|  | 4973 | } | 
| Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 4974 | break; | 
| Richard Smith | 05a2135 | 2017-06-22 22:18:46 +0000 | [diff] [blame] | 4975 | } | 
| Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 4976 |  | 
| John McCall | 32791cc | 2016-01-06 22:34:54 +0000 | [diff] [blame] | 4977 | case UPD_CXX_INSTANTIATED_DEFAULT_ARGUMENT: | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 4978 | Record.AddStmt(const_cast<Expr *>( | 
|  | 4979 | cast<ParmVarDecl>(Update.getDecl())->getDefaultArg())); | 
| John McCall | 32791cc | 2016-01-06 22:34:54 +0000 | [diff] [blame] | 4980 | break; | 
|  | 4981 |  | 
| Richard Smith | 4b054b2 | 2016-08-24 21:25:37 +0000 | [diff] [blame] | 4982 | case UPD_CXX_INSTANTIATED_DEFAULT_MEMBER_INITIALIZER: | 
|  | 4983 | Record.AddStmt( | 
|  | 4984 | cast<FieldDecl>(Update.getDecl())->getInClassInitializer()); | 
|  | 4985 | break; | 
|  | 4986 |  | 
| Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4987 | case UPD_CXX_INSTANTIATED_CLASS_DEFINITION: { | 
|  | 4988 | auto *RD = cast<CXXRecordDecl>(D); | 
| Chandler Carruth | 8a3d24d | 2015-03-26 04:27:10 +0000 | [diff] [blame] | 4989 | UpdatedDeclContexts.insert(RD->getPrimaryContext()); | 
| Akira Hatanaka | fcbe17c | 2018-03-28 21:13:14 +0000 | [diff] [blame] | 4990 | Record.push_back(RD->isParamDestroyedInCallee()); | 
| Akira Hatanaka | e6313ac | 2018-04-09 22:48:22 +0000 | [diff] [blame] | 4991 | Record.push_back(RD->getArgPassingRestrictions()); | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 4992 | Record.AddCXXDefinitionData(RD); | 
| Richard Smith | 72e50fe | 2016-04-14 00:50:18 +0000 | [diff] [blame] | 4993 | Record.AddOffset(WriteDeclContextLexicalBlock( | 
| Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4994 | *Context, const_cast<CXXRecordDecl *>(RD))); | 
|  | 4995 |  | 
|  | 4996 | // This state is sometimes updated by template instantiation, when we | 
|  | 4997 | // switch from the specialization referring to the template declaration | 
|  | 4998 | // to it referring to the template definition. | 
|  | 4999 | if (auto *MSInfo = RD->getMemberSpecializationInfo()) { | 
|  | 5000 | Record.push_back(MSInfo->getTemplateSpecializationKind()); | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5001 | Record.AddSourceLocation(MSInfo->getPointOfInstantiation()); | 
| Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 5002 | } else { | 
|  | 5003 | auto *Spec = cast<ClassTemplateSpecializationDecl>(RD); | 
|  | 5004 | Record.push_back(Spec->getTemplateSpecializationKind()); | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5005 | Record.AddSourceLocation(Spec->getPointOfInstantiation()); | 
| Richard Smith | df35205 | 2014-05-22 20:59:29 +0000 | [diff] [blame] | 5006 |  | 
|  | 5007 | // The instantiation might have been resolved to a partial | 
|  | 5008 | // specialization. If so, record which one. | 
|  | 5009 | auto From = Spec->getInstantiatedFrom(); | 
|  | 5010 | if (auto PartialSpec = | 
|  | 5011 | From.dyn_cast<ClassTemplatePartialSpecializationDecl*>()) { | 
|  | 5012 | Record.push_back(true); | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5013 | Record.AddDeclRef(PartialSpec); | 
|  | 5014 | Record.AddTemplateArgumentList( | 
|  | 5015 | &Spec->getTemplateInstantiationArgs()); | 
| Richard Smith | df35205 | 2014-05-22 20:59:29 +0000 | [diff] [blame] | 5016 | } else { | 
|  | 5017 | Record.push_back(false); | 
|  | 5018 | } | 
| Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 5019 | } | 
|  | 5020 | Record.push_back(RD->getTagKind()); | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5021 | Record.AddSourceLocation(RD->getLocation()); | 
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5022 | Record.AddSourceLocation(RD->getBeginLoc()); | 
| Argyrios Kyrtzidis | d798c05 | 2016-07-15 18:11:33 +0000 | [diff] [blame] | 5023 | Record.AddSourceRange(RD->getBraceRange()); | 
| Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 5024 |  | 
|  | 5025 | // Instantiation may change attributes; write them all out afresh. | 
|  | 5026 | Record.push_back(D->hasAttrs()); | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5027 | if (D->hasAttrs()) | 
|  | 5028 | Record.AddAttributes(D->getAttrs()); | 
| Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 5029 |  | 
|  | 5030 | // FIXME: Ensure we don't get here for explicit instantiations. | 
|  | 5031 | break; | 
|  | 5032 | } | 
|  | 5033 |  | 
| Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 5034 | case UPD_CXX_RESOLVED_DTOR_DELETE: | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5035 | Record.AddDeclRef(Update.getDecl()); | 
| Richard Smith | 5b34958 | 2017-10-13 01:55:36 +0000 | [diff] [blame] | 5036 | Record.AddStmt(cast<CXXDestructorDecl>(D)->getOperatorDeleteThisArg()); | 
| Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 5037 | break; | 
|  | 5038 |  | 
| John McCall | d505e57 | 2019-12-13 21:54:44 -0500 | [diff] [blame] | 5039 | case UPD_CXX_RESOLVED_EXCEPTION_SPEC: { | 
|  | 5040 | auto prototype = | 
|  | 5041 | cast<FunctionDecl>(D)->getType()->castAs<FunctionProtoType>(); | 
|  | 5042 | Record.writeExceptionSpecInfo(prototype->getExceptionSpecInfo()); | 
| Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 5043 | break; | 
| John McCall | d505e57 | 2019-12-13 21:54:44 -0500 | [diff] [blame] | 5044 | } | 
| Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 5045 |  | 
| Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 5046 | case UPD_CXX_DEDUCED_RETURN_TYPE: | 
|  | 5047 | Record.push_back(GetOrCreateTypeID(Update.getType())); | 
|  | 5048 | break; | 
|  | 5049 |  | 
|  | 5050 | case UPD_DECL_MARKED_USED: | 
|  | 5051 | break; | 
| Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 5052 |  | 
|  | 5053 | case UPD_MANGLING_NUMBER: | 
|  | 5054 | case UPD_STATIC_LOCAL_NUMBER: | 
|  | 5055 | Record.push_back(Update.getNumber()); | 
|  | 5056 | break; | 
| Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 5057 |  | 
| Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 5058 | case UPD_DECL_MARKED_OPENMP_THREADPRIVATE: | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5059 | Record.AddSourceRange( | 
|  | 5060 | D->getAttr<OMPThreadPrivateDeclAttr>()->getRange()); | 
| Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 5061 | break; | 
| Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 5062 |  | 
| Alexey Bataev | 27ef951 | 2019-03-20 20:14:22 +0000 | [diff] [blame] | 5063 | case UPD_DECL_MARKED_OPENMP_ALLOCATE: { | 
|  | 5064 | auto *A = D->getAttr<OMPAllocateDeclAttr>(); | 
|  | 5065 | Record.push_back(A->getAllocatorType()); | 
|  | 5066 | Record.AddStmt(A->getAllocator()); | 
|  | 5067 | Record.AddSourceRange(A->getRange()); | 
| Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 5068 | break; | 
| Alexey Bataev | 27ef951 | 2019-03-20 20:14:22 +0000 | [diff] [blame] | 5069 | } | 
| Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 5070 |  | 
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 5071 | case UPD_DECL_MARKED_OPENMP_DECLARETARGET: | 
| Alexey Bataev | d01b749 | 2018-08-15 19:45:12 +0000 | [diff] [blame] | 5072 | Record.push_back(D->getAttr<OMPDeclareTargetDeclAttr>()->getMapType()); | 
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 5073 | Record.AddSourceRange( | 
|  | 5074 | D->getAttr<OMPDeclareTargetDeclAttr>()->getRange()); | 
|  | 5075 | break; | 
|  | 5076 |  | 
| Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 5077 | case UPD_DECL_EXPORTED: | 
| Richard Smith | 4caa449 | 2015-05-15 02:34:32 +0000 | [diff] [blame] | 5078 | Record.push_back(getSubmoduleID(Update.getModule())); | 
| Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 5079 | break; | 
| Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 5080 |  | 
|  | 5081 | case UPD_ADDED_ATTR_TO_RECORD: | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5082 | Record.AddAttributes(llvm::makeArrayRef(Update.getAttr())); | 
| Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 5083 | break; | 
| Richard Smith | 6ef4293 | 2014-03-20 21:02:00 +0000 | [diff] [blame] | 5084 | } | 
|  | 5085 | } | 
|  | 5086 |  | 
| Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 5087 | if (HasUpdatedBody) { | 
| Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 5088 | const auto *Def = cast<FunctionDecl>(D); | 
| Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 5089 | Record.push_back(UPD_CXX_ADDED_FUNCTION_DEFINITION); | 
| Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 5090 | Record.push_back(Def->isInlined()); | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5091 | Record.AddSourceLocation(Def->getInnerLocStart()); | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5092 | Record.AddFunctionDefinition(Def); | 
| Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 5093 | } | 
|  | 5094 |  | 
| Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 5095 | OffsetsRecord.push_back(GetDeclRef(D)); | 
| Richard Smith | 69c82bf | 2016-04-01 22:52:03 +0000 | [diff] [blame] | 5096 | OffsetsRecord.push_back(Record.Emit(DECL_UPDATES)); | 
| Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5097 | } | 
| Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5098 | } | 
|  | 5099 |  | 
| Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5100 | void ASTWriter::AddSourceLocation(SourceLocation Loc, RecordDataImpl &Record) { | 
| Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 5101 | uint32_t Raw = Loc.getRawEncoding(); | 
|  | 5102 | Record.push_back((Raw << 1) | (Raw >> 31)); | 
| Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5103 | } | 
|  | 5104 |  | 
| Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5105 | void ASTWriter::AddSourceRange(SourceRange Range, RecordDataImpl &Record) { | 
| Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 5106 | AddSourceLocation(Range.getBegin(), Record); | 
|  | 5107 | AddSourceLocation(Range.getEnd(), Record); | 
|  | 5108 | } | 
|  | 5109 |  | 
| Richard Smith | f144b54 | 2016-04-08 21:54:32 +0000 | [diff] [blame] | 5110 | void ASTRecordWriter::AddAPFloat(const llvm::APFloat &Value) { | 
|  | 5111 | AddAPInt(Value.bitcastToAPInt()); | 
| Douglas Gregor | e0a3a51 | 2009-04-14 21:55:33 +0000 | [diff] [blame] | 5112 | } | 
|  | 5113 |  | 
| Gauthier Harnisch | 83c7b61 | 2019-06-15 10:24:47 +0000 | [diff] [blame] | 5114 | static void WriteFixedPointSemantics(ASTRecordWriter &Record, | 
|  | 5115 | FixedPointSemantics FPSema) { | 
|  | 5116 | Record.push_back(FPSema.getWidth()); | 
|  | 5117 | Record.push_back(FPSema.getScale()); | 
|  | 5118 | Record.push_back(FPSema.isSigned() | FPSema.isSaturated() << 1 | | 
|  | 5119 | FPSema.hasUnsignedPadding() << 2); | 
|  | 5120 | } | 
|  | 5121 |  | 
|  | 5122 | void ASTRecordWriter::AddAPValue(const APValue &Value) { | 
|  | 5123 | APValue::ValueKind Kind = Value.getKind(); | 
|  | 5124 | push_back(static_cast<uint64_t>(Kind)); | 
|  | 5125 | switch (Kind) { | 
|  | 5126 | case APValue::None: | 
|  | 5127 | case APValue::Indeterminate: | 
|  | 5128 | return; | 
|  | 5129 | case APValue::Int: | 
|  | 5130 | AddAPSInt(Value.getInt()); | 
|  | 5131 | return; | 
|  | 5132 | case APValue::Float: | 
|  | 5133 | push_back(static_cast<uint64_t>( | 
|  | 5134 | llvm::APFloatBase::SemanticsToEnum(Value.getFloat().getSemantics()))); | 
|  | 5135 | AddAPFloat(Value.getFloat()); | 
|  | 5136 | return; | 
|  | 5137 | case APValue::FixedPoint: { | 
|  | 5138 | WriteFixedPointSemantics(*this, Value.getFixedPoint().getSemantics()); | 
|  | 5139 | AddAPSInt(Value.getFixedPoint().getValue()); | 
|  | 5140 | return; | 
|  | 5141 | } | 
|  | 5142 | case APValue::ComplexInt: { | 
|  | 5143 | AddAPSInt(Value.getComplexIntReal()); | 
|  | 5144 | AddAPSInt(Value.getComplexIntImag()); | 
|  | 5145 | return; | 
|  | 5146 | } | 
|  | 5147 | case APValue::ComplexFloat: { | 
|  | 5148 | push_back(static_cast<uint64_t>(llvm::APFloatBase::SemanticsToEnum( | 
|  | 5149 | Value.getComplexFloatReal().getSemantics()))); | 
|  | 5150 | AddAPFloat(Value.getComplexFloatReal()); | 
|  | 5151 | push_back(static_cast<uint64_t>(llvm::APFloatBase::SemanticsToEnum( | 
|  | 5152 | Value.getComplexFloatImag().getSemantics()))); | 
|  | 5153 | AddAPFloat(Value.getComplexFloatImag()); | 
|  | 5154 | return; | 
|  | 5155 | } | 
|  | 5156 | case APValue::LValue: | 
|  | 5157 | case APValue::Vector: | 
|  | 5158 | case APValue::Array: | 
|  | 5159 | case APValue::Struct: | 
|  | 5160 | case APValue::Union: | 
|  | 5161 | case APValue::MemberPointer: | 
|  | 5162 | case APValue::AddrLabelDiff: | 
|  | 5163 | // TODO : Handle all these APValue::ValueKind. | 
|  | 5164 | return; | 
|  | 5165 | } | 
|  | 5166 | llvm_unreachable("Invalid APValue::ValueKind"); | 
|  | 5167 | } | 
|  | 5168 |  | 
| Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5169 | void ASTWriter::AddIdentifierRef(const IdentifierInfo *II, RecordDataImpl &Record) { | 
| Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 5170 | Record.push_back(getIdentifierRef(II)); | 
|  | 5171 | } | 
|  | 5172 |  | 
| Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5173 | IdentID ASTWriter::getIdentifierRef(const IdentifierInfo *II) { | 
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5174 | if (!II) | 
| Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 5175 | return 0; | 
| Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 5176 |  | 
| Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5177 | IdentID &ID = IdentifierIDs[II]; | 
| Douglas Gregor | 3ed42cb | 2009-04-11 00:14:32 +0000 | [diff] [blame] | 5178 | if (ID == 0) | 
| Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 5179 | ID = NextIdentID++; | 
| Douglas Gregor | 4621c6a | 2009-04-22 18:49:13 +0000 | [diff] [blame] | 5180 | return ID; | 
| Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5181 | } | 
|  | 5182 |  | 
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5183 | MacroID ASTWriter::getMacroRef(MacroInfo *MI, const IdentifierInfo *Name) { | 
| Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5184 | // Don't emit builtin macros like __LINE__ to the AST file unless they | 
|  | 5185 | // have been redefined by the header (in which case they are not | 
|  | 5186 | // isBuiltinMacro). | 
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5187 | if (!MI || MI->isBuiltinMacro()) | 
| Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5188 | return 0; | 
|  | 5189 |  | 
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5190 | MacroID &ID = MacroIDs[MI]; | 
|  | 5191 | if (ID == 0) { | 
| Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5192 | ID = NextMacroID++; | 
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5193 | MacroInfoToEmitData Info = { Name, MI, ID }; | 
|  | 5194 | MacroInfosToEmit.push_back(Info); | 
|  | 5195 | } | 
| Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5196 | return ID; | 
|  | 5197 | } | 
|  | 5198 |  | 
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5199 | MacroID ASTWriter::getMacroID(MacroInfo *MI) { | 
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5200 | if (!MI || MI->isBuiltinMacro()) | 
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5201 | return 0; | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 5202 |  | 
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5203 | assert(MacroIDs.find(MI) != MacroIDs.end() && "Macro not emitted!"); | 
|  | 5204 | return MacroIDs[MI]; | 
|  | 5205 | } | 
|  | 5206 |  | 
| Dmitry Polukhin | a7afb21 | 2020-04-16 09:24:46 -0700 | [diff] [blame] | 5207 | uint32_t ASTWriter::getMacroDirectivesOffset(const IdentifierInfo *Name) { | 
| Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 5208 | return IdentMacroDirectivesOffsetMap.lookup(Name); | 
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5209 | } | 
|  | 5210 |  | 
| Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5211 | void ASTRecordWriter::AddSelectorRef(const Selector SelRef) { | 
|  | 5212 | Record->push_back(Writer->getSelectorRef(SelRef)); | 
| Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 5213 | } | 
|  | 5214 |  | 
| Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5215 | SelectorID ASTWriter::getSelectorRef(Selector Sel) { | 
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5216 | if (Sel.getAsOpaquePtr() == nullptr) { | 
| Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 5217 | return 0; | 
| Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 5218 | } | 
|  | 5219 |  | 
| Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5220 | SelectorID SID = SelectorIDs[Sel]; | 
| Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 5221 | if (SID == 0 && Chain) { | 
|  | 5222 | // This might trigger a ReadSelector callback, which will set the ID for | 
|  | 5223 | // this selector. | 
|  | 5224 | Chain->LoadSelector(Sel); | 
| Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5225 | SID = SelectorIDs[Sel]; | 
| Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 5226 | } | 
| Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 5227 | if (SID == 0) { | 
| Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 5228 | SID = NextSelectorID++; | 
| Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5229 | SelectorIDs[Sel] = SID; | 
| Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 5230 | } | 
| Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 5231 | return SID; | 
| Steve Naroff | 2ddea05 | 2009-04-23 10:39:46 +0000 | [diff] [blame] | 5232 | } | 
|  | 5233 |  | 
| Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5234 | void ASTRecordWriter::AddCXXTemporary(const CXXTemporary *Temp) { | 
|  | 5235 | AddDeclRef(Temp->getDestructor()); | 
| Chris Lattner | cba8614 | 2010-05-10 00:25:06 +0000 | [diff] [blame] | 5236 | } | 
|  | 5237 |  | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5238 | void ASTRecordWriter::AddTemplateArgumentLocInfo( | 
|  | 5239 | TemplateArgument::ArgKind Kind, const TemplateArgumentLocInfo &Arg) { | 
| Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 5240 | switch (Kind) { | 
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5241 | case TemplateArgument::Expression: | 
| Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 5242 | AddStmt(Arg.getAsExpr()); | 
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5243 | break; | 
|  | 5244 | case TemplateArgument::Type: | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5245 | AddTypeSourceInfo(Arg.getAsTypeSourceInfo()); | 
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5246 | break; | 
| Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 5247 | case TemplateArgument::Template: | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5248 | AddNestedNameSpecifierLoc(Arg.getTemplateQualifierLoc()); | 
|  | 5249 | AddSourceLocation(Arg.getTemplateNameLoc()); | 
| Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 5250 | break; | 
|  | 5251 | case TemplateArgument::TemplateExpansion: | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5252 | AddNestedNameSpecifierLoc(Arg.getTemplateQualifierLoc()); | 
|  | 5253 | AddSourceLocation(Arg.getTemplateNameLoc()); | 
|  | 5254 | AddSourceLocation(Arg.getTemplateEllipsisLoc()); | 
| Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 5255 | break; | 
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5256 | case TemplateArgument::Null: | 
|  | 5257 | case TemplateArgument::Integral: | 
|  | 5258 | case TemplateArgument::Declaration: | 
| Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 5259 | case TemplateArgument::NullPtr: | 
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5260 | case TemplateArgument::Pack: | 
| Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 5261 | // FIXME: Is this right? | 
| John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 5262 | break; | 
|  | 5263 | } | 
|  | 5264 | } | 
|  | 5265 |  | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5266 | void ASTRecordWriter::AddTemplateArgumentLoc(const TemplateArgumentLoc &Arg) { | 
|  | 5267 | AddTemplateArgument(Arg.getArgument()); | 
| Argyrios Kyrtzidis | ddf5f21 | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 5268 |  | 
|  | 5269 | if (Arg.getArgument().getKind() == TemplateArgument::Expression) { | 
|  | 5270 | bool InfoHasSameExpr | 
|  | 5271 | = Arg.getArgument().getAsExpr() == Arg.getLocInfo().getAsExpr(); | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5272 | Record->push_back(InfoHasSameExpr); | 
| Argyrios Kyrtzidis | ddf5f21 | 2010-06-28 09:31:42 +0000 | [diff] [blame] | 5273 | if (InfoHasSameExpr) | 
|  | 5274 | return; // Avoid storing the same expr twice. | 
|  | 5275 | } | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5276 | AddTemplateArgumentLocInfo(Arg.getArgument().getKind(), Arg.getLocInfo()); | 
| Argyrios Kyrtzidis | ae85e24 | 2010-06-22 09:54:59 +0000 | [diff] [blame] | 5277 | } | 
|  | 5278 |  | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5279 | void ASTRecordWriter::AddTypeSourceInfo(TypeSourceInfo *TInfo) { | 
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5280 | if (!TInfo) { | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5281 | AddTypeRef(QualType()); | 
| John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 5282 | return; | 
|  | 5283 | } | 
|  | 5284 |  | 
| Richard Smith | c23d734 | 2018-06-29 20:46:25 +0000 | [diff] [blame] | 5285 | AddTypeRef(TInfo->getType()); | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5286 | AddTypeLoc(TInfo->getTypeLoc()); | 
| Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5287 | } | 
|  | 5288 |  | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5289 | void ASTRecordWriter::AddTypeLoc(TypeLoc TL) { | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5290 | TypeLocWriter TLW(*this); | 
| Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5291 | for (; !TL.isNull(); TL = TL.getNextTypeLoc()) | 
| Kovarththanan Rajaratnam | a9c81a8 | 2010-03-14 07:06:50 +0000 | [diff] [blame] | 5292 | TLW.Visit(TL); | 
| John McCall | 8f115c6 | 2009-10-16 21:56:05 +0000 | [diff] [blame] | 5293 | } | 
|  | 5294 |  | 
| Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5295 | void ASTWriter::AddTypeRef(QualType T, RecordDataImpl &Record) { | 
| Argyrios Kyrtzidis | 9ab44ea | 2010-08-20 16:04:14 +0000 | [diff] [blame] | 5296 | Record.push_back(GetOrCreateTypeID(T)); | 
|  | 5297 | } | 
|  | 5298 |  | 
| Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 5299 | TypeID ASTWriter::GetOrCreateTypeID(QualType T) { | 
| Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 5300 | assert(Context); | 
| Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 5301 | return MakeTypeID(*Context, T, [&](QualType T) -> TypeIdx { | 
|  | 5302 | if (T.isNull()) | 
|  | 5303 | return TypeIdx(); | 
|  | 5304 | assert(!T.getLocalFastQualifiers()); | 
|  | 5305 |  | 
|  | 5306 | TypeIdx &Idx = TypeIdxs[T]; | 
|  | 5307 | if (Idx.getIndex() == 0) { | 
|  | 5308 | if (DoneWritingDeclsAndTypes) { | 
|  | 5309 | assert(0 && "New type seen after serializing all the types to emit!"); | 
|  | 5310 | return TypeIdx(); | 
|  | 5311 | } | 
|  | 5312 |  | 
|  | 5313 | // We haven't seen this type before. Assign it a new ID and put it | 
|  | 5314 | // into the queue of types to emit. | 
|  | 5315 | Idx = TypeIdx(NextTypeID++); | 
|  | 5316 | DeclTypesToEmit.push(T); | 
|  | 5317 | } | 
|  | 5318 | return Idx; | 
|  | 5319 | }); | 
| Argyrios Kyrtzidis | 082e461 | 2010-08-20 16:04:20 +0000 | [diff] [blame] | 5320 | } | 
| Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5321 |  | 
| Argyrios Kyrtzidis | 0734732 | 2010-08-20 16:04:27 +0000 | [diff] [blame] | 5322 | TypeID ASTWriter::getTypeID(QualType T) const { | 
| Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 5323 | assert(Context); | 
| Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 5324 | return MakeTypeID(*Context, T, [&](QualType T) -> TypeIdx { | 
|  | 5325 | if (T.isNull()) | 
| Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 5326 | return TypeIdx(); | 
| Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 5327 | assert(!T.getLocalFastQualifiers()); | 
| Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 5328 |  | 
| Richard Smith | 2095ffe | 2015-03-16 20:11:03 +0000 | [diff] [blame] | 5329 | TypeIdxMap::const_iterator I = TypeIdxs.find(T); | 
|  | 5330 | assert(I != TypeIdxs.end() && "Type not emitted!"); | 
|  | 5331 | return I->second; | 
|  | 5332 | }); | 
| Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5333 | } | 
|  | 5334 |  | 
| Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5335 | void ASTWriter::AddDeclRef(const Decl *D, RecordDataImpl &Record) { | 
| Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 5336 | Record.push_back(GetDeclRef(D)); | 
|  | 5337 | } | 
|  | 5338 |  | 
| Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5339 | DeclID ASTWriter::GetDeclRef(const Decl *D) { | 
| Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5340 | assert(WritingAST && "Cannot request a declaration ID before AST writing"); | 
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5341 |  | 
|  | 5342 | if (!D) { | 
| Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 5343 | return 0; | 
| Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5344 | } | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 5345 |  | 
| Douglas Gregor | b3163e5 | 2012-01-05 22:33:30 +0000 | [diff] [blame] | 5346 | // If D comes from an AST file, its declaration ID is already known and | 
|  | 5347 | // fixed. | 
|  | 5348 | if (D->isFromASTFile()) | 
|  | 5349 | return D->getGlobalID(); | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 5350 |  | 
| Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 5351 | assert(!(reinterpret_cast<uintptr_t>(D) & 0x01) && "Invalid decl pointer"); | 
| Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5352 | DeclID &ID = DeclIDs[D]; | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 5353 | if (ID == 0) { | 
| Argyrios Kyrtzidis | 442dd80 | 2012-07-02 19:19:01 +0000 | [diff] [blame] | 5354 | if (DoneWritingDeclsAndTypes) { | 
|  | 5355 | assert(0 && "New decl seen after serializing all the decls to emit!"); | 
|  | 5356 | return 0; | 
|  | 5357 | } | 
|  | 5358 |  | 
| Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5359 | // We haven't seen this declaration before. Give it a new ID and | 
|  | 5360 | // enqueue it in the list of declarations to emit. | 
| Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 5361 | ID = NextDeclID++; | 
| Douglas Gregor | 12bfa38 | 2009-10-17 00:13:19 +0000 | [diff] [blame] | 5362 | DeclTypesToEmit.push(const_cast<Decl *>(D)); | 
| Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5363 | } | 
|  | 5364 |  | 
| Sebastian Redl | 66c5eef | 2010-07-27 00:17:23 +0000 | [diff] [blame] | 5365 | return ID; | 
| Douglas Gregor | ef84c4b | 2009-04-09 22:27:44 +0000 | [diff] [blame] | 5366 | } | 
|  | 5367 |  | 
| Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5368 | DeclID ASTWriter::getDeclID(const Decl *D) { | 
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5369 | if (!D) | 
| Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 5370 | return 0; | 
|  | 5371 |  | 
| Douglas Gregor | b3163e5 | 2012-01-05 22:33:30 +0000 | [diff] [blame] | 5372 | // If D comes from an AST file, its declaration ID is already known and | 
|  | 5373 | // fixed. | 
|  | 5374 | if (D->isFromASTFile()) | 
|  | 5375 | return D->getGlobalID(); | 
|  | 5376 |  | 
| Douglas Gregor | e84a9da | 2009-04-20 20:36:09 +0000 | [diff] [blame] | 5377 | assert(DeclIDs.find(D) != DeclIDs.end() && "Declaration not emitted!"); | 
|  | 5378 | return DeclIDs[D]; | 
|  | 5379 | } | 
|  | 5380 |  | 
| Argyrios Kyrtzidis | df53da8 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 5381 | void ASTWriter::associateDeclWithFile(const Decl *D, DeclID ID) { | 
| Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5382 | assert(ID); | 
| Argyrios Kyrtzidis | df53da8 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 5383 | assert(D); | 
|  | 5384 |  | 
|  | 5385 | SourceLocation Loc = D->getLocation(); | 
|  | 5386 | if (Loc.isInvalid()) | 
|  | 5387 | return; | 
| Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5388 |  | 
|  | 5389 | // We only keep track of the file-level declarations of each file. | 
|  | 5390 | if (!D->getLexicalDeclContext()->isFileContext()) | 
|  | 5391 | return; | 
| Argyrios Kyrtzidis | e1bc99e | 2012-02-24 19:45:46 +0000 | [diff] [blame] | 5392 | // FIXME: ParmVarDecls that are part of a function type of a parameter of | 
|  | 5393 | // a function/objc method, should not have TU as lexical context. | 
| Argyrios Kyrtzidis | 71b74eb | 2018-01-26 19:26:12 +0000 | [diff] [blame] | 5394 | // TemplateTemplateParmDecls that are part of an alias template, should not | 
|  | 5395 | // have TU as lexical context. | 
|  | 5396 | if (isa<ParmVarDecl>(D) || isa<TemplateTemplateParmDecl>(D)) | 
| Argyrios Kyrtzidis | ffe055a8 | 2012-02-24 01:12:38 +0000 | [diff] [blame] | 5397 | return; | 
| Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5398 |  | 
|  | 5399 | SourceManager &SM = Context->getSourceManager(); | 
| Argyrios Kyrtzidis | df53da8 | 2011-10-28 23:57:43 +0000 | [diff] [blame] | 5400 | SourceLocation FileLoc = SM.getFileLoc(Loc); | 
| Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5401 | assert(SM.isLocalSourceLocation(FileLoc)); | 
| Argyrios Kyrtzidis | 7362e9b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 5402 | FileID FID; | 
|  | 5403 | unsigned Offset; | 
| Benjamin Kramer | 867ea1d | 2014-03-02 13:01:17 +0000 | [diff] [blame] | 5404 | std::tie(FID, Offset) = SM.getDecomposedLoc(FileLoc); | 
| Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5405 | if (FID.isInvalid()) | 
|  | 5406 | return; | 
| Argyrios Kyrtzidis | 4db774a | 2012-10-02 21:09:17 +0000 | [diff] [blame] | 5407 | assert(SM.getSLocEntry(FID).isFile()); | 
| Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5408 |  | 
| David Blaikie | 409df39 | 2020-04-28 18:05:28 -0700 | [diff] [blame] | 5409 | std::unique_ptr<DeclIDInFileInfo> &Info = FileDeclIDs[FID]; | 
| Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5410 | if (!Info) | 
| David Blaikie | 409df39 | 2020-04-28 18:05:28 -0700 | [diff] [blame] | 5411 | Info = std::make_unique<DeclIDInFileInfo>(); | 
| Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5412 |  | 
| Argyrios Kyrtzidis | 7362e9b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 5413 | std::pair<unsigned, serialization::DeclID> LocDecl(Offset, ID); | 
| Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5414 | LocDeclIDsTy &Decls = Info->DeclIDs; | 
|  | 5415 |  | 
| Argyrios Kyrtzidis | 7362e9b | 2011-10-28 23:57:47 +0000 | [diff] [blame] | 5416 | if (Decls.empty() || Decls.back().first <= Offset) { | 
| Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5417 | Decls.push_back(LocDecl); | 
|  | 5418 | return; | 
|  | 5419 | } | 
|  | 5420 |  | 
| Benjamin Kramer | 45025c0 | 2013-08-24 13:22:59 +0000 | [diff] [blame] | 5421 | LocDeclIDsTy::iterator I = | 
| Fangrui Song | 7264a47 | 2019-07-03 08:13:17 +0000 | [diff] [blame] | 5422 | llvm::upper_bound(Decls, LocDecl, llvm::less_first()); | 
| Argyrios Kyrtzidis | 5fc727a | 2011-10-28 22:54:21 +0000 | [diff] [blame] | 5423 |  | 
|  | 5424 | Decls.insert(I, LocDecl); | 
|  | 5425 | } | 
|  | 5426 |  | 
| Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 5427 | unsigned ASTWriter::getAnonymousDeclarationNumber(const NamedDecl *D) { | 
|  | 5428 | assert(needsAnonymousDeclarationNumber(D) && | 
|  | 5429 | "expected an anonymous declaration"); | 
|  | 5430 |  | 
|  | 5431 | // Number the anonymous declarations within this context, if we've not | 
|  | 5432 | // already done so. | 
|  | 5433 | auto It = AnonymousDeclarationNumbers.find(D); | 
|  | 5434 | if (It == AnonymousDeclarationNumbers.end()) { | 
| Richard Smith | 2b56057 | 2015-02-07 03:11:11 +0000 | [diff] [blame] | 5435 | auto *DC = D->getLexicalDeclContext(); | 
|  | 5436 | numberAnonymousDeclsWithin(DC, [&](const NamedDecl *ND, unsigned Number) { | 
|  | 5437 | AnonymousDeclarationNumbers[ND] = Number; | 
|  | 5438 | }); | 
| Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 5439 |  | 
|  | 5440 | It = AnonymousDeclarationNumbers.find(D); | 
|  | 5441 | assert(It != AnonymousDeclarationNumbers.end() && | 
|  | 5442 | "declaration not found within its lexical context"); | 
|  | 5443 | } | 
|  | 5444 |  | 
|  | 5445 | return It->second; | 
|  | 5446 | } | 
|  | 5447 |  | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5448 | void ASTRecordWriter::AddDeclarationNameLoc(const DeclarationNameLoc &DNLoc, | 
|  | 5449 | DeclarationName Name) { | 
| Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5450 | switch (Name.getNameKind()) { | 
|  | 5451 | case DeclarationName::CXXConstructorName: | 
|  | 5452 | case DeclarationName::CXXDestructorName: | 
|  | 5453 | case DeclarationName::CXXConversionFunctionName: | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5454 | AddTypeSourceInfo(DNLoc.NamedType.TInfo); | 
| Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5455 | break; | 
|  | 5456 |  | 
|  | 5457 | case DeclarationName::CXXOperatorName: | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5458 | AddSourceLocation(SourceLocation::getFromRawEncoding( | 
|  | 5459 | DNLoc.CXXOperatorName.BeginOpNameLoc)); | 
| Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5460 | AddSourceLocation( | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5461 | SourceLocation::getFromRawEncoding(DNLoc.CXXOperatorName.EndOpNameLoc)); | 
| Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5462 | break; | 
|  | 5463 |  | 
|  | 5464 | case DeclarationName::CXXLiteralOperatorName: | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5465 | AddSourceLocation(SourceLocation::getFromRawEncoding( | 
|  | 5466 | DNLoc.CXXLiteralOperatorName.OpNameLoc)); | 
| Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5467 | break; | 
|  | 5468 |  | 
|  | 5469 | case DeclarationName::Identifier: | 
|  | 5470 | case DeclarationName::ObjCZeroArgSelector: | 
|  | 5471 | case DeclarationName::ObjCOneArgSelector: | 
|  | 5472 | case DeclarationName::ObjCMultiArgSelector: | 
|  | 5473 | case DeclarationName::CXXUsingDirective: | 
| Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 5474 | case DeclarationName::CXXDeductionGuideName: | 
| Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5475 | break; | 
|  | 5476 | } | 
|  | 5477 | } | 
|  | 5478 |  | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5479 | void ASTRecordWriter::AddDeclarationNameInfo( | 
|  | 5480 | const DeclarationNameInfo &NameInfo) { | 
|  | 5481 | AddDeclarationName(NameInfo.getName()); | 
|  | 5482 | AddSourceLocation(NameInfo.getLoc()); | 
|  | 5483 | AddDeclarationNameLoc(NameInfo.getInfo(), NameInfo.getName()); | 
| Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5484 | } | 
|  | 5485 |  | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5486 | void ASTRecordWriter::AddQualifierInfo(const QualifierInfo &Info) { | 
|  | 5487 | AddNestedNameSpecifierLoc(Info.QualifierLoc); | 
|  | 5488 | Record->push_back(Info.NumTemplParamLists); | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 5489 | for (unsigned i = 0, e = Info.NumTemplParamLists; i != e; ++i) | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5490 | AddTemplateParameterList(Info.TemplParamLists[i]); | 
| Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 5491 | } | 
|  | 5492 |  | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5493 | void ASTRecordWriter::AddNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS) { | 
| Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5494 | // Nested name specifiers usually aren't too long. I think that 8 would | 
| Chris Lattner | 57540c5 | 2011-04-15 05:22:18 +0000 | [diff] [blame] | 5495 | // typically accommodate the vast majority. | 
| Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 5496 | SmallVector<NestedNameSpecifierLoc , 8> NestedNames; | 
| Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5497 |  | 
|  | 5498 | // Push each of the nested-name-specifiers's onto a stack for | 
|  | 5499 | // serialization in reverse order. | 
|  | 5500 | while (NNS) { | 
|  | 5501 | NestedNames.push_back(NNS); | 
|  | 5502 | NNS = NNS.getPrefix(); | 
|  | 5503 | } | 
|  | 5504 |  | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5505 | Record->push_back(NestedNames.size()); | 
| Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5506 | while(!NestedNames.empty()) { | 
|  | 5507 | NNS = NestedNames.pop_back_val(); | 
|  | 5508 | NestedNameSpecifier::SpecifierKind Kind | 
|  | 5509 | = NNS.getNestedNameSpecifier()->getKind(); | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5510 | Record->push_back(Kind); | 
| Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5511 | switch (Kind) { | 
|  | 5512 | case NestedNameSpecifier::Identifier: | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5513 | AddIdentifierRef(NNS.getNestedNameSpecifier()->getAsIdentifier()); | 
|  | 5514 | AddSourceRange(NNS.getLocalSourceRange()); | 
| Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5515 | break; | 
|  | 5516 |  | 
|  | 5517 | case NestedNameSpecifier::Namespace: | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5518 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsNamespace()); | 
|  | 5519 | AddSourceRange(NNS.getLocalSourceRange()); | 
| Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5520 | break; | 
|  | 5521 |  | 
|  | 5522 | case NestedNameSpecifier::NamespaceAlias: | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5523 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsNamespaceAlias()); | 
|  | 5524 | AddSourceRange(NNS.getLocalSourceRange()); | 
| Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5525 | break; | 
|  | 5526 |  | 
|  | 5527 | case NestedNameSpecifier::TypeSpec: | 
|  | 5528 | case NestedNameSpecifier::TypeSpecWithTemplate: | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5529 | Record->push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate); | 
| Richard Smith | c23d734 | 2018-06-29 20:46:25 +0000 | [diff] [blame] | 5530 | AddTypeRef(NNS.getTypeLoc().getType()); | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5531 | AddTypeLoc(NNS.getTypeLoc()); | 
|  | 5532 | AddSourceLocation(NNS.getLocalSourceRange().getEnd()); | 
| Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5533 | break; | 
|  | 5534 |  | 
|  | 5535 | case NestedNameSpecifier::Global: | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5536 | AddSourceLocation(NNS.getLocalSourceRange().getEnd()); | 
| Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5537 | break; | 
| Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 5538 |  | 
|  | 5539 | case NestedNameSpecifier::Super: | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5540 | AddDeclRef(NNS.getNestedNameSpecifier()->getAsRecordDecl()); | 
|  | 5541 | AddSourceRange(NNS.getLocalSourceRange()); | 
| Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 5542 | break; | 
| Douglas Gregor | a9d87bc | 2011-02-25 00:36:19 +0000 | [diff] [blame] | 5543 | } | 
|  | 5544 | } | 
|  | 5545 | } | 
|  | 5546 |  | 
| Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5547 | void ASTRecordWriter::AddTemplateParameterList( | 
|  | 5548 | const TemplateParameterList *TemplateParams) { | 
| Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5549 | assert(TemplateParams && "No TemplateParams!"); | 
| Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5550 | AddSourceLocation(TemplateParams->getTemplateLoc()); | 
|  | 5551 | AddSourceLocation(TemplateParams->getLAngleLoc()); | 
|  | 5552 | AddSourceLocation(TemplateParams->getRAngleLoc()); | 
| Saar Raz | 0330fba | 2019-10-15 18:44:06 +0000 | [diff] [blame] | 5553 |  | 
| Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5554 | Record->push_back(TemplateParams->size()); | 
| Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 5555 | for (const auto &P : *TemplateParams) | 
| Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5556 | AddDeclRef(P); | 
| Saar Raz | 0330fba | 2019-10-15 18:44:06 +0000 | [diff] [blame] | 5557 | if (const Expr *RequiresClause = TemplateParams->getRequiresClause()) { | 
|  | 5558 | Record->push_back(true); | 
|  | 5559 | AddStmt(const_cast<Expr*>(RequiresClause)); | 
|  | 5560 | } else { | 
|  | 5561 | Record->push_back(false); | 
|  | 5562 | } | 
| Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5563 | } | 
|  | 5564 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5565 | /// Emit a template argument list. | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5566 | void ASTRecordWriter::AddTemplateArgumentList( | 
|  | 5567 | const TemplateArgumentList *TemplateArgs) { | 
| Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5568 | assert(TemplateArgs && "No TemplateArgs!"); | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5569 | Record->push_back(TemplateArgs->size()); | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 5570 | for (int i = 0, e = TemplateArgs->size(); i != e; ++i) | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5571 | AddTemplateArgument(TemplateArgs->get(i)); | 
| Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 5572 | } | 
| Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5573 |  | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5574 | void ASTRecordWriter::AddASTTemplateArgumentListInfo( | 
|  | 5575 | const ASTTemplateArgumentListInfo *ASTTemplArgList) { | 
| Enea Zaffanella | 6dbe187 | 2013-08-10 07:24:53 +0000 | [diff] [blame] | 5576 | assert(ASTTemplArgList && "No ASTTemplArgList!"); | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5577 | AddSourceLocation(ASTTemplArgList->LAngleLoc); | 
|  | 5578 | AddSourceLocation(ASTTemplArgList->RAngleLoc); | 
|  | 5579 | Record->push_back(ASTTemplArgList->NumTemplateArgs); | 
| Enea Zaffanella | 6dbe187 | 2013-08-10 07:24:53 +0000 | [diff] [blame] | 5580 | const TemplateArgumentLoc *TemplArgs = ASTTemplArgList->getTemplateArgs(); | 
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 5581 | for (int i = 0, e = ASTTemplArgList->NumTemplateArgs; i != e; ++i) | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5582 | AddTemplateArgumentLoc(TemplArgs[i]); | 
| Enea Zaffanella | 6dbe187 | 2013-08-10 07:24:53 +0000 | [diff] [blame] | 5583 | } | 
| Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5584 |  | 
| Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5585 | void ASTRecordWriter::AddUnresolvedSet(const ASTUnresolvedSet &Set) { | 
|  | 5586 | Record->push_back(Set.size()); | 
| Argyrios Kyrtzidis | 0f05fb9 | 2012-11-28 03:56:16 +0000 | [diff] [blame] | 5587 | for (ASTUnresolvedSet::const_iterator | 
| Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5588 | I = Set.begin(), E = Set.end(); I != E; ++I) { | 
| Richard Smith | e64e745 | 2016-04-18 21:54:58 +0000 | [diff] [blame] | 5589 | AddDeclRef(I.getDecl()); | 
|  | 5590 | Record->push_back(I.getAccess()); | 
| Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 5591 | } | 
|  | 5592 | } | 
| Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5593 |  | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5594 | // FIXME: Move this out of the main ASTRecordWriter interface. | 
|  | 5595 | void ASTRecordWriter::AddCXXBaseSpecifier(const CXXBaseSpecifier &Base) { | 
|  | 5596 | Record->push_back(Base.isVirtual()); | 
|  | 5597 | Record->push_back(Base.isBaseOfClass()); | 
|  | 5598 | Record->push_back(Base.getAccessSpecifierAsWritten()); | 
|  | 5599 | Record->push_back(Base.getInheritConstructors()); | 
|  | 5600 | AddTypeSourceInfo(Base.getTypeSourceInfo()); | 
|  | 5601 | AddSourceRange(Base.getSourceRange()); | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 5602 | AddSourceLocation(Base.isPackExpansion()? Base.getEllipsisLoc() | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5603 | : SourceLocation()); | 
| Argyrios Kyrtzidis | 3701fcd | 2010-07-02 23:30:27 +0000 | [diff] [blame] | 5604 | } | 
| Sebastian Redl | 85b2a6a | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 5605 |  | 
| Richard Smith | 645d2cf | 2016-04-14 00:29:55 +0000 | [diff] [blame] | 5606 | static uint64_t EmitCXXBaseSpecifiers(ASTWriter &W, | 
|  | 5607 | ArrayRef<CXXBaseSpecifier> Bases) { | 
|  | 5608 | ASTWriter::RecordData Record; | 
|  | 5609 | ASTRecordWriter Writer(W, Record); | 
|  | 5610 | Writer.push_back(Bases.size()); | 
| Dmitry Polukhin | 790b540 | 2016-04-06 10:01:46 +0000 | [diff] [blame] | 5611 |  | 
| Richard Smith | 645d2cf | 2016-04-14 00:29:55 +0000 | [diff] [blame] | 5612 | for (auto &Base : Bases) | 
|  | 5613 | Writer.AddCXXBaseSpecifier(Base); | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5614 |  | 
| Richard Smith | 645d2cf | 2016-04-14 00:29:55 +0000 | [diff] [blame] | 5615 | return Writer.Emit(serialization::DECL_CXX_BASE_SPECIFIERS); | 
| Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5616 | } | 
|  | 5617 |  | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5618 | // FIXME: Move this out of the main ASTRecordWriter interface. | 
| Richard Smith | 645d2cf | 2016-04-14 00:29:55 +0000 | [diff] [blame] | 5619 | void ASTRecordWriter::AddCXXBaseSpecifiers(ArrayRef<CXXBaseSpecifier> Bases) { | 
|  | 5620 | AddOffset(EmitCXXBaseSpecifiers(*Writer, Bases)); | 
|  | 5621 | } | 
|  | 5622 |  | 
| Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5623 | static uint64_t | 
|  | 5624 | EmitCXXCtorInitializers(ASTWriter &W, | 
|  | 5625 | ArrayRef<CXXCtorInitializer *> CtorInits) { | 
|  | 5626 | ASTWriter::RecordData Record; | 
|  | 5627 | ASTRecordWriter Writer(W, Record); | 
|  | 5628 | Writer.push_back(CtorInits.size()); | 
| Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5629 |  | 
| Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5630 | for (auto *Init : CtorInits) { | 
| Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5631 | if (Init->isBaseInitializer()) { | 
| Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5632 | Writer.push_back(CTOR_INITIALIZER_BASE); | 
|  | 5633 | Writer.AddTypeSourceInfo(Init->getTypeSourceInfo()); | 
|  | 5634 | Writer.push_back(Init->isBaseVirtual()); | 
| Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5635 | } else if (Init->isDelegatingInitializer()) { | 
| Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5636 | Writer.push_back(CTOR_INITIALIZER_DELEGATING); | 
|  | 5637 | Writer.AddTypeSourceInfo(Init->getTypeSourceInfo()); | 
| Alexis Hunt | 37a477f | 2011-05-04 01:19:08 +0000 | [diff] [blame] | 5638 | } else if (Init->isMemberInitializer()){ | 
| Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5639 | Writer.push_back(CTOR_INITIALIZER_MEMBER); | 
|  | 5640 | Writer.AddDeclRef(Init->getMember()); | 
| Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5641 | } else { | 
| Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5642 | Writer.push_back(CTOR_INITIALIZER_INDIRECT_MEMBER); | 
|  | 5643 | Writer.AddDeclRef(Init->getIndirectMember()); | 
| Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5644 | } | 
| Francois Pichet | d583da0 | 2010-12-04 09:14:42 +0000 | [diff] [blame] | 5645 |  | 
| Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5646 | Writer.AddSourceLocation(Init->getMemberLocation()); | 
|  | 5647 | Writer.AddStmt(Init->getInit()); | 
|  | 5648 | Writer.AddSourceLocation(Init->getLParenLoc()); | 
|  | 5649 | Writer.AddSourceLocation(Init->getRParenLoc()); | 
|  | 5650 | Writer.push_back(Init->isWritten()); | 
| Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 5651 | if (Init->isWritten()) | 
| Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5652 | Writer.push_back(Init->getSourceOrder()); | 
| Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5653 | } | 
| Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5654 |  | 
|  | 5655 | return Writer.Emit(serialization::DECL_CXX_CTOR_INITIALIZERS); | 
| Argyrios Kyrtzidis | 5b6a03f | 2010-08-09 10:54:12 +0000 | [diff] [blame] | 5656 | } | 
|  | 5657 |  | 
| Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 5658 | // FIXME: Move this out of the main ASTRecordWriter interface. | 
|  | 5659 | void ASTRecordWriter::AddCXXCtorInitializers( | 
|  | 5660 | ArrayRef<CXXCtorInitializer *> CtorInits) { | 
|  | 5661 | AddOffset(EmitCXXCtorInitializers(*Writer, CtorInits)); | 
| Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 5662 | } | 
|  | 5663 |  | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5664 | void ASTRecordWriter::AddCXXDefinitionData(const CXXRecordDecl *D) { | 
| Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 5665 | auto &Data = D->data(); | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5666 | Record->push_back(Data.IsLambda); | 
| Richard Smith | 91aeacc | 2019-10-11 00:29:04 +0000 | [diff] [blame] | 5667 |  | 
|  | 5668 | #define FIELD(Name, Width, Merge) \ | 
|  | 5669 | Record->push_back(Data.Name); | 
|  | 5670 | #include "clang/AST/CXXRecordDeclDefinitionBits.def" | 
| Richard Trieu | fd1acbb | 2017-04-11 21:31:00 +0000 | [diff] [blame] | 5671 |  | 
|  | 5672 | // getODRHash will compute the ODRHash if it has not been previously computed. | 
|  | 5673 | Record->push_back(D->getODRHash()); | 
| Hans Wennborg | 7ea9a6e | 2020-02-27 14:33:43 +0100 | [diff] [blame] | 5674 | bool ModulesDebugInfo = Writer->Context->getLangOpts().ModulesDebugInfo && | 
|  | 5675 | Writer->WritingModule && !D->isDependentType(); | 
| David Blaikie | f63556d | 2017-04-12 20:58:33 +0000 | [diff] [blame] | 5676 | Record->push_back(ModulesDebugInfo); | 
|  | 5677 | if (ModulesDebugInfo) | 
| David Blaikie | 1ac9c98 | 2017-04-11 21:13:37 +0000 | [diff] [blame] | 5678 | Writer->ModularCodegenDecls.push_back(Writer->GetDeclRef(D)); | 
|  | 5679 |  | 
| Richard Smith | 561fb15 | 2012-02-25 07:33:38 +0000 | [diff] [blame] | 5680 | // IsLambda bit is already saved. | 
| Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5681 |  | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5682 | Record->push_back(Data.NumBases); | 
| Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5683 | if (Data.NumBases > 0) | 
| Richard Smith | 645d2cf | 2016-04-14 00:29:55 +0000 | [diff] [blame] | 5684 | AddCXXBaseSpecifiers(Data.bases()); | 
|  | 5685 |  | 
| Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5686 | // FIXME: Make VBases lazily computed when needed to avoid storing them. | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5687 | Record->push_back(Data.NumVBases); | 
| Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 5688 | if (Data.NumVBases > 0) | 
| Richard Smith | 645d2cf | 2016-04-14 00:29:55 +0000 | [diff] [blame] | 5689 | AddCXXBaseSpecifiers(Data.vbases()); | 
| Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5690 |  | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5691 | AddUnresolvedSet(Data.Conversions.get(*Writer->Context)); | 
| Richard Smith | 91aeacc | 2019-10-11 00:29:04 +0000 | [diff] [blame] | 5692 | Record->push_back(Data.ComputedVisibleConversions); | 
|  | 5693 | if (Data.ComputedVisibleConversions) | 
|  | 5694 | AddUnresolvedSet(Data.VisibleConversions.get(*Writer->Context)); | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 5695 | // Data.Definition is the owning decl, no need to write it. | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5696 | AddDeclRef(D->getFirstFriend()); | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 5697 |  | 
| Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 5698 | // Add lambda-specific data. | 
|  | 5699 | if (Data.IsLambda) { | 
| Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 5700 | auto &Lambda = D->getLambdaData(); | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5701 | Record->push_back(Lambda.Dependent); | 
|  | 5702 | Record->push_back(Lambda.IsGenericLambda); | 
|  | 5703 | Record->push_back(Lambda.CaptureDefault); | 
|  | 5704 | Record->push_back(Lambda.NumCaptures); | 
|  | 5705 | Record->push_back(Lambda.NumExplicitCaptures); | 
| Michael Liao | 243ebfb | 2019-10-19 00:15:19 +0000 | [diff] [blame] | 5706 | Record->push_back(Lambda.HasKnownInternalLinkage); | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5707 | Record->push_back(Lambda.ManglingNumber); | 
| Richard Smith | 0bae624 | 2016-08-25 00:34:00 +0000 | [diff] [blame] | 5708 | AddDeclRef(D->getLambdaContextDecl()); | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5709 | AddTypeSourceInfo(Lambda.MethodTyInfo); | 
| Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 5710 | for (unsigned I = 0, N = Lambda.NumCaptures; I != N; ++I) { | 
| Benjamin Kramer | f3ca2698 | 2014-05-10 16:31:55 +0000 | [diff] [blame] | 5711 | const LambdaCapture &Capture = Lambda.Captures[I]; | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5712 | AddSourceLocation(Capture.getLocation()); | 
|  | 5713 | Record->push_back(Capture.isImplicit()); | 
|  | 5714 | Record->push_back(Capture.getCaptureKind()); | 
| Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5715 | switch (Capture.getCaptureKind()) { | 
| Faisal Vali | dc6b596 | 2016-03-21 09:25:37 +0000 | [diff] [blame] | 5716 | case LCK_StarThis: | 
| Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5717 | case LCK_This: | 
| Alexey Bataev | 39c81e2 | 2014-08-28 04:28:19 +0000 | [diff] [blame] | 5718 | case LCK_VLAType: | 
| Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5719 | break; | 
|  | 5720 | case LCK_ByCopy: | 
| Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 5721 | case LCK_ByRef: | 
| Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5722 | VarDecl *Var = | 
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5723 | Capture.capturesVariable() ? Capture.getCapturedVar() : nullptr; | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5724 | AddDeclRef(Var); | 
| Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5725 | AddSourceLocation(Capture.isPackExpansion() ? Capture.getEllipsisLoc() | 
| Richard Smith | 290d801 | 2016-04-06 17:06:00 +0000 | [diff] [blame] | 5726 | : SourceLocation()); | 
| Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 5727 | break; | 
|  | 5728 | } | 
| Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 5729 | } | 
|  | 5730 | } | 
| Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 5731 | } | 
|  | 5732 |  | 
| Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5733 | void ASTWriter::ReaderInitialized(ASTReader *Reader) { | 
| Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5734 | assert(Reader && "Cannot remove chain"); | 
| Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 5735 | assert((!Chain || Chain == Reader) && "Cannot replace chain"); | 
| Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5736 | assert(FirstDeclID == NextDeclID && | 
|  | 5737 | FirstTypeID == NextTypeID && | 
|  | 5738 | FirstIdentID == NextIdentID && | 
| Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5739 | FirstMacroID == NextMacroID && | 
| Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 5740 | FirstSubmoduleID == NextSubmoduleID && | 
| Sebastian Redl | d95a56e | 2010-08-04 18:21:41 +0000 | [diff] [blame] | 5741 | FirstSelectorID == NextSelectorID && | 
| Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5742 | "Setting chain after writing has started."); | 
| Douglas Gregor | 925296b | 2011-07-19 16:10:42 +0000 | [diff] [blame] | 5743 |  | 
| Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5744 | Chain = Reader; | 
| Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5745 |  | 
| Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 5746 | // Note, this will get called multiple times, once one the reader starts up | 
|  | 5747 | // and again each time it's done reading a PCH or module. | 
| Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 5748 | FirstDeclID = NUM_PREDEF_DECL_IDS + Chain->getTotalNumDecls(); | 
|  | 5749 | FirstTypeID = NUM_PREDEF_TYPE_IDS + Chain->getTotalNumTypes(); | 
|  | 5750 | FirstIdentID = NUM_PREDEF_IDENT_IDS + Chain->getTotalNumIdentifiers(); | 
| Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5751 | FirstMacroID = NUM_PREDEF_MACRO_IDS + Chain->getTotalNumMacros(); | 
| Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 5752 | FirstSubmoduleID = NUM_PREDEF_SUBMODULE_IDS + Chain->getTotalNumSubmodules(); | 
| Douglas Gregor | df0c151 | 2011-08-18 04:12:04 +0000 | [diff] [blame] | 5753 | FirstSelectorID = NUM_PREDEF_SELECTOR_IDS + Chain->getTotalNumSelectors(); | 
| Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5754 | NextDeclID = FirstDeclID; | 
|  | 5755 | NextTypeID = FirstTypeID; | 
|  | 5756 | NextIdentID = FirstIdentID; | 
| Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5757 | NextMacroID = FirstMacroID; | 
| Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 5758 | NextSelectorID = FirstSelectorID; | 
| Douglas Gregor | 253eefe | 2011-12-01 00:59:36 +0000 | [diff] [blame] | 5759 | NextSubmoduleID = FirstSubmoduleID; | 
| Sebastian Redl | 07a89a8 | 2010-07-30 00:29:29 +0000 | [diff] [blame] | 5760 | } | 
|  | 5761 |  | 
| Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5762 | void ASTWriter::IdentifierRead(IdentID ID, IdentifierInfo *II) { | 
| Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5763 | // Always keep the highest ID. See \p TypeRead() for more information. | 
|  | 5764 | IdentID &StoredID = IdentifierIDs[II]; | 
|  | 5765 | if (ID > StoredID) | 
|  | 5766 | StoredID = ID; | 
| Sebastian Redl | ff4a295 | 2010-07-23 23:49:55 +0000 | [diff] [blame] | 5767 | } | 
|  | 5768 |  | 
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5769 | void ASTWriter::MacroRead(serialization::MacroID ID, MacroInfo *MI) { | 
| Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5770 | // Always keep the highest ID. See \p TypeRead() for more information. | 
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 5771 | MacroID &StoredID = MacroIDs[MI]; | 
| Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5772 | if (ID > StoredID) | 
|  | 5773 | StoredID = ID; | 
| Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5774 | } | 
|  | 5775 |  | 
| Argyrios Kyrtzidis | bb5c7eae | 2010-08-20 16:03:59 +0000 | [diff] [blame] | 5776 | void ASTWriter::TypeRead(TypeIdx Idx, QualType T) { | 
| Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 5777 | // Always take the highest-numbered type index. This copes with an interesting | 
|  | 5778 | // case for chained AST writing where we schedule writing the type and then, | 
| Michael J. Spencer | 4c0ffa8 | 2010-10-21 03:16:25 +0000 | [diff] [blame] | 5779 | // later, deserialize the type from another AST. In this case, we want to | 
| Douglas Gregor | 9b3932c | 2010-10-05 18:37:06 +0000 | [diff] [blame] | 5780 | // keep the higher-numbered entry so that we can properly write it out to | 
|  | 5781 | // the AST file. | 
|  | 5782 | TypeIdx &StoredIdx = TypeIdxs[T]; | 
|  | 5783 | if (Idx.getIndex() >= StoredIdx.getIndex()) | 
|  | 5784 | StoredIdx = Idx; | 
| Sebastian Redl | 85b2a6a | 2010-07-14 23:45:08 +0000 | [diff] [blame] | 5785 | } | 
|  | 5786 |  | 
| Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 5787 | void ASTWriter::SelectorRead(SelectorID ID, Selector S) { | 
| Douglas Gregor | 8d7edce | 2013-02-08 21:30:59 +0000 | [diff] [blame] | 5788 | // Always keep the highest ID. See \p TypeRead() for more information. | 
|  | 5789 | SelectorID &StoredID = SelectorIDs[S]; | 
|  | 5790 | if (ID > StoredID) | 
|  | 5791 | StoredID = ID; | 
| Sebastian Redl | 834bb97 | 2010-08-04 17:20:04 +0000 | [diff] [blame] | 5792 | } | 
| Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 5793 |  | 
| Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 5794 | void ASTWriter::MacroDefinitionRead(serialization::PreprocessedEntityID ID, | 
| Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 5795 | MacroDefinitionRecord *MD) { | 
| Argyrios Kyrtzidis | 03c40c5 | 2011-09-15 18:02:56 +0000 | [diff] [blame] | 5796 | assert(MacroDefinitions.find(MD) == MacroDefinitions.end()); | 
| Douglas Gregor | 9109629 | 2010-10-02 19:29:26 +0000 | [diff] [blame] | 5797 | MacroDefinitions[MD] = ID; | 
|  | 5798 | } | 
| Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5799 |  | 
| Douglas Gregor | e37a85a | 2011-12-02 17:30:13 +0000 | [diff] [blame] | 5800 | void ASTWriter::ModuleRead(serialization::SubmoduleID ID, Module *Mod) { | 
|  | 5801 | assert(SubmoduleIDs.find(Mod) == SubmoduleIDs.end()); | 
|  | 5802 | SubmoduleIDs[Mod] = ID; | 
|  | 5803 | } | 
|  | 5804 |  | 
| Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5805 | void ASTWriter::CompletedTagDefinition(const TagDecl *D) { | 
| Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 5806 | if (Chain && Chain->isProcessingUpdateRecords()) return; | 
| John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 5807 | assert(D->isCompleteDefinition()); | 
| Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5808 | assert(!WritingAST && "Already writing the AST!"); | 
| Eugene Zelenko | ddaa4b4 | 2015-12-08 18:00:11 +0000 | [diff] [blame] | 5809 | if (auto *RD = dyn_cast<CXXRecordDecl>(D)) { | 
| Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5810 | // We are interested when a PCH decl is modified. | 
| Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 5811 | if (RD->isFromASTFile()) { | 
| Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5812 | // A forward reference was mutated into a definition. Rewrite it. | 
|  | 5813 | // FIXME: This happens during template instantiation, should we | 
|  | 5814 | // have created a new definition decl instead ? | 
| Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 5815 | assert(isTemplateInstantiation(RD->getTemplateSpecializationKind()) && | 
|  | 5816 | "completed a tag from another module but not by instantiation?"); | 
|  | 5817 | DeclUpdates[RD].push_back( | 
|  | 5818 | DeclUpdate(UPD_CXX_INSTANTIATED_CLASS_DEFINITION)); | 
| Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5819 | } | 
| Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 5820 | } | 
|  | 5821 | } | 
| Douglas Gregor | cb28f9d | 2012-10-09 23:05:51 +0000 | [diff] [blame] | 5822 |  | 
| Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 5823 | static bool isImportedDeclContext(ASTReader *Chain, const Decl *D) { | 
|  | 5824 | if (D->isFromASTFile()) | 
|  | 5825 | return true; | 
|  | 5826 |  | 
| Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 5827 | // The predefined __va_list_tag struct is imported if we imported any decls. | 
|  | 5828 | // FIXME: This is a gross hack. | 
|  | 5829 | return D == D->getASTContext().getVaListTagDecl(); | 
|  | 5830 | } | 
|  | 5831 |  | 
| Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 5832 | void ASTWriter::AddedVisibleDecl(const DeclContext *DC, const Decl *D) { | 
| Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 5833 | if (Chain && Chain->isProcessingUpdateRecords()) return; | 
|  | 5834 | assert(DC->isLookupContext() && | 
| Vassil Vassilev | 71eafde | 2016-04-06 20:56:03 +0000 | [diff] [blame] | 5835 | "Should not add lookup results to non-lookup contexts!"); | 
|  | 5836 |  | 
| Vassil Vassilev | 632eac3 | 2016-03-16 11:17:04 +0000 | [diff] [blame] | 5837 | // TU is handled elsewhere. | 
|  | 5838 | if (isa<TranslationUnitDecl>(DC)) | 
|  | 5839 | return; | 
|  | 5840 |  | 
|  | 5841 | // Namespaces are handled elsewhere, except for template instantiations of | 
|  | 5842 | // FunctionTemplateDecls in namespaces. We are interested in cases where the | 
|  | 5843 | // local instantiations are added to an imported context. Only happens when | 
|  | 5844 | // adding ADL lookup candidates, for example templated friends. | 
|  | 5845 | if (isa<NamespaceDecl>(DC) && D->getFriendObjectKind() == Decl::FOK_None && | 
|  | 5846 | !isa<FunctionTemplateDecl>(D)) | 
| Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 5847 | return; | 
|  | 5848 |  | 
| Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 5849 | // We're only interested in cases where a local declaration is added to an | 
|  | 5850 | // imported context. | 
|  | 5851 | if (D->isFromASTFile() || !isImportedDeclContext(Chain, cast<Decl>(DC))) | 
|  | 5852 | return; | 
| Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 5853 |  | 
| Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 5854 | assert(DC == DC->getPrimaryContext() && "added to non-primary context"); | 
| Douglas Gregor | 9f78289 | 2013-01-21 15:25:38 +0000 | [diff] [blame] | 5855 | assert(!getDefinitiveDeclContext(DC) && "DeclContext not definitive!"); | 
| Richard Smith | e9a8bc3 | 2014-09-30 00:45:29 +0000 | [diff] [blame] | 5856 | assert(!WritingAST && "Already writing the AST!"); | 
| Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 5857 | if (UpdatedDeclContexts.insert(DC) && !cast<Decl>(DC)->isFromASTFile()) { | 
|  | 5858 | // We're adding a visible declaration to a predefined decl context. Ensure | 
|  | 5859 | // that we write out all of its lookup results so we don't get a nasty | 
|  | 5860 | // surprise when we try to emit its lookup table. | 
|  | 5861 | for (auto *Child : DC->decls()) | 
| Richard Smith | c26d974 | 2016-10-06 20:30:51 +0000 | [diff] [blame] | 5862 | DeclsToEmitEvenIfUnreferenced.push_back(Child); | 
| Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 5863 | } | 
| Richard Smith | c26d974 | 2016-10-06 20:30:51 +0000 | [diff] [blame] | 5864 | DeclsToEmitEvenIfUnreferenced.push_back(D); | 
| Argyrios Kyrtzidis | 01c2df4 | 2010-10-28 07:38:51 +0000 | [diff] [blame] | 5865 | } | 
| Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 5866 |  | 
|  | 5867 | void ASTWriter::AddedCXXImplicitMember(const CXXRecordDecl *RD, const Decl *D) { | 
| Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 5868 | if (Chain && Chain->isProcessingUpdateRecords()) return; | 
| Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 5869 | assert(D->isImplicit()); | 
| Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 5870 |  | 
|  | 5871 | // We're only interested in cases where a local declaration is added to an | 
|  | 5872 | // imported context. | 
|  | 5873 | if (D->isFromASTFile() || !isImportedDeclContext(Chain, RD)) | 
|  | 5874 | return; | 
|  | 5875 |  | 
| Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 5876 | if (!isa<CXXMethodDecl>(D)) | 
| Richard Smith | f983f7f | 2015-10-13 00:23:25 +0000 | [diff] [blame] | 5877 | return; | 
| Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 5878 |  | 
|  | 5879 | // A decl coming from PCH was modified. | 
| John McCall | f937c02 | 2011-10-07 06:10:15 +0000 | [diff] [blame] | 5880 | assert(RD->isCompleteDefinition()); | 
| Richard Smith | e9a8bc3 | 2014-09-30 00:45:29 +0000 | [diff] [blame] | 5881 | assert(!WritingAST && "Already writing the AST!"); | 
| Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 5882 | DeclUpdates[RD].push_back(DeclUpdate(UPD_CXX_ADDED_IMPLICIT_MEMBER, D)); | 
| Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 5883 | } | 
| Argyrios Kyrtzidis | 402dbbb | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 5884 |  | 
| Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 5885 | void ASTWriter::ResolvedExceptionSpec(const FunctionDecl *FD) { | 
| Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 5886 | if (Chain && Chain->isProcessingUpdateRecords()) return; | 
| Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5887 | assert(!DoneWritingDeclsAndTypes && "Already done writing updates!"); | 
|  | 5888 | if (!Chain) return; | 
| Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 5889 | Chain->forEachImportedKeyDecl(FD, [&](const Decl *D) { | 
| Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5890 | // If we don't already know the exception specification for this redecl | 
|  | 5891 | // chain, add an update record for it. | 
|  | 5892 | if (isUnresolvedExceptionSpec(cast<FunctionDecl>(D) | 
|  | 5893 | ->getType() | 
|  | 5894 | ->castAs<FunctionProtoType>() | 
|  | 5895 | ->getExceptionSpecType())) | 
|  | 5896 | DeclUpdates[D].push_back(UPD_CXX_RESOLVED_EXCEPTION_SPEC); | 
|  | 5897 | }); | 
| Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 5898 | } | 
|  | 5899 |  | 
| Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 5900 | void ASTWriter::DeducedReturnType(const FunctionDecl *FD, QualType ReturnType) { | 
| Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 5901 | if (Chain && Chain->isProcessingUpdateRecords()) return; | 
| Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 5902 | assert(!WritingAST && "Already writing the AST!"); | 
| Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5903 | if (!Chain) return; | 
| Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 5904 | Chain->forEachImportedKeyDecl(FD, [&](const Decl *D) { | 
| Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5905 | DeclUpdates[D].push_back( | 
|  | 5906 | DeclUpdate(UPD_CXX_DEDUCED_RETURN_TYPE, ReturnType)); | 
|  | 5907 | }); | 
| Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 5908 | } | 
|  | 5909 |  | 
| Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 5910 | void ASTWriter::ResolvedOperatorDelete(const CXXDestructorDecl *DD, | 
| Richard Smith | 5b34958 | 2017-10-13 01:55:36 +0000 | [diff] [blame] | 5911 | const FunctionDecl *Delete, | 
|  | 5912 | Expr *ThisArg) { | 
| Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 5913 | if (Chain && Chain->isProcessingUpdateRecords()) return; | 
| Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 5914 | assert(!WritingAST && "Already writing the AST!"); | 
|  | 5915 | assert(Delete && "Not given an operator delete"); | 
| Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5916 | if (!Chain) return; | 
| Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 5917 | Chain->forEachImportedKeyDecl(DD, [&](const Decl *D) { | 
| Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5918 | DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_RESOLVED_DTOR_DELETE, Delete)); | 
|  | 5919 | }); | 
| Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 5920 | } | 
|  | 5921 |  | 
| Sebastian Redl | ab238a7 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 5922 | void ASTWriter::CompletedImplicitDefinition(const FunctionDecl *D) { | 
| Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 5923 | if (Chain && Chain->isProcessingUpdateRecords()) return; | 
| Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5924 | assert(!WritingAST && "Already writing the AST!"); | 
| Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 5925 | if (!D->isFromASTFile()) | 
| Sebastian Redl | ab238a7 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 5926 | return; // Declaration not imported from PCH. | 
|  | 5927 |  | 
| Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 5928 | // Implicit function decl from a PCH was defined. | 
|  | 5929 | DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_ADDED_FUNCTION_DEFINITION)); | 
| Sebastian Redl | ab238a7 | 2011-04-24 16:28:06 +0000 | [diff] [blame] | 5930 | } | 
|  | 5931 |  | 
| Richard Smith | 891fc7f | 2017-12-05 01:31:47 +0000 | [diff] [blame] | 5932 | void ASTWriter::VariableDefinitionInstantiated(const VarDecl *D) { | 
|  | 5933 | if (Chain && Chain->isProcessingUpdateRecords()) return; | 
|  | 5934 | assert(!WritingAST && "Already writing the AST!"); | 
|  | 5935 | if (!D->isFromASTFile()) | 
|  | 5936 | return; | 
|  | 5937 |  | 
|  | 5938 | DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_ADDED_VAR_DEFINITION)); | 
|  | 5939 | } | 
|  | 5940 |  | 
| Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 5941 | void ASTWriter::FunctionDefinitionInstantiated(const FunctionDecl *D) { | 
| Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 5942 | if (Chain && Chain->isProcessingUpdateRecords()) return; | 
| Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 5943 | assert(!WritingAST && "Already writing the AST!"); | 
|  | 5944 | if (!D->isFromASTFile()) | 
|  | 5945 | return; | 
|  | 5946 |  | 
| Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 5947 | DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_ADDED_FUNCTION_DEFINITION)); | 
| Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 5948 | } | 
|  | 5949 |  | 
| Richard Smith | 891fc7f | 2017-12-05 01:31:47 +0000 | [diff] [blame] | 5950 | void ASTWriter::InstantiationRequested(const ValueDecl *D) { | 
| Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 5951 | if (Chain && Chain->isProcessingUpdateRecords()) return; | 
| Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5952 | assert(!WritingAST && "Already writing the AST!"); | 
| Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 5953 | if (!D->isFromASTFile()) | 
| Sebastian Redl | 2ac2c72 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 5954 | return; | 
|  | 5955 |  | 
|  | 5956 | // Since the actual instantiation is delayed, this really means that we need | 
|  | 5957 | // to update the instantiation location. | 
| Richard Smith | 891fc7f | 2017-12-05 01:31:47 +0000 | [diff] [blame] | 5958 | SourceLocation POI; | 
|  | 5959 | if (auto *VD = dyn_cast<VarDecl>(D)) | 
|  | 5960 | POI = VD->getPointOfInstantiation(); | 
|  | 5961 | else | 
|  | 5962 | POI = cast<FunctionDecl>(D)->getPointOfInstantiation(); | 
|  | 5963 | DeclUpdates[D].push_back(DeclUpdate(UPD_CXX_POINT_OF_INSTANTIATION, POI)); | 
| Sebastian Redl | 2ac2c72 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 5964 | } | 
|  | 5965 |  | 
| John McCall | 32791cc | 2016-01-06 22:34:54 +0000 | [diff] [blame] | 5966 | void ASTWriter::DefaultArgumentInstantiated(const ParmVarDecl *D) { | 
| Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 5967 | if (Chain && Chain->isProcessingUpdateRecords()) return; | 
| John McCall | 32791cc | 2016-01-06 22:34:54 +0000 | [diff] [blame] | 5968 | assert(!WritingAST && "Already writing the AST!"); | 
|  | 5969 | if (!D->isFromASTFile()) | 
|  | 5970 | return; | 
|  | 5971 |  | 
|  | 5972 | DeclUpdates[D].push_back( | 
|  | 5973 | DeclUpdate(UPD_CXX_INSTANTIATED_DEFAULT_ARGUMENT, D)); | 
|  | 5974 | } | 
|  | 5975 |  | 
| Richard Smith | 4b054b2 | 2016-08-24 21:25:37 +0000 | [diff] [blame] | 5976 | void ASTWriter::DefaultMemberInitializerInstantiated(const FieldDecl *D) { | 
|  | 5977 | assert(!WritingAST && "Already writing the AST!"); | 
|  | 5978 | if (!D->isFromASTFile()) | 
|  | 5979 | return; | 
|  | 5980 |  | 
|  | 5981 | DeclUpdates[D].push_back( | 
|  | 5982 | DeclUpdate(UPD_CXX_INSTANTIATED_DEFAULT_MEMBER_INITIALIZER, D)); | 
|  | 5983 | } | 
|  | 5984 |  | 
| Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 5985 | void ASTWriter::AddedObjCCategoryToInterface(const ObjCCategoryDecl *CatD, | 
|  | 5986 | const ObjCInterfaceDecl *IFD) { | 
| Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 5987 | if (Chain && Chain->isProcessingUpdateRecords()) return; | 
| Douglas Gregor | 2fd3d40 | 2011-09-17 00:05:03 +0000 | [diff] [blame] | 5988 | assert(!WritingAST && "Already writing the AST!"); | 
| Douglas Gregor | b3722e2 | 2011-09-09 23:01:35 +0000 | [diff] [blame] | 5989 | if (!IFD->isFromASTFile()) | 
| Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 5990 | return; // Declaration not imported from PCH. | 
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 5991 |  | 
| Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 5992 | assert(IFD->getDefinition() && "Category on a class without a definition?"); | 
|  | 5993 | ObjCClassesWithCategories.insert( | 
|  | 5994 | const_cast<ObjCInterfaceDecl *>(IFD->getDefinition())); | 
| Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 5995 | } | 
| Argyrios Kyrtzidis | b97a402 | 2011-11-12 21:07:46 +0000 | [diff] [blame] | 5996 |  | 
| Eli Friedman | 276dd18 | 2013-09-05 00:02:25 +0000 | [diff] [blame] | 5997 | void ASTWriter::DeclarationMarkedUsed(const Decl *D) { | 
| Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 5998 | if (Chain && Chain->isProcessingUpdateRecords()) return; | 
| Eli Friedman | 276dd18 | 2013-09-05 00:02:25 +0000 | [diff] [blame] | 5999 | assert(!WritingAST && "Already writing the AST!"); | 
| Vassil Vassilev | 928c825 | 2016-04-28 14:13:28 +0000 | [diff] [blame] | 6000 |  | 
|  | 6001 | // If there is *any* declaration of the entity that's not from an AST file, | 
|  | 6002 | // we can skip writing the update record. We make sure that isUsed() triggers | 
|  | 6003 | // completion of the redeclaration chain of the entity. | 
|  | 6004 | for (auto Prev = D->getMostRecentDecl(); Prev; Prev = Prev->getPreviousDecl()) | 
|  | 6005 | if (IsLocalDecl(Prev)) | 
|  | 6006 | return; | 
| Eli Friedman | 276dd18 | 2013-09-05 00:02:25 +0000 | [diff] [blame] | 6007 |  | 
| Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 6008 | DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_MARKED_USED)); | 
| Eli Friedman | 276dd18 | 2013-09-05 00:02:25 +0000 | [diff] [blame] | 6009 | } | 
| Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 6010 |  | 
|  | 6011 | void ASTWriter::DeclarationMarkedOpenMPThreadPrivate(const Decl *D) { | 
| Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6012 | if (Chain && Chain->isProcessingUpdateRecords()) return; | 
| Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 6013 | assert(!WritingAST && "Already writing the AST!"); | 
|  | 6014 | if (!D->isFromASTFile()) | 
|  | 6015 | return; | 
|  | 6016 |  | 
|  | 6017 | DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_MARKED_OPENMP_THREADPRIVATE)); | 
|  | 6018 | } | 
| Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 6019 |  | 
| Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 6020 | void ASTWriter::DeclarationMarkedOpenMPAllocate(const Decl *D, const Attr *A) { | 
|  | 6021 | if (Chain && Chain->isProcessingUpdateRecords()) return; | 
|  | 6022 | assert(!WritingAST && "Already writing the AST!"); | 
|  | 6023 | if (!D->isFromASTFile()) | 
|  | 6024 | return; | 
|  | 6025 |  | 
|  | 6026 | DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_MARKED_OPENMP_ALLOCATE, A)); | 
|  | 6027 | } | 
|  | 6028 |  | 
| Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 6029 | void ASTWriter::DeclarationMarkedOpenMPDeclareTarget(const Decl *D, | 
|  | 6030 | const Attr *Attr) { | 
| Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6031 | if (Chain && Chain->isProcessingUpdateRecords()) return; | 
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 6032 | assert(!WritingAST && "Already writing the AST!"); | 
|  | 6033 | if (!D->isFromASTFile()) | 
|  | 6034 | return; | 
|  | 6035 |  | 
| Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 6036 | DeclUpdates[D].push_back( | 
|  | 6037 | DeclUpdate(UPD_DECL_MARKED_OPENMP_DECLARETARGET, Attr)); | 
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 6038 | } | 
|  | 6039 |  | 
| Richard Smith | 4caa449 | 2015-05-15 02:34:32 +0000 | [diff] [blame] | 6040 | void ASTWriter::RedefinedHiddenDefinition(const NamedDecl *D, Module *M) { | 
| Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6041 | if (Chain && Chain->isProcessingUpdateRecords()) return; | 
| Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 6042 | assert(!WritingAST && "Already writing the AST!"); | 
|  | 6043 | assert(D->isHidden() && "expected a hidden declaration"); | 
| Richard Smith | 4caa449 | 2015-05-15 02:34:32 +0000 | [diff] [blame] | 6044 | DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_EXPORTED, M)); | 
| Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 6045 | } | 
| Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 6046 |  | 
|  | 6047 | void ASTWriter::AddedAttributeToRecord(const Attr *Attr, | 
|  | 6048 | const RecordDecl *Record) { | 
| Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 6049 | if (Chain && Chain->isProcessingUpdateRecords()) return; | 
| Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 6050 | assert(!WritingAST && "Already writing the AST!"); | 
|  | 6051 | if (!Record->isFromASTFile()) | 
|  | 6052 | return; | 
|  | 6053 | DeclUpdates[Record].push_back(DeclUpdate(UPD_ADDED_ATTR_TO_RECORD, Attr)); | 
|  | 6054 | } | 
| Richard Smith | c26d974 | 2016-10-06 20:30:51 +0000 | [diff] [blame] | 6055 |  | 
|  | 6056 | void ASTWriter::AddedCXXTemplateSpecialization( | 
|  | 6057 | const ClassTemplateDecl *TD, const ClassTemplateSpecializationDecl *D) { | 
|  | 6058 | assert(!WritingAST && "Already writing the AST!"); | 
|  | 6059 |  | 
|  | 6060 | if (!TD->getFirstDecl()->isFromASTFile()) | 
|  | 6061 | return; | 
|  | 6062 | if (Chain && Chain->isProcessingUpdateRecords()) | 
|  | 6063 | return; | 
|  | 6064 |  | 
|  | 6065 | DeclsToEmitEvenIfUnreferenced.push_back(D); | 
|  | 6066 | } | 
|  | 6067 |  | 
|  | 6068 | void ASTWriter::AddedCXXTemplateSpecialization( | 
|  | 6069 | const VarTemplateDecl *TD, const VarTemplateSpecializationDecl *D) { | 
|  | 6070 | assert(!WritingAST && "Already writing the AST!"); | 
|  | 6071 |  | 
|  | 6072 | if (!TD->getFirstDecl()->isFromASTFile()) | 
|  | 6073 | return; | 
|  | 6074 | if (Chain && Chain->isProcessingUpdateRecords()) | 
|  | 6075 | return; | 
|  | 6076 |  | 
|  | 6077 | DeclsToEmitEvenIfUnreferenced.push_back(D); | 
|  | 6078 | } | 
|  | 6079 |  | 
|  | 6080 | void ASTWriter::AddedCXXTemplateSpecialization(const FunctionTemplateDecl *TD, | 
|  | 6081 | const FunctionDecl *D) { | 
|  | 6082 | assert(!WritingAST && "Already writing the AST!"); | 
|  | 6083 |  | 
|  | 6084 | if (!TD->getFirstDecl()->isFromASTFile()) | 
|  | 6085 | return; | 
|  | 6086 | if (Chain && Chain->isProcessingUpdateRecords()) | 
|  | 6087 | return; | 
|  | 6088 |  | 
|  | 6089 | DeclsToEmitEvenIfUnreferenced.push_back(D); | 
|  | 6090 | } | 
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 6091 |  | 
|  | 6092 | //===----------------------------------------------------------------------===// | 
|  | 6093 | //// OMPClause Serialization | 
|  | 6094 | ////===----------------------------------------------------------------------===// | 
|  | 6095 |  | 
| John McCall | 2ac702a | 2019-12-14 03:17:03 -0500 | [diff] [blame] | 6096 | namespace { | 
|  | 6097 |  | 
|  | 6098 | class OMPClauseWriter : public OMPClauseVisitor<OMPClauseWriter> { | 
|  | 6099 | ASTRecordWriter &Record; | 
|  | 6100 |  | 
|  | 6101 | public: | 
|  | 6102 | OMPClauseWriter(ASTRecordWriter &Record) : Record(Record) {} | 
| Johannes Doerfert | 419a559 | 2020-03-30 19:58:40 -0500 | [diff] [blame] | 6103 | #define OMP_CLAUSE_CLASS(Enum, Str, Class) void Visit##Class(Class *S); | 
|  | 6104 | #include "llvm/Frontend/OpenMP/OMPKinds.def" | 
| John McCall | 2ac702a | 2019-12-14 03:17:03 -0500 | [diff] [blame] | 6105 | void writeClause(OMPClause *C); | 
|  | 6106 | void VisitOMPClauseWithPreInit(OMPClauseWithPreInit *C); | 
|  | 6107 | void VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *C); | 
|  | 6108 | }; | 
|  | 6109 |  | 
|  | 6110 | } | 
|  | 6111 |  | 
|  | 6112 | void ASTRecordWriter::writeOMPClause(OMPClause *C) { | 
|  | 6113 | OMPClauseWriter(*this).writeClause(C); | 
|  | 6114 | } | 
|  | 6115 |  | 
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 6116 | void OMPClauseWriter::writeClause(OMPClause *C) { | 
| Johannes Doerfert | 419a559 | 2020-03-30 19:58:40 -0500 | [diff] [blame] | 6117 | Record.push_back(unsigned(C->getClauseKind())); | 
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 6118 | Visit(C); | 
|  | 6119 | Record.AddSourceLocation(C->getBeginLoc()); | 
|  | 6120 | Record.AddSourceLocation(C->getEndLoc()); | 
|  | 6121 | } | 
|  | 6122 |  | 
|  | 6123 | void OMPClauseWriter::VisitOMPClauseWithPreInit(OMPClauseWithPreInit *C) { | 
| Johannes Doerfert | eb3e81f | 2019-11-04 22:00:49 -0600 | [diff] [blame] | 6124 | Record.push_back(uint64_t(C->getCaptureRegion())); | 
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 6125 | Record.AddStmt(C->getPreInitStmt()); | 
|  | 6126 | } | 
|  | 6127 |  | 
|  | 6128 | void OMPClauseWriter::VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *C) { | 
|  | 6129 | VisitOMPClauseWithPreInit(C); | 
|  | 6130 | Record.AddStmt(C->getPostUpdateExpr()); | 
|  | 6131 | } | 
|  | 6132 |  | 
|  | 6133 | void OMPClauseWriter::VisitOMPIfClause(OMPIfClause *C) { | 
|  | 6134 | VisitOMPClauseWithPreInit(C); | 
| Johannes Doerfert | eb3e81f | 2019-11-04 22:00:49 -0600 | [diff] [blame] | 6135 | Record.push_back(uint64_t(C->getNameModifier())); | 
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 6136 | Record.AddSourceLocation(C->getNameModifierLoc()); | 
|  | 6137 | Record.AddSourceLocation(C->getColonLoc()); | 
|  | 6138 | Record.AddStmt(C->getCondition()); | 
|  | 6139 | Record.AddSourceLocation(C->getLParenLoc()); | 
|  | 6140 | } | 
|  | 6141 |  | 
|  | 6142 | void OMPClauseWriter::VisitOMPFinalClause(OMPFinalClause *C) { | 
| Alexey Bataev | 3a842ec | 2019-10-15 19:37:05 +0000 | [diff] [blame] | 6143 | VisitOMPClauseWithPreInit(C); | 
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 6144 | Record.AddStmt(C->getCondition()); | 
|  | 6145 | Record.AddSourceLocation(C->getLParenLoc()); | 
|  | 6146 | } | 
|  | 6147 |  | 
|  | 6148 | void OMPClauseWriter::VisitOMPNumThreadsClause(OMPNumThreadsClause *C) { | 
|  | 6149 | VisitOMPClauseWithPreInit(C); | 
|  | 6150 | Record.AddStmt(C->getNumThreads()); | 
|  | 6151 | Record.AddSourceLocation(C->getLParenLoc()); | 
|  | 6152 | } | 
|  | 6153 |  | 
|  | 6154 | void OMPClauseWriter::VisitOMPSafelenClause(OMPSafelenClause *C) { | 
|  | 6155 | Record.AddStmt(C->getSafelen()); | 
|  | 6156 | Record.AddSourceLocation(C->getLParenLoc()); | 
|  | 6157 | } | 
|  | 6158 |  | 
|  | 6159 | void OMPClauseWriter::VisitOMPSimdlenClause(OMPSimdlenClause *C) { | 
|  | 6160 | Record.AddStmt(C->getSimdlen()); | 
|  | 6161 | Record.AddSourceLocation(C->getLParenLoc()); | 
|  | 6162 | } | 
|  | 6163 |  | 
| Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 6164 | void OMPClauseWriter::VisitOMPAllocatorClause(OMPAllocatorClause *C) { | 
|  | 6165 | Record.AddStmt(C->getAllocator()); | 
|  | 6166 | Record.AddSourceLocation(C->getLParenLoc()); | 
|  | 6167 | } | 
|  | 6168 |  | 
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 6169 | void OMPClauseWriter::VisitOMPCollapseClause(OMPCollapseClause *C) { | 
|  | 6170 | Record.AddStmt(C->getNumForLoops()); | 
|  | 6171 | Record.AddSourceLocation(C->getLParenLoc()); | 
|  | 6172 | } | 
|  | 6173 |  | 
| Alexey Bataev | 0f0564b | 2020-03-17 09:17:42 -0400 | [diff] [blame] | 6174 | void OMPClauseWriter::VisitOMPDetachClause(OMPDetachClause *C) { | 
|  | 6175 | Record.AddStmt(C->getEventHandler()); | 
|  | 6176 | Record.AddSourceLocation(C->getLParenLoc()); | 
|  | 6177 | } | 
|  | 6178 |  | 
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 6179 | void OMPClauseWriter::VisitOMPDefaultClause(OMPDefaultClause *C) { | 
| Atmn Patel | 577c9b0 | 2020-02-14 21:45:49 -0600 | [diff] [blame] | 6180 | Record.push_back(unsigned(C->getDefaultKind())); | 
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 6181 | Record.AddSourceLocation(C->getLParenLoc()); | 
|  | 6182 | Record.AddSourceLocation(C->getDefaultKindKwLoc()); | 
|  | 6183 | } | 
|  | 6184 |  | 
|  | 6185 | void OMPClauseWriter::VisitOMPProcBindClause(OMPProcBindClause *C) { | 
| Johannes Doerfert | 6c5d1f40 | 2019-12-25 18:15:36 -0600 | [diff] [blame] | 6186 | Record.push_back(unsigned(C->getProcBindKind())); | 
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 6187 | Record.AddSourceLocation(C->getLParenLoc()); | 
|  | 6188 | Record.AddSourceLocation(C->getProcBindKindKwLoc()); | 
|  | 6189 | } | 
|  | 6190 |  | 
|  | 6191 | void OMPClauseWriter::VisitOMPScheduleClause(OMPScheduleClause *C) { | 
|  | 6192 | VisitOMPClauseWithPreInit(C); | 
|  | 6193 | Record.push_back(C->getScheduleKind()); | 
|  | 6194 | Record.push_back(C->getFirstScheduleModifier()); | 
|  | 6195 | Record.push_back(C->getSecondScheduleModifier()); | 
|  | 6196 | Record.AddStmt(C->getChunkSize()); | 
|  | 6197 | Record.AddSourceLocation(C->getLParenLoc()); | 
|  | 6198 | Record.AddSourceLocation(C->getFirstScheduleModifierLoc()); | 
|  | 6199 | Record.AddSourceLocation(C->getSecondScheduleModifierLoc()); | 
|  | 6200 | Record.AddSourceLocation(C->getScheduleKindLoc()); | 
|  | 6201 | Record.AddSourceLocation(C->getCommaLoc()); | 
|  | 6202 | } | 
|  | 6203 |  | 
|  | 6204 | void OMPClauseWriter::VisitOMPOrderedClause(OMPOrderedClause *C) { | 
|  | 6205 | Record.push_back(C->getLoopNumIterations().size()); | 
|  | 6206 | Record.AddStmt(C->getNumForLoops()); | 
|  | 6207 | for (Expr *NumIter : C->getLoopNumIterations()) | 
|  | 6208 | Record.AddStmt(NumIter); | 
|  | 6209 | for (unsigned I = 0, E = C->getLoopNumIterations().size(); I <E; ++I) | 
| Mike Rice | 0ed4666 | 2018-09-20 17:19:41 +0000 | [diff] [blame] | 6210 | Record.AddStmt(C->getLoopCounter(I)); | 
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 6211 | Record.AddSourceLocation(C->getLParenLoc()); | 
|  | 6212 | } | 
|  | 6213 |  | 
|  | 6214 | void OMPClauseWriter::VisitOMPNowaitClause(OMPNowaitClause *) {} | 
|  | 6215 |  | 
|  | 6216 | void OMPClauseWriter::VisitOMPUntiedClause(OMPUntiedClause *) {} | 
|  | 6217 |  | 
|  | 6218 | void OMPClauseWriter::VisitOMPMergeableClause(OMPMergeableClause *) {} | 
|  | 6219 |  | 
|  | 6220 | void OMPClauseWriter::VisitOMPReadClause(OMPReadClause *) {} | 
|  | 6221 |  | 
|  | 6222 | void OMPClauseWriter::VisitOMPWriteClause(OMPWriteClause *) {} | 
|  | 6223 |  | 
| Alexey Bataev | 82f7c20 | 2020-03-03 13:22:35 -0500 | [diff] [blame] | 6224 | void OMPClauseWriter::VisitOMPUpdateClause(OMPUpdateClause *C) { | 
|  | 6225 | Record.push_back(C->isExtended() ? 1 : 0); | 
|  | 6226 | if (C->isExtended()) { | 
|  | 6227 | Record.AddSourceLocation(C->getLParenLoc()); | 
|  | 6228 | Record.AddSourceLocation(C->getArgumentLoc()); | 
|  | 6229 | Record.writeEnum(C->getDependencyKind()); | 
|  | 6230 | } | 
|  | 6231 | } | 
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 6232 |  | 
|  | 6233 | void OMPClauseWriter::VisitOMPCaptureClause(OMPCaptureClause *) {} | 
|  | 6234 |  | 
|  | 6235 | void OMPClauseWriter::VisitOMPSeqCstClause(OMPSeqCstClause *) {} | 
|  | 6236 |  | 
| Alexey Bataev | ea9166b | 2020-02-06 16:30:23 -0500 | [diff] [blame] | 6237 | void OMPClauseWriter::VisitOMPAcqRelClause(OMPAcqRelClause *) {} | 
|  | 6238 |  | 
| Alexey Bataev | 04a830f | 2020-02-10 14:30:39 -0500 | [diff] [blame] | 6239 | void OMPClauseWriter::VisitOMPAcquireClause(OMPAcquireClause *) {} | 
|  | 6240 |  | 
| Alexey Bataev | 9559834 | 2020-02-10 15:49:05 -0500 | [diff] [blame] | 6241 | void OMPClauseWriter::VisitOMPReleaseClause(OMPReleaseClause *) {} | 
|  | 6242 |  | 
| Alexey Bataev | 9a8defc | 2020-02-11 11:10:43 -0500 | [diff] [blame] | 6243 | void OMPClauseWriter::VisitOMPRelaxedClause(OMPRelaxedClause *) {} | 
|  | 6244 |  | 
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 6245 | void OMPClauseWriter::VisitOMPThreadsClause(OMPThreadsClause *) {} | 
|  | 6246 |  | 
|  | 6247 | void OMPClauseWriter::VisitOMPSIMDClause(OMPSIMDClause *) {} | 
|  | 6248 |  | 
|  | 6249 | void OMPClauseWriter::VisitOMPNogroupClause(OMPNogroupClause *) {} | 
|  | 6250 |  | 
| Alexey Bataev | 375437a | 2020-03-02 14:21:20 -0500 | [diff] [blame] | 6251 | void OMPClauseWriter::VisitOMPDestroyClause(OMPDestroyClause *) {} | 
|  | 6252 |  | 
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 6253 | void OMPClauseWriter::VisitOMPPrivateClause(OMPPrivateClause *C) { | 
|  | 6254 | Record.push_back(C->varlist_size()); | 
|  | 6255 | Record.AddSourceLocation(C->getLParenLoc()); | 
|  | 6256 | for (auto *VE : C->varlists()) { | 
|  | 6257 | Record.AddStmt(VE); | 
|  | 6258 | } | 
|  | 6259 | for (auto *VE : C->private_copies()) { | 
|  | 6260 | Record.AddStmt(VE); | 
|  | 6261 | } | 
|  | 6262 | } | 
|  | 6263 |  | 
|  | 6264 | void OMPClauseWriter::VisitOMPFirstprivateClause(OMPFirstprivateClause *C) { | 
|  | 6265 | Record.push_back(C->varlist_size()); | 
|  | 6266 | VisitOMPClauseWithPreInit(C); | 
|  | 6267 | Record.AddSourceLocation(C->getLParenLoc()); | 
|  | 6268 | for (auto *VE : C->varlists()) { | 
|  | 6269 | Record.AddStmt(VE); | 
|  | 6270 | } | 
|  | 6271 | for (auto *VE : C->private_copies()) { | 
|  | 6272 | Record.AddStmt(VE); | 
|  | 6273 | } | 
|  | 6274 | for (auto *VE : C->inits()) { | 
|  | 6275 | Record.AddStmt(VE); | 
|  | 6276 | } | 
|  | 6277 | } | 
|  | 6278 |  | 
|  | 6279 | void OMPClauseWriter::VisitOMPLastprivateClause(OMPLastprivateClause *C) { | 
|  | 6280 | Record.push_back(C->varlist_size()); | 
|  | 6281 | VisitOMPClauseWithPostUpdate(C); | 
|  | 6282 | Record.AddSourceLocation(C->getLParenLoc()); | 
| Alexey Bataev | 93dc40d | 2019-12-20 11:04:57 -0500 | [diff] [blame] | 6283 | Record.writeEnum(C->getKind()); | 
|  | 6284 | Record.AddSourceLocation(C->getKindLoc()); | 
|  | 6285 | Record.AddSourceLocation(C->getColonLoc()); | 
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 6286 | for (auto *VE : C->varlists()) | 
|  | 6287 | Record.AddStmt(VE); | 
|  | 6288 | for (auto *E : C->private_copies()) | 
|  | 6289 | Record.AddStmt(E); | 
|  | 6290 | for (auto *E : C->source_exprs()) | 
|  | 6291 | Record.AddStmt(E); | 
|  | 6292 | for (auto *E : C->destination_exprs()) | 
|  | 6293 | Record.AddStmt(E); | 
|  | 6294 | for (auto *E : C->assignment_ops()) | 
|  | 6295 | Record.AddStmt(E); | 
|  | 6296 | } | 
|  | 6297 |  | 
|  | 6298 | void OMPClauseWriter::VisitOMPSharedClause(OMPSharedClause *C) { | 
|  | 6299 | Record.push_back(C->varlist_size()); | 
|  | 6300 | Record.AddSourceLocation(C->getLParenLoc()); | 
|  | 6301 | for (auto *VE : C->varlists()) | 
|  | 6302 | Record.AddStmt(VE); | 
|  | 6303 | } | 
|  | 6304 |  | 
|  | 6305 | void OMPClauseWriter::VisitOMPReductionClause(OMPReductionClause *C) { | 
|  | 6306 | Record.push_back(C->varlist_size()); | 
|  | 6307 | VisitOMPClauseWithPostUpdate(C); | 
|  | 6308 | Record.AddSourceLocation(C->getLParenLoc()); | 
| Alexey Bataev | 1236eb6 | 2020-03-23 17:30:38 -0400 | [diff] [blame] | 6309 | Record.AddSourceLocation(C->getModifierLoc()); | 
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 6310 | Record.AddSourceLocation(C->getColonLoc()); | 
| Alexey Bataev | 1236eb6 | 2020-03-23 17:30:38 -0400 | [diff] [blame] | 6311 | Record.writeEnum(C->getModifier()); | 
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 6312 | Record.AddNestedNameSpecifierLoc(C->getQualifierLoc()); | 
|  | 6313 | Record.AddDeclarationNameInfo(C->getNameInfo()); | 
|  | 6314 | for (auto *VE : C->varlists()) | 
|  | 6315 | Record.AddStmt(VE); | 
|  | 6316 | for (auto *VE : C->privates()) | 
|  | 6317 | Record.AddStmt(VE); | 
|  | 6318 | for (auto *E : C->lhs_exprs()) | 
|  | 6319 | Record.AddStmt(E); | 
|  | 6320 | for (auto *E : C->rhs_exprs()) | 
|  | 6321 | Record.AddStmt(E); | 
|  | 6322 | for (auto *E : C->reduction_ops()) | 
|  | 6323 | Record.AddStmt(E); | 
|  | 6324 | } | 
|  | 6325 |  | 
|  | 6326 | void OMPClauseWriter::VisitOMPTaskReductionClause(OMPTaskReductionClause *C) { | 
|  | 6327 | Record.push_back(C->varlist_size()); | 
|  | 6328 | VisitOMPClauseWithPostUpdate(C); | 
|  | 6329 | Record.AddSourceLocation(C->getLParenLoc()); | 
|  | 6330 | Record.AddSourceLocation(C->getColonLoc()); | 
|  | 6331 | Record.AddNestedNameSpecifierLoc(C->getQualifierLoc()); | 
|  | 6332 | Record.AddDeclarationNameInfo(C->getNameInfo()); | 
|  | 6333 | for (auto *VE : C->varlists()) | 
|  | 6334 | Record.AddStmt(VE); | 
|  | 6335 | for (auto *VE : C->privates()) | 
|  | 6336 | Record.AddStmt(VE); | 
|  | 6337 | for (auto *E : C->lhs_exprs()) | 
|  | 6338 | Record.AddStmt(E); | 
|  | 6339 | for (auto *E : C->rhs_exprs()) | 
|  | 6340 | Record.AddStmt(E); | 
|  | 6341 | for (auto *E : C->reduction_ops()) | 
|  | 6342 | Record.AddStmt(E); | 
|  | 6343 | } | 
|  | 6344 |  | 
|  | 6345 | void OMPClauseWriter::VisitOMPInReductionClause(OMPInReductionClause *C) { | 
|  | 6346 | Record.push_back(C->varlist_size()); | 
|  | 6347 | VisitOMPClauseWithPostUpdate(C); | 
|  | 6348 | Record.AddSourceLocation(C->getLParenLoc()); | 
|  | 6349 | Record.AddSourceLocation(C->getColonLoc()); | 
|  | 6350 | Record.AddNestedNameSpecifierLoc(C->getQualifierLoc()); | 
|  | 6351 | Record.AddDeclarationNameInfo(C->getNameInfo()); | 
|  | 6352 | for (auto *VE : C->varlists()) | 
|  | 6353 | Record.AddStmt(VE); | 
|  | 6354 | for (auto *VE : C->privates()) | 
|  | 6355 | Record.AddStmt(VE); | 
|  | 6356 | for (auto *E : C->lhs_exprs()) | 
|  | 6357 | Record.AddStmt(E); | 
|  | 6358 | for (auto *E : C->rhs_exprs()) | 
|  | 6359 | Record.AddStmt(E); | 
|  | 6360 | for (auto *E : C->reduction_ops()) | 
|  | 6361 | Record.AddStmt(E); | 
|  | 6362 | for (auto *E : C->taskgroup_descriptors()) | 
|  | 6363 | Record.AddStmt(E); | 
|  | 6364 | } | 
|  | 6365 |  | 
|  | 6366 | void OMPClauseWriter::VisitOMPLinearClause(OMPLinearClause *C) { | 
|  | 6367 | Record.push_back(C->varlist_size()); | 
|  | 6368 | VisitOMPClauseWithPostUpdate(C); | 
|  | 6369 | Record.AddSourceLocation(C->getLParenLoc()); | 
|  | 6370 | Record.AddSourceLocation(C->getColonLoc()); | 
|  | 6371 | Record.push_back(C->getModifier()); | 
|  | 6372 | Record.AddSourceLocation(C->getModifierLoc()); | 
|  | 6373 | for (auto *VE : C->varlists()) { | 
|  | 6374 | Record.AddStmt(VE); | 
|  | 6375 | } | 
|  | 6376 | for (auto *VE : C->privates()) { | 
|  | 6377 | Record.AddStmt(VE); | 
|  | 6378 | } | 
|  | 6379 | for (auto *VE : C->inits()) { | 
|  | 6380 | Record.AddStmt(VE); | 
|  | 6381 | } | 
|  | 6382 | for (auto *VE : C->updates()) { | 
|  | 6383 | Record.AddStmt(VE); | 
|  | 6384 | } | 
|  | 6385 | for (auto *VE : C->finals()) { | 
|  | 6386 | Record.AddStmt(VE); | 
|  | 6387 | } | 
|  | 6388 | Record.AddStmt(C->getStep()); | 
|  | 6389 | Record.AddStmt(C->getCalcStep()); | 
| Alexey Bataev | 195ae90 | 2019-08-08 13:42:45 +0000 | [diff] [blame] | 6390 | for (auto *VE : C->used_expressions()) | 
|  | 6391 | Record.AddStmt(VE); | 
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 6392 | } | 
|  | 6393 |  | 
|  | 6394 | void OMPClauseWriter::VisitOMPAlignedClause(OMPAlignedClause *C) { | 
|  | 6395 | Record.push_back(C->varlist_size()); | 
|  | 6396 | Record.AddSourceLocation(C->getLParenLoc()); | 
|  | 6397 | Record.AddSourceLocation(C->getColonLoc()); | 
|  | 6398 | for (auto *VE : C->varlists()) | 
|  | 6399 | Record.AddStmt(VE); | 
|  | 6400 | Record.AddStmt(C->getAlignment()); | 
|  | 6401 | } | 
|  | 6402 |  | 
|  | 6403 | void OMPClauseWriter::VisitOMPCopyinClause(OMPCopyinClause *C) { | 
|  | 6404 | Record.push_back(C->varlist_size()); | 
|  | 6405 | Record.AddSourceLocation(C->getLParenLoc()); | 
|  | 6406 | for (auto *VE : C->varlists()) | 
|  | 6407 | Record.AddStmt(VE); | 
|  | 6408 | for (auto *E : C->source_exprs()) | 
|  | 6409 | Record.AddStmt(E); | 
|  | 6410 | for (auto *E : C->destination_exprs()) | 
|  | 6411 | Record.AddStmt(E); | 
|  | 6412 | for (auto *E : C->assignment_ops()) | 
|  | 6413 | Record.AddStmt(E); | 
|  | 6414 | } | 
|  | 6415 |  | 
|  | 6416 | void OMPClauseWriter::VisitOMPCopyprivateClause(OMPCopyprivateClause *C) { | 
|  | 6417 | Record.push_back(C->varlist_size()); | 
|  | 6418 | Record.AddSourceLocation(C->getLParenLoc()); | 
|  | 6419 | for (auto *VE : C->varlists()) | 
|  | 6420 | Record.AddStmt(VE); | 
|  | 6421 | for (auto *E : C->source_exprs()) | 
|  | 6422 | Record.AddStmt(E); | 
|  | 6423 | for (auto *E : C->destination_exprs()) | 
|  | 6424 | Record.AddStmt(E); | 
|  | 6425 | for (auto *E : C->assignment_ops()) | 
|  | 6426 | Record.AddStmt(E); | 
|  | 6427 | } | 
|  | 6428 |  | 
|  | 6429 | void OMPClauseWriter::VisitOMPFlushClause(OMPFlushClause *C) { | 
|  | 6430 | Record.push_back(C->varlist_size()); | 
|  | 6431 | Record.AddSourceLocation(C->getLParenLoc()); | 
|  | 6432 | for (auto *VE : C->varlists()) | 
|  | 6433 | Record.AddStmt(VE); | 
|  | 6434 | } | 
|  | 6435 |  | 
| Alexey Bataev | c112e94 | 2020-02-28 09:52:15 -0500 | [diff] [blame] | 6436 | void OMPClauseWriter::VisitOMPDepobjClause(OMPDepobjClause *C) { | 
|  | 6437 | Record.AddStmt(C->getDepobj()); | 
|  | 6438 | Record.AddSourceLocation(C->getLParenLoc()); | 
|  | 6439 | } | 
|  | 6440 |  | 
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 6441 | void OMPClauseWriter::VisitOMPDependClause(OMPDependClause *C) { | 
|  | 6442 | Record.push_back(C->varlist_size()); | 
|  | 6443 | Record.push_back(C->getNumLoops()); | 
|  | 6444 | Record.AddSourceLocation(C->getLParenLoc()); | 
| Alexey Bataev | 13a1504 | 2020-04-01 15:06:38 -0400 | [diff] [blame] | 6445 | Record.AddStmt(C->getModifier()); | 
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 6446 | Record.push_back(C->getDependencyKind()); | 
|  | 6447 | Record.AddSourceLocation(C->getDependencyLoc()); | 
|  | 6448 | Record.AddSourceLocation(C->getColonLoc()); | 
|  | 6449 | for (auto *VE : C->varlists()) | 
|  | 6450 | Record.AddStmt(VE); | 
|  | 6451 | for (unsigned I = 0, E = C->getNumLoops(); I < E; ++I) | 
|  | 6452 | Record.AddStmt(C->getLoopData(I)); | 
|  | 6453 | } | 
|  | 6454 |  | 
|  | 6455 | void OMPClauseWriter::VisitOMPDeviceClause(OMPDeviceClause *C) { | 
|  | 6456 | VisitOMPClauseWithPreInit(C); | 
| Alexey Bataev | 2f8894a | 2020-03-18 15:01:15 -0400 | [diff] [blame] | 6457 | Record.writeEnum(C->getModifier()); | 
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 6458 | Record.AddStmt(C->getDevice()); | 
| Alexey Bataev | 2f8894a | 2020-03-18 15:01:15 -0400 | [diff] [blame] | 6459 | Record.AddSourceLocation(C->getModifierLoc()); | 
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 6460 | Record.AddSourceLocation(C->getLParenLoc()); | 
|  | 6461 | } | 
|  | 6462 |  | 
|  | 6463 | void OMPClauseWriter::VisitOMPMapClause(OMPMapClause *C) { | 
|  | 6464 | Record.push_back(C->varlist_size()); | 
|  | 6465 | Record.push_back(C->getUniqueDeclarationsNum()); | 
|  | 6466 | Record.push_back(C->getTotalComponentListNum()); | 
|  | 6467 | Record.push_back(C->getTotalComponentsNum()); | 
|  | 6468 | Record.AddSourceLocation(C->getLParenLoc()); | 
| Reid Kleckner | ba1ffd2 | 2020-04-03 12:35:30 -0700 | [diff] [blame] | 6469 | for (unsigned I = 0; I < NumberOfOMPMapClauseModifiers; ++I) { | 
| Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 6470 | Record.push_back(C->getMapTypeModifier(I)); | 
|  | 6471 | Record.AddSourceLocation(C->getMapTypeModifierLoc(I)); | 
|  | 6472 | } | 
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 6473 | Record.AddNestedNameSpecifierLoc(C->getMapperQualifierLoc()); | 
|  | 6474 | Record.AddDeclarationNameInfo(C->getMapperIdInfo()); | 
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 6475 | Record.push_back(C->getMapType()); | 
|  | 6476 | Record.AddSourceLocation(C->getMapLoc()); | 
|  | 6477 | Record.AddSourceLocation(C->getColonLoc()); | 
|  | 6478 | for (auto *E : C->varlists()) | 
|  | 6479 | Record.AddStmt(E); | 
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 6480 | for (auto *E : C->mapperlists()) | 
|  | 6481 | Record.AddStmt(E); | 
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 6482 | for (auto *D : C->all_decls()) | 
|  | 6483 | Record.AddDeclRef(D); | 
|  | 6484 | for (auto N : C->all_num_lists()) | 
|  | 6485 | Record.push_back(N); | 
|  | 6486 | for (auto N : C->all_lists_sizes()) | 
|  | 6487 | Record.push_back(N); | 
|  | 6488 | for (auto &M : C->all_components()) { | 
|  | 6489 | Record.AddStmt(M.getAssociatedExpression()); | 
|  | 6490 | Record.AddDeclRef(M.getAssociatedDeclaration()); | 
|  | 6491 | } | 
|  | 6492 | } | 
|  | 6493 |  | 
| Alexey Bataev | e04483e | 2019-03-27 14:14:31 +0000 | [diff] [blame] | 6494 | void OMPClauseWriter::VisitOMPAllocateClause(OMPAllocateClause *C) { | 
|  | 6495 | Record.push_back(C->varlist_size()); | 
|  | 6496 | Record.AddSourceLocation(C->getLParenLoc()); | 
|  | 6497 | Record.AddSourceLocation(C->getColonLoc()); | 
|  | 6498 | Record.AddStmt(C->getAllocator()); | 
|  | 6499 | for (auto *VE : C->varlists()) | 
|  | 6500 | Record.AddStmt(VE); | 
|  | 6501 | } | 
|  | 6502 |  | 
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 6503 | void OMPClauseWriter::VisitOMPNumTeamsClause(OMPNumTeamsClause *C) { | 
|  | 6504 | VisitOMPClauseWithPreInit(C); | 
|  | 6505 | Record.AddStmt(C->getNumTeams()); | 
|  | 6506 | Record.AddSourceLocation(C->getLParenLoc()); | 
|  | 6507 | } | 
|  | 6508 |  | 
|  | 6509 | void OMPClauseWriter::VisitOMPThreadLimitClause(OMPThreadLimitClause *C) { | 
|  | 6510 | VisitOMPClauseWithPreInit(C); | 
|  | 6511 | Record.AddStmt(C->getThreadLimit()); | 
|  | 6512 | Record.AddSourceLocation(C->getLParenLoc()); | 
|  | 6513 | } | 
|  | 6514 |  | 
|  | 6515 | void OMPClauseWriter::VisitOMPPriorityClause(OMPPriorityClause *C) { | 
| Alexey Bataev | 31ba476 | 2019-10-16 18:09:37 +0000 | [diff] [blame] | 6516 | VisitOMPClauseWithPreInit(C); | 
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 6517 | Record.AddStmt(C->getPriority()); | 
|  | 6518 | Record.AddSourceLocation(C->getLParenLoc()); | 
|  | 6519 | } | 
|  | 6520 |  | 
|  | 6521 | void OMPClauseWriter::VisitOMPGrainsizeClause(OMPGrainsizeClause *C) { | 
| Alexey Bataev | b9c55e2 | 2019-10-14 19:29:52 +0000 | [diff] [blame] | 6522 | VisitOMPClauseWithPreInit(C); | 
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 6523 | Record.AddStmt(C->getGrainsize()); | 
|  | 6524 | Record.AddSourceLocation(C->getLParenLoc()); | 
|  | 6525 | } | 
|  | 6526 |  | 
|  | 6527 | void OMPClauseWriter::VisitOMPNumTasksClause(OMPNumTasksClause *C) { | 
| Alexey Bataev | d88c7de | 2019-10-14 20:44:34 +0000 | [diff] [blame] | 6528 | VisitOMPClauseWithPreInit(C); | 
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 6529 | Record.AddStmt(C->getNumTasks()); | 
|  | 6530 | Record.AddSourceLocation(C->getLParenLoc()); | 
|  | 6531 | } | 
|  | 6532 |  | 
|  | 6533 | void OMPClauseWriter::VisitOMPHintClause(OMPHintClause *C) { | 
|  | 6534 | Record.AddStmt(C->getHint()); | 
|  | 6535 | Record.AddSourceLocation(C->getLParenLoc()); | 
|  | 6536 | } | 
|  | 6537 |  | 
|  | 6538 | void OMPClauseWriter::VisitOMPDistScheduleClause(OMPDistScheduleClause *C) { | 
|  | 6539 | VisitOMPClauseWithPreInit(C); | 
|  | 6540 | Record.push_back(C->getDistScheduleKind()); | 
|  | 6541 | Record.AddStmt(C->getChunkSize()); | 
|  | 6542 | Record.AddSourceLocation(C->getLParenLoc()); | 
|  | 6543 | Record.AddSourceLocation(C->getDistScheduleKindLoc()); | 
|  | 6544 | Record.AddSourceLocation(C->getCommaLoc()); | 
|  | 6545 | } | 
|  | 6546 |  | 
|  | 6547 | void OMPClauseWriter::VisitOMPDefaultmapClause(OMPDefaultmapClause *C) { | 
|  | 6548 | Record.push_back(C->getDefaultmapKind()); | 
|  | 6549 | Record.push_back(C->getDefaultmapModifier()); | 
|  | 6550 | Record.AddSourceLocation(C->getLParenLoc()); | 
|  | 6551 | Record.AddSourceLocation(C->getDefaultmapModifierLoc()); | 
|  | 6552 | Record.AddSourceLocation(C->getDefaultmapKindLoc()); | 
|  | 6553 | } | 
|  | 6554 |  | 
|  | 6555 | void OMPClauseWriter::VisitOMPToClause(OMPToClause *C) { | 
|  | 6556 | Record.push_back(C->varlist_size()); | 
|  | 6557 | Record.push_back(C->getUniqueDeclarationsNum()); | 
|  | 6558 | Record.push_back(C->getTotalComponentListNum()); | 
|  | 6559 | Record.push_back(C->getTotalComponentsNum()); | 
|  | 6560 | Record.AddSourceLocation(C->getLParenLoc()); | 
| Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 6561 | Record.AddNestedNameSpecifierLoc(C->getMapperQualifierLoc()); | 
|  | 6562 | Record.AddDeclarationNameInfo(C->getMapperIdInfo()); | 
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 6563 | for (auto *E : C->varlists()) | 
|  | 6564 | Record.AddStmt(E); | 
| Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 6565 | for (auto *E : C->mapperlists()) | 
|  | 6566 | Record.AddStmt(E); | 
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 6567 | for (auto *D : C->all_decls()) | 
|  | 6568 | Record.AddDeclRef(D); | 
|  | 6569 | for (auto N : C->all_num_lists()) | 
|  | 6570 | Record.push_back(N); | 
|  | 6571 | for (auto N : C->all_lists_sizes()) | 
|  | 6572 | Record.push_back(N); | 
|  | 6573 | for (auto &M : C->all_components()) { | 
|  | 6574 | Record.AddStmt(M.getAssociatedExpression()); | 
|  | 6575 | Record.AddDeclRef(M.getAssociatedDeclaration()); | 
|  | 6576 | } | 
|  | 6577 | } | 
|  | 6578 |  | 
|  | 6579 | void OMPClauseWriter::VisitOMPFromClause(OMPFromClause *C) { | 
|  | 6580 | Record.push_back(C->varlist_size()); | 
|  | 6581 | Record.push_back(C->getUniqueDeclarationsNum()); | 
|  | 6582 | Record.push_back(C->getTotalComponentListNum()); | 
|  | 6583 | Record.push_back(C->getTotalComponentsNum()); | 
|  | 6584 | Record.AddSourceLocation(C->getLParenLoc()); | 
| Michael Kruse | 0336c75 | 2019-02-25 20:34:15 +0000 | [diff] [blame] | 6585 | Record.AddNestedNameSpecifierLoc(C->getMapperQualifierLoc()); | 
|  | 6586 | Record.AddDeclarationNameInfo(C->getMapperIdInfo()); | 
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 6587 | for (auto *E : C->varlists()) | 
|  | 6588 | Record.AddStmt(E); | 
| Michael Kruse | 0336c75 | 2019-02-25 20:34:15 +0000 | [diff] [blame] | 6589 | for (auto *E : C->mapperlists()) | 
|  | 6590 | Record.AddStmt(E); | 
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 6591 | for (auto *D : C->all_decls()) | 
|  | 6592 | Record.AddDeclRef(D); | 
|  | 6593 | for (auto N : C->all_num_lists()) | 
|  | 6594 | Record.push_back(N); | 
|  | 6595 | for (auto N : C->all_lists_sizes()) | 
|  | 6596 | Record.push_back(N); | 
|  | 6597 | for (auto &M : C->all_components()) { | 
|  | 6598 | Record.AddStmt(M.getAssociatedExpression()); | 
|  | 6599 | Record.AddDeclRef(M.getAssociatedDeclaration()); | 
|  | 6600 | } | 
|  | 6601 | } | 
|  | 6602 |  | 
|  | 6603 | void OMPClauseWriter::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *C) { | 
|  | 6604 | Record.push_back(C->varlist_size()); | 
|  | 6605 | Record.push_back(C->getUniqueDeclarationsNum()); | 
|  | 6606 | Record.push_back(C->getTotalComponentListNum()); | 
|  | 6607 | Record.push_back(C->getTotalComponentsNum()); | 
|  | 6608 | Record.AddSourceLocation(C->getLParenLoc()); | 
|  | 6609 | for (auto *E : C->varlists()) | 
|  | 6610 | Record.AddStmt(E); | 
|  | 6611 | for (auto *VE : C->private_copies()) | 
|  | 6612 | Record.AddStmt(VE); | 
|  | 6613 | for (auto *VE : C->inits()) | 
|  | 6614 | Record.AddStmt(VE); | 
|  | 6615 | for (auto *D : C->all_decls()) | 
|  | 6616 | Record.AddDeclRef(D); | 
|  | 6617 | for (auto N : C->all_num_lists()) | 
|  | 6618 | Record.push_back(N); | 
|  | 6619 | for (auto N : C->all_lists_sizes()) | 
|  | 6620 | Record.push_back(N); | 
|  | 6621 | for (auto &M : C->all_components()) { | 
|  | 6622 | Record.AddStmt(M.getAssociatedExpression()); | 
|  | 6623 | Record.AddDeclRef(M.getAssociatedDeclaration()); | 
|  | 6624 | } | 
|  | 6625 | } | 
|  | 6626 |  | 
|  | 6627 | void OMPClauseWriter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) { | 
|  | 6628 | Record.push_back(C->varlist_size()); | 
|  | 6629 | Record.push_back(C->getUniqueDeclarationsNum()); | 
|  | 6630 | Record.push_back(C->getTotalComponentListNum()); | 
|  | 6631 | Record.push_back(C->getTotalComponentsNum()); | 
|  | 6632 | Record.AddSourceLocation(C->getLParenLoc()); | 
|  | 6633 | for (auto *E : C->varlists()) | 
|  | 6634 | Record.AddStmt(E); | 
|  | 6635 | for (auto *D : C->all_decls()) | 
|  | 6636 | Record.AddDeclRef(D); | 
|  | 6637 | for (auto N : C->all_num_lists()) | 
|  | 6638 | Record.push_back(N); | 
|  | 6639 | for (auto N : C->all_lists_sizes()) | 
|  | 6640 | Record.push_back(N); | 
|  | 6641 | for (auto &M : C->all_components()) { | 
|  | 6642 | Record.AddStmt(M.getAssociatedExpression()); | 
|  | 6643 | Record.AddDeclRef(M.getAssociatedDeclaration()); | 
|  | 6644 | } | 
|  | 6645 | } | 
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 6646 |  | 
|  | 6647 | void OMPClauseWriter::VisitOMPUnifiedAddressClause(OMPUnifiedAddressClause *) {} | 
| Patrick Lyster | 4a370b9 | 2018-10-01 13:47:43 +0000 | [diff] [blame] | 6648 |  | 
|  | 6649 | void OMPClauseWriter::VisitOMPUnifiedSharedMemoryClause( | 
|  | 6650 | OMPUnifiedSharedMemoryClause *) {} | 
| Patrick Lyster | 6bdf63b | 2018-10-03 20:07:58 +0000 | [diff] [blame] | 6651 |  | 
|  | 6652 | void OMPClauseWriter::VisitOMPReverseOffloadClause(OMPReverseOffloadClause *) {} | 
| Patrick Lyster | 3fe9e39 | 2018-10-11 14:41:10 +0000 | [diff] [blame] | 6653 |  | 
|  | 6654 | void | 
|  | 6655 | OMPClauseWriter::VisitOMPDynamicAllocatorsClause(OMPDynamicAllocatorsClause *) { | 
|  | 6656 | } | 
| Patrick Lyster | 7a2a27c | 2018-11-02 12:18:11 +0000 | [diff] [blame] | 6657 |  | 
|  | 6658 | void OMPClauseWriter::VisitOMPAtomicDefaultMemOrderClause( | 
|  | 6659 | OMPAtomicDefaultMemOrderClause *C) { | 
|  | 6660 | Record.push_back(C->getAtomicDefaultMemOrderKind()); | 
|  | 6661 | Record.AddSourceLocation(C->getLParenLoc()); | 
|  | 6662 | Record.AddSourceLocation(C->getAtomicDefaultMemOrderKindKwLoc()); | 
|  | 6663 | } | 
| Alexey Bataev | b6e7084 | 2019-12-16 15:54:17 -0500 | [diff] [blame] | 6664 |  | 
|  | 6665 | void OMPClauseWriter::VisitOMPNontemporalClause(OMPNontemporalClause *C) { | 
|  | 6666 | Record.push_back(C->varlist_size()); | 
|  | 6667 | Record.AddSourceLocation(C->getLParenLoc()); | 
|  | 6668 | for (auto *VE : C->varlists()) | 
|  | 6669 | Record.AddStmt(VE); | 
| Alexey Bataev | 0860db9 | 2019-12-19 10:01:10 -0500 | [diff] [blame] | 6670 | for (auto *E : C->private_refs()) | 
|  | 6671 | Record.AddStmt(E); | 
| Alexey Bataev | b6e7084 | 2019-12-16 15:54:17 -0500 | [diff] [blame] | 6672 | } | 
| Alexey Bataev | cb8e691 | 2020-01-31 16:09:26 -0500 | [diff] [blame] | 6673 |  | 
| Alexey Bataev | 06dea73 | 2020-03-20 09:41:22 -0400 | [diff] [blame] | 6674 | void OMPClauseWriter::VisitOMPInclusiveClause(OMPInclusiveClause *C) { | 
|  | 6675 | Record.push_back(C->varlist_size()); | 
|  | 6676 | Record.AddSourceLocation(C->getLParenLoc()); | 
|  | 6677 | for (auto *VE : C->varlists()) | 
|  | 6678 | Record.AddStmt(VE); | 
|  | 6679 | } | 
|  | 6680 |  | 
| Alexey Bataev | 63828a3 | 2020-03-23 10:41:08 -0400 | [diff] [blame] | 6681 | void OMPClauseWriter::VisitOMPExclusiveClause(OMPExclusiveClause *C) { | 
|  | 6682 | Record.push_back(C->varlist_size()); | 
|  | 6683 | Record.AddSourceLocation(C->getLParenLoc()); | 
|  | 6684 | for (auto *VE : C->varlists()) | 
|  | 6685 | Record.AddStmt(VE); | 
|  | 6686 | } | 
|  | 6687 |  | 
| Alexey Bataev | cb8e691 | 2020-01-31 16:09:26 -0500 | [diff] [blame] | 6688 | void OMPClauseWriter::VisitOMPOrderClause(OMPOrderClause *C) { | 
|  | 6689 | Record.writeEnum(C->getKind()); | 
|  | 6690 | Record.AddSourceLocation(C->getLParenLoc()); | 
|  | 6691 | Record.AddSourceLocation(C->getKindKwLoc()); | 
|  | 6692 | } | 
|  | 6693 |  | 
| Alexey Bataev | b5be1c5 | 2020-04-21 13:21:00 -0400 | [diff] [blame] | 6694 | void OMPClauseWriter::VisitOMPUsesAllocatorsClause(OMPUsesAllocatorsClause *C) { | 
|  | 6695 | Record.push_back(C->getNumberOfAllocators()); | 
|  | 6696 | Record.AddSourceLocation(C->getLParenLoc()); | 
|  | 6697 | for (unsigned I = 0, E = C->getNumberOfAllocators(); I < E; ++I) { | 
|  | 6698 | OMPUsesAllocatorsClause::Data Data = C->getAllocatorData(I); | 
|  | 6699 | Record.AddStmt(Data.Allocator); | 
|  | 6700 | Record.AddStmt(Data.AllocatorTraits); | 
|  | 6701 | Record.AddSourceLocation(Data.LParenLoc); | 
|  | 6702 | Record.AddSourceLocation(Data.RParenLoc); | 
|  | 6703 | } | 
|  | 6704 | } | 
|  | 6705 |  | 
| Johannes Doerfert | 55eca28 | 2020-03-13 23:42:05 -0500 | [diff] [blame] | 6706 | void ASTRecordWriter::writeOMPTraitInfo(const OMPTraitInfo *TI) { | 
|  | 6707 | writeUInt32(TI->Sets.size()); | 
|  | 6708 | for (const auto &Set : TI->Sets) { | 
| Johannes Doerfert | 1228d42 | 2019-12-19 20:42:12 -0600 | [diff] [blame] | 6709 | writeEnum(Set.Kind); | 
|  | 6710 | writeUInt32(Set.Selectors.size()); | 
|  | 6711 | for (const auto &Selector : Set.Selectors) { | 
|  | 6712 | writeEnum(Selector.Kind); | 
|  | 6713 | writeBool(Selector.ScoreOrCondition); | 
|  | 6714 | if (Selector.ScoreOrCondition) | 
|  | 6715 | writeExprRef(Selector.ScoreOrCondition); | 
|  | 6716 | writeUInt32(Selector.Properties.size()); | 
|  | 6717 | for (const auto &Property : Selector.Properties) | 
|  | 6718 | writeEnum(Property.Kind); | 
|  | 6719 | } | 
|  | 6720 | } | 
|  | 6721 | } |