Skip to content

Commit

Permalink
Merged master:183342c0a98 into amd-gfx:bd825eb42a4
Browse files Browse the repository at this point in the history
Local branch amd-gfx bd825eb Merged master:def48b0e888 into amd-gfx:1fd38bfef96
Remote branch master 183342c [SCCP] Add another switch+phi test (NFC)
  • Loading branch information
Sw authored and Sw committed Jul 23, 2020
2 parents bd825eb + 183342c commit 80a1215
Show file tree
Hide file tree
Showing 65 changed files with 7,494 additions and 313 deletions.
20 changes: 2 additions & 18 deletions compiler-rt/lib/dfsan/dfsan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,6 @@ static void dfsan_check_label(dfsan_label label) {
}
}

static void ReportUnsupportedFast16(const char *func) {
Report("FATAL: DataFlowSanitizer: %s is unsupported in fast16labels mode\n",
func);
Die();
}

// Resolves the union of two unequal labels. Nonequality is a precondition for
// this function (the instrumentation pass inlines the equality test).
extern "C" SANITIZER_INTERFACE_ATTRIBUTE
Expand Down Expand Up @@ -259,10 +253,8 @@ dfsan_union(dfsan_label l1, dfsan_label l2) {

extern "C" SANITIZER_INTERFACE_ATTRIBUTE
dfsan_label dfsan_create_label(const char *desc, void *userdata) {
if (flags().fast16labels)
ReportUnsupportedFast16("dfsan_create_label");
dfsan_label label =
atomic_fetch_add(&__dfsan_last_label, 1, memory_order_relaxed) + 1;
atomic_fetch_add(&__dfsan_last_label, 1, memory_order_relaxed) + 1;
dfsan_check_label(label);
__dfsan_label_info[label].l1 = __dfsan_label_info[label].l2 = 0;
__dfsan_label_info[label].desc = desc;
Expand Down Expand Up @@ -319,15 +311,11 @@ dfsan_read_label(const void *addr, uptr size) {

extern "C" SANITIZER_INTERFACE_ATTRIBUTE
const struct dfsan_label_info *dfsan_get_label_info(dfsan_label label) {
if (flags().fast16labels)
ReportUnsupportedFast16("dfsan_get_label_info");
return &__dfsan_label_info[label];
}

extern "C" SANITIZER_INTERFACE_ATTRIBUTE int
dfsan_has_label(dfsan_label label, dfsan_label elem) {
if (flags().fast16labels)
return label & elem;
if (label == elem)
return true;
const dfsan_label_info *info = dfsan_get_label_info(label);
Expand All @@ -340,8 +328,6 @@ dfsan_has_label(dfsan_label label, dfsan_label elem) {

extern "C" SANITIZER_INTERFACE_ATTRIBUTE dfsan_label
dfsan_has_label_with_desc(dfsan_label label, const char *desc) {
if (flags().fast16labels)
ReportUnsupportedFast16("dfsan_has_label_with_desc");
const dfsan_label_info *info = dfsan_get_label_info(label);
if (info->l1 != 0) {
return dfsan_has_label_with_desc(info->l1, desc) ||
Expand All @@ -361,11 +347,9 @@ dfsan_get_label_count(void) {

extern "C" SANITIZER_INTERFACE_ATTRIBUTE void
dfsan_dump_labels(int fd) {
if (flags().fast16labels)
ReportUnsupportedFast16("dfsan_dump_labels");

dfsan_label last_label =
atomic_load(&__dfsan_last_label, memory_order_relaxed);

for (uptr l = 1; l <= last_label; ++l) {
char buf[64];
internal_snprintf(buf, sizeof(buf), "%u %u %u ", l,
Expand Down
4 changes: 3 additions & 1 deletion compiler-rt/lib/fuzzer/FuzzerDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <string>
#include <vector>

#include "FuzzerPlatform.h"

namespace fuzzer {

Expand Down Expand Up @@ -62,7 +63,8 @@ typedef Vector<uint8_t> Unit;
typedef Vector<Unit> UnitVector;
typedef int (*UserCallback)(const uint8_t *Data, size_t Size);

int FuzzerDriver(int *argc, char ***argv, UserCallback Callback);
ATTRIBUTE_INTERFACE int FuzzerDriver(int *argc, char ***argv,
UserCallback Callback);

uint8_t *ExtraCountersBegin();
uint8_t *ExtraCountersEnd();
Expand Down
8 changes: 4 additions & 4 deletions compiler-rt/lib/scudo/standalone/combined.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ class Allocator {
#endif // GWP_ASAN_HOOKS
}

ALWAYS_INLINE void initThreadMaybe(bool MinimalInit = false) {
TSDRegistry.initThreadMaybe(this, MinimalInit);
}

void reset() { memset(this, 0, sizeof(*this)); }

void unmapTestOnly() {
Expand Down Expand Up @@ -977,10 +981,6 @@ class Allocator {
reinterpret_cast<uptr>(Ptr) - SizeOrUnusedBytes;
}

ALWAYS_INLINE void initThreadMaybe(bool MinimalInit = false) {
TSDRegistry.initThreadMaybe(this, MinimalInit);
}

void quarantineOrDeallocateChunk(void *Ptr, Chunk::UnpackedHeader *Header,
uptr Size) {
Chunk::UnpackedHeader NewHeader = *Header;
Expand Down
58 changes: 18 additions & 40 deletions compiler-rt/lib/scudo/standalone/tests/combined_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,17 @@ void checkMemoryTaggingMaybe(AllocatorT *Allocator, void *P, scudo::uptr Size,
"");
}

template <typename Config> struct TestAllocator : scudo::Allocator<Config> {
TestAllocator() {
this->reset();
this->initThreadMaybe();
}
~TestAllocator() { this->unmapTestOnly(); }
};

template <class Config> static void testAllocator() {
using AllocatorT = scudo::Allocator<Config>;
auto Deleter = [](AllocatorT *A) {
A->unmapTestOnly();
delete A;
};
std::unique_ptr<AllocatorT, decltype(Deleter)> Allocator(new AllocatorT,
Deleter);
Allocator->reset();
using AllocatorT = TestAllocator<Config>;
auto Allocator = std::make_unique<AllocatorT>();

EXPECT_FALSE(Allocator->isOwned(&Mutex));
EXPECT_FALSE(Allocator->isOwned(&Allocator));
Expand Down Expand Up @@ -348,14 +350,8 @@ template <typename AllocatorT> static void stressAllocator(AllocatorT *A) {
}

template <class Config> static void testAllocatorThreaded() {
using AllocatorT = scudo::Allocator<Config>;
auto Deleter = [](AllocatorT *A) {
A->unmapTestOnly();
delete A;
};
std::unique_ptr<AllocatorT, decltype(Deleter)> Allocator(new AllocatorT,
Deleter);
Allocator->reset();
using AllocatorT = TestAllocator<Config>;
auto Allocator = std::make_unique<AllocatorT>();
std::thread Threads[32];
for (scudo::uptr I = 0; I < ARRAY_SIZE(Threads); I++)
Threads[I] = std::thread(stressAllocator<AllocatorT>, Allocator.get());
Expand Down Expand Up @@ -401,14 +397,8 @@ struct DeathConfig {
};

TEST(ScudoCombinedTest, DeathCombined) {
using AllocatorT = scudo::Allocator<DeathConfig>;
auto Deleter = [](AllocatorT *A) {
A->unmapTestOnly();
delete A;
};
std::unique_ptr<AllocatorT, decltype(Deleter)> Allocator(new AllocatorT,
Deleter);
Allocator->reset();
using AllocatorT = TestAllocator<DeathConfig>;
auto Allocator = std::make_unique<AllocatorT>();

const scudo::uptr Size = 1000U;
void *P = Allocator->allocate(Size, Origin);
Expand Down Expand Up @@ -442,29 +432,17 @@ TEST(ScudoCombinedTest, DeathCombined) {
// Ensure that releaseToOS can be called prior to any other allocator
// operation without issue.
TEST(ScudoCombinedTest, ReleaseToOS) {
using AllocatorT = scudo::Allocator<DeathConfig>;
auto Deleter = [](AllocatorT *A) {
A->unmapTestOnly();
delete A;
};
std::unique_ptr<AllocatorT, decltype(Deleter)> Allocator(new AllocatorT,
Deleter);
Allocator->reset();
using AllocatorT = TestAllocator<DeathConfig>;
auto Allocator = std::make_unique<AllocatorT>();

Allocator->releaseToOS();
}

// Verify that when a region gets full, the allocator will still manage to
// fulfill the allocation through a larger size class.
TEST(ScudoCombinedTest, FullRegion) {
using AllocatorT = scudo::Allocator<DeathConfig>;
auto Deleter = [](AllocatorT *A) {
A->unmapTestOnly();
delete A;
};
std::unique_ptr<AllocatorT, decltype(Deleter)> Allocator(new AllocatorT,
Deleter);
Allocator->reset();
using AllocatorT = TestAllocator<DeathConfig>;
auto Allocator = std::make_unique<AllocatorT>();

std::vector<void *> V;
scudo::uptr FailedAllocationsCount = 0;
Expand Down
44 changes: 5 additions & 39 deletions compiler-rt/test/dfsan/fast16labels.c
Original file line number Diff line number Diff line change
@@ -1,59 +1,25 @@
// RUN: %clang_dfsan %s -o %t
// RUN: DFSAN_OPTIONS=fast16labels=1 %run %t
// RUN: DFSAN_OPTIONS=fast16labels=1 not %run %t dfsan_create_label 2>&1 \
// RUN: | FileCheck %s --check-prefix=CREATE-LABEL
// RUN: DFSAN_OPTIONS=fast16labels=1 not %run %t dfsan_get_label_info 2>&1 \
// RUN: | FileCheck %s --check-prefix=GET-LABEL-INFO
// RUN: DFSAN_OPTIONS=fast16labels=1 not %run %t dfsan_has_label_with_desc \
// RUN: 2>&1 | FileCheck %s --check-prefix=HAS-LABEL-WITH-DESC
// RUN: DFSAN_OPTIONS=fast16labels=1:dump_labels_at_exit=/dev/stdout not %run \
// RUN: %t 2>&1 | FileCheck %s --check-prefix=DUMP-LABELS
// RUN: %clang_dfsan %s -o %t && DFSAN_OPTIONS=fast16labels=1 %run %t
//
// Tests DFSAN_OPTIONS=fast16labels=1
//
#include <sanitizer/dfsan_interface.h>

#include <assert.h>
#include <stdio.h>
#include <string.h>

int foo(int a, int b) {
return a + b;
}

int main(int argc, char *argv[]) {
// Death tests for unsupported API usage.
const char *command = (argc < 2) ? "" : argv[1];
fprintf(stderr, "Running with command %s\n", command);
// CREATE-LABEL: FATAL: DataFlowSanitizer: dfsan_create_label is unsupported
if (strcmp(command, "dfsan_create_label") == 0)
dfsan_create_label("", NULL);
// GET-LABEL-INFO: FATAL: DataFlowSanitizer: dfsan_get_label_info is unsupported
if (strcmp(command, "dfsan_get_label_info") == 0)
dfsan_get_label_info(1);
// HAS-LABEL-WITH-DESC: FATAL: DataFlowSanitizer: dfsan_has_label_with_desc is unsupported
if (strcmp(command, "dfsan_has_label_with_desc") == 0)
dfsan_has_label_with_desc(1, "");
// DUMP-LABELS: FATAL: DataFlowSanitizer: dfsan_dump_labels is unsupported

// Supported usage.
int main() {
int a = 10;
int b = 20;
dfsan_set_label(8, &a, sizeof(a));
dfsan_set_label(512, &b, sizeof(b));
int c = foo(a, b);
fprintf(stderr, "A: 0x%x\n", dfsan_get_label(a));
fprintf(stderr, "B: 0x%x\n", dfsan_get_label(b));
printf("A: 0x%x\n", dfsan_get_label(a));
printf("B: 0x%x\n", dfsan_get_label(b));
dfsan_label l = dfsan_get_label(c);
fprintf(stderr, "C: 0x%x\n", l);
fprintf(stderr, "Testing l == 520\n");
printf("C: 0x%x\n", l);
assert(l == 520); // OR of the other two labels.
fprintf(stderr, "Testing dfsan_has_label(l, 8)\n");
assert(dfsan_has_label(l, 8));
fprintf(stderr, "Testing dfsan_has_label(l, 512)\n");
assert(dfsan_has_label(l, 512));
fprintf(stderr, "Testing !dfsan_has_label(l, 1)\n");
assert(!dfsan_has_label(l, 1));
fprintf(stderr, "returning...\n");
return 0;
}
4 changes: 4 additions & 0 deletions flang/include/flang/Lower/OpenACC.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Coding style: https://mlir.llvm.org/getting_started/DeveloperGuide/
//
//===----------------------------------------------------------------------===//

#ifndef FORTRAN_LOWER_OPENACC_H
#define FORTRAN_LOWER_OPENACC_H
Expand Down
4 changes: 4 additions & 0 deletions flang/lib/Lower/OpenACC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Coding style: https://mlir.llvm.org/getting_started/DeveloperGuide/
//
//===----------------------------------------------------------------------===//

#include "flang/Lower/OpenACC.h"
#include "flang/Lower/Bridge.h"
Expand Down
3 changes: 3 additions & 0 deletions libc/config/linux/aarch64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.floor
libc.src.math.floorf
libc.src.math.floorl
libc.src.math.fmax
libc.src.math.fmaxf
libc.src.math.fmaxl
libc.src.math.fmin
libc.src.math.fminf
libc.src.math.fminl
Expand Down
3 changes: 3 additions & 0 deletions libc/config/linux/api.td
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ def MathAPI : PublicAPI<"math.h"> {
"floor",
"floorf",
"floorl",
"fmax",
"fmaxf",
"fmaxl",
"fmin",
"fminf",
"fminl",
Expand Down
3 changes: 3 additions & 0 deletions libc/config/linux/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.fmin
libc.src.math.fminf
libc.src.math.fminl
libc.src.math.fmax
libc.src.math.fmaxf
libc.src.math.fmaxl
libc.src.math.frexp
libc.src.math.frexpf
libc.src.math.frexpl
Expand Down
4 changes: 4 additions & 0 deletions libc/spec/stdc.td
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ def StdC : StandardSpec<"stdc"> {
FunctionSpec<"fminf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,
FunctionSpec<"fminl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,

FunctionSpec<"fmax", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
FunctionSpec<"fmaxf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,
FunctionSpec<"fmaxl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,

FunctionSpec<"frexp", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<IntPtr>]>,
FunctionSpec<"frexpf", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<IntPtr>]>,
FunctionSpec<"frexpl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<IntPtr>]>,
Expand Down
36 changes: 36 additions & 0 deletions libc/src/math/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -449,3 +449,39 @@ add_entrypoint_object(
COMPILE_OPTIONS
-O2
)

add_entrypoint_object(
fmax
SRCS
fmax.cpp
HDRS
fmax.h
DEPENDS
libc.utils.FPUtil.fputil
COMPILE_OPTIONS
-O2
)

add_entrypoint_object(
fmaxf
SRCS
fmaxf.cpp
HDRS
fmaxf.h
DEPENDS
libc.utils.FPUtil.fputil
COMPILE_OPTIONS
-O2
)

add_entrypoint_object(
fmaxl
SRCS
fmaxl.cpp
HDRS
fmaxl.h
DEPENDS
libc.utils.FPUtil.fputil
COMPILE_OPTIONS
-O2
)
18 changes: 18 additions & 0 deletions libc/src/math/fmax.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//===-- Implementation of fmax function -----------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//

#include "src/__support/common.h"
#include "utils/FPUtil/BasicOperations.h"

namespace __llvm_libc {

double LLVM_LIBC_ENTRYPOINT(fmax)(double x, double y) {
return fputil::fmax(x, y);
}

} // namespace __llvm_libc
Loading

0 comments on commit 80a1215

Please sign in to comment.