[llvm] [SPIR-V] Refactor buildMemSemanticsReg to ensure type compatibility (PR #123676)

Michal Paszkowski via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 20 15:44:50 PST 2025


https://github.com/michalpaszkowski created https://github.com/llvm/llvm-project/pull/123676

Fixed a type mismatch issue in the comparison of std::memory_order with unsigned.

This fixes an issue reported by clang-debian-cpp20 buildbot for https://github.com/llvm/llvm-project/pull/123654

>From 594d447368525579bc10e4f1a35f09cdd446399a Mon Sep 17 00:00:00 2001
From: Michal Paszkowski <michal at michalpaszkowski.com>
Date: Tue, 21 Jan 2025 00:33:11 +0100
Subject: [PATCH] [SPIR-V] Refactor buildMemSemanticsReg to ensure type
 compatibility

Fixed a type mismatch issue in the comparison of std::memory_order with
unsigned.

This fixes an issue reported by clang-debian-cpp20 buildbot for
https://github.com/llvm/llvm-project/pull/123654
---
 llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp b/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
index 784bbe8e662c20..d3976f645e6832 100644
--- a/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
@@ -606,13 +606,13 @@ static Register buildMemSemanticsReg(Register SemanticsRegister,
                                      SPIRVGlobalRegistry *GR) {
   if (SemanticsRegister.isValid()) {
     MachineRegisterInfo *MRI = MIRBuilder.getMRI();
-    std::memory_order Order =
-        static_cast<std::memory_order>(getIConstVal(SemanticsRegister, MRI));
-    Semantics =
-        getSPIRVMemSemantics(Order) |
+    int MemoryOrderValue = getIConstVal(SemanticsRegister, MRI);
+    std::memory_order Order = static_cast<std::memory_order>(MemoryOrderValue);
+    unsigned OrderSemantics = getSPIRVMemSemantics(Order);
+    unsigned StorageClassSemantics =
         getMemSemanticsForStorageClass(GR->getPointerStorageClass(PtrRegister));
-
-    if (Order == Semantics) {
+    Semantics = OrderSemantics | StorageClassSemantics;
+    if (OrderSemantics == Semantics) {
       MRI->setRegClass(SemanticsRegister, &SPIRV::iIDRegClass);
       return SemanticsRegister;
     }



More information about the llvm-commits mailing list