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

    <tr>
        <th>Summary</th>
        <td>
            [AArch64][SVE] __SVFloat32_t results in Assertion failed: (isa<To>(Val) && "cast<Ty>() argument of incompatible type!")
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang:frontend,
            SVE
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          DimitryAndric
      </td>
    </tr>
</table>

<pre>
    Test case (in C++):

```c++
// clang -cc1 -triple aarch64-- -S sve.cpp
void a() { __SVFloat32_t{}; }
```

Backtrace:

```text
Assertion failed: (isa<To>(Val) && "cast<Ty>() argument of incompatible type!"), function cast, file /home/dim/src/llvm/llvm-project/llvm/include/llvm/Support/Casting.h, line 578.
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/dim/ins/llvmorg-17-init-12643-ge821db39d22/bin/clang -cc1 -triple aarch64-- -S sve.cpp
1.      <eof> parser at end of file
2.      sve.cpp:1:6: LLVM IR generation of declaration 'a'
3. sve.cpp:1:6: Generating code for declaration 'a'
 #0 0x00000000042e39a7 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/dim/ins/llvmorg-17-init-12643-ge821db39d22/bin/clang+0x42e39a7)
 #1 0x00000000042e18b8 llvm::sys::RunSignalHandlers() (/home/dim/ins/llvmorg-17-init-12643-ge821db39d22/bin/clang+0x42e18b8)
 #2 0x00000000042e4140 SignalHandler(int) Signals.cpp:0:0
 #3 0x0000000829364a3e handle_signal /usr/src/lib/libthr/thread/thr_sig.c:0:3
 #4 0x0000000829363ff9 thr_sighandler /usr/src/lib/libthr/thread/thr_sig.c:247:1
 #5 0x0000000827d5d903 ([vdso]+0x2d3)
 #6 0x000000082f59897a __sys_thr_kill /usr/obj/usr/src/lib/libc/thr_kill.S:4:0
 #7 0x000000082f511954 __raise /usr/src/lib/libc/gen/raise.c:0:10
 #8 0x000000082f5c23e9 abort /usr/src/lib/libc/stdlib/abort.c:73:17
 #9 0x000000082f4f4a41 (/lib/libc.so.7+0x93a41)
#10 0x00000000046680af (anonymous namespace)::ScalarExprEmitter::VisitInitListExpr(clang::InitListExpr*) CGExprScalar.cpp:0:0
#11 0x00000000046556f0 (anonymous namespace)::ScalarExprEmitter::Visit(clang::Expr*) CGExprScalar.cpp:0:0
#12 0x0000000004670402 (anonymous namespace)::ScalarExprEmitter::VisitCastExpr(clang::CastExpr*) CGExprScalar.cpp:0:0
#13 0x000000000465567b clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/home/dim/ins/llvmorg-17-init-12643-ge821db39d22/bin/clang+0x465567b)
#14 0x000000000456b5fb clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr const*, clang::CodeGen::AggValueSlot, bool) (/home/dim/ins/llvmorg-17-init-12643-ge821db39d22/bin/clang+0x456b5fb)
#15 0x000000000456b578 clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) (/home/dim/ins/llvmorg-17-init-12643-ge821db39d22/bin/clang+0x456b578)
#16 0x00000000045aa6c2 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/home/dim/ins/llvmorg-17-init-12643-ge821db39d22/bin/clang+0x45aa6c2)
#17 0x00000000045b7380 clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/home/dim/ins/llvmorg-17-init-12643-ge821db39d22/bin/clang+0x45b7380)
#18 0x0000000004599fd9 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/home/dim/ins/llvmorg-17-init-12643-ge821db39d22/bin/clang+0x4599fd9)
#19 0x00000000044d48f5 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/home/dim/ins/llvmorg-17-init-12643-ge821db39d22/bin/clang+0x44d48f5)
#20 0x00000000044ccbda clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/home/dim/ins/llvmorg-17-init-12643-ge821db39d22/bin/clang+0x44ccbda)
#21 0x00000000044d130e clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/home/dim/ins/llvmorg-17-init-12643-ge821db39d22/bin/clang+0x44d130e)
#22 0x00000000044cb755 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (/home/dim/ins/llvmorg-17-init-12643-ge821db39d22/bin/clang+0x44cb755)
#23 0x0000000004e4572f (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#24 0x0000000004e42965 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) CodeGenAction.cpp:0:0
#25 0x0000000005beaca8 clang::ParseAST(clang::Sema&, bool, bool) (/home/dim/ins/llvmorg-17-init-12643-ge821db39d22/bin/clang+0x5beaca8)
#26 0x0000000004d68fe3 clang::FrontendAction::Execute() (/home/dim/ins/llvmorg-17-init-12643-ge821db39d22/bin/clang+0x4d68fe3)
#27 0x0000000004cec5df clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/dim/ins/llvmorg-17-init-12643-ge821db39d22/bin/clang+0x4cec5df)
#28 0x0000000004e3ba38 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/dim/ins/llvmorg-17-init-12643-ge821db39d22/bin/clang+0x4e3ba38)
#29 0x00000000028abb15 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/dim/ins/llvmorg-17-init-12643-ge821db39d22/bin/clang+0x28abb15)
#30 0x00000000028a7a95 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#31 0x00000000028a6979 clang_main(int, char**, llvm::ToolContext const&) (/home/dim/ins/llvmorg-17-init-12643-ge821db39d22/bin/clang+0x28a6979)
```

Interestingly, the same type of test case in plain C works without asserting:

```c
// clang -cc1 -triple aarch64-- -S sve.c
void a() { __SVFloat32_t x; }
```

gives:

```text
$ clang -cc1 -triple aarch64-- -S sve.c
sve.c:2:26: error: SVE vector type '__SVFloat32_t' cannot be used in a target without sve
void a() { __SVFloat32_t x; }
                         ^
1 error generated.
```

and when enabling SVE explicitly, no problems at all:

```text
$ clang -cc1 -triple aarch64-- -target-feature +sve -S sve.c
<nothing>
```

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMWVtv46oW_jX0BTWywdeHPiTp5VSaLY0mVc9jhfFywh4bLMCZ9t8fgZ0LaTvTdrdHO-olwbD4vm8tYIXFjBFrCXCB0gVKL8_YYDdKX1yKTlj9NJe1FvysUvXTxR0YizkzgBEphMRLRBb-p0R0jqJLFO3-ZtH4w6ceYyu5RuQa85bJNT7nPMbnVou-BcyY5pssOT_H5ytstjDjfT-O2SpRY4ZIgUiJUb7ADw-r--tWMUvJg0X5AuWXiC6w-xdOfYxnwfhPqxmH13BaeLRj09wY0FYoiRsmWqgRnXu2hiG6vFOIXiFS3LPW4yEZIhlGhHBmrHv-ND53D5leDx1Ii1WDheSq65kVVQvYPvWASIwIccKRJW4Gyf2M3oprEK2T-HqjOkDkuhYdItdGc0Su23bbTf_Oe63-Bm4PrULydqjh0LAa-l5p12PJjBVyPds4-62QgNO8mI2Uv3-7mq-usBmqTljMcDWssQY3EFuFN9b2xunmvbcWdjNUM666V8EIYwYwztNM1njChO0GMNfMbHC1dwZZ4l5DrxUHY6DGRg16bHYjmTGKC2ahxnqQ2HAtejtBXlnGf-J66Pq9R6MZ_q7VWrNuL70ZnRfqKKSZMCu9Po_zcyGFPY9JltDzNRQkrita1s4515WQiFy_K17jGfYvRJegGkSvcM-0AY2Z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