Skip to content

Commit e8cdd2a

Browse files
committed
Merge from 'main' to 'sycl-web' (#9)
CONFLICT (content): Merge conflict in clang/lib/Frontend/CompilerInvocation.cpp
2 parents e51dc57 + c332445 commit e8cdd2a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+3628
-3289
lines changed

clang/docs/ClangFormatStyleOptions.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2282,6 +2282,26 @@ the configuration (without a prefix: ``Auto``).
22822282
``ClassImpl.hpp`` would not have the main include file put on top
22832283
before any other include.
22842284

2285+
**IncludeSortAlphabetically** (``bool``)
2286+
Specify if sorting should be done in an alphabetical and
2287+
case sensitive fashion.
2288+
2289+
When ``false``, includes are sorted in an ASCIIbetical
2290+
fashion.
2291+
When ``true``, includes are sorted in an alphabetical
2292+
fashion with case used as a tie-breaker.
2293+
2294+
.. code-block:: c++
2295+
2296+
false: true:
2297+
#include "A/B.h" vs. #include "A/B.h"
2298+
#include "A/b.h" #include "A/b.h"
2299+
#include "B/A.h" #include "a/b.h"
2300+
#include "B/a.h" #include "B/A.h"
2301+
#include "a/b.h" #include "B/a.h"
2302+
2303+
This option is off by default.
2304+
22852305
**IndentCaseBlocks** (``bool``)
22862306
Indent case label blocks one level from the case label.
22872307

clang/include/clang/Basic/CodeGenOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ class CodeGenOptions : public CodeGenOptionsBase {
169169
std::string RecordCommandLine;
170170

171171
std::map<std::string, std::string> DebugPrefixMap;
172+
std::map<std::string, std::string> ProfilePrefixMap;
172173

173174
/// The ABI to use for passing floating point arguments.
174175
std::string FloatABI;

clang/include/clang/Driver/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2667,6 +2667,10 @@ def fdebug_prefix_map_EQ
26672667
: Joined<["-"], "fdebug-prefix-map=">, Group<f_Group>,
26682668
Flags<[CC1Option,CC1AsOption]>,
26692669
HelpText<"remap file source paths in debug info">;
2670+
def fprofile_prefix_map_EQ
2671+
: Joined<["-"], "fprofile-prefix-map=">, Group<f_Group>,
2672+
Flags<[CC1Option]>,
2673+
HelpText<"remap file source paths in coverage info">;
26702674
def ffile_prefix_map_EQ
26712675
: Joined<["-"], "ffile-prefix-map=">, Group<f_Group>,
26722676
HelpText<"remap file source paths in debug info and predefined preprocessor macros">;

clang/include/clang/Tooling/Inclusions/IncludeStyle.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,26 @@ struct IncludeStyle {
147147
/// ``ClassImpl.hpp`` would not have the main include file put on top
148148
/// before any other include.
149149
std::string IncludeIsMainSourceRegex;
150+
151+
/// Specify if sorting should be done in an alphabetical and
152+
/// case sensitive fashion.
153+
///
154+
/// When ``false``, includes are sorted in an ASCIIbetical
155+
/// fashion.
156+
/// When ``true``, includes are sorted in an alphabetical
157+
/// fashion with case used as a tie-breaker.
158+
///
159+
/// \code
160+
/// false: true:
161+
/// #include "A/B.h" vs. #include "A/B.h"
162+
/// #include "A/b.h" #include "A/b.h"
163+
/// #include "B/A.h" #include "a/b.h"
164+
/// #include "B/a.h" #include "B/A.h"
165+
/// #include "a/b.h" #include "B/a.h"
166+
/// \endcode
167+
///
168+
/// This option is off by default.
169+
bool IncludeSortAlphabetically;
150170
};
151171

152172
} // namespace tooling

clang/lib/Analysis/CalledOnceCheck.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -936,8 +936,9 @@ class CalledOnceChecker : public ConstStmtVisitor<CalledOnceChecker> {
936936

937937
/// Return true if the only parameter of the function is conventional.
938938
static bool isOnlyParameterConventional(const FunctionDecl *Function) {
939-
return Function->getNumParams() == 1 &&
940-
hasConventionalSuffix(Function->getName());
939+
IdentifierInfo *II = Function->getIdentifier();
940+
return Function->getNumParams() == 1 && II &&
941+
hasConventionalSuffix(II->getName());
941942
}
942943

943944
/// Return true/false if 'swift_async' attribute states that the given

clang/lib/CodeGen/CoverageMappingGen.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,13 +1544,6 @@ struct CounterCoverageMappingBuilder
15441544
}
15451545
};
15461546

1547-
std::string normalizeFilename(StringRef Filename) {
1548-
llvm::SmallString<256> Path(Filename);
1549-
llvm::sys::fs::make_absolute(Path);
1550-
llvm::sys::path::remove_dots(Path, /*remove_dot_dot=*/true);
1551-
return std::string(Path);
1552-
}
1553-
15541547
} // end anonymous namespace
15551548

15561549
static void dump(llvm::raw_ostream &OS, StringRef FunctionName,
@@ -1592,6 +1585,23 @@ static void dump(llvm::raw_ostream &OS, StringRef FunctionName,
15921585
}
15931586
}
15941587

1588+
CoverageMappingModuleGen::CoverageMappingModuleGen(
1589+
CodeGenModule &CGM, CoverageSourceInfo &SourceInfo)
1590+
: CGM(CGM), SourceInfo(SourceInfo) {
1591+
ProfilePrefixMap = CGM.getCodeGenOpts().ProfilePrefixMap;
1592+
}
1593+
1594+
std::string CoverageMappingModuleGen::normalizeFilename(StringRef Filename) {
1595+
llvm::SmallString<256> Path(Filename);
1596+
llvm::sys::fs::make_absolute(Path);
1597+
llvm::sys::path::remove_dots(Path, /*remove_dot_dot=*/true);
1598+
for (const auto &Entry : ProfilePrefixMap) {
1599+
if (llvm::sys::path::replace_path_prefix(Path, Entry.first, Entry.second))
1600+
break;
1601+
}
1602+
return Path.str().str();
1603+
}
1604+
15951605
static std::string getInstrProfSection(const CodeGenModule &CGM,
15961606
llvm::InstrProfSectKind SK) {
15971607
return llvm::getInstrProfSectionName(

clang/lib/CodeGen/CoverageMappingGen.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ class CoverageMappingModuleGen {
9393
llvm::SmallDenseMap<const FileEntry *, unsigned, 8> FileEntries;
9494
std::vector<llvm::Constant *> FunctionNames;
9595
std::vector<FunctionInfo> FunctionRecords;
96+
std::map<std::string, std::string> ProfilePrefixMap;
97+
98+
std::string normalizeFilename(StringRef Filename);
9699

97100
/// Emit a function record.
98101
void emitFunctionMappingRecord(const FunctionInfo &Info,
@@ -101,8 +104,7 @@ class CoverageMappingModuleGen {
101104
public:
102105
static CoverageSourceInfo *setUpCoverageCallbacks(Preprocessor &PP);
103106

104-
CoverageMappingModuleGen(CodeGenModule &CGM, CoverageSourceInfo &SourceInfo)
105-
: CGM(CGM), SourceInfo(SourceInfo) {}
107+
CoverageMappingModuleGen(CodeGenModule &CGM, CoverageSourceInfo &SourceInfo);
106108

107109
CoverageSourceInfo &getSourceInfo() const {
108110
return SourceInfo;

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,21 @@ static void addMacroPrefixMapArg(const Driver &D, const ArgList &Args,
666666
}
667667
}
668668

669+
/// Add a CC1 and CC1AS option to specify the coverage file path prefix map.
670+
static void addProfilePrefixMapArg(const Driver &D, const ArgList &Args,
671+
ArgStringList &CmdArgs) {
672+
for (const Arg *A : Args.filtered(options::OPT_ffile_prefix_map_EQ,
673+
options::OPT_fprofile_prefix_map_EQ)) {
674+
StringRef Map = A->getValue();
675+
if (Map.find('=') == StringRef::npos)
676+
D.Diag(diag::err_drv_invalid_argument_to_option)
677+
<< Map << A->getOption().getName();
678+
else
679+
CmdArgs.push_back(Args.MakeArgString("-fprofile-prefix-map=" + Map));
680+
A->claim();
681+
}
682+
}
683+
669684
/// Vectorize at all optimization levels greater than 1 except for -Oz.
670685
/// For -Oz the loop vectorizer is disabled, while the slp vectorizer is
671686
/// enabled.
@@ -1408,6 +1423,7 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
14081423
}
14091424

14101425
addMacroPrefixMapArg(D, Args, CmdArgs);
1426+
addProfilePrefixMapArg(D, Args, CmdArgs);
14111427
}
14121428

14131429
// FIXME: Move to target hook.

clang/lib/Format/Format.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,8 @@ template <> struct MappingTraits<FormatStyle> {
571571
IO.mapOptional("IncludeIsMainRegex", Style.IncludeStyle.IncludeIsMainRegex);
572572
IO.mapOptional("IncludeIsMainSourceRegex",
573573
Style.IncludeStyle.IncludeIsMainSourceRegex);
574+
IO.mapOptional("IncludeSortAlphabetically",
575+
Style.IncludeStyle.IncludeSortAlphabetically);
574576
IO.mapOptional("IndentCaseLabels", Style.IndentCaseLabels);
575577
IO.mapOptional("IndentCaseBlocks", Style.IndentCaseBlocks);
576578
IO.mapOptional("IndentGotoLabels", Style.IndentGotoLabels);
@@ -940,6 +942,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
940942
{".*", 1, 0, false}};
941943
LLVMStyle.IncludeStyle.IncludeIsMainRegex = "(Test)?$";
942944
LLVMStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Preserve;
945+
LLVMStyle.IncludeStyle.IncludeSortAlphabetically = false;
943946
LLVMStyle.IndentCaseLabels = false;
944947
LLVMStyle.IndentCaseBlocks = false;
945948
LLVMStyle.IndentGotoLabels = true;
@@ -2194,10 +2197,23 @@ static void sortCppIncludes(const FormatStyle &Style,
21942197
for (unsigned i = 0, e = Includes.size(); i != e; ++i) {
21952198
Indices.push_back(i);
21962199
}
2197-
llvm::stable_sort(Indices, [&](unsigned LHSI, unsigned RHSI) {
2198-
return std::tie(Includes[LHSI].Priority, Includes[LHSI].Filename) <
2199-
std::tie(Includes[RHSI].Priority, Includes[RHSI].Filename);
2200-
});
2200+
2201+
if (Style.IncludeStyle.IncludeSortAlphabetically) {
2202+
llvm::stable_sort(Indices, [&](unsigned LHSI, unsigned RHSI) {
2203+
const auto LHSFilenameLower = Includes[LHSI].Filename.lower();
2204+
const auto RHSFilenameLower = Includes[RHSI].Filename.lower();
2205+
return std::tie(Includes[LHSI].Priority, LHSFilenameLower,
2206+
Includes[LHSI].Filename) <
2207+
std::tie(Includes[RHSI].Priority, RHSFilenameLower,
2208+
Includes[RHSI].Filename);
2209+
});
2210+
} else {
2211+
llvm::stable_sort(Indices, [&](unsigned LHSI, unsigned RHSI) {
2212+
return std::tie(Includes[LHSI].Priority, Includes[LHSI].Filename) <
2213+
std::tie(Includes[RHSI].Priority, Includes[RHSI].Filename);
2214+
});
2215+
}
2216+
22012217
// The index of the include on which the cursor will be put after
22022218
// sorting/deduplicating.
22032219
unsigned CursorIndex;

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,12 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
991991
{std::string(Split.first), std::string(Split.second)});
992992
}
993993

994+
for (const auto &Arg : Args.getAllArgValues(OPT_fprofile_prefix_map_EQ)) {
995+
auto Split = StringRef(Arg).split('=');
996+
Opts.ProfilePrefixMap.insert(
997+
{std::string(Split.first), std::string(Split.second)});
998+
}
999+
9941000
Opts.DisableLLVMPasses =
9951001
Args.hasArg(OPT_disable_llvm_passes) ||
9961002
(Args.hasArg(OPT_fsycl_is_device) && T.isSPIR() &&

0 commit comments

Comments
 (0)