Skip to content
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

Stack overflow / segv in attributor on minimal subset of libc #63956

Closed
JonChesterfield opened this issue Jul 19, 2023 · 4 comments
Closed

Stack overflow / segv in attributor on minimal subset of libc #63956

JonChesterfield opened this issue Jul 19, 2023 · 4 comments

Comments

@JonChesterfield
Copy link
Collaborator

Discovered while using parts of llvm libc as a debugging tool. Symptom was clang crashing at O1 or higher.

target datalayout = "e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-p7:160:256:256:32-p8:128:128-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:\
64-S32-A5-G1-ni:7:8"
target triple = "amdgcn-amd-amdhsa"

%struct.foo = type { %struct.pluto, ptr, i64 }
%struct.pluto = type { [512 x i8], ptr }

@global.2 = internal addrspace(1) global %struct.foo { %struct.pluto zeroinitializer, ptr addrspacecast (ptr addrspace(1) @global.2 to ptr), i64 0 }

; Function Attrs: nounwind                                                                                                                                                                                         
define internal void @hoge(ptr noundef %arg)  {
bb:
  %load = load i64, ptr addrspace(1) getelementptr inbounds (%struct.foo, ptr addrspace(1) @global.2, i64 0, i32 2), align 8

  ret void
}

!0 = !{!"clang version 17.0.0 (git@github.com:llvm/llvm-project.git f717c2d4f2b7663317e46af069aaf88edca760de)"}

Reproduce

opt -mtriple=amdgcn-amd-amdhsa -amdgpu-attributor bugpoint-reduced-simplified.ll

Godbolt crashing (had to delete the target layout string) https://godbolt.org/z/MT5vbj5cx

@arsenm
Copy link
Contributor

arsenm commented Jul 19, 2023

This is just directly recursing on a global used to initialize itself. Do we still not have a generic utility to walk through ConstantExprs correctly?

@jhuber6
Copy link
Contributor

jhuber6 commented Jul 19, 2023

I think I actually remember something like this coming up, specifically in NVPTX and maybe AMDGPU I think we cannot use a self-referential initializer. This is something the libc implementation of the File ended up doing but I thought I statically trimmed that.

In any case, we should probably have a nicer failure mode if it is indeed illegal to initialize in this way.

@JonChesterfield
Copy link
Collaborator Author

This is just directly recursing on a global used to initialize itself. Do we still not have a generic utility to walk through ConstantExprs correctly?

There was a generic utility to expand them into instructions, but it didn't work. I think I've deleted it. Wouldn't apply to the global anyway. I don't know of a traversal API, the on the fly deduplication makes the things quite awkward to deal with.

A global referring to itself sounds fine to me, if the backed blows up on that we should fix that too.

@llvmbot
Copy link
Collaborator

llvmbot commented Jul 19, 2023

@llvm/issue-subscribers-backend-amdgpu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants