Skip to content

Commit f3dee5b

Browse files
committed
llvmjit: Also copy parameter / return value attributes from template functions.
Previously we only copied the function attributes. That caused problems at least on s390x: Because we didn't copy the 'zeroext' attribute for ExecAggTransReparent()'s *IsNull parameters, expressions invoking it didn't ensure that the upper bytes of the registers were zeroed. In the - relatively rare - cases where not, ExecAggTransReparent() wrongly ended up in the newValueIsNull branch due to the register not being zero. Subsequently causing a crash. It's quite possible that this would cause problems on other platforms, and in other places than just ExecAggTransReparent() on s390x. Thanks to Christoph (and the Debian project) for providing me with access to a s390x machine, allowing me to debug this. Reported-By: Christoph Berg Author: Andres Freund Discussion: https://postgr.es/m/20201015083246.kie5726xerdt3ael@alap3.anarazel.de Backpatch: 11-, where JIT was added
1 parent 3c4b520 commit f3dee5b

File tree

1 file changed

+33
-11
lines changed

1 file changed

+33
-11
lines changed

src/backend/jit/llvm/llvmjit.c

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -327,26 +327,48 @@ llvm_get_decl(LLVMModuleRef mod, LLVMValueRef v_src)
327327
}
328328

329329
/*
330-
* Copy attributes from one function to another.
330+
* Copy attributes from one function to another, for a specific index (an
331+
* index can reference return value, function and parameter attributes).
331332
*/
332-
void
333-
llvm_copy_attributes(LLVMValueRef v_from, LLVMValueRef v_to)
333+
static void
334+
llvm_copy_attributes_at_index(LLVMValueRef v_from, LLVMValueRef v_to, uint32 index)
334335
{
335336
int num_attributes;
336-
int attno;
337337
LLVMAttributeRef *attrs;
338+
int attno;
338339

339-
num_attributes =
340-
LLVMGetAttributeCountAtIndex(v_from, LLVMAttributeFunctionIndex);
340+
num_attributes = LLVMGetAttributeCountAtIndex(v_from, index);
341341

342342
attrs = palloc(sizeof(LLVMAttributeRef) * num_attributes);
343-
LLVMGetAttributesAtIndex(v_from, LLVMAttributeFunctionIndex, attrs);
343+
LLVMGetAttributesAtIndex(v_from, index, attrs);
344344

345345
for (attno = 0; attno < num_attributes; attno++)
346-
{
347-
LLVMAddAttributeAtIndex(v_to, LLVMAttributeFunctionIndex,
348-
attrs[attno]);
349-
}
346+
LLVMAddAttributeAtIndex(v_to, index, attrs[attno]);
347+
348+
pfree(attrs);
349+
}
350+
351+
/*
352+
* Copy all attributes from one function to another. I.e. function, return and
353+
* parameters will be copied.
354+
*/
355+
void
356+
llvm_copy_attributes(LLVMValueRef v_from, LLVMValueRef v_to)
357+
{
358+
uint32 param_count;
359+
int paramidx;
360+
361+
/* copy function attributes */
362+
llvm_copy_attributes_at_index(v_from, v_to, LLVMAttributeFunctionIndex);
363+
364+
/* and the return value attributes */
365+
llvm_copy_attributes_at_index(v_from, v_to, LLVMAttributeReturnIndex);
366+
367+
/* and each function parameter's attribute */
368+
param_count = LLVMCountParams(v_from);
369+
370+
for (paramidx = 1; paramidx <= param_count; paramidx++)
371+
llvm_copy_attributes_at_index(v_from, v_to, paramidx);
350372
}
351373

352374
/*

0 commit comments

Comments
 (0)