[all-commits] [llvm/llvm-project] 252c83: [clang][Sema] Fix type of an statement expression ...
Alejandro Álvarez Ayllón via All-commits
all-commits at lists.llvm.org
Tue Feb 18 00:52:54 PST 2025
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 252c83bc9ef9fc885e9e6517f1b4423188bb919f
https://github.com/llvm/llvm-project/commit/252c83bc9ef9fc885e9e6517f1b4423188bb919f
Author: Alejandro Álvarez Ayllón <alejandro.alvarez at sonarsource.com>
Date: 2025-02-18 (Tue, 18 Feb 2025)
Changed paths:
M clang/docs/ReleaseNotes.rst
M clang/lib/Sema/SemaExpr.cpp
A clang/test/Sema/gh106576.c
Log Message:
-----------
[clang][Sema] Fix type of an statement expression ending with an atomic type (#119711)
When a statement expression's last statement is an atomic variable, GCC
and Clang disagree on the type of the expression. This can be made
apparent using `typeof` and forcing a diagnostic message:
```cpp
_Atomic int a = 0;
typeof(({a;})) x = "0";
```
* GCC complains about initializing `int` with `char*`
* Clang complains about initializing `_Atomic(int)` with a `char[2]`
Due to the type of the statement expression being deduced to be atomic,
we end with three implicit casts inside the `StmtExpr` on the AST:
* `LValueToRValue` -> `AtomicToNonAtomic` -> `NonAtomicToAtomic`
In some situations, this can end on an assertion inside
`IntExprEvaluator`, as reported in #106576.
With this patch, we now have two implicit casts, since the type of the
statement expression is deduced to be non-atomic:
* `LValueToRValue` -> `AtomicToNonAtomic`
This is consistent with the C standard (6.7.2.4, p4)
> The properties associated with atomic types are meaningful only for
expressions that are lvalues.
But a statement expression is an rvalue.
`IntExprEvaluator` assumptions are now satisfied and there is no
assertion error.
Additionally, the `typeof` trick mentioned above shows that the type is
consistently deduced between GCC and Clang.
Fixes #106576
---------
Co-authored-by: John McCall <rjmccall at gmail.com>
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list