Skip to content

Commit ed00cc0

Browse files
author
Sriya Pratipati
committed
Merge branch 'main' into mblen-implementation
2 parents 692505f + 5edb845 commit ed00cc0

File tree

87 files changed

+3977
-1241
lines changed

Some content is hidden

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

87 files changed

+3977
-1241
lines changed

.github/workflows/premerge.yaml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ jobs:
3434
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3535
with:
3636
fetch-depth: 2
37-
- name: Setup ccache
38-
uses: hendrikmuhs/ccache-action@a1209f81afb8c005c13b4296c32e363431bffea5 # v1.2.17
39-
with:
40-
variant: "sccache"
41-
max-size: "2000M"
4237
- name: Build and Test
4338
# Mark the job as a success even if the step fails so that people do
4439
# not get notified while the new premerge pipeline is in an
@@ -62,6 +57,13 @@ jobs:
6257
export CC=/opt/llvm/bin/clang
6358
export CXX=/opt/llvm/bin/clang++
6459
60+
# This environment variable is passes into the container through the
61+
# runner pod definition. This differs between our two clusters which
62+
# why we do not hardcode it.
63+
export SCCACHE_GCS_BUCKET=$CACHE_GCS_BUCKET
64+
export SCCACHE_GCS_RW_MODE=READ_WRITE
65+
sccache --start-server
66+
6567
./.ci/monolithic-linux.sh "${projects_to_build}" "${project_check_targets}" "${runtimes_to_build}" "${runtimes_check_targets}" "${runtimes_check_targets_needs_reconfig}" "${enable_cir}"
6668
- name: Upload Artifacts
6769
if: '!cancelled()'

clang/include/clang/Basic/LangOptions.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,8 @@ LANGOPT(CheckConstexprFunctionBodies, 1, 1, Benign,
491491

492492
LANGOPT(BoundsSafety, 1, 0, NotCompatible, "Bounds safety extension for C")
493493

494+
LANGOPT(EnableLifetimeSafety, 1, 0, NotCompatible, "Experimental lifetime safety analysis for C++")
495+
494496
LANGOPT(PreserveVec3Type, 1, 0, NotCompatible, "Preserve 3-component vector type")
495497

496498
#undef LANGOPT

clang/include/clang/Driver/Options.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,6 +1904,14 @@ defm bounds_safety : BoolFOption<
19041904
BothFlags<[], [CC1Option],
19051905
" experimental bounds safety extension for C">>;
19061906

1907+
defm lifetime_safety : BoolFOption<
1908+
"experimental-lifetime-safety",
1909+
LangOpts<"EnableLifetimeSafety">, DefaultFalse,
1910+
PosFlag<SetTrue, [], [CC1Option], "Enable">,
1911+
NegFlag<SetFalse, [], [CC1Option], "Disable">,
1912+
BothFlags<[], [CC1Option],
1913+
" experimental lifetime safety for C++">>;
1914+
19071915
defm addrsig : BoolFOption<"addrsig",
19081916
CodeGenOpts<"Addrsig">, DefaultFalse,
19091917
PosFlag<SetTrue, [], [ClangOption, CC1Option], "Emit">,

clang/lib/Basic/Targets.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,9 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
757757
case llvm::Triple::FreeBSD:
758758
return std::make_unique<FreeBSDTargetInfo<LoongArch64TargetInfo>>(Triple,
759759
Opts);
760+
case llvm::Triple::OpenBSD:
761+
return std::make_unique<OpenBSDTargetInfo<LoongArch64TargetInfo>>(Triple,
762+
Opts);
760763
default:
761764
return std::make_unique<LoongArch64TargetInfo>(Triple, Opts);
762765
}

clang/lib/Basic/Targets/OSTargets.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ class LLVM_LIBRARY_VISIBILITY OpenBSDTargetInfo : public OSTargetInfo<Target> {
496496
case llvm::Triple::sparcv9:
497497
this->MCountName = "_mcount";
498498
break;
499+
case llvm::Triple::loongarch64:
499500
case llvm::Triple::riscv64:
500501
break;
501502
}

clang/lib/Driver/ToolChains/OpenBSD.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ void openbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
161161
if (Nopie || Profiling)
162162
CmdArgs.push_back("-nopie");
163163

164-
if (Triple.isRISCV64()) {
164+
if (Triple.isLoongArch64() || Triple.isRISCV64()) {
165165
CmdArgs.push_back("-X");
166166
if (Args.hasArg(options::OPT_mno_relax))
167167
CmdArgs.push_back("--no-relax");

clang/lib/Sema/AnalysisBasedWarnings.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2901,8 +2901,7 @@ void clang::sema::AnalysisBasedWarnings::IssueWarnings(
29012901
.setAlwaysAdd(Stmt::UnaryOperatorClass);
29022902
}
29032903

2904-
bool EnableLifetimeSafetyAnalysis = !Diags.isIgnored(
2905-
diag::warn_experimental_lifetime_safety_dummy_warning, D->getBeginLoc());
2904+
bool EnableLifetimeSafetyAnalysis = S.getLangOpts().EnableLifetimeSafety;
29062905
// Install the logical handler.
29072906
std::optional<LogicalErrorHandler> LEH;
29082907
if (LogicalErrorHandler::hasActiveDiagnostics(Diags, D->getBeginLoc())) {

clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp

Lines changed: 36 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "clang/Tooling/DependencyScanning/DependencyScanningService.h"
2525
#include "clang/Tooling/DependencyScanning/InProcessModuleCache.h"
2626
#include "clang/Tooling/DependencyScanning/ModuleDepCollector.h"
27-
#include "clang/Tooling/Tooling.h"
2827
#include "llvm/ADT/IntrusiveRefCntPtr.h"
2928
#include "llvm/Support/Allocator.h"
3029
#include "llvm/Support/Error.h"
@@ -376,25 +375,23 @@ class ScanningDependencyDirectivesGetter : public DependencyDirectivesGetter {
376375

377376
/// A clang tool that runs the preprocessor in a mode that's optimized for
378377
/// dependency scanning for the given compiler invocation.
379-
class DependencyScanningAction : public tooling::ToolAction {
378+
class DependencyScanningAction {
380379
public:
381380
DependencyScanningAction(
382381
DependencyScanningService &Service, StringRef WorkingDirectory,
383382
DependencyConsumer &Consumer, DependencyActionController &Controller,
384383
llvm::IntrusiveRefCntPtr<DependencyScanningWorkerFilesystem> DepFS,
385-
bool DisableFree, std::optional<StringRef> ModuleName = std::nullopt)
384+
std::optional<StringRef> ModuleName = std::nullopt)
386385
: Service(Service), WorkingDirectory(WorkingDirectory),
387386
Consumer(Consumer), Controller(Controller), DepFS(std::move(DepFS)),
388-
DisableFree(DisableFree), ModuleName(ModuleName) {}
387+
ModuleName(ModuleName) {}
389388

390389
bool runInvocation(std::shared_ptr<CompilerInvocation> Invocation,
391-
FileManager *DriverFileMgr,
390+
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS,
392391
std::shared_ptr<PCHContainerOperations> PCHContainerOps,
393-
DiagnosticConsumer *DiagConsumer) override {
392+
DiagnosticConsumer *DiagConsumer) {
394393
// Make a deep copy of the original Clang invocation.
395394
CompilerInvocation OriginalInvocation(*Invocation);
396-
// Restore the value of DisableFree, which may be modified by Tooling.
397-
OriginalInvocation.getFrontendOpts().DisableFree = DisableFree;
398395
if (any(Service.getOptimizeArgs() & ScanningOptimizations::Macros))
399396
canonicalizeDefines(OriginalInvocation.getPreprocessorOpts());
400397

@@ -419,8 +416,8 @@ class DependencyScanningAction : public tooling::ToolAction {
419416
// Create the compiler's actual diagnostics engine.
420417
sanitizeDiagOpts(ScanInstance.getDiagnosticOpts());
421418
assert(!DiagConsumerFinished && "attempt to reuse finished consumer");
422-
ScanInstance.createDiagnostics(DriverFileMgr->getVirtualFileSystem(),
423-
DiagConsumer, /*ShouldOwnClient=*/false);
419+
ScanInstance.createDiagnostics(*FS, DiagConsumer,
420+
/*ShouldOwnClient=*/false);
424421
if (!ScanInstance.hasDiagnostics())
425422
return false;
426423

@@ -431,6 +428,7 @@ class DependencyScanningAction : public tooling::ToolAction {
431428
ScanInstance.getHeaderSearchOpts().BuildSessionTimestamp =
432429
Service.getBuildSessionTimestamp();
433430

431+
ScanInstance.getFrontendOpts().DisableFree = false;
434432
ScanInstance.getFrontendOpts().GenerateGlobalModuleIndex = false;
435433
ScanInstance.getFrontendOpts().UseGlobalModuleIndex = false;
436434
// This will prevent us compiling individual modules asynchronously since
@@ -441,9 +439,9 @@ class DependencyScanningAction : public tooling::ToolAction {
441439
any(Service.getOptimizeArgs() & ScanningOptimizations::VFS);
442440

443441
// Support for virtual file system overlays.
444-
auto FS = createVFSFromCompilerInvocation(
445-
ScanInstance.getInvocation(), ScanInstance.getDiagnostics(),
446-
DriverFileMgr->getVirtualFileSystemPtr());
442+
FS = createVFSFromCompilerInvocation(ScanInstance.getInvocation(),
443+
ScanInstance.getDiagnostics(),
444+
std::move(FS));
447445

448446
// Create a new FileManager to match the invocation's FileSystemOptions.
449447
auto *FileMgr = ScanInstance.createFileManager(FS);
@@ -554,9 +552,6 @@ class DependencyScanningAction : public tooling::ToolAction {
554552
if (Result)
555553
setLastCC1Arguments(std::move(OriginalInvocation));
556554

557-
// Propagate the statistics to the parent FileManager.
558-
DriverFileMgr->AddStats(ScanInstance.getFileManager());
559-
560555
return Result;
561556
}
562557

@@ -584,7 +579,6 @@ class DependencyScanningAction : public tooling::ToolAction {
584579
DependencyConsumer &Consumer;
585580
DependencyActionController &Controller;
586581
llvm::IntrusiveRefCntPtr<DependencyScanningWorkerFilesystem> DepFS;
587-
bool DisableFree;
588582
std::optional<StringRef> ModuleName;
589583
std::optional<CompilerInstance> ScanInstanceStorage;
590584
std::shared_ptr<ModuleDepCollector> MDC;
@@ -669,15 +663,14 @@ llvm::Error DependencyScanningWorker::computeDependencies(
669663
}
670664

671665
static bool forEachDriverJob(
672-
ArrayRef<std::string> ArgStrs, DiagnosticsEngine &Diags, FileManager &FM,
666+
ArrayRef<std::string> ArgStrs, DiagnosticsEngine &Diags,
667+
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS,
673668
llvm::function_ref<bool(const driver::Command &Cmd)> Callback) {
674669
SmallVector<const char *, 256> Argv;
675670
Argv.reserve(ArgStrs.size());
676671
for (const std::string &Arg : ArgStrs)
677672
Argv.push_back(Arg.c_str());
678673

679-
llvm::vfs::FileSystem *FS = &FM.getVirtualFileSystem();
680-
681674
std::unique_ptr<driver::Driver> Driver = std::make_unique<driver::Driver>(
682675
Argv[0], llvm::sys::getDefaultTargetTriple(), Diags,
683676
"clang LLVM compiler", FS);
@@ -687,7 +680,8 @@ static bool forEachDriverJob(
687680
bool CLMode = driver::IsClangCL(
688681
driver::getDriverMode(Argv[0], ArrayRef(Argv).slice(1)));
689682

690-
if (llvm::Error E = driver::expandResponseFiles(Argv, CLMode, Alloc, FS)) {
683+
if (llvm::Error E =
684+
driver::expandResponseFiles(Argv, CLMode, Alloc, FS.get())) {
691685
Diags.Report(diag::err_drv_expand_response_file)
692686
<< llvm::toString(std::move(E));
693687
return false;
@@ -710,17 +704,25 @@ static bool forEachDriverJob(
710704

711705
static bool createAndRunToolInvocation(
712706
std::vector<std::string> CommandLine, DependencyScanningAction &Action,
713-
FileManager &FM,
707+
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS,
714708
std::shared_ptr<clang::PCHContainerOperations> &PCHContainerOps,
715709
DiagnosticsEngine &Diags, DependencyConsumer &Consumer) {
716710

717711
// Save executable path before providing CommandLine to ToolInvocation
718712
std::string Executable = CommandLine[0];
719-
ToolInvocation Invocation(std::move(CommandLine), &Action, &FM,
720-
PCHContainerOps);
721-
Invocation.setDiagnosticConsumer(Diags.getClient());
722-
Invocation.setDiagnosticOptions(&Diags.getDiagnosticOptions());
723-
if (!Invocation.run())
713+
714+
llvm::opt::ArgStringList Argv;
715+
for (const std::string &Str : ArrayRef(CommandLine).drop_front())
716+
Argv.push_back(Str.c_str());
717+
718+
auto Invocation = std::make_shared<CompilerInvocation>();
719+
if (!CompilerInvocation::CreateFromArgs(*Invocation, Argv, Diags)) {
720+
// FIXME: Should we just go on like cc1_main does?
721+
return false;
722+
}
723+
724+
if (!Action.runInvocation(std::move(Invocation), std::move(FS),
725+
PCHContainerOps, Diags.getClient()))
724726
return false;
725727

726728
std::vector<std::string> Args = Action.takeLastCC1Arguments();
@@ -733,37 +735,24 @@ bool DependencyScanningWorker::scanDependencies(
733735
DependencyConsumer &Consumer, DependencyActionController &Controller,
734736
DiagnosticConsumer &DC, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS,
735737
std::optional<StringRef> ModuleName) {
736-
auto FileMgr =
737-
llvm::makeIntrusiveRefCnt<FileManager>(FileSystemOptions{}, FS);
738-
739738
std::vector<const char *> CCommandLine(CommandLine.size(), nullptr);
740739
llvm::transform(CommandLine, CCommandLine.begin(),
741740
[](const std::string &Str) { return Str.c_str(); });
742741
auto DiagOpts = CreateAndPopulateDiagOpts(CCommandLine);
743742
sanitizeDiagOpts(*DiagOpts);
744-
IntrusiveRefCntPtr<DiagnosticsEngine> Diags =
745-
CompilerInstance::createDiagnostics(FileMgr->getVirtualFileSystem(),
746-
*DiagOpts, &DC,
747-
/*ShouldOwnClient=*/false);
748-
749-
// Although `Diagnostics` are used only for command-line parsing, the
750-
// custom `DiagConsumer` might expect a `SourceManager` to be present.
751-
SourceManager SrcMgr(*Diags, *FileMgr);
752-
Diags->setSourceManager(&SrcMgr);
753-
// DisableFree is modified by Tooling for running
754-
// in-process; preserve the original value, which is
755-
// always true for a driver invocation.
756-
bool DisableFree = true;
743+
auto Diags = CompilerInstance::createDiagnostics(*FS, *DiagOpts, &DC,
744+
/*ShouldOwnClient=*/false);
745+
757746
DependencyScanningAction Action(Service, WorkingDirectory, Consumer,
758-
Controller, DepFS, DisableFree, ModuleName);
747+
Controller, DepFS, ModuleName);
759748

760749
bool Success = false;
761750
if (CommandLine[1] == "-cc1") {
762-
Success = createAndRunToolInvocation(CommandLine, Action, *FileMgr,
751+
Success = createAndRunToolInvocation(CommandLine, Action, FS,
763752
PCHContainerOps, *Diags, Consumer);
764753
} else {
765754
Success = forEachDriverJob(
766-
CommandLine, *Diags, *FileMgr, [&](const driver::Command &Cmd) {
755+
CommandLine, *Diags, FS, [&](const driver::Command &Cmd) {
767756
if (StringRef(Cmd.getCreator().getName()) != "clang") {
768757
// Non-clang command. Just pass through to the dependency
769758
// consumer.
@@ -782,7 +771,7 @@ bool DependencyScanningWorker::scanDependencies(
782771
// system to ensure that any file system requests that
783772
// are made by the driver do not go through the
784773
// dependency scanning filesystem.
785-
return createAndRunToolInvocation(std::move(Argv), Action, *FileMgr,
774+
return createAndRunToolInvocation(std::move(Argv), Action, FS,
786775
PCHContainerOps, *Diags, Consumer);
787776
});
788777
}

clang/test/CodeGenCXX/microsoft-abi-eh-disabled.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %clang_cl -c --target=x86_64-windows-msvc /EHs-c- -O2 /GS- \
22
// RUN: -Xclang=-import-call-optimization \
3-
// RUN: /clang:-S /clang:-o- %s 2>&1 \
3+
// RUN: /clang:-S /clang:-o- -- %s 2>&1 \
44
// RUN: | FileCheck %s
55

66
#ifdef __clang__

clang/test/CodeGenCXX/microsoft-abi-eh-ip2state.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %clang_cl -c --target=x86_64-windows-msvc -O2 /EHsc /GS- \
22
// RUN: -Xclang=-import-call-optimization \
3-
// RUN: /clang:-S /clang:-o- %s 2>&1 \
3+
// RUN: /clang:-S /clang:-o- -- %s 2>&1 \
44
// RUN: | FileCheck %s
55

66
#ifdef __clang__

0 commit comments

Comments
 (0)