summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/ExprConstant.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* AST/ExprConstant.cpp: Silence a warning on ms cl.exe. "bool" does not prefer ↵NAKAMURA Takumi2012-01-261-1/+1
| | | | | | to be compared to integer. llvm-svn: 149059
* constexpr: evaluate (bool)&x as true when x is a local variable or a temporary.Richard Smith2012-01-261-4/+0
| | | | llvm-svn: 149045
* constexpr: add support for anonymous struct and union members in literal types.Richard Smith2012-01-251-18/+61
| | | | llvm-svn: 148987
* More dead code removal (using -Wunreachable-code)David Blaikie2012-01-201-9/+1
| | | | llvm-svn: 148577
* Move narrowing conversion detection code from SemaInit to SemaOverload, readyRichard Smith2012-01-181-27/+38
| | | | | | | | | | | | | for it to be used in converted constant expression checking, and fix a couple of issues: - Conversion operators implicitly invoked prior to the narrowing conversion were not being correctly handled when determining whether a constant value was narrowed. - For conversions from floating-point to integral types, the diagnostic text incorrectly always claimed that the source expression was not a constant expression. llvm-svn: 148381
* A call to strlen is not a constant expression, even if we're treating it as aRichard Smith2012-01-181-1/+8
| | | | | | builtin. llvm-svn: 148374
* Enable constant evaluation of implicit calls to constexpr conversion operators.Richard Smith2012-01-171-1/+2
| | | | llvm-svn: 148333
* Some improvements to the handling of C11 atomic types:David Chisnall2012-01-161-0/+8
| | | | | | | | | | | | | | | | | | - Add atomic-to/from-nonatomic cast types - Emit atomic operations for arithmetic on atomic types - Emit non-atomic stores for initialisation of atomic types, but atomic stores and loads for every other store / load - Add a __atomic_init() intrinsic which does a non-atomic store to an _Atomic() type. This is needed for the corresponding C11 stdatomic.h function. - Enables the relevant __has_feature() checks. The feature isn't 100% complete yet, but it's done enough that we want people testing it. Still to do: - Make the arithmetic operations on atomic types (e.g. Atomic(int) foo = 1; foo++;) use the correct LLVM intrinsic if one exists, not a loop with a cmpxchg. - Add a signal fence builtin - Properly set the fenv state in atomic operations on floating point values - Correctly handle things like _Atomic(_Complex double) which are too large for an atomic cmpxchg on some platforms (this requires working out what 'correctly' means in this context) - Fix the many remaining corner cases llvm-svn: 148242
* constexpr: casts to void* are allowed in constant expressions, don't set theRichard Smith2012-01-151-3/+3
| | | | | | | designator invalid. (Since we can't read the value of such a pointer, this only affects the quality of diagnostics.) llvm-svn: 148208
* constexpr irgen: Add irgen support for APValue::Struct, APValue::Union,Richard Smith2012-01-141-5/+8
| | | | | | | | | | | | | | | | | | | | APValue::Array and APValue::MemberPointer. All APValue values can now be emitted as constants. Add new CGCXXABI entry point for emitting an APValue MemberPointer. The other entrypoints dealing with constant member pointers are no longer necessary and will be removed in a later change. Switch codegen from using EvaluateAsRValue/EvaluateAsLValue to VarDecl::evaluateValue. This performs caching and deals with the nasty cases in C++11 where a non-const object's initializer can refer indirectly to previously-initialized fields within the same object. Building the intermediate APValue object incurs a measurable performance hit on pathological testcases with huge initializer lists, so we continue to build IR directly from the Expr nodes for array and record types outside of C++11. llvm-svn: 148178
* Fix a silly mistake in ComplexExprEvaluator::ZeroInitialization. ↵Eli Friedman2012-01-131-1/+1
| | | | | | <rdar://problem/10691092>. llvm-svn: 148157
* constexpr: initialization of a union from an empty initializer-list shouldRichard Smith2012-01-121-8/+23
| | | | | | | | | zero-initialize the first union member. Also fix a bug where initializing an array of types compatible with wchar_t from a wide string literal failed in C, and fortify the C++ tests in this area. This part can't be tested without a code change to enable array evaluation in C (where an existing test fails). llvm-svn: 148035
* Allow constant-folding of references which were formed in a manner not permittedRichard Smith2012-01-121-10/+6
| | | | | | in a constant expression, for compatibility with g++. llvm-svn: 148020
* Implement the missing pieces of Evaluate for _Complex types. With that ↵Eli Friedman2012-01-101-5/+39
| | | | | | complete, remove some code from CGExprConstant which is no longer necessary. While I'm here, a couple minor tweaks to _Complex-in-C++. (Specifically, make _Complex types literal types, and don't warn for _Complex int.) llvm-svn: 147840
* PR11724: Implement evaluation for constexpr defaulted trivial union copy/moveRichard Smith2012-01-101-2/+16
| | | | | | | constructors. These are a special case whose behavior cannot be modeled as a user-written constructor. llvm-svn: 147839
* C++11 generalized constant expressions: implement checking and diagnostics forRichard Smith2012-01-061-229/+317
| | | | | | | pointer-arithmetic-related undefined behavior and unspecified results. We continue to fold such values, but now notice they aren't constant expressions. llvm-svn: 147659
* Address Richard's review comments on r147561 (Evaluate support for ↵Eli Friedman2012-01-051-5/+9
| | | | | | address-of-label differences). llvm-svn: 147631
* Add an APValue representation for the difference between two ↵Eli Friedman2012-01-041-0/+46
| | | | | | | | | | address-of-label expressions. Add support to Evaluate and CGExprConstant for generating/handling them. Remove the special-case for such differences in Expr::isConstantInitializer. With that done, remove a bunch of buggy code from CGExprConstant for handling scalar expressions which is no longer necessary. Fixes PR11705. llvm-svn: 147561
* Get rid of an unnecessary check; the AST for init-lists is the same ↵Eli Friedman2012-01-031-6/+4
| | | | | | independent of whether we're in C++11 mode. llvm-svn: 147503
* Support constant evaluation for OpenCL nested vector literals. Patch by ↵Eli Friedman2012-01-031-43/+32
| | | | | | Anton Lokhmotov. llvm-svn: 147496
* Unrevert r147271, reverted in r147361.Richard Smith2011-12-301-48/+172
| | | | | | | | | | | | Also temporarily remove the assumption from IR gen that we can emit IR for every constant we can fold, since it isn't currently true in C++11, to fix PR11676. Original comment from r147271: constexpr: perform zero-initialization prior to / instead of performing a constructor call when appropriate. Thanks to Eli for spotting this. llvm-svn: 147384
* Revert r147271. This fixes PR11676.Rafael Espindola2011-12-301-172/+48
| | | | llvm-svn: 147362
* Small refactoring and simplification of constant evaluation and some of itsRichard Smith2011-12-281-57/+66
| | | | | | clients. No functionality change. llvm-svn: 147318
* constexpr: support for evaluation and codegen of typeid constants.Richard Smith2011-12-271-0/+16
| | | | llvm-svn: 147290
* constexpr: perform zero-initialization prior to / instead of performing aRichard Smith2011-12-251-48/+172
| | | | | | constructor call when appropriate. Thanks to Eli for spotting this. llvm-svn: 147271
* Add support for bitcasts to vector type in Evaluate.Eli Friedman2011-12-221-0/+85
| | | | llvm-svn: 147137
* PR11614: Mark defaulted special constructors as constexpr if their implicitRichard Smith2011-12-221-0/+45
| | | | | | definition would satisfy the constexpr requirements. llvm-svn: 147128
* PR11637: implement special-case constant evaluation for char arrays initializedRichard Smith2011-12-221-0/+26
| | | | | | by string literals. llvm-svn: 147120
* Cast enumerators from different anonymous enums to unsigned, to appease gccMatt Beaumont-Gay2011-12-211-4/+4
| | | | llvm-svn: 147067
* constexpr: diagnostic improvements for invalid lvalue-to-rvalue conversions inRichard Smith2011-12-211-25/+113
| | | | | | constant expressions. llvm-svn: 147035
* Evaluation support for ExprWithCleanups. We won't evaluate any expression whichRichard Smith2011-12-191-0/+4
| | | | | | actually requires non-trivial cleanups, so no cleanups need to be performed. llvm-svn: 146916
* Improve r146813 (for PR11595) to give an appropriate diagnostic.Richard Smith2011-12-191-6/+11
| | | | llvm-svn: 146915
* constexpr handling improvements. Produce detailed diagnostics when a 'constexpr'Richard Smith2011-12-191-65/+54
| | | | | | | | | | | | | | | | | | | | | variable is initialized by a non-constant expression, and pass in the variable being declared so that earlier-initialized fields' values can be used. Rearrange VarDecl init evaluation to make this possible, and in so doing fix a long-standing issue in our C++ constant expression handling, where we would mishandle cases like: extern const int a; const int n = a; const int a = 5; int arr[n]; Here, n is not initialized by a constant expression, so can't be used in an ICE, even though the initialization expression would be an ICE if it appeared later in the TU. This requires computing whether the initializer is an ICE eagerly, and saving that information in PCH files. llvm-svn: 146856
* PR11604: don't allow floating-literal-to-integer casts in ICEs if the ↵Richard Smith2011-12-181-3/+17
| | | | | | | | | | (truncated) floating literal value does not fit into the destination type. Such casts have undefined behavior at translation time; treating them as non-ICE matches the behavior of modern gcc versions. llvm-svn: 146842
* Add a missing check before trying to evaluate a temporary. PR11595.Eli Friedman2011-12-171-0/+3
| | | | llvm-svn: 146813
* C++11 constexpr: Add note stacks containing backtraces if constant evaluationRichard Smith2011-12-161-19/+105
| | | | | | | | | | fails within a call to a constexpr function. Add -fconstexpr-backtrace-limit argument to driver and frontend, to control the maximum number of notes so produced (default 10). Fix APValue printing to be able to pretty-print all APValue types, and move the testing for this functionality from a unittest to a -verify test now that it's visible in clang's output. llvm-svn: 146749
* Add checks and diagnostics for many of the cases which C++11 considers to notRichard Smith2011-12-131-89/+203
| | | | | | be constant expressions. llvm-svn: 146479
* Clean up diagnostic wording for disallowed casts in C++11 constant expressions.Richard Smith2011-12-121-2/+7
| | | | llvm-svn: 146395
* Implement C++11 constant expression cast restrictions.Richard Smith2011-12-121-0/+19
| | | | llvm-svn: 146371
* Fix some not-yet-used diagnostic code in a template, which gcc spotted and clangRichard Smith2011-12-121-1/+1
| | | | | | did not! llvm-svn: 146366
* Prepare constant expression infrastructure for the generation of richerRichard Smith2011-12-121-69/+81
| | | | | | diagnostics. No functionality change. llvm-svn: 146365
* Add a fast path to the constant evaluator for integer literals. This speeds upRichard Smith2011-12-101-0/+8
| | | | | | | compilation of some translation units of SPEC's 445.gobmk by ~4%, and does not seem to cause a measurable slowdown in other cases. llvm-svn: 146306
* C++11 constant expressions: Don't use CheckICE in C++11; instead, determineRichard Smith2011-12-091-284/+379
| | | | | | | | | | | | 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. llvm-svn: 146289
* In ExprEvaluatorBase::VisitOpaqueValueExpr() add a sanity check to avoidArgyrios Kyrtzidis2011-12-091-3/+10
| | | | | | infinite recursion due to bad OpaqueValueExpr. llvm-svn: 146237
* Replace the implementation of __builtin_constant_p (which was based on the GCCRichard Smith2011-12-091-5/+47
| | | | | | | | | | | | | | | | | | | | | | | | 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! llvm-svn: 146236
* When folding the size of a global scope VLA to a constant, require the arrayRichard Smith2011-12-071-0/+34
| | | | | | | 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. llvm-svn: 146000
* Move vector bitcast handling in constant expressions from the expressionRichard Smith2011-12-061-31/+1
| | | | | | | | | | | | | 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. llvm-svn: 145981
* Make isWeakDecl available as a method on ValueDecl.Lang Hames2011-12-051-9/+3
| | | | llvm-svn: 145845
* Add driver arguments -ftemplate-depth=N and -fconstexpr-depth=N, with the sameRichard Smith2011-11-211-8/+8
| | | | | | | | | | | | | 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. llvm-svn: 145045
* Constant expression evaluation: add support for evaluation of member pointersRichard Smith2011-11-171-151/+674
| | | | | | and base-to-derived casts, and add proper handling of temporaries. llvm-svn: 144926
OpenPOWER on IntegriCloud