This is an archive of the discontinued LLVM Phabricator instance.

[flang] Avoid ICE in case of subprogram name clash with runtime namespace.
ClosedPublic

Authored by vzakhari on Mar 8 2023, 10:40 PM.

Details

Summary

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.

Diff Detail

Event Timeline

vzakhari created this revision.Mar 8 2023, 10:40 PM
vzakhari requested review of this revision.Mar 8 2023, 10:40 PM
clementval added inline comments.Mar 9 2023, 4:35 AM
flang/lib/Lower/ConvertCall.cpp
309

So is it meant only for compiler dev?

All builds and tests correctly, but I don't see the results I would expect.

flang/lib/Lower/ConvertCall.cpp
310–314

I built a compiler with this change and then ran the resulting bbc on the test program listed in https://github.com/llvm/llvm-project/issues/61074. But I didn't see this message in the debug output. My command line was bbc -emit-fir -debug test.f90. I would have expected a debug message to appear in the output.

vzakhari added inline comments.Mar 12 2023, 4:21 PM
flang/lib/Lower/ConvertCall.cpp
129

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.

clementval accepted this revision.Mar 13 2023, 6:31 AM

Fine for me if this is the intended behavior.

This revision is now accepted and ready to land.Mar 13 2023, 6:31 AM

Fine for me if this is the intended behavior.

Thanks!