Skip to content

Commit f36451f

Browse files
committed
ARROW-14897: [CI][C++] Upgrade Clang Tools to 12 from 8
Closes apache#11786 from kou/cpp-clang-tools-12 Authored-by: Sutou Kouhei <[email protected]> Signed-off-by: Sutou Kouhei <[email protected]>
1 parent 9ec01da commit f36451f

20 files changed

+105
-68
lines changed

.clang-format

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717
---
18-
BasedOnStyle: Google
19-
DerivePointerAlignment: false
18+
BasedOnStyle: Google
2019
ColumnLimit: 90
20+
DerivePointerAlignment: false
21+
IncludeBlocks: Preserve

.env

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ FEDORA=33
5151
UBUNTU=20.04
5252

5353
# Default versions for various dependencies
54-
CLANG_TOOLS=8
54+
CLANG_TOOLS=12
5555
CUDA=9.1
5656
DASK=latest
5757
DOTNET=3.1

ci/docker/ubuntu-20.04-cpp.dockerfile

+13-6
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,27 @@ RUN echo "debconf debconf/frontend select Noninteractive" | \
2929
# while debugging package list with docker build.
3030
ARG clang_tools
3131
ARG llvm
32-
RUN if [ "${llvm}" -gt "10" ]; then \
32+
RUN latest_system_llvm=10 && \
33+
if [ ${llvm} -gt ${latest_system_llvm} -o \
34+
${clang_tools} -gt ${latest_system_llvm} ]; then \
3335
apt-get update -y -q && \
3436
apt-get install -y -q --no-install-recommends \
3537
apt-transport-https \
3638
ca-certificates \
3739
gnupg \
40+
lsb-release \
3841
wget && \
3942
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - && \
40-
echo "deb https://apt.llvm.org/focal/ llvm-toolchain-focal-${llvm} main" > \
41-
/etc/apt/sources.list.d/llvm.list && \
42-
if [ "${clang_tools}" != "${llvm}" -a "${clang_tools}" -gt 10 ]; then \
43-
echo "deb https://apt.llvm.org/focal/ llvm-toolchain-focal-${clang_tools} main" > \
43+
code_name=$(lsb_release --codename --short) && \
44+
if [ ${llvm} -gt 10 ]; then \
45+
echo "deb https://apt.llvm.org/${code_name}/ llvm-toolchain-${code_name}-${llvm} main" > \
46+
/etc/apt/sources.list.d/llvm.list; \
47+
fi && \
48+
if [ ${clang_tools} -ne ${llvm} -a \
49+
${clang_tools} -gt ${latest_system_llvm} ]; then \
50+
echo "deb https://apt.llvm.org/${code_name}/ llvm-toolchain-${code_name}-${clang_tools} main" > \
4451
/etc/apt/sources.list.d/clang-tools.list; \
45-
fi \
52+
fi; \
4653
fi && \
4754
apt-get update -y -q && \
4855
apt-get install -y -q --no-install-recommends \

ci/docker/ubuntu-21.04-cpp.dockerfile

+14-7
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
ARG base=amd64/ubuntu:20.04
18+
ARG base=amd64/ubuntu:21.04
1919
FROM ${base}
2020

2121
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
@@ -29,20 +29,27 @@ RUN echo "debconf debconf/frontend select Noninteractive" | \
2929
# while debugging package list with docker build.
3030
ARG clang_tools
3131
ARG llvm
32-
RUN if [ "${llvm}" -gt "10" ]; then \
32+
RUN latest_system_llvm=12 && \
33+
if [ ${llvm} -gt ${latest_system_llvm} -o \
34+
${clang_tools} -gt ${latest_system_llvm} ]; then \
3335
apt-get update -y -q && \
3436
apt-get install -y -q --no-install-recommends \
3537
apt-transport-https \
3638
ca-certificates \
3739
gnupg \
40+
lsb-release \
3841
wget && \
3942
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - && \
40-
echo "deb https://apt.llvm.org/hirsute/ llvm-toolchain-hirsute-${llvm} main" > \
41-
/etc/apt/sources.list.d/llvm.list && \
42-
if [ "${clang_tools}" != "${llvm}" -a "${clang_tools}" -gt 10 ]; then \
43-
echo "deb https://apt.llvm.org/hirsute/ llvm-toolchain-hirsute-${clang_tools} main" > \
43+
code_name=$(lsb_release --codename --short) && \
44+
if [ ${llvm} -gt 10 ]; then \
45+
echo "deb https://apt.llvm.org/${code_name}/ llvm-toolchain-${code_name}-${llvm} main" > \
46+
/etc/apt/sources.list.d/llvm.list; \
47+
fi && \
48+
if [ ${clang_tools} -ne ${llvm} -a \
49+
${clang_tools} -gt ${latest_system_llvm} ]; then \
50+
echo "deb https://apt.llvm.org/${code_name}/ llvm-toolchain-${code_name}-${clang_tools} main" > \
4451
/etc/apt/sources.list.d/clang-tools.list; \
45-
fi \
52+
fi; \
4653
fi && \
4754
apt-get update -y -q && \
4855
apt-get install -y -q --no-install-recommends \

cpp/src/arrow/compute/exec/expression_test.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -1222,8 +1222,9 @@ TEST(Expression, SingleComparisonGuarantees) {
12221222
all = false;
12231223
}
12241224
}
1225-
Simplify{filter}.WithGuarantee(guarantee).Expect(
1226-
all ? literal(true) : none ? literal(false) : filter);
1225+
Simplify{filter}.WithGuarantee(guarantee).Expect(all ? literal(true)
1226+
: none ? literal(false)
1227+
: filter);
12271228
}
12281229
}
12291230
}

cpp/src/arrow/compute/exec/hash_join_node_test.cc

+10-8
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,10 @@ struct RandomDataTypeConstraints {
281281

282282
void OnlyInt(int int_size, bool allow_nulls) {
283283
Default();
284-
data_type_enabled_mask =
285-
int_size == 8 ? kInt8 : int_size == 4 ? kInt4 : int_size == 2 ? kInt2 : kInt1;
284+
data_type_enabled_mask = int_size == 8 ? kInt8
285+
: int_size == 4 ? kInt4
286+
: int_size == 2 ? kInt2
287+
: kInt1;
286288
if (!allow_nulls) {
287289
max_null_probability = 0.0;
288290
}
@@ -1166,12 +1168,12 @@ void TestHashJoinDictionaryHelper(
11661168
int expected_num_r_no_match,
11671169
// Whether to swap two inputs to the hash join
11681170
bool swap_sides) {
1169-
int64_t l_length = l_key.is_array()
1170-
? l_key.array()->length
1171-
: l_payload.is_array() ? l_payload.array()->length : -1;
1172-
int64_t r_length = r_key.is_array()
1173-
? r_key.array()->length
1174-
: r_payload.is_array() ? r_payload.array()->length : -1;
1171+
int64_t l_length = l_key.is_array() ? l_key.array()->length
1172+
: l_payload.is_array() ? l_payload.array()->length
1173+
: -1;
1174+
int64_t r_length = r_key.is_array() ? r_key.array()->length
1175+
: r_payload.is_array() ? r_payload.array()->length
1176+
: -1;
11751177
ARROW_DCHECK(l_length >= 0 && r_length >= 0);
11761178

11771179
constexpr int batch_multiplicity_for_parallel = 2;

cpp/src/arrow/compute/exec/key_encode.cc

+8-4
Original file line numberDiff line numberDiff line change
@@ -572,10 +572,14 @@ void KeyEncoder::EncoderBinaryPair::Decode(uint32_t start_row, uint32_t num_rows
572572

573573
uint32_t col_width1 = col_prep[0].metadata().fixed_length;
574574
uint32_t col_width2 = col_prep[1].metadata().fixed_length;
575-
int log_col_width1 =
576-
col_width1 == 8 ? 3 : col_width1 == 4 ? 2 : col_width1 == 2 ? 1 : 0;
577-
int log_col_width2 =
578-
col_width2 == 8 ? 3 : col_width2 == 4 ? 2 : col_width2 == 2 ? 1 : 0;
575+
int log_col_width1 = col_width1 == 8 ? 3
576+
: col_width1 == 4 ? 2
577+
: col_width1 == 2 ? 1
578+
: 0;
579+
int log_col_width2 = col_width2 == 8 ? 3
580+
: col_width2 == 4 ? 2
581+
: col_width2 == 2 ? 1
582+
: 0;
579583

580584
bool is_row_fixed_length = rows.metadata().is_fixed_length;
581585

cpp/src/arrow/compute/exec/key_map.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,10 @@ class SwissTable {
153153

154154
static int num_groupid_bits_from_log_blocks(int log_blocks) {
155155
int required_bits = log_blocks + 3;
156-
return required_bits <= 8 ? 8
157-
: required_bits <= 16 ? 16 : required_bits <= 32 ? 32 : 64;
156+
return required_bits <= 8 ? 8
157+
: required_bits <= 16 ? 16
158+
: required_bits <= 32 ? 32
159+
: 64;
158160
}
159161

160162
// Use 32-bit hash for now

cpp/src/arrow/io/memory_benchmark.cc

+11-11
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ using VectorType = __m512i;
4949
#define VectorSet _mm512_set1_epi32
5050
#define VectorLoad _mm512_stream_load_si512
5151
#define VectorLoadAsm(SRC, DST) \
52-
asm volatile("vmovaps %[src], %[dst]" : [ dst ] "=v"(DST) : [ src ] "m"(SRC) :)
52+
asm volatile("vmovaps %[src], %[dst]" : [dst] "=v"(DST) : [src] "m"(SRC) :)
5353
#define VectorStreamLoad _mm512_stream_load_si512
5454
#define VectorStreamLoadAsm(SRC, DST) \
55-
asm volatile("vmovntdqa %[src], %[dst]" : [ dst ] "=v"(DST) : [ src ] "m"(SRC) :)
55+
asm volatile("vmovntdqa %[src], %[dst]" : [dst] "=v"(DST) : [src] "m"(SRC) :)
5656
#define VectorStreamWrite _mm512_stream_si512
5757

5858
#else
@@ -63,10 +63,10 @@ using VectorType = __m256i;
6363
#define VectorSet _mm256_set1_epi32
6464
#define VectorLoad _mm256_stream_load_si256
6565
#define VectorLoadAsm(SRC, DST) \
66-
asm volatile("vmovaps %[src], %[dst]" : [ dst ] "=v"(DST) : [ src ] "m"(SRC) :)
66+
asm volatile("vmovaps %[src], %[dst]" : [dst] "=v"(DST) : [src] "m"(SRC) :)
6767
#define VectorStreamLoad _mm256_stream_load_si256
6868
#define VectorStreamLoadAsm(SRC, DST) \
69-
asm volatile("vmovntdqa %[src], %[dst]" : [ dst ] "=v"(DST) : [ src ] "m"(SRC) :)
69+
asm volatile("vmovntdqa %[src], %[dst]" : [dst] "=v"(DST) : [src] "m"(SRC) :)
7070
#define VectorStreamWrite _mm256_stream_si256
7171

7272
#else // ARROW_HAVE_AVX2 not set
@@ -75,10 +75,10 @@ using VectorType = __m128i;
7575
#define VectorSet _mm_set1_epi32
7676
#define VectorLoad _mm_stream_load_si128
7777
#define VectorLoadAsm(SRC, DST) \
78-
asm volatile("movaps %[src], %[dst]" : [ dst ] "=x"(DST) : [ src ] "m"(SRC) :)
78+
asm volatile("movaps %[src], %[dst]" : [dst] "=x"(DST) : [src] "m"(SRC) :)
7979
#define VectorStreamLoad _mm_stream_load_si128
8080
#define VectorStreamLoadAsm(SRC, DST) \
81-
asm volatile("movntdqa %[src], %[dst]" : [ dst ] "=x"(DST) : [ src ] "m"(SRC) :)
81+
asm volatile("movntdqa %[src], %[dst]" : [dst] "=x"(DST) : [src] "m"(SRC) :)
8282
#define VectorStreamWrite _mm_stream_si128
8383

8484
#endif // ARROW_HAVE_AVX2
@@ -164,22 +164,22 @@ using VectorTypeDual = uint8x16x2_t;
164164

165165
static void armv8_stream_load_pair(VectorType* src, VectorType* dst) {
166166
asm volatile("LDNP %[reg1], %[reg2], [%[from]]\n\t"
167-
: [ reg1 ] "+r"(*dst), [ reg2 ] "+r"(*(dst + 1))
168-
: [ from ] "r"(src));
167+
: [reg1] "+r"(*dst), [reg2] "+r"(*(dst + 1))
168+
: [from] "r"(src));
169169
}
170170

171171
static void armv8_stream_store_pair(VectorType* src, VectorType* dst) {
172172
asm volatile("STNP %[reg1], %[reg2], [%[to]]\n\t"
173-
: [ to ] "+r"(dst)
174-
: [ reg1 ] "r"(*src), [ reg2 ] "r"(*(src + 1))
173+
: [to] "+r"(dst)
174+
: [reg1] "r"(*src), [reg2] "r"(*(src + 1))
175175
: "memory");
176176
}
177177

178178
static void armv8_stream_ldst_pair(VectorType* src, VectorType* dst) {
179179
asm volatile(
180180
"LDNP q1, q2, [%[from]]\n\t"
181181
"STNP q1, q2, [%[to]]\n\t"
182-
: [ from ] "+r"(src), [ to ] "+r"(dst)
182+
: [from] "+r"(src), [to] "+r"(dst)
183183
:
184184
: "memory", "v0", "v1", "v2", "v3");
185185
}

cpp/src/arrow/testing/util.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
#endif
3939

4040
#include "arrow/table.h"
41-
#include "arrow/type.h"
4241
#include "arrow/testing/random.h"
42+
#include "arrow/type.h"
4343
#include "arrow/util/io_util.h"
4444
#include "arrow/util/logging.h"
4545
#include "arrow/util/pcg_random.h"

cpp/src/arrow/util/basic_decimal.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -1353,9 +1353,9 @@ bool operator<(const BasicDecimal256& left, const BasicDecimal256& right) {
13531353
const auto rhs_le = bit_util::little_endian::Make(right.native_endian_array());
13541354
return lhs_le[3] != rhs_le[3]
13551355
? static_cast<int64_t>(lhs_le[3]) < static_cast<int64_t>(rhs_le[3])
1356-
: lhs_le[2] != rhs_le[2] ? lhs_le[2] < rhs_le[2]
1357-
: lhs_le[1] != rhs_le[1] ? lhs_le[1] < rhs_le[1]
1358-
: lhs_le[0] < rhs_le[0];
1356+
: lhs_le[2] != rhs_le[2] ? lhs_le[2] < rhs_le[2]
1357+
: lhs_le[1] != rhs_le[1] ? lhs_le[1] < rhs_le[1]
1358+
: lhs_le[0] < rhs_le[0];
13591359
}
13601360

13611361
BasicDecimal256 operator-(const BasicDecimal256& operand) {

cpp/src/gandiva/expression_registry.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ FunctionSignature ExpressionRegistry::FunctionSignatureIterator::operator*() {
6060
return *func_sig_it_;
6161
}
6262

63-
ExpressionRegistry::func_sig_iterator_type ExpressionRegistry::FunctionSignatureIterator::
64-
operator++(int increment) {
63+
ExpressionRegistry::func_sig_iterator_type
64+
ExpressionRegistry::FunctionSignatureIterator::operator++(int increment) {
6565
++func_sig_it_;
6666
// point func_sig_it_ to first signature of next nativefunction if func_sig_it_ is
6767
// pointing to end

cpp/src/parquet/arrow/reconstruct_internal_test.cc

+4-3
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,10 @@ class FileBuilder {
113113
auto typed_writer =
114114
checked_cast<TypedColumnWriter<PhysicalType<TYPE>>*>(column_writer);
115115

116-
const int64_t num_values = static_cast<int64_t>(
117-
(max_def_level > 0) ? def_levels.size()
118-
: (max_rep_level > 0) ? rep_levels.size() : values.size());
116+
const int64_t num_values =
117+
static_cast<int64_t>((max_def_level > 0) ? def_levels.size()
118+
: (max_rep_level > 0) ? rep_levels.size()
119+
: values.size());
119120
const int64_t values_written = typed_writer->WriteBatch(
120121
num_values, LevelPointerOrNull(def_levels, max_def_level),
121122
LevelPointerOrNull(rep_levels, max_rep_level), values.data());

dev/tasks/tasks.yml

-2
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,6 @@ tasks:
11981198
params:
11991199
env:
12001200
UBUNTU: 21.04
1201-
CLANG_TOOLS: 9 # can remove this when >=9 is the default
12021201
R_PRUNE_DEPS: TRUE
12031202
flags: '-e ARROW_SOURCE_HOME="/arrow" -e FORCE_BUNDLED_BUILD=TRUE -e LIBARROW_BUILD=TRUE'
12041203
image: ubuntu-r-only-r
@@ -1210,7 +1209,6 @@ tasks:
12101209
params:
12111210
env:
12121211
UBUNTU: 21.04
1213-
CLANG_TOOLS: 9 # can remove this when >=9 is the default
12141212
GCC_VERSION: 11
12151213
# S3 support is not buildable with gcc11 right now
12161214
flags: '-e ARROW_SOURCE_HOME="/arrow" -e FORCE_BUNDLED_BUILD=TRUE -e LIBARROW_BUILD=TRUE -e ARROW_S3=OFF'

docs/source/developers/cpp/building.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ CMake:
398398
LLVM and Clang Tools
399399
~~~~~~~~~~~~~~~~~~~~
400400

401-
We are currently using LLVM 8 for library builds and for other developer tools
401+
We are currently using LLVM for library builds and for other developer tools
402402
such as code formatting with ``clang-format``. LLVM can be installed via most
403403
modern package managers (apt, yum, conda, Homebrew, vcpkg, chocolatey).
404404

docs/source/developers/cpp/development.rst

+5-3
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,11 @@ following checks:
105105
subcommand to :ref:`Archery <archery>`. This can also be fixed locally
106106
by running ``archery lint --cpplint --fix``.
107107

108-
In order to account for variations in the behavior of ``clang-format`` between
109-
major versions of LLVM, we pin the version of ``clang-format`` used (current
110-
LLVM 8).
108+
In order to account for variations in the behavior of ``clang-format``
109+
between major versions of LLVM, we pin the version of ``clang-format``
110+
used. You can confirm the current pinned version by finding
111+
the ``CLANG_TOOLS`` variable value in `.env
112+
<https://github.com/apache/arrow/blob/master/.env>`_.
111113

112114
Depending on how you installed clang-format, the build system may not be able
113115
to find it. You can provide an explicit path to your LLVM installation (or the

r/lint.sh

+10-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,16 @@ SOURCE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
2626
CPP_BUILD_SUPPORT=$SOURCE_DIR/../cpp/build-support
2727

2828
# Run clang-format
29-
: ${CLANG_FORMAT:=$(. "${SOURCE_DIR}/../.env" && echo clang-format-${CLANG_TOOLS})}
29+
if [ -z "${CLANG_FORMAT:-}" ]; then
30+
CLANG_TOOLS=$(. "${SOURCE_DIR}/../.env" && echo ${CLANG_TOOLS})
31+
if type clang-format-${CLANG_TOOLS} >/dev/null 2>&1; then
32+
CLANG_FORMAT=clang-format-${CLANG_TOOLS}
33+
elif type brew >/dev/null 2>&1; then
34+
CLANG_FORMAT=$(brew --prefix llvm@${CLANG_TOOLS})/bin/clang-format
35+
else
36+
CLANG_FORMAT=clang-format
37+
fi
38+
fi
3039
$CPP_BUILD_SUPPORT/run_clang_format.py \
3140
--clang_format_binary=$CLANG_FORMAT \
3241
--exclude_glob=$CPP_BUILD_SUPPORT/lint_exclusions.txt \

r/src/.clang-format

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717
---
18-
BasedOnStyle: Google
19-
DerivePointerAlignment: false
18+
BasedOnStyle: Google
2019
ColumnLimit: 90
20+
DerivePointerAlignment: false
21+
IncludeBlocks: Preserve

r/src/nameof.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ const size_t typename_prefix = search(raw<double>(), "double");
5555
template <typename T>
5656
size_t struct_class_prefix() {
5757
#ifdef _MSC_VER
58-
return starts_with(raw<T>() + typename_prefix, "struct ")
59-
? 7
60-
: starts_with(raw<T>() + typename_prefix, "class ") ? 6 : 0;
58+
return starts_with(raw<T>() + typename_prefix, "struct ") ? 7
59+
: starts_with(raw<T>() + typename_prefix, "class ") ? 6
60+
: 0;
6161
#else
6262
return 0;
6363
#endif

r/vignettes/developers/workflow.Rmd

+6-4
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,18 @@ Fix any style issues before committing with
8787
./lint.sh --fix
8888
```
8989

90-
The lint script requires Python 3 and `clang-format-8`. If the command
90+
The lint script requires Python 3 and `clang-format`. If the command
9191
isn't found, you can explicitly provide the path to it like:
9292

9393
```bash
94-
CLANG_FORMAT=$(which clang-format-8) ./lint.sh
94+
CLANG_FORMAT=/opt/llvm/bin/clang-format ./lint.sh
9595
```
9696

97-
On macOS, you can get this by installing LLVM via Homebrew and running the script as:
97+
You can see what version of `clang-format` is required by the following
98+
command:
99+
98100
```bash
99-
CLANG_FORMAT=$(brew --prefix llvm@8)/bin/clang-format ./lint.sh
101+
(. ../.env && echo ${CLANG_TOOLS})
100102
```
101103

102104
_Note_ that the lint script requires Python 3 and the Python dependencies

0 commit comments

Comments
 (0)