[clang] [Clang] Re-write codegen for atomic_test_and_set and atomic_clear (PR #121943)

Oliver Stannard via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 15 02:57:52 PST 2025


================
@@ -3911,14 +3926,31 @@ ExprResult Sema::BuildAtomicExpr(SourceRange CallRange, SourceRange ExprRange,
     }
   }
 
-  // Pointer to object of size zero is not allowed.
-  if (RequireCompleteType(Ptr->getBeginLoc(), AtomTy,
-                          diag::err_incomplete_type))
-    return ExprError();
-  if (Context.getTypeInfoInChars(AtomTy).Width.isZero()) {
-    Diag(ExprRange.getBegin(), diag::err_atomic_builtin_must_be_pointer)
-        << Ptr->getType() << 1 << Ptr->getSourceRange();
-    return ExprError();
+  if (Form != TestAndSet && Form != Clear) {
+    // Pointer to object of size zero is not allowed.
+    if (RequireCompleteType(Ptr->getBeginLoc(), AtomTy,
+                            diag::err_incomplete_type))
+      return ExprError();
+
+    if (Context.getTypeInfoInChars(AtomTy).Width.isZero()) {
+      Diag(ExprRange.getBegin(), diag::err_atomic_builtin_must_be_pointer)
+          << Ptr->getType() << 1 << Ptr->getSourceRange();
+      return ExprError();
+    }
+  } else {
+    // The __atomic_clear and __atomic_test_and_set intrinsics accept any
----------------
ostannard wrote:

I've tried that, but it results in the block above, which reports an error is a const pointer is used, always printing a `char *` type instead of the actual type from the source code. However I can update this to keep `AtomTy` and `ValType` up to date when the pointer type changes, so that the rest of the checks work correctly.

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


More information about the cfe-commits mailing list