aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CGObjCMac.cpp
AgeCommit message (Collapse)AuthorFilesLines
2019-10-02CGObjCMac - silence static analyzer dyn_cast<>/getAs<> null dereference ↵Simon Pilgrim1-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
2019-07-05Silence gcc warning "control reaches end of non-void function" [NFCI]Mikael Holmen1-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
2019-07-04[NFC] Make some ObjectFormatType switches coveringHubert Tong1-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
2019-05-30Add the `objc_class_stub` attribute.John McCall1-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
2019-05-09[CodeGen][ObjC] Remove the leading `l_` from ObjC symbols and makeAkira Hatanaka1-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
2019-04-11Support objc_nonlazy_class attribute on Objective-C implementationsErik Pilkington1-1/+2
Fixes rdar://49523079 Differential revision: https://reviews.llvm.org/D60544 llvm-svn: 358201
2019-03-14[CodeGen][ObjC] Remove the leading 'l' from symbols for protocolAkira Hatanaka1-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
2019-02-09[opaque pointer types] Cleanup CGBuilder's Create*GEP.James Y Knight1-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
2019-02-05[opaque pointer types] Pass function types for runtime function calls.James Y Knight1-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
2019-02-04[OBJC] Add attribute to mark Objective C class as non-lazyJoe Daniels1-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
2019-01-30Cleanup: replace uses of CallSite with CallBase.James Y Knight1-10/+12
llvm-svn: 352595
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth1-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
2019-01-17[CodeGenObjC] Use a constant value for non-fragile ivar offsets when possibleErik Pilkington1-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
2018-12-11Move CodeGenOptions from Frontend to BasicRichard Trieu1-1/+1
Basic uses CodeGenOptions and should not depend on Frontend. llvm-svn: 348827
2018-10-12[CodeGen] Handle extern references to OBJC_CLASS_$_*Erik Pilkington1-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
2018-08-17[ObjC] Error out when using forward-declared protocol in a @protocolAlex Lorenz1-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
2018-08-17[CodeGen] Merge identical block descriptor global variables.Akira Hatanaka1-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
2018-07-30Remove trailing spaceFangrui Song1-114/+114
sed -Ei 's/[[:space:]]+$//' include/**/*.{def,h,td} lib/**/*.{cpp,h} llvm-svn: 338291
2018-05-09Remove \brief commands from doxygen comments.Adrian Prantl1-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
2018-04-06Fix typos in clangAlexander Kornienko1-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
2018-04-03[ObjC] Use the name specified by objc_runtime_name instead of the classAkira Hatanaka1-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
2018-03-15Recommit r326946 after reducing CallArgList memory footprintYaxun Liu1-2/+2
llvm-svn: 327634
2018-03-10Revert r326946. It caused stack overflows by significantly increasing the ↵Richard Smith1-2/+2
size of a CallArgList. llvm-svn: 327195
2018-03-07CodeGen: Fix address space of indirect function argumentYaxun Liu1-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
2018-03-01Start setting dllimport/dllexport in setGVProperties.Rafael Espindola1-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
2018-01-23CodeGen: use `llvm.used` for ObjC protocolsSaleem Abdulrasool1-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
2018-01-13Remove unused addIfPresent function.Eric Christopher1-4/+0
llvm-svn: 322427
2017-12-07[driver] Set the 'simulator' environment for Darwin when compiling forAlex Lorenz1-4/+1
iOS/tvOS/watchOS simulator rdar://35135215 Differential Revision: https://reviews.llvm.org/D40682 llvm-svn: 320073
2017-11-17[CodeGen] Compute the objc EH vtable address point using inbounds GEP.Ahmed Bougacha1-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
2017-10-27[CodeGen] Add support for IncompleteArrayType in Obj-C ivars.Volodymyr Sapsai1-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
2017-10-25CodeGen: fix a case of incorrect checks for ivarsSaleem Abdulrasool1-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
2017-10-11Revert "[ADT] Make Twine's copy constructor private."Zachary Turner1-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
2017-10-11[ADT] Make Twine's copy constructor private.Zachary Turner1-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
2017-06-30[objc] Don't require null-check and don't emit memset when result is ignored ↵Kuba Mracek1-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
2017-06-29CodeGen: handle missed case of COMDAT handlingSaleem Abdulrasool1-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
2017-06-17CodeGen: make the type match the comment for a libcallSaleem Abdulrasool1-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
2017-06-03CodeGen: fix section names for different file formatsSaleem Abdulrasool1-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
2017-05-09Suppress all uses of LLVM_END_WITH_NULL. NFC.Serge Guelton1-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
2017-05-01Adapt to LLVM's rename of WeakVH to WeakTrackingVH; NFCSanjoy Das1-1/+1
llvm-svn: 301815
2017-04-26Revert "Update to LLVM's use of WeakTrackingVH; NFC"Sanjoy Das1-1/+1
This reverts commit r301427. llvm-svn: 301430
2017-04-26Update to LLVM's use of WeakTrackingVH; NFCSanjoy Das1-1/+1
Summary: Depends on D32266 Reviewers: davide, dblaikie Subscribers: mcrosier, llvm-commits Differential Revision: https://reviews.llvm.org/D32270 llvm-svn: 301427
2017-03-21Update Clang for LLVM rename AttributeSet -> AttributeListReid Kleckner1-14/+10
llvm-svn: 298394
2017-03-02Promote ConstantInitBuilder to be a public CodeGen API; it'sJohn McCall1-1/+1
a generally useful utility for other frontends. NFC. llvm-svn: 296806
2016-11-30Clean up CGObjCMac's APIs for deriving class references. NFC.John McCall1-107/+89
llvm-svn: 288295
2016-11-30Fix some layering violations where CGObjCMac's NSString emission wasJohn McCall1-6/+127
performed at the CodeGenModule level. Would be NFC except we now also use a different uniquing structure so that we don't get spurious conflicts if you ask for both an NSString and a CFString for the same content (which is possible with builtins). llvm-svn: 288287
2016-11-30Prospective GCC build fix: the unelaborated form of this friendJohn McCall1-2/+2
declaration should find the right type, assuming it's supported evenly across all our hosts. llvm-svn: 288231
2016-11-30Switch CGObjCMac to use ConstantInitBuilder. Whew.John McCall1-776/+799
Not strictly NFC because I did change the order of emission of some global constants, but it shouldn't make any difference. llvm-svn: 288229
2016-11-29getObjCEncodingForMethodDecl cannot fail. Simplify. NFC.John McCall1-17/+4
llvm-svn: 288203
2016-10-26Refactor call emission to package the function pointer together withJohn McCall1-4/+6
abstract information about the callee. NFC. The goal here is to make it easier to recognize indirect calls and trigger additional logic in certain cases. That logic will come in a later patch; in the meantime, I felt that this was a significant improvement to the code. llvm-svn: 285258
2016-10-25CodeGen: be more conservative about setting sectionSaleem Abdulrasool1-29/+44
The section names currently are MachO specific. Only set the section on the variables if the file format is MachO. llvm-svn: 285126