aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CGExprConstant.cpp
AgeCommit message (Collapse)AuthorFilesLines
2017-05-09Suppress all uses of LLVM_END_WITH_NULL. NFC.Serge Guelton1-6/+4
Use variadic templates instead of relying on <cstdarg> + sentinel. This enforces better type checking and makes code more readable. Differential revision: https://reviews.llvm.org/D32550 llvm-svn: 302572
2017-04-19[CodeGen] Use APInt::lshrInPlace instead of APInt::lshr. NFCCraig Topper1-3/+3
llvm-svn: 300658
2016-12-28[CodeGen] Unique constant CompoundLiterals.George Burgess IV1-4/+18
Our newly aggressive constant folding logic makes it possible for CGExprConstant to see the same CompoundLiteralExpr more than once. So, emitting a new GlobalVariable every time we see a CompoundLiteral is no longer correct. We had a similar issue with BlockExprs that was caught while testing said aggressive folding, so I applied the same style of fix (see D26410) here. If we find yet another case where this needs to happen, we should probably refactor this so we don't have a third DenseMap+getter+setter. As a design note: getAddrOfConstantCompoundLiteralIfEmitted is really only intended to be called by ConstExprEmitter::EmitLValue. So, returning a GlobalVariable* instead of a ConstantAddress costs us effectively nothing, and saves us either a few bytes per entry in our map or a bit of code duplication. llvm-svn: 290661
2016-12-23Fix problems in "[OpenCL] Enabling the usage of CLK_NULL_QUEUE as compare ↵Egor Churaev1-0/+1
operand." Summary: Fixed warnings in commit: https://reviews.llvm.org/rL290171 Reviewers: djasper, Anastasia Subscribers: yaxunl, cfe-commits, bader Differential Revision: https://reviews.llvm.org/D27981 llvm-svn: 290431
2016-12-15Re-commit r289252 and r289285, and fix PR31374Yaxun Liu1-24/+38
llvm-svn: 289787
2016-12-14Revert 289252 (and follow-up 289285), it caused PR31374Nico Weber1-38/+24
llvm-svn: 289713
2016-12-14Replace APFloatBase static fltSemantics data members with getter functionsStephan Bergmann1-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
2016-12-09Fix unused variable warnings. NFCI.Simon Pilgrim1-3/+3
llvm-svn: 289285
2016-12-09Add support for non-zero null pointer for C and OpenCLYaxun Liu1-24/+38
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
2016-12-06[c++17] P0135R1: Guaranteed copy elision.Richard Smith1-3/+3
When an object of class type is initialized from a prvalue of the same type (ignoring cv qualifications), use the prvalue to initialize the object directly instead of inserting a redundant elidable call to a copy constructor. llvm-svn: 288866
2016-11-03[CodeGen] Use StringRef. NFC.George Burgess IV1-2/+2
Looks like CurFn's name outlives FunctionName, so we can just pass StringRefs around rather than going from a StringRef to a std::string to a const char* to a StringRef. llvm-svn: 285873
2016-09-13[CodeGen] Fix an assert in EmitNullConstant.Akira Hatanaka1-1/+2
r235815 changed CGRecordLowering::accumulateBases to ignore non-virtual bases of size 0, which prevented adding those non-virtual bases to CGRecordLayout's NonVirtualBases. This caused clang to assert when CGRecordLayout::getNonVirtualBaseLLVMFieldNo was called in EmitNullConstant. This commit fixes the bug by ignoring zero-sized non-virtual bases in EmitNullConstant. rdar://problem/28100139 Differential Revision: https://reviews.llvm.org/D24312 llvm-svn: 281405
2016-07-28[OpenCL] Generate opaque type for sampler_t and function call for the ↵Yaxun Liu1-0/+3
initializer Currently Clang use int32 to represent sampler_t, which have been a source of issue for some backends, because in some backends sampler_t cannot be represented by int32. They have to depend on kernel argument metadata and use IPA to find the sampler arguments and global variables and transform them to target specific sampler type. This patch uses opaque pointer type opencl.sampler_t* for sampler_t. For each use of file-scope sampler variable, it generates a function call of __translate_sampler_initializer. For each initialization of function-scope sampler variable, it generates a function call of __translate_sampler_initializer. Each builtin library can implement its own __translate_sampler_initializer(). Since the real sampler type tends to be architecture dependent, allowing it to be initialized by a library function simplifies backend design. A typical implementation of __translate_sampler_initializer could be a table lookup of real sampler literal values. Since its argument is always a literal, the returned pointer is known at compile time and easily optimized to finally become some literal values directly put into image read instructions. This patch is partially based on Alexey Sotkin's work in Khronos Clang (https://github.com/KhronosGroup/SPIR/commit/3d4eec61623502fc306e8c67c9868be2b136e42b). Differential Revision: https://reviews.llvm.org/D21567 llvm-svn: 277024
2016-06-21Re-commit "[Temporary] Add an ExprWithCleanups for each C++ ↵Tim Shen1-0/+6
MaterializeTemporaryExpr." Since D21243 fixes relative clang-tidy tests. This reverts commit a71d9fbd41e99def9159af2b01ef6509394eaeed. llvm-svn: 273312
2016-06-17[CodeGen] Use pointer-sized integers for ptrtoint sourcesDavid Majnemer1-1/+7
Given something like: void *v = (void *)100; We need to synthesize a ptrtoint operation from 100. During constant emission, we choose i64 as the type for our constant because it guaranteed not to drop any bits from our CharUnits representation of the value. However, this is suboptimal for 32-bit targets: LLVM passes like GlobalOpt will get confused by these sorts of casts resulting in pessimization. Instead, make sure the ptrtoint operand has a pointer-sized integer type. llvm-svn: 273020
2016-06-09Revert "[Temporary] Add an ExprWithCleanups for each C++ ↵Tim Shen1-6/+0
MaterializeTemporaryExpr." This reverts r272296, since there are clang-tidy failures that appear to be caused by this change. llvm-svn: 272310
2016-06-09[Temporary] Add an ExprWithCleanups for each C++ MaterializeTemporaryExpr.Tim Shen1-0/+6
These ExprWithCleanups are added for holding a RunCleanupsScope not for destructor calls; rather, they are for lifetime marks. This requires ExprWithCleanups to keep a bit to indicate whether it have cleanups with side effects (e.g. dtor calls). Differential Revision: http://reviews.llvm.org/D20498 llvm-svn: 272296
2016-03-08P0017R1: In C++1z, an aggregate class can have (public non-virtual) base ↵Richard Smith1-1/+15
classes; these are initialized as if they were data members. llvm-svn: 262963
2016-01-14Update for LLVM function name change.Rui Ueyama1-12/+11
llvm-svn: 257802
2016-01-13[Bugfix] Fix ICE on constexpr vector splat.George Burgess IV1-0/+1
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
2015-12-11Clean ExprConstant/CGExprConstant up a bit. NFC.George Burgess IV1-5/+7
llvm-svn: 255314
2015-11-05PR25368: Replace workaround for build failure with modules enabled with a fixRichard Smith1-1/+1
for the root cause. The 'using llvm::isa;' declaration in Basic/LLVM.h only pulls the declarations of llvm::isa that were declared prior to it into namespace clang. In a modules build, this is a hermetic set of just the declarations from LLVM. In a non-modules build, we happened to also pull the declaration from lib/CodeGen/Address.h into namespace clang, which made the code in question accidentally compile. llvm-svn: 252211
2015-10-30CGExprConstant.cpp: Appease Modules.NAKAMURA Takumi1-1/+1
llvm-svn: 251713
2015-10-20[DEBUG INFO] Emit debug info for type used in explicit cast only.Alexey Bataev1-0/+2
Currently debug info for types used in explicit cast only is not emitted. It happened after a patch for better alignment handling. This patch fixes this bug. Differential Revision: http://reviews.llvm.org/D13582 llvm-svn: 250795
2015-09-08Compute and preserve alignment more faithfully in IR-generation.John McCall1-19/+31
Introduce an Address type to bundle a pointer value with an alignment. Introduce APIs on CGBuilderTy to work with Address values. Change core APIs on CGF/CGM to traffic in Address where appropriate. Require alignments to be non-zero. Update a ton of code to compute and propagate alignment information. As part of this, I've promoted CGBuiltin's EmitPointerWithAlignment helper function to CGF and made use of it in a number of places in the expression emitter. The end result is that we should now be significantly more correct when performing operations on objects that are locally known to be under-aligned. Since alignment is not reliably tracked in the type system, there are inherent limits to this, but at least we are no longer confused by standard operations like derived-to-base conversions and array-to-pointer decay. I've also fixed a large number of bugs where we were applying the complete-object alignment to a pointer instead of the non-virtual alignment, although most of these were hidden by the very conservative approach we took with member alignment. Also, because IRGen now reliably asserts on zero alignments, we should no longer be subject to an absurd but frustrating recurring bug where an incomplete type would report a zero alignment and then we'd naively do a alignmentAtOffset on it and emit code using an alignment equal to the largest power-of-two factor of the offset. We should also now be emitting much more aggressive alignment attributes in the presence of over-alignment. In particular, field access now uses alignmentAtOffset instead of min. Several times in this patch, I had to change the existing code-generation pattern in order to more effectively use the Address APIs. For the most part, this seems to be a strict improvement, like doing pointer arithmetic with GEPs instead of ptrtoint. That said, I've tried very hard to not change semantics, but it is likely that I've failed in a few places, for which I apologize. ABIArgInfo now always carries the assumed alignment of indirect and indirect byval arguments. In order to cut down on what was already a dauntingly large patch, I changed the code to never set align attributes in the IR on non-byval indirect arguments. That is, we still generate code which assumes that indirect arguments have the given alignment, but we don't express this information to the backend except where it's semantically required (i.e. on byvals). This is likely a minor regression for those targets that did provide this information, but it'll be trivial to add it back in a later patch. I partially punted on applying this work to CGBuiltin. Please do not add more uses of the CreateDefaultAligned{Load,Store} APIs; they will be going away eventually. llvm-svn: 246985
2015-06-23[CodeGen] Rename EmitMemberPointer to EmitMemberFunctionPointerDavid Majnemer1-1/+1
llvm-svn: 240382
2015-06-22Revert r240270 ("Fixed/added namespace ending comments using clang-tidy").Alexander Kornienko1-1/+1
llvm-svn: 240353
2015-06-22Fixed/added namespace ending comments using clang-tidy. NFCAlexander Kornienko1-1/+1
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
2015-06-10Implementing C99 partial re-initialization behavior (DR-253)Yunzhong Gao1-0/+156
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
2015-05-30[CodeGen] Indirect fields can initialize a unionDavid Majnemer1-2/+8
The first named data member is the field used to default initialize the union. An IndirectFieldDecl can introduce the first named data member of a union. llvm-svn: 238649
2015-05-26[CodeGen] Handle flexible array members containing pointers to membersDavid Majnemer1-4/+0
Types can be classified as being zero-initializable or non-zero-initializable. We used to classify array types by giving them the classification of their base element type. However, incomplete array types are never initialized directly and thus are always zero-initializable. llvm-svn: 238256
2015-04-24Replace getPointeeType()->isFunctionType with isMemberDataPointerTypeDavid Majnemer1-2/+1
llvm-svn: 235682
2015-04-02[opaque pointer type] Update for GEP API changes in LLVMDavid Blaikie1-1/+1
Now the GEP constant utility functions require the type to be explicitly passed (since eventually the pointer type will be opaque and not convey the required type information). For now callers can still pass nullptr (though none were needed here in Clang, which is nice) if convenienc/necessary, but eventually that will be disallowed as well. llvm-svn: 233937
2015-03-14CodeGen: Correctly initialize bitfields with non-constant initializersDavid Majnemer1-3/+8
It is possible to construct an initializer for a bitfield which is not constant. Instead of emitting code to initialize the field before the execution of main, clang would crash. llvm-svn: 232285
2014-12-28CodeGen: Optimize emssion of zeroinitialzied arraysDavid Majnemer1-12/+24
Create an ConstantAggregateZero upfront if we see that it is viable. This saves us from having to manually push_back each and every initializer and then looping back over them to determine if they are 'null'. llvm-svn: 224908
2014-12-14CodeGen: Compound literals with funny types shouldn't crashDavid Majnemer1-1/+2
CodeGen assumed that a compound literal with array type should have a corresponding LLVM IR array type. We had two bugs in this area: - Zero sized arrays in compound literals would lead to the creation of an opaque type. This is unnecessary, we should just create an array type with a bound of zero. - Funny record types (like unions) lead to exotic IR types for compound literals. In this case, CodeGen must be prepared to deal with the possibility that it might not have an array IR type. This fixes PR21912. llvm-svn: 224219
2014-12-01Use nullptr to silence -Wsentinel when self-hosting on WindowsReid Kleckner1-2/+2
Richard rejected my Sema change to interpret an integer literal zero in a varargs context as a null pointer, so -Wsentinel sees an integer literal zero and fires off a warning. Only CodeGen currently knows that it promotes integer literal zeroes in this context to pointer size on Windows. I didn't want to teach -Wsentinel about that compatibility hack. Therefore, I'm migrating to C++11 nullptr. llvm-svn: 223079
2014-10-19CodeGen: ConstStructBuilder must verify packed constraints after paddingDavid Majnemer1-14/+30
This reverts commit r220169 which reverted r220153. However, it also contains additional changes: - We may need to add padding *after* we've packed the struct. This occurs when the aligned next field offset is greater than the new field's offset. When this occurs, we make the struct packed. *However*, once packed the next field offset might be less than the new feild's offset. It is in this case that we might further pad the struct. - We would pad structs which were perfectly sized! This behavior is immensely old. This behavior came from blindly subtracting NextFieldOffsetInChars from RecordSize. This doesn't take into account the fact that the struct might have a greater overall alignment than the last field. llvm-svn: 220175
2014-10-19Revert r220153: "CodeGen: ConstStructBuilder must verify packed constraints ↵Chandler Carruth1-10/+9
after padding" This commit caused two tests in LNT to regress. I'm able to reproduce on any platform and will send reproduction steps to the original commit log. This should restore the LNT bots that have been failing. llvm-svn: 220169
2014-10-19CodeGen: ConstStructBuilder must verify packed constraints after paddingDavid Majnemer1-9/+10
Before, ConstStructBuilder::AppendBytes would check packed constraints prior to padding being added before the field's offset. However, adding this padding might force our struct to be packed. Because we wouldn't check *after* adding padding, ConstStructBuilder would be in an inconsistent state leading to a crash. This fixes PR21300. llvm-svn: 220153
2014-10-17CodeGen: Kill FillInNullDataMemberPointersDavid Majnemer1-106/+3
It exists to handle the case where base subobjects are character arrays. This never happens. llvm-svn: 220006
2014-10-08Fix IRGen for referencing a static local before emitting its declReid Kleckner1-1/+2
Summary: Previously CodeGen assumed that static locals were emitted before they could be accessed, which is true for automatic storage duration locals. However, it is possible to have CodeGen emit a nested function that uses a static local before emitting the function that defines the static local, breaking that assumption. Fix it by creating the static local upon access and ensuring that the deferred function body gets emitted. We may not be able to emit the initializer properly from outside the function body, so don't try. Fixes PR18020. See also previous attempts to fix static locals in PR6769 and PR7101. Reviewers: rsmith Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D4787 llvm-svn: 219265
2014-08-27Allow __fp16 as a function arg or return type for AArch64Oliver Stannard1-1/+2
ACLE 2.0 allows __fp16 to be used as a function argument or return type. This enables this for AArch64. This also fixes an existing bug that causes clang to not allow homogeneous floating-point aggregates with a base type of __fp16. This is valid for AAPCS64, but not for AAPCS-VFP. llvm-svn: 216558
2014-07-31PR18097: Support initializing an _Atomic(T) from an object of C++ class type TRichard Smith1-0/+19
or a class derived from T. We already supported this when initializing _Atomic(T) from T for most (and maybe all) other reasonable values of T. llvm-svn: 214390
2014-05-21[C++11] Use 'nullptr'. CodeGen edition.Craig Topper1-20/+20
llvm-svn: 209272
2014-04-23Objective-C [IRGen]. Fixes a crash in IRGen involving use ofFariborz Jahanian1-1/+4
'typeof' to extract type of an @encode expression used in an initializer. // rdar://16655340 llvm-svn: 207004
2014-04-17Bug 18567: Fix constantexpr pointer casts with address spaces.Matt Arsenault1-1/+3
Getting a pointer into a struct at a non-zero offset would try to use the default address space. llvm-svn: 206478
2014-03-13[C++11] Replacing CXXRecordDecl iterators vbases_begin() and vbases_end() ↵Aaron Ballman1-3/+2
with iterator_range vbases(). Updating all of the usages of the iterators with range-based for loops. llvm-svn: 203808
2014-03-13[C++11] Replacing CXXRecordDecl iterators bases_begin() and bases_end() with ↵Aaron Ballman1-9/+7
iterator_range bases(). Updating all of the usages of the iterators with range-based for loops. llvm-svn: 203803
2014-03-08[C++11] Replacing RecordDecl iterators field_begin() and field_end() with ↵Aaron Ballman1-8/+5
iterator_range fields(). Updating all of the usages of the iterators with range-based for loops. llvm-svn: 203355