Commit Graph

53 Commits

Author SHA1 Message Date
xgopilot
eb0fa2e107 fix(ssa): revert unnecessary formatting changes
Reverted two unnecessary formatting changes based on code review:
- ssa/interface.go: Restored single-line format for val function
- ssa/abitype.go: Moved pkg variable declaration back to original position

These changes don't affect functionality, just code formatting.

Generated with [codeagent](https://github.com/qbox/codeagent)
Co-authored-by: luoliwoshang <51194195+luoliwoshang@users.noreply.github.com>
2025-10-30 08:06:40 +00:00
xgopilot
79bf753c0e fix(ssa): use empty PkgPath for anonymous interfaces
Based on meeting discussion, this commit reverts the previous approach
of extracting PkgPath from interface methods. Instead, anonymous
interfaces now use an empty PkgPath string, and the runtime's methods()
function handles empty PkgPath by returning all methods.

Changes:
- Reverted unsafeInterface() to remove originType parameter
- Set anonymous interface PkgPath to empty string in abitype.go:202
- Added early return in methods() in z_face.go for empty PkgPath
- All call sites of unsafeInterface() updated to pass rawIntf directly

This approach is cleaner because anonymous interfaces don't belong to
any package, and the compiler already guarantees safety for cross-package
private method access.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-authored-by: luoliwoshang <51194195+luoliwoshang@users.noreply.github.com>
2025-10-30 07:33:20 +00:00
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
56f90dbcf9 ssa: fix TypeAssert check null 2025-08-08 12:11:17 +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
3741a28d94 ssa: fix bitcast for float32 2024-12-24 10:02:30 +08:00
visualfc
a6a3c09c05 ssa: closure use specific struct field name { $f ftype, $data unsafe.pointer } 2024-12-22 12:44:33 +08:00
visualfc
6b0122547e reflect.call: internal/abi: TFlagClosure, internal/lib/reflect: flagClosure. 2024-11-01 15:27:40 +08:00
visualfc
2174d8fe8c ssa: makeInterface check funcdecl => closure 2024-08-15 10:12:18 +08:00
visualfc
28d8c56534 ssa: index take addr 2024-07-04 18:50:36 +08:00
visualfc
16352df5b1 ssa: fix abiType && abiMethoOf 2024-06-25 10:22:32 +08:00
visualfc
3f0c65ebb2 ssa: fix typeAssert for Nil 2024-06-11 20:50:01 +08:00
visualfc
2fce2318ed ssa: set method.name to pkg.name if private 2024-06-06 07:30:59 +08:00
visualfc
193e6dfc93 ssa: ChangeInterface 2024-06-03 16:03:05 +08:00
visualfc
7596658e6c ssa: MakeInterface check abi.KindDirectIface 2024-06-03 11:47:16 +08:00
xushiwei
76c1800a53 abiTypes: abiTypeInit fix 2024-05-31 08:12:27 +08:00
xushiwei
3b2f01e974 abiTypes 2024-05-31 07:35:22 +08:00
xushiwei
e5f38a6fc1 abitype.go 2024-05-28 23:58:37 +08:00
xushiwei
8c105d87c1 runtime: newNamed; llgo/ssa: abiMethodOf 2024-05-28 23:45:32 +08:00
xushiwei
1c1da6433a runtime: rm NewSlice (use b.unsafeSlice); llgo/ssa: Println 2024-05-28 07:47:07 +08:00
visualfc
3328847e27 ssa: sliceOf arrayOf 2024-05-27 14:54:24 +08:00
xushiwei
8e89dc8aa9 llgo/ssa: abiMethodOf; AfterInit bugfix 2024-05-27 14:32:23 +08:00
xushiwei
df13e3ab82 PrintIface 2024-05-27 09:56:42 +08:00
xushiwei
8536fe4987 llgo/ssa: Imethod 2024-05-27 09:46:07 +08:00
xushiwei
165a99fd83 llgo/ssa: unsafeInterface; runtime.PointerTo 2024-05-27 08:07:34 +08:00
xushiwei
eae94c5f23 remove abi.Name 2024-05-26 17:53:29 +08:00
xushiwei
ddabfdca3d SetBlockEx: BeforeLast 2024-05-26 16:18:24 +08:00
xushiwei
91c9b4e168 llgo/ssa: pkgName 2024-05-26 09:34:43 +08:00
xushiwei
914a0c60b0 runtime: iface 2024-05-26 08:59:10 +08:00
xushiwei
5eac8d860a abiType fix 2024-05-25 08:20:09 +08:00
xushiwei
1226308f3d TypeAssert bugfix; testcase struczero 2024-05-25 07:43:24 +08:00
xushiwei
40dd25c122 abi: support named 2024-05-25 01:11:35 +08:00
xushiwei
ab7c828cfa InterfaceData 2024-05-24 23:06:54 +08:00
xushiwei
3cc975813d abiType: support pointer 2024-05-24 22:47:45 +08:00
xushiwei
77eeea95c7 valFromData BitCast bugfix 2024-05-24 09:30:16 +08:00
xushiwei
056ad51c24 llgo/ssa.Phi: AddIncoming fix 2024-05-24 09:20:58 +08:00
xushiwei
88004cac76 abiBasic fix 2024-05-24 07:51:41 +08:00
xushiwei
1162a5f916 AfterInit: init 2024-05-24 03:22:10 +08:00
xushiwei
418c37dd52 AfterInit bugfix: add param Builder 2024-05-24 02:42:10 +08:00
xushiwei
b66827998d llgo/ssa: AfterInit 2024-05-24 02:09:57 +08:00
xushiwei
b195656900 llgo/ssa: MakeInterface 2024-05-24 01:45:41 +08:00
xushiwei
2628ee98f3 llgo/ssa: valFromData, buildVal 2024-05-24 01:18:18 +08:00
xushiwei
176c0b2d36 abi.KindOf; llgo/ssa: valFromData 2024-05-24 00:36:51 +08:00
xushiwei
4986592dd7 TypeAssert refactor 2024-05-23 01:34:48 +08:00
xushiwei
a4c4324ba3 merge Field/Extract; prog.Tuple/Zero; TypeAssert refactor 2024-05-23 01:10:13 +08:00
xushiwei
6442ab2f20 llgo/ssa: unsafeEface 2024-05-22 13:47:21 +08:00
xushiwei
c19786bdfb llgo/ssa: AfterInit/SliceLit/InterfaceData, unsafe.Slice; ssa/abi: Basic/Struct 2024-05-22 10:07:21 +08:00
xushiwei
e61ebb4eb9 abi.Name; runtime: MakeAnyInt => MakeAnyIntptr; llgo/ssa: AllocU; builtin unsafe.String; MakeInterface; prog.PointerSize 2024-05-20 08:46:39 +08:00
xushiwei
55365b1d17 update llvm 2024-05-19 16:42:22 +08:00