Skip to content

Commit

Permalink
Merge from 'main' to 'sycl-web' (intel#24)
Browse files Browse the repository at this point in the history
  CONFLICT (content): Merge conflict in clang/lib/Basic/Targets/SPIR.h
  • Loading branch information
abhinavgaba committed Jun 28, 2021
2 parents 00c7995 + 2dbe1c6 commit b31a2e4
Show file tree
Hide file tree
Showing 121 changed files with 2,489 additions and 910 deletions.
4 changes: 2 additions & 2 deletions clang-tools-extra/clangd/ClangdServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -637,8 +637,8 @@ void ClangdServer::applyTweak(PathRef File, Range Sel, StringRef TweakID,
Effect = T.takeError();
}
assert(Effect.hasValue() && "Expected at least one selection");
if (*Effect) {
// Tweaks don't apply clang-format, do that centrally here.
if (*Effect && (*Effect)->FormatEdits) {
// Format tweaks that require it centrally here.
for (auto &It : (*Effect)->ApplyEdits) {
Edit &E = It.second;
format::FormatStyle Style =
Expand Down
3 changes: 3 additions & 0 deletions clang-tools-extra/clangd/refactor/Tweak.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ class Tweak {
/// A message to be displayed to the user.
llvm::Optional<std::string> ShowMessage;
FileEdits ApplyEdits;
/// Whether the edits should be formatted before presenting to the client.
/// Note that it applies to all files.
bool FormatEdits = true;

static Effect showMessage(StringRef S) {
Effect E;
Expand Down
57 changes: 57 additions & 0 deletions clang-tools-extra/clangd/unittests/ClangdTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,22 @@
#include "TestTU.h"
#include "TidyProvider.h"
#include "URI.h"
#include "refactor/Tweak.h"
#include "support/MemoryTree.h"
#include "support/Path.h"
#include "support/Threading.h"
#include "clang/Config/config.h"
#include "clang/Sema/CodeCompleteConsumer.h"
#include "clang/Tooling/ArgumentsAdjusters.h"
#include "clang/Tooling/Core/Replacement.h"
#include "llvm/ADT/None.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Regex.h"
#include "llvm/Support/VirtualFileSystem.h"
Expand Down Expand Up @@ -1259,6 +1262,60 @@ TEST(ClangdServer, MemoryUsageTest) {
ASSERT_TRUE(MT.children().count("tuscheduler"));
EXPECT_TRUE(MT.child("tuscheduler").children().count(FooCpp));
}

TEST(ClangdServer, RespectsTweakFormatting) {
static constexpr const char *TweakID = "ModuleTweak";
static constexpr const char *NewContents = "{not;\nformatted;}";

// Contributes a tweak that generates a non-formatted insertion and disables
// formatting.
struct TweakContributingModule final : public FeatureModule {
struct ModuleTweak final : public Tweak {
const char *id() const override { return TweakID; }
bool prepare(const Selection &Sel) override { return true; }
Expected<Effect> apply(const Selection &Sel) override {
auto &SM = Sel.AST->getSourceManager();
llvm::StringRef FilePath = SM.getFilename(Sel.Cursor);
tooling::Replacements Reps;
llvm::cantFail(
Reps.add(tooling::Replacement(FilePath, 0, 0, NewContents)));
auto E = llvm::cantFail(Effect::mainFileEdit(SM, std::move(Reps)));
E.FormatEdits = false;
return E;
}
std::string title() const override { return id(); }
llvm::StringLiteral kind() const override {
return llvm::StringLiteral("");
};
};

void contributeTweaks(std::vector<std::unique_ptr<Tweak>> &Out) override {
Out.emplace_back(new ModuleTweak);
}
};

MockFS FS;
MockCompilationDatabase CDB;
auto Opts = ClangdServer::optsForTest();
FeatureModuleSet Set;
Set.add(std::make_unique<TweakContributingModule>());
Opts.FeatureModules = &Set;
ClangdServer Server(CDB, FS, Opts);

auto FooCpp = testPath("foo.cpp");
Server.addDocument(FooCpp, "");
ASSERT_TRUE(Server.blockUntilIdleForTest());

// Ensure that disabled formatting is respected.
Notification N;
Server.applyTweak(FooCpp, {}, TweakID, [&](llvm::Expected<Tweak::Effect> E) {
ASSERT_TRUE(static_cast<bool>(E));
EXPECT_THAT(llvm::cantFail(E->ApplyEdits.lookup(FooCpp).apply()),
NewContents);
N.notify();
});
N.wait();
}
} // namespace
} // namespace clangd
} // namespace clang
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/TargetInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,7 @@ class TargetInfo : public virtual TransferrableTargetInfo,
/// Apply changes to the target information with respect to certain
/// language options which change the target configuration and adjust
/// the language based on the target options where applicable.
virtual void adjust(LangOptions &Opts);
virtual void adjust(DiagnosticsEngine &Diags, LangOptions &Opts);

/// Adjust target options based on codegen options.
virtual void adjustTargetOptions(const CodeGenOptions &CGOpts,
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Basic/TargetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ bool TargetInfo::isTypeSigned(IntType T) {
/// Apply changes to the target information with respect to certain
/// language options which change the target configuration and adjust
/// the language based on the target options where applicable.
void TargetInfo::adjust(LangOptions &Opts) {
void TargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
if (Opts.NoBitFieldTypeAlign)
UseBitFieldTypeAlignment = false;

Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Basic/Targets/AMDGPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,8 @@ AMDGPUTargetInfo::AMDGPUTargetInfo(const llvm::Triple &Triple,
MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
}

void AMDGPUTargetInfo::adjust(LangOptions &Opts) {
TargetInfo::adjust(Opts);
void AMDGPUTargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
TargetInfo::adjust(Diags, Opts);
// ToDo: There are still a few places using default address space as private
// address space in OpenCL, which needs to be cleaned up, then Opts.OpenCL
// can be removed from the following line.
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Basic/Targets/AMDGPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {

void setAddressSpaceMap(bool DefaultIsPrivate);

void adjust(LangOptions &Opts) override;
void adjust(DiagnosticsEngine &Diags, LangOptions &Opts) override;

uint64_t getPointerWidthV(unsigned AddrSpace) const override {
if (isR600(getTriple()))
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Basic/Targets/PPC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,10 +614,10 @@ void PPCTargetInfo::fillValidCPUList(SmallVectorImpl<StringRef> &Values) const {
Values.append(std::begin(ValidCPUNames), std::end(ValidCPUNames));
}

void PPCTargetInfo::adjust(LangOptions &Opts) {
void PPCTargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
if (HasAltivec)
Opts.AltiVec = 1;
TargetInfo::adjust(Opts);
TargetInfo::adjust(Diags, Opts);
if (LongDoubleFormat != &llvm::APFloat::IEEEdouble())
LongDoubleFormat = Opts.PPCIEEELongDouble
? &llvm::APFloat::IEEEquad()
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Basic/Targets/PPC.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class LLVM_LIBRARY_VISIBILITY PPCTargetInfo : public TargetInfo {
}

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

// Note: GCC recognizes the following additional cpus:
// 401, 403, 405, 405fp, 440fp, 464, 464fp, 476, 476fp, 505, 740, 801,
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Basic/Targets/SPIR.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ class LLVM_LIBRARY_VISIBILITY SPIRTargetInfo : public TargetInfo {
AddrSpaceMap = DefaultIsGeneric ? &SPIRDefIsGenMap : &SPIRDefIsPrivMap;
}

void adjust(LangOptions &Opts) override {
TargetInfo::adjust(Opts);
void adjust(DiagnosticsEngine &Diags, LangOptions &Opts) override {
TargetInfo::adjust(Diags, Opts);
// NOTE: SYCL specification considers unannotated pointers and references
// to be pointing to the generic address space. See section 5.9.3 of
// SYCL 2020 specification.
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/Basic/Targets/WebAssembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ ArrayRef<Builtin::Info> WebAssemblyTargetInfo::getTargetBuiltins() const {
Builtin::FirstTSBuiltin);
}

void WebAssemblyTargetInfo::adjust(LangOptions &Opts) {
void WebAssemblyTargetInfo::adjust(DiagnosticsEngine &Diags,
LangOptions &Opts) {
// If the Atomics feature isn't available, turn off POSIXThreads and
// ThreadModel, so that we don't predefine _REENTRANT or __STDCPP_THREADS__.
if (!HasAtomics) {
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Basic/Targets/WebAssembly.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public TargetInfo {

bool hasProtectedVisibility() const override { return false; }

void adjust(LangOptions &Opts) override;
void adjust(DiagnosticsEngine &Diags, LangOptions &Opts) override;
};

class LLVM_LIBRARY_VISIBILITY WebAssembly32TargetInfo
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Frontend/ASTUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ class ASTInfoCollector : public ASTReaderListener {
//
// FIXME: We shouldn't need to do this, the target should be immutable once
// created. This complexity should be lifted elsewhere.
Target->adjust(LangOpt);
Target->adjust(PP.getDiagnostics(), LangOpt);

// Initialize the preprocessor.
PP.Initialize(*Target);
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Frontend/CompilerInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ bool CompilerInstance::createTarget() {
//
// FIXME: We shouldn't need to do this, the target should be immutable once
// created. This complexity should be lifted elsewhere.
getTarget().adjust(getLangOpts());
getTarget().adjust(getDiagnostics(), getLangOpts());

// Adjust target options based on codegen options.
getTarget().adjustTargetOptions(getCodeGenOpts(), getTargetOpts());
Expand Down Expand Up @@ -460,7 +460,7 @@ void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) {
getSourceManager(), *HeaderInfo, *this,
/*IdentifierInfoLookup=*/nullptr,
/*OwnsHeaderSearch=*/true, TUKind);
getTarget().adjust(getLangOpts());
getTarget().adjust(getDiagnostics(), getLangOpts());
PP->Initialize(getTarget(), getAuxTarget());

if (PPOpts.DetailedRecord)
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Interpreter/Interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ CreateCI(const llvm::opt::ArgStringList &Argv) {
"Initialization failed. "
"Target is missing");

Clang->getTarget().adjust(Clang->getLangOpts());
Clang->getTarget().adjust(Clang->getDiagnostics(), Clang->getLangOpts());

return std::move(Clang);
}
Expand Down
8 changes: 5 additions & 3 deletions clang/test/CodeGen/convergent-functions.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// RUN: %clang_cc1 -triple i386-pc-win32 -emit-llvm -fconvergent-functions -o - < %s | FileCheck -check-prefix=CONVFUNC %s
// RUN: %clang_cc1 -triple i386-pc-win32 -emit-llvm -o - < %s | FileCheck -check-prefix=NOCONVFUNC %s
// RUN: %clang_cc1 -triple i386-pc-win32 -emit-llvm -fconvergent-functions -o - < %s | FileCheck -check-prefixes=CHECK,CONVFUNC %s
// RUN: %clang_cc1 -triple i386-pc-win32 -emit-llvm -o - < %s | FileCheck -check-prefixes=CHECK,NOCONVFUNC %s

// Test that the -fconvergent-functions flag works

// CONVFUNC: attributes #0 = { convergent {{.*}} }
// CHECK: attributes #0 = {
// NOCONVFUNC-NOT: convergent
// CONVFUNC-SAME: convergent
// CHECK-SAME: }
void func() { }
2 changes: 1 addition & 1 deletion clang/test/CodeGenCUDA/convergent.cu
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ __host__ __device__ void bar() {
// HOST: declare void @_Z3bazv() [[BAZ_ATTR:#[0-9]+]]
// HOST: attributes [[BAZ_ATTR]] = {
// HOST-NOT: convergent
// NOST-SAME: }
// HOST-SAME: }
2 changes: 1 addition & 1 deletion clang/test/CodeGenCUDA/dft-func-attr-skip-intrinsic.hip
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ __device__ float foo(float x) {
// CHECK: attributes [[ATTR1]] = { convergent
// CHECK: attributes [[ATTR2]] = {
// CHECK-NOT: convergent
// CHECK: }
// CHECK-SAME: }
2 changes: 1 addition & 1 deletion clang/tools/clang-import-test/clang-import-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ std::unique_ptr<CompilerInstance> BuildCompilerInstance() {
TargetInfo *TI = TargetInfo::CreateTargetInfo(
Ins->getDiagnostics(), Ins->getInvocation().TargetOpts);
Ins->setTarget(TI);
Ins->getTarget().adjust(Ins->getLangOpts());
Ins->getTarget().adjust(Ins->getDiagnostics(), Ins->getLangOpts());
Ins->createFileManager();
Ins->createSourceManager(Ins->getFileManager());
Ins->createPreprocessor(TU_Complete);
Expand Down
35 changes: 35 additions & 0 deletions clang/www/cxx_status.html
Original file line number Diff line number Diff line change
Expand Up @@ -1283,6 +1283,41 @@ <h2 id="cxx23">C++2b implementation status</h2>
<td><a href="https://wg21.link/p2266r1">P2266R1</a></td>
<td class="unreleased" align="center">Clang 13</td>
</tr>
<tr>
<td><tt>if consteval</tt></td>
<td><a href="https://wg21.link/P1938R3">P1938R3</a></td>
<td class="none" align="center">No</td>
</tr>
<tr>
<td>Allow duplicate attributes</td>
<td><a href="https://wg21.link/P2156R1">P2156R1</a></td>
<td class="unreleased" align="center">Clang 13</td>
</tr>
<tr>
<td>Narrowing contextual conversions to bool</td>
<td><a href="https://wg21.link/P1401R5">P1401R5</a></td>
<td class="none" align="center">No</td>
</tr>
<tr>
<td>Trimming whitespaces before line splicing</td>
<td><a href="https://wg21.link/P2223R2">P2223R2</a></td>
<td class="full" align="center">Yes</td>
</tr>
<tr>
<td>Make declaration order layout mandated</td>
<td><a href="https://wg21.link/p1847r4">P1874R4</a></td>
<td class="full" align="center">Yes</td>
</tr>
<tr>
<td>C++ identifier syntax using UAX 31</td>
<td><a href="https://wg21.link/P1949R7">P1949R7</a></td>
<td class="none" align="center">No</td>
</tr>
<tr>
<td>Mixed string literal concatenation</td>
<td><a href="https://wg21.link/p2201r1">P2201R1</a></td>
<td class="full" align="center">Yes</td>
</tr>
</table>
</details>

Expand Down
19 changes: 17 additions & 2 deletions compiler-rt/lib/hwasan/hwasan_report.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,9 +630,24 @@ void ReportTagMismatch(StackTrace *stack, uptr tagged_addr, uptr access_size,
Printf("%s of size %zu at %p tags: %02x/%02x (ptr/mem) in thread T%zd\n",
is_store ? "WRITE" : "READ", access_size, untagged_addr, ptr_tag,
mem_tag, t->unique_id());
if (mem_tag < kShadowAlignment) {
tag_t *granule_ptr = reinterpret_cast<tag_t *>((untagged_addr + offset) &
~(kShadowAlignment - 1));
// If offset is 0, (untagged_addr + offset) is not aligned to granules.
// This is the offset of the leftmost accessed byte within the bad granule.
u8 in_granule_offset = (untagged_addr + offset) & (kShadowAlignment - 1);
// The first mismatch was a short granule that matched the ptr_tag.
if (granule_ptr[kShadowAlignment - 1] == ptr_tag) {
// If the access starts after the end of the short granule, then the first
// bad byte is the first byte of the access; otherwise it is the first
// byte past the end of the short granule
if (mem_tag > in_granule_offset) {
offset += mem_tag - in_granule_offset;
}
}
}
if (offset != 0)
Printf("Invalid access starting at offset [%zu, %zu)\n", offset,
Min(access_size, static_cast<uptr>(offset) + (1 << kShadowScale)));
Printf("Invalid access starting at offset %zu\n", offset);
Printf("%s", d.Default());

stack->Print();
Expand Down
23 changes: 19 additions & 4 deletions compiler-rt/test/hwasan/TestCases/heap-buffer-overflow-into.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// RUN: %clang_hwasan %s -o %t
// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
// RUN: not %run %t 5 10 2>&1 | FileCheck %s --check-prefix=CHECK5
// RUN: not %run %t 7 10 2>&1 | FileCheck %s --check-prefix=CHECK7
// RUN: not %run %t 8 20 2>&1 | FileCheck %s --check-prefix=CHECK8
// RUN: not %run %t 32 20 2>&1 | FileCheck %s --check-prefix=CHECK32

// REQUIRES: stable-runtime

Expand All @@ -10,8 +13,20 @@

int main(int argc, char **argv) {
__hwasan_enable_allocator_tagging();
char *volatile x = (char *)malloc(10);
memset(x + 5, 0, 26);
// CHECK: is located 5 bytes inside 10-byte region
if (argc < 2) {
fprintf(stderr, "Invalid number of arguments.");
abort();
}
int read_offset = argc < 2 ? 5 : atoi(argv[1]);
int size = argc < 3 ? 10 : atoi(argv[2]);
char *volatile x = (char *)malloc(size);
memset(x + read_offset, 0, 26);
// CHECK5: Invalid access starting at offset 5
// CHECK5: is located 5 bytes inside 10-byte region
// CHECK7: Invalid access starting at offset 3
// CHECK7: is located 7 bytes inside 10-byte region
// CHECK8: Invalid access starting at offset 12
// CHECK8: is located 8 bytes inside 20-byte region
// CHECK32: is located 12 bytes to the right of 20-byte region
free(x);
}
2 changes: 2 additions & 0 deletions compiler-rt/test/hwasan/TestCases/heap-buffer-overflow.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ int main(int argc, char **argv) {
// CHECKM: is located 0 bytes to the right of 1000000-byte region
//
// CHECK31: tags: [[TAG:..]]/0e (ptr/mem)
// CHECK31-NOT: Invalid access starting at offset
// CHECK31: is located 1 bytes to the right of 30-byte region
// CHECK31: Memory tags around the buggy address
// CHECK31: [0e]
// CHECK31: Tags for short granules around the buggy address
// CHECK31: {{\[}}[[TAG]]]
//
// CHECK20-NOT: Invalid access starting at offset
// CHECK20: is located 10 bytes to the right of 20-byte region [0x{{.*}}0,0x{{.*}}4)
free(x);
}
2 changes: 1 addition & 1 deletion compiler-rt/test/hwasan/TestCases/mem-intrinsics.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ int main() {
write(STDOUT_FILENO, "recovered\n", 10);
// WRITE: ERROR: HWAddressSanitizer: tag-mismatch on address
// WRITE: WRITE of size 32 at {{.*}} tags: [[PTR_TAG:..]]/[[MEM_TAG:..]] (ptr/mem)
// WRITE: Invalid access starting at offset [16, 32)
// WRITE: Invalid access starting at offset 16
// WRITE: Memory tags around the buggy address (one tag corresponds to 16 bytes):
// WRITE: =>{{.*}}[[PTR_TAG]]{{[[:space:]]\[}}[[MEM_TAG]]
// WRITE-NOT: recovered
Expand Down
Loading

0 comments on commit b31a2e4

Please sign in to comment.