aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Frontend/HeaderIncludeGen.cpp
AgeCommit message (Collapse)AuthorFilesLines
2022-12-14Return early if FileID is invalid. NFCAkira Hatanaka1-1/+2
2022-12-07Add support for a backdoor driver option that enables emitting headerAkira Hatanaka1-10/+126
usage information in JSON to a file Each line in the file is a JSON object that has the name of the main source file followed by the list of system header files included directly or indirectly from that file. For example: {"source":"/tmp/foo.c", "includes":["/usr/include/stdio.h", "/usr/include/stdlib.h"]} To reduce the amount of data written to the file, only the system headers that are directly included from a non-system header file are recorded. In order to emit the header information in JSON, it is necessary to set the following environment variables: CC_PRINT_HEADERS_FORMAT=json CC_PRINT_HEADERS_FILTERING=only-direct-system The following combination is equivalent to setting CC_PRINT_HEADERS=1: CC_PRINT_HEADERS_FORMAT=textual CC_PRINT_HEADERS_FILTERING=none Differential Revision: https://reviews.llvm.org/D137996
2021-11-12[clang] Inclusive language: change instances of blacklist/whitelist to ↵Zarko Todorovski1-1/+1
allowlist/ignorelist Change the error message to use ignorelist, and changed some variable and function names in related code and test. Reviewed By: thakis Differential Revision: https://reviews.llvm.org/D113189
2021-04-14Add flag for showing skipped headers in -H / --show-includes outputHans Wennborg1-0/+16
Consider the following set of files: a.cc: #include "a.h" a.h: #ifndef A_H #define A_H #include "b.h" #include "c.h" // This gets "skipped". #endif b.h: #ifndef B_H #define B_H #include "c.h" #endif c.h: #ifndef C_H #define C_H void c(); #endif And the output of the -H option: $ clang -c -H a.cc . ./a.h .. ./b.h ... ./c.h Note that the include of c.h in a.h is not shown in the output (GCC does the same). This is because of the include guard optimization: clang knows c.h is covered by an include guard which is already defined, so when it sees the include in a.h, it skips it. The same would have happened if #pragma once were used instead of include guards. However, a.h *does* include c.h, and it may be useful to show that in the -H output. This patch adds a flag for doing that. Differential revision: https://reviews.llvm.org/D100480
2021-04-06[SystemZ][z/OS][Windows] Add new OF_TextWithCRLF flag and use this flag ↵Abhina Sreeskantharajan1-1/+1
instead of OF_Text Problem: On SystemZ we need to open text files in text mode. On Windows, files opened in text mode adds a CRLF '\r\n' which may not be desirable. Solution: This patch adds two new flags - OF_CRLF which indicates that CRLF translation is used. - OF_TextWithCRLF = OF_Text | OF_CRLF indicates that the file is text and uses CRLF translation. Developers should now use either the OF_Text or OF_TextWithCRLF for text files and OF_None for binary files. If the developer doesn't want carriage returns on Windows, they should use OF_Text, if they do want carriage returns on Windows, they should use OF_TextWithCRLF. So this is the behaviour per platform with my patch: z/OS: OF_None: open in binary mode OF_Text : open in text mode OF_TextWithCRLF: open in text mode Windows: OF_None: open file with no carriage return OF_Text: open file with no carriage return OF_TextWithCRLF: open file with carriage return The Major change is in llvm/lib/Support/Windows/Path.inc to only set text mode if the OF_CRLF is set. ``` if (Flags & OF_CRLF) CrtOpenFlags |= _O_TEXT; ``` These following files are the ones that still use OF_Text which I left unchanged. I modified all these except raw_ostream.cpp in recent patches so I know these were previously in Binary mode on Windows. ./llvm/lib/Support/raw_ostream.cpp ./llvm/lib/TableGen/Main.cpp ./llvm/tools/dsymutil/DwarfLinkerForBinary.cpp ./llvm/unittests/Support/Path.cpp ./clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp ./clang/lib/Frontend/CompilerInstance.cpp ./clang/lib/Driver/Driver.cpp ./clang/lib/Driver/ToolChains/Clang.cpp Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D99426
2021-02-10[clang][cli] Generate and round-trip DependencyOutput optionsJan Svoboda1-1/+1
This patch implements generation of remaining dependency output options and tests it by performing parse-generate-parse round trip. Reviewed By: dexonsmith Differential Revision: https://reviews.llvm.org/D96273
2020-02-25clang-cl: Add a `/showIncludes:user` flag.Nico Weber1-2/+5
This flag is like /showIncludes, but it only includes user headers and omits system headers (similar to MD and MMD). The motivation is that projects that already track system includes though other means can use this flag to get consistent behavior on Windows and non-Windows, and it saves tools that output /showIncludes output (e.g. ninja) some work. implementation-wise, this makes `HeaderIncludesCallback` honor the existing `IncludeSystemHeaders` bit, and changes the three clients of `HeaderIncludesCallback` (`/showIncludes`, `-H`, `CC_PRINT_HEADERS=1`) to pass `-sys-header-deps` to set that bit -- except for `/showIncludes:user`, which doesn't pass it. Differential Revision: https://reviews.llvm.org/D75093
2019-08-14[Clang] Migrate llvm::make_unique to std::make_uniqueJonas Devlieghere1-1/+1
Now that we've moved to C++14, we no longer need the llvm::make_unique implementation from STLExtras.h. This patch is a mechanical replacement of (hopefully) all the llvm::make_unique instances across the monorepo. Differential revision: https://reviews.llvm.org/D66259 llvm-svn: 368942
2019-08-05Rename F_{None,Text,Append} to OF_{None,Text,Append}. NFCFangrui Song1-1/+2
F_{None,Text,Append} are kept for compatibility since r334221. llvm-svn: 367800
2019-03-01Fix file headers. NFCFangrui Song1-1/+1
llvm-svn: 355176
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth1-4/+3
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2018-05-04[clang-cl] Print /showIncludes to stderr, if used in combination with /E, ↵Erich Keane1-1/+15
/EP or /P This replicates 'cl.exe' behavior and allows for both preprocessor output and dependency information to be extraced with a single compiler invocation. This is especially useful for compiler caching with tools like Mozilla's sccache. See: https://github.com/mozilla/sccache/issues/246 Patch By: fxb Differential Revision: https://reviews.llvm.org/D46394 llvm-svn: 331533
2016-05-27[Frontend] StringRefize and fix bad indentation.Benjamin Kramer1-22/+22
NFC intended. llvm-svn: 270991
2016-03-23clang-cl: Fix remaining bugs in interaction of /Yc and /FI /showIncludes.Nico Weber1-26/+27
Instead of putting the /Yc header into ExtraDeps, give DependencyOutputOptions a dedicated field for /Yc mode, and let HeaderIncludesCallback hang on to the full DependencyOutputOptions object, not just ExtraDeps. Reverts parts of r263352 that are now no longer needed. llvm-svn: 264182
2016-03-23clang-cl: Include /FI headers in /showIncludes output.Nico Weber1-4/+11
-H in gcc mode doesn't print -include headers, but they are included in depfiles written by MMD and friends. Since /showIncludes is what's used instead of depfiles, printing /FI there seems important (and matches cl.exe). Instead of giving HeaderIncludeGen more options, just switch on ShowAllHeaders in clang-cl mode and let clang::InitializePreprocessor() not put -include flags in the <command line> block. This changes the behavior of -E slightly, and it removes the <command line> flag from the output triggered by setting the obscure CC_PRINT_HEADERS=1 env var to true while running clang. Both of these seem ok to change. http://reviews.llvm.org/D18401 llvm-svn: 264174
2016-03-13clang-cl: Add /Yc argument to /showIncludes output.Nico Weber1-20/+24
To make this work, delay printing of ExtraDeps in HeaderIncludesCallback a bit, so that it happens after CompilerInstance::InitializeSourceManager() has run. General /FI arguments are still missing from /showIncludes output, this still needs to be fixed. llvm-svn: 263352
2015-12-16Update for llvm API change.Rafael Espindola1-1/+0
llvm-svn: 255838
2015-08-13Add sanitizer blacklists to the rules generated with -M/-MM/-MD/-MMD.Ivan Krasin1-23/+40
Summary: Clang sanitizers, such as AddressSanitizer, ThreadSanitizer, MemorySanitizer, Control Flow Integrity and others, use blacklists to specify which types / functions should not be instrumented to avoid false positives or suppress known failures. This change adds the blacklist filenames to the list of dependencies of the rules, generated with -M/-MM/-MD/-MMD. This lets CMake/Ninja recognize that certain C/C++/ObjC files need to be recompiled (if a blacklist is updated). Reviewers: pcc Subscribers: rsmith, honggyu.kim, pcc, cfe-commits Differential Revision: http://reviews.llvm.org/D11968 llvm-svn: 244867
2015-06-22Revert r240270 ("Fixed/added namespace ending comments using clang-tidy").Alexander Kornienko1-1/+1
llvm-svn: 240353
2015-06-22Fixed/added namespace ending comments using clang-tidy. NFCAlexander Kornienko1-1/+1
The patch is generated using this command: $ tools/extra/clang-tidy/tool/run-clang-tidy.py -fix \ -checks=-*,llvm-namespace-comment -header-filter='llvm/.*|clang/.*' \ work/llvm/tools/clang To reduce churn, not touching namespaces spanning less than 10 lines. llvm-svn: 240270
2015-04-11Use 'override/final' instead of 'virtual' for overridden methodsAlexander Kornienko1-1/+1
Summary: The patch is generated using clang-tidy misc-use-override check. This command was used: tools/clang/tools/extra/clang-tidy/tool/run-clang-tidy.py \ -checks='-*,misc-use-override' -header-filter='llvm|clang' -j=32 -fix Reviewers: dblaikie Reviewed By: dblaikie Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D8926 llvm-svn: 234678
2014-09-10Unique_ptrify PPCallbacks ownership.Craig Topper1-3/+6
Unique_ptr creation stil needs to be moved earlier at some of the call sites. llvm-svn: 217474
2014-08-25Update for llvm api change.Rafael Espindola1-6/+5
llvm-svn: 216397
2014-07-17clang-cl: Flush stdout after writing the /showIncludes outputEhsan Akhgari1-0/+1
Summary: Before this patch, you could get lines in the output such as: Note: including file: ../../dist/include/js/Tc:/path/to/foo.cpp(1,1) : error(clang): static_assert failed... This patch ensures that the stdout output from showIncludes won't be garbled in the terminal like this, and it also helps applications that use the output to generate dependency information if they happen to capture both stdout and stderr. Test Plan: Tested locally, it's hard to write an automated test for this as the behavior depends on the buffering of the ostreams. Reviewers: nico Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D4559 llvm-svn: 213297
2014-07-06clang-cl: /showIncludes output should go to stdout, not stderr. Fixes PR20217.Nico Weber1-1/+1
llvm-svn: 212383
2014-03-13[C++11] Add 'override' keyword to virtual methods that override their base ↵Craig Topper1-3/+3
class. llvm-svn: 203758
2014-02-24Update for llvm api change.Rafael Espindola1-1/+2
llvm-svn: 202053
2013-08-09clang-cl: Support /showIncludesHans Wennborg1-7/+15
This option prints information about #included files to stderr. Clang could already do it, this patch just teaches the existing code about the /showIncludes style and adds the flag. Differential Revision: http://llvm-reviews.chandlerc.com/D1333 llvm-svn: 188037
2013-07-16Update for llvm API change.Rafael Espindola1-1/+1
llvm-svn: 186448
2012-02-05Basic: import SmallString<> into clang namespaceDylan Noblesmith1-2/+2
(I was going to fix the TODO about DenseMap too, but that would break self-host right now. See PR11922.) llvm-svn: 149799
2012-02-04Move a method from IdentifierTable.h out of line and remove the SmallString ↵Benjamin Kramer1-0/+1
include. Fix all the transitive include users. llvm-svn: 149783
2011-10-11For the FileChanged Preprocessor callback, when exiting a file, pass its FileID.Argyrios Kyrtzidis1-2/+4
llvm-svn: 141681
2011-07-23remove unneeded llvm:: namespace qualifiers on some core types now that ↵Chris Lattner1-4/+4
LLVM.h imports them into the clang namespace. llvm-svn: 135852
2011-04-14Fix -H. It was pretty broken.Sebastian Redl1-5/+9
llvm-svn: 129514
2011-03-21Frontend: Change CC_PRINT_HEADERS to not print header depth markers, these don'tDaniel Dunbar1-7/+13
really make any sense in this environment. llvm-svn: 128014
2011-02-03Frontend: Switch -header-include-file output to use unbuffered raw_ostreams withDaniel Dunbar1-14/+22
the atomic writes option, since the intent is that this option be set for an entire build, which may have any number of compiler instances writing to the same output file. llvm-svn: 124772
2011-02-02Frontend: Add -header-include-file option, for allowing saving header includeDaniel Dunbar1-7/+30
information to a file. llvm-svn: 124750
2011-02-02Frontend: Add support (unused) for showing all "interesting" headers, not justDaniel Dunbar1-21/+16
ones outside the predefines buffer (which is what -H does). llvm-svn: 124749
2011-02-02Frontend: Factor out header include dumping (-H) into its own preprocessorDaniel Dunbar1-0/+87
callbacks class. - Aside from being generally cleaner, this also allows -H to work correctly in modes other than standard preprocessing (e.g., -c, -MM, etc.) llvm-svn: 124723