summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CGObjCRuntime.h
Commit message (Collapse)AuthorAgeFilesLines
* Implement __attribute__((objc_direct)), __attribute__((objc_direct_members))Pierre Habouzit2019-11-181-0/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | __attribute__((objc_direct)) is an attribute on methods declaration, and __attribute__((objc_direct_members)) on implementation, categories or extensions. A `direct` property specifier is added (@property(direct) type name) These attributes / specifiers cause the method to have no associated Objective-C metadata (for the property or the method itself), and the calling convention to be a direct C function call. The symbol for the method has enforced hidden visibility and such direct calls are hence unreachable cross image. An explicit C function must be made if so desired to wrap them. The implicit `self` and `_cmd` arguments are preserved, however to maintain compatibility with the usual `objc_msgSend` semantics, 3 fundamental precautions are taken: 1) for instance methods, `self` is nil-checked. On arm64 backends this typically adds a single instruction (cbz x0, <closest-ret>) to the codegen, for the vast majority of the cases when the return type is a scalar. 2) for class methods, because the class may not be realized/initialized yet, a call to `[self self]` is emitted. When the proper deployment target is used, this is optimized to `objc_opt_self(self)`. However, long term we might want to emit something better that the optimizer can reason about. When inlining kicks in, these calls aren't optimized away as the optimizer has no idea that a single call is really necessary. 3) the calling convention for the `_cmd` argument is changed: the caller leaves the second argument to the call undefined, and the selector is loaded inside the body when it's referenced only. As far as error reporting goes, the compiler refuses: - making any overloads direct, - making an overload of a direct method, - implementations marked as direct when the declaration in the interface isn't (the other way around is allowed, as the direct attribute is inherited from the declaration), - marking methods required for protocol conformance as direct, - messaging an unqualified `id` with a direct method, - forming any @selector() expression with only direct selectors. As warnings: - any inconsistency of direct-related calling convention when @selector() or messaging is used, - forming any @selector() expression with a possibly direct selector. Lastly an `objc_direct_members` attribute is added that can decorate `@implementation` blocks and causes methods only declared there (and in no `@interface`) to be automatically direct. When decorating an `@interface` then all methods and properties declared in this block are marked direct. Radar-ID: rdar://problem/2684889 Differential Revision: https://reviews.llvm.org/D69991 Reviewed-By: John McCall
* [opaque pointer types] Pass function types for runtime function calls.James Y Knight2019-02-051-17/+16
| | | | | | | | | | | | | Emit{Nounwind,}RuntimeCall{,OrInvoke} have been modified to take a FunctionCallee as an argument, and CreateRuntimeFunction has been modified to return a FunctionCallee. All callers have been updated. Additionally, CreateBuiltinFunction is removed, as it was redundant with CreateRuntimeFunction after some previous changes. Differential Revision: https://reviews.llvm.org/D57668 llvm-svn: 353184
* 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
* [CodeGen] Merge identical block descriptor global variables.Akira Hatanaka2018-08-171-0/+4
| | | | | | | | | | | | | | | | | | Currently, clang generates a new block descriptor global variable for each new block literal. This commit merges block descriptors that are identical inside and across translation units using the same approach taken in r339438. To enable merging identical block descriptors, the size and signature of the block and information about the captures are encoded into the name of the block descriptor variable. Also, the block descriptor variable is marked as linkonce_odr and unnamed_addr. rdar://problem/42640703 Differential Revision: https://reviews.llvm.org/D50783 llvm-svn: 340041
* Add Windows support for the GNUstep Objective-C ABI V2.David Chisnall2018-08-101-0/+3
| | | | | | | | | | | | | | | | | | | | | Summary: Introduces funclet-based unwinding for Objective-C and fixes an issue where global blocks can't have their isa pointers initialised on Windows. After discussion with Dustin, this changes the name mangling of Objective-C types to prevent a C++ catch statement of type struct X* from catching an Objective-C object of type X*. Reviewers: rjmccall, DHowett-MSFT Reviewed By: rjmccall, DHowett-MSFT Subscribers: mgrang, mstorsjo, smeenai, cfe-commits Differential Revision: https://reviews.llvm.org/D50144 llvm-svn: 339428
* Remove trailing spaceFangrui Song2018-07-301-6/+6
| | | | | | sed -Ei 's/[[:space:]]+$//' include/**/*.{def,h,td} lib/**/*.{cpp,h} llvm-svn: 338291
* Clean up CGObjCMac's APIs for deriving class references. NFC.John McCall2016-11-301-3/+0
| | | | llvm-svn: 288295
* Reduce the number of implicit StringRef->std::string conversions by ↵Benjamin Kramer2016-02-131-1/+1
| | | | | | | | threading StringRef through more APIs. No functionality change intended. llvm-svn: 260815
* Reapply "[CodeGen] Fix assignments of inline layouts into the byref structure"Vedant Kumar2015-12-211-0/+3
| | | | | | | | | | | | | | | | | | | When using blocks, a byref structure is created to represent the closure. The "byref.layout" field of this structure is an i8*. However, some 'inline' layouts are represented as i64's, not i8*'s. Prior to r246985 we cast the i64 'inline' layout to an i8* before assigning it into the byref structure. This patch brings the cast back and adds a regression test. The original version of this patch was too invasive. This version only adds the cast to BuildByrefLayout. Differential Revision: http://reviews.llvm.org/D15674 rdar://23713871 llvm-svn: 256190
* Revert "[CodeGen] Fix assignments of inline layouts into the byref structure"Vedant Kumar2015-12-211-3/+0
| | | | | | This reverts commit r256185. It breaks CodeGenObjC/fragile-arc.m. llvm-svn: 256186
* [CodeGen] Fix assignments of inline layouts into the byref structureVedant Kumar2015-12-211-0/+3
| | | | | | | | | | | | | | When using blocks, a byref structure is created to represent the closure. The "byref.layout" field of this structure is an i8*. However, some 'inline' layouts are represented as i64's, not i8*'s. Prior to r246985 we cast the i64 'inline' layout to an i8* before assigning it into the byref structure. This patch brings the cast back and adds a regression test. rdar://23713871 llvm-svn: 256185
* Initialize @catch variables correctly in fragile-runtime ARC.John McCall2015-10-301-0/+4
| | | | llvm-svn: 251677
* Compute and preserve alignment more faithfully in IR-generation.John McCall2015-09-081-12/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Revert r240270 ("Fixed/added namespace ending comments using clang-tidy").Alexander Kornienko2015-06-221-2/+2
| | | | llvm-svn: 240353
* Fixed/added namespace ending comments using clang-tidy. NFCAlexander Kornienko2015-06-221-2/+2
| | | | | | | | | | | | 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
* Header guard canonicalization, clang part.Benjamin Kramer2014-08-131-2/+2
| | | | | | Modifications made by clang-tidy with minor tweaks. llvm-svn: 215557
* [C++11] Use 'nullptr'. CodeGen edition.Craig Topper2014-05-211-3/+3
| | | | llvm-svn: 209272
* Refactor linkage computation in CGObjCMac.cpp.Rafael Espindola2014-02-261-1/+2
| | | | | | | | | | | | | | Before this patch the globals were created with the wrong linkage and patched afterwards. From the comments it looks like something would complain about having an internal GV with no initializer. At least in clang the verifier will only run way after we set the initializer, so that is not a problem. This patch should be a nop. It just figures out the linkage earlier and converts the old calls to setLinkage to asserts. The only case where that is not possible is when we first see a weak import that is then implemented. In that case we have to change the linkage, but that is the only setLinkage left. llvm-svn: 202305
* Use the actual ABI-determined C calling convention for runtimeJohn McCall2013-02-281-5/+5
| | | | | | | | | | | | | | | | | | | | | | calls and declarations. LLVM has a default CC determined by the target triple. This is not always the actual default CC for the ABI we've been asked to target, and so we sometimes find ourselves annotating all user functions with an explicit calling convention. Since these calling conventions usually agree for the simple set of argument types passed to most runtime functions, using the LLVM-default CC in principle has no effect. However, the LLVM optimizer goes into histrionics if it sees this kind of formal CC mismatch, since it has no concept of CC compatibility. Therefore, if this module happens to define the "runtime" function, or got LTO'ed with such a definition, we can miscompile; so it's quite important to get this right. Defining runtime functions locally is quite common in embedded applications. llvm-svn: 176286
* objectiveC++: When throwing c++ exception of Fariborz Jahanian2013-01-101-1/+2
| | | | | | | an objectiveC object, use objc_exception_throw to raise the exception. // rdar://12605907 llvm-svn: 172091
* Reapply r170344, this time without forgetting to commit the header changes.David Chisnall2012-12-171-3/+6
| | | | llvm-svn: 170354
* Revert "Added support for new property helpers (GNUstep runtime)."Benjamin Kramer2012-12-171-6/+3
| | | | | | This reverts commit r170344. Doesn't even compile. llvm-svn: 170351
* Added support for new property helpers (GNUstep runtime).David Chisnall2012-12-171-3/+6
| | | | llvm-svn: 170344
* Sort all of Clang's files under 'lib', and fix up the broken headersChandler Carruth2012-12-041-3/+2
| | | | | | | | | | | | | 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
* objective-C blocks: Provide layout map for byrefFariborz Jahanian2012-11-141-0/+2
| | | | | | variables captured in a block. // rdar://12184410 llvm-svn: 167931
* Put something sane in the DWARF offset field for bitfield ObjC ivars.Eli Friedman2012-11-061-0/+6
| | | | | | | | | This is useful because unnamed bitfields can have effects on the offsets which are not otherwise reflected in the DWARF information. <rdar://problem/12629719> llvm-svn: 167503
* Back out 167431+167437+167487; I didn't realize how incomplete our testEli Friedman2012-11-061-6/+6
| | | | | | coverage of this code is. llvm-svn: 167495
* Propagate CharUnits into ObjC CodeGen. No intended functional change.Eli Friedman2012-11-061-6/+6
| | | | llvm-svn: 167431
* objective-C arc/mrr: Patch for the new block variable layout meta-data.Fariborz Jahanian2012-10-271-0/+2
| | | | | | It is currently off (so no tests). This is wip. llvm-svn: 166892
* Documentation cleanup:James Dennett2012-06-151-9/+9
| | | | | | | | * Escaped Objective-C @keywords in Doxygen comments; * Documented more accurate \params; * Exposed some more summaries using \brief. llvm-svn: 158559
* Documentation cleanup, fixing Doxygen markup. Mostly this avoids common termsJames Dennett2012-06-111-1/+1
| | | | | | | | | | | | | | such as "protocol" and "expression" being implicitly turned into links to mistakenly-generated Doxygen pages: - Escaping @ symbols when Doxygen would otherwise incorrectly interpret them; - Escaping # symbols when they're not intended as explicit Doxygen link requests, such as when discussing preprocessor directives; - In one odd case, unescaping @ in @__experimental_modules_import, because Doxygen wrote '\@' to the output in that case, causing the example in the description of ImportDecl to be wrong; and - Fixing a typo: @breif -> @brief. llvm-svn: 158299
* Add clang support for new Objective-C literal syntax for NSDictionary, NSArray,Ted Kremenek2012-03-061-1/+5
| | | | | | | | | | | | | NSNumber, and boolean literals. This includes both Sema and Codegen support. Included is also support for new Objective-C container subscripting. My apologies for the large patch. It was very difficult to break apart. The patch introduces changes to the driver as well to cause clang to link in additional runtime support when needed to support the new language features. Docs are forthcoming to document the implementation and behavior of these features. llvm-svn: 152137
* Whether an argument is required (in contrast with being anJohn McCall2012-02-171-0/+16
| | | | | | | | | | | | | | | | | | | | | optional argument passed through the variadic ellipsis) potentially affects how we need to lower it. Propagate this information down to the various getFunctionInfo(...) overloads on CodeGenTypes. Furthermore, rename those overloads to clarify their distinct purposes, and make sure we're calling the right one in the right place. This has a nice side-effect of making it easier to construct a function type, since the 'variadic' bit is no longer separable. This shouldn't really change anything for our existing platforms, with one minor exception --- we should now call variadic ObjC methods with the ... in the "right place" (see the test case), which I guess matters for anyone running GNUStep on MIPS. Mostly it's just a substantial clean-up. llvm-svn: 150788
* Support @compatibility_alias at run time (GNUstep Runtime)David Chisnall2012-01-311-0/+3
| | | | | | Patch by Niels Grewe! llvm-svn: 149401
* objc++: some declarations related to atomicFariborz Jahanian2012-01-061-0/+3
| | | | | | | properties of c++ object types with non-trivial assignment copy. Not used yet. // rdar://6137845 llvm-svn: 147666
* Switch assert(0/false) llvm_unreachable.David Blaikie2011-09-231-2/+1
| | | | llvm-svn: 140367
* Support for catching objc pointer objects in c++ catch-statementFariborz Jahanian2011-06-231-2/+1
| | | | | | in fragile abi mode and some other cleanups. // rdar://8940528 llvm-svn: 133747
* Alloa catching Objective-C id's being thrown with C++ throwFariborz Jahanian2011-06-221-1/+2
| | | | | | in Darwin's fragile abi mode. // rdar://8940528 llvm-svn: 133639
* Automatic Reference Counting.John McCall2011-06-151-1/+7
| | | | | | | | | | Language-design credit goes to a lot of people, but I particularly want to single out Blaine Garst and Patrick Beard for their contributions. Compiler implementation credit goes to Argyrios, Doug, Fariborz, and myself, in no particular order. llvm-svn: 133103
* Fix some problems where functions must be bitcast but we're expecting a ↵David Chisnall2011-05-231-3/+3
| | | | | | | | llvm::Function of the right type. PR9994. llvm-svn: 131930
* Patch to fix IR-gen crash generating structure ABI which implementsFariborz Jahanian2011-05-171-0/+1
| | | | | | | user specified string class via -fconstant-string-class option. pr9914. llvm-svn: 131496
* Remove unused STL header includes.Jay Foad2011-04-231-1/+0
| | | | llvm-svn: 130068
* fix a bunch of comment typos found by codespell. Patch byChris Lattner2011-04-151-1/+1
| | | | | | Luis Felipe Strano Moraes! llvm-svn: 129559
* Continuing work on ObjC tidyup:David Chisnall2011-03-251-0/+20
| | | | | | | | | | | | | | | | - Moved the CGObjCRuntime functions out of CGObjCMac.cpp into CGObjCRuntime.cpp - Added generic functions in CGObjCRuntime for emitting @try and @synchronize blocks, usable by any runtime that uses DWARF exceptions. - Made the GNU runtimes use these functions. It should now be possible to replace the equivalent functions in CGObjCNonFragileABIMac with simple calls to these two functions, providing the runtime functions as arguments. I'll post a diff to the list for review before making any changes to the Mac runtime stuff. llvm-svn: 128274
* Simplify Mac runtime selection - it's the factory function's job to select ↵David Chisnall2011-03-221-1/+0
| | | | | | which class to produce, not CodeGenModule's. llvm-svn: 128109
* A few more tweaks to the blocks AST representation: John McCall2011-02-071-3/+3
| | | | | | | | | | | | | | | | | - BlockDeclRefExprs always store VarDecls - BDREs no longer store copy expressions - BlockDecls now store a list of captured variables, information about how they're captured, and a copy expression if necessary With that in hand, change IR generation to use the captures data in blocks instead of walking the block independently. Additionally, optimize block layout by emitting fields in descending alignment order, with a heuristic for filling in words when alignment of the end of the block header is insufficient for the most aligned field. llvm-svn: 125005
* Add support for GNU runtime property set / get structure functions. Minor ↵David Chisnall2010-12-261-2/+4
| | | | | | refactoring of Mac runtime (returns the same function for both, as the Mac runtimes currently only provide a single entry point for setting and getting struct properties, although this will presumably be fixed at some point). llvm-svn: 122569
* Fixes an obscure bug in importd block variable layoutFariborz Jahanian2010-09-111-1/+1
| | | | | | | | information when imported variable is used more than once. Originally though to be a bug in importing block varibles. Fixes radar 8417746. llvm-svn: 113675
* Some early work for providing block layout info. Fariborz Jahanian2010-08-041-0/+4
| | | | | | for objective-c/c++ blocks (NeXt runtime). llvm-svn: 110213
* Support catching Objective C pointers in C++ under the non-fragile NeXT runtime.John McCall2010-07-241-0/+6
| | | | | | Diagnose attempts to do this under the GNU or fragile NeXT runtimes. llvm-svn: 109298
OpenPOWER on IntegriCloud