clang.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. package config
  15. import (
  16. "sort"
  17. "strings"
  18. )
  19. // Cflags that should be filtered out when compiling with clang
  20. var ClangUnknownCflags = sorted([]string{
  21. "-finline-functions",
  22. "-finline-limit=64",
  23. "-fno-canonical-system-headers",
  24. "-Wno-clobbered",
  25. "-fno-devirtualize",
  26. "-fno-tree-sra",
  27. "-fprefetch-loop-arrays",
  28. "-funswitch-loops",
  29. "-Werror=unused-but-set-parameter",
  30. "-Werror=unused-but-set-variable",
  31. "-Wmaybe-uninitialized",
  32. "-Wno-error=clobbered",
  33. "-Wno-error=maybe-uninitialized",
  34. "-Wno-error=unused-but-set-parameter",
  35. "-Wno-error=unused-but-set-variable",
  36. "-Wno-free-nonheap-object",
  37. "-Wno-literal-suffix",
  38. "-Wno-maybe-uninitialized",
  39. "-Wno-old-style-declaration",
  40. "-Wno-psabi",
  41. "-Wno-unused-but-set-parameter",
  42. "-Wno-unused-but-set-variable",
  43. "-Wno-unused-local-typedefs",
  44. "-Wunused-but-set-parameter",
  45. "-Wunused-but-set-variable",
  46. "-fdiagnostics-color",
  47. // arm + arm64 + mips + mips64
  48. "-fgcse-after-reload",
  49. "-frerun-cse-after-loop",
  50. "-frename-registers",
  51. "-fno-strict-volatile-bitfields",
  52. // arm + arm64
  53. "-fno-align-jumps",
  54. // arm
  55. "-mthumb-interwork",
  56. "-fno-builtin-sin",
  57. "-fno-caller-saves",
  58. "-fno-early-inlining",
  59. "-fno-move-loop-invariants",
  60. "-fno-partial-inlining",
  61. "-fno-tree-copy-prop",
  62. "-fno-tree-loop-optimize",
  63. // mips + mips64
  64. "-msynci",
  65. "-mno-synci",
  66. "-mno-fused-madd",
  67. // x86 + x86_64
  68. "-finline-limit=300",
  69. "-fno-inline-functions-called-once",
  70. "-mfpmath=sse",
  71. "-mbionic",
  72. })
  73. var ClangLibToolingUnknownCflags = []string{
  74. "-flto*",
  75. "-fsanitize*",
  76. }
  77. func init() {
  78. pctx.StaticVariable("ClangExtraCflags", strings.Join([]string{
  79. "-D__compiler_offsetof=__builtin_offsetof",
  80. // Help catch common 32/64-bit errors.
  81. "-Werror=int-conversion",
  82. // Disable overly aggressive warning for macros defined with a leading underscore
  83. // This happens in AndroidConfig.h, which is included nearly everywhere.
  84. // TODO: can we remove this now?
  85. "-Wno-reserved-id-macro",
  86. // Disable overly aggressive warning for format strings.
  87. // Bug: 20148343
  88. "-Wno-format-pedantic",
  89. // Workaround for ccache with clang.
  90. // See http://petereisentraut.blogspot.com/2011/05/ccache-and-clang.html.
  91. "-Wno-unused-command-line-argument",
  92. // Force clang to always output color diagnostics. Ninja will strip the ANSI
  93. // color codes if it is not running in a terminal.
  94. "-fcolor-diagnostics",
  95. // http://b/29823425 Disable -Wexpansion-to-defined for Clang update to r271374
  96. "-Wno-expansion-to-defined",
  97. // http://b/68236239 Allow 0/NULL instead of using nullptr everywhere.
  98. "-Wno-zero-as-null-pointer-constant",
  99. // http://b/36463318 Clang executes with an absolute path, so clang-provided
  100. // headers are now absolute.
  101. "-fdebug-prefix-map=$$PWD/=",
  102. }, " "))
  103. pctx.StaticVariable("ClangExtraCppflags", strings.Join([]string{
  104. // Disable -Winconsistent-missing-override until we can clean up the existing
  105. // codebase for it.
  106. "-Wno-inconsistent-missing-override",
  107. // Bug: http://b/29823425 Disable -Wnull-dereference until the
  108. // new instances detected by this warning are fixed.
  109. "-Wno-null-dereference",
  110. // Enable clang's thread-safety annotations in libcxx.
  111. // Turn off -Wthread-safety-negative, to avoid breaking projects that use -Weverything.
  112. "-D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS",
  113. "-Wno-thread-safety-negative",
  114. }, " "))
  115. pctx.StaticVariable("ClangExtraTargetCflags", strings.Join([]string{
  116. "-nostdlibinc",
  117. }, " "))
  118. pctx.StaticVariable("ClangExtraNoOverrideCflags", strings.Join([]string{
  119. "-Werror=address-of-temporary",
  120. // Bug: http://b/29823425 Disable -Wnull-dereference until the
  121. // new cases detected by this warning in Clang r271374 are
  122. // fixed.
  123. //"-Werror=null-dereference",
  124. "-Werror=return-type",
  125. }, " "))
  126. }
  127. func ClangFilterUnknownCflags(cflags []string) []string {
  128. ret := make([]string, 0, len(cflags))
  129. for _, f := range cflags {
  130. if !inListSorted(f, ClangUnknownCflags) {
  131. ret = append(ret, f)
  132. }
  133. }
  134. return ret
  135. }
  136. func inListSorted(s string, list []string) bool {
  137. for _, l := range list {
  138. if s == l {
  139. return true
  140. } else if s < l {
  141. return false
  142. }
  143. }
  144. return false
  145. }
  146. func sorted(list []string) []string {
  147. sort.Strings(list)
  148. return list
  149. }