Commit Graph

234 Commits

Author SHA1 Message Date
Chris Lattner 89399da91a fixme done!
llvm-svn: 39407
2007-04-11 04:16:36 +00:00
Chris Lattner 99ca091b9c Warn when performing 'usual' conversions that require a sign change. This
implements test/Preprocessor/expr_usual_conversions.c, which produces this
output:

expr_usual_conversions.c:5:10: warning: left side of operator converted from negative value to unsigned: -42 to 18446744073709551574
#if (-42 + 0U) / -2
         ^
expr_usual_conversions.c:5:16: warning: right side of operator converted from negative value to unsigned: -2 to 18446744073709551614
#if (-42 + 0U) / -2
               ^

llvm-svn: 39406
2007-04-11 04:14:45 +00:00
Chris Lattner 8ec9355a48 Overflow detection for multiply and divide. Fix a bug handling 'usual
arithmetic conversions'.

llvm-svn: 39405
2007-04-11 04:04:29 +00:00
Chris Lattner 7e61ac5a3c Catch overflow of negate. This allows us to emit:
t.c:2:17: warning: integer overflow in preprocessor expression
#if -(INTMAX_MAX+1)
                ^
t.c:2:5: warning: integer overflow in preprocessor expression
#if -(INTMAX_MAX+1)
    ^

GCC has some seriously confused source locations in this case:
t.c:2:19: warning: integer overflow in preprocessor expression
t.c:2:20: warning: integer overflow in preprocessor expression

column 19/20 are off the end of the line.

llvm-svn: 39404
2007-04-11 03:42:36 +00:00
Chris Lattner 028c7decef Overflow detection for +/-
llvm-svn: 39403
2007-04-11 03:34:29 +00:00
Chris Lattner 9cc755d535 Evaluate result into an explicit destination. No functionality change.
llvm-svn: 39402
2007-04-10 07:07:11 +00:00
Chris Lattner 5a0f164a52 Track overflow of shift amounts, allowing diagnostics like:
t.c:6:7: warning: integer overflow in preprocessor expression
#if 1 << 63
      ^
t.c:8:7: warning: integer overflow in preprocessor expression
#if 4 << 62
      ^
t.c:10:7: warning: integer overflow in preprocessor expression
#if 4 << 66
      ^

but no diagnostic on:
#if 1U << 63

llvm-svn: 39400
2007-04-10 06:54:33 +00:00
Chris Lattner a7fa1b247c 'true' in a CPP expression evaluates to 1 when in C++ mode. This implements
test/Preprocessor/cxx_true.cpp

llvm-svn: 39399
2007-04-10 06:16:30 +00:00
Chris Lattner 7c718bd5a4 Include the filename being looked up in an error message. This gives us stuff
like this:
t3.c:5:10: error: 'vers2.h' file not found
#include xstr(INCFILE(2).h)
         ^

instead of:

t3.c:5:10: error: file not found
#include xstr(INCFILE(2).h)
         ^

which is useful if the #include name is generated through macro expansion.

llvm-svn: 39398
2007-04-10 06:02:46 +00:00
Chris Lattner 86054a9634 Diagnostics relating to computation of values should only be produced if an
expression is live.  For example:
#if 0 ? 124/0 : 42

should cause no error.

This implements test/Preprocessor/expr_liveness.c

llvm-svn: 39397
2007-04-10 05:26:38 +00:00
Chris Lattner f8a0b0fa50 Add support for character constants in PP expressions, like:
#if 'a'

llvm-svn: 39393
2007-04-05 06:58:56 +00:00
Chris Lattner 2f5add6272 Implement support for performing semantic analysis of character literals.
llvm-svn: 39390
2007-04-05 06:57:15 +00:00
Chris Lattner a9eac7ff44 Correctly represent and propagate signedness information in preprocessor
constant expressions.  This allows us to emit this diagnostic:

t.c:5:5: warning: integer constant is so large that it is unsigned
#if 12345678901234567890
    ^

And makes constant evaluation fully correct, but we do not yet detect and
warn about integer overflow.

This patch requires cvs up'ing the main llvm tree to get the APSInt class,
but no libraries need to be rebuilt there.

llvm-svn: 39388
2007-04-05 05:24:00 +00:00
Chris Lattner 6df7975ae6 minor cleanups. The major missing piece is tracking:
* signedness of values
 * overflow of intermediate computations.

llvm-svn: 39387
2007-04-04 06:54:19 +00:00
Chris Lattner 531efa43d8 Ah, this is already correctly rejected!
llvm-svn: 39386
2007-04-04 06:49:26 +00:00
Chris Lattner ce5dc8a6b4 Switch PPExpression parsing to be in terms of APInt's whose widths are properly
sized to the target's intmax_t.  This also allows us to emit diagnostic like:

t.c:11:5: warning: integer constant is too large for its type
#if 18446744073709551616  // 2^64
    ^
t.c:15:5: warning: integer constant is too large for its type
#if 18446744073709551617  // 2^64-1
    ^

llvm-svn: 39385
2007-04-04 06:46:55 +00:00
Chris Lattner 871b4e101c Minor enhancements to GetIntegerValue(APInt):
* Detect overflow correctly.  When it occurs, return the truncated value.
  * Add fixme for radix analysis.

llvm-svn: 39382
2007-04-04 06:36:34 +00:00
Chris Lattner 5b743d3801 Add some really simplistic code for turning a ppnumber into an APInt. Much
improvement is needed!

llvm-svn: 39381
2007-04-04 05:52:58 +00:00
Chris Lattner 23d890337b Specify an initial size for StringMap.
llvm-svn: 39378
2007-04-03 22:14:25 +00:00
Steve Naroff f1e53698a4 Bug #:
Submitted by:
Reviewed by:

Type Checking...round 2. This checkin "breaks" parsing carbon.h. I imagine
that this will be true for the next week or so. Nevertheless, this round of
changes includes the following:

- Hacked various Expr classes to pass the appropriate TypeRef. Still have
a few more classes to touch.
- Implement type checking for ParseArraySubscriptExpr and ParseMemberReferenceExpr.
- Added a debug hook to derive the class name for Stmt/Expr nodes. Currently a
linear search...could easily optimize if important.
- Changed the name of TaggedType->TagType. Now we have TagType and TagDecl (which
are easier to remember).
- Fixed a bug in StringLiteral conversion I did a couple weeks ago. hadError was
not initialized (oops).
- changed Sema::Diag to return true. This streamlines the type checking code
considerably.
- Added many diagnositics.

This should be it!

llvm-svn: 39361
2007-03-23 22:27:02 +00:00
Steve Naroff 4f88b3113e Bug #:
Submitted by:
Reviewed by:
Move string literal parsing from Sema=>LiteralSupport. This consolidates
all the quirky parsing code within the Lexer subsystem (yeah!). This
simplifies Sema and (more importantly) allows future parsers
(i.e. subclasses of Action) to benefit from this code.

llvm-svn: 39354
2007-03-13 22:37:02 +00:00
Steve Naroff f2fb89e759 Bug #:
Submitted by:
Reviewed by:
Misc. cleanup/polish of NumericLiteralParser and it's two clients, the
C preprocessor and AST builder...

llvm-svn: 39353
2007-03-13 20:29:44 +00:00
Steve Naroff 451d8f1626 Bug #:
Submitted by:
Reviewed by:
-Converted the preprocessor to use NumericLiteralParser.
-Several minor changes to LiteralSupport interface/implementation.
-Added an error diagnostic for floating point usage in pp expr's.

llvm-svn: 39352
2007-03-12 23:22:38 +00:00
Steve Naroff 09ef474197 Bug #:
Submitted by:
Reviewed by:
Moved numeric literal support from SemaExpr.cpp to LiteralSupport.[h,cpp]
in Lex. This will allow it to be used by both Sema and Preprocessor (and
should be the last major refactoring of this sub-system).. Over
time, it will be reused by anyone implementing an actions module (i.e.
any subclass of llvm::clang::Action. Minor changes to IntegerLiteral in Expr.h.
More to come...

llvm-svn: 39351
2007-03-09 23:16:33 +00:00
Chris Lattner b055f2ddfc switch to using iterators instead of stringmap visitors.
llvm-svn: 39336
2007-02-11 08:19:57 +00:00
Chris Lattner 54d032bb76 CStringMap -> StringMap.
llvm-svn: 39334
2007-02-08 19:24:25 +00:00
Chris Lattner 34d1f5a8de adjust to CStringMap interface change.
llvm-svn: 39333
2007-02-08 19:08:49 +00:00
Chris Lattner 9561a0b3e7 Add support for target-independent builtin functions (like __builtin_abs),
whose decl objects are lazily created the first time they are referenced.
Builtin functions are described by the clang/AST/Builtins.def file, which
makes it easy to add new ones.

This is missing two important pieces:
1. Support for the rest of the gcc builtins.
2. Support for target-specific builtins (e.g. __builtin_ia32_emms).

Just adding this builtins reduces the number of implicit function definitions
by 6, reducing the # diagnostics from 550 to 544 when parsing carbon.h.

I need to add all the i386-specific ones to eliminate several hundred more.
ugh.

llvm-svn: 39327
2007-01-28 08:20:04 +00:00
Chris Lattner 3e7592ea78 Add support for -fno-operator-names, patch by Bill.
llvm-svn: 39245
2006-12-04 07:48:37 +00:00
Chris Lattner 652c16924e Produce a nice error message for '#define and' in C++. Patch by Bill!
llvm-svn: 39218
2006-11-21 23:47:30 +00:00
Chris Lattner 2bb8a95389 eliminate string compares when checking for the 'defined' token.
llvm-svn: 39216
2006-11-21 22:24:17 +00:00
Chris Lattner 5b9f4891d7 Add support for C++ operator keywords. Patch by Bill Wendling.
llvm-svn: 39214
2006-11-21 17:23:33 +00:00
Chris Lattner b352e3edb5 Change KeepComments/KeepMacroComments modes to be facets of the preprocessor
state, not aspects of the language standard being parsed.

llvm-svn: 39209
2006-11-21 06:17:10 +00:00
Chris Lattner ad7cdd37b3 simplify the Preprocessor ctor.
llvm-svn: 39208
2006-11-21 06:08:20 +00:00
Chris Lattner b8d6d5a81d Formalize preprocessor callbacks together into a PPCallbacks structure, instead
of having a loose collection of function pointers.  This also allows clients to
maintain state, and reduces the size of the Preprocessor.h interface.

llvm-svn: 39203
2006-11-21 04:09:30 +00:00
Chris Lattner c95c8f2356 Fix a bug
llvm-svn: 39128
2006-11-05 07:59:22 +00:00
Chris Lattner cf6bc66421 silence some warnings when asserts are disabled.
llvm-svn: 39127
2006-11-05 07:59:08 +00:00
Chris Lattner 57dd8360f6 implement FIXME: replace use of alloca with use of SmallVector.
llvm-svn: 39102
2006-11-03 07:45:04 +00:00
Chris Lattner 7cee11f078 Export the ASTBuilder class from the AST module.
llvm-svn: 39095
2006-11-03 06:42:29 +00:00
Chris Lattner 9f6604fa60 Add altivec version of block comment skipping code.
llvm-svn: 39093
2006-10-30 20:01:22 +00:00
Chris Lattner c07ba1fe2f Refactor the paths used for checking and getting the spelling of #include
filenames (and also '#pragma GCC dependency' of course).  Now, assuming
no cleaning is needed, we can go all the way from lexing the filename to
doing filename lookups with no mallocs.  This speeds up user PP time from
0.077 to 0.075s for Cocoa.h (2.6%).

llvm-svn: 39092
2006-10-30 05:58:32 +00:00
Chris Lattner b8b94f1e9b Make Preprocessor::LookupFile take a character range instead of a string.
This avoids some copying in its clients.

llvm-svn: 39091
2006-10-30 05:38:06 +00:00
Chris Lattner 7cdbad945d Push strings out of the HeaderSearch interface, it now deals solely with
character ranges.

llvm-svn: 39090
2006-10-30 05:33:15 +00:00
Chris Lattner ee7bf89cd6 Change framework cache map from map to CStringMap. This speeds up PP user
time on Cocoa.h from 0.078 to 0.077s.

llvm-svn: 39089
2006-10-30 05:19:23 +00:00
Chris Lattner b201d9b13d Eliminate string use in DoFrameworkLookup. This speeds up pp of Cocoa.h
marginally from 0.079 to 0.078s.

llvm-svn: 39088
2006-10-30 05:09:49 +00:00
Chris Lattner cf8ddac4bc Use SmallString instead of string in HeaderSearch::LookupFile. This avoids
malloc traffic, speeding up user time preprocessing Carbon.h 5% (0.083s to
0.079s).

llvm-svn: 39087
2006-10-30 04:42:33 +00:00
Chris Lattner 43fd42e4d9 Wean LookupSubframeworkHeader off std::strings, use the new SmallString
class instead.  SmallString allows to code to avoid hitting malloc in
the normal case (or will, when some other stuff is converted over).

llvm-svn: 39084
2006-10-30 03:40:58 +00:00
Chris Lattner da933aac0c remove some temporary testing code
llvm-svn: 39080
2006-10-29 23:49:15 +00:00
Chris Lattner 2b9e19be87 Pull the string hashtable out of the IdentifierTable, moving into LLVM's
libsupport.  Now it can be used for other things besides identifier hashing.

llvm-svn: 39079
2006-10-29 23:43:13 +00:00
Chris Lattner ec659fce46 move memory allocation abstraction stuff out into LLVM's libsupport
llvm-svn: 39078
2006-10-29 22:09:44 +00:00