================
@@ -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());
----------------
adams381 wrote:

No good reason, and it is unconditional now.  The fallout is 86 test files and 
it is all one shape: an on-demand declaration used to be emitted immediately 
before the definition that triggered it, and now it follows it.

@andykaylor, your ordering hunch was right.  Three tests carried a comment 
recording that CIR and classic disagreed on emission order, 
`array-init-loop-exprs.cpp`, `delegating-ctor.cpp` and 
`lambda-generic-in-cxx11abi-lambda.cpp`.  All three now emit in the same order 
as classic, so the comments are gone.  `setjmp.c` had a second check prefix 
that existed only to tolerate the disagreement, and that is gone too.

https://github.com/llvm/llvm-project/pull/207260
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to