diff --git a/contrib/llvm-project/compiler-rt/lib/asan/asan_rtl_x86_64.S b/contrib/llvm-project/compiler-rt/lib/asan/asan_rtl_x86_64.S --- a/contrib/llvm-project/compiler-rt/lib/asan/asan_rtl_x86_64.S +++ b/contrib/llvm-project/compiler-rt/lib/asan/asan_rtl_x86_64.S @@ -27,7 +27,12 @@ #define ASAN_MEMORY_ACCESS_INITIAL_CHECK_ADD(reg, op, s) \ mov %##reg,%r10 ;\ shr $0x3,%r10 ;\ + .if ASAN_SHADOW_OFFSET_CONST < 0x80000000 ;\ movsbl ASAN_SHADOW_OFFSET_CONST(%r10),%r10d ;\ + .else ;\ + movabsq $ASAN_SHADOW_OFFSET_CONST,%r11 ;\ + movsbl (%r10,%r11),%r10d ;\ + .endif ;\ test %r10d,%r10d ;\ jne CLABEL(reg, op, s, add) ;\ RLABEL(reg, op, s, add): ;\ @@ -90,7 +95,12 @@ #define ASAN_MEMORY_ACCESS_CHECK_ADD(reg, op, s, c) \ mov %##reg,%r10 ;\ shr $0x3,%r10 ;\ + .if ASAN_SHADOW_OFFSET_CONST < 0x80000000 ;\ ##c $0x0,ASAN_SHADOW_OFFSET_CONST(%r10) ;\ + .else ;\ + movabsq $ASAN_SHADOW_OFFSET_CONST,%r11 ;\ + ##c $0x0,(%r10,%r11) ;\ + .endif ;\ jne FLABEL(reg, op, s, add) ;\ retq ;\ diff --git a/contrib/llvm-project/openmp/runtime/src/kmp_csupport.cpp b/contrib/llvm-project/openmp/runtime/src/kmp_csupport.cpp --- a/contrib/llvm-project/openmp/runtime/src/kmp_csupport.cpp +++ b/contrib/llvm-project/openmp/runtime/src/kmp_csupport.cpp @@ -18,6 +18,7 @@ #include "kmp_itt.h" #include "kmp_lock.h" #include "kmp_stats.h" +#include "kmp_utils.h" #include "ompt-specific.h" #define MAX_MESSAGE 512 @@ -4195,7 +4196,7 @@ up = pr_buf->th_doacross_info[3]; st = pr_buf->th_doacross_info[4]; #if OMPT_SUPPORT && OMPT_OPTIONAL - ompt_dependence_t deps[num_dims]; + SimpleVLA deps(num_dims); #endif if (st == 1) { // most common case if (vec[0] < lo || vec[0] > up) { @@ -4307,7 +4308,7 @@ lo = pr_buf->th_doacross_info[2]; st = pr_buf->th_doacross_info[4]; #if OMPT_SUPPORT && OMPT_OPTIONAL - ompt_dependence_t deps[num_dims]; + SimpleVLA deps(num_dims); #endif if (st == 1) { // most common case iter_number = vec[0] - lo; diff --git a/contrib/llvm-project/openmp/runtime/src/kmp_gsupport.cpp b/contrib/llvm-project/openmp/runtime/src/kmp_gsupport.cpp --- a/contrib/llvm-project/openmp/runtime/src/kmp_gsupport.cpp +++ b/contrib/llvm-project/openmp/runtime/src/kmp_gsupport.cpp @@ -12,6 +12,7 @@ #include "kmp.h" #include "kmp_atomic.h" +#include "kmp_utils.h" #if OMPT_SUPPORT #include "ompt-specific.h" @@ -1280,7 +1281,7 @@ KMP_ASSERT(depend); kmp_gomp_depends_info_t gomp_depends(depend); kmp_int32 ndeps = gomp_depends.get_num_deps(); - kmp_depend_info_t dep_list[ndeps]; + SimpleVLA dep_list(ndeps); for (kmp_int32 i = 0; i < ndeps; i++) dep_list[i] = gomp_depends.get_kmp_depend(i); kmp_int32 ndeps_cnv; @@ -1309,7 +1310,7 @@ KMP_ASSERT(depend); kmp_gomp_depends_info_t gomp_depends(depend); kmp_int32 ndeps = gomp_depends.get_num_deps(); - kmp_depend_info_t dep_list[ndeps]; + SimpleVLA dep_list(ndeps); for (kmp_int32 i = 0; i < ndeps; i++) dep_list[i] = gomp_depends.get_kmp_depend(i); __kmpc_omp_wait_deps(&loc, gtid, ndeps, dep_list, 0, NULL); @@ -1993,7 +1994,7 @@ KA_TRACE(20, ("GOMP_taskwait_depend: T#%d\n", gtid)); kmp_gomp_depends_info_t gomp_depends(depend); kmp_int32 ndeps = gomp_depends.get_num_deps(); - kmp_depend_info_t dep_list[ndeps]; + SimpleVLA dep_list(ndeps); for (kmp_int32 i = 0; i < ndeps; i++) dep_list[i] = gomp_depends.get_kmp_depend(i); #if OMPT_SUPPORT diff --git a/contrib/llvm-project/openmp/runtime/src/kmp_runtime.cpp b/contrib/llvm-project/openmp/runtime/src/kmp_runtime.cpp --- a/contrib/llvm-project/openmp/runtime/src/kmp_runtime.cpp +++ b/contrib/llvm-project/openmp/runtime/src/kmp_runtime.cpp @@ -24,6 +24,7 @@ #include "kmp_wait_release.h" #include "kmp_wrapper_getpid.h" #include "kmp_dispatch.h" +#include "kmp_utils.h" #if KMP_USE_HIER_SCHED #include "kmp_dispatch_hier.h" #endif @@ -1641,7 +1642,7 @@ /* josh todo: hypothetical question: what do we do for OS X*? */ #if KMP_OS_LINUX && \ (KMP_ARCH_X86 || KMP_ARCH_X86_64 || KMP_ARCH_ARM || KMP_ARCH_AARCH64) - void *args[argc]; + SimpleVLA args(argc); #else void **args = (void **)KMP_ALLOCA(argc * sizeof(void *)); #endif /* KMP_OS_LINUX && ( KMP_ARCH_X86 || KMP_ARCH_X86_64 || KMP_ARCH_ARM || \ diff --git a/contrib/llvm-project/openmp/runtime/src/kmp_utils.h b/contrib/llvm-project/openmp/runtime/src/kmp_utils.h new file mode 100644 --- /dev/null +++ b/contrib/llvm-project/openmp/runtime/src/kmp_utils.h @@ -0,0 +1,55 @@ +/* + * kmp_utils.h -- Utilities that used internally + */ + +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#ifndef __KMP_UTILS_H__ +#define __KMP_UTILS_H__ + +#include + +#include "kmp.h" + +/// A simple pure header implementation of VLA that aims to replace uses of +/// actual VLA, which can cause compile warning. This class by default creates a +/// stack buffer that can accomodate \p N elements. If the number of elements is +/// greater than \p N, then a heap buffer will be allocated and used to +/// accomodate the elements. Similar to the actual VLA, we don't check boundary +/// (for now), so we will not store the number of elements. We can always revise +/// it later. +template class SimpleVLA final { + T StackBuffer[N]; + T *HeapBuffer = nullptr; + T *Ptr = StackBuffer; + +public: + SimpleVLA() = delete; + SimpleVLA(const SimpleVLA &) = delete; + SimpleVLA(SimpleVLA &&) = delete; + SimpleVLA &operator=(const SimpleVLA &) = delete; + SimpleVLA &operator=(SimpleVLA &&) = delete; + + explicit SimpleVLA(unsigned NumOfElements) noexcept { + if (NumOfElements > N) { + HeapBuffer = + reinterpret_cast(__kmp_allocate(NumOfElements * sizeof(T))); + Ptr = HeapBuffer; + } + } + + ~SimpleVLA() { + if (HeapBuffer) + __kmp_free(HeapBuffer); + } + + operator T *() noexcept { return Ptr; } + operator const T *() const noexcept { return Ptr; } +}; + +#endif diff --git a/lib/libomp/Makefile b/lib/libomp/Makefile --- a/lib/libomp/Makefile +++ b/lib/libomp/Makefile @@ -72,6 +72,10 @@ .endif .endif +.if ${COMPILER_TYPE} == "clang" && ${COMPILER_VERSION} >= 180000 +CWARNFLAGS+= -Wno-vla-cxx-extension +.endif + LDFLAGS+= -Wl,--warn-shared-textrel LDFLAGS+= -Wl,--gc-sections LDFLAGS+= -Wl,-z,noexecstack