Skip to content

Commit

Permalink
Merge pull request #19 from llvm/main
Browse files Browse the repository at this point in the history
[pull] main from llvm:main
  • Loading branch information
devkadirselcuk authored Jul 8, 2021
2 parents 71efe5d + 026bb84 commit 5b87741
Show file tree
Hide file tree
Showing 89 changed files with 2,978 additions and 1,794 deletions.
4 changes: 4 additions & 0 deletions clang/include/clang/Driver/ToolChain.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,10 @@ class ToolChain {
/// Check if the toolchain should use the integrated assembler.
virtual bool useIntegratedAs() const;

/// Check if the toolchain should use AsmParser to parse inlineAsm when
/// integrated assembler is not default.
virtual bool parseInlineAsmUsingAsmParser() const { return false; }

/// IsMathErrnoDefault - Does this tool chain use -fmath-errno by default.
virtual bool IsMathErrnoDefault() const { return true; }

Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Driver/ToolChains/AIX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA,
/// AIX - AIX tool chain which can call as(1) and ld(1) directly.
AIX::AIX(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
: ToolChain(D, Triple, Args) {
ParseInlineAsmUsingAsmParser = Args.hasFlag(
options::OPT_fintegrated_as, options::OPT_fno_integrated_as, true);
getLibraryPaths().push_back(getDriver().SysRoot + "/usr/lib");
}

Expand Down
4 changes: 4 additions & 0 deletions clang/lib/Driver/ToolChains/AIX.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ class LLVM_LIBRARY_VISIBILITY AIX : public ToolChain {
AIX(const Driver &D, const llvm::Triple &Triple,
const llvm::opt::ArgList &Args);

bool parseInlineAsmUsingAsmParser() const override {
return ParseInlineAsmUsingAsmParser;
}
bool isPICDefault() const override { return true; }
bool isPIEDefault() const override { return false; }
bool isPICDefaultForced() const override { return true; }
Expand Down Expand Up @@ -87,6 +90,7 @@ class LLVM_LIBRARY_VISIBILITY AIX : public ToolChain {

private:
llvm::StringRef GetHeaderSysroot(const llvm::opt::ArgList &DriverArgs) const;
bool ParseInlineAsmUsingAsmParser;
};

} // end namespace toolchains
Expand Down
4 changes: 3 additions & 1 deletion clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5038,7 +5038,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
<< A->getValue() << A->getOption().getName();
}

if (!TC.useIntegratedAs())
// If toolchain choose to use MCAsmParser for inline asm don't pass the
// option to disable integrated-as explictly.
if (!TC.useIntegratedAs() && !TC.parseInlineAsmUsingAsmParser())
CmdArgs.push_back("-no-integrated-as");

if (Args.hasArg(options::OPT_fdebug_pass_structure)) {
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/Frontend/InitPreprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,8 @@ static void InitializeCPlusPlusFeatureTestMacros(const LangOptions &LangOpts,
}
// C++2b features.
if (LangOpts.CPlusPlus2b) {
Builder.defineMacro("__cpp_implicit_move", "202011L");
if (!LangOpts.MSVCCompat)
Builder.defineMacro("__cpp_implicit_move", "202011L");
Builder.defineMacro("__cpp_size_t_suffix", "202011L");
}
if (LangOpts.Char8)
Expand Down
7 changes: 6 additions & 1 deletion clang/lib/Sema/SemaStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3333,8 +3333,13 @@ Sema::NamedReturnInfo Sema::getNamedReturnInfo(Expr *&E, bool ForceCXX2b) {
if (!VD)
return NamedReturnInfo();
NamedReturnInfo Res = getNamedReturnInfo(VD);
// FIXME: We supress simpler implicit move here (unless ForceCXX2b is true)
// in msvc compatibility mode just as a temporary work around,
// as the MSVC STL has issues with this change.
// We will come back later with a more targeted approach.
if (Res.Candidate && !E->isXValue() &&
(ForceCXX2b || getLangOpts().CPlusPlus2b)) {
(ForceCXX2b ||
(getLangOpts().CPlusPlus2b && !getLangOpts().MSVCCompat))) {
E = ImplicitCastExpr::Create(Context, VD->getType().getNonReferenceType(),
CK_NoOp, E, nullptr, VK_XValue,
FPOptionsOverride());
Expand Down
15 changes: 15 additions & 0 deletions clang/test/Driver/aix-as.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,18 @@
// CHECK-AS32-MultiInput: "{{.*}}as{{(.exe)?}}"
// CHECK-AS32-MultiInput: "-a32"
// CHECK-AS32-MultiInput: "-many"

// Check not passing no-integrated-as flag by default.
// RUN: %clang -no-canonical-prefixes %s -### -c -o %t.o 2>&1 \
// RUN: -target powerpc64-ibm-aix7.1.0.0 \
// RUN: | FileCheck --check-prefix=CHECK-IAS --implicit-check-not=-no-integrated-as %s
// CHECK-IAS: InstalledDir
// CHECK-IAS: "-a64"

// Check passing no-integrated-as flag if specified by user.
// RUN: %clang -no-canonical-prefixes %s -### -c -o %t.o 2>&1 \
// RUN: -target powerpc64-ibm-aix7.1.0.0 -fno-integrated-as \
// RUN: | FileCheck --check-prefix=CHECK-NOIAS %s
// CHECK-NOIAS: InstalledDir
// CHECK-NOIAS: -no-integrated-as
// CHECK-NOIAS: "-a64"
50 changes: 50 additions & 0 deletions clang/test/SemaCXX/cxx2b-p2266-disable-with-msvc-compat.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// RUN: %clang_cc1 -std=c++2b -fsyntax-only -fcxx-exceptions -verify=new %s
// RUN: %clang_cc1 -std=c++2b -fsyntax-only -fcxx-exceptions -fms-compatibility -verify=old %s
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions -verify=old %s

// FIXME: This is a test for a temporary workaround where we disable simpler implicit moves
// when compiling with -fms-compatibility, because the MSVC STL does not compile.
// A better workaround is under discussion.
// The test cases here are just a copy from `CXX/class/class.init/class.copy.elision/p3.cpp`,
// so feel free to delete this file when the workaround is not needed anymore.

struct CopyOnly {
CopyOnly(); // new-note {{candidate constructor not viable: requires 0 arguments, but 1 was provided}}
// new-note@-1 {{candidate constructor not viable: requires 0 arguments, but 1 was provided}}
CopyOnly(CopyOnly &); // new-note {{candidate constructor not viable: expects an lvalue for 1st argument}}
// new-note@-1 {{candidate constructor not viable: expects an lvalue for 1st argument}}
};
struct MoveOnly {
MoveOnly();
MoveOnly(MoveOnly &&);
};
MoveOnly &&rref();

MoveOnly &&test1(MoveOnly &&w) {
return w; // old-error {{cannot bind to lvalue of type}}
}

CopyOnly test2(bool b) {
static CopyOnly w1;
CopyOnly w2;
if (b) {
return w1;
} else {
return w2; // new-error {{no matching constructor for initialization}}
}
}

template <class T> T &&test3(T &&x) { return x; } // old-error {{cannot bind to lvalue of type}}
template MoveOnly &test3<MoveOnly &>(MoveOnly &);
template MoveOnly &&test3<MoveOnly>(MoveOnly &&); // old-note {{in instantiation of function template specialization}}

MoveOnly &&test4() {
MoveOnly &&x = rref();
return x; // old-error {{cannot bind to lvalue of type}}
}

void test5() try {
CopyOnly x;
throw x; // new-error {{no matching constructor for initialization}}
} catch (...) {
}
8 changes: 6 additions & 2 deletions compiler-rt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,12 @@ if (NOT COMPILER_RT_ASAN_SHADOW_SCALE STREQUAL "")
-D${COMPILER_RT_ASAN_SHADOW_SCALE_DEFINITION})
endif()

set(COMPILER_RT_HWASAN_WITH_INTERCEPTORS ON CACHE BOOL
"Enable libc interceptors in HWASan (testing mode)")
if(FUCHSIA)
set(COMPILER_RT_HWASAN_WITH_INTERCEPTORS_DEFAULT OFF)
else()
set(COMPILER_RT_HWASAN_WITH_INTERCEPTORS_DEFAULT ON)
endif()
set(COMPILER_RT_HWASAN_WITH_INTERCEPTORS ${COMPILER_RT_HWASAN_WITH_INTERCEPTORS_DEFAULT} CACHE BOOL "Enable libc interceptors in HWASan (testing mode)")

set(COMPILER_RT_BAREMETAL_BUILD OFF CACHE BOOL
"Build for a bare-metal target.")
Expand Down
6 changes: 6 additions & 0 deletions compiler-rt/lib/hwasan/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ set(HWASAN_RTL_SOURCES
hwasan_allocation_functions.cpp
hwasan_dynamic_shadow.cpp
hwasan_exceptions.cpp
hwasan_fuchsia.cpp
hwasan_globals.cpp
hwasan_interceptors.cpp
hwasan_interceptors_vfork.S
Expand Down Expand Up @@ -44,6 +45,11 @@ set(HWASAN_RTL_HEADERS
set(HWASAN_DEFINITIONS)
append_list_if(COMPILER_RT_HWASAN_WITH_INTERCEPTORS HWASAN_WITH_INTERCEPTORS=1 HWASAN_DEFINITIONS)

if(FUCHSIA)
# Set this explicitly on Fuchsia, otherwise the default value is set to HWASAN_WITH_INTERCEPTORS.
list(APPEND HWASAN_DEFINITIONS HWASAN_REPLACE_OPERATORS_NEW_AND_DELETE=1)
endif()

set(HWASAN_RTL_CFLAGS ${SANITIZER_COMMON_CFLAGS})
append_rtti_flag(OFF HWASAN_RTL_CFLAGS)
append_list_if(COMPILER_RT_HAS_FPIC_FLAG -fPIC HWASAN_RTL_CFLAGS)
Expand Down
159 changes: 159 additions & 0 deletions compiler-rt/lib/hwasan/hwasan_fuchsia.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
//===-- hwasan_fuchsia.cpp --------------------------------------*- C++ -*-===//
//
// 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
//
//===----------------------------------------------------------------------===//
///
/// \file
/// This file is a part of HWAddressSanitizer and contains Fuchsia-specific
/// code.
///
//===----------------------------------------------------------------------===//

#include "sanitizer_common/sanitizer_fuchsia.h"
#if SANITIZER_FUCHSIA

#include "hwasan.h"
#include "hwasan_interface_internal.h"
#include "hwasan_report.h"
#include "hwasan_thread.h"
#include "hwasan_thread_list.h"

// This TLS variable contains the location of the stack ring buffer and can be
// used to always find the hwasan thread object associated with the current
// running thread.
[[gnu::tls_model("initial-exec")]]
SANITIZER_INTERFACE_ATTRIBUTE
THREADLOCAL uptr __hwasan_tls;

namespace __hwasan {

// These are known parameters passed to the hwasan runtime on thread creation.
struct Thread::InitState {
uptr stack_bottom, stack_top;
};

static void FinishThreadInitialization(Thread *thread);

void InitThreads() {
// This is the minimal alignment needed for the storage where hwasan threads
// and their stack ring buffers are placed. This alignment is necessary so the
// stack ring buffer can perform a simple calculation to get the next element
// in the RB. The instructions for this calculation are emitted by the
// compiler. (Full explanation in hwasan_thread_list.h.)
uptr alloc_size = UINT64_C(1) << kShadowBaseAlignment;
uptr thread_start = reinterpret_cast<uptr>(
MmapAlignedOrDieOnFatalError(alloc_size, alloc_size, __func__));

InitThreadList(thread_start, alloc_size);

// Create the hwasan thread object for the current (main) thread. Stack info
// for this thread is known from information passed via
// __sanitizer_startup_hook.
const Thread::InitState state = {
.stack_bottom = __sanitizer::MainThreadStackBase,
.stack_top =
__sanitizer::MainThreadStackBase + __sanitizer::MainThreadStackSize,
};
FinishThreadInitialization(hwasanThreadList().CreateCurrentThread(&state));
}

uptr *GetCurrentThreadLongPtr() { return &__hwasan_tls; }

// This is called from the parent thread before the new thread is created. Here
// we can propagate known info like the stack bounds to Thread::Init before
// jumping into the thread. We cannot initialize the stack ring buffer yet since
// we have not entered the new thread.
static void *BeforeThreadCreateHook(uptr user_id, bool detached,
const char *name, uptr stack_bottom,
uptr stack_size) {
const Thread::InitState state = {
.stack_bottom = stack_bottom,
.stack_top = stack_bottom + stack_size,
};
return hwasanThreadList().CreateCurrentThread(&state);
}

// This sets the stack top and bottom according to the InitState passed to
// CreateCurrentThread above.
void Thread::InitStackAndTls(const InitState *state) {
CHECK_NE(state->stack_bottom, 0);
CHECK_NE(state->stack_top, 0);
stack_bottom_ = state->stack_bottom;
stack_top_ = state->stack_top;
tls_end_ = tls_begin_ = 0;
}

// This is called after creating a new thread with the pointer returned by
// BeforeThreadCreateHook. We are still in the creating thread and should check
// if it was actually created correctly.
static void ThreadCreateHook(void *hook, bool aborted) {
Thread *thread = static_cast<Thread *>(hook);
if (!aborted) {
// The thread was created successfully.
// ThreadStartHook can already be running in the new thread.
} else {
// The thread wasn't created after all.
// Clean up everything we set up in BeforeThreadCreateHook.
atomic_signal_fence(memory_order_seq_cst);
hwasanThreadList().ReleaseThread(thread);
}
}

// This is called in the newly-created thread before it runs anything else,
// with the pointer returned by BeforeThreadCreateHook (above). Here we can
// setup the stack ring buffer.
static void ThreadStartHook(void *hook, thrd_t self) {
Thread *thread = static_cast<Thread *>(hook);
FinishThreadInitialization(thread);
thread->InitRandomState();
}

// This is the function that sets up the stack ring buffer and enables us to use
// GetCurrentThread. This function should only be called while IN the thread
// that we want to create the hwasan thread object for so __hwasan_tls can be
// properly referenced.
static void FinishThreadInitialization(Thread *thread) {
CHECK_NE(thread, nullptr);

// The ring buffer is located immediately before the thread object.
uptr stack_buffer_size = hwasanThreadList().GetRingBufferSize();
uptr stack_buffer_start = reinterpret_cast<uptr>(thread) - stack_buffer_size;
thread->InitStackRingBuffer(stack_buffer_start, stack_buffer_size);
}

static void ThreadExitHook(void *hook, thrd_t self) {
Thread *thread = static_cast<Thread *>(hook);
atomic_signal_fence(memory_order_seq_cst);
hwasanThreadList().ReleaseThread(thread);
}

} // namespace __hwasan

extern "C" {

void *__sanitizer_before_thread_create_hook(thrd_t thread, bool detached,
const char *name, void *stack_base,
size_t stack_size) {
return __hwasan::BeforeThreadCreateHook(
reinterpret_cast<uptr>(thread), detached, name,
reinterpret_cast<uptr>(stack_base), stack_size);
}

void __sanitizer_thread_create_hook(void *hook, thrd_t thread, int error) {
__hwasan::ThreadCreateHook(hook, error != thrd_success);
}

void __sanitizer_thread_start_hook(void *hook, thrd_t self) {
__hwasan::ThreadStartHook(hook, reinterpret_cast<uptr>(self));
}

void __sanitizer_thread_exit_hook(void *hook, thrd_t self) {
__hwasan::ThreadExitHook(hook, self);
}

} // extern "C"

#endif // SANITIZER_FUCHSIA
5 changes: 5 additions & 0 deletions compiler-rt/lib/hwasan/hwasan_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ void Thread::Init(uptr stack_buffer_start, uptr stack_buffer_size,
heap_allocations_ = HeapAllocationsRingBuffer::New(sz);

InitStackAndTls(state);
#if !SANITIZER_FUCHSIA
// Do not initialize the stack ring buffer just yet on Fuchsia. Threads will
// be initialized before we enter the thread itself, so we will instead call
// this later.
InitStackRingBuffer(stack_buffer_start, stack_buffer_size);
#endif
}

void Thread::InitStackRingBuffer(uptr stack_buffer_start,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class G
int G::n_alive = 0;
bool G::op_run = false;

void foo() {}
void foo() { done = true; }

int main(int, char**)
{
Expand All @@ -75,6 +75,7 @@ int main(int, char**)
assert(G::n_alive == 1);
}
assert(G::n_alive == 0);
done = false;
#ifndef TEST_HAS_NO_EXCEPTIONS
{
std::thread t0 = support::make_test_thread(foo);
Expand All @@ -85,6 +86,11 @@ int main(int, char**)
t0.detach();
} catch (std::system_error const&) {
}
// Wait to make sure that the detached thread has started up.
// Without this, we could exit main and start destructing global
// resources that are needed when the thread starts up, while the
// detached thread would start up only later.
while (!done) {}
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion lld/MachO/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ static void compileBitcodeFiles() {
// FIXME: Remove this once LTO.cpp honors config->exportDynamic.
if (config->exportDynamic)
for (InputFile *file : inputFiles)
if (auto *bitcodeFile = dyn_cast<BitcodeFile>(file)) {
if (isa<BitcodeFile>(file)) {
warn("the effect of -export_dynamic on LTO is not yet implemented");
break;
}
Expand Down
Loading

0 comments on commit 5b87741

Please sign in to comment.