Skip to content

Add metadata api and set llvm 20 as default#36

Closed
zhouguangyuan0718 wants to merge 1 commit intoxgo-dev:goplusfrom
zhouguangyuan0718:goplus_21
Closed

Add metadata api and set llvm 20 as default#36
zhouguangyuan0718 wants to merge 1 commit intoxgo-dev:goplusfrom
zhouguangyuan0718:goplus_21

Conversation

@zhouguangyuan0718
Copy link
Copy Markdown

Summary:

  • add metadata APIs in IR bindings
  • switch default LLVM version from 19 to 20
  • keep LLVM 19/20 config files aligned with the new default

Test:

  • not run

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, 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 primarily focuses on enhancing the LLVM bindings by introducing new metadata-related APIs and updating the default LLVM version to 20. These changes improve the flexibility of working with LLVM metadata and ensure the project leverages the latest LLVM features, while also updating the Go module's minimum Go version requirement.

Highlights

  • Metadata APIs: New metadata APIs, specifically MetadataType and MetadataAsValue, have been added to the IR bindings to enhance metadata handling capabilities.
  • LLVM Version Update: The default LLVM version has been switched from 19 to 20, aligning the project with a newer LLVM release.
  • Build Tag Alignment: The build configuration files for LLVM 19 and LLVM 20 have been updated to reflect the new default version, ensuring proper conditional compilation.
  • Go Version Update: The required Go version in go.mod has been updated from 1.14 to 1.22.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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.

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
Copy Markdown

@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 new metadata APIs, upgrades the Go version to 1.22, and makes LLVM 20 the default. While the code changes for the new APIs and build configurations appear correct and consistent with the project's style, the PR description states that no tests were run. Given the changes to the build configuration and Go version, this is a critical risk. It is imperative to run the full test suite to validate these changes and prevent potential build failures or regressions before merging.

Comment thread llvm_config_llvm19.go
@@ -1,4 +1,4 @@
//go:build !byollvm && !llvm14 && !llvm15 && !llvm16 && !llvm17 && !llvm18 && !llvm20 && !llvm21
//go:build !byollvm && llvm19
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Silent breaking change for existing LLVM 19 users

The old tag (!byollvm && !llvm14 && ... && !llvm18 && !llvm20 && !llvm21) made LLVM 19 the default — any build without an explicit version tag would select it. The new tag !byollvm && llvm19 requires an explicit opt-in.

Any CI pipeline or user who was building without a version tag (relying on LLVM 19 as the default) will silently switch to LLVM 20 after this change. There is no compile-time error; the wrong LLVM version is simply picked up transparently.

Consider adding a note in the PR description or README about this migration requirement.

Comment thread ir.go Outdated
md.C = C.LLVMMDString2(c.C, cstr, C.unsigned(len(str)))
return
}
func (c Context) MetadataType() (t Type) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Naming inconsistency with existing metadata API

The existing metadata functions in this file use the MD prefix: MDString, MDNode. The new function uses the full word MetadataType, breaking the established convention. Consider renaming to MDType for consistency.

MetadataAsValue is less clear-cut since the upstream C function is LLVMMetadataAsValue, but if MDType is preferred, MDAsValue or MDValue would follow the same pattern.

Comment thread ir.go
md.C = C.LLVMConstantAsMetadata(v.C)
return
}
func (c Context) MetadataAsValue(md Metadata) (v Value) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Potential crash on nil Metadata

LLVMMetadataAsValue in upstream LLVM does not null-guard its MD argument — unlike the custom wrappers in IRBindings.cpp (e.g., LLVMSetMetadata2) which explicitly check if (!MD). Calling this with a zero-valued Metadata{} passes NULL across the CGo boundary and causes an unrecoverable SIGSEGV inside LLVM's C++ runtime.

Consider adding a guard:

func (c Context) MetadataAsValue(md Metadata) (v Value) {
    if md.C == nil {
        return
    }
    v.C = C.LLVMMetadataAsValue(c.C, md.C)
    return
}

Comment thread ir.go Outdated
md.C = C.LLVMMDString2(c.C, cstr, C.unsigned(len(str)))
return
}
func (c Context) MetadataType() (t Type) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing blank lines and doc comments

Both new functions are inserted without a preceding blank line, diverging from the style of every other function in this file. Per gofmt and Go conventions, top-level declarations should be separated by blank lines.

Additionally, both exported functions lack Go doc comments. Standard convention requires a comment beginning with the function name, e.g.:

// MetadataType returns the metadata type for the given context.
func (c Context) MetadataType() (t Type) { ... }

Without these, go doc output will be empty for these new API entries.

@fennoai
Copy link
Copy Markdown

fennoai Bot commented Mar 22, 2026

Clean, well-scoped PR. The metadata API additions are minimal and follow existing patterns. The main concerns are: (1) the LLVM 19 → 20 default switch is a silent behavioral change for users building without explicit version tags — worth calling out in the description or docs; (2) the go.mod bump from 1.14 → 1.22 is a significant jump that deserves a rationale comment. The llvm20 exclusion list also doesn't yet exclude future versions (e.g., llvm22), which mirrors the original LLVM 19 issue this PR is correcting.

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.

2 participants