[PATCH] D111293: [CFE][Codegen][In-progress] Remove CodeGenFunction::InitTempAlloca()

Mahesha S via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 7 22:17:24 PDT 2021


hsmhsm updated this revision to Diff 378092.
hsmhsm added a comment.

Add lit test - CodeGenObjC/static-alloc-init.m


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111293

Files:
  clang/lib/CodeGen/CGObjCGNU.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/CodeGenObjC/static-alloc-init.m


Index: clang/test/CodeGenObjC/static-alloc-init.m
===================================================================
--- /dev/null
+++ clang/test/CodeGenObjC/static-alloc-init.m
@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-freebsd -S -emit-llvm -fobjc-runtime=gnustep-2.0 -o - %s | FileCheck %s
+
+typedef struct {
+  int x[12];
+} Big;
+
+ at protocol P
+- (Big) foo;
+ at end
+
+// CHECK-LABEL:    define{{.*}} void @test(
+// CHECK:   %p.addr = alloca i8*, align 8
+// CHECK-NEXT:   %big = alloca %struct.Big, align 4
+// CHECK-NEXT:   %tmp = alloca i8*, align 8
+// CHECK-NEXT:   %null = alloca %struct.Big, align 4
+// CHECK-NEXT:   store i8* %p, i8** %p.addr, align 8
+// CHECK-NEXT:   br label %for.cond
+//
+// CHECK-LABEL: for.cond:
+// CHECK-NEXT:   %0 = load i8*, i8** %p.addr, align 8
+// CHECK-NEXT:   %1 = icmp eq i8* %0, null
+// CHECK-NEXT:   br i1 %1, label %continue, label %msgSend
+//
+// CHECK-LABEL: msgSend:
+// CHECK-NEXT:   store i8* %0, i8** %tmp, align 8
+// CHECK-NEXT:   %2 = call { i8*, i8*, i8*, i32, i8* (i8*, i8*, ...)* }* @objc_msg_lookup_sender(i8** %tmp, i8* bitcast ({ i8*, i8* }* @".objc_selector_foo_{?=[12i]}16\010:8" to i8*), i8* null)
+// CHECK-NEXT:   %3 = getelementptr inbounds { i8*, i8*, i8*, i32, i8* (i8*, i8*, ...)* }, { i8*, i8*, i8*, i32, i8* (i8*, i8*, ...)* }* %2, i32 0, i32 4
+// CHECK-NEXT:   %4 = load i8* (i8*, i8*, ...)*, i8* (i8*, i8*, ...)** %3, align 8
+// CHECK-NEXT:   %5 = load volatile i8*, i8** %tmp, align 8
+// CHECK-NEXT:   %6 = bitcast i8* (i8*, i8*, ...)* %4 to void (%struct.Big*, i8*, i8*)*
+// CHECK-NEXT:   call void %6(%struct.Big* sret(%struct.Big) align 4 %big, i8* %5, i8* bitcast ({ i8*, i8* }* @".objc_selector_foo_{?=[12i]}16\010:8" to i8*))
+// CHECK-NEXT:   br label %continue
+//
+// CHECK-LABEL: continue:
+// CHECK-NEXT:   %7 = phi %struct.Big* [ %big, %msgSend ], [ %null, %for.cond ]
+// CHECK-NEXT:   store %struct.Big zeroinitializer, %struct.Big* %null, align 4
+// CHECK-NEXT:   br label %for.cond
+
+void test(id<P> p) {
+  for (;;) {
+    Big big = [p foo];
+  }
+}
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===================================================================
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -981,7 +981,8 @@
   // precise source location of the checked return statement.
   if (requiresReturnValueCheck()) {
     ReturnLocation = CreateDefaultAlignTempAlloca(Int8PtrTy, "return.sloc.ptr");
-    InitTempAlloca(ReturnLocation, llvm::ConstantPointerNull::get(Int8PtrTy));
+    Builder.CreateStore(llvm::ConstantPointerNull::get(Int8PtrTy),
+                        ReturnLocation);
   }
 
   // Emit subprogram debug descriptor.
Index: clang/lib/CodeGen/CGObjCGNU.cpp
===================================================================
--- clang/lib/CodeGen/CGObjCGNU.cpp
+++ clang/lib/CodeGen/CGObjCGNU.cpp
@@ -2760,7 +2760,7 @@
       llvm::PHINode *phi = Builder.CreatePHI(v.getType(), 2);
       llvm::Type *RetTy = v.getElementType();
       Address NullVal = CGF.CreateTempAlloca(RetTy, v.getAlignment(), "null");
-      CGF.InitTempAlloca(NullVal, llvm::Constant::getNullValue(RetTy));
+      Builder.CreateStore(llvm::Constant::getNullValue(RetTy), NullVal);
       phi->addIncoming(v.getPointer(), messageBB);
       phi->addIncoming(NullVal.getPointer(), startBB);
       msgRet = RValue::getAggregate(Address(phi, v.getAlignment()));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111293.378092.patch
Type: text/x-patch
Size: 3425 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211008/a5c08bb3/attachment-0001.bin>


More information about the cfe-commits mailing list