summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/ExprConstant.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Fix ICE with constexpr and friend functionsOlivier Goffart2016-02-121-7/+9
| | | | | | | | | | | | | Fix a crash while parsing this code: struct X { friend constexpr int foo(X*) { return 12; } static constexpr int j = foo(static_cast<X*>(nullptr)); }; Differential Revision: http://reviews.llvm.org/D16973 llvm-svn: 260675
* Update for LLVM function name change.Rui Ueyama2016-01-141-1/+1
| | | | llvm-svn: 257802
* [Bugfix] Fix ICE on constexpr vector splat.George Burgess IV2016-01-131-1/+6
| | | | | | | | | | | | | In {CG,}ExprConstant.cpp, we weren't treating vector splats properly. This patch makes us treat splats more properly. Additionally, this patch adds a new cast kind which allows a bool->int cast to result in -1 or 0, instead of 1 or 0 (for true and false, respectively), so we can sanely model OpenCL bool->int casts in the AST. Differential Revision: http://reviews.llvm.org/D14877 llvm-svn: 257559
* [TrailingObjects] Convert OffsetOfExpr.James Y Knight2015-12-291-5/+5
| | | | | | That necessitated moving the OffsetOfNode class out of OffsetOfExpr. llvm-svn: 256590
* Clean ExprConstant/CGExprConstant up a bit. NFC.George Burgess IV2015-12-111-9/+9
| | | | llvm-svn: 255314
* Explicitly permit undefined behavior in constant initializers for globalRichard Smith2015-12-081-6/+38
| | | | | | | | variables in C, in the cases where we can constant-fold it to a value regardless (such as floating-point division by zero and signed integer overflow). Strictly enforcing this rule breaks too much code. llvm-svn: 254992
* Don't assert if evaluation of an expression that we're syntactically requiredRichard Smith2015-12-041-1/+5
| | | | | | | to treat as an ICE results in undefined behavior. Instead, return the "natural" result of the operation (signed wraparound / inf / nan). llvm-svn: 254699
* PR17381: Treat undefined behavior during expression evaluation as an unmodeledRichard Smith2015-12-031-51/+64
| | | | | | | | | | | | | | | | | | | | | side-effect, so that we don't allow speculative evaluation of such expressions during code generation. This caused a diagnostic quality regression, so fix constant expression diagnostics to prefer either the first "can't be constant folded" diagnostic or the first "not a constant expression" diagnostic depending on the kind of evaluation we're doing. This was always the intent, but didn't quite work correctly before. This results in certain initializers that used to be constant initializers to no longer be; in particular, things like: float f = 1e100; are no longer accepted in C. This seems appropriate, as such constructs would lead to code being executed if sanitizers are enabled. llvm-svn: 254574
* Add the `pass_object_size` attribute to clang.George Burgess IV2015-12-021-12/+56
| | | | | | | | | | | | | `pass_object_size` is our way of enabling `__builtin_object_size` to produce high quality results without requiring inlining to happen everywhere. A link to the design doc for this attribute is available at the Differential review link below. Differential Revision: http://reviews.llvm.org/D13263 llvm-svn: 254554
* [MSVC] 'property' with an empty array in array subscript expression.Alexey Bataev2015-11-251-0/+1
| | | | | | | | | | | | MSVC supports 'property' attribute and allows to apply it to the declaration of an empty array in a class or structure definition. For example: ``` __declspec(property(get=GetX, put=PutX)) int x[]; ``` The above statement indicates that x[] can be used with one or more array indices. In this case, i=p->x[a][b] will be turned into i=p->GetX(a, b), and p->x[a][b] = i will be turned into p->PutX(a, b, i); Differential Revision: http://reviews.llvm.org/D13336 llvm-svn: 254067
* Move global classes into anonymous namespaces. NFC.Benjamin Kramer2015-10-281-0/+2
| | | | llvm-svn: 251528
* [coroutines] Creation of promise object, lookup of operator co_await, buildingRichard Smith2015-10-271-0/+3
| | | | | | of await_* calls, and AST representation for same. llvm-svn: 251387
* Make __builtin_object_size more conservativeGeorge Burgess IV2015-10-161-22/+138
| | | | | | | | | | | | | | | | | | | | | | | | | | | r246877 made __builtin_object_size substantially more aggressive with unknown bases if Type=1 or Type=3, which causes issues when we encounter code like this: struct Foo { int a; char str[1]; }; const char str[] = "Hello, World!"; struct Foo *f = (struct Foo *)malloc(sizeof(*f) + strlen(str)); strcpy(&f->str, str); __builtin_object_size(&f->str, 1) would hand back 1, which is technically correct given the type of Foo, but the type of Foo lies to us about how many bytes are available in this case. This patch adds support for this "writing off the end" idiom -- we now answer conservatively when we're given the address of the very last member in a struct. Differential Revision: http://reviews.llvm.org/D12169 llvm-svn: 250488
* Pass ArrayRef by value. NFC.Craig Topper2015-09-291-1/+1
| | | | llvm-svn: 248773
* Don't crash when passing &@selector to a _Nonnull parameter. Fixes PR24774.Nico Weber2015-09-151-2/+3
| | | | | | | | | The root cause here is that ObjCSelectorExpr is an rvalue, yet it can have its address taken. That's kind of awkward, but fixing this is awkward in other ways, see https://llvm.org/bugs/show_bug.cgi?id=24774#c16 . For now, just fix the crash. llvm-svn: 247740
* Fix a bug in __builtin_object_size cast removalGeorge Burgess IV2015-09-041-3/+10
| | | | | | | | | | | Apparently there are many cast kinds that may cause implicit pointer arithmetic to happen. In light of this, the cast ignoring logic introduced in r246877 has been changed to only ignore a small set of cast kinds, and a test for this behavior has been added. Thanks to Richard for catching this before it became a bug report. :) llvm-svn: 246890
* Increase accuracy of __builtin_object_size.George Burgess IV2015-09-041-35/+96
| | | | | | | | | | | | | | | | | | | Improvements: - For all types, we would give up in a case such as: __builtin_object_size((char*)&foo, N); even if we could provide an answer to __builtin_object_size(&foo, N); We now provide the same answer for both of the above examples in all cases. - For type=1|3, we now support subobjects with unknown bases, as long as the designator is valid. Thanks to Richard Smith for the review + design planning. Review: http://reviews.llvm.org/D12169 llvm-svn: 246877
* [AST] Don't crash when comparing incomplete objectDavid Majnemer2015-08-291-1/+7
| | | | | | | | | | We cannot tell if an object is past-the-end if its type is incomplete. Zero sized objects satisfy past-the-end criteria and our object might turn out to be such an object. This fixes PR24622. llvm-svn: 246359
* PR24597: Fix in-place evaluation of call expressions to provide a proper "this"Richard Smith2015-08-281-17/+51
| | | | | | pointer to an RVO construction of a returned object. llvm-svn: 246263
* [OPENMP 4.0] Initial support for array sections.Alexey Bataev2015-08-251-0/+1
| | | | | | | | Adds parsing/sema analysis/serialization/deserialization for array sections in OpenMP constructs (introduced in OpenMP 4.0). Currently it is allowed to use array sections only in OpenMP clauses that accepts list of expressions. Differential Revision: http://reviews.llvm.org/D10732 llvm-svn: 245937
* Make __builtin_object_size always answer correctlyGeorge Burgess IV2015-08-191-43/+88
| | | | | | | | | | | | | | | | | | __builtin_object_size would return incorrect answers for many uses where type=3. This fixes the inaccuracy by making us emit 0 instead of LLVM's objectsize intrinsic. Additionally, there are many cases where we would emit suboptimal (but correct) answers, such as when arrays are involved. This patch fixes some of these cases (please see new tests in test/CodeGen/object-size.c for specifics on which cases are improved) Resubmit of r245323 with PR24493 fixed. Patch mostly by Richard Smith. Differential Revision: http://reviews.llvm.org/D12000 This fixes PR15212. llvm-svn: 245403
* Revert r245323, it caused PR24493.Nico Weber2015-08-181-82/+44
| | | | llvm-svn: 245342
* Make __builtin_object_size always answer correctlyGeorge Burgess IV2015-08-181-44/+82
| | | | | | | | | | | | | | | | | __builtin_object_size would return incorrect answers for many uses where type=3. This fixes the inaccuracy by making us emit 0 instead of LLVM's objectsize intrinsic. Additionally, there are many cases where we would emit suboptimal (but correct) answers, such as when arrays are involved. This patch fixes some of these cases (please see new tests in test/CodeGen/object-size.c for specifics on which cases are improved) Patch mostly by Richard Smith. Differential Revision: http://reviews.llvm.org/D12000 This fixes PR15212. llvm-svn: 245323
* -Wdeprecated: Job objects are stored in a vector yet are not really ↵David Blaikie2015-08-121-2/+8
| | | | | | copyable, make them movable instead llvm-svn: 244829
* [OPENMP] Introduced type trait "__builtin_omp_required_simd_align" for ↵Alexey Bataev2015-07-021-0/+7
| | | | | | | | | default simd alignment. Adds type trait "__builtin_omp_required_simd_align" after discussions here http://reviews.llvm.org/D9894 Differential Revision: http://reviews.llvm.org/D10597 llvm-svn: 241237
* Revert r240270 ("Fixed/added namespace ending comments using clang-tidy").Alexander Kornienko2015-06-221-8/+8
| | | | llvm-svn: 240353
* Fixed/added namespace ending comments using clang-tidy. NFCAlexander Kornienko2015-06-221-8/+8
| | | | | | | | | | | | The patch is generated using this command: $ tools/extra/clang-tidy/tool/run-clang-tidy.py -fix \ -checks=-*,llvm-namespace-comment -header-filter='llvm/.*|clang/.*' \ work/llvm/tools/clang To reduce churn, not touching namespaces spanning less than 10 lines. llvm-svn: 240270
* Implementing C99 partial re-initialization behavior (DR-253)Yunzhong Gao2015-06-101-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | Based on previous discussion on the mailing list, clang currently lacks support for C99 partial re-initialization behavior: Reference: http://lists.cs.uiuc.edu/pipermail/cfe-dev/2013-April/029188.html Reference: http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_253.htm This patch attempts to fix this problem. Given the following code snippet, struct P1 { char x[6]; }; struct LP1 { struct P1 p1; }; struct LP1 l = { .p1 = { "foo" }, .p1.x[2] = 'x' }; // this example is adapted from the example for "struct fred x[]" in DR-253; // currently clang produces in l: { "\0\0x" }, // whereas gcc 4.8 produces { "fox" }; // with this fix, clang will also produce: { "fox" }; Differential Review: http://reviews.llvm.org/D5789 llvm-svn: 239446
* Fix PR21945: Crash in constant evaluator.Jonathan Roelofs2015-06-011-0/+5
| | | | | | Patch by Косов Евгений! llvm-svn: 238758
* PR23373: A defaulted union copy constructor that is not trivial must still beRichard Smith2015-04-291-6/+5
| | | | | | emitted as a memcpy. llvm-svn: 236142
* Make helper functions static. NFC.Benjamin Kramer2015-03-091-3/+4
| | | | | | Found by -Wmissing-prototypes. llvm-svn: 231668
* Add support for generating MIPS legacy NaNPetar Jovanovic2015-02-261-4/+17
| | | | | | | | | | | Currently, the NaN values emitted for MIPS architectures do not cover non-IEEE754-2008 compliant case. This change fixes the issue. Patch by Vladimir Radosavljevic. Differential Revision: http://reviews.llvm.org/D7882 llvm-svn: 230653
* Removing LLVM_EXPLICIT, as MSVC 2012 was the last reason for requiring the ↵Aaron Ballman2015-02-151-1/+1
| | | | | | macro. NFC; Clang edition. llvm-svn: 229336
* Catch more cases when diagnosing integer-constant-expression overflows.Josh Magee2015-02-041-2/+6
| | | | | | | | | When visiting AssignmentOps, keep evaluating after a failure (when possible) in order to identify overflow in subexpressions. Differential Revision: http://reviews.llvm.org/D1238 llvm-svn: 228202
* Support constant evaluation for member calls on std::initializer_listRichard Smith2014-12-171-0/+3
| | | | | | temporaries. llvm-svn: 224449
* Improve handling of value dependent expressions in ↵Nick Lewycky2014-12-161-1/+2
| | | | | | __attribute__((enable_if)), both in the condition expression and at the call site. Fixes PR20988! llvm-svn: 224320
* AST: Limit zero-sized constexpr behavior to array typesDavid Majnemer2014-12-141-1/+3
| | | | | | | Restricting this "extension" to array types maximizes our standards conformance while not miscompiling real-world programs. llvm-svn: 224215
* AST: Incomplete types might be zero sizedDavid Majnemer2014-12-111-3/+7
| | | | | | | | Comparing the address of an object with an incomplete type might return true with a 'distinct' object if the former has a size of zero. However, such an object should compare unequal with null. llvm-svn: 224040
* AST: Don't assume two zero sized objects live at different addressesDavid Majnemer2014-12-091-0/+10
| | | | | | | | Zero sized objects may overlap with each other or any other object. This fixes PR21786. llvm-svn: 223852
* [OpenCL] Implemented restrictions for pointer conversions specified in ↵Anastasia Stulova2014-11-261-0/+1
| | | | | | | | | | | | OpenCL v2.0. OpenCL v2.0 s6.5.5 restricts conversion of pointers to different address spaces: - the named address spaces (__global, __local, and __private) => __generic - implicitly converted; - __generic => named - with an explicit cast; - named <=> named - disallowed; - __constant <=> any other - disallowed. llvm-svn: 222834
* Fix bug where a trivial constexpr copy/move operation couldn't copy from anRichard Smith2014-11-191-4/+31
| | | | | | | empty non-constexpr object. Such a copy doesn't break any of the constexpr rules. llvm-svn: 222387
* Fix assert/crash on invalid with __builtin_constant_p conditionals in ↵Richard Smith2014-11-131-1/+5
| | | | | | constant expressions. llvm-svn: 221942
* [c++1z] N4295: fold-expressions.Richard Smith2014-11-081-0/+1
| | | | | | | | | | | | | | | | This is a new form of expression of the form: (expr op ... op expr) where one of the exprs is a parameter pack. It expands into (expr1 op (expr2onwards op ... op expr)) (and likewise if the pack is on the right). The non-pack operand can be omitted; in that case, an empty pack gives a fallback value or an error, depending on the operator. llvm-svn: 221573
* Add the initial TypoExpr AST node for delayed typo correction.Kaelyn Takata2014-10-271-0/+1
| | | | llvm-svn: 220692
* PR21327 / C++ DR1652 / C++ DR73: comparing a past-the-end pointer for oneRichard Smith2014-10-211-0/+28
| | | | | | | | complete object to a pointer to the start of another complete object does not evaluate to the constant 'false'. All other comparisons between the addresses of subobjects of distinct complete objects still do. llvm-svn: 220343
* [complex] Teach the other two binary operators on complex numbers (==Chandler Carruth2014-10-111-5/+17
| | | | | | | | | | | | | | | | | and !=) to support mixed complex and real operand types. This requires removing an assert from SemaChecking, and adding support both to the constant evaluator and the code generator to synthesize the imaginary part when needed. This seemed somewhat cleaner than having just the comparison operators force real-to-complex conversions. I've added test cases for these operations. I'm really terrified that there were *no* tests in-tree which exercised this. This turned up when trying to build R after my change to the complex type lowering. llvm-svn: 219570
* [complex] Teach Clang to preserve different-type operands to arithmeticChandler Carruth2014-10-111-52/+156
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | operators where one type is a C complex type, and to emit both the efficient and correct implementation for complex arithmetic according to C11 Annex G using this extra information. For both multiply and divide the old code was writing a long-hand reduced version of the math without any of the special handling of inf and NaN recommended by the standard here. Instead of putting more complexity here, this change does what GCC does which is to emit a libcall for the fully general case. However, the old code also failed to do the proper minimization of the set of operations when there was a mixed complex and real operation. In those cases, C provides a spec for much more minimal operations that are valid. Clang now emits the exact suggested operations. This change isn't *just* about performance though, without minimizing these operations, we again lose the correct handling of infinities and NaNs. It is critical that this happen in the frontend based on assymetric type operands to complex math operations. The performance implications of this change aren't trivial either. I've run a set of benchmarks in Eigen, an open source mathematics library that makes heavy use of complex. While a few have slowed down due to the libcall being introduce, most sped up and some by a huge amount: up to 100% and 140%. In order to make all of this work, also match the algorithm in the constant evaluator to the one in the runtime library. Currently it is a broken port of the simplifications from C's Annex G to the long-hand formulation of the algorithm. Splitting this patch up is very hard because none of this works without the AST change to preserve non-complex operands. Sorry for the enormous change. Follow-up changes will include support for sinking the libcalls onto cold paths in common cases and fastmath improvements to allow more aggressive backend folding. Differential Revision: http://reviews.llvm.org/D5698 llvm-svn: 219557
* Fix for bug http://llvm.org/PR17427.Alexey Bataev2014-10-091-3/+5
| | | | | | | | Assertion failed: "Computed __func__ length differs from type!" Reworked PredefinedExpr representation with internal StringLiteral field for function declaration. Differential Revision: http://reviews.llvm.org/D5365 llvm-svn: 219393
* constexpr evaluation for __builtin_assume_alignedHal Finkel2014-10-031-37/+98
| | | | | | | | | | | | | | | | | Richard noted in the review of r217349 that extra handling of __builtin_assume_aligned inside of the expression evaluator was needed. He was right, and this should address the concerns raised, namely: 1. The offset argument to __builtin_assume_aligned can have side effects, and we need to make sure that all arguments are properly evaluated. 2. If the alignment assumption does not hold, that introduces undefined behavior, and undefined behavior cannot appear inside a constexpr. and hopefully the diagnostics produced are detailed enough to explain what is going on. llvm-svn: 218992
* Revert useless part of r217349Hal Finkel2014-10-031-1/+0
| | | | | | | | | | Adding handling of __builtin_assume_aligned to IntExprEvaluator does not make sense because __builtin_assume_aligned returns a pointer (not an integer). Thanks to Richard for figuring out why this was not doing anything. I'll add this back in a better place (PointerExprEvaluator perhaps). llvm-svn: 218958
OpenPOWER on IntegriCloud