[PATCH] D65470: [WebAssembly] Fix allocsize attribute in sjlj lowering
Keno Fischer via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 30 12:19:01 PDT 2019
loladiro created this revision.
loladiro added reviewers: kripken, sbc100.
Herald added subscribers: llvm-commits, sunfish, aheejin, hiraditya, jgravelle-google, dschuff.
Herald added a project: LLVM.
The allocsize attribute refers to call parameters by index.
Thus, when we add the extra parameter in sjlj lowering, we
need to increment the referenced paramater in the allocsize
attribute to avoid angering the Verifier.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D65470
Files:
llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
llvm/test/CodeGen/WebAssembly/lower-em-sjlj.ll
Index: llvm/test/CodeGen/WebAssembly/lower-em-sjlj.ll
===================================================================
--- llvm/test/CodeGen/WebAssembly/lower-em-sjlj.ll
+++ llvm/test/CodeGen/WebAssembly/lower-em-sjlj.ll
@@ -94,7 +94,7 @@
}
; Test a case when a function call is within try-catch, after a setjmp
-define hidden void @exception_and_longjmp() #3 personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
+define hidden void @exception_and_longjmp() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
; CHECK-LABEL: @exception_and_longjmp
entry:
%buf = alloca [1 x %struct.__jmp_buf_tag], align 16
@@ -203,6 +203,19 @@
ret void
}
+; Test that the allocsize attribute is being transformed properly
+declare void @allocator(i32, %struct.__jmp_buf_tag*) #3
+define hidden void @allocsize() {
+; CHECK-LABEL: @allocsize
+entry:
+ %buf = alloca [1 x %struct.__jmp_buf_tag], align 16
+ %arraydecay = getelementptr inbounds [1 x %struct.__jmp_buf_tag], [1 x %struct.__jmp_buf_tag]* %buf, i32 0, i32 0
+ %call = call i32 @setjmp(%struct.__jmp_buf_tag* %arraydecay) #0
+; CHECK: void @"__invoke_void_i32_%struct.__jmp_buf_tag*"([[ARGS:.*]]) #[[ALLOCSIZE_ATTR:[0-9]+]]
+ call void @allocator(i32 20, %struct.__jmp_buf_tag* %arraydecay) #3
+ ret void
+}
+
declare void @foo()
; Function Attrs: returns_twice
declare i32 @setjmp(%struct.__jmp_buf_tag*) #0
@@ -227,3 +240,5 @@
attributes #0 = { returns_twice }
attributes #1 = { noreturn }
attributes #2 = { nounwind }
+attributes #3 = { allocsize(0) }
+; CHECK: attributes #[[ALLOCSIZE_ATTR]] = { allocsize(1) }
Index: llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
===================================================================
--- llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
@@ -432,9 +432,22 @@
for (unsigned I = 0, E = CI->getNumArgOperands(); I < E; ++I)
ArgAttributes.push_back(InvokeAL.getParamAttributes(I));
+ AttrBuilder FnAttrs(InvokeAL.getFnAttributes());
+ if (FnAttrs.contains(Attribute::AllocSize)) {
+ // The allocsize attribute (if any) referes to parameters by index and needs
+ // to be adjusted.
+ unsigned SizeArg;
+ Optional<unsigned> NEltArg;
+ std::tie(SizeArg, NEltArg) = FnAttrs.getAllocSizeArgs();
+ SizeArg += 1;
+ if (NEltArg.hasValue())
+ NEltArg = NEltArg.getValue() + 1;
+ FnAttrs.addAllocSizeAttr(SizeArg, NEltArg);
+ }
+
// Reconstruct the AttributesList based on the vector we constructed.
AttributeList NewCallAL =
- AttributeList::get(C, InvokeAL.getFnAttributes(),
+ AttributeList::get(C, AttributeSet::get(C, FnAttrs),
InvokeAL.getRetAttributes(), ArgAttributes);
NewCall->setAttributes(NewCallAL);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65470.212409.patch
Type: text/x-patch
Size: 2847 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190730/8be3fbeb/attachment.bin>
More information about the llvm-commits
mailing list