Skip to content

Commit 0a9b9e6

Browse files
committed
Merging r345838:
------------------------------------------------------------------------ r345838 | erichkeane | 2018-11-01 08:11:41 -0700 (Thu, 01 Nov 2018) | 8 lines CPU-Dispatch- Fix type of a member function, prevent deferrals The member type creation for a cpu-dispatch function was not correctly including the 'this' parameter, so ensure that the type is properly determined. Also, disable defer in the cases of emitting the functoins, as it can end up resulting in the wrong version being emitted. Change-Id: I0b8fc5e0b0d1ae1a9d98fd54f35f27f6e5d5d083 ------------------------------------------------------------------------ llvm-svn: 348684
1 parent 5a9000b commit 0a9b9e6

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2467,7 +2467,13 @@ void CodeGenModule::emitCPUDispatchDefinition(GlobalDecl GD) {
24672467
assert(FD && "Not a FunctionDecl?");
24682468
const auto *DD = FD->getAttr<CPUDispatchAttr>();
24692469
assert(DD && "Not a cpu_dispatch Function?");
2470-
llvm::Type *DeclTy = getTypes().ConvertTypeForMem(FD->getType());
2470+
QualType CanonTy = Context.getCanonicalType(FD->getType());
2471+
llvm::Type *DeclTy = getTypes().ConvertFunctionType(CanonTy, FD);
2472+
2473+
if (const auto *CXXFD = dyn_cast<CXXMethodDecl>(FD)) {
2474+
const CGFunctionInfo &FInfo = getTypes().arrangeCXXMethodDeclaration(CXXFD);
2475+
DeclTy = getTypes().GetFunctionType(FInfo);
2476+
}
24712477

24722478
StringRef ResolverName = getMangledName(GD);
24732479
llvm::Type *ResolverType = llvm::FunctionType::get(
@@ -2485,7 +2491,7 @@ void CodeGenModule::emitCPUDispatchDefinition(GlobalDecl GD) {
24852491
std::string MangledName = getMangledNameImpl(*this, GD, FD, true) +
24862492
getCPUSpecificMangling(*this, II->getName());
24872493
llvm::Constant *Func = GetOrCreateLLVMFunction(
2488-
MangledName, DeclTy, GD, /*ForVTable=*/false, /*DontDefer=*/false,
2494+
MangledName, DeclTy, GD, /*ForVTable=*/false, /*DontDefer=*/true,
24892495
/*IsThunk=*/false, llvm::AttributeList(), ForDefinition);
24902496
llvm::SmallVector<StringRef, 32> Features;
24912497
Target.getCPUSpecificCPUDispatchFeatures(II->getName(), Features);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,LINUX
2+
3+
struct S {
4+
__attribute__((cpu_specific(atom)))
5+
void Func(){}
6+
__attribute__((cpu_dispatch(ivybridge,atom)))
7+
void Func(){}
8+
};
9+
10+
void foo() {
11+
S s;
12+
s.Func();
13+
}
14+
15+
// LINUX: define void (%struct.S*)* @_ZN1S4FuncEv.resolver
16+
// LINUX: ret void (%struct.S*)* @_ZN1S4FuncEv.S
17+
// LINUX: ret void (%struct.S*)* @_ZN1S4FuncEv.O

0 commit comments

Comments
 (0)