<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Crash during OpenMP code generation when marking a const templated aggregate value as firstprivate"
   href="https://bugs.llvm.org/show_bug.cgi?id=50642">50642</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Crash during OpenMP code generation when marking a const templated aggregate value as firstprivate
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>OpenMP
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>a.bataev@hotmail.com
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>huberjn@ornl.gov
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>huberjn@ornl.gov, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Clang crashes during OpenMP code generation on my machine when compiling this
code (<a href="https://godbolt.org/z/WMdcxznTW">https://godbolt.org/z/WMdcxznTW</a>). The reason is most likely the code
generation not correctly handling the template arguments when creating the
global variable for the firstprivate value. Normally, the compiler will create
a global variable mapped to the device's constant memory for a firstprivate
argument marked const. Here is the stack trace I get from compiling this code
on my machine

$ clang++ -fopenmp -fopenmp-targets=nvptx64 -Xopenmp-target -march=sm_70
private.cpp
clang-13:
/home2/3n4/llvm/llvm-project/clang/lib/CodeGen/CGOpenMPRuntime.cpp:2173:
llvm::Constant*
clang::CodeGen::CGOpenMPRuntime::getOrCreateInternalVariable(llvm::Type*, const
llvm::Twine&, unsigned int): Assertion
`Elem.second->getType()->getPointerElementType() == Ty && "OMP internal
variable has different type than requested"' failed.
PLEASE submit a bug report to <a href="https://bugs.llvm.org/">https://bugs.llvm.org/</a> and include the crash
backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: /home2/3n4/clang/bin/clang-13 -cc1 -triple
x86_64-unknown-linux-gnu -emit-llvm-bc -emit-llvm-uselists -disable-free
-main-file-name private.cpp -mrelocation-model static -mframe-pointer=all
-fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables
-target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb
-fcoverage-compilation-dir=/home2/3n4/test -resource-dir
/home2/3n4/clang/lib/clang/13.0.0
-I/home2/3n4/spack/opt/spack/linux-centos8-broadwell/gcc-8.3.1/python-3.8.7-yvhk6s7e3gl4ibgp3ohzpiicvlsjhkdk/include/python3.8
-I/data1/projects/spack/spack/opt/spack/linux-centos8-broadwell/gcc-8.3.1/python-3.7.6-7zpobbl7yu5kkafgzvrl3qa4mrrwrkcv/include/python3.7m
-c-isystem
/home2/3n4/spack/opt/spack/linux-centos8-broadwell/gcc-8.3.1/benchmark-1.5.0-tn6oiy6sytzjw24jkdrm6kjsk2hl6sbl/include
-c-isystem
/home2/3n4/spack/opt/spack/linux-centos8-broadwell/gcc-8.3.1/googletest-1.10.0-coih2gkcvnv6kp6im26outzyquy2thdk/include
-c-isystem
/data1/projects/spack/spack/opt/spack/linux-centos8-broadwell/gcc-8.3.1/openblas-0.3.10-3fr25oz7i7ahayvwzizuzd4dsrcubkcq/include
-c-isystem
/home2/3n4/spack/opt/spack/linux-centos8-broadwell/gcc-8.3.1/python-3.8.7-yvhk6s7e3gl4ibgp3ohzpiicvlsjhkdk/include
-c-isystem
/data1/projects/spack/spack/opt/spack/linux-centos8-broadwell/gcc-8.3.1/curl-7.68.0-pawp6gmugr473rvqgupbqo7nxqx4f6ce/include
-c-isystem
/data1/projects/spack/spack/opt/spack/linux-centos8-broadwell/gcc-8.3.1/python-3.7.6-7zpobbl7yu5kkafgzvrl3qa4mrrwrkcv/include
-c-isystem
/data1/projects/spack/spack/opt/spack/linux-centos8-broadwell/gcc-8.3.1/cuda-10.1.243-l23v7goqrwkd4wwkihlhpwfjjtzihb6b/include
-cxx-isystem
/home2/3n4/spack/opt/spack/linux-centos8-broadwell/gcc-8.3.1/benchmark-1.5.0-tn6oiy6sytzjw24jkdrm6kjsk2hl6sbl/include
-cxx-isystem
/home2/3n4/spack/opt/spack/linux-centos8-broadwell/gcc-8.3.1/googletest-1.10.0-coih2gkcvnv6kp6im26outzyquy2thdk/include
-cxx-isystem
/data1/projects/spack/spack/opt/spack/linux-centos8-broadwell/gcc-8.3.1/openblas-0.3.10-3fr25oz7i7ahayvwzizuzd4dsrcubkcq/include
-cxx-isystem
/home2/3n4/spack/opt/spack/linux-centos8-broadwell/gcc-8.3.1/python-3.8.7-yvhk6s7e3gl4ibgp3ohzpiicvlsjhkdk/include
-cxx-isystem
/data1/projects/spack/spack/opt/spack/linux-centos8-broadwell/gcc-8.3.1/curl-7.68.0-pawp6gmugr473rvqgupbqo7nxqx4f6ce/include
-cxx-isystem
/data1/projects/spack/spack/opt/spack/linux-centos8-broadwell/gcc-8.3.1/python-3.7.6-7zpobbl7yu5kkafgzvrl3qa4mrrwrkcv/include
-cxx-isystem
/data1/projects/spack/spack/opt/spack/linux-centos8-broadwell/gcc-8.3.1/cuda-10.1.243-l23v7goqrwkd4wwkihlhpwfjjtzihb6b/include
-internal-isystem /usr/lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8
-internal-isystem
/usr/lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8/x86_64-redhat-linux
-internal-isystem
/usr/lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8/backward
-internal-isystem /usr/lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8
-internal-isystem
/usr/lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8/x86_64-redhat-linux
-internal-isystem
/usr/lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8/backward
-internal-isystem /home2/3n4/clang/lib/clang/13.0.0/include -internal-isystem
/usr/local/include -internal-isystem
/usr/lib/gcc/x86_64-redhat-linux/8/../../../../x86_64-redhat-linux/include
-internal-externc-isystem /include -internal-externc-isystem /usr/include
-internal-isystem /home2/3n4/clang/lib/clang/13.0.0/include -internal-isystem
/usr/local/include -internal-isystem
/usr/lib/gcc/x86_64-redhat-linux/8/../../../../x86_64-redhat-linux/include
-internal-externc-isystem /include -internal-externc-isystem /usr/include
-fdeprecated-macro -fdebug-compilation-dir=/home2/3n4/test -ferror-limit 19
-fopenmp -fopenmp-cuda-parallel-target-regions -fgnuc-version=4.2.1
-fcxx-exceptions -fexceptions -fcolor-diagnostics -disable-llvm-passes
-fopenmp-targets=nvptx64 -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o
/tmp/private-97af4e.bc -x c++ private.cpp
1.      <eof> parser at end of file
2.      Per-file LLVM IR generation
3.      private.cpp:7:6: Generating code for declaration 'foo'
 #0 0x00007f93ea34c16f PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
 #1 0x00007f93ea3499de SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f93f4252b20 __restore_rt sigaction.c:0:0
 #3 0x00007f93e94d67ff raise (/lib64/libc.so.6+0x377ff)
 #4 0x00007f93e94c0c35 abort (/lib64/libc.so.6+0x21c35)
 #5 0x00007f93e94c0b09 _nl_load_domain.cold.0 loadmsgcat.c:0:0
 #6 0x00007f93e94cede6 .annobin___GI___assert_fail.end assert.c:0:0
 #7 0x00007f93f047710b
clang::CodeGen::CGOpenMPRuntime::getOrCreateInternalVariable(llvm::Type*,
llvm::Twine const&, unsigned int)
(/home2/3n4/clang/bin/../lib/libclangCodeGen.so.13git+0x34410b)
 #8 0x00007f93f04bc317
clang::CodeGen::CGOpenMPRuntime::emitTargetCall(clang::CodeGen::CodeGenFunction&,
clang::OMPExecutableDirective const&, llvm::Function*, llvm::Value*,
clang::Expr const*, llvm::PointerIntPair<clang::Expr const*, 2u,
clang::OpenMPDeviceClauseModifier, llvm::PointerLikeTypeTraits<clang::Expr
const*>, llvm::PointerIntPairInfo<clang::Expr const*, 2u,
llvm::PointerLikeTypeTraits<clang::Expr const*> > >,
llvm::function_ref<llvm::Value* (clang::CodeGen::CodeGenFunction&,
clang::OMPLoopDirective const&)>)::'lambda2'(clang::CodeGen::CodeGenFunction&,
clang::CodeGen::PrePostActionTy&)::operator()(clang::CodeGen::CodeGenFunction&,
clang::CodeGen::PrePostActionTy&) const (.isra.3001) CGOpenMPRuntime.cpp:0:0
 #9 0x00007f93f046677b
clang::CodeGen::RegionCodeGenTy::operator()(clang::CodeGen::CodeGenFunction&)
const (/home2/3n4/clang/bin/../lib/libclangCodeGen.so.13git+0x33377b)
#10 0x00007f93f046e370
clang::CodeGen::CGOpenMPRuntime::emitTargetCall(clang::CodeGen::CodeGenFunction&,
clang::OMPExecutableDirective const&, llvm::Function*, llvm::Value*,
clang::Expr const*, llvm::PointerIntPair<clang::Expr const*, 2u,
clang::OpenMPDeviceClauseModifier, llvm::PointerLikeTypeTraits<clang::Expr
const*>, llvm::PointerIntPairInfo<clang::Expr const*, 2u,
llvm::PointerLikeTypeTraits<clang::Expr const*> > >,
llvm::function_ref<llvm::Value* (clang::CodeGen::CodeGenFunction&,
clang::OMPLoopDirective const&)>)
(/home2/3n4/clang/bin/../lib/libclangCodeGen.so.13git+0x33b370)
#11 0x00007f93f050b32f
emitCommonOMPTargetDirective(clang::CodeGen::CodeGenFunction&,
clang::OMPExecutableDirective const&, clang::CodeGen::RegionCodeGenTy const&)
(.constprop.2454) CGStmtOpenMP.cpp:0:0
#12 0x00007f93f050b7e2
clang::CodeGen::CodeGenFunction::EmitOMPTargetDirective(clang::OMPTargetDirective
const&) (/home2/3n4/clang/bin/../lib/libclangCodeGen.so.13git+0x3d87e2)
#13 0x00007f93f04f0c78 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt
const*, llvm::ArrayRef<clang::Attr const*>)
(/home2/3n4/clang/bin/../lib/libclangCodeGen.so.13git+0x3bdc78)
#14 0x00007f93f04f5c4c
clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt
const&, bool, clang::CodeGen::AggValueSlot)
(/home2/3n4/clang/bin/../lib/libclangCodeGen.so.13git+0x3c2c4c)
#15 0x00007f93f054bc41
clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*)
(/home2/3n4/clang/bin/../lib/libclangCodeGen.so.13git+0x418c41)
#16 0x00007f93f055babc
clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl,
llvm::Function*, clang::CodeGen::CGFunctionInfo const&)
(/home2/3n4/clang/bin/../lib/libclangCodeGen.so.13git+0x428abc)
#17 0x00007f93f05a7b19
clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl,
llvm::GlobalValue*)
(/home2/3n4/clang/bin/../lib/libclangCodeGen.so.13git+0x474b19)
#18 0x00007f93f05a3dc5
clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl,
llvm::GlobalValue*)
(/home2/3n4/clang/bin/../lib/libclangCodeGen.so.13git+0x470dc5)
#19 0x00007f93f05ab6ff clang::CodeGen::CodeGenModule::EmitDeferred()
(/home2/3n4/clang/bin/../lib/libclangCodeGen.so.13git+0x4786ff)
#20 0x00007f93f05ab648 clang::CodeGen::CodeGenModule::EmitDeferred()
(/home2/3n4/clang/bin/../lib/libclangCodeGen.so.13git+0x478648)
#21 0x00007f93f05accc9 clang::CodeGen::CodeGenModule::Release()
(/home2/3n4/clang/bin/../lib/libclangCodeGen.so.13git+0x479cc9)
#22 0x00007f93f0624cca (anonymous
namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&)
ModuleBuilder.cpp:0:0
#23 0x00007f93f0548717
clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&)
(/home2/3n4/clang/bin/../lib/libclangCodeGen.so.13git+0x415717)
#24 0x00007f93e3cd1f99 clang::ParseAST(clang::Sema&, bool, bool)
(/home2/3n4/clang/bin/../lib/../lib/libclangParse.so.13git+0x32f99)
#25 0x00007f93f05475d8 clang::CodeGenAction::ExecuteAction()
(/home2/3n4/clang/bin/../lib/libclangCodeGen.so.13git+0x4145d8)
#26 0x00007f93ed7b1b01 clang::FrontendAction::Execute()
(/home2/3n4/clang/bin/../lib/libclangFrontend.so.13git+0x11ab01)
#27 0x00007f93ed7435b9
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
(/home2/3n4/clang/bin/../lib/libclangFrontend.so.13git+0xac5b9)
#28 0x00007f93f403d7c0
clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
(/home2/3n4/clang/bin/../lib/libclangFrontendTool.so.13git+0x47c0)
#29 0x0000000000415c62 cc1_main(llvm::ArrayRef<char const*>, char const*,
void*) (/home2/3n4/clang/bin/clang-13+0x415c62)
#30 0x0000000000412287 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&)
driver.cpp:0:0
#31 0x000000000040f8f3 main (/home2/3n4/clang/bin/clang-13+0x40f8f3)
#32 0x00007f93e94c27b3 __libc_start_main (/lib64/libc.so.6+0x237b3)
#33 0x0000000000411d7e _start (/home2/3n4/clang/bin/clang-13+0x411d7e)
clang-13: error: unable to execute command: Aborted (core dumped)
clang-13: error: clang frontend command failed due to signal (use -v to see
invocation)
clang version 13.0.0
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home2/3n4/clang/bin
clang-13: note: diagnostic msg: Error generating preprocessed source(s).</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>