[llvm-bugs] [Bug 39860] New: Template<Function> - Definition with same mangled name error when Function attributes differ

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Dec 2 03:46:53 PST 2018


https://bugs.llvm.org/show_bug.cgi?id=39860

            Bug ID: 39860
           Summary: Template<Function> - Definition with same mangled name
                    error when Function attributes differ
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: kobalicek.petr at gmail.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
                    neeilans at live.com, richard-llvm at metafoo.co.uk

The following snippet fails when compiled in 32-bit mode (-m32):

#include <stdint.h>

#if defined(_MSC_VER)
  #define FASTCALL __fastcall
#else
  #define FASTCALL __attribute((fastcall))
#endif

int f(int x) { return x; }
int FASTCALL g(int x) { return x; }

template<typename Fn>
static intptr_t func_as_ptr(Fn fn) { return intptr_t(fn); }

intptr_t fAsPtr() { return func_as_ptr(f); }
intptr_t gAsPtr() { return func_as_ptr(g); }

This may be a duplicate of #28909 although it's a bit different test-case and
I'm not sure this can be workarounded by using C++ attributes. GCC and MSVC
pass this test-case.

Compiler Explorer:

https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(j:1,lang:c%2B%2B,source:'%23include+%3Cstdint.h%3E%0A%0A%23if+defined(_MSC_VER)%0A%23+define+FASTCALL+__fastcall%0A%23else%0A%23+define+FASTCALL+__attribute((fastcall))%0A%23endif%0A%0Aint+f(int+x)+%7B+return+x%3B+%7D%0Aint+FASTCALL+g(int+x)+%7B+return+x%3B+%7D%0A%0Atemplate%3Ctypename+Fn%3E%0Astatic+intptr_t+func_as_ptr(Fn+fn)+%7B%0A++return+intptr_t(fn)%3B%0A%7D%0A%0Aintptr_t+fAsPtr()+%7B%0A++return+func_as_ptr(f)%3B%0A%7D%0A%0Aintptr_t+gAsPtr()+%7B%0A++return+func_as_ptr(g)%3B%0A%7D%0A'),l:'5',n:'0',o:'C%2B%2B+source+%231',t:'0')),k:28.292682926829272,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:clang_trunk,filters:(b:'0',binary:'1',commentOnly:'0',demangle:'0',directives:'0',execute:'1',intel:'0',trim:'1'),lang:c%2B%2B,libs:!(),options:'-O2+-m32',source:1),l:'5',n:'0',o:'x86-64+clang+(trunk)+(Editor+%231,+Compiler+%231)+C%2B%2B',t:'0')),k:18.125901244232036,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:gsnapshot,filters:(b:'0',binary:'1',commentOnly:'0',demangle:'0',directives:'0',execute:'1',intel:'0',trim:'1'),lang:c%2B%2B,libs:!(),options:'-O2+-m32',source:1),l:'5',n:'0',o:'x86-64+gcc+(trunk)+(Editor+%231,+Compiler+%232)+C%2B%2B',t:'0')),k:18.00384130319344,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:'vcpp_v19_15_(vs_15_8)_x86',filters:(b:'0',binary:'1',commentOnly:'0',demangle:'0',directives:'0',execute:'1',intel:'0',trim:'1'),lang:c%2B%2B,libs:!(),options:/Ox,source:1),l:'5',n:'0',o:'x86+msvc+v19.15+(VS+15.8)+(Editor+%231,+Compiler+%233)+C%2B%2B',t:'0')),k:15.577574525745257,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:output,i:(compiler:1,editor:1,wrap:'1'),l:'5',n:'0',o:'%231+with+x86-64+clang+(trunk)',t:'0')),k:20,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4

-- 
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/20181202/06bf5f69/attachment-0001.html>


More information about the llvm-bugs mailing list