-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[clang][CodeGen] sret
args should always point to the alloca
AS, so use that
#114062
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
d2d2d3d
693253d
b5a7df0
f6cff66
2de33d4
6d9cb89
b209d67
ac6367b
c8f03e7
24d8edb
5ccd554
9ff1d0d
1c3e67c
c9288fc
99e03a2
013790c
c4bdeab
5afb40e
d07d63d
eeb54e4
6c0ef88
abab201
6e78db1
7d45638
f16d1d9
0277516
056c9ec
207a2ae
d8bd7ab
f6c8e01
0f724f8
7158b8d
8f472f3
2bdb085
99101fb
86093c2
4b47cd7
d103255
e325239
27ef889
260e96d
5227aef
94b51d5
53d8462
4d2b9f7
d9595fc
3acc4ff
69b7937
ddaccb8
f442024
939af07
05f0701
3e10da3
0867735
553ac57
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1672,8 +1672,7 @@ CodeGenTypes::GetFunctionType(const CGFunctionInfo &FI) { | |
|
||
// Add type for sret argument. | ||
if (IRFunctionArgs.hasSRetArg()) { | ||
QualType Ret = FI.getReturnType(); | ||
unsigned AddressSpace = CGM.getTypes().getTargetAddressSpace(Ret); | ||
unsigned AddressSpace = CGM.getDataLayout().getAllocaAddrSpace(); | ||
ArgTypes[IRFunctionArgs.getSRetArgNo()] = | ||
llvm::PointerType::get(getLLVMContext(), AddressSpace); | ||
} | ||
|
@@ -5145,7 +5144,6 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo, | |
// If the call returns a temporary with struct return, create a temporary | ||
// alloca to hold the result, unless one is given to us. | ||
Address SRetPtr = Address::invalid(); | ||
RawAddress SRetAlloca = RawAddress::invalid(); | ||
llvm::Value *UnusedReturnSizePtr = nullptr; | ||
if (RetAI.isIndirect() || RetAI.isInAlloca() || RetAI.isCoerceAndExpand()) { | ||
// For virtual function pointer thunks and musttail calls, we must always | ||
|
@@ -5159,16 +5157,19 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo, | |
} else if (!ReturnValue.isNull()) { | ||
SRetPtr = ReturnValue.getAddress(); | ||
} else { | ||
SRetPtr = CreateMemTemp(RetTy, "tmp", &SRetAlloca); | ||
SRetPtr = CreateMemTempWithoutCast(RetTy, "tmp"); | ||
if (HaveInsertPoint() && ReturnValue.isUnused()) { | ||
llvm::TypeSize size = | ||
CGM.getDataLayout().getTypeAllocSize(ConvertTypeForMem(RetTy)); | ||
UnusedReturnSizePtr = EmitLifetimeStart(size, SRetAlloca.getPointer()); | ||
UnusedReturnSizePtr = EmitLifetimeStart(size, SRetPtr.getBasePointer()); | ||
} | ||
} | ||
if (IRFunctionArgs.hasSRetArg()) { | ||
// If the caller allocated the return slot, it is possible that the | ||
// alloca was AS casted to the default as, so we ensure the cast is | ||
// stripped before binding to the sret arg, which is in the allocaAS. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, what? It seems really wrong to be blindly stripping pointer casts here. Can you explain what code pattern is leading to us not having a pointer in the right address space? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not really blind (albeit it might be somewhat tightly coupling |
||
IRCallArgs[IRFunctionArgs.getSRetArgNo()] = | ||
getAsNaturalPointerTo(SRetPtr, RetTy); | ||
getAsNaturalPointerTo(SRetPtr, RetTy)->stripPointerCasts(); | ||
} else if (RetAI.isInAlloca()) { | ||
Address Addr = | ||
Builder.CreateStructGEP(ArgMemory, RetAI.getInAllocaFieldIndex()); | ||
|
@@ -5740,7 +5741,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo, | |
// pop this cleanup later on. Being eager about this is OK, since this | ||
// temporary is 'invisible' outside of the callee. | ||
if (UnusedReturnSizePtr) | ||
pushFullExprCleanup<CallLifetimeEnd>(NormalEHLifetimeMarker, SRetAlloca, | ||
pushFullExprCleanup<CallLifetimeEnd>(NormalEHLifetimeMarker, SRetPtr, | ||
UnusedReturnSizePtr); | ||
|
||
llvm::BasicBlock *InvokeDest = CannotThrow ? nullptr : getInvokeDest(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,34 @@ | ||
// RUN: %clang_cc1 %s -Wno-strict-prototypes -emit-llvm -o - | FileCheck %s | ||
// RUN: %clang_cc1 %s -Wno-strict-prototypes -triple amdgcn-amd-amdhsa -emit-llvm -o - | FileCheck --check-prefix=NONZEROALLOCAAS %s | ||
|
||
struct abc { | ||
long a; | ||
long b; | ||
long c; | ||
long d; | ||
long e; | ||
long f; | ||
long g; | ||
long h; | ||
long i; | ||
long j; | ||
}; | ||
|
||
struct abc foo1(void); | ||
// CHECK-DAG: declare {{.*}} @foo1(ptr dead_on_unwind writable sret(%struct.abc) | ||
// NONZEROALLOCAAS-DAG: declare {{.*}} @foo1(ptr addrspace(5) dead_on_unwind writable sret(%struct.abc) | ||
struct abc foo2(); | ||
// CHECK-DAG: declare {{.*}} @foo2(ptr dead_on_unwind writable sret(%struct.abc) | ||
// NONZEROALLOCAAS-DAG: declare {{.*}} @foo2(ptr addrspace(5) dead_on_unwind writable sret(%struct.abc) | ||
struct abc foo3(void){} | ||
// CHECK-DAG: define {{.*}} @foo3(ptr dead_on_unwind noalias writable sret(%struct.abc) | ||
// NONZEROALLOCAAS-DAG: define {{.*}} @foo3(ptr addrspace(5) dead_on_unwind noalias writable sret(%struct.abc) | ||
|
||
void bar(void) { | ||
struct abc dummy1 = foo1(); | ||
// CHECK-DAG: call {{.*}} @foo1(ptr dead_on_unwind writable sret(%struct.abc) | ||
// NONZEROALLOCAAS-DAG: call {{.*}} @foo1(ptr addrspace(5) dead_on_unwind writable sret(%struct.abc) | ||
struct abc dummy2 = foo2(); | ||
// CHECK-DAG: call {{.*}} @foo2(ptr dead_on_unwind writable sret(%struct.abc) | ||
// NONZEROALLOCAAS-DAG: call {{.*}} @foo2(ptr addrspace(5) dead_on_unwind writable sret(%struct.abc) | ||
} |
Uh oh!
There was an error while loading. Please reload this page.