summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/APValue.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Silence static analyzer getAs<RecordType> null dereference warnings. NFCI.Simon Pilgrim2019-10-031-1/+1
| | | | | | The static analyzer is warning about potential null dereferences, but in these cases we should be able to use castAs<RecordType> directly and if not assert will fire for us. llvm-svn: 373584
* Silence static analyzer getAs<VectorType> null dereference warnings. NFCI.Simon Pilgrim2019-10-021-1/+1
| | | | | | The static analyzer is warning about potential null dereferences, but in these cases we should be able to use castAs<VectorType> directly and if not assert will fire for us. llvm-svn: 373478
* For P0784R7: Add support for dynamic allocation with new / delete duringRichard Smith2019-09-271-4/+30
| | | | | | constant evaluation. llvm-svn: 373036
* [clang] Add storage for APValue in ConstantExprGauthier Harnisch2019-06-151-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: When using ConstantExpr we often need the result of the expression to be kept in the AST. Currently this is done on a by the node that needs the result and has been done multiple times for enumerator, for constexpr variables... . This patch adds to ConstantExpr the ability to store the result of evaluating the expression. no functional changes expected. Changes: - Add trailling object to ConstantExpr that can hold an APValue or an uint64_t. the uint64_t is here because most ConstantExpr yield integral values so there is an optimized layout for integral values. - Add basic* serialization support for the trailing result. - Move conversion functions from an enum to a fltSemantics from clang::FloatingLiteral to llvm::APFloatBase. this change is to make it usable for serializing APValues. - Add basic* Import support for the trailing result. - ConstantExpr created in CheckConvertedConstantExpression now stores the result in the ConstantExpr Node. - Adapt AST dump to print the result when present. basic* : None, Indeterminate, Int, Float, FixedPoint, ComplexInt, ComplexFloat, the result is not yet used anywhere but for -ast-dump. Reviewers: rsmith, martong, shafik Reviewed By: rsmith Subscribers: rnkovacs, hiraditya, dexonsmith, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D62399 llvm-svn: 363493
* Refactor: split Uninitialized state on APValue into an "Absent" stateRichard Smith2019-05-211-10/+19
| | | | | | | representing no such object, and an "Indeterminate" state representing an uninitialized object. The latter is not yet used, but soon will be. llvm-svn: 361328
* Fix alignment check to check the alignment of the intended type.Richard Smith2019-05-171-1/+1
| | | | llvm-svn: 360997
* Refactor constant evaluation of typeid(T) to track a symbolic type_infoRichard Smith2019-05-171-7/+65
| | | | | | | | | | | | | | object rather than tracking the originating expression. This is groundwork for supporting polymorphic typeid expressions. (Note that this somewhat regresses our support for DR1968, but it turns out that that never actually worked anyway, at least in non-trivial cases.) This reinstates r360974, reverted in r360988, with a fix for a static_assert failure on 32-bit builds: force Type base class to have 8-byte alignment like the rest of Clang's AST nodes. llvm-svn: 360995
* Revert Refactor constant evaluation of typeid(T) to track a symbolic ↵Chris Bieneman2019-05-171-58/+1
| | | | | | | | type_info object rather than tracking the originating expression. This reverts r360974 (git commit 7ee4307bd4450022c3c8777f43a40cc4f0ccc009) llvm-svn: 360988
* Refactor constant evaluation of typeid(T) to track a symbolic type_infoRichard Smith2019-05-171-1/+58
| | | | | | | | | | object rather than tracking the originating expression. This is groundwork for supporting polymorphic typeid expressions. (Note that this somewhat regresses our support for DR1968, but it turns out that that never actually worked anyway, at least in non-trivial cases.) llvm-svn: 360974
* Fix handling of objects under construction during constant expressionRichard Smith2019-05-121-5/+8
| | | | | | | | | | | | | evaluation. It's not enough to just track the LValueBase that we're evaluating, we need to also track the path to the objects whose constructors are running. This reinstates r360464 (reverted in r360531) with a workaround for an MSVC bug that previously caused the Windows bots to fail. llvm-svn: 360537
* Revert rL360499 and rL360464 from cfe/trunk:Simon Pilgrim2019-05-111-8/+5
| | | | | | | | | | | | | | | | | | | | | | | | Reject attempts to call non-static member functions on objects outside their lifetime in constant expressions. This is undefined behavior per [class.cdtor]p2. We continue to allow this for objects whose values are not visible within the constant evaluation, because there's no way we can tell whether the access is defined or not, existing code relies on the ability to make such calls, and every other compiler allows such calls. ........ Fix handling of objects under construction during constant expression evaluation. It's not enough to just track the LValueBase that we're evaluating, we need to also track the path to the objects whose constructors are running. ........ Fixes windows buildbots llvm-svn: 360531
* Fix handling of objects under construction during constant expressionRichard Smith2019-05-101-5/+8
| | | | | | | | | | evaluation. It's not enough to just track the LValueBase that we're evaluating, we need to also track the path to the objects whose constructors are running. llvm-svn: 360464
* Improve interface of APValuePathEntry.Richard Smith2019-05-101-3/+2
| | | | llvm-svn: 360463
* Inline asm constraints: allow ICE-like pointers for the "n" constraint (PR40890)Hans Wennborg2019-03-061-0/+20
| | | | | | | | | | | | Apparently GCC allows this, and there's code relying on it (see bug). The idea is to allow expression that would have been allowed if they were cast to int. So I based the code on how such a cast would be done (the CK_PointerToIntegral case in IntExprEvaluator::VisitCastExpr()). Differential Revision: https://reviews.llvm.org/D58821 llvm-svn: 355491
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-4/+3
| | | | | | | | | | | | | | | | | to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
* [Fixed Point Arithmetic] Add APFixedPoint to APValueLeonard Chan2019-01-161-0/+15
| | | | | | | | This adds APFixedPoint to the union of values that can be represented with an APValue. Differential Revision: https://reviews.llvm.org/D56746 llvm-svn: 351368
* Fix crash on call to __builtin_memcpy with a null pointer to anRichard Smith2018-09-131-6/+14
| | | | | | | | incomplete type. Also improve the diagnostics for similar situations. llvm-svn: 342192
* [ExprConstant] Use an AST node and a version number as a key to createAkira Hatanaka2018-04-101-17/+62
| | | | | | | | | | | | | | | an APValue and retrieve it from map Temporaries. The version number is needed when a single AST node is visited multiple times and is used to create APValues that are required to be distinct from each other (for example, MaterializeTemporaryExprs in default arguments and VarDecls in loops). rdar://problem/36505742 Differential Revision: https://reviews.llvm.org/D42776 llvm-svn: 329671
* Re-commit r289252 and r289285, and fix PR31374Yaxun Liu2016-12-151-4/+13
| | | | llvm-svn: 289787
* Revert 289252 (and follow-up 289285), it caused PR31374Nico Weber2016-12-141-13/+4
| | | | llvm-svn: 289713
* Replace APFloatBase static fltSemantics data members with getter functionsStephan Bergmann2016-12-141-1/+1
| | | | | | | | | | | | | At least the plugin used by the LibreOffice build (<https://wiki.documentfoundation.org/Development/Clang_plugins>) indirectly uses those members (through inline functions in LLVM/Clang include files in turn using them), but they are not exported by utils/extract_symbols.py on Windows, and accessing data across DLL/EXE boundaries on Windows is generally problematic. Differential Revision: https://reviews.llvm.org/D26671 llvm-svn: 289647
* Add support for non-zero null pointer for C and OpenCLYaxun Liu2016-12-091-4/+13
| | | | | | | | | | | | | | | | | | In amdgcn target, null pointers in global, constant, and generic address space take value 0 but null pointers in private and local address space take value -1. Currently LLVM assumes all null pointers take value 0, which results in incorrectly translated IR. To workaround this issue, instead of emit null pointers in local and private address space, a null pointer in generic address space is emitted and casted to local and private address space. Tentative definition of global variables with non-zero initializer will have weak linkage instead of common linkage since common linkage requires zero initializer and does not have explicit section to hold the non-zero value. Virtual member functions getNullPointer and performAddrSpaceCast are added to TargetCodeGenInfo which by default returns ConstantPointerNull and emitting addrspacecast instruction. A virtual member function getNullPointerValue is added to TargetInfo which by default returns 0. Each target can override these virtual functions to get target specific null pointer and the null pointer value for specific address space, and perform specific translations for addrspacecast. Wrapper functions getNullPointer is added to CodegenModule and getTargetNullPointerValue is added to ASTContext to facilitate getting the target specific null pointers and their values. This change has no effect on other targets except amdgcn target. Other targets can provide support of non-zero null pointer in a similar way. This change only provides support for non-zero null pointer for C and OpenCL. Supporting for other languages will be added later incrementally. Differential Revision: https://reviews.llvm.org/D26196 llvm-svn: 289252
* [NFC] Header cleanupMehdi Amini2016-07-181-2/+0
| | | | | | | | | | Summary: Removed unused headers, replaced some headers with forward class declarations Patch by: Eugene <claprix@yandex.ru> Differential Revision: https://reviews.llvm.org/D20100 llvm-svn: 275882
* Annotate dump() methods with LLVM_DUMP_METHOD, addressing Richard Smith ↵Yaron Keren2016-01-291-1/+1
| | | | | | r259192 post commit comment. llvm-svn: 259232
* Simplify creation of a bunch of ArrayRefs by using None, makeArrayRef or ↵Craig Topper2014-08-271-2/+2
| | | | | | just letting them be implicitly created. llvm-svn: 216528
* Removing an "if (this == nullptr)" check from two print methods. The conditionRichard Trieu2014-06-091-1/+6
| | | | | | | will never be true in a well-defined context. The checking for null pointers has been moved into the caller logic so it does not rely on undefined behavior. llvm-svn: 210498
* [C++11] Use 'nullptr'. AST edition.Craig Topper2014-05-121-4/+5
| | | | llvm-svn: 208517
* Make some assertions on constant expressions static.Benjamin Kramer2014-03-151-1/+1
| | | | llvm-svn: 204012
* [C++11] Replacing RecordDecl iterators field_begin() and field_end() with ↵Aaron Ballman2014-03-081-2/+1
| | | | | | iterator_range fields(). Updating all of the usages of the iterators with range-based for loops. llvm-svn: 203355
* Reapply r198845, reverted in r198849, with a fix to make it valid C++98, notRichard Smith2014-01-101-35/+39
| | | | | | | | | | | just valid C++11 =) Original commit message: PR18427: Use an appropriately-aligned buffer in APValue, to avoid a crash on SPARC, where uint64_t apparently requires higher alignment than void*. llvm-svn: 198903
* Revert "PR18427: Use an appropriately-aligned buffer in APValue, to avoid a ↵Argyrios Kyrtzidis2014-01-091-40/+34
| | | | | | | | | crash on" It broke building. This reverts commit r198845. llvm-svn: 198849
* PR18427: Use an appropriately-aligned buffer in APValue, to avoid a crash onRichard Smith2014-01-091-34/+40
| | | | | | SPARC, where uint64_t apparently requires higher alignment than void*. llvm-svn: 198845
* Pacify compilers that think you can drop off a fully covered switch.Benjamin Kramer2013-06-031-0/+1
| | | | llvm-svn: 183155
* Fix memory leak for APValues that do memory allocation.Manuel Klimek2013-06-031-0/+33
| | | | | | | | | This patch ensures that APValues are deallocated with the ASTContext by registering a deallocation function for APValues to the ASTContext. Original version of the patch by James Dennett. llvm-svn: 183101
* Don't crash while printing APValues that are lvalues casted to aDouglas Gregor2013-01-291-0/+2
| | | | | | decidedly non-reference, non-pointer type. Fixes <rdar://problem/13090123>. llvm-svn: 173747
* Sort all of Clang's files under 'lib', and fix up the broken headersChandler Carruth2012-12-041-1/+1
| | | | | | | | | | | | | uncovered. This required manually correcting all of the incorrect main-module headers I could find, and running the new llvm/utils/sort_includes.py script over the files. I also manually added quite a few missing headers that were uncovered by shuffling the order or moving headers up to be main-module-headers. llvm-svn: 169237
* Store SourceManager pointer on PrintingPolicy in the case where we're dumping,Richard Smith2012-08-161-3/+2
| | | | | | | | | and remove ASTContext reference (which was frequently bound to a dereferenced null pointer) from the recursive lump of printPretty functions. In so doing, fix (at least) one case where we intended to use the 'dump' mode, but that failed because a null ASTContext reference had been passed in. llvm-svn: 162011
* Remove the ref/value inconsistency in filter_decl_iterator.David Blaikie2012-04-301-3/+3
| | | | | | | | | | | | | 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
* Teach APValue printer to print boolean 0 and 1 as 'false' and 'true'. Fix upRichard Smith2012-03-231-1/+4
| | | | | | some calling code to actually pass in a non-null type, to avoid a crash. llvm-svn: 153358
* Assign APValues by swapping from a temporary. Removes a bunch of unnecessaryRichard Smith2012-03-101-42/+47
| | | | | | | | 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] APValue: Split the fast path of MakeUninit to be inline.Daniel Dunbar2012-03-081-1/+1
| | | | | | | - This change seems to be a tiny loss on 403.gcc/combine.c (.2%), but I think it is the right thing to do. llvm-svn: 152330
* Implement DR1454. This allows all intermediate results in constant expressionsRichard Smith2012-02-151-4/+15
| | | | | | | | | | | | to be core constant expressions (including pointers and references to temporaries), and makes constexpr calculations Turing-complete. A Turing machine simulator is included as a testcase. This opens up the possibilty of removing CCValue entirely, and removing some copies from the constant evaluator in the process, but that cleanup is not part of this change. llvm-svn: 150557
* Add an APValue representation for the difference between two ↵Eli Friedman2012-01-041-1/+16
| | | | | | | | | | 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
* Add missing flush call. This is an attempt to fix a broken Windows buildbot.Eli Friedman2011-12-161-0/+1
| | | | llvm-svn: 146760
* C++11 constexpr: Add note stacks containing backtraces if constant evaluationRichard Smith2011-12-161-57/+192
| | | | | | | | | | 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
* Constant expression evaluation: add support for evaluation of member pointersRichard Smith2011-11-171-16/+105
| | | | | | and base-to-derived casts, and add proper handling of temporaries. llvm-svn: 144926
* Represent an APValue based on a Decl as that Decl, rather than a DeclRefExprRichard Smith2011-11-121-9/+4
| | | | | | | | 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. llvm-svn: 144468
* Constant expression evaluation: support for evaluation of structs and unions ofRichard Smith2011-11-101-12/+78
| | | | | | | literal types, as well as derived-to-base casts for lvalues and derived-to-virtual-base casts. llvm-svn: 144265
* Constant expression evaluation: support for arrays.Richard Smith2011-11-071-2/+43
| | | | llvm-svn: 143922
* Fix 32-bit build bots and remove some casting-away-const warnings.Richard Smith2011-11-071-2/+6
| | | | llvm-svn: 143914
OpenPOWER on IntegriCloud