summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/ExprConstant.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* AST: Initialization with dllimport functions in CDavid Majnemer2014-06-251-8/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The C++ language requires that the address of a function be the same across all translation units. To make __declspec(dllimport) useful, this means that a dllimported function must also obey this rule. MSVC implements this by dynamically querying the import address table located in the linked executable. This means that the address of such a function in C++ is not constant (which violates other rules). However, the C language has no notion of ODR nor does it permit dynamic initialization whatsoever. This requires implementations to _not_ dynamically query the import address table and instead utilize a wrapper function that will be synthesized by the linker which will eventually query the import address table. The effect this has is, to say the least, perplexing. Consider the following C program: __declspec(dllimport) void f(void); typedef void (*fp)(void); static const fp var = &f; const fp fun() { return &f; } int main() { return fun() == var; } MSVC will statically initialize "var" with the address of the wrapper function and "fun" returns the address of the actual imported function. This means that "main" will return false! Note that LLVM's optimizers are strong enough to figure out that "main" should return true. However, this result is dependent on having optimizations enabled! N.B. This change also permits the usage of dllimport declarators inside of template arguments; they are sufficiently constant for such a purpose. Add tests to make sure we don't regress here. llvm-svn: 211677
* AST: Address of dllimport functions isn't constantDavid Majnemer2014-06-241-1/+4
| | | | | | | | | | | | | | | | The address of dllimport functions can be accessed one of two ways: - Through the IAT which is symbolically referred to with a symbol starting with __imp_. - Via the wrapper-function which ends up calling through the __imp_ symbol. The problem with using the wrapper-function is that it's address will not compare as equal in all translation units. Specifically, it will compare unequally with the translation unit which defines the function. This fixes PR19955. llvm-svn: 211570
* AST: Address of dllimport variables isn't constantDavid Majnemer2014-06-241-0/+3
| | | | | | | | | | | | | The address of dllimport variables isn't something that can be meaningfully used in a constexpr context and isn't suitable for evaluation at load-time. They require loads from memory to properly evaluate. This fixes PR19955. Differential Revision: http://reviews.llvm.org/D4250 llvm-svn: 211568
* Add missing "non-constant" diagnostic for a member call on a temporary ofRichard Smith2014-06-111-0/+1
| | | | | | non-literal class type. llvm-svn: 210696
* Related to PR19992: when the GNU alignof-expression extension is applied to anRichard Smith2014-06-101-3/+4
| | | | | | | expression of array-of-unknown-bound type, don't try to complete the array bound, and return the alignment of the element type rather than 1. llvm-svn: 210608
* [C++11] Use 'nullptr'. AST edition.Craig Topper2014-05-121-55/+58
| | | | llvm-svn: 208517
* PR19346: Adding 0 to a null pointer has defined behavior in C++. Allow it in ↵Richard Smith2014-04-081-2/+2
| | | | | | constant expressions. llvm-svn: 205757
* [C++11] Replacing CompoundStmt iterators body_begin() and body_end() with ↵Aaron Ballman2014-03-171-3/+2
| | | | | | iterator_range body(). Updating all of the usages of the iterators with range-based for loops. llvm-svn: 204040
* Fix a crash (assertion failure) in EvaluateAsRValue.James Dennett2014-03-141-0/+10
| | | | | | | | | | | | | | | | Summary: Gracefully fail to evaluate a constant expression if its type is unknown, rather than failing an assertion trying to access the type. Reviewers: klimek Reviewed By: klimek CC: chandlerc, cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D3075 llvm-svn: 203950
* [C++11] Replacing DeclStmt iterators decl_begin() and decl_end() with ↵Aaron Ballman2014-03-141-3/+2
| | | | | | iterator_range decls(). Updating all of the usages of the iterators with range-based for loops. llvm-svn: 203947
* [C++11] Replacing CXXRecordDecl iterators init_begin() and init_end() with ↵Aaron Ballman2014-03-131-11/+10
| | | | | | iterator_range inits(). Updating all of the usages of the iterators with range-based for loops. llvm-svn: 203819
* Reverting llvm::distance changes to use std::distance with iterators ↵Aaron Ballman2014-03-101-4/+5
| | | | | | | | instead, per post-commit review feedback. Replacing llvm::copy changes with SmallVector range-based construction which is a considerably cleaner approach. llvm-svn: 203461
* [C++11] Replacing RecordDecl iterators field_begin() and field_end() with ↵Aaron Ballman2014-03-081-14/+10
| | | | | | iterator_range fields(). Updating all of the usages of the iterators with range-based for loops. llvm-svn: 203355
* Renaming the chains() ranged iterator to chain() per suggestion by Richard ↵Aaron Ballman2014-03-071-2/+2
| | | | | | Smith. llvm-svn: 203262
* [C++11] Replacing IndirectFieldDecl iterators chain_begin() and chain_end() ↵Aaron Ballman2014-03-071-7/+4
| | | | | | with iterator_range chains(). Updating all of the usages of the iterators with range-based for loops. llvm-svn: 203261
* PR19010: Make sure we initialize (empty) indirect base class subobjects whenRichard Smith2014-03-051-23/+12
| | | | | | evaluating trivial default initialization of a literal class type. llvm-svn: 203025
* [AST] Follow-up for r201468, move the check to the caller and add an assertion.Argyrios Kyrtzidis2014-02-201-4/+8
| | | | | | Suggested by Richard Smith. llvm-svn: 201753
* [Sema] Fix assertion hit while trying to do constant evaluation for a ↵Argyrios Kyrtzidis2014-02-151-0/+2
| | | | | | | | | | dependent expression inside a GNU statement expression. rdar://16064952 llvm-svn: 201468
* PR18283: If a const variable of integral or enumeration type isRichard Smith2014-01-251-1/+11
| | | | | | | | initialized from a constant expression in C++98, it can be used in constant expressions, even if it was brace-initialized. Patch by Rahul Jain! llvm-svn: 200098
* Rename getResultType() on function and method declarations to getReturnType()Alp Toker2014-01-251-1/+1
| | | | | | | | | | | | | | | A return type is the declared or deduced part of the function type specified in the declaration. A result type is the (potentially adjusted) type of the value of an expression that calls the function. Rule of thumb: * Declarations have return types and parameters. * Expressions have result types and arguments. llvm-svn: 200082
* Add a new attribute 'enable_if' which can be used to control overload ↵Nick Lewycky2014-01-111-4/+85
| | | | | | resolution based on the values of the function arguments at the call site. llvm-svn: 198996
* Fixing a FIXME; the RetTy template parameter is always bool in practice, and ↵Aaron Ballman2014-01-031-48/+47
| | | | | | so it has been removed. No functional changes intended. llvm-svn: 198440
* Eliminate UnaryTypeTraitExprAlp Toker2014-01-011-5/+0
| | | | | | | | | | | | | Remove UnaryTypeTraitExpr and switch all remaining type trait related handling over to TypeTraitExpr. The UTT/BTT/TT enum prefix and evaluation code is retained pending further cleanup. This is part of the ongoing work to unify type traits following the removal of BinaryTypeTraitExpr in r197273. llvm-svn: 198271
* Rename isBuiltinCall() to getBuiltinCallee()Alp Toker2013-12-281-7/+7
| | | | | | | | This better describes what the function does. Cleanup only. llvm-svn: 198127
* Eliminate BinaryTypeTraitExprAlp Toker2013-12-131-5/+0
| | | | | | | | | | | | | | | | | There's nothing special about type traits accepting two arguments. This commit eliminates BinaryTypeTraitExpr and switches all related handling over to TypeTraitExpr. Also fixes a CodeGen failure with variadic type traits appearing in a non-constant expression. The BTT/TT prefix and evaluation code is retained as-is for now but will soon be further cleaned up. This is part of the ongoing work to unify type traits. llvm-svn: 197273
* Add front-end infrastructure now address space casts are in LLVM IR.David Tweed2013-12-111-0/+2
| | | | | | | | | | With the introduction of explicit address space casts into LLVM, there's a need to provide a new cast kind the front-end can create for C/OpenCL/CUDA and code to produce address space casts from those kinds when appropriate. Patch by Michele Scandale! llvm-svn: 197036
* Modern gcc is happy to constant evaluate __builtin_strlen in various casesRichard Smith2013-11-151-17/+42
| | | | | | | where we didn't. Extend our constant evaluation for __builtin_strlen to handle any constant array of chars, not just string literals, to match. llvm-svn: 194762
* PR17615: A delegating constructor initializer is a full-expression. Don'tRichard Smith2013-11-071-2/+5
| | | | | | forget to clean up temporaries at the end of it. llvm-svn: 194213
* Silencing some MSVC warnings about not all control paths returning a value ↵Aaron Ballman2013-11-061-0/+2
| | | | | | when they actually do. llvm-svn: 194156
* More constant evaluation cleanup, and fix an issue where we'd override anRichard Smith2013-11-061-22/+25
| | | | | | | earlier 'non-constant' diagnostic with a later one if the earlier one was from a side-effect we thought we could evaluate past. llvm-svn: 194117
* Simplify: we don't care why constant evaluation might have failed when we'reRichard Smith2013-11-051-6/+3
| | | | | | checking an expression for constant overflow. llvm-svn: 194099
* Refactor constant expression handling and make a couple of tweaks to make it aRichard Smith2013-11-051-64/+156
| | | | | | | | | bit more robust against future changes. This includes a slight diagnostic improvement: if we know we're only trying to form a constant expression, take the first diagnostic which shows the expression is not a constant expression, rather than preferring the first one which makes the expression unfoldable. llvm-svn: 194098
* Add constant evaluation support for __builtin_isinf, __builtin_isfinite,Richard Smith2013-10-151-0/+24
| | | | | | __builtin_isnan, and __builtin_isnormal. Patch by Karthik Bhat! Tests by me. llvm-svn: 192729
* Fix comment to match name of variable.Nick Lewycky2013-09-221-1/+1
| | | | llvm-svn: 191171
* Add the intrinsic __builtin_convertvectorHal Finkel2013-09-181-0/+1
| | | | | | | | | | | | | | | | | | LLVM supports applying conversion instructions to vectors of the same number of elements (fptrunc, fptosi, etc.) but there had been no way for a Clang user to cause such instructions to be generated when using builtin vector types. C-style casting on vectors is already defined in terms of bitcasts, and so cannot be used for these conversions as well (without leading to a very confusing set of semantics). As a result, this adds a __builtin_convertvector intrinsic (patterned after the OpenCL __builtin_astype intrinsic). This is intended to aid the creation of vector intrinsic headers that create generic IR instead of target-dependent intrinsics (in other words, this is a generic _mm_cvtepi32_ps). As noted in the documentation, the action of __builtin_convertvector is defined in terms of the action of a C-style cast on each vector element. llvm-svn: 190915
* Fix const-eval of vector init-lists of a vector.Eli Friedman2013-09-171-1/+1
| | | | | | | | | Like any other type, an init list for a vector can have the same type as the vector itself; handle that case. <rdar://problem/14990460> llvm-svn: 190844
* Part three of PR15721: if we have an invalid CXXDefaultInitExpr, don't crash ifRichard Smith2013-09-131-2/+6
| | | | | | we try to constant-evaluate it. Patch by Karthik Bhat, test by me. llvm-svn: 190722
* PR5683: Issue a warning when subtracting pointers to types of zero size, andRichard Smith2013-09-101-0/+9
| | | | | | | treat such subtractions as being non-constant. Patch by Serge Pavlov! With a few tweaks by me. llvm-svn: 190439
* Adjust clang for change to APFloat::toString.Eli Friedman2013-08-291-1/+10
| | | | | | | | I changed the diagnostic printing code because it's probably better to cut off a digit from DBL_MAX than to print something like 1.300000001 when the user wrote 1.3. llvm-svn: 189625
* Constify more uses of ASTContext&. No functional change.Craig Topper2013-08-221-7/+8
| | | | llvm-svn: 188991
* PR16755: When initializing or modifying a bitfield member in a constantRichard Smith2013-08-061-7/+48
| | | | | | expression, truncate the stored value to the size of the bitfield. llvm-svn: 187782
* C++1y: track object lifetime during constexpr evaluation, and don't allowRichard Smith2013-07-241-59/+170
| | | | | | | objects to be used once their lifetimes end. This completes the C++1y constexpr extensions. llvm-svn: 187025
* Make IgnoreParens() look through ChooseExprs.Eli Friedman2013-07-201-2/+2
| | | | | | | | | | | | | This is the same way GenericSelectionExpr works, and it's generally a more consistent approach. A large part of this patch is devoted to caching the value of the condition of a ChooseExpr; it's needed to avoid threading an ASTContext into IgnoreParens(). Fixes <rdar://problem/14438917>. llvm-svn: 186738
* Add a __builtin_addressof that performs the same functionality as the built-inRichard Smith2013-07-111-1/+7
| | | | | | | | | | | & operator (ignoring any overloaded operator& for the type). The purpose of this builtin is for use in std::addressof, to allow it to be made constexpr; the existing implementation technique (reinterpret_cast to some reference type, take address, reinterpert_cast back) does not permit this because reinterpret_cast between reference types is not permitted in a constant expression in C++11 onwards. llvm-svn: 186053
* PR16377: Allow evaluation of statement expressions in constant evaluation,Richard Smith2013-06-201-2/+47
| | | | | | why not. Apparently GCC supports this. llvm-svn: 184396
* PR14503: Don't assert if a constexpr constructor temploid instantiates to aRichard Smith2013-06-181-0/+5
| | | | | | | constructor that does not initialize all members, and that constructor is used to initialize a global. llvm-svn: 184211
* Emit initializers for static-storage-duration temporaries as constants whereRichard Smith2013-06-141-0/+1
| | | | | | possible. llvm-svn: 183967
* More for PR12457: fix handling of __builtin_isinf_sign and test.Richard Smith2013-06-131-1/+1
| | | | llvm-svn: 183890
* Towards PR12457: constant expression evaluation support for ↵Richard Smith2013-06-131-14/+63
| | | | | | __builtin_parity{,l,ll}, __builtin_ffs{,l,ll}, and __builtin_fpclassify. llvm-svn: 183889
* Fix part of PR12457. Patch by Justin Bogner!Richard Smith2013-06-131-0/+34
| | | | llvm-svn: 183886
OpenPOWER on IntegriCloud