summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/ExprConstant.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Factor out computation of whether a typeid's expression is potentiallyRichard Smith2012-08-131-0/+3
| | | | | | evaluated into a CXXTypeid member function. No functionality change. llvm-svn: 161779
* Teach Expr::HasSideEffects about all the Expr types, and fix a bug where itRichard Smith2012-08-071-92/+3
| | | | | | | | | | | | | | | | | | | was mistakenly classifying dynamic_casts which might throw as having no side effects. Switch it from a visitor to a switch, so it is kept up-to-date as future Expr nodes are added. Move it from ExprConstant.cpp to Expr.cpp, since it's not really related to constant expression evaluation. Since we use HasSideEffect to determine whether to emit an unused global with internal linkage, this has the effect of suppressing emission of globals in some cases. I've left many of the Objective-C cases conservatively assuming that the expression has side-effects. I'll leave it to someone with better knowledge of Objective-C than mine to improve them. llvm-svn: 161388
* objective-C string literal has no side-effect,Fariborz Jahanian2012-08-041-0/+1
| | | | | | | resulting in issuance of unused static variable warning now. // rdar://10777111 llvm-svn: 161291
* Let Expr::HasSideEffects() return false for NULL, bool literals, this, and ↵Nico Weber2012-07-201-0/+6
| | | | | | | | nullptr. Fixes PR13413, -Wunused-private-field now warns on unused fields initialized to NULL. llvm-svn: 160541
* Don't treat overflow in floating-point conversions as a hard error in ↵Eli Friedman2012-07-171-6/+5
| | | | | | constant evaluation. <rdar://problem/11874571>. llvm-svn: 160394
* add support for conditional expressions in Expr::HasSideEffects()Nuno Lopes2012-07-131-0/+3
| | | | | | This fixes a bug in __builtin_object_size() codegen llvm-svn: 160191
* Fix crash when constant-evaluating a CXXConstructExpr representingRichard Smith2012-07-101-8/+9
| | | | | | | value-initialization for an array of class type with a trivial default constructor. llvm-svn: 160024
* PR13290: Constant-evaluation support for CXXConstructExprs which construct aRichard Smith2012-07-071-19/+39
| | | | | | | | multidimensional array of class type. Also, preserve zero-initialization when evaluating an initializer list for an array, in case the initializers refer to later elements (which have preceding zero-initialization). llvm-svn: 159904
* Remove typedef which is unused after r159189.Richard Smith2012-06-261-4/+0
| | | | llvm-svn: 159224
* Fix lifetime issue for backing APValue of OpaqueValueExpr in recursiveRichard Smith2012-06-261-41/+7
| | | | | | | | | | constexpr function evaluation, and corresponding ASan / valgrind issue in tests, by storing the corresponding value with the relevant stack frame. This also prevents re-evaluation of the source of the underlying OpaqueValueExpr, which makes a major performance difference for certain contrived code (see testcase update). llvm-svn: 159189
* Use std::map instead of llvm::DenseMap because we rely on the stability of ↵Eli Friedman2012-06-251-2/+6
| | | | | | references to values in these maps. PR13197. llvm-svn: 159161
* Revert Decl's iterators back to pointer value_type rather than reference ↵David Blaikie2012-06-061-4/+4
| | | | | | | | | | | | | | value_type In addition, I've made the pointer and reference typedef 'void' rather than T* just so they can't get misused. I would've omitted them entirely but std::distance likes them to be there even if it doesn't use them. This rolls back r155808 and r155869. Review by Doug Gregor incorporating feedback from Chandler Carruth. llvm-svn: 158104
* If the first argument of __builtin_object_size can be folded to a constantRichard Smith2012-05-231-4/+13
| | | | | | | | pointer, but such folding encounters side-effects, ignore the side-effects rather than performing them at runtime: CodeGen generates wrong code for __builtin_object_size in that case. llvm-svn: 157310
* My first effort to do this more subtly failed, so elaboratelyJohn McCall2012-05-011-31/+59
| | | | | | | test for an invalid declaration at every single place in the constant evaluator that's about to request a struct layout. llvm-svn: 155868
* Remove the ref/value inconsistency in filter_decl_iterator.David Blaikie2012-04-301-11/+11
| | | | | | | | | | | | | filter_decl_iterator had a weird mismatch where both op* and op-> returned T* making it difficult to generalize this filtering behavior into a reusable library of any kind. This change errs on the side of value, making op-> return T* and op* return T&. (reviewed by Richard Smith) llvm-svn: 155808
* Fix a crash-on-invalid where the constant evaluator would try toJohn McCall2012-04-261-0/+5
| | | | | | evaluate certain expressions involving invalidly-defined classes. llvm-svn: 155645
* Implements boxed expressions for Objective-C. <rdar://problem/10194391>Patrick Beard2012-04-191-2/+2
| | | | llvm-svn: 155082
* Per Richard's comments on r154794, add the checks necessary to handle ↵Eli Friedman2012-04-161-2/+13
| | | | | | constant-folding relational comparisons safely in case the user is using -fwrapv or equivalent. llvm-svn: 154849
* Make constant evaluation for pointer comparisons work correctly for some ↵Eli Friedman2012-04-161-6/+18
| | | | | | uncommon cases. <rdar://problem/10962435>. llvm-svn: 154794
* The result of the Microsoft __uuidof operator must be considered a global ↵Francois Pichet2012-04-161-0/+6
| | | | | | | | | | | | | lvalue during constant expression evaluation. Otherwise we would get this error in C++11 mode (because of a recent change): error: non-type template argument of type 'const _GUID *' is not a constant expression For code like: template <const GUID* g = &__uuidof(struct_with_uuid)> class COM_CLASS { }; llvm-svn: 154790
* PR12226: don't generate wrong code if a braced string literal is used toRichard Smith2012-04-151-6/+9
| | | | | | | | | initialize an array of unsigned char. Outside C++11 mode, this bug was benign, and just resulted in us emitting a constant which was double the required length, padded with 0s. In C++11, it resulted in us generating an array whose first element was something like i8 ptrtoint ([n x i8]* @str to i8). llvm-svn: 154756
* Implement the missing pieces needed to support libstdc++4.7's <atomic>:Richard Smith2012-04-131-26/+26
| | | | | | | | | | | | | | | | | | | | | | | | __atomic_test_and_set, __atomic_clear, plus a pile of undocumented __GCC_* predefined macros. Implement library fallback for __atomic_is_lock_free and __c11_atomic_is_lock_free, and implement __atomic_always_lock_free. Contrary to their documentation, GCC's __atomic_fetch_add family don't multiply the operand by sizeof(T) when operating on a pointer type. libstdc++ relies on this quirk. Remove this handling for all but the __c11_atomic_fetch_add and __c11_atomic_fetch_sub builtins. Contrary to their documentation, __atomic_test_and_set and __atomic_clear take a first argument of type 'volatile void *', not 'void *' or 'bool *', and __atomic_is_lock_free and __atomic_always_lock_free have an argument of type 'const volatile void *', not 'void *'. With this change, libstdc++4.7's <atomic> passes libc++'s atomic test suite, except for a couple of libstdc++ bugs and some cases where libc++'s test suite tests for properties which implementations have latitude to vary. llvm-svn: 154640
* Provide, and document, a set of __c11_atomic_* intrinsics to implement C11'sRichard Smith2012-04-111-1/+2
| | | | | | | | | <stdatomic.h> header. In passing, fix LanguageExtensions to note that C11 and C++11 are no longer "upcoming standards" but are now actually standardized. llvm-svn: 154513
* Don't forget to evaluate the subexpression in a null pointer cast. If we'reRichard Smith2012-04-081-0/+2
| | | | | | converting from std::nullptr_t, the subexpression might have side-effects. llvm-svn: 154278
* Implement support for null non-type template arguments for non-typeDouglas Gregor2012-04-061-2/+4
| | | | | | | template parameters of pointer, pointer-to-member, or nullptr_t type in C++11. Fixes PR9700 / <rdar://problem/11193097>. llvm-svn: 154219
* Simplify DataRecursiveIntBinOpEvaluator::VisitBinOp() a bit and make sure we ↵Argyrios Kyrtzidis2012-03-221-13/+9
| | | | | | | | don't evaluate RHS if LHS could not be evaluated and keepEvaluatingAfterFailure() is false. llvm-svn: 153235
* Change the binary operator data recursive evaluator to not stop at the firstRichard Trieu2012-03-211-16/+14
| | | | | | | | | | | non-constant value encountered. This allows the evaluator to deduce that expressions like (x < 5 || true) is equal to true. Previously, it would visit x and determined that the entire expression is could not evaluated to a constant. This fixes PR12318. llvm-svn: 153226
* [Sema] Introduce a data recursive evaluator specific to binary operators.Argyrios Kyrtzidis2012-03-151-181/+401
| | | | | | | | | | | This allows us to handle extreme cases of chained binary operators without causing stack overflow. The binary operators that are handled with the data recursive evaluator are comma, logical, or operators that have operands with integral or enumeration type. Part of rdar://10941790. llvm-svn: 152819
* Remove hacky temporary fix of r151585.Argyrios Kyrtzidis2012-03-151-22/+1
| | | | llvm-svn: 152818
* Unrevert r152761 (reverted in r152772) with a fix for the issue which wasRichard Smith2012-03-151-64/+75
| | | | | | | | breaking bootstrap. No test yet: it's quite hard to tickle the failure case. The specific testcase for this wouldn't be useful for testing anything more general than a reintroduction of this precise bug in any case. llvm-svn: 152775
* Revert r152761 "Minor optimization to constant evaluation: don't botherDaniel Dunbar2012-03-151-74/+64
| | | | | | computing expr source...", it breaks bootstrap. llvm-svn: 152772
* Minor optimization to constant evaluation: don't bother computing expr sourceRichard Smith2012-03-151-64/+74
| | | | | | | | | | locations for diagnostics we're not going to emit, and don't track the subobject designator outside C++11 (since we're not going to use it anyway). This seems to give about a 0.5% speedup on 403.gcc/combine.c, but the results were sufficiently noisy that I can't reject the null hypothesis. llvm-svn: 152761
* Allow vectors to be constructed from constexpr function arguments inRichard Smith2012-03-131-2/+2
| | | | | | constant expressions. llvm-svn: 152665
* Unify naming of LangOptions variable/get function across the Clang stack ↵David Blaikie2012-03-111-9/+9
| | | | | | | | | | (Lex to AST). The member variable is always "LangOpts" and the member function is always "getLangOpts". Reviewed by Chris Lattner llvm-svn: 152536
* Add a missing 'template' keyword.Douglas Gregor2012-03-111-1/+1
| | | | llvm-svn: 152526
* Remove BlockDeclRefExpr and introduce a bit on DeclRefExpr toJohn McCall2012-03-101-6/+0
| | | | | | | | track whether the referenced declaration comes from an enclosing local context. I'm amenable to suggestions about the exact meaning of this bit. llvm-svn: 152491
* Assign APValues by swapping from a temporary. Removes a bunch of unnecessaryRichard Smith2012-03-101-2/+8
| | | | | | | | copy-construction, which Daniel Dunbar reports as giving a 0.75% speedup on 403.gcc/combine.c. The performance differences on my constexpr torture tests are below the noise floor. llvm-svn: 152455
* [AST] Reduce Decl::getASTContext() calls.Daniel Dunbar2012-03-091-1/+1
| | | | | | | - This function is not at all free; pass it around along some hot paths instead of recomputing it deep inside various VarDecl methods. llvm-svn: 152363
* AST representation for user-defined literals, plus just enough of semanticRichard Smith2012-03-071-0/+1
| | | | | | | | | | | | | | | | | | | | | analysis to make the AST representation testable. They are represented by a new UserDefinedLiteral AST node, which is a sugared CallExpr. All semantic properties, including full CodeGen support, are achieved for free by this representation. UserDefinedLiterals can never be dependent, so no custom instantiation behavior is required. They are mangled as if they were direct calls to the underlying literal operator. This matches g++'s apparent behavior (but not its actual mangling, which is broken for literal-operator-ids). User-defined *string* literals are now fully-operational, but the semantic analysis is quite hacky and needs more work. No other forms of user-defined literal are created yet, but the AST support for them is present. This patch committed after midnight because we had already hit the quota for new kinds of literal yesterday. llvm-svn: 152211
* The constant folder's diagnosic mechanism is irrelevant for C; don't botherRichard Smith2012-03-071-4/+0
| | | | | | producing a C-only diagnostic. llvm-svn: 152181
* Add clang support for new Objective-C literal syntax for NSDictionary, NSArray,Ted Kremenek2012-03-061-0/+11
| | | | | | | | | | | | | NSNumber, and boolean literals. This includes both Sema and Codegen support. Included is also support for new Objective-C container subscripting. My apologies for the large patch. It was very difficult to break apart. The patch introduces changes to the driver as well to cause clang to link in additional runtime support when needed to support the new language features. Docs are forthcoming to document the implementation and behavior of these features. llvm-svn: 152137
* constexpr: Remove APValue/CCValue distinction. It is no longer useful given theRichard Smith2012-03-031-183/+95
| | | | | | resolution of core issue 1454. llvm-svn: 151991
* Move llvm/ADT/SaveAndRestore.h -> llvm/Support/SaveAndRestore.h.Argyrios Kyrtzidis2012-03-011-1/+1
| | | | | | Needs llvm update. llvm-svn: 151829
* When evaluating integer expressions include a check for sub-expressionsArgyrios Kyrtzidis2012-02-271-1/+21
| | | | | | | | depth and error if we exceed a max value, to make sure we avoid a stack overflow. This is a hacky temporary fix. rdar://10913206. llvm-svn: 151585
* Revert testing code I committed by mistake in r151464.Argyrios Kyrtzidis2012-02-271-4/+4
| | | | llvm-svn: 151548
* Revert r151460 as it is not enough to address the issue.Argyrios Kyrtzidis2012-02-251-52/+38
| | | | | | | | | | | Original log: When evaluating integer expressions handle logical operators outside VisitBinaryOperator() to reduce stack pressure for source with huge number of logical operators. Fixes rdar://10913206. llvm-svn: 151464
* When evaluating integer expressions handle logical operators outsideArgyrios Kyrtzidis2012-02-251-34/+48
| | | | | | | | | VisitBinaryOperator() to reduce stack pressure for source with huge number of logical operators. Fixes rdar://10913206. llvm-svn: 151460
* When checking whether a reference to a variable is an ICE, look at the type ofRichard Smith2012-02-241-4/+5
| | | | | | | the declaration, not at the type of the DeclRefExpr, since within a lambda the DeclRefExpr can be more const than the declaration is. llvm-svn: 151399
* Remove some trivial uses of hasTrivialCopyConstructor() andDouglas Gregor2012-02-241-2/+2
| | | | | | hasTrivialMoveConstructor(). llvm-svn: 151354
* Implement a new type trait __is_trivially_constructible(T, Args...)Douglas Gregor2012-02-241-0/+5
| | | | | | | | | | | | | | | | that provides the behavior of the C++11 library trait std::is_trivially_constructible<T, Args...>, which can't be implemented purely as a library. Since __is_trivially_constructible can have zero or more arguments, I needed to add Yet Another Type Trait Expression Class, this one handling arbitrary arguments. The next step will be to migrate UnaryTypeTrait and BinaryTypeTrait over to this new, more general TypeTrait class. Fixes the Clang side of <rdar://problem/10895483> / PR12038. llvm-svn: 151352
OpenPOWER on IntegriCloud