Commit Graph

1200 Commits

Author SHA1 Message Date
Argyrios Kyrtzidis 2edbc86809 Make the FilenameRange of the InclusionDirective callback more accurate,
preserve the macro location of the range end if the filename came from a macro.

Patch by Kim Gräsman!

llvm-svn: 167239
2012-11-01 17:52:58 +00:00
David Blaikie a0613170b4 Handle string encoding diagnostics when there are too many invalid ranges.
llvm-svn: 167059
2012-10-30 23:22:22 +00:00
Seth Cantrell 4cfc817a9a improve highlighting of invalid string encodings
limit highlight to exactly the bad encoding, and highlight every
bad encoding in a string.

llvm-svn: 166900
2012-10-28 18:24:46 +00:00
Argyrios Kyrtzidis d53d0daab9 Take into account that there may be a BOM at the beginning of the file,
when computing the size of the precompiled preamble.

llvm-svn: 166659
2012-10-25 01:51:45 +00:00
Douglas Gregor 1452ff155b Teach the preprocessor to hold onto the preprocessor options.
llvm-svn: 166599
2012-10-24 17:46:57 +00:00
Douglas Gregor b85b9ccb76 Move HeaderSearchOptions into the Lex library, make it intrusively
reference-counted, and hold a reference to it in HeaderSearch.

llvm-svn: 166583
2012-10-24 16:19:39 +00:00
Mahesha S 3009374fa4 Removed an extra blank line.
llvm-svn: 166571
2012-10-24 15:12:40 +00:00
Douglas Gregor 811db4eac4 Make DiagnosticOptions intrusively reference-counted, and make sure
the various stakeholders bump up the reference count. In particular,
the diagnostics engine now keeps the DiagnosticOptions object alive.

llvm-svn: 166508
2012-10-23 22:26:28 +00:00
Richard Trieu da031982b8 Fix for PR13334. This prevents crashes that result from badly formed
expressions involving __has_include

llvm-svn: 166438
2012-10-22 20:28:48 +00:00
Douglas Gregor bc10b9fbc5 Teach TargetInfo to hold on to the TargetOptions with which it was
created.

llvm-svn: 165943
2012-10-15 16:45:32 +00:00
Douglas Gregor 5952766628 Introduce the notion of excluded headers into the module map
description. Previously, one could emulate this behavior by placing
the header in an always-unavailable submodule, but Argyrios guilted me
into expressing this idea properly.

llvm-svn: 165921
2012-10-15 06:28:11 +00:00
Douglas Gregor 056396ae8c Sanitize the names of modules determined based on the names of headers
or directories, to make sure that they are identifiers that are not
keywords in any dialect. Fixes <rdar://problem/12489495>.

llvm-svn: 165821
2012-10-12 21:15:50 +00:00
Douglas Gregor cfa46a82b8 Track which particular submodule #undef's a macro, so that the actual
#undef only occurs if that submodule is imported.

llvm-svn: 165773
2012-10-12 00:16:50 +00:00
Douglas Gregor 5968b1b71f Diagnose the expansion of ambiguous macro definitions. This can happen
only with modules, when two disjoint modules #define the same
identifier to different token sequences.

llvm-svn: 165746
2012-10-11 21:07:39 +00:00
Douglas Gregor e740089d29 Introduce a simple "hint" scheme to eliminate the quadratic behavior
associated with deserializing macro history for an identifier.

llvm-svn: 165729
2012-10-11 17:41:54 +00:00
Douglas Gregor 0634737452 Remove an unused bit from the serialized IdentifierInfo
llvm-svn: 165683
2012-10-11 00:48:48 +00:00
Douglas Gregor 5a4649b034 Deserialize macro history when we deserialize an identifier that has
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
2012-10-11 00:46:49 +00:00
Douglas Gregor cb28f9d7ad Rework the (de-)serialization of macros, as stored in
MacroInfo*. Instead of simply dumping an offset into the current file,
give each macro definition a proper ID with all of the standard
modules-remapping facilities. Additionally, when a macro is modified
in a subsequent AST file (e.g., #undef'ing a macro loaded from another
module or from a precompiled header), provide a macro update record
rather than rewriting the entire macro definition. This gives us
greater consistency with the way we handle declarations, and ties
together macro definitions much more cleanly.

Note that we're still not actually deserializing macro history (we
never were), but it's far easy to do properly now.

llvm-svn: 165560
2012-10-09 23:05:51 +00:00
Argyrios Kyrtzidis c597c8c48b [Modules] Introduce Module::TopHeaders which is a set of top-level headers
that are associated with a (sub)module.

llvm-svn: 165279
2012-10-05 00:22:33 +00:00
Argyrios Kyrtzidis abc721ab4d [preprocessing record] Have PPEntityID be independent of the size of the
loaded entities vector, otherwise its meaning will change when a module
is imported and the vector size changes.

llvm-svn: 165278
2012-10-05 00:22:28 +00:00
Argyrios Kyrtzidis f590e094ad Add info in the preprocessing record whether an inclusion directive
resulted in an automatic module import.

llvm-svn: 165022
2012-10-02 16:10:46 +00:00
Dmitri Gribenko 6743e04699 Move the 'find macro by spelling' infrastructure to the Preprocessor class and
use it to suggest appropriate macro for __attribute__((deprecated)) in
-Wdocumentation-deprecated-sync.

llvm-svn: 164892
2012-09-29 11:40:46 +00:00
Argyrios Kyrtzidis 19d78b743f For PPCallbacks::InclusionDirective() add a parameter for the module, whenever
an inclusion directive was automatically turned into a module import, and
PPCallbacks::moduleImport() for an explicit module import.

llvm-svn: 164874
2012-09-29 01:06:10 +00:00
Argyrios Kyrtzidis 051b443242 Add an assertion to make sure the implicitly imported module
is the same as the suggested one when looking up the include filename.

llvm-svn: 164872
2012-09-29 01:06:01 +00:00
Alexander Kornienko e61e5625e7 Compatibility macro detection for the -Wimplicit-fallthrough diagnostic.
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
2012-09-28 22:24:03 +00:00
Douglas Gregor 07c22b78e5 Following up on r164620, cope with symlinking from an embedded
framework location out to a top-level framework. Such frameworks are
not really embedded at all.

llvm-svn: 164774
2012-09-27 14:50:15 +00:00
Argyrios Kyrtzidis 4fcd2885de Per discussion in http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20120917/064551.html
have PPCallbacks::InclusionDirective pass the character range for the filename quotes or brackets.

rdar://11113134 & http://llvm.org/PR13880

llvm-svn: 164743
2012-09-27 01:42:07 +00:00
Nico Weber dd9602fe93 Revert r163022, it caused PR13924.
Add a test for PR13924. Do not revert the test added in r163022,
it surprisingly still passes even after reverting the code changes.

llvm-svn: 164672
2012-09-26 08:19:01 +00:00
Jordan Rose de584de370 Rename CanFitInto64Bits to alwaysFitsInto64Bits per discussion on IRC.
This makes the behavior clearer concerning literals with the maximum
number of digits. For a 32-bit example, 4,000,000,000 is a valid uint32_t,
but 5,000,000,000 is not, so we'd have to count 10-digit decimal numbers
as "unsafe" (meaning we have to check for overflow when parsing them,
just as we would for numbers with 11 digits or higher). This is the same,
only with 64 bits to play with.

No functionality change.

llvm-svn: 164639
2012-09-25 22:32:51 +00:00
Dmitri Gribenko 511288b2b5 Optimize NumericLiteralParser::GetIntegerValue().
It does a conservative estimate on the size of numbers that can fit into
uint64_t.  This bound is improved.

llvm-svn: 164624
2012-09-25 19:09:15 +00:00
Douglas Gregor 24ff3bc392 Under certain terrible circumstances (<rdar://problem/10805775>),
top-level frameworks can actually be symlinked over to embedded
frameworks, and accessed via the top-level framework's headers. In
this case, we need to determine that the framework was *actually* an
embedded framework, so we can load the appropriate top-level module.

llvm-svn: 164620
2012-09-25 18:29:14 +00:00
Alexander Kornienko 1d26c02722 Macro history (de-)serialization. Deserialization currently reads only the latest macro definition. Needs more work.
Summary: Passes all tests (+ the new one with code completion), but needs a thorough review in part related to modules.

Reviewers: doug.gregor

Reviewed By: alexfh

CC: cfe-commits, rsmith

Differential Revision: http://llvm-reviews.chandlerc.com/D41

llvm-svn: 164610
2012-09-25 17:18:14 +00:00
Douglas Gregor c83de30add Introduce builtin macros to determine whether we're building a
specific module (__building_module(modulename)) and to get the name of
the current module as an identifier (__MODULE__). 

Used to help headers behave differently when they're being included as
part of building a module. Oh, the irony.

llvm-svn: 164605
2012-09-25 15:44:52 +00:00
Dmitri Gribenko b8e9e7507e StringRef'ize Preprocessor::CreateString().
llvm-svn: 164555
2012-09-24 21:07:17 +00:00
Dmitri Gribenko ae07f72017 Replace raw call to snprintf() by llvm streams.
llvm-svn: 164554
2012-09-24 20:56:28 +00:00
Dmitri Gribenko 1cd2305703 Change the wording of the extension warning from
> 'long long' is an extension when C99 mode is not enabled
to
> 'long long' is a C++11 extension
while compiling in C++98 mode.

llvm-svn: 164545
2012-09-24 18:19:21 +00:00
Dmitri Gribenko 7ba91723e7 Small cleanup of literal semantic analysis: hiding 'char *' pointers behind
StringRef makes code cleaner.  Also, make the temporary buffer smaller:
512 characters is unreasonably large for integer literals.

llvm-svn: 164484
2012-09-24 09:53:54 +00:00
Eli Friedman 847f3ca350 The keywords "true" and "false" shouldn't warn under -Wundef.
llvm-svn: 164279
2012-09-20 02:38:38 +00:00
Craig Topper 462a36d229 Remove an unused private field exposed by the recent LLVM_DELETED_FUNCTION changes.
llvm-svn: 164103
2012-09-18 05:21:59 +00:00
Ted Kremenek db90859400 Fix dead store found by static analyzer.
llvm-svn: 163994
2012-09-16 06:18:45 +00:00
Argyrios Kyrtzidis e552941316 [libclang] Fix getting a cursor inside an angled #include directive.
Fixed by pointing the end location of the preprocessed entity for the #include
at the closing '>', instead of the start of '<'.

rdar://11113134

llvm-svn: 163588
2012-09-11 02:17:21 +00:00
Richard Smith 639b8d05dd When a bad UTF-8 encoding or bogus escape sequence is encountered in a
string literal, produce a diagnostic pointing at the erroneous character
range, not at the start of the literal.

llvm-svn: 163459
2012-09-08 07:16:20 +00:00
Roman Divacky e637711ae0 Dont cast away const needlessly. Found by gcc48 -Wcast-qual.
llvm-svn: 163325
2012-09-06 15:59:27 +00:00
Joao Matos c0d4c1bcde Normalize line endings of r163022.
llvm-svn: 163023
2012-08-31 21:34:27 +00:00
Joao Matos e85e3b64f8 Emulate MSVC's preprocessor macro argument separator behavior by not considering commas from nested macro expansions as argument separators. Fixes parsing of VS 2012 headers.
llvm-svn: 163022
2012-08-31 21:10:54 +00:00
Eli Friedman 324adad966 Make a bunch of methods on Lexer private.
llvm-svn: 162970
2012-08-31 02:29:37 +00:00
Douglas Gregor 8bea83a866 Extend the "__is_pod" hack, which demotes various type trait keywords
(__is_pod, __is_signed, etc.) to normal identifiers if they are
encountered in certain places in the grammar where we know that prior
versions of libstdc++ or libc++ use them, to still allow the use of
these keywords as type traits. Fixes <rdar://problem/9836262> and PR10184.

llvm-svn: 162937
2012-08-30 20:04:43 +00:00
Richard Smith 5edd5830e1 Make preprocessor act in a GCC-compatible fashion when a macro is redefined
within its own argument list. The original definition is used for the immediate
expansion, but the new definition is used for any subsequent occurences within
the argument list or after the expansion.

llvm-svn: 162906
2012-08-30 13:38:46 +00:00
Alexander Kornienko c0b4928df8 Fixed a problem with #pragma push_macro/pop_macro implementation.
Summary:
The problem was with the following sequence:
  #pragma push_macro("long")
  #undef long
  #pragma pop_macro("long")
in case when "long" didn't represent a macro.
Fixed crash and removed code duplication for #undef/pop_macro case. Added regression tests.

Reviewers: doug.gregor, klimek

Reviewed By: doug.gregor

CC: cfe-commits, chapuni

Differential Revision: http://llvm-reviews.chandlerc.com/D31

llvm-svn: 162845
2012-08-29 16:56:24 +00:00
Alexander Kornienko 8b3f623582 Keep history of macro definitions and #undefs
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
2012-08-29 00:20:03 +00:00