-
Notifications
You must be signed in to change notification settings - Fork 766
[SYCL] Ignore unknown users of virtual functions instead of crashing #17397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Maetveis
wants to merge
1
commit into
intel:sycl
Choose a base branch
from
Maetveis:sycl-virtual-funcs-ignore-insts
base: sycl
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...test/SYCLLowerIR/SYCLVirtualFunctionsAnalysis/calls-indirectly-propagation-other-users.ll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
; RUN: opt -S -passes=sycl-virtual-functions-analysis %s | FileCheck %s | ||
; | ||
; Check if non-vtable uses of a function marked with "indirectly-callable" attribute | ||
; are ignored. This used to crash. | ||
|
||
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64-G1" | ||
target triple = "spir64-unknown-unknown" | ||
|
||
@vtable = linkonce_odr dso_local unnamed_addr addrspace(1) constant { [3 x ptr addrspace(4)] } { [3 x ptr addrspace(4)] [ptr addrspace(4) null, ptr addrspace(4) null, ptr addrspace(4) addrspacecast (ptr @foo to ptr addrspace(4))] }, align 8 | ||
|
||
define linkonce_odr dso_local spir_func void @foo() unnamed_addr #0 { | ||
ret void | ||
} | ||
|
||
define weak_odr dso_local spir_kernel void @kernel(ptr addrspace(1) noundef align 8 %_arg_StorageAcc) #1 { | ||
entry: | ||
store ptr addrspace(1) getelementptr inbounds inrange(-16, 8) (i8, ptr addrspace(1) @vtable, i64 16), ptr addrspace(1) %_arg_StorageAcc, align 8 | ||
ret void | ||
} | ||
|
||
define weak_odr dso_local spir_kernel void @kernel2() #1 { | ||
entry: | ||
; using the symbol in an instruction is ignored | ||
%ptr = addrspacecast ptr @foo to ptr addrspace(4) | ||
; as a special case of above using the symbol in a call should be ignored | ||
call spir_func void @foo() | ||
ret void | ||
} | ||
|
||
; CHECK: @kernel({{.*}} #[[#KERNEL_ATTRS:]] | ||
; CHECK: @kernel2({{.*}} #[[#KERNEL2_ATTRS:]] | ||
; CHECK: attributes #[[#KERNEL_ATTRS]] = {{.*}}"calls-indirectly"="set-foo" | ||
; CHECK-NOT: attributes #[[#KERNEL2_ATTRS]] = {{.*}}"calls-indirectly" | ||
|
||
attributes #0 = { "indirectly-callable"="set-foo" "sycl-module-id"="v.cpp" } | ||
attributes #1 = { "sycl-module-id"="v.cpp" } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to my understanding,
llvm_unreachable
is put here to catch cases which were missed during development. Ignoring "unhandled" cases might lead to bugs which are hard to analyze. The crash here is easy to analyze.@Maetveis, do you have test case leading to running into
llvm_unreachable
? If so, please, add a regression test and one more if to handle it.If would prefer to have
llvm_unreachable("Unhandled type of user");
for unhandled users instead of silently ignoring them.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See the attached test, it was reduced from basically:
Should this be added as test too?
I can add an
isa<Instruction>
branch if thats preferred.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's preferred and will help us detecting incompatible LLVM community changes (e.g. adding more types of Users we need to handle).
Alternatively, we can consider replacing
llvm_unreachable
with anassert
, but I'd like code owners/authors to comment on that first.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code is trying to look through constant expressions to find global variables that use the function pointers in their initializers. Personally, I don't really expect LLVM to start allowing non constants in global variable initializers. If other
User
s appear they are either going to be subclasses ofConstant
or probably won't appear in global initializers.BTW looking at it again even the current code is redundant,
ConstantExpr
is a subclass ofConstant
.In summary IMO having an allowlist here is unlikely to catch real bugs, but can easily be a source of churn or hidden crashes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the form of
sycl_indirectly_callable
? Right know there is only a single (more or less properly) documented way of using indirect calls in SYCL - that is through virtual functions and the corresponding extension (#10540).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't at my PC when I wrote that message, and didn't know the full syntax OTOH.
This is the full reproducer