Colin Cross | d00350c | 2017-11-17 10:55:38 -0800 | [diff] [blame] | 1 | // Copyright 2017 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 15 | package config |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 16 | |
| 17 | import ( |
| 18 | "sort" |
| 19 | "strings" |
Colin Cross | c8bed31 | 2021-07-14 17:56:21 -0700 | [diff] [blame] | 20 | |
| 21 | "android/soong/android" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 22 | ) |
| 23 | |
| 24 | // Cflags that should be filtered out when compiling with clang |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 25 | var ClangUnknownCflags = sorted([]string{ |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 26 | "-finline-functions", |
| 27 | "-finline-limit=64", |
| 28 | "-fno-canonical-system-headers", |
Dan Willemsen | 3bf6b47 | 2015-09-11 17:41:10 -0700 | [diff] [blame] | 29 | "-Wno-clobbered", |
| 30 | "-fno-devirtualize", |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 31 | "-fno-tree-sra", |
Colin Cross | a360e8b | 2015-03-16 16:22:28 -0700 | [diff] [blame] | 32 | "-fprefetch-loop-arrays", |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 33 | "-funswitch-loops", |
| 34 | "-Wmaybe-uninitialized", |
Dan Willemsen | 3bf6b47 | 2015-09-11 17:41:10 -0700 | [diff] [blame] | 35 | "-Wno-error=clobbered", |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 36 | "-Wno-error=maybe-uninitialized", |
Chih-Hung Hsieh | 3ede294 | 2018-01-10 14:30:44 -0800 | [diff] [blame] | 37 | "-Wno-extended-offsetof", |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 38 | "-Wno-free-nonheap-object", |
| 39 | "-Wno-literal-suffix", |
| 40 | "-Wno-maybe-uninitialized", |
| 41 | "-Wno-old-style-declaration", |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 42 | "-Wno-unused-local-typedefs", |
Dan Willemsen | e654045 | 2015-10-20 15:21:33 -0700 | [diff] [blame] | 43 | "-fdiagnostics-color", |
Yabin Cui | 8ec05ff | 2020-04-10 13:36:41 -0700 | [diff] [blame] | 44 | // http://b/153759688 |
| 45 | "-fuse-init-array", |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 46 | |
Elliott Hughes | da3a071 | 2020-03-06 16:55:28 -0800 | [diff] [blame] | 47 | // arm + arm64 |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 48 | "-fgcse-after-reload", |
| 49 | "-frerun-cse-after-loop", |
| 50 | "-frename-registers", |
| 51 | "-fno-strict-volatile-bitfields", |
| 52 | |
| 53 | // arm + arm64 |
| 54 | "-fno-align-jumps", |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 55 | |
| 56 | // arm |
| 57 | "-mthumb-interwork", |
| 58 | "-fno-builtin-sin", |
| 59 | "-fno-caller-saves", |
| 60 | "-fno-early-inlining", |
| 61 | "-fno-move-loop-invariants", |
| 62 | "-fno-partial-inlining", |
| 63 | "-fno-tree-copy-prop", |
| 64 | "-fno-tree-loop-optimize", |
| 65 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 66 | // x86 + x86_64 |
| 67 | "-finline-limit=300", |
| 68 | "-fno-inline-functions-called-once", |
| 69 | "-mfpmath=sse", |
| 70 | "-mbionic", |
Dan Willemsen | 01f388c | 2017-11-30 13:31:26 -0800 | [diff] [blame] | 71 | |
| 72 | // windows |
| 73 | "--enable-stdcall-fixup", |
Dan Willemsen | e654045 | 2015-10-20 15:21:33 -0700 | [diff] [blame] | 74 | }) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 75 | |
Chih-Hung Hsieh | 1017b37 | 2018-12-06 12:12:41 -0800 | [diff] [blame] | 76 | var ClangLibToolingUnknownCflags = sorted([]string{}) |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 77 | |
Dan Albert | d12afec | 2020-08-14 16:53:21 -0700 | [diff] [blame] | 78 | // List of tidy checks that should be disabled globally. When the compiler is |
| 79 | // updated, some checks enabled by this module may be disabled if they have |
| 80 | // become more strict, or if they are a new match for a wildcard group like |
| 81 | // `modernize-*`. |
Stephen Hines | 2210e72 | 2020-07-15 11:11:57 -0700 | [diff] [blame] | 82 | var ClangTidyDisableChecks = []string{ |
| 83 | "misc-no-recursion", |
Yabin Cui | db7dda8 | 2020-11-30 15:47:45 -0800 | [diff] [blame] | 84 | "readability-function-cognitive-complexity", // http://b/175055536 |
Stephen Hines | 2210e72 | 2020-07-15 11:11:57 -0700 | [diff] [blame] | 85 | } |
Dan Albert | d12afec | 2020-08-14 16:53:21 -0700 | [diff] [blame] | 86 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 87 | func ClangFilterUnknownCflags(cflags []string) []string { |
Dan Albert | d12afec | 2020-08-14 16:53:21 -0700 | [diff] [blame] | 88 | result, _ := android.FilterList(cflags, ClangUnknownCflags) |
| 89 | return result |
| 90 | } |
| 91 | |
| 92 | func clangTidyNegateChecks(checks []string) []string { |
| 93 | ret := make([]string, 0, len(checks)) |
| 94 | for _, c := range checks { |
| 95 | if strings.HasPrefix(c, "-") { |
| 96 | ret = append(ret, c) |
| 97 | } else { |
| 98 | ret = append(ret, "-"+c) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 99 | } |
| 100 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 101 | return ret |
| 102 | } |
| 103 | |
Dan Albert | d12afec | 2020-08-14 16:53:21 -0700 | [diff] [blame] | 104 | func ClangRewriteTidyChecks(checks []string) []string { |
| 105 | checks = append(checks, clangTidyNegateChecks(ClangTidyDisableChecks)...) |
| 106 | // clang-tidy does not allow later arguments to override earlier arguments, |
| 107 | // so if we just disabled an argument that was explicitly enabled we must |
| 108 | // remove the enabling argument from the list. |
| 109 | result, _ := android.FilterList(checks, ClangTidyDisableChecks) |
| 110 | return result |
| 111 | } |
Chih-Hung Hsieh | 02b4da5 | 2018-04-03 11:33:34 -0700 | [diff] [blame] | 112 | |
Yo Chiang | 8aa4e3f | 2020-11-19 16:30:49 +0800 | [diff] [blame] | 113 | func ClangLibToolingFilterUnknownCflags(libToolingFlags []string) []string { |
| 114 | return android.RemoveListFromList(libToolingFlags, ClangLibToolingUnknownCflags) |
| 115 | } |
| 116 | |
Dan Willemsen | e654045 | 2015-10-20 15:21:33 -0700 | [diff] [blame] | 117 | func sorted(list []string) []string { |
| 118 | sort.Strings(list) |
| 119 | return list |
| 120 | } |