[LLVMbugs] [Bug 19480] New: Miscompile when linking variable templates instantiated from similarly named local types

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Apr 18 15:03:48 PDT 2014


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

            Bug ID: 19480
           Summary: Miscompile when linking variable templates
                    instantiated from similarly named local types
           Product: clang
           Version: 3.4
          Hardware: Other
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++1y
          Assignee: unassignedclangbugs at nondot.org
          Reporter: hstong at ca.ibm.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

The functions foo() in the program below can only reside in their native
translation unit.
The local classes Foo in each foo() are distinct entities.

Clang seems to treat the x<Foo> specializations as one entity.


### TRANSLATION UNIT A:
> cat badvartmpllinkA.cc 
template <typename T> int x = 42;

static int &foo() {
   struct Foo { };
   return x<Foo>;
}

int &bar() { return foo(); }
Return:  0x00:0


### TRANSLATION UNIT B:
> cat badvartmpllinkB.cc 
template <typename T> int x = 42;

static int &foo() {
   struct Foo { };
   return x<Foo>;
}

int &bar();

int main() { &bar() == &foo() ? throw 0 : (void)0; }
Return:  0x00:0


### COMPILER INVOCATION:
> clang++ -std=c++1y -pedantic-errors badvartmpllinkA.cc badvartmpllinkB.cc -o badvartmpllink                    
Return:  0x00:0


### OUTPUT FROM RESULTING BINARY:
> ./badvartmpllink 
terminate called after throwing an instance of 'int'
Aborted (core dumped)
Return:  0x86:134


### VERSION INFORMATION:
> clang++ -v
clang version 3.4 (tags/RELEASE_34/final)
Target: powerpc64-unknown-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/lib/gcc/ppc64-redhat-linux/4.4.4
Found candidate GCC installation: /usr/lib/gcc/ppc64-redhat-linux/4.4.6
Selected GCC installation: /usr/lib/gcc/ppc64-redhat-linux/4.4.6
Return:  0x00:0

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140418/927eb0e0/attachment.html>


More information about the llvm-bugs mailing list