This is an archive of the discontinued LLVM Phabricator instance.

[flang] Fixed global name creation for literal constants.
ClosedPublic

Authored by vzakhari on May 11 2023, 10:01 AM.

Details

Summary

The global names were created using a hash based on the address
of std::vector::data address. Since the memory may be reused
by different std::vector's, this may cause non-equivalent
constant expressions to map to the same name. This is what is happening
in the modified flang/test/Lower/constant-literal-mangling.f90 test.

I changed the name creation to use a map between the constant expressions
and corresponding unique names. The uniquing is done using a name counter
in FirConverter. The effect of this change is that the equivalent
constant expressions are now mapped to the same global, and the naming
is "stable" (i.e. it does not change from compilation to compilation).

Though, the issue is not HLFIR specific it was affecting several tests
when using HLFIR lowering.

Diff Detail

Event Timeline

vzakhari created this revision.May 11 2023, 10:01 AM
vzakhari requested review of this revision.May 11 2023, 10:01 AM
PeteSteinfeld accepted this revision.May 11 2023, 6:33 PM

Apart from a couple of superfluous includes, all builds and tests correctly and looks good.

Thanks for spotting and fixing this!

flang/include/flang/Lower/IterationSpace.h
18

I don't think that this include is needed.

flang/lib/Lower/ConvertConstant.cpp
19

I don't think that this include is needed.

This revision is now accepted and ready to land.May 11 2023, 6:33 PM

Apart from a couple of superfluous includes, all builds and tests correctly and looks good.

Thanks for spotting and fixing this!

Thank you, Pete! I removed the includes.

vzakhari updated this revision to Diff 521547.May 11 2023, 8:26 PM

I tried several versions of clang-format on flang/include/flang/Lower/Mangler.h, but they did not make any formatting change. I am not sure why the pre-commit complains about it. @PeteSteinfeld, could you please try clang-format on your side?

vzakhari updated this revision to Diff 521666.May 12 2023, 8:48 AM

Just a rebase.

I tried several versions of clang-format on flang/include/flang/Lower/Mangler.h, but they did not make any formatting change. I am not sure why the pre-commit complains about it. @PeteSteinfeld, could you please try clang-format on your side?

I see diffs when running clang-format. I'm using version 16.0.0 of clang-format, which I believe is the latest released version --

clang-format --version
clang-format version 16.0.0 (https://github.com/llvm/llvm-project.git 08d094a0e457360ad8b94b017d2dc277e697ca76)
jeanPerier accepted this revision.May 12 2023, 11:48 AM

Thank you Slava!

vzakhari updated this revision to Diff 521758.May 12 2023, 12:20 PM

clang-format