aboutsummaryrefslogtreecommitdiff
path: root/lib/AST/ExprConstant.cpp
AgeCommit message (Collapse)Author
2011-11-11Reduce the constexpr stack pressure somewhat. Hopefully this will be enough toRichard Smith
please the buildbots. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144375 91177308-0d34-0410-b5e6-96231b3b80d8
2011-11-11Constant expression evaluation: support for constexpr member functions. ThisRichard Smith
reinstates r144273; a combination of r144333's fix for NoOp rvalue-to-lvalue casts and some corresponding changes here resolve the regression which that caused. This patch also adds support for some additional forms of member function call, along with additional testing. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144369 91177308-0d34-0410-b5e6-96231b3b80d8
2011-11-10Revert r144273. It causes clang self-host build failure.Devang Patel
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144296 91177308-0d34-0410-b5e6-96231b3b80d8
2011-11-10Constant expression evaluation: support for constexpr member functions.Richard Smith
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144273 91177308-0d34-0410-b5e6-96231b3b80d8
2011-11-10Constant expression evaluation: support for evaluation of structs and unions ofRichard Smith
literal types, as well as derived-to-base casts for lvalues and derived-to-virtual-base casts. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144265 91177308-0d34-0410-b5e6-96231b3b80d8
2011-11-10Temporary fix for a performance problem Eli spotted. The APValue representationRichard Smith
is currently too inefficient to allow us to use it for array initializers, but fortunately we usually don't yet need to evaluate such initializers. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144260 91177308-0d34-0410-b5e6-96231b3b80d8
2011-11-09Constant expression evaluation: support for default arguments.Richard Smith
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144156 91177308-0d34-0410-b5e6-96231b3b80d8
2011-11-08Fix a cluster of related issues involving value-dependence and constantRichard Smith
expression evaluation: - When folding a non-value-dependent expression, we may try to use the initializer of a value-dependent variable. If that happens, give up. - In C++98, actually check that a const, non-volatile DeclRefExpr inside an ICE is of integral or enumeration type (a reference isn't OK!) - In C++11, DeclRefExprs for objects of const literal type initialized with value-dependent expressions are themselves value-dependent. - So are references initialized with value-dependent expressions (though this case is missing from the C++11 standard, along with many others). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144056 91177308-0d34-0410-b5e6-96231b3b80d8
2011-11-07Constant expression evaluation: support for arrays.Richard Smith
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143922 91177308-0d34-0410-b5e6-96231b3b80d8
2011-11-07Rip out CK_GetObjCProperty.John McCall
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143910 91177308-0d34-0410-b5e6-96231b3b80d8
2011-11-07Constant expression evaluation: preserve subobject designator when flattening aRichard Smith
core constant value down to an APValue. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143909 91177308-0d34-0410-b5e6-96231b3b80d8
2011-11-07Allow constexpr variables' initializers to be folded in C++11 mode. ThisRichard Smith
partially undoes the revert in r143491, but does not introduce any new instances of the underlying issue (which is not yet fixed) in code which does not use the 'constexpr' keyword. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143905 91177308-0d34-0410-b5e6-96231b3b80d8
2011-11-06Change the AST representation of operations on Objective-CJohn McCall
property references to use a new PseudoObjectExpr expression which pairs a syntactic form of the expression with a set of semantic expressions implementing it. This should significantly reduce the complexity required elsewhere in the compiler to deal with these kinds of expressions (e.g. IR generation's special l-value kind, the static analyzer's Message abstraction), at the lower cost of specifically dealing with the odd AST structure of these expressions. It should also greatly simplify efforts to implement similar language features in the future, most notably Managed C++'s properties and indexed properties. Most of the effort here is in dealing with the various clients of the AST. I've gone ahead and simplified the ObjC rewriter's use of properties; other clients, like IR-gen and the static analyzer, have all the old complexity *and* all the new complexity, at least temporarily. Many thanks to Ted for writing and advising on the necessary changes to the static analyzer. I've xfailed a small diagnostics regression in the static analyzer at Ted's request. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143867 91177308-0d34-0410-b5e6-96231b3b80d8
2011-11-04Remove unused variables.Benjamin Kramer
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143696 91177308-0d34-0410-b5e6-96231b3b80d8
2011-11-04Constant expression evaluation: refactor to start the groundwork for coping withRichard Smith
initializations which refer indirectly to elements of the object being initialized. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143680 91177308-0d34-0410-b5e6-96231b3b80d8
2011-11-04Constant expression evaluation: track the manner in which an lvalue was written,Richard Smith
to allow us to implement the C++11 rule that a non-active union member can't be read, and use it to implement subobject access for string literals. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143677 91177308-0d34-0410-b5e6-96231b3b80d8
2011-11-04Constant expression evaluation: although we don't know whether a literal willRichard Smith
be at the same address as another object, we do know it won't alias a null pointer. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143674 91177308-0d34-0410-b5e6-96231b3b80d8
2011-11-01When constant-folding, don't look at the initializer of a global const variableRichard Smith
if it's marked as weak: that definition may not end up being used. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143496 91177308-0d34-0410-b5e6-96231b3b80d8
2011-11-01Temporarily disable lvalue-to-rvalue conversions on const pointers while anRichard Smith
apparent miscompile triggered by this is investigated. This is essentially a revert of r143298. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143491 91177308-0d34-0410-b5e6-96231b3b80d8
2011-11-01Implement C++11 'constexpr calls must return constant expressions' rule, andRichard Smith
perform the code simplifications this rule allows. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143463 91177308-0d34-0410-b5e6-96231b3b80d8
2011-10-31Some minor comment changes in constant-folding comparisons.Eli Friedman
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143391 91177308-0d34-0410-b5e6-96231b3b80d8
2011-10-31Don't try to fold comparisons between the address of an object and an ↵Eli Friedman
arbitrary integer constant. Fixes regression from r143334. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143374 91177308-0d34-0410-b5e6-96231b3b80d8
2011-10-31Refactoring and test for r143360. Support for array rvalue to pointer decay isRichard Smith
needed for C++11, and will follow later. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143363 91177308-0d34-0410-b5e6-96231b3b80d8
2011-10-31Temporary fix for assert while evaluating array-to-pointer decay on arrayRichard Smith
rvalue. Test and better fix to follow. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143360 91177308-0d34-0410-b5e6-96231b3b80d8
2011-10-31C++11 generalized constant expression handling: evaluation support forRichard Smith
materialized temporaries. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143335 91177308-0d34-0410-b5e6-96231b3b80d8
2011-10-31C++11 generalized constant expressions: evaluate equality comparisons betweenRichard Smith
arbitrary pointers, if those pointers don't point to weak objects or literals. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143334 91177308-0d34-0410-b5e6-96231b3b80d8
2011-10-31C++11 generalized constant expressions: support pointer comparisons where theRichard Smith
result is not unspecified. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143329 91177308-0d34-0410-b5e6-96231b3b80d8
2011-10-30Fix assert on constant expression evaluation of floating point increment.Richard Smith
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143320 91177308-0d34-0410-b5e6-96231b3b80d8
2011-10-29Don't crash if a GCC binary conditional is used in a constant expression on anRichard Smith
integer-cast pointer value. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143299 91177308-0d34-0410-b5e6-96231b3b80d8
2011-10-29constexpr evaluation: allow lvalue-to-rvalue conversion on any literal type, notRichard Smith
just integers and floating point types. Since we don't support evaluating class types or performing lvalue-to-rvalue conversions on array elements yet, this just means pointer types right now. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143298 91177308-0d34-0410-b5e6-96231b3b80d8
2011-10-29constexpr function substitution:Richard Smith
Track the function invocation where an lvalue referring to a constexpr function parameter originated from, and use it to substitute the correct argument and to determine whether such an argument's lifetime has ended. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143296 91177308-0d34-0410-b5e6-96231b3b80d8
2011-10-29Rename Expr::Evaluate to Expr::EvaluateAsRValue to make it clear that it willRichard Smith
implicitly perform an lvalue-to-rvalue conversion if used on an lvalue expression. Also improve the documentation of Expr::Evaluate* to indicate which of them will accept expressions with side-effects. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143263 91177308-0d34-0410-b5e6-96231b3b80d8
2011-10-28Fix assertion in constant expression evaluation. The LHS of a floating-pointRichard Smith
binary operator isn't an rvalue if it's an assignment operator. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143250 91177308-0d34-0410-b5e6-96231b3b80d8
2011-10-28Initial support for C++11 constexpr function invocation substitution. UsingRichard Smith
constexpr function arguments outside of their function (passing or returning them by reference) does not work correctly yet. Calling constexpr function templates does not work yet, since the bodies are not instantiated until the end of the translation unit. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143234 91177308-0d34-0410-b5e6-96231b3b80d8
2011-10-28Reinstate r142844 (reverted in r142872) now that lvalue-to-rvalue conversionsRichard Smith
are present in all the necessary places: In constant expression evaluation, evaluate lvalues as lvalues and rvalues as rvalues. Remove special case for caching reference initialization and fix a cyclic initialization crash in the process. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143204 91177308-0d34-0410-b5e6-96231b3b80d8
2011-10-25Clean up, as suggested by John.Richard Smith
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142884 91177308-0d34-0410-b5e6-96231b3b80d8
2011-10-24Revert r142844, it broke selfhost. The problem appears to be a missingRichard Smith
lvalue-to-rvalue conversion on the LHS operand of '->'. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142872 91177308-0d34-0410-b5e6-96231b3b80d8
2011-10-24Add explanatory comments for ICE checking in C99 mode.Richard Smith
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142866 91177308-0d34-0410-b5e6-96231b3b80d8
2011-10-24Constant expression evaluation: evaluate lvalues as lvalues, and rvalues asRichard Smith
rvalues, as C++11 constant evaluation semantics require. DeclRefs referring to references can now use the normal initialization-caching codepath, which incidentally fixes a crash in cyclic initialization of references. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142844 91177308-0d34-0410-b5e6-96231b3b80d8
2011-10-24Constant expression evaluation: factor out handling of ignored values.Richard Smith
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142835 91177308-0d34-0410-b5e6-96231b3b80d8
2011-10-24In accordance with the C89, C99 and C++98 standards, ICEs can only containRichard Smith
floating-point literals if they are the immediate operands of casts. ImplicitCastExpr is not a cast in the language-standards sense. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142832 91177308-0d34-0410-b5e6-96231b3b80d8
2011-10-24Constant expression evaluation: factor out VarDecl initializer evaluation andRichard Smith
caching. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142812 91177308-0d34-0410-b5e6-96231b3b80d8
2011-10-22Refactor vector constant expression evaluation to return bool like all the otherRichard Smith
const expression evaluation subclasses, and remove some APValue copying and malloc traffic in the process. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142733 91177308-0d34-0410-b5e6-96231b3b80d8
2011-10-17Initial implementation of __atomic_is_lock_free. The input is the size of ↵Eli Friedman
an atomic type rather than an atomic type itself just to save some implementation pain; I can change that if it seems worthwhile. I think this is the last hook needed for <atomic> besides defines for ATOMIC_CHAR_LOCK_FREE and friends. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142281 91177308-0d34-0410-b5e6-96231b3b80d8
2011-10-16Split apart the state accumulated during constant expression evaluation and theRichard Smith
end result. Use this split to propagate state information and diagnostics through more of constant expression evaluation. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142159 91177308-0d34-0410-b5e6-96231b3b80d8
2011-10-11Constant expression evaluation: refactor value initialization and scalar ↵Richard Smith
list initialization into base class. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@141717 91177308-0d34-0410-b5e6-96231b3b80d8
2011-10-11Initial implementation of __atomic_* (everything except __atomic_is_lock_free).Eli Friedman
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@141632 91177308-0d34-0410-b5e6-96231b3b80d8
2011-10-11Extend lvalue evaluation in ExprConstant.cpp to handle CK_LValueBitCast ↵Eli Friedman
(which is completely trivial). PR8836. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@141604 91177308-0d34-0410-b5e6-96231b3b80d8
2011-10-10Constant expression evaluation refactoring:Richard Smith
- Remodel Expr::EvaluateAsInt to behave like the other EvaluateAs* functions, and add Expr::EvaluateKnownConstInt to capture the current fold-or-assert behaviour. - Factor out evaluation of bitfield bit widths. - Fix a few places which would evaluate an expression twice: once to determine whether it is a constant expression, then again to get the value. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@141561 91177308-0d34-0410-b5e6-96231b3b80d8
2011-09-29PR11040: CheckICE should not allow an lvalue bitcast as part of an integer ↵Eli Friedman
constant expression. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140812 91177308-0d34-0410-b5e6-96231b3b80d8