Skip to content

[clang][Sema] Fix type of an statement expression ending with an atomic type #119711

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ Bug Fixes to C++ Support

Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
- Fixed type checking when a statement expression ends in an l-value of atomic type. (#GH106576)

Miscellaneous Bug Fixes
^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15946,7 +15946,7 @@ ExprResult Sema::ActOnStmtExprResult(ExprResult ER) {
// FIXME: Provide a better location for the initialization.
return PerformCopyInitialization(
InitializedEntity::InitializeStmtExprResult(
E->getBeginLoc(), E->getType().getUnqualifiedType()),
E->getBeginLoc(), E->getType().getAtomicUnqualifiedType()),
SourceLocation(), E);
}

Expand Down
14 changes: 14 additions & 0 deletions clang/test/Sema/gh106576.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s

typedef _Atomic char atomic_char;

atomic_char counter;

char load_plus_one(void) {
return ({counter;}) + 1; // no crash
}

char type_of_stmt_expr(void) {
typeof(({counter;})) y = ""; // expected-error-re {{incompatible pointer to integer conversion initializing 'typeof (({{{.*}}}))' (aka 'char') with an expression of type 'char[1]'}}
return y;
}