[llvm-branch-commits] Add pointer field protection feature. (PR #133538)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Mar 28 15:38:22 PDT 2025


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff ee0ee253d617aa4cddfe5216f93365645579b54d 3bdbe711b5f937d564e1883ec94e1c5ecbd87750 --extensions ,cpp,h -- clang/test/CodeGen/pfp-attribute-disable.cpp clang/test/CodeGen/pfp-load-store.cpp clang/test/CodeGen/pfp-memcpy.cpp clang/test/CodeGen/pfp-null-init.cpp clang/test/CodeGen/pfp-struct-gep.cpp clang/include/clang/AST/ASTContext.h clang/include/clang/Basic/LangOptions.h clang/lib/AST/ASTContext.cpp clang/lib/AST/ExprConstant.cpp clang/lib/AST/Type.cpp clang/lib/AST/TypePrinter.cpp clang/lib/CodeGen/CGCall.cpp clang/lib/CodeGen/CGClass.cpp clang/lib/CodeGen/CGExpr.cpp clang/lib/CodeGen/CGExprAgg.cpp clang/lib/CodeGen/CGExprCXX.cpp clang/lib/CodeGen/CGExprConstant.cpp clang/lib/CodeGen/CodeGenFunction.cpp clang/lib/CodeGen/CodeGenFunction.h clang/lib/CodeGen/CodeGenModule.cpp clang/lib/CodeGen/CodeGenModule.h clang/lib/CodeGen/ItaniumCXXABI.cpp clang/lib/CodeGen/MicrosoftCXXABI.cpp clang/lib/Driver/ToolChains/Clang.cpp clang/lib/Sema/SemaDeclAttr.cpp clang/lib/Sema/SemaExprCXX.cpp clang/test/CodeGenCXX/trivial_abi.cpp libcxx/include/__config libcxx/include/__functional/function.h libcxx/include/__memory/shared_ptr.h libcxx/include/__memory/unique_ptr.h libcxx/include/__tree libcxx/include/__type_traits/is_trivially_relocatable.h libcxx/include/__vector/vector.h libcxx/include/typeinfo libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp libcxxabi/include/__cxxabi_config.h libcxxabi/src/private_typeinfo.h llvm/include/llvm/Analysis/PtrUseVisitor.h llvm/include/llvm/Transforms/Utils/Local.h llvm/lib/Analysis/PtrUseVisitor.cpp llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp llvm/lib/Transforms/Scalar/SROA.cpp llvm/lib/Transforms/Utils/SimplifyCFG.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 9d824231d0..b4ac45a920 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -1299,8 +1299,7 @@ static llvm::Value *CoerceIntOrPtrToIntOrPtr(llvm::Value *Val,
 /// destination type; in this situation the values of bits which not
 /// present in the src are undefined.
 static llvm::Value *CreateCoercedLoad(Address Src, QualType SrcFETy,
-                                      llvm::Type *Ty,
-                                      CodeGenFunction &CGF) {
+                                      llvm::Type *Ty, CodeGenFunction &CGF) {
   llvm::Type *SrcTy = Src.getElementType();
 
   // If SrcTy and Ty are the same, just do a load.
@@ -1344,7 +1343,8 @@ static llvm::Value *CreateCoercedLoad(Address Src, QualType SrcFETy,
       CharUnits Offset = CharUnits::Zero();
       llvm::Value *Val = llvm::UndefValue::get(AT);
       for (unsigned i = 0; i != AT->getNumElements(); ++i, Offset += wordSize)
-        Val = CGF.Builder.CreateInsertValue(Val, LoadCoercedField(Offset, ET), i);
+        Val =
+            CGF.Builder.CreateInsertValue(Val, LoadCoercedField(Offset, ET), i);
       return Val;
     }
     auto *ST = cast<llvm::StructType>(Ty);
@@ -1426,10 +1426,8 @@ static llvm::Value *CreateCoercedLoad(Address Src, QualType SrcFETy,
   return CGF.Builder.CreateLoad(Tmp);
 }
 
-void CodeGenFunction::CreateCoercedStore(llvm::Value *Src,
-                                         QualType SrcFETy,
-                                         Address Dst,
-                                         llvm::TypeSize DstSize,
+void CodeGenFunction::CreateCoercedStore(llvm::Value *Src, QualType SrcFETy,
+                                         Address Dst, llvm::TypeSize DstSize,
                                          bool DstIsVolatile) {
   if (!DstSize)
     return;
@@ -4119,8 +4117,7 @@ void CodeGenFunction::EmitFunctionEpilog(const CGFunctionInfo &FI,
 
       auto eltAddr = Builder.CreateStructGEP(addr, i);
       llvm::Value *elt = CreateCoercedLoad(
-          eltAddr,
-          RetTy,
+          eltAddr, RetTy,
           unpaddedStruct ? unpaddedStruct->getElementType(unpaddedIndex++)
                          : unpaddedCoercionType,
           *this);
@@ -5711,8 +5708,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
         if (ABIArgInfo::isPaddingForCoerceAndExpand(eltType)) continue;
         Address eltAddr = Builder.CreateStructGEP(addr, i);
         llvm::Value *elt = CreateCoercedLoad(
-            eltAddr,
-            I->Ty,
+            eltAddr, I->Ty,
             unpaddedStruct ? unpaddedStruct->getElementType(unpaddedIndex++)
                            : unpaddedCoercionType,
             *this);
diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp
index ae1d78baed..9d3784cf63 100644
--- a/clang/lib/CodeGen/CGClass.cpp
+++ b/clang/lib/CodeGen/CGClass.cpp
@@ -672,7 +672,8 @@ static void EmitMemberInitializer(CodeGenFunction &CGF,
     QualType BaseElementTy = CGF.getContext().getBaseElementType(Array);
     CXXConstructExpr *CE = dyn_cast<CXXConstructExpr>(MemberInit->getInit());
     if (BaseElementTy.isPODType(CGF.getContext()) ||
-        (CE && isMemcpyEquivalentSpecialMember(CGF.CGM, CE->getConstructor()))) {
+        (CE &&
+         isMemcpyEquivalentSpecialMember(CGF.CGM, CE->getConstructor()))) {
       unsigned SrcArgIndex =
           CGF.CGM.getCXXABI().getSrcArgforCopyCtor(Constructor, Args);
       llvm::Value *SrcPtr
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp
index e5bf8a8315..af28cdd81e 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -2197,7 +2197,8 @@ Address CodeGenFunction::EmitAddressOfPFPField(Address RecordPtr,
           {RecordPtr.getBasePointer(), Builder.getInt64(Offset.getQuantity()),
            llvm::MetadataAsValue::get(
                getLLVMContext(),
-               llvm::MDString::get(getLLVMContext(), CGM.getPFPFieldName(Field))),
+               llvm::MDString::get(getLLVMContext(),
+                                   CGM.getPFPFieldName(Field))),
            getContext().arePFPFieldsTriviallyRelocatable(Field->getParent())
                ? Builder.getFalse()
                : Builder.getTrue()}),
diff --git a/libcxx/include/__memory/unique_ptr.h b/libcxx/include/__memory/unique_ptr.h
index 5e4fa857eb..289bd6ffa2 100644
--- a/libcxx/include/__memory/unique_ptr.h
+++ b/libcxx/include/__memory/unique_ptr.h
@@ -393,7 +393,8 @@ private:
 };
 
 template <class _Tp, class _Dp>
-class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr<_Tp[], _Dp> _LIBCPP_MAYBE_FORCE_NONSTANDARD_LAYOUT {
+class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr<_Tp[], _Dp>
+    _LIBCPP_MAYBE_FORCE_NONSTANDARD_LAYOUT {
 public:
   typedef _Tp element_type;
   typedef _Dp deleter_type;
diff --git a/libcxxabi/src/private_typeinfo.h b/libcxxabi/src/private_typeinfo.h
index a3bc0bffd4..c472bf0761 100644
--- a/libcxxabi/src/private_typeinfo.h
+++ b/libcxxabi/src/private_typeinfo.h
@@ -145,7 +145,7 @@ public:
 // Has one non-virtual public base class at offset zero
 class _LIBCXXABI_TYPE_VIS __si_class_type_info : public __class_type_info {
 public:
-  _LIBCXXABI_NO_PFP const __class_type_info *__base_type;
+  _LIBCXXABI_NO_PFP const __class_type_info* __base_type;
 
   _LIBCXXABI_HIDDEN virtual ~__si_class_type_info();
 
@@ -204,7 +204,7 @@ public:
 class _LIBCXXABI_TYPE_VIS __pbase_type_info : public __shim_type_info {
 public:
   unsigned int __flags;
-  _LIBCXXABI_NO_PFP const __shim_type_info *__pointee;
+  _LIBCXXABI_NO_PFP const __shim_type_info* __pointee;
 
   enum __masks {
     __const_mask = 0x1,
@@ -245,7 +245,7 @@ public:
 class _LIBCXXABI_TYPE_VIS __pointer_to_member_type_info
     : public __pbase_type_info {
 public:
-  _LIBCXXABI_NO_PFP const __class_type_info *__context;
+  _LIBCXXABI_NO_PFP const __class_type_info* __context;
 
   _LIBCXXABI_HIDDEN virtual ~__pointer_to_member_type_info();
   _LIBCXXABI_HIDDEN virtual bool can_catch(const __shim_type_info *,
diff --git a/llvm/lib/Analysis/PtrUseVisitor.cpp b/llvm/lib/Analysis/PtrUseVisitor.cpp
index b34f380b7d..d9e9e8d20d 100644
--- a/llvm/lib/Analysis/PtrUseVisitor.cpp
+++ b/llvm/lib/Analysis/PtrUseVisitor.cpp
@@ -21,9 +21,9 @@ void detail::PtrUseVisitorBase::enqueueUsers(Value &I) {
   for (Use &U : I.uses()) {
     if (VisitedUses.insert(&U).second) {
       UseToVisit NewU = {
-        UseToVisit::UseAndIsOffsetKnownPair(&U, IsOffsetKnown),
-        Offset,
-        ProtectedField,
+          UseToVisit::UseAndIsOffsetKnownPair(&U, IsOffsetKnown),
+          Offset,
+          ProtectedField,
       };
       Worklist.push_back(std::move(NewU));
     }
diff --git a/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp b/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
index bdaaedcfce..5128ec4faf 100644
--- a/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
+++ b/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
@@ -474,7 +474,7 @@ bool expandProtectedFieldPtr(Function &Intr) {
   FunctionCallee EmuAuthIntr = M.getOrInsertFunction("__emupac_autda", EmuFnTy);
 
   auto CreateSign = [&](IRBuilder<> &B, Value *Val, Value *Disc,
-                       OperandBundleDef DSBundle) {
+                        OperandBundleDef DSBundle) {
     Function *F = B.GetInsertBlock()->getParent();
     Attribute FSAttr = F->getFnAttribute("target-features");
     if (FSAttr.isValid() && FSAttr.getValueAsString().contains("+pauth"))
@@ -483,7 +483,7 @@ bool expandProtectedFieldPtr(Function &Intr) {
   };
 
   auto CreateAuth = [&](IRBuilder<> &B, Value *Val, Value *Disc,
-                       OperandBundleDef DSBundle) {
+                        OperandBundleDef DSBundle) {
     Function *F = B.GetInsertBlock()->getParent();
     Attribute FSAttr = F->getFnAttribute("target-features");
     if (FSAttr.isValid() && FSAttr.getValueAsString().contains("+pauth"))
@@ -616,8 +616,7 @@ bool expandProtectedFieldPtr(Function &Intr) {
       auto *SI = cast<StoreInst>(I);
       IRBuilder<> B(SI);
       auto *FieldAddr = SI->getPointerOperand();
-      auto *SIValInt =
-          B.CreatePtrToInt(SI->getValueOperand(), B.getInt64Ty());
+      auto *SIValInt = B.CreatePtrToInt(SI->getValueOperand(), B.getInt64Ty());
       Value *Sign;
       switch (Encoding) {
       case PointerEncoding::Rotate:
@@ -682,7 +681,7 @@ bool expandProtectedFieldPtr(Function &Intr) {
   return true;
 }
 
-}
+} // namespace
 
 bool PreISelIntrinsicLowering::lowerIntrinsics(Module &M) const {
   bool Changed = false;
diff --git a/llvm/lib/Transforms/Scalar/SROA.cpp b/llvm/lib/Transforms/Scalar/SROA.cpp
index ca428f4f5b..cdc9523c70 100644
--- a/llvm/lib/Transforms/Scalar/SROA.cpp
+++ b/llvm/lib/Transforms/Scalar/SROA.cpp
@@ -534,7 +534,8 @@ class Slice {
 public:
   Slice() = default;
 
-  Slice(uint64_t BeginOffset, uint64_t EndOffset, Use *U, bool IsSplittable, Value *ProtectedField)
+  Slice(uint64_t BeginOffset, uint64_t EndOffset, Use *U, bool IsSplittable,
+        Value *ProtectedField)
       : BeginOffset(BeginOffset), EndOffset(EndOffset),
         UseAndIsSplittable(U, IsSplittable), ProtectedField(ProtectedField) {}
 
@@ -1077,7 +1078,8 @@ private:
       EndOffset = AllocSize;
     }
 
-    AS.Slices.push_back(Slice(BeginOffset, EndOffset, U, IsSplittable, ProtectedField));
+    AS.Slices.push_back(
+        Slice(BeginOffset, EndOffset, U, IsSplittable, ProtectedField));
   }
 
   void visitBitCastInst(BitCastInst &BC) {

``````````

</details>


https://github.com/llvm/llvm-project/pull/133538


More information about the llvm-branch-commits mailing list