Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
---
Language: Cpp
AccessModifierOffset: -1
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: true
AfterControlStatement: false
AfterEnum: true
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: true
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakConstructorInitializersBeforeComma: false
BreakStringLiterals: true
ColumnLimit: 150
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 2
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
IncludeBlocks: Preserve
IndentCaseLabels: true
IndentWidth: 2
IndentPPDirectives: AfterHash
IndentWrappedFunctionNames: true
NamespaceIndentation: None # Could consider Inner
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
ReflowComments: false
SpaceAfterCStyleCast: false
# SpaceAfterLogicalNot: false # No longer available in clang-format 6.0
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
# SpaceBeforeCpp11BracedList: true # No longer available in clang-format 6.0
# SpaceBeforeCtorInitializerColon: true # No longer available in clang-format 6.0
# SpaceBeforeInheritanceColon: true # No longer available in clang-format 6.0
SpaceBeforeParens: ControlStatements
# SpaceBeforeRangeBasedForLoopColon: true # No longer available in clang-format 6.0
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
SortIncludes: false
SortUsingDeclarations: true
Standard: c++17
TabWidth: 2
UseTab: Never
---
Language: JavaScript
BasedOnStyle: Mozilla
# Use 100 columns for JS.
ColumnLimit: 180
JavaScriptQuotes: Single
SpacesInContainerLiterals: false
...
85 changes: 85 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
---

# magic numbers are useful to layout stuff in Qt...
# -readability-magic-numbers and its alias cppcoreguidelines-avoid-magic-numbers

# `protected`: followed by `protected slots:` would trigger it
# -readability-redundant-access-specifiers,

# Problem with OS_ASSERT macro
# -cppcoreguidelines-pro-bounds-array-to-pointer-decay,

# We use raw pointers for Qt, since usually the memory is then owned by the parent
# -cppcoreguidelines-owning-memory

# Because of Google Tests
# -cppcoreguidelines-avoid-non-const-global-variables

# I don't think this really helps clarify the intent
# -readability-else-after-return
# -modernize-concat-nested-namespaces

# Aliases
# - cppcoreguidelines-avoid-c-arrays => modernize-avoid-c-arrays
# - cppcoreguidelines-non-private-member-variables-in-classes => misc-non-private-member-variables-in-classes
# - cppcoreguidelines-explicit-virtual-functions, hicpp-use-override => modernize-use-override
# - bugprone-narrowing-conversions => cppcoreguidelines-narrowing-conversions

# Annoying: some config options exist only in later versions...
# cppcoreguidelines-narrowing-conversions.WarnOnEquivalentBitWidth was added in clang-tidy 13, and that would allow avoiding uint->int narrowing conversions
# Instead I have to disable the entire check...

Checks: |
*,
-fuchsia-*,
-google-*,
-zircon-*,
-abseil-*,
-llvm*,
-altera*,
-modernize-use-trailing-return-type,
-cppcoreguidelines-avoid-magic-numbers,
-readability-magic-numbers,
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
-cppcoreguidelines-owning-memory,
-cppcoreguidelines-pro-bounds-constant-array-index,
-readability-redundant-access-specifiers,
-cppcoreguidelines-explicit-virtual-functions,
-readability-else-after-return,
-modernize-concat-nested-namespaces,
-hicpp-*,
-hicpp-avoid-goto,
hicpp-exception-baseclass,
hicpp-multiway-paths-covered,
hicpp-no-assembler,
hicpp-signed-bitwise,
-cppcoreguidelines-avoid-c-arrays,
-cppcoreguidelines-non-private-member-variables-in-classes,
-bugprone-narrowing-conversions,
-cppcoreguidelines-narrowing-conversions,
-readability-function-cognitive-complexity,
-cppcoreguidelines-avoid-non-const-global-variables,
-modernize-use-override,
-readability-uppercase-literal-suffix,
-readability-identifier-length,
-bugprone-easily-swappable-parameters,
-modernize-use-nodiscard,
-cert-err58-cpp,

WarningsAsErrors: '*'
HeaderFilterRegex: '*'
FormatStyle: 'file'
UseColor: 'true'
CheckOptions:
- key: modernize-use-override.AllowOverrideAndFinal
value: 'true'
- key: modernize-use-override.IgnoreDestructors
value: 'true'
- key: performance-for-range-copy.WarnOnAllAutoCopies
value: 'true'
- key: cppcoreguidelines-narrowing-conversions.WarnOnEquivalentBitWidth
value: 'false'
- key: readability-implicit-bool-conversion.AllowPointerConditions
value: 'true'
- key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
value: 'true'
82 changes: 74 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,50 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: deps
run: sudo apt install clang-format-9
run: sudo apt install clang-format-14

- name: lint
run: clang-format-9 -i main.cpp && git diff --exit-code
run: |
clang-format-14 -style=file -i main.cpp
# clang-format will auto correct files so prepare the diff and use this as artifact
git diff > clang_format.patch

# Delete if nothing otherwise exit 1 to indicate a failed job
if [ ! -s clang_format.patch ]
then
rm clang_format.patch
exit 0
else
echo "clang-format auto corrected files:"
git diff --name-only
echo -e "\nPlease correct these files. Patch is uploaded as an artifact for convenience."
exit 1
fi
# git diff --exit-code

- name: Upload clang-format patch as artifact
if: ${{ failure() }}
uses: actions/upload-artifact@v3
with:
name: constexpr-everything-clang_format.patch
path: clang_format.patch

build:
runs-on: ubuntu-20.04
name: Ubuntu Clang ${{ matrix.llvm-toolchain }}
strategy:
# fail-fast: Default is true, switch to false to allow one platform to fail and still run others
fail-fast: false
matrix:
llvm-toolchain: [9, 10, 11]
llvm-toolchain: [9, 10, 11, 12, 13, 14, 15]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: deps
shell: bash
run: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo add-apt-repository "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-${{ matrix.llvm-toolchain }} main"
Expand All @@ -40,9 +68,47 @@ jobs:
libclang-${{ matrix.llvm-toolchain }}-dev

- name: build
shell: bash
run: |
export LLVM_DIR=/usr/lib/llvm-${{ matrix.llvm-toolchain }}/lib/cmake/llvm
export Clang_DIR=/usr/lib/llvm-${{ matrix.llvm-toolchain }}/lib/cmake/clang
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Debug ..
cmake -DCMAKE_BUILD_TYPE=Debug -DLLVM_DIR:PATH=/usr/lib/llvm-${{ matrix.llvm-toolchain }}/lib/cmake/llvm \
-DClang_DIR:PATH=/usr/lib/llvm-${{ matrix.llvm-toolchain }}/lib/cmake/clang ..
cmake --build .

- name: Test the binary
working-directory: build/
shell: bash
run: |
./constexpr-everything -p . ../main.cpp

- name: Archive binary artifacts
uses: actions/upload-artifact@v3
with:
name: constexpr-everything-ubuntu-clang${{ matrix.llvm-toolchain }}
path: build/constexpr-everything

build-mac:
runs-on: macos-latest
name: MacOS Clang 15
steps:
- uses: actions/checkout@v3

- name: build
shell: bash
run: |
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE:STRING=Debug -DLLVM_DIR:PATH=$(brew --prefix llvm@15)/lib/cmake/llvm \
-DClang_DIR:PATH=$(brew --prefix llvm@15)/lib/cmake/clang ..
cmake --build .

- name: Test the binary
working-directory: build/
shell: bash
run: |
./constexpr-everything -p . ../main.cpp

- name: Archive binary artifacts
uses: actions/upload-artifact@v3
with:
name: constexpr-everything-mac
path: build/constexpr-everything
15 changes: 4 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.8)
project(constexpr-everything CXX)
project(constexpr-everything CXX C)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand Down Expand Up @@ -42,8 +42,8 @@ message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")

if((${LLVM_PACKAGE_VERSION} VERSION_LESS "9.0.0")
OR (${LLVM_PACKAGE_VERSION} VERSION_GREATER_EQUAL "12"))
message(FATAL_ERROR "Only LLVM 9 through 11 are supported.")
OR (${LLVM_PACKAGE_VERSION} VERSION_GREATER_EQUAL "16"))
message(FATAL_ERROR "Only LLVM 9 through 15 are supported.")
endif()

# The clang package doesn't appear to provide a version
Expand All @@ -65,11 +65,4 @@ target_link_libraries(${PROJECT_NAME} ${LIBRARY_LIST})

target_link_libraries(
${PROJECT_NAME}
LLVMTransformUtils
LLVMAnalysis
LLVMTarget
LLVMOption # Support
LLVMObject # BitReader, Core, Support
LLVMBitReader # Core, Support
LLVMCore # Support
LLVMSupport)
LLVM)
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for trimming this -- IIRC we had to specify all of these manually for a much earlier version of LLVM.

Loading