Repository navigation
Crash during codegen for target OS PS3 #26020
Description
Activity
- addedbugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behavior
on Nov 23, 2025 Have you built LLVM with either
-DCMAKE_BUILD_TYPE=Debugor-DCMAKE_BUILD_TYPE=RelWithDebInfo -DLLVM_ENABLE_ASSERTIONS=ON? (Recommend the latter asDebugLLVM is very slow.) If not, I strongly suggest doing that before even trying to investigate this.Yeah, trying to compile the LLVM IR emitted by Zig using a debug build of
llcaborts with the following assertion failure:llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1354: void {anonymous}::SelectionDAGLegalize::LegalizeOp(llvm::SDNode*): Assertion `(Res.getValueType() == Node->getValueType(0) || Node->getValueType(0) == MVT::Glue) && "Type mismatch for custom legalized operation"' failed.Considering ISEL is very much outside of my area of expertise I doubt I'll be able to make much sense of this, but I'll see what I can do.
I suggest grabbing the LLVM IR that's causing that assertion to get hit and running it through
llvm-reduce. By the end of that, it should be much easier to determine what the root cause is.llvm-reduceleaves me with the following:target datalayout = "E-m:e-p:32:32-Fi64-i64:64-i128:128-n32:64" target triple = "ppc64-unknown-lv2-unknown" @__anon_1820 = external constant [7 x i8] define { ptr, i64 } @__ubsan_handle_add_overflow() { Entry: ret { ptr, i64 } { ptr @__anon_1820, i64 6 } }
Fwiw, running release
llcon the reduced IR crashes with a different error from the one initially observed, but maybe they're related:LLVM ERROR: Cannot select: 0x55a235378dd0: i64 = any_extend 0x55a2353790e0 0x55a2353790e0: i64,ch = PPCISD::TOC_ENTRY<(load (s64) from got)> TargetGlobalAddress:i32<ptr @__anon_1820> 0, Register:i64 $x2 In function: __ubsan_handle_add_overflowWell, I think you're out of luck here; it doesn't look like this target is well-tested in LLVM at all.
❯ bat test.c int x; int main() { return x; } ❯ clang --target=powerpc64-lv2 test.c -c clang: /home/alexrp/Source/llvm-project/llvm/lib/Target/PowerPC/PPCFastISel.cpp:2047: llvm::Register {anonymous}::PPCFastISel::PPCMaterializeGV(const llvm::GlobalValue*, llvm::MVT): Assertion `VT == MVT::i64 && "Non-address!"' failed.Interestingly your example doesn't reproduce for me, tried it with a debug clang 21 as well as on compiler explorer.
Zig Version
0.16.0-dev.1446+947301105
Steps to Reproduce and Observed Behavior
I'd like to preface this with the fact that this is not an issue that can be triggered with the current upstream compiler. I was experimenting with the
powerpc64-ps3(-ilp32)target and extendedlib/std/Target.zig:cTypeBitSizewith the following prong to get rid of the initial panic when using the target:Which matches the
clangbehavior. Running the patched compiler however crashes due to a segfault:I realize this is probably not a priority issue, given that the target isn't even strictly supported in the compiler, but I thought I'd put it out there and then see if I can get to the bottom of it when I get the time.
Expected Behavior
No segfault.