[DeclContext] Sort the Decls before adding into DeclContext
authorSteven Wu <stevenwu@apple.com>
Thu, 2 Feb 2023 23:07:16 +0000 (15:07 -0800)
committerSteven Wu <stevenwu@apple.com>
Thu, 2 Feb 2023 23:16:20 +0000 (15:16 -0800)
commit0480748ea6728392886931b8470969ae17aaa91f
treebcabf0a48345ba67755101263d9be79b7bedcf40
parentbf07de38b05e4c952beb4009aa15060d0e4f7cc7
[DeclContext] Sort the Decls before adding into DeclContext

Fix a non-deterministic issue in clang module generation, which the
anonymous declaration number from a function context is not
deterministic. This is due to the unstable iteration order for decls in
scope so the order after moving the decls into function decl context is
not deterministic.

From https://reviews.llvm.org/D135118, we can't use a set that preserves
the order without the performance penalty. Fix the issue by sorting the
decls based on raw encoding of their source location.

rdar://104097976

Reviewed By: akyrtzi, vsapsai

Differential Revision: https://reviews.llvm.org/D141625
clang/lib/Parse/ParseDecl.cpp
clang/test/Modules/decl-params-determinisim.m [new file with mode: 0644]