summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/ItaniumCXXABI.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* [patch][pr19848] Produce explicit comdats in clang.Rafael Espindola2015-01-121-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | The llvm IR until recently had no support for comdats. This was a problem when targeting C++ on ELF/COFF as just using weak linkage would cause quite a bit of dead bits to remain on the executable (unless -ffunction-sections, -fdata-sections and --gc-sections were used). To fix the problem, llvm's codegen will just assume that any weak or linkonce that is not in an explicit comdat should be output in one with the same name as the global. This unfortunately breaks cases like pr19848 where a weak symbol is not xpected to be part of any comdat. Now that we have explicit comdats in the IR, we can finally get both cases right. This first patch just makes clang give explicit comdats to GlobalValues where t is allowed to. A followup patch to llvm will then stop implicitly producing comdats. llvm-svn: 225705
* Fix comment typo.Nico Weber2015-01-071-1/+1
| | | | llvm-svn: 225340
* Revert "Put static local variables of inline functions in the function comdat."Rafael Espindola2014-12-171-4/+2
| | | | | | | | | This reverts commit r224369. Thanks to Reid Kleckner for pointing out that we need a bigger gun to fix this case. llvm-svn: 224475
* Put static local variables of inline functions in the function comdat.Rafael Espindola2014-12-161-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | The variable (and the GV) is only ever used if the function is. Putting it in the function's comdat make it easier for the linker to discard them. The motivating example is struct S { static const int x; }; // const int S::x = 42; inline const int *f() { static const int y = S::x; return &y; } const int *g() { return f(); } With S::x commented out, _ZZ1fvE1y is a variable with a guard variable that is initialized by f. With S::x present, _ZZ1fvE1y is a constant. llvm-svn: 224369
* Use nullptr to silence -Wsentinel when self-hosting on WindowsReid Kleckner2014-12-011-1/+1
| | | | | | | | | | | Richard rejected my Sema change to interpret an integer literal zero in a varargs context as a null pointer, so -Wsentinel sees an integer literal zero and fires off a warning. Only CodeGen currently knows that it promotes integer literal zeroes in this context to pointer size on Windows. I didn't want to teach -Wsentinel about that compatibility hack. Therefore, I'm migrating to C++11 nullptr. llvm-svn: 223079
* MS ABI: Add CodeGen support for rethrowing MS C++ exceptionsDavid Majnemer2014-11-251-0/+16
| | | | | | | | | | Rethrowing exceptions in the MS model is very simple: just call _CxxThrowException with nullptr for both arguments. N.B. They chose stdcall as the calling convention for x86 but cdecl for all other platforms. llvm-svn: 222733
* Update for LLVM API change to make Small(Ptr)Set::insert return ↵David Blaikie2014-11-191-2/+2
| | | | | | pair<iterator, bool> as per the C++ standard's associative container concept. llvm-svn: 222335
* Introduce a SanitizerKind enum to LangOptions.Alexey Samsonov2014-11-071-2/+2
| | | | | | | | | | | | | Use the bitmask to store the set of enabled sanitizers instead of a bitfield. On the negative side, it makes syntax for querying the set of enabled sanitizers a bit more clunky. On the positive side, we will be able to use SanitizerKind to eventually implement the new semantics for -fsanitize-recover= flag, that would allow us to make some sanitizers recoverable, and some non-recoverable. No functionality change. llvm-svn: 221558
* CodeGen, Itanium: Properly dllimport RTTI dataDavid Majnemer2014-11-071-1/+10
| | | | | | | | | | We would blindly assume that RTTI data should have the same linkage as the vtable because we didn't think the RTTI data was external. This oversight stemmed because we didn't take dllimport into account. This fixes PR21512. llvm-svn: 221511
* CodeGen: Declutter the emitVirtualObjectDelete interfaceDavid Majnemer2014-11-011-7/+9
| | | | | | No functionality change intended. llvm-svn: 221043
* MS ABI: Properly call global delete when invoking virtual destructorsDavid Majnemer2014-10-311-25/+45
| | | | | | | | | | | | | | | | | | | | Summary: The Itanium ABI approach of using offset-to-top isn't possible with the MS ABI, it doesn't have that kind of information lying around. Instead, we do the following: - Call the virtual deleting destructor with the "don't delete the object flag" set. The virtual deleting destructor will return a pointer to 'this' adjusted to the most derived class. - Call the global delete using the adjusted 'this' pointer. Reviewers: rnk Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D5996 llvm-svn: 220993
* SanitizerBlacklist: blacklist functions by their source location.Alexey Samsonov2014-10-171-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit changes the way we blacklist functions in ASan, TSan, MSan and UBSan. We used to treat function as "blacklisted" and turned off instrumentation in it in two cases: 1) Function is explicitly blacklisted by its mangled name. This part is not changed. 2) Function is located in llvm::Module, whose identifier is contained in the list of blacklisted sources. This is completely wrong, as llvm::Module may not correspond to the actual source file function is defined in. Also, function can be defined in a header, in which case user had to blacklist the .cpp file this header was #include'd into, not the header itself. Such functions could cause other problems - for instance, if the header was included in multiple source files, compiled separately and linked into a single executable, we could end up with both instrumented and non-instrumented version of the same function participating in the same link. After this change we will make blacklisting decision based on the SourceLocation of a function definition. If a function is not explicitly defined in the source file, (for example, the function is compiler-generated and responsible for initialization/destruction of a global variable), then it will be blacklisted if the corresponding global variable is defined in blacklisted source file, and will be instrumented otherwise. After this commit, the active users of blacklist files may have to revisit them. This is a backwards-incompatible change, but I don't think it's possible or makes sense to support the old incorrect behavior. I plan to make similar change for blacklisting GlobalVariables (which is ASan-specific). llvm-svn: 219997
* MS ABI: Implement thread_local for global variablesDavid Majnemer2014-10-051-7/+29
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: This add support for the C++11 feature, thread_local global variables. The ABI Clang implements is an improvement of the MSVC ABI. Sadly, further improvements could be made but not without sacrificing ABI compatibility. The feature is implemented as follows: - All thread_local initialization routines are pointed to from the .CRT$XDU section. - All non-weak thread_local variables have their initialization routines call from a single function instead of getting their own .CRT$XDU section entry. This is done to open up optimization opportunities to the compiler. - All weak thread_local variables have their own .CRT$XDU section entry. This entry is in a COMDAT with the global variable it is initializing; this ensures that we will initialize the global exactly once. - Destructors are registered in the initialization function using __tlregdtor. Differential Revision: http://reviews.llvm.org/D5597 llvm-svn: 219074
* 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
OpenPOWER on IntegriCloud