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

    <tr>
        <th>Summary</th>
        <td>
            [clang][bytecode] Assertion `NumElements.isPositive()' failed.
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang:frontend,
            crash,
            clang:bytecode
      </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/8j5f1To58
```cpp
constexpr void f() {
  int a = -1;
  int *b = new int[a];
}
```

Backtrace:
```console
clang++: /root/llvm-project/llvm/tools/clang/lib/AST/ByteCode/Interp.h:3461: bool clang::interp::AllocN(clang::interp::InterpState&, clang::interp::CodePtr, clang::interp::PrimType, const clang::Expr*, bool) [with clang::interp::PrimType Name = clang::interp::PT_Sint32; SizeT = clang::interp::Integral<32, true>]: Assertion `NumElements.isPositive()' 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: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -fexperimental-new-constant-interpreter <source>
1.      <eof> parser at end of file
2.      <source>:1:20: parsing function body 'f'
 #0 0x000000000400b2d8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x400b2d8)
 #1 0x0000000004008704 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4008704)
 #2 0x0000000003f4d048 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x0000745123c42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x0000745123c969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x0000745123c42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x0000745123c287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x0000745123c2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x0000745123c39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x0000000007af5f06 bool clang::interp::AllocN<(clang::interp::PrimType)4, clang::interp::Integral<32u, true>>(clang::interp::InterpState&, clang::interp::CodePtr, clang::interp::PrimType, clang::Expr const*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7af5f06)
#10 0x0000000007b6d3b1 clang::interp::Interpret(clang::interp::InterpState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7b6d3b1)
#11 0x000000000798e227 clang::interp::Context::isPotentialConstantExpr(clang::interp::State&, clang::FunctionDecl const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x798e227)
#12 0x000000000792e6a2 clang::Expr::isPotentialConstantExpr(clang::FunctionDecl const*, llvm::SmallVectorImpl<std::pair<clang::SourceLocation, clang::PartialDiagnostic>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x792e6a2)
#13 0x0000000006af9366 clang::Sema::CheckConstexprFunctionDefinition(clang::FunctionDecl const*, clang::Sema::CheckConstexprKind) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6af9366)
#14 0x0000000006a80953 clang::Sema::ActOnFinishFunctionBody(clang::Decl*, clang::Stmt*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6a80953)
#15 0x00000000067c65ef clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x67c65ef)
#16 0x00000000066bd483 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66bd483)
#17 0x00000000066f33ad clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66f33ad)
#18 0x00000000066b07ee clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66b07ee)
#19 0x00000000066b0f8f clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66b0f8f)
#20 0x00000000066b8763 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66b8763)
#21 0x00000000066b9675 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66b9675)
#22 0x00000000066b9b30 clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66b9b30)
#23 0x00000000066ab843 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66ab843)
#24 0x00000000049b0d28 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x49b0d28)
#25 0x0000000004ca5115 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ca5115)
#26 0x0000000004c2144e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4c2144e)
#27 0x0000000004d96861 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4d96861)
#28 0x0000000000daf00f cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdaf00f)
#29 0x0000000000da5cba ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#30 0x0000000004a18669 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
#31 0x0000000003f4d4e4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f4d4e4)
#32 0x0000000004a18c7f 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
#33 0x00000000049daf1d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x49daf1d)
#34 0x00000000049dbfae clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x49dbfae)
#35 0x00000000049e39f5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x49e39f5)
#36 0x0000000000dab4c5 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdab4c5)
#37 0x0000000000c5f554 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc5f554)
#38 0x0000745123c29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#39 0x0000745123c29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#40 0x0000000000da5765 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xda5765)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzkWl1z4ygW_TXkhZJLAn0-5EFx4tme7Z1OtVP76kII2UxkoQWUdubXbwFy9JHYnUzF_bA71VPlCLicc7jcewUiSvFtw9g1iG5AdHtFOr0T8vrRI1KKH-qqEOXz9XfWSlF2lEmAc-DnO61bZX6iFUCrrSgLUeuFkFuAVn8BtEr_jKrgQUQp8HMQ--4fbVvg51Q0SrNDK-GT4CWsAEoByiBIboCfQ8gbDQkE-BZ6AcDDM4Dywj5u2A_zAEQ3BES3rgtIbscTmd9-fkPoo5aEMgd5gCEaJWpmoNSk2QJ0Y_7hHAK0kkJogFZ1_bT3Win-ZPT4J0ArLUStAFr1w1Y1LwBa5esHgFY3z5otRckAWn1pNJPtYgdwjsM4MJYLIWrohuEc4JzbLu53XteC_gFQeqLdmVtrohlAMUDLU4bM9PdanulxL_n-4blltotZhnHHu0MrAcpNm4Fr1yS6-cH17mfm4B9kz-zanOr4sFnzRmME8A1c87_Yw7nehvBWkhrgJUYGjpYdA_jOrnYOc6WY1Fw0EMT-H93-rmZ71mi14OpeKK75E3MuBVACK8JrVi6An99_vcvXd1B1xZ4bDyu6LZSsFVJDLeDMn7nedcWCiv2w-DOX4Ep1zDgDJE0JeUPrr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