diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td b/clang/include/clang/Basic/DiagnosticFrontendKinds.td --- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td +++ b/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; diff --git a/clang/include/clang/Basic/LangOptions.h b/clang/include/clang/Basic/LangOptions.h --- 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 #include @@ -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; } }; diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h --- a/clang/include/clang/Basic/TargetInfo.h +++ b/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 diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td --- a/clang/include/clang/Driver/Options.td +++ b/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, "None">; def exception_model_EQ : Joined<["-"], "exception-model=">, diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h --- a/clang/include/clang/Sema/Sema.h +++ b/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( diff --git a/clang/lib/Basic/CMakeLists.txt b/clang/lib/Basic/CMakeLists.txt --- 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 --- 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 @@ 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 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/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(LangOpts.getExceptionHandling()) << T.str(); diff --git a/clang/lib/Sema/CMakeLists.txt b/clang/lib/Sema/CMakeLists.txt --- 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 --- a/clang/lib/Sema/SemaAttr.cpp +++ b/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; diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp --- 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 @@ 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; diff --git a/llvm/utils/gn/secondary/clang/lib/Basic/BUILD.gn b/llvm/utils/gn/secondary/clang/lib/Basic/BUILD.gn --- a/llvm/utils/gn/secondary/clang/lib/Basic/BUILD.gn +++ b/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 = [ "." ] diff --git a/llvm/utils/gn/secondary/clang/lib/Sema/BUILD.gn b/llvm/utils/gn/secondary/clang/lib/Sema/BUILD.gn --- a/llvm/utils/gn/secondary/clang/lib/Sema/BUILD.gn +++ b/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 = [ diff --git a/llvm/utils/gn/secondary/clang/tools/clang-format/BUILD.gn b/llvm/utils/gn/secondary/clang/tools/clang-format/BUILD.gn --- 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 @@ "//clang/lib/Frontend/", "//clang/lib/Sema/", "//llvm/lib/IR", + "//llvm/lib/MC", ] sources = [ "ClangFormat.cpp" ] }