[LLVMbugs] [Bug 7445] New: Not all template symbols exported when compiling with -O2

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Jun 21 15:37:32 PDT 2010


http://llvm.org/bugs/show_bug.cgi?id=7445

           Summary: Not all template symbols exported when compiling with
                    -O2
           Product: clang
           Version: unspecified
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: nicolasweber at gmx.de
                CC: llvmbugs at cs.uiuc.edu, dgregor at apple.com


Consider the following program (sorry for its size, I couldn't get it much
smaller):

$ cat test.cc
typedef unsigned int uint32_t;
namespace v8 {
  namespace internal {
    class Object {
      public:
        inline bool IsNull() {return false;}
    };
    template<typename Shape, typename Key> class HashTable {
      public:
        Object* KeyAt(int entry) {return 0;}
        int FindEntry(Key key);
        static uint32_t FirstProbe(uint32_t hash) {return 0;}
    };
    template <typename Shape, typename Key>
    class Dictionary: public HashTable<Shape, Key> {};
    class NumberDictionaryShape {
      public:
        static inline bool IsMatch() {return false;}
        static inline uint32_t Hash(uint32_t key) {return 0;}
    };
    class NumberDictionary: public Dictionary<NumberDictionaryShape, uint32_t>
{
    };
    template<typename Shape, typename Key>
    int HashTable<Shape, Key>::FindEntry(Key key) {
      Object* element = KeyAt(0);
      !element->IsNull() && Shape::IsMatch();
      FirstProbe(Shape::Hash(key));
      return 0;
    }
    void f() { NumberDictionary().FindEntry(0); }

    // Explicit instantiation.
    template class Dictionary<NumberDictionaryShape, uint32_t>;
  }
}

If compiled with clang++, g++, and g++ -O2, the resulting object file contains
the symbol
__ZN2v88internal9HashTableINS0_21NumberDictionaryShapeEjE9FindEntryEj (which is
mangled for "v8::internal::HashTable<v8::internal::NumberDictionaryShape,
unsigned int>::FindEntry(unsigned int)"):

$ g++ -c test.cc
$ nm test.o | grep
__ZN2v88internal9HashTableINS0_21NumberDictionaryShapeEjE9FindEntryEj
00000062 S
__ZN2v88internal9HashTableINS0_21NumberDictionaryShapeEjE9FindEntryEj
00000184 S
__ZN2v88internal9HashTableINS0_21NumberDictionaryShapeEjE9FindEntryEj.eh
$ g++ -c -O2 test.cc
$ nm test.o | grep
__ZN2v88internal9HashTableINS0_21NumberDictionaryShapeEjE9FindEntryEj
00000020 S
__ZN2v88internal9HashTableINS0_21NumberDictionaryShapeEjE9FindEntryEj
00000044 S
__ZN2v88internal9HashTableINS0_21NumberDictionaryShapeEjE9FindEntryEj.eh
$ ~/src/llvm/Release/bin/clang++ -c test.cc  # yields a harmless warning
test.cc:26:7: warning: expression result unused [-Wunused-value]
      !element->IsNull() && Shape::IsMatch();
      ^~~~~~~~~~~~~~~~~~
test.cc:30:35: note: in instantiation of member function
'v8::internal::HashTable<v8::internal::NumberDictionaryShape, unsigned
int>::FindEntry' requested here
    void f() { NumberDictionary().FindEntry(0); }
                                  ^
1 warning generated.
$ nm test.o | grep
__ZN2v88internal9HashTableINS0_21NumberDictionaryShapeEjE9FindEntryEj
00000020 S
__ZN2v88internal9HashTableINS0_21NumberDictionaryShapeEjE9FindEntryEj
00000188 S
__ZN2v88internal9HashTableINS0_21NumberDictionaryShapeEjE9FindEntryEj.eh


However, if compiled with clang++ -O2, that symbol isn't exported:

$ ~/src/llvm/Release/bin/clang++ -O2 -c test.cc
# harmless warning omitted
$ nm test.o | grep
__ZN2v88internal9HashTableINS0_21NumberDictionaryShapeEjE9FindEntryEj

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list