]> granicus.if.org Git - postgresql/commitdiff
Fix JITed EEOP_AGG_INIT_TRANS, which missed some state.
authorAndres Freund <andres@anarazel.de>
Sun, 22 Jul 2018 23:47:00 +0000 (16:47 -0700)
committerAndres Freund <andres@anarazel.de>
Mon, 23 Jul 2018 00:00:41 +0000 (17:00 -0700)
The JIT compiled implementation missed maintaining
AggState->{current_set,curaggcontext}. That could lead to trouble
because the transition value could be allocated in the wrong context.

Reported-By: Rushabh Lathia
Diagnosed-By: Dmitry Dolgov
Author: Dmitry Dolgov, with minor changes by me
Discussion: https://postgr.es/m/CAGPqQf165-=+Drw3Voim7M5EjHT1zwPF9BQRjLFQzCzYnNZEiQ@mail.gmail.com
Backpatch: 11-, where JIT compilation support was added

src/backend/jit/llvm/llvmjit_expr.c

index 36c5f7d500e889164d60172aca02d11c8e7955b8..31b03212751b3f0ec30a2d3b41049e5c9ce5f8f9 100644 (file)
@@ -2228,6 +2228,28 @@ llvm_compile_expr(ExprState *state)
 
                                        {
                                                LLVMValueRef params[3];
+                                               LLVMValueRef v_curaggcontext;
+                                               LLVMValueRef v_current_set;
+                                               LLVMValueRef v_aggcontext;
+
+                                               v_aggcontext = l_ptr_const(op->d.agg_init_trans.aggcontext,
+                                                                                                  l_ptr(StructExprContext));
+
+                                               v_current_set =
+                                                       LLVMBuildStructGEP(b,
+                                                                                          v_aggstatep,
+                                                                                          FIELDNO_AGGSTATE_CURRENT_SET,
+                                                                                          "aggstate.current_set");
+                                               v_curaggcontext =
+                                                       LLVMBuildStructGEP(b,
+                                                                                          v_aggstatep,
+                                                                                          FIELDNO_AGGSTATE_CURAGGCONTEXT,
+                                                                                          "aggstate.curaggcontext");
+
+                                               LLVMBuildStore(b, l_int32_const(op->d.agg_init_trans.setno),
+                                                                          v_current_set);
+                                               LLVMBuildStore(b, v_aggcontext,
+                                                                          v_curaggcontext);
 
                                                params[0] = v_aggstatep;
                                                params[1] = v_pertransp;