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

Commit c8a2bb0

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 f915453 commit c8a2bb0

File tree

1 file changed

+32
-12
lines changed

1 file changed

+32
-12
lines changed

src/backend/jit/llvm/llvmjit.c

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -330,26 +330,46 @@ llvm_get_decl(LLVMModuleRef mod, LLVMValueRef v_src)
330330
}
331331

332332
/*
333-
* Copy attributes from one function to another.
333+
* Copy attributes from one function to another, for a specific index (an
334+
* index can reference return value, function and parameter attributes).
334335
*/
335-
void
336-
llvm_copy_attributes(LLVMValueRef v_from, LLVMValueRef v_to)
336+
static void
337+
llvm_copy_attributes_at_index(LLVMValueRef v_from, LLVMValueRef v_to, uint32 index)
337338
{
338339
int num_attributes;
339-
int attno;
340340
LLVMAttributeRef *attrs;
341341

342-
num_attributes =
343-
LLVMGetAttributeCountAtIndex(v_from, LLVMAttributeFunctionIndex);
342+
num_attributes = LLVMGetAttributeCountAtIndex(v_from, index);
344343

345344
attrs = palloc(sizeof(LLVMAttributeRef) * num_attributes);
346-
LLVMGetAttributesAtIndex(v_from, LLVMAttributeFunctionIndex, attrs);
345+
LLVMGetAttributesAtIndex(v_from, index, attrs);
347346

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

355375
/*

0 commit comments

Comments
 (0)