ajpaverd updated this revision to Diff 225955.
ajpaverd marked 3 inline comments as done.
ajpaverd added a comment.

Formatting fixes for CFGuard patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65761

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Driver/ToolChains/MSVC.cpp
  llvm/include/llvm/CodeGen/MachineFunction.h
  llvm/include/llvm/Transforms/CFGuard.h
  llvm/lib/CodeGen/CFGuardLongjmp.cpp
  llvm/lib/Target/AArch64/AArch64CallingConvention.h
  llvm/lib/Target/ARM/ARMCallingConv.h
  llvm/lib/Target/X86/X86RegisterInfo.cpp
  llvm/lib/Target/X86/X86TargetMachine.cpp
  llvm/lib/Transforms/CFGuard/CFGuard.cpp

Index: llvm/lib/Transforms/CFGuard/CFGuard.cpp
===================================================================
--- llvm/lib/Transforms/CFGuard/CFGuard.cpp
+++ llvm/lib/Transforms/CFGuard/CFGuard.cpp
@@ -17,8 +17,8 @@
 #include "llvm/ADT/Statistic.h"
 #include "llvm/ADT/Triple.h"
 #include "llvm/IR/CallingConv.h"
-#include "llvm/IR/Instruction.h"
 #include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/Instruction.h"
 #include "llvm/InitializePasses.h"
 #include "llvm/Pass.h"
 
@@ -196,8 +196,7 @@
     GuardFnGlobal = ConstantExpr::getBitCast(GuardFnGlobal, PTy);
 
   // Load the global as a pointer to a function of the same type.
-  LoadInst *GuardDispatchLoad =
-      B.CreateLoad(CalledOperandType, GuardFnGlobal);
+  LoadInst *GuardDispatchLoad = B.CreateLoad(CalledOperandType, GuardFnGlobal);
 
   // Add the original call target as a cfguardtarget operand bundle.
   SmallVector<llvm::OperandBundleDef, 1> Bundles;
@@ -206,11 +205,11 @@
 
   // Create a copy of the call/invoke instruction and add the new bundle.
   CallBase *NewCB;
-  if (CallInst* CI = dyn_cast<CallInst>(CB)) {
+  if (CallInst *CI = dyn_cast<CallInst>(CB)) {
     NewCB = CallInst::Create(CI, Bundles, CB);
   } else {
     assert(isa<InvokeInst>(CB) && "Unknown indirect call type");
-    InvokeInst* II = cast<InvokeInst>(CB);
+    InvokeInst *II = cast<InvokeInst>(CB);
     NewCB = llvm::InvokeInst::Create(II, Bundles, CB);
   }
 
@@ -237,17 +236,17 @@
 
   // Set up prototypes for the guard check and dispatch functions.
   GuardFnType = FunctionType::get(Type::getVoidTy(M.getContext()),
-                          {Type::getInt8PtrTy(M.getContext())}, false);
+                                  {Type::getInt8PtrTy(M.getContext())}, false);
   GuardFnPtrType = PointerType::get(GuardFnType, 0);
 
   // Get or insert the guard check or dispatch global symbols.
   if (GuardMechanism == CF_Check) {
-    GuardFnGlobal = M.getOrInsertGlobal(
-      "__guard_check_icall_fptr", GuardFnPtrType);
+    GuardFnGlobal =
+        M.getOrInsertGlobal("__guard_check_icall_fptr", GuardFnPtrType);
   } else {
     assert(GuardMechanism == CF_Dispatch && "Invalid CFGuard mechanism");
-    GuardFnGlobal = M.getOrInsertGlobal(
-      "__guard_dispatch_icall_fptr", GuardFnPtrType);
+    GuardFnGlobal =
+        M.getOrInsertGlobal("__guard_dispatch_icall_fptr", GuardFnPtrType);
   }
 
   return true;
Index: llvm/lib/Target/X86/X86TargetMachine.cpp
===================================================================
--- llvm/lib/Target/X86/X86TargetMachine.cpp
+++ llvm/lib/Target/X86/X86TargetMachine.cpp
@@ -419,7 +419,7 @@
   // Add Control Flow Guard checks.
   const Triple &TT = TM->getTargetTriple();
   if (TT.isOSWindows()) {
-    if(TT.getArch() == Triple::x86_64) {
+    if (TT.getArch() == Triple::x86_64) {
       addPass(createCFGuardDispatchPass());
     } else {
       addPass(createCFGuardCheckPass());
Index: llvm/lib/Target/X86/X86RegisterInfo.cpp
===================================================================
--- llvm/lib/Target/X86/X86RegisterInfo.cpp
+++ llvm/lib/Target/X86/X86RegisterInfo.cpp
@@ -343,8 +343,8 @@
     }
   case CallingConv::CFGuard_Check:
     assert(!Is64Bit && "CFGuard check mechanism only used on 32-bit X86");
-    return (HasSSE ? CSR_Win32_CFGuard_Check_SaveList :
-                       CSR_Win32_CFGuard_Check_NoSSE_SaveList);
+    return (HasSSE ? CSR_Win32_CFGuard_Check_SaveList
+                   : CSR_Win32_CFGuard_Check_NoSSE_SaveList);
   case CallingConv::Cold:
     if (Is64Bit)
       return CSR_64_MostRegs_SaveList;
@@ -461,8 +461,8 @@
     }
   case CallingConv::CFGuard_Check:
     assert(!Is64Bit && "CFGuard check mechanism only used on 32-bit X86");
-    return (HasSSE ? CSR_Win32_CFGuard_Check_RegMask :
-                       CSR_Win32_CFGuard_Check_NoSSE_RegMask);
+    return (HasSSE ? CSR_Win32_CFGuard_Check_RegMask
+                   : CSR_Win32_CFGuard_Check_NoSSE_RegMask);
   case CallingConv::Cold:
     if (Is64Bit)
       return CSR_64_MostRegs_RegMask;
Index: llvm/lib/Target/ARM/ARMCallingConv.h
===================================================================
--- llvm/lib/Target/ARM/ARMCallingConv.h
+++ llvm/lib/Target/ARM/ARMCallingConv.h
@@ -33,8 +33,8 @@
                      CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags,
                      CCState &State);
 bool CC_ARM_Win32_CFGuard_Check(unsigned ValNo, MVT ValVT, MVT LocVT,
-                     CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags,
-                     CCState &State);
+                                CCValAssign::LocInfo LocInfo,
+                                ISD::ArgFlagsTy ArgFlags, CCState &State);
 bool RetCC_ARM_AAPCS(unsigned ValNo, MVT ValVT, MVT LocVT,
                      CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags,
                      CCState &State);
Index: llvm/lib/Target/AArch64/AArch64CallingConvention.h
===================================================================
--- llvm/lib/Target/AArch64/AArch64CallingConvention.h
+++ llvm/lib/Target/AArch64/AArch64CallingConvention.h
@@ -32,8 +32,8 @@
                              CCValAssign::LocInfo LocInfo,
                              ISD::ArgFlagsTy ArgFlags, CCState &State);
 bool CC_AArch64_Win64_CFGuard_Check(unsigned ValNo, MVT ValVT, MVT LocVT,
-                             CCValAssign::LocInfo LocInfo,
-                             ISD::ArgFlagsTy ArgFlags, CCState &State);
+                                    CCValAssign::LocInfo LocInfo,
+                                    ISD::ArgFlagsTy ArgFlags, CCState &State);
 bool CC_AArch64_WebKit_JS(unsigned ValNo, MVT ValVT, MVT LocVT,
                           CCValAssign::LocInfo LocInfo,
                           ISD::ArgFlagsTy ArgFlags, CCState &State);
Index: llvm/lib/CodeGen/CFGuardLongjmp.cpp
===================================================================
--- llvm/lib/CodeGen/CFGuardLongjmp.cpp
+++ llvm/lib/CodeGen/CFGuardLongjmp.cpp
@@ -75,18 +75,19 @@
     for (MachineInstr &MI : MBB) {
 
       // Skip instructions that are not calls to global functions.
-      if (!MI.isCall() || MI.getNumOperands() < 1 || !MI.getOperand(0).isGlobal())
+      if (!MI.isCall() || MI.getNumOperands() < 1 ||
+          !MI.getOperand(0).isGlobal())
         continue;
 
       auto *F = dyn_cast<Function>(MI.getOperand(0).getGlobal());
-      if (!F) continue;
+      if (!F)
+        continue;
 
       // If the instruction calls a function that returns twice, add
       // it to the list of targets.
       if (F->hasFnAttribute(Attribute::ReturnsTwice)) {
         SetjmpCalls.push_back(&MI);
       }
-
     }
   }
 
Index: llvm/include/llvm/Transforms/CFGuard.h
===================================================================
--- llvm/include/llvm/Transforms/CFGuard.h
+++ llvm/include/llvm/Transforms/CFGuard.h
@@ -1,12 +1,12 @@
-//===-- CFGuard.h - CFGuard Transformations ----------------------*- C++ -*-===//
+//===-- CFGuard.h - CFGuard Transformations ---------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
-//===----------------------------------------------------------------------===//
+//===---------------------------------------------------------------------===//
 // Windows Control Flow Guard passes (/guard:cf).
-//===----------------------------------------------------------------------===//
+//===---------------------------------------------------------------------===//
 
 #ifndef LLVM_TRANSFORMS_CFGUARD_H
 #define LLVM_TRANSFORMS_CFGUARD_H
@@ -21,6 +21,6 @@
 /// Insert Control FLow Guard dispatches on indirect function calls.
 FunctionPass *createCFGuardDispatchPass();
 
-}
+} // namespace llvm
 
 #endif
Index: llvm/include/llvm/CodeGen/MachineFunction.h
===================================================================
--- llvm/include/llvm/CodeGen/MachineFunction.h
+++ llvm/include/llvm/CodeGen/MachineFunction.h
@@ -837,15 +837,13 @@
   /// Returns a reference to a list of symbols immediately following calls to
   /// _setjmp in the function. Used to construct the longjmp target table used
   /// by Windows Control Flow Guard.
-  const std::vector<MCSymbol*> &getLongjmpTargets() const {
+  const std::vector<MCSymbol *> &getLongjmpTargets() const {
     return LongjmpTargets;
   }
 
   /// Add the specified symbol to the list of valid longjmp targets for Windows
   /// Control Flow Guard.
-  void addLongjmpTarget(MCSymbol *Target) {
-    LongjmpTargets.push_back(Target);
-  }
+  void addLongjmpTarget(MCSymbol *Target) { LongjmpTargets.push_back(Target); }
 
   /// \name Exception Handling
   /// \{
Index: clang/lib/Driver/ToolChains/MSVC.cpp
===================================================================
--- clang/lib/Driver/ToolChains/MSVC.cpp
+++ clang/lib/Driver/ToolChains/MSVC.cpp
@@ -422,13 +422,13 @@
 
   Args.AddAllArgValues(CmdArgs, options::OPT__SLASH_link);
 
+  // Control Flow Guard checks
   if (Arg *A = Args.getLastArg(options::OPT__SLASH_guard)) {
     StringRef GuardArgs = A->getValue();
     if (GuardArgs.equals_lower("cf") || GuardArgs.equals_lower("cf,nochecks")) {
       // MSVC doesn't yet support the "nochecks" modifier.
       CmdArgs.push_back("-guard:cf");
-    }
-    else if (GuardArgs.equals_lower("cf-")) {
+    } else if (GuardArgs.equals_lower("cf-")) {
       CmdArgs.push_back("-guard:cf-");
     }
   }
@@ -690,13 +690,13 @@
                           : "/Zc:threadSafeInit-");
   }
 
+  // Control Flow Guard checks
   if (Arg *A = Args.getLastArg(options::OPT__SLASH_guard)) {
     StringRef GuardArgs = A->getValue();
     if (GuardArgs.equals_lower("cf") || GuardArgs.equals_lower("cf,nochecks")) {
       // MSVC doesn't yet support the "nochecks" modifier.
       CmdArgs.push_back("/guard:cf");
-    }
-    else if (GuardArgs.equals_lower("cf-")) {
+    } else if (GuardArgs.equals_lower("cf-")) {
       CmdArgs.push_back("/guard:cf-");
     }
   }
Index: clang/lib/CodeGen/CodeGenModule.cpp
===================================================================
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -484,8 +484,7 @@
   if (CodeGenOpts.ControlFlowGuard) {
     // Function ID tables and checks for Control Flow Guard (cfguard=2).
     getModule().addModuleFlag(llvm::Module::Warning, "cfguard", 2);
-  }
-  else if (CodeGenOpts.ControlFlowGuardNoChecks) {
+  } else if (CodeGenOpts.ControlFlowGuardNoChecks) {
     // Function ID tables for Control Flow Guard (cfguard=1).
     getModule().addModuleFlag(llvm::Module::Warning, "cfguard", 1);
   }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to