Thread: BUG #17927: Postgres does not compile with LLVM-16

BUG #17927: Postgres does not compile with LLVM-16

From
PG Bug reporting form
Date:
The following bug has been logged on the website:

Bug reference:      17927
Logged by:          RekGRpth
Email address:      rekgrpth@gmail.com
PostgreSQL version: 15.2
Operating system:   alpine in docker
Description:

cc1plus: warning: '-Werror=' argument
'-Werror=implicit-function-declaration' is not valid for C++
In file included from llvmjit.c:17:
../../../../src/include/jit/llvmjit_emit.h: In function
'l_load_struct_gep':
../../../../src/include/jit/llvmjit_emit.h:112:30: error: implicit
declaration of function 'LLVMBuildStructGEP'; did you mean
'LLVMBuildStructGEP2'? [-Werror=implicit-function-declaration]
  112 |         LLVMValueRef v_ptr = LLVMBuildStructGEP(b, v, idx, "");
      |                              ^~~~~~~~~~~~~~~~~~
      |                              LLVMBuildStructGEP2
../../../../src/include/jit/llvmjit_emit.h:112:30: warning: initialization
of 'LLVMValueRef' {aka 'struct LLVMOpaqueValue *'} from 'int' makes pointer
from integer without a cast [-Wint-conversion]
../../../../src/include/jit/llvmjit_emit.h:114:16: error: implicit
declaration of function 'LLVMBuildLoad'; did you mean 'LLVMBuildLoad2'?
[-Werror=implicit-function-declaration]
  114 |         return LLVMBuildLoad(b, v_ptr, name);
      |                ^~~~~~~~~~~~~
      |                LLVMBuildLoad2
../../../../src/include/jit/llvmjit_emit.h:114:16: warning: returning 'int'
from a function with return type 'LLVMValueRef' {aka 'struct LLVMOpaqueValue
*'} makes pointer from integer without a cast [-Wint-conversion]
  114 |         return LLVMBuildLoad(b, v_ptr, name);
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../../../src/include/jit/llvmjit_emit.h: In function 'l_load_gep1':
../../../../src/include/jit/llvmjit_emit.h:123:30: error: implicit
declaration of function 'LLVMBuildGEP'; did you mean 'LLVMBuildGEP2'?
[-Werror=implicit-function-declaration]
  123 |         LLVMValueRef v_ptr = LLVMBuildGEP(b, v, &idx, 1, "");
      |                              ^~~~~~~~~~~~
      |                              LLVMBuildGEP2
../../../../src/include/jit/llvmjit_emit.h:123:30: warning: initialization
of 'LLVMValueRef' {aka 'struct LLVMOpaqueValue *'} from 'int' makes pointer
from integer without a cast [-Wint-conversion]
../../../../src/include/jit/llvmjit_emit.h:125:16: warning: returning 'int'
from a function with return type 'LLVMValueRef' {aka 'struct LLVMOpaqueValue
*'} makes pointer from integer without a cast [-Wint-conversion]
  125 |         return LLVMBuildLoad(b, v_ptr, name);
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../../../src/include/jit/llvmjit_emit.h: In function 'l_mcxt_switch':
../../../../src/include/jit/llvmjit_emit.h:213:13: warning: assignment to
'LLVMValueRef' {aka 'struct LLVMOpaqueValue *'} from 'int' makes pointer
from integer without a cast [-Wint-conversion]
  213 |         ret = LLVMBuildLoad(b, cur, cmc);
      |             ^
g++ -Wall -Wpointer-arith -Wendif-labels -Wmissing-format-attribute
-Wformat-security -fno-strict-aliasing -fwrapv -fno-omit-frame-pointer
-Werror-implicit-function-declaration -std=c++17 -fPIC -D__STDC_LIMIT_MACROS
-D__STDC_FORMAT_MACROS -D__STDC_CONSTANT_MACROS -I/usr/lib/llvm16/include
-I../../../../src/include  -D_GNU_SOURCE -I/usr/include/libxml2
-I/usr/local/include  -c -o llvmjit_inline.o llvmjit_inline.cpp
cc1plus: warning: '-Werror=' argument
'-Werror=implicit-function-declaration' is not valid for C++
llvmjit.c: In function 'llvm_function_reference':
llvmjit.c:496:32: warning: returning 'int' from a function with return type
'LLVMValueRef' {aka 'struct LLVMOpaqueValue *'} makes pointer from integer
without a cast [-Wint-conversion]
  496 |                         return LLVMBuildLoad(builder, v_fn, "");
      |                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
llvmjit.c:506:24: warning: returning 'int' from a function with return type
'LLVMValueRef' {aka 'struct LLVMOpaqueValue *'} makes pointer from integer
without a cast [-Wint-conversion]
  506 |                 return LLVMBuildLoad(builder, v_fn, "");
      |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
make[1]: *** [<builtin>: llvmjit.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make[1]: Leaving directory
'/var/lib/postgresql/src/postgres/src/backend/jit/llvm'
make: *** [Makefile:42: install-backend/jit/llvm-recurse] Error 2


Re: BUG #17927: Postgres does not compile with LLVM-16

From
Daniel Gustafsson
Date:
> On 10 May 2023, at 12:10, PG Bug reporting form <noreply@postgresql.org> wrote:

Thanks for your report!

> llvmjit.c:506:24: warning: returning 'int' from a function with return type
> 'LLVMValueRef' {aka 'struct LLVMOpaqueValue *'} makes pointer from integer
> without a cast [-Wint-conversion]
>  506 |                 return LLVMBuildLoad(builder, v_fn, "");
>      |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This is a known problem which is currently being worked on.  LLVM 16 deprecated
typed pointers which the postgres JIT implementation is using, switching over
to opaque pointers is no simple task though.

--
Daniel Gustafsson