[LLVMdev] weak_odr constant versus weak_odr global
Rafael EspĂndola
rafael.espindola at gmail.com
Mon Nov 7 07:37:29 PST 2011
I tried a small variation:
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
extern int f();
const int S::x = 42;
int main() {
return f() + reinterpret_cast<long>(&U<S>::k);
}
#endif
#ifdef TU2
int f() { return U<S>::k; }
#endif
and it crashes with gcc too :-( The original testcase works because
gcc folds the value into main even at -O0.
If we are going to support it for real, I think Richard patch is going
on the right direction, but we should completely drop the idea of a
"weak_odr constant". If we cannot use it for instructing the linker to
put it an o ro section, the "constant" gives us nothing that the "odr"
doesn't.
We could always convert a "weak_odr global" into a plain constant in
LTO if the linker tells us we have all the parts.
Cheers,
Rafael
More information about the llvm-dev
mailing list