Polygeist icon indicating copy to clipboard operation
Polygeist copied to clipboard

"op symbol declaration cannot have public visibility" when using "new" keyword

Open yar-sh opened this issue 2 years ago • 0 comments

I am using this commit: https://github.com/llvm/Polygeist/commit/a27def31a2b0742308e7c8db4c0f40a37727269a to transform C++ code to MLIR. I run into issues when using the new keyword with --memref-abi=0.

With this simple C++ code (test.cpp):

int main()
{
    int* arr = new int[5];
    return arr[0];
}

I am executing the command cgeist test.cpp --resource-dir="$(clang++ -print-resource-dir)" --function=* -S --memref-abi=0. It results in the following output:

full output
error: 'func.func' op symbol declaration cannot have public visibility
"builtin.module"() ({
  "func.func"() ({
  }) {function_type = (i64) -> memref<?xi8>, sym_name = "malloc"} : () -> ()
  "func.func"() ({
    %0 = "arith.constant"() {value = 20 : index} : () -> index
    %1 = "func.call"(%0) {callee = @malloc} : (index) -> memref<?xi8>
    %2 = "llvm.bitcast"(%1) : (memref<?xi8>) -> !llvm.ptr<i32>
    %3 = "llvm.load"(%2) : (!llvm.ptr<i32>) -> i32
    "func.return"(%3) : (i32) -> ()
  }) {function_type = () -> i32, llvm.linkage = #llvm.linkage<external>, sym_name = "main"} : () -> ()
}) {dlti.dl_spec = #dlti.dl_spec<#dlti.dl_entry<"dlti.endianness", "little">, #dlti.dl_entry<i64, dense<64> : vector<2xi32>>, #dlti.dl_entry<f80, dense<128> : vector<2xi32>>, #dlti.dl_entry<i1, dense<8> : vector<2xi32>>, #dlti.dl_entry<i8, dense<8> : vector<2xi32>>, #dlti.dl_entry<i16, dense<16> : vector<2xi32>>, #dlti.dl_entry<i32, dense<32> : vector<2xi32>>, #dlti.dl_entry<f16, dense<16> : vector<2xi32>>, #dlti.dl_entry<f64, dense<64> : vector<2xi32>>, #dlti.dl_entry<f128, dense<128> : vector<2xi32>>>, llvm.data_layout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128", llvm.target_triple = "x86_64-unknown-linux-gnu", "polygeist.target-cpu" = "broadwell", "polygeist.target-features" = "+64bit,+adx,+aes,+avx,+avx2,+bmi,+bmi2,+cmov,+crc32,+cx16,+cx8,+f16c,+fma,+fsgsbase,+fxsr,+invpcid,+lzcnt,+mmx,+movbe,+pclmul,+popcnt,+prfchw,+rdrnd,+rdseed,+rtm,+sahf,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave,+xsaveopt,-amx-bf16,-amx-fp16,-amx-int8,-amx-tile,-avx512bf16,-avx512bitalg,-avx512bw,-avx512cd,-avx512dq,-avx512er,-avx512f,-avx512fp16,-avx512ifma,-avx512pf,-avx512vbmi,-avx512vbmi2,-avx512vl,-avx512vnni,-avx512vp2intersect,-avx512vpopcntdq,-avxvnni,-cldemote,-clflushopt,-clwb,-clzero,-enqcmd,-fma4,-gfni,-hreset,-kl,-lwp,-movdir64b,-movdiri,-mwaitx,-pconfig,-pku,-prefetchi,-prefetchwt1,-ptwrite,-rdpid,-rdpru,-serialize,-sgx,-sha,-shstk,-sse4a,-tbm,-tsxldtrk,-uintr,-vaes,-vpclmulqdq,-waitpkg,-wbnoinvd,-widekl,-xop,-xsavec,-xsaves"} : () -> ()

There is an error about the declaration of the malloc function. It seems that the issue is that it is missing the external linkage.

yar-sh avatar Apr 11 '23 13:04 yar-sh