Skip to content

Commit d3aea99

Browse files
authored
Merge branch 'main' into fix/112208
2 parents 59e54ca + d8b17f2 commit d3aea99

File tree

113 files changed

+3326
-1042
lines changed

Some content is hidden

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

113 files changed

+3326
-1042
lines changed

clang/lib/Driver/ToolChains/Cuda.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,8 +634,8 @@ void NVPTX::Linker::ConstructJob(Compilation &C, const JobAction &JA,
634634
std::vector<StringRef> Features;
635635
getNVPTXTargetFeatures(C.getDriver(), getToolChain().getTriple(), Args,
636636
Features);
637-
for (StringRef Feature : Features)
638-
CmdArgs.append({"--feature", Args.MakeArgString(Feature)});
637+
CmdArgs.push_back(
638+
Args.MakeArgString("--plugin-opt=-mattr=" + llvm::join(Features, ",")));
639639

640640
// Add paths for the default clang library path.
641641
SmallString<256> DefaultLibPath =

clang/test/Driver/cuda-cross-compiling.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,4 @@
104104
// RUN: %clang -target nvptx64-nvidia-cuda --cuda-feature=+ptx63 -march=sm_52 -### %s 2>&1 \
105105
// RUN: | FileCheck -check-prefix=FEATURE %s
106106

107-
// FEATURE: clang-nvlink-wrapper{{.*}}"--feature" "+ptx63"
107+
// FEATURE: clang-nvlink-wrapper{{.*}}"--plugin-opt=-mattr=+ptx63"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: echo '{' > %t.json
2+
// RUN: echo ' "married": true' >> %t.json
3+
// RUN: echo '}' >> %t.json
4+
5+
// RUN: clang-format -n -style=LLVM %t.json 2>&1 | FileCheck %s -allow-empty
6+
7+
// RUN: clang-format -n -style=LLVM < %t.json 2>&1 \
8+
// RUN: | FileCheck %s -check-prefix=CHECK2 -strict-whitespace
9+
10+
// RUN: echo '{' > %t.json
11+
// RUN: echo ' "married" : true' >> %t.json
12+
// RUN: echo '}' >> %t.json
13+
14+
// RUN: clang-format -n -style=LLVM < %t.json 2>&1 | FileCheck %s -allow-empty
15+
16+
// RUN: clang-format -n -style=LLVM %t.json 2>&1 \
17+
// RUN: | FileCheck %s -check-prefix=CHECK2 -strict-whitespace
18+
19+
// RUN: rm %t.json
20+
21+
// CHECK-NOT: warning
22+
// CHECK2: warning: code should be clang-formatted

clang/tools/clang-format/ClangFormat.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,6 @@ static void outputReplacementsXML(const Replacements &Replaces) {
351351
static bool
352352
emitReplacementWarnings(const Replacements &Replaces, StringRef AssumedFileName,
353353
const std::unique_ptr<llvm::MemoryBuffer> &Code) {
354-
if (Replaces.empty())
355-
return false;
356-
357354
unsigned Errors = 0;
358355
if (WarnFormat && !NoWarnFormat) {
359356
SourceMgr Mgr;
@@ -490,9 +487,11 @@ static bool format(StringRef FileName, bool ErrorOnIncompleteFormat = false) {
490487
Replacements Replaces = sortIncludes(*FormatStyle, Code->getBuffer(), Ranges,
491488
AssumedFileName, &CursorPosition);
492489

490+
const bool IsJson = FormatStyle->isJson();
491+
493492
// To format JSON insert a variable to trick the code into thinking its
494493
// JavaScript.
495-
if (FormatStyle->isJson() && !FormatStyle->DisableFormat) {
494+
if (IsJson && !FormatStyle->DisableFormat) {
496495
auto Err = Replaces.add(tooling::Replacement(
497496
tooling::Replacement(AssumedFileName, 0, 0, "x = ")));
498497
if (Err)
@@ -510,9 +509,11 @@ static bool format(StringRef FileName, bool ErrorOnIncompleteFormat = false) {
510509
Replacements FormatChanges =
511510
reformat(*FormatStyle, *ChangedCode, Ranges, AssumedFileName, &Status);
512511
Replaces = Replaces.merge(FormatChanges);
513-
if (OutputXML || DryRun) {
514-
if (DryRun)
515-
return emitReplacementWarnings(Replaces, AssumedFileName, Code);
512+
if (DryRun) {
513+
return Replaces.size() > (IsJson ? 1 : 0) &&
514+
emitReplacementWarnings(Replaces, AssumedFileName, Code);
515+
}
516+
if (OutputXML) {
516517
outputXML(Replaces, FormatChanges, Status, Cursor, CursorPosition);
517518
} else {
518519
IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem(

clang/tools/clang-nvlink-wrapper/ClangNVLinkWrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ Expected<std::unique_ptr<lto::LTO>> createLTO(const ArgList &Args) {
344344
Conf.RemarksHotnessThreshold = RemarksHotnessThreshold;
345345
Conf.RemarksFormat = RemarksFormat;
346346

347-
Conf.MAttrs = {Args.getLastArgValue(OPT_feature, "").str()};
347+
Conf.MAttrs = llvm::codegen::getMAttrs();
348348
std::optional<CodeGenOptLevel> CGOptLevelOrNone =
349349
CodeGenOpt::parseLevel(Args.getLastArgValue(OPT_O, "2")[0]);
350350
assert(CGOptLevelOrNone && "Invalid optimization level");

clang/tools/clang-nvlink-wrapper/NVLinkOpts.td

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ def arch : Separate<["--", "-"], "arch">,
4747
def : Joined<["--", "-"], "plugin-opt=mcpu=">,
4848
Flags<[HelpHidden, WrapperOnlyOption]>, Alias<arch>;
4949

50-
def feature : Separate<["--", "-"], "feature">, Flags<[WrapperOnlyOption]>,
51-
HelpText<"Specify the '+ptx' freature to use for LTO.">;
52-
5350
def g : Flag<["-"], "g">, HelpText<"Specify that this was a debug compile.">;
5451
def debug : Flag<["--"], "debug">, Alias<g>;
5552

compiler-rt/lib/lsan/lsan_common.cpp

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,27 @@ struct DirectMemoryAccessor {
293293
void Init(uptr begin, uptr end) {};
294294
void *LoadPtr(uptr p) const { return *reinterpret_cast<void **>(p); }
295295
};
296+
297+
struct CopyMemoryAccessor {
298+
void Init(uptr begin, uptr end) {
299+
this->begin = begin;
300+
buffer.clear();
301+
buffer.resize(end - begin);
302+
MemCpyAccessible(buffer.data(), reinterpret_cast<void *>(begin),
303+
buffer.size());
304+
};
305+
306+
void *LoadPtr(uptr p) const {
307+
uptr offset = p - begin;
308+
CHECK_LE(offset + sizeof(void *), reinterpret_cast<uptr>(buffer.size()));
309+
return *reinterpret_cast<void **>(offset +
310+
reinterpret_cast<uptr>(buffer.data()));
311+
}
312+
313+
private:
314+
uptr begin;
315+
InternalMmapVector<char> buffer;
316+
};
296317
} // namespace
297318

298319
// Scans the memory range, looking for byte patterns that point into allocator
@@ -373,18 +394,18 @@ void ScanGlobalRange(uptr begin, uptr end, Frontier *frontier) {
373394
}
374395

375396
template <class Accessor>
376-
void ScanExtraStack(const InternalMmapVector<Range> &ranges, Frontier *frontier,
377-
Accessor &accessor) {
397+
void ScanRanges(const InternalMmapVector<Range> &ranges, Frontier *frontier,
398+
const char *region_type, Accessor &accessor) {
378399
for (uptr i = 0; i < ranges.size(); i++) {
379-
ScanForPointers(ranges[i].begin, ranges[i].end, frontier, "FAKE STACK",
400+
ScanForPointers(ranges[i].begin, ranges[i].end, frontier, region_type,
380401
kReachable, accessor);
381402
}
382403
}
383404

384405
void ScanExtraStackRanges(const InternalMmapVector<Range> &ranges,
385406
Frontier *frontier) {
386407
DirectMemoryAccessor accessor;
387-
ScanExtraStack(ranges, frontier, accessor);
408+
ScanRanges(ranges, frontier, "FAKE STACK", accessor);
388409
}
389410

390411
# if SANITIZER_FUCHSIA
@@ -478,7 +499,7 @@ static void ProcessThread(tid_t os_id, uptr sp,
478499
ScanForPointers(stack_begin, stack_end, frontier, "STACK", kReachable,
479500
accessor);
480501
GetThreadExtraStackRangesLocked(os_id, &extra_ranges);
481-
ScanExtraStack(extra_ranges, frontier, accessor);
502+
ScanRanges(extra_ranges, frontier, "FAKE STACK", accessor);
482503
}
483504

484505
if (flags()->use_tls) {
@@ -500,13 +521,14 @@ static void ProcessThread(tid_t os_id, uptr sp,
500521
}
501522
}
502523
# if SANITIZER_ANDROID
524+
extra_ranges.clear();
503525
auto *cb = +[](void *dtls_begin, void *dtls_end, uptr /*dso_idd*/,
504526
void *arg) -> void {
505-
ScanForPointers(
506-
reinterpret_cast<uptr>(dtls_begin), reinterpret_cast<uptr>(dtls_end),
507-
reinterpret_cast<Frontier *>(arg), "DTLS", kReachable, accessor);
527+
reinterpret_cast<InternalMmapVector<Range> *>(arg)->push_back(
528+
{reinterpret_cast<uptr>(dtls_begin),
529+
reinterpret_cast<uptr>(dtls_end)});
508530
};
509-
531+
ScanRanges(extra_ranges, frontier, "DTLS", accessor);
510532
// FIXME: There might be a race-condition here (and in Bionic) if the
511533
// thread is suspended in the middle of updating its DTLS. IOWs, we
512534
// could scan already freed memory. (probably fine for now)
@@ -535,6 +557,7 @@ static void ProcessThread(tid_t os_id, uptr sp,
535557
static void ProcessThreads(SuspendedThreadsList const &suspended_threads,
536558
Frontier *frontier, tid_t caller_tid,
537559
uptr caller_sp) {
560+
InternalMmapVector<tid_t> done_threads;
538561
InternalMmapVector<uptr> registers;
539562
InternalMmapVector<Range> extra_ranges;
540563
for (uptr i = 0; i < suspended_threads.ThreadCount(); i++) {
@@ -559,6 +582,25 @@ static void ProcessThreads(SuspendedThreadsList const &suspended_threads,
559582

560583
DirectMemoryAccessor accessor;
561584
ProcessThread(os_id, sp, registers, extra_ranges, frontier, accessor);
585+
if (flags()->use_detached)
586+
done_threads.push_back(os_id);
587+
}
588+
589+
if (flags()->use_detached) {
590+
CopyMemoryAccessor accessor;
591+
InternalMmapVector<tid_t> known_threads;
592+
GetRunningThreadsLocked(&known_threads);
593+
Sort(done_threads.data(), done_threads.size());
594+
for (tid_t os_id : known_threads) {
595+
registers.clear();
596+
extra_ranges.clear();
597+
598+
uptr i = InternalLowerBound(done_threads, os_id);
599+
if (i >= done_threads.size() || done_threads[i] != os_id) {
600+
uptr sp = (os_id == caller_tid) ? caller_sp : 0;
601+
ProcessThread(os_id, sp, registers, extra_ranges, frontier, accessor);
602+
}
603+
}
562604
}
563605

564606
// Add pointers reachable from ThreadContexts

compiler-rt/lib/lsan/lsan_flags.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ LSAN_FLAG(bool, use_ld_allocations, true,
4141
LSAN_FLAG(bool, use_unaligned, false, "Consider unaligned pointers valid.")
4242
LSAN_FLAG(bool, use_poisoned, false,
4343
"Consider pointers found in poisoned memory to be valid.")
44+
LSAN_FLAG(bool, use_detached, false,
45+
"Scan threads even if attaching to them failed.")
4446
LSAN_FLAG(bool, log_pointers, false, "Debug logging")
4547
LSAN_FLAG(bool, log_threads, false, "Debug logging")
4648
LSAN_FLAG(int, tries, 1, "Debug option to repeat leak checking multiple times")

flang/include/flang/Optimizer/Dialect/CUF/CUFOps.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "flang/Optimizer/Dialect/CUF/Attributes/CUFAttr.h"
1313
#include "flang/Optimizer/Dialect/CUF/CUFDialect.h"
1414
#include "flang/Optimizer/Dialect/FIRType.h"
15+
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
1516
#include "mlir/IR/OpDefinition.h"
1617

1718
#define GET_OP_CLASSES

flang/include/flang/Optimizer/Dialect/CUF/CUFOps.td

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ include "flang/Optimizer/Dialect/CUF/CUFDialect.td"
1818
include "flang/Optimizer/Dialect/CUF/Attributes/CUFAttr.td"
1919
include "flang/Optimizer/Dialect/FIRTypes.td"
2020
include "flang/Optimizer/Dialect/FIRAttr.td"
21+
include "mlir/Dialect/LLVMIR/LLVMOpBase.td"
2122
include "mlir/Interfaces/LoopLikeInterface.td"
2223
include "mlir/IR/BuiltinAttributes.td"
2324

@@ -288,15 +289,30 @@ def cuf_KernelOp : cuf_Op<"kernel", [AttrSizedOperandSegments,
288289
let hasVerifier = 1;
289290
}
290291

292+
def cuf_RegisterModuleOp : cuf_Op<"register_module", []> {
293+
let summary = "Register a CUDA module";
294+
295+
let arguments = (ins
296+
SymbolRefAttr:$name
297+
);
298+
299+
let assemblyFormat = [{
300+
$name attr-dict `->` type($modulePtr)
301+
}];
302+
303+
let results = (outs LLVM_AnyPointer:$modulePtr);
304+
}
305+
291306
def cuf_RegisterKernelOp : cuf_Op<"register_kernel", []> {
292307
let summary = "Register a CUDA kernel";
293308

294309
let arguments = (ins
295-
SymbolRefAttr:$name
310+
SymbolRefAttr:$name,
311+
LLVM_AnyPointer:$modulePtr
296312
);
297313

298314
let assemblyFormat = [{
299-
$name attr-dict
315+
$name `(` $modulePtr `:` type($modulePtr) `)`attr-dict
300316
}];
301317

302318
let hasVerifier = 1;

0 commit comments

Comments
 (0)