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

    <tr>
        <th>Summary</th>
        <td>
            OpenMP Scan Directive not supported for Generic types 
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          animeshk-amd
      </td>
    </tr>
</table>

<pre>
    Although the following test code satisfies the restrictions with respect to the usage of the `scan` directive in the spec, the compilation fails in the frontend.
``` c++
template<typename T>
void exclusiveScan(const long N, std::vector<T> v) {
  T scan_v{0};

  #pragma omp parallel for reduction(inscan, +:scan_v)
 for(int n = 0; n < N; ++n){
    v[n] = scan_v;
    #pragma omp scan exclusive(scan_v)
    scan_v += v[n];
  }
}
```
However, the same test compiles successfully when a specific datatype like `int` or `double` is used.
The error log and stack trace: 
``` sh
clang++: /home/animkuma/llvm-project/llvm/include/llvm/Support/Casting.h:662: decltype(auto) llvm::dyn_cast(From*) [with To = clang::BinaryOperator; From = clang::Stmt]: Assertion `detail::isPresent(Val) && "dyn_cast on a non-existent value"' failed.
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: /home/animkuma/trunk_1.0/bin/clang++ -c scan.cpp -fopenmp -o scan.o
1.      scan.cpp:13:1: current parser token '}'
2. scan.cpp:4:52: parsing function body 'exclusiveScan'
3. scan.cpp:4:52: in compound statement ('{}')
 #0 0x00005579bd93483f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/animkuma/trunk_1.0/bin/clang+++0x278d83f)
 #1 0x00005579bd9323bc llvm::sys::CleanupOnSignal(unsigned long) (/home/animkuma/trunk_1.0/bin/clang+++0x278b3bc)
 #2 0x00005579bd876628 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007fe1e16b6420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007fe1e10aa00b raise /build/glibc-SzIz7B/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #5 0x00007fe1e1089859 abort /build/glibc-SzIz7B/glibc-2.31/stdlib/abort.c:81:7
 #6 0x00007fe1e1089729 get_sysdep_segment_value /build/glibc-SzIz7B/glibc-2.31/intl/loadmsgcat.c:509:8
 #7 0x00007fe1e1089729 _nl_load_domain /build/glibc-SzIz7B/glibc-2.31/intl/loadmsgcat.c:970:34
 #8 0x00007fe1e109afd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #9 0x00005579c039ec9c clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::EvaluatedExprMarker, void>::Visit(clang::Stmt*) SemaExpr.cpp:0:0
#10 0x00005579c039f24e clang::Sema::MarkDeclarationsReferencedInExpr(clang::Expr*, bool, llvm::ArrayRef<clang::Expr const*>) (/home/animkuma/trunk_1.0/bin/clang+++0x51f824e)
#11 0x00005579c062ea0f clang::Sema::ActOnOpenMPRegionEnd(clang::ActionResult<clang::Stmt*, true>, llvm::ArrayRef<clang::OMPClause*>) (/home/animkuma/trunk_1.0/bin/clang+++0x5487a0f)
#12 0x00005579bfebc483 clang::Parser::ParseOpenMPDeclarativeOrExecutableDirective(clang::Parser::ParsedStmtContext, bool) (/home/animkuma/trunk_1.0/bin/clang+++0x4d15483)
#13 0x00005579bfed9872 clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&) (/home/animkuma/trunk_1.0/bin/clang+++0x4d32872)
#14 0x00005579bfedb6df clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) (/home/animkuma/trunk_1.0/bin/clang+++0x4d346df)
#15 0x00005579bfedc6b9 clang::Parser::ParseCompoundStatementBody(bool) (/home/animkuma/trunk_1.0/bin/clang+++0x4d356b9)
#16 0x00005579bfede04a clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/home/animkuma/trunk_1.0/bin/clang+++0x4d3704a)
#17 0x00005579bfe079a1 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/home/animkuma/trunk_1.0/bin/clang+++0x4c609a1)
#18 0x00005579bfef8176 clang::Parser::ParseSingleDeclarationAfterTemplate(clang::DeclaratorContext, clang::Parser::ParsedTemplateInfo const&, clang::ParsingDeclRAIIObject&, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/home/animkuma/trunk_1.0/bin/clang+++0x4d51176)
#19 0x00005579bfefd760 clang::Parser::ParseTemplateDeclarationOrSpecialization(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (.part.0) ParseTemplate.cpp:0:0
#20 0x00005579bfefda13 clang::Parser::ParseDeclarationStartingWithTemplate(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/home/animkuma/trunk_1.0/bin/clang+++0x4d56a13)
#21 0x00005579bfe37d9d clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) (/home/animkuma/trunk_1.0/bin/clang+++0x4c90d9d)
#22 0x00005579bfe01ed4 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/home/animkuma/trunk_1.0/bin/clang+++0x4c5aed4)
#23 0x00005579bfe02e55 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/home/animkuma/trunk_1.0/bin/clang+++0x4c5be55)
#24 0x00005579bfdf6baa clang::ParseAST(clang::Sema&, bool, bool) (/home/animkuma/trunk_1.0/bin/clang+++0x4c4fbaa)
#25 0x00005579bebf00b8 clang::CodeGenAction::ExecuteAction() (/home/animkuma/trunk_1.0/bin/clang+++0x3a490b8)
#26 0x00005579be42af29 clang::FrontendAction::Execute() (/home/animkuma/trunk_1.0/bin/clang+++0x3283f29)
#27 0x00005579be3a9c2e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/animkuma/trunk_1.0/bin/clang+++0x3202c2e)
#28 0x00005579be50e9a6 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/animkuma/trunk_1.0/bin/clang+++0x33679a6)
#29 0x00005579bbf2a826 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/animkuma/trunk_1.0/bin/clang+++0xd83826)
#30 0x00005579bbf2242a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#31 0x00005579be201f8d void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#32 0x00005579bd876b30 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/home/animkuma/trunk_1.0/bin/clang+++0x26cfb30)
#33 0x00005579be2025af clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#34 0x00005579be1c92bc clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/home/animkuma/trunk_1.0/bin/clang+++0x30222bc)
#35 0x00005579be1c9d4d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/home/animkuma/trunk_1.0/bin/clang+++0x3022d4d)
#36 0x00005579be1d22e5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/home/animkuma/trunk_1.0/bin/clang+++0x302b2e5)
#37 0x00005579bbf2809a clang_main(int, char**, llvm::ToolContext const&) (/home/animkuma/trunk_1.0/bin/clang+++0xd8109a)
#38 0x00005579bbe74c65 main (/home/animkuma/trunk_1.0/bin/clang+++0xccdc65)
#39 0x00007fe1e108b083 __libc_start_main /build/glibc-SzIz7B/glibc-2.31/csu/../csu/libc-start.c:342:3
#40 0x00005579bbf21eee _start (/home/animkuma/trunk_1.0/bin/clang+++0xd7aeee)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
clang version 18.0.0 (https://github.com/llvm/llvm-project.git 8cad4dd00077226f9fca5d176b7ef6ed9f668008)
Target: x86_64-unknown-linux-gnu
Thread model: posix
```
PFA: Preprocessed source and run script.
[scan-b0e5fd.zip](https://github.com/llvm/llvm-project/files/12683807/scan-b0e5fd.zip)

cc: @alexey-bataev 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkWltv47iS_jXKCxGDou4PeXCceE4Pek6CTjD7aFBkyeZGJrUk5Xbm1y9IyY6pdjLd7d6DARZIuyXxUl99VSwWL9QYsZYAN1F2G2V3V7S3G6VvqBRbMJuXa7rlV7Xirzfz1m5Uv94guwHUqLZVX4VcIwvGIqY4IEOtMI0A42toMFYLZoWSBn0VduO-dMAssspX6A1dA1KNf4lybBiVUY4RFxqYFTtAQvoy1yoiC__M1LYTLXW9ooaK1hwqNVpJC5LPInwX4XmU4-EPsYjcuj__2cK2a6mFKFnY1w4k3QJ6jpL7oXSnBEewZ21vxA6eHB5SMiWNRa2Sa_Rvh8JYHiXzKJnvgFmlo2ThOkC7iFQoKkY5CD0jp89qFxW3OCruomQsOZRHJOk0XW8pUtsOdVTTtoUWNUojDbz3vEWkFNLTQhbI6ZDMx05JNfbTKO1rWSRRlNwhHCW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