[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
Thu May 6 12:38:49 PDT 2021


efriedma created this revision.
efriedma added reviewers: rsmith, ahatanak, rjmccall.
Herald added a subscriber: jfb.
efriedma requested review of this revision.
Herald added a project: clang.

I wouldn't recommend writing code like the testcase; a function parameter isn't atomic, so using an atomic type doesn't really make sense.  But it's valid, so clang shouldn't crash on it.

The code was assuming hasAggregateEvaluationKind(Ty) implies Ty is a RecordType, which isn't true.  Looking at the code, I think the only other possibility for a parameter is an atomic type, though.  Atomic types are always trivially destructible, I think.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102015

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


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,9 @@
   // CHECK: }
 }
 
+// Check this doesn't crash
+// CHECK: @test_atomic_array_param(
+void test_atomic_array_param(_Atomic(struct foo) a) {
+}
+
 #endif
Index: clang/lib/CodeGen/CGDecl.cpp
===================================================================
--- clang/lib/CodeGen/CGDecl.cpp
+++ clang/lib/CodeGen/CGDecl.cpp
@@ -2474,6 +2474,7 @@
     // Don't push a cleanup in a thunk for a method that will also emit a
     // cleanup.
     if (hasAggregateEvaluationKind(Ty) && !CurFuncIsThunk &&
+        !Ty->isAtomicType() &&
         Ty->castAs<RecordType>()->getDecl()->isParamDestroyedInCallee()) {
       if (QualType::DestructionKind DtorKind =
               D.needsDestruction(getContext())) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102015.343477.patch
Type: text/x-patch
Size: 918 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210506/1c57a233/attachment-0001.bin>


More information about the cfe-commits mailing list