Skip to content

fix:GenLL flag to correct compile#1314

Merged
xushiwei merged 1 commit intogoplus:mainfrom
luoliwoshang:internal/build/genll
Sep 21, 2025
Merged

fix:GenLL flag to correct compile#1314
xushiwei merged 1 commit intogoplus:mainfrom
luoliwoshang:internal/build/genll

Conversation

@luoliwoshang
Copy link
Member

@luoliwoshang luoliwoshang commented Sep 17, 2025

fix

ld.lld: error: /Users/zhangzhiyang/Library/Caches/go-build/66/6632870c9c1a886cefc86ba8c27b73e755145f805c59d5666222059cd92fc1cd-d.ll:1: malformed number: ' >>> ; ModuleID = 'github.com/goplus/llgo/_demo/arr' >>> ^ exit status 1

@niupilot
Copy link

niupilot bot commented Sep 17, 2025

🔍 PR Review Analysis

Reviewing PR #1314 - Changes to internal/build/build.go

Todo Checklist:

  • Read and analyze the modified file (internal/build/build.go)
  • Check for repository-specific guidelines (CLAUDE.md)
  • Review code quality and best practices
  • Identify potential bugs or issues
  • Assess architecture and design decisions
  • Check documentation consistency requirements
  • Provide comprehensive review feedback

📋 Summary

This PR adds 20 lines of code to the linkObjFiles function in internal/build/build.go. The change introduces logic to compile .ll (LLVM IR) files to .o (object) files when the GenLL configuration option is enabled.

🔍 Detailed Analysis

Code Quality Assessment

Strengths:

  • Clear Intent: The code clearly handles the case where LLVM IR files need to be compiled to object files before linking
  • Error Handling: Proper error propagation with descriptive error messages using fmt.Errorf
  • Consistent Style: Follows existing code patterns and naming conventions in the file
  • Verbose Output: Respects the existing verbose flag for debugging compilation commands

Potential Issues

⚠️ Medium Priority Issues:

  1. Slice Memory Management (internal/build/build.go:853-870)

    • The code creates a new slice compiledObjFiles and copies all files, even when no .ll files are present
    • Consider early return if no .ll files exist to avoid unnecessary memory allocation
  2. File Path Handling (internal/build/build.go:856)

    • Uses basic strings.TrimSuffix + concatenation for path manipulation
    • Consider using filepath package for more robust cross-platform path handling
  3. Compiler Arguments (internal/build/build.go:858)

    • The -Wno-override-module flag is hardcoded
    • Consider making compiler warnings configurable or documenting why this specific warning is suppressed

Architecture & Design

Good Design Decisions:

  • Single Responsibility: The added logic is focused and doesn't mix concerns
  • Configuration-Driven: Properly gated behind the ctx.buildConf.GenLL flag
  • Integration: Fits well within the existing linkObjFiles function flow

Best Practices Compliance

Follows Go Best Practices:

  • Proper error handling and propagation
  • Clear variable naming (compiledObjFiles, oFile)
  • Consistent with existing code style in the repository

Testing & Documentation

Considerations:

  • No obvious documentation updates needed (this appears to be internal build logic)
  • Test coverage unclear from the PR - consider adding tests for the new compilation path

🚀 Suggestions for Improvement

While the code is functional and well-written, here are some optimization opportunities:

  1. Early Exit Optimization: Check if any .ll files exist before creating the new slice
  2. Use filepath Package: Use filepath.ChangeExt() or similar for path manipulation
  3. Consider Parallel Compilation: For large numbers of .ll files, consider parallel compilation

✅ Overall Assessment

This is a well-implemented feature addition that:

  • ✅ Solves a clear need (compiling LLVM IR files during the build process)
  • ✅ Maintains code quality standards
  • ✅ Follows existing patterns and conventions
  • ✅ Includes proper error handling

The code is ready for merge with only minor optimization opportunities for future consideration.


👉 Want me to re-run this review? Just type /review in the comments! For more usage examples, visit CodeAgent GitHub Repository.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @luoliwoshang, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the build system to correctly handle LLVM Intermediate Representation files. It introduces a new build configuration flag, GenLL, which, when activated, enables the compilation of .ll files into standard object files using clang prior to the linking phase. This change ensures that projects utilizing LLVM IR can be successfully built and linked, resolving potential compilation failures related to these file types.

Highlights

  • LLVM IR Compilation: Introduced new logic to compile .ll (LLVM Intermediate Representation) files into standard .o object files using clang when the GenLL build flag is enabled.
  • Build Process Integration: Modified the linkObjFiles function to preprocess LLVM IR files, ensuring they are properly compiled before being passed to the linker, thus correcting compilation issues.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a fix to correctly handle the GenLL flag by compiling .ll files into object files before linking. The implementation is sound, but I've suggested a refactoring to improve efficiency and code clarity. By modifying the slice of object files in-place, we can avoid allocating a new slice, which makes the code more concise and performant.

Comment on lines +853 to +869
var compiledObjFiles []string
for _, objFile := range objFiles {
if strings.HasSuffix(objFile, ".ll") {
oFile := strings.TrimSuffix(objFile, ".ll") + ".o"
args := []string{"-o", oFile, "-c", objFile, "-Wno-override-module"}
if verbose {
fmt.Fprintln(os.Stderr, "clang", args)
}
if err := ctx.compiler().Compile(args...); err != nil {
return fmt.Errorf("failed to compile %s: %v", objFile, err)
}
compiledObjFiles = append(compiledObjFiles, oFile)
} else {
compiledObjFiles = append(compiledObjFiles, objFile)
}
}
objFiles = compiledObjFiles

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This loop can be simplified by modifying the objFiles slice in-place. This avoids allocating a new slice compiledObjFiles, which improves both performance and readability.

for i, objFile := range objFiles {
	if strings.HasSuffix(objFile, ".ll") {
		oFile := strings.TrimSuffix(objFile, ".ll") + ".o"
		args := []string{"-o", oFile, "-c", objFile, "-Wno-override-module"}
		if verbose {
			fmt.Fprintln(os.Stderr, "clang", args)
		}
		if err := ctx.compiler().Compile(args...); err != nil {
			return fmt.Errorf("failed to compile %s: %v", objFile, err)
		}
		objFiles[i] = oFile
	}
}

@codecov
Copy link

codecov bot commented Sep 17, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.10%. Comparing base (18e0365) to head (c562f05).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1314   +/-   ##
=======================================
  Coverage   90.10%   90.10%           
=======================================
  Files          43       43           
  Lines       12562    12562           
=======================================
  Hits        11319    11319           
  Misses       1087     1087           
  Partials      156      156           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@xushiwei xushiwei merged commit 67a3cb2 into goplus:main Sep 21, 2025
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants