[PATCH] D91607: [clang][Sparc] Fix __builtin_extract_return_addr etc.

Rainer Orth via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 17 03:12:23 PST 2020


ro created this revision.
ro added reviewers: efriedma, brad.
Herald added subscribers: atanasyan, fedor.sergeev, kristof.beyls, arichardson, sdardis, jyknight.
Herald added a project: clang.
ro requested review of this revision.

While investigating the failures of `symbolize_pc.cpp` and `symbolize_pc_inline.cpp` on SPARC (both Solaris and Linux), I noticed that `__builtin_extract_return_addr` is a no-op in `clang` on all targets, while `gcc` has non-default implementations for arm, mips, s390, and sparc.

This patch provides the SPARC implementation.  For background see `SparcISelLowering.cpp` (`SparcTargetLowering::LowerReturn_32`) , the SPARC psABI p.3-12, `%i7` and p.3-16/17, and SCD 2.4.1, p.3P-10, `%i7` and p.3P-15.

Tested (after enabling the `sanitizer_common` tests on SPARC) on `sparcv9-sun-solaris2.11`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D91607

Files:
  clang/lib/CodeGen/TargetInfo.cpp


Index: clang/lib/CodeGen/TargetInfo.cpp
===================================================================
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -9221,6 +9221,32 @@
 public:
   SparcV8TargetCodeGenInfo(CodeGenTypes &CGT)
       : TargetCodeGenInfo(std::make_unique<SparcV8ABIInfo>(CGT)) {}
+
+  llvm::Value *decodeReturnAddress(CodeGen::CodeGenFunction &CGF,
+                                   llvm::Value *Address) const override {
+    llvm::Value *AddrAsInt = Address;
+    AddrAsInt = CGF.Builder.CreatePtrToInt(AddrAsInt, CGF.IntPtrTy);
+    AddrAsInt = CGF.Builder.CreateAdd(AddrAsInt,
+                                      llvm::ConstantInt::get(CGF.IntPtrTy, 8));
+    if (isAggregateTypeForABI(CGF.CurFnInfo->getReturnType()))
+      AddrAsInt = CGF.Builder.CreateAdd(
+          AddrAsInt, llvm::ConstantInt::get(CGF.IntPtrTy, 4));
+    AddrAsInt = CGF.Builder.CreateIntToPtr(AddrAsInt, Address->getType());
+    return AddrAsInt;
+  }
+
+  llvm::Value *encodeReturnAddress(CodeGen::CodeGenFunction &CGF,
+                                   llvm::Value *Address) const override {
+    llvm::Value *AddrAsInt = Address;
+    AddrAsInt = CGF.Builder.CreatePtrToInt(AddrAsInt, CGF.IntPtrTy);
+    AddrAsInt = CGF.Builder.CreateAdd(AddrAsInt,
+                                      llvm::ConstantInt::get(CGF.IntPtrTy, -8));
+    if (isAggregateTypeForABI(CGF.CurFnInfo->getReturnType()))
+      AddrAsInt = CGF.Builder.CreateAdd(
+          AddrAsInt, llvm::ConstantInt::get(CGF.IntPtrTy, -4));
+    AddrAsInt = CGF.Builder.CreateIntToPtr(AddrAsInt, Address->getType());
+    return AddrAsInt;
+  }
 };
 } // end anonymous namespace
 
@@ -9495,6 +9521,26 @@
 
   bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
                                llvm::Value *Address) const override;
+
+  llvm::Value *decodeReturnAddress(CodeGen::CodeGenFunction &CGF,
+                                   llvm::Value *Address) const override {
+    llvm::Value *AddrAsInt = Address;
+    AddrAsInt = CGF.Builder.CreatePtrToInt(AddrAsInt, CGF.IntPtrTy);
+    AddrAsInt = CGF.Builder.CreateAdd(AddrAsInt,
+                                      llvm::ConstantInt::get(CGF.IntPtrTy, 8));
+    AddrAsInt = CGF.Builder.CreateIntToPtr(AddrAsInt, Address->getType());
+    return AddrAsInt;
+  }
+
+  llvm::Value *encodeReturnAddress(CodeGen::CodeGenFunction &CGF,
+                                   llvm::Value *Address) const override {
+    llvm::Value *AddrAsInt = Address;
+    AddrAsInt = CGF.Builder.CreatePtrToInt(AddrAsInt, CGF.IntPtrTy);
+    AddrAsInt = CGF.Builder.CreateAdd(AddrAsInt,
+                                      llvm::ConstantInt::get(CGF.IntPtrTy, -8));
+    AddrAsInt = CGF.Builder.CreateIntToPtr(AddrAsInt, Address->getType());
+    return AddrAsInt;
+  }
 };
 } // end anonymous namespace
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91607.305714.patch
Type: text/x-patch
Size: 2855 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201117/0a407ca1/attachment.bin>


More information about the cfe-commits mailing list