Skip to content

Commit

Permalink
Manually Merged master:308b8b76cee into amd-gfx:4c172c4c298
Browse files Browse the repository at this point in the history
Local branch amd-gfx 4c172c4 Merged master:345f59667d8 into amd-gfx:c7c3b88d580
Remote branch master 308b8b7 [OpenCL] Add builtin function extension handling
  • Loading branch information
Tim Corringham committed Dec 18, 2019
2 parents 4c172c4 + 308b8b7 commit 4b00afd
Show file tree
Hide file tree
Showing 408 changed files with 12,686 additions and 4,735 deletions.
6 changes: 5 additions & 1 deletion clang-tools-extra/clangd/AST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "clang/AST/ASTContext.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclBase.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/AST/DeclarationName.h"
#include "clang/AST/NestedNameSpecifier.h"
Expand Down Expand Up @@ -222,8 +223,11 @@ std::string printName(const ASTContext &Ctx, const NamedDecl &ND) {
// Come up with a presentation for an anonymous entity.
if (isa<NamespaceDecl>(ND))
return "(anonymous namespace)";
if (auto *Cls = llvm::dyn_cast<RecordDecl>(&ND))
if (auto *Cls = llvm::dyn_cast<RecordDecl>(&ND)) {
if (Cls->isLambda())
return "(lambda)";
return ("(anonymous " + Cls->getKindName() + ")").str();
}
if (isa<EnumDecl>(ND))
return "(anonymous enum)";
return "(anonymous)";
Expand Down
38 changes: 23 additions & 15 deletions clang-tools-extra/clangd/Hover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@

#include "clang/AST/ASTContext.h"
#include "clang/AST/ASTTypeTraits.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclBase.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/AST/PrettyPrinter.h"
#include "clang/Index/IndexSymbol.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/raw_ostream.h"

namespace clang {
Expand Down Expand Up @@ -72,12 +76,17 @@ std::string getLocalScope(const Decl *D) {
std::string getNamespaceScope(const Decl *D) {
const DeclContext *DC = D->getDeclContext();

if (const TypeDecl *TD = dyn_cast<TypeDecl>(DC))
if (const TagDecl *TD = dyn_cast<TagDecl>(DC))
return getNamespaceScope(TD);
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(DC))
return getNamespaceScope(FD);
if (const NamespaceDecl *NSD = dyn_cast<NamespaceDecl>(DC)) {
// Skip inline/anon namespaces.
if (NSD->isInline() || NSD->isAnonymousNamespace())
return getNamespaceScope(NSD);
}
if (const NamedDecl *ND = dyn_cast<NamedDecl>(DC))
return ND->getQualifiedNameAsString();
return printQualifiedName(*ND);

return "";
}
Expand Down Expand Up @@ -342,18 +351,22 @@ HoverInfo getHoverContents(const Decl *D, const SymbolIndex *Index) {
}

/// Generate a \p Hover object given the type \p T.
HoverInfo getHoverContents(QualType T, const Decl *D, ASTContext &ASTCtx,
const SymbolIndex *Index) {
HoverInfo getHoverContents(QualType T, ASTContext &ASTCtx,
const SymbolIndex *Index) {
HoverInfo HI;
llvm::raw_string_ostream OS(HI.Name);
PrintingPolicy Policy = printingPolicyForDecls(ASTCtx.getPrintingPolicy());
T.print(OS, Policy);
OS.flush();

if (D) {
if (const auto *D = T->getAsTagDecl()) {
HI.Name = printName(ASTCtx, *D);
HI.Kind = index::getSymbolInfo(D).Kind;
enhanceFromIndex(HI, D, Index);
}

if (HI.Name.empty()) {
// Builtin types
llvm::raw_string_ostream OS(HI.Name);
PrintingPolicy Policy = printingPolicyForDecls(ASTCtx.getPrintingPolicy());
T.print(OS, Policy);
}
return HI;
}

Expand Down Expand Up @@ -396,12 +409,7 @@ llvm::Optional<HoverInfo> getHover(ParsedAST &AST, Position Pos,
getBeginningOfIdentifier(Pos, SM, AST.getLangOpts()));

if (auto Deduced = getDeducedType(AST.getASTContext(), SourceLocationBeg)) {
// Find the corresponding decl to populate kind and fetch documentation.
DeclRelationSet Rel = DeclRelation::TemplatePattern | DeclRelation::Alias;
auto Decls =
targetDecl(ast_type_traits::DynTypedNode::create(*Deduced), Rel);
HI = getHoverContents(*Deduced, Decls.empty() ? nullptr : Decls.front(),
AST.getASTContext(), Index);
HI = getHoverContents(*Deduced, AST.getASTContext(), Index);
} else if (auto M = locateMacroAt(SourceLocationBeg, AST.getPreprocessor())) {
HI = getHoverContents(*M, AST);
} else {
Expand Down
92 changes: 78 additions & 14 deletions clang-tools-extra/clangd/unittests/HoverTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ TEST(Hover, Structured) {
}}
)cpp",
[](HoverInfo &HI) {
HI.NamespaceScope = "ns1::(anonymous)::";
HI.NamespaceScope = "ns1::";
HI.LocalScope = "(anonymous struct)::";
HI.Name = "bar";
HI.Kind = index::SymbolKind::Field;
Expand Down Expand Up @@ -362,7 +362,7 @@ void foo())cpp";
}
)cpp",
[](HoverInfo &HI) {
HI.Name = "class (lambda)";
HI.Name = "(lambda)";
HI.Kind = index::SymbolKind::Class;
}},
// auto on template instantiation
Expand All @@ -373,7 +373,7 @@ void foo())cpp";
}
)cpp",
[](HoverInfo &HI) {
HI.Name = "class Foo<int>";
HI.Name = "Foo<int>";
HI.Kind = index::SymbolKind::Class;
}},
// auto on specialized template
Expand All @@ -385,7 +385,7 @@ void foo())cpp";
}
)cpp",
[](HoverInfo &HI) {
HI.Name = "class Foo<int>";
HI.Name = "Foo<int>";
HI.Kind = index::SymbolKind::Class;
}},

Expand Down Expand Up @@ -524,6 +524,44 @@ void foo())cpp";
HI.NamespaceScope = "";
HI.LocalScope = "boom::";
}},
{
R"cpp(// Should not print inline or anon namespaces.
namespace ns {
inline namespace in_ns {
namespace a {
namespace {
namespace b {
inline namespace in_ns2 {
class Foo {};
} // in_ns2
} // b
} // anon
} // a
} // in_ns
} // ns
void foo() {
ns::a::b::[[F^oo]] x;
(void)x;
}
)cpp",
[](HoverInfo &HI) {
HI.Name = "Foo";
HI.Kind = index::SymbolKind::Class;
HI.NamespaceScope = "ns::a::b::";
HI.Definition = "class Foo {}";
}},
{
R"cpp(
template <typename T> class Foo {};
class X;
void foo() {
[[^auto]] x = Foo<X>();
}
)cpp",
[](HoverInfo &HI) {
HI.Name = "Foo<X>";
HI.Kind = index::SymbolKind::Class;
}},
};
for (const auto &Case : Cases) {
SCOPED_TRACE(Case.Code);
Expand Down Expand Up @@ -895,7 +933,7 @@ TEST(Hover, All) {
[](HoverInfo &HI) {
HI.Name = "foo";
HI.Kind = index::SymbolKind::Variable;
HI.NamespaceScope = "ns::(anonymous)::";
HI.NamespaceScope = "ns::";
HI.Type = "int";
HI.Definition = "int foo";
}},
Expand Down Expand Up @@ -1173,7 +1211,7 @@ TEST(Hover, All) {
}
)cpp",
[](HoverInfo &HI) {
HI.Name = "class std::initializer_list<int>";
HI.Name = "initializer_list<int>";
HI.Kind = index::SymbolKind::Class;
}},
{
Expand Down Expand Up @@ -1231,7 +1269,7 @@ TEST(Hover, All) {
}
)cpp",
[](HoverInfo &HI) {
HI.Name = "struct Bar";
HI.Name = "Bar";
HI.Kind = index::SymbolKind::Struct;
}},
{
Expand All @@ -1242,7 +1280,7 @@ TEST(Hover, All) {
}
)cpp",
[](HoverInfo &HI) {
HI.Name = "struct Bar";
HI.Name = "Bar";
HI.Kind = index::SymbolKind::Struct;
}},
{
Expand All @@ -1253,7 +1291,7 @@ TEST(Hover, All) {
}
)cpp",
[](HoverInfo &HI) {
HI.Name = "struct Bar";
HI.Name = "Bar";
HI.Kind = index::SymbolKind::Struct;
}},
{
Expand All @@ -1265,7 +1303,7 @@ TEST(Hover, All) {
}
)cpp",
[](HoverInfo &HI) {
HI.Name = "struct Bar";
HI.Name = "Bar";
HI.Kind = index::SymbolKind::Struct;
}},
{
Expand All @@ -1277,7 +1315,7 @@ TEST(Hover, All) {
}
)cpp",
[](HoverInfo &HI) {
HI.Name = "struct Bar";
HI.Name = "Bar";
HI.Kind = index::SymbolKind::Struct;
}},
{
Expand All @@ -1289,7 +1327,7 @@ TEST(Hover, All) {
}
)cpp",
[](HoverInfo &HI) {
HI.Name = "struct Bar";
HI.Name = "Bar";
HI.Kind = index::SymbolKind::Struct;
}},
{
Expand All @@ -1300,7 +1338,7 @@ TEST(Hover, All) {
}
)cpp",
[](HoverInfo &HI) {
HI.Name = "struct Bar";
HI.Name = "Bar";
HI.Kind = index::SymbolKind::Struct;
}},
{
Expand Down Expand Up @@ -1364,7 +1402,7 @@ TEST(Hover, All) {
}
)cpp",
[](HoverInfo &HI) {
HI.Name = "struct Bar";
HI.Name = "Bar";
HI.Kind = index::SymbolKind::Struct;
}},
{
Expand Down Expand Up @@ -1396,6 +1434,32 @@ TEST(Hover, All) {
HI.Definition = "struct Test &&test = {}";
HI.Value = "{}";
}},
{
R"cpp(// auto on alias
typedef int int_type;
^[[auto]] x = int_type();
)cpp",
[](HoverInfo &HI) { HI.Name = "int"; }},
{
R"cpp(// auto on alias
struct cls {};
typedef cls cls_type;
^[[auto]] y = cls_type();
)cpp",
[](HoverInfo &HI) {
HI.Name = "cls";
HI.Kind = index::SymbolKind::Struct;
}},
{
R"cpp(// auto on alias
template <class>
struct templ {};
^[[auto]] z = templ<int>();
)cpp",
[](HoverInfo &HI) {
HI.Name = "templ<int>";
HI.Kind = index::SymbolKind::Struct;
}},
};

// Create a tiny index, so tests above can verify documentation is fetched.
Expand Down
73 changes: 73 additions & 0 deletions clang/include/clang/AST/OpenMPClause.h
Original file line number Diff line number Diff line change
Expand Up @@ -6242,6 +6242,79 @@ class OMPIsDevicePtrClause final
}
};

/// This represents clause 'nontemporal' in the '#pragma omp ...' directives.
///
/// \code
/// #pragma omp simd nontemporal(a)
/// \endcode
/// In this example directive '#pragma omp simd' has clause 'nontemporal' for
/// the variable 'a'.
class OMPNontemporalClause final
: public OMPVarListClause<OMPNontemporalClause>,
private llvm::TrailingObjects<OMPNontemporalClause, Expr *> {
friend class OMPClauseReader;
friend OMPVarListClause;
friend TrailingObjects;

/// Build clause with number of variables \a N.
///
/// \param StartLoc Starting location of the clause.
/// \param LParenLoc Location of '('.
/// \param EndLoc Ending location of the clause.
/// \param N Number of the variables in the clause.
OMPNontemporalClause(SourceLocation StartLoc, SourceLocation LParenLoc,
SourceLocation EndLoc, unsigned N)
: OMPVarListClause<OMPNontemporalClause>(OMPC_nontemporal, StartLoc,
LParenLoc, EndLoc, N) {}

/// Build an empty clause.
///
/// \param N Number of variables.
explicit OMPNontemporalClause(unsigned N)
: OMPVarListClause<OMPNontemporalClause>(
OMPC_nontemporal, SourceLocation(), SourceLocation(),
SourceLocation(), N) {}

public:
/// Creates clause with a list of variables \a VL.
///
/// \param C AST context.
/// \param StartLoc Starting location of the clause.
/// \param LParenLoc Location of '('.
/// \param EndLoc Ending location of the clause.
/// \param VL List of references to the variables.
static OMPNontemporalClause *
Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
SourceLocation EndLoc, ArrayRef<Expr *> VL);

/// Creates an empty clause with the place for \a N variables.
///
/// \param C AST context.
/// \param N The number of variables.
static OMPNontemporalClause *CreateEmpty(const ASTContext &C, unsigned N);

child_range children() {
return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
reinterpret_cast<Stmt **>(varlist_end()));
}

const_child_range children() const {
auto Children = const_cast<OMPNontemporalClause *>(this)->children();
return const_child_range(Children.begin(), Children.end());
}

child_range used_children() {
return child_range(child_iterator(), child_iterator());
}
const_child_range used_children() const {
return const_child_range(const_child_iterator(), const_child_iterator());
}

static bool classof(const OMPClause *T) {
return T->getClauseKind() == OMPC_nontemporal;
}
};

/// This class implements a simple visitor for OMPClause
/// subclasses.
template<class ImplClass, template <typename> class Ptr, typename RetTy>
Expand Down
7 changes: 7 additions & 0 deletions clang/include/clang/AST/RecursiveASTVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -3374,6 +3374,13 @@ bool RecursiveASTVisitor<Derived>::VisitOMPIsDevicePtrClause(
return true;
}

template <typename Derived>
bool RecursiveASTVisitor<Derived>::VisitOMPNontemporalClause(
OMPNontemporalClause *C) {
TRY_TO(VisitOMPClauseList(C));
return true;
}

// FIXME: look at the following tricky-seeming exprs to see if we
// need to recurse on anything. These are ones that have methods
// returning decls or qualtypes or nestednamespecifier -- though I'm
Expand Down
Loading

0 comments on commit 4b00afd

Please sign in to comment.