================
@@ -104,6 +104,35 @@ bool SemaPPC::CheckPPCBuiltinFunctionCall(const TargetInfo 
&TI,
     return Diag(TheCall->getBeginLoc(), diag::err_64_bit_builtin_32_bit_tgt)
            << TheCall->getSourceRange();
 
+  // Common BCD type-validation helpers
+  // Emit diagnostics and return true on failure
+  //  - VerifyVectorType: enforces vector unsigned char
+  //  - VerifyIntType: enforces any integer type
+  // Lambdas centralize type checks for BCD builtin handlers
+  QualType VecType = Context.getVectorType(Context.UnsignedCharTy, 16,
+                                           VectorKind::AltiVecVector);
+  // Lambda 1: verify vector type
+  auto VerifyVectorType = [&](QualType ArgTy, SourceLocation Loc,
+                              unsigned ArgIndex) -> bool {
+    if (!Context.hasSameType(ArgTy, VecType)) {
+      Diag(Loc, diag::err_ppc_invalid_vector_type)
+          << ArgIndex << VecType << ArgTy;
+      return true;
+    }
+    return false;
+  };
+
+  // Lambda 2: verify integer type
+  auto VerifyIntType = [&](QualType ArgTy, SourceLocation Loc,
+                           unsigned ArgIndex) -> bool {
+    if (!ArgTy->isIntegerType()) {
+      Diag(Loc, diag::err_ppc_invalid_integer_type)
+          << ArgIndex << "integer type" << ArgTy;
+      return true;
+    }
+    return false;
----------------
lei137 wrote:

nit: Prefer early exit.  `VerifyIntType` return `false` when the argTy is int 
is not very intuitive. 
```suggestion
    if (ArgTy->isIntegerType())
      return true;
    Diag(Loc, diag::err_ppc_invalid_integer_type)
          << ArgIndex << "integer type" << ArgTy;
    return false;   
```

https://github.com/llvm/llvm-project/pull/154715
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to