thakis created this revision. thakis added a reviewer: hans. Herald added subscribers: dexonsmith, dang, mgorny. Herald added a reviewer: aaron.ballman. thakis requested review of this revision. Herald added subscribers: llvm-commits, aheejin. Herald added a project: LLVM.
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. https://reviews.llvm.org/D101463 Files: clang/include/clang/Basic/DiagnosticFrontendKinds.td clang/include/clang/Basic/LangOptions.h clang/include/clang/Basic/TargetInfo.h clang/include/clang/Driver/Options.td clang/include/clang/Sema/Sema.h clang/lib/Basic/CMakeLists.txt clang/lib/Basic/Targets/OSTargets.h clang/lib/Frontend/CompilerInvocation.cpp clang/lib/Sema/CMakeLists.txt clang/lib/Sema/SemaAttr.cpp clang/lib/Sema/SemaDeclAttr.cpp llvm/utils/gn/secondary/clang/lib/Basic/BUILD.gn llvm/utils/gn/secondary/clang/lib/Sema/BUILD.gn llvm/utils/gn/secondary/clang/tools/clang-format/BUILD.gn
Index: llvm/utils/gn/secondary/clang/tools/clang-format/BUILD.gn =================================================================== --- llvm/utils/gn/secondary/clang/tools/clang-format/BUILD.gn +++ llvm/utils/gn/secondary/clang/tools/clang-format/BUILD.gn @@ -12,6 +12,7 @@ "//clang/lib/Frontend/", "//clang/lib/Sema/", "//llvm/lib/IR", + "//llvm/lib/MC", ] sources = [ "ClangFormat.cpp" ] } Index: llvm/utils/gn/secondary/clang/lib/Sema/BUILD.gn =================================================================== --- llvm/utils/gn/secondary/clang/lib/Sema/BUILD.gn +++ llvm/utils/gn/secondary/clang/lib/Sema/BUILD.gn @@ -25,6 +25,7 @@ "//clang/lib/Edit", "//clang/lib/Lex", "//llvm/lib/Frontend/OpenMP", + "//llvm/lib/MC", "//llvm/lib/Support", ] sources = [ Index: llvm/utils/gn/secondary/clang/lib/Basic/BUILD.gn =================================================================== --- llvm/utils/gn/secondary/clang/lib/Basic/BUILD.gn +++ llvm/utils/gn/secondary/clang/lib/Basic/BUILD.gn @@ -49,7 +49,6 @@ "//clang/include/clang/Sema:AttrParsedAttrKinds", "//clang/include/clang/Sema:AttrSpellingListIndex", "//llvm/include/llvm/Config:llvm-config", - "//llvm/lib/MC", "//llvm/lib/Support", ] include_dirs = [ "." ] Index: clang/lib/Sema/SemaDeclAttr.cpp =================================================================== --- clang/lib/Sema/SemaDeclAttr.cpp +++ 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 @@ 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 @@ // `#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; Index: clang/lib/Sema/SemaAttr.cpp =================================================================== --- clang/lib/Sema/SemaAttr.cpp +++ clang/lib/Sema/SemaAttr.cpp @@ -269,8 +269,10 @@ 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 @@ 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; Index: clang/lib/Sema/CMakeLists.txt =================================================================== --- clang/lib/Sema/CMakeLists.txt +++ clang/lib/Sema/CMakeLists.txt @@ -1,6 +1,7 @@ set(LLVM_LINK_COMPONENTS Core FrontendOpenMP + MC Support ) Index: clang/lib/Frontend/CompilerInvocation.cpp =================================================================== --- clang/lib/Frontend/CompilerInvocation.cpp +++ clang/lib/Frontend/CompilerInvocation.cpp @@ -463,7 +463,8 @@ 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(); Index: clang/lib/Basic/Targets/OSTargets.h =================================================================== --- clang/lib/Basic/Targets/OSTargets.h +++ 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 @@ 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"; Index: clang/lib/Basic/CMakeLists.txt =================================================================== --- clang/lib/Basic/CMakeLists.txt +++ clang/lib/Basic/CMakeLists.txt @@ -1,5 +1,4 @@ set(LLVM_LINK_COMPONENTS - MC Support ) Index: clang/include/clang/Sema/Sema.h =================================================================== --- clang/include/clang/Sema/Sema.h +++ clang/include/clang/Sema/Sema.h @@ -4288,6 +4288,7 @@ 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( Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -1387,7 +1387,7 @@ 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=">, Index: clang/include/clang/Basic/TargetInfo.h =================================================================== --- clang/include/clang/Basic/TargetInfo.h +++ clang/include/clang/Basic/TargetInfo.h @@ -1147,21 +1147,6 @@ 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 Index: clang/include/clang/Basic/LangOptions.h =================================================================== --- clang/include/clang/Basic/LangOptions.h +++ 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 @@ }; /// 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 @@ } 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; } }; Index: clang/include/clang/Basic/DiagnosticFrontendKinds.td =================================================================== --- clang/include/clang/Basic/DiagnosticFrontendKinds.td +++ clang/include/clang/Basic/DiagnosticFrontendKinds.td @@ -112,7 +112,7 @@ 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>;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits