Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
2ec5653
feat: implement llgo.stackSave
MeteorsLiu Sep 15, 2025
93e660a
fix: amd64 getsp demo
MeteorsLiu Sep 15, 2025
c3dbc58
chore: update stacksave signature commets
MeteorsLiu Sep 15, 2025
cf55925
chore(deps): bump github.com/goplus/gogen from 1.19.2 to 1.19.3
dependabot[bot] Oct 10, 2025
7e1abf1
Merge pull request #1333 from goplus/dependabot/go_modules/github.com…
xushiwei Oct 12, 2025
cadafde
Merge pull request #1333 from goplus/dependabot/go_modules/github.com…
xgopilot Oct 13, 2025
f65072d
docs: address review feedback on CLAUDE.md
xgopilot Oct 13, 2025
c7e3408
docs: simplify CLAUDE.md per review feedback
xgopilot Oct 13, 2025
1edd4b8
docs: merge Testing and Validation into single section
xgopilot Oct 13, 2025
a99f3d9
docs: refactor Important Notes with clear workflow and requirements
xgopilot Oct 13, 2025
72602d6
docs: address review feedback on CLAUDE.md
xgopilot Oct 13, 2025
00d5aad
docs: remove duplicate validation section from CLAUDE.md
xgopilot Oct 13, 2025
62198a5
docs: add descriptive instructions to Code Quality section
xgopilot Oct 13, 2025
d6f45c6
docs: merge Testing and Validation into single section
xgopilot Oct 13, 2025
391e09a
docs: migrate all build commands to Common Development Tasks
xgopilot Oct 13, 2025
cf6cc93
fix: add runtime.rand and runtime.memhash for hash/maphash support
xgopilot Oct 14, 2025
441b4b1
test: add hash/maphash demo test case
xgopilot Oct 14, 2025
8aadfde
style: apply linter fixes to maphash test
xgopilot Oct 14, 2025
e05c915
refactor: move hash/maphash linkname bindings to maphash package
xgopilot Oct 14, 2025
3ce198f
fix: remove llgo:skipall directive from maphash overlay
xgopilot Oct 14, 2025
e5ebc32
fix: add randUint64 wrapper for Go 1.21 compatibility
xgopilot Oct 14, 2025
ed3176a
test: expand maphash demo with comprehensive API coverage
xgopilot Oct 14, 2025
2b92b52
fix: resolve compilation errors in maphash demo
xgopilot Oct 14, 2025
bf05779
ci: prevent duplicate workflow runs for xgopilot branches
luoliwoshang Oct 14, 2025
18ef720
Merge pull request #1341 from luoliwoshang/fix-ci-duplicate-runs
xushiwei Oct 14, 2025
75fa863
Merge pull request #1336 from goplus/xgopilot/claude/issue-1335-17603…
xushiwei Oct 14, 2025
e03f4da
Merge pull request #1339 from goplus/xgopilot/claude/issue-1338-17604…
xushiwei Oct 14, 2025
355ff10
chore(deps): bump actions/setup-node from 5 to 6
dependabot[bot] Oct 15, 2025
27efaa2
docs: add hash/maphash to README with partial support status
xgopilot Oct 15, 2025
01ada11
fix: override go/build.defaultContext() to use gc compiler
xgopilot Oct 15, 2025
d8cf93a
refactor: move go/build overlay to runtime/internal for minimal patching
xgopilot Oct 15, 2025
2e0fc5f
refactor: reduce go/build overlay to minimal 87-line patch
xgopilot Oct 15, 2025
d145967
revert: restore full overlay approach for go/build
xgopilot Oct 15, 2025
938f883
refactor: use hasAltPkg with minimal implementation (94% reduction)
xgopilot Oct 15, 2025
325e9a9
Merge pull request #1347 from cpunion/feature/tls-gc
xushiwei Oct 16, 2025
58352e3
Merge pull request #1345 from goplus/xgopilot/claude/issue-1344-17604…
xushiwei Oct 16, 2025
d2a2225
Merge pull request #1342 from goplus/dependabot/github_actions/action…
xushiwei Oct 16, 2025
7fbcc8c
refactor: use runtime.Version() instead of hardcoded goVersion
xgopilot Oct 16, 2025
224e3b9
fix: add Go 1.23+ build constraint to gobuild demo
xgopilot Oct 16, 2025
c4fdb1e
refactor: move cgoSupported to internal/platform package
xgopilot Oct 16, 2025
0b00e06
refactor: update platform package to match original Go structure
xgopilot Oct 16, 2025
8ac7ada
refactor: use go:linkname to link internal/platform.CgoSupported
xgopilot Oct 16, 2025
e96625c
feat: add go:linkname directives for defaultToolTags and defaultRelea…
xgopilot Oct 16, 2025
8b61831
refactor: address review comments on build.go
xgopilot Oct 16, 2025
946a4bf
refactor: link internal/buildcfg.ToolTags and enhance demo test coverage
xgopilot Oct 16, 2025
ee49fad
refactor: follow Go stdlib conventions for build.go
xgopilot Oct 16, 2025
29504f2
refactor: address final review comments
xgopilot Oct 16, 2025
e614edf
test: enhance demo to test multiple go/build public functions
xgopilot Oct 16, 2025
d09ce61
fix: remove trailing newline in build.go
xgopilot Oct 16, 2025
0a94a54
test: enhance demo to test multiple go/build public functions
xgopilot Oct 16, 2025
6e41cc7
refactor: simplify go/build patch using init function
xgopilot Oct 16, 2025
420ad8e
refactor: simplify go/build patch - use build.Default directly
xgopilot Oct 16, 2025
9b39772
Remove redundant CompareString from llgo:skip directive
xgopilot Oct 17, 2025
e47728b
feat(reflect): add Indirect function
xgopilot Oct 17, 2025
8d6d1b7
refactor: move reflect.Indirect test to _demo and use panic()
xgopilot Oct 17, 2025
0c68ae0
refactor: rename reflect-indirect to reflectindirect
xgopilot Oct 17, 2025
a74ca94
feat(reflect): add struct test cases for Indirect function
xgopilot Oct 20, 2025
a2c8132
Merge pull request #1355 from goplus/feature/reflect-indirect
xushiwei Oct 26, 2025
e16fc69
Merge pull request #1349 from goplus/xgopilot/claude/issue-1346-17604…
xushiwei Oct 26, 2025
c036243
Merge pull request #1352 from goplus/xgopilot/claude/issue-1351-17606…
xushiwei Oct 26, 2025
f340621
chore(deps): bump actions/download-artifact from 5 to 6
dependabot[bot] Oct 27, 2025
533ba9e
chore(deps): bump actions/upload-artifact from 4 to 5
dependabot[bot] Oct 27, 2025
3c88949
Merge pull request #1376 from goplus/dependabot/github_actions/action…
xushiwei Oct 27, 2025
86cafff
Merge pull request #1375 from goplus/dependabot/github_actions/action…
xushiwei Oct 27, 2025
bf6f785
Merge branch 'main' of https://github.com/goplus/llgo into impl-stack…
MeteorsLiu Oct 30, 2025
8f5f36e
docs(CLAUDE.md): document out.ll update process after IR changes
xgopilot Oct 31, 2025
c15c7a0
docs(CLAUDE.md): add gentests for batch out.ll updates
xgopilot Oct 31, 2025
c557aa2
docs(CLAUDE.md): remove pro tip line
xgopilot Oct 31, 2025
01af858
docs(CLAUDE.md): remove redundant test failure mention
xgopilot Oct 31, 2025
742bfd9
chore: remove deprecated //export LLGoVersion comment
xgopilot Nov 4, 2025
cda9d68
ci:avoid brew auto upgrade dependant
luoliwoshang Nov 6, 2025
41b403a
fix(runtime): segmentation fault when calling interface private metho…
luoliwoshang Nov 6, 2025
4e374a9
test:refression test for https://github.com/goplus/llgo/issues/1370
luoliwoshang Nov 6, 2025
d368cad
Merge pull request #1388 from luoliwoshang/ci/no-auto-update
xushiwei Nov 10, 2025
a676ba2
Merge pull request #1387 from luoliwoshang/runtime/iface/func
xushiwei Nov 10, 2025
34caf51
Merge pull request #1386 from goplus/xgopilot/claude/issue-1385-17622…
xushiwei Nov 10, 2025
830e8e7
Merge pull request #1381 from goplus/xgopilot/claude/document-outll-p…
xushiwei Nov 10, 2025
2363d28
feat(runtime): add SIGSEGV signal handler to convert nil pointer dere…
luoliwoshang Nov 3, 2025
7ce2733
Merge pull request #1383 from luoliwoshang/feat/nil/recover
xushiwei Nov 11, 2025
ff4a180
chore(deps): bump github.com/goplus/lib from 0.3.0 to 0.3.1
dependabot[bot] Nov 11, 2025
4d1906d
Merge pull request #1391 from goplus/dependabot/go_modules/github.com…
xushiwei Nov 11, 2025
91f6ad9
chore(deps): bump github.com/goplus/gogen from 1.19.3 to 1.19.5
dependabot[bot] Nov 11, 2025
0dbe528
Merge pull request #1304 from MeteorsLiu/impl-stacksave
xushiwei Nov 12, 2025
3f8c95c
Merge pull request #1334 from goplus/dependabot/go_modules/github.com…
xushiwei Nov 12, 2025
1670941
defer: enable loop lowering
cpunion Oct 15, 2025
3307860
ssa: avoid redundant thread defer update
cpunion Oct 15, 2025
30bde9f
tls: stub handle for go test
cpunion Oct 15, 2025
cb173f9
ssa: rely on runtime thread defer TLS
cpunion Oct 15, 2025
983a189
test: cover defer recover and nested loops
cpunion Oct 17, 2025
21fef12
di: clean unreachable code
cpunion Oct 22, 2025
e459ca9
runtime: remove overlays for defer workaround
cpunion Oct 24, 2025
0455ad4
ssa: Add test for >64 conditional defers; cover panic at eh.go:252-254
cpunion Nov 13, 2025
317de80
test: add nested defer/loop/branch/recover tests and fix mixed branch…
cpunion Nov 13, 2025
aeb5d82
ssa: remove unreachable switch case
cpunion Nov 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/actions/setup-deps/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ runs:
- name: Install macOS dependencies
if: runner.os == 'macOS'
shell: bash
env:
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: 1
run: |
brew update

Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches:
- "**"
- "!dependabot/**"
- "!xgopilot/**"
pull_request:
branches: ["**"]

Expand All @@ -20,7 +21,7 @@ jobs:
- uses: actions/checkout@v5

- name: Set up Node.js
uses: actions/setup-node@v5
uses: actions/setup-node@v6
with:
node-version: "20"

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/fmt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches:
- "**"
- "!dependabot/**"
- "!xgopilot/**"
pull_request:
branches: ["**"]

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
branches:
- "**"
- "!dependabot/**"
- "!xgopilot/**"
pull_request:
branches: ["**"]

Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/llgo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
branches:
- "**"
- "!dependabot/**"
- "!xgopilot/**"
pull_request:
branches: ["**"]

Expand All @@ -26,7 +27,7 @@ jobs:
wget -P ./_demo/c/llama2-c https://huggingface.co/karpathy/tinyllamas/resolve/main/stories15M.bin

- name: Upload model as artifact
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v5
with:
name: llama2-model
path: ./_demo/c/llama2-c/stories15M.bin
Expand All @@ -51,7 +52,7 @@ jobs:
with:
llvm-version: ${{matrix.llvm}}
- name: Download model artifact
uses: actions/download-artifact@v5
uses: actions/download-artifact@v6
with:
name: llama2-model
path: ./_demo/c/llama2-c/
Expand Down
17 changes: 10 additions & 7 deletions .github/workflows/release-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ name: Release Build

on:
push:
branches: ["**"]
branches:
- "**"
- "!dependabot/**"
- "!xgopilot/**"
tags: ["*"]
pull_request:
branches: ["**"]
Expand Down Expand Up @@ -79,39 +82,39 @@ jobs:
release --verbose --skip=publish,nfpm,snapcraft --snapshot --clean

- name: Upload Darwin AMD64 Artifacts
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v5
with:
name: llgo-darwin-amd64
path: .dist/*darwin-amd64.tar.gz
retention-days: 3
include-hidden-files: true

- name: Upload Darwin ARM64 Artifacts
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v5
with:
name: llgo-darwin-arm64
path: .dist/*darwin-arm64.tar.gz
retention-days: 3
include-hidden-files: true

- name: Upload Linux AMD64 Artifacts
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v5
with:
name: llgo-linux-amd64
path: .dist/*linux-amd64.tar.gz
retention-days: 3
include-hidden-files: true

- name: Upload Linux ARM64 Artifacts
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v5
with:
name: llgo-linux-arm64
path: .dist/*linux-arm64.tar.gz
retention-days: 3
include-hidden-files: true

- name: Upload Checksums
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v5
with:
name: llgo-checksums
path: .dist/*checksums.txt
Expand Down Expand Up @@ -155,7 +158,7 @@ jobs:
with:
go-version: ${{ matrix.go-version }}
- name: Download Platform Artifact
uses: actions/download-artifact@v5
uses: actions/download-artifact@v6
with:
name: llgo-${{ matrix.goos }}-${{ matrix.goarch }}
path: .
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/targets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
branches:
- "**"
- "!dependabot/**"
- "!xgopilot/**"
pull_request:
branches: ["**"]

Expand Down
182 changes: 182 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
# LLGo Project AI Assistant Guide

This document provides essential information for AI assistants to help fix bugs and implement features in the LLGo project.

## About LLGo

LLGo is a Go compiler based on LLVM designed to better integrate Go with the C ecosystem, including Python and JavaScript. It's a subproject of the XGo project that aims to expand the boundaries of Go/XGo for game development, AI and data science, WebAssembly, and embedded development.

## Project Structure

- `cmd/llgo` - Main llgo compiler command (usage similar to `go` command)
- `cl/` - Core compiler logic that converts Go packages to LLVM IR
- `ssa/` - LLVM IR file generation using Go SSA semantics
- `internal/build/` - Build process orchestration
- `runtime/` - LLGo runtime library
- `chore/` - Development tools (llgen, llpyg, ssadump, etc.)
- `_demo/` - Example programs demonstrating C/C++ interop (`c/hello`, `c/qsort`) and Python integration (`py/callpy`, `py/numpy`)
- `_cmptest/` - Comparison tests to verify the same program gets the same output with Go and LLGo

## Development Environment

For detailed dependency requirements and installation instructions, see the [Dependencies](README.md#dependencies) and [How to install](README.md#how-to-install) sections in the README.

## Testing & Validation

The following commands and workflows are essential when fixing bugs or implementing features in the LLGo project:

### Run all tests
```bash
go test ./...
```

**Note:** Some tests may fail if optional dependencies (like Python) are not properly configured. The test suite includes comprehensive tests for:
- Compiler functionality
- SSA generation
- C interop
- Python integration (requires Python development headers)

### Write and run tests for your changes

When adding new functionality or fixing bugs, create appropriate test cases:

```bash
# Add your test to the relevant package's *_test.go file
# Then run tests for that package
go test ./path/to/package

# Or run all tests
go test ./...
```

**Important:** The `LLGO_ROOT` environment variable must be set to the repository root when running llgo commands during development.

### Update out.ll files after modifying compiler IR generation

**CRITICAL:** When you modify the compiler's IR generation logic (especially in `ssa/` or `cl/` packages), you MUST update all out.ll test files under the `cl/` directory.

#### Understanding out.ll files

The `out.ll` files under the `cl/` directory are comparison IR files that serve as reference outputs for the test suite:
- They are generated by `llgen` from the corresponding `in.go` files in the same directory
- They reflect the current compiler's LLVM IR representation of the Go source code
- They are used by tests to verify that the compiler generates correct and consistent IR output

#### Required steps after modifying IR generation logic

1. **Reinstall the tools** to apply your compiler changes:
```bash
go install -v ./chore/gentests
go install -v ./chore/llgen
```

2. **Regenerate out.ll files**:

**For batch updates (recommended)** - Use `gentests` to regenerate all test files:
```bash
gentests
```
This will automatically regenerate all out.ll files in these directories:
- `cl/_testlibc`
- `cl/_testlibgo`
- `cl/_testrt`
- `cl/_testgo`
- `cl/_testpy`
- `cl/_testdata`

**For individual test inspection** - Use `llgen` to regenerate specific test directories:
```bash
llgen cl/_testgo/interface
llgen cl/_testrt/tpmethod
```

3. **Verify the changes** make sense by reviewing the diff in the out.ll files

4. **Commit the updated out.ll files** along with your compiler changes

#### Why this matters

This process ensures that:
- The test suite reflects the current compiler behavior
- Changes to IR generation are properly documented and reviewed
- Future regressions can be detected by comparing against the reference output

## Code Quality

Before submitting any code updates, you must run the following formatting and validation commands:

### Format code
```bash
go fmt ./...
```

**Important:** Always run `go fmt ./...` before committing code changes. This ensures consistent code formatting across the project.

### Run static analysis
```bash
go vet ./...
```

**Note:** Currently reports some issues related to lock passing by value in `ssa/type_cvt.go` and a possible unsafe.Pointer misuse in `cl/builtin_test.go`. These are known issues.


## Common Development Tasks

### Build the entire project
```bash
go build -v ./...
```

### Build llgo command specifically
```bash
go build -o llgo ./cmd/llgo
```

### Check llgo version
```bash
llgo version
```

### Install llgo for system-wide use
```bash
./install.sh
```

### Build development tools
```bash
go install -v ./cmd/...
go install -v ./chore/...
```

## Key Modules for Understanding

- `ssa` - Generates LLVM IR using Go SSA semantics
- `cl` - Core compiler converting Go to LLVM IR
- `internal/build` - Orchestrates the compilation process

## Debugging

### Disable Garbage Collection
For testing purposes, you can disable GC:
```bash
LLGO_ROOT=/path/to/llgo llgo run -tags nogc .
```

## LLGO_ROOT Environment Variable

**CRITICAL:** Always set `LLGO_ROOT` to the repository root when running llgo during development:

```bash
export LLGO_ROOT=/path/to/llgo
# or
LLGO_ROOT=/path/to/llgo llgo run .
```

## Important Notes

1. **Testing Requirement:** All bug fixes and features MUST include tests
2. **Demo Directory:** Examples in `_demo` are prefixed with `_` to prevent standard `go` command from trying to compile them
3. **Defer in Loops:** LLGo intentionally does not support `defer` in loops (considered bad practice)
4. **C Ecosystem Integration:** LLGo uses `go:linkname` directive to link external symbols through ABI
5. **Python Integration:** Third-party Python libraries require separate installation of library files

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ All Go syntax (including `cgo`) is already supported. Here are some examples:

### Defer

LLGo `defer` does not support usage in loops. This is not a bug but a feature, because we think that using `defer` in a loop is a very unrecommended practice.
LLGo now supports `defer` within loops, matching Go's semantics of executing defers in LIFO order for every iteration. The usual caveat from Go still applies: be mindful of loop-heavy defer usage because it allocates per iteration.


### Garbage Collection (GC)
Expand Down Expand Up @@ -323,6 +323,7 @@ Here are the Go packages that can be imported correctly:
* [hash/adler32](https://pkg.go.dev/hash/adler32)
* [hash/crc32](https://pkg.go.dev/hash/crc32) (partially)
* [hash/crc64](https://pkg.go.dev/hash/crc64)
* [hash/maphash](https://pkg.go.dev/hash/maphash) (partially)
* [crypto](https://pkg.go.dev/crypto)
* [crypto/md5](https://pkg.go.dev/crypto/md5)
* [crypto/sha1](https://pkg.go.dev/crypto/sha1)
Expand Down
22 changes: 22 additions & 0 deletions _demo/c/stacksave/stacksave_amd64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//go:build amd64

package main

import (
"unsafe"
_ "unsafe"
)

//go:linkname getsp llgo.stackSave
func getsp() unsafe.Pointer

//go:linkname asmFull llgo.asm
func asmFull(instruction string, regs map[string]any) uintptr { return 0 }

func main() {
sp := asmFull("movq %rsp, {}", nil)

if sp != uintptr(getsp()) {
panic("invalid stack pointer")
}
}
22 changes: 22 additions & 0 deletions _demo/c/stacksave/stacksave_arm64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//go:build arm64

package main

import (
"unsafe"
_ "unsafe"
)

//go:linkname getsp llgo.stackSave
func getsp() unsafe.Pointer

//go:linkname asmFull llgo.asm
func asmFull(instruction string, regs map[string]any) uintptr { return 0 }

func main() {
sp := asmFull("mov {}, sp", nil)

if sp != uintptr(getsp()) {
panic("invalid stack pointer")
}
}
Loading