[llvm] 7c6c03e - [NFC] Fix possibly deref nullptr
via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 16 18:44:07 PDT 2023
Author: XinWang10
Date: 2023-08-16T18:43:33-07:00
New Revision: 7c6c03ea71106c671f82eedf32f15c7d23af2f40
URL: https://github.com/llvm/llvm-project/commit/7c6c03ea71106c671f82eedf32f15c7d23af2f40
DIFF: https://github.com/llvm/llvm-project/commit/7c6c03ea71106c671f82eedf32f15c7d23af2f40.diff
LOG: [NFC] Fix possibly deref nullptr
1. In X86LowerAMXType.cpp dyn_cast could lead to UserI be nullptr which coud be dref in IRBuilder constructor.
2. In AsmPrinter.cpp, doInitialization could make MMI be nullptr if MMIWP->getMMI() is false, then the deref after could be unexpected.
Reviewed By: skan
Differential Revision: https://reviews.llvm.org/D157948
Added:
Modified:
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
llvm/lib/Target/X86/X86LowerAMXType.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 5381dfdd184cc9..a39abf4a3aaf4b 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -383,6 +383,7 @@ const TargetLoweringObjectFile &AsmPrinter::getObjFileLowering() const {
}
const DataLayout &AsmPrinter::getDataLayout() const {
+ assert(MMI && "MMI could not be nullptr!");
return MMI->getModule()->getDataLayout();
}
@@ -516,6 +517,7 @@ bool AsmPrinter::doInitialization(Module &M) {
CodeViewLineTablesGroupDescription);
}
if (!EmitCodeView || M.getDwarfVersion()) {
+ assert(MMI && "MMI could not be nullptr here!");
if (MMI->hasDebugInfo()) {
DD = new DwarfDebug(this);
Handlers.emplace_back(std::unique_ptr<DwarfDebug>(DD), DbgTimerName,
diff --git a/llvm/lib/Target/X86/X86LowerAMXType.cpp b/llvm/lib/Target/X86/X86LowerAMXType.cpp
index 69e0af6a5e9296..d20d5fe96f492c 100644
--- a/llvm/lib/Target/X86/X86LowerAMXType.cpp
+++ b/llvm/lib/Target/X86/X86LowerAMXType.cpp
@@ -494,7 +494,7 @@ static void replaceWithTileLoad(Use &U, Value *Ptr, bool IsPHI = false) {
Value *Row = II->getOperand(0);
Value *Col = II->getOperand(1);
- Instruction *UserI = dyn_cast<Instruction>(U.getUser());
+ Instruction *UserI = cast<Instruction>(U.getUser());
IRBuilder<> Builder(UserI);
Value *Stride = Builder.getInt64(64);
std::array<Value *, 4> Args = {Row, Col, Ptr, Stride};
More information about the llvm-commits
mailing list