aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/ReachingDefAnalysis.cpp
diff options
context:
space:
mode:
authorAlejandro Álvarez Ayllón <alejandro.alvarez@sonarsource.com>2024-12-10 09:17:41 +0100
committerGitHub <noreply@github.com>2024-12-10 09:17:41 +0100
commitc2d7e96cde10a0da6fff8dde9473b508f0ef29ba (patch)
treea80401d0c0c19c19f362d538be8d75c64c3403f0 /llvm/lib/CodeGen/ReachingDefAnalysis.cpp
parenteadc0c901ba3253ee3764f012c60de36e58cbf10 (diff)
downloadllvm-c2d7e96cde10a0da6fff8dde9473b508f0ef29ba.zip
llvm-c2d7e96cde10a0da6fff8dde9473b508f0ef29ba.tar.gz
llvm-c2d7e96cde10a0da6fff8dde9473b508f0ef29ba.tar.bz2
[clang] Fix non-deterministic infinite recursion... (#118288)
...in `ASTContext::getAutoTypeInternal` Given ```cpp template < typename > concept C1 = true; template < typename , auto > concept C2 = true; template < C1 auto V, C2< V > auto> struct S; ``` Both `C1 auto V` and `C2<V> auto` end on the set `AutoType`, the former being a template parameter for the latter. Since the hashing is not deterministic (i.e., pointers are hashed), every now and then, both will end on the same bucket. Given that `FoldingSet` recomputes the `FoldingSetID` for each node in the target bucket on lookup, this triggers an infinite recursion: 1. Look for `X` in `AutoTypes` 2. Let's assume it would be in bucket N, so it iterates over nodes in that bucket. Let's assume the first is `C2<V> auto`. 3. Computes the `FoldingSetID` for this one, which requires the profile of its template parameters, so they are visited. 4. In some frames below, we end on the same `FoldingSet`, and, by chance, `C1 auto V` would be in bucket N too. 5. But the first node in the bucket is `C2<V> auto` for which we need to profile `C1 auto V` 6. ... stack overflow! No step individually does anything wrong, but in general, `FoldingSet` seems not to be re-entrant, and this fact is hidden behind many nested calls. With this change, we store the `AutoType`s inside a `DenseMap` instead. The `FoldingSetID` is computed once only and then kept as the map's key, avoiding the need to do recursive lookups. We also now make sure the key for the inserted `AutoType` is the same as the key used for lookup. Before, this was not the case, and it caused also non-deterministic parsing errors. Fixes https://github.com/llvm/llvm-project/issues/110231
Diffstat (limited to 'llvm/lib/CodeGen/ReachingDefAnalysis.cpp')
0 files changed, 0 insertions, 0 deletions