-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Description
Bugzilla Link | 27853 |
Resolution | INVALID |
Resolved on | May 26, 2016 18:02 |
Version | trunk |
OS | Linux |
Attachments | demonstration of described behavior |
Reporter | LLVM Bugzilla Contributor |
CC | @dwblaikie,@DougGregor,@zygoloid,@rnk |
Extended Description
We've noticed a major incompatability between clang & gcc in the way that template classes are instantiated when optimization is in effect across multiple translation units.
There's not much to be found in a Google search, but this post (https://whatofhow.wordpress.com/2015/03/17/odr-rtti-dso/) seems to suggest that this incompatibility is intentional.
This recently bit us with code similar to attached, which was attempting to define a single using a local static object. The code works as expected with g++ (4.3.3, 4.8.2, 5.3.0) at all optimization levels. Also works as expected with clang at -O0, but at -O3 the instance() method (and associated local static) appear to be inlined, which appears to violate ODR(?). The results are consistent with clang 3.7.0, trunk(r264914) and trunk(r269323).
The results of running the attached code with different compilers and optimization levels:
$ CXX=g++ ./test.sh -O0
test1.so:0000000000000717 W Singleton::instance()
test2.so:0000000000000717 W Singleton::instance()
test1.so:0000000000200a80 u Singleton::instance()::obj
test2.so:0000000000200a80 u Singleton::instance()::obj
$ CXX=g++ ./test.sh -O1
test1.so:0000000000200910 u Singleton::instance()::obj
test2.so:0000000000200910 u Singleton::instance()::obj
$ CXX=g++ ./test.sh -O2
test1.so:0000000000200910 u Singleton::instance()::obj
test2.so:0000000000200910 u Singleton::instance()::obj
$ CXX=g++ ./test.sh -O3
test1.so:0000000000200910 u Singleton::instance()::obj
test2.so:0000000000200910 u Singleton::instance()::obj
$ CXX=clang++ ./test.sh -O0
test1.so:0000000000000770 W Singleton::instance()
test2.so:0000000000000770 W Singleton::instance()
test1.so:0000000000200af0 V Singleton::instance()::obj
test2.so:0000000000200af0 V Singleton::instance()::obj
$ CXX=clang++ ./test.sh -O1
test1.so:0000000000000740 W Singleton::instance()
test2.so:0000000000000740 W Singleton::instance()
test1.so:0000000000200a90 V Singleton::instance()::obj
test2.so:0000000000200a90 V Singleton::instance()::obj
$ CXX=clang++ ./test.sh -O2
$ CXX=clang++ ./test.sh -O3
$
So, I have the following questions:
- Is this behavior intended?
- Is this behavior correct?
Any references to rationale for this discrepancy would be much appreciated.
Thanks!