Skip to content

Conversation

@HighCommander4
Copy link
Collaborator

No description provided.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Feb 11, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 11, 2025

@llvm/pr-subscribers-clang

Author: Nathan Ridge (HighCommander4)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/126690.diff

1 Files Affected:

  • (modified) clang/lib/Sema/HeuristicResolver.cpp (+5-1)
diff --git a/clang/lib/Sema/HeuristicResolver.cpp b/clang/lib/Sema/HeuristicResolver.cpp
index 3cbf33dcdced38..adce403412f689 100644
--- a/clang/lib/Sema/HeuristicResolver.cpp
+++ b/clang/lib/Sema/HeuristicResolver.cpp
@@ -258,7 +258,11 @@ QualType HeuristicResolverImpl::simplifyType(QualType Type, const Expr *E,
     }
     return T;
   };
-  while (!Current.Type.isNull()) {
+  // As an additional protection against infinite loops, bound the number of
+  // simplification steps.
+  size_t StepCount = 0;
+  const size_t MaxSteps = 64;
+  while (!Current.Type.isNull() && StepCount++ < MaxSteps) {
     TypeExprPair New = SimplifyOneStep(Current);
     if (New.Type == Current.Type)
       break;

@HighCommander4
Copy link
Collaborator Author

This is not needed to fix #126536 (#126689 does that), it's a hedge against additional bugs that may be lurking that cause infinite loops.

I'm open to suggestions as to whether this is a good idea. It may hide some bugs, but the symptoms of those bugs are much less severe (incorrect or failed heuristic resolution of a dependent name in a template) than an infinite loop.

@kadircet
Copy link
Member

what about landing this one, and cherry picking it into the 20 release. then we can land #126689 and revert this one. giving us the next release cycle to vet the underlying change?

@kadircet
Copy link
Member

going to land this one, since review of #126689 can take longer and this should enable us to unblock our releases. I am happy to revert afterwards.

@kadircet kadircet merged commit 7808946 into users/HighCommander4/issue-126536 Feb 11, 2025
9 of 10 checks passed
@kadircet kadircet deleted the users/HighCommander4/issue-126536-additional branch February 11, 2025 08:12
@kadircet
Copy link
Member

oops I wasn't looking at the target branch :( let me cherry-pick this into main

@HighCommander4
Copy link
Collaborator Author

and cherry picking it into the 20 release

The regressing change, which introduced the simplifyType() function, isn't present on the llvm 20 branch (it landed a bit after the branch cut). So there should not be a need to cherry-pick the fix onto the llvm 20 branch either.

kadircet pushed a commit that referenced this pull request Feb 11, 2025
Icohedron pushed a commit to Icohedron/llvm-project that referenced this pull request Feb 11, 2025
joaosaffran pushed a commit to joaosaffran/llvm-project that referenced this pull request Feb 14, 2025
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants