Skip to content

Commit

Permalink
Merge master:0d4d86cbd19 into amd-gfx
Browse files Browse the repository at this point in the history
Change-Id: Iec650a747e3e9bdf3fd12fdd120dc21f864a5805
  • Loading branch information
jayfoad committed May 7, 2020
2 parents e9ce1da + 0d4d86c commit 0aaf507
Show file tree
Hide file tree
Showing 222 changed files with 5,340 additions and 2,679 deletions.
19 changes: 17 additions & 2 deletions clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ using namespace clang::ast_matchers;
namespace clang {
namespace tidy {
namespace bugprone {
namespace {
AST_MATCHER(Decl, isFromStdNamespace) {
if (const auto *D = Node.getDeclContext()->getEnclosingNamespaceContext())
return D->isStdNamespace();
return false;
}
} // namespace

ArgumentCommentCheck::ArgumentCommentCheck(StringRef Name,
ClangTidyContext *Context)
Expand Down Expand Up @@ -54,10 +61,18 @@ void ArgumentCommentCheck::registerMatchers(MatchFinder *Finder) {
// don't check them against NewCallback's parameter names.
// FIXME: Make this configurable.
unless(hasDeclaration(functionDecl(
hasAnyName("NewCallback", "NewPermanentCallback")))))
hasAnyName("NewCallback", "NewPermanentCallback")))),
// Ignore APIs from the standard library, since their names are
// not specified by the standard, and standard library
// implementations in practice have to use reserved names to
// avoid conflicts with same-named macros.
unless(hasDeclaration(isFromStdNamespace())))
.bind("expr"),
this);
Finder->addMatcher(
cxxConstructExpr(unless(hasDeclaration(isFromStdNamespace())))
.bind("expr"),
this);
Finder->addMatcher(cxxConstructExpr().bind("expr"), this);
}

static std::vector<std::pair<SourceLocation, StringRef>>
Expand Down
56 changes: 53 additions & 3 deletions clang-tools-extra/clangd/Headers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "Compiler.h"
#include "SourceCode.h"
#include "support/Logger.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/CompilerInvocation.h"
#include "clang/Frontend/FrontendActions.h"
Expand All @@ -21,6 +23,11 @@ namespace clang {
namespace clangd {
namespace {

bool isMainFile(llvm::StringRef FileName, const SourceManager &SM) {
auto FE = SM.getFileManager().getFile(FileName);
return FE && *FE == SM.getFileEntryForID(SM.getMainFileID());
}

class RecordHeaders : public PPCallbacks {
public:
RecordHeaders(const SourceManager &SM, IncludeStructure *Out)
Expand All @@ -30,11 +37,27 @@ class RecordHeaders : public PPCallbacks {
// in the main file are collected.
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
llvm::StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange, const FileEntry *File,
llvm::StringRef /*SearchPath*/,
CharSourceRange /*FilenameRange*/,
const FileEntry *File, llvm::StringRef /*SearchPath*/,
llvm::StringRef /*RelativePath*/,
const Module * /*Imported*/,
SrcMgr::CharacteristicKind FileKind) override {
auto MainFID = SM.getMainFileID();
// If an include is part of the preamble patch, translate #line directives.
if (InBuiltinFile) {
auto Presumed = SM.getPresumedLoc(HashLoc);
// Presumed locations will have an invalid file id when #line directive
// changes the filename.
if (Presumed.getFileID().isInvalid() &&
isMainFile(Presumed.getFilename(), SM)) {
// Now we'll hit the case below.
HashLoc = SM.translateLineCol(MainFID, Presumed.getLine(),
Presumed.getColumn());
}
}

// Record main-file inclusions (including those mapped from the preamble
// patch).
if (isInsideMainFile(HashLoc, SM)) {
Out->MainFileIncludes.emplace_back();
auto &Inc = Out->MainFileIncludes.back();
Expand All @@ -47,21 +70,48 @@ class RecordHeaders : public PPCallbacks {
Inc.FileKind = FileKind;
Inc.Directive = IncludeTok.getIdentifierInfo()->getPPKeywordID();
}

// Record include graph (not just for main-file includes)
if (File) {
auto *IncludingFileEntry = SM.getFileEntryForID(SM.getFileID(HashLoc));
if (!IncludingFileEntry) {
assert(SM.getBufferName(HashLoc).startswith("<") &&
"Expected #include location to be a file or <built-in>");
// Treat as if included from the main file.
IncludingFileEntry = SM.getFileEntryForID(SM.getMainFileID());
IncludingFileEntry = SM.getFileEntryForID(MainFID);
}
Out->recordInclude(IncludingFileEntry->getName(), File->getName(),
File->tryGetRealPathName());
}
}

void FileChanged(SourceLocation Loc, FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType,
FileID PrevFID) override {
switch (Reason) {
case PPCallbacks::EnterFile:
if (BuiltinFile.isInvalid() && SM.isWrittenInBuiltinFile(Loc)) {
BuiltinFile = SM.getFileID(Loc);
InBuiltinFile = true;
}
break;
case PPCallbacks::ExitFile:
if (PrevFID == BuiltinFile)
InBuiltinFile = false;
break;
case PPCallbacks::RenameFile:
case PPCallbacks::SystemHeaderPragma:
break;
}
}

private:
const SourceManager &SM;
// Set after entering the <built-in> file.
FileID BuiltinFile;
// Indicates whether <built-in> file is part of include stack.
bool InBuiltinFile = false;

IncludeStructure *Out;
};

Expand Down
24 changes: 24 additions & 0 deletions clang-tools-extra/clangd/unittests/HeadersTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "clang/Frontend/CompilerInvocation.h"
#include "clang/Frontend/FrontendActions.h"
#include "clang/Lex/PreprocessorOptions.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/Path.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
Expand All @@ -25,7 +26,9 @@ namespace clangd {
namespace {

using ::testing::AllOf;
using ::testing::Contains;
using ::testing::ElementsAre;
using ::testing::Not;
using ::testing::UnorderedElementsAre;

class HeadersTest : public ::testing::Test {
Expand Down Expand Up @@ -302,6 +305,27 @@ TEST(Headers, NoHeaderSearchInfo) {
llvm::None);
}

TEST_F(HeadersTest, PresumedLocations) {
std::string HeaderFile = "implicit_include.h";

// Line map inclusion back to main file.
std::string HeaderContents =
llvm::formatv("#line 0 \"{0}\"", llvm::sys::path::filename(MainFile));
HeaderContents += R"cpp(
#line 3
#include <a.h>)cpp";
FS.Files[HeaderFile] = HeaderContents;

// Including through non-builtin file has no effects.
FS.Files[MainFile] = "#include \"implicit_include.h\"\n\n";
EXPECT_THAT(collectIncludes().MainFileIncludes,
Not(Contains(Written("<a.h>"))));

// Now include through built-in file.
CDB.ExtraClangFlags = {"-include", testPath(HeaderFile)};
EXPECT_THAT(collectIncludes().MainFileIncludes,
Contains(AllOf(IncludeLine(2), Written("<a.h>"))));
}
} // namespace
} // namespace clangd
} // namespace clang
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,22 @@ void g() { f6(/*xxy=*/0, 0); }
// CHECK-NOTES: [[@LINE-3]]:13: note: 'xxx' declared here
// CHECK-FIXES: void g() { f6(/*xxy=*/0, 0); }
}


namespace std {
template <typename T>
class vector {
public:
void assign(int __n, const T &__val);
};
template<typename T>
void swap(T& __a, T& __b);
} // namespace std
namespace ignore_std_functions {
void test(int a, int b) {
std::vector<int> s;
// verify the check is not fired on std functions.
s.assign(1, /*value=*/2);
std::swap(a, /*num=*/b);
}
} // namespace ignore_std_functions
72 changes: 41 additions & 31 deletions clang/cmake/modules/AddClang.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ endmacro()

macro(add_clang_library name)
cmake_parse_arguments(ARG
"SHARED;INSTALL_WITH_TOOLCHAIN"
"SHARED;STATIC;INSTALL_WITH_TOOLCHAIN"
""
"ADDITIONAL_HEADERS"
${ARGN})
Expand Down Expand Up @@ -81,7 +81,10 @@ macro(add_clang_library name)
${ARG_ADDITIONAL_HEADERS} # It may contain unparsed unknown args.
)
endif()
if(ARG_SHARED)

if(ARG_SHARED AND ARG_STATIC)
set(LIBTYPE SHARED STATIC)
elseif(ARG_SHARED)
set(LIBTYPE SHARED)
else()
# llvm_add_library ignores BUILD_SHARED_LIBS if STATIC is explicitly set,
Expand All @@ -99,38 +102,45 @@ macro(add_clang_library name)
endif()
llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs})

if(TARGET ${name})
target_link_libraries(${name} INTERFACE ${LLVM_COMMON_LIBS})

if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ARG_INSTALL_WITH_TOOLCHAIN)
set(export_to_clangtargets)
if(${name} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
"clang-libraries" IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
NOT LLVM_DISTRIBUTION_COMPONENTS)
set(export_to_clangtargets EXPORT ClangTargets)
set_property(GLOBAL PROPERTY CLANG_HAS_EXPORTS True)
endif()
set(libs ${name})
if(ARG_SHARED AND ARG_STATIC)
list(APPEND libs ${name}_static)
endif()

install(TARGETS ${name}
COMPONENT ${name}
${export_to_clangtargets}
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}
RUNTIME DESTINATION bin)

if (NOT LLVM_ENABLE_IDE)
add_llvm_install_targets(install-${name}
DEPENDS ${name}
COMPONENT ${name})
foreach(lib ${libs})
if(TARGET ${lib})
target_link_libraries(${lib} INTERFACE ${LLVM_COMMON_LIBS})

if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ARG_INSTALL_WITH_TOOLCHAIN)
set(export_to_clangtargets)
if(${lib} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
"clang-libraries" IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
NOT LLVM_DISTRIBUTION_COMPONENTS)
set(export_to_clangtargets EXPORT ClangTargets)
set_property(GLOBAL PROPERTY CLANG_HAS_EXPORTS True)
endif()

install(TARGETS ${lib}
COMPONENT ${lib}
${export_to_clangtargets}
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}
RUNTIME DESTINATION bin)

if (NOT LLVM_ENABLE_IDE)
add_llvm_install_targets(install-${lib}
DEPENDS ${lib}
COMPONENT ${lib})
endif()

set_property(GLOBAL APPEND PROPERTY CLANG_LIBS ${lib})
endif()

set_property(GLOBAL APPEND PROPERTY CLANG_LIBS ${name})
set_property(GLOBAL APPEND PROPERTY CLANG_EXPORTS ${lib})
else()
# Add empty "phony" target
add_custom_target(${lib})
endif()
set_property(GLOBAL APPEND PROPERTY CLANG_EXPORTS ${name})
else()
# Add empty "phony" target
add_custom_target(${name})
endif()
endforeach()

set_target_properties(${name} PROPERTIES FOLDER "Clang libraries")
set_clang_windows_version_resource_properties(${name})
Expand Down
13 changes: 13 additions & 0 deletions clang/docs/ClangFormatStyleOptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2336,6 +2336,19 @@ the configuration (without a prefix: ``Auto``).
}
}

* ``SBPO_ControlStatementsExceptForEachMacros`` (in configuration: ``ControlStatementsExceptForEachMacros``)
Same as ``SBPO_ControlStatements`` except this option doesn't apply to
ForEach macros. This is useful in projects where ForEach macros are
treated as function calls instead of control statements.

.. code-block:: c++

void f() {
Q_FOREACH(...) {
f();
}
}

* ``SBPO_NonEmptyParentheses`` (in configuration: ``NonEmptyParentheses``)
Put a space before opening parentheses only if the parentheses are not
empty i.e. '()'
Expand Down
32 changes: 26 additions & 6 deletions clang/docs/LanguageExtensions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3173,16 +3173,36 @@ at the start of a compound statement (excluding comments). When using within a
compound statement, the pragma is active within the scope of the compound
statement.
Currently, only FP contraction can be controlled with the pragma. ``#pragma
clang fp contract`` specifies whether the compiler should contract a multiply
and an addition (or subtraction) into a fused FMA operation when supported by
the target.
Currently, the following settings can be controlled with this pragma:
``#pragma clang fp reassociate`` allows control over the reassociation
of floating point expressions. When enabled, this pragma allows the expression
``x + (y + z)`` to be reassociated as ``(x + y) + z``.
Reassociation can also occur across multiple statements.
This pragma can be used to disable reassociation when it is otherwise
enabled for the translation unit with the ``-fassociative-math`` flag.
The pragma can take two values: ``on`` and ``off``.
.. code-block:: c++
float f(float x, float y, float z)
{
// Enable floating point reassociation across statements
#pragma fp reassociate(on)
float t = x + y;
float v = t + z;
}
``#pragma clang fp contract`` specifies whether the compiler should
contract a multiply and an addition (or subtraction) into a fused FMA
operation when supported by the target.
The pragma can take three values: ``on``, ``fast`` and ``off``. The ``on``
option is identical to using ``#pragma STDC FP_CONTRACT(ON)`` and it allows
fusion as specified the language standard. The ``fast`` option allows fusiong
fusion as specified the language standard. The ``fast`` option allows fusion
in cases when the language standard does not make this possible (e.g. across
statements in C)
statements in C).
.. code-block:: c++
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/Attr.td
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ def XRayLogArgs : InheritableAttr {

def PatchableFunctionEntry
: InheritableAttr,
TargetSpecificAttr<TargetArch<["aarch64", "x86", "x86_64"]>> {
TargetSpecificAttr<TargetArch<["aarch64", "aarch64_be", "x86", "x86_64"]>> {
let Spellings = [GCC<"patchable_function_entry">];
let Subjects = SubjectList<[Function, ObjCMethod]>;
let Args = [UnsignedArgument<"Count">, DefaultIntArgument<"Offset", 0>];
Expand Down
5 changes: 4 additions & 1 deletion clang/include/clang/Basic/BuiltinsNVPTX.def
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
#pragma push_macro("PTX63")
#pragma push_macro("PTX64")
#pragma push_macro("PTX65")
#define PTX65 "ptx65"
#pragma push_macro("PTX70")
#define PTX70 "ptx70"
#define PTX65 "ptx65|" PTX70
#define PTX64 "ptx64|" PTX65
#define PTX63 "ptx63|" PTX64
#define PTX61 "ptx61|" PTX63
Expand Down Expand Up @@ -731,3 +733,4 @@ TARGET_BUILTIN(__imma_m8n8k32_st_c_i32, "vi*iC*UiIi", "", AND(SM_75,PTX63))
#pragma pop_macro("PTX63")
#pragma pop_macro("PTX64")
#pragma pop_macro("PTX65")
#pragma pop_macro("PTX70")
Loading

0 comments on commit 0aaf507

Please sign in to comment.