<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - CNTTP materialisation exported even for unnamed-namespace content"
href="https://bugs.llvm.org/show_bug.cgi?id=52229">52229</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>CNTTP materialisation exported even for unnamed-namespace content
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++2a
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>thiago@kde.org
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>When a non-type class template parameter is materialised because its address is
taken, clang emits it as weak but always global. That content does not obey
either -fvisibility=hidden nor the fact that the type may be in an unnamed
namespace. The latter produces broken code.
$ cat test1.cpp
#include <stdio.h>
[[gnu::noinline]] void dump(const void *data, size_t len)
{
const char *ptr = reinterpret_cast<const char *>(data);
const char *end = ptr + len;
printf("%p(%zd) = ", data, len);
for ( ; ptr != end; ++ptr)
printf("%02x", *ptr);
puts("");
}
namespace { struct Foo { short i; }; }
template <Foo f> void test1()
{
dump(&f, sizeof(f));
printf("expected: %d\n", f.i);
}
void test2();
int main()
{
test1<Foo{}>();
test2();
}
$ cat test2.cpp
#include <stdio.h>
void dump(const void *data, size_t len);
namespace { struct Foo { int Foo::* i; }; }
template <Foo f> void test2()
{
dump(&f, sizeof(f));
printf("expected: %td\n", f.i);
}
void test2()
{
test2<Foo{}>();
}
$ g++ -O2 -std=c++20 test1.cpp test2.cpp
$ ./a.out
0x402022(2) = 0000
expected: 0
0x402038(8) = ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
expected: -1
$ clang -O2 -std=c++20 test1.cpp test2.cpp
tjmaciei@tjmaciei-mobl5 /tmp $ ./a.out
0x402028(2) = 0000
expected: 0
0x402028(8) = 0000657870656374
expected: -1
The assembly for test2.cpp ends in:
.type _ZTAXtlN12_GLOBAL__N_13FooEEE,@object #
@_ZTAXtlN12_GLOBAL__N_13FooEEE
.section
.rodata._ZTAXtlN12_GLOBAL__N_13FooEEE,"aG",@progbits,_ZTAXtlN12_GLOBAL__N_13FooEEE,comdat
.weak _ZTAXtlN12_GLOBAL__N_13FooEEE
.p2align 3
_ZTAXtlN12_GLOBAL__N_13FooEEE:
.quad -1 # 0xffffffffffffffff
The _ZTA symbol is .weak but exported. Therefore, the <unnamed
namespace>::Foo{} expression in it matches the other Foo expression, thus
making the two symbols get merged by the linker, even though they don't have
the same size or contents.
$ clang --version
clang version 13.0.0
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>