Fix ODR violations in math_brute_force (#1255)

A program having a type (such as ThreadInfo) defined differently in
multiple translation units exhibits undefined behaviour.

This commit fixes such issues in the math_brute_force component by
ensuring most types are local to their translation unit with the help of
anonymous namespaces. Later refactoring will be able to extract common
definitions to a single place.

This patch also removes unnecessary static and typedef keywords.
Otherwise, code is only moved around with no change.

Signed-off-by: Marco Antognini <marco.antognini@arm.com>
This commit is contained in:
Marco Antognini
2021-05-21 10:07:54 +01:00
committed by GitHub
parent ce1687a408
commit ba9312e4a2
27 changed files with 2400 additions and 2321 deletions

View File

@@ -23,8 +23,10 @@
#define CORRECTLY_ROUNDED 0
#define FLUSHED 1
static int BuildKernel(const char *name, int vectorSize, cl_kernel *k,
cl_program *p, bool relaxedMode)
namespace {
int BuildKernel(const char *name, int vectorSize, cl_kernel *k, cl_program *p,
bool relaxedMode)
{
const char *c[] = { "#pragma OPENCL EXTENSION cl_khr_fp64 : enable\n",
"__kernel void math_kernel",
@@ -116,16 +118,16 @@ static int BuildKernel(const char *name, int vectorSize, cl_kernel *k,
return MakeKernel(kern, (cl_uint)kernSize, testName, k, p, relaxedMode);
}
typedef struct BuildKernelInfo
struct BuildKernelInfo
{
cl_uint offset; // the first vector size to build
cl_kernel *kernels;
cl_program *programs;
const char *nameInCode;
bool relaxedMode; // Whether to build with -cl-fast-relaxed-math.
} BuildKernelInfo;
};
static cl_int BuildKernelFn(cl_uint job_id, cl_uint thread_id UNUSED, void *p)
cl_int BuildKernelFn(cl_uint job_id, cl_uint thread_id UNUSED, void *p)
{
BuildKernelInfo *info = (BuildKernelInfo *)p;
cl_uint i = info->offset + job_id;
@@ -134,7 +136,7 @@ static cl_int BuildKernelFn(cl_uint job_id, cl_uint thread_id UNUSED, void *p)
}
// A table of more difficult cases to get right
static const double specialValues[] = {
const double specialValues[] = {
-NAN,
-INFINITY,
-DBL_MAX,
@@ -202,9 +204,11 @@ static const double specialValues[] = {
+0.0,
};
static const size_t specialValuesCount =
constexpr size_t specialValuesCount =
sizeof(specialValues) / sizeof(specialValues[0]);
} // anonymous namespace
int TestFunc_Double_Double_Double_Double(const Func *f, MTdata d,
bool relaxedMode)
{