Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 7255943

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 a97e85f commit 7255943

File tree

1 file changed

+32
-12
lines changed

1 file changed

+32
-12
lines changed

src/backend/jit/llvm/llvmjit.c

+32-12
Original file line numberDiff line numberDiff line change
@@ -324,26 +324,46 @@ llvm_pg_func(LLVMModuleRef mod, const char *funcname)
324324
}
325325

326326
/*
327-
* Copy attributes from one function to another.
327+
* Copy attributes from one function to another, for a specific index (an
328+
* index can reference return value, function and parameter attributes).
328329
*/
329-
void
330-
llvm_copy_attributes(LLVMValueRef v_from, LLVMValueRef v_to)
330+
static void
331+
llvm_copy_attributes_at_index(LLVMValueRef v_from, LLVMValueRef v_to, uint32 index)
331332
{
332333
int num_attributes;
333-
int attno;
334334
LLVMAttributeRef *attrs;
335335

336-
num_attributes =
337-
LLVMGetAttributeCountAtIndex(v_from, LLVMAttributeFunctionIndex);
336+
num_attributes = LLVMGetAttributeCountAtIndex(v_from, index);
338337

339338
attrs = palloc(sizeof(LLVMAttributeRef) * num_attributes);
340-
LLVMGetAttributesAtIndex(v_from, LLVMAttributeFunctionIndex, attrs);
339+
LLVMGetAttributesAtIndex(v_from, index, attrs);
341340

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

349369
/*

0 commit comments

Comments
 (0)