Skip to content

Commit

Permalink
Merged main:fa2fe9608c1c into amd-gfx:8eff8b2c9df5
Browse files Browse the repository at this point in the history
Local branch amd-gfx 8eff8b2 Merged main:d58512b2e31a into amd-gfx:56124e34625d
Remote branch main fa2fe96 [clang][cli] Port more CodeGenOptions to marshalling infrastructure
  • Loading branch information
Sw authored and Sw committed Jan 14, 2021
2 parents 8eff8b2 + fa2fe96 commit 978a610
Show file tree
Hide file tree
Showing 30 changed files with 548 additions and 370 deletions.
8 changes: 4 additions & 4 deletions clang-tools-extra/clangd/CollectMacros.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
namespace clang {
namespace clangd {

void CollectMainFileMacros::add(const Token &MacroNameTok,
const MacroInfo *MI) {
void CollectMainFileMacros::add(const Token &MacroNameTok, const MacroInfo *MI,
bool IsDefinition) {
if (!InMainFile)
return;
auto Loc = MacroNameTok.getLocation();
Expand All @@ -26,9 +26,9 @@ void CollectMainFileMacros::add(const Token &MacroNameTok,
auto Range = halfOpenToRange(
SM, CharSourceRange::getCharRange(Loc, MacroNameTok.getEndLoc()));
if (auto SID = getSymbolID(Name, MI, SM))
Out.MacroRefs[SID].push_back(Range);
Out.MacroRefs[SID].push_back({Range, IsDefinition});
else
Out.UnknownMacros.push_back(Range);
Out.UnknownMacros.push_back({Range, IsDefinition});
}
} // namespace clangd
} // namespace clang
18 changes: 12 additions & 6 deletions clang-tools-extra/clangd/CollectMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,20 @@
namespace clang {
namespace clangd {

struct MainFileMacros {
llvm::StringSet<> Names;
struct MacroOccurrence {
// Instead of storing SourceLocation, we have to store the token range because
// SourceManager from preamble is not available when we build the AST.
llvm::DenseMap<SymbolID, std::vector<Range>> MacroRefs;
Range Rng;
bool IsDefinition;
};

struct MainFileMacros {
llvm::StringSet<> Names;
llvm::DenseMap<SymbolID, std::vector<MacroOccurrence>> MacroRefs;
// Somtimes it is not possible to compute the SymbolID for the Macro, e.g. a
// reference to an undefined macro. Store them separately, e.g. for semantic
// highlighting.
std::vector<Range> UnknownMacros;
std::vector<MacroOccurrence> UnknownMacros;
// Ranges skipped by the preprocessor due to being inactive.
std::vector<Range> SkippedRanges;
};
Expand All @@ -49,7 +54,7 @@ class CollectMainFileMacros : public PPCallbacks {
}

void MacroDefined(const Token &MacroName, const MacroDirective *MD) override {
add(MacroName, MD->getMacroInfo());
add(MacroName, MD->getMacroInfo(), /*IsDefinition=*/true);
}

void MacroExpands(const Token &MacroName, const MacroDefinition &MD,
Expand Down Expand Up @@ -87,7 +92,8 @@ class CollectMainFileMacros : public PPCallbacks {
}

private:
void add(const Token &MacroNameTok, const MacroInfo *MI);
void add(const Token &MacroNameTok, const MacroInfo *MI,
bool IsDefinition = false);
const SourceManager &SM;
bool InMainFile = true;
MainFileMacros &Out;
Expand Down
4 changes: 2 additions & 2 deletions clang-tools-extra/clangd/SemanticHighlighting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,10 @@ std::vector<HighlightingToken> getSemanticHighlightings(ParsedAST &AST) {
// Add highlightings for macro references.
for (const auto &SIDToRefs : AST.getMacros().MacroRefs) {
for (const auto &M : SIDToRefs.second)
Builder.addToken({HighlightingKind::Macro, M});
Builder.addToken({HighlightingKind::Macro, M.Rng});
}
for (const auto &M : AST.getMacros().UnknownMacros)
Builder.addToken({HighlightingKind::Macro, M});
Builder.addToken({HighlightingKind::Macro, M.Rng});

return std::move(Builder).collect(AST);
}
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/XRefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,7 @@ ReferencesResult findReferences(ParsedAST &AST, Position Pos, uint32_t Limit,
if (Refs != IDToRefs.end()) {
for (const auto &Ref : Refs->second) {
Location Result;
Result.range = Ref;
Result.range = Ref.Rng;
Result.uri = URIMainFile;
Results.References.push_back(std::move(Result));
}
Expand Down
21 changes: 18 additions & 3 deletions clang-tools-extra/clangd/index/SymbolCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,16 +386,31 @@ void SymbolCollector::handleMacros(const MainFileMacros &MacroRefsToIndex) {
const auto MainFileURI = toURI(SM, MainFileEntry->getName(), Opts);
// Add macro references.
for (const auto &IDToRefs : MacroRefsToIndex.MacroRefs) {
for (const auto &Range : IDToRefs.second) {
for (const auto &MacroRef : IDToRefs.second) {
const auto &Range = MacroRef.Rng;
bool IsDefinition = MacroRef.IsDefinition;
Ref R;
R.Location.Start.setLine(Range.start.line);
R.Location.Start.setColumn(Range.start.character);
R.Location.End.setLine(Range.end.line);
R.Location.End.setColumn(Range.end.character);
R.Location.FileURI = MainFileURI.c_str();
// FIXME: Add correct RefKind information to MainFileMacros.
R.Kind = RefKind::Reference;
R.Kind = IsDefinition ? RefKind::Definition : RefKind::Reference;
Refs.insert(IDToRefs.first, R);
if (IsDefinition) {
Symbol S;
S.ID = IDToRefs.first;
auto StartLoc = cantFail(sourceLocationInMainFile(SM, Range.start));
auto EndLoc = cantFail(sourceLocationInMainFile(SM, Range.end));
S.Name = toSourceCode(SM, SourceRange(StartLoc, EndLoc));
S.SymInfo.Kind = index::SymbolKind::Macro;
S.SymInfo.SubKind = index::SymbolSubKind::None;
S.SymInfo.Properties = index::SymbolPropertySet();
S.SymInfo.Lang = index::SymbolLanguage::C;
S.Origin = Opts.Origin;
S.CanonicalDeclaration = R.Location;
Symbols.insert(S);
}
}
}
}
Expand Down
12 changes: 8 additions & 4 deletions clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,18 @@ TEST(CollectMainFileMacros, SelectedMacros) {
assert(Macro);
auto SID = getSymbolID(Macro->Name, Macro->Info, SM);

EXPECT_THAT(ExpectedRefs,
UnorderedElementsAreArray(ActualMacroRefs.MacroRefs[SID]))
std::vector<Range> Ranges;
for (const auto &Ref : ActualMacroRefs.MacroRefs[SID])
Ranges.push_back(Ref.Rng);
EXPECT_THAT(ExpectedRefs, UnorderedElementsAreArray(Ranges))
<< "Annotation=" << I << ", MacroName=" << Macro->Name
<< ", Test = " << Test;
}
// Unknown macros.
EXPECT_THAT(AST.getMacros().UnknownMacros,
UnorderedElementsAreArray(T.ranges("Unknown")))
std::vector<Range> Ranges;
for (const auto &Ref : AST.getMacros().UnknownMacros)
Ranges.push_back(Ref.Rng);
EXPECT_THAT(Ranges, UnorderedElementsAreArray(T.ranges("Unknown")))
<< "Unknown macros doesn't match in " << Test;
}
}
Expand Down
12 changes: 1 addition & 11 deletions clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,7 @@ std::vector<SymbolInformation> getSymbols(TestTU &TU, llvm::StringRef Query,
return *SymbolInfos;
}

// FIXME: We update two indexes during main file processing:
// - preamble index (static)
// - main-file index (dynamic)
// The macro in this test appears to be in the preamble index and not
// in the main-file index. According to our logic of indexes merging, we
// do not take this macro from the static (preamble) index, because it
// location within the file from the dynamic (main-file) index.
//
// Possible solution is to exclude main-file symbols from the preamble
// index, after that we can enable this test again.
TEST(WorkspaceSymbols, DISABLED_Macros) {
TEST(WorkspaceSymbols, Macros) {
TestTU TU;
TU.Code = R"cpp(
#define MACRO X
Expand Down
4 changes: 2 additions & 2 deletions clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,10 @@ TEST(ParsedASTTest, CollectsMainFileMacroExpansions) {
std::vector<Position> MacroExpansionPositions;
for (const auto &SIDToRefs : AST.getMacros().MacroRefs) {
for (const auto &R : SIDToRefs.second)
MacroExpansionPositions.push_back(R.start);
MacroExpansionPositions.push_back(R.Rng.start);
}
for (const auto &R : AST.getMacros().UnknownMacros)
MacroExpansionPositions.push_back(R.start);
MacroExpansionPositions.push_back(R.Rng.start);
EXPECT_THAT(MacroExpansionPositions,
testing::UnorderedElementsAreArray(TestCase.points()));
}
Expand Down
6 changes: 3 additions & 3 deletions clang/include/clang/AST/DependentDiagnostic.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class DependentDiagnostic {
QualType BaseObjectType,
const PartialDiagnostic &PDiag) {
DependentDiagnostic *DD = Create(Context, Parent, PDiag);
DD->AccessData.Loc = Loc.getRawEncoding();
DD->AccessData.Loc = Loc;
DD->AccessData.IsMember = IsMemberAccess;
DD->AccessData.Access = AS;
DD->AccessData.TargetDecl = TargetDecl;
Expand All @@ -73,7 +73,7 @@ class DependentDiagnostic {

SourceLocation getAccessLoc() const {
assert(getKind() == Access);
return SourceLocation::getFromRawEncoding(AccessData.Loc);
return AccessData.Loc;
}

NamedDecl *getAccessTarget() const {
Expand Down Expand Up @@ -112,7 +112,7 @@ class DependentDiagnostic {
PartialDiagnostic Diag;

struct {
unsigned Loc;
SourceLocation Loc;
unsigned Access : 2;
unsigned IsMember : 1;
NamedDecl *TargetDecl;
Expand Down
39 changes: 21 additions & 18 deletions clang/include/clang/AST/Expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -4994,10 +4994,10 @@ class DesignatedInitExpr final
uintptr_t NameOrField;

/// The location of the '.' in the designated initializer.
unsigned DotLoc;
SourceLocation DotLoc;

/// The location of the field name in the designated initializer.
unsigned FieldLoc;
SourceLocation FieldLoc;
};

/// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
Expand All @@ -5006,12 +5006,12 @@ class DesignatedInitExpr final
/// initializer expression's list of subexpressions.
unsigned Index;
/// The location of the '[' starting the array range designator.
unsigned LBracketLoc;
SourceLocation LBracketLoc;
/// The location of the ellipsis separating the start and end
/// indices. Only valid for GNU array-range designators.
unsigned EllipsisLoc;
SourceLocation EllipsisLoc;
/// The location of the ']' terminating the array range designator.
unsigned RBracketLoc;
SourceLocation RBracketLoc;
};

/// Represents a single C99 designator.
Expand Down Expand Up @@ -5043,29 +5043,32 @@ class DesignatedInitExpr final
Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc,
SourceLocation FieldLoc)
: Kind(FieldDesignator) {
new (&Field) DesignatedInitExpr::FieldDesignator;
Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01;
Field.DotLoc = DotLoc.getRawEncoding();
Field.FieldLoc = FieldLoc.getRawEncoding();
Field.DotLoc = DotLoc;
Field.FieldLoc = FieldLoc;
}

/// Initializes an array designator.
Designator(unsigned Index, SourceLocation LBracketLoc,
SourceLocation RBracketLoc)
: Kind(ArrayDesignator) {
new (&ArrayOrRange) DesignatedInitExpr::ArrayOrRangeDesignator;
ArrayOrRange.Index = Index;
ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding();
ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
ArrayOrRange.LBracketLoc = LBracketLoc;
ArrayOrRange.EllipsisLoc = SourceLocation();
ArrayOrRange.RBracketLoc = RBracketLoc;
}

/// Initializes a GNU array-range designator.
Designator(unsigned Index, SourceLocation LBracketLoc,
SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
: Kind(ArrayRangeDesignator) {
new (&ArrayOrRange) DesignatedInitExpr::ArrayOrRangeDesignator;
ArrayOrRange.Index = Index;
ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding();
ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
ArrayOrRange.LBracketLoc = LBracketLoc;
ArrayOrRange.EllipsisLoc = EllipsisLoc;
ArrayOrRange.RBracketLoc = RBracketLoc;
}

bool isFieldDesignator() const { return Kind == FieldDesignator; }
Expand All @@ -5089,30 +5092,30 @@ class DesignatedInitExpr final

SourceLocation getDotLoc() const {
assert(Kind == FieldDesignator && "Only valid on a field designator");
return SourceLocation::getFromRawEncoding(Field.DotLoc);
return Field.DotLoc;
}

SourceLocation getFieldLoc() const {
assert(Kind == FieldDesignator && "Only valid on a field designator");
return SourceLocation::getFromRawEncoding(Field.FieldLoc);
return Field.FieldLoc;
}

SourceLocation getLBracketLoc() const {
assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
"Only valid on an array or array-range designator");
return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc);
return ArrayOrRange.LBracketLoc;
}

SourceLocation getRBracketLoc() const {
assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
"Only valid on an array or array-range designator");
return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc);
return ArrayOrRange.RBracketLoc;
}

SourceLocation getEllipsisLoc() const {
assert(Kind == ArrayRangeDesignator &&
"Only valid on an array-range designator");
return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc);
return ArrayOrRange.EllipsisLoc;
}

unsigned getFirstExprIndex() const {
Expand Down
8 changes: 4 additions & 4 deletions clang/include/clang/AST/TemplateBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,8 @@ struct TemplateArgumentLocInfo {
// but template arguments get canonicalized too quickly.
NestedNameSpecifier *Qualifier;
void *QualifierLocData;
unsigned TemplateNameLoc;
unsigned EllipsisLoc;
SourceLocation TemplateNameLoc;
SourceLocation EllipsisLoc;
};

llvm::PointerUnion<TemplateTemplateArgLocInfo *, Expr *, TypeSourceInfo *>
Expand Down Expand Up @@ -444,11 +444,11 @@ struct TemplateArgumentLocInfo {
}

SourceLocation getTemplateNameLoc() const {
return SourceLocation::getFromRawEncoding(getTemplate()->TemplateNameLoc);
return getTemplate()->TemplateNameLoc;
}

SourceLocation getTemplateEllipsisLoc() const {
return SourceLocation::getFromRawEncoding(getTemplate()->EllipsisLoc);
return getTemplate()->EllipsisLoc;
}
};

Expand Down
Loading

0 comments on commit 978a610

Please sign in to comment.