[clang] [AMDGPU] Add sema check for global_atomic_fadd_v2f16 builtin (PR #158145)

Tim Gu via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 12 08:57:32 PDT 2025


================
@@ -436,4 +440,32 @@ void SemaAMDGPU::handleAMDGPUMaxNumWorkGroupsAttr(Decl *D,
   addAMDGPUMaxNumWorkGroupsAttr(D, AL, AL.getArgAsExpr(0), YExpr, ZExpr);
 }
 
+
+bool SemaAMDGPU::checkAMDGCNAtomicFaddV2F16Type(CallExpr *TheCall) {
+  // Check that the pointer argument is a pointer to v2f16
+
+  Expr *Arg = TheCall->getArg(1);
+  QualType ArgType = Arg->getType();
+
+  // Check if it's a vector type
+  if (!ArgType->isVectorType()) {
+    Diag(Arg->getBeginLoc(), diag::err_typecheck_call_different_arg_types)
+        << "expected _Float16 vector of length 2" << ArgType
+        << Arg->getSourceRange();
+    return true;
+  }
+
+  const VectorType *VT = ArgType->getAs<VectorType>();
+
+  // Check element type (should be _Float16) and vector length (should be 2)
+  QualType ElementType = VT->getElementType();
+  if (!ElementType->isFloat16Type() || VT->getNumElements() != 2) {
----------------
tcgu-amd wrote:

Thanks for the comment! That's what I thought as well, but for some reason without explicit checking it here clang does not seem to catch the type mismatch. I am new to clang development so I don't know if that's expected. 

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


More information about the cfe-commits mailing list