[PATCH] D106095: [Verifier] Extend address taken check for unknown intrinsics

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 15 13:31:23 PDT 2021


nikic created this revision.
nikic added a reviewer: opaque-pointers.
Herald added subscribers: dexonsmith, hiraditya.
nikic requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Intrinsics can only be called directly, taking their address is not legal. This is currently only enforced for intrinsics that have an ID, rather than all intrinsics. Adjust the check to cover all intrinsics.

This came up in D106013 <https://reviews.llvm.org/D106013>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106095

Files:
  llvm/lib/IR/Verifier.cpp
  llvm/test/Verifier/intrinsic-addr-taken.ll


Index: llvm/test/Verifier/intrinsic-addr-taken.ll
===================================================================
--- /dev/null
+++ llvm/test/Verifier/intrinsic-addr-taken.ll
@@ -0,0 +1,9 @@
+; RUN: not llvm-as < %s 2>&1 | FileCheck %s
+
+declare i32 @llvm.umax.i32(i32, i32)
+declare i32 @llvm.my.custom.intrinsic()
+
+; CHECK: Invalid user of intrinsic instruction!
+ at g1 = global i32(i32, i32)* @llvm.umax.i32
+; CHECK: Invalid user of intrinsic instruction!
+ at g2 = global i32()* @llvm.my.custom.intrinsic
Index: llvm/lib/IR/Verifier.cpp
===================================================================
--- llvm/lib/IR/Verifier.cpp
+++ llvm/lib/IR/Verifier.cpp
@@ -2521,7 +2521,7 @@
   // direct call/invokes, never having its "address taken".
   // Only do this if the module is materialized, otherwise we don't have all the
   // uses.
-  if (F.getIntrinsicID() && F.getParent()->isMaterialized()) {
+  if (F.isIntrinsic() && F.getParent()->isMaterialized()) {
     const User *U;
     if (F.hasAddressTaken(&U))
       Assert(false, "Invalid user of intrinsic instruction!", U);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106095.359110.patch
Type: text/x-patch
Size: 1091 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210715/71307110/attachment.bin>


More information about the llvm-commits mailing list