Skip to content

Conversation

@JDevlieghere
Copy link
Member

This is an experiment to encode the LLVM Coding Standards 1 as instructions for the Copilot reviewer on GitHub. Ideally, this will catch common issues automatically and reduce the review burden.

Adding Copilot as a reviewer is entirely opt-in. Initially, I will add it as a reviewer to test this. If the experiment is successful, we can explore how to integrate this into other parts of LLVM.

This is an experiment to encode the LLVM Coding Standards [1] as
instructions for the Copilot reviewer on GitHub. Ideally, this will
catch common issues automatically and reduce the review burden.

Adding Copilot as a reviewer is entirely opt-in. Initially, I will add
it as a reviewer to test this. If the experiment is successful, we can
explore how to integrate this into other parts of LLVM.

[1]: https://llvm.org/docs/CodingStandards.html
Copy link
Collaborator

@kbeyls kbeyls left a comment

Choose a reason for hiding this comment

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

Thank you for experimenting with this!
I think it's great to experiment with using LLM tools in ways that help us reduce our limited reviewer bandwidth problem, rather than making it worse!

I left a bunch of nit-picky observations.
But I think this is good to commit as is too, if you think none of those nit-picks make sense.

## Comments & Documentation

- Each source file should include the standard LLVM file header.
- Header files must have proper header guards.
Copy link
Collaborator

Choose a reason for hiding this comment

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

It might be useful to add something here to cover "Aim to describe what the code is trying to do and why, not how it does it at a micro level" from our CodingStandards. Basically, I'd like to say "make sure that non-obvious code has comments explaining what it is aiming to do and why"

- Each source file should include the standard LLVM file header.
- Header files must have proper header guards.
- Non-trivial classes and public methods should have Doxygen documentation.
- Use `//` or `///` comments normally; avoid block comments unless necessary.
Copy link
Collaborator

Choose a reason for hiding this comment

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

By the point I got to this point (reading or Coding Standards document in parallel), I'm guessing you're leaving out everything that is checked/covered by clang-format. Is that correct? If so, maybe that's a "design decision" that would be good to document at least in the commit message?
Would it make sense to also have that in this instructions.md file at the top?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I want to leave all that up to clang-format. I'll include an explicit directive to ignore it.

- Write portable code; wrap non-portable code in interfaces.
- Do not use RTTI or exceptions.
- Prefer C++-style casts over C-style casts.
- Avoid static constructors or global objects with heavy initialization.
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit pick: our coding standard says "do not use static constructers" rather than "avoid ...". Not sure if it makes a difference to copilot....

- Do not use RTTI or exceptions.
- Prefer C++-style casts over C-style casts.
- Avoid static constructors or global objects with heavy initialization.
- Use `class` or `struct` consistently; `struct` only for all-public data.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I found this sentence a bit too cryptic for me too understand what was meant. Maybe that makes it too cryptic for copilot too?
My attempt to rewrite it to make it less cryptic:

  • For classes with only public members, use struct instead of class.
  • When then same class is declared or defined multiple times, make sure it's consistently done using either class or struct.

Copy link
Collaborator

Choose a reason for hiding this comment

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

(BTW, this is where I'm starting to suspect you might have used the help of an LLM to produce this ;) )

Copy link
Member Author

Choose a reason for hiding this comment

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

I absolutely did!

## General Guidelines

- Use `assert` liberally; prefer `llvm_unreachable` for unreachable states.
- Avoid `using namespace std;` in headers.
Copy link
Collaborator

Choose a reason for hiding this comment

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

s/"avoid"/"do not use"/


- Use `assert` liberally; prefer `llvm_unreachable` for unreachable states.
- Avoid `using namespace std;` in headers.
- Ensure at least one out-of-line virtual method per class with virtuals.
Copy link
Collaborator

Choose a reason for hiding this comment

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

s/virtuals./virtual methods./
(Not sure if that would be better. As a human, that reads better, but maybe the shorter form is better for copilot?)

- Methods in class definitions are already inline—don’t add `inline`.

## Microscopic Details

Copy link
Collaborator

Choose a reason for hiding this comment

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

Reading through the coding standard in parallel, maybe this section should also have:
"- Functions and variables should have the most restricted visibility possible."
?

@JDevlieghere
Copy link
Member Author

Thanks Kristof, really appreciate your input. I've addressed your remarks and updated some other places in the same spirit.

@JDevlieghere JDevlieghere merged commit 230e8b6 into llvm:main Oct 31, 2025
12 checks passed
@JDevlieghere JDevlieghere deleted the copilot-instructions-lldb branch October 31, 2025 15:56
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