summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNico Weber <thakis@chromium.org>2021-04-20 10:58:19 -0400
committerNico Weber <thakis@chromium.org>2021-04-28 12:16:22 -0400
commit671f0e2e189c561512511331d95de382e2d6d15d (patch)
tree339db1a366a2430a79952421b62bccbbdb096248
parentd16d820c2e6400aa2242efcedbfa824fbfa2fc09 (diff)
downloadllvm-671f0e2e189c561512511331d95de382e2d6d15d.tar.gz
[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
-rw-r--r--clang/include/clang/Basic/DiagnosticFrontendKinds.td2
-rw-r--r--clang/include/clang/Basic/LangOptions.h11
-rw-r--r--clang/include/clang/Basic/TargetInfo.h15
-rw-r--r--clang/include/clang/Driver/Options.td2
-rw-r--r--clang/include/clang/Sema/Sema.h1
-rw-r--r--clang/lib/Basic/CMakeLists.txt1
-rw-r--r--clang/lib/Basic/Targets/OSTargets.h10
-rw-r--r--clang/lib/Frontend/CompilerInvocation.cpp3
-rw-r--r--clang/lib/Sema/CMakeLists.txt1
-rw-r--r--clang/lib/Sema/SemaAttr.cpp9
-rw-r--r--clang/lib/Sema/SemaDeclAttr.cpp28
-rw-r--r--llvm/utils/gn/secondary/clang/lib/Basic/BUILD.gn1
-rw-r--r--llvm/utils/gn/secondary/clang/lib/Sema/BUILD.gn1
-rw-r--r--llvm/utils/gn/secondary/clang/tools/clang-format/BUILD.gn1
14 files changed, 42 insertions, 44 deletions
diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index 39fdefc77fbe..5122770316cd 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -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>;
diff --git a/clang/include/clang/Basic/LangOptions.h b/clang/include/clang/Basic/LangOptions.h
index c898ef19a6cf..85fe4af72023 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -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;
}
};
diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h
index 3300fe012aa8..532ff4554656 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -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
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 06a21a9b6e9c..1b4dfe4b6d3b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -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=">,
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index e0ededea6bca..aeb05d758cae 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -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(
diff --git a/clang/lib/Basic/CMakeLists.txt b/clang/lib/Basic/CMakeLists.txt
index 534886e8ed2e..cbf99b2a848f 100644
--- a/clang/lib/Basic/CMakeLists.txt
+++ b/clang/lib/Basic/CMakeLists.txt
@@ -1,5 +1,4 @@
set(LLVM_LINK_COMPONENTS
- MC
Support
)
diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h
index 6e757adfa8bf..cecac1cec172 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -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";
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 36d2fe379528..2578c8cc0b95 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -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();
diff --git a/clang/lib/Sema/CMakeLists.txt b/clang/lib/Sema/CMakeLists.txt
index 251856c933ac..0e0681a8e292 100644
--- a/clang/lib/Sema/CMakeLists.txt
+++ b/clang/lib/Sema/CMakeLists.txt
@@ -1,6 +1,7 @@
set(LLVM_LINK_COMPONENTS
Core
FrontendOpenMP
+ MC
Support
)
diff --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp
index 67e553a3b259..fe8f02f02368 100644
--- a/clang/lib/Sema/SemaAttr.cpp
+++ b/clang/lib/Sema/SemaAttr.cpp
@@ -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;
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 7db720f6c57d..f961076421b5 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -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;
diff --git a/llvm/utils/gn/secondary/clang/lib/Basic/BUILD.gn b/llvm/utils/gn/secondary/clang/lib/Basic/BUILD.gn
index 0db0cb25b7de..52d38954c3c1 100644
--- a/llvm/utils/gn/secondary/clang/lib/Basic/BUILD.gn
+++ b/llvm/utils/gn/secondary/clang/lib/Basic/BUILD.gn
@@ -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 = [ "." ]
diff --git a/llvm/utils/gn/secondary/clang/lib/Sema/BUILD.gn b/llvm/utils/gn/secondary/clang/lib/Sema/BUILD.gn
index 8ec471e130e3..93d6b7dc2d29 100644
--- a/llvm/utils/gn/secondary/clang/lib/Sema/BUILD.gn
+++ b/llvm/utils/gn/secondary/clang/lib/Sema/BUILD.gn
@@ -25,6 +25,7 @@ static_library("Sema") {
"//clang/lib/Edit",
"//clang/lib/Lex",
"//llvm/lib/Frontend/OpenMP",
+ "//llvm/lib/MC",
"//llvm/lib/Support",
]
sources = [
diff --git a/llvm/utils/gn/secondary/clang/tools/clang-format/BUILD.gn b/llvm/utils/gn/secondary/clang/tools/clang-format/BUILD.gn
index 243dae89bb6a..d1a83faa6322 100644
--- a/llvm/utils/gn/secondary/clang/tools/clang-format/BUILD.gn
+++ b/llvm/utils/gn/secondary/clang/tools/clang-format/BUILD.gn
@@ -12,6 +12,7 @@ executable("clang-format") {
"//clang/lib/Frontend/",
"//clang/lib/Sema/",
"//llvm/lib/IR",
+ "//llvm/lib/MC",
]
sources = [ "ClangFormat.cpp" ]
}