Skip to content

Commit b31a2e4

Browse files
committed
Merge from 'main' to 'sycl-web' (intel#24)
CONFLICT (content): Merge conflict in clang/lib/Basic/Targets/SPIR.h
2 parents 00c7995 + 2dbe1c6 commit b31a2e4

121 files changed

Lines changed: 2489 additions & 910 deletions

File tree

Some content is hidden

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

clang-tools-extra/clangd/ClangdServer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -637,8 +637,8 @@ void ClangdServer::applyTweak(PathRef File, Range Sel, StringRef TweakID,
637637
Effect = T.takeError();
638638
}
639639
assert(Effect.hasValue() && "Expected at least one selection");
640-
if (*Effect) {
641-
// Tweaks don't apply clang-format, do that centrally here.
640+
if (*Effect && (*Effect)->FormatEdits) {
641+
// Format tweaks that require it centrally here.
642642
for (auto &It : (*Effect)->ApplyEdits) {
643643
Edit &E = It.second;
644644
format::FormatStyle Style =

clang-tools-extra/clangd/refactor/Tweak.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ class Tweak {
7878
/// A message to be displayed to the user.
7979
llvm::Optional<std::string> ShowMessage;
8080
FileEdits ApplyEdits;
81+
/// Whether the edits should be formatted before presenting to the client.
82+
/// Note that it applies to all files.
83+
bool FormatEdits = true;
8184

8285
static Effect showMessage(StringRef S) {
8386
Effect E;

clang-tools-extra/clangd/unittests/ClangdTests.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,22 @@
1818
#include "TestTU.h"
1919
#include "TidyProvider.h"
2020
#include "URI.h"
21+
#include "refactor/Tweak.h"
2122
#include "support/MemoryTree.h"
2223
#include "support/Path.h"
2324
#include "support/Threading.h"
2425
#include "clang/Config/config.h"
2526
#include "clang/Sema/CodeCompleteConsumer.h"
2627
#include "clang/Tooling/ArgumentsAdjusters.h"
28+
#include "clang/Tooling/Core/Replacement.h"
2729
#include "llvm/ADT/None.h"
2830
#include "llvm/ADT/Optional.h"
2931
#include "llvm/ADT/SmallVector.h"
3032
#include "llvm/ADT/StringMap.h"
3133
#include "llvm/ADT/StringRef.h"
3234
#include "llvm/Support/Allocator.h"
3335
#include "llvm/Support/Errc.h"
36+
#include "llvm/Support/Error.h"
3437
#include "llvm/Support/Path.h"
3538
#include "llvm/Support/Regex.h"
3639
#include "llvm/Support/VirtualFileSystem.h"
@@ -1259,6 +1262,60 @@ TEST(ClangdServer, MemoryUsageTest) {
12591262
ASSERT_TRUE(MT.children().count("tuscheduler"));
12601263
EXPECT_TRUE(MT.child("tuscheduler").children().count(FooCpp));
12611264
}
1265+
1266+
TEST(ClangdServer, RespectsTweakFormatting) {
1267+
static constexpr const char *TweakID = "ModuleTweak";
1268+
static constexpr const char *NewContents = "{not;\nformatted;}";
1269+
1270+
// Contributes a tweak that generates a non-formatted insertion and disables
1271+
// formatting.
1272+
struct TweakContributingModule final : public FeatureModule {
1273+
struct ModuleTweak final : public Tweak {
1274+
const char *id() const override { return TweakID; }
1275+
bool prepare(const Selection &Sel) override { return true; }
1276+
Expected<Effect> apply(const Selection &Sel) override {
1277+
auto &SM = Sel.AST->getSourceManager();
1278+
llvm::StringRef FilePath = SM.getFilename(Sel.Cursor);
1279+
tooling::Replacements Reps;
1280+
llvm::cantFail(
1281+
Reps.add(tooling::Replacement(FilePath, 0, 0, NewContents)));
1282+
auto E = llvm::cantFail(Effect::mainFileEdit(SM, std::move(Reps)));
1283+
E.FormatEdits = false;
1284+
return E;
1285+
}
1286+
std::string title() const override { return id(); }
1287+
llvm::StringLiteral kind() const override {
1288+
return llvm::StringLiteral("");
1289+
};
1290+
};
1291+
1292+
void contributeTweaks(std::vector<std::unique_ptr<Tweak>> &Out) override {
1293+
Out.emplace_back(new ModuleTweak);
1294+
}
1295+
};
1296+
1297+
MockFS FS;
1298+
MockCompilationDatabase CDB;
1299+
auto Opts = ClangdServer::optsForTest();
1300+
FeatureModuleSet Set;
1301+
Set.add(std::make_unique<TweakContributingModule>());
1302+
Opts.FeatureModules = &Set;
1303+
ClangdServer Server(CDB, FS, Opts);
1304+
1305+
auto FooCpp = testPath("foo.cpp");
1306+
Server.addDocument(FooCpp, "");
1307+
ASSERT_TRUE(Server.blockUntilIdleForTest());
1308+
1309+
// Ensure that disabled formatting is respected.
1310+
Notification N;
1311+
Server.applyTweak(FooCpp, {}, TweakID, [&](llvm::Expected<Tweak::Effect> E) {
1312+
ASSERT_TRUE(static_cast<bool>(E));
1313+
EXPECT_THAT(llvm::cantFail(E->ApplyEdits.lookup(FooCpp).apply()),
1314+
NewContents);
1315+
N.notify();
1316+
});
1317+
N.wait();
1318+
}
12621319
} // namespace
12631320
} // namespace clangd
12641321
} // namespace clang

clang/include/clang/Basic/TargetInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1162,7 +1162,7 @@ class TargetInfo : public virtual TransferrableTargetInfo,
11621162
/// Apply changes to the target information with respect to certain
11631163
/// language options which change the target configuration and adjust
11641164
/// the language based on the target options where applicable.
1165-
virtual void adjust(LangOptions &Opts);
1165+
virtual void adjust(DiagnosticsEngine &Diags, LangOptions &Opts);
11661166

11671167
/// Adjust target options based on codegen options.
11681168
virtual void adjustTargetOptions(const CodeGenOptions &CGOpts,

clang/lib/Basic/TargetInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ bool TargetInfo::isTypeSigned(IntType T) {
346346
/// Apply changes to the target information with respect to certain
347347
/// language options which change the target configuration and adjust
348348
/// the language based on the target options where applicable.
349-
void TargetInfo::adjust(LangOptions &Opts) {
349+
void TargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
350350
if (Opts.NoBitFieldTypeAlign)
351351
UseBitFieldTypeAlignment = false;
352352

clang/lib/Basic/Targets/AMDGPU.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,8 @@ AMDGPUTargetInfo::AMDGPUTargetInfo(const llvm::Triple &Triple,
358358
MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
359359
}
360360

361-
void AMDGPUTargetInfo::adjust(LangOptions &Opts) {
362-
TargetInfo::adjust(Opts);
361+
void AMDGPUTargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
362+
TargetInfo::adjust(Diags, Opts);
363363
// ToDo: There are still a few places using default address space as private
364364
// address space in OpenCL, which needs to be cleaned up, then Opts.OpenCL
365365
// can be removed from the following line.

clang/lib/Basic/Targets/AMDGPU.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
9393

9494
void setAddressSpaceMap(bool DefaultIsPrivate);
9595

96-
void adjust(LangOptions &Opts) override;
96+
void adjust(DiagnosticsEngine &Diags, LangOptions &Opts) override;
9797

9898
uint64_t getPointerWidthV(unsigned AddrSpace) const override {
9999
if (isR600(getTriple()))

clang/lib/Basic/Targets/PPC.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -614,10 +614,10 @@ void PPCTargetInfo::fillValidCPUList(SmallVectorImpl<StringRef> &Values) const {
614614
Values.append(std::begin(ValidCPUNames), std::end(ValidCPUNames));
615615
}
616616

617-
void PPCTargetInfo::adjust(LangOptions &Opts) {
617+
void PPCTargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
618618
if (HasAltivec)
619619
Opts.AltiVec = 1;
620-
TargetInfo::adjust(Opts);
620+
TargetInfo::adjust(Diags, Opts);
621621
if (LongDoubleFormat != &llvm::APFloat::IEEEdouble())
622622
LongDoubleFormat = Opts.PPCIEEELongDouble
623623
? &llvm::APFloat::IEEEquad()

clang/lib/Basic/Targets/PPC.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class LLVM_LIBRARY_VISIBILITY PPCTargetInfo : public TargetInfo {
8989
}
9090

9191
// Set the language option for altivec based on our value.
92-
void adjust(LangOptions &Opts) override;
92+
void adjust(DiagnosticsEngine &Diags, LangOptions &Opts) override;
9393

9494
// Note: GCC recognizes the following additional cpus:
9595
// 401, 403, 405, 405fp, 440fp, 464, 464fp, 476, 476fp, 505, 740, 801,

clang/lib/Basic/Targets/SPIR.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ class LLVM_LIBRARY_VISIBILITY SPIRTargetInfo : public TargetInfo {
136136
AddrSpaceMap = DefaultIsGeneric ? &SPIRDefIsGenMap : &SPIRDefIsPrivMap;
137137
}
138138

139-
void adjust(LangOptions &Opts) override {
140-
TargetInfo::adjust(Opts);
139+
void adjust(DiagnosticsEngine &Diags, LangOptions &Opts) override {
140+
TargetInfo::adjust(Diags, Opts);
141141
// NOTE: SYCL specification considers unannotated pointers and references
142142
// to be pointing to the generic address space. See section 5.9.3 of
143143
// SYCL 2020 specification.

0 commit comments

Comments
 (0)