[PATCH] D106013: [Verifier] Require same signature for intrinsic calls

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 14 13:33:56 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.

As suggested on D105733 <https://reviews.llvm.org/D105733>, this adds a verifier rule that calls to intrinsics must match the signature of the intrinsic. Without opaque pointers this is automatically enforced because the pointer types need to match, but with opaque pointers it is not. We probably can't enforce this in general due to unreachable (possibly de-indirected) calls, but I don't see a reason why we can't enforce this for intrinsics at least.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106013

Files:
  llvm/lib/IR/Verifier.cpp
  llvm/test/Verifier/force-opaque-ptr.ll


Index: llvm/test/Verifier/force-opaque-ptr.ll
===================================================================
--- /dev/null
+++ llvm/test/Verifier/force-opaque-ptr.ll
@@ -0,0 +1,9 @@
+; RUN: not opt -passes=verify -force-opaque-pointers -S < %s 2>&1 | FileCheck %s
+
+declare i32 @llvm.umax.i32(i32, i32)
+
+define void @intrinsic_signature_mismatch() {
+; CHECK: Intrinsic called with incompatible signature
+  call i32 @llvm.umax.i32(i32 0)
+  ret void
+}
Index: llvm/lib/IR/Verifier.cpp
===================================================================
--- llvm/lib/IR/Verifier.cpp
+++ llvm/lib/IR/Verifier.cpp
@@ -3055,11 +3055,12 @@
   Assert(verifyAttributeCount(Attrs, Call.arg_size()),
          "Attribute after last parameter!", Call);
 
-  bool IsIntrinsic = Call.getCalledFunction() &&
-                     Call.getCalledFunction()->getName().startswith("llvm.");
-
   Function *Callee =
       dyn_cast<Function>(Call.getCalledOperand()->stripPointerCasts());
+  bool IsIntrinsic = Callee && Callee->getName().startswith("llvm.");
+  if (IsIntrinsic)
+    Assert(Callee->getValueType() == FTy,
+           "Intrinsic called with incompatible signature", Call);
 
   if (Attrs.hasFnAttribute(Attribute::Speculatable)) {
     // Don't allow speculatable on call sites, unless the underlying function


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106013.358718.patch
Type: text/x-patch
Size: 1318 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210714/ea438ddd/attachment.bin>


More information about the llvm-commits mailing list