aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CGObjCMac.cpp
AgeCommit message (Collapse)AuthorFilesLines
2023-02-14Revert "[NFC][IR] Make Module::getGlobalList() private"Vasileios Porpodas1-1/+1
This reverts commit ed3e3ee9e30dfbffd2170a770a49b36a7f444916.
2023-02-14[NFC][IR] Make Module::getGlobalList() privateVasileios Porpodas1-1/+1
This patch adds several missing GlobalList modifier functions, like removeGlobalVariable(), eraseGlobalVariable() and insertGlobalVariable(). There is no longer need to access the list directly so it also makes getGlobalList() private. Differential Revision: https://reviews.llvm.org/D144027
2023-01-13[clang][NFC] Remove dependency on DataLayout::getPrefTypeAlignmentGuillaume Chatelet1-8/+6
2022-12-03[CodeGen] Use std::nullopt instead of None (NFC)Kazu Hirata1-2/+2
This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-11-30[clang][TargetInfo] Use LangAS for getPointer{Width,Align}()Alex Richardson1-4/+4
Mixing LLVM and Clang address spaces can result in subtle bugs, and there is no need for this hook to use the LLVM IR level address spaces. Most of this change is just replacing zero with LangAS::Default, but it also allows us to remove a few calls to getTargetAddressSpace(). This also removes a stale comment+workaround in CGDebugInfo::CreatePointerLikeType(): ASTContext::getTypeSize() does return the expected size for ReferenceType (and handles address spaces). Differential Revision: https://reviews.llvm.org/D138295
2022-11-04[IR] Switch everything to use memory attributeNikita Popov1-4/+7
This switches everything to use the memory attribute proposed in https://discourse.llvm.org/t/rfc-unify-memory-effect-attributes/65579. The old argmemonly, inaccessiblememonly and inaccessiblemem_or_argmemonly attributes are dropped. The readnone, readonly and writeonly attributes are restricted to parameters only. The old attributes are auto-upgraded both in bitcode and IR. The bitcode upgrade is a policy requirement that has to be retained indefinitely. The IR upgrade is mainly there so it's not necessary to update all tests using memory attributes in this patch, which is already large enough. We could drop that part after migrating tests, or retain it longer term, to make it easier to import IR from older LLVM versions. High-level Function/CallBase APIs like doesNotAccessMemory() or setDoesNotAccessMemory() are mapped transparently to the memory attribute. Code that directly manipulates attributes (e.g. via AttributeList) on the other hand needs to switch to working with the memory attribute instead. Differential Revision: https://reviews.llvm.org/D135780
2022-09-21Remove the unused/undefined `_cmd` parameter in `objc_direct` methods.Michael Wyman1-1/+5
When `objc_direct` methods were implemented, the implicit `_cmd` parameter was left as an argument to the method implementation function, but was unset by callers; if the method body referenced the `_cmd` variable, a selector load would be emitted inside the body. However, this leaves an unused argument in the ABI, and is unnecessary. This change removes the empty/unset argument, and if `_cmd` is referenced inside an `objc_direct` method it will emit local storage for the implicit variable. From the ABI perspective, `objc_direct` methods will have the implicit `self` parameter, immediately followed by whatever explicit arguments are defined on the method, rather than having one unset/undefined register in the middle. Differential Revision: https://reviews.llvm.org/D131424
2022-09-03[clang] Qualify auto in range-based for loops (NFC)Kazu Hirata1-2/+2
2022-08-04[ObjC] type method metadata `_imp`, messenger routine at callsite with ↵Matt Jacobson1-3/+6
program address space On targets with non-default program address space (e.g., Harvard architectures), clang crashes when emitting Objective-C method metadata, because the address of the method IMP cannot be bitcast to i8*. It similarly crashes at messenger callsite with a failed bitcast. Define the _imp field instead as i8 addrspace(1)* (or whatever the target's program address space is). And in getMessageSendInfo(), create signatureType by specifying the program address space. Add a regression test using the AVR target. Test failed previously and passes now. Checked codegen of the test for x86_64-apple-darwin19.6.0 and saw no difference, as expected. Reviewed By: rjmccall, dylanmckay Differential Revision: https://reviews.llvm.org/D112113
2022-04-19[CodeGen] Fix -Wswitch after D116462Fangrui Song1-0/+1
2022-03-29NFC. Fixing warnings from adding DXContainerChris Bieneman1-0/+1
Adds DXContainer to switch statements in Clang and LLDB to silence warnings.
2022-03-23[CGObjCMac] Check global value type instead of poitner typeNikita Popov1-1/+1
As we're going to reassign the initializer, we actually need the value types to match, not just the pointer types. This is only relevant with opaque pointers.
2022-03-11[NFC][Clang][OpaquePtr] Remove calls to Address::deprecated in a coupleAkira Hatanaka1-2/+2
more files Differential Revision: https://reviews.llvm.org/D121135
2022-02-17[CodeGen] Rename deprecated Address constructorNikita Popov1-3/+3
To make uses of the deprecated constructor easier to spot, and to ensure that no new uses are introduced, rename it to Address::deprecated(). While doing the rename, I've filled in element types in cases where it was relatively obvious, but we're still left with 135 calls to the deprecated constructor.
2022-02-14[CGBuilder] Remove CreateBitCast() methodNikita Popov1-25/+34
Use CreateElementBitCast() instead, or don't work on Address where not necessary.
2022-01-26[ObjC] Emit selector load right before msgSend call.Ahmed Bougacha1-10/+12
We currently emit the selector load early, but only because we need it to compute the signature (so that we know which msgSend variant to call). We can prepare the signature with a plain undef, and replace it with the materialized selector value if (and only if) needed, later. Concretely, this usually doesn't have an effect, but tests need updating because we reordered the receiver bitcast and the selector load, which is always fine. There is one notable change: with this, when a msgSend needs a receiver null check, the selector is now loaded in the non-null block, instead of before the null check. That should be a mild improvement.
2022-01-11[CodeGen] Treat ObjC `__unsafe_unretained` and class types as trivialAkira Hatanaka1-2/+1
when generating copy/dispose helper functions Analyze the block captures just once before generating copy/dispose block helper functions and honor the inert `__unsafe_unretained` qualifier. This refactor fixes a bug where captures of ObjC `__unsafe_unretained` and class types were needlessly retained/released by the copy/dispose helper functions. Differential Revision: https://reviews.llvm.org/D116948
2022-01-08[CGObjCMac] Use castAs<> instead of getAs<> to avoid dereference of nullptr ↵Simon Pilgrim1-1/+1
inside BuildRCBlockVarRecordLayout This will assert the cast is correct instead of returning nullptr (UnionType is a subtype of RecordType so this should be clean).
2022-01-06[CodeGen] Emit elementtype attributes for indirect inline asm constraintsNikita Popov1-1/+9
This implements the clang side of D116531. The elementtype attribute is added for all indirect constraints (*) and tests are updated accordingly. Differential Revision: https://reviews.llvm.org/D116666
2021-12-15[CodeGen] Avoid deprecated ConstantAddress constructorNikita Popov1-2/+3
Change all uses of the deprecated constructor to pass the element type explicitly and drop it. For cases where the correct element type was not immediately obvious to me or would require a slightly larger change I'm falling back to explicitly calling getPointerElementType() for now.
2021-11-12[clang][objc][codegen] Skip emitting ObjC category metadata when theJosh Learn1-17/+37
category is empty Currently, if we create a category in ObjC that is empty, we still emit runtime metadata for that category. This is a scenario that could commonly be run into when using __attribute__((objc_direct_members)), which elides the need for much of the category metadata. This is slightly wasteful and can be easily skipped by checking the category metadata contents during CodeGen. rdar://66177182 Differential Revision: https://reviews.llvm.org/D113455
2021-10-27[clang] Add range accessor for ObjCAtTryStmt catch_stmts and use itNico Weber1-3/+1
No behavior change. Differential Revision: https://reviews.llvm.org/D112543
2021-10-08Fix a variety of bugs with nil-receiver checks when targetingJohn McCall1-73/+6
non-Darwin ObjC runtimes: - Use the same logic the Darwin runtime does for inferring that a receiver is non-null and therefore doesn't require null checks. Previously we weren't skipping these for non-super dispatch. - Emit a null check when there's a consumed parameter so that we can destroy the argument if the call doesn't happen. This mostly involves extracting some common logic from the Darwin-runtime code. - Generate a zero aggregate by zeroing the same memory that was used in the method call instead of zeroing separate memory and then merging them with a phi. This uses less memory and avoids unnecessary copies. - Emit zero initialization, and generate zero values in phis, using the proper zero-value routines instead of assuming that the zero value of the result type has a bitwise-zero representation.
2021-04-19[clang] NFC: Fix range-based for loop warnings related to decl lookupJan Svoboda1-1/+1
2021-03-11[CGBuilder] Remove type-less CreateAlignedLoad() APIs (NFC)Nikita Popov1-10/+15
These are incompatible with opaque pointers. This is in preparation of dropping this API on the IRBuilder side as well. Instead explicitly pass the loaded type.
2021-01-21Fix crash when emitting NullReturn guards for functions returning BOOLJon Roelofs1-1/+2
CodeGenModule::EmitNullConstant() creates constants with their "in memory" type, not their "in vregs" type. The one place where this difference matters is when the type is _Bool, as that is an i1 when in vregs and an i8 in memory. Fixes: rdar://73361264
2020-12-28[CodeGen][ObjC] Destroy callee-destroyed arguments in the callerAkira Hatanaka1-2/+20
function when the receiver is nil Callee-destroyed arguments to a method have to be destroyed in the caller function when the receiver is nil as the method doesn't get executed. This fixes PR48207. rdar://71808391 Differential Revision: https://reviews.llvm.org/D93273
2020-10-02[clang] Implement objc_non_runtime_protocol to remove protocol metadataNathan Lanza1-9/+24
Summary: Motivated by the new objc_direct attribute, this change adds a new attribute that remotes metadata from Protocols that the programmer knows isn't going to be used at runtime. We simply have the frontend skip generating any protocol metadata entries (e.g. OBJC_CLASS_NAME, _OBJC_$_PROTOCOL_INSTANCE_METHDOS, _OBJC_PROTOCOL, etc) for a protocol marked with `__attribute__((objc_non_runtime_protocol))`. There are a few APIs used to retrieve a protocol at runtime. `@protocol(SomeProtocol)` will now error out of the requested protocol is marked with attribute. `objc_getProtocol` will return `NULL` which is consistent with the behavior of a non-existing protocol. Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D75574
2020-09-29Fix a variety of minor issues with ObjC method mangling:John McCall1-14/+6
- Fix a memory leak accidentally introduced yesterday by using CodeGen's existing mangling context instead of creating a new context afresh. - Move GNU-runtime ObjC method mangling into the AST mangler; this will eventually be necessary to support direct methods there, but is also just the right architecture. - Make the Apple-runtime method mangling work properly when given an interface declaration, fixing a bug (which had solidified into a test) where mangling a category method from the interface could cause it to be mangled as if the category name was a class name. (Category names are namespaced within their class and have no global meaning.) - Fix a code cross-reference in dsymutil. Based on a patch by Ellis Hoag.
2020-09-29This reduces code duplication between CGObjCMac.cpp and Mangle.cppEllis Hoag1-24/+9
for generating the mangled name of an Objective-C method. This has no intended functionality change. https://reviews.llvm.org/D88329
2020-08-11[SystemZ/ZOS] Add binary format goff and operating system zos to the tripleKai Nacke1-1/+2
Adds the binary format goff and the operating system zos to the triple class. goff is selected as default binary format if zos is choosen as operating system. No further functionality is added. Reviewers: efriedma, tahonermann, hubert.reinterpertcast, MaskRay Reviewed By: efriedma, tahonermann, hubert.reinterpertcast Differential Revision: https://reviews.llvm.org/D82081
2020-04-14[ADT/STLExtras.h] - Add llvm::is_sorted wrapper and update callers.Georgii Rymar1-1/+1
It can be used to avoid passing the begin and end of a range. This makes the code shorter and it is consistent with another wrappers we already have. Differential revision: https://reviews.llvm.org/D78016
2020-04-03[clang][opaque pointers] Fix up a bunch of "getType()->getElementType()"Eli Friedman1-4/+4
In contexts where we know an LLVM type is a pointer, there's generally some simpler way to get the pointee type.
2020-04-01[clang] CodeGen: Make getOrEmitProtocol public for SwiftArnold Schwaighofer1-5/+0
Summary: Swift would like to use clang's apis to emit protocol declarations. This commits adds the public API: ``` emitObjCProtocolObject(CodeGenModule &CGM, const ObjCProtocolDecl *p); ``` rdar://60888524 Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D77077
2020-03-12Replace getAs with castAs to fix null dereference static analyzer warning.Simon Pilgrim1-3/+2
Use castAs as we know the cast should succeed (and castAs will assert if it doesn't) and we're dereferencing it directly in the BuildRCBlockVarRecordLayout call.
2020-03-11Fix conflict value for metadata "Objective-C Garbage Collection" in the mix ↵Jin Lin1-4/+7
of swift and Objective-C bitcode Summary: The change is to fix conflict value for metadata "Objective-C Garbage Collection" in the mix of swift and Objective-C bitcode. The purpose is to provide the support of LTO for swift and Objective-C mixed project. Reviewers: rjmccall, ahatanak, steven_wu Reviewed By: rjmccall, steven_wu Subscribers: manmanren, mehdi_amini, hiraditya, dexonsmith, llvm-commits, jinlin Tags: #llvm Differential Revision: https://reviews.llvm.org/D71219
2020-03-10[CodeGenObjC] Place property names in __objc_methnameErik Pilkington1-1/+2
This allows the property name to deduplicate with the accessor method name. rdar://58927964
2020-03-09[CodeGenObjC] Privatize some ObjC metadata symbolsErik Pilkington1-13/+9
Nobody needs these symbols, so there isn't any benefit in including them. This saves some code-size in Objective-C binaries. Partially reverts: https://reviews.llvm.org/D61454. rdar://56579760 Differential revision: https://reviews.llvm.org/D75491
2020-01-30[objc_direct] fix codegen for mismatched Decl/Impl return typesPierre Habouzit1-10/+37
For non direct methods, the codegen uses the type of the Implementation. Because Objective-C rules allow some differences between the Declaration and Implementation return types, when the Implementation is in this translation unit, the type of the Implementation should be preferred to emit the Function over the Declaration. Radar-Id: rdar://problem/58797748 Signed-off-by: Pierre Habouzit <phabouzit@apple.com> Differential Revision: https://reviews.llvm.org/D73208
2020-01-28Make llvm::StringRef to std::string conversions explicit.Benjamin Kramer1-4/+5
This is how it should've been and brings it more in line with std::string_view. There should be no functional change here. This is mostly mechanical from a custom clang-tidy check, with a lot of manual fixups. It uncovers a lot of minor inefficiencies. This doesn't actually modify StringRef yet, I'll do that in a follow-up.
2020-01-24[Alignment][NFC] Deprecate Align::None()Guillaume Chatelet1-1/+1
Summary: This is a follow up on https://reviews.llvm.org/D71473#inline-647262. There's a caveat here that `Align(1)` relies on the compiler understanding of `Log2_64` implementation to produce good code. One could use `Align()` as a replacement but I believe it is less clear that the alignment is one in that case. Reviewers: xbolva00, courbet, bollu Subscribers: arsenm, dylanmckay, sdardis, nemanjai, jvesely, nhaehnle, hiraditya, kbarton, jrtc27, atanasyan, jsji, Jim, kerbowa, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D73099
2020-01-23[objc_direct] do not add direct properties to the serialization arrayPierre Habouzit1-2/+4
If we do, then the property_list_t length is wrong and class_getProperty gets very sad. Signed-off-by: Pierre Habouzit <phabouzit@apple.com> Radar-Id: rdar://problem/58804805 Differential Revision: https://reviews.llvm.org/D73219
2020-01-06[CodeGen][ObjC] Push the properties of a protocol before pushing theAkira Hatanaka1-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
2019-12-20[objc_direct] Tigthen checks for direct methodsPierre Habouzit1-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
2019-12-10NFC: Get rid of an unused parameter to CGObjCMac::EmitSelectorAddr.Erik Pilkington1-12/+10
2019-12-09Avoid Attr.h includes, CodeGen editionReid Kleckner1-1/+2
This saves around 20 includes of Attr.h. Not much.
2019-12-06[ObjC] Make sure that the implicit arguments for direct methods have been setupAlex Lorenz1-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
2019-11-18Implement __attribute__((objc_direct)), __attribute__((objc_direct_members))Pierre Habouzit1-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
2019-11-08Redeclare Objective-C property accessors inside the ObjCImplDecl in which ↵Adrian Prantl1-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
2019-10-03[Alignment][Clang][NFC] Add CharUnits::getAsAlignGuillaume Chatelet1-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