[LLVMbugs] [Bug 18408] New: clang-3.5 emits function definition with internal linkage incorrectly

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Jan 7 01:47:47 PST 2014


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

            Bug ID: 18408
           Summary: clang-3.5 emits function definition with internal
                    linkage incorrectly
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: release blocker
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: ken at fsfoundry.org
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

I use Ubuntu 12.04 and installed clang-3.5 using official repository following
the instructions from http://llvm.org/apt/

$ clang++ --version
Ubuntu clang version 3.5-1~exp1 (trunk) (based on LLVM 3.5)
Target: x86_64-pc-linux-gnu
Thread model: posix

Clang emits function definition incorrectly with internal linkage, when one of
the function's parameters is an instance of, or a pointer to, a template class
taking a nested class template as its template template parameter. This is kind
of mouthful, the code below reproduces the issue.

template <template <class> class A>
struct TemplateTakingTemplateTemplateParameter {};

template <typename B>
class GlobalTemplate {};

struct OutterClass {
    template <typename B>
    class InnerTemplate {};

#if(__cplusplus > 199711L)
    // No template alias pre-C++11
    template <typename B>
    using InnerAliasToGlobalTemplate = GlobalTemplate<B>;
#endif
};

typedef TemplateTakingTemplateTemplateParameter<GlobalTemplate> T1;
typedef TemplateTakingTemplateTemplateParameter<OutterClass::InnerTemplate> T2;
#if(__cplusplus > 199711L)
typedef
TemplateTakingTemplateTemplateParameter<OutterClass::InnerAliasToGlobalTemplate>
T3;
#endif

typedef T1* P1;
typedef T2* P2;
#if(__cplusplus > 199711L)
typedef T3* P3;
#endif

void linkageTest(T1) {}
void linkageTest(T2) {}
#if(__cplusplus > 199711L)
void linkageTest(T3) {}
#endif
void linkageTest(P1) {}
void linkageTest(P2) {}
#if(__cplusplus > 199711L)
void linkageTest(P3) {}
#endif

void test()
{
    linkageTest(T1());
    linkageTest(T2());
#if(__cplusplus > 199711L)
    linkageTest(T3());
#endif
    linkageTest(P1());
    linkageTest(P2());
#if(__cplusplus > 199711L)
    linkageTest(P3());
#endif
}

$ # Using clang to generate IR and grep for "internal"
$ clang++ -std=c++1y -S -emit-llvm internal-linkage.cpp -o - | grep define
define void
@_Z11linkageTest39TemplateTakingTemplateTemplateParameterI14GlobalTemplateE()
#0 {
define void
@_Z11linkageTestP39TemplateTakingTemplateTemplateParameterI14GlobalTemplateE(%struct.TemplateTakingTemplateTemplateParameter*)
#0 {
define void @_Z4testv() #1 {
define internal void
@_Z11linkageTest39TemplateTakingTemplateTemplateParameterIN11OutterClass14NestedTemplateEE()
#0 {
define internal void
@_Z11linkageTest39TemplateTakingTemplateTemplateParameterIN11OutterClass27NestedAliasToGlobalTemplateEE()
#0 {
define internal void
@_Z11linkageTestP39TemplateTakingTemplateTemplateParameterIN11OutterClass14NestedTemplateEE(%struct.TemplateTakingTemplateTemplateParameter.0*)
#0 {
define internal void
@_Z11linkageTestP39TemplateTakingTemplateTemplateParameterIN11OutterClass27NestedAliasToGlobalTemplateEE(%struct.TemplateTakingTemplateTemplateParameter.1*)
#0 {

Note 1: linkageTest(T1) and linkageTest(P1) are emitted correctly without
"internal"
Note 2: Incorrect code are also emitted when the parameter is a (const)
lval-ref or an rval-ref
Note 3: It doesn't matter which -std is used here. I tried c++98, c++0x, c++11
and c++1y

-- 
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/20140107/b90f62e6/attachment.html>


More information about the llvm-bugs mailing list