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

Open
#336 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
cpp
Domain
compilers

Research direction

Start by reproducing the diagnostic with test.cpp and the documented cgeist command using --memref-abi=0. Inspect where the generated malloc func.func declaration is created and verify that the declaration has external linkage; done means the example no longer reports the public-visibility error.

Written by the indexing model from the issue text.

Description

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.

Dominant language
C++
Stars
624
Forks
170
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from llvm/Polygeist

All issues in llvm/Polygeist

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.