From patchwork Wed Mar 30 19:27:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Noah Goldstein X-Patchwork-Id: 1611338 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=m6joWX4l; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KTGfg451bz9sCq for ; Thu, 31 Mar 2022 06:27:39 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 68AFE388883A for ; Wed, 30 Mar 2022 19:27:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 68AFE388883A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1648668457; bh=GEhN1R/ZwobL9RIjGRt412xPaaJdMhWD9xIzLuimDJk=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=m6joWX4l3rDZw2vs3Mql9dVC7o5viPwEjCAn5ME7zZ1/wjtqDD8M2FYnaMFzLkqvV NdZDf3Tz0LPFfsx/TSDkqR/19SZ/pzfMRkc1q4g9XYKtvlqEnDbXBThfQPpqPI1gWq PiOQGOhcDF4U657sMppubDJpK/d9sARWfyswjtJ4= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-io1-xd2c.google.com (mail-io1-xd2c.google.com [IPv6:2607:f8b0:4864:20::d2c]) by sourceware.org (Postfix) with ESMTPS id AC3B7385DC31 for ; Wed, 30 Mar 2022 19:27:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AC3B7385DC31 Received: by mail-io1-xd2c.google.com with SMTP id q11so25981836iod.6 for ; Wed, 30 Mar 2022 12:27:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GEhN1R/ZwobL9RIjGRt412xPaaJdMhWD9xIzLuimDJk=; b=rd0e3KFUtbRtxCrivaedAxH140chtBrG5vM8L6RTCzUh+nFcvxtyCGsqsIcgmstalB Ktto8nZKJvdqeK+7oWv39YcteaobyrK2c/4TWZFpGdUEPHYeL/x1nr12jKsO/RvZfZwO v0Pd9Ec9pmfOK8hu6QzdF5op5B4pDcHxaoGBwAc3tVvOGnTdR5RMqWGOZNsZvW7OQ6YQ kseNGEWr5DTFnCJCOK4v4v3lW+yzsLKN7TiwSuNxjnoL/vnF1gdUxCcwM8JQ2ed6+8us yk3Xc5qSJDFq1F4USei+oAyBYVnw0+h2ZiVbdAUtMcYE8xU/8FyQzlwzYTPpqh8Wxdsg rRFw== X-Gm-Message-State: AOAM5317rbc6atoKVSYA30QrKFEMwUCybJPZmCD4Ex4ZM3X4Rm9KGoho /ZisrB1BT9XxvFbxw7g1Oyo1ddpERyU= X-Google-Smtp-Source: ABdhPJyvHXkqaGFSWe5ja/kwyeFdHiNExa0gF9Jnu/4j0+PYfb58rJaS80rJResJpGECwQmEspqykg== X-Received: by 2002:a5e:8a07:0:b0:64c:8b33:6d19 with SMTP id d7-20020a5e8a07000000b0064c8b336d19mr6011162iok.170.1648668441561; Wed, 30 Mar 2022 12:27:21 -0700 (PDT) Received: from localhost.localdomain (node-17-161.flex.volo.net. [76.191.17.161]) by smtp.googlemail.com with ESMTPSA id j13-20020a056e02014d00b002c98acb8d32sm7907768ilr.45.2022.03.30.12.27.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 12:27:21 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v3] Add .clang-format style file Date: Wed, 30 Mar 2022 14:27:14 -0500 Message-Id: <20220330192714.3177346-1-goldstein.w.n@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220328191254.913833-1-goldstein.w.n@gmail.com> References: <20220328191254.913833-1-goldstein.w.n@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Noah Goldstein via Libc-alpha From: Noah Goldstein Reply-To: Noah Goldstein Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" Went with version >= 11.0 since it covers most of the major features and should be pretty universally accessibly. There are some issues: 1. indention of preprocessor directives: Unfortunately there doesn't appear to be a switch for a seperate 'IndentWidth' for preprocessor directives vs. normal code so we are stuck either not indenting the directives or over-indenting them. i.e: Desired: ``` #ifndef A # define B #endif ``` Options: ``` #ifndef A # define B /* Two spaces instead of one. */ #endif #ifndef C #define D /* No spaces. */ #endif ``` Chose to over-indent as it generally seems easier to script halving all pre-processor indentations than counting the nested depth and indenting from scratch. 2. concatenation of lines missing semi-colons: Throughout glibc there are macros used to setup aliasing that are outside of functions and don't end in semi-colons i.e: ``` libc_hidden_def (__pthread_self) weak_alias (__pthread_self, pthread_self) ``` clang-format reformats lines like these to: ``` libc_hidden_def (__pthread_self) weak_alias (__pthread_self, pthread_self) ``` which is generally undesirable. Other than those two big concerns there are certainly some questions diffs but for the most part it creates a easy to read and consistent style. Reviewed-by: Fangrui Song --- .clang-format | 175 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000000..fcb344ef70 --- /dev/null +++ b/.clang-format @@ -0,0 +1,175 @@ +# clang-format file for GLIBC +# Copyright (C) 2022 Free Software Foundation, Inc. +# This file is part of the GNU C Library. +# +# The GNU C Library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# The GNU C Library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with the GNU C Library; if not, see +# . +# +# Requires clang-format version >= 11.0 +# +# For more information, see: +# +# Documentation/process/clang-format.rst +# https://clang.llvm.org/docs/ClangFormat.html +# https://clang.llvm.org/docs/ClangFormatStyleOptions.html +# +# There are some known cases that this doesn't produce the desired +# style (i.e Preprocessor Directives are over-indented and not +# auto-commented). As a result, this is meant to be a utility to make +# formatting easier, not a definitive standard. +# +# To format the current git diff inplace (-i) the follow command can +# be used: +# $> git diff -U0 --no-color HEAD^ | clang-format-diff -i -p1 +# +# To just view the diff clang-format would generate: +# $> git diff -U0 --no-color HEAD^ | clang-format-diff -p1 +# +# NB: clang-format-diff, along with other clang-format related tools, +# can be found at: /path/to/llvm-project/clang/tools/clang-format/ +# +# +--- +# BasedOnStyle: GNU +AccessModifierOffset: -2 +AlignAfterOpenBracket: Align +AlignConsecutiveMacros: false +AlignConsecutiveAssignments: false +AlignConsecutiveBitFields: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Right +AlignOperands: true +AlignTrailingComments: true +AllowAllArgumentsOnNextLine: true +AllowAllConstructorInitializersOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortEnumsOnASingleLine: true +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortLambdasOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: All +AlwaysBreakAfterReturnType: AllDefinitions +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: MultiLine +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterCaseLabel: true + AfterClass: true + AfterControlStatement: true + AfterEnum: true + AfterFunction: true + AfterNamespace: true + AfterStruct: true + AfterUnion: true + AfterExternBlock: true + BeforeCatch: true + BeforeElse: true + BeforeWhile: true + IndentBraces: true + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: All +BreakBeforeBraces: GNU +BreakBeforeInheritanceComma: false +BreakInheritanceList: BeforeColon +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeColon +BreakStringLiterals: true +ColumnLimit: 79 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: false +DeriveLineEnding: true +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: false +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + - Regex: '.*' + Priority: 1 +IncludeIsMainRegex: '(Test)?$' +IndentCaseLabels: false +IndentCaseBlocks: false +IndentGotoLabels: true +IndentWidth: 2 +IndentPPDirectives: AfterHash +IndentExternBlock: AfterExternBlock +IndentWrappedFunctionNames: false +InsertTrailingCommas: None +KeepEmptyLinesAtTheStartOfBlocks: true +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Right +ReflowComments: true +SortIncludes: false +SortUsingDeclarations: true +SpaceAfterCStyleCast: true +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: Always +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInConditionalStatement: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +SpaceBeforeSquareBrackets: false +Standard: Cpp03 +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 8 +UseTab: Never +ForEachMacros: + - 'FOR_EACH_IMPL' + - 'list_for_each' + - 'list_for_each_prev' + - 'list_for_each_prev_safe' +...