to268 created this revision. to268 added a reviewer: aaron.ballman. to268 added a project: clang. Herald added a project: All. to268 requested review of this revision. Herald added a subscriber: cfe-commits.
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 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D159522 Files: clang/lib/Sema/SemaOverload.cpp clang/test/Sema/atomic-expr.c Index: clang/test/Sema/atomic-expr.c =================================================================== --- clang/test/Sema/atomic-expr.c +++ clang/test/Sema/atomic-expr.c @@ -216,3 +216,9 @@ 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) { } +} Index: clang/lib/Sema/SemaOverload.cpp =================================================================== --- clang/lib/Sema/SemaOverload.cpp +++ clang/lib/Sema/SemaOverload.cpp @@ -6302,8 +6302,10 @@ 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);
Index: clang/test/Sema/atomic-expr.c =================================================================== --- clang/test/Sema/atomic-expr.c +++ clang/test/Sema/atomic-expr.c @@ -216,3 +216,9 @@ 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) { } +} Index: clang/lib/Sema/SemaOverload.cpp =================================================================== --- clang/lib/Sema/SemaOverload.cpp +++ clang/lib/Sema/SemaOverload.cpp @@ -6302,8 +6302,10 @@ 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);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits