summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2023-09-29 19:10:22 -0400
committerGitHub <noreply@github.com>2023-09-29 16:10:22 -0700
commit6138de5f084cafdc98381237c2d8bed7c8804f1c (patch)
treeed6530954c9f4a19447b094ce62a237c3eb19978
parentf20f4e2b39142dfab55be05eea064033719665ad (diff)
Fix for problem with OrderedHashSet causing crash (#3251)
* Fix for problem with OrderedHashSet causing crashes during running tests on on g++ 7.3 * Fix typo
-rw-r--r--premake5.lua3
-rw-r--r--source/core/slang-dictionary.h33
2 files changed, 32 insertions, 4 deletions
diff --git a/premake5.lua b/premake5.lua
index 3e4ac1100..98bb2b6a0 100644
--- a/premake5.lua
+++ b/premake5.lua
@@ -403,6 +403,9 @@ workspace "slang"
}
filter { "toolset:gcc*", "language:C++" }
buildoptions { "-Wno-class-memaccess" }
+ -- If a function returns an address/reference to a local, we want it to produce an error, because
+ -- it probably means something very bad.
+ buildoptions { "-Werror=return-local-addr" }
filter { "toolset:clang", "language:C++" }
buildoptions { "-Wno-assume" }
filter { "toolset:clang or gcc*", "language:C++" }
diff --git a/source/core/slang-dictionary.h b/source/core/slang-dictionary.h
index ff7e201bf..ba4672740 100644
--- a/source/core/slang-dictionary.h
+++ b/source/core/slang-dictionary.h
@@ -75,6 +75,32 @@ namespace Slang
return KeyValuePair<TKey, TValue>(k, v);
}
+ namespace KeyValueDetail {
+
+ template <typename KEY, typename VALUE>
+ SLANG_FORCE_INLINE const KEY* getKey(const std::pair<KEY, VALUE>* in)
+ {
+ return &in->first;
+ }
+ template <typename KEY, typename VALUE>
+ SLANG_FORCE_INLINE const KEY* getKey(const KeyValuePair<KEY, VALUE>* in)
+ {
+ return &in->key;
+ }
+
+ template <typename KEY, typename VALUE>
+ SLANG_FORCE_INLINE const VALUE* getValue(const std::pair<KEY, VALUE>* in)
+ {
+ return &in->second;
+ }
+ template <typename KEY, typename VALUE>
+ SLANG_FORCE_INLINE const VALUE* getValue(const KeyValuePair<KEY, VALUE>* in)
+ {
+ return &in->value;
+ }
+
+ } // namespace KeyValueDetail
+
const float kMaxLoadFactor = 0.7f;
template<typename TKey, typename TValue, typename Hash = Slang::Hash<TKey>, typename KeyEqual = std::equal_to<TKey>>
@@ -321,14 +347,13 @@ namespace Slang
Iterator() = default;
const T& operator*() const
{
- const auto& [k, v] = *iter;
- return k;
+ return *KeyValueDetail::getKey(std::addressof(*iter));
}
const T* operator->() const
{
- const auto& [k, v] = *iter;
- return &k;
+ return KeyValueDetail::getKey(std::addressof(*iter));
}
+
Iterator& operator++()
{
++iter;