Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clang/include/clang/Driver/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ enum ClangVisibility {
FlangOption = (1 << 4),
FC1Option = (1 << 5),
DXCOption = (1 << 6),
SYCLRTCOnlyOption = (1 << 7),
};

enum ID {
Expand Down
14 changes: 14 additions & 0 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ def FC1Option : OptionVisibility;
// are made available when the driver is running in DXC compatibility mode.
def DXCOption : OptionVisibility;

def SYCLRTCOnlyOption : OptionVisibility;

/////////
// Docs

Expand Down Expand Up @@ -195,6 +197,11 @@ def sycl_Group : OptionGroup<"<SYCL group>">, Group<f_Group>,
DocName<"SYCL options">,
Visibility<[ClangOption, CLOption]>;

def sycl_rtc_only_Group : OptionGroup<"<SYCL RTC only group">,
Group<f_Group>,
DocName<"SYCL RTC specific options">,
Visibility<[SYCLRTCOnlyOption]>;

def cuda_Group : OptionGroup<"<CUDA group>">, Group<f_Group>,
DocName<"CUDA options">,
Visibility<[ClangOption, CLOption]>;
Expand Down Expand Up @@ -7460,6 +7467,13 @@ def fsyclbin : Flag<["-"], "fsyclbin">, Alias<fsyclbin_EQ>,
AliasArgs<["executable"]>;
} // let Group = sycl_Group

let Visibility = [SYCLRTCOnlyOption] in {
let Group = sycl_rtc_only_Group in {
def auto_pch : Flag<["--"], "auto-pch">,
HelpText<"Enable Auto-PCH for SYCL RTC Compilation">;
} // let Group = sycl_rtc_only_Group
} // let Visibility = [SYCLRTCOnlyOption]

// FIXME: -fsycl-explicit-simd is deprecated. remove it when support is dropped.
def : Flag<["-"], "fsycl-explicit-simd">, Flags<[Deprecated]>,
Group<clang_ignored_legacy_options_Group>,
Expand Down
4 changes: 2 additions & 2 deletions clang/include/clang/Frontend/PrecompiledPreamble.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ class PrecompiledPreamble {
DiagnosticsEngine &Diagnostics,
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
std::shared_ptr<PCHContainerOperations> PCHContainerOps,
bool StoreInMemory, StringRef StoragePath,
PreambleCallbacks &Callbacks);
bool StoreInMemory, StringRef StoragePath, PreambleCallbacks &Callbacks,
bool AllowASTWithErrors = true);

PrecompiledPreamble(PrecompiledPreamble &&);
PrecompiledPreamble &operator=(PrecompiledPreamble &&);
Expand Down
19 changes: 12 additions & 7 deletions clang/lib/Frontend/PrecompiledPreamble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,10 @@ class TempPCHFile {
class PrecompilePreambleAction : public ASTFrontendAction {
public:
PrecompilePreambleAction(std::shared_ptr<PCHBuffer> Buffer, bool WritePCHFile,
PreambleCallbacks &Callbacks)
PreambleCallbacks &Callbacks,
bool AllowASTWithErrors = true)
: Buffer(std::move(Buffer)), WritePCHFile(WritePCHFile),
Callbacks(Callbacks) {}
Callbacks(Callbacks), AllowASTWithErrors(AllowASTWithErrors) {}

std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
StringRef InFile) override;
Expand Down Expand Up @@ -287,16 +288,18 @@ class PrecompilePreambleAction : public ASTFrontendAction {
bool WritePCHFile; // otherwise the PCH is written into the PCHBuffer only.
std::unique_ptr<llvm::raw_pwrite_stream> FileOS; // null if in-memory
PreambleCallbacks &Callbacks;
bool AllowASTWithErrors;
};

class PrecompilePreambleConsumer : public PCHGenerator {
public:
PrecompilePreambleConsumer(PrecompilePreambleAction &Action, Preprocessor &PP,
ModuleCache &ModCache, StringRef isysroot,
std::shared_ptr<PCHBuffer> Buffer)
std::shared_ptr<PCHBuffer> Buffer,
bool AllowASTWithErrors = true)
: PCHGenerator(PP, ModCache, "", isysroot, std::move(Buffer),
ArrayRef<std::shared_ptr<ModuleFileExtension>>(),
/*AllowASTWithErrors=*/true),
AllowASTWithErrors),
Action(Action) {}

bool HandleTopLevelDecl(DeclGroupRef DG) override {
Expand Down Expand Up @@ -337,7 +340,8 @@ PrecompilePreambleAction::CreateASTConsumer(CompilerInstance &CI,
Sysroot.clear();

return std::make_unique<PrecompilePreambleConsumer>(
*this, CI.getPreprocessor(), CI.getModuleCache(), Sysroot, Buffer);
*this, CI.getPreprocessor(), CI.getModuleCache(), Sysroot, Buffer,
AllowASTWithErrors);
}

template <class T> bool moveOnNoError(llvm::ErrorOr<T> Val, T &Output) {
Expand Down Expand Up @@ -415,7 +419,8 @@ llvm::ErrorOr<PrecompiledPreamble> PrecompiledPreamble::Build(
DiagnosticsEngine &Diagnostics,
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
std::shared_ptr<PCHContainerOperations> PCHContainerOps, bool StoreInMemory,
StringRef StoragePath, PreambleCallbacks &Callbacks) {
StringRef StoragePath, PreambleCallbacks &Callbacks,
bool AllowASTWithErrors) {
assert(VFS && "VFS is null");

auto PreambleInvocation = std::make_shared<CompilerInvocation>(Invocation);
Expand Down Expand Up @@ -511,7 +516,7 @@ llvm::ErrorOr<PrecompiledPreamble> PrecompiledPreamble::Build(
auto Act = std::make_unique<PrecompilePreambleAction>(
std::move(Buffer),
/*WritePCHFile=*/Storage->getKind() == PCHStorage::Kind::TempFile,
Callbacks);
Callbacks, AllowASTWithErrors);
if (!Act->BeginSourceFile(*Clang, Clang->getFrontendOpts().Inputs[0]))
return BuildPreambleError::BeginSourceFileFailed;

Expand Down
9 changes: 9 additions & 0 deletions clang/test/Driver/sycl-unsupported.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@
// UNSUPPORTED_OPT-NOT: clang{{.*}} "-fsycl-is-device"{{.*}} "[[OPT_CC1]]{{.*}}"
// UNSUPPORTED_OPT: clang{{.*}} "-fsycl-is-host"{{.*}} "[[OPT_CC1]]{{.*}}"

// "--auto-pch" should only be enabled for SYCL RTC compilations, regular driver
// shouldn't know about it:
//
// RUN: not %clangxx -### %s --auto-pch 2>&1 | FileCheck %s --check-prefix AUTO_PCH
// RUN: not %clangxx -fsycl-device-only -### %s --auto-pch 2>&1 | FileCheck %s --check-prefix AUTO_PCH
// RUN: not %clangxx -fsycl -### %s --auto-pch 2>&1 | FileCheck %s --check-prefix AUTO_PCH
//
// AUTO_PCH: error: unknown argument: '--auto-pch'

// FPGA support has been removed, usage of any FPGA specific options and any
// options that have FPGA specific arguments should emit a specific error
// diagnostic.
Expand Down
Loading
Loading