[clang] [Clang] Restrict AMDGCN image built-ins (PR #180949)

Matt Arsenault via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 6 03:30:27 PST 2026


================
@@ -293,9 +323,14 @@ bool SemaAMDGPU::CheckAMDGCNBuiltinFunctionCall(unsigned BuiltinID,
     unsigned ArgCount = TheCall->getNumArgs() - 1;
     llvm::APSInt Result;
 
-    return (SemaRef.BuiltinConstantArg(TheCall, 1, Result)) ||
-           (SemaRef.BuiltinConstantArg(TheCall, ArgCount, Result)) ||
-           (SemaRef.BuiltinConstantArg(TheCall, (ArgCount - 1), Result));
+    // Complain about dmask values which are too huge to fully fit into 4 bits
+    // (which is the actual size of the dmask in corresponding HW instructions).
+    constexpr unsigned DMaskArgNo = 1;
+    return SemaRef.BuiltinConstantArgRange(TheCall, DMaskArgNo, /* Low = */ 0,
+                                           /* High = */ 15,
+                                           /* RangeIsError = */ true) ||
----------------
arsenm wrote:

```suggestion
    return SemaRef.BuiltinConstantArgRange(TheCall, DMaskArgNo, /*Low=*/0,
                                           /*High=*/ 15,
                                           /*RangeIsError=*/ true) ||
```

clang-format only recognizes a specific pattern 

https://github.com/llvm/llvm-project/pull/180949


More information about the cfe-commits mailing list