forked from OSchip/llvm-project
[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 30ba67439
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
This commit is contained in:
parent
d16d820c2e
commit
671f0e2e18
|
@ -112,7 +112,7 @@ def err_fe_action_not_available : Error<
|
|||
def err_fe_invalid_alignment : Error<
|
||||
"invalid value '%1' in '%0'; alignment must be a power of 2">;
|
||||
def err_fe_invalid_exception_model
|
||||
: Error<"invalid exception model '%select{none|dwarf|sjlj|arm|seh|wasm|aix}0' for target '%1'">;
|
||||
: Error<"invalid exception model '%select{none|sjlj|seh|dwarf|wasm}0' for target '%1'">;
|
||||
def warn_fe_concepts_ts_flag : Warning<
|
||||
"-fconcepts-ts is deprecated - use '-std=c++20' for Concepts support">,
|
||||
InGroup<Deprecated>;
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
#include "llvm/ADT/FloatingPointMode.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/ADT/Triple.h"
|
||||
#include "llvm/MC/MCTargetOptions.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
@ -222,7 +221,7 @@ public:
|
|||
};
|
||||
|
||||
/// Possible exception handling behavior.
|
||||
using ExceptionHandlingKind = llvm::ExceptionHandling;
|
||||
enum class ExceptionHandlingKind { None, SjLj, WinEH, DwarfCFI, Wasm };
|
||||
|
||||
enum class LaxVectorConversionKind {
|
||||
/// Permit no implicit vector bitcasts.
|
||||
|
@ -410,19 +409,19 @@ public:
|
|||
}
|
||||
|
||||
bool hasSjLjExceptions() const {
|
||||
return getExceptionHandling() == llvm::ExceptionHandling::SjLj;
|
||||
return getExceptionHandling() == ExceptionHandlingKind::SjLj;
|
||||
}
|
||||
|
||||
bool hasSEHExceptions() const {
|
||||
return getExceptionHandling() == llvm::ExceptionHandling::WinEH;
|
||||
return getExceptionHandling() == ExceptionHandlingKind::WinEH;
|
||||
}
|
||||
|
||||
bool hasDWARFExceptions() const {
|
||||
return getExceptionHandling() == llvm::ExceptionHandling::DwarfCFI;
|
||||
return getExceptionHandling() == ExceptionHandlingKind::DwarfCFI;
|
||||
}
|
||||
|
||||
bool hasWasmExceptions() const {
|
||||
return getExceptionHandling() == llvm::ExceptionHandling::Wasm;
|
||||
return getExceptionHandling() == ExceptionHandlingKind::Wasm;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -1147,21 +1147,6 @@ public:
|
|||
getTriple().getVendor() == llvm::Triple::SCEI);
|
||||
}
|
||||
|
||||
/// An optional hook that targets can implement to perform semantic
|
||||
/// checking on attribute((section("foo"))) specifiers.
|
||||
///
|
||||
/// In this case, "foo" is passed in to be checked. If the section
|
||||
/// specifier is invalid, the backend should return an Error that indicates
|
||||
/// the problem.
|
||||
///
|
||||
/// This hook is a simple quality of implementation feature to catch errors
|
||||
/// and give good diagnostics in cases when the assembler or code generator
|
||||
/// would otherwise reject the section specifier.
|
||||
///
|
||||
virtual llvm::Error isValidSectionSpecifier(StringRef SR) const {
|
||||
return llvm::Error::success();
|
||||
}
|
||||
|
||||
/// Set forced language options.
|
||||
///
|
||||
/// Apply changes to the target information with respect to certain
|
||||
|
|
|
@ -1387,7 +1387,7 @@ def fwasm_exceptions : Flag<["-"], "fwasm-exceptions">, Group<f_Group>,
|
|||
def exception_model : Separate<["-"], "exception-model">,
|
||||
Flags<[CC1Option, NoDriverOption]>, HelpText<"The exception model: dwarf|sjlj|seh|wasm">,
|
||||
Values<"dwarf,sjlj,seh,wasm">,
|
||||
NormalizedValuesScope<"llvm::ExceptionHandling">,
|
||||
NormalizedValuesScope<"LangOptions::ExceptionHandlingKind">,
|
||||
NormalizedValues<["DwarfCFI", "SjLj", "WinEH", "Wasm"]>,
|
||||
MarshallingInfoEnum<LangOpts<"ExceptionHandling">, "None">;
|
||||
def exception_model_EQ : Joined<["-"], "exception-model=">,
|
||||
|
|
|
@ -4288,6 +4288,7 @@ public:
|
|||
bool checkStringLiteralArgumentAttr(const ParsedAttr &Attr, unsigned ArgNum,
|
||||
StringRef &Str,
|
||||
SourceLocation *ArgLocation = nullptr);
|
||||
llvm::Error isValidSectionSpecifier(StringRef Str);
|
||||
bool checkSectionName(SourceLocation LiteralLoc, StringRef Str);
|
||||
bool checkTargetAttr(SourceLocation LiteralLoc, StringRef Str);
|
||||
bool checkMSInheritanceAttrOnDefinition(
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
set(LLVM_LINK_COMPONENTS
|
||||
MC
|
||||
Support
|
||||
)
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
#define LLVM_CLANG_LIB_BASIC_TARGETS_OSTARGETS_H
|
||||
|
||||
#include "Targets.h"
|
||||
#include "llvm/MC/MCSectionMachO.h"
|
||||
|
||||
namespace clang {
|
||||
namespace targets {
|
||||
|
@ -114,15 +113,6 @@ public:
|
|||
this->MCountName = "\01mcount";
|
||||
}
|
||||
|
||||
llvm::Error isValidSectionSpecifier(StringRef SR) const override {
|
||||
// Let MCSectionMachO validate this.
|
||||
StringRef Segment, Section;
|
||||
unsigned TAA, StubSize;
|
||||
bool HasTAA;
|
||||
return llvm::MCSectionMachO::ParseSectionSpecifier(SR, Segment, Section,
|
||||
TAA, HasTAA, StubSize);
|
||||
}
|
||||
|
||||
const char *getStaticInitSectionSpecifier() const override {
|
||||
// FIXME: We should return 0 when building kexts.
|
||||
return "__TEXT,__StaticInit,regular,pure_instructions";
|
||||
|
|
|
@ -463,7 +463,8 @@ static bool FixupInvocation(CompilerInvocation &Invocation,
|
|||
|
||||
CodeGenOpts.CodeModel = TargetOpts.CodeModel;
|
||||
|
||||
if (LangOpts.getExceptionHandling() != llvm::ExceptionHandling::None &&
|
||||
if (LangOpts.getExceptionHandling() !=
|
||||
LangOptions::ExceptionHandlingKind::None &&
|
||||
T.isWindowsMSVCEnvironment())
|
||||
Diags.Report(diag::err_fe_invalid_exception_model)
|
||||
<< static_cast<unsigned>(LangOpts.getExceptionHandling()) << T.str();
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
set(LLVM_LINK_COMPONENTS
|
||||
Core
|
||||
FrontendOpenMP
|
||||
MC
|
||||
Support
|
||||
)
|
||||
|
||||
|
|
|
@ -269,8 +269,10 @@ void Sema::ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind,
|
|||
AlignPackStack.Act(PragmaLoc, Action, StringRef(), Info);
|
||||
}
|
||||
|
||||
void Sema::ActOnPragmaClangSection(SourceLocation PragmaLoc, PragmaClangSectionAction Action,
|
||||
PragmaClangSectionKind SecKind, StringRef SecName) {
|
||||
void Sema::ActOnPragmaClangSection(SourceLocation PragmaLoc,
|
||||
PragmaClangSectionAction Action,
|
||||
PragmaClangSectionKind SecKind,
|
||||
StringRef SecName) {
|
||||
PragmaClangSection *CSec;
|
||||
int SectionFlags = ASTContext::PSF_Read;
|
||||
switch (SecKind) {
|
||||
|
@ -301,8 +303,7 @@ void Sema::ActOnPragmaClangSection(SourceLocation PragmaLoc, PragmaClangSectionA
|
|||
return;
|
||||
}
|
||||
|
||||
if (llvm::Error E =
|
||||
Context.getTargetInfo().isValidSectionSpecifier(SecName)) {
|
||||
if (llvm::Error E = isValidSectionSpecifier(SecName)) {
|
||||
Diag(PragmaLoc, diag::err_pragma_section_invalid_for_target)
|
||||
<< toString(std::move(E));
|
||||
CSec->Valid = false;
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include "llvm/ADT/STLExtras.h"
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
#include "llvm/IR/Assumptions.h"
|
||||
#include "llvm/MC/MCSectionMachO.h"
|
||||
#include "llvm/Support/Error.h"
|
||||
#include "llvm/Support/MathExtras.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
|
@ -2985,9 +2986,29 @@ SectionAttr *Sema::mergeSectionAttr(Decl *D, const AttributeCommonInfo &CI,
|
|||
return ::new (Context) SectionAttr(Context, CI, Name);
|
||||
}
|
||||
|
||||
/// Used to implement to perform semantic checking on
|
||||
/// attribute((section("foo"))) specifiers.
|
||||
///
|
||||
/// In this case, "foo" is passed in to be checked. If the section
|
||||
/// specifier is invalid, return an Error that indicates the problem.
|
||||
///
|
||||
/// This is a simple quality of implementation feature to catch errors
|
||||
/// and give good diagnostics in cases when the assembler or code generator
|
||||
/// would otherwise reject the section specifier.
|
||||
llvm::Error Sema::isValidSectionSpecifier(StringRef SecName) {
|
||||
if (!Context.getTargetInfo().getTriple().isOSDarwin())
|
||||
return llvm::Error::success();
|
||||
|
||||
// Let MCSectionMachO validate this.
|
||||
StringRef Segment, Section;
|
||||
unsigned TAA, StubSize;
|
||||
bool HasTAA;
|
||||
return llvm::MCSectionMachO::ParseSectionSpecifier(SecName, Segment, Section,
|
||||
TAA, HasTAA, StubSize);
|
||||
}
|
||||
|
||||
bool Sema::checkSectionName(SourceLocation LiteralLoc, StringRef SecName) {
|
||||
if (llvm::Error E =
|
||||
Context.getTargetInfo().isValidSectionSpecifier(SecName)) {
|
||||
if (llvm::Error E = isValidSectionSpecifier(SecName)) {
|
||||
Diag(LiteralLoc, diag::err_attribute_section_invalid_for_target)
|
||||
<< toString(std::move(E)) << 1 /*'section'*/;
|
||||
return false;
|
||||
|
@ -3021,8 +3042,7 @@ static void handleSectionAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
|
|||
// `#pragma code_seg("segname")` uses checkSectionName() instead.
|
||||
static bool checkCodeSegName(Sema &S, SourceLocation LiteralLoc,
|
||||
StringRef CodeSegName) {
|
||||
if (llvm::Error E =
|
||||
S.Context.getTargetInfo().isValidSectionSpecifier(CodeSegName)) {
|
||||
if (llvm::Error E = S.isValidSectionSpecifier(CodeSegName)) {
|
||||
S.Diag(LiteralLoc, diag::err_attribute_section_invalid_for_target)
|
||||
<< toString(std::move(E)) << 0 /*'code-seg'*/;
|
||||
return false;
|
||||
|
|
|
@ -49,7 +49,6 @@ static_library("Basic") {
|
|||
"//clang/include/clang/Sema:AttrParsedAttrKinds",
|
||||
"//clang/include/clang/Sema:AttrSpellingListIndex",
|
||||
"//llvm/include/llvm/Config:llvm-config",
|
||||
"//llvm/lib/MC",
|
||||
"//llvm/lib/Support",
|
||||
]
|
||||
include_dirs = [ "." ]
|
||||
|
|
|
@ -25,6 +25,7 @@ static_library("Sema") {
|
|||
"//clang/lib/Edit",
|
||||
"//clang/lib/Lex",
|
||||
"//llvm/lib/Frontend/OpenMP",
|
||||
"//llvm/lib/MC",
|
||||
"//llvm/lib/Support",
|
||||
]
|
||||
sources = [
|
||||
|
|
|
@ -12,6 +12,7 @@ executable("clang-format") {
|
|||
"//clang/lib/Frontend/",
|
||||
"//clang/lib/Sema/",
|
||||
"//llvm/lib/IR",
|
||||
"//llvm/lib/MC",
|
||||
]
|
||||
sources = [ "ClangFormat.cpp" ]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue