[PATCH] D102015: [clang CodeGen] Don't crash on large atomic function parameter.

Eli Friedman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri May 14 13:33:49 PDT 2021


efriedma updated this revision to Diff 345543.
efriedma added a comment.

Figured out a way to test the EmitDelegateCallArg codepath.  (A thunk doesn't work because the code is guarded by `!CurFuncIsThunk`.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102015

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/test/CodeGen/big-atomic-ops.c
  clang/test/CodeGenCXX/atomic.cpp


Index: clang/test/CodeGenCXX/atomic.cpp
===================================================================
--- clang/test/CodeGenCXX/atomic.cpp
+++ clang/test/CodeGenCXX/atomic.cpp
@@ -15,3 +15,13 @@
   }
   void f(Ptr<int> *a) { a->f(); }
 }
+
+namespace DelegatingParameter {
+  // Check that we're delegating the complete ctor to the base
+  // ctor, and that doesn't crash.
+  // CHECK-LABEL: define void @_ZN19DelegatingParameter1SC1EU7_AtomicNS_1ZE
+  // CHECK: call void @_ZN19DelegatingParameter1SC2EU7_AtomicNS_1ZE
+  struct Z { int z[100]; };
+  struct S { S(_Atomic Z); };
+  S::S(_Atomic Z) {}
+}
Index: clang/test/CodeGen/big-atomic-ops.c
===================================================================
--- clang/test/CodeGen/big-atomic-ops.c
+++ clang/test/CodeGen/big-atomic-ops.c
@@ -311,4 +311,10 @@
   // CHECK: }
 }
 
+// Check this doesn't crash
+// CHECK: @test_atomic_array_param(
+void test_atomic_array_param(_Atomic(struct foo) a) {
+  test_atomic_array_param(a);
+}
+
 #endif
Index: clang/lib/CodeGen/CGDecl.cpp
===================================================================
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp
@@ -2473,7 +2473,7 @@
     // Push a destructor cleanup for this parameter if the ABI requires it.
     // Don't push a cleanup in a thunk for a method that will also emit a
     // cleanup.
-    if (hasAggregateEvaluationKind(Ty) && !CurFuncIsThunk &&
+    if (Ty->isRecordType() && !CurFuncIsThunk &&
         Ty->castAs<RecordType>()->getDecl()->isParamDestroyedInCallee()) {
       if (QualType::DestructionKind DtorKind =
               D.needsDestruction(getContext())) {
Index: clang/lib/CodeGen/CGCall.cpp
===================================================================
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -3698,7 +3698,7 @@
   }
 
   // Deactivate the cleanup for the callee-destructed param that was pushed.
-  if (hasAggregateEvaluationKind(type) && !CurFuncIsThunk &&
+  if (type->isRecordType() && !CurFuncIsThunk &&
       type->castAs<RecordType>()->getDecl()->isParamDestroyedInCallee() &&
       param->needsDestruction(getContext())) {
     EHScopeStack::stable_iterator cleanup =
@@ -4269,7 +4269,7 @@
   // In the Microsoft C++ ABI, aggregate arguments are destructed by the callee.
   // However, we still have to push an EH-only cleanup in case we unwind before
   // we make it to the call.
-  if (HasAggregateEvalKind &&
+  if (type->isRecordType() &&
       type->castAs<RecordType>()->getDecl()->isParamDestroyedInCallee()) {
     // If we're using inalloca, use the argument memory.  Otherwise, use a
     // temporary.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102015.345543.patch
Type: text/x-patch
Size: 2661 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210514/805f8c48/attachment.bin>


More information about the cfe-commits mailing list