https://github.com/alejandro-alvarez-sonarsource updated 
https://github.com/llvm/llvm-project/pull/119711

From d398fa13c2fa141954c79ca68a59c6ac506b393f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alejandro=20=C3=81lvarez=20Ayll=C3=B3n?=
 <alejandro.alva...@sonarsource.com>
Date: Wed, 11 Dec 2024 15:43:58 +0100
Subject: [PATCH 1/7] Add regression test

---
 clang/test/Sema/gh106576.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
 create mode 100644 clang/test/Sema/gh106576.c

diff --git a/clang/test/Sema/gh106576.c b/clang/test/Sema/gh106576.c
new file mode 100644
index 0000000000000..792977dea1413
--- /dev/null
+++ b/clang/test/Sema/gh106576.c
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+typedef _Atomic char atomic_char;
+
+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;
+}

From 296aa35fe32449067c69d2b40031af0dd6822a07 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alejandro=20=C3=81lvarez=20Ayll=C3=B3n?=
 <alejandro.alva...@sonarsource.com>
Date: Thu, 12 Dec 2024 15:08:56 +0100
Subject: [PATCH 2/7] Tentative fix

---
 clang/lib/Sema/SemaExpr.cpp | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 20bf6f7f6f28f..165447efb345c 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -15861,10 +15861,19 @@ ExprResult Sema::ActOnStmtExprResult(ExprResult ER) {
   if (Cast && Cast->getCastKind() == CK_ARCConsumeObject)
     return Cast->getSubExpr();
 
+  auto Ty = E->getType().getUnqualifiedType();
+
+  // If the type is an atomic, the statement type is the underlying type.
+  if (const AtomicType *AT = Ty->getAs<AtomicType>()) {
+    Ty = AT->getValueType().getUnqualifiedType();
+    return ImplicitCastExpr::Create(Context, Ty, CK_AtomicToNonAtomic, E,
+                                    /*base path*/ nullptr, VK_PRValue,
+                                    FPOptionsOverride());
+  }
+
   // FIXME: Provide a better location for the initialization.
   return PerformCopyInitialization(
-      InitializedEntity::InitializeStmtExprResult(
-          E->getBeginLoc(), E->getType().getUnqualifiedType()),
+      InitializedEntity::InitializeStmtExprResult(E->getBeginLoc(), Ty),
       SourceLocation(), E);
 }
 

From d13e1090c641314aae8eef50f1b0fb5c0ec67e39 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alejandro=20=C3=81lvarez=20Ayll=C3=B3n?=
 <alejandro.alva...@sonarsource.com>
Date: Thu, 12 Dec 2024 15:30:07 +0100
Subject: [PATCH 3/7] Use PerformImplicitConversion

---
 clang/lib/Sema/SemaExpr.cpp | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 165447efb345c..45ae97807c203 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -15866,9 +15866,7 @@ ExprResult Sema::ActOnStmtExprResult(ExprResult ER) {
   // If the type is an atomic, the statement type is the underlying type.
   if (const AtomicType *AT = Ty->getAs<AtomicType>()) {
     Ty = AT->getValueType().getUnqualifiedType();
-    return ImplicitCastExpr::Create(Context, Ty, CK_AtomicToNonAtomic, E,
-                                    /*base path*/ nullptr, VK_PRValue,
-                                    FPOptionsOverride());
+    return PerformImplicitConversion(E, Ty, AssignmentAction::Casting);
   }
 
   // FIXME: Provide a better location for the initialization.

From 02d8385cc0f824ff0436a7b0a42d16555e5ee0c5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alejandro=20=C3=81lvarez=20Ayll=C3=B3n?=
 <alejandro.alva...@sonarsource.com>
Date: Wed, 18 Dec 2024 09:19:51 +0100
Subject: [PATCH 4/7] Add release note

---
 clang/docs/ReleaseNotes.rst | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 408b2800f9e79..24420d9dd49d5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -853,6 +853,7 @@ Bug Fixes to AST Handling
 - Clang now uses the location of the begin of the member expression for 
``CallExpr``
   involving deduced ``this``. (#GH116928)
 - Fixed printout of AST that uses pack indexing expression. (#GH116486)
+- Fixed type deduction of an statement expression (a GCC extension) ending 
with an atomic type. (#GH106576)
 
 Miscellaneous Bug Fixes
 ^^^^^^^^^^^^^^^^^^^^^^^

From 2cfef9885cdf023b038cce86519f65a4e9c60bfa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alejandro=20=C3=81lvarez=20Ayll=C3=B3n?=
 <alejandro.alva...@sonarsource.com>
Date: Wed, 12 Feb 2025 11:22:03 +0100
Subject: [PATCH 5/7] Fix by using getAtomicUnqualifiedType

---
 clang/lib/Sema/SemaExpr.cpp | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 28ee5b07152ff..263cc181ad8de 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -15919,17 +15919,10 @@ ExprResult Sema::ActOnStmtExprResult(ExprResult ER) {
   if (Cast && Cast->getCastKind() == CK_ARCConsumeObject)
     return Cast->getSubExpr();
 
-  auto Ty = E->getType().getUnqualifiedType();
-
-  // If the type is an atomic, the statement type is the underlying type.
-  if (const AtomicType *AT = Ty->getAs<AtomicType>()) {
-    Ty = AT->getValueType().getUnqualifiedType();
-    return PerformImplicitConversion(E, Ty, AssignmentAction::Casting);
-  }
-
   // FIXME: Provide a better location for the initialization.
   return PerformCopyInitialization(
-      InitializedEntity::InitializeStmtExprResult(E->getBeginLoc(), Ty),
+      InitializedEntity::InitializeStmtExprResult(
+          E->getBeginLoc(), E->getType().getAtomicUnqualifiedType()),
       SourceLocation(), E);
 }
 

From 87f664448decd94fb90077774bdcfe172a23ff8c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alejandro=20=C3=81lvarez=20Ayll=C3=B3n?=
 <alejandro.alva...@sonarsource.com>
Date: Thu, 13 Feb 2025 08:59:32 +0100
Subject: [PATCH 6/7] Update clang/docs/ReleaseNotes.rst

Co-authored-by: John McCall <rjmcc...@gmail.com>
---
 clang/docs/ReleaseNotes.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2b0e4914ea23d..42834149ae987 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -163,7 +163,7 @@ Bug Fixes to C++ Support
 
 Bug Fixes to AST Handling
 ^^^^^^^^^^^^^^^^^^^^^^^^^
-- Fixed type deduction of an statement expression (a GCC extension) ending 
with an atomic type. (#GH106576)
+- Fixed type checking when a statement expression ends in an l-value of atomic 
type. (#GH106576)
 
 Miscellaneous Bug Fixes
 ^^^^^^^^^^^^^^^^^^^^^^^

From 81e4efbaa7bbf6fa63ce065892d942ba1401fcda Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alejandro=20=C3=81lvarez=20Ayll=C3=B3n?=
 <alejandro.alva...@sonarsource.com>
Date: Thu, 13 Feb 2025 09:06:52 +0100
Subject: [PATCH 7/7] Remove duplicated typedef from test

---
 clang/test/Sema/gh106576.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/clang/test/Sema/gh106576.c b/clang/test/Sema/gh106576.c
index 792977dea1413..a72592aac0129 100644
--- a/clang/test/Sema/gh106576.c
+++ b/clang/test/Sema/gh106576.c
@@ -2,8 +2,6 @@
 
 typedef _Atomic char atomic_char;
 
-typedef _Atomic char atomic_char;
-
 atomic_char counter;
 
 char load_plus_one(void) {

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to