summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/ItaniumCXXABI.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Small fix for bug 18635.Alexander Musman2014-09-261-7/+8
| | | | | | | | (clang crashed in CodeGen in llvm::Module::getNamedValue on thread_local std::unique_ptr<int>). Differential Revision: http://reviews.llvm.org/D5353 llvm-svn: 218503
* Revert "Don't use comdats for initializers on platforms that don't support it"Reid Kleckner2014-09-231-2/+1
| | | | | | | | | On further investigation, COMDATs should work with .ctors, and the issue I was hitting probably reproduces with .init_array. This reverts commit r218287. llvm-svn: 218313
* Don't use comdats for initializers on platforms that don't support itReid Kleckner2014-09-231-1/+2
| | | | | | | | | In particular, pre-.init_array ELF uses the .ctors section mechanism. MinGW COFF also uses .ctors, now that I think about it. Therefore, restrict this optimization to the two platforms that are currently known to work: ELF with .init_array and COFF with .CRT$XCU. llvm-svn: 218287
* Fix ctor/dtor aliases losing 'dllexport' (for Itanium ABI)Dario Domizioli2014-09-191-1/+1
| | | | | | | This patch makes sure that the dllexport attribute is transferred to the alias when such alias is created. It only affects the Itanium ABI because for the MSVC ABI a workaround is in place to not generate aliases of dllexport ctors/dtors. A new CodeGenModule function is provided, CodeGenModule::setAliasAttributes, to factor the code for transferring attributes to aliases. llvm-svn: 218159
* In the Itanium ABI, move stuff to the comdat of variables with static init.Rafael Espindola2014-09-191-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Clang can already handle ------------------------------------------- struct S { static const int x; }; template<typename T> struct U { static const int k; }; template<typename T> const int U<T>::k = T::x; const int S::x = 42; extern const int *f(); const int *g() { return &U<S>::k; } int main() { return *f() + U<S>::k; } const int *f() { return &U<S>::k; } ------------------------------------------- since r217264 which puts the .inint_array section in the same COMDAT as the variable. This patch allows the linker to more easily delete some dead code and data by putting the guard variable and init function in the same COMDAT. This is a fixed version of r218089. llvm-svn: 218141
* Revert "Put more stuff in the comdat used for variables with static init."Rafael Espindola2014-09-191-7/+0
| | | | | | | This reverts commit r218089. It looks like it was causing issues on COFF. llvm-svn: 218094
* Put more stuff in the comdat used for variables with static init.Rafael Espindola2014-09-181-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Clang can already handle ------------------------------------------- struct S { static const int x; }; template<typename T> struct U { static const int k; }; template<typename T> const int U<T>::k = T::x; const int S::x = 42; extern const int *f(); const int *g() { return &U<S>::k; } int main() { return *f() + U<S>::k; } const int *f() { return &U<S>::k; } ------------------------------------------- since r217264 which puts the .inint_array section in the same COMDAT as the variable. This patch allows the linker to more easily delete some dead code and data by putting the guard variable and init function in the same COMDAT. llvm-svn: 218089
* Don't try to use C5/D5 comdats in COFF.Rafael Espindola2014-09-161-2/+6
| | | | | | This should fix the mingw bootstrap. llvm-svn: 217897
* Add support for putting constructors and destructos in explicit comdats.Rafael Espindola2014-09-161-36/+106
| | | | | | | | | | | | | | | | | | There are situations when clang knows that the C1 and C2 constructors or the D1 and D2 destructors are identical. We already optimize some of these cases, but cannot optimize it when the GlobalValue is weak_odr. The problem with weak_odr is that an old TU seeing the same code will have a C1 and a C2 comdat with the corresponding symbols. We cannot suddenly start putting the C2 symbol in the C1 comdat as we cannot guarantee that the linker will not pick a .o with only C1 in it. The solution implemented by GCC is to expand the ABI to have a comdat whose name uses a C5/D5 suffix and always has both symbols. That is what this patch implements. llvm-svn: 217874
* Reduce code duplication a bit more. NFC.Rafael Espindola2014-09-151-12/+1
| | | | llvm-svn: 217813
* Reduce code duplication a bit more. NFC.Rafael Espindola2014-09-151-11/+1
| | | | llvm-svn: 217811
* Simplify the code a bit, NFC.Rafael Espindola2014-09-151-7/+2
| | | | | | hasConstructorVariants is always true for MS and false for Itanium. llvm-svn: 217809
* Move emitCXXStructor to CGCXXABI.Rafael Espindola2014-09-151-0/+79
| | | | | | A followup patch will address the code duplication. llvm-svn: 217807
* MS ABI: Use the correct this arg when generating implict copy ctorDavid Majnemer2014-09-111-0/+6
| | | | | | | | | | We assumed that the incoming this argument would be the last argument. However, this is not true under the MS ABI. This fixes PR20897. llvm-svn: 217642
* Merge GetAddrOfCXXConstructor and GetAddrOfCXXDonstructor. NFC.Rafael Espindola2014-09-111-1/+1
| | | | llvm-svn: 217598
* CodeGen: Use a fixed alignment for vtables.Benjamin Kramer2014-09-101-0/+6
| | | | | | | | | | | | | | | Pointer-sized alignment is sufficient as we only ever read single values from the table. Otherwise we'd bump the alignment to 16 bytes in the backend if the vtable is larger than 16 bytes. This is great for structures that are accessed with vector instructions or copied around, but that's simply not the case for vtables. Shrinks the data segment of a Release x86_64 clang by 0.3%. The wins are larger for i386 and code bases that use vtables more often than we do. This matches the behavior of GCC 5. llvm-svn: 217495
* Handle constructors and destructors a bit more uniformly in CodeGen.Rafael Espindola2014-09-081-36/+12
| | | | | | | | | There were code paths that are duplicated for constructors and destructors just because we have both CXXCtorType and CXXDtorsTypes. This patch introduces an unified enum and reduces code deplication a bit. llvm-svn: 217383
* call __asan_load_cxx_array_cookie when loading array cookie in asan mode.Kostya Serebryany2014-08-291-5/+14
| | | | | | | | | | | | | | | | | | Summary: The current implementation of asan cookie is incorrect: we add nosanitize metadata to the cookie load, but the metadata may be lost and we will instrument the load from poisoned memory. This change replaces the load with a call to __asan_load_cxx_array_cookie (r216692) Reviewers: rsmith Reviewed By: rsmith Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D5111 llvm-svn: 216702
* Reverting r216675. This breaks some bots. Before this can be committed ↵Aaron Ballman2014-08-281-35/+0
| | | | | | again, I have to explore runtime ABI requirements with libc++abi. llvm-svn: 216677
* Throw a std::bad_array_new_length exception when the expression (or ↵Aaron Ballman2014-08-281-0/+35
| | | | | | constant-expression) passed to operator new[] results in overflow in conformance with [expr.new]p7. Fixes PR11644. llvm-svn: 216675
* [clang/asan] call __asan_poison_cxx_array_cookie after operator new[]Kostya Serebryany2014-08-261-5/+17
| | | | | | | | | | | | | | | | | | | | Summary: PR19838 When operator new[] is called and an array cookie is created we want asan to detect buffer overflow bugs that touch the cookie. For that we need to a) poison the shadow for the array cookie (call __asan_poison_cxx_array_cookie). b) ignore the legal accesses to the cookie generated by clang (add 'nosanitize' metadata) Reviewers: timurrrr, samsonov, rsmith Reviewed By: rsmith Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D4774 llvm-svn: 216434
* Pass actual CallExpr instead of CallExpr-specific iteratorsAlexey Samsonov2014-08-251-10/+9
| | | | | | | | | | | into EmitCXXMemberOrOperatorCall methods. In the end we want to make declaration visible in EmitCallArgs() method, that would allow us to alter CodeGen depending on function/parameter attributes. No functionality change. llvm-svn: 216404
* CodeGen: Don't emit a thread-wrapper if we can't touch the backing variableDavid Majnemer2014-07-111-7/+23
| | | | | | | | | | | | | | | | OS X TLS has all accesses going through the thread-wrapper function and gives the backing thread-local variable internal linkage. This means that thread-wrappers must have WeakAnyLinkage so that references to the internal thread-local variables do not get propagated to other code. It also means that translation units which do not provide a definition for the thread-local variable cannot attempt to emit a thread-wrapper because the thread wrapper will attempt to reference the backing variable. Differential Revision: http://reviews.llvm.org/D4109 llvm-svn: 212841
* CodeGen: Refactor RTTI emissionDavid Majnemer2014-07-071-2/+1030
| | | | | | | | | | | | | | | | | | | | | | | Let's not expose ABI specific minutia inside of CodeGenModule and Type. Instead, let's abstract it through CXXABI. This gets rid of: CodeGenModule::getCompleteObjectLocator, CodeGenModule::EmitFundamentalTypeDescriptor{s,}, CodeGenModule::getMSTypeDescriptor, CodeGenModule::getMSCompleteObjectLocator, CGCXXABI::shouldRTTIBeUnique, CGCXXABI::classifyRTTIUniqueness. CGRTTI was *almost* entirely centered around providing Itanium-style RTTI information. Instead of providing interfaces that only it consumes, move it to the ItaniumCXXABI implementation file. This allows it to have access to Itanium-specific implementation details without providing useless expansion points for the Microsoft ABI side. Differential Revision: http://reviews.llvm.org/D4261 llvm-svn: 212435
* MS ABI: Reference MSVC RTTI from the VFTableDavid Majnemer2014-07-011-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The pointer for a class's RTTI data comes right before the VFTable but has no name. To be properly compatible with this, we do the following: * Create a single GlobalVariable which holds the contents of the VFTable _and_ the pointer to the RTTI data. * Create a GlobalAlias, with appropriate linkage/visibility, that points just after the RTTI data pointer. This ensures that the VFTable symbol will always refer to VFTable data. * Create a Comdat with a "Largest" SelectionKind and stick the private GlobalVariable in it. By transitivity, the GlobalAlias will be a member of the Comdat group. Using "Largest" ensures that foreign definitions without an RTTI data pointer will _not_ be chosen in the final linked image. Whether or not we emit RTTI data depends on several things: * The -fno-rtti flag implies that we should never not emit a pointer to RTTI data before the VFTable. * __declspec(dllimport) brings in the VFTable from a remote DLL. Use an available_externally GlobalVariable to provide a local definition of the VFTable. This means that we won't have any available_externally definitions of things like complete object locators. This is acceptable because they are never directly referenced. To my knowledge, this completes the implementation of MSVC RTTI code generation. Further semantic work should be done to properly support /GR-. llvm-svn: 212125
* Remove llvm:: from uses of ArrayRef.Craig Topper2014-06-281-2/+2
| | | | llvm-svn: 211987
* CodeGen: Fix a typo in getThreadLocalWrapperLinkageDavid Majnemer2014-06-271-1/+1
| | | | | | The description had a misspelling. No functionality change. llvm-svn: 211908
* Revert "Revert r211402 (and r211408,r211410), "CodeGen: Refactor ↵David Majnemer2014-06-221-0/+209
| | | | | | | | | dynamic_cast and typeid" It crashes msvc codegen in clang/test/SemaCXX/undefined-internal.cpp." This reverts commit r211467 which reverted r211408,r211410, it caused crashes in test/SemaCXX/undefined-internal.cpp for i686-win32 targets. llvm-svn: 211473
* Revert r211402 (and r211408,r211410), "CodeGen: Refactor dynamic_cast and ↵NAKAMURA Takumi2014-06-221-209/+0
| | | | | | | | | | typeid" It crashes msvc codegen in clang/test/SemaCXX/undefined-internal.cpp. It is reproducible with: $ clang -cc1 -triple i686-win32 -emit-llvm-only clang/test/SemaCXX/undefined-internal.cpp llvm-svn: 211467
* CodeGen: Refactor dynamic_cast and typeidDavid Majnemer2014-06-201-0/+209
| | | | | | | | | | | This refactors the emission of dynamic_cast and typeid expressions so that ABI specific knowledge lives in appropriate places. There are quite a few benefits for having the two implementations share a common core like sharing logic for optimization opportunities. While we are at it, clean up the tests. llvm-svn: 211402
* CodeGen: Correct linkage of thread_local for OS XDavid Majnemer2014-06-111-6/+15
| | | | | | | | | | | | | The backing store of thread local variables is internal for OS X and all accesses must go through the thread wrapper. However, individual TUs may have inlined through the thread wrapper. To fix this, give the thread wrapper functions WeakAnyLinkage. This prevents them from getting inlined into call-sites. This fixes PR19989. llvm-svn: 210632
* MS ABI: Update the thunk linkage computationHans Wennborg2014-06-061-1/+2
| | | | | | | | | | | | | | | | | | | | | | | As suggested by Reid: - class has GVA_Internal linkage -> internal - thunk has return adjustment -> weak_odr, to handle evil corner case [1] - all other normal methods -> linkonce_odr 1. Evil corner case: struct Incomplete; struct A { int a; virtual A *bar(); }; struct B { int b; virtual B *foo(Incomplete); }; struct C : A, B { int c; virtual C *foo(Incomplete); }; C c; Here, the thunk for C::foo() will be emitted when C::foo() is defined, which might be in a different translation unit, so it needs to be weak_odr. Differential Revision: http://reviews.llvm.org/D3992 llvm-svn: 210368
* Itanium ABI: Update getAddrOfVTable to set the DLL storage class for vtablesHans Wennborg2014-06-021-0/+6
| | | | | | | | This corresponds to the same change for the MS ABI in r209908. Differential Revision: http://reviews.llvm.org/D3993 llvm-svn: 210054
* [C++11] Use 'nullptr'. CodeGen edition.Craig Topper2014-05-211-5/+6
| | | | llvm-svn: 209272
* Update for llvm api change.Rafael Espindola2014-05-171-2/+2
| | | | llvm-svn: 209077
* Update for llvm api change.Rafael Espindola2014-05-171-3/+2
| | | | llvm-svn: 209074
* Update for llvm API change.Rafael Espindola2014-05-161-3/+3
| | | | llvm-svn: 208984
* Revert Itanium parts of "Don't copy objects with trivial, deleted copy ctors"Reid Kleckner2014-05-151-4/+9
| | | | | | | | | | | | | | | | | | | | | | | | This undoes half of r208786. It had problems with lazily declared special members in cases like this: struct A { A(); A &operator=(A &&o); void *p; }; void foo(A); void bar() { foo({}); } In this case, the copy and move constructors are implicitly deleted. However, Clang doesn't eagerly declare the copy ctor in the AST, so we pass the struct in registers. Furthermore, GCC passes this in registers even though this class should be uncopyable. Revert this for now until the dust settles. llvm-svn: 208836
* Don't copy objects with trivial, deleted copy ctorsReid Kleckner2014-05-141-7/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This affects both the Itanium and Microsoft C++ ABIs. This is in anticipation of a change to the Itanium C++ ABI, and should match GCC's current behavior. The new text will likely be: """ Pass an object of class type by value if every copy constructor and move constructor is deleted or trivial and at least one of them is not deleted, and the destructor is trivial. """ http://sourcerytools.com/pipermail/cxx-abi-dev/2014-May/002728.html On x86 Windows, we can mostly use the same logic, where we use inalloca instead of passing by address. However, on Win64, there are register parameters, and we have to do what MSVC does. MSVC ignores the presence of non-trivial move constructors and only considers the presence of non-trivial or deleted copy constructors. If a non-trivial or deleted copy ctor is present, it passes the argument indirectly. This change fixes bugs and makes us more ABI compatible with both GCC and MSVC. Fixes PR19668. Reviewers: rsmith Differential Revision: http://reviews.llvm.org/D3660 llvm-svn: 208786
* Push record return type classification into CGCXXABIReid Kleckner2014-05-131-5/+16
| | | | | | | | | | | | In the Microsoft C++ ABI, instance methods always return records indirectly via the second hidden parameter. This was implemented in X86_32ABIInfo, but not WinX86_64ABIInfo. Rather than exposing a handful of boolean methods in the CGCXXABI interface, we can expose a single method that applies C++ ABI return value classification rules. llvm-svn: 208733
* CodeGen: Don't set hidden visibility on symbols with local linkageDuncan P. N. Exon Smith2014-05-071-1/+2
| | | | llvm-svn: 208258
* CodeGen: Assign linkage to thread-wrappers correctlyDavid Majnemer2014-05-051-2/+3
| | | | | | | | | | We would sometimes incorrectly give a thread-wrapper external linkage instead of internal linkage if we had only CodeGen'd it's declaration, not it's definition. This fixes PR19655. llvm-svn: 207988
* CodeGen: Unify handling guard variables in the Itanium C++ ABIJustin Bogner2014-04-231-41/+39
| | | | | | | | | | | | | | | We previously treated ARM separately from the generic Itanium ABI for initializing guard variables. This code duplication led to things like the ARM path missing the memory barrier for threadsafe handling, and a highly misleading comment about how we were (mis)using the generic ABI for ARM64 when really it went through the ARM codepath. This unifies the two code paths. Functionally, this changes the ARM and ARM64 codepath to use one byte loads instead of 4 and 8, respectively, and adds the missing atomic acquire to these loads. Other architectures are unchanged. llvm-svn: 206937
* RTTI: refactor the uniqueness question into CGCXXABI.Tim Northover2014-03-301-0/+3
| | | | | | | This also brings the code into closer conformance with usual LLVM coding style and other surrounding conventions. llvm-svn: 205158
* ARM64: initial clang support commit.Tim Northover2014-03-291-0/+15
| | | | | | | | | | | This adds Clang support for the ARM64 backend. There are definitely still some rough edges, so please bring up any issues you see with this patch. As with the LLVM commit though, we think it'll be more useful for merging with AArch64 from within the tree. llvm-svn: 205100
* PR19254: If a thread_local data member of a class is accessed via member accessRichard Smith2014-03-261-8/+7
| | | | | | syntax, don't forget to run its initializer. llvm-svn: 204869
* Fix PR19104: Incorrect handling of non-virtual calls of virtual methodsTimur Iskhodzhanov2014-03-141-3/+0
| | | | | | Reviewed at http://llvm-reviews.chandlerc.com/D3054 llvm-svn: 203949
* PR19113: Emit 'vtable' TBAA metadata when loading a vptr in a ↵Richard Smith2014-03-121-2/+1
| | | | | | pointer-to-member-function call. llvm-svn: 203691
* [C++11] Add 'override' keyword to virtual methods that override their base ↵Craig Topper2014-03-121-70/+74
| | | | | | class. llvm-svn: 203643
* Sema: Do not assert when dereferencing member pointer using virtual ↵David Majnemer2014-02-201-10/+8
| | | | | | | | | | | | | | inheritance with an incomplete class type The MS ABI requires that we determine the vbptr offset if have a virtual inheritance model. Instead, raise an error pointing to the diagnostic when this happens. This fixes PR18583. Differential Revision: http://llvm-reviews.chandlerc.com/D2842 llvm-svn: 201824
OpenPOWER on IntegriCloud