This might be a bug, the Symbol References that refer to the current FuncOp symbol were not updated after modification to the FuncOp symbol. This results in not being able to find functions in the module later in the lowering via operations containing SymbolRef's as they have stale symbols.
This showed as a problem in OpenMPToLLVMIRTranslation.cpp where the Flang compiler has lowered from FIR + friends to LLVM Dialect + OpenMP. When we have an OpenMP operation that was populated during the PFT lowering to MLIR; that has a SymbolRef referring to a FuncOp symbol, the symbols would not match later on when we try to lower it further during the OpenMPToLLVMIRTranslation phase where we lower to LLVM IR.
The options -emit-mlir and -emit-fir seem to occur before the rewriting that occurs inside of the ExternalNameConversion.cpp file, so the problem is a little opaque when using just -emit-mlir, however, comparing -emit-llvm and -emit-mlir indicates different function symbol mangling. This occurs during some stage of MLIR lowering to other MLIR dialects, so it may pose issues to other MLIR dialects that get intermixed with Flang.
This SymbolRef mismatch could be an issue for other operations that are rewritten inside of ExternalNameConversion.cpp as they also do not seem to update their SymbolRefs. There are rewrite rules for CallOp, GlobalOp and AddrOfOp within ExternalNameConversion.cpp that may be impacted by similar issues to FuncOp. I currently do not have test cases for these at the moment, so I have left them be for now, but I am happy to modify them if someone with more knowledge believes it's correct to replicate the behavior in this patch across them all (if this is indeed a bug and the desired fix for it).
We use fully qualified names