125 Commits

Author SHA1 Message Date
Rahul Joshi
f44c18a97d
[NFC][CodingStandard] Fix text style for C++ keywords (#128932)
Fix C++ keywords in Restrict Visibility section to use `` (inline
literal) markup to be consistent with the rest of the doc.
2025-03-03 10:18:12 -08:00
Rahul Joshi
5bddadf783
[CodingStandard] Rework anonymous namespace section to cover visibility more broadly (#126775)
- Rename anonymous namespace section and rework it to
  cover visibility more broadly.
- Add language suggesting restricting visibility as much as
  possible, using various C++ facilities.

---------

Co-authored-by: Aaron Ballman <aaron@aaronballman.com>
2025-02-24 08:24:54 -08:00
Rahul Joshi
e2c3d16282
[NFC] Eliminate need of Emacs tag and file name in file header (#118553)
- Simplify file header to not require file name and C++ Emacs tag.

See
https://discourse.llvm.org/t/is-c-in-header-files-still-relevant/83124/1
2024-12-04 08:57:27 -08:00
Rahul Joshi
84b99b4b1e
[NFC][CodingStandard] Extend if-else brace example with else-if (#112193)
Extend example to document that single statement `else if` needs a brace
as well if the associated `if` needs a brace.
2024-10-14 07:20:39 -07:00
Rahul Joshi
900ea21ffb
[NFC][CodingStandard] Add additional example for if-else brace rule (#111733)
Add example to document that single statement `else` needs a brace if
the associated `if` needs a brace.
2024-10-11 05:25:12 -07:00
Richard Dzenis
3985eda8ee
[docs] Update links for C++ compiler supported features in CodingStandards (#81587) 2024-02-13 21:19:49 +02:00
James Henderson
18bb972561 [doc] Add casting style preference to coding standards
Differential Revision: https://reviews.llvm.org/D151187
2023-11-09 11:01:51 +00:00
Jakub Kuderski
00c8da6159
[docs] Fix suggested darker command in coding standards (#69860)
Do not attempt to format deleted files.
2023-10-21 21:33:40 -04:00
Joel E. Denny
15a1d288ba
[docs] Add more details about Python formatting (#66141)
Describe the darker utility. Make it clear that black/darker's default
rules should be used. Add some examples.

See ongoing discussion at
<https://discourse.llvm.org/t/rfc-document-and-standardize-python-code-style/68257>.
2023-09-14 12:00:19 -04:00
Felipe de Azevedo Piovezan
f8a1d021ed [Coding style] Fix incorrect link syntax 2023-06-17 08:26:05 -04:00
Prajwal S N
cca42ffd16 [docs] Fix link for static constructors article
It was previously present in the inline code block and did not work as a
hyperlink.

Reviewed By: yassingh

Differential Revision: https://reviews.llvm.org/D153061
2023-06-17 15:35:07 +05:30
Kazu Hirata
a82f2b2db3 Fix typos in documentation 2023-05-28 13:13:12 -07:00
Tobias Hieta
83768e6610
[docs] Add Python coding standard to documentation
As discussed on the forums:

https://discourse.llvm.org/t/rfc-document-and-standardize-python-code-style/

Reviewed By: jhenderson, JDevlieghere

Differential Revision: https://reviews.llvm.org/D143852
2023-05-15 10:58:51 +02:00
Nikita Popov
c8ec751d88 Revert "CodingStandards: restrict CamelCase variable names guideline to llvm/clang/clang-tools-extra/polly/bolt"
This reverts commit ee9ccb11036ac46ff9b9f3fa2d459d9d2bce5509.

See https://reviews.llvm.org/D140585#4019417 and following.
Multiple people requested a revert of this change pending further
discussion.
2023-01-06 09:44:27 +01:00
Aaron Ballman
b4993bea29 Remove documentation about the Go bindings
We removed the Go bindings in https://reviews.llvm.org/D135436 but
missed documentation that talks about the bindings.
2023-01-05 14:49:28 -05:00
Fangrui Song
ee9ccb1103 CodingStandards: restrict CamelCase variable names guideline to llvm/clang/clang-tools-extra/polly/bolt
See https://discourse.llvm.org/t/top-level-clang-tidy-options-and-variablename-suggestion-on-codingstandards/58783 ,
the CamelCase variable names guideline does not reflect the truth:
flang, libc, libclc, libcxx, libcxxabi, libunwind, lld, mlir, openmp,
and pstl use camelCase. lldb uses snake_case.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D140585
2022-12-28 12:48:13 -08:00
Aaron Ballman
cda093681b Update coding standards for constexpr if statements; NFC
We currently suggest that users not use an else clause after a return
statement in a prior if branch. e.g.,

if (foo)
  return 1;
else // Should remove this else clause
  return 10;

however, this suggestion is incorrect for a constexpr if statement
because one of the two branches will be a discarded statement and thus
can impact template instantiation behavior. This updates the coding
standard to make it clear that it's okay to have a return after an else
in a constexpr if statement.

I think this is an NFC change to the intent of the rule, which is why
I've not started an RFC for the changes.

Differential Revision: https://reviews.llvm.org/D132232
2022-08-19 15:53:19 -04:00
Tobias Hieta
b1356504e6
[LLVM] Update C++ standard to 17
Also make the soft toolchain requirements hard. This allows
us to use C++17 features in LLVM now.

If we find patterns with C++17 that improve readability
it should be recommended in the coding standards.

Reviewed By: jhenderson, cor3ntin, MaskRay

Differential Revision: https://reviews.llvm.org/D130689
2022-08-06 09:42:10 +02:00
owenca
3d56131bf6 [Docs] Clarify the guideline on omitting braces
While working on a clang-format option RemoveBracesLLVM that removes
braces following the guideline, we were unsure about what to do with
the braces of do-while loops. The ratio of using to omitting the
braces is about 4:1 in the llvm-project source, so it will help to
add an example to the guideline.

Also cleans up the original examples including making the nested if
example more targeted on avoiding potential dangling else situations.

Differential Revision: https://reviews.llvm.org/D126512
2022-05-31 23:35:30 -07:00
Brian Tracy
87a55137e2 Fix "the the" typo in documentation and user facing strings
There are many more instances of this pattern, but I chose to limit this change to .rst files (docs), anything in libcxx/include, and string literals. These have the highest chance of being seen by end users.

Reviewed By: #libc, Mordante, martong, ldionne

Differential Revision: https://reviews.llvm.org/D124708
2022-05-05 17:52:08 +02:00
Carlos Galvez
d40130199f [doc] Fix namespace comment style in Coding Guidelines
The Coding Guidelines specify that the ending brace of a
namespace shall have a comment like:

}  // end namespace clang

However the majority of the code uses a different style:

}  // namespace clang

Indeed:

$ git grep '// end' | wc -l
6724
$ git grep '// namespace' | wc -l
14348

Besides, this is the style enforced automatically by clang-format,
via the FixNamespaceComments option.

Having inconsistencies between the Coding Guidelines and the
code/tooling creates confusion, can lead to bikeshedding during
reviews and overall delays merging code. Therefore, update the
guidelines to reflect current usage. Updating legacy code to the
new standard should be done in a separate patch, if wanted.

Reviewed By: jyknight

Differential Revision: https://reviews.llvm.org/D115115
2021-12-07 13:36:25 +00:00
Shao-Ce SUN
0c660256eb [NFC] Trim trailing whitespace in *.rst 2021-11-15 09:17:08 +08:00
Frederic Cambus
9635b2951d [docs] Fix broken link rendering in the LLVM Coding Standards. 2021-10-21 11:12:33 +02:00
Hafiz Abid Qadeer
43def795aa Update references to 'master' branch.
This commit replace 'master' with 'main' in llvm/docs.

Reviewed By: sammccall, kristof.beyls

Differential Revision: https://reviews.llvm.org/D92831
2020-12-21 19:10:34 +00:00
serge-sans-paille
9218ff50f9 llvmbuildectomy - replace llvm-build by plain cmake
No longer rely on an external tool to build the llvm component layout.

Instead, leverage the existing `add_llvm_componentlibrary` cmake function and
introduce `add_llvm_component_group` to accurately describe component behavior.

These function store extra properties in the created targets. These properties
are processed once all components are defined to resolve library dependencies
and produce the header expected by llvm-config.

Differential Revision: https://reviews.llvm.org/D90848
2020-11-13 10:35:24 +01:00
Mircea Trofin
abb8128237 [doc] Describe the header guard style
clang-tidy's llvm-header-guard rule references the LLVM style - where it's
missing.

Differential Revision: https://reviews.llvm.org/D84989
2020-07-30 16:08:07 -07:00
Mehdi Amini
140c296ef5 Clarify a bit the guideline on omitting braces, including more examples (NFC)
Like most readability rules, it isn't absolute and there is a matter of taste
to it. I think more recent part of the project may be more consistent in the
current application of the guideline. I suspect sources like
mlir/lib/Dialect/StandardOps/IR/Ops.cpp may be examples of this at the moment.

Differential Revision: https://reviews.llvm.org/D82594
2020-07-15 21:11:30 +00:00
Roman Lebedev
29a9dd5bfe
[Docs] CodingStandards: for_each is discouraged
Summary:
As per disscussion in D83351, using `for_each` is potentially confusing,
at least in regards to inconsistent style (there's less than 100 `for_each`
usages in LLVM, but ~100.000 `for` range-based loops

Therefore, it should be avoided.

Reviewers: dblaikie, nickdesaulniers

Reviewed By: dblaikie, nickdesaulniers

Subscribers: hubert.reinterpretcast, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D83431
2020-07-09 23:10:42 +03:00
Erich Keane
fad9cba8f5 [Docs] Add missing space, requested on c08ea07 2020-06-15 16:20:32 -07:00
Erich Keane
c08ea07716 Add to the Coding Standard our that single-line bodies omit braces
This is a rule that seems to have been enforced for the better part of
the decade, so we should document it for new contributors.

Differential Revision: https://reviews.llvm.org/D80947
2020-06-11 12:46:15 -07:00
Jan Korous
5f5d972d83 [docs] Fix self-contradictory description of llvm_unreachable
Just two paragraphs above it says:
"If the compiler does not support this [skipping code generation for a particular branch], it will fall back
to the "abort" implementation."

And that actually correctly describes llvm_unreachable implementation.

Differential Revision: https://reviews.llvm.org/D81130
2020-06-04 11:15:20 -07:00
James Henderson
6aacdd6083 [docs] Document coding standard for error and warning messages
In particular, these messages should start with a lower-case letter and
should have no trailing period at the end of the last sentence.

See http://lists.llvm.org/pipermail/llvm-dev/2020-March/140178.html for
context.

Reviewed by: aaron.ballman, hubert.reinterpretcast, rnk, dblaikie

Differential Revision: https://reviews.llvm.org/D76833
2020-03-31 12:41:17 +01:00
Aaron Ballman
4778e409de Clarify use of llvm_unreachable in the coding standard.
There has been some ongoing confusion regarding when to use `llvm_unreachable`
which this patch attempts to address. Specifically, the confusion has been
around whether `llvm_unreachable` is intended to mark only unreachable code
paths that the compiler cannot determine itself or to mark a code path which is
unconditionally a bug to reach. Based on email and IRC discussions, it sounds
like "unconditional bug to reach" is the consensus.
2020-03-26 08:08:23 -04:00
Reid Kleckner
236fcbc21a Add coding standard recommending use of qualifiers in cpp files
There is prior art for this in the code base itself, and a recent
example of this here: c45f8d49897f

This came up in discussion on this review where @maskray was going the
opposite direction:
  https://reviews.llvm.org/D68772

Given that there is disagreement, we should make a choice and document
it.

Thanks to John McCall for the precise wording.

Reviewed By: MaskRay, rjmccall

Differential Revision: https://reviews.llvm.org/D74515
2020-02-18 14:08:56 -08:00
Johannes Doerfert
b0279d62ac [CodingStandards] Add link to "Picking the Right Data Structure"
See https://reviews.llvm.org/D74340
2020-02-11 11:06:04 -06:00
Johannes Doerfert
5afd9fd916 [CodingStandards] Clarify C++ Standard Library usage
The existing wording leaves it unclear if C++ standard library data
structures should be preferred over custom LLVM ones, e.g., SmallVector,
even though common practice seems clear on the issue. This change makes
the wording more explicit and aligns it better with the code base.

Some motivating statistics:

```
ag SmallVector llvm/lib/ | wc
  8846   40306  901421
 ag 'std::vector' llvm/lib/ | wc
  2123    8990  214482

ag SmallVector clang/lib/ | wc
  3023   13824  281691
ag 'std::vector' clang/lib/ | wc
   719    2914   72817
```

Differential Revision: https://reviews.llvm.org/D74340
2020-02-10 20:30:00 -06:00
Kazuaki Ishizaki
f65d4aa960 [llvm] NFC: fix trivial typos in documents
Reviewers: hans, Jim

Reviewed By: Jim

Subscribers: jvesely, nhaehnle, mgorny, arphaman, bmahjour, kerbowa, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D73017
2020-01-22 11:32:51 +08:00
Dmitri Gribenko
161742a612 Make coding standards document more inclusive
Summary: Patch by Doug Gregor, Tres Popp, and Dmitri Gribenko.

Reviewers: chandlerc

Subscribers: hfinkel, bmcreusillet, arsenm, doug.gregor, mgrang, arphaman, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D69354
2019-11-21 13:37:17 +01:00
Chandler Carruth
bf2975eca0 Remove a no longer accurate sentence from the coding standards.
(And test my commit access. We're working on larger changes here.)
2019-10-23 11:40:45 -07:00
JF Bastien
b13c8ca9eb Move to C++14
Summary:
I just bumped the minimum compiler versions to support C++14 in D66188.

Following [our process](http://llvm.org/docs/DeveloperPolicy.html#toolchain) and [our previous agreement](http://lists.llvm.org/pipermail/llvm-dev/2019-January/129452.html), I'm now officially bumping the C++ version to 14 and updating the documentation.

Subscribers: mgorny, jkorous, dexonsmith, llvm-commits, chandlerc, thakis, EricWF, jyknight, lhames, JDevlieghere

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D66195

llvm-svn: 368887
2019-08-14 17:39:07 +00:00
Chandler Carruth
8617e5bd27 Update the coding standards with the new file header.
llvm-svn: 351652
2019-01-19 11:53:58 +00:00
Paul Robinson
a6a19c00d5 Document how to comment an actual parameter.
Differential Revision: https://reviews.llvm.org/D54446

llvm-svn: 346861
2018-11-14 13:43:19 +00:00
Chandler Carruth
9ae926b973 [IR] Replace isa<TerminatorInst> with isTerminator().
This is a bit awkward in a handful of places where we didn't even have
an instruction and now we have to see if we can build one. But on the
whole, this seems like a win and at worst a reasonable cost for removing
`TerminatorInst`.

All of this is part of the removal of `TerminatorInst` from the
`Instruction` type hierarchy.

llvm-svn: 340701
2018-08-26 09:51:22 +00:00
Aaron Ballman
cd27070a05 Update the coding standards and developer policy documentation surrounding whitespace.
Clarify that you should not introduce trailing whitespace when making a commit and that you should not remove trailing whitespace that's unrelated to code you are changing or are about to change. Then clarified the developer policy around what is considered an obvious whitespace commit.

llvm-svn: 339455
2018-08-10 17:26:07 +00:00
JF Bastien
86e128362b [NFC] update coding standard links to HTTPS
Update one link which redirected, and remove an Amazon ref.

llvm-svn: 332735
2018-05-18 16:44:13 +00:00
Mandeep Singh Grang
434d4c0b88 [docs] Add a note on non-deterministic sorting order of equal elements
Reviewers: RKSimon, t.p.northover, dexonsmith

Reviewed By: RKSimon

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D45831

llvm-svn: 330773
2018-04-24 21:25:57 +00:00
Alexander Kornienko
94d9c391b6 Minor fix in docs.
llvm-svn: 329277
2018-04-05 12:48:22 +00:00
David Blaikie
47ff8f457f Coding Standards: Document library layering requirements & header isolation.
(I suppose these two pieces could be separated - but seemed related
enough)

As discussed on llvm-dev, this documents the general expectation of how
library layering should be handled. There are a few existing cases where
these constraints are not met, but as with most style guide things -
this is forward looking and provides guidance when cleaning up existing
code, it doesn't immediately require that all previous code be cleaned
up to match. (see: naming conventions, etc)

Differential Revision: https://reviews.llvm.org/D42771

llvm-svn: 324004
2018-02-01 21:03:35 +00:00
Hans Wennborg
08b34a017a Update some code.google.com links
llvm-svn: 318115
2017-11-13 23:47:58 +00:00
Mandeep Singh Grang
d147f52252 [docs] Add a note on iteration of unordered containers to coding standards
Summary: Beware of non-determinism due to ordering of pointers

Reviewers: dblaikie, dexonsmith

Reviewed By: dblaikie

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D37525

llvm-svn: 312667
2017-09-06 20:19:10 +00:00