This is an archive of the discontinued LLVM Phabricator instance.

msabi: Fix exponential mangling time for even more contrived inputs
ClosedPublic

Authored by thakis on Jun 1 2019, 9:56 AM.

Details

Summary

This is a follow-up to r362293 which fixed exponential time needed
for mangling certain templates. This fixes the same issue if that
template pattern happens in template arguments > 10: The first
ten template arguments can use back references, and r362293 added
caching for back references. For latter arguments, we have to add
a cache for the mangling itself instead.

Fixes PR42091 even more.

Diff Detail

Repository
rL LLVM

Event Timeline

thakis created this revision.Jun 1 2019, 9:56 AM
rnk added inline comments.Jun 3 2019, 11:37 AM
clang/lib/AST/MicrosoftMangle.cpp
819–823 ↗(On Diff #202561)

Here's a thought: could we get by with one map? I think we can be certain that nothing mangles to integer literals between 0 and 9, since otherwise the demangler couldn't distinguish those from back references. So, can we keep the string map, and insert the string "0", "1", etc for back referenced things?

thakis marked an inline comment as done.Jun 3 2019, 3:25 PM
thakis added inline comments.
clang/lib/AST/MicrosoftMangle.cpp
819–823 ↗(On Diff #202561)

I had wondered too. In the end, I figured the int map needs less memory and is almost always enough, so I went with this approach.

rnk accepted this revision.Jun 4 2019, 4:07 PM

lgtm

clang/lib/AST/MicrosoftMangle.cpp
819–823 ↗(On Diff #202561)

I think I'm coming at this more from the perspective of less code complexity, fewer ifs, fewer data structures to name and have to understand. We could get the memory wins by storing numbers in the map, and then having a side vector of numbered strings, indexed by BackrefId-10. Then that data structure would be seldom used. Anyway, it's all code golf, not really important.

This revision is now accepted and ready to land.Jun 4 2019, 4:07 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJun 4 2019, 4:25 PM