summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CGCall.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Refactor ABIArgInfo::Expand implementation (NFC).Alexey Samsonov2014-09-291-120/+155
| | | | | | | | Hoist the logic which determines the way QualType is expanded into a separate method. Remove a bunch of copy-paste and simplify getTypesFromArgs() / ExpandTypeFromArgs() / ExpandTypeToArgs() methods. llvm-svn: 218615
* Support the assume_aligned function attributeHal Finkel2014-09-261-54/+71
| | | | | | | | | In addition to __builtin_assume_aligned, GCC also supports an assume_aligned attribute which specifies the alignment (and optional offset) of a function's return value. Here we implement support for the assume_aligned attribute by making use of the @llvm.assume intrinsic. llvm-svn: 218500
* Report source location of returns_nonnull attribute in UBSan reports.Alexey Samsonov2014-09-081-9/+11
| | | | llvm-svn: 217400
* Implement nonnull-attribute sanitizerAlexey Samsonov2014-09-081-11/+46
| | | | | | | | | | | | | | | | | | | | | | | | Summary: This patch implements a new UBSan check, which verifies that function arguments declared to be nonnull with __attribute__((nonnull)) are actually nonnull in runtime. To implement this check, we pass FunctionDecl to CodeGenFunction::EmitCallArgs (where applicable) and if function declaration has nonnull attribute specified for a certain formal parameter, we compare the corresponding RValue to null as soon as it's calculated. Test Plan: regression test suite Reviewers: rsmith Reviewed By: rsmith Subscribers: cfe-commits, rnk Differential Revision: http://reviews.llvm.org/D5082 llvm-svn: 217389
* Handle constructors and destructors a bit more uniformly in CodeGen.Rafael Espindola2014-09-081-38/+20
| | | | | | | | | There were code paths that are duplicated for constructors and destructors just because we have both CXXCtorType and CXXDtorsTypes. This patch introduces an unified enum and reduces code deplication a bit. llvm-svn: 217383
* Don't emit prologues or epilogues for naked functions (PR18791, PR20028)Hans Wennborg2014-09-041-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | For naked functions with parameters, Clang would still emit stores in the prologue that would clobber the stack, because LLVM doesn't set up a stack frame. (This shows up in -O0 compiles, because the stores are optimized away otherwise.) For example: __attribute__((naked)) int f(int x) { asm("movl $42, %eax"); asm("retl"); } Would result in: _Z1fi: movl 12(%esp), %eax movl %eax, (%esp) <--- Oops. movl $42, %eax retl Differential Revision: http://reviews.llvm.org/D5183 llvm-svn: 217198
* Make all virtual member pointers use variadic musttail callsReid Kleckner2014-08-291-0/+14
| | | | | | | | | This avoids encoding information about the function prototype into the thunk at the cost of some function prototype bitcast gymnastics. Fixes PR20653. llvm-svn: 216782
* Use store size instead of alloc size when coercing.James Molloy2014-08-291-3/+5
| | | | | | | | | | Previously, EnterStructPointerForCoercedAccess used Alloc size when determining how to convert. This was problematic, because there were situations were the alloc size was larger than the store size. For example, if the first element of a structure were i24 and the destination type were i32, the old code would generate a GEP and a load i24. The code should compare store sizes to ensure the whole object is loaded. I have attached a test case. This patch modifies the output of arm64-be-bitfield.c test case, but the new IR seems to be equivalent, and after -O3, the compiler generates identical ARM assembly. (asr x0, x0, #54) Patch by Thomas Jablin! llvm-svn: 216722
* Properly handle multiple nonnull attributes in CodeGenAlexey Samsonov2014-08-281-15/+25
| | | | llvm-svn: 216638
* Fix regression in r216520: don't apply nonnull to non-pointer functionRichard Smith2014-08-271-2/+11
| | | | | | parameters in the IR. llvm-svn: 216574
* Move some ARM-specific code from CGCall.cpp to TargetInfo.cppOliver Stannard2014-08-271-36/+11
| | | | | | | | | This tidies up some ARM-specific code added by r208417 to move it out of the target-independent parts of clang into TargetInfo.cpp. This also has the advantage that we can now flatten struct arguments to variadic AAPCS functions. llvm-svn: 216535
* Simplify creation of a bunch of ArrayRefs by using None, makeArrayRef or ↵Craig Topper2014-08-271-6/+5
| | | | | | just letting them be implicitly created. llvm-svn: 216528
* CGCall: Factor out the logic mapping call arguments to LLVM IR arguments.Alexey Samsonov2014-08-221-223/+314
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This refactoring introduces ClangToLLVMArgMapping class, which encapsulates the information about the order in which function arguments listed in CGFunctionInfo should be passed to actual LLVM IR function, such as: 1) positions of sret, if there is any 2) position of inalloca argument, if there is any 3) position of helper padding argument for each call argument 4) positions of regular argument (there can be many if it's expanded). Simplify several related methods (ConstructAttributeList, EmitFunctionProlog and EmitCall): now they don't have to maintain iterators over the list of LLVM IR function arguments, dealing with all the sret/inalloca/this complexities, and just use expected positions of LLVM IR arguments stored in ClangToLLVMArgMapping. This may increase the running time of EmitFunctionProlog, as we have to traverse expandable arguments twice, but in further refactoring we will be able to speed up EmitCall by passing already calculated CallArgsToIRArgsMapping to ConstructAttributeList, thus avoiding traversing expandable argument there. No functionality change. Test Plan: regression test suite Reviewers: majnemer, rnk Reviewed By: rnk Subscribers: cfe-commits, rjmccall, timurrrr Differential Revision: http://reviews.llvm.org/D4938 llvm-svn: 216251
* Simplify some CodeGenTypes::arrangeXXX functions. No functionality changeAlexey Samsonov2014-08-131-28/+10
| | | | llvm-svn: 215606
* Simplify a few loops over CallArgList/FunctionArgList. NFCAlexey Samsonov2014-08-131-14/+10
| | | | llvm-svn: 215571
* [UBSan] Add returns-nonnull sanitizer.Alexey Samsonov2014-08-131-1/+18
| | | | | | | | | | | | | | | | | | | | Summary: This patch adds a runtime check verifying that functions annotated with "returns_nonnull" attribute do in fact return nonnull pointers. It is based on suggestion by Jakub Jelinek: http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20140623/223693.html. Test Plan: regression test suite Reviewers: rsmith Reviewed By: rsmith Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D4849 llvm-svn: 215485
* MS ABI: Use musttail for vtable thunks that pass arguments by valueReid Kleckner2014-07-261-13/+2
| | | | | | | | | | | | | This moves some memptr specific code into the generic thunk emission codepath. Fixes PR20053. Reviewers: majnemer Differential Revision: http://reviews.llvm.org/D4613 llvm-svn: 214004
* Cleanup comparisons to VariableArrayType::Static for non-VLAsHal Finkel2014-07-191-1/+1
| | | | | | | The enum is part of ArrayType, so there is no functional change, but comparing to ArrayType::Static for non-VLAs makes more sense. llvm-svn: 213446
* Use the dereferenceable attribute on C99 array parameters with staticHal Finkel2014-07-191-1/+37
| | | | | | | | | | | | | | In C99, an array parameter declarator might have the form: direct-declarator '[' 'static' type-qual-list[opt] assign-expr ']' where the static keyword indicates that the caller will always provide a pointer to the beginning of an array with at least the number of elements specified by the assignment expression. For constant sizes, we can use the new dereferenceable attribute to pass this information to the optimizer. For VLAs, we don't know the size, but (for addrspace(0)) do know that the pointer must be nonnull (and so we can use the nonnull attribute). llvm-svn: 213444
* Mark C++ reference parameters as dereferenceableHal Finkel2014-07-181-4/+16
| | | | | | | | | | | | | | Because references must be initialized using some evaluated expression, they must point to something, and a callee can assume the reference parameter is dereferenceable. Taking advantage of a new attribute just added to LLVM, mark them as such. Because dereferenceability in addrspace(0) implies nonnull in the backend, we don't need both attributes. However, we need to know the size of the object to use the dereferenceable attribute, so for incomplete types we still emit only nonnull. llvm-svn: 213386
* Add nonnull in CodeGen for __attribute__((returns_nonnull))Hal Finkel2014-07-121-0/+2
| | | | | | | As a follow-up to r212835, also add the LLVM nonnull function attribute when __attribute__((returns_nonnull)) is provided. llvm-svn: 212874
* Add nonnull in CodeGen for __attribute__((nonnull))Hal Finkel2014-07-111-0/+11
| | | | | | | | We now have an LLVM-level nonnull attribute that can be applied to function parameters, and we emit it for reference types (as of r209723), but did not emit it when an __attribute__((nonnull)) was provided. Now we will. llvm-svn: 212835
* MS ABI: "Fix" passing non-POD structs by value to variadic functionsReid Kleckner2014-07-081-20/+25
| | | | | | | | | | Of course, such code is horribly broken and will explode on impact. That said, ATL does it, and we have to support them, at least a little bit. Fixes PR20191. llvm-svn: 212508
* Add 'nonnull' parameter or return attribute when producing an llvm pointer ↵Nick Lewycky2014-05-281-0/+6
| | | | | | type in a function type where the C++ type is a reference. Update the tests. llvm-svn: 209723
* [C++11] Use 'nullptr'. CodeGen edition.Craig Topper2014-05-211-35/+35
| | | | llvm-svn: 209272
* Implement the flatten attribute.Peter Collingbourne2014-05-201-0/+6
| | | | | | | | | | This is a GNU attribute that causes calls within the attributed function to be inlined where possible. It is implemented by giving such calls the alwaysinline attribute. Differential Revision: http://reviews.llvm.org/D3816 llvm-svn: 209217
* Implement the no_split_stack attribute.Peter Collingbourne2014-05-191-1/+2
| | | | | | | | | This is a GNU attribute that allows split stacks to be turned off on a per-function basis. Differential Revision: http://reviews.llvm.org/D3817 llvm-svn: 209167
* MS ABI: Use musttail for thunk IR generationReid Kleckner2014-05-151-1/+1
| | | | | | | | | | | This allows us to perfectly forward non-trivial arguments that use inalloca. We still can't forward non-trivial arguments through thunks when we have a covariant return type with a non-trivial adjustment. This would require emitting an extra copy, which is non-conforming anyway. llvm-svn: 208927
* MS ABI: Pass 'sret' as the second parameter of instance methodsReid Kleckner2014-05-091-13/+52
| | | | | | | | | | | | | | | | | Summary: MSVC always passes 'sret' after 'this', unlike GCC. This required changing a number of places in Clang that assumed the sret parameter was always first in LLVM IR. This fixes win64 MSVC ABI compatibility for methods returning structs. Reviewers: rsmith, majnemer Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D3618 llvm-svn: 208458
* Reapply r208417 (olista01 'ARM: HFAs must be passed in consecutive ↵James Molloy2014-05-091-8/+34
| | | | | | registers'). Bots are now pacified. llvm-svn: 208425
* Revert r208417 (olista01 'ARM: HFAs must be passed in consecutive ↵James Molloy2014-05-091-34/+8
| | | | | | registers'). This is a followon commit from r208413 which broke the LLVM bots. llvm-svn: 208422
* ARM: HFAs must be passed in consecutive registersOliver Stannard2014-05-091-8/+34
| | | | | | | This is the clang counterpart to 208413, which ensures that Homogeneous Floating-point Aggregates are passed in consecutive registers on ARM. llvm-svn: 208417
* When doing int<->ptr coercion for big-endian, calculate the shift amount ↵James Molloy2014-05-071-2/+3
| | | | | | | | | | | | | | | correctly. Previously we calculated the shift amount based upon DataLayout::getTypeAllocSizeInBits. This will only work for legal types - types such as i24 that are created as part of structs for bitfields will return "32" from that function. Change to using getTypeSizeInBits. It turns out that AArch64 didn't run across this problem because it always returned [1 x i64] as the type for a bitfield, whereas ARM64 returns i64 so goes down this (better, but wrong) codepath. llvm-svn: 208231
* MS ABI x64: Pass small objects with dtors but no copy ctors directlyReid Kleckner2014-05-031-5/+10
| | | | | | | | | | | | | | | Passing objects directly (in registers or memory) creates a second copy of the object in the callee. The callee always destroys its copy, but we also have to destroy any temporary created in the caller. In other words, copy elision of these kinds of objects is impossible. Objects larger than 8 bytes with non-trivial dtors and trivial copy ctors are still passed indirectly, and we can still elide copies of them. Fixes PR19640. llvm-svn: 207889
* MS ABI x64: Don't destroy arguments twice on x64Reid Kleckner2014-05-011-4/+11
| | | | | | | | We were destroying them in the callee, and then again in the caller. We should use an EH-only cleanup and disable it at the point of the call for win64, even though we don't use inalloca. llvm-svn: 207733
* Update Clang for LLVM split stack API changes in r205997Reid Kleckner2014-04-101-0/+2
| | | | | | Patch by Alex Crichton! llvm-svn: 205998
* Avoid crashing when failing to emit a thunkReid Kleckner2014-04-101-2/+8
| | | | | | | | If we crash, we raise a crash handler dialog, and that's really annoying. Even though we can't emit correct IR until we have musttail, don't crash. llvm-svn: 205948
* MS ABI: Use the proper type for inalloca argsDavid Majnemer2014-03-311-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | Summary: The definition of a type later in a translation unit may change it's type from {}* to (%struct.foo*)*. Earlier function definitions may use the former while more recent definitions might use the later. This is fine until they interact with one another (like one calling the other). In these cases, a bitcast is needed because the inalloca must match the function call but the store to the lvalue which initializes the argument slot has to match the rvalue's type. This technique is along the same lines with what the other, non-inalloca, codepaths perform. This fixes PR19287. Reviewers: rnk CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D3224 llvm-svn: 205217
* ObjC: allow targets to decide when to use stret for blocks.Tim Northover2014-03-291-0/+5
| | | | | | | This was originally part of the ARM64 patch, but seems semantically separate. llvm-svn: 205097
* [C++11] Replacing CGFunctionInfo arg iterators with iterator_range ↵Aaron Ballman2014-03-171-8/+6
| | | | | | arguments(). Updating all of the usages of the iterators with range-based for loops. llvm-svn: 204068
* [C++11] Replacing CallArgList writeback iterators with iterator_range ↵Aaron Ballman2014-03-171-3/+2
| | | | | | writebacks(). Updating all of the usages of the iterators with range-based for loops, and removing the no-longer-needed iterator versions. llvm-svn: 204062
* [C++11] Add 'override' keyword to virtual methods that override their base ↵Craig Topper2014-03-121-1/+1
| | | | | | class. llvm-svn: 203643
* [C++11] Update Clang for the change to LLVM's Use-Def chain iterators inChandler Carruth2014-03-091-1/+1
| | | | | | | | | r203364: what was use_iterator is now user_iterator, and there is a use_iterator for directly iterating over the uses. This also switches to use the range-based APIs where appropriate. llvm-svn: 203365
* [C++11] Replacing RecordDecl iterators field_begin() and field_end() with ↵Aaron Ballman2014-03-081-20/+8
| | | | | | iterator_range fields(). Updating all of the usages of the iterators with range-based for loops. llvm-svn: 203355
* [C++11] Replacing ObjCMethodDecl iterators param_begin() and param_end() ↵Aaron Ballman2014-03-071-3/+2
| | | | | | with iterator_range params(). Updating all of the usages of the iterators with range-based for loops. llvm-svn: 203255
* [Modules] Update to reflect the move of CallSite into the IR library inChandler Carruth2014-03-041-1/+1
| | | | | | LLVM r202816. llvm-svn: 202817
* MS ABI: Return sret parameters when using inallocaReid Kleckner2014-02-251-2/+20
| | | | | | | | Previously the X86 backend would look for the sret attribute and handle this for us. inalloca takes that all away, so we have to do the return ourselves now. llvm-svn: 202097
* Exposing the noduplicate attribute within Clang, which marks functions so ↵Aaron Ballman2014-02-221-0/+2
| | | | | | | | that the optimizer does not duplicate code. Patch thanks to Marcello Maggioni! llvm-svn: 201941
* Remove local type use in template.Reid Kleckner2014-02-011-1/+1
| | | | llvm-svn: 200598
* [ms-cxxabi] Use inalloca on win32 when passing non-trivial C++ objectsReid Kleckner2014-02-011-44/+306
| | | | | | | | | | | | | | | | | | | When a non-trivial parameter is present, clang now gathers up all the parameters that lack inreg and puts them into a packed struct. MSVC always aligns each parameter to 4 bytes and no more, so this is a pretty simple struct to lay out. On win64, non-trivial records are passed indirectly. Prior to this change, clang was incorrectly using byval on win64. I'm able to self-host a working clang with this change and additional LLVM patches. Reviewers: rsmith Differential Revision: http://llvm-reviews.chandlerc.com/D2636 llvm-svn: 200597
OpenPOWER on IntegriCloud