Commit Graph

498 Commits

Author SHA1 Message Date
Chris Lattner 1c1a00cf51 move token paste poisoning diagnostics to after the instantiation loc
for a token is set, this makes the diagnostic "expanded from stack" work
for this diagnostic.  Add a testcase for PR3918.

llvm-svn: 69544
2009-04-19 20:29:42 +00:00
Chris Lattner da4ebb8921 Fix PR3918: Invalid use of __VA_ARGS__ not diagnosed,
by rejecting invalid poisoned tokens in the token
pasting path.

llvm-svn: 69536
2009-04-19 20:06:32 +00:00
Chris Lattner 249c38bb02 Fix PR4006, incorrect handling of __VA_ARGS__ when it was the first token
in a function-like macro body.  This has the added bonus of moving some
function-like macro specific code out of the object-like macro codepath.

llvm-svn: 69530
2009-04-19 18:26:34 +00:00
Chris Lattner bf78da7b36 Fix PR3917: the location of a #line directive is the location of the first _.
llvm-svn: 69485
2009-04-18 22:29:33 +00:00
Chris Lattner 93017cc12a Change Preprocessor::AdvanceToTokenCharacter to stop at
the first real character of a token.  For example, advancing
to byte 3 of foo\
bar

should stop at the b, not the \.

llvm-svn: 69484
2009-04-18 22:28:58 +00:00
Chris Lattner 38b2cde4c4 add a new Lexer::SkipEscapedNewLines method.
llvm-svn: 69483
2009-04-18 22:27:02 +00:00
Chris Lattner fbce7aa1f4 factor escape newline measuring out into its own helper function.
llvm-svn: 69482
2009-04-18 22:05:41 +00:00
Chris Lattner dfbfc44df7 remove unneeded scopes.
llvm-svn: 69481
2009-04-18 21:57:20 +00:00
Chris Lattner 397ca4a9ef fix typo
llvm-svn: 69479
2009-04-18 21:55:02 +00:00
Chris Lattner d66f172ab1 more fun with line markers: the digit string is required to be interpreted
as decimal, even if it starts with 0.  Also, since things like 0x1 are
completely illegal, don't even bother using numericliteralparser for them.

llvm-svn: 69454
2009-04-18 18:35:15 +00:00
Chris Lattner 35dd5056fc fix PR3927 by being more careful about the pp test for identifier.
llvm-svn: 69423
2009-04-18 06:44:18 +00:00
Chris Lattner 5ca5d40cf4 second half of PR3940: #line requires simple digit sequence.
llvm-svn: 69422
2009-04-18 06:38:24 +00:00
Chris Lattner 2425bcb49a enforce requirements imposed by C90 6.8 TC1, fixing PR3919.
llvm-svn: 69415
2009-04-18 02:23:25 +00:00
Chris Lattner bc63de144f Fix PR3938 by taking into account C99 6.10p4.
llvm-svn: 69413
2009-04-18 01:34:22 +00:00
Chris Lattner c17925da61 Substantially restructure function-like macro argument parsing.
Highlights: PP::isNextPPTokenLParen() no longer eats the ( 
when present.  We now simplify slightly the logic parsing
macro arguments.  We now handle PR3937 and other related cases
correctly.

llvm-svn: 69411
2009-04-18 01:13:56 +00:00
Chris Lattner b40289b2b8 Fix two problems from PR3916, and one problem I noticed while hacking
on the code.

llvm-svn: 69404
2009-04-17 23:56:52 +00:00
Chris Lattner ca556cb3e3 implement PR3940: #line numbers not fully checked
llvm-svn: 69403
2009-04-17 23:37:49 +00:00
Chris Lattner 0003c27f5e #line is allowed to have macros that expand to nothing after them.
llvm-svn: 69401
2009-04-17 23:30:53 +00:00
Chris Lattner 184e65d363 Change Lexer::MeasureTokenLength to take a LangOptions reference.
This allows it to accurately measure tokens, so that we get:

t.cpp:8:13: error: unknown type name 'X'
static foo::X  P;
       ~~~~~^

instead of the woefully inferior:

t.cpp:8:13: error: unknown type name 'X'
static foo::X  P;
       ~~~~ ^

Most of this is just plumbing to push the reference around.

llvm-svn: 69099
2009-04-14 23:22:57 +00:00
Chris Lattner 66037791b1 temporarily revert r69046
llvm-svn: 69054
2009-04-14 18:05:08 +00:00
Sanjiv Gupta 69650b099a Literal value calculation isn't likely to overflow on targets having int as 32 or less. Fixing the assert as it otherwise triggers for PIC16 which as i16 as int.
llvm-svn: 69046
2009-04-14 16:46:37 +00:00
Chris Lattner 825676afdf Offer a fixit hint for our warning about tokens at the end of a directive:
t.c:3:8: warning: extra tokens at end of #endif directive
#endif foo
       ^
       //

Don't do this in strict-C89 mode because bcpl comments aren't 
valid there, and it is too much trouble to analyze whether
C block comments are safe.

llvm-svn: 69024
2009-04-14 05:15:20 +00:00
Chris Lattner ce2ab6f425 Fix the #import / #include_next "extra tokens at end of #foo directive"
Warning to properly report that it is an import/include_next instead of
claiming it is a #include.

llvm-svn: 69023
2009-04-14 05:07:49 +00:00
Daniel Dunbar 2cba6be499 Fix assertion failure in PTH when tokens followed a closing #endif.
- Ted, please check.

 - Missing test case because PTH won't reliably cache the tokens in a
   test case. *cough*

llvm-svn: 68966
2009-04-13 17:57:49 +00:00
Chris Lattner 0af3ba1748 implement the microsoft/gnu "__COUNTER__" macro: rdar://4329310
llvm-svn: 68933
2009-04-13 01:29:17 +00:00
Chris Lattner 928e9096cb add a ppcallback hook for macro definitions.
llvm-svn: 68883
2009-04-12 01:39:54 +00:00
Douglas Gregor 92863e475e Compare the predefines buffer in the PCH file with the predefines
buffer generated for the current translation unit. If they are
different, complain and then ignore the PCH file. This effectively
checks for all compilation options that somehow would affect
preprocessor state (-D, -U, -include, the dreaded -imacros, etc.).

When we do accept the PCH file, throw away the contents of the
predefines buffer rather than parsing them, since all of the results
of that parsing are already stored in the PCH file. This eliminates
the ugliness with the redefinition of __builtin_va_list, among other
things.

llvm-svn: 68838
2009-04-10 23:10:45 +00:00
Chris Lattner d959d753bc do a dance with predefines, and finally enable reading of macros from
PCH.  This works now, except for limitations not being able to do things
with identifiers.  The basic example in the testcase works though.

llvm-svn: 68832
2009-04-10 22:13:17 +00:00
Chris Lattner 3c68407868 move a bunch of code for initializing the predefines buffer out of Preprocessor.cpp
into clang-cc.cpp.  This makes it so clang-cc constructs the *entire* predefines 
buffer, not just half of it.  A bonus of this is that we get to kill a copy
of DefineBuiltinMacro.

llvm-svn: 68830
2009-04-10 21:58:23 +00:00
Chris Lattner 5ec5a30901 simplify code.
llvm-svn: 68825
2009-04-10 21:17:07 +00:00
Douglas Gregor a7f71a91c5 PCH serialization/deserialization of the source manager. With this
improvement, source locations read from the PCH file will properly
resolve to the source files that were used to build the PCH file
itself.

Once we have the preprocessor state stored in the PCH file, source
locations that refer to macro instantiations that occur in the PCH
file should have the appropriate instantiation information.

llvm-svn: 68758
2009-04-10 03:52:48 +00:00
Chris Lattner e01d82b81f finish the implementation of -imacros. The driver still needs to be hooked up.
llvm-svn: 68640
2009-04-08 20:53:24 +00:00
Chris Lattner 58a1eb0ba0 reject the #__include_macros directive unless it comes from the
predefines buffer.

llvm-svn: 68627
2009-04-08 18:46:40 +00:00
Chris Lattner 14a7f39733 Add initial support for -imacros. Right now it has the same semantics as
-include, but that will be fixed soon.

llvm-svn: 68625
2009-04-08 18:24:34 +00:00
Daniel Dunbar 17ddaa677e More fixes to builtin preprocessor defines.
- Add -static-define option driver can use when __STATIC__ should be
   defined (instead of __DYNAMIC__).

 - Don't set __OPTIMIZE_SIZE__ on Os, __OPTIMIZE_SIZE__ is tied to Oz.

 - Set __NO_INLINE__ following GCC 4.2.

 - Set __GNU_GNU_INLINE__ or __GNU_STDC_INLINE__ following GCC 4.2.

 - Set __EXCEPTIONS for Objective-C NonFragile ABI.

 - Set __STRICT_ANSI__ for standard conforming modes.

 - I added a clang style test case in utils for this, but its not
   particularly portable and I don't think it belongs in the test
   suite.

llvm-svn: 68621
2009-04-08 18:03:55 +00:00
Daniel Dunbar ab7b2f5623 Set __PIC__ (more) correctly.
- Add -pic-level clang-cc option to specify the value for the define,
   updated driver to pass this.

 - Added __pic__

 - Added OBJC_ZEROCOST_EXCEPTIONS define while I was here (to match gcc).

llvm-svn: 68584
2009-04-08 03:03:23 +00:00
Chris Lattner c2d140156c The __weak and __strong defines are common to all darwin targets
and are even set in C mode.  As such, move them to Targets.cpp.

__OBJC_GC__ is also darwin specific, but seems reasonable to always
define it when in objc-gc mode.

This fixes rdar://6761450

llvm-svn: 68494
2009-04-07 04:48:21 +00:00
Anders Carlsson 65cb90efc1 Define __OPTIMIZE__ and __OPTIMIZE_SIZE__ if the -O[12] and -Os flags are passed to the compiler.
llvm-svn: 68450
2009-04-06 17:37:10 +00:00
Chris Lattner ecdaf40c9e fix rdar://6757323, where an escaped newline in a // comment
was causing the char after the newline to get eaten.

llvm-svn: 68430
2009-04-05 00:26:41 +00:00
Mike Stump 0be8875ea4 A code modification hint for files that don't end in a newline.
Eventually, would be nice to be able to run these modifications even
when we don't want the warning or errors for the actual diagnostic.

llvm-svn: 68272
2009-04-02 02:29:42 +00:00
Steve Naroff c94adda157 ProcessUCNEscape(): Incorportate some feedback from Chris.
llvm-svn: 68198
2009-04-01 11:09:15 +00:00
Eli Friedman 1c3fb22cad Fix pascal string support; testcase from mailing list message.
llvm-svn: 68181
2009-04-01 03:17:08 +00:00
Steve Naroff f2a880ca22 Incorporate feedback from Eli.
llvm-svn: 68107
2009-03-31 10:29:45 +00:00
Steve Naroff 7b753d21b5 Implement UCN support for C string literals (C99 6.4.3) and add some very basic tests. Chris Goller has graciously offered to write some test to help validate UCN support.
From a front-end perspective, I believe this code should work for ObjC @-strings. At the moment, I believe we need to tweak the code generation for @-strings (which doesn't appear to handle them). Will be investigating.

llvm-svn: 68076
2009-03-30 23:46:03 +00:00
Chris Lattner 839150e0d2 push line markers through -E mode.
llvm-svn: 67854
2009-03-27 17:13:49 +00:00
Fariborz Jahanian c35c9d87a9 Put back __OBJC2__ definition.
llvm-svn: 67802
2009-03-26 23:57:56 +00:00
Fariborz Jahanian dac14a7159 - Minor change to dump of ivar layout map.
- Temporarily undef'ed __OBJC2__ in nonfragile objc abi mode
  as it was forcing ivar synthesis in a certain project which clang
  does not yet support.

llvm-svn: 67766
2009-03-26 19:10:36 +00:00
Chris Lattner 51a53f92a5 fix PR3880, fixing a comma swallowing bug handling macros that only take
... arguments.

llvm-svn: 67706
2009-03-25 21:08:24 +00:00
Chris Lattner beb9055000 remove some dead code. ArgTokens can never be empty, because it is always
terminated with an EOF token.  The condition it is trying to check for is
handled by this code above.

    // Empty arguments are standard in C99 and supported as an extension in
    // other modes.
    if (ArgTokens.empty() && !Features.C99)
      Diag(Tok, diag::ext_empty_fnmacro_arg);

llvm-svn: 67705
2009-03-25 21:01:40 +00:00
Chris Lattner 73a7cab9e1 change the __VERSION__ string to be more sensible. It would be useful to include the clang version # too.
llvm-svn: 67619
2009-03-24 16:09:18 +00:00
Chris Lattner 5030e5eabe The individual pieces of an invalid paste as still candidates for expansion.
This matters in assembler mode, where this is silently allowed.
This fixes rdar://6709206.

llvm-svn: 67539
2009-03-23 17:32:45 +00:00
Ted Kremenek dc637a0be9 PTHManager::Create():
- Make the Diagnostic::Level for PTH errors to be specified by the caller

clang (driver):
- Set the PTHManager diagnostic level to "Diagnostic::Error" for -include-pth
  (a hard error) and Diagnostic::Warning for -token-cache (we can still
  proceed).

llvm-svn: 67462
2009-03-22 06:42:39 +00:00
Ted Kremenek f97c47ca15 Add back warning about a PTH file not containing any identifiers, but don't make
it a hard error.

llvm-svn: 67424
2009-03-21 00:25:09 +00:00
Ted Kremenek b12f24116d Allow PTH files with no identifiers.
llvm-svn: 67423
2009-03-21 00:15:11 +00:00
Chris Lattner 1d1d80e5f9 rename the <predefines> buffer to <built-in> to solve PR3849.
Add a #include directive around the command line buffer so that
diagnostics generated from -include directives get diagnostics
like:

In file included from <built-in>:98:
In file included from <command line>:3:
./t.h:2:1: warning: type specifier missing, defaults to 'int'
b;
^

llvm-svn: 67396
2009-03-20 20:16:10 +00:00
Ted Kremenek 80e239abc0 PTHManager::Create() now creates a PTHManager even if the PTH file contains no
cached tokens. This is for use with -include-pth.

llvm-svn: 67385
2009-03-20 17:54:25 +00:00
Chris Lattner 4ba73aa0c2 pass LangOptions into TargetInfo::getTargetDefines, so that targets
can have language-specific defines.

llvm-svn: 67375
2009-03-20 15:52:06 +00:00
Ted Kremenek f9ccd5cdc2 Add PTHManager::getOriginalSourceFile(), a method that returns the name of the
original source file (if any) that was used to generate the PTH cache.

llvm-svn: 67343
2009-03-19 22:19:30 +00:00
Chris Lattner d14705b9b4 silence some errors that should not apply to .S files on code like:
''
   '
 '

llvm-svn: 67237
2009-03-18 21:10:12 +00:00
Chris Lattner 2d17ab783b when preprocessing a .S file, unknown directives should just be passed through,
and the token after the # should be expanded if it is not a valid directive.
This allows us to transform things like:

#define FOO BAR
# FOO

into # BAR, even though FOO is not normally expanded for directives.

This should fix PR3833

llvm-svn: 67236
2009-03-18 21:00:25 +00:00
Chris Lattner 2534324a4e properly form a full token for # before calling HandleDirective.
llvm-svn: 67235
2009-03-18 20:58:27 +00:00
Chris Lattner 5eb8ae2453 This is not considered a preprocessor directive in .S files:
# 4 

llvm-svn: 67233
2009-03-18 20:41:10 +00:00
Chris Lattner 5def81401f constructs like:
#define Y X ## .
Y

are ok in .S files.

llvm-svn: 67231
2009-03-18 20:31:57 +00:00
Daniel Dunbar dc78bd9f79 Fix -E mismatch; an identifier followed by a numeric constant does not
require a space (to avoid concatenation) if the numeric constant had a
leading period.
 - PR3819.

llvm-svn: 67163
2009-03-18 03:32:24 +00:00
Gabor Greif 31a082fd7a typo
llvm-svn: 67081
2009-03-17 11:39:38 +00:00
Douglas Gregor 23d75bb326 Build system changes to use TableGen to generate the various
diagnostics. This builds on the patch that Sebastian committed and
then revert. Major differences are:

  - We don't remove or use the current ".def" files. Instead, for now,
    we just make sure that we're building the ".inc" files.
  - Fixed CMake makefiles to run TableGen and build the ".inc" files
    when needed. Tested with both the Xcode and Makefile generators
    provided by CMake, so it should be solid.
  - Fixed normal makefiles to handle out-of-source builds that involve
    the ".inc" files.

I'll send a separate patch to the list with Sebastian's changes that
eliminate the use of the .def files.

llvm-svn: 67058
2009-03-16 23:06:59 +00:00
Anders Carlsson 5bd30395b9 (Hopefully) instantiate dependent array types correctly.
llvm-svn: 67032
2009-03-15 20:12:13 +00:00
Chris Lattner 83aba00ee8 make Preprocessor::Diags be a pointer instead of a reference.
llvm-svn: 66955
2009-03-13 21:17:43 +00:00
Chris Lattner 80c21df8ea use accessor instead of poking ivar directly
llvm-svn: 66954
2009-03-13 21:17:23 +00:00
Chris Lattner cf35ce9d0d add a callback for macro expansion, based on a patch by Paolo Bolzoni!
llvm-svn: 66799
2009-03-12 17:31:43 +00:00
Chris Lattner da248f4f30 fix PR3768, Clang does -D__STDC_HOSTED__=1, even if -ffreestanding is passed.
llvm-svn: 66474
2009-03-09 21:50:12 +00:00
Chris Lattner 794c001ad4 fix PR3764 - A redefinition of a pre-processor macro fails
Redefinition checking should ignore the leading whitespace and
start of line flags on the first token of an expansion.

llvm-svn: 66442
2009-03-09 20:33:32 +00:00
Chris Lattner 7253991f9d add \n characters to the scratch buffer *before* returned tokens.
This prevents caret diagnostics from the scratch buffer from 
including other tokens in the scratch buffer that occurred beforei
them.

llvm-svn: 66375
2009-03-08 08:16:41 +00:00
Chris Lattner fa217bda40 simplify some logic by making ScratchBuffer handle the application of trailing
\0's to created tokens instead of making all clients do it.  No functionality
change.

llvm-svn: 66373
2009-03-08 08:08:45 +00:00
Mike Stump 82d8d559bb Fix warnings in build on clang-x86_64-freebsd buildbot.
llvm-svn: 66344
2009-03-07 18:35:41 +00:00
Chris Lattner d4a96730c1 #import is not considered an extension for ObjC.
llvm-svn: 66246
2009-03-06 04:28:03 +00:00
Chris Lattner 8322dc809e make the token lexer allocate its temporary token buffers for
preexpanded macro arguments from the preprocessor's bump pointer.
This reduces # mallocs from 12444 to 11792.

llvm-svn: 66025
2009-03-04 06:50:57 +00:00
Chris Lattner c25d8a7e30 improve compatibility with GCC 4.4, patch by Michel Salim (PR3697)
llvm-svn: 65884
2009-03-02 22:20:04 +00:00
Douglas Gregor 96977da72c Clean up and document code modification hints.
llvm-svn: 65641
2009-02-27 17:53:17 +00:00
Chris Lattner d42c29f9a2 fix some sema problems with wide strings and hook up basic codegen for them.
llvm-svn: 65582
2009-02-26 23:01:51 +00:00
Ted Kremenek 29b8697393 Move PTHStatCache within the anonymous namespace.
llvm-svn: 65348
2009-02-23 23:27:54 +00:00
Chris Lattner 70946da73a switch the macroinfo argument lists from being allocated off the heap
to being allocated from the same bumpptr that the MacroInfo objects 
themselves are.

This speeds up -Eonly cocoa.h pth by ~4%, fsyntax-only is barely measurable.

llvm-svn: 65195
2009-02-20 22:46:43 +00:00
Chris Lattner f87c510cc9 detemplatify setArgumentList and some other cleanups.
llvm-svn: 65187
2009-02-20 22:31:31 +00:00
Chris Lattner 666f7a42d6 require the MAcroInfo objects are explcitly destroyed.
llvm-svn: 65179
2009-02-20 22:19:20 +00:00
Ted Kremenek e76eb060c7 Fix another PTH warning that should not be a note.
llvm-svn: 65072
2009-02-19 22:14:49 +00:00
Ted Kremenek 36b005db45 Make PTH warnings actual warnings instead of 'notes'.
llvm-svn: 65071
2009-02-19 22:13:40 +00:00
Chris Lattner 91668def8b fix PR3609, emit:
t.c:1:10: error: missing terminating '>' character
#include <stdio.h
         ^

instead of:

t.c:1:10: error: missing terminating " character
#include <stdio.h
         ^

llvm-svn: 65052
2009-02-19 18:29:56 +00:00
Chris Lattner ddb7191920 Next step toward making string diagnostics correct: handle
escapes in the string for subtoken positioning.  This gives
us working examples like:

t.m:5:16: warning: field width should have type 'int', but argument has type 'unsigned int'
  printf("\n\n%*d", (unsigned) 1, 1);
               ^    ~~~~~~~~~~~~

where before the caret pointed two spaces to the left.

llvm-svn: 64940
2009-02-18 19:21:10 +00:00
Chris Lattner 57a09cfcbc update comment.
llvm-svn: 64939
2009-02-18 18:56:29 +00:00
Chris Lattner ec396b5114 Fix some issues handling sub-token locations that come from macro expansions.
We now emit:

t.m:6:15: warning: field width should have type 'int', but argument has type 'unsigned int'
  printf(STR, (unsigned) 1, 1);
         ^    ~~~~~~~~~~~~
t.m:3:18: note: instantiated from:
#define STR "abc%*ddef"
                 ^

which has the correct location in the string literal in the note line.

llvm-svn: 64936
2009-02-18 18:52:52 +00:00
Fariborz Jahanian eb209e7dbd define __OBJC2__ for objc's nonfragile abi.
llvm-svn: 64642
2009-02-16 18:28:48 +00:00
Chris Lattner ee4b5235e3 Add support for deprecated members of RecordDecls (e.g. struct fields).
llvm-svn: 64634
2009-02-16 17:07:21 +00:00
Chris Lattner f52c0b261c add a new SourceManager::getInstantiationRange helper method.
llvm-svn: 64606
2009-02-15 21:26:50 +00:00
Chris Lattner 5a2e9cb42d fix PR3579: __LINE__ expands to the presumed location of the
*end* of a macro instantiation, not the start of it.  This is
really all about bug-for-bug compatibility with GCC, but not
doing this breaks the FreeBSD kernel.

llvm-svn: 64604
2009-02-15 21:06:39 +00:00
Chris Lattner 9dc9c206d3 track "just a little more" location information for macro instantiations.
Now instead of just tracking the expansion history, also track the full
range of the macro that got replaced.  For object-like macros, this doesn't
change anything.  For _Pragma and function-like macros, this means we track
the locations of the ')'.

This is required for PR3579 because apparently GCC uses the line of the ')'
of a function-like macro as the location to expand __LINE__ to.

llvm-svn: 64601
2009-02-15 20:52:18 +00:00
Chris Lattner 190f64e9b8 add an assertion from Alexei Svitkine!
llvm-svn: 64503
2009-02-13 23:06:48 +00:00
Chris Lattner 7e4c81c8c6 Give TargetInfo a new IntPtrType to hold the intptr_t type for
a target.

Make Preprocessor.cpp define a new __INTPTR_TYPE__ macro based on this.

On linux/32, set intptr_t to int, instead of long.  This fixes PR3563.

llvm-svn: 64495
2009-02-13 22:28:55 +00:00
Ted Kremenek 2fd18ec43a PTH: Cache directory and negative 'stat' calls. This gives us a 1% performance improvement on Cocoa.h (fsyntax-only+PTH).
llvm-svn: 64490
2009-02-13 22:07:44 +00:00
Chris Lattner 9ef847be12 Fix rdar://6562329, a static analyzer crash Ted noticed on
wine sources.  This was happening because HighlightMacros was 
calling EnterMainFile multiple times on the same preprocessor
object and getting an assert due to the new #line stuff (the
file in question was bison output with #line directives).

The fix for this is to not reenter the file.  Instead, 
relex the tokens in raw mode, swizzle them a bit and repreprocess
the token stream.  An added bonus of this is that rewrite macros
will now hilight the macro definition as well as its uses.  Woo.

llvm-svn: 64480
2009-02-13 19:33:24 +00:00
Ted Kremenek 29942a349c Add some boilerplate to the PTH file to prepare for the caching of stats for directories (and negative stats too).
llvm-svn: 64477
2009-02-13 19:13:46 +00:00
Mike Stump 57d7354635 Fix cmake builds.
llvm-svn: 64455
2009-02-13 15:42:50 +00:00
Eli Friedman 159a7cbc36 Fix gcc warning: gcc correctly notes that const-qualifying the return
type doesn't do anything.

llvm-svn: 64424
2009-02-13 01:02:29 +00:00
Chris Lattner 644d452de5 factor token concatenation avoidance logic out of
PrintPreprocessedOutput into its own file.  No functionality change.

llvm-svn: 64418
2009-02-13 00:46:04 +00:00
Daniel Dunbar ad027c7781 Fix assertion when input is an empty string.
llvm-svn: 64397
2009-02-12 19:31:53 +00:00
Ted Kremenek b4c85ccaaa Re-enable PTH stat caching. All tests pass now.
llvm-svn: 64356
2009-02-12 03:45:39 +00:00
Ted Kremenek c6a2a37222 Fix bad reading of bytes in ReadUnalignedLE64() (copy-paste error).
llvm-svn: 64355
2009-02-12 03:39:55 +00:00
Ted Kremenek 3280145da4 Temporarily disable PTH stat caching as it appears to be failing on some machines.
llvm-svn: 64354
2009-02-12 03:36:54 +00:00
Ted Kremenek a5c2c27ebd PTH: Cache stat information for files in the PTH file. Hook up FileManager
to use this stat information in the PTH file using a 'StatSysCallCache' object.

Performance impact (Cocoa.h, PTH):
- number of stat calls reduces from 1230 to 425
- fsyntax-only: time improves by 4.2% 

We can reduce the number of stat calls to almost zero by caching negative stat
calls and directory stat calls in the PTH file as well.

llvm-svn: 64353
2009-02-12 03:26:59 +00:00
Ted Kremenek 4c1d41f2b1 PTH: Have meta data be at the beginning of the PTH file, not the end.
llvm-svn: 64338
2009-02-11 23:34:32 +00:00
Ted Kremenek e5554deb45 PTH: Replace string identifier to persistent ID lookup with a hashtable. This is
actually *slightly* slower than the binary search. Since this is algorithmically
better, further performance tuning should be able to make this faster.

llvm-svn: 64326
2009-02-11 21:29:16 +00:00
Ted Kremenek 8527e3a727 PTH: Don't emit the PTH offset of the IdentifierInfo string data as that data is
referenced by other tables.

llvm-svn: 64304
2009-02-11 16:06:55 +00:00
Ted Kremenek 86423a9993 PTH: Replace ad hoc 'file name' -> 'PTH data' lookup table in the PTH file with an on-disk chained hash table. This data structure is implemented using templates, and will be used to replace similar data structures. This change leads to no visibile performance impact on Cocoa.h, but now we only pay a price for the table on order with the number of files accessed and not the number in the PTH file.
llvm-svn: 64245
2009-02-10 22:16:22 +00:00
Chris Lattner 0763cc6bfd Export __INT8_TYPE__ / __INT16_TYPE__ / __INT32_TYPE__ / __INT64_TYPE__
in a gcc 4.5 compatible way so that stdint.h can follow the compiler's 
notion of types.

llvm-svn: 63976
2009-02-06 22:59:26 +00:00
Chris Lattner a31829b5bc -funsigned-char sets __CHAR_UNSIGNED__
llvm-svn: 63942
2009-02-06 18:20:57 +00:00
Chris Lattner 1630c3c4f0 Add an implementation of -dM that follows GCC closely enough to permit
diffing the output of:
  clang -dM -o - -E -x c foo.c | sort

llvm-svn: 63926
2009-02-06 06:45:26 +00:00
Chris Lattner 5c7cd6043e add interface for walking macro table.
llvm-svn: 63925
2009-02-06 06:26:42 +00:00
Chris Lattner bba531ce99 get __WCHAR_TYPE__ from the targetinfo hook
llvm-svn: 63920
2009-02-06 05:06:07 +00:00
Chris Lattner a91c30fdb0 simplify and refactor a bunch of type definition code in Preprocessor
predefines buffer initialization.

llvm-svn: 63919
2009-02-06 05:04:11 +00:00
Chris Lattner 61898606dc remove some ad-hocery and use DefineTypeSize for more things.
Now you too can have a 47 bit long long!

llvm-svn: 63918
2009-02-06 04:55:18 +00:00
Chris Lattner a3dc5d8423 refactor some code into a DefineTypeSize function.
llvm-svn: 63917
2009-02-06 04:50:25 +00:00
Chris Lattner fafd8d1be9 correct and generalize computation of __INTMAX_MAX__.
llvm-svn: 63848
2009-02-05 07:27:41 +00:00
Chris Lattner 8181312251 fix some differences between apple gcc and clang on darwin/x86-32.
llvm-svn: 63846
2009-02-05 07:19:24 +00:00
Chris Lattner 022923a22a Fix PR3464 by searching for headers from the predefines
buffer as if the #include happened from the main file.

llvm-svn: 63764
2009-02-04 19:45:07 +00:00
Chris Lattner 1c967784f3 Implement handling of file entry/exit notifications from GNU
line markers, including maintenance of the virtual include stack.

For something like this:

# 42 "bar.c" 1
# 142 "bar2.c" 1

#warning zappa
# 92 "bar.c" 2
#warning gonzo
# 102 "foo.c" 2
#warning bonkta


we now produce these three warnings:

#1:
In file included from foo.c:3:
In file included from bar.c:42:
bar2.c:143:2: warning: #warning zappa
#warning zappa
 ^

#2:
In file included from foo.c:3:
bar.c:92:2: warning: #warning gonzo
#warning gonzo
 ^

#3:
foo.c:102:2: warning: #warning bonkta
#warning bonkta
 ^

llvm-svn: 63722
2009-02-04 06:25:26 +00:00
Chris Lattner 0a1a8d8514 propagate linemarker flags down into the the line table, currently
ignoring include stack push/pop info though.

llvm-svn: 63719
2009-02-04 05:21:58 +00:00
Chris Lattner 1eaa70a612 stub out basic #line handling calls.
llvm-svn: 63667
2009-02-03 21:52:55 +00:00
Chris Lattner 60f36223a9 move library-specific diagnostic headers into library private dirs. Reduce
redundant #includes.  Patch by Anders Johnsen!

llvm-svn: 63271
2009-01-29 05:15:15 +00:00
Ted Kremenek 62224c1d7f Add more PTH diagnostics for invalid PTH files, etc.
llvm-svn: 63232
2009-01-28 21:02:43 +00:00
Ted Kremenek 3b0589e4b4 Enhance PTHManager::Create() to take an optional Diagnostic* argument that can be used to report issues such as a missing PTH file.
llvm-svn: 63231
2009-01-28 20:49:33 +00:00
Chris Lattner 7368d581c1 Split the single monolithic DiagnosticKinds.def file into one
.def file for each library.  This means that adding a diagnostic
to sema doesn't require all the other libraries to be rebuilt.

Patch by Anders Johnsen!

llvm-svn: 63111
2009-01-27 18:30:58 +00:00
Chris Lattner f1ca7d3e02 Introduce a new PresumedLoc class to represent the concept of a location
as reported to the user and as manipulated by #line.  This is what __FILE__,
__INCLUDE_LEVEL__, diagnostics and other things should follow (but not 
dependency generation!).  

This patch also includes several cleanups along the way: 

- SourceLocation now has a dump method, and several other places 
  that did similar things now use it.
- I cleaned up some code in AnalysisConsumer, but it should probably be
  simplified further now that NamedDecl is better.
- TextDiagnosticPrinter is now simplified and cleaned up a bit.

This patch is a prerequisite for #line, but does not actually provide 
any #line functionality.

llvm-svn: 63098
2009-01-27 07:57:44 +00:00
Chris Lattner bf648a3a63 Fix a bug that I noticed by inspection.
llvm-svn: 63094
2009-01-27 05:34:03 +00:00
Ted Kremenek 8d178f4357 PTH: Use Token::setLiteralData() to directly store a pointer to cached spelling data in the PTH file. This removes a ton of code for looking up spellings using sourcelocations in the PTH file. This simplifies both PTH-generation and reading.
Performance impact for -fsyntax-only on Cocoa.h (with Cocoa.h in the PTH file):
- PTH generation time improves by 5%
- PTH reading improves by 0.3%.

llvm-svn: 63072
2009-01-27 00:01:05 +00:00
Chris Lattner d381721810 Fix a bug I introduced in my changes, which caused MeasureTokenLength
to crash when given an instantiation location.  Thanks to Fariborz for
the testcase.

llvm-svn: 63057
2009-01-26 22:24:27 +00:00
Ted Kremenek 327d00cd45 Silence warning.
llvm-svn: 63054
2009-01-26 22:16:12 +00:00
Ted Kremenek 978b5becea Add version number checking to PTH files.
llvm-svn: 63047
2009-01-26 21:50:21 +00:00
Ted Kremenek eb8c8fbd63 Embed the offset of the PTH table inside the prologue of the PTH file. This will help improve gradual versioning of PTH files instead of relying that the PTH table is at a fixed offset.
llvm-svn: 63045
2009-01-26 21:43:14 +00:00
Chris Lattner 357b57d749 remove my hacks that aggressively threw away multiple
instantiation history in an effort to speed up c99-intconst-1.c.
Now that multiple nested instantiations are allowed, we just
make them and don't pay the cost of lookups.  With the other
changes that went in before this, reverting this is actually
a speedup for c99-intconst-1.c, speeding it up from 1.96s to 1.80s,
and preserves much better loc info.

llvm-svn: 63036
2009-01-26 20:24:53 +00:00
Chris Lattner 7e20927756 allow _Pragmas formed from #defines to keep their full instantiation
history

llvm-svn: 63035
2009-01-26 20:15:46 +00:00
Chris Lattner 5a7971e0c3 This change refactors some of the low-level lexer interfaces a bit.
Token now has a class of kinds for "literals", which include 
numeric constants, strings, etc.  These tokens can optionally have
a pointer to the start of the token in the lexer buffer.  This 
makes it faster to get spelling and do other gymnastics, because we
don't have to go through source locations.

This change is performance neutral, but will make other changes
more feasible down the road.

llvm-svn: 63028
2009-01-26 19:29:26 +00:00
Chris Lattner b5fba6f8d8 start plumbing together the line table information. So far we just
unique the Filenames in #line directives, assigning them UIDs.

llvm-svn: 63010
2009-01-26 07:57:50 +00:00
Chris Lattner 76e689636b add parsing and constraint enforcement for GNU line marker directives.
llvm-svn: 63003
2009-01-26 06:19:46 +00:00
Chris Lattner 38d7fd252a a few minor cleanups
llvm-svn: 63000
2009-01-26 05:30:54 +00:00
Chris Lattner 100c65e810 parse and enforce required constraints on #line directives. Right now
we just discard them.

llvm-svn: 62999
2009-01-26 05:29:08 +00:00
Chris Lattner ad13cf4e7a eagerly resolve the spelling locations of macro argument preexpansions.
This reduces fsyntax-only time on c99-intconst-1.c from 2.43s down to 
2.01s (20%), reducing the number of fileid lookups from 2529040 linear 
and 64771121 binary to 5625902 linear and 4151182 binary.

This knocks getFileID down to only 4.6% of compile time on this testcase.
At this point, malloc/free is over 35% of compile time, primarily allocating
MacroArgs objects and their argument preexpansion vectors.

I don't feel like malloc avoiding right now, so I'm just going to call
this good.

llvm-svn: 62994
2009-01-26 04:33:10 +00:00
Chris Lattner 5a5d67101b Eagerly resolve the spelling location of the tokens in a definition
of a macro.  Since these tokens may themselves be from macro 
expansions, we need to resolve down to the spelling loc when the
macro ends up being instantiated.  Instead of resolving this for
each token expanded from the macro definition, just do it once when
the macro is defined.  This speeds up clang on c99-intconst-1.c from
2.66s to 2.43s (9.5%), reducing the FileID lookups from 407244 linear and
114175649 binary to 2529040 linear and 64771121 binary.

llvm-svn: 62993
2009-01-26 04:06:48 +00:00
Chris Lattner dd9babc79a Only resolve a macro's instantiation loc once per macro, instead of once
per token lexed from it.  This speeds up clang on c99-intconst-1.c from
the GCC testsuite from 3.64s to 2.66s (36%).  This reduces the number of
binary search FileID lookups from 251570522 to 114175649 on this testcase.

llvm-svn: 62992
2009-01-26 03:46:22 +00:00
Chris Lattner 4fa23625ab Check in the long promised SourceLocation rewrite. This lays the
ground work for implementing #line, and fixes the "out of macro ID's" 
problem.

There is nothing particularly tricky about the code, other than the
very performance sensitive SourceManager::getFileID() method.

llvm-svn: 62978
2009-01-26 00:43:02 +00:00
Chris Lattner 1f6c7fe6a8 This is a follow-up to r62675:
Refactor how the preprocessor changes a token from being an tok::identifier to a 
keyword (e.g. tok::kw_for).  Instead of doing this in HandleIdentifier, hoist this
common case out into the caller, so that every keyword doesn't have to go through
HandleIdentifier.  This drops time in HandleIdentifier from 1.25ms to .62ms, and
speeds up clang -Eonly with PTH by about 1%.

llvm-svn: 62855
2009-01-23 18:35:48 +00:00
Chris Lattner f8ccb4f9e3 Update comment.
llvm-svn: 62819
2009-01-23 00:13:28 +00:00