Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ThroughMLIR] Cannot lower function with pointer arguments #658

Open
SchrodingerZhu opened this issue Jun 4, 2024 · 1 comment
Open

Comments

@SchrodingerZhu
Copy link
Contributor

echo "void test(int *){}" |  ./bin/clang -xc++ - -Xclang -triple -Xclang x86_64-unknown-linux-gnu -fclangir-S -Xclang -fno-clangir-direct-lowering -Xclang -emit-mlir -o -

The above command will fail with

loc(fused["<stdin>":1:1, "<stdin>":1:18]): error: failed to legalize operation 'cir.func' that was explicitly marked illegal
fatal error: error in backend: The pass manager failed to lower CIR to LLVMIR dialect!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: ./bin/clang -xc++ - -Xclang -triple -Xclang x86_64-unknown-linux-gnu -fclangir -S -Xclang -fno-clangir-direct-lowering -Xclang -emit-mlir -o -
1.      <eof> parser at end of file
 #0 0x00005fd5d65183c9 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/yifzhu/Documents/clangir/llvm/lib/Support/Unix/Signals.inc:723:11
 #1 0x00005fd5d651887b PrintStackTraceSignalHandler(void*) /home/yifzhu/Documents/clangir/llvm/lib/Support/Unix/Signals.inc:798:1
 #2 0x00005fd5d6516ccf llvm::sys::RunSignalHandlers() /home/yifzhu/Documents/clangir/llvm/lib/Support/Signals.cpp:105:5
 #3 0x00005fd5d6517da9 llvm::sys::CleanupOnSignal(unsigned long) /home/yifzhu/Documents/clangir/llvm/lib/Support/Unix/Signals.inc:368:1
 #4 0x00005fd5d6443782 (anonymous namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) /home/yifzhu/Documents/clangir/llvm/lib/Support/CrashRecoveryContext.cpp:0:7
 #5 0x00005fd5d64436b7 llvm::CrashRecoveryContext::HandleExit(int) /home/yifzhu/Documents/clangir/llvm/lib/Support/CrashRecoveryContext.cpp:446:3
 #6 0x00005fd5d6512b2f llvm::sys::Process::Exit(int, bool) /home/yifzhu/Documents/clangir/llvm/lib/Support/Process.cpp:115:7
 #7 0x00005fd5d45f7796 (./bin/clang+0x68f7796)
 #8 0x00005fd5d644ca15 llvm::report_fatal_error(llvm::Twine const&, bool) /home/yifzhu/Documents/clangir/llvm/lib/Support/ErrorHandling.cpp:104:5
 #9 0x00005fd5d644c962 /home/yifzhu/Documents/clangir/llvm/lib/Support/ErrorHandling.cpp:83:3
#10 0x00005fd5d8043271 cir::lowerFromCIRToMLIR(mlir::ModuleOp, mlir::MLIRContext*) /home/yifzhu/Documents/clangir/clang/lib/CIR/Lowering/ThroughMLIR/LowerCIRToMLIR.cpp:1398:17
#11 0x00005fd5d7f6a509 cir::CIRGenConsumer::HandleTranslationUnit(clang::ASTContext&) /home/yifzhu/Documents/clangir/clang/lib/CIR/FrontendAction/CIRGenAction.cpp:252:32
#12 0x00005fd5dc7d29d9 clang::ParseAST(clang::Sema&, bool, bool) /home/yifzhu/Documents/clangir/clang/lib/Parse/ParseAST.cpp:183:12
#13 0x00005fd5d79489ea clang::ASTFrontendAction::ExecuteAction() /home/yifzhu/Documents/clangir/clang/lib/Frontend/FrontendAction.cpp:1214:1
#14 0x00005fd5d7f68f4b cir::CIRGenAction::ExecuteAction() /home/yifzhu/Documents/clangir/clang/lib/CIR/FrontendAction/CIRGenAction.cpp:408:5
#15 0x00005fd5d7948442 clang::FrontendAction::Execute() /home/yifzhu/Documents/clangir/clang/lib/Frontend/FrontendAction.cpp:1102:7
#16 0x00005fd5d7866f69 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /home/yifzhu/Documents/clangir/clang/lib/Frontend/CompilerInstance.cpp:1062:23
#17 0x00005fd5d7af785e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /home/yifzhu/Documents/clangir/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:342:8
#18 0x00005fd5d45f6f12 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) /home/yifzhu/Documents/clangir/clang/tools/driver/cc1_main.cpp:232:13
#19 0x00005fd5d45eab2e ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) /home/yifzhu/Documents/clangir/clang/tools/driver/driver.cpp:215:5
#20 0x00005fd5d45eb50d clang_main(int, char**, llvm::ToolContext const&)::$_0::operator()(llvm::SmallVectorImpl<char const*>&) const /home/yifzhu/Documents/clangir/clang/tools/driver/driver.cpp:355:7
#21 0x00005fd5d45eb4dd int llvm::function_ref<int (llvm::SmallVectorImpl<char const*>&)>::callback_fn<clang_main(int, char**, llvm::ToolContext const&)::$_0>(long, llvm::SmallVectorImpl<char const*>&) /home/yifzhu/Documents/clangir/llvm/include/llvm/ADT/STLFunctionalExtras.h:45:5
#22 0x00005fd5d76fead1 llvm::function_ref<int (llvm::SmallVectorImpl<char const*>&)>::operator()(llvm::SmallVectorImpl<char const*>&) const /home/yifzhu/Documents/clangir/llvm/include/llvm/ADT/STLFunctionalExtras.h:68:5
#23 0x00005fd5d76facf8 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::__1::optional<llvm::StringRef>>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>*, bool*) const::$_0::operator()() const /home/yifzhu/Documents/clangir/clang/lib/Driver/Job.cpp:440:34
#24 0x00005fd5d76facc5 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::__1::optional<llvm::StringRef>>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>*, bool*) const::$_0>(long) /home/yifzhu/Documents/clangir/llvm/include/llvm/ADT/STLFunctionalExtras.h:45:5
#25 0x00005fd5d5127ff9 llvm::function_ref<void ()>::operator()() const /home/yifzhu/Documents/clangir/llvm/include/llvm/ADT/STLFunctionalExtras.h:68:5
#26 0x00005fd5d644359f llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) /home/yifzhu/Documents/clangir/llvm/lib/Support/CrashRecoveryContext.cpp:427:3
#27 0x00005fd5d76fa973 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::__1::optional<llvm::StringRef>>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>*, bool*) const /home/yifzhu/Documents/clangir/clang/lib/Driver/Job.cpp:440:7
#28 0x00005fd5d769b499 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const /home/yifzhu/Documents/clangir/clang/lib/Driver/Compilation.cpp:199:15
#29 0x00005fd5d769b67c clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::__1::pair<int, clang::driver::Command const*>>&, bool) const /home/yifzhu/Documents/clangir/clang/lib/Driver/Compilation.cpp:253:13
#30 0x00005fd5d76b52b1 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::__1::pair<int, clang::driver::Command const*>>&) /home/yifzhu/Documents/clangir/clang/lib/Driver/Driver.cpp:1927:7
#31 0x00005fd5d45ea643 clang_main(int, char**, llvm::ToolContext const&) /home/yifzhu/Documents/clangir/clang/tools/driver/driver.cpp:391:9
#32 0x00005fd5d4618c95 main /home/yifzhu/Documents/clangir/build/tools/clang/tools/driver/clang-driver.cpp:17:3
#33 0x00007962cb029d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#34 0x00007962cb029e40 call_init ./csu/../csu/libc-start.c:128:20
#35 0x00007962cb029e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#36 0x00005fd5d45e9425 _start (./bin/clang+0x68e9425)
@SchrodingerZhu
Copy link
Contributor Author

The CIR looks like


!s32i = !cir.int<s, 32>
#fn_attr = #cir<extra({inline = #cir.inline<no>, optnone = #cir.optnone})>
#loc3 = loc("<stdin>":1:11)
#loc4 = loc("<stdin>":1:15)
#loc7 = loc(fused[#loc3, #loc4])
module attributes {cir.lang = #cir.lang<cxx>, cir.sob = #cir.signed_overflow_behavior<undefined>, dlti.dl_spec = #dlti.dl_spec<#dlti.dl_entry<!llvm.ptr<270>, dense<32> : vector<4xi64>>, #dlti.dl_entry<!llvm.ptr<271>, dense<32> : vector<4xi64>>, #dlti.dl_entry<f128, dense<128> : vector<2xi64>>, #dlti.dl_entry<f16, dense<16> : vector<2xi64>>, #dlti.dl_entry<f64, dense<64> : vector<2xi64>>, #dlti.dl_entry<i64, dense<64> : vector<2xi64>>, #dlti.dl_entry<i128, dense<128> : vector<2xi64>>, #dlti.dl_entry<!llvm.ptr<272>, dense<64> : vector<4xi64>>, #dlti.dl_entry<!llvm.ptr, dense<64> : vector<4xi64>>, #dlti.dl_entry<f80, dense<128> : vector<2xi64>>, #dlti.dl_entry<i16, dense<16> : vector<2xi64>>, #dlti.dl_entry<i32, dense<32> : vector<2xi64>>, #dlti.dl_entry<i1, dense<8> : vector<2xi64>>, #dlti.dl_entry<i8, dense<8> : vector<2xi64>>, #dlti.dl_entry<"dlti.endianness", "little">, #dlti.dl_entry<"dlti.stack_alignment", 128 : i64>>, llvm.data_layout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"} {
  cir.func @_Z4testPi(%arg0: !cir.ptr<!s32i> loc(fused[#loc3, #loc4])) extra(#fn_attr) {
    %0 = cir.alloca !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>>, ["", init] {alignment = 8 : i64} loc(#loc7)
    cir.store %arg0, %0 : !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>> loc(#loc5)
    cir.return loc(#loc2)
  } loc(#loc6)
} loc(#loc)
#loc = loc(unknown)
#loc1 = loc("<stdin>":1:1)
#loc2 = loc("<stdin>":1:18)
#loc5 = loc("<stdin>":1:17)
#loc6 = loc(fused[#loc1, #loc2])

@bcardosolopes bcardosolopes changed the title Cannot lower function with pointer arguments through MLIR [ThroughMLIR] Cannot lower function with pointer arguments Jun 6, 2024
bcardosolopes pushed a commit that referenced this issue Jun 13, 2024
…684)

This PR is to fix the issue #658 .
Now we can get the correct result using the following command.
```
echo "void test(int *){}" |  ./build/Debug/bin/clang -cc1 -triple x86_64-unknown-linux-gnu -fclangir -fno-clangir-direct-lowering -emit-mlir -o -
```
result:
```
module attributes {cir.lang = #cir.lang<c>, cir.sob = #cir.signed_overflow_behavior<undefined>, cir.triple = "x86_64-unknown-linux-gnu", dlti.dl_spec = #dlti.dl_spec<#dlti.dl_entry<!llvm.ptr, dense<64> : vector<4xi64>>, #dlti.dl_entry<i1, dense<8> : vector<2xi64>>, #dlti.dl_entry<f16, dense<16> : vector<2xi64>>, #dlti.dl_entry<i32, dense<32> : vector<2xi64>>, #dlti.dl_entry<i8, dense<8> : vector<2xi64>>, #dlti.dl_entry<i16, dense<16> : vector<2xi64>>, #dlti.dl_entry<!llvm.ptr<272>, dense<64> : vector<4xi64>>, #dlti.dl_entry<!llvm.ptr<271>, dense<32> : vector<4xi64>>, #dlti.dl_entry<!llvm.ptr<270>, dense<32> : vector<4xi64>>, #dlti.dl_entry<f128, dense<128> : vector<2xi64>>, #dlti.dl_entry<f64, dense<64> : vector<2xi64>>, #dlti.dl_entry<f80, dense<128> : vector<2xi64>>, #dlti.dl_entry<i128, dense<128> : vector<2xi64>>, #dlti.dl_entry<i64, dense<64> : vector<2xi64>>, #dlti.dl_entry<"dlti.stack_alignment", 128 : i64>, #dlti.dl_entry<"dlti.endianness", "little">>, llvm.data_layout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"} {
  func.func @test(%arg0: memref<i32> loc(fused[#loc3, #loc4])) {
    %alloca = memref.alloca() {alignment = 8 : i64} : memref<memref<i32>> loc(#loc7)
    memref.store %arg0, %alloca[] : memref<memref<i32>> loc(#loc5)
    return loc(#loc2)
  } loc(#loc6)
} loc(#loc)
```
And the test/CIR/Lowering/ThroughMLIR/dot.cir now passes the test, so I
have removed the XFAIL flag.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant