Skip to content

Commit

Permalink
Merged main:4c8c6368710e into amd-gfx:b0130cb8e30b
Browse files Browse the repository at this point in the history
Local branch amd-gfx b0130cb Merged main:09d0e7a7c153 into amd-gfx:e73e167c66fb
Remote branch main 4c8c636 [test] Cleanup some CGSCCPassManager tests
  • Loading branch information
Sw authored and Sw committed Dec 17, 2020
2 parents b0130cb + 4c8c636 commit f590b57
Show file tree
Hide file tree
Showing 47 changed files with 1,180 additions and 84 deletions.
17 changes: 17 additions & 0 deletions clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "llvm/Support/Debug.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MemoryBufferRef.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/YAMLTraits.h"
#include "llvm/Support/raw_ostream.h"
Expand Down Expand Up @@ -390,6 +391,22 @@ parseConfiguration(llvm::MemoryBufferRef Config) {
return Options;
}

static void diagHandlerImpl(const llvm::SMDiagnostic &Diag, void *Ctx) {
(*reinterpret_cast<DiagCallback *>(Ctx))(Diag);
};

llvm::ErrorOr<ClangTidyOptions>
parseConfigurationWithDiags(llvm::MemoryBufferRef Config,
DiagCallback Handler) {
llvm::yaml::Input Input(Config, nullptr, Handler ? diagHandlerImpl : nullptr,
&Handler);
ClangTidyOptions Options;
Input >> Options;
if (Input.error())
return Input.error();
return Options;
}

std::string configurationAsText(const ClangTidyOptions &Options) {
std::string Text;
llvm::raw_string_ostream Stream(Text);
Expand Down
6 changes: 6 additions & 0 deletions clang-tools-extra/clang-tidy/ClangTidyOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/MemoryBufferRef.h"
#include "llvm/Support/VirtualFileSystem.h"
#include <functional>
#include <string>
Expand Down Expand Up @@ -311,6 +312,11 @@ std::error_code parseLineFilter(llvm::StringRef LineFilter,
llvm::ErrorOr<ClangTidyOptions>
parseConfiguration(llvm::MemoryBufferRef Config);

using DiagCallback = llvm::function_ref<void(const llvm::SMDiagnostic &)>;

llvm::ErrorOr<ClangTidyOptions>
parseConfigurationWithDiags(llvm::MemoryBufferRef Config, DiagCallback Handler);

/// Serializes configuration to a YAML-encoded string.
std::string configurationAsText(const ClangTidyOptions &Options);

Expand Down
1 change: 1 addition & 0 deletions clang-tools-extra/unittests/clang-tidy/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
set(LLVM_LINK_COMPONENTS
FrontendOpenMP
Support
TestingSupport
)

get_filename_component(CLANG_LINT_SOURCE_DIR
Expand Down
97 changes: 97 additions & 0 deletions clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#include "ClangTidyCheck.h"
#include "ClangTidyDiagnosticConsumer.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/ScopedPrinter.h"
#include "llvm/Testing/Support/Annotations.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"

namespace clang {
Expand Down Expand Up @@ -123,6 +126,100 @@ TEST(ParseConfiguration, MergeConfigurations) {
EXPECT_TRUE(*Options.UseColor);
}

namespace {
class DiagCollecter {
public:
struct Diag {
private:
static size_t posToOffset(const llvm::SMLoc Loc,
const llvm::SourceMgr *Src) {
return Loc.getPointer() -
Src->getMemoryBuffer(Src->FindBufferContainingLoc(Loc))
->getBufferStart();
}

public:
Diag(const llvm::SMDiagnostic &D)
: Message(D.getMessage()), Kind(D.getKind()),
Pos(posToOffset(D.getLoc(), D.getSourceMgr())) {
if (!D.getRanges().empty()) {
// Ranges are stored as column numbers on the line that has the error.
unsigned Offset = Pos - D.getColumnNo();
Range.emplace();
Range->Begin = Offset + D.getRanges().front().first,
Range->End = Offset + D.getRanges().front().second;
}
}
std::string Message;
llvm::SourceMgr::DiagKind Kind;
size_t Pos;
Optional<llvm::Annotations::Range> Range;

friend void PrintTo(const Diag &D, std::ostream *OS) {
*OS << (D.Kind == llvm::SourceMgr::DK_Error ? "error: " : "warning: ")
<< D.Message << "@" << llvm::to_string(D.Pos);
if (D.Range)
*OS << ":[" << D.Range->Begin << ", " << D.Range->End << ")";
}
};

DiagCollecter() = default;
DiagCollecter(const DiagCollecter &) = delete;

std::function<void(const llvm::SMDiagnostic &)>
getCallback(bool Clear = true) & {
if (Clear)
Diags.clear();
return [&](const llvm::SMDiagnostic &Diag) { Diags.emplace_back(Diag); };
}

std::function<void(const llvm::SMDiagnostic &)>
getCallback(bool Clear = true) && = delete;

llvm::ArrayRef<Diag> getDiags() const { return Diags; }

private:
std::vector<Diag> Diags;
};

MATCHER_P(DiagMessage, M, "") { return arg.Message == M; }
MATCHER_P(DiagKind, K, "") { return arg.Kind == K; }
MATCHER_P(DiagPos, P, "") { return arg.Pos == P; }
MATCHER_P(DiagRange, P, "") { return arg.Range && *arg.Range == P; }
} // namespace

using ::testing::AllOf;
using ::testing::ElementsAre;

TEST(ParseConfiguration, CollectDiags) {
DiagCollecter Collector;
auto ParseWithDiags = [&](llvm::StringRef Buffer) {
return parseConfigurationWithDiags(llvm::MemoryBufferRef(Buffer, "Options"),
Collector.getCallback());
};
llvm::Annotations Options(R"(
[[Check]]: llvm-include-order
)");
llvm::ErrorOr<ClangTidyOptions> ParsedOpt = ParseWithDiags(Options.code());
EXPECT_TRUE(!ParsedOpt);
EXPECT_THAT(Collector.getDiags(),
testing::ElementsAre(AllOf(DiagMessage("unknown key 'Check'"),
DiagKind(llvm::SourceMgr::DK_Error),
DiagPos(Options.range().Begin),
DiagRange(Options.range()))));

Options = llvm::Annotations(R"(
UseColor: [[NotABool]]
)");
ParsedOpt = ParseWithDiags(Options.code());
EXPECT_TRUE(!ParsedOpt);
EXPECT_THAT(Collector.getDiags(),
testing::ElementsAre(AllOf(DiagMessage("invalid boolean"),
DiagKind(llvm::SourceMgr::DK_Error),
DiagPos(Options.range().Begin),
DiagRange(Options.range()))));
}

namespace {
class TestCheck : public ClangTidyCheck {
public:
Expand Down
5 changes: 5 additions & 0 deletions clang/docs/LibASTMatchersReference.html
Original file line number Diff line number Diff line change
Expand Up @@ -1704,6 +1704,11 @@ <h2 id="decl-matchers">Node Matchers</h2>
</pre></td></tr>


<tr><td>Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('genericSelectionExpr0')"><a name="genericSelectionExpr0Anchor">genericSelectionExpr</a></td><td>Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1GenericSelectionExpr.html">GenericSelectionExpr</a>&gt;...</td></tr>
<tr><td colspan="4" class="doc" id="genericSelectionExpr0"><pre>Matches C11 _Generic expression.
</pre></td></tr>


<tr><td>Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('gnuNullExpr0')"><a name="gnuNullExpr0Anchor">gnuNullExpr</a></td><td>Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1GNUNullExpr.html">GNUNullExpr</a>&gt;...</td></tr>
<tr><td colspan="4" class="doc" id="gnuNullExpr0"><pre>Matches GNU __null expression.
</pre></td></tr>
Expand Down
4 changes: 4 additions & 0 deletions clang/include/clang/ASTMatchers/ASTMatchers.h
Original file line number Diff line number Diff line change
Expand Up @@ -2362,6 +2362,10 @@ extern const internal::VariadicDynCastAllOfMatcher<Stmt, ChooseExpr>
extern const internal::VariadicDynCastAllOfMatcher<Stmt, GNUNullExpr>
gnuNullExpr;

/// Matches C11 _Generic expression.
extern const internal::VariadicDynCastAllOfMatcher<Stmt, GenericSelectionExpr>
genericSelectionExpr;

/// Matches atomic builtins.
/// Example matches __atomic_load_n(ptr, 1)
/// \code
Expand Down
37 changes: 36 additions & 1 deletion clang/lib/AST/ASTImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ namespace clang {
ExpectedStmt VisitVAArgExpr(VAArgExpr *E);
ExpectedStmt VisitChooseExpr(ChooseExpr *E);
ExpectedStmt VisitGNUNullExpr(GNUNullExpr *E);
ExpectedStmt VisitGenericSelectionExpr(GenericSelectionExpr *E);
ExpectedStmt VisitPredefinedExpr(PredefinedExpr *E);
ExpectedStmt VisitDeclRefExpr(DeclRefExpr *E);
ExpectedStmt VisitImplicitValueInitExpr(ImplicitValueInitExpr *E);
Expand Down Expand Up @@ -6526,6 +6527,40 @@ ExpectedStmt ASTNodeImporter::VisitGNUNullExpr(GNUNullExpr *E) {
return new (Importer.getToContext()) GNUNullExpr(*TypeOrErr, *BeginLocOrErr);
}

ExpectedStmt
ASTNodeImporter::VisitGenericSelectionExpr(GenericSelectionExpr *E) {
Error Err = Error::success();
auto ToGenericLoc = importChecked(Err, E->getGenericLoc());
auto *ToControllingExpr = importChecked(Err, E->getControllingExpr());
auto ToDefaultLoc = importChecked(Err, E->getDefaultLoc());
auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
if (Err)
return std::move(Err);

ArrayRef<const TypeSourceInfo *> FromAssocTypes(E->getAssocTypeSourceInfos());
SmallVector<TypeSourceInfo *, 1> ToAssocTypes(FromAssocTypes.size());
if (Error Err = ImportContainerChecked(FromAssocTypes, ToAssocTypes))
return std::move(Err);

ArrayRef<const Expr *> FromAssocExprs(E->getAssocExprs());
SmallVector<Expr *, 1> ToAssocExprs(FromAssocExprs.size());
if (Error Err = ImportContainerChecked(FromAssocExprs, ToAssocExprs))
return std::move(Err);

const ASTContext &ToCtx = Importer.getToContext();
if (E->isResultDependent()) {
return GenericSelectionExpr::Create(
ToCtx, ToGenericLoc, ToControllingExpr,
llvm::makeArrayRef(ToAssocTypes), llvm::makeArrayRef(ToAssocExprs),
ToDefaultLoc, ToRParenLoc, E->containsUnexpandedParameterPack());
}

return GenericSelectionExpr::Create(
ToCtx, ToGenericLoc, ToControllingExpr, llvm::makeArrayRef(ToAssocTypes),
llvm::makeArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
E->containsUnexpandedParameterPack(), E->getResultIndex());
}

ExpectedStmt ASTNodeImporter::VisitPredefinedExpr(PredefinedExpr *E) {

Error Err = Error::success();
Expand Down Expand Up @@ -8223,7 +8258,7 @@ Expected<Decl *> ASTImporter::Import(Decl *FromD) {
return make_error<ImportError>(*Error);
}

// If FromD has some updated flags after last import, apply it
// If FromD has some updated flags after last import, apply it.
updateFlags(FromD, ToD);
// If we encounter a cycle during an import then we save the relevant part
// of the import path associated to the Decl.
Expand Down
18 changes: 18 additions & 0 deletions clang/lib/AST/ASTStructuralEquivalence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,24 @@ class StmtComparer {
return E1->isExact() == E2->isExact() && E1->getValue() == E2->getValue();
}

bool IsStmtEquivalent(const GenericSelectionExpr *E1,
const GenericSelectionExpr *E2) {
for (auto Pair : zip_longest(E1->getAssocTypeSourceInfos(),
E2->getAssocTypeSourceInfos())) {
Optional<TypeSourceInfo *> Child1 = std::get<0>(Pair);
Optional<TypeSourceInfo *> Child2 = std::get<1>(Pair);
// Skip this case if there are a different number of associated types.
if (!Child1 || !Child2)
return false;

if (!IsStructurallyEquivalent(Context, (*Child1)->getType(),
(*Child2)->getType()))
return false;
}

return true;
}

bool IsStmtEquivalent(const ImplicitCastExpr *CastE1,
const ImplicitCastExpr *CastE2) {
return IsStructurallyEquivalent(Context, CastE1->getType(),
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/ASTMatchers/ASTMatchersInternal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,8 @@ const internal::VariadicDynCastAllOfMatcher<Stmt, CXXNullPtrLiteralExpr>
cxxNullPtrLiteralExpr;
const internal::VariadicDynCastAllOfMatcher<Stmt, ChooseExpr> chooseExpr;
const internal::VariadicDynCastAllOfMatcher<Stmt, GNUNullExpr> gnuNullExpr;
const internal::VariadicDynCastAllOfMatcher<Stmt, GenericSelectionExpr>
genericSelectionExpr;
const internal::VariadicDynCastAllOfMatcher<Stmt, AtomicExpr> atomicExpr;
const internal::VariadicDynCastAllOfMatcher<Stmt, StmtExpr> stmtExpr;
const internal::VariadicDynCastAllOfMatcher<Stmt, BinaryOperator>
Expand Down
1 change: 1 addition & 0 deletions clang/lib/ASTMatchers/Dynamic/Registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ RegistryMaps::RegistryMaps() {
REGISTER_MATCHER(functionProtoType);
REGISTER_MATCHER(functionTemplateDecl);
REGISTER_MATCHER(functionType);
REGISTER_MATCHER(genericSelectionExpr);
REGISTER_MATCHER(gnuNullExpr);
REGISTER_MATCHER(gotoStmt);
REGISTER_MATCHER(has);
Expand Down
4 changes: 0 additions & 4 deletions clang/lib/Analysis/ExprMutationAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,6 @@ AST_MATCHER(CXXTypeidExpr, isPotentiallyEvaluated) {
return Node.isPotentiallyEvaluated();
}

const ast_matchers::internal::VariadicDynCastAllOfMatcher<Stmt,
GenericSelectionExpr>
genericSelectionExpr;

AST_MATCHER_P(GenericSelectionExpr, hasControllingExpr,
ast_matchers::internal::Matcher<Expr>, InnerMatcher) {
return InnerMatcher.matches(*Node.getControllingExpr(), Finder, Builder);
Expand Down
6 changes: 6 additions & 0 deletions clang/test/ASTMerge/generic-selection-expr/Inputs/generic.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
void f() {
int x;
float y;
_Static_assert(_Generic(x, float : 0, int : 1), "Incorrect semantics of _Generic");
_Static_assert(_Generic(y, float : 1, int : 0), "Incorrect semantics of _Generic");
}
5 changes: 5 additions & 0 deletions clang/test/ASTMerge/generic-selection-expr/Inputs/generic.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
template <typename T>
void f() {
T x;
_Static_assert(_Generic(x, float : 0, int : 1), "Incorrect semantics of _Generic");
}
3 changes: 3 additions & 0 deletions clang/test/ASTMerge/generic-selection-expr/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// RUN: %clang_cc1 -std=c11 -emit-pch -o %t.ast %S/Inputs/generic.c
// RUN: %clang_cc1 -std=c11 -ast-merge %t.ast -fsyntax-only -verify %s
// expected-no-diagnostics
3 changes: 3 additions & 0 deletions clang/test/ASTMerge/generic-selection-expr/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// RUN: %clang_cc1 -std=c++03 -emit-pch -o %t.ast %S/Inputs/generic.cpp
// RUN: %clang_cc1 -std=c++03 -ast-merge %t.ast -fsyntax-only -verify %s
// expected-no-diagnostics
39 changes: 39 additions & 0 deletions clang/unittests/AST/ASTImporterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,15 @@ TEST_P(ImportExpr, ImportGNUNullExpr) {
functionDecl(hasDescendant(gnuNullExpr(hasType(isInteger())))));
}

TEST_P(ImportExpr, ImportGenericSelectionExpr) {
MatchVerifier<Decl> Verifier;

testImport(
"void declToImport() { int x; (void)_Generic(x, int: 0, float: 1); }",
Lang_C99, "", Lang_C99, Verifier,
functionDecl(hasDescendant(genericSelectionExpr())));
}

TEST_P(ImportExpr, ImportCXXNullPtrLiteralExpr) {
MatchVerifier<Decl> Verifier;
testImport(
Expand Down Expand Up @@ -1087,6 +1096,36 @@ TEST_P(ASTImporterOptionSpecificTestBase, ImportChooseExpr) {
ToChooseExpr->isConditionDependent());
}

TEST_P(ASTImporterOptionSpecificTestBase, ImportGenericSelectionExpr) {
Decl *From, *To;
std::tie(From, To) = getImportedDecl(
R"(
int declToImport() {
int x;
return _Generic(x, int: 0, default: 1);
}
)",
Lang_C99, "", Lang_C99);

auto ToResults =
match(genericSelectionExpr().bind("expr"), To->getASTContext());
auto FromResults =
match(genericSelectionExpr().bind("expr"), From->getASTContext());

const GenericSelectionExpr *FromGenericSelectionExpr =
selectFirst<GenericSelectionExpr>("expr", FromResults);
ASSERT_TRUE(FromGenericSelectionExpr);

const GenericSelectionExpr *ToGenericSelectionExpr =
selectFirst<GenericSelectionExpr>("expr", ToResults);
ASSERT_TRUE(ToGenericSelectionExpr);

EXPECT_EQ(FromGenericSelectionExpr->isResultDependent(),
ToGenericSelectionExpr->isResultDependent());
EXPECT_EQ(FromGenericSelectionExpr->getResultIndex(),
ToGenericSelectionExpr->getResultIndex());
}

TEST_P(ASTImporterOptionSpecificTestBase,
ImportFunctionWithBackReferringParameter) {
Decl *From, *To;
Expand Down
Loading

0 comments on commit f590b57

Please sign in to comment.