John Thompson | d977c1e | 2013-03-27 18:34:38 +0000 | [diff] [blame] | 1 | //===- extra/modularize/Modularize.cpp - Check modularized headers --------===// |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements a tool that checks whether a set of headers provides |
| 11 | // the consistent definitions required to use modules. For example, it detects |
| 12 | // whether the same entity (say, a NULL macro or size_t typedef) is defined in |
| 13 | // multiple headers or whether a header produces different definitions under |
| 14 | // different circumstances. These conditions cause modules built from the |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 15 | // headers to behave poorly, and should be fixed before introducing a module |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 16 | // map. |
| 17 | // |
| 18 | // Modularize takes as argument a file name for a file containing the |
| 19 | // newline-separated list of headers to check with respect to each other. |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 20 | // Lines beginning with '#' and empty lines are ignored. |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 21 | // Modularize also accepts regular front-end arguments. |
| 22 | // |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 23 | // Usage: modularize [-prefix (optional header path prefix)] |
John Thompson | a2de108 | 2013-03-26 01:17:48 +0000 | [diff] [blame] | 24 | // (include-files_list) [(front-end-options) ...] |
| 25 | // |
John Thompson | a44f85a | 2013-04-15 22:32:28 +0000 | [diff] [blame] | 26 | // Note that unless a "-prefix (header path)" option is specified, |
John Thompson | a2de108 | 2013-03-26 01:17:48 +0000 | [diff] [blame] | 27 | // non-absolute file paths in the header list file will be relative |
| 28 | // to the header list file directory. Use -prefix to specify a different |
| 29 | // directory. |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 30 | // |
John Thompson | fd8ca38 | 2013-03-27 19:31:22 +0000 | [diff] [blame] | 31 | // Note that by default, the underlying Clang front end assumes .h files |
| 32 | // contain C source. If your .h files in the file list contain C++ source, |
John Thompson | ea6c8db | 2013-03-27 21:23:21 +0000 | [diff] [blame] | 33 | // you should append the following to your command lines: -x c++ |
John Thompson | fd8ca38 | 2013-03-27 19:31:22 +0000 | [diff] [blame] | 34 | // |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 35 | // Modularize will do normal parsing, reporting normal errors and warnings, |
| 36 | // but will also report special error messages like the following: |
| 37 | // |
John Thompson | a44f85a | 2013-04-15 22:32:28 +0000 | [diff] [blame] | 38 | // error: '(symbol)' defined at multiple locations: |
| 39 | // (file):(row):(column) |
| 40 | // (file):(row):(column) |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 41 | // |
| 42 | // error: header '(file)' has different contents dependening on how it was |
| 43 | // included |
| 44 | // |
| 45 | // The latter might be followed by messages like the following: |
| 46 | // |
| 47 | // note: '(symbol)' in (file) at (row):(column) not always provided |
| 48 | // |
John Thompson | ce601e2 | 2013-03-14 01:41:29 +0000 | [diff] [blame] | 49 | // Future directions: |
| 50 | // |
| 51 | // Basically, we want to add new checks for whatever we can check with respect |
| 52 | // to checking headers for module'ability. |
| 53 | // |
| 54 | // Some ideas: |
| 55 | // |
John Thompson | 3b1ee2b | 2013-03-28 02:46:25 +0000 | [diff] [blame] | 56 | // 1. Try to figure out the preprocessor conditional directives that |
John Thompson | ce601e2 | 2013-03-14 01:41:29 +0000 | [diff] [blame] | 57 | // contribute to problems. |
| 58 | // |
John Thompson | 3b1ee2b | 2013-03-28 02:46:25 +0000 | [diff] [blame] | 59 | // 2. Check for correct and consistent usage of extern "C" {} and other |
John Thompson | ce601e2 | 2013-03-14 01:41:29 +0000 | [diff] [blame] | 60 | // directives. Warn about #include inside extern "C" {}. |
| 61 | // |
John Thompson | 3b1ee2b | 2013-03-28 02:46:25 +0000 | [diff] [blame] | 62 | // 3. What else? |
John Thompson | ce601e2 | 2013-03-14 01:41:29 +0000 | [diff] [blame] | 63 | // |
| 64 | // General clean-up and refactoring: |
| 65 | // |
| 66 | // 1. The Location class seems to be something that we might |
| 67 | // want to design to be applicable to a wider range of tools, and stick it |
| 68 | // somewhere into Tooling/ in mainline |
| 69 | // |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 70 | //===----------------------------------------------------------------------===// |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 71 | |
John Thompson | d977c1e | 2013-03-27 18:34:38 +0000 | [diff] [blame] | 72 | #include "clang/AST/ASTConsumer.h" |
| 73 | #include "clang/AST/ASTContext.h" |
| 74 | #include "clang/AST/RecursiveASTVisitor.h" |
| 75 | #include "clang/Basic/SourceManager.h" |
| 76 | #include "clang/Frontend/CompilerInstance.h" |
| 77 | #include "clang/Frontend/FrontendActions.h" |
| 78 | #include "clang/Lex/Preprocessor.h" |
| 79 | #include "clang/Tooling/CompilationDatabase.h" |
| 80 | #include "clang/Tooling/Tooling.h" |
| 81 | #include "llvm/ADT/OwningPtr.h" |
| 82 | #include "llvm/ADT/StringRef.h" |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 83 | #include "llvm/Config/config.h" |
John Thompson | a2de108 | 2013-03-26 01:17:48 +0000 | [diff] [blame] | 84 | #include "llvm/Support/CommandLine.h" |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 85 | #include "llvm/Support/FileSystem.h" |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 86 | #include "llvm/Support/MemoryBuffer.h" |
John Thompson | a2de108 | 2013-03-26 01:17:48 +0000 | [diff] [blame] | 87 | #include "llvm/Support/Path.h" |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 88 | #include <algorithm> |
John Thompson | d977c1e | 2013-03-27 18:34:38 +0000 | [diff] [blame] | 89 | #include <fstream> |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 90 | #include <iterator> |
John Thompson | d977c1e | 2013-03-27 18:34:38 +0000 | [diff] [blame] | 91 | #include <string> |
| 92 | #include <vector> |
John Thompson | 1e01014 | 2013-07-26 18:16:22 +0000 | [diff] [blame^] | 93 | #include "PreprocessorTracker.h" |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 94 | |
| 95 | using namespace clang::tooling; |
| 96 | using namespace clang; |
John Thompson | a2de108 | 2013-03-26 01:17:48 +0000 | [diff] [blame] | 97 | using namespace llvm; |
John Thompson | 1e01014 | 2013-07-26 18:16:22 +0000 | [diff] [blame^] | 98 | using namespace Modularize; |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 99 | |
John Thompson | ea6c8db | 2013-03-27 21:23:21 +0000 | [diff] [blame] | 100 | // Option to specify a file name for a list of header files to check. |
John Thompson | b809dfc | 2013-07-19 14:19:31 +0000 | [diff] [blame] | 101 | cl::opt<std::string> |
| 102 | ListFileName(cl::Positional, |
| 103 | cl::desc("<name of file containing list of headers to check>")); |
John Thompson | ea6c8db | 2013-03-27 21:23:21 +0000 | [diff] [blame] | 104 | |
| 105 | // Collect all other arguments, which will be passed to the front end. |
John Thompson | 161381e | 2013-06-27 18:52:23 +0000 | [diff] [blame] | 106 | cl::list<std::string> |
John Thompson | b809dfc | 2013-07-19 14:19:31 +0000 | [diff] [blame] | 107 | CC1Arguments(cl::ConsumeAfter, |
| 108 | cl::desc("<arguments to be passed to front end>...")); |
John Thompson | ea6c8db | 2013-03-27 21:23:21 +0000 | [diff] [blame] | 109 | |
| 110 | // Option to specify a prefix to be prepended to the header names. |
| 111 | cl::opt<std::string> HeaderPrefix( |
| 112 | "prefix", cl::init(""), |
| 113 | cl::desc( |
| 114 | "Prepend header file paths with this prefix." |
| 115 | " If not specified," |
| 116 | " the files are considered to be relative to the header list file.")); |
| 117 | |
| 118 | // Read the header list file and collect the header file names. |
John Thompson | 54c8369 | 2013-06-18 19:56:05 +0000 | [diff] [blame] | 119 | error_code getHeaderFileNames(SmallVectorImpl<std::string> &headerFileNames, |
John Thompson | ea6c8db | 2013-03-27 21:23:21 +0000 | [diff] [blame] | 120 | StringRef listFileName, StringRef headerPrefix) { |
| 121 | |
| 122 | // By default, use the path component of the list file name. |
| 123 | SmallString<256> headerDirectory(listFileName); |
| 124 | sys::path::remove_filename(headerDirectory); |
| 125 | |
| 126 | // Get the prefix if we have one. |
| 127 | if (headerPrefix.size() != 0) |
| 128 | headerDirectory = headerPrefix; |
| 129 | |
| 130 | // Read the header list file into a buffer. |
| 131 | OwningPtr<MemoryBuffer> listBuffer; |
John Thompson | 26b567a | 2013-06-19 20:35:50 +0000 | [diff] [blame] | 132 | if (error_code ec = MemoryBuffer::getFile(listFileName, listBuffer)) { |
John Thompson | ea6c8db | 2013-03-27 21:23:21 +0000 | [diff] [blame] | 133 | return ec; |
| 134 | } |
| 135 | |
| 136 | // Parse the header list into strings. |
| 137 | SmallVector<StringRef, 32> strings; |
| 138 | listBuffer->getBuffer().split(strings, "\n", -1, false); |
| 139 | |
| 140 | // Collect the header file names from the string list. |
| 141 | for (SmallVectorImpl<StringRef>::iterator I = strings.begin(), |
| 142 | E = strings.end(); |
| 143 | I != E; ++I) { |
| 144 | StringRef line = (*I).trim(); |
| 145 | // Ignore comments and empty lines. |
| 146 | if (line.empty() || (line[0] == '#')) |
| 147 | continue; |
| 148 | SmallString<256> headerFileName; |
| 149 | // Prepend header file name prefix if it's not absolute. |
| 150 | if (sys::path::is_absolute(line)) |
| 151 | headerFileName = line; |
| 152 | else { |
| 153 | headerFileName = headerDirectory; |
| 154 | sys::path::append(headerFileName, line); |
| 155 | } |
| 156 | // Save the resulting header file path. |
| 157 | headerFileNames.push_back(headerFileName.str()); |
| 158 | } |
| 159 | |
| 160 | return error_code::success(); |
| 161 | } |
| 162 | |
John Thompson | ce601e2 | 2013-03-14 01:41:29 +0000 | [diff] [blame] | 163 | // FIXME: The Location class seems to be something that we might |
| 164 | // want to design to be applicable to a wider range of tools, and stick it |
| 165 | // somewhere into Tooling/ in mainline |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 166 | struct Location { |
| 167 | const FileEntry *File; |
| 168 | unsigned Line, Column; |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 169 | |
| 170 | Location() : File(), Line(), Column() {} |
| 171 | |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 172 | Location(SourceManager &SM, SourceLocation Loc) : File(), Line(), Column() { |
| 173 | Loc = SM.getExpansionLoc(Loc); |
| 174 | if (Loc.isInvalid()) |
| 175 | return; |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 176 | |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 177 | std::pair<FileID, unsigned> Decomposed = SM.getDecomposedLoc(Loc); |
| 178 | File = SM.getFileEntryForID(Decomposed.first); |
| 179 | if (!File) |
| 180 | return; |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 181 | |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 182 | Line = SM.getLineNumber(Decomposed.first, Decomposed.second); |
| 183 | Column = SM.getColumnNumber(Decomposed.first, Decomposed.second); |
| 184 | } |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 185 | |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 186 | operator bool() const { return File != 0; } |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 187 | |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 188 | friend bool operator==(const Location &X, const Location &Y) { |
| 189 | return X.File == Y.File && X.Line == Y.Line && X.Column == Y.Column; |
| 190 | } |
| 191 | |
| 192 | friend bool operator!=(const Location &X, const Location &Y) { |
| 193 | return !(X == Y); |
| 194 | } |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 195 | |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 196 | friend bool operator<(const Location &X, const Location &Y) { |
| 197 | if (X.File != Y.File) |
| 198 | return X.File < Y.File; |
| 199 | if (X.Line != Y.Line) |
| 200 | return X.Line < Y.Line; |
| 201 | return X.Column < Y.Column; |
| 202 | } |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 203 | friend bool operator>(const Location &X, const Location &Y) { return Y < X; } |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 204 | friend bool operator<=(const Location &X, const Location &Y) { |
| 205 | return !(Y < X); |
| 206 | } |
| 207 | friend bool operator>=(const Location &X, const Location &Y) { |
| 208 | return !(X < Y); |
| 209 | } |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 210 | }; |
| 211 | |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 212 | struct Entry { |
John Thompson | 52d9886 | 2013-03-28 18:38:43 +0000 | [diff] [blame] | 213 | enum EntryKind { |
| 214 | EK_Tag, |
| 215 | EK_Value, |
| 216 | EK_Macro, |
| 217 | |
| 218 | EK_NumberOfKinds |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 219 | } Kind; |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 220 | |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 221 | Location Loc; |
John Thompson | 4e4d9b3 | 2013-03-28 01:20:19 +0000 | [diff] [blame] | 222 | |
| 223 | StringRef getKindName() { return getKindName(Kind); } |
John Thompson | 52d9886 | 2013-03-28 18:38:43 +0000 | [diff] [blame] | 224 | static StringRef getKindName(EntryKind kind); |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 225 | }; |
| 226 | |
John Thompson | 4e4d9b3 | 2013-03-28 01:20:19 +0000 | [diff] [blame] | 227 | // Return a string representing the given kind. |
John Thompson | 52d9886 | 2013-03-28 18:38:43 +0000 | [diff] [blame] | 228 | StringRef Entry::getKindName(Entry::EntryKind kind) { |
John Thompson | 4e4d9b3 | 2013-03-28 01:20:19 +0000 | [diff] [blame] | 229 | switch (kind) { |
John Thompson | 52d9886 | 2013-03-28 18:38:43 +0000 | [diff] [blame] | 230 | case EK_Tag: |
John Thompson | 4e4d9b3 | 2013-03-28 01:20:19 +0000 | [diff] [blame] | 231 | return "tag"; |
John Thompson | 52d9886 | 2013-03-28 18:38:43 +0000 | [diff] [blame] | 232 | case EK_Value: |
John Thompson | 4e4d9b3 | 2013-03-28 01:20:19 +0000 | [diff] [blame] | 233 | return "value"; |
John Thompson | 52d9886 | 2013-03-28 18:38:43 +0000 | [diff] [blame] | 234 | case EK_Macro: |
John Thompson | 4e4d9b3 | 2013-03-28 01:20:19 +0000 | [diff] [blame] | 235 | return "macro"; |
John Thompson | 52d9886 | 2013-03-28 18:38:43 +0000 | [diff] [blame] | 236 | case EK_NumberOfKinds: |
John Thompson | 4e4d9b3 | 2013-03-28 01:20:19 +0000 | [diff] [blame] | 237 | break; |
John Thompson | 4e4d9b3 | 2013-03-28 01:20:19 +0000 | [diff] [blame] | 238 | } |
David Blaikie | c66c07d | 2013-03-28 02:30:37 +0000 | [diff] [blame] | 239 | llvm_unreachable("invalid Entry kind"); |
John Thompson | 4e4d9b3 | 2013-03-28 01:20:19 +0000 | [diff] [blame] | 240 | } |
| 241 | |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 242 | struct HeaderEntry { |
| 243 | std::string Name; |
| 244 | Location Loc; |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 245 | |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 246 | friend bool operator==(const HeaderEntry &X, const HeaderEntry &Y) { |
| 247 | return X.Loc == Y.Loc && X.Name == Y.Name; |
| 248 | } |
| 249 | friend bool operator!=(const HeaderEntry &X, const HeaderEntry &Y) { |
| 250 | return !(X == Y); |
| 251 | } |
| 252 | friend bool operator<(const HeaderEntry &X, const HeaderEntry &Y) { |
| 253 | return X.Loc < Y.Loc || (X.Loc == Y.Loc && X.Name < Y.Name); |
| 254 | } |
| 255 | friend bool operator>(const HeaderEntry &X, const HeaderEntry &Y) { |
| 256 | return Y < X; |
| 257 | } |
| 258 | friend bool operator<=(const HeaderEntry &X, const HeaderEntry &Y) { |
| 259 | return !(Y < X); |
| 260 | } |
| 261 | friend bool operator>=(const HeaderEntry &X, const HeaderEntry &Y) { |
| 262 | return !(X < Y); |
| 263 | } |
| 264 | }; |
| 265 | |
| 266 | typedef std::vector<HeaderEntry> HeaderContents; |
| 267 | |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 268 | class EntityMap : public StringMap<SmallVector<Entry, 2> > { |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 269 | public: |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 270 | DenseMap<const FileEntry *, HeaderContents> HeaderContentMismatches; |
| 271 | |
John Thompson | 52d9886 | 2013-03-28 18:38:43 +0000 | [diff] [blame] | 272 | void add(const std::string &Name, enum Entry::EntryKind Kind, Location Loc) { |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 273 | // Record this entity in its header. |
| 274 | HeaderEntry HE = { Name, Loc }; |
| 275 | CurHeaderContents[Loc.File].push_back(HE); |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 276 | |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 277 | // Check whether we've seen this entry before. |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 278 | SmallVector<Entry, 2> &Entries = (*this)[Name]; |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 279 | for (unsigned I = 0, N = Entries.size(); I != N; ++I) { |
| 280 | if (Entries[I].Kind == Kind && Entries[I].Loc == Loc) |
| 281 | return; |
| 282 | } |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 283 | |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 284 | // We have not seen this entry before; record it. |
| 285 | Entry E = { Kind, Loc }; |
| 286 | Entries.push_back(E); |
| 287 | } |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 288 | |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 289 | void mergeCurHeaderContents() { |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 290 | for (DenseMap<const FileEntry *, HeaderContents>::iterator |
| 291 | H = CurHeaderContents.begin(), |
| 292 | HEnd = CurHeaderContents.end(); |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 293 | H != HEnd; ++H) { |
| 294 | // Sort contents. |
| 295 | std::sort(H->second.begin(), H->second.end()); |
| 296 | |
| 297 | // Check whether we've seen this header before. |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 298 | DenseMap<const FileEntry *, HeaderContents>::iterator KnownH = |
| 299 | AllHeaderContents.find(H->first); |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 300 | if (KnownH == AllHeaderContents.end()) { |
| 301 | // We haven't seen this header before; record its contents. |
| 302 | AllHeaderContents.insert(*H); |
| 303 | continue; |
| 304 | } |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 305 | |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 306 | // If the header contents are the same, we're done. |
| 307 | if (H->second == KnownH->second) |
| 308 | continue; |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 309 | |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 310 | // Determine what changed. |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 311 | std::set_symmetric_difference( |
| 312 | H->second.begin(), H->second.end(), KnownH->second.begin(), |
| 313 | KnownH->second.end(), |
| 314 | std::back_inserter(HeaderContentMismatches[H->first])); |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 315 | } |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 316 | |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 317 | CurHeaderContents.clear(); |
| 318 | } |
John Thompson | 161381e | 2013-06-27 18:52:23 +0000 | [diff] [blame] | 319 | |
John Thompson | 1f67ccb | 2013-03-12 18:51:47 +0000 | [diff] [blame] | 320 | private: |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 321 | DenseMap<const FileEntry *, HeaderContents> CurHeaderContents; |
| 322 | DenseMap<const FileEntry *, HeaderContents> AllHeaderContents; |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 323 | }; |
| 324 | |
John Thompson | 161381e | 2013-06-27 18:52:23 +0000 | [diff] [blame] | 325 | class CollectEntitiesVisitor |
| 326 | : public RecursiveASTVisitor<CollectEntitiesVisitor> { |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 327 | public: |
| 328 | CollectEntitiesVisitor(SourceManager &SM, EntityMap &Entities) |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 329 | : SM(SM), Entities(Entities) {} |
| 330 | |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 331 | bool TraverseStmt(Stmt *S) { return true; } |
| 332 | bool TraverseType(QualType T) { return true; } |
| 333 | bool TraverseTypeLoc(TypeLoc TL) { return true; } |
| 334 | bool TraverseNestedNameSpecifier(NestedNameSpecifier *NNS) { return true; } |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 335 | bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS) { |
| 336 | return true; |
| 337 | } |
| 338 | bool TraverseDeclarationNameInfo(DeclarationNameInfo NameInfo) { |
| 339 | return true; |
| 340 | } |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 341 | bool TraverseTemplateName(TemplateName Template) { return true; } |
| 342 | bool TraverseTemplateArgument(const TemplateArgument &Arg) { return true; } |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 343 | bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &ArgLoc) { |
| 344 | return true; |
| 345 | } |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 346 | bool TraverseTemplateArguments(const TemplateArgument *Args, |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 347 | unsigned NumArgs) { |
| 348 | return true; |
| 349 | } |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 350 | bool TraverseConstructorInitializer(CXXCtorInitializer *Init) { return true; } |
| 351 | bool TraverseLambdaCapture(LambdaExpr::Capture C) { return true; } |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 352 | |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 353 | bool VisitNamedDecl(NamedDecl *ND) { |
| 354 | // We only care about file-context variables. |
| 355 | if (!ND->getDeclContext()->isFileContext()) |
| 356 | return true; |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 357 | |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 358 | // Skip declarations that tend to be properly multiply-declared. |
| 359 | if (isa<NamespaceDecl>(ND) || isa<UsingDirectiveDecl>(ND) || |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 360 | isa<NamespaceAliasDecl>(ND) || |
| 361 | isa<ClassTemplateSpecializationDecl>(ND) || isa<UsingDecl>(ND) || |
| 362 | isa<UsingShadowDecl>(ND) || isa<FunctionDecl>(ND) || |
| 363 | isa<FunctionTemplateDecl>(ND) || |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 364 | (isa<TagDecl>(ND) && |
| 365 | !cast<TagDecl>(ND)->isThisDeclarationADefinition())) |
| 366 | return true; |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 367 | |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 368 | std::string Name = ND->getNameAsString(); |
| 369 | if (Name.empty()) |
| 370 | return true; |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 371 | |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 372 | Location Loc(SM, ND->getLocation()); |
| 373 | if (!Loc) |
| 374 | return true; |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 375 | |
John Thompson | 52d9886 | 2013-03-28 18:38:43 +0000 | [diff] [blame] | 376 | Entities.add(Name, isa<TagDecl>(ND) ? Entry::EK_Tag : Entry::EK_Value, Loc); |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 377 | return true; |
| 378 | } |
John Thompson | 161381e | 2013-06-27 18:52:23 +0000 | [diff] [blame] | 379 | |
John Thompson | 1f67ccb | 2013-03-12 18:51:47 +0000 | [diff] [blame] | 380 | private: |
| 381 | SourceManager &SM; |
| 382 | EntityMap &Entities; |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 383 | }; |
| 384 | |
| 385 | class CollectEntitiesConsumer : public ASTConsumer { |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 386 | public: |
John Thompson | 1e01014 | 2013-07-26 18:16:22 +0000 | [diff] [blame^] | 387 | CollectEntitiesConsumer(EntityMap &Entities, |
| 388 | PreprocessorTracker &preprocessorTracker, |
| 389 | Preprocessor &PP, StringRef InFile) |
| 390 | : Entities(Entities), PPTracker(preprocessorTracker), PP(PP) { |
| 391 | PPTracker.handlePreprocessorEntry(PP, InFile); |
| 392 | } |
| 393 | |
| 394 | ~CollectEntitiesConsumer() { PPTracker.handlePreprocessorExit(); } |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 395 | |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 396 | virtual void HandleTranslationUnit(ASTContext &Ctx) { |
| 397 | SourceManager &SM = Ctx.getSourceManager(); |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 398 | |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 399 | // Collect declared entities. |
| 400 | CollectEntitiesVisitor(SM, Entities) |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 401 | .TraverseDecl(Ctx.getTranslationUnitDecl()); |
| 402 | |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 403 | // Collect macro definitions. |
| 404 | for (Preprocessor::macro_iterator M = PP.macro_begin(), |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 405 | MEnd = PP.macro_end(); |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 406 | M != MEnd; ++M) { |
| 407 | Location Loc(SM, M->second->getLocation()); |
| 408 | if (!Loc) |
| 409 | continue; |
| 410 | |
John Thompson | 52d9886 | 2013-03-28 18:38:43 +0000 | [diff] [blame] | 411 | Entities.add(M->first->getName().str(), Entry::EK_Macro, Loc); |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 412 | } |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 413 | |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 414 | // Merge header contents. |
| 415 | Entities.mergeCurHeaderContents(); |
| 416 | } |
John Thompson | 161381e | 2013-06-27 18:52:23 +0000 | [diff] [blame] | 417 | |
John Thompson | 1f67ccb | 2013-03-12 18:51:47 +0000 | [diff] [blame] | 418 | private: |
| 419 | EntityMap &Entities; |
John Thompson | 1e01014 | 2013-07-26 18:16:22 +0000 | [diff] [blame^] | 420 | PreprocessorTracker &PPTracker; |
John Thompson | 1f67ccb | 2013-03-12 18:51:47 +0000 | [diff] [blame] | 421 | Preprocessor &PP; |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 422 | }; |
| 423 | |
| 424 | class CollectEntitiesAction : public SyntaxOnlyAction { |
John Thompson | 1f67ccb | 2013-03-12 18:51:47 +0000 | [diff] [blame] | 425 | public: |
John Thompson | 1e01014 | 2013-07-26 18:16:22 +0000 | [diff] [blame^] | 426 | CollectEntitiesAction(EntityMap &Entities, |
| 427 | PreprocessorTracker &preprocessorTracker) |
| 428 | : Entities(Entities), PPTracker(preprocessorTracker) {} |
John Thompson | 161381e | 2013-06-27 18:52:23 +0000 | [diff] [blame] | 429 | |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 430 | protected: |
John Thompson | 161381e | 2013-06-27 18:52:23 +0000 | [diff] [blame] | 431 | virtual clang::ASTConsumer *CreateASTConsumer(CompilerInstance &CI, |
| 432 | StringRef InFile) { |
John Thompson | 1e01014 | 2013-07-26 18:16:22 +0000 | [diff] [blame^] | 433 | return new CollectEntitiesConsumer(Entities, PPTracker, |
| 434 | CI.getPreprocessor(), InFile); |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 435 | } |
John Thompson | 161381e | 2013-06-27 18:52:23 +0000 | [diff] [blame] | 436 | |
John Thompson | 1f67ccb | 2013-03-12 18:51:47 +0000 | [diff] [blame] | 437 | private: |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 438 | EntityMap &Entities; |
John Thompson | 1e01014 | 2013-07-26 18:16:22 +0000 | [diff] [blame^] | 439 | PreprocessorTracker &PPTracker; |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 440 | }; |
| 441 | |
| 442 | class ModularizeFrontendActionFactory : public FrontendActionFactory { |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 443 | public: |
John Thompson | 1e01014 | 2013-07-26 18:16:22 +0000 | [diff] [blame^] | 444 | ModularizeFrontendActionFactory(EntityMap &Entities, |
| 445 | PreprocessorTracker &preprocessorTracker) |
| 446 | : Entities(Entities), PPTracker(preprocessorTracker) {} |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 447 | |
| 448 | virtual CollectEntitiesAction *create() { |
John Thompson | 1e01014 | 2013-07-26 18:16:22 +0000 | [diff] [blame^] | 449 | return new CollectEntitiesAction(Entities, PPTracker); |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 450 | } |
John Thompson | 161381e | 2013-06-27 18:52:23 +0000 | [diff] [blame] | 451 | |
John Thompson | 1f67ccb | 2013-03-12 18:51:47 +0000 | [diff] [blame] | 452 | private: |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 453 | EntityMap &Entities; |
John Thompson | 1e01014 | 2013-07-26 18:16:22 +0000 | [diff] [blame^] | 454 | PreprocessorTracker &PPTracker; |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 455 | }; |
| 456 | |
| 457 | int main(int argc, const char **argv) { |
John Thompson | a2de108 | 2013-03-26 01:17:48 +0000 | [diff] [blame] | 458 | |
| 459 | // This causes options to be parsed. |
| 460 | cl::ParseCommandLineOptions(argc, argv, "modularize.\n"); |
| 461 | |
| 462 | // No go if we have no header list file. |
| 463 | if (ListFileName.size() == 0) { |
| 464 | cl::PrintHelpMessage(); |
John Thompson | ea6c8db | 2013-03-27 21:23:21 +0000 | [diff] [blame] | 465 | return 1; |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 466 | } |
John Thompson | a2de108 | 2013-03-26 01:17:48 +0000 | [diff] [blame] | 467 | |
John Thompson | ea6c8db | 2013-03-27 21:23:21 +0000 | [diff] [blame] | 468 | // Get header file names. |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 469 | SmallVector<std::string, 32> Headers; |
John Thompson | 54c8369 | 2013-06-18 19:56:05 +0000 | [diff] [blame] | 470 | if (error_code ec = getHeaderFileNames(Headers, ListFileName, HeaderPrefix)) { |
John Thompson | ea6c8db | 2013-03-27 21:23:21 +0000 | [diff] [blame] | 471 | errs() << argv[0] << ": error: Unable to get header list '" << ListFileName |
| 472 | << "': " << ec.message() << '\n'; |
| 473 | return 1; |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 474 | } |
John Thompson | a2de108 | 2013-03-26 01:17:48 +0000 | [diff] [blame] | 475 | |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 476 | // Create the compilation database. |
John Thompson | a2de108 | 2013-03-26 01:17:48 +0000 | [diff] [blame] | 477 | SmallString<256> PathBuf; |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 478 | sys::fs::current_path(PathBuf); |
| 479 | OwningPtr<CompilationDatabase> Compilations; |
| 480 | Compilations.reset( |
| 481 | new FixedCompilationDatabase(Twine(PathBuf), CC1Arguments)); |
John Thompson | a2de108 | 2013-03-26 01:17:48 +0000 | [diff] [blame] | 482 | |
John Thompson | 1e01014 | 2013-07-26 18:16:22 +0000 | [diff] [blame^] | 483 | // Create preprocessor tracker, to watch for macro and conditional problems. |
| 484 | OwningPtr<PreprocessorTracker> PPTracker(PreprocessorTracker::create()); |
| 485 | |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 486 | // Parse all of the headers, detecting duplicates. |
| 487 | EntityMap Entities; |
| 488 | ClangTool Tool(*Compilations, Headers); |
John Thompson | 1e01014 | 2013-07-26 18:16:22 +0000 | [diff] [blame^] | 489 | int HadErrors = |
| 490 | Tool.run(new ModularizeFrontendActionFactory(Entities, *PPTracker)); |
John Thompson | ce601e2 | 2013-03-14 01:41:29 +0000 | [diff] [blame] | 491 | |
John Thompson | 4e4d9b3 | 2013-03-28 01:20:19 +0000 | [diff] [blame] | 492 | // Create a place to save duplicate entity locations, separate bins per kind. |
| 493 | typedef SmallVector<Location, 8> LocationArray; |
John Thompson | 52d9886 | 2013-03-28 18:38:43 +0000 | [diff] [blame] | 494 | typedef SmallVector<LocationArray, Entry::EK_NumberOfKinds> EntryBinArray; |
John Thompson | 4e4d9b3 | 2013-03-28 01:20:19 +0000 | [diff] [blame] | 495 | EntryBinArray EntryBins; |
Michael Gottesman | 4b24921 | 2013-03-28 06:07:15 +0000 | [diff] [blame] | 496 | int kindIndex; |
John Thompson | 52d9886 | 2013-03-28 18:38:43 +0000 | [diff] [blame] | 497 | for (kindIndex = 0; kindIndex < Entry::EK_NumberOfKinds; ++kindIndex) { |
| 498 | LocationArray array; |
| 499 | EntryBins.push_back(array); |
Michael Gottesman | 4b24921 | 2013-03-28 06:07:15 +0000 | [diff] [blame] | 500 | } |
John Thompson | 4e4d9b3 | 2013-03-28 01:20:19 +0000 | [diff] [blame] | 501 | |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 502 | // Check for the same entity being defined in multiple places. |
| 503 | for (EntityMap::iterator E = Entities.begin(), EEnd = Entities.end(); |
| 504 | E != EEnd; ++E) { |
John Thompson | 4e4d9b3 | 2013-03-28 01:20:19 +0000 | [diff] [blame] | 505 | // If only one occurance, exit early. |
| 506 | if (E->second.size() == 1) |
| 507 | continue; |
| 508 | // Clear entity locations. |
| 509 | for (EntryBinArray::iterator CI = EntryBins.begin(), CE = EntryBins.end(); |
| 510 | CI != CE; ++CI) { |
John Thompson | 52d9886 | 2013-03-28 18:38:43 +0000 | [diff] [blame] | 511 | CI->clear(); |
John Thompson | 4e4d9b3 | 2013-03-28 01:20:19 +0000 | [diff] [blame] | 512 | } |
| 513 | // Walk the entities of a single name, collecting the locations, |
| 514 | // separated into separate bins. |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 515 | for (unsigned I = 0, N = E->second.size(); I != N; ++I) { |
John Thompson | 52d9886 | 2013-03-28 18:38:43 +0000 | [diff] [blame] | 516 | EntryBins[E->second[I].Kind].push_back(E->second[I].Loc); |
John Thompson | 4e4d9b3 | 2013-03-28 01:20:19 +0000 | [diff] [blame] | 517 | } |
| 518 | // Report any duplicate entity definition errors. |
| 519 | int kindIndex = 0; |
| 520 | for (EntryBinArray::iterator DI = EntryBins.begin(), DE = EntryBins.end(); |
| 521 | DI != DE; ++DI, ++kindIndex) { |
John Thompson | 52d9886 | 2013-03-28 18:38:43 +0000 | [diff] [blame] | 522 | int eCount = DI->size(); |
John Thompson | 4e4d9b3 | 2013-03-28 01:20:19 +0000 | [diff] [blame] | 523 | // If only 1 occurance, skip; |
| 524 | if (eCount <= 1) |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 525 | continue; |
John Thompson | 52d9886 | 2013-03-28 18:38:43 +0000 | [diff] [blame] | 526 | LocationArray::iterator FI = DI->begin(); |
John Thompson | b809dfc | 2013-07-19 14:19:31 +0000 | [diff] [blame] | 527 | StringRef kindName = Entry::getKindName((Entry::EntryKind)kindIndex); |
John Thompson | 4e4d9b3 | 2013-03-28 01:20:19 +0000 | [diff] [blame] | 528 | errs() << "error: " << kindName << " '" << E->first() |
| 529 | << "' defined at multiple locations:\n"; |
John Thompson | 52d9886 | 2013-03-28 18:38:43 +0000 | [diff] [blame] | 530 | for (LocationArray::iterator FE = DI->end(); FI != FE; ++FI) { |
John Thompson | 4e4d9b3 | 2013-03-28 01:20:19 +0000 | [diff] [blame] | 531 | errs() << " " << FI->File->getName() << ":" << FI->Line << ":" |
| 532 | << FI->Column << "\n"; |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 533 | } |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 534 | HadErrors = 1; |
| 535 | } |
| 536 | } |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 537 | |
John Thompson | 1e01014 | 2013-07-26 18:16:22 +0000 | [diff] [blame^] | 538 | // Complain about macro instance in header files that differ based on how |
| 539 | // they are included. |
| 540 | if (PPTracker->reportInconsistentMacros(errs())) |
| 541 | HadErrors = 1; |
| 542 | |
| 543 | // Complain about preprocessor conditional directives in header files that |
| 544 | // differ based on how they are included. |
| 545 | if (PPTracker->reportInconsistentConditionals(errs())) |
| 546 | HadErrors = 1; |
| 547 | |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 548 | // Complain about any headers that have contents that differ based on how |
| 549 | // they are included. |
John Thompson | ce601e2 | 2013-03-14 01:41:29 +0000 | [diff] [blame] | 550 | // FIXME: Could we provide information about which preprocessor conditionals |
| 551 | // are involved? |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 552 | for (DenseMap<const FileEntry *, HeaderContents>::iterator |
| 553 | H = Entities.HeaderContentMismatches.begin(), |
| 554 | HEnd = Entities.HeaderContentMismatches.end(); |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 555 | H != HEnd; ++H) { |
| 556 | if (H->second.empty()) { |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 557 | errs() << "internal error: phantom header content mismatch\n"; |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 558 | continue; |
| 559 | } |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 560 | |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 561 | HadErrors = 1; |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 562 | errs() << "error: header '" << H->first->getName() |
John Thompson | 1e01014 | 2013-07-26 18:16:22 +0000 | [diff] [blame^] | 563 | << "' has different contents depending on how it was included.\n"; |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 564 | for (unsigned I = 0, N = H->second.size(); I != N; ++I) { |
John Thompson | 161381e | 2013-06-27 18:52:23 +0000 | [diff] [blame] | 565 | errs() << "note: '" << H->second[I].Name << "' in " |
| 566 | << H->second[I].Loc.File->getName() << " at " |
| 567 | << H->second[I].Loc.Line << ":" << H->second[I].Loc.Column |
| 568 | << " not always provided\n"; |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 569 | } |
| 570 | } |
John Thompson | f5db45b | 2013-03-27 01:02:46 +0000 | [diff] [blame] | 571 | |
John Thompson | 4f8ba65 | 2013-03-12 02:07:30 +0000 | [diff] [blame] | 572 | return HadErrors; |
| 573 | } |