Commit Graph

1003 Commits

Author SHA1 Message Date
Douglas Gregor 925296b4c2 Revamp the SourceManager to separate the representation of parsed
source locations from source locations loaded from an AST/PCH file.

Previously, loading an AST/PCH file involved carefully pre-allocating
space at the beginning of the source manager for the source locations
and FileIDs that correspond to the prefix, and then appending the
source locations/FileIDs used for parsing the remaining translation
unit. This design forced us into loading PCH files early, as a prefix,
whic has become a rather significant limitation.

This patch splits the SourceManager space into two parts: for source
location "addresses", the lower values (growing upward) are used to
describe parsed code, while upper values (growing downward) are used
for source locations loaded from AST/PCH files. Similarly, positive
FileIDs are used to describe parsed code while negative FileIDs are
used to file/macro locations loaded from AST/PCH files. As a result,
we can load PCH/AST files even during parsing, making various
improvemnts in the future possible, e.g., teaching #include <foo.h> to
look for and load <foo.h.gch> if it happens to be already available.

This patch was originally written by Sebastian Redl, then brought
forward to the modern age by Jonathan Turner, and finally
polished/finished by me to be committed.

llvm-svn: 135484
2011-07-19 16:10:42 +00:00
Alexis Hunt c6d1d946e7 Remember to add a has_feature macro for __underlying_type now that it is
correctly impelmented

llvm-svn: 135401
2011-07-18 17:08:00 +00:00
Chandler Carruth a88a221855 Move the rest of the preprocessor terminology from 'instantiate' and
variants to 'expand'. This changed a couple of public APIs, including
one public type "MacroInstantiation" which is now "MacroExpansion". The
rest of the codebase was updated to reflect this, especially the
libclang code. Two of the C++ (and thus easily changed) libclang APIs
were updated as well because they pertained directly to the old
MacroInstantiation class.

No functionality changed.

llvm-svn: 135139
2011-07-14 08:20:46 +00:00
Chandler Carruth e2c09ebcaa Convert terminology in the Lexer from 'instantiate' and variants to
'expand'. Also update the public API it provides to the new term, and
propagate that update to the various clients.

No functionality changed.

llvm-svn: 135138
2011-07-14 08:20:40 +00:00
Chandler Carruth c9c8419c38 Switch the TokenLexer's terminology from various forms of 'instantiate'
to 'expand' for macros. Only comments and uses local to the TokenLexer
are updated.

No functionality changed.

llvm-svn: 135137
2011-07-14 08:20:34 +00:00
Peter Collingbourne 77b0e7f296 Implement -MG. Fixes PR9613
llvm-svn: 134996
2011-07-12 19:35:15 +00:00
Argyrios Kyrtzidis 2299889f87 Don't warn for unused macro when undef'ing it, if it comes from an included file. rdar://9745065
llvm-svn: 134919
2011-07-11 20:39:47 +00:00
Eli Friedman f7ca26a077 Fix up dependency file name printing to more closely match that of gcc, including fixing a nasty recent regression that could make us print "/foo.h" with a command-line including "-I ./".
rdar://problem/9734352

llvm-svn: 134728
2011-07-08 20:17:28 +00:00
Chandler Carruth 8ae50ad064 Tweak formatting.
llvm-svn: 134675
2011-07-08 01:04:24 +00:00
Chandler Carruth 2536c072f7 Switch the token-paste source locations inside of function style macro
argument expansion to use the macro argument source locations as well.
Add a few tests to exercise this. There is still a bit more work needed
here though.

llvm-svn: 134674
2011-07-08 01:04:21 +00:00
Chandler Carruth 402bb38823 Keep track of which source locations are part of a macro argument
instantiation and improve diagnostics which are stem from macro
arguments to trace the argument itself back through the layers of macro
expansion.

This requires some tricky handling of the source locations, as the
argument appears to be expanded in the opposite direction from the
surrounding macro. This patch provides helper routines that encapsulate
the logic and explain the reasoning behind how we step through macros
during diagnostic printing.

This fixes the rest of the test cases originially in PR9279, and later
split out into PR10214 and PR10215.

There is still some more work we can do here to improve the macro
backtrace, but those will follow as separate patches.

llvm-svn: 134660
2011-07-07 23:56:36 +00:00
Argyrios Kyrtzidis 61c58f7f43 Move SourceManager::isAt[Start/End]OfMacroInstantiation functions to the Lexer, since they depend on it now.
llvm-svn: 134644
2011-07-07 21:54:45 +00:00
Argyrios Kyrtzidis dccf6e1948 Turn hashhash into tok::unkwown when it comes from expanding an argument, per Chris' suggestion.
llvm-svn: 134621
2011-07-07 18:04:47 +00:00
Argyrios Kyrtzidis e245aa2a93 When expanding macro arguments, treat '##' coming from an argument as a normal token.
e.g.

#define M(x) A x B
M(##) // should expand to 'A ## B', not 'AB'

llvm-svn: 134588
2011-07-07 03:40:37 +00:00
Argyrios Kyrtzidis 41fb2d95a3 Make the Preprocessor more memory efficient and improve macro instantiation 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
2011-07-07 03:40:34 +00:00
John McCall 24fc0decfe Change the driver's logic about Objective-C runtimes: abstract out a
structure to hold inferred information, then propagate each invididual
bit down to -cc1.  Separate the bits of "supports weak" and "has a native
ARC runtime";  make the latter a CodeGenOption.

The tool chain is still driving this decision, because it's the place that
has the required deployment target information on Darwin, but at least it's
better-factored now.

llvm-svn: 134453
2011-07-06 00:26:06 +00:00
Peter Collingbourne d395b9344d Replace an unreachable error path with an assert
(SourceManager::createFileID cannot return an invalid file ID).
Also update a comment to reflect this.

llvm-svn: 134168
2011-06-30 16:41:03 +00:00
Argyrios Kyrtzidis 8cc0459907 Introduce a caching mechanism for macro expanded tokens.
Previously macro expanded tokens were added to Preprocessor's bump allocator and never released,
even after the TokenLexer that were lexing them was finished, thus they were wasting memory.
A very "useful" boost library was causing clang to eat 1 GB just for the expanded macro tokens.

Introduce a special cache that works like a stack; a TokenLexer can add the macro expanded tokens
in the cache, and when it finishes, the tokens are removed from the end of the cache.

Now consumed memory by expanded tokens for that library is ~ 1.5 MB.

Part of rdar://9327049.

llvm-svn: 134105
2011-06-29 22:20:11 +00:00
Argyrios Kyrtzidis e379ee31c0 Introduce Preprocessor::getTotalMemory() and use it in CIndex.cpp, no functionality change.
llvm-svn: 134103
2011-06-29 22:20:04 +00:00
Argyrios Kyrtzidis 2cfce18645 Allow Lexer::getLocForEndOfToken to return the location just passed the macro instantiation
if the location given points at the last token of the macro instantiation.

Fixes rdar://9045701.

llvm-svn: 133804
2011-06-24 17:58:59 +00:00
Douglas Gregor 3bde9b15a1 Copy diagnostic pragmas to the preprocessed output, from Richard Osborne!
llvm-svn: 133633
2011-06-22 19:41:48 +00:00
Jay Foad 9a6b09874d Make more use of llvm::StringRef in various APIs. In particular, don't
use the deprecated forms of llvm::StringMap::GetOrCreateValue().

llvm-svn: 133515
2011-06-21 15:13:30 +00:00
John McCall 31168b077c Automatic Reference Counting.
Language-design credit goes to a lot of people, but I particularly want
to single out Blaine Garst and Patrick Beard for their contributions.

Compiler implementation credit goes to Argyrios, Doug, Fariborz, and myself,
in no particular order.

llvm-svn: 133103
2011-06-15 23:02:42 +00:00
Chris Lattner 848fa212e8 revert r133003 and fix the bug properly: the issue was that ## in a token
lexer is not a paste operator, it is a normal token.  This fixes a conformance
issue shown here:
http://p99.gforge.inria.fr/c99-conformance/c99-conformance-clang-2.9.html

and it defines away the crash from before.

llvm-svn: 133005
2011-06-14 18:19:37 +00:00
Chris Lattner 07efdfdafa Fix a crash on the testcase in PR9981 / rdar://9486765.
llvm-svn: 133003
2011-06-14 18:12:03 +00:00
Benjamin Kramer 38bcb72ee0 Copy IsWarnIfUnused too when making a copy of a MacroInfo.
Found by valgrind.

llvm-svn: 132540
2011-06-03 10:33:36 +00:00
Francois Pichet 2e11f5df3d Disable MSVC warning about runtime stack overflow for DebugOverflowStack.
llvm-svn: 132059
2011-05-25 16:15:03 +00:00
Argyrios Kyrtzidis 0e37afa15e A StringRef-ication of the DiagnosticIDs API and internals.
Patch by Matthieu Monrocq with tweaks by me to avoid StringRefs in the static
diagnostic data structures, which resulted in a huge global-var-init function.

Depends on llvm commit r132046.

llvm-svn: 132047
2011-05-25 05:05:01 +00:00
Nico Weber 3b1d1217f8 Make it possible for external tools to distinguish between paths that come from -I and paths that come from -system. Patch from Paul Holden!
llvm-svn: 131955
2011-05-24 04:31:14 +00:00
Chris Lattner 3bdc7679ce Invoke the FileChanged callback before pushing the linemarker for a system
header.  Getting it in the wrong order generated incorrect line markers in -E 
mode.  In the testcase from PR9861 we used to generate:

# 1 "test.c" 2
# 1 "./foobar.h" 1
# 0 "./foobar.h"
# 0 "./foobar.h" 3
# 2 "test.c" 2

now we properly produce:

# 1 "test.c" 2
# 1 "./foobar.h" 1
# 1 "./foobar.h" 3
# 2 "test.c" 2

This fixes PR9861.

llvm-svn: 131871
2011-05-22 22:10:16 +00:00
Douglas Gregor 80af31397a Audit and finish the implementation of C++0x nullptr, fixing two
minor issues along the way:
  - Non-type template parameters of type 'std::nullptr_t' were not
  permitted.
  - We didn't properly introduce built-in operators for nullptr ==,
  !=, <, <=, >=, or > as candidate functions .

To my knowledge, there's only one (minor but annoying) part of nullptr
that hasn't been implemented: catching a thrown 'nullptr' as a pointer
or pointer-to-member, per C++0x [except.handle]p4.

llvm-svn: 131813
2011-05-21 23:15:46 +00:00
Argyrios Kyrtzidis 627c14a068 Only ignore extra tokens after #else if we skip it, otherwise warn. Fixes rdar://9475098.
llvm-svn: 131788
2011-05-21 04:26:04 +00:00
Alexis Hunt 7957fdb60a Revert r131672 until __underlying_type is properly implemented in the
template case.

llvm-svn: 131692
2011-05-19 22:52:25 +00:00
Alexis Hunt d6cbf0d4be Implement a __has_feature for __underlying_type
llvm-svn: 131672
2011-05-19 20:48:13 +00:00
Argyrios Kyrtzidis 8b7252a8b3 Fix a nasty bug where inside StringLiteralParser:
1. We would assume that the length of the string literal token was at least 2
2. We would allocate a buffer with size length-2

And when the stars aligned (one of which would be an invalid source location due to stale PCH)
The length would be 0 and we would try to allocate a 4GB buffer.

Add checks for this corner case and a bunch of asserts.
(We really really should have had an assert for 1.).

Note that there's no test case since I couldn't get one (it was major PITA to reproduce),
maybe later.

llvm-svn: 131492
2011-05-17 22:09:56 +00:00
Peter Collingbourne d5d410faa8 Introduce __has_extension macro
__has_extension is a function-like macro which takes the same set
of feature identifiers as __has_feature.  It evaluates to 1 if the
feature is supported by Clang in the current language (either as a
language extension or a standard language feature) or 0 if not.

At the same time, add support for the C1X feature identifiers
c_generic_selections (renamed from generic_selections) and
c_static_assert, and document them.

Patch by myself and Jean-Daniel Dupas.

llvm-svn: 131308
2011-05-13 20:54:45 +00:00
Alexis Hunt d9a5cc13cf Implement the __is_trivially_copyable type trait
llvm-svn: 131270
2011-05-13 00:31:07 +00:00
Howard Hinnant 2d3eadac9b enable __has_feature(is_standard_layout)
llvm-svn: 131240
2011-05-12 19:52:14 +00:00
Douglas Gregor 347d626cf7 Implement CWG1170, which makes access-control errors into template
argument deduction failures. Only implemented in C++0x, since this is
a significant change in behavior from C++98/03.

llvm-svn: 131209
2011-05-11 23:45:11 +00:00
Eli Friedman 86a5101c27 Don't strlen() every file before parsing it.
llvm-svn: 131132
2011-05-10 17:11:21 +00:00
Douglas Gregor 998caead70 Introduce a new libclang parsing flag,
CXTranslationUnit_NestedMacroInstantiations, which indicates whether
we want to see "nested" macro instantiations (e.g., those that occur
inside other macro instantiations) within the detailed preprocessing
record. Many clients (e.g., those that only care about visible tokens)
don't care about this information, and in code that uses preprocessor
metaprogramming, this information can have a very high cost.

Addresses <rdar://problem/9389320>.

llvm-svn: 130990
2011-05-06 16:33:08 +00:00
Richard Smith 3f1b5d077b Implement support for C++0x alias templates.
llvm-svn: 130953
2011-05-05 21:57:07 +00:00
Douglas Gregor 37aa4938c8 Introduce a new libclang API, clang_isFileMultipleIncludeGuarded(),
which determines whether a particular file is actually a header that
is intended to be guarded from multiple inclusions within the same
translation unit.

llvm-svn: 130808
2011-05-04 00:14:37 +00:00
Alexis Hunt 61bc173784 Fully implement delegating constructors!
As far as I know, this implementation is complete but might be missing a
few optimizations. Exceptions and virtual bases are handled correctly.

Because I'm an optimist, the web page has appropriately been updated. If
I'm wrong, feel free to downgrade its support categories.

llvm-svn: 130642
2011-05-01 07:04:31 +00:00
Douglas Gregor 68dac4676d Use DirectoryLookup::getName() rather than getDir()->getName() in a context where we don't know whether we have a normal directory
llvm-svn: 130467
2011-04-29 00:45:09 +00:00
Douglas Gregor b6100f2bdc Only call the MacroExpands callback when we're actually going to
expand the macro, based on a patch by Ori Avtalion. Fixes PR9799.

llvm-svn: 130402
2011-04-28 16:36:13 +00:00
Chandler Carruth 6e1f9babcd Silence more -Wnon-pod-memset given its current implementation. I may be
able to revert these based on a patch I'm working on, but no reason for
people to be spammed with warnings in the interim.

llvm-svn: 130394
2011-04-28 08:19:45 +00:00
John Wiegley 1c0675e155 Parsing/AST support for Structured Exception Handling
Patch authored by Sohail Somani.

Provide parsing and AST support for Windows structured exception handling.

llvm-svn: 130366
2011-04-28 01:08:34 +00:00
Argyrios Kyrtzidis f7620e4d49 If a null statement was preceded by an empty macro keep its instantiation source location
in NullStmt.

llvm-svn: 130289
2011-04-27 05:04:02 +00:00
Manuel Klimek 0c69fd2760 To be able to replay compilations we need to accurately remodel how
includes get resolved, especially when they are found relatively to
another include file. We also try to get it working for framework
includes, but that part of the code is untested, as I don't have a code
base that uses it.

llvm-svn: 130246
2011-04-26 21:50:03 +00:00
Chandler Carruth a3e1f9a02c Implement basic __is_trivial type-trait support, enough to close PR9472.
This introduces a few APIs on the AST to bundle up the standard-based
logic so that programmatic clients have access to exactly the same
behavior.

There is only one serious FIXME here: checking for non-trivial move
constructors and move assignment operators. Those bits need to be added
to the declaration and accessors provided.

This implementation should be enough for the uses of __is_trivial in
libstdc++ 4.6's C++98 library implementation.

Ideas for more thorough test cases or any edge cases missing would be
appreciated. =D

llvm-svn: 130057
2011-04-23 10:47:28 +00:00
Chandler Carruth 7980348fcf Sort the type traits in a few places where they weren't previously
sorted in order to prepare for adding some new ones.

llvm-svn: 130056
2011-04-23 10:47:20 +00:00
Chris Lattner 9fa385d437 don't warn about empty macro arguments in c++'0x mode, since it sucked in
the c99 preprocessor.  Patch by Jonathan Sauer!

llvm-svn: 130031
2011-04-22 23:25:09 +00:00
Richard Smith 9bc6eedab4 Add __has_feature(cxx_range_for) check for C++11 range-based for loop.
llvm-svn: 129573
2011-04-15 15:14:40 +00:00
Chris Lattner 57540c5be0 fix a bunch of comment typos found by codespell. Patch by
Luis Felipe Strano Moraes!

llvm-svn: 129559
2011-04-15 05:22:18 +00:00
Peter Collingbourne 9114759641 C1X: implement generic selections
As an extension, generic selection support has been added for all
supported languages.  The syntax is the same as for C1X.

llvm-svn: 129554
2011-04-15 00:35:48 +00:00
Richard Smith f7b6202e6c Implement C++0x [lex.pptoken]p3's handling of <::.
llvm-svn: 129525
2011-04-14 18:36:27 +00:00
Eric Christopher 7f36a79ee9 Eat the UTF-8 BOM at the beginning of a file since it's ignored anyhow.
Nom Nom Nom.

Patch by Anton Korobeynikov!

llvm-svn: 129174
2011-04-09 00:01:04 +00:00
John McCall 75ca6d72c2 Fix getLocForEndOfToken to not double-count spurious internal characters
within a token, like trigraphs and escaped newlines.               
Patch by Marcin Kowalczyk!

llvm-svn: 128978
2011-04-06 01:50:22 +00:00
Douglas Gregor 7bf3fbe6e1 Add a __has_feature check for the 'availability' attribute
llvm-svn: 128337
2011-03-26 12:16:15 +00:00
Anders Carlsson 69f1f9391b we can now claim to fully support the override control feature in C++0x.
llvm-svn: 128281
2011-03-25 15:04:23 +00:00
Daniel Dunbar 1057f86d0e Lexer: Add extremely limited support for -traditional-cpp, ignoring BCPL
comments.

llvm-svn: 127910
2011-03-18 21:23:38 +00:00
Argyrios Kyrtzidis d6278e3252 Having FileManager::getFile always open the file, brought much consternation and leaking of file descriptors.
Add 'openFile' bool to FileManager::getFile to specify whether we want to have the file opened or not, have it
false by default, and enable it only in HeaderSearch.cpp where the open+fstat optimization matters.

Fixes rdar://9139899.

llvm-svn: 127748
2011-03-16 19:17:25 +00:00
Chandler Carruth 3cc331a160 Add a 'RawPath' parameter to the PPCallbacks interface. This allows
clients to observe the exact path through which an #included file was
located. This is very useful when trying to record and replay inclusion
operations without it beind influenced by the aggressive caching done
inside the FileManager to avoid redundant system calls and filesystem
operations.

The work to compute and return this is only done in the presence of
callbacks, so it should have no effect on normal compilation.

Patch by Manuel Klimek.

llvm-svn: 127742
2011-03-16 18:34:36 +00:00
Sebastian Redl c17003c66b Create __has_feature(cxx_noexcept) and mark it as working.
Find out that our C++0x status has only one field for noexcept expression and specification together, and that it was accidentally already marked as fully implemented.
This completes noexcept specification work.

llvm-svn: 127701
2011-03-15 21:17:12 +00:00
John McCall 462c055d85 Fix my earlier commit to work with escaped newlines and leave breadcrumbs
in case we want to make a world where we can check intermediate instantiations
for this kind of breadcrumb.

llvm-svn: 127221
2011-03-08 07:59:04 +00:00
John McCall cff9bcfbd3 Add an API call to retrieve the spelling data of a token from its SourceLocation.
llvm-svn: 127216
2011-03-08 04:06:57 +00:00
John McCall 86bc21ffcf Provide an attribute, objc_method_family, to allow the inferred family
of an Objective-C method to be overridden on a case-by-case basis.  This
is a higher-level tool than ns_returns_retained &c.;  it lets users specify
that not only does a method have different retain/release semantics, but
that it semantically acts differently than one might assume from its name.
This in turn is quite useful to static analysis.

llvm-svn: 126839
2011-03-02 11:33:24 +00:00
Peter Collingbourne 2f1e36bfd0 Rename tok::eom to tok::eod.
The previous name was inaccurate as this token in fact appears at
the end of every preprocessing directive, not just macro definitions.
No functionality change, except for a diagnostic tweak.

llvm-svn: 126631
2011-02-28 02:37:51 +00:00
Peter Collingbourne f29ce975ba Reimplement __pragma support using a TokenLexer
llvm-svn: 126221
2011-02-22 13:49:06 +00:00
Peter Collingbourne 2c9f966600 Make TokenLexer capable of storing preprocessor directive tokens
llvm-svn: 126220
2011-02-22 13:49:00 +00:00
Richard Smith 7ee0d5664e Turn on __has_feature(cxx_auto_type). The feature is now fully implemented.
llvm-svn: 126078
2011-02-20 12:13:05 +00:00
Argyrios Kyrtzidis c541ade850 Warn for missing terminating " or ' instead of error for gcc compatibility. Fixed rdar://8914293.
llvm-svn: 125616
2011-02-15 23:45:31 +00:00
Peter Collingbourne 564c0fa47a Move support for "#pragma STDC FP_CONTRACT" to Parser; add Sema actions
llvm-svn: 125474
2011-02-14 01:42:35 +00:00
Peter Collingbourne 3bffa52933 Make LexOnOffSwitch a Preprocessor member function
llvm-svn: 125473
2011-02-14 01:42:24 +00:00
Jeffrey Yasskin c498878e6d Add CMake dependencies so that LLVM_USED_LIBS order doesn't matter.
I also sorted the tools/driver dependencies since their order no
longer matters.

llvm-svn: 125417
2011-02-11 23:46:38 +00:00
Douglas Gregor 09b6989ef0 Implement two related optimizations that make de-serialization of
AST/PCH files more lazy:
  - Don't preload all of the file source-location entries when reading
  the AST file. Instead, load them lazily, when needed.
  - Only look up header-search information (whether a header was already
  #import'd, how many times it's been included, etc.) when it's needed
  by the preprocessor, rather than pre-populating it.

Previously, we would pre-load all of the file source-location entries,
which also populated the header-search information structure. This was
a relatively minor performance issue, since we would end up stat()'ing
all of the headers stored within a AST/PCH file when the AST/PCH file
was loaded. In the normal PCH use case, the stat()s were cached, so
the cost--of preloading ~860 source-location entries in the Cocoa.h
case---was relatively low.

However, the recent optimization that replaced stat+open with
open+fstat turned this into a major problem, since the preloading of
source-location entries would now end up opening those files. Worse,
those files wouldn't be closed until the file manager was destroyed,
so just opening a Cocoa.h PCH file would hold on to ~860 file
descriptors, and it was easy to blow through the process's limit on
the number of open file descriptors.

By eliminating the preloading of these files, we neither open nor stat
the headers stored in the PCH/AST file until they're actually needed
for something. Concretely, we went from

*** HeaderSearch Stats:
835 files tracked.
  364 #import/#pragma once files.
  823 included exactly once.
  6 max times a file is included.
  3 #include/#include_next/#import.
    0 #includes skipped due to the multi-include optimization.
1 framework lookups.
0 subframework lookups.

*** Source Manager Stats:
835 files mapped, 3 mem buffers mapped.
37460 SLocEntry's allocated, 11215575B of Sloc address space used.
62 bytes of files mapped, 0 files with line #'s computed.

with a trivial program that uses a chained PCH including a Cocoa PCH
to

*** HeaderSearch Stats:
4 files tracked.
  1 #import/#pragma once files.
  3 included exactly once.
  2 max times a file is included.
  3 #include/#include_next/#import.
    0 #includes skipped due to the multi-include optimization.
1 framework lookups.
0 subframework lookups.

*** Source Manager Stats:
3 files mapped, 3 mem buffers mapped.
37460 SLocEntry's allocated, 11215575B of Sloc address space used.
62 bytes of files mapped, 0 files with line #'s computed.

for the same program.

llvm-svn: 125286
2011-02-10 17:09:37 +00:00
NAKAMURA Takumi 98dd73d66c CMake: LLVM_NO_RTTI must be obsolete now!
llvm-svn: 125275
2011-02-10 09:15:32 +00:00
Peter Collingbourne c1270f51fa Lexer: add CUDA kernel call tokens
llvm-svn: 125218
2011-02-09 21:08:21 +00:00
Douglas Gregor 7115aee109 Add a __has_feature check for default template arguments in function
templates, a C++0x feature.

llvm-svn: 124973
2011-02-05 20:35:30 +00:00
Douglas Gregor 7c60768590 Add __has_feature() for each of the type traits
llvm-svn: 124820
2011-02-03 21:57:35 +00:00
Douglas Gregor 86af98444f Harden Lexer::GetBeginningOfToken() against bogus source locations and
the disappearance/alteration of files.

llvm-svn: 124616
2011-01-31 22:42:36 +00:00
Ted Kremenek afe348ea43 Wire up attributes 'ns_consumed' and 'cf_consumed' in the static analyzer's ObjC retain/release checker.
llvm-svn: 124386
2011-01-27 18:43:03 +00:00
Ted Kremenek 0e89838ced Hook up attribute ns_consumes_self in the ObjC retain/release checker in the static analyzer.
llvm-svn: 124360
2011-01-27 06:54:14 +00:00
Douglas Gregor 56d5f0abaa Add __has_feature(cxx_reference_qualified_functions); update tests and
documentation.

llvm-svn: 124322
2011-01-26 21:25:54 +00:00
Douglas Gregor c41d94eb1a Clean up the C++0x __has_feature tests. Specifically:
- Don't publicize a C++0x feature through __has_feature if we aren't
    in C++0x mode (even if the feature is available only with a
    warning). 
  - "auto" is not implemented well enough for its __has_feature to be
    turned on.
  - Fix the test of C++0x __has_feature to actually test what we're
  trying to test. Searching for the substring "foo" when our options
  are "foo" and "no_foo" doesn't work :)

llvm-svn: 124291
2011-01-26 15:36:03 +00:00
Douglas Gregor 0098499f7d Downgrade the error about rvalue references to an extension warning
and turn on __has_feature(cxx_rvalue_references). The core rvalue
references proposal seems to be fully implemented now, pending lots
more testing.

llvm-svn: 124169
2011-01-25 02:17:32 +00:00
Douglas Gregor 312ab72dbd Eradicate any mention of C++0x concepts.
llvm-svn: 123860
2011-01-19 23:15:20 +00:00
Douglas Gregor eecc6bc388 Variadic templates are fully implemented.
Turn on the __has_feature switch for variadic templates, document
their completion, and put the ExtWarn into the c++0x-extensions
warning group.

llvm-svn: 123854
2011-01-19 22:11:50 +00:00
Argyrios Kyrtzidis b495cc1a7b When redefining a macro don't warn twice if it's not used and don't warn for duplicate
definition by command line options. Fixes rdar://8875916.

llvm-svn: 123767
2011-01-18 19:50:15 +00:00
Chris Lattner 008c0a4a68 clean up some dead code around __has_include() processing code identified by the ted-o-matic.
rdar://8867482

llvm-svn: 123522
2011-01-15 06:57:04 +00:00
Francois Pichet 12df1dc8f2 Microsoft integer suffix changes:
i64 is like LL
i32 is like L

Also set isMicrosoftInteger to true only if the suffix is well formed.

llvm-svn: 123230
2011-01-11 11:57:53 +00:00
Michael J. Spencer f6efe58d45 Replace all uses of PathV1::exists with PathV2::fs::exists.
llvm-svn: 123150
2011-01-10 02:34:13 +00:00
Chris Lattner 56f64c14b7 fix rdar://8823139, a crash on a comment in a preprocessed .s file
that contains the ## operator.

llvm-svn: 122946
2011-01-06 05:01:51 +00:00
Chandler Carruth 540960f4a2 Fix PR8654, ensuring each branch of an #if, #elif, #else, ... chain
receives a PPCallback.

Patch by Richard Smith.

llvm-svn: 122755
2011-01-03 17:40:17 +00:00
Jeffrey Yasskin b3321531a8 Change all self assignments X=X to (void)X, so that we can turn on a
new gcc warning that complains on self-assignments and
self-initializations.  Fix one bug found by the warning, in which one
clang::OverloadCandidate constructor failed to initialize its
FunctionTemplate member.

llvm-svn: 122459
2010-12-23 01:01:28 +00:00
Abramo Bagnara ea4f7c7761 Introduced raw_identifier token kind.
llvm-svn: 122394
2010-12-22 08:23:18 +00:00
Nick Lewycky 2e998b7a6e Add missing standard includes. Patch by Joerg Sonnenberger!
llvm-svn: 122194
2010-12-19 20:49:25 +00:00
Michael J. Spencer f28df4cdba Replace all uses of PathV1::isAbsolute with PathV2::is_{absolute,relative}.
llvm-svn: 122087
2010-12-17 21:22:22 +00:00
Michael J. Spencer d9da7a1f16 MemoryBuffer API update.
llvm-svn: 121956
2010-12-16 03:28:14 +00:00
Argyrios Kyrtzidis 1cb0de1d4c Fix diagnostic pragmas.
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
2010-12-15 18:44:22 +00:00
Douglas Gregor 9c7bd2f535 Don't crash when code-completing after "#include <". It would be far
better to actually produce a decent set of completions by checking the
system include paths, but not today. Fixes PR8744.

llvm-svn: 121431
2010-12-09 23:35:36 +00:00
Michael J. Spencer f25faaaffb Use error_code instead of std::string* for MemoryBuffer.
llvm-svn: 121378
2010-12-09 17:36:38 +00:00
Ted Kremenek 8c4c74f4fb Fix diagnostic for reporting bad escape sequence.
Patch by Paul Curtis!

llvm-svn: 120759
2010-12-03 00:09:56 +00:00
Michael J. Spencer 8aaf49959c Merge System into Support.
llvm-svn: 120297
2010-11-29 18:12:39 +00:00
Chris Lattner dd278430a3 change the 'is directory' indicator to be a null-or-not
pointer that is passed down through the APIs, and make
FileSystemStatCache::get be the one that filters out
directory lookups that hit files.  This also paves the
way to have stat queries be able to return opened files.

llvm-svn: 120060
2010-11-23 21:17:56 +00:00
Chris Lattner 8f0583daa2 simplify the cache miss handling code, eliminating CacheMissing.
llvm-svn: 120038
2010-11-23 20:05:15 +00:00
Chris Lattner 226efd356c rework the stat cache, pulling it out of FileManager.h into
its own header and giving it some more structure.  No 
functionality change.

llvm-svn: 120030
2010-11-23 19:19:34 +00:00
Chris Lattner 7219a5db6e don't allow remapping PTH file paths with -fworking-directory, the
client should just pass in absolute paths.

llvm-svn: 120012
2010-11-23 09:01:31 +00:00
Chris Lattner 5159f6162e now the FileManager has a FileSystemOpts ivar, stop threading
FileSystemOpts through a ton of apis, simplifying a lot of code.
This also fixes a latent bug in ASTUnit where it would invoke
methods on FileManager without creating one in some code paths
in cindextext.

llvm-svn: 120010
2010-11-23 08:35:12 +00:00
Chris Lattner 7c434b6937 tidy up
llvm-svn: 119996
2010-11-23 04:40:26 +00:00
Chris Lattner 8afa6deb1d remove old compatibility APIs, use StringRef versions instead.
llvm-svn: 119935
2010-11-21 09:55:08 +00:00
Argyrios Kyrtzidis de2bdf637e Revert r119838 "Don't warn for empty 'if' body if there is a macro that expands to nothing"
and use a better and more general approach, where NullStmt has a flag to indicate whether it was preceded by an empty macro.

Thanks to Abramo Bagnara for the hint!

llvm-svn: 119887
2010-11-20 02:04:01 +00:00
Craig Silverstein 1a9ca21881 Several PPCallbacks take an SourceLocation + IdentifierInfo, rather
than a Token that holds the same information all in one easy-to-use
package.  There's no technical reason to prefer the former -- the
information comes from a Token originally -- and it's clumsier to use,
so I've changed the code to use tokens everywhere.

Approved by clattner

llvm-svn: 119845
2010-11-19 21:33:15 +00:00
Argyrios Kyrtzidis 90ee2a4ecf Don't warn for empty 'if' body if there is a macro that expands to nothing, e.g:
if (condition)
    CALL(0); // empty macro but don't warn for empty body.

Fixes rdar://8436021.

llvm-svn: 119838
2010-11-19 20:54:25 +00:00
Chris Lattner 39720111e0 move getSpelling from Preprocessor to Lexer, which it is more conceptually related to.
llvm-svn: 119479
2010-11-17 07:26:20 +00:00
Chris Lattner 6bab435db6 propagate preprocessor out of StringLiteralParser. It is now
possible to create one without a preprocessor.

llvm-svn: 119476
2010-11-17 07:21:13 +00:00
Chris Lattner 2be8aa9611 push the preprocessor out of EncodeUCNEscape
llvm-svn: 119475
2010-11-17 07:12:42 +00:00
Chris Lattner 2a6ee91619 move AdvanceToTokenCharacter and getLocForEndOfToken from
Preprocessor to Lexer where they make more sense.

llvm-svn: 119474
2010-11-17 07:05:50 +00:00
Chris Lattner b1ab2c2d3d add a static version of PP::AdvanceToTokenCharacter.
llvm-svn: 119472
2010-11-17 06:55:10 +00:00
Chris Lattner bde1b81eb8 push use of Preprocessor out farther.
llvm-svn: 119471
2010-11-17 06:46:14 +00:00
Chris Lattner 3a324d3232 push use of Preprocessor out of getOffsetOfStringByte
llvm-svn: 119470
2010-11-17 06:35:43 +00:00
Chris Lattner 30d4c928ac add a static form of the efficient PP::getSpelling method.
llvm-svn: 119469
2010-11-17 06:31:48 +00:00
Chris Lattner 7a02bfdfce refactor the interface to StringLiteralParser::getOffsetOfStringByte,
pushing the dependency on the preprocessor out a bit.

llvm-svn: 119468
2010-11-17 06:26:08 +00:00
Douglas Gregor 453b012513 Make sure to always check the result of
SourceManager::getPresumedLoc(), so that we don't try to make use of
an invalid presumed location. Doing so can cause crashes.

llvm-svn: 118885
2010-11-12 07:15:47 +00:00
NAKAMURA Takumi c0d7d99cc1 lib/Lex/PPMacroExpansion.cpp: Fixup to appease MSVC.
Confirmed on MSVS10.

llvm-svn: 118496
2010-11-09 06:27:32 +00:00
Douglas Gregor ae674f3148 Appeasing MSVC, take 3
llvm-svn: 118493
2010-11-09 05:43:53 +00:00
Douglas Gregor 416463f7f3 Try to appease MSVC
llvm-svn: 118487
2010-11-09 04:38:09 +00:00
Douglas Gregor 9169dcb7a9 sprintf -> snprintf conversion, from Vladimir Kirillov
llvm-svn: 118478
2010-11-09 03:20:07 +00:00
John McCall f71b45367f Document Clang's support for attributes on individual enumerators and
tweak the documentation for deprecation-with-message.  Provide __has_feature
tests for both.  rdar://problem/8605692

llvm-svn: 118435
2010-11-08 19:48:17 +00:00
Craig Silverstein 8e3d95e7df Add PPCallbacks for #if/#ifdef/etc.
The callback info for #if/#elif is not great -- ideally it would give
us a list of tokens in the #if, or even better, a little parse tree.
But that's a lot more work.  Instead, clients can retokenize using
Lexer::LexFromRawLexer().

Reviewed by nlewycky.

llvm-svn: 118318
2010-11-06 01:19:03 +00:00
Argyrios Kyrtzidis 71731d6b05 Implement -working-directory.
When -working-directory is passed in command line, file paths are resolved relative to the specified directory.
This helps both when using libclang (where we can't require the user to actually change the working directory)
and to help reproduce test cases when the reproduction work comes along.

--FileSystemOptions is introduced which controls how file system operations are performed (currently it just contains
 the working directory value if set).
--FileSystemOptions are passed around to various interfaces that perform file operations.
--Opening & reading the content of files should be done only through FileManager. This is useful in general since
 file operations will be abstracted in the future for the reproduction mechanism.

FileSystemOptions is independent of FileManager so that we can have multiple translation units sharing the same
FileManager but with different FileSystemOptions.

Addresses rdar://8583824.

llvm-svn: 118203
2010-11-03 22:45:23 +00:00
Douglas Gregor f09b6c9c85 Plug a leak in the preprocessing record's handling of inclusion
directives. We had a std::string in an object that was allocated via a
BumpPtrAllocator.

llvm-svn: 117912
2010-11-01 15:03:47 +00:00
Chris Lattner 5c0b40528d Rename alignof -> alignOf to avoid irritating C++'0x compilers,
PR8423

llvm-svn: 117775
2010-10-30 05:14:06 +00:00
Douglas Gregor 5ef9e33137 Make the deserialization of macro definitions lazy, so that we can
load identifiers without loading their corresponding macro
definitions. This is likely to improve PCH performance slightly, and
reduces deserialization stack depth considerably when using
preprocessor metaprogramming.

llvm-svn: 117750
2010-10-30 00:23:06 +00:00
Chandler Carruth c3ce5840af Update remaining attribute macros to new style.
llvm-svn: 117204
2010-10-23 08:44:57 +00:00
Douglas Gregor 796d76a663 Extend the preprocessing record and libclang with support for
inclusion directives, keeping track of every #include, #import,
etc. in the translation unit. We keep track of the source location and
kind of the inclusion, how the file name was spelled, and the
underlying file to which the inclusion resolved.

llvm-svn: 116952
2010-10-20 22:00:55 +00:00
Anders Carlsson 274a70ed7f Add a __has_attribute macro that works much like __has_feature and __has_builtin.
llvm-svn: 116906
2010-10-20 02:31:43 +00:00
Ted Kremenek c8456f8c59 Really^2 fix <rdar://problem/8361834>, this time without crashing.
Now MICache is a linked list (per the FIXME), where we tradeoff between MacroInfo objects being in MICache
and MIChainHead.  MacroInfo objects in the MICache chain are already "Destroy()'ed", so they can be reused.  When
inserting into MICache, we need to remove them from the regular linked list so that they aren't destroyed more than
once.

llvm-svn: 116869
2010-10-19 22:15:20 +00:00
Ted Kremenek 60ba93cd62 Revert most of r116862. It isn't quite the right fix for a memory leak in Preprocessor.
llvm-svn: 116864
2010-10-19 21:40:34 +00:00
Ted Kremenek e75b876fb9 Really fix: <rdar://problem/8361834> MacroInfo::AddTokenToBody() leaks memory
The problem was not the management of MacroInfo objects, but that when we recycle them
via the MICache the memory of the underlying SmallVector (within MacroInfo) was not getting
released.  This is because objects stashed into MICache simply are reused with a placement
new, and never have their destructor called.

llvm-svn: 116862
2010-10-19 21:30:15 +00:00
Ted Kremenek b865f7e025 Simplify loop. No functionality change.
llvm-svn: 116861
2010-10-19 21:30:11 +00:00
Ted Kremenek 1f1e4bdbf7 Simplify lifetime management of MacroInfo objects in Preprocessor by having the Preprocessor maintain them in a linked
list of allocated MacroInfos.  This requires only 1 extra pointer per MacroInfo object, and allows us to blow them
away in one place.  This fixes an elusive memory leak with MacroInfos (whose exact location I couldn't still figure
out despite substantial digging).

Fixes <rdar://problem/8361834>.

llvm-svn: 116842
2010-10-19 18:16:54 +00:00
Ted Kremenek 2c8028bcf4 In ~Preprocessor(), also cleanup the MacroInfo objects left-over from stray "#pragma push_macro" uses. This
fixes a potential memory leak.

llvm-svn: 116826
2010-10-19 17:40:53 +00:00
Ted Kremenek 6339f1ce2f Fix typo in comment.
llvm-svn: 116825
2010-10-19 17:40:50 +00:00
Chris Lattner 26f6c227dc allow I128 suffixes in msextensions mode just like i128 suffixes, patch
by Martin Vejnar!

llvm-svn: 116460
2010-10-14 00:24:10 +00:00
Chris Lattner 2edb926880 move logic for computing signed integer overflow when constant folding
into APInt.

llvm-svn: 116453
2010-10-13 23:46:56 +00:00
Nico Weber a6bde81bc8 Add support for UCNs for character literals
llvm-svn: 116129
2010-10-09 00:27:47 +00:00
Douglas Gregor 0bf3140424 Implement C++0x scoped enumerations, from Daniel Wallin! (and tweaked a
bit by me). 

llvm-svn: 116122
2010-10-08 23:50:27 +00:00
Nico Weber 9762e0a234 Add support for 4-byte UCNs like \U12345678. Warn about UCNs in c90 mode.
llvm-svn: 115743
2010-10-06 04:57:26 +00:00
Douglas Gregor 7fb25418ed Implement the C++0x "trailing return type" feature, e.g.,
auto f(int) -> int

from Daniel Wallin!

(With a few minor bug fixes from me).

llvm-svn: 115322
2010-10-01 18:44:50 +00:00
Sebastian Redl 517523014d In MeasureTokenLength, the FileLoc supplied to the lexer must point to the start of the buffer, or we risk overflow.
llvm-svn: 115117
2010-09-30 01:03:03 +00:00
Michael J. Spencer 4362a1c987 Fix coding standard mistake from my last commit.
That, and keep aKor happy :P.

llvm-svn: 114816
2010-09-27 06:34:47 +00:00
Michael J. Spencer a0a820fadb Lexer: Implement GCC's version of pragma message.
llvm-svn: 114814
2010-09-27 06:19:02 +00:00
Anders Carlsson 991285e425 Allow the use of C++0x deleted functions as an extension in C++98.
llvm-svn: 114762
2010-09-24 21:25:25 +00:00
Michael J. Spencer 09476212de Revert "CMake: Update to use standard CMake dependency tracking facilities instead"
This reverts commit r113631

Conflicts:

	CMakeLists.txt
	lib/CodeGen/CMakeLists.txt

llvm-svn: 113817
2010-09-13 23:54:41 +00:00
Michael J. Spencer 0881f4a367 CMake: Update to use standard CMake dependency tracking facilities instead
of whatever we were using before...

llvm-svn: 113631
2010-09-10 21:13:16 +00:00
Douglas Gregor c7d6576d54 When we parse a pragma, keep track of how that pragma was originally
spelled (#pragma, _Pragma, __pragma). In -E mode, use that information
to add appropriate newlines when translating _Pragma and __pragma into
#pragma, like GCC does. Fixes <rdar://problem/8412013>.

llvm-svn: 113553
2010-09-09 22:45:38 +00:00
Douglas Gregor b2f0713ddc Clean up some of the CMake dependencies
llvm-svn: 113416
2010-09-08 21:40:53 +00:00
Chris Lattner f0b0497343 fix 7320: we can't delete a trailing space if it doesn't exist.
llvm-svn: 113125
2010-09-05 23:16:09 +00:00
Fariborz Jahanian 9e42a952d7 Use getSpelling to get original text of the
c++ operator token. (radar 8328250).

llvm-svn: 112977
2010-09-03 17:33:04 +00:00
Fariborz Jahanian 0389df4a45 Patch to allow alternative representation of c++
operators (and, or, etc.) to be used as selectors
to match g++'s behavior.

llvm-svn: 112935
2010-09-03 01:26:16 +00:00
Fariborz Jahanian 39de024e66 Prevent warning when built with assert off.
llvm-svn: 112680
2010-08-31 23:54:38 +00:00
Fariborz Jahanian abaae2b692 Some support for unicode string constants
in wide strings. radar 8360841.

llvm-svn: 112672
2010-08-31 23:34:27 +00:00
Sebastian Redl a93bb5b807 Implement __has_feature(cxx_inline_namespaces)
llvm-svn: 112671
2010-08-31 23:28:47 +00:00
Chris Lattner 0f0492e69c improve isHexaLiteral to work with escaped newlines and trigraphs,
patch by Francois Pichet!

llvm-svn: 112602
2010-08-31 16:42:00 +00:00
Chris Lattner dec7334218 silence a warning
llvm-svn: 112549
2010-08-30 23:11:03 +00:00
Alexis Hunt 3b7918625c Revert my user-defined literal commits - r1124{58,60,67} pending
some issues being sorted out.

llvm-svn: 112493
2010-08-30 17:47:05 +00:00
Chris Lattner 5f183aa592 add a fixme.
llvm-svn: 112491
2010-08-30 17:11:14 +00:00
Chris Lattner 7a9e9e7d76 use 'features' instead of 'PP->getLangOptions'.
llvm-svn: 112490
2010-08-30 17:09:08 +00:00
Douglas Gregor 3cc2648b47 Now that GCC will have #pragma push/pop (in GCC 4.6), allow the
#pragma without requiring it to be in the "clang" namespace, from
Louis Gerbarg!

llvm-svn: 112484
2010-08-30 15:15:34 +00:00
Douglas Gregor 759ef23bb8 In Microsoft compatibility mode, don't parse the exponent as part of
the pp-number in a hexadecimal floating point literal, from Francois
Pichet! Fixes PR7968.

llvm-svn: 112481
2010-08-30 14:50:47 +00:00
Alexis Hunt 79eb5469e0 Implement C++0x user-defined string literals.
The extra data stored on user-defined literal Tokens is stored in extra
allocated memory, which is managed by the PreprocessorLexer because there isn't
a better place to put it that makes sure it gets deallocated, but only after
it's used up. My testing has shown no significant slowdown as a result, but
independent testing would be appreciated.

llvm-svn: 112458
2010-08-29 21:26:48 +00:00
John McCall 49039d4afb Complain if a __pragma isn't terminated.
llvm-svn: 112392
2010-08-29 01:09:54 +00:00
John McCall 89e925d78e Add support for Microsoft's __pragma in the preprocessor.
Patch by Francois Pichet!

llvm-svn: 112391
2010-08-28 22:34:47 +00:00
Douglas Gregor 33551892fa Tweak wording in an assertion, from dawn@burble.org.
llvm-svn: 112182
2010-08-26 14:07:34 +00:00
Douglas Gregor 115837041e Introduce a preprocessor code-completion hook for contexts where we
expect "natural" language and should not provide any completions,
e.g., comments, string literals, #error.

llvm-svn: 112054
2010-08-25 17:04:25 +00:00
Douglas Gregor ec00a26855 Implement code completion for preprocessor expressions and in macro
arguments.

llvm-svn: 111976
2010-08-24 22:20:20 +00:00
Douglas Gregor 127851084d Implement preprocessor code completion where a macro name is expected,
e.g., after #ifdef/#ifndef or #undef, or inside a defined <macroname>
expression in a preprocessor conditional.

llvm-svn: 111954
2010-08-24 20:21:13 +00:00
Douglas Gregor 3a7ad25eb6 Introduce basic code-completion support for preprocessor directives,
e.g., after a "#" we'll suggest #if, #ifdef, etc.

llvm-svn: 111943
2010-08-24 19:08:16 +00:00
Eli Friedman 04831926ec Detabify.
llvm-svn: 111768
2010-08-22 01:00:03 +00:00
Chris Lattner 20a2b46ca2 fix PR7943, a corner case with the GNU __VA_ARGS__ comma
swallowing extension.

llvm-svn: 111701
2010-08-21 00:27:00 +00:00
Sebastian Redl d44cd6adba More PCH -> AST renaming.
llvm-svn: 111472
2010-08-18 23:57:06 +00:00
Daniel Dunbar 211a787eaf CrashRecovery: Add #pragma clang __debug handle_crash, useful when debugging
CrashRecovery since it avoids sending a signal which may be intercepted by the
debugger.

llvm-svn: 111449
2010-08-18 23:09:23 +00:00
Chris Lattner 66b67d209e no need to pass bumppointer allocator into macroinfo::destroy
llvm-svn: 111364
2010-08-18 16:08:51 +00:00
Daniel Dunbar f2cf329ccd Lex: Add #pragma clang __debug {llvm_fatal_error, llvm_unreachable}, for testing
those crash paths.

llvm-svn: 111311
2010-08-17 22:32:48 +00:00
Chris Lattner c0a585d63c Implement #pragma push_macro, patch by Francois Pichet!
llvm-svn: 111234
2010-08-17 15:55:45 +00:00
Douglas Gregor 02690ba643 Don't emit end-of-file diagnostics like "unterminated conditional" or
"unterminated string" when we're performing code completion.

llvm-svn: 110933
2010-08-12 17:04:55 +00:00
Benjamin Kramer e8394df11b Random temporary string cleanup.
llvm-svn: 110807
2010-08-11 14:47:12 +00:00
Douglas Gregor 028d3e4d0f Use precompiled preambles for in-process code completion.
llvm-svn: 110596
2010-08-09 20:45:32 +00:00
Douglas Gregor 618e64a23b Revert r110440, the fix for PR4897. Chris claims to have a better way.
llvm-svn: 110544
2010-08-08 07:49:23 +00:00
Benjamin Kramer d05f31d059 Push location through the MacroUndefined PPCallback and use it to print #undefs in -dD mode. (PR7818)
llvm-svn: 110523
2010-08-07 22:27:00 +00:00
Douglas Gregor d26129a98a Fix the #include search path when reading from stdin, from Jon Simons!
Fixes PR4897.

llvm-svn: 110440
2010-08-06 12:06:13 +00:00
Ted Kremenek d21139a34f After a lengthy design discussion, add support for "ownership attributes" for malloc/free checking. Patch by Andrew McGregor!
llvm-svn: 109939
2010-07-31 01:52:11 +00:00
Daniel Dunbar 51738ba43e Transcribe clattner email to SVN.
llvm-svn: 109727
2010-07-29 02:46:02 +00:00
Daniel Dunbar e11281077d Change #pragma crash to segv, instead of abort.
llvm-svn: 109725
2010-07-29 02:25:07 +00:00
Daniel Dunbar b8068c33e2 Preprocessor: Add support for '#pragma clang __debug crash' and '#pragma clang
__debug overflow_stack'.
 - For testing crash reporting stuff... you'd think I could just use some C++
   code but Doug keeps fixing stuff!

llvm-svn: 109587
2010-07-28 15:40:33 +00:00
Sebastian Redl 9891212476 Record macros in dependent PCHs. Also add various info tables to dependent PCHs; tests for this to follow.
llvm-svn: 109554
2010-07-27 23:01:28 +00:00
Ted Kremenek 2bd41d1e30 Add PTHLexer::LexEndOfFile() to emit diagnostics at end-of-file similar to those by Lexer::LexEndOfFile().
llvm-svn: 109486
2010-07-27 02:59:02 +00:00
Douglas Gregor 3f4bea0646 Introduce basic support for loading a precompiled preamble while
reparsing an ASTUnit. When saving a preamble, create a buffer larger
than the actual file we're working with but fill everything from the
end of the preamble to the end of the file with spaces (so the lexer
will quickly skip them). When we load the file, create a buffer of the
same size, filling it with the file and then spaces. Then, instruct
the lexer to start lexing after the preamble, therefore continuing the
parse from the spot where the preamble left off.

It's now possible to perform a simple preamble build + parse (+
reparse) with ASTUnit. However, one has to disable a bunch of checking
in the PCH reader to do so. That part isn't committed; it will likely
be handled with some other kind of flag (e.g., -fno-validate-pch).

As part of this, fix some issues with null termination of the memory
buffers created for the preamble; we were trying to explicitly
NULL-terminate them, even though they were also getting implicitly
NULL terminated, leading to excess warnings about NULL characters in
source files.

llvm-svn: 109445
2010-07-26 21:36:20 +00:00
Dan Gohman 28ade550f4 Fix namespace polution.
llvm-svn: 109440
2010-07-26 21:25:24 +00:00
Douglas Gregor cd8bdd025f Improve performance during cursor traversal when a region of interest
is present. 

Rather than using clang_getCursorExtent(), which requires
us to lex the token at the ending position to determine its
length. Then, we'd be comparing [a, b) source ranges that cover the
characters in the range rather than the normal behavior for Clang's
source ranges, which covers the tokens in the range. However, relexing
causes us to read the source file (which may come from a precompiled
header), which is rather unfortunate and affects performance.

In the new scheme, we only use Clang-style source ranges that cover
the tokens in the range. At the entry points where this matters
(clang_annotateTokens, clang_getCursor), we make sure to move source
locations to the start of the token.

Addresses most of <rdar://problem/8049381>.

llvm-svn: 109134
2010-07-22 20:22:31 +00:00
Douglas Gregor af82e3510b Introduce a new lexer function to compute the "preamble" of a file,
which is the part of the file that contains all of the initial
comments, includes, and preprocessor directives that occur before any
of the actual code. Added a new -print-preamble cc1 action that is
only used for testing.

llvm-svn: 108913
2010-07-20 20:18:03 +00:00
Douglas Gregor b37b46e488 Complain when string literals are too long for the active language
standard's minimum requirements.

llvm-svn: 108837
2010-07-20 14:33:20 +00:00
Chris Lattner ad4f38b1a9 BUILD_ARCHIVE is the default for libraries, no need to set it.
llvm-svn: 108633
2010-07-18 00:14:47 +00:00
Chris Lattner 52c00bdd5b Add another terrible VC++ compatibility hack: allow users to
allow invalid token pastes (when in -fms-extensions mode)
with -Wno-invalid-token-paste

llvm-svn: 108624
2010-07-17 16:24:30 +00:00
Argyrios Kyrtzidis 36745fda34 Modify the pragma handlers to accept and use StringRefs instead of IdentifierInfos.
When loading the PCH, IdentifierInfos that are associated with pragmas cause declarations that use these identifiers to be deserialized (e.g. the "clang" pragma causes the "clang" namespace to be loaded).
We can avoid this if we just use StringRefs for the pragmas.

As a bonus, since we don't have to create and pass IdentifierInfos, the pragma interfaces get a bit more simplified.

llvm-svn: 108237
2010-07-13 09:07:17 +00:00
Argyrios Kyrtzidis d1d239f35c Remove the check for repeated tok::eofs, we are not supposed to go past eof so this code is
totally unnecessary.

llvm-svn: 108199
2010-07-12 21:41:41 +00:00
Argyrios Kyrtzidis c2924de667 If we are past tok::eof and in caching lex mode, avoid caching repeated tok::eofs.
llvm-svn: 108175
2010-07-12 18:49:30 +00:00
Chris Lattner 5a503e9f70 we do in fact have to cache the EOF token returned by the preprocessor.
In the case of backtracking, the cached token lexer will be the only 
lexer on the stack, without this the token stack will be empty and EOF
won't be returned.

This fixes PR7072.

llvm-svn: 108124
2010-07-12 04:25:32 +00:00
Chris Lattner 86851b8a7a fix PR4499, patch by Kyle Dean!
llvm-svn: 107836
2010-07-07 23:24:27 +00:00
Chris Lattner 30c924b3e8 Implement support for #pragma message, patch by Michael Spencer!
llvm-svn: 106950
2010-06-26 17:11:39 +00:00
Eric Christopher 03256c32ff More clang support for darwin tls. Add a __has_feature macro and
target specific preprocessor define as well.

llvm-svn: 106715
2010-06-24 02:02:00 +00:00
Chris Lattner c548be9ab3 Remove a dead argument to ProcessUCNEscape.
Fix string concatenation to treat escapes in concatenated strings that
are wide because of other string chunks to process the escapes as wide
themselves.  Before we would warn about and miscompile the attached testcase.

This fixes rdar://8040728 - miscompile + warning: hex escape sequence out of range

llvm-svn: 106012
2010-06-15 18:06:43 +00:00
Daniel Dunbar d839e77b12 Preprocessor: Ignore unknown pragmas in -E -dM and -Eonly modes.
llvm-svn: 105830
2010-06-11 20:10:12 +00:00
Ted Kremenek dea66e3e4c Fix memory leak in Preprocessor where MacroInfo objects in the MICache wouldn't have their
associated SmallVectors get deallocated.

llvm-svn: 105658
2010-06-08 23:00:53 +00:00
Daniel Dunbar ee6b692551 Makefiles: Set Clang CPP compiler flags in a single location, instead of scattered throughout the project Makefiles.
llvm-svn: 105638
2010-06-08 20:44:43 +00:00
Daniel Dunbar e6c1daa8fd Makefile: Switch Clang Makefiles to always include the top-level Clang Makefile.
- This eliminates most dependencies on how Clang is installed relative to LLVM.

llvm-svn: 105637
2010-06-08 20:34:18 +00:00
Chris Lattner 52d96ac930 simpler fix for rdar://8044135 - escaped newlines have already
been processed, so they don't have to be tip-toed around.

llvm-svn: 105182
2010-05-30 23:27:38 +00:00
Douglas Gregor fe4a4107d8 Improve our handling of NULL after an escaping '\' in a string
literal. Fixes <rdar://problem/8044135>.

llvm-svn: 105181
2010-05-30 22:59:50 +00:00
Fariborz Jahanian 93bef10131 Fix a miscompile of wchar pascal strings.
(radar 8020384)

llvm-svn: 104996
2010-05-28 19:40:48 +00:00
Douglas Gregor 9af03022ff Tell the string literal parser when it's not permitted to emit
diagnostics. That would be while we're parsing string literals for the
sole purpose of producing a diagnostic about them. Fixes
<rdar://problem/8026030>.

llvm-svn: 104684
2010-05-26 05:35:51 +00:00
Douglas Gregor 6da3db4af3 Improve code completion in failure cases in two ways:
1) Suppress diagnostics as soon as we form the code-completion
  token, so we don't get any error/warning spew from the early
  end-of-file.
  2) If we consume a code-completion token when we weren't expecting
  one, go into a code-completion recovery path that produces the best
  results it can based on the context that the parser is in.

llvm-svn: 104585
2010-05-25 05:58:43 +00:00
Chris Lattner 467f6bcfe5 robustify the conflict marker stuff. Don't add 7 twice, which would
make it miss (invalid) things like:
<<<<<<<
>>>>>>>

and crash if 

<<<<<<< 

was at the end of the line.  When we find a >>>>>>> that is not at the
end of the line, make sure to reset Pos so we don't crash on something
like:
<<<<<<< >>>>>>>

This isn't worth making testcases for, since each would require a new file.

rdar://7987078 - signal 11 compiling "<<<<<<<<<<"

llvm-svn: 103968
2010-05-17 20:27:25 +00:00
Chris Lattner 561aabd943 when code completing inside a C-style block comment, don't emit errors about
a missing */ since we truncated the file.

This fixes rdar://7948776

llvm-svn: 103913
2010-05-16 19:54:05 +00:00
Ted Kremenek e506ddc71e Add '__has_feature' support for weak ObjC classes.
llvm-svn: 102588
2010-04-29 02:06:46 +00:00
Ted Kremenek 6459939112 Sort '__has_feature' cases. No functionality change.
llvm-svn: 102587
2010-04-29 02:06:42 +00:00
Chris Lattner fb24a3a4ec push some source location information down through the compiler,
into ContentCache::getBuffer.  This allows it to produce 
diagnostics on the broken #include line instead of without a 
location.

llvm-svn: 101939
2010-04-20 20:35:58 +00:00
Chris Lattner 72286d6129 add a PPCallback handler for a skipped #include, patch by
Zhanyong Wan!

llvm-svn: 101813
2010-04-19 20:44:31 +00:00
Chris Lattner 1cf5bdd03d emit warn_char_constant_too_large at most once per literal, fixing PR6852
llvm-svn: 101580
2010-04-16 23:44:05 +00:00
Chris Lattner c745cec17c Improve line marker directive locations, patch by Jordy Rose
llvm-svn: 101226
2010-04-14 04:28:50 +00:00
Chris Lattner 0384e63501 make the token paste avoidance logic turn "..." into ".. ." instead of ". . ."
when avoiding paste.  Patch by David Peixotto!

llvm-svn: 101218
2010-04-14 03:57:19 +00:00
Chris Lattner 1a9e873bf9 fix a minor bug I noticed while work with Jordy's patch for PR6101,
in an input file like this:

# 42
int x;

we were emitting:

# <something>
 int x;

(with a space before the int) because we weren't clearing the leading 
whitespace flag properly after the \n from the directive was handled.

llvm-svn: 101084
2010-04-12 23:04:41 +00:00
Chris Lattner 58c79341ab Match MemoryBuffer API changes.
llvm-svn: 100484
2010-04-05 22:42:27 +00:00
Douglas Gregor a771f46c82 Reinstate my CodeModificationHint -> FixItHint renaming patch, without
the C-only "optimization".

llvm-svn: 100022
2010-03-31 17:46:05 +00:00
Douglas Gregor 30e631862f Revert r100008, which inexplicably breaks the clang-i686-darwin10 builder
llvm-svn: 100018
2010-03-31 17:25:35 +00:00
Douglas Gregor 3baad0d4f7 Rename CodeModificationHint to FixItHint, since we've been using the
term "fix-it" everywhere and even *I* get tired of long names
sometimes. No functionality change.

llvm-svn: 100008
2010-03-31 15:31:50 +00:00
Chris Lattner 8c5d05a299 fix a case where macro expansion should be disabled, patch by
Abramo Bagnara!

llvm-svn: 99626
2010-03-26 17:49:16 +00:00
Chris Lattner 80dbccd1bf fix a bug in paste avoidance which would cause us to accidentally
form a >>=.  Patch by Abramo Bagnara, testcase by me.

llvm-svn: 99624
2010-03-26 17:10:02 +00:00
Daniel Dunbar cb9eaf59fb PPCallbacks: Add hook for reaching the end of the main file, and fix DependencyFile to not do work in its destructor.
llvm-svn: 99257
2010-03-23 05:09:10 +00:00
Douglas Gregor 8aaca67b0a Robustify PreprocessingRecord slightly, by only creating macro
instantiations when we have the corresponding macro definition and by
removing macro definition information from our table when the macro is
undefined. 

llvm-svn: 99004
2010-03-19 21:58:23 +00:00
Douglas Gregor aae9224e49 Implement serialization and lazy deserialization of the preprocessing
record (which includes all macro instantiations and definitions). As
with all lay deserialization, this introduces a new external source
(here, an external preprocessing record source) that loads all of the
preprocessed entities prior to iterating over the entities.

The preprocessing record is an optional part of the precompiled header
that is disabled by default (enabled with
-detailed-preprocessing-record). When the preprocessor given to the
PCH writer has a preprocessing record, that record is written into the
PCH file. When the PCH reader is given a PCH file that contains a
preprocessing record, it will be lazily loaded (which, effectively,
implicitly adds -detailed-preprocessing-record). This is the first
case where we have sections of the precompiled header that are
added/removed based on a compilation flag, which is
unfortunate. However, this data consumes ~550k in the PCH file for
Cocoa.h (out of ~9.9MB), and there is a non-trivial cost to gathering
this detailed preprocessing information, so it's too expensive to turn
on by default. In the future, we should investigate a better encoding
of this information.

llvm-svn: 99002
2010-03-19 21:51:54 +00:00
Douglas Gregor 7dc8722bd3 Make the preprocessing record a PPCallbacks subclass itself,
eliminating the extra PopulatePreprocessingRecord object. This will
become useful once we start writing the preprocessing record to
precompiled headers.

llvm-svn: 98966
2010-03-19 17:12:43 +00:00
Douglas Gregor 7f6d60dcc2 Optionally store a PreprocessingRecord in the preprocessor itself, and
tie its creation to a CC1 flag -detailed-preprocessing-record.

llvm-svn: 98963
2010-03-19 16:15:56 +00:00
Douglas Gregor 78ae2481b6 Explicitly link macro instantiations to macro definitions in the
preprocessing record. Use that link with clang_getCursorReferenced()
and clang_getCursorDefinition() to match instantiations of a macro to
the definition of the macro.

llvm-svn: 98842
2010-03-18 18:23:03 +00:00
Douglas Gregor 065f8d11ca Introduce the notion of a "preprocessing record", which keeps track of
the macro definitions and macro instantiations that are found
during preprocessing. Preprocessing records are *not* generated by
default; rather, we provide a PPCallbacks subclass that hooks into the
existing callback mechanism to record this activity.

The only client of preprocessing records is CIndex, which keeps track
of macro definitions and instantations so that they can be exposed via
cursors. At present, only token annotation uses these facilities, and
only for macro instantiations; both will change in the near
future. However, with this change, token annotation properly annotates
macro instantiations that do not produce any tokens and instantiations
of macros that are later undef'd, improving our consistency.

Preprocessing directives that are not macro definitions are still
handled by clang_annotateTokens() via re-lexing, so that we don't have
to track every preprocessing directive in the preprocessing record.

Performance impact of preprocessing records is still TBD, although it
is limited to CIndex and therefore out of the path of the main compiler.

llvm-svn: 98836
2010-03-18 17:52:52 +00:00
Douglas Gregor 4ad3da2843 Entering the main source file in the preprocessor can fail if the
source file has been changed. Handle that failure more gracefully.

llvm-svn: 98727
2010-03-17 15:44:30 +00:00
Douglas Gregor 1668355e06 Remove unused variable
llvm-svn: 98691
2010-03-16 22:54:32 +00:00
Douglas Gregor dc970f0866 Audit all Preprocessor::getSpelling() callers, improving failure
recovery for those that need it.

llvm-svn: 98689
2010-03-16 22:30:13 +00:00
Douglas Gregor 42fe858cd6 Audit all callers of SourceManager::getCharacterData(); update some of
them to recover more gracefully on failure.

llvm-svn: 98672
2010-03-16 20:46:42 +00:00