Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Mangled names for unnamed local types declared in block expressions in non-static data member initializers lack discriminators #33483

Open Quuxplusone opened 7 years ago

Quuxplusone commented 7 years ago
Bugzilla Link PR34511
Status NEW
Importance P normal
Reported by Tom Honermann (thonerma@synopsys.com)
Reported on 2017-09-06 13:50:31 -0700
Last modified on 2017-09-07 00:33:58 -0700
Version 4.0
Hardware All All
CC dgregor@apple.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk, sig-rnd-sat-clang-bugs@synopsys.com
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
Mangled names for unnamed local types declared in block expressions in non-
static data member initializers lack discriminators:

$ cat t.cpp
template<typename T> void tf(T) {}
struct S {
  void(^bp)() = ^{
    enum {} e;
    tf(e);
    struct {} s1;
    tf(s1);
    struct {} s2;
    tf(s2);
  };
};
auto x = S{}.bp;

$ clang++ --version
clang version 4.0.0 (tags/RELEASE_400/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix

$ clang++ -c -std=c++11 -fblocks t.cpp
t.cpp:1:27: error: definition with same mangled name as another definition
template<typename T> void tf(T) {}
                          ^
t.cpp:1:27: note: previous definition is here
t.cpp:1:27: error: definition with same mangled name as another definition
template<typename T> void tf(T) {}
                          ^
t.cpp:1:27: note: previous definition is here
2 errors generated.

Reducing the function template from a definition to a declaration reveals the
conflicting name:

$ cat t2.cpp
template<typename T> void tf(T);
struct S {
  void(^bp)() = ^{
    enum {} e;
    tf(e);
    struct {} s1;
    tf(s1);
    struct {} s2;
    tf(s2);
  };
};
auto x = S{}.bp;

$ clang++ -c -std=c++11 -fblocks t2.cpp
$ nm t2.o
                 U _NSConcreteGlobalBlock
                 U _Z2tfIZ1S2bpMUb0_EUt_EvT_
0000000000000000 r __block_descriptor_tmp
0000000000000020 r __block_literal_global
0000000000000000 D x
0000000000000000 t x_block_invoke

The single symbol ('_Z2tfIZ1S2bpMUb0_EUt_EvT_') emitted for the function
template instantiations reveals that each of the unnamed types were given the
same name: 'Z1S2bpMUb0_EUt_'.  This name is strange in that the 'M' production
corresponding to <pointer-to-member-type> from the Itanium ABI [1] matches the
'<class type>' production (with 'Ub0_'), but is missing a match for '<member
type>'; thus the mangled name appears to be ill-formed.

Clearly, there should be three separate symbol references emitted; each
disambiguated by a discriminator on the <unnamed-type-name> ('Ut_') production
within the name.

[1]: http://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangle.pointer-to-member-
type
Quuxplusone commented 7 years ago
(In reply to Tom Honermann from comment #0)
> [...] the 'M' production corresponding to <pointer-to-member-type>
> from the Itanium ABI [...]

(For posterity, after discussion on cfe-dev:) This is the <data-member-prefix>
production, not <pointer-to-member-type>. The first mangled name appears to be
correct, except that its Ub0_ should be simply Ub_, which I fixed in r312700.
The correct manglings would be:

_Z2tfIZ1S2bpMUb_EUt_EvT_ -- tf(e)
_Z2tfIZ1S2bpMUb_EUt0_EvT_ -- tf(s1)
_Z2tfIZ1S2bpMUb_EUt1_EvT_ -- tf(s2)