Skip to content

Commit

Permalink
merge main into amd-staging
Browse files Browse the repository at this point in the history
reverts: MC fails to build, needs downstream work
9abb574 [MC] Make MCCFIInstruction smaller

Change-Id: Ie1090b05dc092956fff4412d92b684625423886e
  • Loading branch information
ronlieb committed Jul 7, 2024
2 parents 5c685e1 + 902fb1b commit 26a8914
Show file tree
Hide file tree
Showing 94 changed files with 1,411 additions and 213 deletions.
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/support/ThreadsafeFS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class VolatileFileSystem : public llvm::vfs::ProxyFileSystem {
llvm::StringRef FileName = llvm::sys::path::filename(Path);
if (FileName.starts_with("preamble-") && FileName.ends_with(".pch"))
return File;
return std::unique_ptr<VolatileFile>(new VolatileFile(std::move(*File)));
return std::make_unique<VolatileFile>(std::move(*File));
}

private:
Expand Down
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,8 @@ Bug Fixes to C++ Support
of the address of operator. (#GH97483).
- Fixed an assertion failure about a constant expression which is a known integer but is not
evaluated to an integer. (#GH96670).
- Fixed a bug where references to lambda capture inside a ``noexcept`` specifier were not correctly
instantiated. (#GH95735).

Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
6 changes: 6 additions & 0 deletions clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4704,6 +4704,12 @@ void Sema::InstantiateExceptionSpec(SourceLocation PointOfInstantiation,
return;
}

// The noexcept specification could reference any lambda captures. Ensure
// those are added to the LocalInstantiationScope.
LambdaScopeForCallOperatorInstantiationRAII PushLambdaCaptures(
*this, Decl, TemplateArgs, Scope,
/*ShouldAddDeclsFromParentScope=*/false);

SubstExceptionSpec(Decl, Template->getType()->castAs<FunctionProtoType>(),
TemplateArgs);
}
Expand Down
23 changes: 23 additions & 0 deletions clang/test/SemaTemplate/generic-lambda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,26 @@ template<class T1> C1<X<X<T1>>> auto t3() {
template C1<X<X<int>>> auto t3<int>();
static_assert(is_same<decltype(t3<int>()), X<X<X<int>>>>);
#endif

namespace GH95735 {

int g(int fn) {
return [f = fn](auto tpl) noexcept(noexcept(f)) { return f; }(0);
}

int foo(auto... fn) {
// FIXME: This one hits the assertion "if the exception specification is dependent,
// then the noexcept expression should be value-dependent" in the constructor of
// FunctionProtoType.
// One possible solution is to update Sema::canThrow() to consider expressions
// (e.g. DeclRefExpr/FunctionParmPackExpr) involving unexpanded parameters as Dependent.
// This would effectively add an extra value-dependent flag to the noexcept expression.
// However, I'm afraid that would also cause ABI breakage.
// [...f = fn](auto tpl) noexcept(noexcept(f)) { return 0; }(0);
[...f = fn](auto tpl) noexcept(noexcept(g(fn...))) { return 0; }(0);
return [...f = fn](auto tpl) noexcept(noexcept(g(f...))) { return 0; }(0);
}

int v = foo(42);

} // namespace GH95735
25 changes: 12 additions & 13 deletions libc/benchmarks/gpu/LibcGpuBenchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ void Benchmark::add_benchmark(Benchmark *benchmark) {
benchmarks.push_back(benchmark);
}

BenchmarkResult reduce_results(cpp::array<BenchmarkResult, 1024> &results) {
BenchmarkResult
reduce_results(const cpp::array<BenchmarkResult, 1024> &results) {
BenchmarkResult result;
uint64_t cycles_sum = 0;
double standard_deviation_sum = 0;
Expand Down Expand Up @@ -51,16 +52,16 @@ void Benchmark::run_benchmarks() {
uint64_t id = gpu::get_thread_id();
gpu::sync_threads();

for (Benchmark *benchmark : benchmarks)
results[id] = benchmark->run();
for (Benchmark *b : benchmarks)
results[id] = b->run();
gpu::sync_threads();
if (id == 0) {
for (Benchmark *benchmark : benchmarks) {
for (Benchmark const *b : benchmarks) {
BenchmarkResult all_results = reduce_results(results);
constexpr auto GREEN = "\033[32m";
constexpr auto RESET = "\033[0m";
log << GREEN << "[ RUN ] " << RESET << benchmark->get_name() << '\n';
log << GREEN << "[ OK ] " << RESET << benchmark->get_name() << ": "
log << GREEN << "[ RUN ] " << RESET << b->get_name() << '\n';
log << GREEN << "[ OK ] " << RESET << b->get_name() << ": "
<< all_results.cycles << " cycles, " << all_results.min << " min, "
<< all_results.max << " max, " << all_results.total_iterations
<< " iterations, " << all_results.total_time << " ns, "
Expand All @@ -82,7 +83,6 @@ BenchmarkResult benchmark(const BenchmarkOptions &options,
uint32_t samples = 0;
uint64_t total_time = 0;
uint64_t best_guess = 0;
uint64_t total_cycles = 0;
uint64_t cycles_squared = 0;
uint64_t min = UINT64_MAX;
uint64_t max = 0;
Expand All @@ -92,23 +92,22 @@ BenchmarkResult benchmark(const BenchmarkOptions &options,
for (int i = 0; i < overhead_iterations; i++)
overhead = cpp::min(overhead, LIBC_NAMESPACE::overhead());

for (uint64_t time_budget = options.max_duration; time_budget >= 0;) {
for (int64_t time_budget = options.max_duration; time_budget >= 0;) {
uint64_t sample_cycles = 0;
const clock_t start = static_cast<double>(clock());
for (uint32_t i = 0; i < iterations; i++) {
auto wrapper_intermediate = wrapper_func();
uint64_t result = wrapper_intermediate - overhead;
max = cpp::max(max, result);
min = cpp::min(min, result);
sample_cycles += result;
uint64_t current_result = wrapper_intermediate - overhead;
max = cpp::max(max, current_result);
min = cpp::min(min, current_result);
sample_cycles += current_result;
}
const clock_t end = clock();
const clock_t duration_ns =
((end - start) * 1000 * 1000 * 1000) / CLOCKS_PER_SEC;
total_time += duration_ns;
time_budget -= duration_ns;
samples++;
total_cycles += sample_cycles;
cycles_squared += sample_cycles * sample_cycles;

total_iterations += iterations;
Expand Down
4 changes: 2 additions & 2 deletions libc/benchmarks/gpu/LibcGpuBenchmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ struct BenchmarkOptions {
uint32_t max_iterations = 10000000;
uint32_t min_samples = 4;
uint32_t max_samples = 1000;
uint64_t min_duration = 0; // in nanoseconds (ns)
uint64_t max_duration = 1000 * 1000 * 1000; // 1e9 nanoseconds = 1 second
int64_t min_duration = 0; // in nanoseconds (ns)
int64_t max_duration = 1000 * 1000 * 1000; // 1e9 nanoseconds = 1 second
double epsilon = 0.01;
double scaling_factor = 1.4;
};
Expand Down
6 changes: 6 additions & 0 deletions libc/config/linux/aarch64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.ctype.tolower
libc.src.ctype.toupper

# dlfcn.h entrypoints
libc.src.dlfcn.dlclose
libc.src.dlfcn.dlerror
libc.src.dlfcn.dlopen
libc.src.dlfcn.dlsym

# errno.h entrypoints
libc.src.errno.errno

Expand Down
6 changes: 6 additions & 0 deletions libc/config/linux/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.ctype.tolower
libc.src.ctype.toupper

# dlfcn.h entrypoints
libc.src.dlfcn.dlclose
libc.src.dlfcn.dlerror
libc.src.dlfcn.dlopen
libc.src.dlfcn.dlsym

# errno.h entrypoints
libc.src.errno.errno

Expand Down
4 changes: 4 additions & 0 deletions libc/docs/dev/undefined_behavior.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,7 @@ The C23 standard states that if the value of the ``rnd`` argument of the
the value of a math rounding direction macro, the direction of rounding is
unspecified. LLVM's libc chooses to use the ``FP_INT_TONEAREST`` rounding
direction in this case.

Non-const Constant Return Values
--------------------------------
Some libc functions, like ``dlerror()``, return ``char *`` instead of ``const char *`` and then tell the caller they promise not to to modify this value. Any modification of this value is undefined behavior.
35 changes: 35 additions & 0 deletions libc/spec/posix.td
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,40 @@ def POSIX : StandardSpec<"POSIX"> {
[] // Functions
>;

HeaderSpec DlFcn = HeaderSpec<
"dlfcn.h",
[
Macro<"RTLD_LAZY">,
Macro<"RTLD_NOW">,
Macro<"RTLD_GLOBAL">,
Macro<"RTLD_LOCAL">,
],
[], // Types
[], // Enumerations
[
FunctionSpec<
"dlclose",
RetValSpec<IntType>,
[ArgSpec<VoidPtr>]
>,
FunctionSpec<
"dlerror",
RetValSpec<CharPtr>,
[]
>,
FunctionSpec<
"dlopen",
RetValSpec<VoidPtr>,
[ArgSpec<ConstCharPtr>, ArgSpec<IntType>]
>,
FunctionSpec<
"dlsym",
RetValSpec<VoidPtr>,
[ArgSpec<VoidRestrictedPtr>, ArgSpec<ConstCharRestrictedPtr>]
>,
]
>;

HeaderSpec FCntl = HeaderSpec<
"fcntl.h",
[], // Macros
Expand Down Expand Up @@ -1690,6 +1724,7 @@ def POSIX : StandardSpec<"POSIX"> {
ArpaInet,
CType,
Dirent,
DlFcn,
Errno,
FCntl,
PThread,
Expand Down
1 change: 1 addition & 0 deletions libc/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
add_subdirectory(__support)

add_subdirectory(ctype)
add_subdirectory(dlfcn)
add_subdirectory(errno)
add_subdirectory(fenv)
add_subdirectory(inttypes)
Expand Down
40 changes: 40 additions & 0 deletions libc/src/dlfcn/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
add_entrypoint_object(
dlclose
SRCS
dlclose.cpp
HDRS
dlclose.h
)

add_entrypoint_object(
dlerror
SRCS
dlerror.cpp
HDRS
dlerror.h
DEPENDS
libc.include.dlfcn
libc.src.errno.errno
)

add_entrypoint_object(
dlopen
SRCS
dlopen.cpp
HDRS
dlopen.h
DEPENDS
libc.include.dlfcn
libc.src.errno.errno
)

add_entrypoint_object(
dlsym
SRCS
dlsym.cpp
HDRS
dlsym.h
DEPENDS
libc.include.dlfcn
libc.src.errno.errno
)
18 changes: 18 additions & 0 deletions libc/src/dlfcn/dlclose.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//===-- Implementation of dlclose -----------------------------------------===//
//
// 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 "dlclose.h"

#include "src/__support/common.h"

namespace LIBC_NAMESPACE {

// TODO(@izaakschroeder): https://github.com/llvm/llvm-project/issues/97917
LLVM_LIBC_FUNCTION(int, dlclose, (void *)) { return -1; }

} // namespace LIBC_NAMESPACE
18 changes: 18 additions & 0 deletions libc/src/dlfcn/dlclose.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//===-- Implementation header of dlclose ------------------------*- 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
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SRC_DLFCN_DLCLOSE_H
#define LLVM_LIBC_SRC_DLFCN_DLCLOSE_H

namespace LIBC_NAMESPACE {

int dlclose(void *);

} // namespace LIBC_NAMESPACE

#endif // LLVM_LIBC_SRC_DLFCN_DLCLOSE_H
20 changes: 20 additions & 0 deletions libc/src/dlfcn/dlerror.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation of delerror ----------------------------------------===//
//
// 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 "dlerror.h"

#include "src/__support/common.h"

namespace LIBC_NAMESPACE {

// TODO(@izaakschroeder): https://github.com/llvm/llvm-project/issues/97918
LLVM_LIBC_FUNCTION(char *, dlerror, ()) {
return const_cast<char *>("unsupported");
}

} // namespace LIBC_NAMESPACE
18 changes: 18 additions & 0 deletions libc/src/dlfcn/dlerror.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//===-- Implementation header of dlerror ------------------------*- 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
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SRC_DLFCN_DLERROR_H
#define LLVM_LIBC_SRC_DLFCN_DLERROR_H

namespace LIBC_NAMESPACE {

char *dlerror();

} // namespace LIBC_NAMESPACE

#endif // LLVM_LIBC_SRC_DLFCN_DLERROR_H
18 changes: 18 additions & 0 deletions libc/src/dlfcn/dlopen.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//===-- Implementation of dlopen -----------------------------------------===//
//
// 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 "dlopen.h"

#include "src/__support/common.h"

namespace LIBC_NAMESPACE {

// TODO(@izaakschroeder): https://github.com/llvm/llvm-project/issues/97919
LLVM_LIBC_FUNCTION(void *, dlopen, (const char *, int)) { return nullptr; }

} // namespace LIBC_NAMESPACE
18 changes: 18 additions & 0 deletions libc/src/dlfcn/dlopen.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//===-- Implementation header of dlopen -------------------------*- 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
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SRC_DLFCN_DLOPEN_H
#define LLVM_LIBC_SRC_DLFCN_DLOPEN_H

namespace LIBC_NAMESPACE {

void *dlopen(const char *, int);

} // namespace LIBC_NAMESPACE

#endif // LLVM_LIBC_SRC_DLFCN_DLOPEN_H
Loading

0 comments on commit 26a8914

Please sign in to comment.