diff --git a/.ci/generate-buildkite-pipeline-premerge b/.ci/generate-buildkite-pipeline-premerge index fd603de611e562..98a8b8fff3687a 100755 --- a/.ci/generate-buildkite-pipeline-premerge +++ b/.ci/generate-buildkite-pipeline-premerge @@ -74,7 +74,8 @@ function compute-projects-to-test() { fi ;; clang) - for p in clang-tools-extra compiler-rt lldb cross-project-tests; do + # lldb is temporarily removed to alleviate Linux pre-commit CI waiting times + for p in clang-tools-extra compiler-rt cross-project-tests; do echo $p done ;; diff --git a/.github/workflows/restart-preempted-libcxx-jobs.yaml b/.github/workflows/libcxx-restart-preempted-jobs.yaml similarity index 97% rename from .github/workflows/restart-preempted-libcxx-jobs.yaml rename to .github/workflows/libcxx-restart-preempted-jobs.yaml index f8faaf25045bf2..21879ce19c27c5 100644 --- a/.github/workflows/restart-preempted-libcxx-jobs.yaml +++ b/.github/workflows/libcxx-restart-preempted-jobs.yaml @@ -34,7 +34,7 @@ jobs: script: | const failure_regex = /Process completed with exit code 1./ const preemption_regex = /The runner has received a shutdown signal/ - + const wf_run = context.payload.workflow_run core.notice(`Running on "${wf_run.display_title}" by @${wf_run.actor.login} (event: ${wf_run.event})\nWorkflow run URL: ${wf_run.html_url}`) @@ -80,30 +80,30 @@ jobs: } check_run_ids.push(check_run.id); } - + has_preempted_job = false; for (check_run_id of check_run_ids) { console.log('Listing annotations for check run: ' + check_run_id); - + annotations = await github.rest.checks.listAnnotations({ owner: context.repo.owner, repo: context.repo.repo, check_run_id: check_run_id }) - + for (annotation of annotations.data) { if (annotation.annotation_level != 'failure') { continue; } - + const preemption_match = annotation.message.match(preemption_regex); - + if (preemption_match != null) { console.log('Found preemption message: ' + annotation.message); has_preempted_job = true; } - + const failure_match = annotation.message.match(failure_regex); if (failure_match != null) { // We only want to restart the workflow if all of the failures were due to preemption. @@ -115,14 +115,14 @@ jobs: return; } } - } - + } + if (!has_preempted_job) { core.notice('No preempted jobs found. Not restarting workflow.'); await create_check_run('neutral', 'No preempted jobs found. Not restarting workflow.') return; } - + core.notice("Restarted workflow: " + context.payload.workflow_run.id); await github.rest.actions.reRunWorkflowFailedJobs({ owner: context.repo.owner, @@ -130,5 +130,3 @@ jobs: run_id: context.payload.workflow_run.id }) await create_check_run('success', 'Restarted workflow run due to preempted job') - - diff --git a/bolt/lib/Rewrite/LinuxKernelRewriter.cpp b/bolt/lib/Rewrite/LinuxKernelRewriter.cpp index 6b3f5bce9f0f58..7e0141b003bd0e 100644 --- a/bolt/lib/Rewrite/LinuxKernelRewriter.cpp +++ b/bolt/lib/Rewrite/LinuxKernelRewriter.cpp @@ -1479,8 +1479,9 @@ Error LinuxKernelRewriter::tryReadAltInstructions(uint32_t AltInstFeatureSize, } } - BC.outs() << "BOLT-INFO: parsed " << EntryID - << " alternative instruction entries\n"; + if (!ParseOnly) + BC.outs() << "BOLT-INFO: parsed " << EntryID + << " alternative instruction entries\n"; return Error::success(); } diff --git a/clang-tools-extra/clang-doc/tool/CMakeLists.txt b/clang-tools-extra/clang-doc/tool/CMakeLists.txt index fb8317b272932f..4944251245c6bc 100644 --- a/clang-tools-extra/clang-doc/tool/CMakeLists.txt +++ b/clang-tools-extra/clang-doc/tool/CMakeLists.txt @@ -18,10 +18,38 @@ target_link_libraries(clang-doc clangDoc ) -install(FILES ../assets/clang-doc-default-stylesheet.css - DESTINATION "${CMAKE_INSTALL_DATADIR}/clang" - COMPONENT clang-doc) -install(FILES ../assets/index.js - DESTINATION "${CMAKE_INSTALL_DATADIR}/clang" - COMPONENT clang-doc) +set(assets + index.js + clang-doc-default-stylesheet.css +) + +set(asset_dir "${CMAKE_CURRENT_SOURCE_DIR}/../assets") +set(resource_dir "${CMAKE_BINARY_DIR}/share/clang") +set(out_files) + +function(copy_files_to_dst src_dir dst_dir file) + set(src "${src_dir}/${file}") + set(dst "${dst_dir}/${file}") + add_custom_command(OUTPUT ${dst} + DEPENDS ${src} + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst} + COMMENT "Copying ${file} to ${dst_dir}" + ) + list(APPEND out_files ${dst}) + set(out_files ${out_files} PARENT_SCOPE) +endfunction(copy_files_to_dst) + +foreach(f ${assets}) + install(FILES ${asset_dir}/${f} + DESTINATION "${CMAKE_INSTALL_DATADIR}/clang" + COMPONENT clang-doc) + copy_files_to_dst(${asset_dir} ${resource_dir} ${f}) +endforeach(f) + +add_custom_target(copy-clang-doc-assets + DEPENDS ${out_files} + COMMENT "Copying Clang-Doc Assets" +) +set_target_properties(copy-clang-doc-assets PROPERTIES FOLDER "Clang-Doc/Assets") +add_dependencies(clang-doc copy-clang-doc-assets) diff --git a/clang-tools-extra/clangd/TidyProvider.cpp b/clang-tools-extra/clangd/TidyProvider.cpp index a4121df30d3dfa..a87238e0c0938c 100644 --- a/clang-tools-extra/clangd/TidyProvider.cpp +++ b/clang-tools-extra/clangd/TidyProvider.cpp @@ -195,10 +195,10 @@ TidyProvider addTidyChecks(llvm::StringRef Checks, } TidyProvider disableUnusableChecks(llvm::ArrayRef ExtraBadChecks) { - constexpr llvm::StringLiteral Seperator(","); + constexpr llvm::StringLiteral Separator(","); static const std::string BadChecks = llvm::join_items( - Seperator, - // We want this list to start with a seperator to + Separator, + // We want this list to start with a separator to // simplify appending in the lambda. So including an // empty string here will force that. "", @@ -227,7 +227,7 @@ TidyProvider disableUnusableChecks(llvm::ArrayRef ExtraBadChecks) { for (const std::string &Str : ExtraBadChecks) { if (Str.empty()) continue; - Size += Seperator.size(); + Size += Separator.size(); if (LLVM_LIKELY(Str.front() != '-')) ++Size; Size += Str.size(); @@ -238,7 +238,7 @@ TidyProvider disableUnusableChecks(llvm::ArrayRef ExtraBadChecks) { for (const std::string &Str : ExtraBadChecks) { if (Str.empty()) continue; - DisableGlob += Seperator; + DisableGlob += Separator; if (LLVM_LIKELY(Str.front() != '-')) DisableGlob.push_back('-'); DisableGlob += Str; diff --git a/clang-tools-extra/include-cleaner/lib/IncludeSpeller.cpp b/clang-tools-extra/include-cleaner/lib/IncludeSpeller.cpp index 2073f0a1d3d878..8332eb685d652f 100644 --- a/clang-tools-extra/include-cleaner/lib/IncludeSpeller.cpp +++ b/clang-tools-extra/include-cleaner/lib/IncludeSpeller.cpp @@ -9,6 +9,7 @@ #include "clang-include-cleaner/IncludeSpeller.h" #include "clang-include-cleaner/Types.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringRef.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/Registry.h" #include @@ -30,8 +31,14 @@ class DefaultIncludeSpeller : public IncludeSpeller { return Input.H.verbatim().str(); case Header::Physical: bool IsAngled = false; + std::string WorkingDir; + if (auto WD = Input.HS.getFileMgr() + .getVirtualFileSystem() + .getCurrentWorkingDirectory()) + WorkingDir = *WD; std::string FinalSpelling = Input.HS.suggestPathToFileForDiagnostics( - Input.H.physical(), Input.Main->tryGetRealPathName(), &IsAngled); + Input.H.resolvedPath(), WorkingDir, Input.Main->tryGetRealPathName(), + &IsAngled); return IsAngled ? "<" + FinalSpelling + ">" : "\"" + FinalSpelling + "\""; } llvm_unreachable("Unknown clang::include_cleaner::Header::Kind enum"); @@ -60,4 +67,4 @@ std::string spellHeader(const IncludeSpeller::Input &Input) { return Spelling; } -} // namespace clang::include_cleaner \ No newline at end of file +} // namespace clang::include_cleaner diff --git a/clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp b/clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp index a548868071a122..8f6ad09c46cc4a 100644 --- a/clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp +++ b/clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp @@ -89,6 +89,24 @@ TEST(IncludeSpeller, CanOverrideSystemHeaders) { HS, MainFile})); } +TEST(IncludeSpeller, RelativeIncludeSearchPath) { + TestInputs Inputs; + + Inputs.WorkingDir = "/root/inner"; + Inputs.ExtraArgs.push_back("-I.."); + Inputs.ExtraFiles["/root/foo.h"] = ""; + TestAST AST{Inputs}; + + auto &FM = AST.fileManager(); + auto &HS = AST.preprocessor().getHeaderSearchInfo(); + const auto *MainFile = AST.sourceManager().getFileEntryForID( + AST.sourceManager().getMainFileID()); + + EXPECT_EQ("\"foo.h\"", + spellHeader( + {Header{*FM.getOptionalFileRef("/root/foo.h")}, HS, MainFile})); +} + IncludeSpellingStrategy::Add Speller("dummy", "Dummy Include Speller"); diff --git a/clang/bindings/python/clang/cindex.py b/clang/bindings/python/clang/cindex.py index 302d99dccd77b5..b3d51e4d2a668a 100644 --- a/clang/bindings/python/clang/cindex.py +++ b/clang/bindings/python/clang/cindex.py @@ -649,7 +649,7 @@ def name(self): @classmethod def from_id(cls, id): - if id >= len(cls._kinds) or cls._kinds[id] is None: + if id < 0 or id >= len(cls._kinds) or cls._kinds[id] is None: raise ValueError("Unknown template argument kind %d" % id) return cls._kinds[id] @@ -1336,7 +1336,7 @@ def __repr__(self): CursorKind.OMP_TEAMS_DISTRIBUTE_DIRECTIVE = CursorKind(271) # OpenMP teams distribute simd directive. -CursorKind.OMP_TEAMS_DISTRIBUTE_DIRECTIVE = CursorKind(272) +CursorKind.OMP_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE = CursorKind(272) # OpenMP teams distribute parallel for simd directive. CursorKind.OMP_TEAMS_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE = CursorKind(273) @@ -2215,7 +2215,7 @@ def name(self): @staticmethod def from_id(id): - if id >= len(StorageClass._kinds) or not StorageClass._kinds[id]: + if id < 0 or id >= len(StorageClass._kinds) or not StorageClass._kinds[id]: raise ValueError("Unknown storage class %d" % id) return StorageClass._kinds[id] @@ -2395,7 +2395,7 @@ def __repr__(self): TypeKind.OCLRESERVEID = TypeKind(160) TypeKind.OBJCOBJECT = TypeKind(161) -TypeKind.OBJCCLASS = TypeKind(162) +TypeKind.OBJCTYPEPARAM = TypeKind(162) TypeKind.ATTRIBUTED = TypeKind(163) TypeKind.OCLINTELSUBGROUPAVCMCEPAYLOAD = TypeKind(164) diff --git a/clang/bindings/python/tests/cindex/test_enums.py b/clang/bindings/python/tests/cindex/test_enums.py new file mode 100644 index 00000000000000..6fc0e5ed77e3e7 --- /dev/null +++ b/clang/bindings/python/tests/cindex/test_enums.py @@ -0,0 +1,47 @@ +import unittest + +from clang.cindex import ( + CursorKind, + TemplateArgumentKind, + ExceptionSpecificationKind, + AvailabilityKind, + AccessSpecifier, + TypeKind, + RefQualifierKind, + LinkageKind, + TLSKind, + StorageClass, +) + + +class TestCursorKind(unittest.TestCase): + enums = [ + CursorKind, + TemplateArgumentKind, + ExceptionSpecificationKind, + AvailabilityKind, + AccessSpecifier, + TypeKind, + RefQualifierKind, + LinkageKind, + TLSKind, + StorageClass, + ] + + def test_from_id(self): + """Check that kinds can be constructed from valid IDs""" + for enum in self.enums: + self.assertEqual(enum.from_id(2), enum._kinds[2]) + with self.assertRaises(ValueError): + enum.from_id(len(enum._kinds)) + with self.assertRaises(ValueError): + enum.from_id(-1) + + def test_unique_kinds(self): + """Check that no kind name has been used multiple times""" + for enum in self.enums: + for id in range(len(enum._kinds)): + try: + enum.from_id(id).name + except ValueError: + pass diff --git a/clang/cmake/caches/Fuchsia-stage2.cmake b/clang/cmake/caches/Fuchsia-stage2.cmake index aa07b04be65ccf..a573ec54732101 100644 --- a/clang/cmake/caches/Fuchsia-stage2.cmake +++ b/clang/cmake/caches/Fuchsia-stage2.cmake @@ -300,14 +300,14 @@ if(FUCHSIA_SDK) set(LLVM_RUNTIME_MULTILIB_hwasan+noexcept_TARGETS "aarch64-unknown-fuchsia;riscv64-unknown-fuchsia" CACHE STRING "") endif() -foreach(target armv6m-unknown-eabi) +foreach(target armv6m-unknown-eabi;armv7m-unknown-eabi;armv8m-unknown-eabi) list(APPEND BUILTIN_TARGETS "${target}") set(BUILTINS_${target}_CMAKE_SYSTEM_NAME Generic CACHE STRING "") set(BUILTINS_${target}_CMAKE_SYSTEM_PROCESSOR arm CACHE STRING "") set(BUILTINS_${target}_CMAKE_SYSROOT "" CACHE STRING "") set(BUILTINS_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "") foreach(lang C;CXX;ASM) - set(BUILTINS_${target}_CMAKE_${lang}_FLAGS "--target=${target} -mcpu=cortex-m0plus -mthumb" CACHE STRING "") + set(BUILTINS_${target}_CMAKE_${lang}_FLAGS "--target=${target} -mthumb" CACHE STRING "") endforeach() foreach(type SHARED;MODULE;EXE) set(BUILTINS_${target}_CMAKE_${type}_LINKER_FLAGS "-fuse-ld=lld" CACHE STRING "") @@ -321,7 +321,7 @@ foreach(target armv6m-unknown-eabi) set(RUNTIMES_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "") set(RUNTIMES_${target}_CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY CACHE STRING "") foreach(lang C;CXX;ASM) - set(RUNTIMES_${target}_CMAKE_${lang}_FLAGS "--target=${target} -mcpu=cortex-m0plus -mthumb" CACHE STRING "") + set(RUNTIMES_${target}_CMAKE_${lang}_FLAGS "--target=${target} -mthumb" CACHE STRING "") endforeach() foreach(type SHARED;MODULE;EXE) set(RUNTIMES_${target}_CMAKE_${type}_LINKER_FLAGS "-fuse-ld=lld" CACHE STRING "") diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 8c2f737836a9dc..36efeb8c70cca8 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -135,6 +135,14 @@ Clang Frontend Potentially Breaking Changes - The ``hasTypeLoc`` AST matcher will no longer match a ``classTemplateSpecializationDecl``; existing uses should switch to ``templateArgumentLoc`` or ``hasAnyTemplateArgumentLoc`` instead. +Clang Python Bindings Potentially Breaking Changes +-------------------------------------------------- +- Renamed ``CursorKind`` variant 272 from ``OMP_TEAMS_DISTRIBUTE_DIRECTIVE`` + to ``OMP_TEAMS_DISTRIBUTE_SIMD_DIRECTIVE``. The previous name was incorrect, it was a duplicate + of variant 271. +- Renamed ``TypeKind`` variant 162 from ``OBJCCLASS`` to ``OBJCTYPEPARAM``. + The previous name was incorrect, it was a duplicate of variant 28. + What's New in Clang |release|? ============================== Some of the major new features and improvements to Clang are listed @@ -343,6 +351,9 @@ Non-comprehensive list of changes in this release - Added ``__is_bitwise_cloneable`` which is used to check whether a type can be safely copied by memcpy/memmove. +- ``#pragma GCC diagnostic warning "-Wfoo"`` can now downgrade ``-Werror=foo`` + errors and certain default-to-error ``-W`` diagnostics to warnings. + New Compiler Flags ------------------ - ``-fsanitize=implicit-bitfield-conversion`` checks implicit truncation and @@ -921,6 +932,10 @@ Android Support Windows Support ^^^^^^^^^^^^^^^ +- The clang-cl ``/Ot`` compiler option ("optimize for speed", also implied by + ``/O2``) now maps to clang's ``-O3`` optimizataztion level instead of ``-O2``. + Users who prefer the old behavior can use ``clang-cl /Ot /clang:-O2 ...``. + - Clang-cl now supports function targets with intrinsic headers. This allows for runtime feature detection of intrinsics. Previously under clang-cl ``immintrin.h`` and similar intrinsic headers would only include the intrinsics diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst index f954857b0235af..8e01ea15064ba7 100644 --- a/clang/docs/UsersManual.rst +++ b/clang/docs/UsersManual.rst @@ -1138,7 +1138,7 @@ and ``#pragma clang diagnostic`` are synonyms for Clang. GCC will ignore The pragma may control any warning that can be used from the command line. Warnings may be set to ignored, warning, error, or fatal. The -following example code will tell Clang or GCC to ignore the -Wall +following example code will tell Clang or GCC to ignore the ``-Wall`` warnings: .. code-block:: c @@ -1186,6 +1186,15 @@ severity levels. They can be used to change severity of a particular diagnostic for a region of source file. A notable difference from GCC is that diagnostic not enabled via command line arguments can't be enabled this way yet. +Some diagnostics associated with a ``-W`` flag have the error severity by +default. They can be ignored or downgraded to warnings: + +.. code-block:: cpp + + // C only + #pragma GCC diagnostic warning "-Wimplicit-function-declaration" + int main(void) { puts(""); } + In addition to controlling warnings and errors generated by the compiler, it is possible to generate custom warning and error messages through the following pragmas: @@ -4632,12 +4641,13 @@ Execute ``clang-cl /?`` to see a list of supported options: /Ob0 Disable function inlining /Ob1 Only inline functions which are (explicitly or implicitly) marked inline /Ob2 Inline functions as deemed beneficial by the compiler + /Ob3 Same as /Ob2 /Od Disable optimization /Og No effect /Oi- Disable use of builtin functions /Oi Enable use of builtin functions - /Os Optimize for size - /Ot Optimize for speed + /Os Optimize for size (like clang -Os) + /Ot Optimize for speed (like clang -O3) /Ox Deprecated (same as /Og /Oi /Ot /Oy /Ob2); use /O2 instead /Oy- Disable frame pointer omission (x86 only, default) /Oy Enable frame pointer omission (x86 only) diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index f1f20fca477a47..53ece996769a87 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -3210,6 +3210,9 @@ class ASTContext : public RefCountedBase { /// valid feature names. ParsedTargetAttr filterFunctionTargetAttrs(const TargetAttr *TD) const; + std::vector + filterFunctionTargetVersionAttrs(const TargetVersionAttr *TV) const; + void getFunctionFeatureMap(llvm::StringMap &FeatureMap, const FunctionDecl *) const; void getFunctionFeatureMap(llvm::StringMap &FeatureMap, diff --git a/clang/include/clang/AST/PrettyPrinter.h b/clang/include/clang/AST/PrettyPrinter.h index da276e26049b00..332ac3c6a004a9 100644 --- a/clang/include/clang/AST/PrettyPrinter.h +++ b/clang/include/clang/AST/PrettyPrinter.h @@ -77,7 +77,7 @@ struct PrintingPolicy { PrintCanonicalTypes(false), PrintInjectedClassNameWithArguments(true), UsePreferredNames(true), AlwaysIncludeTypeForTemplateArgument(false), CleanUglifiedParameters(false), EntireContentsOfLargeArray(true), - UseEnumerators(true) {} + UseEnumerators(true), UseHLSLTypes(LO.HLSL) {} /// Adjust this printing policy for cases where it's known that we're /// printing C++ code (for instance, if AST dumping reaches a C++-only @@ -342,6 +342,11 @@ struct PrintingPolicy { LLVM_PREFERRED_TYPE(bool) unsigned UseEnumerators : 1; + /// Whether or not we're printing known HLSL code and should print HLSL + /// sugared types when possible. + LLVM_PREFERRED_TYPE(bool) + unsigned UseHLSLTypes : 1; + /// Callbacks to use to allow the behavior of printing to be customized. const PrintingCallbacks *Callbacks = nullptr; }; diff --git a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td index cdf27247602f2b..e10fa71011f304 100644 --- a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td +++ b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td @@ -26,6 +26,8 @@ def err_unsupported_environment : Error<"environment '%0' is not supported: '%1' def err_unsupported_os : Error<"os '%0' is not supported: '%1'">; def err_cannot_read_input_list : Error<"could not read %0 input list '%1': %2">; def err_invalid_label: Error<"label '%0' is reserved: use a different label name for -X