This is related to llvm-project#61074.
In general, it is undefined behavior if user subprogram is declared
with a name that matches a name of function from any runtime library
that Flang is using (e.g. FortranRuntime, libm, etc.). With this change-set
we avoid ICE for invalid calls generated during math lowering by
type casing the function before the call. This happens when a user function
call is lowered before the math function call with the same name.
To detect the name clash in cases when the math function call is lowered
before the user function call we set fir.runtime attribute for the math
functions and check it when we lower the user function call.
The warnings are currently emitted only in debug compiler and
under llvm debug options. I think they should be reported
in the same way as regular Flang warnings.
Note that this change-set does not resolve issues with the conversion
passes that might introduce libm calls after the lowering.
Yes, the warnings are only printed under -debug-only=flang-lower-intrinsic,flang-lower-expr. For the initial change-set I followed these lines here.
I am not sure if we should be reporting user-visible warnings via mlir::emitWarning during the lowering. I guess we may want to use the parser::Messages and also support warnings-as-errors. If the debug-only warnings look reasonable to you, I can check how to emit the warnings in a way consistent with parser/semantics. Though, I was not aiming at proper warnings emission in the current change-set.