[PATCH] D152303: [ExprConstant] fix ICE from Evaluate on _Atomic structs

Nick Desaulniers via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 8 13:20:40 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rG9daab7fb02d2: [ExprConstant] fix ICE from Evaluate on _Atomic structs (authored by nickdesaulniers).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152303/new/

https://reviews.llvm.org/D152303

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/ExprConstant.cpp
  clang/test/CodeGenCXX/atomicinit.cpp


Index: clang/test/CodeGenCXX/atomicinit.cpp
===================================================================
--- clang/test/CodeGenCXX/atomicinit.cpp
+++ clang/test/CodeGenCXX/atomicinit.cpp
@@ -8,6 +8,10 @@
 // CHECK-DAG: @_ZN7PR180978constant1bE ={{.*}} local_unnamed_addr global { i16, i8 } { i16 2, i8 6 }, align 4
 // CHECK-DAG: @_ZN7PR180978constant1cE ={{.*}} local_unnamed_addr global { i16, i8 } { i16 3, i8 6 }, align 4
 // CHECK-DAG: @_ZN7PR180978constant1yE ={{.*}} local_unnamed_addr global { { i16, i8 }, i32 } { { i16, i8 } { i16 4, i8 6 }, i32 5 }, align 4
+// CHECK-DAG: @_ZN7PR180978constant1zE ={{.*}} global i32 0, align 4
+// CHECK-DAG: @_ZN7PR180978constant2y2E ={{.*}} global %"struct.PR18097::constant::Y" zeroinitializer
+// CHECK-DAG: @_ZN7PR180978constant1gE ={{.*}} global %"struct.PR18097::constant::Struct0" zeroinitializer
+// CHECK-DAG: @_ZN7PR180978constantL1xE = internal {{.*}} constant { i16, i8 } { i16 1, i8 6 }
 
 struct A {
   _Atomic(int) i;
@@ -102,5 +106,23 @@
       _Atomic(int) b;
     };
     Y y = { X(4), 5 };
+
+    // CHECK-LABEL: define {{.*}} @__cxx_global_var_init
+    // CHECK: tail call void @llvm.memcpy.p0.p0.i32(ptr{{.*}} @_ZN7PR180978constant2y2E, ptr{{.*}} @_ZN7PR180978constantL1xE, i32 3, i1 false)
+    // CHECK: %0 = load i32, ptr @_ZN7PR180978constant1zE
+    // CHECK: store i32 %0, ptr getelementptr inbounds (%"struct.PR18097::constant::Y", ptr @_ZN7PR180978constant2y2E, i32 0, i32 1)
+    int z;
+    constexpr X x{1};
+    Y y2 = { x, z };
+
+    typedef union {
+      unsigned int f0;
+    } Union0;
+
+    typedef struct {
+      _Atomic(Union0) f1;
+    } Struct0;
+
+    Struct0 g = {};
   }
 }
Index: clang/lib/AST/ExprConstant.cpp
===================================================================
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -15064,6 +15064,7 @@
           E, Unqual, ScopeKind::FullExpression, LV);
       if (!EvaluateAtomic(E, &LV, Value, Info))
         return false;
+      Result = Value;
     } else {
       if (!EvaluateAtomic(E, nullptr, Result, Info))
         return false;
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -488,6 +488,8 @@
   (`#63010 <https://github.com/llvm/llvm-project/issues/63010>`_).
 - Fix rejects-valid when consteval operator appears inside of a template.
   (`#62886 <https://github.com/llvm/llvm-project/issues/62886>`_).
+- Fix crash for code using ``_Atomic`` types in C++
+  (`See patch <https://reviews.llvm.org/D152303>`_).
 
 Bug Fixes to Compiler Builtins
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152303.529703.patch
Type: text/x-patch
Size: 2687 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230608/5b051312/attachment.bin>


More information about the cfe-commits mailing list