[PATCH] D158939: FixProtect against null dereferences
Akshay Khadse via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 26 10:00:43 PDT 2023
akshaykhadse created this revision.
Herald added subscribers: pengfei, hiraditya.
Herald added a project: All.
akshaykhadse requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D158939
Files:
llvm/lib/CodeGen/CodeGenPrepare.cpp
llvm/lib/TableGen/TGParser.cpp
llvm/lib/Target/X86/X86ISelLowering.cpp
Index: llvm/lib/Target/X86/X86ISelLowering.cpp
===================================================================
--- llvm/lib/Target/X86/X86ISelLowering.cpp
+++ llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -5963,6 +5963,8 @@
if (DAG.ComputeNumSignBits(Src, DemandedSrcElts) != NumBitsPerSrcElt)
return false;
+ // Call DAG->ComputeNumSignBits(Src, DemandedSrcElts, 0U) may return 0
+ assert(NumBitsPerSrcElt != 0 && "Modulo by zero");
assert((NumBitsPerElt % NumBitsPerSrcElt) == 0 && "Unexpected extension");
unsigned Scale = NumBitsPerElt / NumBitsPerSrcElt;
for (unsigned I = 0; I != NumElts; ++I)
Index: llvm/lib/TableGen/TGParser.cpp
===================================================================
--- llvm/lib/TableGen/TGParser.cpp
+++ llvm/lib/TableGen/TGParser.cpp
@@ -581,9 +581,11 @@
ArgName = Arg->getName();
// We can only specify the template argument once.
- if (!is_contained(UnsolvedArgNames, ArgName))
+ if (!is_contained(UnsolvedArgNames, ArgName)){
+ assert(ArgName != nullptr && "ArgName must be initialized");
return Error(Loc, "We can only specify the template argument '" +
ArgName->getAsUnquotedString() + "' once");
+ }
ArgValueHandler(ArgName, ArgValue);
llvm::erase_value(UnsolvedArgNames, ArgName);
Index: llvm/lib/CodeGen/CodeGenPrepare.cpp
===================================================================
--- llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -7067,10 +7067,14 @@
// Sink expensive instructions into the conditional blocks to avoid executing
// them speculatively.
- for (Instruction *I : TrueInstrs)
+ for (Instruction *I : TrueInstrs) {
+ assert(TrueBranch != nullptr && "TrueBranch must be initialized");
I->moveBefore(TrueBranch);
- for (Instruction *I : FalseInstrs)
+ }
+ for (Instruction *I : FalseInstrs) {
+ assert(FalseBranch != nullptr && "FalseBranch must be initialized");
I->moveBefore(FalseBranch);
+ }
// If we did not create a new block for one of the 'true' or 'false' paths
// of the condition, it means that side of the branch goes to the end block
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158939.553743.patch
Type: text/x-patch
Size: 2200 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230826/80273016/attachment.bin>
More information about the llvm-commits
mailing list