Skip to content

[wip] Add builtin debugtrap target verification script#1740

Draft
luoliwoshang wants to merge 3 commits intogoplus:mainfrom
luoliwoshang:codex/verify-builtin-debugtrap-pr
Draft

[wip] Add builtin debugtrap target verification script#1740
luoliwoshang wants to merge 3 commits intogoplus:mainfrom
luoliwoshang:codex/verify-builtin-debugtrap-pr

Conversation

@luoliwoshang
Copy link
Copy Markdown
Member

Summary

  • add a minimal __builtin_debugtrap() verification script that walks targets/*.json
  • resolve inherits so each target is checked against its effective codegen configuration
  • keep overlay/base targets in the report and mark them as SKIP with an explicit reason
  • delete workflow YAML files in this branch so this sync-only draft PR does not consume CI

Verification

  • bash _demo/embed/targetsbuild/verify_builtin_debugtrap.sh esp32 nrf51-s110v8 atmega328p
  • bash _demo/embed/targetsbuild/verify_builtin_debugtrap.sh

Notes

  • This PR is intentionally draft and workflow-light because it is only for syncing with teammates.

@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 introduces a new verification script aimed at ensuring the consistent and correct compilation of the __builtin_debugtrap() intrinsic across the project's diverse set of hardware targets. The script intelligently resolves target inheritance to apply accurate compilation flags and provides a detailed report on the intrinsic's behavior in LLVM IR and assembly. This PR is currently a draft, focused on internal synchronization, and has temporarily disabled CI workflows to streamline the process.

Highlights

  • Debugtrap Verification Script: Introduced a new bash script (verify_builtin_debugtrap.sh) to systematically compile __builtin_debugtrap() for all defined targets and verify its behavior in both LLVM IR and generated assembly.
  • Target Configuration Resolution: Implemented logic within the verification script to parse targets/*.json files and resolve inherits properties, ensuring each target is checked against its fully effective codegen configuration (llvm-target, cpu, features).
  • Overlay/Base Target Handling: The script now explicitly identifies and marks overlay or base targets (those without an effective llvm-target after inheritance resolution) as SKIP in the verification report, providing a clear reason for their exclusion from compilation checks.
  • Temporary CI Streamlining: Workflow YAML files were temporarily removed in this draft pull request to prevent unnecessary CI consumption, as it is intended for syncing purposes.

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

Ignored Files
  • Ignored by pattern: .github/workflows/** (10)
    • .github/workflows/build-cache.yml
    • .github/workflows/doc-link-checker.yml
    • .github/workflows/doc.yml
    • .github/workflows/fmt.yml
    • .github/workflows/go.yml
    • .github/workflows/llgo.yml
    • .github/workflows/release-build.yml
    • .github/workflows/stdlib-coverage.yml
    • .github/workflows/targets.yml
    • .github/workflows/verify-builtin-debugtrap.yml
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 a verification script for __builtin_debugtrap() across various targets. The script is well-designed, leveraging a mix of Bash and an embedded Python script for handling target configurations. My review highlights a few opportunities to enhance the script's portability and maintainability. Specifically, I've pointed out a hardcoded path that limits portability, an unnecessary directory change that could affect robustness, and some code duplication that can be refactored. These changes will make the script more robust and easier to maintain.


SYS_CLANG="${CLANG:-clang}"
ESP_CLANG_DEFAULT="${HOME}/Library/Caches/llgo/crosscompile/esp-clang-19.1.2_20250905-3/bin/clang"
ESP_CLANG="${ESP_CLANG:-${ESP_CLANG_DEFAULT}}"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The use of ESP_CLANG_DEFAULT makes the script non-portable due to its hardcoded macOS path on line 26. It's better to default to esp-clang and let it be found in the PATH, which is more robust and consistent with how SYS_CLANG is handled. Please remove line 26 and apply the suggested change to this line.

Suggested change
ESP_CLANG="${ESP_CLANG:-${ESP_CLANG_DEFAULT}}"
ESP_CLANG="${ESP_CLANG:-esp-clang}"

print("\t".join([name, llvm_target, cpu, features]))
PY

cd "${REPO_ROOT}"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Changing the current directory with cd inside a script can make it more fragile and harder to reason about. Since the script appears to use absolute paths for all significant file operations, this cd command is unnecessary. Removing it will improve the script's robustness.

Comment on lines +143 to +170
if [[ -n "${cpu}" ]]; then
if [[ "${llvm_target}" == avr* ]]; then
asm_flags=(-mmcu="${cpu}" "${asm_flags[@]}")
ir_flags=(-mmcu="${cpu}" "${ir_flags[@]}")
else
asm_flags=(-mcpu="${cpu}" "${asm_flags[@]}")
ir_flags=(-mcpu="${cpu}" "${ir_flags[@]}")
fi
fi

case "${llvm_target}" in
avr*)
asm_flags=(-mdouble=64 "${asm_flags[@]}")
ir_flags=(-mdouble=64 "${ir_flags[@]}")
;;
riscv32-esp-elf)
asm_flags=(-march=rv32imc -fforce-enable-int128 "${asm_flags[@]}")
ir_flags=(-march=rv32imc -fforce-enable-int128 "${ir_flags[@]}")
;;
riscv32-*)
asm_flags=(-march=rv32imac -fforce-enable-int128 "${asm_flags[@]}")
ir_flags=(-march=rv32imac -fforce-enable-int128 "${ir_flags[@]}")
;;
riscv64-*)
asm_flags=(-march=rv64gc "${asm_flags[@]}")
ir_flags=(-march=rv64gc "${ir_flags[@]}")
;;
esac
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The logic for adding compiler flags is duplicated for asm_flags and ir_flags throughout this block. This can be simplified and made more maintainable by using a helper function to add flags to both arrays at once.

For example, you could define a function at the top of the script:

add_flags() {
    asm_flags= ("$@" "${asm_flags[@]}")
    ir_flags= ("$@" "${ir_flags[@]}")
}

And then use it within this block to reduce duplication, like so:

if [[ -n "${cpu}" ]]; then
    if [[ "${llvm_target}" == avr* ]]; then
        add_flags "-mmcu=${cpu}"
    else
        add_flags "-mcpu=${cpu}"
    fi
fi

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.

1 participant