Skip to content

Commit

Permalink
Merged main:7539bcf994ed into amd-gfx:0e8798f5c1bd
Browse files Browse the repository at this point in the history
Local branch amd-gfx 0e8798f Merged main:e86d6a43f03b into amd-gfx:caaa027161c5
Remote branch main 7539bcf [clang-format][NFC] AlignTokenSequence: Rename Changes[i] to CurrentC…
  • Loading branch information
SC llvm team authored and SC llvm team committed Oct 4, 2023
2 parents 0e8798f + 7539bcf commit ab27814
Show file tree
Hide file tree
Showing 20 changed files with 253 additions and 134 deletions.
86 changes: 44 additions & 42 deletions clang/lib/Format/WhitespaceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,9 @@ AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End,
SmallVector<unsigned, 16> ScopeStack;

for (unsigned i = Start; i != End; ++i) {
auto &CurrentChange = Changes[i];
if (ScopeStack.size() != 0 &&
Changes[i].indentAndNestingLevel() <
CurrentChange.indentAndNestingLevel() <
Changes[ScopeStack.back()].indentAndNestingLevel()) {
ScopeStack.pop_back();
}
Expand All @@ -320,42 +321,42 @@ AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End,
Changes[PreviousNonComment].Tok->is(tok::comment)) {
--PreviousNonComment;
}
if (i != Start && Changes[i].indentAndNestingLevel() >
if (i != Start && CurrentChange.indentAndNestingLevel() >
Changes[PreviousNonComment].indentAndNestingLevel()) {
ScopeStack.push_back(i);
}

bool InsideNestedScope = ScopeStack.size() != 0;
bool ContinuedStringLiteral = i > Start &&
Changes[i].Tok->is(tok::string_literal) &&
CurrentChange.Tok->is(tok::string_literal) &&
Changes[i - 1].Tok->is(tok::string_literal);
bool SkipMatchCheck = InsideNestedScope || ContinuedStringLiteral;

if (Changes[i].NewlinesBefore > 0 && !SkipMatchCheck) {
if (CurrentChange.NewlinesBefore > 0 && !SkipMatchCheck) {
Shift = 0;
FoundMatchOnLine = false;
}

// If this is the first matching token to be aligned, remember by how many
// spaces it has to be shifted, so the rest of the changes on the line are
// shifted by the same amount
if (!FoundMatchOnLine && !SkipMatchCheck && Matches(Changes[i])) {
if (!FoundMatchOnLine && !SkipMatchCheck && Matches(CurrentChange)) {
FoundMatchOnLine = true;
Shift = Column - (RightJustify ? Changes[i].TokenLength : 0) -
Changes[i].StartOfTokenColumn;
Changes[i].Spaces += Shift;
Shift = Column - (RightJustify ? CurrentChange.TokenLength : 0) -
CurrentChange.StartOfTokenColumn;
CurrentChange.Spaces += Shift;
// FIXME: This is a workaround that should be removed when we fix
// http://llvm.org/PR53699. An assertion later below verifies this.
if (Changes[i].NewlinesBefore == 0) {
Changes[i].Spaces =
std::max(Changes[i].Spaces,
static_cast<int>(Changes[i].Tok->SpacesRequiredBefore));
if (CurrentChange.NewlinesBefore == 0) {
CurrentChange.Spaces =
std::max(CurrentChange.Spaces,
static_cast<int>(CurrentChange.Tok->SpacesRequiredBefore));
}
}

// This is for function parameters that are split across multiple lines,
// as mentioned in the ScopeStack comment.
if (InsideNestedScope && Changes[i].NewlinesBefore > 0) {
if (InsideNestedScope && CurrentChange.NewlinesBefore > 0) {
unsigned ScopeStart = ScopeStack.back();
auto ShouldShiftBeAdded = [&] {
// Function declaration
Expand All @@ -378,47 +379,47 @@ AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End,
TT_TemplateCloser) &&
Changes[ScopeStart - 1].Tok->is(tok::l_paren) &&
Changes[ScopeStart].Tok->isNot(TT_LambdaLSquare)) {
if (Changes[i].Tok->MatchingParen &&
Changes[i].Tok->MatchingParen->is(TT_LambdaLBrace)) {
if (CurrentChange.Tok->MatchingParen &&
CurrentChange.Tok->MatchingParen->is(TT_LambdaLBrace)) {
return false;
}
if (Changes[ScopeStart].NewlinesBefore > 0)
return false;
if (Changes[i].Tok->is(tok::l_brace) &&
Changes[i].Tok->is(BK_BracedInit)) {
if (CurrentChange.Tok->is(tok::l_brace) &&
CurrentChange.Tok->is(BK_BracedInit)) {
return true;
}
return Style.BinPackArguments;
}

// Ternary operator
if (Changes[i].Tok->is(TT_ConditionalExpr))
if (CurrentChange.Tok->is(TT_ConditionalExpr))
return true;

// Period Initializer .XXX = 1.
if (Changes[i].Tok->is(TT_DesignatedInitializerPeriod))
if (CurrentChange.Tok->is(TT_DesignatedInitializerPeriod))
return true;

// Continued ternary operator
if (Changes[i].Tok->Previous &&
Changes[i].Tok->Previous->is(TT_ConditionalExpr)) {
if (CurrentChange.Tok->Previous &&
CurrentChange.Tok->Previous->is(TT_ConditionalExpr)) {
return true;
}

// Continued direct-list-initialization using braced list.
if (ScopeStart > Start + 1 &&
Changes[ScopeStart - 2].Tok->is(tok::identifier) &&
Changes[ScopeStart - 1].Tok->is(tok::l_brace) &&
Changes[i].Tok->is(tok::l_brace) &&
Changes[i].Tok->is(BK_BracedInit)) {
CurrentChange.Tok->is(tok::l_brace) &&
CurrentChange.Tok->is(BK_BracedInit)) {
return true;
}

// Continued braced list.
if (ScopeStart > Start + 1 &&
Changes[ScopeStart - 2].Tok->isNot(tok::identifier) &&
Changes[ScopeStart - 1].Tok->is(tok::l_brace) &&
Changes[i].Tok->isNot(tok::r_brace)) {
CurrentChange.Tok->isNot(tok::r_brace)) {
for (unsigned OuterScopeStart : llvm::reverse(ScopeStack)) {
// Lambda.
if (OuterScopeStart > Start &&
Expand All @@ -439,26 +440,26 @@ AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End,
};

if (ShouldShiftBeAdded())
Changes[i].Spaces += Shift;
CurrentChange.Spaces += Shift;
}

if (ContinuedStringLiteral)
Changes[i].Spaces += Shift;
CurrentChange.Spaces += Shift;

// We should not remove required spaces unless we break the line before.
assert(Shift >= 0 || Changes[i].NewlinesBefore > 0 ||
Changes[i].Spaces >=
CurrentChange.Spaces >=
static_cast<int>(Changes[i].Tok->SpacesRequiredBefore) ||
Changes[i].Tok->is(tok::eof));
CurrentChange.Tok->is(tok::eof));

Changes[i].StartOfTokenColumn += Shift;
CurrentChange.StartOfTokenColumn += Shift;
if (i + 1 != Changes.size())
Changes[i + 1].PreviousEndOfTokenColumn += Shift;

// If PointerAlignment is PAS_Right, keep *s or &s next to the token
if ((Style.PointerAlignment == FormatStyle::PAS_Right ||
Style.ReferenceAlignment == FormatStyle::RAS_Right) &&
Changes[i].Spaces != 0) {
CurrentChange.Spaces != 0) {
const bool ReferenceNotRightAligned =
Style.ReferenceAlignment != FormatStyle::RAS_Right &&
Style.ReferenceAlignment != FormatStyle::RAS_Pointer;
Expand Down Expand Up @@ -579,16 +580,17 @@ static unsigned AlignTokens(const FormatStyle &Style, F &&Matches,

unsigned i = StartAt;
for (unsigned e = Changes.size(); i != e; ++i) {
if (Changes[i].indentAndNestingLevel() < IndentAndNestingLevel)
auto &CurrentChange = Changes[i];
if (CurrentChange.indentAndNestingLevel() < IndentAndNestingLevel)
break;

if (Changes[i].NewlinesBefore != 0) {
if (CurrentChange.NewlinesBefore != 0) {
CommasBeforeMatch = 0;
EndOfSequence = i;

// Whether to break the alignment sequence because of an empty line.
bool EmptyLineBreak =
(Changes[i].NewlinesBefore > 1) && !ACS.AcrossEmptyLines;
(CurrentChange.NewlinesBefore > 1) && !ACS.AcrossEmptyLines;

// Whether to break the alignment sequence because of a line without a
// match.
Expand All @@ -600,27 +602,27 @@ static unsigned AlignTokens(const FormatStyle &Style, F &&Matches,

// A new line starts, re-initialize line status tracking bools.
// Keep the match state if a string literal is continued on this line.
if (i == 0 || Changes[i].Tok->isNot(tok::string_literal) ||
if (i == 0 || CurrentChange.Tok->isNot(tok::string_literal) ||
Changes[i - 1].Tok->isNot(tok::string_literal)) {
FoundMatchOnLine = false;
}
LineIsComment = true;
}

if (Changes[i].Tok->isNot(tok::comment))
if (CurrentChange.Tok->isNot(tok::comment))
LineIsComment = false;

if (Changes[i].Tok->is(tok::comma)) {
if (CurrentChange.Tok->is(tok::comma)) {
++CommasBeforeMatch;
} else if (Changes[i].indentAndNestingLevel() > IndentAndNestingLevel) {
} else if (CurrentChange.indentAndNestingLevel() > IndentAndNestingLevel) {
// Call AlignTokens recursively, skipping over this scope block.
unsigned StoppedAt =
AlignTokens(Style, Matches, Changes, i, ACS, RightJustify);
i = StoppedAt - 1;
continue;
}

if (!Matches(Changes[i]))
if (!Matches(CurrentChange))
continue;

// If there is more than one matching token per line, or if the number of
Expand All @@ -634,16 +636,16 @@ static unsigned AlignTokens(const FormatStyle &Style, F &&Matches,
if (StartOfSequence == 0)
StartOfSequence = i;

unsigned ChangeWidthLeft = Changes[i].StartOfTokenColumn;
unsigned ChangeWidthLeft = CurrentChange.StartOfTokenColumn;
unsigned ChangeWidthAnchor = 0;
unsigned ChangeWidthRight = 0;
if (RightJustify)
if (ACS.PadOperators)
ChangeWidthAnchor = Changes[i].TokenLength;
ChangeWidthAnchor = CurrentChange.TokenLength;
else
ChangeWidthLeft += Changes[i].TokenLength;
ChangeWidthLeft += CurrentChange.TokenLength;
else
ChangeWidthRight = Changes[i].TokenLength;
ChangeWidthRight = CurrentChange.TokenLength;
for (unsigned j = i + 1; j != e && Changes[j].NewlinesBefore == 0; ++j) {
ChangeWidthRight += Changes[j].Spaces;
// Changes are generally 1:1 with the tokens, but a change could also be
Expand Down
2 changes: 0 additions & 2 deletions clang/lib/Frontend/InitPreprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1081,8 +1081,6 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
DefineFloatMacros(Builder, "FLT", &TI.getFloatFormat(), "F");
DefineFloatMacros(Builder, "DBL", &TI.getDoubleFormat(), "");
DefineFloatMacros(Builder, "LDBL", &TI.getLongDoubleFormat(), "L");
if (TI.hasFloat128Type())
DefineFloatMacros(Builder, "FLT128", &TI.getFloat128Format(), "Q");

// Define a __POINTER_WIDTH__ macro for stdint.h.
Builder.defineMacro("__POINTER_WIDTH__",
Expand Down
15 changes: 0 additions & 15 deletions clang/test/Preprocessor/init-x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -1023,21 +1023,6 @@
// X86_64-LINUX:#define __DBL_MIN_EXP__ (-1021)
// X86_64-LINUX:#define __DBL_MIN__ 2.2250738585072014e-308
// X86_64-LINUX:#define __DECIMAL_DIG__ __LDBL_DECIMAL_DIG__
// X86_64-LINUX:#define __FLOAT128__ 1
// X86_64-LINUX:#define __FLT128_DECIMAL_DIG__ 36
// X86_64-LINUX:#define __FLT128_DENORM_MIN__ 6.47517511943802511092443895822764655e-4966Q
// X86_64-LINUX:#define __FLT128_DIG__ 33
// X86_64-LINUX:#define __FLT128_EPSILON__ 1.92592994438723585305597794258492732e-34Q
// X86_64-LINUX:#define __FLT128_HAS_DENORM__ 1
// X86_64-LINUX:#define __FLT128_HAS_INFINITY__ 1
// X86_64-LINUX:#define __FLT128_HAS_QUIET_NAN__ 1
// X86_64-LINUX:#define __FLT128_MANT_DIG__ 113
// X86_64-LINUX:#define __FLT128_MAX_10_EXP__ 4932
// X86_64-LINUX:#define __FLT128_MAX_EXP__ 16384
// X86_64-LINUX:#define __FLT128_MAX__ 1.18973149535723176508575932662800702e+4932Q
// X86_64-LINUX:#define __FLT128_MIN_10_EXP__ (-4931)
// X86_64-LINUX:#define __FLT128_MIN_EXP__ (-16381)
// X86_64-LINUX:#define __FLT128_MIN__ 3.36210314311209350626267781732175260e-4932Q
// X86_64-LINUX:#define __FLT_DENORM_MIN__ 1.40129846e-45F
// X86_64-LINUX:#define __FLT_DIG__ 6
// X86_64-LINUX:#define __FLT_EPSILON__ 1.19209290e-7F
Expand Down
14 changes: 0 additions & 14 deletions clang/test/Preprocessor/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -1576,20 +1576,6 @@
// EMSCRIPTEN-NEXT:#define __EMSCRIPTEN__ 1
// WEBASSEMBLY-NEXT:#define __FINITE_MATH_ONLY__ 0
// WEBASSEMBLY-NEXT:#define __FLOAT128__ 1
// WEBASSEMBLY-NEXT:#define __FLT128_DECIMAL_DIG__ 36
// WEBASSEMBLY-NEXT:#define __FLT128_DENORM_MIN__ 6.47517511943802511092443895822764655e-4966Q
// WEBASSEMBLY-NEXT:#define __FLT128_DIG__ 33
// WEBASSEMBLY-NEXT:#define __FLT128_EPSILON__ 1.92592994438723585305597794258492732e-34Q
// WEBASSEMBLY-NEXT:#define __FLT128_HAS_DENORM__ 1
// WEBASSEMBLY-NEXT:#define __FLT128_HAS_INFINITY__ 1
// WEBASSEMBLY-NEXT:#define __FLT128_HAS_QUIET_NAN__ 1
// WEBASSEMBLY-NEXT:#define __FLT128_MANT_DIG__ 113
// WEBASSEMBLY-NEXT:#define __FLT128_MAX_10_EXP__ 4932
// WEBASSEMBLY-NEXT:#define __FLT128_MAX_EXP__ 16384
// WEBASSEMBLY-NEXT:#define __FLT128_MAX__ 1.18973149535723176508575932662800702e+4932Q
// WEBASSEMBLY-NEXT:#define __FLT128_MIN_10_EXP__ (-4931)
// WEBASSEMBLY-NEXT:#define __FLT128_MIN_EXP__ (-16381)
// WEBASSEMBLY-NEXT:#define __FLT128_MIN__ 3.36210314311209350626267781732175260e-4932Q
// WEBASSEMBLY-NOT:#define __FLT16_DECIMAL_DIG__
// WEBASSEMBLY-NOT:#define __FLT16_DENORM_MIN__
// WEBASSEMBLY-NOT:#define __FLT16_DIG__
Expand Down
14 changes: 14 additions & 0 deletions clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@ Error linkBitcodeFiles(SmallVectorImpl<OffloadFile> &InputFiles,
StringRef Arch = Args.getLastArgValue(OPT_arch_EQ);

SmallVector<OffloadFile, 4> BitcodeInputFiles;
DenseSet<StringRef> StrongResolutions;
DenseSet<StringRef> UsedInRegularObj;
DenseSet<StringRef> UsedInSharedLib;
BumpPtrAllocator Alloc;
Expand All @@ -608,6 +609,18 @@ Error linkBitcodeFiles(SmallVectorImpl<OffloadFile> &InputFiles,
file_magic Type = identify_magic(Buffer.getBuffer());
switch (Type) {
case file_magic::bitcode: {
Expected<IRSymtabFile> IRSymtabOrErr = readIRSymtab(Buffer);
if (!IRSymtabOrErr)
return IRSymtabOrErr.takeError();

// Check for any strong resolutions we need to preserve.
for (unsigned I = 0; I != IRSymtabOrErr->Mods.size(); ++I) {
for (const auto &Sym : IRSymtabOrErr->TheReader.module_symbols(I)) {
if (!Sym.isFormatSpecific() && Sym.isGlobal() && !Sym.isWeak() &&
!Sym.isUndefined())
StrongResolutions.insert(Saver.save(Sym.Name));
}
}
BitcodeInputFiles.emplace_back(std::move(File));
continue;
}
Expand Down Expand Up @@ -696,6 +709,7 @@ Error linkBitcodeFiles(SmallVectorImpl<OffloadFile> &InputFiles,
// it is undefined or another definition has already been used.
Res.Prevailing =
!Sym.isUndefined() &&
!(Sym.isWeak() && StrongResolutions.contains(Sym.getName())) &&
PrevailingSymbols.insert(Saver.save(Sym.getName())).second;

// We need LTO to preseve the following global symbols:
Expand Down
Loading

0 comments on commit ab27814

Please sign in to comment.