[clang] [CIR] Insert on-demand functions at module scope (PR #207260)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 2 14:55:18 PDT 2026
================
@@ -3420,8 +3412,15 @@ CIRGenModule::createCIRFunction(mlir::Location loc, StringRef name,
//
// Be sure to insert a new function before a current one.
CIRGenFunction *cgf = this->curCGF;
- if (cgf)
+ if (cgf) {
builder.setInsertionPoint(cgf->curFn);
+ } else {
+ // No CIRGenFunction is active, but the builder's insertion point may
+ // still be inside another op (e.g. a function materialized on demand
+ // while generating a vtable thunk). Insert at module scope so the new
+ // function is not parented under the ambient insertion point.
+ builder.setInsertionPointToEnd(theModule.getBody());
----------------
erichkeane wrote:
Maybe? But this extra branch above just seems silly IMO. Its perhaps worth the fallout just to simplify this a bit, but also like you said, could very well better match OGCG for ordering.
https://github.com/llvm/llvm-project/pull/207260
More information about the cfe-commits
mailing list