[PATCH] D108642: [CGProfile] allows undef in metadata node storing function pointers

Yuanfang Chen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 24 10:09:36 PDT 2021


ychen created this revision.
ychen added reviewers: tejohnson, StephenTozer, zequanwu.
Herald added subscribers: dexonsmith, hiraditya.
ychen requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Commits like e5d958c <https://reviews.llvm.org/rGe5d958c45629ccd2f5b5f7432756be1d0fcf052c> may RAUW with undef value. It seems better to allow
this pattern in IR verifier rather than fixing the RAUWs for e5d958c <https://reviews.llvm.org/rGe5d958c45629ccd2f5b5f7432756be1d0fcf052c> and
future commits.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D108642

Files:
  llvm/lib/IR/Verifier.cpp
  llvm/lib/Target/TargetLoweringObjectFile.cpp
  llvm/test/Verifier/module-flags-cgprofile.ll


Index: llvm/test/Verifier/module-flags-cgprofile.ll
===================================================================
--- llvm/test/Verifier/module-flags-cgprofile.ll
+++ llvm/test/Verifier/module-flags-cgprofile.ll
@@ -6,7 +6,7 @@
 !llvm.module.flags = !{!0}
 
 !0 = !{i32 5, !"CG Profile", !1}
-!1 = !{!2, !"", !3, !4, !5, !6, !7, !8}
+!1 = !{!2, !"", !3, !4, !5, !6, !7, !8, !9}
 !2 = !{void ()* @a, void ()* @b, i64 32}
 !3 = !{void ()* @a, void ()* @b}
 !4 = !{void ()* @a, void ()* @b, i64 32, i64 32}
@@ -14,6 +14,7 @@
 !6 = !{void ()* @a, !"b", i64 32}
 !7 = !{void ()* @a, void ()* @b, !""}
 !8 = !{void ()* @a, void ()* @b, null}
+!9 = !{void ()* @a, void ()* undef, i64 32}
 
 ; CHECK: expected a MDNode triple
 ; CHECK: !""
@@ -21,9 +22,9 @@
 ; CHECK: !3 = !{void ()* @a, void ()* @b}
 ; CHECK: expected a MDNode triple
 ; CHECK: !4 = !{void ()* @a, void ()* @b, i64 32, i64 32}
-; CHECK: expected a Function or null
+; CHECK: expected a Value
 ; CHECK: !"a"
-; CHECK: expected a Function or null
+; CHECK: expected a Value
 ; CHECK: !"b"
 ; CHECK: expected an integer constant
 ; CHECK: !""
Index: llvm/lib/Target/TargetLoweringObjectFile.cpp
===================================================================
--- llvm/lib/Target/TargetLoweringObjectFile.cpp
+++ llvm/lib/Target/TargetLoweringObjectFile.cpp
@@ -171,8 +171,8 @@
     if (!MDO)
       return nullptr;
     auto *V = cast<ValueAsMetadata>(MDO);
-    const Function *F = cast<Function>(V->getValue()->stripPointerCasts());
-    if (F->hasDLLImportStorageClass())
+    const Function *F = dyn_cast<Function>(V->getValue()->stripPointerCasts());
+    if (!F || F->hasDLLImportStorageClass())
       return nullptr;
     return TM->getSymbol(F);
   };
Index: llvm/lib/IR/Verifier.cpp
===================================================================
--- llvm/lib/IR/Verifier.cpp
+++ llvm/lib/IR/Verifier.cpp
@@ -1641,7 +1641,9 @@
     if (!FuncMDO)
       return;
     auto F = dyn_cast<ValueAsMetadata>(FuncMDO);
-    Assert(F && isa<Function>(F->getValue()->stripPointerCasts()),
+    Assert(F, "expected a Value", FuncMDO);
+    auto VF = F->getValue()->stripPointerCasts();
+    Assert(isa<Function>(VF) || isa<UndefValue>(VF),
            "expected a Function or null", FuncMDO);
   };
   auto Node = dyn_cast_or_null<MDNode>(MDO);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108642.368384.patch
Type: text/x-patch
Size: 2315 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210824/8dcc42e1/attachment.bin>


More information about the llvm-commits mailing list