Skip to content

Commit 17d910e

Browse files
Melanie Bloweredymtt
authored andcommitted
[clang][PATCH][nfc] Refactor TargetInfo::adjust to pass DiagnosticsEngine to allow diagnostics on target-unsupported options
Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D104729 (cherry picked from commit aaba371)
1 parent 760738f commit 17d910e

File tree

15 files changed

+21
-19
lines changed

15 files changed

+21
-19
lines changed

clang/include/clang/Basic/TargetInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1164,7 +1164,7 @@ class TargetInfo : public virtual TransferrableTargetInfo,
11641164
/// Apply changes to the target information with respect to certain
11651165
/// language options which change the target configuration and adjust
11661166
/// the language based on the target options where applicable.
1167-
virtual void adjust(LangOptions &Opts);
1167+
virtual void adjust(DiagnosticsEngine &Diags, LangOptions &Opts);
11681168

11691169
/// Adjust target options based on codegen options.
11701170
virtual void adjustTargetOptions(const CodeGenOptions &CGOpts,

clang/lib/Basic/TargetInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ bool TargetInfo::isTypeSigned(IntType T) {
347347
/// Apply changes to the target information with respect to certain
348348
/// language options which change the target configuration and adjust
349349
/// the language based on the target options where applicable.
350-
void TargetInfo::adjust(LangOptions &Opts) {
350+
void TargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
351351
if (Opts.NoBitFieldTypeAlign)
352352
UseBitFieldTypeAlignment = false;
353353

clang/lib/Basic/Targets/AMDGPU.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,8 @@ AMDGPUTargetInfo::AMDGPUTargetInfo(const llvm::Triple &Triple,
358358
MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
359359
}
360360

361-
void AMDGPUTargetInfo::adjust(LangOptions &Opts) {
362-
TargetInfo::adjust(Opts);
361+
void AMDGPUTargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
362+
TargetInfo::adjust(Diags, Opts);
363363
// ToDo: There are still a few places using default address space as private
364364
// address space in OpenCL, which needs to be cleaned up, then Opts.OpenCL
365365
// can be removed from the following line.

clang/lib/Basic/Targets/AMDGPU.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
9393

9494
void setAddressSpaceMap(bool DefaultIsPrivate);
9595

96-
void adjust(LangOptions &Opts) override;
96+
void adjust(DiagnosticsEngine &Diags, LangOptions &Opts) override;
9797

9898
uint64_t getPointerWidthV(unsigned AddrSpace) const override {
9999
if (isR600(getTriple()))

clang/lib/Basic/Targets/PPC.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,10 +606,10 @@ void PPCTargetInfo::fillValidCPUList(SmallVectorImpl<StringRef> &Values) const {
606606
Values.append(std::begin(ValidCPUNames), std::end(ValidCPUNames));
607607
}
608608

609-
void PPCTargetInfo::adjust(LangOptions &Opts) {
609+
void PPCTargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
610610
if (HasAltivec)
611611
Opts.AltiVec = 1;
612-
TargetInfo::adjust(Opts);
612+
TargetInfo::adjust(Diags, Opts);
613613
if (LongDoubleFormat != &llvm::APFloat::IEEEdouble())
614614
LongDoubleFormat = Opts.PPCIEEELongDouble
615615
? &llvm::APFloat::IEEEquad()

clang/lib/Basic/Targets/PPC.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class LLVM_LIBRARY_VISIBILITY PPCTargetInfo : public TargetInfo {
8989
}
9090

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

9494
// Note: GCC recognizes the following additional cpus:
9595
// 401, 403, 405, 405fp, 440fp, 464, 464fp, 476, 476fp, 505, 740, 801,

clang/lib/Basic/Targets/SPIR.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ class LLVM_LIBRARY_VISIBILITY SPIRTargetInfo : public TargetInfo {
135135
AddrSpaceMap = DefaultIsGeneric ? &SPIRDefIsGenMap : &SPIRDefIsPrivMap;
136136
}
137137

138-
void adjust(LangOptions &Opts) override {
139-
TargetInfo::adjust(Opts);
138+
void adjust(DiagnosticsEngine &Diags, LangOptions &Opts) override {
139+
TargetInfo::adjust(Diags, Opts);
140140
// FIXME: SYCL specification considers unannotated pointers and references
141141
// to be pointing to the generic address space. See section 5.9.3 of
142142
// SYCL 2020 specification.

clang/lib/Basic/Targets/WebAssembly.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,8 @@ ArrayRef<Builtin::Info> WebAssemblyTargetInfo::getTargetBuiltins() const {
234234
Builtin::FirstTSBuiltin);
235235
}
236236

237-
void WebAssemblyTargetInfo::adjust(LangOptions &Opts) {
237+
void WebAssemblyTargetInfo::adjust(DiagnosticsEngine &Diags,
238+
LangOptions &Opts) {
238239
// If the Atomics feature isn't available, turn off POSIXThreads and
239240
// ThreadModel, so that we don't predefine _REENTRANT or __STDCPP_THREADS__.
240241
if (!HasAtomics) {

clang/lib/Basic/Targets/WebAssembly.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public TargetInfo {
138138

139139
bool hasProtectedVisibility() const override { return false; }
140140

141-
void adjust(LangOptions &Opts) override;
141+
void adjust(DiagnosticsEngine &Diags, LangOptions &Opts) override;
142142
};
143143

144144
class LLVM_LIBRARY_VISIBILITY WebAssembly32TargetInfo

clang/lib/Frontend/ASTUnit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ class ASTInfoCollector : public ASTReaderListener {
588588
//
589589
// FIXME: We shouldn't need to do this, the target should be immutable once
590590
// created. This complexity should be lifted elsewhere.
591-
Target->adjust(LangOpt);
591+
Target->adjust(PP.getDiagnostics(), LangOpt);
592592

593593
// Initialize the preprocessor.
594594
PP.Initialize(*Target);

clang/lib/Frontend/CompilerInstance.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ bool CompilerInstance::createTarget() {
144144
// Inform the target of the language options.
145145
// FIXME: We shouldn't need to do this, the target should be immutable once
146146
// created. This complexity should be lifted elsewhere.
147-
getTarget().adjust(getLangOpts());
147+
getTarget().adjust(getDiagnostics(), getLangOpts());
148148

149149
// Adjust target options based on codegen options.
150150
getTarget().adjustTargetOptions(getCodeGenOpts(), getTargetOpts());
@@ -459,7 +459,7 @@ void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) {
459459
getSourceManager(), *HeaderInfo, *this,
460460
/*IdentifierInfoLookup=*/nullptr,
461461
/*OwnsHeaderSearch=*/true, TUKind);
462-
getTarget().adjust(getLangOpts());
462+
getTarget().adjust(getDiagnostics(), getLangOpts());
463463
PP->Initialize(getTarget(), getAuxTarget());
464464

465465
if (PPOpts.DetailedRecord)

clang/lib/Interpreter/Interpreter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ CreateCI(const llvm::opt::ArgStringList &Argv) {
110110
"Initialization failed. "
111111
"Target is missing");
112112

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

115115
return std::move(Clang);
116116
}

clang/tools/clang-import-test/clang-import-test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ std::unique_ptr<CompilerInstance> BuildCompilerInstance() {
208208
TargetInfo *TI = TargetInfo::CreateTargetInfo(
209209
Ins->getDiagnostics(), Ins->getInvocation().TargetOpts);
210210
Ins->setTarget(TI);
211-
Ins->getTarget().adjust(Ins->getLangOpts());
211+
Ins->getTarget().adjust(Ins->getDiagnostics(), Ins->getLangOpts());
212212
Ins->createFileManager();
213213
Ins->createSourceManager(Ins->getFileManager());
214214
Ins->createPreprocessor(TU_Complete);

lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,8 @@ ClangExpressionParser::ClangExpressionParser(
658658
//
659659
// FIXME: We shouldn't need to do this, the target should be immutable once
660660
// created. This complexity should be lifted elsewhere.
661-
m_compiler->getTarget().adjust(m_compiler->getLangOpts());
661+
m_compiler->getTarget().adjust(m_compiler->getDiagnostics(),
662+
m_compiler->getLangOpts());
662663

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

lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ ClangModulesDeclVendor::Create(Target &target) {
704704
if (!instance->hasTarget())
705705
return nullptr;
706706

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

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

0 commit comments

Comments
 (0)