Author: Erich Keane
Date: 2026-06-12T20:00:09Z
New Revision: 5f51294647b3c4c08dfd0e455b1a997074864d26

URL: 
https://github.com/llvm/llvm-project/commit/5f51294647b3c4c08dfd0e455b1a997074864d26
DIFF: 
https://github.com/llvm/llvm-project/commit/5f51294647b3c4c08dfd0e455b1a997074864d26.diff

LOG: Fix contextual implicit conversions to int: with _Atomic (#203522)

PerformContextualImplicitConversion was performing
default-lvalue-conversions, then basing decisions on viable conversion
functions on this type However, when we then went to add the candidates
we were using the 'old' value (pre-conversion) of the type, resulting in
us regaining the lost 'atomic' from the default Lvalue conversion.

This patch updates the 'from' variable to be the converted value so all
conversions are done post-conversion.

Fixes: #201770

Added: 
    clang/test/Sema/atomic-conversions-to-int.cpp

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/lib/Sema/SemaOverload.cpp

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a984982d1bd41..7828135a6edbc 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -705,6 +705,7 @@ Bug Fixes in This Version
 - Fixed crash when checking for overflow for unary operator that can't 
overflow (#GH170072)
 - Clang no longer handles a `" q-char-sequence "` header name as a string 
literal (#GH132643).
 - Fixed an assertion when ``__attribute__((alloc_size))`` is used with an 
argument type wider than the target's pointer width. (#GH190445)
+- Fixed an assertion where we improperly handled implicit conversions to 
integral types from an atomic-type with a conversion function. (#GH201770)
 
 Bug Fixes to Compiler Builtins
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index ecda430c8424a..cda3d7196767b 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -7031,6 +7031,7 @@ ExprResult Sema::PerformContextualImplicitConversion(
   // Try converting the expression to an Lvalue first, to get rid of 
qualifiers.
   ExprResult Converted = DefaultLvalueConversion(From);
   QualType T = Converted.isUsable() ? Converted.get()->getType() : QualType();
+  From = Converted.isUsable() ? Converted.get() : nullptr;
   // If the expression already has a matching type, we're golden.
   if (Converter.match(T))
     return Converted;

diff  --git a/clang/test/Sema/atomic-conversions-to-int.cpp 
b/clang/test/Sema/atomic-conversions-to-int.cpp
new file mode 100644
index 0000000000000..f4791699972c8
--- /dev/null
+++ b/clang/test/Sema/atomic-conversions-to-int.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -verify %s
+
+struct Convert {
+  operator unsigned() const;
+};
+
+struct NoConvert {
+  operator float() const;
+};
+
+struct H {
+  static _Atomic Convert conv;
+  static _Atomic NoConvert noconv;
+};
+
+void foo() {
+    switch(H::conv){}
+    (void)__builtin_stdc_rotate_left(H::conv, H::conv);
+
+    // expected-error@+1{{statement requires expression of integer type 
('NoConvert' invalid)}}
+    switch(H::noconv){}
+    // expected-error@+1{{1st argument must be a scalar unsigned integer type 
(was 'NoConvert')}}
+    (void)__builtin_stdc_rotate_left(H::noconv, H::noconv);
+}
+


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

Reply via email to