Crash when using a generic function
toolchain
### Description of the bug:
Compiling the following code result in a crash:
```carbon
import Core library "io";
fn Fun[N :! Core.IntLiteral()](x : Core.Int(N)) -> Core.Int(N) {
var zero : Core.Int(N) = 0;
if (x < zero) {
return -x;
} else {
return x;
}
}
fn Run() -> i32 {
var f : i32 = -1;
var g : i32 = Fun(f);
return 0;
}
```
### What did you do, or what's a simple way to reproduce the bug?
Try compiling the code above with
```shell
carbon compile test.carbon
```
I get the following error
```shell
test.carbon:14:6: warning: binding `g` unused
<09>var g : i32 = Fun(f);
^
Please report issues to https://github.com/carbon-language/carbon-lang/issues and include the crash backtrace.
Stack dump:
0. Program arguments: carbon compile test.carbon
1. Carbon version: 0.0.0-0.nightly.2026.03.12+c1fd771
2. Pending diagnostics:
3. Filename: test.carbon
4. test.carbon:3:1: Lowering function Fun(32)
fn Fun[N :! Core.IntLiteral()](x : Core.Int(N)) -> Core.Int(N) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5. test.carbon:4:2: Lowering call
<09>var zero : Core.Int(N) = 0;
^~~~~~~~~~~~~~~~~~~~~~
#0 0x0000557821802c28 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/local/bin/carbon+0x87b7c28)
#1 0x00005578217ff9e4 llvm::sys::RunSignalHandlers() (/usr/local/bin/carbon+0x87b49e4)
#2 0x0000557821803711 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#3 0x00007ff7073fbdf0 (/lib/x86_64-linux-gnu/libc.so.6+0x3fdf0)
#4 0x00007ff70745095c (/lib/x86_64-linux-gnu/libc.so.6+0x9495c)
#5 0x00007ff7073fbcc2 raise (/lib/x86_64-linux-gnu/libc.so.6+0x3fcc2)
#6 0x00007ff7073e44ac abort (/lib/x86_64-linux-gnu/libc.so.6+0x284ac)
#7 0x000055781cb95f58 Carbon::Internal::CheckFailImpl(char const*, char const*, int, char const*, llvm::StringRef) (/usr/local/bin/carbon+0x3b4af58)
#8 0x000055781caa147c void Carbon::Internal::CheckFail<Carbon::TemplateString<5>{"FATAL"}, Carbon::TemplateString<31>{"toolchain/lower/handle_call.cpp"}, 551, Carbon::TemplateString<0>{}, Carbon::TemplateString<57>{"Missing constant value for call to comptime-only function"}>() (/usr/local/bin/carbon+0x3a5647c)
#9 0x000055781caa07b0 Carbon::Lower::HandleInst(Carbon::Lower::FunctionContext&, Carbon::SemIR::InstId, Carbon::SemIR::Call) (/usr/local/bin/carbon+0x3a557b0)
#10 0x000055781ca8c36b Carbon::Lower::FunctionContext::LowerInst(Carbon::SemIR::InstId) (/usr/local/bin/carbon+0x3a4136b)
#11 0x000055781ca8bc71 Carbon::Lower::FunctionContext::LowerBlockContents(Carbon::SemIR::InstBlockId) (/usr/local/bin/carbon+0x3a40c71)
#12 0x000055781ca7a369 Carbon::Lower::FileContext::BuildFunctionBody(Carbon::SemIR::FunctionId, Carbon::SemIR::SpecificId, Carbon::SemIR::Function const&, Carbon::Lower::FileContext&, Carbon::SemIR::Function const&) (/usr/local/bin/carbon+0x3a2f369)
#13 0x000055781ca75ebc Carbon::Lower::Context::Finalize() && (/usr/local/bin/carbon+0x3a2aebc)
#14 0x000055781ca74f4f Carbon::Lower::LowerToLLVM(llvm::LLVMContext&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, Carbon::FixedSizeValueStore<Carbon::SemIR::CheckIRId, llvm::function_ref<Carbon::Parse::TreeAndSubtrees const& ()>, Carbon::Untagged> const&, Carbon::SemIR::File const&, int, Carbon::Lower::LowerToLLVMOptions const&) (/usr/local/bin/carbon+0x3a29f4f)
#15 0x000055781bbd25e9 void llvm::function_ref<void ()>::callback_fn<Carbon::(anonymous namespace)::CompilationUnit::RunLower()::$_0>(long) compile_subcommand.cpp:0:0
#16 0x000055781bbcec4e Carbon::(anonymous namespace)::CompilationUnit::LogCall(llvm::StringLiteral, llvm::StringLiteral, llvm::function_ref<void ()>) compile_subcommand.cpp:0:0
#17 0x000055781bbcbd20 Carbon::CompileSubcommand::Run(Carbon::DriverEnv&) (/usr/local/bin/carbon+0x2b80d20)
#18 0x000055781bbc0c24 Carbon::Driver::RunCommand(llvm::ArrayRef<llvm::StringRef>) (/usr/local/bin/carbon+0x2b75c24)
#19 0x000055781bb97cbb Carbon::Main(int, char**) busybox_main.cpp:0:0
#20 0x000055781bb95494 main (/usr/local/bin/carbon+0x2b4a494)
#21 0x00007ff7073e5ca8 (/lib/x86_64-linux-gnu/libc.so.6+0x29ca8)
#22 0x00007ff7073e5d65 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29d65)
#23 0x000055781bb953e5 _start (/usr/local/bin/carbon+0x2b4a3e5)
FATAL failure at toolchain/lower/handle_call.cpp:551: Missing constant value for call to comptime-only function
Aborted
```
### What did you expect to happen?
_No response_
### What actually happened?
_No response_
### Any other information, logs, or outputs that you want to share?
_No response_
1 条评论