Commit Graph

26 Commits

Author SHA1 Message Date
xgopilot
88d32c9930 fix(ssa): correct PkgPath for interface metadata in cross-package conversions
Fixes #1370 - Segmentation Fault When Calling Interface Private Methods Cross-Package

This commit fixes a critical bug where interface metadata's PkgPath was incorrectly
set when converting concrete type pointers to interfaces with private methods across
package boundaries.

Problem:
- When a concrete type pointer was converted to an interface with private methods
  in a package different from the interface definition package, the compiler
  incorrectly set the interface metadata's PkgPath to the current compilation
  package instead of the interface definition package
- This caused the runtime to only fill exported methods in the itab, leaving
  private method slots as NULL (0x0), resulting in segmentation faults

Solution:
- Modified abiInterfaceOf() in ssa/abitype.go to extract the package path from
  the interface's private methods (if any)
- Use that package path instead of the current compilation package path
- Fall back to current package path only if all methods are exported

Changes:
- ssa/abitype.go: Use abi.PathOf() to get correct package path
- ssa/interface.go: Refactor to simplify interface type handling
- Added comprehensive test cases and demos for go/types, go/token, and go/ast
- Updated all test outputs to reflect correct interface metadata generation

This fix resolves segmentation faults when using Go standard library interfaces
and user-defined interfaces with private methods across package boundaries.

Generated with [codeagent](https://github.com/qbox/codeagent)
Co-authored-by: luoliwoshang <51194195+luoliwoshang@users.noreply.github.com>
2025-10-30 06:24:23 +00:00
visualfc
5592a8fc26 ssa: fix abiTupleOf 2025-09-25 20:16:44 +08:00
visualfc
56f90dbcf9 ssa: fix TypeAssert check null 2025-08-08 12:11:17 +08:00
visualfc
c4f0dd124d cl: funcName check $bound 2025-05-15 21:12:18 +08:00
Li Jie
ed366568b4 move out c/cpp/py 2025-04-03 16:26:11 +08:00
Li Jie
1172e5bdce build: separate compiler and libs 2025-01-08 14:59:01 +08:00
visualfc
ef28abe896 internal/runtime: funcStr, interfaceStr, array str 2024-12-20 12:33:34 +08:00
visualfc
d251232f8a internal/runtime: named(ptr) type preset for method type 2024-12-20 11:37:30 +08:00
visualfc
e55a5d7486 internal/runtime: NewNamedInterface, InitNamedInterface 2024-12-16 12:07:13 +08:00
Li Jie
43c1bc8d5f ssa: compile go string constant without alloca 2024-11-24 15:29:20 +08:00
visualfc
d62c2d913e ssa: abi check interface method 2024-10-12 15:59:10 +08:00
visualfc
9eb9b48534 internal/lib/reflect: type.Field FieldByIndex FieldByName 2024-09-22 20:56:15 +08:00
Li Jie
c0e1e31572 rebuild tests 2024-09-14 16:14:50 +08:00
visualfc
2feb3e1d7a ssa: prog.linkname; abi llvm.LinkOnceAnyLinkage always 2024-08-20 21:11:27 +08:00
visualfc
cf75e3e664 ssa: abiNamed set underlying size 2024-07-17 10:42:04 +08:00
visualfc
73b42f924d ssa: fix setDirectIface 2024-07-08 20:19:25 +08:00
visualfc
91ba215568 internal/runtime: check abi.KindDirectIface 2024-07-04 18:59:41 +08:00
visualfc
bcb217c1da ssa: set pointer directiface 2024-07-04 18:50:37 +08:00
visualfc
16352df5b1 ssa: fix abiType && abiMethoOf 2024-06-25 10:22:32 +08:00
visualfc
c090c34491 runtime: panic any custometype 2024-06-23 21:51:00 +08:00
visualfc
9ae7d4f2bf ssa: abiTypeInit kind 2024-06-20 22:09:26 +08:00
Li Jie
73570b5628 cl: re-generate tests 2024-06-20 20:13:53 +08:00
visualfc
ec1cca7ca4 ssa: global use elem type 2024-06-14 10:09:46 +08:00
visualfc
0c321c8c98 ssa: binop equal(func,slice,array,struct) and buildConstStr 2024-06-14 10:04:01 +08:00
xushiwei
45f470e3a7 merge upstream 2024-06-12 21:02:26 +08:00
visualfc
3f0c65ebb2 ssa: fix typeAssert for Nil 2024-06-11 20:50:01 +08:00