Skip to content

Conversation

kazutakahirata
Copy link
Contributor

This patch consolidates DenseMapInfo for integer types T with a
common templated implementation. DenseMapInfo is excluded
because it uses ~0 for the empty key despite char being a signed type.
Also, we preserve the tombstone key value for long, which is:

std::numeric_limits::max() - 1

This patch consolidates DenseMapInfo<T> for integer types T with a
common templated implementation.  DenseMapInfo<char> is excluded
because it uses ~0 for the empty key despite char being a signed type.
Also, we preserve the tombstone key value for long, which is:

  std::numeric_limits<long>::max() - 1
@llvmbot
Copy link
Member

llvmbot commented Aug 27, 2025

@llvm/pr-subscribers-llvm-adt

Author: Kazu Hirata (kazutakahirata)

Changes

This patch consolidates DenseMapInfo<T> for integer types T with a
common templated implementation. DenseMapInfo<char> is excluded
because it uses ~0 for the empty key despite char being a signed type.
Also, we preserve the tombstone key value for long, which is:

std::numeric_limits<long>::max() - 1


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

1 Files Affected:

  • (modified) llvm/include/llvm/ADT/DenseMapInfo.h (+22-111)
diff --git a/llvm/include/llvm/ADT/DenseMapInfo.h b/llvm/include/llvm/ADT/DenseMapInfo.h
index 9d8fd893540a3..a3a459930b38a 100644
--- a/llvm/include/llvm/ADT/DenseMapInfo.h
+++ b/llvm/include/llvm/ADT/DenseMapInfo.h
@@ -17,6 +17,7 @@
 #include <cassert>
 #include <cstddef>
 #include <cstdint>
+#include <limits>
 #include <optional>
 #include <tuple>
 #include <type_traits>
@@ -101,122 +102,32 @@ template<> struct DenseMapInfo<char> {
   }
 };
 
-// Provide DenseMapInfo for unsigned chars.
-template <> struct DenseMapInfo<unsigned char> {
-  static constexpr unsigned char getEmptyKey() { return ~0; }
-  static constexpr unsigned char getTombstoneKey() { return ~0 - 1; }
-  static unsigned getHashValue(const unsigned char &Val) { return Val * 37U; }
-
-  static bool isEqual(const unsigned char &LHS, const unsigned char &RHS) {
-    return LHS == RHS;
-  }
-};
-
-// Provide DenseMapInfo for unsigned shorts.
-template <> struct DenseMapInfo<unsigned short> {
-  static constexpr unsigned short getEmptyKey() { return 0xFFFF; }
-  static constexpr unsigned short getTombstoneKey() { return 0xFFFF - 1; }
-  static unsigned getHashValue(const unsigned short &Val) { return Val * 37U; }
-
-  static bool isEqual(const unsigned short &LHS, const unsigned short &RHS) {
-    return LHS == RHS;
-  }
-};
-
-// Provide DenseMapInfo for unsigned ints.
-template<> struct DenseMapInfo<unsigned> {
-  static constexpr unsigned getEmptyKey() { return ~0U; }
-  static constexpr unsigned getTombstoneKey() { return ~0U - 1; }
-  static unsigned getHashValue(const unsigned& Val) { return Val * 37U; }
-
-  static bool isEqual(const unsigned& LHS, const unsigned& RHS) {
-    return LHS == RHS;
-  }
-};
-
-// Provide DenseMapInfo for unsigned longs.
-template<> struct DenseMapInfo<unsigned long> {
-  static constexpr unsigned long getEmptyKey() { return ~0UL; }
-  static constexpr unsigned long getTombstoneKey() { return ~0UL - 1L; }
-
-  static unsigned getHashValue(const unsigned long& Val) {
-    if constexpr (sizeof(Val) == 4)
-      return DenseMapInfo<unsigned>::getHashValue(Val);
+// Provide DenseMapInfo for all integral types except char.
+//
+// The "char" case is excluded because it uses ~0 as the empty key despite
+// "char" being a signed type.  "std::is_same_v<T, char>" is included below
+// for clarity; technically, we do not need it because the explicit
+// specialization above "wins",
+template <typename T>
+struct DenseMapInfo<
+    T, std::enable_if_t<std::is_integral_v<T> && !std::is_same_v<T, char>>> {
+  static constexpr T getEmptyKey() { return std::numeric_limits<T>::max(); }
+
+  static constexpr T getTombstoneKey() {
+    if constexpr (std::is_unsigned_v<T> || std::is_same_v<T, long>)
+      return std::numeric_limits<T>::max() - 1;
     else
-      return densemap::detail::mix(Val);
+      return std::numeric_limits<T>::min();
   }
 
-  static bool isEqual(const unsigned long& LHS, const unsigned long& RHS) {
-    return LHS == RHS;
-  }
-};
-
-// Provide DenseMapInfo for unsigned long longs.
-template<> struct DenseMapInfo<unsigned long long> {
-  static constexpr unsigned long long getEmptyKey() { return ~0ULL; }
-  static constexpr unsigned long long getTombstoneKey() { return ~0ULL - 1ULL; }
-
-  static unsigned getHashValue(const unsigned long long& Val) {
-    return densemap::detail::mix(Val);
-  }
-
-  static bool isEqual(const unsigned long long& LHS,
-                      const unsigned long long& RHS) {
-    return LHS == RHS;
-  }
-};
-
-// Provide DenseMapInfo for shorts.
-template <> struct DenseMapInfo<short> {
-  static constexpr short getEmptyKey() { return 0x7FFF; }
-  static constexpr short getTombstoneKey() { return -0x7FFF - 1; }
-  static unsigned getHashValue(const short &Val) { return Val * 37U; }
-  static bool isEqual(const short &LHS, const short &RHS) { return LHS == RHS; }
-};
-
-// Provide DenseMapInfo for ints.
-template<> struct DenseMapInfo<int> {
-  static constexpr int getEmptyKey() { return 0x7fffffff; }
-  static constexpr int getTombstoneKey() { return -0x7fffffff - 1; }
-  static unsigned getHashValue(const int& Val) { return (unsigned)(Val * 37U); }
-
-  static bool isEqual(const int& LHS, const int& RHS) {
-    return LHS == RHS;
-  }
-};
-
-// Provide DenseMapInfo for longs.
-template<> struct DenseMapInfo<long> {
-  static constexpr long getEmptyKey() {
-    return (1UL << (sizeof(long) * 8 - 1)) - 1UL;
-  }
-
-  static constexpr long getTombstoneKey() { return getEmptyKey() - 1L; }
-
-  static unsigned getHashValue(const long& Val) {
-    return (unsigned)(Val * 37UL);
-  }
-
-  static bool isEqual(const long& LHS, const long& RHS) {
-    return LHS == RHS;
-  }
-};
-
-// Provide DenseMapInfo for long longs.
-template<> struct DenseMapInfo<long long> {
-  static constexpr long long getEmptyKey() { return 0x7fffffffffffffffLL; }
-  static constexpr long long getTombstoneKey() {
-    return -0x7fffffffffffffffLL - 1;
-  }
-
-  static unsigned getHashValue(const long long& Val) {
-    return (unsigned)(Val * 37ULL);
+  static unsigned getHashValue(const T &Val) {
+    if constexpr (std::is_unsigned_v<T> && sizeof(T) > sizeof(unsigned))
+      return densemap::detail::mix(Val);
+    else
+      return (unsigned)(Val * 37U);
   }
 
-  static bool isEqual(const long long& LHS,
-                      const long long& RHS) {
-    return LHS == RHS;
-  }
+  static bool isEqual(const T &LHS, const T &RHS) { return LHS == RHS; }
 };
 
 // Provide DenseMapInfo for all pairs whose members have info.

@kazutakahirata kazutakahirata merged commit ffcbaa2 into llvm:main Aug 28, 2025
9 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_20250826_DenseMapInfo branch August 28, 2025 00:07
@llvm-ci
Copy link
Collaborator

llvm-ci commented Aug 28, 2025

LLVM Buildbot has detected a new failure on builder sanitizer-aarch64-linux-bootstrap-ubsan running on sanitizer-buildbot9 while building llvm at step 2 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/85/builds/12757

Here is the relevant piece of the build log for the reference
Step 2 (annotate) failure: 'python ../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py' (failure)
...
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:527: note: using lld-link: /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/lld-link
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:527: note: using ld64.lld: /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/ld64.lld
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:527: note: using wasm-ld: /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/wasm-ld
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:527: note: using ld.lld: /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/ld.lld
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:527: note: using lld-link: /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/lld-link
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:527: note: using ld64.lld: /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/ld64.lld
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:527: note: using wasm-ld: /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/wasm-ld
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/llvm/utils/lit/lit/main.py:74: note: The test suite configuration requested an individual test timeout of 0 seconds but a timeout of 900 seconds was requested on the command line. Forcing timeout to be 900 seconds.
-- Testing: 90090 tests, 72 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90
FAIL: MLIR :: Analysis/test-match-reduction.mlir (84230 of 90090)
******************** TEST 'MLIR :: Analysis/test-match-reduction.mlir' FAILED ********************
Exit Code: -6

Command Output (stdout):
--
# RUN: at line 1
/home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/mlir-opt /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/mlir/test/Analysis/test-match-reduction.mlir -pass-pipeline="builtin.module(func.func(test-match-reduction))" -verify-diagnostics -split-input-file
# executed command: /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/mlir-opt /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/mlir/test/Analysis/test-match-reduction.mlir '-pass-pipeline=builtin.module(func.func(test-match-reduction))' -verify-diagnostics -split-input-file
# .---command stderr------------
# | PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
# | Stack dump:
# | 0.	Program arguments: /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/mlir-opt /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/mlir/test/Analysis/test-match-reduction.mlir -pass-pipeline=builtin.module(func.func(test-match-reduction)) -verify-diagnostics -split-input-file
# |  #0 0x0000aacdb5cf1c18 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/Support/Unix/Signals.inc:834:13
# |  #1 0x0000aacdb5ceea08 __cxx_atomic_store<CallbackAndCookie::Status> /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/libcxx_install_ubsan/include/c++/v1/__atomic/support/c11.h:68:3
# |  #2 0x0000aacdb5ceea08 store /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/libcxx_install_ubsan/include/c++/v1/__atomic/atomic.h:62:5
# |  #3 0x0000aacdb5ceea08 llvm::sys::RunSignalHandlers() /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/Support/Signals.cpp:106:16
# |  #4 0x0000aacdb5cf3260 SignalHandler(int, siginfo_t*, void*) /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/Support/Unix/Signals.inc:426:38
# |  #5 0x0000ea61fa9228f8 (linux-vdso.so.1+0x8f8)
# |  #6 0x0000ea61fa317608 (/lib/aarch64-linux-gnu/libc.so.6+0x87608)
# |  #7 0x0000ea61fa2ccb3c raise (/lib/aarch64-linux-gnu/libc.so.6+0x3cb3c)
# |  #8 0x0000ea61fa2b7e00 abort (/lib/aarch64-linux-gnu/libc.so.6+0x27e00)
# |  #9 0x0000aacdb5bee3ec __sanitizer::Atexit(void (*)()) /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp:168:10
# | #10 0x0000aacdb5bec290 __sanitizer::Die() /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_termination.cpp:52:5
# | #11 0x0000aacdb5bfe130 __ubsan_handle_negate_overflow /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/compiler-rt/lib/ubsan/ubsan_handlers.cpp:275:0
# | #12 0x0000aacdbfb2a174 get<mlir::detail::AffineConstantExprStorage, long &> /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/mlir/include/mlir/Support/StorageUniquer.h:217:12
# | #13 0x0000aacdbfb2a174 mlir::detail::AffineConstantExprStorage* mlir::StorageUniquer::get<mlir::detail::AffineConstantExprStorage, long&>(llvm::function_ref<void (mlir::detail::AffineConstantExprStorage*)>, long&) /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/mlir/include/mlir/Support/StorageUniquer.h:223:12
# | #14 0x0000aacdbfb2a024 mlir::getAffineConstantExpr(long, mlir::MLIRContext*) /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/mlir/lib/IR/AffineExpr.cpp:649:18
# | #15 0x0000aacdbfb3a31c mlir::AffineMap::compose(llvm::ArrayRef<long>) const /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/mlir/lib/IR/AffineMap.cpp:581:21
# | #16 0x0000aacdbda928e0 mlir::detail::IndexingMapOpInterfaceTrait<mlir::linalg::GenericOp>::getStaticLoopRanges() /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm_build_ubsan/tools/mlir/include/mlir/Interfaces/IndexingMapOpInterface.h.inc:198:16
# | #17 0x0000aacdbe3ff67c mlir::detail::IndexingMapOpInterfaceInterfaceTraits::Model<mlir::linalg::GenericOp>::getStaticLoopRanges(mlir::detail::IndexingMapOpInterfaceInterfaceTraits::Concept const*, mlir::Operation*) /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm_build_ubsan/tools/mlir/include/mlir/Interfaces/IndexingMapOpInterface.h.inc:230:3
# | #18 0x0000aacdbe7d8ae4 getOperation /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/mlir/include/mlir/IR/OpDefinition.h:112:38
# | #19 0x0000aacdbe7d8ae4 mlir::IndexingMapOpInterface::verifyImpl() /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/mlir/lib/Interfaces/IndexingMapOpInterface.cpp:39:31
# | #20 0x0000aacdbe0db608 mlir::linalg::detail::verifyStructuredOpInterface(mlir::Operation*) /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp:1259:47
# | #21 0x0000aacdbe402eac verifyRegionTrait /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm_build_ubsan/tools/mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.h.inc:1101:14
# | #22 0x0000aacdbe402eac verifyRegionTrait<mlir::linalg::LinalgOp::Trait<mlir::linalg::GenericOp> > /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/mlir/include/mlir/IR/OpDefinition.h:1652:12
# | #23 0x0000aacdbe402eac verifyRegionTraits<mlir::OpTrait::OneRegion<mlir::linalg::GenericOp>, mlir::OpTrait::VariadicResults<mlir::linalg::GenericOp>, mlir::OpTrait::ZeroSuccessors<mlir::linalg::GenericOp>, mlir::OpTrait::VariadicOperands<mlir::linalg::GenericOp>, mlir::OpTrait::SingleBlock<mlir::linalg::GenericOp>, mlir::OpTrait::SingleBlockImplicitTerminator<mlir::linalg::YieldOp>::Impl<mlir::linalg::GenericOp>, mlir::OpTrait::AttrSizedOperandSegments<mlir::linalg::GenericOp>, mlir::OpTrait::OpInvariants<mlir::linalg::GenericOp>, mlir::BytecodeOpInterface::Trait<mlir::linalg::GenericOp>, mlir::MemoryEffectOpInterface::Trait<mlir::linalg::GenericOp>, mlir::ConditionallySpeculatable::Trait<mlir::linalg::GenericOp>, mlir::OpTrait::HasRecursiveMemoryEffects<mlir::linalg::GenericOp>, mlir::DestinationStyleOpInterface::Trait<mlir::linalg::GenericOp>, mlir::IndexingMapOpInterface::Trait<mlir::linalg::GenericOp>, mlir::linalg::LinalgOp::Trait<mlir::linalg::GenericOp>, mlir::ReifyRankedShapedTypeOpInterface::Trait<mlir::linalg::GenericOp>, mlir::OpAsmOpInterface::Trait<mlir::linalg::GenericOp> > /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/mlir/include/mlir/IR/OpDefinition.h:1661:29
# | #24 0x0000aacdbe402eac mlir::Op<mlir::linalg::GenericOp, mlir::OpTrait::OneRegion, mlir::OpTrait::VariadicResults, mlir::OpTrait::ZeroSuccessors, mlir::OpTrait::VariadicOperands, mlir::OpTrait::SingleBlock, mlir::OpTrait::SingleBlockImplicitTerminator<mlir::linalg::YieldOp>::Impl, mlir::OpTrait::AttrSizedOperandSegments, mlir::OpTrait::OpInvariants, mlir::BytecodeOpInterface::Trait, mlir::MemoryEffectOpInterface::Trait, mlir::ConditionallySpeculatable::Trait, mlir::OpTrait::HasRecursiveMemoryEffects, mlir::DestinationStyleOpInterface::Trait, mlir::IndexingMapOpInterface::Trait, mlir::linalg::LinalgOp::Trait, mlir::ReifyRankedShapedTypeOpInterface::Trait, mlir::OpAsmOpInterface::Trait>::verifyRegionInvariants(mlir::Operation*) /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/mlir/include/mlir/IR/OpDefinition.h:2063:16
# | #25 0x0000aacdbe3fe748 asInt /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/llvm/include/llvm/ADT/PointerIntPair.h:41:5
Step 11 (stage2/ubsan check) failure: stage2/ubsan check (failure)
...
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:527: note: using lld-link: /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/lld-link
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:527: note: using ld64.lld: /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/ld64.lld
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:527: note: using wasm-ld: /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/wasm-ld
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:527: note: using ld.lld: /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/ld.lld
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:527: note: using lld-link: /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/lld-link
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:527: note: using ld64.lld: /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/ld64.lld
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:527: note: using wasm-ld: /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/wasm-ld
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/llvm/utils/lit/lit/main.py:74: note: The test suite configuration requested an individual test timeout of 0 seconds but a timeout of 900 seconds was requested on the command line. Forcing timeout to be 900 seconds.
-- Testing: 90090 tests, 72 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90
FAIL: MLIR :: Analysis/test-match-reduction.mlir (84230 of 90090)
******************** TEST 'MLIR :: Analysis/test-match-reduction.mlir' FAILED ********************
Exit Code: -6

Command Output (stdout):
--
# RUN: at line 1
/home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/mlir-opt /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/mlir/test/Analysis/test-match-reduction.mlir -pass-pipeline="builtin.module(func.func(test-match-reduction))" -verify-diagnostics -split-input-file
# executed command: /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/mlir-opt /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/mlir/test/Analysis/test-match-reduction.mlir '-pass-pipeline=builtin.module(func.func(test-match-reduction))' -verify-diagnostics -split-input-file
# .---command stderr------------
# | PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
# | Stack dump:
# | 0.	Program arguments: /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/mlir-opt /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/mlir/test/Analysis/test-match-reduction.mlir -pass-pipeline=builtin.module(func.func(test-match-reduction)) -verify-diagnostics -split-input-file
# |  #0 0x0000aacdb5cf1c18 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/Support/Unix/Signals.inc:834:13
# |  #1 0x0000aacdb5ceea08 __cxx_atomic_store<CallbackAndCookie::Status> /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/libcxx_install_ubsan/include/c++/v1/__atomic/support/c11.h:68:3
# |  #2 0x0000aacdb5ceea08 store /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/libcxx_install_ubsan/include/c++/v1/__atomic/atomic.h:62:5
# |  #3 0x0000aacdb5ceea08 llvm::sys::RunSignalHandlers() /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/Support/Signals.cpp:106:16
# |  #4 0x0000aacdb5cf3260 SignalHandler(int, siginfo_t*, void*) /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/Support/Unix/Signals.inc:426:38
# |  #5 0x0000ea61fa9228f8 (linux-vdso.so.1+0x8f8)
# |  #6 0x0000ea61fa317608 (/lib/aarch64-linux-gnu/libc.so.6+0x87608)
# |  #7 0x0000ea61fa2ccb3c raise (/lib/aarch64-linux-gnu/libc.so.6+0x3cb3c)
# |  #8 0x0000ea61fa2b7e00 abort (/lib/aarch64-linux-gnu/libc.so.6+0x27e00)
# |  #9 0x0000aacdb5bee3ec __sanitizer::Atexit(void (*)()) /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp:168:10
# | #10 0x0000aacdb5bec290 __sanitizer::Die() /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_termination.cpp:52:5
# | #11 0x0000aacdb5bfe130 __ubsan_handle_negate_overflow /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/compiler-rt/lib/ubsan/ubsan_handlers.cpp:275:0
# | #12 0x0000aacdbfb2a174 get<mlir::detail::AffineConstantExprStorage, long &> /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/mlir/include/mlir/Support/StorageUniquer.h:217:12
# | #13 0x0000aacdbfb2a174 mlir::detail::AffineConstantExprStorage* mlir::StorageUniquer::get<mlir::detail::AffineConstantExprStorage, long&>(llvm::function_ref<void (mlir::detail::AffineConstantExprStorage*)>, long&) /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/mlir/include/mlir/Support/StorageUniquer.h:223:12
# | #14 0x0000aacdbfb2a024 mlir::getAffineConstantExpr(long, mlir::MLIRContext*) /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/mlir/lib/IR/AffineExpr.cpp:649:18
# | #15 0x0000aacdbfb3a31c mlir::AffineMap::compose(llvm::ArrayRef<long>) const /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/mlir/lib/IR/AffineMap.cpp:581:21
# | #16 0x0000aacdbda928e0 mlir::detail::IndexingMapOpInterfaceTrait<mlir::linalg::GenericOp>::getStaticLoopRanges() /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm_build_ubsan/tools/mlir/include/mlir/Interfaces/IndexingMapOpInterface.h.inc:198:16
# | #17 0x0000aacdbe3ff67c mlir::detail::IndexingMapOpInterfaceInterfaceTraits::Model<mlir::linalg::GenericOp>::getStaticLoopRanges(mlir::detail::IndexingMapOpInterfaceInterfaceTraits::Concept const*, mlir::Operation*) /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm_build_ubsan/tools/mlir/include/mlir/Interfaces/IndexingMapOpInterface.h.inc:230:3
# | #18 0x0000aacdbe7d8ae4 getOperation /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/mlir/include/mlir/IR/OpDefinition.h:112:38
# | #19 0x0000aacdbe7d8ae4 mlir::IndexingMapOpInterface::verifyImpl() /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/mlir/lib/Interfaces/IndexingMapOpInterface.cpp:39:31
# | #20 0x0000aacdbe0db608 mlir::linalg::detail::verifyStructuredOpInterface(mlir::Operation*) /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp:1259:47
# | #21 0x0000aacdbe402eac verifyRegionTrait /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm_build_ubsan/tools/mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.h.inc:1101:14
# | #22 0x0000aacdbe402eac verifyRegionTrait<mlir::linalg::LinalgOp::Trait<mlir::linalg::GenericOp> > /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/mlir/include/mlir/IR/OpDefinition.h:1652:12
# | #23 0x0000aacdbe402eac verifyRegionTraits<mlir::OpTrait::OneRegion<mlir::linalg::GenericOp>, mlir::OpTrait::VariadicResults<mlir::linalg::GenericOp>, mlir::OpTrait::ZeroSuccessors<mlir::linalg::GenericOp>, mlir::OpTrait::VariadicOperands<mlir::linalg::GenericOp>, mlir::OpTrait::SingleBlock<mlir::linalg::GenericOp>, mlir::OpTrait::SingleBlockImplicitTerminator<mlir::linalg::YieldOp>::Impl<mlir::linalg::GenericOp>, mlir::OpTrait::AttrSizedOperandSegments<mlir::linalg::GenericOp>, mlir::OpTrait::OpInvariants<mlir::linalg::GenericOp>, mlir::BytecodeOpInterface::Trait<mlir::linalg::GenericOp>, mlir::MemoryEffectOpInterface::Trait<mlir::linalg::GenericOp>, mlir::ConditionallySpeculatable::Trait<mlir::linalg::GenericOp>, mlir::OpTrait::HasRecursiveMemoryEffects<mlir::linalg::GenericOp>, mlir::DestinationStyleOpInterface::Trait<mlir::linalg::GenericOp>, mlir::IndexingMapOpInterface::Trait<mlir::linalg::GenericOp>, mlir::linalg::LinalgOp::Trait<mlir::linalg::GenericOp>, mlir::ReifyRankedShapedTypeOpInterface::Trait<mlir::linalg::GenericOp>, mlir::OpAsmOpInterface::Trait<mlir::linalg::GenericOp> > /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/mlir/include/mlir/IR/OpDefinition.h:1661:29
# | #24 0x0000aacdbe402eac mlir::Op<mlir::linalg::GenericOp, mlir::OpTrait::OneRegion, mlir::OpTrait::VariadicResults, mlir::OpTrait::ZeroSuccessors, mlir::OpTrait::VariadicOperands, mlir::OpTrait::SingleBlock, mlir::OpTrait::SingleBlockImplicitTerminator<mlir::linalg::YieldOp>::Impl, mlir::OpTrait::AttrSizedOperandSegments, mlir::OpTrait::OpInvariants, mlir::BytecodeOpInterface::Trait, mlir::MemoryEffectOpInterface::Trait, mlir::ConditionallySpeculatable::Trait, mlir::OpTrait::HasRecursiveMemoryEffects, mlir::DestinationStyleOpInterface::Trait, mlir::IndexingMapOpInterface::Trait, mlir::linalg::LinalgOp::Trait, mlir::ReifyRankedShapedTypeOpInterface::Trait, mlir::OpAsmOpInterface::Trait>::verifyRegionInvariants(mlir::Operation*) /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/mlir/include/mlir/IR/OpDefinition.h:2063:16
# | #25 0x0000aacdbe3fe748 asInt /home/b/sanitizer-aarch64-linux-bootstrap-ubsan/build/llvm-project/llvm/include/llvm/ADT/PointerIntPair.h:41:5

// Provide DenseMapInfo for all integral types except char.
//
// The "char" case is excluded because it uses ~0 as the empty key despite
// "char" being a signed type. "std::is_same_v<T, char>" is included below
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

char is a signed type on x86, but it's an unsigned type on arm and risc-v. I don't know about other targets.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@topperc Thanks! I think it's best not to touch char here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I wasn't suggesting to change the code. It is best to not depend on the signedness of char on the platform.

if constexpr (std::is_unsigned_v<T> && sizeof(T) > sizeof(unsigned))
return densemap::detail::mix(Val);
else
return static_cast<unsigned>(Val * 37U);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI this resulted in UB for signed types > int, created a fix here: #155826

WillFroom added a commit that referenced this pull request Aug 28, 2025
Fixes the signed overflow for signed types > int after #155549
@vitalybuka
Copy link
Collaborator

@kazutakahirata I am going to revert to fix our bots?

@vitalybuka
Copy link
Collaborator

@kazutakahirata I am going to revert to fix our bots?

Or maybe not, #155826 probably works

@kazutakahirata
Copy link
Contributor Author

@vitalybuka @WillFroom Thank you for following up on this PR. I see that #155826 has landed. Is everything OK now?

@zeroomega
Copy link
Contributor

zeroomega commented Aug 28, 2025

We bisected the blamelist and identified the patch 9c9e56b is the culprit for the stage2 build failures we saw on x86 platform. Sorry for the confusion.

This patch might have caused a weird build issue in 2stage clang build. We are still doing a bisecting so not yet confirmed. But it looks most suspicious from the blamelist.
The tablegen generated include file somehow doesn't satisfy UTF-8 format and caused an undeclared identifier error.

@WillFroom
Copy link
Contributor

@vitalybuka @WillFroom Thank you for following up on this PR. I see that #155826 has landed. Is everything OK now?

I think so, the internal sanitizer errors we were seeing have been fixed after my patch afaict

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants