summaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenModule.cpp
AgeCommit message (Collapse)Author
2017-05-20Revert "CodeGenModule: Always output wchar_size, check LLVM assumptions."Matthias Braun
Let's revert this for now (and with it the assert()) to get the bots back to green until I have LLVM synced up properly. This reverts commit r303463. llvm-svn: 303474
2017-05-19CodeGenModule: Always output wchar_size, check LLVM assumptions.Matthias Braun
llvm::TargetLibraryInfo needs to know the size of wchar_t to work on functions like `wcslen`. This patch changes clang to always emit the wchar_size module flag (it would only do so for ARM previously). This also adds an `assert()` to ensure the LLVM defaults based on the target triple are in sync with clang. Differential Revision: https://reviews.llvm.org/D32982 llvm-svn: 303463
2017-05-18CodeGen: Cast alloca to expected address spaceYaxun Liu
Alloca always returns a pointer in alloca address space, which may be different from the type defined by the language. For example, in C++ the auto variables are in the default address space. Therefore cast alloca to the expected address space when necessary. Differential Revision: https://reviews.llvm.org/D32248 llvm-svn: 303370
2017-05-09Suppress all uses of LLVM_END_WITH_NULL. NFC.Serge Guelton
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-02Re-land r301697 "[IR] Make add/remove Attributes use AttrBuilder instead of ↵Reid Kleckner
AttributeList" This time, I fixed, built, and tested clang. This reverts r301712. llvm-svn: 301981
2017-05-01Adapt to LLVM's rename of WeakVH to WeakTrackingVH; NFCSanjoy Das
llvm-svn: 301815
2017-05-01Remove unneeded struct; NFCSanjoy Das
Summary: Unless I'm missing something, the DeferredGlobal struct's GV field is unused, removing which makes the struct itself trivial. Reviewers: rafael, chandlerc Subscribers: mcrosier, llvm-commits Differential Revision: https://reviews.llvm.org/D32691 llvm-svn: 301789
2017-04-27[Profile] Add off-by-default -Wprofile-instr-missing warningVedant Kumar
Clang warns that a profile is out-of-date if it can't find a profile record for any function in a TU. This warning became noisy after llvm started allowing dead-stripping of instrumented functions. To fix this, this patch changes the existing profile out-of-date warning (-Wprofile-instr-out-of-date) so that it only complains about mismatched data. Further, it introduces a new, off-by-default warning about missing function data (-Wprofile-instr-missing). Differential Revision: https://reviews.llvm.org/D28867 llvm-svn: 301570
2017-04-26Revert "Update to LLVM's use of WeakTrackingVH; NFC"Sanjoy Das
This reverts commit r301427. llvm-svn: 301430
2017-04-26Update to LLVM's use of WeakTrackingVH; NFCSanjoy Das
Summary: Depends on D32266 Reviewers: davide, dblaikie Subscribers: mcrosier, llvm-commits Differential Revision: https://reviews.llvm.org/D32270 llvm-svn: 301427
2017-04-24[Devirtualization] Emit invariant.group loads with empty group mdPiotr Padlewski
Summary: As discussed here http://lists.llvm.org/pipermail/llvm-dev/2017-January/109332.html having different groups doesn't solve the problem entirly. Reviewers: rjmccall, rsmith Subscribers: amharc, cfe-commits Differential Revision: https://reviews.llvm.org/D32110 llvm-svn: 301178
2017-04-19Fix assertion failure in codegen on non-template deduction guide.Richard Smith
llvm-svn: 300762
2017-04-18Use less temporary AttributeLists NFCReid Kleckner
llvm-svn: 300628
2017-04-17CodeGen: Let lifetime intrinsic use alloca address spaceYaxun Liu
Differential Revision: https://reviews.llvm.org/D31717 llvm-svn: 300485
2017-04-13[IR] Make getParamAttributes take argument numbers, not ArgNo+1Reid Kleckner
Add hasParamAttribute() and use it instead of hasAttribute(ArgNo+1, Kind) everywhere. The fact that the AttributeList index for an argument is ArgNo+1 should be a hidden implementation detail. NFC llvm-svn: 300272
2017-04-13[IR] Take func, ret, and arg attrs separately in AttributeList::getReid Kleckner
This seems like a much more natural API, based on Derek Schuff's comments on r300015. It further hides the implementation detail of AttributeList that function attributes come last and appear at index ~0U, which is easy for the user to screw up. git diff says it saves code as well: 97 insertions(+), 137 deletions(-) This also makes it easier to change the implementation, which I want to do next. llvm-svn: 300153
2017-04-12[IR] Add AttributeSet to hide AttributeSetNode* again, NFCReid Kleckner
Summary: For now, it just wraps AttributeSetNode*. Eventually, it will hold AvailableAttrs as an inline bitset, and adding and removing enum attributes will be super cheap. This sinks AttributeSetNode back down to lib/IR/AttributeImpl.h. Reviewers: pete, chandlerc Subscribers: llvm-commits, jfb Differential Revision: https://reviews.llvm.org/D31940 llvm-svn: 300014
2017-04-11Modular Codegen: Support homing debug info for types in modular objectsDavid Blaikie
Matching the function-homing support for modular codegen. Any type implicitly (implicit template specializations) or explicitly defined in a module is attached to that module's object file and omitted elsewhere (only a declaration used if necessary for references). llvm-svn: 299987
2017-04-10Reland "[IR] Make AttributeSetNode public, avoid temporary AttributeList copies"Reid Kleckner
This re-lands r299875. I introduced a bug in Clang code responsible for replacing K&R, no prototype declarations with a real function definition with a prototype. The bug was here: // Collect any return attributes from the call. - if (oldAttrs.hasAttributes(llvm::AttributeList::ReturnIndex)) - newAttrs.push_back(llvm::AttributeList::get(newFn->getContext(), - oldAttrs.getRetAttributes())); + newAttrs.push_back(oldAttrs.getRetAttributes()); Previously getRetAttributes() carried AttributeList::ReturnIndex in its AttributeList. Now that we return the AttributeSetNode* directly, it no longer carries that index, and we call this overload with a single node: AttributeList::get(LLVMContext&, ArrayRef<AttributeSetNode*>) That aborted with an assertion on x86_32 targets. I added an explicit triple to the test and added CHECKs to help find issues like this in the future sooner. llvm-svn: 299899
2017-04-07[cfi] Emit __cfi_check stub in the frontend.Evgeniy Stepanov
Previously __cfi_check was created in LTO optimization pipeline, which means LLD has no way of knowing about the existence of this symbol without rescanning the LTO output object. As a result, LLD fails to export __cfi_check, even when given --export-dynamic-symbol flag. llvm-svn: 299806
2017-03-30Move NumRegParameters Module Flag. NFCI.Nirav Dave
llvm-svn: 299079
2017-03-30[XRay] Add -fxray-{always,never}-instrument= flags to clangDean Michael Berris
Summary: The -fxray-always-instrument= and -fxray-never-instrument= flags take filenames that are used to imbue the XRay instrumentation attributes using a whitelist mechanism (similar to the sanitizer special cases list). We use the same syntax and semantics as the sanitizer blacklists files in the implementation. As implemented, we respect the attributes that are already defined in the source file (i.e. those that have the [[clang::xray_{always,never}_instrument]] attributes) before applying the always/never instrument lists. Reviewers: rsmith, chandlerc Subscribers: jfb, mgorny, cfe-commits Differential Revision: https://reviews.llvm.org/D30388 llvm-svn: 299041
2017-03-23[CodeGen] Emit a CoreFoundation link guard when @available is usedAlex Lorenz
After r297760, __isOSVersionAtLeast in compiler-rt loads the CoreFoundation symbols at runtime. This means that `@available` will always fail when used in a binary without a linked CoreFoundation. This commit forces Clang to emit a reference to a CoreFoundation symbol when `@available` is used to ensure that linking will fail when CoreFoundation isn't linked with the build product. rdar://31039592 Differential Revision: https://reviews.llvm.org/D30977 llvm-svn: 298588
2017-03-21Update Clang for LLVM rename AttributeSet -> AttributeListReid Kleckner
llvm-svn: 298394
2017-03-21IRGen: Do not set dllexport on declarations.Peter Collingbourne
Setting dllexport on a declaration has no effect, as we do not emit export directives for declarations. Part of the fix for PR32334. Differential Revision: https://reviews.llvm.org/D31162 llvm-svn: 298330
2017-03-18[X86] Add NumRegisterParameters Module Flag.Nirav Dave
Reviewers: rnk, mkuper Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D27051 llvm-svn: 298177
2017-03-02Promote ConstantInitBuilder to be a public CodeGen API; it'sJohn McCall
a generally useful utility for other frontends. NFC. llvm-svn: 296806
2017-02-15[dllimport] Check for dtor references in functionsHans Wennborg
Destructor references are not modelled explicitly in the AST. This adds checks for destructor calls due to variable definitions and temporaries. If a dllimport function references a non-dllimport destructor, it must not be emitted available_externally, as the referenced destructor might live across the DLL boundary and isn't exported. llvm-svn: 295258
2017-02-15[dllimport] Look through typedefs and arrays in HasNonDllImportDtorHans Wennborg
The function is used to check whether a type is a class with non-dllimport destructor. It needs to look through typedefs and array types. llvm-svn: 295257
2017-01-30Prototype of modules codegenDavid Blaikie
First pass at generating weak definitions of inline functions from module files (& skipping (-O0) or emitting available_externally (optimizations) definitions where those modules are used). External functions defined in modules are emitted into the modular object file as well (this may turn an existing ODR violation (if that module were imported into multiple translations) into valid/linkable code). Internal symbols (static functions, for example) are not correctly supported yet. The symbol will be produced, internal, in the modular object - unreferenceable from the users. Reviewers: rsmith Differential Revision: https://reviews.llvm.org/D28845 llvm-svn: 293456
2017-01-23Re-commit "Don't inline dllimport functions referencing non-imported methods"Hans Wennborg
This re-commits r292522 with the addition that it also handles calls through pointer to member functions without crashing. llvm-svn: 292856
2017-01-20Revert "Don't inline dllimport functions referencing non-imported methods"Reid Kleckner
This reverts commit r292522. It appears to be causing crashes in builds using dllimport. llvm-svn: 292643
2017-01-19Don't inline dllimport functions referencing non-imported methodsHans Wennborg
This is another follow-up to r246338. I had assumed methods were already handled by the AST visitor, but turns out they weren't. llvm-svn: 292522
2017-01-18Remove now redundant code that ensured debug info for class definitions was ↵David Blaikie
emitted under certain circumstances Introduced in r181561 - it may've been subsumed by work done to allow emission of declarations for vtable types while still emitting some of their member functions correctly for those declarations. Whatever the reason, the tests pass without this code now. llvm-svn: 292439
2017-01-17[WebAssembly] Add minimal support for the new wasm object format triple.Dan Gohman
llvm-svn: 292269
2017-01-11Module: Do not add any link flags when an implementation TU of a module importsManman Ren
a header of that same module. This fixes a regression caused by r280409. rdar://problem/29930553 This is an updated version for r291628 (which was reverted in r291688). llvm-svn: 291689
2016-12-24Deduplicate several GD.getDecl() calls into Decl * local variable.Yaron Keren
llvm-svn: 290495
2016-12-23Cleanup the handling of noinline function attributes, -fno-inline,Chandler Carruth
-fno-inline-functions, -O0, and optnone. These were really, really tangled together: - We used the noinline LLVM attribute for -fno-inline - But not for -fno-inline-functions (breaking LTO) - But we did use it for -finline-hint-functions (yay, LTO is happy!) - But we didn't for -O0 (LTO is sad yet again...) - We had weird structuring of CodeGenOpts with both an inlining enumeration and a boolean. They interacted in weird ways and needlessly. - A *lot* of set smashing went on with setting these, and then got worse when we considered optnone and other inlining-effecting attributes. - A bunch of inline affecting attributes were managed in a completely different place from -fno-inline. - Even with -fno-inline we failed to put the LLVM noinline attribute onto many generated function definitions because they didn't show up as AST-level functions. - If you passed -O0 but -finline-functions we would run the normal inliner pass in LLVM despite it being in the O0 pipeline, which really doesn't make much sense. - Lastly, we used things like '-fno-inline' to manipulate the pass pipeline which forced the pass pipeline to be much more parameterizable than it really needs to be. Instead we can *just* use the optimization level to select a pipeline and control the rest via attributes. Sadly, this causes a bunch of churn in tests because we don't run the optimizer in the tests and check the contents of attribute sets. It would be awesome if attribute sets were a bit more FileCheck friendly, but oh well. I think this is a significant improvement and should remove the semantic need to change what inliner pass we run in order to comply with the requested inlining semantics by relying completely on attributes. It also cleans up tho optnone and related handling a bit. One unfortunate aspect of this is that for generating alwaysinline routines like those in OpenMP we end up removing noinline and then adding alwaysinline. I tried a bunch of other approaches, but because we recompute function attributes from scratch and don't have a declaration here I couldn't find anything substantially cleaner than this. Differential Revision: https://reviews.llvm.org/D28053 llvm-svn: 290398
2016-12-15Re-commit r289252 and r289285, and fix PR31374Yaxun Liu
llvm-svn: 289787
2016-12-15CodeGen: fix runtime function dll storageSaleem Abdulrasool
Properly attribute DLL storage to runtime functions. When generating the runtime function, scan for an existing declaration which may provide an explicit declaration (local storage) or a DLL import or export storage from the user. Honour that if available. Otherwise, if building with a local visibility of the public or standard namespaces (-flto-visibility-public-std), give the symbols local storage (it indicates a /MT[d] link, so static runtime). Otherwise, assume that the link is dynamic, and give the runtime function dllimport storage. This allows for implementations to get the correct storage as long as they are properly declared, the user to override the import storage, and in case no explicit storage is given, use of the import storage. llvm-svn: 289776
2016-12-14Revert 289252 (and follow-up 289285), it caused PR31374Nico Weber
llvm-svn: 289713
2016-12-09Add support for non-zero null pointer for C and OpenCLYaxun Liu
In amdgcn target, null pointers in global, constant, and generic address space take value 0 but null pointers in private and local address space take value -1. Currently LLVM assumes all null pointers take value 0, which results in incorrectly translated IR. To workaround this issue, instead of emit null pointers in local and private address space, a null pointer in generic address space is emitted and casted to local and private address space. Tentative definition of global variables with non-zero initializer will have weak linkage instead of common linkage since common linkage requires zero initializer and does not have explicit section to hold the non-zero value. Virtual member functions getNullPointer and performAddrSpaceCast are added to TargetCodeGenInfo which by default returns ConstantPointerNull and emitting addrspacecast instruction. A virtual member function getNullPointerValue is added to TargetInfo which by default returns 0. Each target can override these virtual functions to get target specific null pointer and the null pointer value for specific address space, and perform specific translations for addrspacecast. Wrapper functions getNullPointer is added to CodegenModule and getTargetNullPointerValue is added to ASTContext to facilitate getting the target specific null pointers and their values. This change has no effect on other targets except amdgcn target. Other targets can provide support of non-zero null pointer in a similar way. This change only provides support for non-zero null pointer for C and OpenCL. Supporting for other languages will be added later incrementally. Differential Revision: https://reviews.llvm.org/D26196 llvm-svn: 289252
2016-11-30Introduce a type-safe enum for ForDefinition.John McCall
llvm-svn: 288289
2016-11-30Fix some layering violations where CGObjCMac's NSString emission wasJohn McCall
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-28Hide the result of building a constant initializer. NFC.John McCall
llvm-svn: 288080
2016-11-28ConstantBuilder -> ConstantInitBuilder for clarity, andJohn McCall
move the member classes up to top level to allow forward declarations to name them. NFC. llvm-svn: 288079
2016-11-23[CodeGen] Simplify code. No functionality change intended.Benjamin Kramer
llvm-svn: 287754
2016-11-19Remove alignment from ctors/dtors lists in an attempt to placate LTO.John McCall
llvm-svn: 287458
2016-11-19Introduce a helper class for building complex constant initializers. NFC.John McCall
I've adopted this in most of the places it makes sense, but v-tables and CGObjCMac will need a second pass. llvm-svn: 287437
2016-11-02regcall: Implement regcall Calling Conv in clangErich Keane
This patch implements the register call calling convention, which ensures as many values as possible are passed in registers. CodeGen changes were committed in https://reviews.llvm.org/rL284108. Differential Revision: https://reviews.llvm.org/D25204 llvm-svn: 285849