mirror of
https://github.com/Gericom/teak-llvm.git
synced 2025-06-20 03:55:48 -04:00

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
36 lines
1.1 KiB
C++
36 lines
1.1 KiB
C++
// RUN: %clang_cc1 -emit-llvm -triple=i386-pc-win32 -fms-compatibility %s -o - | FileCheck %s
|
|
// RUN: %clang_cc1 -DINLINE_INIT -emit-llvm -triple=i386-pc-win32 -fms-compatibility %s -o - | FileCheck %s --check-prefix=CHECK-INLINE
|
|
// RUN: %clang_cc1 -DREAL_DEFINITION -emit-llvm -triple=i386-pc-win32 -fms-compatibility %s -o - | FileCheck %s --check-prefix=CHECK-OUTOFLINE
|
|
// RUN: %clang_cc1 -DINLINE_INIT -DREAL_DEFINITION -emit-llvm -triple=i386-pc-win32 -fms-compatibility %s -o - | FileCheck %s --check-prefix=CHECK-INLINE
|
|
|
|
struct S {
|
|
// For MS ABI, we emit a linkonce_odr definition here, even though it's really just a declaration.
|
|
#ifdef INLINE_INIT
|
|
static const int x = 5;
|
|
#else
|
|
static const int x;
|
|
#endif
|
|
};
|
|
|
|
const int *f() {
|
|
return &S::x;
|
|
};
|
|
|
|
#ifdef REAL_DEFINITION
|
|
#ifdef INLINE_INIT
|
|
const int S::x;
|
|
#else
|
|
const int S::x = 5;
|
|
#endif
|
|
#endif
|
|
|
|
|
|
// Inline initialization.
|
|
// CHECK-INLINE: @"\01?x@S@@2HB" = linkonce_odr constant i32 5, comdat, align 4
|
|
|
|
// Out-of-line initialization.
|
|
// CHECK-OUTOFLINE: @"\01?x@S@@2HB" = constant i32 5, align 4
|
|
|
|
// No initialization.
|
|
// CHECK: @"\01?x@S@@2HB" = external constant i32
|