llvm-project/clang/test/CodeGenCXX/ms-local-vft-alias-comdat.cpp
jyu2-git 10cc3a8556
[MS-ABI] skip generate comdat for vftable defined with internal alias. (#71748)
We got a error:
`LLVM ERROR: Associative COMDAT symbol '??_7?$T@V<lambda_0>@@@@6B@' is
not a key for its COMDAT`

Current we create internal alias for vftable when lambd is used.
For the test, IR generate:
```
 $"??_7?$T@V<lambda_0>@@$0A@@@6b@" = comdat any

@0 = private unnamed_addr constant { [2 x ptr] } { [2 x ptr] [ptr @"??_R4?$T@V<lambda_0>@@$0A@@@6b@", ptr @"?c@b@@UEAAXXZ"] }, comdat($"??_7?$T@V<lambda_0>@@$0A@@@6b@")

@"??_7?$T@V<lambda_0>@@$0A@@@6b@" = internal unnamed_addr alias ptr, getelementptr inbounds ({ [2 x ptr] }, ptr @0, i32 0, i32 0, i32 1)
```

According LLVM language reference manual section on COMDATs:
There are some restrictions on the properties of the global object. It,
or an alias to it, must have the same name as the COMDAT group when
targeting COFF. The contents and size of this object may be used during
link-time to determine which COMDAT groups get selected depending on the
selection kind. Because the name of the object must match the name of
the
COMDAT group, the linkage of the global object must not be local; local
symbols can get renamed if a collision occurs in the symbol table.

So one way to fix this is to not create comdat for the alias.

@0 = private unnamed_addr constant { [2 x ptr] } { [2 x ptr] [ptr
@"??_R4?$T@V<lambda_0>@@@@6B@", ptr @"?c@?$T@V<lambda_0>@@@@UEAAXXZ"] }
2023-11-15 17:39:54 -08:00

31 lines
883 B
C++

// RUN: %clang_cc1 -fcxx-exceptions -triple=x86_64-windows-msvc \
// RUN: -Wmicrosoft-template -fms-compatibility -emit-llvm %s -o - \
// RUN: | FileCheck %s
template <typename a> struct T {
virtual void c();
T(a h) {}
};
struct m {
template <typename j> void ab(j ac) {
using ad = T<j>;
ad j(ac);
}
};
template <typename ae> struct n {
template <typename j> n(j ac) { q.ab(ac); }
ae q;
};
class s : n<m> {
using ag = n<m>;
public:
template <typename j> s(j ac) : ag(ac) {}
};
struct ah {
ah(s);
} a([]{});
//CHECK: @0 = private unnamed_addr constant { [2 x ptr] } { [2 x ptr] [ptr @"??_R4?$T@V<lambda_0>@@@@6B@", ptr @"?c@?$T@V<lambda_0>@@@@UEAAXXZ"] }
//CHECK: @"??_7?$T@V<lambda_0>@@@@6B@" = internal unnamed_addr alias ptr, getelementptr inbounds ({ [2 x ptr] }, ptr @0, i32 0, i32 0, i32 1)
//CHECK-NOT : "??_7?$e@V<lambda_0>@@@@6B@" = comdat any