[Verifier] Restore defined-resolver verification for IFuncs
Now that clang no longer emits GlobalIFunc-s with a declaration for a resolver, we can restore that check. In addition, add a linkage check like the one we have on GlobalAlias-es, and a Verifier test for ifuncs. Signed-off-by: Itay Bookstein <ibookstein@gmail.com> Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D120267
This commit is contained in:
parent
730acdc445
commit
7ca7d8126d
|
@ -84,6 +84,11 @@ public:
|
|||
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;
|
||||
|
|
|
@ -836,13 +836,19 @@ void Verifier::visitGlobalAlias(const GlobalAlias &GA) {
|
|||
}
|
||||
|
||||
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());
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
; RUN: not llvm-as %s -o /dev/null 2>&1 | FileCheck %s
|
||||
|
||||
define void ()* @resolver() {
|
||||
ret void ()* null
|
||||
}
|
||||
|
||||
@inval_linkage = extern_weak ifunc void (), void ()* ()* @resolver
|
||||
; CHECK: IFunc should have {{.*}} linkage!
|
||||
; CHECK-NEXT: @inval_linkage
|
||||
|
||||
@g = external global i32
|
||||
@inval_objtype = ifunc void (), bitcast(i32* @g to void ()* ()*)
|
||||
; CHECK: IFunc must have a Function resolver
|
||||
|
||||
declare void ()* @resolver_decl()
|
||||
@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
|
||||
}
|
||||
@inval_resolver_decl2 = ifunc void (), void ()* ()* @resolver_linker_decl
|
||||
; CHECK: IFunc resolver must be a definition
|
||||
; CHECK-NEXT: @inval_resolver_decl2
|
||||
|
||||
@inval_resolver_type = ifunc i32 (), void ()* ()* @resolver
|
||||
; CHECK: IFunc resolver has incorrect type
|
||||
; CHECK-NEXT: @inval_resolver_type
|
Loading…
Reference in New Issue