[PATCH] D120267: [Verifier] Restore defined-resolver verification for IFuncs

Itay Bookstein via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 26 02:02:48 PST 2022


ibookstein updated this revision to Diff 411590.
ibookstein added a comment.

add another test with available_externally resolver


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120267/new/

https://reviews.llvm.org/D120267

Files:
  llvm/include/llvm/IR/GlobalIFunc.h
  llvm/lib/IR/Verifier.cpp
  llvm/test/Verifier/ifunc.ll


Index: llvm/test/Verifier/ifunc.ll
===================================================================
--- /dev/null
+++ llvm/test/Verifier/ifunc.ll
@@ -0,0 +1,29 @@
+; RUN:  not llvm-as %s -o /dev/null 2>&1 | FileCheck %s
+
+define void ()* @resolver() {
+  ret void ()* null
+}
+
+ at inval_linkage = extern_weak ifunc void (), void ()* ()* @resolver
+; CHECK: IFunc should have {{.*}} linkage!
+; CHECK-NEXT: @inval_linkage
+
+ at g = external global i32
+ at inval_objtype = ifunc void (), bitcast(i32* @g to void ()* ()*)
+; CHECK: IFunc must have a Function resolver
+
+declare void ()* @resolver_decl()
+ at inval_resolver_decl = ifunc void (), void ()* ()* @resolver_decl
+; CHECK: IFunc resolver must be a definition
+; CHECK-NEXT: @inval_resolver_decl
+
+define available_externally void ()* @resolver_linker_decl() {
+  ret void ()* null
+}
+ at inval_resolver_decl2 = ifunc void (), void ()* ()* @resolver_linker_decl
+; CHECK: IFunc resolver must be a definition
+; CHECK-NEXT: @inval_resolver_decl2
+
+ at inval_resolver_type = ifunc i32 (), void ()* ()* @resolver
+; CHECK: IFunc resolver has incorrect type
+; CHECK-NEXT: @inval_resolver_type
Index: llvm/lib/IR/Verifier.cpp
===================================================================
--- llvm/lib/IR/Verifier.cpp
+++ llvm/lib/IR/Verifier.cpp
@@ -836,13 +836,19 @@
 }
 
 void Verifier::visitGlobalIFunc(const GlobalIFunc &GI) {
+  Assert(GlobalIFunc::isValidLinkage(GI.getLinkage()),
+         "IFunc should have private, internal, linkonce, weak, linkonce_odr, "
+         "weak_odr, or external linkage!",
+         &GI);
   // Pierce through ConstantExprs and GlobalAliases and check that the resolver
-  // has a Function 
+  // is a Function definition.
   const Function *Resolver = GI.getResolverFunction();
   Assert(Resolver, "IFunc must have a Function resolver", &GI);
+  Assert(!Resolver->isDeclarationForLinker(),
+         "IFunc resolver must be a definition", &GI);
 
   // Check that the immediate resolver operand (prior to any bitcasts) has the
-  // correct type
+  // correct type.
   const Type *ResolverTy = GI.getResolver()->getType();
   const Type *ResolverFuncTy =
       GlobalIFunc::getResolverFunctionType(GI.getValueType());
Index: llvm/include/llvm/IR/GlobalIFunc.h
===================================================================
--- llvm/include/llvm/IR/GlobalIFunc.h
+++ llvm/include/llvm/IR/GlobalIFunc.h
@@ -84,6 +84,11 @@
     return FunctionType::get(IFuncValTy->getPointerTo(), false);
   }
 
+  static bool isValidLinkage(LinkageTypes L) {
+    return isExternalLinkage(L) || isLocalLinkage(L) || isWeakLinkage(L) ||
+           isLinkOnceLinkage(L);
+  }
+
   // Methods for support type inquiry through isa, cast, and dyn_cast:
   static bool classof(const Value *V) {
     return V->getValueID() == Value::GlobalIFuncVal;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120267.411590.patch
Type: text/x-patch
Size: 2825 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220226/edb348dc/attachment.bin>


More information about the llvm-commits mailing list