https://github.com/Kristianerik updated 
https://github.com/llvm/llvm-project/pull/207042

>From 4814925b921fcec603b5508db32271c8b533a859 Mon Sep 17 00:00:00 2001
From: Kristianerik <[email protected]>
Date: Wed, 1 Jul 2026 10:42:35 -0700
Subject: [PATCH] [Sema] Strip atomic qualifier in
 TryObjectArgumentInitialization

---
 clang/docs/ReleaseNotes.md                     |  1 +
 clang/lib/Sema/SemaOverload.cpp                |  5 +++++
 .../SemaCXX/atomic-member-access-crash.cpp     | 18 ++++++++++++++++++
 3 files changed, 24 insertions(+)
 create mode 100644 clang/test/SemaCXX/atomic-member-access-crash.cpp

diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index c8b940836a67f..5ea8c02531331 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -754,6 +754,7 @@ latest release, please see the [Clang Web 
Site](https://clang.llvm.org) or the
   calling `__builtin_bit_cast`. (#GH200112)
 - Clang now SFINAE friendly when the ``__reference_meows_from_temporary`` 
builtins
   should SFINAE friendly when the 1st type is not a reference type. (#GH206524)
+- Fixed an assertion failure when calling a member function on an 
`_Atomic`-qualified struct. (#GH206860)
 
 
 #### Bug Fixes to Attribute Support
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index c663765573612..59a504bc8e0ca 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -6122,6 +6122,11 @@ static ImplicitConversionSequence 
TryObjectArgumentInitialization(
     assert(FromClassification.isLValue());
   }
 
+  // Strip atomic qualifier - accessing members of _Atomic structs
+  // is undefined behavior but shouldn't crash the compiler.
+  if (const auto *AT = FromType->getAs<AtomicType>())
+    FromType = AT->getValueType();
+
   auto ValueKindFromClassification = [](Expr::Classification C) {
     if (C.isPRValue())
       return clang::VK_PRValue;
diff --git a/clang/test/SemaCXX/atomic-member-access-crash.cpp 
b/clang/test/SemaCXX/atomic-member-access-crash.cpp
new file mode 100644
index 0000000000000..39381b7d84fc4
--- /dev/null
+++ b/clang/test/SemaCXX/atomic-member-access-crash.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
+// This test verifies that accessing members of an _Atomic struct
+// produces diagnostics instead of crashing.
+
+struct S {};
+constexpr S s;
+
+struct SS {
+  consteval const S *operator->() const { return &s; }
+  consteval int foo() const { return 42; }
+};
+
+_Atomic SS ss; // expected-note {{declared here}}
+
+int v = ss->bar; // expected-error {{no member named 'bar' in 'SS'}} \
+                 // expected-error {{call to consteval function 
'SS::operator->' is not a constant expression}} \
+                 // expected-note {{read of non-constexpr variable 'ss' is not 
allowed in a constant expression}}
+int x = ss.foo(); // expected-error {{accessing a member of an atomic 
structure or union is undefined behavior}}

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

Reply via email to