[Verifier] Extend address taken check for unknown intrinsics

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.

Differential Revision: https://reviews.llvm.org/D106095
This commit is contained in:
Nikita Popov 2021-07-15 20:34:56 +02:00
parent 803cf7ac0c
commit ff59a1cfe6
2 changed files with 10 additions and 1 deletions

View File

@ -2521,7 +2521,7 @@ void Verifier::visitFunction(const Function &F) {
// 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);

View File

@ -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!
@g1 = global i32(i32, i32)* @llvm.umax.i32
; CHECK: Invalid user of intrinsic instruction!
@g2 = global i32()* @llvm.my.custom.intrinsic