Commit b019be0c8 for llama.cpp
commit b019be0c86e8adaf8b46627c091c24c1597b95f9
Author: Johannes Gäßler <johannesg@5d6.de>
Date: Sat Nov 21 12:46:59 2026 +0100
CUDA: abort on UB in fastdiv (#32698)
diff --git a/ggml/src/ggml-cuda/common.cuh b/ggml/src/ggml-cuda/common.cuh
index 053ed60f7..8cd2366ed 100644
--- a/ggml/src/ggml-cuda/common.cuh
+++ b/ggml/src/ggml-cuda/common.cuh
@@ -1046,6 +1046,12 @@ static const uint3 init_fastdiv_values(uint64_t d_64) {
uint32_t L = 0;
while (L < 32 && (uint32_t{ 1 } << L) < d) {
L++;
+ if (L == 32) {
+ // Shifting uint32_t by 32 to the right is undefined behavior.
+ // On NVIDIA it will produce 0.
+ // On AMD the value by which is shifted is masked with & 31 so it is shifting by 0 bits.
+ GGML_ABORT("undefined behavior in fastdiv");
+ }
}
uint32_t mp = (uint32_t) ((uint64_t{ 1 } << 32) * ((uint64_t{ 1 } << L) - d) / d + 1);