================
@@ -1107,6 +1107,124 @@ bool SemaARM::CheckARMBuiltinFunctionCall(const 
TargetInfo &TI,
   }
 }
 
+static bool CheckAArch64AtomicStoreWithStshhCall(SemaARM &S,
+                                                 CallExpr *TheCall) {
+  Sema &SemaRef = S.SemaRef;
+  ASTContext &Context = S.getASTContext();
+  DeclRefExpr *DRE =
+      cast<DeclRefExpr>(TheCall->getCallee()->IgnoreParenCasts());
+  SourceLocation Loc = DRE->getBeginLoc();
+
+  // Ensure we have the proper number of arguments.
+  if (SemaRef.checkArgCount(TheCall, 4))
+    return true;
+
+  // Normalize arg0/arg1 into value form, and check valid
+  ExprResult PtrRes =
+      SemaRef.DefaultFunctionArrayLvalueConversion(TheCall->getArg(0));
+  ExprResult ValRes =
+      SemaRef.DefaultFunctionArrayLvalueConversion(TheCall->getArg(1));
+
+  if (PtrRes.isInvalid())
+    return true;
+
+  if (ValRes.isInvalid())
+    return true;
+
+  TheCall->setArg(0, PtrRes.get());
+  Expr *PointerArg = PtrRes.get();
+  QualType PtrType = PointerArg->getType();
+
+  // Check arg 0 is a pointer type, err out if not
+  const PointerType *PointerTy = PtrType->getAs<PointerType>();
+  if (!PointerTy) {
+    SemaRef.Diag(Loc, diag::err_atomic_builtin_must_be_pointer)
+        << PtrType << 0 << PointerArg->getSourceRange();
+    return true;
+  }
+
+  // Reject const-qualified pointee types
+  QualType ValType = PointerTy->getPointeeType();
+  if (ValType.isConstQualified()) {
+    SemaRef.Diag(Loc, diag::err_atomic_builtin_cannot_be_const)
+        << PtrType << PointerArg->getSourceRange();
+    return true;
+  }
+
+  ValType = ValType.getUnqualifiedType();
+  bool BadInt = true;
+  if (ValType->isIntegerType()) {
+    unsigned Bits = Context.getTypeSize(ValType);
+    switch (Bits) {
+    case 8:
+    case 16:
+    case 32:
+    case 64:
+      BadInt = false;
+      break;
+    default:
+      break;
+    }
+  }
+
+  // Only 8/16/32/64-bit integers are supported
+  if (BadInt) {
+    SemaRef.Diag(Loc, diag::err_arm_atomic_store_with_stshh_bad_type)
+        << PtrType << PointerArg->getSourceRange();
+    return true;
+  }
+
+  Expr *ValArg = ValRes.get();
+  QualType ValArgType = ValArg->getType().getUnqualifiedType();
+
+  // Check value type and width
+  if (!Context.hasSameType(ValArgType, ValType)) {
+    SemaRef.Diag(Loc, diag::err_arm_atomic_store_with_stshh_bad_value_type)
+        << ValType << ValArg->getType() << ValArg->getSourceRange();
+    return true;
+  }
+
+  Expr *OrderArg = TheCall->getArg(2);
+
+  // Defer validation for dependent memory_order arguments.
+  if (OrderArg->isValueDependent())
+    return false;
----------------
kmclaughlin-arm wrote:

Is it worth moving any check that could defer validation to the start of the 
function?

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

Reply via email to