aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Frontend/CompilerInvocation.cpp
diff options
context:
space:
mode:
authorAlejandro Álvarez Ayllón <alejandro.alvarez@sonarsource.com>2025-02-18 09:52:31 +0100
committerGitHub <noreply@github.com>2025-02-18 09:52:31 +0100
commit252c83bc9ef9fc885e9e6517f1b4423188bb919f (patch)
tree87d9d90ded193ff9d028d397ce044daf892588c6 /clang/lib/Frontend/CompilerInvocation.cpp
parentf7c71f162269a10a635c4125142ae8b0a194f3aa (diff)
downloadllvm-252c83bc9ef9fc885e9e6517f1b4423188bb919f.zip
llvm-252c83bc9ef9fc885e9e6517f1b4423188bb919f.tar.gz
llvm-252c83bc9ef9fc885e9e6517f1b4423188bb919f.tar.bz2
[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@gmail.com>
Diffstat (limited to 'clang/lib/Frontend/CompilerInvocation.cpp')
0 files changed, 0 insertions, 0 deletions