[clang] 624c130 - [Clang][C] Fixed a bug where we reject an _Atomic qualified integer in a switch statment

Corentin Jabot via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 20 10:19:09 PDT 2023


Author: Guillot Tony
Date: 2023-09-20T19:19:02+02:00
New Revision: 624c130578744da4bb07b13e056e619f8ce260fa

URL: https://github.com/llvm/llvm-project/commit/624c130578744da4bb07b13e056e619f8ce260fa
DIFF: https://github.com/llvm/llvm-project/commit/624c130578744da4bb07b13e056e619f8ce260fa.diff

LOG: [Clang][C] Fixed a bug where we reject an _Atomic qualified integer in a switch statment

We are currently rejecting an _Atomic qualified integer in a switch statment.
This fixes the issue by doing an Lvalue conversion before trying to match on the type.
Fixes #65557

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D159522

Added: 
    

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/lib/Sema/SemaOverload.cpp
    clang/test/Sema/atomic-expr.c

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 44a5d5740dabef1..43b113d00a50956 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -226,6 +226,8 @@ Bug Fixes in This Version
   an invalid conversion during method function overload resolution.
 - Fix parser crash when dealing with ill-formed objective C++ header code. Fixes
   (`#64836 <https://github.com/llvm/llvm-project/issues/64836>`_)
+- Clang now allows an ``_Atomic`` qualified integer in a switch statement. Fixes
+  (`#65557 <https://github.com/llvm/llvm-project/issues/65557>`_)
 
 Bug Fixes to Compiler Builtins
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 3ba7266122e4c0c..0ac2ac258c0c7d1 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -6302,10 +6302,12 @@ ExprResult Sema::PerformContextualImplicitConversion(
     From = result.get();
   }
 
+  // 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();
   // If the expression already has a matching type, we're golden.
-  QualType T = From->getType();
   if (Converter.match(T))
-    return DefaultLvalueConversion(From);
+    return Converted;
 
   // FIXME: Check for missing '()' if T is a function type?
 

diff  --git a/clang/test/Sema/atomic-expr.c b/clang/test/Sema/atomic-expr.c
index b34c15e4fca8b49..8eefbf92152b817 100644
--- a/clang/test/Sema/atomic-expr.c
+++ b/clang/test/Sema/atomic-expr.c
@@ -216,3 +216,9 @@ void func_18(void) {
   struct T { int a; };
   (void)(_Atomic struct T)s; // expected-error {{used type 'struct T' where arithmetic or pointer type is required}}
 }
+
+// Test if we can handle an _Atomic qualified integer in a switch statement.
+void func_19(void) {
+  _Atomic int a = 0;
+  switch (a) { }
+}


        


More information about the cfe-commits mailing list