Skip to content

Commit

Permalink
[Clang][C] Fixed a bug where we reject an _Atomic qualified integer i…
Browse files Browse the repository at this point in the history
…n 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
  • Loading branch information
to268 authored and cor3ntin committed Sep 20, 2023
1 parent 3641d18 commit 624c130
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
6 changes: 4 additions & 2 deletions clang/lib/Sema/SemaOverload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down
6 changes: 6 additions & 0 deletions clang/test/Sema/atomic-expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) { }
}

0 comments on commit 624c130

Please sign in to comment.