summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CGObjCMac.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [CodeGen][ObjC] Push the properties of a protocol before pushing theAkira Hatanaka2020-01-061-3/+3
| | | | | | | | | | properties of the protocol it inherits This fixes a bug where the type string for a @dynamic property of an @implementation didn't have 'D' in it when the protocol it conforms to redeclares the property declared in the base protocol. rdar://problem/45503561
* [objc_direct] Tigthen checks for direct methodsPierre Habouzit2019-12-201-9/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Because the name of a direct method must be agreed upon by the caller and the implementation, certain bad practices that one can get away with when using dynamism are fatal with direct methods. To avoid really weird and unscruttable linker error, tighten the front-end error reporting. Rule 1: Direct methods can only have at most one declaration in an @interface container. Any redeclaration is strictly forbidden. Today some amount of redeclaration is tolerated between the main interface and categories for dynamic methods, but we can't have that. Rule 2: Direct method implementations can only be declared in a matching @interface container: when implemented in the primary @implementation then the declaration must be in the primary @interface or an extension, and when implemented in a category, the declaration must be in the @interface for the same category. Also fix another issue with ObjCMethod::getCanonicalDecl(): when an implementation lives in the primary @interface, then its canonical declaration can be in any extension, even when it's not an accessor. Add Sema tests to cover the new errors, and CG tests to beef up testing around function names for categories and extensions. Radar-Id: <rdar://problem/58054563> Differential Revision: https://reviews.llvm.org/D71694
* NFC: Get rid of an unused parameter to CGObjCMac::EmitSelectorAddr.Erik Pilkington2019-12-101-12/+10
|
* Avoid Attr.h includes, CodeGen editionReid Kleckner2019-12-091-1/+2
| | | | This saves around 20 includes of Attr.h. Not much.
* [ObjC] Make sure that the implicit arguments for direct methods have been setupAlex Lorenz2019-12-061-2/+2
| | | | | | | | | | | | | | | | | | | | This commit sets the Self and Imp declarations for ObjC method declarations, in addition to the definitions. It also fixes a bunch of code in clang that had wrong assumptions about when getSelfDecl() would be set: - CGDebugInfo::getObjCMethodName and AnalysisConsumer::getFunctionName would assume that it was set for method declarations part of a protocol, which they never were, and that self would be a Class type, which it isn't as it is id for a protocol. Also use the Canonical Decl to index the set of Direct methods so that when calls and implementations interleave, the same llvm::Function is used and the same symbol name emitted. Radar-Id: rdar://problem/57661767 Patch by: Pierre Habouzit Differential Revision: https://reviews.llvm.org/D71091
* Implement __attribute__((objc_direct)), __attribute__((objc_direct_members))Pierre Habouzit2019-11-181-27/+175
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | __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
* Redeclare Objective-C property accessors inside the ObjCImplDecl in which ↵Adrian Prantl2019-11-081-19/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | they are synthesized. This patch is motivated by (and factored out from) https://reviews.llvm.org/D66121 which is a debug info bugfix. Starting with DWARF 5 all Objective-C methods are nested inside their containing type, and that patch implements this for synthesized Objective-C properties. 1. SemaObjCProperty populates a list of synthesized accessors that may need to inserted into an ObjCImplDecl. 2. SemaDeclObjC::ActOnEnd inserts forward-declarations for all accessors for which no override was provided into their ObjCImplDecl. This patch does *not* synthesize AST function *bodies*. Moving that code from the static analyzer into Sema may be a good idea though. 3. Places that expect all methods to have bodies have been updated. I did not update the static analyzer's inliner for synthesized properties to point back to the property declaration (see test/Analysis/Inputs/expected-plists/nullability-notes.m.plist), which I believed to be more bug than a feature. Differential Revision: https://reviews.llvm.org/D68108 rdar://problem/53782400
* [Alignment][Clang][NFC] Add CharUnits::getAsAlignGuillaume Chatelet2019-10-031-18/+19
| | | | | | | | | | | | | | | | | | Summary: This is a prerequisite to removing `llvm::GlobalObject::setAlignment(unsigned)`. This is patch is part of a series to introduce an Alignment type. See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html See this patch for the introduction of the type: https://reviews.llvm.org/D64790 Reviewers: courbet Subscribers: jholewinski, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D68274 llvm-svn: 373592
* CGObjCMac - silence static analyzer dyn_cast<>/getAs<> null dereference ↵Simon Pilgrim2019-10-021-6/+4
| | | | | | | | warnings. NFCI. The static analyzer is warning about potential null dereferences, but we should be able to use cast<>/castAs<> directly and if not assert will fire for us. llvm-svn: 373520
* Silence gcc warning "control reaches end of non-void function" [NFCI]Mikael Holmen2019-07-051-0/+2
| | | | | | | | | | | | | | Without this fix gcc (7.4) complains with /data/repo/master/clang/lib/CodeGen/CGObjCMac.cpp: In member function 'std::__cxx11::string {anonymous}::CGObjCCommonMac::GetSectionName(llvm::StringRef, llvm::StringRef)': /data/repo/master/clang/lib/CodeGen/CGObjCMac.cpp:4944:1: error: control reaches end of non-void function [-Werror=return-type] } ^ All values in the ObjectFormatType enum are currently handled in the switch but gcc complains anyway. llvm-svn: 365174
* [NFC] Make some ObjectFormatType switches coveringHubert Tong2019-07-041-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | Summary: This patch removes the `default` case from some switches on `llvm::Triple::ObjectFormatType`, and cases for the missing enumerators are then added. For `UnknownObjectFormat`, the action (`llvm_unreachable`) for the `default` case is kept. For the other unhandled cases, `report_fatal_error` is used instead. Reviewers: sfertile, jasonliu, daltenty Reviewed By: sfertile Subscribers: wuzish, aheejin, jsji, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D63767 llvm-svn: 365160
* Add the `objc_class_stub` attribute.John McCall2019-05-301-13/+90
| | | | | | | | | | | | | | | | | | | | | | | | | Swift requires certain classes to be not just initialized lazily on first use, but actually allocated lazily using information that is only available at runtime. This is incompatible with ObjC class initialization, or at least not efficiently compatible, because there is no meaningful class symbol that can be put in a class-ref variable at load time. This leaves ObjC code unable to access such classes, which is undesirable. objc_class_stub says that class references should be resolved by calling a new ObjC runtime function with a pointer to a new "class stub" structure. Non-ObjC compilers (like Swift) can simply emit this structure when ObjC interop is required for a class that cannot be statically allocated, then apply this attribute to the `@interface` in the generated ObjC header for the class. This attribute can be thought of as a generalization of the existing `objc_runtime_visible` attribute which permits more efficient class resolution as well as supporting the additon of categories to the class. Subclassing these classes from ObjC is currently not allowed. Patch by Slava Pestov! llvm-svn: 362054
* [CodeGen][ObjC] Remove the leading `l_` from ObjC symbols and makeAkira Hatanaka2019-05-091-86/+99
| | | | | | | | | | | | | | | private symbols in the __DATA segment internal. This prevents the linker from removing the symbol names. Keeping the symbols visible enables tools to collect various information about the symbols, for example, tools that discover whether or not a symbol gets dirtied. rdar://problem/48887111 Differential Revision: https://reviews.llvm.org/D61454 llvm-svn: 360359
* Support objc_nonlazy_class attribute on Objective-C implementationsErik Pilkington2019-04-111-1/+2
| | | | | | | | Fixes rdar://49523079 Differential revision: https://reviews.llvm.org/D60544 llvm-svn: 358201
* [CodeGen][ObjC] Remove the leading 'l' from symbols for protocolAkira Hatanaka2019-03-141-3/+3
| | | | | | | | | | | | | metadata and protocol list The leading 'l' tells ld64 to remove the symbol name, which can make debugging difficult. rdar://problem/47256637 Differential Revision: https://reviews.llvm.org/D59234 llvm-svn: 356156
* [opaque pointer types] Cleanup CGBuilder's Create*GEP.James Y Knight2019-02-091-12/+7
| | | | | | | | | | | | | | The various EltSize, Offset, DataLayout, and StructLayout arguments are all computable from the Address's element type and the DataLayout which the CGBuilder already has access to. After having previously asserted that the computed values are the same as those passed in, now remove the redundant arguments from CGBuilder's Create*GEP functions. Differential Revision: https://reviews.llvm.org/D57767 llvm-svn: 353629
* [opaque pointer types] Pass function types for runtime function calls.James Y Knight2019-02-051-91/+89
| | | | | | | | | | | | | 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
* [OBJC] Add attribute to mark Objective C class as non-lazyJoe Daniels2019-02-041-3/+4
| | | | | | | | | | | | | A non-lazy class will be initialized eagerly when the Objective-C runtime is loaded. This is required for certain system classes which have instances allocated in non-standard ways, such as the classes for blocks and constant strings. Adding this attribute is essentially equivalent to providing a trivial +load method but avoids the (fairly small) load-time overheads associated with defining and calling such a method. Differential Revision: https://reviews.llvm.org/D56555 llvm-svn: 353116
* Cleanup: replace uses of CallSite with CallBase.James Y Knight2019-01-301-10/+12
| | | | llvm-svn: 352595
* 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
* [CodeGenObjC] Use a constant value for non-fragile ivar offsets when possibleErik Pilkington2019-01-171-11/+33
| | | | | | | | | | | | | | | If a class inherits from NSObject and has an implementation, then we can assume that ivar offsets won't need to be updated by the runtime. This allows us to index into the object using a constant value and avoid loading from the ivar offset variable. This patch was adapted from one written by Pete Cooper. rdar://problem/10132568 Differential revision: https://reviews.llvm.org/D56802 llvm-svn: 351461
* Move CodeGenOptions from Frontend to BasicRichard Trieu2018-12-111-1/+1
| | | | | | Basic uses CodeGenOptions and should not depend on Frontend. llvm-svn: 348827
* [CodeGen] Handle extern references to OBJC_CLASS_$_*Erik Pilkington2018-10-121-6/+12
| | | | | | | | | | | | | | | | | | | | | | Some ObjC users declare a extern variable named OBJC_CLASS_$_Foo, then use it's address as a Class. I.e., one could define isInstanceOfF: BOOL isInstanceOfF(id c) { extern void OBJC_CLASS_$_F; return [c class] == (Class)&OBJC_CLASS_$_F; } This leads to asserts in clang CodeGen if there is an @implementation of F in the same TU as an instance of this pattern, because CodeGen assumes that a variable named OBJC_CLASS_$_* has the right type. This commit fixes the problem by RAUWing the old (incorrectly typed) global with a new global, then removing the old global. rdar://45077269 Differential revision: https://reviews.llvm.org/D53154 llvm-svn: 344373
* [ObjC] Error out when using forward-declared protocol in a @protocolAlex Lorenz2018-08-171-2/+3
| | | | | | | | | | | | | | | | | | | | | | expression Clang emits invalid protocol metadata when a @protocol expression is used with a forward-declared protocol. The protocol metadata is missing protocol conformance list of the protocol since we don't have access to the definition of it in the compiled translation unit. The linker then might end up picking the invalid metadata when linking which will lead to incorrect runtime protocol conformance checks. This commit makes sure that Clang fails to compile code that uses a @protocol expression with a forward-declared protocol. This ensures that Clang does not emit invalid protocol metadata. I added an extra assert in CodeGen to ensure that this kind of issue won't happen in other places. rdar://32787811 Differential Revision: https://reviews.llvm.org/D49462 llvm-svn: 340102
* [CodeGen] Merge identical block descriptor global variables.Akira Hatanaka2018-08-171-2/+57
| | | | | | | | | | | | | | | | | | 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
* Remove trailing spaceFangrui Song2018-07-301-114/+114
| | | | | | sed -Ei 's/[[:space:]]+$//' include/**/*.{def,h,td} lib/**/*.{cpp,h} llvm-svn: 338291
* Remove \brief commands from doxygen comments.Adrian Prantl2018-05-091-1/+1
| | | | | | | | | | | | | | | | | | | This is similar to the LLVM change https://reviews.llvm.org/D46290. We've been running doxygen with the autobrief option for a couple of years now. This makes the \brief markers into our comments redundant. Since they are a visual distraction and we don't want to encourage more \brief markers in new code either, this patch removes them all. Patch produced by for i in $(git grep -l '\@brief'); do perl -pi -e 's/\@brief //g' $i & done for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done Differential Revision: https://reviews.llvm.org/D46320 llvm-svn: 331834
* Fix typos in clangAlexander Kornienko2018-04-061-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Found via codespell -q 3 -I ../clang-whitelist.txt Where whitelist consists of: archtype cas classs checkk compres definit frome iff inteval ith lod methode nd optin ot pres statics te thru Patch by luzpaz! (This is a subset of D44188 that applies cleanly with a few files that have dubious fixes reverted.) Differential revision: https://reviews.llvm.org/D44188 llvm-svn: 329399
* [ObjC] Use the name specified by objc_runtime_name instead of the classAkira Hatanaka2018-04-031-2/+6
| | | | | | | | | | | | | identifier. This patch fixes a few places in CGObjCMac.cpp where the class identifier was used instead of the name specified by objc_runtime_name. rdar://problem/37910822 Differential Revision: https://reviews.llvm.org/D45101 llvm-svn: 329128
* Recommit r326946 after reducing CallArgList memory footprintYaxun Liu2018-03-151-2/+2
| | | | llvm-svn: 327634
* Revert r326946. It caused stack overflows by significantly increasing the ↵Richard Smith2018-03-101-2/+2
| | | | | | size of a CallArgList. llvm-svn: 327195
* CodeGen: Fix address space of indirect function argumentYaxun Liu2018-03-071-2/+2
| | | | | | | | | | | | | | | | | | | | | The indirect function argument is in alloca address space in LLVM IR. However, during Clang codegen for C++, the address space of indirect function argument should match its address space in the source code, i.e., default addr space, even for indirect argument. This is because destructor of the indirect argument may be called in the caller function, and address of the indirect argument may be taken, in either case the indirect function argument is expected to be in default addr space, not the alloca address space. Therefore, the indirect function argument should be mapped to the temp var casted to default address space. The caller will cast it to alloca addr space when passing it to the callee. In the callee, the argument is also casted to the default address space and used. CallArg is refactored to facilitate this fix. Differential Revision: https://reviews.llvm.org/D34367 llvm-svn: 326946
* Start setting dllimport/dllexport in setGVProperties.Rafael Espindola2018-03-011-16/+5
| | | | | | | | | | This is the next step in setting dso_local for COFF. The patches changes setGVProperties to first set dllimport/dllexport and changes a few cases that were setting dllimport/dllexport manually. With this a few more GVs are marked dso_local. llvm-svn: 326397
* CodeGen: use `llvm.used` for ObjC protocolsSaleem Abdulrasool2018-01-231-3/+3
| | | | | | | | | These symbols are supposed to be preserved even by the linker. Use the `llvm.used` to ensure that the symbols are not removed by DCE in the linker. This should be a no-op change on MachO since the symbols are annotated as `no_dead_strip`. llvm-svn: 323247
* Remove unused addIfPresent function.Eric Christopher2018-01-131-4/+0
| | | | llvm-svn: 322427
* [driver] Set the 'simulator' environment for Darwin when compiling forAlex Lorenz2017-12-071-4/+1
| | | | | | | | | | iOS/tvOS/watchOS simulator rdar://35135215 Differential Revision: https://reviews.llvm.org/D40682 llvm-svn: 320073
* [CodeGen] Compute the objc EH vtable address point using inbounds GEP.Ahmed Bougacha2017-11-171-2/+3
| | | | | | | | | | | | | | | | The object is provided by the objc runtime and is never visible in the module itself, but even so, the address point we compute points into it, and "+16" is guaranteed not to overflow. This matches the c++ vtable IRGen. Note that I'm not entirely convinced the 'i8*' type is correct here: at the IR level, we're accessing memory that's outside the global object. But we don't control the allocation, so it's not obviously wrong either. But either way, this is only in a global initializer, so I don't think it's going to be mucked with. Filed PR35352 to discuss that. llvm-svn: 318545
* [CodeGen] Add support for IncompleteArrayType in Obj-C ivars.Volodymyr Sapsai2017-10-271-0/+5
| | | | | | | | | | | | | | | | | Fixes an assertion failure when ivar is a struct containing incomplete array. Also completes support for direct flexible array members. rdar://problem/21054495 Reviewers: rjmccall, theraven Reviewed By: rjmccall Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D38774 llvm-svn: 316723
* CodeGen: fix a case of incorrect checks for ivarsSaleem Abdulrasool2017-10-251-4/+8
| | | | | | | | Ensure that we check the ivar containing decl for the DLL storage attribute rather than the ivar itself as the dll storage is associated to the interface decl not the ivar decl. llvm-svn: 316545
* Revert "[ADT] Make Twine's copy constructor private."Zachary Turner2017-10-111-35/+40
| | | | | | | | | | This reverts commit 4e4ee1c507e2707bb3c208e1e1b6551c3015cbf5. This is failing due to some code that isn't built on MSVC so I didn't catch. Not immediately obvious how to fix this at first glance, so I'm reverting for now. llvm-svn: 315536
* [ADT] Make Twine's copy constructor private.Zachary Turner2017-10-111-40/+35
| | | | | | | | | | | | | | | | | There's a lot of misuse of Twine scattered around LLVM. This ranges in severity from benign (returning a Twine from a function by value that is just a string literal) to pretty sketchy (storing a Twine by value in a class). While there are some uses for copying Twines, most of the very compelling ones are confined to the Twine class implementation itself, and other uses are either dubious or easily worked around. This patch makes Twine's copy constructor private, and fixes up all callsites. Differential Revision: https://reviews.llvm.org/D38767 llvm-svn: 315530
* [objc] Don't require null-check and don't emit memset when result is ignored ↵Kuba Mracek2017-06-301-11/+22
| | | | | | | | | | for struct-returning method calls [clang part] This fixes an issue with the emission of lifetime markers for struct-returning Obj-C msgSend calls. When the result of a struct-returning call is ignored, the temporary storage is only marked with lifetime markers in one of the two branches of the nil-receiver-check. The check is, however, not required when the result is unused. If we still need to emit the check (due to consumer arguments), let's not emit the memset to zero out the result if it's unused. This fixes a use-after-scope false positive with AddressSanitizer. Differential Revision: https://reviews.llvm.org/D34834 llvm-svn: 306837
* CodeGen: handle missed case of COMDAT handlingSaleem Abdulrasool2017-06-291-6/+5
| | | | | | | | When Protocol references are constructed, we need to add the reference symbol to a COMDAT group on non-MachO object file formats (MachO handles this by having a coalesced attribute). This adds the missing case. llvm-svn: 306622
* CodeGen: make the type match the comment for a libcallSaleem Abdulrasool2017-06-171-1/+1
| | | | | | | | Fix the type for a (runtime) library call to match both the comment and the runtime implementation. As it happens, the type being used matched, this just makes it more precise. llvm-svn: 305638
* CodeGen: fix section names for different file formatsSaleem Abdulrasool2017-06-031-16/+49
| | | | | | | | | This changes the codegen to match the section names according to the ObjC rewriter as well as the runtime. The changes to the test are simply whitespace changes to the section attributes and names and are functionally equivalent (the whitespace is ignored by the linker). llvm-svn: 304661
* Suppress all uses of LLVM_END_WITH_NULL. NFC.Serge Guelton2017-05-091-105/+65
| | | | | | | | | | 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
* Adapt to LLVM's rename of WeakVH to WeakTrackingVH; NFCSanjoy Das2017-05-011-1/+1
| | | | llvm-svn: 301815
* Revert "Update to LLVM's use of WeakTrackingVH; NFC"Sanjoy Das2017-04-261-1/+1
| | | | | | This reverts commit r301427. llvm-svn: 301430
* Update to LLVM's use of WeakTrackingVH; NFCSanjoy Das2017-04-261-1/+1
| | | | | | | | | | | | Summary: Depends on D32266 Reviewers: davide, dblaikie Subscribers: mcrosier, llvm-commits Differential Revision: https://reviews.llvm.org/D32270 llvm-svn: 301427
* Update Clang for LLVM rename AttributeSet -> AttributeListReid Kleckner2017-03-211-14/+10
| | | | llvm-svn: 298394
OpenPOWER on IntegriCloud