[PATCH] D152151: AutoUpgrade: Fix crash when tbaa has an empty argument

Matt Arsenault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 5 06:06:43 PDT 2023


arsenm created this revision.
arsenm added reviewers: RKSimon, dexonsmith, mehdi_amini.
Herald added subscribers: jeroen.dobbelaere, hiraditya.
Herald added a project: All.
arsenm requested review of this revision.
Herald added a subscriber: wdng.
Herald added a project: LLVM.

https://reviews.llvm.org/D152151

Files:
  llvm/lib/IR/AutoUpgrade.cpp
  llvm/test/Bitcode/tbaa-empty-arg-autoupgrade-crash.ll


Index: llvm/test/Bitcode/tbaa-empty-arg-autoupgrade-crash.ll
===================================================================
--- /dev/null
+++ llvm/test/Bitcode/tbaa-empty-arg-autoupgrade-crash.ll
@@ -0,0 +1,11 @@
+; RUN: llvm-as -o - < %s | llvm-dis | FileCheck %s
+
+; Test there's no crash if tbaa has an empty argument.
+; CHECK: store i32 %arg0, ptr addrspace(1) %arg1, align 4{{$}}
+
+define void @tbaa_empty_arg(i32 %arg0, ptr addrspace(1) %arg1) {
+  store i32 %arg0, ptr addrspace(1) %arg1, align 4, !tbaa !0
+  ret void
+}
+
+!0 = !{}
Index: llvm/lib/IR/AutoUpgrade.cpp
===================================================================
--- llvm/lib/IR/AutoUpgrade.cpp
+++ llvm/lib/IR/AutoUpgrade.cpp
@@ -4453,12 +4453,16 @@
 }
 
 MDNode *llvm::UpgradeTBAANode(MDNode &MD) {
+  const unsigned NumOperands = MD.getNumOperands();
+  if (NumOperands == 0)
+    return nullptr;
+
   // Check if the tag uses struct-path aware TBAA format.
-  if (isa<MDNode>(MD.getOperand(0)) && MD.getNumOperands() >= 3)
+  if (isa<MDNode>(MD.getOperand(0)) && NumOperands >= 3)
     return &MD;
 
   auto &Context = MD.getContext();
-  if (MD.getNumOperands() == 3) {
+  if (NumOperands == 3) {
     Metadata *Elts[] = {MD.getOperand(0), MD.getOperand(1)};
     MDNode *ScalarType = MDNode::get(Context, Elts);
     // Create a MDNode <ScalarType, ScalarType, offset 0, const>


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152151.528395.patch
Type: text/x-patch
Size: 1373 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230605/4f1f0542/attachment.bin>


More information about the llvm-commits mailing list