Put more stuff in the comdat used for variables with static init

Rafael EspĂ­ndola rafael.espindola at gmail.com
Tue Sep 16 09:05:03 PDT 2014


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;

#ifdef TU1
const int S::x = 42;
extern const int *f();
const int *g() { return &U<S>::k; }
int main() {
  return *f() + U<S>::k;
}
#endif

#ifdef TU2
const int *f() { return &U<S>::k; }
#endif
-------------------------------------------

since r217264 which puts the .inint_array section in the same COMDAT
as the variable.

The attached 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.

One thing we have to decide is what to do about MachO. Should we omit
the comdats from the IR for MachO or have llvm ignore it?

Cheers,
Rafael
-------------- next part --------------
A non-text attachment was scrubbed...
Name: t.patch
Type: text/x-patch
Size: 2659 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140916/a831c8b3/attachment.bin>


More information about the cfe-commits mailing list