[PATCH] D138634: GlobalIFunc: Make allowed constant expressions stricter
Matt Arsenault via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 23 19:18:40 PST 2022
arsenm created this revision.
arsenm added reviewers: MaskRay, ibookstein, tejohnson, dexonsmith.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
arsenm requested review of this revision.
Herald added a subscriber: wdng.
Herald added a project: LLVM.
This was allowing getelementptr with offsets, which doesn't make
sense. My initial attempt to use stripPointerCasts broke a few tests
involving aliases; add a new targeted verifier test for aliases.
This also provides the fix from D138537 <https://reviews.llvm.org/D138537> for free, and also adds
support for addrspacecast (D138538 <https://reviews.llvm.org/D138538>) for free. Merge the tests in from
those.
I'm not really sure why findBaseObject exists; it seems redundant with
stripPointerCasts* (I'm also not really sure why getelementptrs are
allowed off of functions).
https://reviews.llvm.org/D138634
Files:
llvm/lib/IR/Globals.cpp
llvm/test/Assembler/ifunc-addrspacecast.ll
llvm/test/Assembler/ifunc-alias.ll
llvm/test/Assembler/ifunc-unhandled-constantexpr.ll
llvm/test/Verifier/ifunc-opaque.ll
Index: llvm/test/Verifier/ifunc-opaque.ll
===================================================================
--- /dev/null
+++ llvm/test/Verifier/ifunc-opaque.ll
@@ -0,0 +1,9 @@
+; RUN: not llvm-as %s -o /dev/null 2>&1 | FileCheck %s
+
+define ptr @resolver() {
+ ret ptr null
+}
+
+; CHECK: IFunc must have a Function resolver
+; CHECK-NEXT: ptr @ifunc_getelementptr
+ at ifunc_getelementptr = ifunc void (), ptr getelementptr (i8, ptr @resolver, i32 4)
Index: llvm/test/Assembler/ifunc-unhandled-constantexpr.ll
===================================================================
--- /dev/null
+++ llvm/test/Assembler/ifunc-unhandled-constantexpr.ll
@@ -0,0 +1,12 @@
+; RUN: not llvm-as < %s 2>&1 | FileCheck %s
+
+; Make sure nothing asserts on an unhandled constantexpr for the
+; resolver.
+
+; CHECK: IFunc must have a Function resolver
+; CHECK-NEXT: ptr @ifunc_shl
+ at ifunc_shl = ifunc void (), ptr inttoptr (i64 shl (i64 ptrtoint (ptr @resolver to i64), i64 4) to ptr)
+
+define ptr @resolver() {
+ ret ptr null
+}
Index: llvm/test/Assembler/ifunc-alias.ll
===================================================================
--- /dev/null
+++ llvm/test/Assembler/ifunc-alias.ll
@@ -0,0 +1,12 @@
+; RUN: llvm-as < %s | llvm-dis | FileCheck %s
+
+; CHECK: @alias_resolver = internal alias i32 (i32), ptr @resolver
+ at alias_resolver = internal alias i32 (i32), ptr @resolver
+
+; CHECK: @ifunc_resolver_is_alias = internal ifunc i32 (i32), ptr @alias_resolver
+ at ifunc_resolver_is_alias = internal ifunc i32 (i32), ptr @alias_resolver
+
+; CHECK: define internal ptr @resolver() {
+define internal ptr @resolver() {
+ ret ptr null
+}
Index: llvm/test/Assembler/ifunc-addrspacecast.ll
===================================================================
--- /dev/null
+++ llvm/test/Assembler/ifunc-addrspacecast.ll
@@ -0,0 +1,9 @@
+; RUN: llvm-as < %s | llvm-dis | FileCheck %s
+
+; CHECK: @ifunc_addrspacecast_as1_to_as0 = ifunc void (), addrspacecast (ptr addrspace(1) @resolver_as1 to ptr)
+ at ifunc_addrspacecast_as1_to_as0 = ifunc void (), ptr addrspacecast (ptr addrspace(1) @resolver_as1 to ptr)
+
+; CHECK: define ptr @resolver_as1() addrspace(1) {
+define ptr @resolver_as1() addrspace(1) {
+ ret ptr null
+}
Index: llvm/lib/IR/Globals.cpp
===================================================================
--- llvm/lib/IR/Globals.cpp
+++ llvm/lib/IR/Globals.cpp
@@ -589,9 +589,7 @@
}
const Function *GlobalIFunc::getResolverFunction() const {
- DenseSet<const GlobalAlias *> Aliases;
- return dyn_cast<Function>(
- findBaseObject(getResolver(), Aliases, [](const GlobalValue &) {}));
+ return dyn_cast<Function>(getResolver()->stripPointerCastsAndAliases());
}
void GlobalIFunc::applyAlongResolverPath(
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138634.477676.patch
Type: text/x-patch
Size: 2732 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221124/12eea16a/attachment.bin>
More information about the llvm-commits
mailing list