Skip to content

Conversation

@WillFroom
Copy link
Contributor

Fixes the signed overflow for signed types > int after #155549, as integer promotion would result in Val * 37U being signed which would result in UB signed overflow for large values

@llvmbot
Copy link
Member

llvmbot commented Aug 28, 2025

@llvm/pr-subscribers-llvm-adt

Author: Will Froom (WillFroom)

Changes

Fixes the signed overflow for signed types > int after #155549, as integer promotion would result in Val * 37U being signed which would result in UB signed overflow for large values


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

1 Files Affected:

  • (modified) llvm/include/llvm/ADT/DenseMapInfo.h (+2-1)
diff --git a/llvm/include/llvm/ADT/DenseMapInfo.h b/llvm/include/llvm/ADT/DenseMapInfo.h
index 930bd4baca31d..ec7a116856bb4 100644
--- a/llvm/include/llvm/ADT/DenseMapInfo.h
+++ b/llvm/include/llvm/ADT/DenseMapInfo.h
@@ -124,7 +124,8 @@ struct DenseMapInfo<
     if constexpr (std::is_unsigned_v<T> && sizeof(T) > sizeof(unsigned))
       return densemap::detail::mix(Val);
     else
-      return static_cast<unsigned>(Val * 37U);
+      return static_cast<unsigned>(Val *
+                                   static_cast<std::make_unsigned_t<T>>(37U));
   }
 
   static bool isEqual(const T &LHS, const T &RHS) { return LHS == RHS; }

@WillFroom WillFroom enabled auto-merge (squash) August 28, 2025 12:48
@WillFroom WillFroom merged commit a01933d into llvm:main Aug 28, 2025
11 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Aug 28, 2025

LLVM Buildbot has detected a new failure on builder llvm-clang-aarch64-darwin running on doug-worker-4 while building llvm at step 4 "cmake-configure".

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

Here is the relevant piece of the build log for the reference
Step 4 (cmake-configure) failure: cmake (failure)
Upon execvpe b'cmake' [b'cmake', b'-DCMAKE_C_COMPILER=clang', b'-DCMAKE_CXX_COMPILER=clang++', b'-DCMAKE_BUILD_TYPE=Release', b'-DLLVM_BUILD_TESTS=ON', b'-DLLVM_CCACHE_BUILD=ON', b'-DLLVM_ENABLE_ASSERTIONS=ON', b'-DLLVM_INCLUDE_EXAMPLES=OFF', b'-DLLVM_LIT_ARGS=--verbose --timeout=900', b'-DLLVM_TARGETS_TO_BUILD=AArch64', b'-DLLVM_ENABLE_PROJECTS=llvm;cross-project-tests;lld;clang-tools-extra;clang', b'-GNinja', b'../llvm-project/llvm'] in environment id 4365123904
:Traceback (most recent call last):
  File "/Library/Python/3.9/site-packages/twisted/internet/process.py", line 433, in _fork
    self._execChild(path, uid, gid, executable, args, environment)
  File "/Library/Python/3.9/site-packages/twisted/internet/process.py", line 504, in _execChild
    os.execvpe(executable, args, environment)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/os.py", line 583, in execvpe
    _execvpe(file, args, env)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/os.py", line 616, in _execvpe
    raise last_exc
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/os.py", line 607, in _execvpe
    exec_func(fullname, *argrest)
FileNotFoundError: [Errno 2] No such file or directory: b'/opt/homebrew/bin/cmake'

t-a-james pushed a commit to t-a-james/llvm-project that referenced this pull request Aug 28, 2025
…oject into bugprone-method-hiding

* 'bugprone-method-hiding' of github.com:t-a-james/llvm-project: (230 commits)
  [SimplifyCFG] Move token type check into canReplaceOperandWithVariable()
  [ADT] Fix signed integer overflow (llvm#155826)
  [Offload] Update LIBOMPTARGET_INFO text for `attach` map-type. (llvm#155509)
  [CMake][AIX] Enable CMP0182: Create shared library archives by default (llvm#155686)
  AMDGPU: Add tests for atomics with AGPR operands (llvm#155820)
  [AArch64] Split zero cycle zeoring per register class (llvm#154561)
  [gn build] Port fa883e1
  [mlir][tosa] Allow shift operand of tosa::MulOp as non-constant (llvm#155197)
  [AArch64][NFC] Add MCInstrAnalysis unittests (llvm#155609)
  [Offload][OpenMP] Tests require libc on GPU for printf (llvm#155785)
  AMDGPU: Add missing verifier tests for load/store AGPR case (llvm#155815)
  [lldb-mcp] Fix building for Windows
  Revert "[lldb] Correct a usage after a rename was merged. (llvm#155720)"
  Revert "[lldb] NFC Moving mcp::Transport into its own file. (llvm#155711)"
  [lldb][test] Run ranges::ref_vew test only for libc++ (llvm#155813)
  [SCCP][FuncSpec] Poison unreachable constant global variable user (llvm#155753)
  [LoongArch] Lowering v32i8 vector mask generation to `VMSKLTZ` (llvm#149953)
  [flang][docs][NFC] Remove stray backtick (llvm#154974)
  [MLIR] Apply clang-tidy fixes for misc-use-internal-linkage in LinalgOps.cpp (NFC)
  [MLIR] Apply clang-tidy fixes for performance-move-const-arg in VariantValue.cpp (NFC)
  ...
vitalybuka added a commit that referenced this pull request Aug 28, 2025
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.

3 participants