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

    <tr>
        <th>Summary</th>
        <td>
            [clang] Runtime call emitted to `consteval` function (regression from 16)
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            c++20,
            clang:frontend,
            consteval
      </td>
    </tr>

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

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

<pre>
    The following code creates a runtime call to `operator""_short_string`, even though it's declared as `consteval`, or triggers an ICE if assertions are enabled. This was observed on a recent commit on `main` (99074aafc31593c9935da483edab1333d6ce5a5b). This issue is not reproducible with Clang 16.

[Godbolt link](https://godbolt.org/z/WezrE8qGr)

```c++
void __assert_rtn(const char *, char const*, int, char const*);
struct StringView {
  constexpr StringView(char const *) {
    if (!__builtin_is_constant_evaluated())
      __builtin_expect(!0, 0) ? __assert_rtn(__func__, "", 9, "") : (void)0;
  }
};
struct String {
  static consteval String from_utf8_short_string(StringView) { return {}; }
};
consteval String operator""_short_string(char const *cstring, unsigned long) {
  return String::from_utf8_short_string(cstring);
}
struct IntersectionObserverInit {
  String root_margin{""_short_string};
};
void start_intersection_observing_a_lazy_loading_element() {
 IntersectionObserverInit{};
}
```

<details>
<summary> Backtrace of Clang crash with assertions enabled </summary>

```
Assertion failed: (!cast<FunctionDecl>(GD.getDecl())->isImmediateFunction() && "an immediate function should never be emitted"), function GetAddrOfFunction, file CodeGenModule.cpp, line 4455.
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: /Users/dani/Source/llvm-project/build/bin/clang -std=c++20 crash.ii -fno-crash-diagnostics -c -o /dev/null
1.      <eof> parser at end of file
2.      crash.ii:18:6: LLVM IR generation of declaration 'start_intersection_observing_a_lazy_loading_element'
3.      crash.ii:18:6: Generating code for declaration 'start_intersection_observing_a_lazy_loading_element'
 #0 0x0000000110009d44 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/Users/dani/Source/llvm-project/build/lib/libLLVM.dylib+0x139d44)
 #1 0x0000000110008260 llvm::sys::RunSignalHandlers() (/Users/dani/Source/llvm-project/build/lib/libLLVM.dylib+0x138260)
 #2 0x00000001100094dc llvm::sys::CleanupOnSignal(unsigned long) (/Users/dani/Source/llvm-project/build/lib/libLLVM.dylib+0x1394dc)
 #3 0x000000010ff6299c CrashRecoverySignalHandler(int) (/Users/dani/Source/llvm-project/build/lib/libLLVM.dylib+0x9299c)
 #4 0x0000000182579a24 (/usr/lib/system/libsystem_platform.dylib+0x180465a24)
 #5 0x000000018254acc0 (/usr/lib/system/libsystem_pthread.dylib+0x180436cc0)
 #6 0x000000018245aa80 (/usr/lib/system/libsystem_c.dylib+0x180346a80)
 #7 0x0000000182459d9c (/usr/lib/system/libsystem_c.dylib+0x180345d9c)
 #8 0x000000010acaf2b8 clang::CodeGen::CodeGenModule::GetAddrOfFunction(clang::GlobalDecl, llvm::Type*, bool, bool, clang::CodeGen::ForDefinition_t) (.cold.3) (/Users/dani/Source/llvm-project/build/lib/libclang-cpp.dylib+0x2a372b8)
 #9 0x0000000109715208 clang::CodeGen::CodeGenModule::GetAddrOfFunction(clang::GlobalDecl, llvm::Type*, bool, bool, clang::CodeGen::ForDefinition_t) (/Users/dani/Source/llvm-project/build/lib/libclang-cpp.dylib+0x149d208)
#10 0x000000010959690c EmitFunctionDeclPointer(clang::CodeGen::CodeGenModule&, clang::GlobalDecl) (/Users/dani/Source/llvm-project/build/lib/libclang-cpp.dylib+0x131e90c)
#11 0x000000010959593c EmitDirectCallee(clang::CodeGen::CodeGenFunction&, clang::GlobalDecl) (/Users/dani/Source/llvm-project/build/lib/libclang-cpp.dylib+0x131d93c)
#12 0x0000000109594698 clang::CodeGen::CodeGenFunction::EmitCallee(clang::Expr const*) (/Users/dani/Source/llvm-project/build/lib/libclang-cpp.dylib+0x131c698)
#13 0x0000000109594334 clang::CodeGen::CodeGenFunction::EmitCallExpr(clang::CallExpr const*, clang::CodeGen::ReturnValueSlot) (/Users/dani/Source/llvm-project/build/lib/libclang-cpp.dylib+0x131c334)
#14 0x00000001095a1538 clang::CodeGen::RValue llvm::function_ref<clang::CodeGen::RValue (clang::CodeGen::ReturnValueSlot)>::callback_fn<(anonymous namespace)::AggExprEmitter::VisitCallExpr(clang::CallExpr const*)::$_0>(long, clang::CodeGen::ReturnValueSlot) (/Users/dani/Source/llvm-project/build/lib/libclang-cpp.dylib+0x1329538)
#15 0x00000001095a1418 (anonymous namespace)::AggExprEmitter::withReturnValueSlot(clang::Expr const*, llvm::function_ref<clang::CodeGen::RValue (clang::CodeGen::ReturnValueSlot)>) (/Users/dani/Source/llvm-project/build/lib/libclang-cpp.dylib+0x1329418)
#16 0x000000010959ce00 (anonymous namespace)::AggExprEmitter::VisitCallExpr(clang::CallExpr const*) (/Users/dani/Source/llvm-project/build/lib/libclang-cpp.dylib+0x1324e00)
#17 0x000000010959d810 (anonymous namespace)::AggExprEmitter::VisitInitListExpr(clang::InitListExpr*) (/Users/dani/Source/llvm-project/build/lib/libclang-cpp.dylib+0x1325810)
#18 0x000000010959c498 (anonymous namespace)::AggExprEmitter::VisitCXXDefaultInitExpr(clang::CXXDefaultInitExpr*) (/Users/dani/Source/llvm-project/build/lib/libclang-cpp.dylib+0x1324498)
#19 0x0000000109597758 clang::CodeGen::CodeGenFunction::EmitAggExpr(clang::Expr const*, clang::CodeGen::AggValueSlot) (/Users/dani/Source/llvm-project/build/lib/libclang-cpp.dylib+0x131f758)
#20 0x000000010959f7d4 (anonymous namespace)::AggExprEmitter::EmitInitializationToLValue(clang::Expr*, clang::CodeGen::LValue) (/Users/dani/Source/llvm-project/build/lib/libclang-cpp.dylib+0x13277d4)
#21 0x00000001095a0400 (anonymous namespace)::AggExprEmitter::VisitCXXParenListOrInitListExpr(clang::Expr*, llvm::ArrayRef<clang::Expr*>, clang::FieldDecl*, clang::Expr*) (/Users/dani/Source/llvm-project/build/lib/libclang-cpp.dylib+0x1328400)
#22 0x00000001095a1ddc (anonymous namespace)::AggExprEmitter::VisitCastExpr(clang::CastExpr*) (/Users/dani/Source/llvm-project/build/lib/libclang-cpp.dylib+0x1329ddc)
#23 0x0000000109597758 clang::CodeGen::CodeGenFunction::EmitAggExpr(clang::Expr const*, clang::CodeGen::AggValueSlot) (/Users/dani/Source/llvm-project/build/lib/libclang-cpp.dylib+0x131f758)
#24 0x000000010957cf30 clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr const*, clang::CodeGen::AggValueSlot, bool) (/Users/dani/Source/llvm-project/build/lib/libclang-cpp.dylib+0x1304f30)
#25 0x000000010957cd7c clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) (/Users/dani/Source/llvm-project/build/lib/libclang-cpp.dylib+0x1304d7c)
#26 0x000000010969b52c clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/Users/dani/Source/llvm-project/build/lib/libclang-cpp.dylib+0x142352c)
#27 0x00000001096a4db0 clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/Users/dani/Source/llvm-project/build/lib/libclang-cpp.dylib+0x142cdb0)
#28 0x00000001096f5538 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/Users/dani/Source/llvm-project/build/lib/libclang-cpp.dylib+0x147d538)
#29 0x00000001096f5e6c clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/Users/dani/Source/llvm-project/build/lib/libclang-cpp.dylib+0x147de6c)
#30 0x0000000109713a98 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/Users/dani/Source/llvm-project/build/lib/libclang-cpp.dylib+0x149ba98)
#31 0x000000010970d9c4 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/Users/dani/Source/llvm-project/build/lib/libclang-cpp.dylib+0x14959c4)
#32 0x0000000109711558 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/Users/dani/Source/llvm-project/build/lib/libclang-cpp.dylib+0x1499558)
#33 0x000000010970c648 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (/Users/dani/Source/llvm-project/build/lib/libclang-cpp.dylib+0x1494648)
#34 0x00000001097a42d8 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) (/Users/dani/Source/llvm-project/build/lib/libclang-cpp.dylib+0x152c2d8)
#35 0x00000001096ec3f8 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/Users/dani/Source/llvm-project/build/lib/libclang-cpp.dylib+0x14743f8)
#36 0x00000001083d9d20 clang::ParseAST(clang::Sema&, bool, bool) (/Users/dani/Source/llvm-project/build/lib/libclang-cpp.dylib+0x161d20)
#37 0x000000010a0678a4 clang::FrontendAction::Execute() (/Users/dani/Source/llvm-project/build/lib/libclang-cpp.dylib+0x1def8a4)
#38 0x000000010a0021d8 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/Users/dani/Source/llvm-project/build/lib/libclang-cpp.dylib+0x1d8a1d8)
#39 0x000000010a0dea68 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/Users/dani/Source/llvm-project/build/lib/libclang-cpp.dylib+0x1e66a68)
#40 0x00000001001b32f4 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/Users/dani/Source/llvm-project/build/bin/clang-17+0x10000b2f4)
#41 0x00000001001afab4 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) (/Users/dani/Source/llvm-project/build/bin/clang-17+0x100007ab4)
#42 0x0000000109d04728 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::__1::optional<llvm::StringRef>>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>*, bool*) const::$_1>(long) (/Users/dani/Source/llvm-project/build/lib/libclang-cpp.dylib+0x1a8c728)
#43 0x000000010ff626bc llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/Users/dani/Source/llvm-project/build/lib/libLLVM.dylib+0x926bc)
#44 0x0000000109d04100 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::__1::optional<llvm::StringRef>>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>*, bool*) const (/Users/dani/Source/llvm-project/build/lib/libclang-cpp.dylib+0x1a8c100)
#45 0x0000000109cd39e4 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/Users/dani/Source/llvm-project/build/lib/libclang-cpp.dylib+0x1a5b9e4)
#46 0x0000000109cd3c14 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::__1::pair<int, clang::driver::Command const*>>&, bool) const (/Users/dani/Source/llvm-project/build/lib/libclang-cpp.dylib+0x1a5bc14)
#47 0x0000000109ceb58c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::__1::pair<int, clang::driver::Command const*>>&) (/Users/dani/Source/llvm-project/build/lib/libclang-cpp.dylib+0x1a7358c)
#48 0x00000001001aed58 clang_main(int, char**, llvm::ToolContext const&) (/Users/dani/Source/llvm-project/build/bin/clang-17+0x100006d58)
#49 0x00000001001bbb28 main (/Users/dani/Source/llvm-project/build/bin/clang-17+0x100013b28)
#50 0x00000001821d1058 
clang: error: clang frontend command failed with exit code 134 (use -v to see invocation)
```

</details>

Will try to bisect.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsW19z2yyX_zTKDZOMBPp7kQvHibN5p--002T79M6DANlsEXgBpU0__Q5ItoViJ21aP312djOZREIIzu93DuccEGB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