Commit Graph

67 Commits

Author SHA1 Message Date
Anders Carlsson 5b3638b6e7 Generate the correct results for the comma expression. Fixes PR3123.
llvm-svn: 60334
2008-12-01 06:44:05 +00:00
Anders Carlsson 564730a857 Emit the correct diagnostic when a comma is in an ICE.
llvm-svn: 60316
2008-12-01 02:07:06 +00:00
Anders Carlsson b33d6c8611 Change the diagnostics that the evaluator reports to be of type NOTE.
llvm-svn: 60301
2008-11-30 18:37:00 +00:00
Anders Carlsson 5862001157 Replace the isEvaluated bool with a ShortCircuit int, making it easier to handle recursion
llvm-svn: 60300
2008-11-30 18:26:25 +00:00
Anders Carlsson 27b8c5c464 Pass the expression to the Error and Extension methods.
llvm-svn: 60299
2008-11-30 18:14:57 +00:00
Anders Carlsson 7b6f0af83f Add a new variant of Evaluate and reimplement the old Evaluate in terms of the new.
llvm-svn: 60298
2008-11-30 16:58:53 +00:00
Anders Carlsson f50de0c590 General cleanup, evaluate the RHS of a logical op even if the LHS will give us the result.
llvm-svn: 60297
2008-11-30 16:51:17 +00:00
Anders Carlsson bd1df8e866 EvalInfo now holds a reference to an EvalResult struct.
llvm-svn: 60296
2008-11-30 16:38:33 +00:00
Nuno Lopes 615f34c719 remove debug-only assertion in the complex float evaluator as it makes some real apps crash
llvm-svn: 60069
2008-11-26 00:39:53 +00:00
Anders Carlsson a42ee44aab The address of a variable is only constant if the variable has global storage.
llvm-svn: 59939
2008-11-24 04:41:22 +00:00
Anders Carlsson 4c76e93507 Fix bug in the constant evaluator. Fixes PR3115.
llvm-svn: 59938
2008-11-24 04:21:33 +00:00
Anders Carlsson 7c282e4f3f Return false if we encounter a type we can't handle.
llvm-svn: 59889
2008-11-22 22:56:32 +00:00
Anders Carlsson 475f4bce36 Case values must be evaluated
llvm-svn: 59884
2008-11-22 21:50:49 +00:00
Anders Carlsson 59689ed764 Use Expr::Evaluate for case statements. Fixes PR2525
llvm-svn: 59881
2008-11-22 21:04:56 +00:00
Nuno Lopes 0e33c688d5 fix folding of '*doubleArray'
llvm-svn: 59647
2008-11-19 17:44:31 +00:00
Anders Carlsson 899c7050b6 Address some comments Eli had.
llvm-svn: 59430
2008-11-16 22:46:56 +00:00
Nuno Lopes 527b5a6858 use HandleConversionToBool() to check if a given cond is foldable (per Eli's comment)
llvm-svn: 59429
2008-11-16 22:06:39 +00:00
Anders Carlsson 9ddf7bedf9 More complex float evaluator support.
llvm-svn: 59428
2008-11-16 21:51:21 +00:00
Chris Lattner 67d7b9204c rename Expr::tryEvaluate to Expr::Evaluate.
llvm-svn: 59426
2008-11-16 21:24:15 +00:00
Anders Carlsson 537969c237 Add very limited support for evaluating complex floats.
llvm-svn: 59425
2008-11-16 20:27:53 +00:00
Nuno Lopes e236a48210 fix folding of comma if given a non-constant operand.
Eli please take a look, as I'm not sure if this gets the extension warning in the right place

llvm-svn: 59422
2008-11-16 20:09:07 +00:00
Nuno Lopes 420426100c make IntExprEvaluator fold the ?: operator
llvm-svn: 59421
2008-11-16 19:28:31 +00:00
Anders Carlsson 9f9e4249cc More work on the constant evaluator. Eli, it would be great if you could have a look at this.
llvm-svn: 59420
2008-11-16 19:01:22 +00:00
Anders Carlsson acc7981883 Add the ability to evaluate comparison operators with floating point numbers as operands.
llvm-svn: 59408
2008-11-16 07:17:21 +00:00
Eli Friedman 5a332ea01f Fix for crash issues with comma operators with a void first operand, and
some more bullet-proofing/enhancements for tryEvaluate.  This shouldn't 
cause any behavior changes except for handling cases where we were 
crashing before and being able to evaluate a few more cases in tryEvaluate.
 
This should settle the minor mess surrounding r59196.

llvm-svn: 59224
2008-11-13 06:09:17 +00:00
Eli Friedman 8553a98b8e Backout of r59196, plus a new ICE test. Sorry if this is a
little rude; I figure it's cleaner to just back this out now so 
it doesn't get forgotten or mixed up with other checkins.

The modification to isICE is simply wrong; I've added a test that the 
change to isICE breaks.

I'm pretty sure the modification to tryEvaluate is also wrong.  
At the very least, there's some serious miscommunication going on here, 
as this is going in exactly the opposite direction of r59105.  My 
understanding is that tryEvaluate is not supposed to care about side 
effects.  That said, a lot of the clients to tryEvaluate are 
expecting it to enforce a no-side-effects policy, so we probably need 
another method that provides that guarantee.

llvm-svn: 59212
2008-11-13 02:13:11 +00:00
Daniel Dunbar c7ec5fcf24 Fix bug in constant evaluation exposed by 176.gcc.
- Evaluation of , operator used bogus assumption that LHS could be
   evaluated as an integral expression even though its type is
   unspecified.

This change is making isICE very permissive of the LHS in non-evaluated 
contexts because it is not clear what predicate we would use to reject 
code here. The standard didn't offer me any guidance; opinions?

llvm-svn: 59196
2008-11-13 00:03:19 +00:00
Daniel Dunbar a461e6d124 Disable some debug prints.
llvm-svn: 59174
2008-11-12 21:52:46 +00:00
Eli Friedman 9a156e5c1e Some additions to tryEvaluate I've had sitting around for a while.
This pushes it a lot closer to being able to deal with most of the stuff 
CodeGen's constant expression evaluator knows how to deal with.  This 
also fixes PR3003.

The test could possibly use some improvement, but this'll work for now.  
Test 6 is inspired by PR3003; the other tests are mostly just designed
to exercise the new code.  The reason for the funny structure of the 
tests is that type fixing for arrays inside of structs is the only place 
in Sema that calls tryEvaluate, at least for the moment.

llvm-svn: 59125
2008-11-12 09:44:48 +00:00
Chris Lattner fac05aeae5 fix a crash analyzing constants in 176.gcc/expr.c with my next patch. It was
crashing because we errors are ignored in subexpressions that are not evaluated,
but we still evaluate the result of parents.  This would cause an assertion 
because the erroneous subexpr didn't have its result value set to the right type.

llvm-svn: 59110
2008-11-12 07:43:42 +00:00
Chris Lattner aa3f951efc Teach the aggressive constant folder to fold X && 0 -> 0 and X || 1 -> 1
llvm-svn: 59105
2008-11-12 07:04:29 +00:00
Sebastian Redl 6f28289aca Introduce a single AST node SizeOfAlignOfExpr for all sizeof and alignof expressions, both of values and types.
llvm-svn: 59057
2008-11-11 17:56:53 +00:00
Daniel Dunbar d7be95d60a PR2919: __builtin_types_compatible_p strips CRV qualifiers.
llvm-svn: 58079
2008-10-24 08:07:57 +00:00
Daniel Dunbar c3d79cf6b3 Teach tryEvaluate that fabs, copysign, and unary +/- are constants for
floats.
 - With testcase, which also has some other things GCC folds but we
   don't commented out in it.

llvm-svn: 57624
2008-10-16 03:51:50 +00:00
Daniel Dunbar 1be9f88a2f Fix test suite regression, getFloatTypeSemantics shouldn't be called
on non-float types.

llvm-svn: 57477
2008-10-14 05:41:12 +00:00
Dale Johannesen c48814bc98 Adjust calls to APFloat conversion for new interface.
llvm-svn: 57332
2008-10-09 23:02:32 +00:00
Chris Lattner 2c091b1ead ExprConstant should not abort when it sees a pointer constant that isn't.
llvm-svn: 57162
2008-10-06 07:20:11 +00:00
Chris Lattner cb13691a62 Add a Expr::isEvaluatable method, eliminate isBuiltinConstantExpr
which is checking for something that can be inconsistent with
what we can constant fold.

llvm-svn: 57159
2008-10-06 06:49:02 +00:00
Chris Lattner 86ee286b09 Move folding of __builtin_classify_type out of the CallExpr
interface into the constant folding interface.

llvm-svn: 57158
2008-10-06 06:40:35 +00:00
Chris Lattner 0b7282eafc Move handling of __builtin_nan("") out of CGBuiltin.cpp into ExprConstant.cpp
llvm-svn: 57157
2008-10-06 06:31:58 +00:00
Chris Lattner 37346e081c Teach FloatExprEvaluator to evaluate __builtin_huge_val and inf.
llvm-svn: 57154
2008-10-06 05:53:16 +00:00
Chris Lattner 4deaa4ea24 Add a comment that describes tryEvaluate. Make tryEvaluate fold
__builtin_constant_p properly, and add some scaffolding for
FloatExprEvaluator to eventually handle huge_val and inf.

llvm-svn: 57152
2008-10-06 05:28:25 +00:00
Eli Friedman 24c0154b77 Initial implementation of floats in Expr::tryEvaluate; this doesn't
implement some things, like unary operators and casts, but it's enough
to fix PR2703 as filed.

llvm-svn: 55155
2008-08-22 00:06:13 +00:00
Argyrios Kyrtzidis 3bab3d21f9 Add ExplicitCastExpr to replace the current CastExpr, and have ImplicitCastExpr and ExplicitCastExpr derive from a common base class (CastExpr):
Expr
  -> CastExpr
     -> ExplicitCastExpr
     -> ImplicitCastExpr 

llvm-svn: 54955
2008-08-18 23:01:59 +00:00
Daniel Dunbar 56fdb6ae69 More #include cleaning
- Kill unnecessary #includes in .cpp files. This is an automatic
   sweep so some things removed are actually used, but happen to be
   included by a previous header. I tried to get rid of the obvious
   examples and this was the easiest way to trim the #includes in one
   fell swoop.
 - We now return to regularly scheduled development.

llvm-svn: 54632
2008-08-11 06:23:49 +00:00
Anders Carlsson d361a7df78 Remove the old evaluator code.
llvm-svn: 54615
2008-08-10 17:03:01 +00:00
Eli Friedman 5cf85cc977 Turn on the new constant expression evaluator; it isn't
anywhere near complete, but I don't know of any issues, and it can 
handle enough to allow removing the I-C-E pointer cast hack.

llvm-svn: 54597
2008-08-09 22:21:56 +00:00
Eli Friedman bd84059cdb Minor tweak plus a couple of FIXMEs.
llvm-svn: 54119
2008-07-27 05:46:18 +00:00
Chris Lattner 477c4be1e9 expand casts to handle what isIntegerConstantExpr handles.
Casts from pointers remain a problem. :)

llvm-svn: 53501
2008-07-12 01:15:53 +00:00
Chris Lattner 7174bf3722 Add support for __builtin_type_compatible_p, enums, etc.
llvm-svn: 53500
2008-07-12 00:38:25 +00:00