[clang] 698568b - [clang CodeGen] Don't crash on large atomic function parameter.

Eli Friedman via cfe-commits cfe-commits at lists.llvm.org
Mon May 17 13:18:48 PDT 2021


Author: Eli Friedman
Date: 2021-05-17T13:18:23-07:00
New Revision: 698568b74c93ab6d9374adc8bdc6e60fbcf41ff1

URL: https://github.com/llvm/llvm-project/commit/698568b74c93ab6d9374adc8bdc6e60fbcf41ff1
DIFF: https://github.com/llvm/llvm-project/commit/698568b74c93ab6d9374adc8bdc6e60fbcf41ff1.diff

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

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.  Just use isRecordType() instead.

Differential Revision: https://reviews.llvm.org/D102015

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index b665e6758e3dd..241479de58571 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -3712,7 +3712,7 @@ void CodeGenFunction::EmitDelegateCallArg(CallArgList &args,
   }
 
   // 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 =
@@ -4283,7 +4283,7 @@ void CodeGenFunction::EmitCallArg(CallArgList &args, const Expr *E,
   // 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.

diff  --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index 10781dbb51834..22bd8d14b87a8 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -2473,7 +2473,7 @@ void CodeGenFunction::EmitParmDecl(const VarDecl &D, ParamValue Arg,
     // 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())) {

diff  --git a/clang/test/CodeGen/big-atomic-ops.c b/clang/test/CodeGen/big-atomic-ops.c
index c584ffcf7cf75..0dc43caa64723 100644
--- a/clang/test/CodeGen/big-atomic-ops.c
+++ b/clang/test/CodeGen/big-atomic-ops.c
@@ -311,4 +311,10 @@ void atomic_init_foo()
   // 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

diff  --git a/clang/test/CodeGenCXX/atomic.cpp b/clang/test/CodeGenCXX/atomic.cpp
index f40cb6d6ad14d..e5ecf0cbf74b7 100644
--- a/clang/test/CodeGenCXX/atomic.cpp
+++ b/clang/test/CodeGenCXX/atomic.cpp
@@ -15,3 +15,13 @@ namespace PR11411 {
   }
   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) {}
+}


        


More information about the cfe-commits mailing list