aboutsummaryrefslogtreecommitdiff
path: root/lib/AST/ExprConstant.cpp
AgeCommit message (Collapse)Author
2011-12-12Clean up diagnostic wording for disallowed casts in C++11 constant expressions.Richard Smith
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146395 91177308-0d34-0410-b5e6-96231b3b80d8
2011-12-12Implement C++11 constant expression cast restrictions.Richard Smith
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146371 91177308-0d34-0410-b5e6-96231b3b80d8
2011-12-12Fix some not-yet-used diagnostic code in a template, which gcc spotted and clangRichard Smith
did not! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146366 91177308-0d34-0410-b5e6-96231b3b80d8
2011-12-12Prepare constant expression infrastructure for the generation of richerRichard Smith
diagnostics. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146365 91177308-0d34-0410-b5e6-96231b3b80d8
2011-12-10Add a fast path to the constant evaluator for integer literals. This speeds upRichard Smith
compilation of some translation units of SPEC's 445.gobmk by ~4%, and does not seem to cause a measurable slowdown in other cases. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146306 91177308-0d34-0410-b5e6-96231b3b80d8
2011-12-09C++11 constant expressions: Don't use CheckICE in C++11; instead, determineRichard Smith
whether an expression is a (core) constant expression as a side-effect of evaluation. This takes us from accepting far too few expressions as ICEs to accepting slightly too many -- fixes for the remaining cases are coming next. The diagnostics produced when an expression is found to be non-constant are currently quite poor (with generic wording but reasonable source locations), and will be improved in subsequent commits. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146289 91177308-0d34-0410-b5e6-96231b3b80d8
2011-12-09In ExprEvaluatorBase::VisitOpaqueValueExpr() add a sanity check to avoidArgyrios Kyrtzidis
infinite recursion due to bad OpaqueValueExpr. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146237 91177308-0d34-0410-b5e6-96231b3b80d8
2011-12-09Replace the implementation of __builtin_constant_p (which was based on the GCCRichard Smith
documentation) with one based on what GCC's __builtin_constant_p is actually intended to do (discovered by asking a friendly GCC developer). In particular, an expression which folds to a pointer is now only considered to be a "constant" by this builtin if it refers to the first character in a string literal. This fixes a rather subtle wrong-code issue when building with glibc. Given: const char cs[4] = "abcd"; int f(const char *p) { return strncmp(p, cs, 4); } ... the macro magic for strncmp produces a (potentially crashing) call to strlen(cs), because it expands to an expression starting with: __builtin_constant_p(cs) && strlen(cs) < 4 ? /* ... */ Under the secret true meaning of __builtin_constant_p, this is guaranteed to be safe! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146236 91177308-0d34-0410-b5e6-96231b3b80d8
2011-12-07When folding the size of a global scope VLA to a constant, require the arrayRichard Smith
bound to not have side effects(!). Add constant-folding support for expressions of void type, to ensure that we can still fold ((void)0, 1) as an array bound. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146000 91177308-0d34-0410-b5e6-96231b3b80d8
2011-12-06Move vector bitcast handling in constant expressions from the expressionRichard Smith
evaluator into constant initializer handling / IRGen. The practical consequence of this is that the bitcast now lives in the constant's definition, rather than in its uses. The code in the constant expression evaluator was producing vectors of the wrong type and size (and possibly of the wrong value for a big-endian int-to-vector bitcast). We were getting away with this only because we don't yet support constant-folding of any expressions which inspect vector values. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145981 91177308-0d34-0410-b5e6-96231b3b80d8
2011-12-05Make isWeakDecl available as a method on ValueDecl.Lang Hames
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145845 91177308-0d34-0410-b5e6-96231b3b80d8
2011-11-21Add driver arguments -ftemplate-depth=N and -fconstexpr-depth=N, with the sameRichard Smith
semantics and defaults as the corresponding g++ arguments. The historical g++ argument -ftemplate-depth-N is kept for compatibility, but modern g++ versions no longer document that option. Add -cc1 argument -fconstexpr-depth N to implement the corresponding functionality. The -ftemplate-depth=N part of this fixes PR9890. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145045 91177308-0d34-0410-b5e6-96231b3b80d8
2011-11-17Constant expression evaluation: add support for evaluation of member pointersRichard Smith
and base-to-derived casts, and add proper handling of temporaries. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144926 91177308-0d34-0410-b5e6-96231b3b80d8
2011-11-16PR11391: Don't try to evaluate the LHS of a _Complex assignment as an rvalue.Richard Smith
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144799 91177308-0d34-0410-b5e6-96231b3b80d8
2011-11-16Fix PR11385: A pointer constant expression which has been cast via an integer isRichard Smith
not safely derived. Don't allow lvalue-to-rvalue conversions on the result of dereferencing such a pointer. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144783 91177308-0d34-0410-b5e6-96231b3b80d8
2011-11-12Represent an APValue based on a Decl as that Decl, rather than a DeclRefExprRichard Smith
or MemberExpr which refers to it. As a side-effect, MemberExprs which refer to static member functions and static data members are now emitted as constant expressions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144468 91177308-0d34-0410-b5e6-96231b3b80d8
2011-11-11Constant expression evalation: const_cast support.Richard Smith
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144382 91177308-0d34-0410-b5e6-96231b3b80d8
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