[clang] Add clang_elementwise_builtin_alias (PR #86175)

Farzon Lotfi via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 21 13:20:50 PDT 2024


================
@@ -2239,6 +2239,39 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
       return true;
     ICEArguments &= ~(1 << ArgNo);
   }
+  // if the call has the elementwise attribute, then
+  // make sure that an elementwise expr is emitted.
+  if (FDecl->hasAttr<ElementwiseBuiltinAliasAttr>()) {
+    switch (FDecl->getNumParams()) {
+    case 1: {
+      if (PrepareBuiltinElementwiseMathOneArgCall(TheCall))
+        return ExprError();
+
+      QualType ArgTy = TheCall->getArg(0)->getType();
+      if (checkFPMathBuiltinElementType(
+              *this, TheCall->getArg(0)->getBeginLoc(), ArgTy, 1))
+        return ExprError();
+      break;
+    }
+    case 2: {
+      if (SemaBuiltinElementwiseMath(TheCall))
+        return ExprError();
+
+      QualType ArgTy = TheCall->getArg(0)->getType();
+      if (checkFPMathBuiltinElementType(
+              *this, TheCall->getArg(0)->getBeginLoc(), ArgTy, 1) ||
+          checkFPMathBuiltinElementType(
+              *this, TheCall->getArg(1)->getBeginLoc(), ArgTy, 2))
+        return ExprError();
+      break;
+    }
+    case 3: {
+      if (SemaBuiltinElementwiseTernaryMath(TheCall))
----------------
farzonl wrote:

there are ternaryMath calls that are not floating point  only so you really want to do this instead:

```c++
if (SemaBuiltinElementwiseTernaryMath(
            TheCall, /*CheckForFloatArgs*/
            TheCall->getArg(0)->getType()->hasFloatingRepresentation()))
```

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


More information about the cfe-commits mailing list