Skip to content

Commit 671f0e2

Browse files
committed
[clang] Make libBasic not depend on MC
Reduces numbers of files built for clang-format from 575 to 449. Requires two small changes: 1. Don't use llvm::ExceptionHandling in LangOptions. This isn't even quite the right type since we don't use all of its values. Tweaks the changes made in: - https://reviews.llvm.org/D93215 - https://reviews.llvm.org/D93216 2. Move section name validation code added (long ago) in commit 30ba674 out of libBasic into Sema and base the check on the triple. This is a bit less OOP-y, but completely in line with what we do in many other places in Sema. No behavior change. Differential Revision: https://reviews.llvm.org/D101463
1 parent d16d820 commit 671f0e2

File tree

14 files changed

+42
-44
lines changed

14 files changed

+42
-44
lines changed

clang/include/clang/Basic/DiagnosticFrontendKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def err_fe_action_not_available : Error<
112112
def err_fe_invalid_alignment : Error<
113113
"invalid value '%1' in '%0'; alignment must be a power of 2">;
114114
def err_fe_invalid_exception_model
115-
: Error<"invalid exception model '%select{none|dwarf|sjlj|arm|seh|wasm|aix}0' for target '%1'">;
115+
: Error<"invalid exception model '%select{none|sjlj|seh|dwarf|wasm}0' for target '%1'">;
116116
def warn_fe_concepts_ts_flag : Warning<
117117
"-fconcepts-ts is deprecated - use '-std=c++20' for Concepts support">,
118118
InGroup<Deprecated>;

clang/include/clang/Basic/LangOptions.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include "llvm/ADT/FloatingPointMode.h"
2424
#include "llvm/ADT/StringRef.h"
2525
#include "llvm/ADT/Triple.h"
26-
#include "llvm/MC/MCTargetOptions.h"
2726
#include <string>
2827
#include <vector>
2928

@@ -222,7 +221,7 @@ class LangOptions : public LangOptionsBase {
222221
};
223222

224223
/// Possible exception handling behavior.
225-
using ExceptionHandlingKind = llvm::ExceptionHandling;
224+
enum class ExceptionHandlingKind { None, SjLj, WinEH, DwarfCFI, Wasm };
226225

227226
enum class LaxVectorConversionKind {
228227
/// Permit no implicit vector bitcasts.
@@ -410,19 +409,19 @@ class LangOptions : public LangOptionsBase {
410409
}
411410

412411
bool hasSjLjExceptions() const {
413-
return getExceptionHandling() == llvm::ExceptionHandling::SjLj;
412+
return getExceptionHandling() == ExceptionHandlingKind::SjLj;
414413
}
415414

416415
bool hasSEHExceptions() const {
417-
return getExceptionHandling() == llvm::ExceptionHandling::WinEH;
416+
return getExceptionHandling() == ExceptionHandlingKind::WinEH;
418417
}
419418

420419
bool hasDWARFExceptions() const {
421-
return getExceptionHandling() == llvm::ExceptionHandling::DwarfCFI;
420+
return getExceptionHandling() == ExceptionHandlingKind::DwarfCFI;
422421
}
423422

424423
bool hasWasmExceptions() const {
425-
return getExceptionHandling() == llvm::ExceptionHandling::Wasm;
424+
return getExceptionHandling() == ExceptionHandlingKind::Wasm;
426425
}
427426
};
428427

clang/include/clang/Basic/TargetInfo.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,21 +1147,6 @@ class TargetInfo : public virtual TransferrableTargetInfo,
11471147
getTriple().getVendor() == llvm::Triple::SCEI);
11481148
}
11491149

1150-
/// An optional hook that targets can implement to perform semantic
1151-
/// checking on attribute((section("foo"))) specifiers.
1152-
///
1153-
/// In this case, "foo" is passed in to be checked. If the section
1154-
/// specifier is invalid, the backend should return an Error that indicates
1155-
/// the problem.
1156-
///
1157-
/// This hook is a simple quality of implementation feature to catch errors
1158-
/// and give good diagnostics in cases when the assembler or code generator
1159-
/// would otherwise reject the section specifier.
1160-
///
1161-
virtual llvm::Error isValidSectionSpecifier(StringRef SR) const {
1162-
return llvm::Error::success();
1163-
}
1164-
11651150
/// Set forced language options.
11661151
///
11671152
/// Apply changes to the target information with respect to certain

clang/include/clang/Driver/Options.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1387,7 +1387,7 @@ def fwasm_exceptions : Flag<["-"], "fwasm-exceptions">, Group<f_Group>,
13871387
def exception_model : Separate<["-"], "exception-model">,
13881388
Flags<[CC1Option, NoDriverOption]>, HelpText<"The exception model: dwarf|sjlj|seh|wasm">,
13891389
Values<"dwarf,sjlj,seh,wasm">,
1390-
NormalizedValuesScope<"llvm::ExceptionHandling">,
1390+
NormalizedValuesScope<"LangOptions::ExceptionHandlingKind">,
13911391
NormalizedValues<["DwarfCFI", "SjLj", "WinEH", "Wasm"]>,
13921392
MarshallingInfoEnum<LangOpts<"ExceptionHandling">, "None">;
13931393
def exception_model_EQ : Joined<["-"], "exception-model=">,

clang/include/clang/Sema/Sema.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4288,6 +4288,7 @@ class Sema final {
42884288
bool checkStringLiteralArgumentAttr(const ParsedAttr &Attr, unsigned ArgNum,
42894289
StringRef &Str,
42904290
SourceLocation *ArgLocation = nullptr);
4291+
llvm::Error isValidSectionSpecifier(StringRef Str);
42914292
bool checkSectionName(SourceLocation LiteralLoc, StringRef Str);
42924293
bool checkTargetAttr(SourceLocation LiteralLoc, StringRef Str);
42934294
bool checkMSInheritanceAttrOnDefinition(

clang/lib/Basic/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
set(LLVM_LINK_COMPONENTS
2-
MC
32
Support
43
)
54

clang/lib/Basic/Targets/OSTargets.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#define LLVM_CLANG_LIB_BASIC_TARGETS_OSTARGETS_H
1414

1515
#include "Targets.h"
16-
#include "llvm/MC/MCSectionMachO.h"
1716

1817
namespace clang {
1918
namespace targets {
@@ -114,15 +113,6 @@ class LLVM_LIBRARY_VISIBILITY DarwinTargetInfo : public OSTargetInfo<Target> {
114113
this->MCountName = "\01mcount";
115114
}
116115

117-
llvm::Error isValidSectionSpecifier(StringRef SR) const override {
118-
// Let MCSectionMachO validate this.
119-
StringRef Segment, Section;
120-
unsigned TAA, StubSize;
121-
bool HasTAA;
122-
return llvm::MCSectionMachO::ParseSectionSpecifier(SR, Segment, Section,
123-
TAA, HasTAA, StubSize);
124-
}
125-
126116
const char *getStaticInitSectionSpecifier() const override {
127117
// FIXME: We should return 0 when building kexts.
128118
return "__TEXT,__StaticInit,regular,pure_instructions";

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,8 @@ static bool FixupInvocation(CompilerInvocation &Invocation,
463463

464464
CodeGenOpts.CodeModel = TargetOpts.CodeModel;
465465

466-
if (LangOpts.getExceptionHandling() != llvm::ExceptionHandling::None &&
466+
if (LangOpts.getExceptionHandling() !=
467+
LangOptions::ExceptionHandlingKind::None &&
467468
T.isWindowsMSVCEnvironment())
468469
Diags.Report(diag::err_fe_invalid_exception_model)
469470
<< static_cast<unsigned>(LangOpts.getExceptionHandling()) << T.str();

clang/lib/Sema/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
set(LLVM_LINK_COMPONENTS
22
Core
33
FrontendOpenMP
4+
MC
45
Support
56
)
67

clang/lib/Sema/SemaAttr.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,10 @@ void Sema::ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind,
269269
AlignPackStack.Act(PragmaLoc, Action, StringRef(), Info);
270270
}
271271

272-
void Sema::ActOnPragmaClangSection(SourceLocation PragmaLoc, PragmaClangSectionAction Action,
273-
PragmaClangSectionKind SecKind, StringRef SecName) {
272+
void Sema::ActOnPragmaClangSection(SourceLocation PragmaLoc,
273+
PragmaClangSectionAction Action,
274+
PragmaClangSectionKind SecKind,
275+
StringRef SecName) {
274276
PragmaClangSection *CSec;
275277
int SectionFlags = ASTContext::PSF_Read;
276278
switch (SecKind) {
@@ -301,8 +303,7 @@ void Sema::ActOnPragmaClangSection(SourceLocation PragmaLoc, PragmaClangSectionA
301303
return;
302304
}
303305

304-
if (llvm::Error E =
305-
Context.getTargetInfo().isValidSectionSpecifier(SecName)) {
306+
if (llvm::Error E = isValidSectionSpecifier(SecName)) {
306307
Diag(PragmaLoc, diag::err_pragma_section_invalid_for_target)
307308
<< toString(std::move(E));
308309
CSec->Valid = false;

0 commit comments

Comments
 (0)