summaryrefslogtreecommitdiffstats
path: root/clang/lib/Lex/MacroInfo.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-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
* [Lex] Make MacroDirective::findDirectiveAtLoc take const SourceManagerKristof Umann2018-10-311-1/+2
| | | | | | | | | I'm currently working on including macro expansions in the Static Analyzer's plist output, where I can only access a const SourceManager. Differential Revision: https://reviews.llvm.org/D53940 llvm-svn: 345741
* Remove \brief commands from doxygen comments.Adrian Prantl2018-05-091-1/+1
| | | | | | | | | | | | | | | | | | | This is similar to the LLVM change https://reviews.llvm.org/D46290. We've been running doxygen with the autobrief option for a couple of years now. This makes the \brief markers into our comments redundant. Since they are a visual distraction and we don't want to encourage more \brief markers in new code either, this patch removes them all. Patch produced by for i in $(git grep -l '\@brief'); do perl -pi -e 's/\@brief //g' $i & done for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done Differential Revision: https://reviews.llvm.org/D46320 llvm-svn: 331834
* [Lex] Fix some Clang-tidy modernize and Include What You Use warnings; other ↵Eugene Zelenko2017-12-041-16/+20
| | | | | | minor fixes (NFC). llvm-svn: 319714
* [NFC] Refactor the Preprocessor function that handles Macro definitions and ↵Faisal Vali2017-07-171-9/+10
| | | | | | | | | | | | | | | | | rename Arguments to Parameters in Macro Definitions. - Extracted the reading of the tokens out into a separate function. - Replace 'Argument' with 'Parameter' when referring to the identifiers of the macro definition (as opposed to the supplied arguments - MacroArgs - during the macro invocation). This is in preparation for submitting patches for review to implement __VA_OPT__ which will otherwise just keep lengthening the HandleDefineDirective function and making it less comprehensible. I will also directly update some extra clang tooling that is broken by the change from Argument to Parameter. Hopefully the bots will stay appeased. Thanks! llvm-svn: 308190
* Revert changes from my previous refactoring - will need to fix dependencies ↵Faisal Vali2017-07-171-10/+9
| | | | | | | | in clang's extra tooling (such as clang-tidy etc.). Sorry about that. llvm-svn: 308158
* [NFC] Refactor the Preprocessor function that handles Macro definitions and ↵Faisal Vali2017-07-171-9/+10
| | | | | | | | | | | | | | rename Arguments to Parameters in Macro Definitions. - Extracted the reading of the tokens out into a separate function. - Replace 'Argument' with 'Parameter' when referring to the identifiers of the macro definition (as opposed to the supplied arguments - MacroArgs - during the macro invocation). This is in preparation for submitting patches for review to implement __VA_OPT__ which will otherwise just keep lengthening the HandleDefineDirective function and making it less comprehensible. Thanks! llvm-svn: 308157
* Remove unused tracking of owning module for MacroInfo objects.Richard Smith2017-05-121-2/+0
| | | | llvm-svn: 302966
* Constify SourceManager input to MacroInfo::getDefinitionLengthSlow, NFC.Yaron Keren2017-04-271-1/+1
| | | | llvm-svn: 301526
* Retire llvm::alignOf in favor of C++11 alignof.Benjamin Kramer2016-10-201-1/+1
| | | | | | No functionality change intended. llvm-svn: 284730
* Annotate dump() methods with LLVM_DUMP_METHOD, addressing Richard Smith ↵Yaron Keren2016-01-291-2/+2
| | | | | | r259192 post commit comment. llvm-svn: 259232
* Improve macro dumping to preserve semantically-relevant spelling information.Richard Smith2015-11-051-5/+9
| | | | llvm-svn: 252206
* [modules] Add a mechanism to dump information about a macro.Richard Smith2015-04-301-4/+2
| | | | | | Wire this up to "#pragma clang __debug macro <name>". llvm-svn: 236280
* Remove dead code: a MacroDirective can't be imported or ambiguous any more.Richard Smith2015-04-301-21/+0
| | | | llvm-svn: 236197
* [modules] Store a ModuleMacro* on an imported macro directive rather than ↵Richard Smith2015-04-231-0/+19
| | | | | | duplicating the info within it. llvm-svn: 235644
* [modules] Determine the set of macros exported by a submodule at the end of ↵Richard Smith2015-04-231-2/+2
| | | | | | | | | | | that submodule. Previously we'd defer this determination until writing the AST, which doesn't allow us to use this information when building other submodules of the same module. This change also allows us to use a uniform mechanism for writing module macro records, independent of whether they are local or imported. llvm-svn: 235614
* [modules] Actually allocate the extra space we use for the tail-allocated arrayRichard Smith2015-04-231-3/+5
| | | | | | in this class. llvm-svn: 235570
* [modules] Build a DAG of module macros for each identifier.Richard Smith2015-04-221-0/+7
| | | | | | | | This graph will be used to determine the current set of active macros. This is foundation work for getting macro visibility correct across submodules of the current module. No functionality change for now. llvm-svn: 235461
* Reinstate r213348, reverted in r213395, with an additional bug fix and moreRichard Smith2014-07-181-0/+1
| | | | | | | | | | | | | | | | | | | | thorough tests. Original commit message: [modules] Fix macro hiding bug exposed if: * A submodule of module A is imported into module B * Another submodule of module A that is not imported into B exports a macro * Some submodule of module B also exports a definition of the macro, and happens to be the first submodule of B that imports module A. In this case, we would incorrectly determine that A's macro redefines B's macro, and so we don't need to re-export B's macro at all. This happens with the 'assert' macro in an LLVM self-host. =( llvm-svn: 213416
* Add dump() for MacroDirective and MacroInfo.Richard Smith2014-07-181-0/+72
| | | | llvm-svn: 213349
* [C++11] Use 'nullptr'. Lex edition.Craig Topper2014-05-171-2/+3
| | | | llvm-svn: 209083
* [Preprocessor/CodeComplete] Don't add include guard macros to ↵Argyrios Kyrtzidis2014-04-091-1/+2
| | | | | | code-completion results. llvm-svn: 205917
* If a module A exports a macro M, and a module B imports that macro and #undef'sRichard Smith2014-03-011-1/+1
| | | | | | | | | | | | | | it, importers of B should not see the macro. This is complicated by the fact that A's macro could also be visible through a different path. The rules (as hashed out on cfe-commits) are included as a documentation update in this change. With this, the number of regressions in libc++'s testsuite when modules are enabled drops from 47 to 7. Those remaining 7 are also macro-related, and are due to remaining bugs in this change (in particular, the handling of submodules is imperfect). llvm-svn: 202560
* Remove dead code; MacroDirective's IsHidden flag is always false.Richard Smith2014-01-271-4/+1
| | | | llvm-svn: 200265
* [preprocessor] Minor optimization following r178671.Argyrios Kyrtzidis2013-04-031-2/+3
| | | | | | Don't bother looking for parameter index of 'B' token if 'A' is not a parameter. llvm-svn: 178699
* [preprocessor] Allow comparing two macro definitions syntactically instead ↵Argyrios Kyrtzidis2013-04-031-10/+26
| | | | | | | | | | | | | | of only lexically. Syntactically means the function macro parameter names do not need to use the same identifiers in order for the definitions to be considered identical. Syntactic equivalence is a microsoft extension for macro redefinitions and we'll also use this kind of comparison to check for ambiguous macros coming from modules. rdar://13562254 llvm-svn: 178671
* [Preprocessor/Modules] Separate the macro directives kinds into their own ↵Argyrios Kyrtzidis2013-03-261-7/+33
| | | | | | | | | | | | | | | | MacroDirective's subclasses. For each macro directive (define, undefine, visibility) have a separate object that gets chained to the macro directive history. This has several benefits: -No need to mutate a MacroDirective when there is a undefine/visibility directive. Stuff like PPMutationListener become unnecessary. -No need to keep extra source locations for the undef/visibility locations for the define directive object (which is the majority of the directives) -Much easier to hide/unhide a section in the macro directive history. -Easier to track the effects of the directives across different submodules. llvm-svn: 178037
* [modules] When a MacroInfo object is deserialized, allocate and store its ↵Argyrios Kyrtzidis2013-03-221-1/+2
| | | | | | submodule ID. llvm-svn: 177760
* Documentation cleanup for MacroInfo.James Dennett2013-03-201-4/+4
| | | | | | | | | | | | | | * Clarify what MacroInfo::isBuiltinMacro means, as it really means something more like "isMagicalMacro" or "requiresProcessingBeforeExpansion" -- the macros defined in "<built-in>" are not considered built-in by this function; * Escape __LINE__ as \__LINE__ in Doxygen comments so that the underscores don't get replaced by *bold* output; * Turn comments in MacroInfo.cpp into non-Doxygen comments, so that they don't result in duplicated/badly formatted Doxygen output; * Clean up a bunch of \brief formatting, and add a \file comment for MacroInfo.h. llvm-svn: 177581
* [preprocessor] Split the MacroInfo class into two separate concepts, ↵Argyrios Kyrtzidis2013-02-201-46/+13
| | | | | | | | | | | | | | | | | | | | | | | | | MacroInfo class for the data specific to a macro definition (e.g. what the tokens are), and MacroDirective class which encapsulates the changes to the "macro namespace" (e.g. the location where the macro name became active, the location where it was undefined, etc.) (A MacroDirective always points to a MacroInfo object.) Usually a macro definition (MacroInfo) is where a macro name becomes active (MacroDirective) but splitting the concepts allows us to better model the effect of modules to the macro namespace (also as a bonus it allows better modeling of push_macro/pop_macro #pragmas). Modules can have their own macro history, separate from the local (current translation unit) macro history; MacroDirectives will be used to model the macro history (changes to macro namespace). For example, if "@import A;" imports macro FOO, there will be a new local MacroDirective created to indicate that "FOO" became active at the import location. Module "A" itself will contain another MacroDirective in its macro history (at the point of the definition of FOO) and both MacroDirectives will point to the same MacroInfo object. Introducing the separation of macro concepts is the first part towards better modeling of module macros. llvm-svn: 175585
* Suppress elided variadic macro argument extension diagnostic for macros usingEli Friedman2012-11-141-0/+2
| | | | | | | | | | | | | | | | | | | | | | the related comma pasting extension. In certain cases, we used to get two diagnostics for what is essentially one extension. This change suppresses the first diagnostic in certain cases where we know we're going to print the second diagnostic. The diagnostic is redundant, and it can't be suppressed in the definition of the macro because it points at the use of the macro, so we want to avoid printing it if possible. The implementation works by detecting constructs which look like comma pasting at the time of the definition of the macro; this information is then used when the macro is used. (We can't actually detect whether we're using the comma pasting extension until the macro is actually used, but we can detecting constructs which will be comma pasting if the varargs argument is elided.) <rdar://problem/12292192> llvm-svn: 167907
* Diagnose the expansion of ambiguous macro definitions. This can happenDouglas Gregor2012-10-111-2/+4
| | | | | | | only with modules, when two disjoint modules #define the same identifier to different token sequences. llvm-svn: 165746
* Deserialize macro history when we deserialize an identifier that hasDouglas Gregor2012-10-111-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | macro history. When deserializing macro history, we arrange history such that the macros that have definitions (that haven't been #undef'd) and are visible come at the beginning of the list, which is what the preprocessor and other clients of Preprocessor::getMacroInfo() expect. If additional macro definitions become visible later, they'll be moved toward the front of the list. Note that it's possible to have ambiguities, but we don't diagnose them yet. There is a partially-implemented design decision here that, if a particular identifier has been defined or #undef'd within the translation unit, that definition (or #undef) hides any macro definitions that come from imported modules. There's still a little work to do to ensure that the right #undef'ing happens. Additionally, we'll need to scope the update records for #undefs, so they only kick in when the submodule containing that update record becomes visible. llvm-svn: 165682
* Compatibility macro detection for the -Wimplicit-fallthrough diagnostic.Alexander Kornienko2012-09-281-0/+12
| | | | | | | | | | | | | | | | | | | Summary: When issuing a diagnostic message for the -Wimplicit-fallthrough diagnostics, always try to find the latest macro, defined at the point of fallthrough, which is immediately expanded to "[[clang::fallthrough]]", and use it's name instead of the actual sequence. Known issues: * uses PP.getSpelling() to compare macro definition with a string (anyone can suggest a convenient way to fill a token array, or maybe lex it in runtime?); * this can be generalized and used in other similar cases, any ideas where it should reside then? Reviewers: doug.gregor, rsmith Reviewed By: rsmith CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D50 llvm-svn: 164858
* Keep history of macro definitions and #undefsAlexander Kornienko2012-08-291-36/+38
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Summary: Keep history of macro definitions and #undefs with corresponding source locations, so that we can later find out all macros active in a specified source location. We don't save the history in PCH (no need currently). Memory overhead is about sizeof(void*)*3*<number of macro definitions and #undefs>+<in-memory size of all #undef'd macros> I've run a test on a file composed of 109 .h files from boost 1.49 on x86-64 linux. Stats before this patch: *** Preprocessor Stats: 73222 directives found: 19171 #define. 4345 #undef. #include/#include_next/#import: 5233 source files entered. 27 max include stack depth 19210 #if/#ifndef/#ifdef. 2384 #else/#elif. 6891 #endif. 408 #pragma. 14466 #if/#ifndef#ifdef regions skipped 80023/451669/1270 obj/fn/builtin macros expanded, 85724 on the fast path. 127145 token paste (##) operations performed, 11008 on the fast path. Preprocessor Memory: 5874615B total BumpPtr: 4399104 Macro Expanded Tokens: 417768 Predefines Buffer: 8135 Macros: 1048576 #pragma push_macro Info: 0 Poison Reasons: 1024 Comment Handlers: 8 Stats with this patch: ... Preprocessor Memory: 7541687B total BumpPtr: 6066176 Macro Expanded Tokens: 417768 Predefines Buffer: 8135 Macros: 1048576 #pragma push_macro Info: 0 Poison Reasons: 1024 Comment Handlers: 8 In my test increase in memory usage is about 1.7Mb, which is ~28% of initial preprocessor's memory usage and about 0.8% of clang's total VMM allocation. As for CPU overhead, it should only be noticeable when iterating over all macros, and should mostly consist of couple extra dereferences and one comparison per macro + skipping of #undef'd macros. It's less trivial to measure, though, as the preprocessor consumes a very small fraction of compilation time. Reviewers: doug.gregor, klimek, rsmith, djasper Reviewed By: doug.gregor CC: cfe-commits, chandlerc Differential Revision: http://llvm-reviews.chandlerc.com/D28 llvm-svn: 162810
* For modules, all macros that aren't include guards are implicitlyDouglas Gregor2011-10-171-1/+4
| | | | | | | public. Add a __private_macro__ directive to hide a macro, similar to the __module_private__ declaration specifier. llvm-svn: 142188
* Modules hide macro definitions by default, so that silly things likeDouglas Gregor2011-09-011-0/+2
| | | | | | | | | | | include guards don't show up as macro definitions in every translation unit that imports a module. Macro definitions can, however, be exported with the intentionally-ugly #__export_macro__ directive. Implement this feature by not even bothering to serialize non-exported macros to a module, because clients of that module need not (should not) know that these macros even exist. llvm-svn: 138943
* Rename getDecomposedInstantiationLoc to getDecomposedExpansionLoc.Chandler Carruth2011-07-251-2/+2
| | | | llvm-svn: 135962
* Make the Preprocessor more memory efficient and improve macro instantiation ↵Argyrios Kyrtzidis2011-07-071-0/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | diagnostics. When a macro instantiation occurs, reserve a SLocEntry chunk with length the full length of the macro definition source. Set the spelling location of this chunk to point to the start of the macro definition and any tokens that are lexed directly from the macro definition will get a location from this chunk with the appropriate offset. For any tokens that come from argument expansion, '##' paste operator, etc. have their instantiation location point at the appropriate place in the instantiated macro definition (the argument identifier and the '##' token respectively). This improves macro instantiation diagnostics: Before: t.c:5:9: error: invalid operands to binary expression ('struct S' and 'int') int y = M(/); ^~~~ t.c:5:11: note: instantiated from: int y = M(/); ^ After: t.c:5:9: error: invalid operands to binary expression ('struct S' and 'int') int y = M(/); ^~~~ t.c:3:20: note: instantiated from: \#define M(op) (foo op 3); ~~~ ^ ~ t.c:5:11: note: instantiated from: int y = M(/); ^ The memory savings for a candidate boost library that abuses the preprocessor are: - 32% less SLocEntries (37M -> 25M) - 30% reduction in PCH file size (900M -> 635M) - 50% reduction in memory usage for the SLocEntry table (1.6G -> 800M) llvm-svn: 134587
* Copy IsWarnIfUnused too when making a copy of a MacroInfo.Benjamin Kramer2011-06-031-0/+1
| | | | | | Found by valgrind. llvm-svn: 132540
* Fix diagnostic pragmas.Argyrios Kyrtzidis2010-12-151-1/+2
| | | | | | | | | | | | Diagnostic pragmas are broken because we don't keep track of the diagnostic state changes and we only check the current/latest state. Problems manifest if a diagnostic is emitted for a source line that has different diagnostic state than the current state; this can affect a lot of places, like C++ inline methods, template instantiations, the lexer, etc. Fix the issue by having the Diagnostic object keep track of the source location of the pragmas so that it is able to know what is the diagnostic state at any given source location. Fixes rdar://8365684. llvm-svn: 121873
* More PCH -> AST renaming.Sebastian Redl2010-08-181-2/+2
| | | | llvm-svn: 111472
* Implement #pragma push_macro, patch by Francois Pichet!Chris Lattner2010-08-171-0/+18
| | | | llvm-svn: 111234
* Record macros in dependent PCHs. Also add various info tables to dependent ↵Sebastian Redl2010-07-271-0/+1
| | | | | | PCHs; tests for this to follow. llvm-svn: 109554
* Remove tabs, and whitespace cleanups.Mike Stump2009-09-091-6/+6
| | | | llvm-svn: 81346
* fix PR3764 - A redefinition of a pre-processor macro failsChris Lattner2009-03-091-3/+8
| | | | | | | Redefinition checking should ignore the leading whitespace and start of line flags on the first token of an expansion. llvm-svn: 66442
* Make a major restructuring of the clang tree: introduce a top-levelChris Lattner2008-03-151-0/+70
lib dir and move all the libraries into it. This follows the main llvm tree, and allows the libraries to be built in parallel. The top level now enforces that all the libs are built before Driver, but we don't care what order the libs are built in. This speeds up parallel builds, particularly incremental ones. llvm-svn: 48402
OpenPOWER on IntegriCloud