Skip to content

Commit 74be3aa

Browse files
committed
Use getSymbolID instead of raw pointer values for SymbolRef ordering
1 parent 5e5adba commit 74be3aa

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "llvm/ADT/DenseMap.h"
2626
#include "llvm/ADT/DenseSet.h"
2727
#include "llvm/ADT/FoldingSet.h"
28+
#include "llvm/ADT/ImmutableSet.h"
2829
#include "llvm/ADT/iterator_range.h"
2930
#include "llvm/Support/Allocator.h"
3031
#include <cassert>
@@ -710,4 +711,35 @@ class SymbolVisitor {
710711

711712
} // namespace clang
712713

714+
// Override the default definition that would use pointer values of SymbolRefs
715+
// to order them, which is unstable due to ASLR.
716+
// Use the SymbolID instead which reflect the order in which the symbols were
717+
// allocated. This is usually stable across runs leading to the stability of
718+
// ConstraintMap and other containers using SymbolRef as keys.
719+
template <>
720+
struct ::llvm::ImutContainerInfo<clang::ento::SymbolRef>
721+
: public ImutProfileInfo<clang::ento::SymbolRef> {
722+
using value_type =
723+
typename ImutProfileInfo<clang::ento::SymbolRef>::value_type;
724+
using value_type_ref =
725+
typename ImutProfileInfo<clang::ento::SymbolRef>::value_type_ref;
726+
using key_type = value_type;
727+
using key_type_ref = value_type_ref;
728+
using data_type = bool;
729+
using data_type_ref = bool;
730+
731+
static key_type_ref KeyOfValue(value_type_ref D) { return D; }
732+
static data_type_ref DataOfValue(value_type_ref) { return true; }
733+
734+
static bool isEqual(key_type_ref LHS, key_type_ref RHS) {
735+
return LHS->getSymbolID() == RHS->getSymbolID();
736+
}
737+
738+
static bool isLess(key_type_ref LHS, key_type_ref RHS) {
739+
return LHS->getSymbolID() < RHS->getSymbolID();
740+
}
741+
742+
static bool isDataEqual(data_type_ref, data_type_ref) { return true; }
743+
};
744+
713745
#endif // LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SYMBOLMANAGER_H

0 commit comments

Comments
 (0)