Skip to content

Commit

Permalink
[clang][PATCH][nfc] Refactor TargetInfo::adjust to pass DiagnosticsEn…
Browse files Browse the repository at this point in the history
…gine to allow diagnostics on target-unsupported options

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D104729
  • Loading branch information
Melanie Blower committed Jun 28, 2021
1 parent 614b46e commit 2dbe1c6
Show file tree
Hide file tree
Showing 15 changed files with 21 additions and 19 deletions.
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 @@ -135,8 +135,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);
// FIXME: 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 @@ -142,7 +142,7 @@ bool CompilerInstance::createTarget() {
// Inform the target of the language options.
// 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 @@ -457,7 +457,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
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
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,8 @@ ClangExpressionParser::ClangExpressionParser(
//
// FIXME: We shouldn't need to do this, the target should be immutable once
// created. This complexity should be lifted elsewhere.
m_compiler->getTarget().adjust(m_compiler->getLangOpts());
m_compiler->getTarget().adjust(m_compiler->getDiagnostics(),
m_compiler->getLangOpts());

// 6. Set up the diagnostic buffer for reporting errors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ ClangModulesDeclVendor::Create(Target &target) {
if (!instance->hasTarget())
return nullptr;

instance->getTarget().adjust(instance->getLangOpts());
instance->getTarget().adjust(*diagnostics_engine, instance->getLangOpts());

if (!action->BeginSourceFile(*instance,
instance->getFrontendOpts().Inputs[0]))
Expand Down

0 comments on commit 2dbe1c6

Please sign in to comment.