Skip to content

sync: align Cond with stdlib to fix interface nil comparisons#1494

Merged
xushiwei merged 1 commit intogoplus:mainfrom
cpunion:fix/iface-zeroinit
Dec 21, 2025
Merged

sync: align Cond with stdlib to fix interface nil comparisons#1494
xushiwei merged 1 commit intogoplus:mainfrom
cpunion:fix/iface-zeroinit

Conversation

@cpunion
Copy link
Collaborator

@cpunion cpunion commented Dec 19, 2025

Fixes #1493

Root cause: llgo’s sync.Cond diverged from the stdlib layout. It stored a *sync.Mutex and didn’t expose Cond.L, so code that accessed Cond.L (an interface) loaded a pointer instead. Comparisons like p.c.L == nil or nil == p.c.L then produced invalid LLVM IR (icmp between pointer and interface).

Changes:

  • Add L gosync.Locker to sync.Cond and store it in NewCond.
  • Use Cond.L in Wait (validate *Mutex and ensure init).
  • Use cond.Signal/Broadcast directly (remove pthread linkname calls).
  • Add http2pipe interface comparison tests/demos covering both operand orders.

@gemini-code-assist
Copy link

Summary of Changes

Hello @cpunion, 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 addresses a critical bug in the SSA generation process that led to the creation of malformed LLVM IR when comparing an interface value with a non-interface value. The core change ensures that such comparisons are correctly handled by explicitly converting the non-interface operand to an interface, thereby aligning the generated IR with Go's runtime semantics for interface equality and preventing runtime errors or unexpected behavior.

Highlights

  • Bug Fix: Resolved an issue where comparing a non-interface value with an interface value generated invalid LLVM IR, specifically icmp eq ptr ... instead of proper interface equality checks.
  • Type Conversion: Implemented logic in the BinOp function to detect mixed interface/non-interface comparisons and automatically convert the non-interface operand to an interface type using MakeInterface.
  • New Test Case: Added a new test file, interface_cmp_test.go, to specifically verify the fix for mixed interface comparisons, drawing inspiration from sync.Cond usage in net/http.

🧠 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.

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 correctly fixes a bug that caused invalid LLVM IR generation for comparisons between interface and non-interface types. The approach of converting the non-interface operand to an interface before comparison is sound. The added test case effectively covers the failing scenario. I have a couple of suggestions to improve code readability and maintainability in both the fix and the new test file.

@xgopilot
Copy link
Contributor

xgopilot bot commented Dec 19, 2025

Code Review Summary

Great work on fixing the invalid LLVM IR generation for mixed interface/pointer comparisons! The approach is sound, but there's a critical bug that needs to be fixed.

Critical Issue:

  • Missing kind = y.kind in the second conversion branch (line 554). This will cause incorrect comparison logic when the right operand is converted.

Important Improvements:

Security & Performance: No concerns. The code is type-safe and the interface conversion overhead is acceptable for correctness.

Please address the critical bug before merging.

@codecov
Copy link

codecov bot commented Dec 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.58%. Comparing base (5627fb3) to head (26e43bb).
⚠️ Report is 18 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1494   +/-   ##
=======================================
  Coverage   90.58%   90.58%           
=======================================
  Files          43       43           
  Lines       11429    11429           
=======================================
  Hits        10353    10353           
  Misses        914      914           
  Partials      162      162           

☔ 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.

@cpunion cpunion force-pushed the fix/iface-zeroinit branch 9 times, most recently from 8420770 to 08f97ad Compare December 19, 2025 10:09
@cpunion cpunion changed the title ssa: fix invalid LLVM IR for mixed interface/pointer comparison sync: align Cond with stdlib to fix interface nil comparisons Dec 19, 2025
@xushiwei xushiwei merged commit 84c9a7d into goplus:main Dec 21, 2025
41 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.

Compiler error: Invalid LLVM IR instruction for nil pointer comparison with interface

2 participants