This is an archive of the discontinued LLVM Phabricator instance.

[clang] Fix an infinite loop during typo-correction
ClosedPublic

Authored by hokein on Jul 6 2021, 11:48 PM.

Diff Detail

Event Timeline

hokein requested review of this revision.Jul 6 2021, 11:48 PM
hokein created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptJul 6 2021, 11:48 PM
hokein retitled this revision from [clang] Fix an infinite loop during typo-correction See https://bugs.llvm.org/show_bug.cgi?id=50797#c6 to [clang] Fix an infinite loop during typo-correction.Jul 6 2021, 11:49 PM
hokein edited the summary of this revision. (Show Details)
sammccall accepted this revision.Jul 7 2021, 1:55 AM

Great analysis, and the bailout seems reasonable. The overall algorithm seems terribly confusing though :-(

clang/lib/Sema/SemaExprCXX.cpp
8338

Comment is good but maybe could mention the high-level effect of breaking out (treat as unambiguous)

This revision is now accepted and ready to land.Jul 7 2021, 1:55 AM
dgoldman added inline comments.Jul 7 2021, 8:11 AM
clang/lib/Sema/SemaExprCXX.cpp
8338

At this point we know the tree is so invalid that transforming no longer works, so our correction didn't really help. Is it even worth suggesting a correction (if we treat it as ambiguous we won't)?

8339–8342

Is all of this needed - can you just change the while below to also be && Next != TC? Could move Next assignment up into the body if we want to change how we handle stalled progress

dgoldman added inline comments.Jul 7 2021, 9:51 AM
clang/lib/Sema/SemaExprCXX.cpp
8338

Nevermind, misunderstood, left some comments on the bug there. What happens if the right correction actually was ambiguous though? Would we skip it here?

clang/test/Sema/typo-correction-no-hang.c
5–15

Could you add another test case for the same thing but making the correction ambiguous, e.g. g_998 or similar?

hokein updated this revision to Diff 357313.Jul 8 2021, 12:00 PM
hokein marked an inline comment as done.

refine the fix based on the discussion: https://bugs.llvm.org/show_bug.cgi?id=50797#c13

dgoldman accepted this revision.Jul 8 2021, 3:31 PM

Thanks! Just to confirm, the non-simplified example is also fixed, right?

struct a {
  int xxx;
};

int g_107;
int g_108;
int g_109;

struct a g_999;

void b() { (g_910.xxx = g_910.xxx1); }
hokein added a comment.Jul 9 2021, 2:50 AM

Thanks! Just to confirm, the non-simplified example is also fixed, right?

struct a {
  int xxx;
};

int g_107;
int g_108;
int g_109;

struct a g_999;

void b() { (g_910.xxx = g_910.xxx1); }

yeah, it works, added to the test.

hokein updated this revision to Diff 357460.Jul 9 2021, 2:51 AM

add the non-simplified sample.

This revision was landed with ongoing or failed builds.Jul 9 2021, 3:04 AM
This revision was automatically updated to reflect the committed changes.