[clang] [llvm] [mlir] [RFC] [IR] Change personality function type from Constant* to Function* (PR #176952)

via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 20 08:10:23 PST 2026


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 origin/main HEAD --extensions cpp,h -- clang/lib/CodeGen/CGException.cpp llvm/include/llvm/AsmParser/LLParser.h llvm/include/llvm/CodeGen/TargetLowering.h llvm/include/llvm/IR/EHPersonalities.h llvm/include/llvm/IR/Function.h llvm/lib/Analysis/MustExecute.cpp llvm/lib/AsmParser/LLParser.cpp llvm/lib/Bitcode/Reader/BitcodeReader.cpp llvm/lib/CodeGen/AsmPrinter/AIXException.cpp llvm/lib/CodeGen/AsmPrinter/ARMException.cpp llvm/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp llvm/lib/CodeGen/AsmPrinter/WinException.cpp llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp llvm/lib/CodeGen/MachineLICM.cpp llvm/lib/CodeGen/RDFGraph.cpp llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp llvm/lib/IR/Core.cpp llvm/lib/IR/EHPersonalities.cpp llvm/lib/IR/Function.cpp llvm/lib/IR/Verifier.cpp llvm/lib/Target/AArch64/AArch64Arm64ECCallLowering.cpp llvm/lib/Target/AArch64/AArch64ISelLowering.cpp llvm/lib/Target/AArch64/AArch64ISelLowering.h llvm/lib/Target/ARM/ARMISelLowering.cpp llvm/lib/Target/ARM/ARMISelLowering.h llvm/lib/Target/CSKY/CSKYISelLowering.cpp llvm/lib/Target/CSKY/CSKYISelLowering.h llvm/lib/Target/Hexagon/HexagonISelLowering.h llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp llvm/lib/Target/LoongArch/LoongArchISelLowering.h llvm/lib/Target/M68k/M68kISelLowering.cpp llvm/lib/Target/M68k/M68kISelLowering.h llvm/lib/Target/Mips/MipsISelLowering.h llvm/lib/Target/PowerPC/PPCISelLowering.cpp llvm/lib/Target/PowerPC/PPCISelLowering.h llvm/lib/Target/RISCV/RISCVISelLowering.cpp llvm/lib/Target/RISCV/RISCVISelLowering.h llvm/lib/Target/Sparc/SparcISelLowering.h llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp llvm/lib/Target/SystemZ/SystemZISelLowering.cpp llvm/lib/Target/SystemZ/SystemZISelLowering.h llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp llvm/lib/Target/X86/X86ISelLowering.cpp llvm/lib/Target/X86/X86ISelLowering.h llvm/lib/Target/X86/X86WinEHState.cpp llvm/lib/Target/XCore/XCoreFrameLowering.cpp llvm/lib/Target/XCore/XCoreISelLowering.h llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp llvm/lib/Transforms/Utils/CloneFunction.cpp llvm/lib/Transforms/Utils/CloneModule.cpp llvm/lib/Transforms/Utils/EscapeEnumerator.cpp llvm/lib/Transforms/Utils/InlineFunction.cpp llvm/unittests/Analysis/IRSimilarityIdentifierTest.cpp llvm/unittests/Transforms/Utils/CodeExtractorTest.cpp mlir/lib/Target/LLVMIR/ModuleImport.cpp mlir/lib/Target/LLVMIR/ModuleTranslation.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

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

``````````diff
diff --git a/clang/lib/CodeGen/CGException.cpp b/clang/lib/CodeGen/CGException.cpp
index e3338e619..a5f41a5ca 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -270,8 +270,8 @@ static llvm::FunctionCallee getPersonalityFn(CodeGenModule &CGM,
                                    llvm::AttributeList(), /*Local=*/true);
 }
 
-static llvm::Function *getOpaquePersonalityFn(CodeGenModule &CGM,
-                                              const EHPersonality &Personality) {
+static llvm::Function *
+getOpaquePersonalityFn(CodeGenModule &CGM, const EHPersonality &Personality) {
   llvm::FunctionCallee Fn = getPersonalityFn(CGM, Personality);
   return cast<llvm::Function>(Fn.getCallee());
 }
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index d9231d8eb..8c66d057b 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -1818,7 +1818,8 @@ GlobalValue *LLParser::getGlobalVal(const std::string &Name, Type *Ty,
       Val = I->second.first;
       // If we expect a function but the forward ref is not one, RAUW it.
       if (ExpectFunction && !isa<Function>(Val)) {
-        GlobalValue *FwdVal = createGlobalFwdRef(M, PTy, /*ExpectFunction=*/true);
+        GlobalValue *FwdVal =
+            createGlobalFwdRef(M, PTy, /*ExpectFunction=*/true);
         Val->replaceAllUsesWith(FwdVal);
         Val->eraseFromParent();
         ForwardRefVals[Name] = std::make_pair(FwdVal, I->second.second);
@@ -1856,7 +1857,8 @@ GlobalValue *LLParser::getGlobalVal(unsigned ID, Type *Ty, LocTy Loc,
       Val = I->second.first;
       // If we expect a function but the forward ref is not one, RAUW it.
       if (ExpectFunction && !isa<Function>(Val)) {
-        GlobalValue *FwdVal = createGlobalFwdRef(M, PTy, /*ExpectFunction=*/true);
+        GlobalValue *FwdVal =
+            createGlobalFwdRef(M, PTy, /*ExpectFunction=*/true);
         Val->replaceAllUsesWith(FwdVal);
         Val->eraseFromParent();
         ForwardRefValIDs[ID] = std::make_pair(FwdVal, I->second.second);
@@ -4657,13 +4659,15 @@ bool LLParser::parsePersonality(Function *&F) {
   ValID ID;
   Value *V = nullptr;
   LocTy Loc = Lex.getLoc();
-  bool Parsed = parseValID(ID, /*PFS=*/nullptr, Ty) ||
-                convertValIDToValue(Ty, ID, V, nullptr, /*ExpectFunction=*/true);
+  bool Parsed =
+      parseValID(ID, /*PFS=*/nullptr, Ty) ||
+      convertValIDToValue(Ty, ID, V, nullptr, /*ExpectFunction=*/true);
   if (Parsed)
     return true;
   if (!V)
     return false;
-  // Allow null/zero/undef/poison constants and treat them as nullptr (no personality) for parsing legacy IR.
+  // Allow null/zero/undef/poison constants and treat them as nullptr (no
+  // personality) for parsing legacy IR.
   if (isa<ConstantPointerNull>(V) || isa<UndefValue>(V) ||
       (isa<Constant>(V) && cast<Constant>(V)->isNullValue()))
     return false;
@@ -6551,8 +6555,7 @@ bool LLParser::parseMetadata(Metadata *&MD, PerFunctionState *PFS) {
 //===----------------------------------------------------------------------===//
 
 bool LLParser::convertValIDToValue(Type *Ty, ValID &ID, Value *&V,
-                                   PerFunctionState *PFS,
-                                   bool ExpectFunction) {
+                                   PerFunctionState *PFS, bool ExpectFunction) {
   if (Ty->isFunctionTy())
     return error(ID.Loc, "functions are not values, refer to them as pointers");
 
@@ -6881,8 +6884,7 @@ bool LLParser::parseFunctionHeader(Function *&Fn, bool IsDefine,
       (EatIfPresent(lltok::kw_gc) && parseStringConstant(GC)) ||
       (EatIfPresent(lltok::kw_prefix) && parseGlobalTypeAndValue(Prefix)) ||
       (EatIfPresent(lltok::kw_prologue) && parseGlobalTypeAndValue(Prologue)) ||
-      (EatIfPresent(lltok::kw_personality) &&
-       parsePersonality(PersonalityFn)))
+      (EatIfPresent(lltok::kw_personality) && parsePersonality(PersonalityFn)))
     return true;
 
   if (FuncAttrs.contains(Attribute::Builtin))
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index b3897b6ea..12b10c6fb 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -3194,9 +3194,9 @@ Error BitcodeReader::resolveGlobalAndIndirectSymbolInits() {
         if (!MaybeC)
           return MaybeC.takeError();
         Constant *C = MaybeC.get();
-        // Old bitcode may have null/undef/poison as personality - treat as none.
-        // Also unwrap any ConstantExpr (bitcast, etc.) to get the underlying
-        // function.
+        // Old bitcode may have null/undef/poison as personality - treat as
+        // none. Also unwrap any ConstantExpr (bitcast, etc.) to get the
+        // underlying function.
         if (!C->isNullValue() && !isa<UndefValue>(C)) {
           C = C->stripPointerCasts();
           if (!C->isNullValue() && !isa<UndefValue>(C)) {
@@ -3204,8 +3204,8 @@ Error BitcodeReader::resolveGlobalAndIndirectSymbolInits() {
             if (!PersonalityFn) {
               // Warn and drop unsupported personality (e.g. alias, constant).
               errs() << "warning: dropping unsupported personality for "
-                     << Info.F->getName() << " (got "
-                     << C->getNameOrAsOperand() << ")\n";
+                     << Info.F->getName() << " (got " << C->getNameOrAsOperand()
+                     << ")\n";
             } else {
               Info.F->setPersonalityFn(PersonalityFn);
             }
diff --git a/llvm/lib/Transforms/Utils/CloneModule.cpp b/llvm/lib/Transforms/Utils/CloneModule.cpp
index 6a51b20cd..1d5f94971 100644
--- a/llvm/lib/Transforms/Utils/CloneModule.cpp
+++ b/llvm/lib/Transforms/Utils/CloneModule.cpp
@@ -158,8 +158,7 @@ std::unique_ptr<Module> llvm::CloneModule(
                       Returns);
 
     if (I.hasPersonalityFn())
-      F->setPersonalityFn(
-          cast<Function>(MapValue(I.getPersonalityFn(), VMap)));
+      F->setPersonalityFn(cast<Function>(MapValue(I.getPersonalityFn(), VMap)));
 
     copyComdat(F, &I);
   }
diff --git a/llvm/unittests/Transforms/Utils/CodeExtractorTest.cpp b/llvm/unittests/Transforms/Utils/CodeExtractorTest.cpp
index 4842a4b97..97c90fbc1 100644
--- a/llvm/unittests/Transforms/Utils/CodeExtractorTest.cpp
+++ b/llvm/unittests/Transforms/Utils/CodeExtractorTest.cpp
@@ -352,9 +352,10 @@ TEST(CodeExtractor, StoreOutputInvokeResultAfterEHPad) {
         %ex.2 = phi ptr [ %ex.1, %lpad2 ], [ null, %lpad ]
         unreachable
     }
-  )invalid", Err, Ctx));
+  )invalid",
+                                                Err, Ctx));
 
-	if (!M) {
+  if (!M) {
     Err.print("unit", errs());
     exit(1);
   }

``````````

</details>


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


More information about the cfe-commits mailing list