summaryrefslogtreecommitdiff
path: root/lib/CodeGen/CodeGenModule.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [AMDGPU] Fix assertion due to initializer listYaxun Liu2019-10-201-10/+6
| | | | | | | | | | | | | | Sometimes a global var is replaced by a different llvm value. clang use GetAddrOfGlobalVar to get the original llvm global variable. For most targets, GetAddrOfGlobalVar returns either the llvm global variable or a bitcast of the llvm global variable. However, for AMDGPU target, GetAddrOfGlobalVar returns the addrspace cast or addrspace cast plus bitcast of the llvm global variable. To get the llvm global variable, these casts need to be stripped, otherwise there is assertion. This patch fixes that. Differential Revision: https://reviews.llvm.org/D69129 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@375362 91177308-0d34-0410-b5e6-96231b3b80d8
* Revert Tag CFI-generated data structures with "#pragma clang section" ↵Dmitry Mikulin2019-10-171-22/+5
| | | | | | | | attributes. This reverts r375022 (git commit e2692b3bc0327606748b6d291b9009d2c845ced5) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@375069 91177308-0d34-0410-b5e6-96231b3b80d8
* Tag CFI-generated data structures with "#pragma clang section" attributes.Dmitry Mikulin2019-10-161-5/+22
| | | | | | Differential Revision: https://reviews.llvm.org/D68808 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@375022 91177308-0d34-0410-b5e6-96231b3b80d8
* [Clang][OpenMP Offload] Move offload registration code to the wrapperSergey Dmitriev2019-10-151-6/+1
| | | | | | | | | | The final list of OpenMP offload targets becomes known only at the link time and since offload registration code depends on the targets list it makes sense to delay offload registration code generation to the link time instead of adding it to the host part of every fat object. This patch moves offload registration code generation from clang to the offload wrapper tool. This is the last part of the OpenMP linker script elimination patch https://reviews.llvm.org/D64943 Differential Revision: https://reviews.llvm.org/D68746 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@374937 91177308-0d34-0410-b5e6-96231b3b80d8
* Added support for "#pragma clang section relro=<name>"Dmitry Mikulin2019-10-151-0/+3
| | | | | | Differential Revision: https://reviews.llvm.org/D68806 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@374934 91177308-0d34-0410-b5e6-96231b3b80d8
* [OPENMP50]Support for declare variant directive for NVPTX target.Alexey Bataev2019-10-101-0/+44
| | | | | | | NVPTX does not support global aliases. Instead, we have to copy the full body of the variant function for the original function. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@374387 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix crash or wrong code bug if a lifetime-extended temporary contains aRichard Smith2019-10-081-7/+6
| | | | | | | | | | | | | | "non-constant" value. If the constant evaluator evaluates part of a variable initializer, including the initializer for some lifetime-extended temporary, but fails to fully evaluate the initializer, it can leave behind wrong values for temporaries encountered in that initialization. Don't try to emit those from CodeGen! Instead, look at the values that constant evaluation produced if (and only if) it actually succeeds and we're emitting the lifetime-extending declaration's initializer as a constant. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@374119 91177308-0d34-0410-b5e6-96231b3b80d8
* Properly handle instantiation-dependent array bounds.Richard Smith2019-10-041-1/+1
| | | | | | | | | We previously failed to treat an array with an instantiation-dependent but not value-dependent bound as being an instantiation-dependent type. We now track the array bound expression as part of a constant array type if it's an instantiation-dependent expression. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@373685 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix MSVC "result of 32-bit shift implicitly converted to 64 bits" warning. NFCI.Simon Pilgrim2019-10-031-1/+1
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@373613 91177308-0d34-0410-b5e6-96231b3b80d8
* [Alignment][Clang][NFC] Add CharUnits::getAsAlignGuillaume Chatelet2019-10-031-13/+12
| | | | | | | | | | | | | | | | | | 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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@373592 91177308-0d34-0410-b5e6-96231b3b80d8
* [OPENMP50]Initial codegen for declare variant implementation vendor.Alexey Bataev2019-10-011-0/+14
| | | | | | | Initial implementation of global aliases emission for the declare variant pragma with implementation vendor context selector set. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@373387 91177308-0d34-0410-b5e6-96231b3b80d8
* For P0784R7: compute whether a variable has constant destruction if itRichard Smith2019-09-291-2/+2
| | | | | | | | | | has a constexpr destructor. For constexpr variables, reject if the variable does not have constant destruction. In all cases, do not emit runtime calls to the destructor for variables with constant destruction. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@373159 91177308-0d34-0410-b5e6-96231b3b80d8
* Support for DWARF-5 C++ language tags.Adrian Prantl2019-09-241-1/+3
| | | | | | | | | | | | This patch provides support for DW_LANG_C_plus_plus_11, DW_LANG_C_plus_plus_14 tags in the Clang C++ frontend. Patch by Sourabh Singh Tomar! Differential Revision: https://reviews.llvm.org/D67613 Reapplies r372663 after adapting a failing test in the LLDB testsuite. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@372681 91177308-0d34-0410-b5e6-96231b3b80d8
* Revert "Support for DWARF-5 C++ language tags."Jonas Devlieghere2019-09-231-3/+1
| | | | | | This reverts commit bf9c8ffb54943c6d77398adbedddf05ef9724007. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@372672 91177308-0d34-0410-b5e6-96231b3b80d8
* Support for DWARF-5 C++ language tags.Adrian Prantl2019-09-231-1/+3
| | | | | | | | | | This patch provides support for DW_LANG_C_plus_plus_11, DW_LANG_C_plus_plus_14 tags in the Clang C++ frontend. Patch by Sourabh Singh Tomar! Differential Revision: https://reviews.llvm.org/D67613 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@372663 91177308-0d34-0410-b5e6-96231b3b80d8
* [CodeGen] Add alias for cpu_dispatch function with IFunc & Fix resolver ↵Fangrui Song2019-09-111-3/+24
| | | | | | | | | | | | | | linkage type Multi-versioned functions defined by cpu_dispatch and implemented with IFunc can not be called outside the translation units where they are defined due to lack of symbols. This patch add function aliases for these functions and thus make them visible outside. Differential Revision: https://reviews.llvm.org/D67058 Patch by Senran Zhang git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@371586 91177308-0d34-0410-b5e6-96231b3b80d8
* [OPENMP5.0]Add support for device_type clause in declare targetAlexey Bataev2019-08-231-3/+15
| | | | | | | | | | construct. OpenMP 5.0 introduced new clause for declare target directive, device_type clause, which may accept values host, nohost, and any. Host means that the function must be emitted only for the host, nohost - only for the device, and any - for both, device and the host. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@369775 91177308-0d34-0410-b5e6-96231b3b80d8
* [Clang][CodeGen] set alias linkage on QualTypeNick Desaulniers2019-08-221-4/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | Summary: It seems that CodeGen was always using ExternalLinkage when emitting a GlobalDecl with __attribute__((alias)). This leads to symbol redefinitions (ODR) that cause failures at link time for static aliases. This is readily attempting to link an ARM (32b) allyesconfig Linux kernel built with Clang. Reported-by: nathanchance Suggested-by: ihalip Link: https://bugs.llvm.org/show_bug.cgi?id=42377 Link: https://github.com/ClangBuiltLinux/linux/issues/631 Reviewers: rsmith, aaron.ballman, erichkeane Reviewed By: aaron.ballman Subscribers: javed.absar, kristof.beyls, cfe-commits, srhines, ihalip, nathanchance Tags: #clang Differential Revision: https://reviews.llvm.org/D66492 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@369705 91177308-0d34-0410-b5e6-96231b3b80d8
* [Clang] Migrate llvm::make_unique to std::make_uniqueJonas Devlieghere2019-08-141-1/+1
| | | | | | | | | | Now that we've moved to C++14, we no longer need the llvm::make_unique implementation from STLExtras.h. This patch is a mechanical replacement of (hopefully) all the llvm::make_unique instances across the monorepo. Differential revision: https://reviews.llvm.org/D66259 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@368942 91177308-0d34-0410-b5e6-96231b3b80d8
* cfi-icall: Allow the jump table to be optionally made non-canonical.Peter Collingbourne2019-08-091-14/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The default behavior of Clang's indirect function call checker will replace the address of each CFI-checked function in the output file's symbol table with the address of a jump table entry which will pass CFI checks. We refer to this as making the jump table `canonical`. This property allows code that was not compiled with ``-fsanitize=cfi-icall`` to take a CFI-valid address of a function, but it comes with a couple of caveats that are especially relevant for users of cross-DSO CFI: - There is a performance and code size overhead associated with each exported function, because each such function must have an associated jump table entry, which must be emitted even in the common case where the function is never address-taken anywhere in the program, and must be used even for direct calls between DSOs, in addition to the PLT overhead. - There is no good way to take a CFI-valid address of a function written in assembly or a language not supported by Clang. The reason is that the code generator would need to insert a jump table in order to form a CFI-valid address for assembly functions, but there is no way in general for the code generator to determine the language of the function. This may be possible with LTO in the intra-DSO case, but in the cross-DSO case the only information available is the function declaration. One possible solution is to add a C wrapper for each assembly function, but these wrappers can present a significant maintenance burden for heavy users of assembly in addition to adding runtime overhead. For these reasons, we provide the option of making the jump table non-canonical with the flag ``-fno-sanitize-cfi-canonical-jump-tables``. When the jump table is made non-canonical, symbol table entries point directly to the function body. Any instances of a function's address being taken in C will be replaced with a jump table address. This scheme does have its own caveats, however. It does end up breaking function address equality more aggressively than the default behavior, especially in cross-DSO mode which normally preserves function address equality entirely. Furthermore, it is occasionally necessary for code not compiled with ``-fsanitize=cfi-icall`` to take a function address that is valid for CFI. For example, this is necessary when a function's address is taken by assembly code and then called by CFI-checking C code. The ``__attribute__((cfi_jump_table_canonical))`` attribute may be used to make the jump table entry of a specific function canonical so that the external code will end up taking a address for the function that will pass CFI checks. Fixes PR41972. Differential Revision: https://reviews.llvm.org/D65629 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@368495 91177308-0d34-0410-b5e6-96231b3b80d8
* CodeGen: ensure 8-byte aligned String Swift CF ABISaleem Abdulrasool2019-08-091-1/+4
| | | | | | | | | CFStrings should be 8-byte aligned when built for the Swift CF runtime ABI as the atomic CF info field must be properly aligned. This is a problem on 32-bit platforms which would give the structure 4-byte alignment rather than 8-byte alignment. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@368471 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix parameter name comments using clang-tidy. NFC.Rui Ueyama2019-07-161-1/+1
| | | | | | | | | | | | | | | | | | | | | This patch applies clang-tidy's bugprone-argument-comment tool to LLVM, clang and lld source trees. Here is how I created this patch: $ git clone https://github.com/llvm/llvm-project.git $ cd llvm-project $ mkdir build $ cd build $ cmake -GNinja -DCMAKE_BUILD_TYPE=Debug \ -DLLVM_ENABLE_PROJECTS='clang;lld;clang-tools-extra' \ -DCMAKE_EXPORT_COMPILE_COMMANDS=On -DLLVM_ENABLE_LLD=On \ -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ ../llvm $ ninja $ parallel clang-tidy -checks='-*,bugprone-argument-comment' \ -config='{CheckOptions: [{key: StrictMode, value: 1}]}' -fix \ ::: ../llvm/lib/**/*.{cpp,h} ../clang/lib/**/*.{cpp,h} ../lld/**/*.{cpp,h} git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@366177 91177308-0d34-0410-b5e6-96231b3b80d8
* ARM MTE stack sanitizer.Evgeniy Stepanov2019-07-151-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | Add "memtag" sanitizer that detects and mitigates stack memory issues using armv8.5 Memory Tagging Extension. It is similar in principle to HWASan, which is a software implementation of the same idea, but there are enough differencies to warrant a new sanitizer type IMHO. It is also expected to have very different performance properties. The new sanitizer does not have a runtime library (it may grow one later, along with a "debugging" mode). Similar to SafeStack and StackProtector, the instrumentation pass (in a follow up change) will be inserted in all cases, but will only affect functions marked with the new sanitize_memtag attribute. Reviewers: pcc, hctim, vitalybuka, ostannard Subscribers: srhines, mehdi_amini, javed.absar, kristof.beyls, hiraditya, cryptoad, steven_wu, dexonsmith, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D64169 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@366123 91177308-0d34-0410-b5e6-96231b3b80d8
* [OpenCL][PR41727] Prevent ICE on global dtorsAnastasia Stulova2019-07-151-2/+6
| | | | | | | | | | | | Pass NULL to pointer arg of __cxa_atexit if addr space is not matching with its param. This doesn't align yet with how dtors are generated that should be changed too. Differential Revision: https://reviews.llvm.org/D62413 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@366059 91177308-0d34-0410-b5e6-96231b3b80d8
* [Concepts] Concept definitions (D40381)Saar Raz2019-07-101-0/+1
| | | | | | | | First in a series of patches to land C++2a Concepts support. This patch adds AST and parsing support for concept-declarations. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@365699 91177308-0d34-0410-b5e6-96231b3b80d8
* [HIP] Support attribute hip_pinned_shadowYaxun Liu2019-06-261-4/+12
| | | | | | | | | | | | | | | | This patch introduces support of hip_pinned_shadow variable for HIP. A hip_pinned_shadow variable is a global variable with attribute hip_pinned_shadow. It has external linkage on device side and has no initializer. It has internal linkage on host side and has initializer or static constructor. It can be accessed in both device code and host code. This allows HIP runtime to implement support of HIP texture reference. Differential Revision: https://reviews.llvm.org/D62738 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@364381 91177308-0d34-0410-b5e6-96231b3b80d8
* [CUDA][HIP] Don't set comdat attribute for CUDA device stub ↵Konstantin Pyzhov2019-06-241-0/+5
| | | | | | functions.\nDifferential Revision: https://reviews.llvm.org/D63277 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@364183 91177308-0d34-0410-b5e6-96231b3b80d8
* [OpenMP] Add support for handling declare target to clause when unified ↵Gheorghe-Teodor Bercea2019-06-201-4/+10
| | | | | | | | | | | | | | | | | | | | | memory is required Summary: This patch adds support for the handling of the variables under the declare target to clause. The variables in this case are handled like link variables are. A pointer is created on the host and then mapped to the device. The runtime will then copy the address of the host variable in the device pointer. Reviewers: ABataev, AlexEichenberger, caomhin Reviewed By: ABataev Subscribers: guansong, jdoerfert, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D63108 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@363959 91177308-0d34-0410-b5e6-96231b3b80d8
* [HIP] Add the interface deriving the stub name of device kernels.Michael Liao2019-06-171-6/+4
| | | | | | | | | | | | | | | | Summary: - Revise the interface to derive the stub name and simplify the assertion of it. Reviewers: yaxunl, tra Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D63335 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@363553 91177308-0d34-0410-b5e6-96231b3b80d8
* [CodeGen][ObjC] Annotate retain-agnostic ObjC globals with attributeAkira Hatanaka2019-06-141-0/+1
| | | | | | | | | | | | | | | 'objc_arc_inert' The attribute enables the ARC optimizer to delete ObjC ARC runtime calls on the annotated globals (see https://reviews.llvm.org/D62433). We currently only annotate global variables for string literals and global blocks with the attribute. rdar://problem/49839633 Differential Revision: https://reviews.llvm.org/D62831 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@363467 91177308-0d34-0410-b5e6-96231b3b80d8
* Driver, IRGen: Set partitions on GlobalValues according to ↵Peter Collingbourne2019-06-071-4/+5
| | | | | | | | -fsymbol-partition flag. Differential Revision: https://reviews.llvm.org/D62636 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@362829 91177308-0d34-0410-b5e6-96231b3b80d8
* [OpenCL] Fix OpenCL/SPIR version metadata in C++ mode.Anastasia Stulova2019-05-301-4/+9
| | | | | | | | | | | C++ is derived from OpenCL v2.0 therefore set the versions identically. Differential Revision: https://reviews.llvm.org/D62657 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@362102 91177308-0d34-0410-b5e6-96231b3b80d8
* [CUDA][HIP] Skip setting `externally_initialized` for static device variables.Michael Liao2019-05-291-1/+2
| | | | | | | | | | | | | | | | | Summary: - By declaring device variables as `static`, we assume they won't be addressable from the host side. Thus, no `externally_initialized` is required. Reviewers: yaxunl Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D62603 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@361994 91177308-0d34-0410-b5e6-96231b3b80d8
* [CUDA][HIP] Emit dependent libs for host onlyYaxun Liu2019-05-281-1/+6
| | | | | | | | | | | | | | Recently D60274 was introduced to allow lld to handle dependent libs. However current usage of dependent libs (e.g. pragma comment(lib, *) in windows header files) are intended for host only. Emitting the metadata in device IR causes link error in device path. Until there is a way to different it dependent libs for device or host, metadata for dependent libs should be emitted for host only. This patch enforces that. Differential Revision: https://reviews.llvm.org/D62483 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@361880 91177308-0d34-0410-b5e6-96231b3b80d8
* Refactor: split Uninitialized state on APValue into an "Absent" stateRichard Smith2019-05-211-1/+1
| | | | | | | representing no such object, and an "Indeterminate" state representing an uninitialized object. The latter is not yet used, but soon will be. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@361328 91177308-0d34-0410-b5e6-96231b3b80d8
* [OpenMP] Add support for registering requires directives with the runtimeGheorghe-Teodor Bercea2019-05-211-0/+4
| | | | | | | | | | | | | | | | | | | | | | | Summary: This patch adds support for the registration of the requires directives with the runtime. Each requires directive clause will enable a particular flag to be set. The set of flags is passed to the runtime to be checked for compatibility with other such flags coming from other object files. The registration function is called whenever OpenMP is present even if a requires directive is not present. This helps detect cases in which requires directives are used inconsistently. Reviewers: ABataev, AlexEichenberger, caomhin Reviewed By: ABataev, AlexEichenberger Subscribers: jholewinski, guansong, jfb, jdoerfert, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D60568 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@361298 91177308-0d34-0410-b5e6-96231b3b80d8
* [OPENMP]Use the attributes for dso locality when building for device.Alexey Bataev2019-05-211-1/+1
| | | | | | | | | Currently, we ignore all dso locality attributes/info when building for the device and thus all symblos are externally visible and can be preemted at the runtime. It may lead to incorrect results. We need to follow the same logic, compiler uses for static/pie builds. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@361283 91177308-0d34-0410-b5e6-96231b3b80d8
* [ELF] Implement Dependent Libraries FeatureBen Dunbobbin2019-05-171-12/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch implements a limited form of autolinking primarily designed to allow either the --dependent-library compiler option, or "comment lib" pragmas ( https://docs.microsoft.com/en-us/cpp/preprocessor/comment-c-cpp?view=vs-2017) in C/C++ e.g. #pragma comment(lib, "foo"), to cause an ELF linker to automatically add the specified library to the link when processing the input file generated by the compiler. Currently this extension is unique to LLVM and LLD. However, care has been taken to design this feature so that it could be supported by other ELF linkers. The design goals were to provide: - A simple linking model for developers to reason about. - The ability to to override autolinking from the linker command line. - Source code compatibility, where possible, with "comment lib" pragmas in other environments (MSVC in particular). Dependent library support is implemented differently for ELF platforms than on the other platforms. Primarily this difference is that on ELF we pass the dependent library specifiers directly to the linker without manipulating them. This is in contrast to other platforms where they are mapped to a specific linker option by the compiler. This difference is a result of the greater variety of ELF linkers and the fact that ELF linkers tend to handle libraries in a more complicated fashion than on other platforms. This forces us to defer handling the specifiers to the linker. In order to achieve a level of source code compatibility with other platforms we have restricted this feature to work with libraries that meet the following "reasonable" requirements: 1. There are no competing defined symbols in a given set of libraries, or if they exist, the program owner doesn't care which is linked to their program. 2. There may be circular dependencies between libraries. The binary representation is a mergeable string section (SHF_MERGE, SHF_STRINGS), called .deplibs, with custom type SHT_LLVM_DEPENDENT_LIBRARIES (0x6fff4c04). The compiler forms this section by concatenating the arguments of the "comment lib" pragmas and --dependent-library options in the order they are encountered. Partial (-r, -Ur) links are handled by concatenating .deplibs sections with the normal mergeable string section rules. As an example, #pragma comment(lib, "foo") would result in: .section ".deplibs","MS",@llvm_dependent_libraries,1 .asciz "foo" For LTO, equivalent information to the contents of a the .deplibs section can be retrieved by the LLD for bitcode input files. LLD processes the dependent library specifiers in the following way: 1. Dependent libraries which are found from the specifiers in .deplibs sections of relocatable object files are added when the linker decides to include that file (which could itself be in a library) in the link. Dependent libraries behave as if they were appended to the command line after all other options. As a consequence the set of dependent libraries are searched last to resolve symbols. 2. It is an error if a file cannot be found for a given specifier. 3. Any command line options in effect at the end of the command line parsing apply to the dependent libraries, e.g. --whole-archive. 4. The linker tries to add a library or relocatable object file from each of the strings in a .deplibs section by; first, handling the string as if it was specified on the command line; second, by looking for the string in each of the library search paths in turn; third, by looking for a lib<string>.a or lib<string>.so (depending on the current mode of the linker) in each of the library search paths. 5. A new command line option --no-dependent-libraries tells LLD to ignore the dependent libraries. Rationale for the above points: 1. Adding the dependent libraries last makes the process simple to understand from a developers perspective. All linkers are able to implement this scheme. 2. Error-ing for libraries that are not found seems like better behavior than failing the link during symbol resolution. 3. It seems useful for the user to be able to apply command line options which will affect all of the dependent libraries. There is a potential problem of surprise for developers, who might not realize that these options would apply to these "invisible" input files; however, despite the potential for surprise, this is easy for developers to reason about and gives developers the control that they may require. 4. This algorithm takes into account all of the different ways that ELF linkers find input files. The different search methods are tried by the linker in most obvious to least obvious order. 5. I considered adding finer grained control over which dependent libraries were ignored (e.g. MSVC has /nodefaultlib:<library>); however, I concluded that this is not necessary: if finer control is required developers can fall back to using the command line directly. RFC thread: http://lists.llvm.org/pipermail/llvm-dev/2019-March/131004.html. Differential Revision: https://reviews.llvm.org/D60274 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@360984 91177308-0d34-0410-b5e6-96231b3b80d8
* make -ftime-trace also print template argumentsLubos Lunak2019-05-121-2/+7
| | | | | | | | | Without this, I get e.g. 'PerformPendingInstantiations' -> 'std::fill', now I get 'std::fill<unsigned long *, int>'. Differential Revision: https://reviews.llvm.org/D61822 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@360539 91177308-0d34-0410-b5e6-96231b3b80d8
* [OpenCL] Make global ctor init function a kernelAnastasia Stulova2019-05-091-0/+206
| | | | | | | | | | | | | | | | We need to be able to enqueue internal function that initializes global constructors on the host side. Therefore it has to be converted to a kernel. This change factors out common logic for adding kernel metadata and moves it from CodeGenFunction to CodeGenModule in order to make it accessible for the extra use case. Differential revision: https://reviews.llvm.org/D61488 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@360342 91177308-0d34-0410-b5e6-96231b3b80d8
* [SPIR] Simplified target checking.Anastasia Stulova2019-05-091-2/+1
| | | | | | | | | | | | Switched to Triple::isSPIR() helper to simplify code. Patch by kpet (Kevin Petit)! Differential revision: https://reviews.llvm.org/D61639 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@360325 91177308-0d34-0410-b5e6-96231b3b80d8
* [COFF] Use COFF stubs for extern_weak functionsReid Kleckner2019-05-071-0/+7
| | | | | | | | | | | | | | | | | | | | | | | Summary: A COFF stub indirects the reference to a symbol through memory. A .refptr.$sym global variable pointer is created to refer to $sym. Typically mingw uses these for external global variable declarations, but we can use them for weak function declarations as well. Updates the dso_local classification to add a special case for extern_weak symbols on COFF in both clang and LLVM. Fixes PR37598 Reviewers: smeenai, mstorsjo Subscribers: hiraditya, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D61615 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@360207 91177308-0d34-0410-b5e6-96231b3b80d8
* Re-land r359250, [COFF] Statically link certain runtime library functionsReid Kleckner2019-04-291-3/+7
| | | | | | | | Reverts the revert of r359251, this time with fixed tests. Differential Revision: https://reviews.llvm.org/D55229 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@359513 91177308-0d34-0410-b5e6-96231b3b80d8
* Revert [COFF] Statically link certain runtime library functionsReid Kleckner2019-04-251-7/+3
| | | | | | | | | This reverts r359250 (git commit 4730604bd3a361c68b92b18bf73a5daa15afe9f4) The newly added test should use -cc1 and -emit-llvm and there are other test failures that need fixing. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@359251 91177308-0d34-0410-b5e6-96231b3b80d8
* [COFF] Statically link certain runtime library functionsReid Kleckner2019-04-251-3/+7
| | | | | | | | | | | | | | | | | | | Statically link certain runtime library functions for MSVC/GNU Windows environments. This is consistent with MSVC behavior. Fixes LNK4286 and LNK4217 warnings from link.exe when linking the static CRT: LINK : warning LNK4286: symbol '__std_terminate' defined in 'libvcruntime.lib(ehhelpers.obj)' is imported by 'ASAN_NOINST_TEST_OBJECTS.asan_noinst_test.cc.x86_64-calls.o' LINK : warning LNK4286: symbol '__std_terminate' defined in 'libvcruntime.lib(ehhelpers.obj)' is imported by 'ASAN_NOINST_TEST_OBJECTS.asan_test_main.cc.x86_64-calls.o' LINK : warning LNK4217: symbol '_CxxThrowException' defined in 'libvcruntime.lib(throw.obj)' is imported by 'ASAN_NOINST_TEST_OBJECTS.gtest-all.cc.x86_64-calls.o' in function '"int `public: static class UnitTest::GetInstance * __cdecl testing::UnitTest::GetInstance(void)'::`1'::dtor$5" (?dtor$5@?0??GetInstance@UnitTest@testing@@SAPEAV12@XZ@4HA)' Reviewers: mstorsjo, efriedma, TomTan, compnerd, smeenai, mgrang Subscribers: abdulras, theraven, smeenai, pcc, mehdi_amini, javed.absar, inglorion, kristof.beyls, dexonsmith, cfe-commits Differential Revision: https://reviews.llvm.org/D55229 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@359250 91177308-0d34-0410-b5e6-96231b3b80d8
* Use llvm::stable_sortFangrui Song2019-04-241-4/+3
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@359098 91177308-0d34-0410-b5e6-96231b3b80d8
* Move setTargetAttributes after setGVProperties in SetFunctionAttributesScott Linder2019-04-231-5/+5
| | | | | | | | | | | AMDGPU currently relies on global properties being set before setTargetProperties is called. Existing targets like MIPS which rely on setTargetProperties do not rely on the current behavior, so this patch moves the call later in SetFunctionAttributes. Differential Revision: https://reviews.llvm.org/D60967 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@359039 91177308-0d34-0410-b5e6-96231b3b80d8
* Adds `-ftime-trace` option to clang that produces Chrome `chrome://tracing` ↵Anton Afanasyev2019-03-301-0/+4
| | | | | | | | | | | | | | compatible JSON profiling output dumps. This change adds hierarchical "time trace" profiling blocks that can be visualized in Chrome, in a "flame chart" style. Each profiling block can have a "detail" string that for example indicates the file being processed, template name being instantiated, function being optimized etc. This is taken from GitHub PR: https://github.com/aras-p/llvm-project-20170507/pull/2 Patch by Aras Pranckevičius. Differential Revision: https://reviews.llvm.org/D58675 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@357340 91177308-0d34-0410-b5e6-96231b3b80d8
* IRGen: Remove StructorType; thread GlobalDecl through more code. NFCI.Peter Collingbourne2019-03-221-13/+4
| | | | | | | | This should make it easier to add more structor variants. Differential Revision: https://reviews.llvm.org/D59724 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@356822 91177308-0d34-0410-b5e6-96231b3b80d8
* [OPENMP]Codegen support for allocate directive on global variables.Alexey Bataev2019-03-211-0/+5
| | | | | | | | | For the global variables the allocate directive must specify only the predefined allocator. This allocator must be translated into the correct form of the address space for the targets that support different address spaces. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@356702 91177308-0d34-0410-b5e6-96231b3b80d8