[clang] [Clang] Instantiate functions from constant evaluation. (PR #205557)

Daniel M. Katz via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 26 05:28:44 PDT 2026


================
@@ -1776,15 +1777,28 @@ bool CheckBitCast(InterpState &S, CodePtr OpPC, const Type *TargetType,
   return true;
 }
 
-static void compileFunction(InterpState &S, const Function *Func) {
-  const FunctionDecl *Definition;
-  if (!Func->getDecl()->getBody(Definition))
-    return;
-  if (!Definition)
+static void compileFunction(InterpState &S, const Function *Func,
+                            CodePtr OpPC) {
+  const FunctionDecl *Fn = Func->getDecl();
+
+  // [C++26] [temp.inst] p5
+  // [...] the function template specialization is implicitly instantiated
+  // when the specialization is referenced in a context that requires a function
+  // definition to exist or if the existence of the definition affects the
+  // semantics of the program.
+  if (FunctionDefinitionCanBeLazilyInstantiated(Fn) && S.inConstantContext()) {
+    SemaProxy *SP = S.getSemaProxy();
+    if (!SP)
+      return;
+    SP->instantiateFunctionDefinition(S.Current->getLocation(OpPC),
+                                      const_cast<FunctionDecl *>(Fn));
+  }
+  Fn = Fn->getDefinition();
----------------
katzdm wrote:

Ah, whoops! Thanks for pointing out the regression. Fixed.

https://github.com/llvm/llvm-project/pull/205557


More information about the cfe-commits mailing list