Skip to content

Commit

Permalink
Merged main:02cbae4fe068 into amd-gfx:5118390a1fcc
Browse files Browse the repository at this point in the history
Local branch amd-gfx 5118390 Merged main:202dda8e5c3f into amd-gfx:6034dce6d758
Remote branch main 02cbae4 [RISCV] Work on subreg for insert_vector_elt when vlen is known (llvm#72666) (llvm#73680)
  • Loading branch information
SC llvm team authored and SC llvm team committed Nov 28, 2023
2 parents 5118390 + 02cbae4 commit 14c4d99
Show file tree
Hide file tree
Showing 87 changed files with 1,653 additions and 1,981 deletions.
3 changes: 3 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,9 @@ Bug Fixes in This Version
- Fix crash during code generation of C++ coroutine initial suspend when the return
type of await_resume is not trivially destructible.
Fixes (`#63803 <https://github.com/llvm/llvm-project/issues/63803>`_)
- ``__is_trivially_relocatable`` no longer returns true for non-object types
such as references and functions.
Fixes (`#67498 <https://github.com/llvm/llvm-project/issues/67498>`_)
- Fix crash when the object used as a ``static_assert`` message has ``size`` or ``data`` members
which are not member functions.
- Support UDLs in ``static_assert`` message.
Expand Down
22 changes: 10 additions & 12 deletions clang/include/clang/Frontend/ASTUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -691,18 +691,16 @@ class ASTUnit {
/// lifetime is expected to extend past that of the returned ASTUnit.
///
/// \returns - The initialized ASTUnit or null if the AST failed to load.
static std::unique_ptr<ASTUnit>
LoadFromASTFile(const std::string &Filename,
const PCHContainerReader &PCHContainerRdr, WhatToLoad ToLoad,
IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
const FileSystemOptions &FileSystemOpts,
std::shared_ptr<HeaderSearchOptions> HSOpts,
bool UseDebugInfo = false, bool OnlyLocalDecls = false,
CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::None,
bool AllowASTWithCompilerErrors = false,
bool UserFilesAreVolatile = false,
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS =
llvm::vfs::getRealFileSystem());
static std::unique_ptr<ASTUnit> LoadFromASTFile(
const std::string &Filename, const PCHContainerReader &PCHContainerRdr,
WhatToLoad ToLoad, IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
const FileSystemOptions &FileSystemOpts,
std::shared_ptr<HeaderSearchOptions> HSOpts, bool OnlyLocalDecls = false,
CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::None,
bool AllowASTWithCompilerErrors = false,
bool UserFilesAreVolatile = false,
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS =
llvm::vfs::getRealFileSystem());

private:
/// Helper function for \c LoadFromCompilerInvocation() and
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/AST/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2649,6 +2649,8 @@ bool QualType::isTriviallyRelocatableType(const ASTContext &Context) const {

if (BaseElementType->isIncompleteType()) {
return false;
} else if (!BaseElementType->isObjectType()) {
return false;
} else if (const auto *RD = BaseElementType->getAsRecordDecl()) {
return RD->canPassInRegisters();
} else {
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Frontend/ASTMerge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void ASTMergeAction::ExecuteAction() {
/*ShouldOwnClient=*/true));
std::unique_ptr<ASTUnit> Unit = ASTUnit::LoadFromASTFile(
ASTFiles[I], CI.getPCHContainerReader(), ASTUnit::LoadEverything, Diags,
CI.getFileSystemOpts(), CI.getHeaderSearchOptsPtr(), false);
CI.getFileSystemOpts(), CI.getHeaderSearchOptsPtr());

if (!Unit)
continue;
Expand Down
7 changes: 3 additions & 4 deletions clang/lib/Frontend/ASTUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -790,10 +790,9 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromASTFile(
const std::string &Filename, const PCHContainerReader &PCHContainerRdr,
WhatToLoad ToLoad, IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
const FileSystemOptions &FileSystemOpts,
std::shared_ptr<HeaderSearchOptions> HSOpts, bool UseDebugInfo,
bool OnlyLocalDecls, CaptureDiagsKind CaptureDiagnostics,
bool AllowASTWithCompilerErrors, bool UserFilesAreVolatile,
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) {
std::shared_ptr<HeaderSearchOptions> HSOpts, bool OnlyLocalDecls,
CaptureDiagsKind CaptureDiagnostics, bool AllowASTWithCompilerErrors,
bool UserFilesAreVolatile, IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) {
std::unique_ptr<ASTUnit> AST(new ASTUnit(true));

// Recover resources if we crash before exiting this method.
Expand Down
5 changes: 2 additions & 3 deletions clang/lib/Frontend/FrontendAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
std::unique_ptr<ASTUnit> AST = ASTUnit::LoadFromASTFile(
std::string(InputFile), CI.getPCHContainerReader(),
ASTUnit::LoadPreprocessorOnly, ASTDiags, CI.getFileSystemOpts(),
/*HeaderSearchOptions=*/nullptr, CI.getCodeGenOpts().DebugTypeExtRefs);
/*HeaderSearchOptions=*/nullptr);
if (!AST)
return false;

Expand Down Expand Up @@ -689,8 +689,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
std::unique_ptr<ASTUnit> AST = ASTUnit::LoadFromASTFile(
std::string(InputFile), CI.getPCHContainerReader(),
ASTUnit::LoadEverything, Diags, CI.getFileSystemOpts(),
CI.getHeaderSearchOptsPtr(),
CI.getCodeGenOpts().DebugTypeExtRefs);
CI.getHeaderSearchOptsPtr());

if (!AST)
return false;
Expand Down
8 changes: 7 additions & 1 deletion clang/test/SemaCXX/type-traits-incomplete.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s

struct S; // expected-note 2 {{forward declaration of 'S'}}
struct S; // expected-note 6 {{forward declaration of 'S'}}

void f() {
__is_pod(S); // expected-error{{incomplete type 'S' used in type trait expression}}
__is_pod(S[]); // expected-error{{incomplete type 'S' used in type trait expression}}

__is_trivially_copyable(S); // expected-error{{incomplete type 'S' used in type trait expression}}
__is_trivially_copyable(S[]); // expected-error{{incomplete type 'S' used in type trait expression}}

__is_trivially_relocatable(S); // expected-error{{incomplete type 'S' used in type trait expression}}
__is_trivially_relocatable(S[]); // expected-error{{incomplete type 'S' used in type trait expression}}
}
16 changes: 16 additions & 0 deletions clang/test/SemaCXX/type-traits-nonobject.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s

// expected-no-diagnostics

static_assert(!__is_pod(void), "");
static_assert(!__is_pod(int&), "");
static_assert(!__is_pod(int()), "");

static_assert(!__is_trivially_copyable(void), "");
static_assert(!__is_trivially_copyable(int&), "");
static_assert(!__is_trivially_copyable(int()), "");

static_assert(!__is_trivially_relocatable(void), "");
static_assert(!__is_trivially_relocatable(int&), "");
static_assert(!__is_trivially_relocatable(int()), "");
2 changes: 1 addition & 1 deletion clang/tools/c-index-test/core_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ static bool printSourceSymbolsFromModule(StringRef modulePath,
CompilerInstance::createDiagnostics(new DiagnosticOptions());
std::unique_ptr<ASTUnit> AU = ASTUnit::LoadFromASTFile(
std::string(modulePath), *pchRdr, ASTUnit::LoadASTOnly, Diags,
FileSystemOpts, HSOpts, /*UseDebugInfo=*/false,
FileSystemOpts, HSOpts,
/*OnlyLocalDecls=*/true, CaptureDiagsKind::None,
/*AllowASTWithCompilerErrors=*/true,
/*UserFilesAreVolatile=*/false);
Expand Down
4 changes: 2 additions & 2 deletions clang/tools/libclang/CIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3877,8 +3877,8 @@ enum CXErrorCode clang_createTranslationUnit2(CXIndex CIdx,
std::unique_ptr<ASTUnit> AU = ASTUnit::LoadFromASTFile(
ast_filename, CXXIdx->getPCHContainerOperations()->getRawReader(),
ASTUnit::LoadEverything, Diags, FileSystemOpts, HSOpts,
/*UseDebugInfo=*/false, CXXIdx->getOnlyLocalDecls(),
CaptureDiagsKind::All, /*AllowASTWithCompilerErrors=*/true,
CXXIdx->getOnlyLocalDecls(), CaptureDiagsKind::All,
/*AllowASTWithCompilerErrors=*/true,
/*UserFilesAreVolatile=*/true);
*out_TU = MakeCXTranslationUnit(CXXIdx, std::move(AU));
return *out_TU ? CXError_Success : CXError_Failure;
Expand Down
3 changes: 1 addition & 2 deletions clang/unittests/Frontend/ASTUnitTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ TEST_F(ASTUnitTest, SaveLoadPreservesLangOptionsInPrintingPolicy) {

std::unique_ptr<ASTUnit> AU = ASTUnit::LoadFromASTFile(
std::string(ASTFileName.str()), PCHContainerOps->getRawReader(),
ASTUnit::LoadEverything, Diags, FileSystemOptions(), HSOpts,
/*UseDebugInfo=*/false);
ASTUnit::LoadEverything, Diags, FileSystemOptions(), HSOpts);

if (!AU)
FAIL() << "failed to load ASTUnit";
Expand Down
5 changes: 4 additions & 1 deletion compiler-rt/lib/sanitizer_common/sanitizer_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,12 @@
#if SANITIZER_WINDOWS64 && SANITIZER_ARM64
# define SANITIZER_WINDOWS_ARM64 1
# define SANITIZER_WINDOWS_x64 0
#else
#elif SANITIZER_WINDOWS64 && !SANITIZER_ARM64
# define SANITIZER_WINDOWS_ARM64 0
# define SANITIZER_WINDOWS_x64 1
#else
# define SANITIZER_WINDOWS_ARM64 0
# define SANITIZER_WINDOWS_x64 0
#endif

#if SANITIZER_SOLARIS && SANITIZER_WORDSIZE == 32
Expand Down
5 changes: 5 additions & 0 deletions libc/docs/dev/api_test.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
========
API Test
========

.. warning::
This page is severely out of date. Much of the information it contains may be
incorrect. Please only remove this warning once the page has been updated.

The implementation of libc-project is unique because our public C header files
are generated using information from ground truth captured in TableGen files.
Unit tests only exercise the internal C++ implementations and don't ensure the
Expand Down
6 changes: 6 additions & 0 deletions libc/docs/dev/clang_tidy_checks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

LLVM libc clang-tidy checks
===========================


.. warning::
This page is severely out of date. Much of the information it contains may be
incorrect. Please only remove this warning once the page has been updated.

These are the clang-tidy checks designed to help enforce implementation
standards.
The configuration file is ``src/.clang-tidy``.
Expand Down
4 changes: 4 additions & 0 deletions libc/docs/dev/header_generation.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Generating Public and Internal headers
======================================

.. warning::
This page is severely out of date. Much of the information it contains may be
incorrect. Please only remove this warning once the page has been updated.

Other libc implementations make use of preprocessor macro tricks to make header
files platform agnostic. When macros aren't suitable, they rely on build
system tricks to pick the right set of files to compile and export. While these
Expand Down
84 changes: 36 additions & 48 deletions libc/docs/dev/implementation_standard.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,81 +5,69 @@ LLVM-libc entrypoints are defined in the entrypoints document. In this document,
we explain how the entrypoints are implemented. The source layout document
explains that, within the high level ``src`` directory, there exists one
directory for every public header file provided by LLVM-libc. The
implementations of related group of entrypoints will also live in a directory of
their own. This directory will have a name indicative of the related group of
entrypoints, and will be under the directory corresponding to the header file of
the entrypoints. For example, functions like ``fopen`` and ``fclose`` cannot be
tested independent of each other and hence will live in a directory named
``src/stdio/file_operations``. On the other hand, the implementation of the
``round`` function from ``math.h`` can be tested by itself, so it will live in
the directory of its own named ``src/math/round/``.
implementations of entrypoints live in the directory for the header they belong
to. Some entrypoints are platform specific, and so their implementations are in
a subdirectory with the name of the platform (e.g. ``stdio/linux/remove.cpp``).

Implementation of entrypoints can span multiple ``.cpp`` and ``.h`` files, but
there will be at least one header file with name of the form
``<entrypoint name>.h`` for every entrypoint. This header file is called as the
implementation header file. For the ``round`` function, the path to the
implementation header file will be ``src/math/round/round.h``. The rest of this
document explains the structure of implementation header files and ``.cpp``
files.
``<entrypoint name>.h`` for every entrypoint. This header file is called the
implementation header file. For the ``isalpha`` function, the path to the
implementation header file is ``src/ctype/isalpha.h``.

Implementation Header File Structure
------------------------------------

We will use the ``round`` function from the public ``math.h`` header file as an
example. The ``round`` function will be declared in an internal header file
``src/math/round/round.h`` as follows::
We will use the ``isalpha`` function from the public ``ctype.h`` header file as an
example. The ``isalpha`` function will be declared in an internal header file
``src/ctype/isalpha.h`` as follows::

// --- round.h --- //
#ifndef LLVM_LIBC_SRC_MATH_ROUND_ROUND_H
#define LLVM_LIBC_SRC_MATH_ROUND_ROUND_H
// --- isalpha.h --- //
#ifndef LLVM_LIBC_SRC_CTYPE_ISALPHA_H
#define LLVM_LIBC_SRC_CTYPE_ISALPHA_H

namespace LIBC_NAMESPACE {

double round(double);
int isalpha(int c);

} // namespace LIBC_NAMESPACE

#endif LLVM_LIBC_SRC_MATH_ROUND_ROUND_H
#endif LLVM_LIBC_SRC_CTYPE_ISALPHA_H

Notice that the ``round`` function declaration is nested inside the namespace
``LIBC_NAMESPACE``. All implementation constructs in LLVM-libc are declared within
the namespace ``LIBC_NAMESPACE``.
Notice that the ``isalpha`` function declaration is nested inside the namespace
``LIBC_NAMESPACE``. All implementation constructs in LLVM-libc are declared
within the namespace ``LIBC_NAMESPACE``.

``.cpp`` File Structure
-----------------------

The implementation can span multiple ``.cpp`` files. However, the signature of
the entrypoint function should make use of a special macro. For example, the
``round`` function from ``math.h`` should be defined as follows, say in the file
``src/math/math/round.cpp``::
The main ``.cpp`` file is named ``<entrypoint name>.cpp`` and is usually in the
same folder as the header. It contains the signature of the entrypoint function,
which must be defined with the ``LLVM_LIBC_FUNCTION`` macro. For example, the
``isalpha`` function from ``ctype.h`` is defined as follows, in the file
``src/ctype/isalpha.cpp``::

// --- round.cpp --- //
// --- isalpha.cpp --- //

namespace LIBC_NAMESPACE {

double LLVM_LIBC_ENTRYPOINT(round)(double d) {
LLVM_LIBC_FUNCTION(int, isalpha, (int c)) {
// ... implementation goes here.
}

} // namespace LIBC_NAMESPACE

Notice the use of the macro ``LLVM_LIBC_ENTRYPOINT``. This macro helps us define
an C alias symbol for the C++ implementation. The C alias need not be added by
the macro by itself. For example, for ELF targets, the macro is defined as
follows::
Notice the use of the macro ``LLVM_LIBC_FUNCTION``. This macro helps us define
a C alias symbol for the C++ implementation. For example, for a library build,
the macro is defined as follows::

#define ENTRYPOINT_SECTION_ATTRIBUTE(name) \
__attribute__((section(".llvm.libc.entrypoint."#name)))
#define LLVM_LIBC_ENTRYPOINT(name) ENTRYPOINT_SECTION_ATTRIBUTE(name) name
#define LLVM_LIBC_FUNCTION(type, name, arglist)
LLVM_LIBC_FUNCTION_IMPL(type, name, arglist)
#define LLVM_LIBC_FUNCTION_IMPL(type, name, arglist)
LLVM_LIBC_FUNCTION_ATTR decltype(LIBC_NAMESPACE::name)
__##name##_impl__ __asm__(#name);
decltype(LIBC_NAMESPACE::name) name [[gnu::alias(#name)]];
type __##name##_impl__ arglist

The macro places the C++ function in a unique section with name
``.llvm.libc.entrypoint.<function name>``. This allows us to add a C alias using
a post build step. For example, for the ``round`` function, one can use
``objcopy`` to add an alias symbol as follows::

objcopy --add-symbol round=.llvm.libc.entrypoint.round:0,function round.o

NOTE: We use a post build ``objcopy`` step to add an alias instead of using
the ``__attribute__((alias))``. For C++, this ``alias`` attribute requires
mangled names of the referees. Using the post build ``objcopy`` step helps
us avoid putting mangled names with ``alias`` attributes.
The LLVM_LIBC_FUNCTION_ATTR macro is normally defined to nothing, but can be
defined by vendors who want to set their own attributes.
Loading

0 comments on commit 14c4d99

Please sign in to comment.