<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/145216>145216</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [Flang][OpenMP] crashes when using non-C_PTR type in USE_DEVICE_PTR
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            crash,
            flang:openmp
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          k-arrows
      </td>
    </tr>
</table>

<pre>
    Reproducer:
https://godbolt.org/z/569voxf9z
```f90
use iso_c_binding, only: c_loc, c_ptr
real, allocatable, target :: arr(:,:)
type(c_ptr) :: devptr

!$omp target data use_device_ptr(arr)
devptr = c_loc(arr(1,1))
!$omp end target data

end
```

Backtrace:
```console
flang-21: warning: OpenMP support in flang is still experimental [-Wexperimental-option]
/app/example.f90:5:19: warning: Use of non-C_PTR type 'arr' in USE_DEVICE_PTR is deprecated, use USE_DEVICE_ADDR instead
 !$omp target data use_device_ptr(arr)
 ^^^^^^^^^^^^^^^^^^^
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /opt/compiler-explorer/clang-llvmflang-trunk-20250622/bin/flang -fc1 -triple x86_64-unknown-linux-gnu -S -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu x86-64 -mllvm -x86-asm-syntax=intel -fopenmp -resource-dir /opt/compiler-explorer/clang-llvmflang-trunk-20250622/lib/clang/21 -mframe-pointer=all -o /app/output.s -x f95 /app/example.f90
 #0 0x0000000003e78268 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-llvmflang-trunk-20250622/bin/flang+0x3e78268)
 #1 0x0000000003e75e24 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #2 0x00007537ac042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x0000000007613cd5 mlir::LLVM::detail::createIntrinsicCall(llvm::IRBuilderBase&, mlir::LLVM::ModuleTranslation&, mlir::Operation*, unsigned int, unsigned int, llvm::ArrayRef<unsigned int>, llvm::ArrayRef<unsigned int>, llvm::ArrayRef<unsigned int>, llvm::ArrayRef<llvm::StringLiteral>) (/opt/compiler-explorer/clang-llvmflang-trunk-20250622/bin/flang+0x7613cd5)
 #4 0x0000000005e55588 convertOperationImpl(mlir::Operation&, llvm::IRBuilderBase&, mlir::LLVM::ModuleTranslation&) LLVMToLLVMIRTranslation.cpp:0:0
 #5 0x000000000760f9c6 mlir::LLVM::ModuleTranslation::convertOperation(mlir::Operation&, llvm::IRBuilderBase&, bool) (/opt/compiler-explorer/clang-llvmflang-trunk-20250622/bin/flang+0x760f9c6)
 #6 0x000000000760fddb mlir::LLVM::ModuleTranslation::convertBlockImpl(mlir::Block&, bool, llvm::IRBuilderBase&, bool) (/opt/compiler-explorer/clang-llvmflang-trunk-20250622/bin/flang+0x760fddb)
 #7 0x0000000005c5ef62 inlineConvertOmpRegions(mlir::Region&, llvm::StringRef, llvm::IRBuilderBase&, mlir::LLVM::ModuleTranslation&, llvm::SmallVectorImpl<llvm::Value*>*) OpenMPToLLVMIRTranslation.cpp:0:0
 #8 0x0000000005c624c4 llvm::Expected<llvm::IRBuilderBase::InsertPoint> llvm::function_ref<llvm::Expected<llvm::IRBuilderBase::InsertPoint> (llvm::IRBuilderBase::InsertPoint, llvm::OpenMPIRBuilder::BodyGenTy)>::callback_fn<convertOmpTargetData(mlir::Operation*, llvm::IRBuilderBase&, mlir::LLVM::ModuleTranslation&)::'lambda6'(llvm::IRBuilderBase::InsertPoint, llvm::OpenMPIRBuilder::BodyGenTy)>(long, llvm::IRBuilderBase::InsertPoint, llvm::OpenMPIRBuilder::BodyGenTy) OpenMPToLLVMIRTranslation.cpp:0:0
 #9 0x00000000081722d4 llvm::OpenMPIRBuilder::createTargetData(llvm::OpenMPIRBuilder::LocationDescription const&, llvm::IRBuilderBase::InsertPoint, llvm::IRBuilderBase::InsertPoint, llvm::Value*, llvm::Value*, llvm::OpenMPIRBuilder::TargetDataInfo&, llvm::function_ref<llvm::OpenMPIRBuilder::MapInfosTy& (llvm::IRBuilderBase::InsertPoint)>, llvm::function_ref<llvm::Expected<llvm::Function*> (unsigned int)>, llvm::omp::RuntimeFunction*, llvm::function_ref<llvm::Expected<llvm::IRBuilderBase::InsertPoint> (llvm::IRBuilderBase::InsertPoint, llvm::OpenMPIRBuilder::BodyGenTy)>, llvm::function_ref<void (unsigned int, llvm::Value*)>, llvm::Value*) (/opt/compiler-explorer/clang-llvmflang-trunk-20250622/bin/flang+0x81722d4)
#10 0x0000000005c566bb convertOmpTargetData(mlir::Operation*, llvm::IRBuilderBase&, mlir::LLVM::ModuleTranslation&) OpenMPToLLVMIRTranslation.cpp:0:0
#11 0x0000000005c75a3b convertHostOrTargetOperation(mlir::Operation*, llvm::IRBuilderBase&, mlir::LLVM::ModuleTranslation&) OpenMPToLLVMIRTranslation.cpp:0:0
#12 0x0000000005c75fa5 (anonymous namespace)::OpenMPDialectLLVMIRTranslationInterface::convertOperation(mlir::Operation*, llvm::IRBuilderBase&, mlir::LLVM::ModuleTranslation&) const OpenMPToLLVMIRTranslation.cpp:0:0
#13 0x000000000760f9c6 mlir::LLVM::ModuleTranslation::convertOperation(mlir::Operation&, llvm::IRBuilderBase&, bool) (/opt/compiler-explorer/clang-llvmflang-trunk-20250622/bin/flang+0x760f9c6)
#14 0x000000000760fddb mlir::LLVM::ModuleTranslation::convertBlockImpl(mlir::Block&, bool, llvm::IRBuilderBase&, bool) (/opt/compiler-explorer/clang-llvmflang-trunk-20250622/bin/flang+0x760fddb)
#15 0x00000000076155f3 mlir::LLVM::ModuleTranslation::convertOneFunction(mlir::LLVM::LLVMFuncOp) (/opt/compiler-explorer/clang-llvmflang-trunk-20250622/bin/flang+0x76155f3)
#16 0x0000000007616db8 mlir::LLVM::ModuleTranslation::convertFunctions() (/opt/compiler-explorer/clang-llvmflang-trunk-20250622/bin/flang+0x7616db8)
#17 0x000000000761f35e mlir::translateModuleToLLVMIR(mlir::Operation*, llvm::LLVMContext&, llvm::StringRef, bool) (/opt/compiler-explorer/clang-llvmflang-trunk-20250622/bin/flang+0x761f35e)
#18 0x000000000418ad0f Fortran::frontend::CodeGenAction::generateLLVMIR() (/opt/compiler-explorer/clang-llvmflang-trunk-20250622/bin/flang+0x418ad0f)
#19 0x0000000004190438 Fortran::frontend::CodeGenAction::executeAction() (/opt/compiler-explorer/clang-llvmflang-trunk-20250622/bin/flang+0x4190438)
#20 0x0000000003ed099d Fortran::frontend::FrontendAction::execute() (/opt/compiler-explorer/clang-llvmflang-trunk-20250622/bin/flang+0x3ed099d)
#21 0x0000000003ebea78 Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) (/opt/compiler-explorer/clang-llvmflang-trunk-20250622/bin/flang+0x3ebea78)
#22 0x0000000003eda0d3 Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (/opt/compiler-explorer/clang-llvmflang-trunk-20250622/bin/flang+0x3eda0d3)
#23 0x0000000002216b3a fc1_main(llvm::ArrayRef<char const*>, char const*) (/opt/compiler-explorer/clang-llvmflang-trunk-20250622/bin/flang+0x2216b3a)
#24 0x00000000020c5846 main (/opt/compiler-explorer/clang-llvmflang-trunk-20250622/bin/flang+0x20c5846)
#25 0x00007537ac029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#26 0x00007537ac029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#27 0x0000000002215505 _start (/opt/compiler-explorer/clang-llvmflang-trunk-20250622/bin/flang+0x2215505)
flang-21: error: unable to execute command: Segmentation fault (core dumped)
flang-21: error: flang frontend command failed due to signal (use -v to see invocation)
flang version 21.0.0git (https://github.com/llvm/llvm-project.git f280d3b705de7f94ef9756e3ef2842b415a7c038)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/compiler-explorer/clang-llvmflang-trunk-20250622/bin
flang-21: warning: OpenMP support in flang is still experimental [-Wexperimental-option]
flang-21: note: diagnostic msg: 
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzkWl1z26jX_zTkhpFHQi-WLnLh2PFuZtppJ-n2ufQgOHJ4ikADKHX20_8HJMdv2TRp4-3F7nhTCcE5v995gYMQtVasFcAlyq9QvrigvbvX5vJbRI3R3-1Frfnj5S10RvOegUHpDMWze-c66y_JEpHlWvNaSzfRZo3I8m9ElnlRPehNU_2N4hkq4uHXVDGKZ70FLKxesVUtFBdqjcgcayUfUTrDbCU18w1s1TmD4pkBKv09lVIz6mgtwd86atbgsEeQzjA1BpEywJmHvxWKZ-6xA0TKQRCptn05PAyS_Y8kiGS67bbyOHUU9xZWHB4Eg2FoGcR7kcNYjNLFFujwrEwQmSe-T-i2EwuK74setILi-1YZGq8o--YMZTDY9-kp08pqCSieNZKqdUQST-I7NcpbLp3hTx2oj5-x7btOG4eFwqEjFhZbJ6TEsOnAiBaUoxKj_Cr6v_2WSHdOaIXyRQC-pF2HyBI2tO0kTLzH0lmO0llSHen9ywLWDVZaRfPV5y-32NsbIzINFpl6IH_dXa8W119v5tehg7CYQ2eAUQfcO9FHwl6f2WJxi4WyDqg3EH6rdzDKr3_yF88-f7ie3V1j29etcJjiul9jA8GkTuOjcBfuvq8nTLeILKV82P4TdUb_PzCHyFJY24NFZImp4lgoJnsO2N0DZobae1xv3T1B8ezOUfYN877tBufHExRXn41eG9piata9d5VXjxFZ6s7LZ7rthAQTwaaT2oDxbSFAPJAhVJzp1beIxCSPC0IQWdZCIbIcwiNqWIIjZ0QnAW_KYlVkUa--Kf1dRVKofhOtVY-jOxy1BkLqCa2iVnOQuBMMR51gkYQHkJgMN8JGnQAcDc6KWNd7uVGR4aj1oHDkb6ltI_uoHN2gdCGUA4mjRneg2g5HBqzuDYOIC_OLXKWot90QWZIER21jaAtRp71Wg9IFlRJHGj8Fve5d17uJxdEGN1WOn82GEJdpjONNvP0v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