[PATCH] D108905: [ItaniumCXXABI] Add -fassume-nothrow-exception-dtor to assume that an exception object' destructor is nothrow
ChuanqiXu added a comment. Oh, I am not saying the legacy and old comment. I mean you need to touch ReleaseNotes.rst and UserManual.rst since we add a new flag. Also we need either add a TODO/FIXME saying we need to emit an error in Sema if we find the the dtor of the exception we're throwing may throw or implement the semantics actually. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D108905/new/ https://reviews.llvm.org/D108905 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)
@@ -696,6 +698,19 @@ buildPreamble(PathRef FileName, CompilerInvocation CI, Result->Includes = CapturedInfo.takeIncludes(); Result->Pragmas = std::make_shared( CapturedInfo.takePragmaIncludes()); + +if (ExperimentalModulesSupport) { + WallTimer PrerequisiteModuleTimer; + PrerequisiteModuleTimer.startTimer(); + Result->DependentModulesInfo = + PrerequisiteModules::buildPrerequisiteModulesFor(FileName, Inputs.TFS, + CDB); + PrerequisiteModuleTimer.stopTimer(); + + log("Built prerequisite module for file {0} in {1} seconds", FileName, ChuanqiXu9 wrote: Done https://github.com/llvm/llvm-project/pull/66462 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)
@@ -0,0 +1,78 @@ +//=== ModuleDependencyScanner.cpp *- C++-*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "ModuleDependencyScanner.h" + +namespace clang { +namespace clangd { + +std::optional +ModuleDependencyScanner::scan(PathRef FilePath) { + std::optional Cmd = CDB.getCompileCommand(FilePath); + + if (!Cmd) +return std::nullopt; + + using namespace clang::tooling::dependencies; + + llvm::SmallString<128> FilePathDir(FilePath); + llvm::sys::path::remove_filename(FilePathDir); + DependencyScanningTool ScanningTool(Service, TFS.view(FilePathDir)); ChuanqiXu9 wrote: Yeah, initially I added a cache for this. But you pointed out that the implementation is problematic. Then I dropped the cache and added a TODO in the header of `ModuleDependencyScanner.h`. My thought is that this is an performance optimization that we can perform later and this may not be a blocker. https://github.com/llvm/llvm-project/pull/66462 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)
@@ -0,0 +1,141 @@ +//===- PrerequisiteModules.h -*- +//C++-*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// Experimental support for C++20 Modules. +// +// Currently we simplify the implementations by preventing reusing module files +// across different versions and different source files. But this is clearly a +// waste of time and space in the end of the day. +// +// FIXME: Supporting reusing module files across different versions and +// different source files. +// +//===--===// + +#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_PREREQUISITEMODULES_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_PREREQUISITEMODULES_H + +#include "Compiler.h" +#include "GlobalCompilationDatabase.h" +#include "ModuleDependencyScanner.h" +#include "support/Path.h" + +#include "clang/Lex/HeaderSearchOptions.h" + +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/StringMap.h" + +namespace clang { +namespace clangd { + +/// Build and store all the needed module files information to parse a single +/// source file. e.g., +/// +/// ``` +/// // a.cppm +/// export module a; +/// +/// // b.cppm +/// export module b; +/// import a; +/// +/// // c.cppm +/// export module c; +/// import a; +/// ``` +/// +/// For the source file `c.cppm`, an instance of the class will build and store +/// the module files for `a.cppm` and `b.cppm`. But the module file for `c.cppm` +/// won't be built. Since it is not needed to parse `c.cppm`. +/// +/// All the built module files won't be shared with other instances of the +/// class. So that we can avoid worrying thread safety. +/// +/// A PrerequisiteModules instace should only be initialized by +/// `PrerequisiteModules::buildPrerequisiteModulesFor(...)`. +/// +/// Users can detect whether the PrerequisiteModules is still up to date by +/// calling the `CanReuse()` member function. +/// +/// The users should call `adjustHeaderSearchOptions(...)` or +/// `adjustCompileCommands(CompileCommand&)` member function to update the +/// compilation commands to select the built module files first. +struct PrerequisiteModules { ChuanqiXu9 wrote: Done https://github.com/llvm/llvm-project/pull/66462 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)
@@ -0,0 +1,55 @@ +//===-- ProjectModules.h -*- C++-*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_PROJECTMODULES_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_PROJECTMODULES_H + +#include "ModuleDependencyScanner.h" + +namespace clang { +namespace clangd { + +/// An interface to query the modules information in the project. +/// This should be obtained by +/// `GlobalCompilationDatabase::getProjectModules(PathRef)`. +/// +/// TODO: The existing `ScanningAllProjectModules` is not efficient. See the +/// comments in ModuleDependencyScanner for detail. +class ProjectModules { +public: + virtual std::vector getRequiredModules(PathRef File) = 0; + virtual PathRef getSourceForModuleName(StringRef ModuleName) = 0; +}; + +class ScanningAllProjectModules : public ProjectModules { ChuanqiXu9 wrote: Done https://github.com/llvm/llvm-project/pull/66462 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)
@@ -587,11 +587,11 @@ class DiagPatcher { }; } // namespace -std::shared_ptr -buildPreamble(PathRef FileName, CompilerInvocation CI, - const ParseInputs &Inputs, bool StoreInMemory, - PreambleParsedCallback PreambleCallback, - PreambleBuildStats *Stats) { +std::shared_ptr buildPreamble( +PathRef FileName, CompilerInvocation CI, const ParseInputs &Inputs, +bool StoreInMemory, bool ExperimentalModulesSupport, +const GlobalCompilationDatabase &CDB, ChuanqiXu9 wrote: Done by adding a `ModuleBuilder*` parameter to the interface. https://github.com/llvm/llvm-project/pull/66462 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)
@@ -104,6 +107,8 @@ struct PreambleData { IncludeStructure Includes; // Captures #include-mapping information in #included headers. std::shared_ptr Pragmas; + // Information about module files for this preamble. + std::optional DependentModulesInfo; ChuanqiXu9 wrote: Done https://github.com/llvm/llvm-project/pull/66462 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)
@@ -0,0 +1,278 @@ +//===- PrerequisiteModules.cpp ---*- +//C++-*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "PrerequisiteModules.h" +#include "ProjectModules.h" +#include "support/Logger.h" + +#include "clang/Frontend/FrontendAction.h" +#include "clang/Frontend/FrontendActions.h" +#include "clang/Serialization/ASTReader.h" + +namespace clang { +namespace clangd { + +namespace { +llvm::SmallString<128> getAbsolutePath(const tooling::CompileCommand &Cmd) { + llvm::SmallString<128> AbsolutePath; + if (llvm::sys::path::is_absolute(Cmd.Filename)) { +AbsolutePath = Cmd.Filename; + } else { +AbsolutePath = Cmd.Directory; +llvm::sys::path::append(AbsolutePath, Cmd.Filename); +llvm::sys::path::remove_dots(AbsolutePath, true); + } + return AbsolutePath; +} +} // namespace + +PrerequisiteModules::PrerequisiteModules(PathRef MainFile, + const GlobalCompilationDatabase &CDB) { + std::optional PI = CDB.getProjectInfo(MainFile); + if (!PI) +return; + + llvm::SmallString<128> Result(PI->SourceRoot); ChuanqiXu9 wrote: Done by adding a FIXME. https://github.com/llvm/llvm-project/pull/66462 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)
@@ -0,0 +1,78 @@ +//=== ModuleDependencyScanner.cpp *- C++-*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "ModuleDependencyScanner.h" + +namespace clang { +namespace clangd { + +std::optional +ModuleDependencyScanner::scan(PathRef FilePath) { + std::optional Cmd = CDB.getCompileCommand(FilePath); + + if (!Cmd) +return std::nullopt; + + using namespace clang::tooling::dependencies; + + llvm::SmallString<128> FilePathDir(FilePath); + llvm::sys::path::remove_filename(FilePathDir); + DependencyScanningTool ScanningTool(Service, TFS.view(FilePathDir)); + + llvm::Expected P1689Result = ChuanqiXu9 wrote: Done https://github.com/llvm/llvm-project/pull/66462 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)
@@ -0,0 +1,78 @@ +//=== ModuleDependencyScanner.cpp *- C++-*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "ModuleDependencyScanner.h" + +namespace clang { +namespace clangd { + +std::optional +ModuleDependencyScanner::scan(PathRef FilePath) { + std::optional Cmd = CDB.getCompileCommand(FilePath); + + if (!Cmd) +return std::nullopt; + + using namespace clang::tooling::dependencies; + + llvm::SmallString<128> FilePathDir(FilePath); + llvm::sys::path::remove_filename(FilePathDir); + DependencyScanningTool ScanningTool(Service, TFS.view(FilePathDir)); + + llvm::Expected P1689Result = + ScanningTool.getP1689ModuleDependencyFile(*Cmd, Cmd->Directory); + + if (auto E = P1689Result.takeError()) { +// Ignore any error. ChuanqiXu9 wrote: I prefer `log()` here. Since if anything bad happens, it shouldn't be a bug of clangd itself. It might be the problem of user files or the implementation of clang-scan-deps. So it may not be helpful for debugging clangd and it violates the comment with `vlog()`. https://github.com/llvm/llvm-project/pull/66462 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)
@@ -0,0 +1,90 @@ +//===-- ModuleDependencyScanner.h *- C++-*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_MODULEDEPENDENCYSCANNER_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_MODULEDEPENDENCYSCANNER_H + +#include "GlobalCompilationDatabase.h" +#include "support/Path.h" +#include "support/ThreadsafeFS.h" + +#include "clang/Tooling/DependencyScanning/DependencyScanningService.h" +#include "clang/Tooling/DependencyScanning/DependencyScanningTool.h" + +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/StringMap.h" + +namespace clang { +namespace clangd { + +/// A scanner to query the dependency information for C++20 Modules. +/// +/// The scanner can scan a single file with `scan(PathRef)` member function +/// or scan the whole project with `globalScan(PathRef)` member function. See +/// the comments of `globalScan` to see the details. +class ModuleDependencyScanner { +public: + ModuleDependencyScanner(const GlobalCompilationDatabase &CDB, + const ThreadsafeFS &TFS) + : CDB(CDB), TFS(TFS), +Service(tooling::dependencies::ScanningMode::CanonicalPreprocessing, +tooling::dependencies::ScanningOutputFormat::P1689) {} + + // The scanned modules dependency information for a specific source file. + struct ModuleDependencyInfo { +// The name of the module if the file is a module unit. +std::optional ModuleName; +// A list of names for the modules that the file directly depends. +std::vector RequiredModules; + }; + + /// Scanning the single file specified by \param FilePath. + /// NOTE: This is only used by unittests for external uses. + std::optional scan(PathRef FilePath); + + /// Scanning every source file in the current project to get the + /// to map. + /// It looks unefficiency to scan the whole project especially for + /// every version of every file! + /// TODO: We should find an efficient method to get the + /// to map. We can make it either by providing + /// a global module dependency scanner to monitor every file. Or we + /// can simply require the build systems (or even if the end users) + /// to provide the map. + void globalScan(const std::vector &AllFiles); + bool isGlobalScanned() const { return GlobalScanned; } + + /// Get the source file from the module name. Note that the language + /// guarantees all the module names are unique in a valid program. + /// This function should only be called after globalScan. + /// FIXME: Maybe we should handle the corner cases. + PathRef getSourceForModuleName(StringRef ModuleName) const; + + /// Return the direct required modules. Indirect required modules are not + /// included. + std::vector getRequiredModules(PathRef File); + +private: + const GlobalCompilationDatabase &CDB; + const ThreadsafeFS &TFS; + + // Whether the scanner has scanned the project globally. + bool GlobalScanned = false; + + clang::tooling::dependencies::DependencyScanningService Service; + + // TODO: Add a scanning cache. + + // Map module name to source file path. ChuanqiXu9 wrote: We simply assume that a module can't be declared by multiple source files and I commented this in comments of ModuleDependencyScanner. And I add a comment to ProjectModules to explain the meaning of module names. https://github.com/llvm/llvm-project/pull/66462 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)
@@ -0,0 +1,90 @@ +//===-- ModuleDependencyScanner.h *- C++-*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_MODULEDEPENDENCYSCANNER_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_MODULEDEPENDENCYSCANNER_H + +#include "GlobalCompilationDatabase.h" +#include "support/Path.h" +#include "support/ThreadsafeFS.h" + +#include "clang/Tooling/DependencyScanning/DependencyScanningService.h" +#include "clang/Tooling/DependencyScanning/DependencyScanningTool.h" + +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/StringMap.h" + +namespace clang { +namespace clangd { + +/// A scanner to query the dependency information for C++20 Modules. +/// +/// The scanner can scan a single file with `scan(PathRef)` member function +/// or scan the whole project with `globalScan(PathRef)` member function. See +/// the comments of `globalScan` to see the details. +class ModuleDependencyScanner { +public: + ModuleDependencyScanner(const GlobalCompilationDatabase &CDB, + const ThreadsafeFS &TFS) + : CDB(CDB), TFS(TFS), +Service(tooling::dependencies::ScanningMode::CanonicalPreprocessing, +tooling::dependencies::ScanningOutputFormat::P1689) {} + + // The scanned modules dependency information for a specific source file. + struct ModuleDependencyInfo { +// The name of the module if the file is a module unit. +std::optional ModuleName; +// A list of names for the modules that the file directly depends. +std::vector RequiredModules; + }; + + /// Scanning the single file specified by \param FilePath. + /// NOTE: This is only used by unittests for external uses. + std::optional scan(PathRef FilePath); + + /// Scanning every source file in the current project to get the + /// to map. + /// It looks unefficiency to scan the whole project especially for + /// every version of every file! + /// TODO: We should find an efficient method to get the + /// to map. We can make it either by providing + /// a global module dependency scanner to monitor every file. Or we + /// can simply require the build systems (or even if the end users) + /// to provide the map. + void globalScan(const std::vector &AllFiles); + bool isGlobalScanned() const { return GlobalScanned; } + + /// Get the source file from the module name. Note that the language + /// guarantees all the module names are unique in a valid program. + /// This function should only be called after globalScan. + /// FIXME: Maybe we should handle the corner cases. ChuanqiXu9 wrote: Done by expanding the FIXME. https://github.com/llvm/llvm-project/pull/66462 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)
@@ -104,6 +107,8 @@ struct PreambleData { IncludeStructure Includes; // Captures #include-mapping information in #included headers. std::shared_ptr Pragmas; + // Information about module files for this preamble. + std::optional DependentModulesInfo; ChuanqiXu9 wrote: Done https://github.com/llvm/llvm-project/pull/66462 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)
@@ -0,0 +1,278 @@ +//===- PrerequisiteModules.cpp ---*- +//C++-*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "PrerequisiteModules.h" +#include "ProjectModules.h" +#include "support/Logger.h" + +#include "clang/Frontend/FrontendAction.h" +#include "clang/Frontend/FrontendActions.h" +#include "clang/Serialization/ASTReader.h" + +namespace clang { +namespace clangd { + +namespace { +llvm::SmallString<128> getAbsolutePath(const tooling::CompileCommand &Cmd) { + llvm::SmallString<128> AbsolutePath; + if (llvm::sys::path::is_absolute(Cmd.Filename)) { +AbsolutePath = Cmd.Filename; + } else { +AbsolutePath = Cmd.Directory; +llvm::sys::path::append(AbsolutePath, Cmd.Filename); +llvm::sys::path::remove_dots(AbsolutePath, true); + } + return AbsolutePath; +} +} // namespace + +PrerequisiteModules::PrerequisiteModules(PathRef MainFile, + const GlobalCompilationDatabase &CDB) { + std::optional PI = CDB.getProjectInfo(MainFile); + if (!PI) +return; + + llvm::SmallString<128> Result(PI->SourceRoot); + llvm::sys::path::append(Result, ".cache"); + llvm::sys::path::append(Result, "clangd"); + llvm::sys::path::append(Result, "module_files"); + llvm::sys::fs::create_directories(Result, /*IgnoreExisting=*/true); + + llvm::sys::path::append(Result, llvm::sys::path::filename(MainFile)); + llvm::sys::fs::createUniqueDirectory(Result, UniqueModuleFilesPathPrefix); + + log("Initialized module files to {0}", UniqueModuleFilesPathPrefix.str()); +} + +PrerequisiteModules::~PrerequisiteModules() { + DependentModuleNames.clear(); + + if (UniqueModuleFilesPathPrefix.empty()) +return; + + llvm::sys::fs::remove_directories(UniqueModuleFilesPathPrefix); + UniqueModuleFilesPathPrefix.clear(); +} + +llvm::SmallString<256> +PrerequisiteModules::getModuleFilePath(StringRef ModuleName) const { + llvm::SmallString<256> ModuleFilePath; + + ModuleFilePath = UniqueModuleFilesPathPrefix; + auto [PrimaryModuleName, PartitionName] = ModuleName.split(':'); + llvm::sys::path::append(ModuleFilePath, PrimaryModuleName); + if (!PartitionName.empty()) { +ModuleFilePath.append("-"); +ModuleFilePath.append(PartitionName); + } + ModuleFilePath.append(".pcm"); + + return ModuleFilePath; +} + +bool PrerequisiteModules::isModuleUnitBuilt(StringRef ModuleName) const { + if (!DependentModuleNames.count(ModuleName)) +return false; + + auto BMIPath = getModuleFilePath(ModuleName); + if (llvm::sys::fs::exists(BMIPath)) +return true; + + DependentModuleNames.erase(ModuleName); + return false; +} + +void PrerequisiteModules::adjustHeaderSearchOptions( +HeaderSearchOptions &Options) const { + if (!IsInited()) +return; + + Options.PrebuiltModulePaths.insert(Options.PrebuiltModulePaths.begin(), + UniqueModuleFilesPathPrefix.str().str()); + + for (auto Iter = Options.PrebuiltModuleFiles.begin(); + Iter != Options.PrebuiltModuleFiles.end();) { +if (isModuleUnitBuilt(Iter->first)) { + Iter = Options.PrebuiltModuleFiles.erase(Iter); + continue; +} + +Iter++; + } +} + +void PrerequisiteModules::adjustCompileCommands( +tooling::CompileCommand &Cmd) const { + if (!IsInited()) +return; + + std::vector CommandLine(std::move(Cmd.CommandLine)); + + Cmd.CommandLine.emplace_back(CommandLine[0]); + Cmd.CommandLine.emplace_back( ChuanqiXu9 wrote: Done. Originally I just felt it was simpler. And now I feel passing `-fmodule-file==` looks more neat indeed. https://github.com/llvm/llvm-project/pull/66462 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)
@@ -0,0 +1,278 @@ +//===- PrerequisiteModules.cpp ---*- +//C++-*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "PrerequisiteModules.h" +#include "ProjectModules.h" +#include "support/Logger.h" + +#include "clang/Frontend/FrontendAction.h" +#include "clang/Frontend/FrontendActions.h" +#include "clang/Serialization/ASTReader.h" + +namespace clang { +namespace clangd { + +namespace { +llvm::SmallString<128> getAbsolutePath(const tooling::CompileCommand &Cmd) { + llvm::SmallString<128> AbsolutePath; + if (llvm::sys::path::is_absolute(Cmd.Filename)) { +AbsolutePath = Cmd.Filename; + } else { +AbsolutePath = Cmd.Directory; +llvm::sys::path::append(AbsolutePath, Cmd.Filename); +llvm::sys::path::remove_dots(AbsolutePath, true); + } + return AbsolutePath; +} +} // namespace + +PrerequisiteModules::PrerequisiteModules(PathRef MainFile, + const GlobalCompilationDatabase &CDB) { + std::optional PI = CDB.getProjectInfo(MainFile); + if (!PI) +return; + + llvm::SmallString<128> Result(PI->SourceRoot); + llvm::sys::path::append(Result, ".cache"); + llvm::sys::path::append(Result, "clangd"); + llvm::sys::path::append(Result, "module_files"); ChuanqiXu9 wrote: Personally, I prefer using the term `module files` to describe on disk BMI files. Since the term "modules" may have too many meanings. https://github.com/llvm/llvm-project/pull/66462 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)
@@ -0,0 +1,141 @@ +//===- PrerequisiteModules.h -*- +//C++-*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// Experimental support for C++20 Modules. +// +// Currently we simplify the implementations by preventing reusing module files +// across different versions and different source files. But this is clearly a +// waste of time and space in the end of the day. +// +// FIXME: Supporting reusing module files across different versions and +// different source files. +// +//===--===// + +#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_PREREQUISITEMODULES_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_PREREQUISITEMODULES_H + +#include "Compiler.h" +#include "GlobalCompilationDatabase.h" +#include "ModuleDependencyScanner.h" +#include "support/Path.h" + +#include "clang/Lex/HeaderSearchOptions.h" + +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/StringMap.h" + +namespace clang { +namespace clangd { + +/// Build and store all the needed module files information to parse a single +/// source file. e.g., +/// +/// ``` +/// // a.cppm +/// export module a; +/// +/// // b.cppm +/// export module b; +/// import a; +/// +/// // c.cppm +/// export module c; +/// import a; +/// ``` +/// +/// For the source file `c.cppm`, an instance of the class will build and store +/// the module files for `a.cppm` and `b.cppm`. But the module file for `c.cppm` +/// won't be built. Since it is not needed to parse `c.cppm`. +/// +/// All the built module files won't be shared with other instances of the +/// class. So that we can avoid worrying thread safety. +/// +/// A PrerequisiteModules instace should only be initialized by +/// `PrerequisiteModules::buildPrerequisiteModulesFor(...)`. +/// +/// Users can detect whether the PrerequisiteModules is still up to date by +/// calling the `CanReuse()` member function. +/// +/// The users should call `adjustHeaderSearchOptions(...)` or +/// `adjustCompileCommands(CompileCommand&)` member function to update the +/// compilation commands to select the built module files first. +struct PrerequisiteModules { ChuanqiXu9 wrote: Done. https://github.com/llvm/llvm-project/pull/66462 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)
@@ -0,0 +1,78 @@ +//=== ModuleDependencyScanner.cpp *- C++-*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#include "ModuleDependencyScanner.h" + +namespace clang { +namespace clangd { + +std::optional +ModuleDependencyScanner::scan(PathRef FilePath) { + std::optional Cmd = CDB.getCompileCommand(FilePath); + + if (!Cmd) +return std::nullopt; + + using namespace clang::tooling::dependencies; + + llvm::SmallString<128> FilePathDir(FilePath); + llvm::sys::path::remove_filename(FilePathDir); + DependencyScanningTool ScanningTool(Service, TFS.view(FilePathDir)); + + llvm::Expected P1689Result = + ScanningTool.getP1689ModuleDependencyFile(*Cmd, Cmd->Directory); + + if (auto E = P1689Result.takeError()) { +// Ignore any error. +llvm::consumeError(std::move(E)); +return std::nullopt; + } + + ModuleDependencyInfo Result; + + if (P1689Result->Provides) { +ModuleNameToSource[P1689Result->Provides->ModuleName] = FilePath; +Result.ModuleName = P1689Result->Provides->ModuleName; + } + + for (auto &Required : P1689Result->Requires) +Result.RequiredModules.push_back(Required.ModuleName); + + return Result; +} + +void ModuleDependencyScanner::globalScan( +const std::vector &AllFiles) { + for (auto &File : AllFiles) +scan(File); + + GlobalScanned = true; +} + +PathRef ModuleDependencyScanner::getSourceForModuleName(StringRef ModuleName) const { + assert( ChuanqiXu9 wrote: I prefer the current style. It reduces the functionalities of `getSourceForModuleName()` also it forces the users/devs to understand what happens. e.g., I may image `getSourceForModuleName()` to be light-weight function from its name and it is surprising to me that it is actually pretty heavy. https://github.com/llvm/llvm-project/pull/66462 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)
@@ -0,0 +1,141 @@ +//===- PrerequisiteModules.h -*- +//C++-*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// Experimental support for C++20 Modules. +// +// Currently we simplify the implementations by preventing reusing module files +// across different versions and different source files. But this is clearly a +// waste of time and space in the end of the day. +// +// FIXME: Supporting reusing module files across different versions and +// different source files. +// +//===--===// + +#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_PREREQUISITEMODULES_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_PREREQUISITEMODULES_H + +#include "Compiler.h" +#include "GlobalCompilationDatabase.h" +#include "ModuleDependencyScanner.h" +#include "support/Path.h" + +#include "clang/Lex/HeaderSearchOptions.h" + +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/StringMap.h" + +namespace clang { +namespace clangd { + +/// Build and store all the needed module files information to parse a single +/// source file. e.g., +/// +/// ``` +/// // a.cppm +/// export module a; +/// +/// // b.cppm +/// export module b; +/// import a; +/// +/// // c.cppm +/// export module c; +/// import a; +/// ``` +/// +/// For the source file `c.cppm`, an instance of the class will build and store +/// the module files for `a.cppm` and `b.cppm`. But the module file for `c.cppm` +/// won't be built. Since it is not needed to parse `c.cppm`. +/// +/// All the built module files won't be shared with other instances of the +/// class. So that we can avoid worrying thread safety. +/// +/// A PrerequisiteModules instace should only be initialized by +/// `PrerequisiteModules::buildPrerequisiteModulesFor(...)`. +/// +/// Users can detect whether the PrerequisiteModules is still up to date by +/// calling the `CanReuse()` member function. +/// +/// The users should call `adjustHeaderSearchOptions(...)` or +/// `adjustCompileCommands(CompileCommand&)` member function to update the +/// compilation commands to select the built module files first. +struct PrerequisiteModules { + ~PrerequisiteModules(); + + PrerequisiteModules(const PrerequisiteModules &) = delete; + PrerequisiteModules operator=(const PrerequisiteModules &) = delete; + + PrerequisiteModules(PrerequisiteModules &&Other) ChuanqiXu9 wrote: Done https://github.com/llvm/llvm-project/pull/66462 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)
https://github.com/ChuanqiXu9 updated https://github.com/llvm/llvm-project/pull/66462 >From 190e160868080f7d64c0c05de0fd4315a3ff2b93 Mon Sep 17 00:00:00 2001 From: Chuanqi Xu Date: Fri, 15 Sep 2023 11:33:53 +0800 Subject: [PATCH] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules Alternatives to https://reviews.llvm.org/D153114. Try to address https://github.com/clangd/clangd/issues/1293. See the links for design ideas. We want to have some initial support in clang18. This is the initial support for C++20 Modules in clangd. As suggested by sammccall in https://reviews.llvm.org/D153114, we should minimize the scope of the initial patch to make it easier to review and understand so that every one are in the same page: > Don't attempt any cross-file or cross-version coordination: i.e. don't > try to reuse BMIs between different files, don't try to reuse BMIs > between (preamble) reparses of the same file, don't try to persist the > module graph. Instead, when building a preamble, synchronously scan > for the module graph, build the required PCMs on the single preamble > thread with filenames private to that preamble, and then proceed to > build the preamble. And this patch reflects the above opinions. --- clang-tools-extra/clangd/CMakeLists.txt | 4 + clang-tools-extra/clangd/ClangdServer.cpp | 2 + clang-tools-extra/clangd/ClangdServer.h | 3 + .../clangd/GlobalCompilationDatabase.cpp | 23 ++ .../clangd/GlobalCompilationDatabase.h| 14 + .../clangd/ModuleDependencyScanner.cpp| 81 .../clangd/ModuleDependencyScanner.h | 106 ++ clang-tools-extra/clangd/ModulesBuilder.cpp | 347 ++ clang-tools-extra/clangd/ModulesBuilder.h | 71 clang-tools-extra/clangd/ParsedAST.cpp| 7 + clang-tools-extra/clangd/Preamble.cpp | 28 +- clang-tools-extra/clangd/Preamble.h | 10 + .../clangd/PrerequisiteModules.h | 86 + clang-tools-extra/clangd/ProjectModules.cpp | 60 +++ clang-tools-extra/clangd/ProjectModules.h | 53 +++ clang-tools-extra/clangd/TUScheduler.cpp | 50 ++- clang-tools-extra/clangd/TUScheduler.h| 7 + clang-tools-extra/clangd/test/CMakeLists.txt | 1 + clang-tools-extra/clangd/test/modules.test| 83 + clang-tools-extra/clangd/tool/Check.cpp | 13 +- clang-tools-extra/clangd/tool/ClangdMain.cpp | 8 + .../clangd/unittests/CMakeLists.txt | 2 + .../clangd/unittests/CodeCompleteTests.cpp| 22 +- .../clangd/unittests/FileIndexTests.cpp | 4 +- .../unittests/ModuleDependencyScannerTest.cpp | 176 + .../clangd/unittests/ModulesTestSetup.h | 103 ++ .../clangd/unittests/ParsedASTTests.cpp | 8 +- .../clangd/unittests/PreambleTests.cpp| 6 +- .../unittests/PrerequisiteModulesTest.cpp | 238 clang-tools-extra/clangd/unittests/TestTU.cpp | 14 +- clang-tools-extra/docs/ReleaseNotes.rst | 3 + 31 files changed, 1593 insertions(+), 40 deletions(-) create mode 100644 clang-tools-extra/clangd/ModuleDependencyScanner.cpp create mode 100644 clang-tools-extra/clangd/ModuleDependencyScanner.h create mode 100644 clang-tools-extra/clangd/ModulesBuilder.cpp create mode 100644 clang-tools-extra/clangd/ModulesBuilder.h create mode 100644 clang-tools-extra/clangd/PrerequisiteModules.h create mode 100644 clang-tools-extra/clangd/ProjectModules.cpp create mode 100644 clang-tools-extra/clangd/ProjectModules.h create mode 100644 clang-tools-extra/clangd/test/modules.test create mode 100644 clang-tools-extra/clangd/unittests/ModuleDependencyScannerTest.cpp create mode 100644 clang-tools-extra/clangd/unittests/ModulesTestSetup.h create mode 100644 clang-tools-extra/clangd/unittests/PrerequisiteModulesTest.cpp diff --git a/clang-tools-extra/clangd/CMakeLists.txt b/clang-tools-extra/clangd/CMakeLists.txt index 3911fb6c6c746a8..242a8ad2e350be7 100644 --- a/clang-tools-extra/clangd/CMakeLists.txt +++ b/clang-tools-extra/clangd/CMakeLists.txt @@ -97,7 +97,10 @@ add_clang_library(clangDaemon IncludeFixer.cpp InlayHints.cpp JSONTransport.cpp + ModuleDependencyScanner.cpp + ModulesBuilder.cpp PathMapping.cpp + ProjectModules.cpp Protocol.cpp Quality.cpp ParsedAST.cpp @@ -161,6 +164,7 @@ clang_target_link_libraries(clangDaemon clangAST clangASTMatchers clangBasic + clangDependencyScanning clangDriver clangFormat clangFrontend diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp index 13d788162817fb4..8ba4b38c420ab6a 100644 --- a/clang-tools-extra/clangd/ClangdServer.cpp +++ b/clang-tools-extra/clangd/ClangdServer.cpp @@ -202,6 +202,7 @@ ClangdServer::Options::operator TUScheduler::Options() const { Opts.UpdateDebounce = UpdateDebounce; Opts.ContextProvider = ContextProvider; Opts.PreambleThrottler = PreambleThrottler; + Opts.Experiment
[clang] [clang] Ignore GCC 11 `[[malloc(x)]]` attribute (PR #68059)
gustedt wrote: I see that the fix is almost ready, good. But generally it would also have helped if the `__has_c_attribute` feature test for this type of borrowed attributes would provide means to distinguish different versions. Here gcc as well as clang only have the value 1. So if the patch would also change the return value for clang to the year whenever the first version of gcc-11 with that feature was released, that would really be helpful. https://github.com/llvm/llvm-project/pull/68059 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [time-trace] Add a new time trace scope variable named "ParseDeclarationOrFunctionDefinition". (PR #65268)
https://github.com/MaggieYingYi updated https://github.com/llvm/llvm-project/pull/65268 >From 5b750383cace7db24144d16ce8a9ca0864c37613 Mon Sep 17 00:00:00 2001 From: Ying Yi Date: Fri, 1 Sep 2023 15:30:44 +0100 Subject: [PATCH] [Clang] Add two time-trace scope variables. A time trace scope variable of `ParseDeclarationOrFunctionDefinition` with the function's source location is added to record the time spent parsing the function's declaration or definition. Another time trace scope variable of `ParseFunctionDefinition` is also added to record the name of the defined function. A release note is added as well. Reviewed by: Aaron Ballman Pull request: #65268 --- clang/docs/ReleaseNotes.rst | 8 clang/lib/Parse/Parser.cpp| 14 +- ...e-ParseDeclarationOrFunctionDefinition.cpp | 15 +++ clang/unittests/Support/TimeProfilerTest.cpp | 44 +++ 4 files changed, 62 insertions(+), 19 deletions(-) create mode 100644 clang/test/Driver/check-time-trace-ParseDeclarationOrFunctionDefinition.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index bc28bb567f6932a..c151bd9d234b51e 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -427,6 +427,14 @@ Improvements to Clang's diagnostics (or, more commonly, ``NULL`` when the platform defines it as ``__null``) to be more consistent with GCC. +Improvements to Clang's time-trace +-- +- Two time-trace scope variables are added. A time trace scope variable of + ``ParseDeclarationOrFunctionDefinition`` with the function's source location + is added to record the time spent parsing the function's declaration or + definition. Another time trace scope variable of ``ParseFunctionDefinition`` + is also added to record the name of the defined function. + Bug Fixes in This Version - - Fixed an issue where a class template specialization whose declaration is diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp index 0f930248e77174b..bef3a0dcb285efd 100644 --- a/clang/lib/Parse/Parser.cpp +++ b/clang/lib/Parse/Parser.cpp @@ -13,8 +13,8 @@ #include "clang/Parse/Parser.h" #include "clang/AST/ASTConsumer.h" #include "clang/AST/ASTContext.h" -#include "clang/AST/DeclTemplate.h" #include "clang/AST/ASTLambda.h" +#include "clang/AST/DeclTemplate.h" #include "clang/Basic/FileManager.h" #include "clang/Parse/ParseDiagnostic.h" #include "clang/Parse/RAIIObjectsForParser.h" @@ -22,6 +22,7 @@ #include "clang/Sema/ParsedTemplate.h" #include "clang/Sema/Scope.h" #include "llvm/Support/Path.h" +#include "llvm/Support/TimeProfiler.h" using namespace clang; @@ -1229,6 +1230,13 @@ Parser::DeclGroupPtrTy Parser::ParseDeclOrFunctionDefInternal( Parser::DeclGroupPtrTy Parser::ParseDeclarationOrFunctionDefinition( ParsedAttributes &Attrs, ParsedAttributes &DeclSpecAttrs, ParsingDeclSpec *DS, AccessSpecifier AS) { + // Add an enclosing time trace scope for a bunch of small scopes with + // "EvaluateAsConstExpr". + llvm::TimeTraceScope TimeScope( + "ParseDeclarationOrFunctionDefinition", + Tok.getLocation().printToString( + Actions.getASTContext().getSourceManager())); + if (DS) { return ParseDeclOrFunctionDefInternal(Attrs, DeclSpecAttrs, *DS, AS); } else { @@ -1259,6 +1267,10 @@ Parser::DeclGroupPtrTy Parser::ParseDeclarationOrFunctionDefinition( Decl *Parser::ParseFunctionDefinition(ParsingDeclarator &D, const ParsedTemplateInfo &TemplateInfo, LateParsedAttrList *LateParsedAttrs) { + llvm::TimeTraceScope TimeScope( + "ParseFunctionDefinition", + Actions.GetNameForDeclarator(D).getName().getAsString()); + // Poison SEH identifiers so they are flagged as illegal in function bodies. PoisonSEHIdentifiersRAIIObject PoisonSEHIdentifiers(*this, true); const DeclaratorChunk::FunctionTypeInfo &FTI = D.getFunctionTypeInfo(); diff --git a/clang/test/Driver/check-time-trace-ParseDeclarationOrFunctionDefinition.cpp b/clang/test/Driver/check-time-trace-ParseDeclarationOrFunctionDefinition.cpp new file mode 100644 index 000..f854cddadbfcc1d --- /dev/null +++ b/clang/test/Driver/check-time-trace-ParseDeclarationOrFunctionDefinition.cpp @@ -0,0 +1,15 @@ +// RUN: %clangxx -S -ftime-trace -ftime-trace-granularity=0 -o %T/check-time-trace-ParseDeclarationOrFunctionDefinition %s +// RUN: cat %T/check-time-trace-ParseDeclarationOrFunctionDefinition.json \ +// RUN: | %python -c 'import json, sys; json.dump(json.loads(sys.stdin.read()), sys.stdout, sort_keys=True, indent=2)' \ +// RUN: | FileCheck %s + +// CHECK-DAG: "name": "ParseDeclarationOrFunctionDefinition" +// CHECK-DAG: "detail": "{{.*}}check-time-trace-ParseDeclarationOrFunctionDefinition.cpp:15:1" +// CHECK-DAG: "name": "ParseFunctionDefinition" +// CHECK-DAG: "detail": "foo" +// CHEC
[clang] 8d4e356 - [Clang][LoongArch] Support compiler options -mlsx/-mlasx for clang
Author: licongtian Date: 2023-10-31T15:52:05+08:00 New Revision: 8d4e35600f3ba90997a59fdb9baeb196e723eec9 URL: https://github.com/llvm/llvm-project/commit/8d4e35600f3ba90997a59fdb9baeb196e723eec9 DIFF: https://github.com/llvm/llvm-project/commit/8d4e35600f3ba90997a59fdb9baeb196e723eec9.diff LOG: [Clang][LoongArch] Support compiler options -mlsx/-mlasx for clang This patch adds compiler options -mlsx/-mlasx which enables the instruction sets of LSX and LASX, and sets related predefined macros according to the options. Added: clang/test/Driver/loongarch-mlasx-error.c clang/test/Driver/loongarch-mlasx.c clang/test/Driver/loongarch-mlsx-error.c clang/test/Driver/loongarch-mlsx.c Modified: clang/include/clang/Basic/DiagnosticDriverKinds.td clang/include/clang/Driver/Options.td clang/lib/Basic/Targets/LoongArch.cpp clang/lib/Basic/Targets/LoongArch.h clang/lib/Driver/ToolChains/Arch/LoongArch.cpp clang/test/Preprocessor/init-loongarch.c Removed: diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td index c0ccd64a2a7b82e..676f1a62b49dd0d 100644 --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td +++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -765,6 +765,12 @@ def warn_drv_loongarch_conflicting_implied_val : Warning< InGroup; def err_drv_loongarch_invalid_mfpu_EQ : Error< "invalid argument '%0' to -mfpu=; must be one of: 64, 32, none, 0 (alias for none)">; +def err_drv_loongarch_wrong_fpu_width_for_lsx : Error< + "wrong fpu width; LSX depends on 64-bit FPU.">; +def err_drv_loongarch_wrong_fpu_width_for_lasx : Error< + "wrong fpu width; LASX depends on 64-bit FPU.">; +def err_drv_loongarch_invalid_simd_option_combination : Error< + "invalid option combination; LASX depends on LSX.">; def err_drv_expand_response_file : Error< "failed to expand response file: %0">; diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 7f3f5125d42e7a9..c8b730e0f7ecd84 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -208,6 +208,8 @@ def m_riscv_Features_Group : OptionGroup<"">, Group, DocName<"RISC-V">; def m_ve_Features_Group : OptionGroup<"">, Group, DocName<"VE">; +def m_loongarch_Features_Group : OptionGroup<"">, + Group, DocName<"LoongArch">; def m_libc_Group : OptionGroup<"">, Group, Flags<[HelpHidden]>; @@ -4886,6 +4888,14 @@ def mstack_protector_guard_reg_EQ : Joined<["-"], "mstack-protector-guard-reg="> def mfentry : Flag<["-"], "mfentry">, HelpText<"Insert calls to fentry at function entry (x86/SystemZ only)">, Visibility<[ClangOption, CC1Option]>, Group, MarshallingInfoFlag>; +def mlsx : Flag<["-"], "mlsx">, Group, + HelpText<"Enable Loongson SIMD Extension (LSX).">; +def mno_lsx : Flag<["-"], "mno-lsx">, Group, + HelpText<"Disable Loongson SIMD Extension (LSX).">; +def mlasx : Flag<["-"], "mlasx">, Group, + HelpText<"Enable Loongson Advanced SIMD Extension (LASX).">; +def mno_lasx : Flag<["-"], "mno-lasx">, Group, + HelpText<"Disable Loongson Advanced SIMD Extension (LASX).">; def mnop_mcount : Flag<["-"], "mnop-mcount">, HelpText<"Generate mcount/__fentry__ calls as nops. To activate they need to be patched in.">, Visibility<[ClangOption, CC1Option]>, Group, MarshallingInfoFlag>; diff --git a/clang/lib/Basic/Targets/LoongArch.cpp b/clang/lib/Basic/Targets/LoongArch.cpp index 4448a2ae10a1725..88537989a05129f 100644 --- a/clang/lib/Basic/Targets/LoongArch.cpp +++ b/clang/lib/Basic/Targets/LoongArch.cpp @@ -208,6 +208,11 @@ void LoongArchTargetInfo::getTargetDefines(const LangOptions &Opts, TuneCPU = ArchName; Builder.defineMacro("__loongarch_tune", Twine('"') + TuneCPU + Twine('"')); + if (HasFeatureLSX) +Builder.defineMacro("__loongarch_sx", Twine(1)); + if (HasFeatureLASX) +Builder.defineMacro("__loongarch_asx", Twine(1)); + StringRef ABI = getABI(); if (ABI == "lp64d" || ABI == "lp64f" || ABI == "lp64s") Builder.defineMacro("__loongarch_lp64"); @@ -257,6 +262,8 @@ bool LoongArchTargetInfo::hasFeature(StringRef Feature) const { .Case("loongarch64", Is64Bit) .Case("32bit", !Is64Bit) .Case("64bit", Is64Bit) + .Case("lsx", HasFeatureLSX) + .Case("lasx", HasFeatureLASX) .Default(false); } @@ -274,7 +281,10 @@ bool LoongArchTargetInfo::handleTargetFeatures( if (Feature == "+d") { HasFeatureD = true; } -} +} else if (Feature == "+lsx") + HasFeatureLSX = true; +else if (Feature == "+lasx") + HasFeatureLASX = true; } return true; } diff --git a/clang/lib/Basic/Targets/LoongArch.h b/clang/lib/Basic/Targets/LoongArch.h index ba7fb78ab94cd23..
[clang] eb49b86 - [Clang][LoongArch] Add ABI implementation of passing vectors
Author: licongtian Date: 2023-10-31T15:52:05+08:00 New Revision: eb49b86f5a9b54b0e3c37024334a3c6f6ca88e14 URL: https://github.com/llvm/llvm-project/commit/eb49b86f5a9b54b0e3c37024334a3c6f6ca88e14 DIFF: https://github.com/llvm/llvm-project/commit/eb49b86f5a9b54b0e3c37024334a3c6f6ca88e14.diff LOG: [Clang][LoongArch] Add ABI implementation of passing vectors Added: Modified: clang/lib/CodeGen/Targets/LoongArch.cpp Removed: diff --git a/clang/lib/CodeGen/Targets/LoongArch.cpp b/clang/lib/CodeGen/Targets/LoongArch.cpp index 7483bf6d6d1e8e2..26c68c3583b2a19 100644 --- a/clang/lib/CodeGen/Targets/LoongArch.cpp +++ b/clang/lib/CodeGen/Targets/LoongArch.cpp @@ -321,6 +321,13 @@ ABIArgInfo LoongArchABIInfo::classifyArgumentType(QualType Ty, bool IsFixed, return ABIArgInfo::getDirect(); } + // Pass 128-bit/256-bit vector values via vector registers directly. + if (Ty->isVectorType() && (((getContext().getTypeSize(Ty) == 128) && + (getTarget().hasFeature("lsx"))) || + ((getContext().getTypeSize(Ty) == 256) && + getTarget().hasFeature("lasx" +return ABIArgInfo::getDirect(); + // Complex types for the *f or *d ABI must be passed directly rather than // using CoerceAndExpand. if (IsFixed && Ty->isComplexType() && FRLen && FARsLeft >= 2) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)
ChuanqiXu9 wrote: @sam-mccall Thanks for you high quality comments! I think all the comments (except few ones I explained in inline comments) should be addressed in the latest force-push commit. I didn't click the `Resolve Conversation` button since there is a discussion for it: https://discourse.llvm.org/t/rfc-github-pr-resolve-conversation-button/73178/42. The "significant" changes in the latest commit are mainly interface changes. They include: - Introduced a `ModulesBuilder` class. The class is responsible for building module files. Currently it follows the original style to build module files seperetely for every different source files. As we discussed, `ModulesBuilder` class can be used to reuse the module files across different source files. - Split `buildPrerequisiteModulesFor` from `PrerequisiteModules` to `ModulesBuilder` class. Now `PrerequisiteModules` are simply collection of module files. And it has two duties: - Check if all the module files are still up-to-date (or valid) - Adjust the header search options to make it to try search for the module files built by us first. - Split the original `PrerequisiteModules` to a pure virtual class and move the implementations to `ModulesBuilder.cpp`. - `ScanningAllProjectModules` are removed from the header files. - The suggested ModuleFile class are introduced as a private class to `StandalonePrerequisiteModules`. I think it is good now since all the module files are owned by `StandalonePrerequisiteModules` and they are private to others. I can image, in the end of the day, we need to have a "public" ModuleFile class which are owned by `ModulesBuilder` to make it to be shared with other source files. And derived class from `PrerequisiteModules` will only have references to some module files. But I didn't move on. I feel they should be part of the later patches. https://github.com/llvm/llvm-project/pull/66462 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang-tools-extra] [clang] [llvm-objcopy] Add --gap-fill and --pad-to options (PR #65815)
@@ -2636,30 +2636,30 @@ template Error ELFWriter::finalize() { } Error BinaryWriter::write() { - SmallVector LoadableSections; + SmallVector BitsSections; jh7370 wrote: Without knowing the code around it, I wouldn't know what `BitsSections` means. How about `SectionsToWrite`? https://github.com/llvm/llvm-project/pull/65815 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang] [llvm] [llvm-objcopy] Add --gap-fill and --pad-to options (PR #65815)
@@ -163,8 +163,8 @@ Sections: EntSize: 0x0001 Content: 4743433A -## In this test, output sections are defined out of in respect to their load -## addresses. Verify that gaps are still correctly filled. +## In this test, output sections are defined out of order in respect to their jh7370 wrote: ```suggestion ## In this test, output sections are defined out of order with respect to their ``` Nit: the phrase is "with respect to". https://github.com/llvm/llvm-project/pull/65815 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang-tools-extra] [llvm-objcopy] Add --gap-fill and --pad-to options (PR #65815)
@@ -67,12 +67,18 @@ using namespace llvm::object; // The name this program was invoked as. static StringRef ToolName; -static ErrorSuccess reportWarning(Error E) { +namespace llvm { +namespace objcopy { + +ErrorSuccess reportWarning(Error E) { jh7370 wrote: Please follow the guideline described here: https://llvm.org/docs/CodingStandards.html#use-namespace-qualifiers-to-implement-previously-declared-functions https://github.com/llvm/llvm-project/pull/65815 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang-tools-extra] [clang] [llvm-objcopy] Add --gap-fill and --pad-to options (PR #65815)
https://github.com/jh7370 commented: Basically looks good. Just some minor nits now. https://github.com/llvm/llvm-project/pull/65815 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [llvm] [llvm-objcopy] Add --gap-fill and --pad-to options (PR #65815)
https://github.com/jh7370 edited https://github.com/llvm/llvm-project/pull/65815 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer][NFC] Add more tests of 'StreamChecker' about 'tmpfile' (PR #70540)
balazske wrote: I would like to have the new test in `stream.c` (not `stream.cpp`) because the C++ test file contains only C++ related StreamChecker tests (`tmpfile` belongs not here). And a "FIXME" could be added to the test to indicate that this is a faulty behavior (in the current case). The test and code change can be in a single PR, this is a bugfix and addition of a related test, these are done usually together. https://github.com/llvm/llvm-project/pull/70540 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [llvm] [Clang][LoongArch] Support builtin functions for LSX and LASX (PR #69313)
https://github.com/SixWeining closed https://github.com/llvm/llvm-project/pull/69313 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [clang-tools-extra] [Clang][LoongArch] Support builtin functions for LSX and LASX (PR #69313)
SixWeining wrote: To keep original 6 commits I have manually merged into trunk. Now close this PR. https://github.com/llvm/llvm-project/pull/69313 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Perf/lexer faster slow get char and size (PR #70543)
serge-sans-paille wrote: recommited as 8116b6dce70ef284f9a0895b0f9f45bfa9a3ade7 https://github.com/llvm/llvm-project/pull/70543 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[compiler-rt] [libcxx] [llvm] [lldb] [flang] [clang] [clang-tools-extra] [libc] [PowerPC] Support mcmodel=large for AIX (PR #70652)
@@ -5723,16 +5723,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, if (Arg *A = Args.getLastArg(options::OPT_mcmodel_EQ)) { StringRef CM = A->getValue(); bool Ok = false; -if (Triple.isOSAIX() && CM == "medium") { +if (Triple.isOSAIX() && CM == "medium") CM = "large"; - Ok = true; -} if (Triple.isAArch64(64)) { Ok = CM == "tiny" || CM == "small" || CM == "large"; if (CM == "large" && RelocationModel != llvm::Reloc::Static) D.Diag(diag::err_drv_argument_only_allowed_with) << A->getAsString(Args) << "-fno-pic"; -} else if (Triple.isPPC64()) { +} else if (Triple.isPPC64() || Triple.isOSAIX()) { chenzheng1030 wrote: AIX seems good now. However I think we still have one active ppc32 target like SPE working on PPC. So now clang can not accept any code model for target `-target powerpcspe`. >From simple testing, this target supports all these three models. https://github.com/llvm/llvm-project/pull/70652 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-scan-deps] [P1689] Keep consistent behavior for make dependencies with clang (PR #69551)
https://github.com/ChuanqiXu9 updated https://github.com/llvm/llvm-project/pull/69551 >From 6ee8058b3ce5c8c64fd21109407f8a081dc64df5 Mon Sep 17 00:00:00 2001 From: Chuanqi Xu Date: Mon, 30 Oct 2023 11:51:04 +0800 Subject: [PATCH] [clang-scan-deps] [P1689] Keep consistent behavior for make dependencies with clang Close #69439. This patch tries to reuse the codes to generate make style dependencies information with P1689 format directly. --- .../DependencyScanning/ModuleDepCollector.cpp| 12 clang/test/ClangScanDeps/P1689.cppm | 10 ++ 2 files changed, 22 insertions(+) diff --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp index 40115b7b5ae25b3..930d07e182087e9 100644 --- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp +++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp @@ -666,12 +666,24 @@ static StringRef makeAbsoluteAndPreferred(CompilerInstance &CI, StringRef Path, } void ModuleDepCollector::addFileDep(StringRef Path) { + if (IsStdModuleP1689Format) { +// Within P1689 format, we don't want all the paths to be absolute path +// since it may violate the tranditional make style dependencies info. +FileDeps.push_back(std::string(Path)); +return; + } + llvm::SmallString<256> Storage; Path = makeAbsoluteAndPreferred(ScanInstance, Path, Storage); FileDeps.push_back(std::string(Path)); } void ModuleDepCollector::addFileDep(ModuleDeps &MD, StringRef Path) { + if (IsStdModuleP1689Format) { +MD.FileDeps.insert(Path); +return; + } + llvm::SmallString<256> Storage; Path = makeAbsoluteAndPreferred(ScanInstance, Path, Storage); MD.FileDeps.insert(Path); diff --git a/clang/test/ClangScanDeps/P1689.cppm b/clang/test/ClangScanDeps/P1689.cppm index dffb16974a3e4e4..24632e25cf7f3bd 100644 --- a/clang/test/ClangScanDeps/P1689.cppm +++ b/clang/test/ClangScanDeps/P1689.cppm @@ -42,6 +42,14 @@ // RUN: clang-scan-deps -format=p1689 \ // RUN: -- %clang++ -std=c++20 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -c %t/impl_part.cppm -o %t/impl_part.o \ // RUN: | FileCheck %t/impl_part.cppm -DPREFIX=%/t +// +// Check the path in the make style dependencies are generated in relative path form +// RUN: cd %t +// RUN: clang-scan-deps -format=p1689 \ +// RUN: -- %clang++ -std=c++20 -c -fprebuilt-module-path=%t impl_part.cppm -o impl_part.o \ +// RUN: -MT impl_part.o.ddi -MD -MF impl_part.dep +// RUN: cat impl_part.dep | FileCheck impl_part.cppm -DPREFIX=%/t --check-prefix=CHECK-MAKE-RELATIVE + //--- P1689.json.in [ @@ -168,6 +176,8 @@ void World() { // CHECK-MAKE: [[PREFIX]]/impl_part.cppm // CHECK-MAKE: [[PREFIX]]/header.mock +// CHECK-MAKE-RELATIVE: impl_part.o.ddi: impl_part.cppm header.mock + //--- interface_part.cppm export module M:interface_part; export void World(); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-scan-deps] [P1689] Keep consistent behavior for make dependencies with clang (PR #69551)
@@ -666,13 +666,19 @@ static StringRef makeAbsoluteAndPreferred(CompilerInstance &CI, StringRef Path, } void ModuleDepCollector::addFileDep(StringRef Path) { - llvm::SmallString<256> Storage; - Path = makeAbsoluteAndPreferred(ScanInstance, Path, Storage); + // Within P1689 format, we don't want all the paths to be absolute path + // since it may violate the tranditional make style dependencies info. + if (!IsStdModuleP1689Format) { +llvm::SmallString<256> Storage; +Path = makeAbsoluteAndPreferred(ScanInstance, Path, Storage); + } FileDeps.push_back(std::string(Path)); ChuanqiXu9 wrote: Done. Thanks for your catch! https://github.com/llvm/llvm-project/pull/69551 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC] [Serializer] Pack information in serializer (PR #69287)
@@ -2407,6 +2407,53 @@ class ASTReader bool isProcessingUpdateRecords() { return ProcessingUpdateRecords; } }; +/// A simple helper class to unpack an integer to bits and consuming +/// the bits in order. +class BitsUnpacker { + constexpr static uint32_t BitsIndexUpbound = 32; + +public: + BitsUnpacker(uint32_t V) { updateValue(V); } + BitsUnpacker(const BitsUnpacker &) = delete; + BitsUnpacker(BitsUnpacker &&) = delete; + BitsUnpacker operator=(const BitsUnpacker &) = delete; + BitsUnpacker operator=(BitsUnpacker &&) = delete; + ~BitsUnpacker() { +#ifndef NDEBUG +while (isValid()) + assert(!getNextBit() && "There are bits failed to read!"); ChuanqiXu9 wrote: Done https://github.com/llvm/llvm-project/pull/69287 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC] [Serializer] Pack information in serializer (PR #69287)
@@ -2407,6 +2407,53 @@ class ASTReader bool isProcessingUpdateRecords() { return ProcessingUpdateRecords; } }; +/// A simple helper class to unpack an integer to bits and consuming +/// the bits in order. +class BitsUnpacker { + constexpr static uint32_t BitsIndexUpbound = 32; + +public: + BitsUnpacker(uint32_t V) { updateValue(V); } + BitsUnpacker(const BitsUnpacker &) = delete; + BitsUnpacker(BitsUnpacker &&) = delete; + BitsUnpacker operator=(const BitsUnpacker &) = delete; + BitsUnpacker operator=(BitsUnpacker &&) = delete; + ~BitsUnpacker() { +#ifndef NDEBUG +while (isValid()) + assert(!getNextBit() && "There are bits failed to read!"); +#endif + } + + void updateValue(uint32_t V) { +Value = V; +CurrentBitsIndex = 0; + } + + bool getNextBit() { +assert(isValid()); +return Value & (1 << CurrentBitsIndex++); + } + + uint32_t getNextBits(uint32_t Width) { +assert(isValid()); +assert(Width < BitsIndexUpbound); +uint32_t Ret = (Value >> CurrentBitsIndex) & ((1 << Width) - 1); +CurrentBitsIndex += Width; +return Ret; + } + + bool isValidToGetNextNBits(uint32_t Width) const { ChuanqiXu9 wrote: Done https://github.com/llvm/llvm-project/pull/69287 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC] [Serializer] Pack information in serializer (PR #69287)
@@ -1689,9 +1709,10 @@ void ASTDeclReader::VisitParmVarDecl(ParmVarDecl *PD) { } else { PD->setScopeInfo(scopeDepth, scopeIndex); } - PD->ParmVarDeclBits.IsKNRPromoted = Record.readInt(); - PD->ParmVarDeclBits.HasInheritedDefaultArg = Record.readInt(); - if (Record.readInt()) // hasUninstantiatedDefaultArg. + PD->ParmVarDeclBits.IsKNRPromoted = ParmVarDeclBits.getNextBit(); + ; ChuanqiXu9 wrote: Done https://github.com/llvm/llvm-project/pull/69287 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC] [Serializer] Pack information in serializer (PR #69287)
https://github.com/ChuanqiXu9 updated https://github.com/llvm/llvm-project/pull/69287 >From ae4ee482f5b6b5d2487ed642b92e513ffd269781 Mon Sep 17 00:00:00 2001 From: Chuanqi Xu Date: Mon, 16 Oct 2023 16:41:31 +0800 Subject: [PATCH 1/2] [Serializer] Pack bits into integers Previously, the boolean values will occupy spaces that can contain integers. It wastes the spaces especially if the boolean values are serialized consecutively. The patch tries to pack such consecutive boolean values (and enum values) so that we can save more spaces and so the times. Before the patch, we need 4.478s (in my machine) to build the std module (https://libcxx.llvm.org/Modules.html) with 28712 bytes. After the patch, the time becomes to 4.374s and the size becomes to 27568 bytes. This is intended to be a NFC patch. This patch doesn't optimize all such cases. We can do it later after we have consensus on this. fmt --- clang/include/clang/AST/Decl.h| 2 +- clang/include/clang/AST/DeclBase.h| 2 +- clang/include/clang/Serialization/ASTReader.h | 47 +++ clang/include/clang/Serialization/ASTWriter.h | 53 +++ clang/lib/Serialization/ASTReaderDecl.cpp | 230 ++- clang/lib/Serialization/ASTWriter.cpp | 32 +- clang/lib/Serialization/ASTWriterDecl.cpp | 381 +++--- clang/test/Modules/decl-params-determinisim.m | 16 +- 8 files changed, 405 insertions(+), 358 deletions(-) diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h index 7f076cc77ea82cb..cd9a830dbaaf426 100644 --- a/clang/include/clang/AST/Decl.h +++ b/clang/include/clang/AST/Decl.h @@ -4073,7 +4073,7 @@ class RecordDecl : public TagDecl { /// returned from function calls. This takes into account the target-specific /// and version-specific rules along with the rules determined by the /// language. - enum ArgPassingKind : unsigned { + enum ArgPassingKind : unsigned char { /// The argument of this type can be passed directly in registers. APK_CanPassInRegs, diff --git a/clang/include/clang/AST/DeclBase.h b/clang/include/clang/AST/DeclBase.h index d383e46e22e16f4..7a30529f1f73d74 100644 --- a/clang/include/clang/AST/DeclBase.h +++ b/clang/include/clang/AST/DeclBase.h @@ -211,7 +211,7 @@ class alignas(8) Decl { /// The kind of ownership a declaration has, for visibility purposes. /// This enumeration is designed such that higher values represent higher /// levels of name hiding. - enum class ModuleOwnershipKind : unsigned { + enum class ModuleOwnershipKind : unsigned char { /// This declaration is not owned by a module. Unowned, diff --git a/clang/include/clang/Serialization/ASTReader.h b/clang/include/clang/Serialization/ASTReader.h index 531ad94f0906ac0..f54ebe2913786c9 100644 --- a/clang/include/clang/Serialization/ASTReader.h +++ b/clang/include/clang/Serialization/ASTReader.h @@ -2407,6 +2407,53 @@ class ASTReader bool isProcessingUpdateRecords() { return ProcessingUpdateRecords; } }; +/// A simple helper class to unpack an integer to bits and consuming +/// the bits in order. +class BitsUnpacker { + constexpr static uint32_t BitsIndexUpbound = 32; + +public: + BitsUnpacker(uint32_t V) { updateValue(V); } + BitsUnpacker(const BitsUnpacker &) = delete; + BitsUnpacker(BitsUnpacker &&) = delete; + BitsUnpacker operator=(const BitsUnpacker &) = delete; + BitsUnpacker operator=(BitsUnpacker &&) = delete; + ~BitsUnpacker() { +#ifndef NDEBUG +while (isValid()) + assert(!getNextBit() && "There are bits failed to read!"); +#endif + } + + void updateValue(uint32_t V) { +Value = V; +CurrentBitsIndex = 0; + } + + bool getNextBit() { +assert(isValid()); +return Value & (1 << CurrentBitsIndex++); + } + + uint32_t getNextBits(uint32_t Width) { +assert(isValid()); +assert(Width < BitsIndexUpbound); +uint32_t Ret = (Value >> CurrentBitsIndex) & ((1 << Width) - 1); +CurrentBitsIndex += Width; +return Ret; + } + + bool isValidToGetNextNBits(uint32_t Width) const { +return CurrentBitsIndex + Width < BitsIndexUpbound; + } + +private: + bool isValid() const { return CurrentBitsIndex < BitsIndexUpbound; } + + uint32_t Value; + uint32_t CurrentBitsIndex = ~0; +}; + } // namespace clang #endif // LLVM_CLANG_SERIALIZATION_ASTREADER_H diff --git a/clang/include/clang/Serialization/ASTWriter.h b/clang/include/clang/Serialization/ASTWriter.h index 98445d40ebd82c3..96e218149dd4d17 100644 --- a/clang/include/clang/Serialization/ASTWriter.h +++ b/clang/include/clang/Serialization/ASTWriter.h @@ -830,6 +830,59 @@ class PCHGenerator : public SemaConsumer { bool hasEmittedPCH() const { return Buffer->IsComplete; } }; +/// A simple helper class to pack several bits in order into (a) 32 bit +/// integer(s). +class BitsPacker { + constexpr static uint32_t BitIndexUpbound = 32u; + +public: + BitsPacker() = default; + BitsPacker(const BitsPacker &) = delete; + BitsPacker(BitsP
[clang] [Clang][RISCV] Add vcreate intrinsics for RVV non-tuple types (PR #70355)
https://github.com/yetingk approved this pull request. LGTM. https://github.com/llvm/llvm-project/pull/70355 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][DebugInfo][NFC] Add createConstantValueExpression helper (PR #70674)
https://github.com/Michael137 updated https://github.com/llvm/llvm-project/pull/70674 >From 82795f2e8b06c8ae866c2f58e463d21958105108 Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Fri, 27 Oct 2023 16:33:07 +0100 Subject: [PATCH 1/3] [clang][DebugInfo][NFC] Add createConstantValueExpression helper This patch factors out the code to create a DIExpression from an APValue into a separate helper function. This will be useful in a follow-up patch where we re-use this logic elsewhere. --- clang/lib/CodeGen/CGDebugInfo.cpp | 44 ++- clang/lib/CodeGen/CGDebugInfo.h | 5 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 0aaf678bf287c6e..9de55e41f885d26 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -5580,25 +5580,8 @@ void CGDebugInfo::EmitGlobalVariable(const ValueDecl *VD, const APValue &Init) { auto &GV = DeclCache[VD]; if (GV) return; - llvm::DIExpression *InitExpr = nullptr; - if (CGM.getContext().getTypeSize(VD->getType()) <= 64) { -// FIXME: Add a representation for integer constants wider than 64 bits. -if (Init.isInt()) { - const llvm::APSInt &InitInt = Init.getInt(); - std::optional InitIntOpt; - if (InitInt.isUnsigned()) -InitIntOpt = InitInt.tryZExtValue(); - else if (auto tmp = InitInt.trySExtValue(); tmp.has_value()) -// Transform a signed optional to unsigned optional. When cpp 23 comes, -// use std::optional::transform -InitIntOpt = (uint64_t)tmp.value(); - if (InitIntOpt) -InitExpr = DBuilder.createConstantValueExpression(InitIntOpt.value()); -} else if (Init.isFloat()) - InitExpr = DBuilder.createConstantValueExpression( - Init.getFloat().bitcastToAPInt().getZExtValue()); - } + llvm::DIExpression *InitExpr = createConstantValueExpression(VD, Init); llvm::MDTuple *TemplateParameters = nullptr; if (isa(VD)) @@ -5935,3 +5918,28 @@ llvm::DINode::DIFlags CGDebugInfo::getCallSiteRelatedAttrs() const { return llvm::DINode::FlagAllCallsDescribed; } + +llvm::DIExpression * +CGDebugInfo::createConstantValueExpression(clang::ValueDecl const *VD, + const APValue &Val) { + llvm::DIExpression *ValExpr = nullptr; + if (CGM.getContext().getTypeSize(VD->getType()) <= 64) { +// FIXME: Add a representation for integer constants wider than 64 bits. +if (Val.isInt()) { + const llvm::APSInt &ValInt = Val.getInt(); + std::optional ValIntOpt; + if (ValInt.isUnsigned()) +ValIntOpt = ValInt.tryZExtValue(); + else if (auto tmp = ValInt.trySExtValue(); tmp.has_value()) +// Transform a signed optional to unsigned optional. When cpp 23 comes, +// use std::optional::transform +ValIntOpt = (uint64_t)tmp.value(); + if (ValIntOpt) +ValExpr = DBuilder.createConstantValueExpression(ValIntOpt.value()); +} else if (Val.isFloat()) + ValExpr = DBuilder.createConstantValueExpression( + Val.getFloat().bitcastToAPInt().getZExtValue()); + } + + return ValExpr; +} diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h index ae12485850ca775..7b60e94555d0608 100644 --- a/clang/lib/CodeGen/CGDebugInfo.h +++ b/clang/lib/CodeGen/CGDebugInfo.h @@ -800,6 +800,11 @@ class CGDebugInfo { llvm::MDTuple *&TemplateParameters, llvm::DIScope *&VDContext); + /// Create a DIExpression representing the constant corresponding + /// to the specified 'Val'. Returns nullptr on failure. + llvm::DIExpression *createConstantValueExpression(const clang::ValueDecl *VD, +const APValue &Val); + /// Allocate a copy of \p A using the DebugInfoNames allocator /// and return a reference to it. If multiple arguments are given the strings /// are concatenated. >From 96a433349a0db8c096bb8a7aeeaccd914392e592 Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Mon, 30 Oct 2023 17:57:01 + Subject: [PATCH 2/3] fixup! refactor function to use llvm code-style --- clang/lib/CodeGen/CGDebugInfo.cpp | 43 --- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 9de55e41f885d26..76ce1572cdfc69c 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -5920,26 +5920,27 @@ llvm::DINode::DIFlags CGDebugInfo::getCallSiteRelatedAttrs() const { } llvm::DIExpression * -CGDebugInfo::createConstantValueExpression(clang::ValueDecl const *VD, +CGDebugInfo::createConstantValueExpression(const clang::ValueDecl *VD, const APValue &Val) { - llvm::DIExpression *ValExpr = nullptr; - if (CGM.getContext().getTypeSize(VD->getTy
[flang] [clang-tools-extra] [compiler-rt] [libc] [llvm] [lldb] [clang] [libcxx] [PowerPC] Support mcmodel=large for AIX (PR #70652)
@@ -5723,16 +5723,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, if (Arg *A = Args.getLastArg(options::OPT_mcmodel_EQ)) { StringRef CM = A->getValue(); bool Ok = false; -if (Triple.isOSAIX() && CM == "medium") { +if (Triple.isOSAIX() && CM == "medium") CM = "large"; - Ok = true; -} if (Triple.isAArch64(64)) { Ok = CM == "tiny" || CM == "small" || CM == "large"; if (CM == "large" && RelocationModel != llvm::Reloc::Static) D.Diag(diag::err_drv_argument_only_allowed_with) << A->getAsString(Args) << "-fno-pic"; -} else if (Triple.isPPC64()) { +} else if (Triple.isPPC64() || Triple.isOSAIX()) { ecnelises wrote: CC @chmeeedalf https://github.com/llvm/llvm-project/pull/70652 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer][NFC] Add more tests of 'StreamChecker' about 'tmpfile' (PR #70540)
https://github.com/steakhal approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/70540 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer][NFC] Add more tests of 'StreamChecker' about 'tmpfile' (PR #70540)
benshi001 wrote: > I would like to have the new test in `stream.c` (not `stream.cpp`) because > the C++ test file contains only C++ related StreamChecker tests (`tmpfile` > belongs not here). And a "FIXME" could be added to the test to indicate that > this is a faulty behavior (in the current case). The test and code change can > be in a single PR, this is a bugfix and addition of a related test, these are > done usually together. Unfortunately I can not add `extern FILE *tmpfile(char *)` in `stream.c`, since pure C program does not support function overload. So I add it to `stream.cpp`. https://github.com/llvm/llvm-project/pull/70540 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [SystemZ][z/OS] This change adds support for the PPA2 section in zOS (PR #68926)
https://github.com/uweigand edited https://github.com/llvm/llvm-project/pull/68926 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [SystemZ][z/OS] This change adds support for the PPA2 section in zOS (PR #68926)
https://github.com/uweigand requested changes to this pull request. https://github.com/llvm/llvm-project/pull/68926 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [SystemZ][z/OS] This change adds support for the PPA2 section in zOS (PR #68926)
@@ -976,6 +976,40 @@ void CodeGenModule::Release() { Context.getTypeSizeInChars(Context.getWideCharType()).getQuantity(); getModule().addModuleFlag(llvm::Module::Error, "wchar_size", WCharWidth); + if (getTriple().isOSzOS()) { +getModule().addModuleFlag(llvm::Module::Warning, "Product Major Version", + uint32_t(CLANG_VERSION_MAJOR)); +getModule().addModuleFlag(llvm::Module::Warning, "Product Minor Version", + uint32_t(CLANG_VERSION_MINOR)); +getModule().addModuleFlag(llvm::Module::Warning, "Product Patchlevel", + uint32_t(CLANG_VERSION_PATCHLEVEL)); + +// Record the language because we need it for the PPA2. +StringRef lang_str = languageToString( +LangStandard::getLangStandardForKind(LangOpts.LangStd).Language); +getModule().addModuleFlag(llvm::Module::Error, "zos_cu_language", + llvm::MDString::get(VMContext, lang_str)); + +std::string ProductId; +#ifdef CLANG_VENDOR +ProductId = #CLANG_VENDOR; +#else +ProductId = "clang"; +#endif + +getModule().addModuleFlag(llvm::Module::Error, "Product Id", + llvm::MDString::get(VMContext, ProductId)); + +getModule().addModuleFlag(llvm::Module::Error, "TranslationTime", uweigand wrote: I don't think `Error` is the correct setting for this. That would prevent LTO unless modules were built at the exact same time. Rather, I think this should be `Max` here. https://github.com/llvm/llvm-project/pull/68926 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [SystemZ][z/OS] This change adds support for the PPA2 section in zOS (PR #68926)
@@ -90,6 +90,7 @@ LANGOPT(C23 , 1, 0, "C23") LANGOPT(MSVCCompat, 1, 0, "Microsoft Visual C++ full compatibility mode") LANGOPT(Kernel, 1, 0, "Kernel mode") LANGOPT(MicrosoftExt , 1, 0, "Microsoft C++ extensions") +LANGOPT(ASCIICharMode , 1, 1, "z/OS Language Environment Character mode") uweigand wrote: This doesn't appear to do anything except for setting the PPA flag. Is this correct? If the implementation is simply incomplete / not present yet, I don't think we should add this flag now - rather, we should have the PPA flag reflect the default and update this once full support for ASCII mode is merged. https://github.com/llvm/llvm-project/pull/68926 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [SystemZ][z/OS] This change adds support for the PPA2 section in zOS (PR #68926)
@@ -976,6 +976,40 @@ void CodeGenModule::Release() { Context.getTypeSizeInChars(Context.getWideCharType()).getQuantity(); getModule().addModuleFlag(llvm::Module::Error, "wchar_size", WCharWidth); + if (getTriple().isOSzOS()) { +getModule().addModuleFlag(llvm::Module::Warning, "Product Major Version", + uint32_t(CLANG_VERSION_MAJOR)); +getModule().addModuleFlag(llvm::Module::Warning, "Product Minor Version", + uint32_t(CLANG_VERSION_MINOR)); +getModule().addModuleFlag(llvm::Module::Warning, "Product Patchlevel", + uint32_t(CLANG_VERSION_PATCHLEVEL)); + +// Record the language because we need it for the PPA2. +StringRef lang_str = languageToString( +LangStandard::getLangStandardForKind(LangOpts.LangStd).Language); +getModule().addModuleFlag(llvm::Module::Error, "zos_cu_language", + llvm::MDString::get(VMContext, lang_str)); + +std::string ProductId; +#ifdef CLANG_VENDOR +ProductId = #CLANG_VENDOR; +#else +ProductId = "clang"; +#endif + +getModule().addModuleFlag(llvm::Module::Error, "Product Id", + llvm::MDString::get(VMContext, ProductId)); uweigand wrote: Same comment as above about the name space. Also, please move this up next to the other product-related flags. https://github.com/llvm/llvm-project/pull/68926 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [SystemZ][z/OS] This change adds support for the PPA2 section in zOS (PR #68926)
@@ -1765,7 +1765,7 @@ void Clang::RenderTargetOptions(const llvm::Triple &EffectiveTriple, break; case llvm::Triple::systemz: -AddSystemZTargetArgs(Args, CmdArgs); +AddSystemZTargetArgs(EffectiveTriple, Args, CmdArgs); uweigand wrote: This (and the related) changes are no longer needed now. https://github.com/llvm/llvm-project/pull/68926 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [SystemZ][z/OS] This change adds support for the PPA2 section in zOS (PR #68926)
@@ -976,6 +976,40 @@ void CodeGenModule::Release() { Context.getTypeSizeInChars(Context.getWideCharType()).getQuantity(); getModule().addModuleFlag(llvm::Module::Error, "wchar_size", WCharWidth); + if (getTriple().isOSzOS()) { +getModule().addModuleFlag(llvm::Module::Warning, "Product Major Version", + uint32_t(CLANG_VERSION_MAJOR)); +getModule().addModuleFlag(llvm::Module::Warning, "Product Minor Version", + uint32_t(CLANG_VERSION_MINOR)); +getModule().addModuleFlag(llvm::Module::Warning, "Product Patchlevel", + uint32_t(CLANG_VERSION_PATCHLEVEL)); uweigand wrote: I think I commented on that previously: these flags are set only on z/OS, but have rather generic names. If they're z/OS specific, I think they should have names in the "zos_..." name space like the others. https://github.com/llvm/llvm-project/pull/68926 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] bbd61d8 - [clang][dataflow][NFC] Move `parseAll()` to TestingSupport and rename `parseFormulas()` (#70437)
Author: martinboehme Date: 2023-10-31T10:04:30+01:00 New Revision: bbd61d807f86e0b043976eb39a1b0ad13f306a9c URL: https://github.com/llvm/llvm-project/commit/bbd61d807f86e0b043976eb39a1b0ad13f306a9c DIFF: https://github.com/llvm/llvm-project/commit/bbd61d807f86e0b043976eb39a1b0ad13f306a9c.diff LOG: [clang][dataflow][NFC] Move `parseAll()` to TestingSupport and rename `parseFormulas()` (#70437) I'm working on a patch that will use this function from a different test. Added: Modified: clang/unittests/Analysis/FlowSensitive/SolverTest.cpp clang/unittests/Analysis/FlowSensitive/TestingSupport.cpp clang/unittests/Analysis/FlowSensitive/TestingSupport.h Removed: diff --git a/clang/unittests/Analysis/FlowSensitive/SolverTest.cpp b/clang/unittests/Analysis/FlowSensitive/SolverTest.cpp index a61e692088a8717..71f6da93594e30e 100644 --- a/clang/unittests/Analysis/FlowSensitive/SolverTest.cpp +++ b/clang/unittests/Analysis/FlowSensitive/SolverTest.cpp @@ -25,6 +25,7 @@ using namespace clang; using namespace dataflow; using test::ConstraintContext; +using test::parseFormulas; using testing::_; using testing::AnyOf; using testing::Pair; @@ -33,21 +34,6 @@ using testing::UnorderedElementsAre; constexpr auto AssignedTrue = Solver::Result::Assignment::AssignedTrue; constexpr auto AssignedFalse = Solver::Result::Assignment::AssignedFalse; -std::vector parseAll(Arena &A, StringRef Lines) { - std::vector Result; - while (!Lines.empty()) { -auto [First, Rest] = Lines.split('\n'); -Lines = Rest; -if (First.trim().empty()) - continue; -if (auto F = A.parseFormula(First)) - Result.push_back(&*F); -else - ADD_FAILURE() << llvm::toString(F.takeError()); - } - return Result; -} - // Checks if the conjunction of `Vals` is satisfiable and returns the // corresponding result. Solver::Result solve(llvm::ArrayRef Vals) { @@ -277,7 +263,7 @@ TEST(SolverTest, IffWithUnits) { TEST(SolverTest, IffWithUnitsConflict) { Arena A; - auto Constraints = parseAll(A, R"( + auto Constraints = parseFormulas(A, R"( (V0 = V1) V0 !V1 @@ -287,7 +273,7 @@ TEST(SolverTest, IffWithUnitsConflict) { TEST(SolverTest, IffTransitiveConflict) { Arena A; - auto Constraints = parseAll(A, R"( + auto Constraints = parseFormulas(A, R"( (V0 = V1) (V1 = V2) V2 @@ -298,7 +284,7 @@ TEST(SolverTest, IffTransitiveConflict) { TEST(SolverTest, DeMorgan) { Arena A; - auto Constraints = parseAll(A, R"( + auto Constraints = parseFormulas(A, R"( (!(V0 | V1) = (!V0 & !V1)) (!(V2 & V3) = (!V2 | !V3)) )"); @@ -307,7 +293,7 @@ TEST(SolverTest, DeMorgan) { TEST(SolverTest, RespectsAdditionalConstraints) { Arena A; - auto Constraints = parseAll(A, R"( + auto Constraints = parseFormulas(A, R"( (V0 = V1) V0 !V1 @@ -317,7 +303,7 @@ TEST(SolverTest, RespectsAdditionalConstraints) { TEST(SolverTest, ImplicationIsEquivalentToDNF) { Arena A; - auto Constraints = parseAll(A, R"( + auto Constraints = parseFormulas(A, R"( !((V0 => V1) = (!V0 | V1)) )"); EXPECT_THAT(solve(Constraints), unsat()); @@ -325,7 +311,7 @@ TEST(SolverTest, ImplicationIsEquivalentToDNF) { TEST(SolverTest, ImplicationConflict) { Arena A; - auto Constraints = parseAll(A, R"( + auto Constraints = parseFormulas(A, R"( (V0 => V1) (V0 & !V1) )"); @@ -334,7 +320,7 @@ TEST(SolverTest, ImplicationConflict) { TEST(SolverTest, ReachedLimitsReflectsTimeouts) { Arena A; - auto Constraints = parseAll(A, R"( + auto Constraints = parseFormulas(A, R"( (!(V0 | V1) = (!V0 & !V1)) (!(V2 & V3) = (!V2 & !V3)) )"); diff --git a/clang/unittests/Analysis/FlowSensitive/TestingSupport.cpp b/clang/unittests/Analysis/FlowSensitive/TestingSupport.cpp index 65c527ae63d2d71..e24ff25cb8292fb 100644 --- a/clang/unittests/Analysis/FlowSensitive/TestingSupport.cpp +++ b/clang/unittests/Analysis/FlowSensitive/TestingSupport.cpp @@ -15,6 +15,7 @@ #include "llvm/ADT/StringSet.h" #include "llvm/Support/Error.h" #include "llvm/Testing/Annotations/Annotations.h" +#include "gtest/gtest.h" #include #include #include @@ -218,3 +219,18 @@ const IndirectFieldDecl *test::findIndirectFieldDecl(ASTContext &ASTCtx, assert(Result != nullptr); return Result; } + +std::vector test::parseFormulas(Arena &A, StringRef Lines) { + std::vector Result; + while (!Lines.empty()) { +auto [First, Rest] = Lines.split('\n'); +Lines = Rest; +if (First.trim().empty()) + continue; +if (auto F = A.parseFormula(First)) + Result.push_back(&*F); +else + ADD_FAILURE() << llvm::toString(F.takeError()); + } + return Result; +} diff --git a/clang/unittests/Analysis/FlowSensitive/TestingSupport.h b/clang/unittests/Analysis/FlowSensitive/TestingSupport.h index a8089d9b8c7a13f..100d78378695d3c 100644 --- a/cla
[clang] [clang][dataflow][NFC] Move `parseAll()` to TestingSupport and rename `parseFormulas()` (PR #70437)
https://github.com/martinboehme closed https://github.com/llvm/llvm-project/pull/70437 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer][NFC] Add more tests of 'StreamChecker' about 'tmpfile' (PR #70540)
https://github.com/benshi001 updated https://github.com/llvm/llvm-project/pull/70540 >From 73d6ce1980fcbb1869b1be522adda6ab5af8a385 Mon Sep 17 00:00:00 2001 From: Ben Shi Date: Tue, 31 Oct 2023 13:05:19 +0800 Subject: [PATCH] [clang][analyzer] Update CallDescription of 'tmpfile' in StreamChecker --- .../StaticAnalyzer/Checkers/StreamChecker.cpp | 2 +- clang/test/Analysis/stream-wild-function.c| 22 +++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 clang/test/Analysis/stream-wild-function.c diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp index 4b7103c20557cc4..34df62f073e9a8c 100644 --- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp @@ -241,7 +241,7 @@ class StreamChecker : public Checkerhttps://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer][NFC] Add more tests of 'StreamChecker' about 'tmpfile' (PR #70540)
benshi001 wrote: > I would like to have the new test in `stream.c` (not `stream.cpp`) because > the C++ test file contains only C++ related StreamChecker tests (`tmpfile` > belongs not here). And a "FIXME" could be added to the test to indicate that > this is a faulty behavior (in the current case). The test and code change can > be in a single PR, this is a bugfix and addition of a related test, these are > done usually together. I have created a new file `stream-wild-function.c`, other than adding to `stream.c`, since pure C does not support function overload, there could be a conflict between standard `tmpfile` and non standard one. https://github.com/llvm/llvm-project/pull/70540 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 33b8586 - Add two time-trace scope variables.
Author: Ying Yi Date: 2023-10-31T09:16:06Z New Revision: 33b85867e30e1adc2ff2173039c199b81c10f52b URL: https://github.com/llvm/llvm-project/commit/33b85867e30e1adc2ff2173039c199b81c10f52b DIFF: https://github.com/llvm/llvm-project/commit/33b85867e30e1adc2ff2173039c199b81c10f52b.diff LOG: Add two time-trace scope variables. A time trace scope variable of `ParseDeclarationOrFunctionDefinition` with the function's source location is added to record the time spent parsing the function's declaration or definition. Another time trace scope variable of `ParseFunctionDefinition` is also added to record the name of the defined function. A release note is added as well. Reviewed by: Aaron Ballman Pull request: #65268 Added: clang/test/Driver/check-time-trace-ParseDeclarationOrFunctionDefinition.cpp Modified: clang/docs/ReleaseNotes.rst clang/lib/Parse/Parser.cpp clang/unittests/Support/TimeProfilerTest.cpp Removed: diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index bc28bb567f6932a..c151bd9d234b51e 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -427,6 +427,14 @@ Improvements to Clang's diagnostics (or, more commonly, ``NULL`` when the platform defines it as ``__null``) to be more consistent with GCC. +Improvements to Clang's time-trace +-- +- Two time-trace scope variables are added. A time trace scope variable of + ``ParseDeclarationOrFunctionDefinition`` with the function's source location + is added to record the time spent parsing the function's declaration or + definition. Another time trace scope variable of ``ParseFunctionDefinition`` + is also added to record the name of the defined function. + Bug Fixes in This Version - - Fixed an issue where a class template specialization whose declaration is diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp index 0f930248e77174b..bef3a0dcb285efd 100644 --- a/clang/lib/Parse/Parser.cpp +++ b/clang/lib/Parse/Parser.cpp @@ -13,8 +13,8 @@ #include "clang/Parse/Parser.h" #include "clang/AST/ASTConsumer.h" #include "clang/AST/ASTContext.h" -#include "clang/AST/DeclTemplate.h" #include "clang/AST/ASTLambda.h" +#include "clang/AST/DeclTemplate.h" #include "clang/Basic/FileManager.h" #include "clang/Parse/ParseDiagnostic.h" #include "clang/Parse/RAIIObjectsForParser.h" @@ -22,6 +22,7 @@ #include "clang/Sema/ParsedTemplate.h" #include "clang/Sema/Scope.h" #include "llvm/Support/Path.h" +#include "llvm/Support/TimeProfiler.h" using namespace clang; @@ -1229,6 +1230,13 @@ Parser::DeclGroupPtrTy Parser::ParseDeclOrFunctionDefInternal( Parser::DeclGroupPtrTy Parser::ParseDeclarationOrFunctionDefinition( ParsedAttributes &Attrs, ParsedAttributes &DeclSpecAttrs, ParsingDeclSpec *DS, AccessSpecifier AS) { + // Add an enclosing time trace scope for a bunch of small scopes with + // "EvaluateAsConstExpr". + llvm::TimeTraceScope TimeScope( + "ParseDeclarationOrFunctionDefinition", + Tok.getLocation().printToString( + Actions.getASTContext().getSourceManager())); + if (DS) { return ParseDeclOrFunctionDefInternal(Attrs, DeclSpecAttrs, *DS, AS); } else { @@ -1259,6 +1267,10 @@ Parser::DeclGroupPtrTy Parser::ParseDeclarationOrFunctionDefinition( Decl *Parser::ParseFunctionDefinition(ParsingDeclarator &D, const ParsedTemplateInfo &TemplateInfo, LateParsedAttrList *LateParsedAttrs) { + llvm::TimeTraceScope TimeScope( + "ParseFunctionDefinition", + Actions.GetNameForDeclarator(D).getName().getAsString()); + // Poison SEH identifiers so they are flagged as illegal in function bodies. PoisonSEHIdentifiersRAIIObject PoisonSEHIdentifiers(*this, true); const DeclaratorChunk::FunctionTypeInfo &FTI = D.getFunctionTypeInfo(); diff --git a/clang/test/Driver/check-time-trace-ParseDeclarationOrFunctionDefinition.cpp b/clang/test/Driver/check-time-trace-ParseDeclarationOrFunctionDefinition.cpp new file mode 100644 index 000..f854cddadbfcc1d --- /dev/null +++ b/clang/test/Driver/check-time-trace-ParseDeclarationOrFunctionDefinition.cpp @@ -0,0 +1,15 @@ +// RUN: %clangxx -S -ftime-trace -ftime-trace-granularity=0 -o %T/check-time-trace-ParseDeclarationOrFunctionDefinition %s +// RUN: cat %T/check-time-trace-ParseDeclarationOrFunctionDefinition.json \ +// RUN: | %python -c 'import json, sys; json.dump(json.loads(sys.stdin.read()), sys.stdout, sort_keys=True, indent=2)' \ +// RUN: | FileCheck %s + +// CHECK-DAG: "name": "ParseDeclarationOrFunctionDefinition" +// CHECK-DAG: "detail": "{{.*}}check-time-trace-ParseDeclarationOrFunctionDefinition.cpp:15:1" +// CHECK-DAG: "name": "ParseFunctionDefinition" +// CHECK-DAG: "detail": "foo" +// CHECK-DAG: "name": "ParseFunctionDe
[clang] [time-trace] Add a new time trace scope variable named "ParseDeclarationOrFunctionDefinition". (PR #65268)
https://github.com/MaggieYingYi closed https://github.com/llvm/llvm-project/pull/65268 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [time-trace] Add a new time trace scope variable named "ParseDeclarationOrFunctionDefinition". (PR #65268)
MaggieYingYi wrote: I tried to use `squash and merge` but the commit message using the wrong email address. Therefore, I have committed the changes using the git command. https://github.com/llvm/llvm-project/pull/65268 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 03ec84a - Revert "Add two time-trace scope variables."
Author: Nikita Popov Date: 2023-10-31T10:46:49+01:00 New Revision: 03ec84a00ba4d540222ab39c407e02959058fbdd URL: https://github.com/llvm/llvm-project/commit/03ec84a00ba4d540222ab39c407e02959058fbdd DIFF: https://github.com/llvm/llvm-project/commit/03ec84a00ba4d540222ab39c407e02959058fbdd.diff LOG: Revert "Add two time-trace scope variables." This reverts commit 33b85867e30e1adc2ff2173039c199b81c10f52b. This causes a large compile-time regression (about 1% for unoptimized builds). Added: Modified: clang/docs/ReleaseNotes.rst clang/lib/Parse/Parser.cpp clang/unittests/Support/TimeProfilerTest.cpp Removed: clang/test/Driver/check-time-trace-ParseDeclarationOrFunctionDefinition.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index c151bd9d234b51e..bc28bb567f6932a 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -427,14 +427,6 @@ Improvements to Clang's diagnostics (or, more commonly, ``NULL`` when the platform defines it as ``__null``) to be more consistent with GCC. -Improvements to Clang's time-trace --- -- Two time-trace scope variables are added. A time trace scope variable of - ``ParseDeclarationOrFunctionDefinition`` with the function's source location - is added to record the time spent parsing the function's declaration or - definition. Another time trace scope variable of ``ParseFunctionDefinition`` - is also added to record the name of the defined function. - Bug Fixes in This Version - - Fixed an issue where a class template specialization whose declaration is diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp index bef3a0dcb285efd..0f930248e77174b 100644 --- a/clang/lib/Parse/Parser.cpp +++ b/clang/lib/Parse/Parser.cpp @@ -13,8 +13,8 @@ #include "clang/Parse/Parser.h" #include "clang/AST/ASTConsumer.h" #include "clang/AST/ASTContext.h" -#include "clang/AST/ASTLambda.h" #include "clang/AST/DeclTemplate.h" +#include "clang/AST/ASTLambda.h" #include "clang/Basic/FileManager.h" #include "clang/Parse/ParseDiagnostic.h" #include "clang/Parse/RAIIObjectsForParser.h" @@ -22,7 +22,6 @@ #include "clang/Sema/ParsedTemplate.h" #include "clang/Sema/Scope.h" #include "llvm/Support/Path.h" -#include "llvm/Support/TimeProfiler.h" using namespace clang; @@ -1230,13 +1229,6 @@ Parser::DeclGroupPtrTy Parser::ParseDeclOrFunctionDefInternal( Parser::DeclGroupPtrTy Parser::ParseDeclarationOrFunctionDefinition( ParsedAttributes &Attrs, ParsedAttributes &DeclSpecAttrs, ParsingDeclSpec *DS, AccessSpecifier AS) { - // Add an enclosing time trace scope for a bunch of small scopes with - // "EvaluateAsConstExpr". - llvm::TimeTraceScope TimeScope( - "ParseDeclarationOrFunctionDefinition", - Tok.getLocation().printToString( - Actions.getASTContext().getSourceManager())); - if (DS) { return ParseDeclOrFunctionDefInternal(Attrs, DeclSpecAttrs, *DS, AS); } else { @@ -1267,10 +1259,6 @@ Parser::DeclGroupPtrTy Parser::ParseDeclarationOrFunctionDefinition( Decl *Parser::ParseFunctionDefinition(ParsingDeclarator &D, const ParsedTemplateInfo &TemplateInfo, LateParsedAttrList *LateParsedAttrs) { - llvm::TimeTraceScope TimeScope( - "ParseFunctionDefinition", - Actions.GetNameForDeclarator(D).getName().getAsString()); - // Poison SEH identifiers so they are flagged as illegal in function bodies. PoisonSEHIdentifiersRAIIObject PoisonSEHIdentifiers(*this, true); const DeclaratorChunk::FunctionTypeInfo &FTI = D.getFunctionTypeInfo(); diff --git a/clang/test/Driver/check-time-trace-ParseDeclarationOrFunctionDefinition.cpp b/clang/test/Driver/check-time-trace-ParseDeclarationOrFunctionDefinition.cpp deleted file mode 100644 index f854cddadbfcc1d..000 --- a/clang/test/Driver/check-time-trace-ParseDeclarationOrFunctionDefinition.cpp +++ /dev/null @@ -1,15 +0,0 @@ -// RUN: %clangxx -S -ftime-trace -ftime-trace-granularity=0 -o %T/check-time-trace-ParseDeclarationOrFunctionDefinition %s -// RUN: cat %T/check-time-trace-ParseDeclarationOrFunctionDefinition.json \ -// RUN: | %python -c 'import json, sys; json.dump(json.loads(sys.stdin.read()), sys.stdout, sort_keys=True, indent=2)' \ -// RUN: | FileCheck %s - -// CHECK-DAG: "name": "ParseDeclarationOrFunctionDefinition" -// CHECK-DAG: "detail": "{{.*}}check-time-trace-ParseDeclarationOrFunctionDefinition.cpp:15:1" -// CHECK-DAG: "name": "ParseFunctionDefinition" -// CHECK-DAG: "detail": "foo" -// CHECK-DAG: "name": "ParseFunctionDefinition" -// CHECK-DAG: "detail": "bar" - -template -void foo(T) {} -void bar() { foo(0); } diff --git a/clang/unittests/Support/TimeProfilerTest.cpp b/clang/unittests/Support/TimeProfilerTest.cpp index 97fdbb7232b1351..a7ca2b
[clang] [time-trace] Add a new time trace scope variable named "ParseDeclarationOrFunctionDefinition". (PR #65268)
nikic wrote: I've reverted this change because it causes a large compile-time regression: http://llvm-compile-time-tracker.com/compare.php?from=61b9176cf70444c54f3ac6eebd82fc9ffd69944d&to=33b85867e30e1adc2ff2173039c199b81c10f52b&stat=instructions:u >From a quick glance at your implementation, I suspect the issues is that the >used strings may be expensive to compute. TimeTraceScope has an overload >accepting a closure that calculates the detail string for such cases. https://github.com/llvm/llvm-project/pull/65268 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Simplify SVal for simple NonLoc->Loc casts (PR #66463)
steakhal wrote: This is a brief summary of my recent investigation, no direct action is required. I had a quick look at the issue differences between clang-17 and llvm/main as a preparation for the clang-18 release in early January and noticed that because of this patch, we have some unexpected improvements. FYI this FP was eliminated by Z3 refutation anyway if you enabled that, but now even the engine can avoid exploring that dead-code. --- Now that we simplify more often (see the patch), we can exclude more execution paths. Here is an [example](https://godbolt.org/z/x35MT33xT): ```C++ int fixedFP(int x) { int* z = 0; if ((x & 1) && ((x & 1) ^ 1)) { return *z; // Nullptr deref FP? Now it's eliminated. } return 0; } ``` Notice, that the FP is only eliminated in C++ mode, and still present in C mode for some reason. My theory is that we use `int` as a `bool` type, thus simplification can't exploit that a boolean expression can only be `1` or `0`; and fails to simplify the expression. The reason for having a wider impact than originally anticipated was that the function we modified `handleLValueBitCast()` suggested that it should be invoked only for lvalue bitcasts, however, actually, it gets invoked from a few more places including ExprEngineC.cpp ExprEngine::VisitCast: ```C++ case CK_IntegralToBoolean: case CK_IntegralToFloating: case CK_FloatingToIntegral: case CK_FloatingToBoolean: case CK_FloatingCast: case CK_FloatingRealToComplex: case CK_FloatingComplexToReal: case CK_FloatingComplexToBoolean: case CK_FloatingComplexCast: case CK_FloatingComplexToIntegralComplex: case CK_IntegralRealToComplex: case CK_IntegralComplexToReal: case CK_IntegralComplexToBoolean: case CK_IntegralComplexCast: case CK_IntegralComplexToFloatingComplex: case CK_CPointerToObjCPointerCast: case CK_BlockPointerToObjCPointerCast: case CK_AnyPointerToBlockPointerCast: case CK_ObjCObjectLValueCast: case CK_ZeroToOCLOpaqueType: case CK_IntToOCLSampler: case CK_LValueBitCast: case CK_FloatingToFixedPoint: case CK_FixedPointToFloating: case CK_FixedPointCast: case CK_FixedPointToBoolean: case CK_FixedPointToIntegral: case CK_IntegralToFixedPoint: { state = handleLValueBitCast(state, Ex, LCtx, T, ExTy, CastE, Bldr, Pred); continue; } ``` And this could have caused this "improvement". --- The exploded node of the `PostStmt` `((x & 1) ^ 1)` was this prior the patch:  And now it looks like this (notice that the expression value is now simplified to `0 U1b`):  Here is how a child node looks like for C now (notice that the constraint is `((reg_$0) & 1) ^ 1: { [-2147483648, -1], [1, 2147483647] }`. This is the same state we had before this patch for C and C++ as well.  https://github.com/llvm/llvm-project/pull/66463 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang] [AArch64][SME] Remove immediate argument restriction for svldr and svstr (PR #68565)
@@ -1741,6 +1742,54 @@ void AArch64DAGToDAGISel::SelectCVTIntrinsic(SDNode *N, unsigned NumVecs, CurDAG->RemoveDeadNode(N); } +void AArch64DAGToDAGISel::SelectSMELdrStrZA(SDNode *N, bool IsLoad) { + // Lower an SME LDR/STR ZA intrinsic to LDR_ZA_PSEUDO or STR_ZA. + // If the vector select parameter is an immediate in the range 0-15 then we + // can emit it directly into the instruction as it's a legal operand. + // Otherwise we must emit 0 as the vector select operand and modify the base + // register instead. + SDLoc DL(N); + + SDValue VecNum = N->getOperand(4), Base = N->getOperand(3), + TileSlice = N->getOperand(2); + int Imm = -1; + if (auto ImmNode = dyn_cast(VecNum)) +Imm = ImmNode->getZExtValue(); + + if (Imm >= 0 && Imm <= 15) { SamTebbs33 wrote: > Something still needs to happen with the immediate argument when it doesn't > fit entirely into the instruction's immediate operand. The current result is > not correct. I don't quite understand what that something is if immediate if it doesn't fit in the range. Currently the immediate is multiplied by svl and added to the base register if it doesn't fit. What else should be done if it doesn't fit in the range? > Maybe you can restructure the code in such a way that it first tries to fold > as much of the constant into the instruction's immediate operand, and then > adds the remainder to the tile-slice and to the pointer (multiplied by SVL), > as you do in the code below. Do you mean that if, for example, we have an immediate vecnum of 17, then we put 15 into the offset field of the instruction and add 2 x SVL to the base and slice registers? Naively I don't see that being an improvement as you're doing the multiplication in two places (ldr instruction and an extra madd) rather than one. https://github.com/llvm/llvm-project/pull/68565 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer][NFC] Add more tests of 'StreamChecker' about 'tmpfile' (PR #70540)
https://github.com/benshi001 updated https://github.com/llvm/llvm-project/pull/70540 >From e89412b0a67927145f49d9cc53562eed77989f99 Mon Sep 17 00:00:00 2001 From: Ben Shi Date: Tue, 31 Oct 2023 13:05:19 +0800 Subject: [PATCH] [clang][analyzer] Update CallDescription of 'tmpfile' & 'fopen' in StreamChecker --- .../StaticAnalyzer/Checkers/StreamChecker.cpp| 4 ++-- clang/test/Analysis/stream-wild-function.c | 16 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 clang/test/Analysis/stream-wild-function.c diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp index 4b7103c20557cc4..7e8031c7545f691 100644 --- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp @@ -238,10 +238,10 @@ class StreamChecker : public Checker FnDescriptions = { - {{{"fopen"}}, {nullptr, &StreamChecker::evalFopen, ArgNone}}, + {{{"fopen"}, 2}, {nullptr, &StreamChecker::evalFopen, ArgNone}}, {{{"freopen"}, 3}, {&StreamChecker::preFreopen, &StreamChecker::evalFreopen, 2}}, - {{{"tmpfile"}}, {nullptr, &StreamChecker::evalFopen, ArgNone}}, + {{{"tmpfile"}, 0}, {nullptr, &StreamChecker::evalFopen, ArgNone}}, {{{"fclose"}, 1}, {&StreamChecker::preDefault, &StreamChecker::evalFclose, 0}}, {{{"fread"}, 4}, diff --git a/clang/test/Analysis/stream-wild-function.c b/clang/test/Analysis/stream-wild-function.c new file mode 100644 index 000..b059816249de77c --- /dev/null +++ b/clang/test/Analysis/stream-wild-function.c @@ -0,0 +1,16 @@ +// RUN: %clang_analyze_cc1 -fno-builtin -analyzer-checker=core,alpha.unix.Stream -verify %s +// expected-no-diagnostics + +typedef struct _FILE FILE; + +// These functions are not standard C library functions. +FILE *tmpfile(const char *restrict path); +FILE *fopen(const char *restrict path); + +void test_fopen(void) { + FILE *fp = fopen("file"); +} + +void test_tmpfile(void) { + FILE *fp = tmpfile("file"); +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] Update CallDescription of 'tmpfile' & 'fopen' in StreamChecker (PR #70540)
https://github.com/benshi001 edited https://github.com/llvm/llvm-project/pull/70540 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AArch64][Clang] Refactor code to emit SVE & SME builtins (PR #70662)
@@ -9893,24 +9888,40 @@ Value *CodeGenFunction::FormSVEBuiltinResult(Value *Call) { return Call; } -Value *CodeGenFunction::EmitAArch64SVEBuiltinExpr(unsigned BuiltinID, - const CallExpr *E) { +void CodeGenFunction::GetAArch64SVEProcessedOperands( +unsigned BuiltinID, const CallExpr *E, SmallVectorImpl &Ops, +SVETypeFlags TypeFlags) { // Find out if any arguments are required to be integer constant expressions. unsigned ICEArguments = 0; ASTContext::GetBuiltinTypeError Error; getContext().GetBuiltinType(BuiltinID, Error, &ICEArguments); assert(Error == ASTContext::GE_None && "Should not codegen an error"); - llvm::Type *Ty = ConvertType(E->getType()); - if (BuiltinID >= SVE::BI__builtin_sve_reinterpret_s8_s8 && - BuiltinID <= SVE::BI__builtin_sve_reinterpret_f64_f64) { -Value *Val = EmitScalarExpr(E->getArg(0)); -return EmitSVEReinterpret(Val, Ty); - } + // Tuple set/get only requires one insert/extract vector, which is + // created by EmitSVETupleSetOrGet. + bool IsTupleGetOrSet = TypeFlags.isTupleSet() || TypeFlags.isTupleGet(); - llvm::SmallVector Ops; for (unsigned i = 0, e = E->getNumArgs(); i != e; i++) { -if ((ICEArguments & (1 << i)) == 0) +bool IsICE = ICEArguments & (1 << i); +if (!IsTupleGetOrSet && !IsICE) { sdesmalen-arm wrote: nit: While we're refactoring this, can this loop be rewritten a bit, e.g. ``` for (unsigned i = 0, e = E->getNumArgs(); i != e; i++) { bool IsICE = ICEArguments & (1 << i); Value *Arg = EmitScalarExpr(E->getArg(i)); if (!isa(Arg->getType())) { if (IsICE || !IsTupleGetOrSet) Ops.push_back(Arg); continue; } auto *VTy = cast(Arg->getType()) /* rest of the code here */ } ``` https://github.com/llvm/llvm-project/pull/70662 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AArch64][Clang] Refactor code to emit SVE & SME builtins (PR #70662)
@@ -9893,24 +9888,40 @@ Value *CodeGenFunction::FormSVEBuiltinResult(Value *Call) { return Call; } -Value *CodeGenFunction::EmitAArch64SVEBuiltinExpr(unsigned BuiltinID, - const CallExpr *E) { +void CodeGenFunction::GetAArch64SVEProcessedOperands( +unsigned BuiltinID, const CallExpr *E, SmallVectorImpl &Ops, +SVETypeFlags TypeFlags) { // Find out if any arguments are required to be integer constant expressions. unsigned ICEArguments = 0; ASTContext::GetBuiltinTypeError Error; getContext().GetBuiltinType(BuiltinID, Error, &ICEArguments); assert(Error == ASTContext::GE_None && "Should not codegen an error"); - llvm::Type *Ty = ConvertType(E->getType()); - if (BuiltinID >= SVE::BI__builtin_sve_reinterpret_s8_s8 && - BuiltinID <= SVE::BI__builtin_sve_reinterpret_f64_f64) { -Value *Val = EmitScalarExpr(E->getArg(0)); -return EmitSVEReinterpret(Val, Ty); - } + // Tuple set/get only requires one insert/extract vector, which is + // created by EmitSVETupleSetOrGet. + bool IsTupleGetOrSet = TypeFlags.isTupleSet() || TypeFlags.isTupleGet(); - llvm::SmallVector Ops; for (unsigned i = 0, e = E->getNumArgs(); i != e; i++) { -if ((ICEArguments & (1 << i)) == 0) +bool IsICE = ICEArguments & (1 << i); +if (!IsTupleGetOrSet && !IsICE) { + Value *Arg = EmitScalarExpr(E->getArg(i)); + if (auto *VTy = dyn_cast(Arg->getType())) { +unsigned MinElts = VTy->getMinNumElements(); +bool IsPred = VTy->getElementType()->isIntegerTy(1); +unsigned N = +(MinElts * VTy->getScalarSizeInBits()) / (IsPred ? 16 : 128); +for (unsigned I = 0; I < N; ++I) { + Value *Idx = ConstantInt::get(CGM.Int64Ty, (I * MinElts) / N); + auto *NewVTy = + ScalableVectorType::get(VTy->getElementType(), MinElts / N); + if (N == 1 && VTy == NewVTy) sdesmalen-arm wrote: Is `VTy == NewVTy` implied if `N == 1`? If so, can we hoist the `N == 1` check out of the loop? https://github.com/llvm/llvm-project/pull/70662 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [time-trace] Add a new time trace scope variable named "ParseDeclarationOrFunctionDefinition". (PR #65268)
https://github.com/MaggieYingYi reopened https://github.com/llvm/llvm-project/pull/65268 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [time-trace] Add a new time trace scope variable named "ParseDeclarationOrFunctionDefinition". (PR #65268)
MaggieYingYi wrote: Hi @nikic, thanks for spotting the issue and reverted the commit. Hi @AaronBallman, As @nikic mentioned that the issue is that the used strings may be expensive to compute. If we remove the change to record the function name and function location, I think the issue will be fixed. This means: 1. Remove the time trace scope variable of `ParseFunctionDefinition`. ``` llvm::TimeTraceScope TimeScope( "ParseFunctionDefinition", Actions.GetNameForDeclarator(D).getName().getAsString()); ``` 2. Remove the source location for the time trace scope variable of "ParseDeclarationOrFunctionDefinition". Change: ``` llvm::TimeTraceScope TimeScope( "ParseDeclarationOrFunctionDefinition", Tok.getLocation().printToString( Actions.getASTContext().getSourceManager())); ``` To: ``` llvm::TimeTraceScope TimeScope( "ParseDeclarationOrFunctionDefinition"); ``` Could you please let me know your thoughts? or any suggestion? Thanks, Maggie https://github.com/llvm/llvm-project/pull/65268 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 4f5d463 - Remove malformed brief commands in comments (NFC) (#70746)
Author: Mike Rice Date: 2023-10-31T03:49:53-07:00 New Revision: 4f5d463505b3e313cd3943132e7b2784a65c39d9 URL: https://github.com/llvm/llvm-project/commit/4f5d463505b3e313cd3943132e7b2784a65c39d9 DIFF: https://github.com/llvm/llvm-project/commit/4f5d463505b3e313cd3943132e7b2784a65c39d9.diff LOG: Remove malformed brief commands in comments (NFC) (#70746) Co-authored-by: Timm Baeder Added: Modified: clang/include/clang/Basic/TargetInfo.h clang/include/clang/Parse/Parser.h Removed: diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h index 9d56e97a3d4bb88..b3c5cbfb319f01f 100644 --- a/clang/include/clang/Basic/TargetInfo.h +++ b/clang/include/clang/Basic/TargetInfo.h @@ -1291,20 +1291,20 @@ class TargetInfo : public TransferrableTargetInfo, fillValidCPUList(Values); } - /// brief Determine whether this TargetInfo supports the given CPU name. + /// Determine whether this TargetInfo supports the given CPU name. virtual bool isValidCPUName(StringRef Name) const { return true; } - /// brief Determine whether this TargetInfo supports the given CPU name for - // tuning. + /// Determine whether this TargetInfo supports the given CPU name for + /// tuning. virtual bool isValidTuneCPUName(StringRef Name) const { return isValidCPUName(Name); } virtual ParsedTargetAttr parseTargetAttr(StringRef Str) const; - /// brief Determine whether this TargetInfo supports tune in target attribute. + /// Determine whether this TargetInfo supports tune in target attribute. virtual bool supportsTargetAttributeTune() const { return false; } diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h index 79ac622fd03e24e..30e0352c868637b 100644 --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -663,9 +663,9 @@ class Parser : public CodeCompletionHandler { return PrevTokLocation; } - ///\ brief When we are consuming a code-completion token without having - /// matched specific position in the grammar, provide code-completion results - /// based on context. + /// When we are consuming a code-completion token without having matched + /// specific position in the grammar, provide code-completion results based + /// on context. /// /// \returns the source location of the code-completion token. SourceLocation handleUnexpectedCodeCompletionToken(); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Remove malformed brief commands in comments (NFC) (PR #70746)
https://github.com/mikerice1969 closed https://github.com/llvm/llvm-project/pull/70746 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Fix clang++ crash on assertions when compiling source (PR #70594)
https://github.com/Rajveer100 updated https://github.com/llvm/llvm-project/pull/70594 >From efea75d1ae4a1da80b16b3e743a15a82b5f8d971 Mon Sep 17 00:00:00 2001 From: Rajveer Date: Sun, 29 Oct 2023 18:37:17 +0530 Subject: [PATCH] [clang] Fix a crash in debug mode Resolves Issue #35603 This bug was caused due to the assertions being too strict, loosened by stripping qualifiers from the base class but not from the type of the initializer. --- clang/lib/AST/ExprConstant.cpp | 2 +- clang/test/Sema/GH35603.cpp| 19 +++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 clang/test/Sema/GH35603.cpp diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 5947805f9576ff8..07f0a12385b46e9 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -6431,7 +6431,7 @@ static bool HandleConstructorCall(const Expr *E, const LValue &This, // Non-virtual base classes are initialized in the order in the class // definition. We have already checked for virtual base classes. assert(!BaseIt->isVirtual() && "virtual base for literal type"); - assert(Info.Ctx.hasSameType(BaseIt->getType(), BaseType) && + assert(Info.Ctx.hasSameUnqualifiedType(BaseIt->getType(), BaseType) && "base class initializers not in expected order"); ++BaseIt; #endif diff --git a/clang/test/Sema/GH35603.cpp b/clang/test/Sema/GH35603.cpp new file mode 100644 index 000..853552108ec2b67 --- /dev/null +++ b/clang/test/Sema/GH35603.cpp @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify +// RUN: %clang_cc1 -fsyntax-only -std=c++23 %s -verify + +// expected-no-diagnostics + +struct A {}; +using CA = const A; + +struct S1 : CA { + constexpr S1() : CA() {} +}; + +struct S2 : A { + constexpr S2() : CA() {} +}; + +struct S3 : CA { + constexpr S3() : A() {} +}; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Fix clang++ crash on assertions when compiling source (PR #70594)
@@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify +// RUN: %clang_cc1 -fsyntax-only -std=c++23 %s -verify + +// expected-no-diagnostics + +struct A {}; +using CA = const A; + +struct S1 : CA { Rajveer100 wrote: In the `godbolt` links, the compilers seem to be two different versions of `clang`, one being a `trunk` and other is an `assertion trunk`? https://github.com/llvm/llvm-project/pull/70594 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Fix clang++ crash on assertions when compiling source (PR #70594)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff 4f5d463505b3e313cd3943132e7b2784a65c39d9 efea75d1ae4a1da80b16b3e743a15a82b5f8d971 -- clang/test/Sema/GH35603.cpp clang/lib/AST/ExprConstant.cpp `` View the diff from clang-format here. ``diff diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 07f0a12385b4..97705c1afc13 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -2772,9 +2772,9 @@ static bool EvalAndBitcastToAPInt(EvalInfo &Info, const Expr *E, } unsigned BaseEltSize = EltAsInt.getBitWidth(); if (BigEndian) -Res |= EltAsInt.zextOrTrunc(VecSize).rotr(i*EltSize+BaseEltSize); +Res |= EltAsInt.zextOrTrunc(VecSize).rotr(i * EltSize + BaseEltSize); else -Res |= EltAsInt.zextOrTrunc(VecSize).rotl(i*EltSize); +Res |= EltAsInt.zextOrTrunc(VecSize).rotl(i * EltSize); } return true; } @@ -10566,9 +10566,9 @@ bool VectorExprEvaluator::VisitCastExpr(const CastExpr *E) { for (unsigned i = 0; i < NElts; i++) { llvm::APInt Elt; if (BigEndian) - Elt = SValInt.rotl(i*EltSize+EltSize).zextOrTrunc(EltSize); + Elt = SValInt.rotl(i * EltSize + EltSize).zextOrTrunc(EltSize); else - Elt = SValInt.rotr(i*EltSize).zextOrTrunc(EltSize); + Elt = SValInt.rotr(i * EltSize).zextOrTrunc(EltSize); Elts.push_back(APValue(APSInt(Elt, !EltTy->isSignedIntegerType(; } } else { `` https://github.com/llvm/llvm-project/pull/70594 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libcxx] [libc] [flang] [clang-tools-extra] [clang] [compiler-rt] [llvm] [LoopPeeling] Fix weights updating of peeled off branches (PR #70094)
https://github.com/aleks-tmb updated https://github.com/llvm/llvm-project/pull/70094 >From 4265cc4a05d939a29e57a116e696fa1eb032c249 Mon Sep 17 00:00:00 2001 From: Aleksandr Popov Date: Tue, 24 Oct 2023 16:47:50 + Subject: [PATCH] [LoopPeeling] Fix weights updating of peeled off branches In https://reviews.llvm.org/D64235 a new algorithm has been introduced for updating the branch weights of latch blocks and their copies. It increases the probability of going to the exit block for each next peel iteration, calculating weights by (F - I * E, E), where: - F is a weight of the edge from latch to header. - E is a weight of the edge from latch to exit. - I is a number of peeling iteration. E.g: Let's say the latch branch weights are (100,300) and the estimated trip count is 4. If we peel off all 4 iterations the weights of the copied branches will be: 0: (100,300) 1: (100,200) 2: (100,100) 3: (100,1) https://godbolt.org/z/93KnoEsT6 So we make the original loop almost unreachable from the 3rd peeled copy according to the profile data. But that's only true if the profiling data is accurate. Underestimated trip count can lead to a performance issues with the register allocator, which may decide to spill intervals inside the loop assuming it's unreachable. Since we don't know how accurate the profiling data is, it seems better to set neutral 1/1 weights on the last peeled latch branch. After this change, the weights in the example above will look like this: 0: (100,300) 1: (100,200) 2: (100,100) 3: (100,100) --- llvm/lib/Transforms/Utils/LoopPeel.cpp | 10 +++--- llvm/test/Transforms/LoopUnroll/peel-loop-pgo-deopt.ll | 5 ++--- llvm/test/Transforms/LoopUnroll/peel-loop-pgo.ll | 5 ++--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/llvm/lib/Transforms/Utils/LoopPeel.cpp b/llvm/lib/Transforms/Utils/LoopPeel.cpp index 31f065b691f864c..30c525dd82bbd97 100644 --- a/llvm/lib/Transforms/Utils/LoopPeel.cpp +++ b/llvm/lib/Transforms/Utils/LoopPeel.cpp @@ -636,9 +636,13 @@ static void updateBranchWeights(Instruction *Term, WeightInfo &Info) { MDB.createBranchWeights(Info.Weights)); for (auto [Idx, SubWeight] : enumerate(Info.SubWeights)) if (SubWeight != 0) - Info.Weights[Idx] = Info.Weights[Idx] > SubWeight - ? Info.Weights[Idx] - SubWeight - : 1; + // Don't set the probability of taking the edge from latch to loop header + // to less than 1, as this could significantly reduce the loop's hotness, + // which would be incorrect in the case of underestimating the trip count. + Info.Weights[Idx] = + Info.Weights[Idx] > SubWeight + ? std::max(Info.Weights[Idx] - SubWeight, SubWeight) + : SubWeight; } /// Initialize the weights for all exiting blocks. diff --git a/llvm/test/Transforms/LoopUnroll/peel-loop-pgo-deopt.ll b/llvm/test/Transforms/LoopUnroll/peel-loop-pgo-deopt.ll index a0dc216133fb7d5..d91cb5bab382782 100644 --- a/llvm/test/Transforms/LoopUnroll/peel-loop-pgo-deopt.ll +++ b/llvm/test/Transforms/LoopUnroll/peel-loop-pgo-deopt.ll @@ -21,7 +21,7 @@ ; CHECK: br i1 %{{.*}}, label %[[NEXT2:.*]], label %for.cond.for.end_crit_edge, !prof !18 ; CHECK: [[NEXT2]]: ; CHECK: br i1 %c, label %{{.*}}, label %side_exit.loopexit, !prof !15 -; CHECK: br i1 %{{.*}}, label %for.body, label %{{.*}}, !prof !19 +; CHECK: br i1 %{{.*}}, label %for.body, label %{{.*}}, !prof !18 define i32 @basic(ptr %p, i32 %k, i1 %c) #0 !prof !15 { entry: @@ -85,6 +85,5 @@ attributes #1 = { nounwind optsize } ; This is a weights of latch and its copies. ;CHECK: !16 = !{!"branch_weights", i32 3001, i32 1001} ;CHECK: !17 = !{!"branch_weights", i32 2000, i32 1001} -;CHECK: !18 = !{!"branch_weights", i32 999, i32 1001} -;CHECK: !19 = !{!"branch_weights", i32 1, i32 1001} +;CHECK: !18 = !{!"branch_weights", i32 1001, i32 1001} diff --git a/llvm/test/Transforms/LoopUnroll/peel-loop-pgo.ll b/llvm/test/Transforms/LoopUnroll/peel-loop-pgo.ll index cadb6739dbc3fbb..15dce234baee91d 100644 --- a/llvm/test/Transforms/LoopUnroll/peel-loop-pgo.ll +++ b/llvm/test/Transforms/LoopUnroll/peel-loop-pgo.ll @@ -24,7 +24,7 @@ ; CHECK: [[NEXT1]]: ; CHECK: br i1 %{{.*}}, label %[[NEXT2:.*]], label %for.cond.for.end_crit_edge, !prof !17 ; CHECK: [[NEXT2]]: -; CHECK: br i1 %{{.*}}, label %for.body, label %{{.*}}, !prof !18 +; CHECK: br i1 %{{.*}}, label %for.body, label %{{.*}}, !prof !17 define void @basic(ptr %p, i32 %k) #0 !prof !15 { entry: @@ -105,6 +105,5 @@ attributes #1 = { nounwind optsize } ;CHECK: !15 = !{!"branch_weights", i32 3001, i32 1001} ;CHECK: !16 = !{!"branch_weights", i32 2000, i32 1001} -;CHECK: !17 = !{!"branch_weights", i32 999, i32 1001} -;CHECK: !18 = !{!"branch_weights", i32 1, i32 1001} +;CHECK: !17 = !{!"branch_weights", i32 1001, i32 1001} ___ cfe-commits mailing list cfe
[clang] [llvm] [DebugMetadata][DwarfDebug] Clone uniqued function-local types after metadata loading (PR #68986)
https://github.com/dzhidzhoev updated https://github.com/llvm/llvm-project/pull/68986 >From d61f109dcb92db45fa8f6ce7503409edcbfbce63 Mon Sep 17 00:00:00 2001 From: Vladislav Dzhidzhoev Date: Tue, 18 Jul 2023 14:22:46 +0200 Subject: [PATCH 1/3] [DebugMetadata][DwarfDebug] Support function-local types in lexical block scopes (4/7) RFC https://discourse.llvm.org/t/rfc-dwarfdebug-fix-and-improve-handling-imported-entities-types-and-static-local-in-subprogram-and-lexical-block-scopes/68544 Similar to imported declarations, the patch tracks function-local types in DISubprogram's 'retainedNodes' field. DwarfDebug is adjusted in accordance with the aforementioned metadata change and provided a support of function-local types scoped within a lexical block. The patch assumes that DICompileUnit's 'enums field' no longer tracks local types and DwarfDebug would assert if any locally-scoped types get placed there. Reviewed By: jmmartinez Differential Revision: https://reviews.llvm.org/D144006 --- .../CodeGen/debug-info-codeview-unnamed.c | 16 +- clang/test/CodeGen/debug-info-unused-types.c | 16 +- .../test/CodeGen/debug-info-unused-types.cpp | 14 +- clang/test/CodeGenCXX/debug-info-access.cpp | 2 +- .../CodeGenCXX/debug-info-anon-union-vars.cpp | 12 +- .../debug-info-codeview-unnamed.cpp | 110 +++-- .../debug-info-gline-tables-only-codeview.cpp | 4 +- clang/test/CodeGenCXX/debug-lambda-this.cpp | 4 +- llvm/include/llvm/IR/DIBuilder.h | 6 +- llvm/include/llvm/IR/DebugInfo.h | 1 + llvm/lib/Bitcode/Reader/MetadataLoader.cpp| 86 ++-- .../CodeGen/AsmPrinter/DwarfCompileUnit.cpp | 60 ++- .../lib/CodeGen/AsmPrinter/DwarfCompileUnit.h | 16 +- llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp| 13 +- llvm/lib/IR/DIBuilder.cpp | 37 +- llvm/lib/IR/DebugInfo.cpp | 11 +- llvm/lib/IR/Verifier.cpp | 6 +- llvm/lib/Transforms/Utils/CloneFunction.cpp | 7 +- llvm/test/Bitcode/upgrade-cu-locals.ll| 68 +-- llvm/test/Bitcode/upgrade-cu-locals.ll.bc | Bin 2688 -> 2780 bytes .../DebugInfo/Generic/inlined-local-type.ll | 128 ++ .../Generic/lexical-block-retained-types.ll | 55 +++ .../DebugInfo/Generic/lexical-block-types.ll | 425 ++ .../Generic/verifier-invalid-disubprogram.ll | 2 +- .../X86/local-type-as-template-parameter.ll | 161 +++ llvm/test/DebugInfo/X86/set.ll| 4 +- .../split-dwarf-local-import.ll | 1 - .../split-dwarf-local-import2.ll | 1 - .../split-dwarf-local-import3.ll | 0 .../Transforms/Utils/CloningTest.cpp | 93 30 files changed, 1165 insertions(+), 194 deletions(-) create mode 100644 llvm/test/DebugInfo/Generic/inlined-local-type.ll create mode 100644 llvm/test/DebugInfo/Generic/lexical-block-retained-types.ll create mode 100644 llvm/test/DebugInfo/Generic/lexical-block-types.ll create mode 100644 llvm/test/DebugInfo/X86/local-type-as-template-parameter.ll rename llvm/test/DebugInfo/{Generic => X86}/split-dwarf-local-import.ll (98%) rename llvm/test/DebugInfo/{Generic => X86}/split-dwarf-local-import2.ll (98%) rename llvm/test/DebugInfo/{Generic => X86}/split-dwarf-local-import3.ll (100%) diff --git a/clang/test/CodeGen/debug-info-codeview-unnamed.c b/clang/test/CodeGen/debug-info-codeview-unnamed.c index bd2a7543e56b2ba..16ffb3682236f18 100644 --- a/clang/test/CodeGen/debug-info-codeview-unnamed.c +++ b/clang/test/CodeGen/debug-info-codeview-unnamed.c @@ -8,23 +8,23 @@ int main(int argc, char* argv[], char* arge[]) { // struct { int bar; } one = {42}; // - // LINUX: !{{[0-9]+}} = !DILocalVariable(name: "one" - // LINUX-SAME: type: [[TYPE_OF_ONE:![0-9]+]] - // LINUX-SAME: ) - // LINUX: [[TYPE_OF_ONE]] = distinct !DICompositeType( + // LINUX: [[TYPE_OF_ONE:![0-9]+]] = distinct !DICompositeType( // LINUX-SAME: tag: DW_TAG_structure_type // LINUX-NOT: name: // LINUX-NOT: identifier: // LINUX-SAME: ) + // LINUX: !{{[0-9]+}} = !DILocalVariable(name: "one" + // LINUX-SAME: type: [[TYPE_OF_ONE]] + // LINUX-SAME: ) // - // MSVC: !{{[0-9]+}} = !DILocalVariable(name: "one" - // MSVC-SAME: type: [[TYPE_OF_ONE:![0-9]+]] - // MSVC-SAME: ) - // MSVC: [[TYPE_OF_ONE]] = distinct !DICompositeType + // MSVC: [[TYPE_OF_ONE:![0-9]+]] = distinct !DICompositeType // MSVC-SAME: tag: DW_TAG_structure_type // MSVC-NOT: name: // MSVC-NOT: identifier: // MSVC-SAME: ) + // MSVC: !{{[0-9]+}} = !DILocalVariable(name: "one" + // MSVC-SAME: type: [[TYPE_OF_ONE]] + // MSVC-SAME: ) return 0; } diff --git a/clang/test/CodeGen/debug-info-unused-types.c b/clang/test/CodeGen/debug-info-unused-types.c index 3e9f7b07658e36e..31d608d92a06b41 100644 --- a/clang/test/CodeGen/debug-info-unu
[compiler-rt] [flang] [libc] [libcxx] [llvm] [lldb] [clang-tools-extra] [clang] [AMDGPU] Fix nondeterminism in SIFixSGPRCopies (PR #70644)
https://github.com/jayfoad updated https://github.com/llvm/llvm-project/pull/70644 >From bfc7b2041f5a05105808b0b1ee0427d9c9eb9f4b Mon Sep 17 00:00:00 2001 From: Jay Foad Date: Mon, 30 Oct 2023 15:23:48 + Subject: [PATCH 1/4] Precommit test --- .../AMDGPU/fix-sgpr-copies-nondeterminism.ll | 52 +++ 1 file changed, 52 insertions(+) create mode 100644 llvm/test/CodeGen/AMDGPU/fix-sgpr-copies-nondeterminism.ll diff --git a/llvm/test/CodeGen/AMDGPU/fix-sgpr-copies-nondeterminism.ll b/llvm/test/CodeGen/AMDGPU/fix-sgpr-copies-nondeterminism.ll new file mode 100644 index 000..8b7e691dbddeae5 --- /dev/null +++ b/llvm/test/CodeGen/AMDGPU/fix-sgpr-copies-nondeterminism.ll @@ -0,0 +1,52 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 3 +; RUN: llc -mtriple=amdgcn -mcpu=gfx1100 < %s | FileCheck %s + +define amdgpu_gs void @f(i32 inreg %arg, i32 %arg1, i32 %arg2) { +; CHECK-LABEL: f: +; CHECK: ; %bb.0: ; %bb +; CHECK-NEXT:s_cmp_eq_u32 s0, 0 +; CHECK-NEXT:s_mov_b32 s0, 0 +; CHECK-NEXT:s_cbranch_scc1 .LBB0_2 +; CHECK-NEXT: ; %bb.1: ; %bb3 +; CHECK-NEXT:v_mov_b32_e32 v4, v1 +; CHECK-NEXT:s_branch .LBB0_3 +; CHECK-NEXT: .LBB0_2: +; CHECK-NEXT:v_mov_b32_e32 v0, 1 +; CHECK-NEXT:v_mov_b32_e32 v4, 0 +; CHECK-NEXT: .LBB0_3: ; %bb4 +; CHECK-NEXT:v_mov_b32_e32 v1, 0 +; CHECK-NEXT:s_mov_b32 s1, s0 +; CHECK-NEXT:s_mov_b32 s2, s0 +; CHECK-NEXT:s_mov_b32 s3, s0 +; CHECK-NEXT:s_delay_alu instid0(VALU_DEP_1) +; CHECK-NEXT:v_mov_b32_e32 v2, v1 +; CHECK-NEXT:v_mov_b32_e32 v3, v1 +; CHECK-NEXT:v_mov_b32_e32 v5, v1 +; CHECK-NEXT:v_mov_b32_e32 v6, v1 +; CHECK-NEXT:v_mov_b32_e32 v7, v1 +; CHECK-NEXT:s_clause 0x1 +; CHECK-NEXT:buffer_store_b128 v[0:3], v1, s[0:3], 0 idxen +; CHECK-NEXT:buffer_store_b128 v[4:7], v1, s[0:3], 0 idxen +; CHECK-NEXT:s_nop 0 +; CHECK-NEXT:s_sendmsg sendmsg(MSG_DEALLOC_VGPRS) +; CHECK-NEXT:s_endpgm +bb: + %i = icmp eq i32 %arg, 0 + br i1 %i, label %bb4, label %bb3 + +bb3: + br label %bb4 + +bb4: + %i5 = phi i32 [ %arg1, %bb3 ], [ 1, %bb ] + %i6 = phi i32 [ %arg2, %bb3 ], [ 0, %bb ] + %i7 = insertelement <4 x i32> zeroinitializer, i32 %i5, i64 0 + %i8 = bitcast <4 x i32> %i7 to <4 x float> + call void @llvm.amdgcn.struct.buffer.store.v4f32(<4 x float> %i8, <4 x i32> zeroinitializer, i32 0, i32 0, i32 0, i32 0) + %i9 = insertelement <4 x i32> zeroinitializer, i32 %i6, i64 0 + %i10 = bitcast <4 x i32> %i9 to <4 x float> + call void @llvm.amdgcn.struct.buffer.store.v4f32(<4 x float> %i10, <4 x i32> zeroinitializer, i32 0, i32 0, i32 0, i32 0) + ret void +} + +declare void @llvm.amdgcn.struct.buffer.store.v4f32(<4 x float>, <4 x i32>, i32, i32, i32, i32 immarg) >From aa050e8d720150b97d7af18d97d1d7f5d010bedc Mon Sep 17 00:00:00 2001 From: Jay Foad Date: Mon, 30 Oct 2023 10:40:22 + Subject: [PATCH 2/4] [AMDGPU] Fix nondeterminism in SIFixSGPRCopies There are a couple of loops that iterate over V2SCopies. The iteration order needs to be deterministic, otherwise we can call moveToVALU in different orders, which causes temporary vregs to be allocated in different orders, which can affect register allocation heuristics. --- llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp| 8 +++ .../AMDGPU/fix-sgpr-copies-nondeterminism.ll | 22 +-- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp b/llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp index b32ed9fef5dd34e..3e6ed2d793ae563 100644 --- a/llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp +++ b/llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp @@ -125,7 +125,7 @@ class SIFixSGPRCopies : public MachineFunctionPass { SmallVector PHINodes; SmallVector S2VCopies; unsigned NextVGPRToSGPRCopyID; - DenseMap V2SCopies; + MapVector V2SCopies; DenseMap> SiblingPenalty; public: @@ -988,7 +988,7 @@ bool SIFixSGPRCopies::needToBeConvertedToVALU(V2SCopyInfo *Info) { for (auto J : Info->Siblings) { auto InfoIt = V2SCopies.find(J); if (InfoIt != V2SCopies.end()) { - MachineInstr *SiblingCopy = InfoIt->getSecond().Copy; + MachineInstr *SiblingCopy = InfoIt->second.Copy; if (SiblingCopy->isImplicitDef()) // the COPY has already been MoveToVALUed continue; @@ -1023,12 +1023,12 @@ void SIFixSGPRCopies::lowerVGPR2SGPRCopies(MachineFunction &MF) { unsigned CurID = LoweringWorklist.pop_back_val(); auto CurInfoIt = V2SCopies.find(CurID); if (CurInfoIt != V2SCopies.end()) { - V2SCopyInfo C = CurInfoIt->getSecond(); + V2SCopyInfo C = CurInfoIt->second; LLVM_DEBUG(dbgs() << "Processing ...\n"; C.dump()); for (auto S : C.Siblings) { auto SibInfoIt = V2SCopies.find(S); if (SibInfoIt != V2SCopies.end()) { - V2SCopyInfo &SI = SibInfoIt->getSecond(); + V2SCopyInfo &SI = SibInfoIt->second; L
[clang] [llvm] [DebugMetadata][DwarfDebug] Clone uniqued function-local types after metadata loading (PR #68986)
@@ -731,6 +731,29 @@ class MetadataLoader::MetadataLoaderImpl { upgradeCULocals(); } + void cloneLocalTypes() { +for (int I = MetadataList.size() - 1; I >= 0; --I) { dzhidzhoev wrote: Sorry, it's just a residue from the function draft. Fixed that. https://github.com/llvm/llvm-project/pull/68986 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Fix clang++ crash on assertions when compiling source (PR #70594)
Rajveer100 wrote: Why are `clang-format` changes showing up for changes not committed by me? https://github.com/llvm/llvm-project/pull/70594 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [libc] [libcxx] [lldb] [flang] [compiler-rt] [clang-tools-extra] [clang] [AMDGPU] Fix nondeterminism in SIFixSGPRCopies (PR #70644)
https://github.com/jayfoad closed https://github.com/llvm/llvm-project/pull/70644 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [NFC] [Serializer] Pack information in serializer (PR #69287)
@@ -2005,14 +2039,7 @@ void ASTWriter::WriteDeclAbbrevs() { // Decl Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext - Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl - Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs - Abv->Add(BitCodeAbbrevOp(0)); // isImplicit - Abv->Add(BitCodeAbbrevOp(0)); // isUsed - Abv->Add(BitCodeAbbrevOp(0)); // isReferenced - Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // AccessSpecifier - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // ModuleOwnershipKind + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 11)); // Decl Bits vgvassilev wrote: These sections became a little harder to read. Perhaps we could keep the comments and this way the reader could probably do the math why this is 11 bits for example. https://github.com/llvm/llvm-project/pull/69287 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] c280bed - [clang-format] Fix annotating annotations after requires clause
Author: Björn Schäpers Date: 2023-10-31T13:10:46+01:00 New Revision: c280bed85a8b9cd6ebf48f9f2923890edc7039f0 URL: https://github.com/llvm/llvm-project/commit/c280bed85a8b9cd6ebf48f9f2923890edc7039f0 DIFF: https://github.com/llvm/llvm-project/commit/c280bed85a8b9cd6ebf48f9f2923890edc7039f0.diff LOG: [clang-format] Fix annotating annotations after requires clause Fixes #69325. Added: Modified: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/TokenAnnotatorTest.cpp Removed: diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index aee966145b8e518..729e7e370bf62ea 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -2101,7 +2101,8 @@ class AnnotatingParser { BeforeParen->isNot(TT_TypenameMacro) && BeforeParen->TokenText == BeforeParen->TokenText.upper() && (!BeforeParen->Previous || - BeforeParen->Previous->ClosesTemplateDeclaration)) { + BeforeParen->Previous->ClosesTemplateDeclaration || + BeforeParen->Previous->ClosesRequiresClause)) { Current.setType(TT_FunctionAnnotationRParen); } } diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index c16c7d64752458a..c9f1439e212b0ff 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -1376,6 +1376,20 @@ TEST_F(TokenAnnotatorTest, RequiresDoesNotChangeParsingOfTheRest) { "}"; RequiresTokenCount = 9; TestRequires(__LINE__); + + BaseCode = "template\n" + "ANNOTATE(\"S\"\n" + " \"S\")\n" + "void foo();"; + ConstrainedCode = "template\n" +" requires(true)\n" +"ANNOTATE(\"S\"\n" +" \"S\")\n" +"void foo();"; + BaseTokenCount = 16; + RequiresTokenCount = 4; + PrefixTokenCount = 5; + TestRequires(__LINE__); } TEST_F(TokenAnnotatorTest, UnderstandsAsm) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix annotating annotations after requires clause (PR #70602)
https://github.com/HazardyKnusperkeks closed https://github.com/llvm/llvm-project/pull/70602 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AMDGPU] Accept/Ignore any -mcmodel arguments. (PR #70760)
https://github.com/jhuber6 approved this pull request. https://github.com/llvm/llvm-project/pull/70760 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Fix uninitialized base class with initializer list when ctor is not declared in the base class (#70464) (PR #70792)
https://github.com/Snape3058 created https://github.com/llvm/llvm-project/pull/70792 When ctor is not declared in the base class, initializing the base class with the initializer list will not trigger a proper assignment of the base region, as a CXXConstructExpr doing that is not available in the AST. This patch checks whether the init expr is an InitListExpr under a base initializer, and adds a binding if so. >From 86002768f8926a65802ca5c6766e1da56179d0fd Mon Sep 17 00:00:00 2001 From: Ella Ma Date: Tue, 31 Oct 2023 18:41:14 +0800 Subject: [PATCH] [analyzer] Fix uninitialized base class with initializer list when ctor is not declared in the base class (#70464) When ctor is not declared in the base class, initializing the base class with initializer list will not trigger a proper assignment of the base region, as a CXXConstructExpr doing that is not available in the AST. This patch checks whether the init expr is a InitListExpr under a base initializer, and add a binding if so. --- clang/lib/StaticAnalyzer/Core/ExprEngine.cpp | 9 +++ clang/test/Analysis/issue-70464.cpp | 69 2 files changed, 78 insertions(+) create mode 100644 clang/test/Analysis/issue-70464.cpp diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp index 2e67fb953e45611..78dd1147ce1aa7c 100644 --- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -1222,6 +1222,15 @@ void ExprEngine::ProcessInitializer(const CFGInitializer CFGInit, PostInitializer PP(BMI, FieldLoc.getAsRegion(), stackFrame); evalBind(Tmp, Init, Pred, FieldLoc, InitVal, /*isInit=*/true, &PP); } + } else if (BMI->isBaseInitializer() && isa(Init)) { +// When the base class is initialized with an initialization list, there +// will not be a CXXConstructExpr to initialize the base region. Hence, we +// need to make the bind for it. +StoreManager &StoreMgr = State->getStateManager().getStoreManager(); +SVal BaseLoc = StoreMgr.evalDerivedToBase( +thisVal, QualType(BMI->getBaseClass(), 0), BMI->isBaseVirtual()); +SVal InitVal = State->getSVal(Init, stackFrame); +evalBind(Tmp, Init, Pred, BaseLoc, InitVal, true); } else { assert(BMI->isBaseInitializer() || BMI->isDelegatingInitializer()); Tmp.insert(Pred); diff --git a/clang/test/Analysis/issue-70464.cpp b/clang/test/Analysis/issue-70464.cpp new file mode 100644 index 000..0acced7ae102cac --- /dev/null +++ b/clang/test/Analysis/issue-70464.cpp @@ -0,0 +1,69 @@ +// Refer issue 70464 for more details. +// +// When the base class does not have a declared constructor, the base +// initializer in the constructor of the derived class should use the given +// initializer list to finish the initialization of the base class. +// +// Also testing base constructor and delegate constructor to make sure this +// change will not break these two cases when a CXXConstructExpr is available. + +// RUN: %clang_analyze_cc1 %s -verify -analyzer-checker=core,debug.ExprInspection + +void clang_analyzer_dump(int); + +namespace init_list { + +struct foo { + int foox; +}; + +class bar : public foo { +public: + bar() : foo{42} { +// The dereference to this->foox below should be initialized properly. +clang_analyzer_dump(this->foox); // expected-warning{{42 S32b}} + } +}; + +void entry() { bar test; } + +} // namespace init_list + +namespace base_ctor_call { + +void clang_analyzer_dump(int); + +struct foo { + int foox; + foo(int x) : foox(x) {} +}; + +class bar : public foo { +public: + bar() : foo{42} { +clang_analyzer_dump(this->foox); // expected-warning{{42 S32b}} + } +}; + +void entry() { bar test; } + +} // namespace base_ctor_call + +namespace delegate_ctor_call { + +void clang_analyzer_dump(int); + +struct foo { + int foox; +}; + +struct bar : foo { + bar(int parx) { this->foox = parx; } + bar() : bar{42} { +clang_analyzer_dump(this->foox); // expected-warning{{42 S32b}} + } +}; + +void entry() { bar test; } + +} // namespace delegate_ctor_call ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Fix uninitialized base class with initializer list when ctor is not declared in the base class (#70464) (PR #70792)
llvmbot wrote: @llvm/pr-subscribers-clang-static-analyzer-1 Author: Ella Ma (Snape3058) Changes When ctor is not declared in the base class, initializing the base class with the initializer list will not trigger a proper assignment of the base region, as a CXXConstructExpr doing that is not available in the AST. This patch checks whether the init expr is an InitListExpr under a base initializer, and adds a binding if so. --- Full diff: https://github.com/llvm/llvm-project/pull/70792.diff 2 Files Affected: - (modified) clang/lib/StaticAnalyzer/Core/ExprEngine.cpp (+9) - (added) clang/test/Analysis/issue-70464.cpp (+69) ``diff diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp index 2e67fb953e45611..78dd1147ce1aa7c 100644 --- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -1222,6 +1222,15 @@ void ExprEngine::ProcessInitializer(const CFGInitializer CFGInit, PostInitializer PP(BMI, FieldLoc.getAsRegion(), stackFrame); evalBind(Tmp, Init, Pred, FieldLoc, InitVal, /*isInit=*/true, &PP); } + } else if (BMI->isBaseInitializer() && isa(Init)) { +// When the base class is initialized with an initialization list, there +// will not be a CXXConstructExpr to initialize the base region. Hence, we +// need to make the bind for it. +StoreManager &StoreMgr = State->getStateManager().getStoreManager(); +SVal BaseLoc = StoreMgr.evalDerivedToBase( +thisVal, QualType(BMI->getBaseClass(), 0), BMI->isBaseVirtual()); +SVal InitVal = State->getSVal(Init, stackFrame); +evalBind(Tmp, Init, Pred, BaseLoc, InitVal, true); } else { assert(BMI->isBaseInitializer() || BMI->isDelegatingInitializer()); Tmp.insert(Pred); diff --git a/clang/test/Analysis/issue-70464.cpp b/clang/test/Analysis/issue-70464.cpp new file mode 100644 index 000..0acced7ae102cac --- /dev/null +++ b/clang/test/Analysis/issue-70464.cpp @@ -0,0 +1,69 @@ +// Refer issue 70464 for more details. +// +// When the base class does not have a declared constructor, the base +// initializer in the constructor of the derived class should use the given +// initializer list to finish the initialization of the base class. +// +// Also testing base constructor and delegate constructor to make sure this +// change will not break these two cases when a CXXConstructExpr is available. + +// RUN: %clang_analyze_cc1 %s -verify -analyzer-checker=core,debug.ExprInspection + +void clang_analyzer_dump(int); + +namespace init_list { + +struct foo { + int foox; +}; + +class bar : public foo { +public: + bar() : foo{42} { +// The dereference to this->foox below should be initialized properly. +clang_analyzer_dump(this->foox); // expected-warning{{42 S32b}} + } +}; + +void entry() { bar test; } + +} // namespace init_list + +namespace base_ctor_call { + +void clang_analyzer_dump(int); + +struct foo { + int foox; + foo(int x) : foox(x) {} +}; + +class bar : public foo { +public: + bar() : foo{42} { +clang_analyzer_dump(this->foox); // expected-warning{{42 S32b}} + } +}; + +void entry() { bar test; } + +} // namespace base_ctor_call + +namespace delegate_ctor_call { + +void clang_analyzer_dump(int); + +struct foo { + int foox; +}; + +struct bar : foo { + bar(int parx) { this->foox = parx; } + bar() : bar{42} { +clang_analyzer_dump(this->foox); // expected-warning{{42 S32b}} + } +}; + +void entry() { bar test; } + +} // namespace delegate_ctor_call `` https://github.com/llvm/llvm-project/pull/70792 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [time-trace] Add a new time trace scope variable named "ParseDeclarationOrFunctionDefinition". (PR #65268)
AaronBallman wrote: > Hi @nikic, thanks for spotting the issue and reverted the commit. > > Hi @AaronBallman, > > As @nikic mentioned that the issue is that the used strings may be expensive > to compute. If we remove the change to record the function name and function > location, I think the issue will be fixed. > > This means: > > 1. Remove the time trace scope variable of `ParseFunctionDefinition`. > > > ``` > llvm::TimeTraceScope TimeScope( > "ParseFunctionDefinition", > Actions.GetNameForDeclarator(D).getName().getAsString()); > ``` > > 2. Remove the source location for the time trace scope variable of > "ParseDeclarationOrFunctionDefinition". >Change: > > > ``` > llvm::TimeTraceScope TimeScope( > "ParseDeclarationOrFunctionDefinition", > Tok.getLocation().printToString( > Actions.getASTContext().getSourceManager())); > ``` > > To: > > ``` > llvm::TimeTraceScope TimeScope( > "ParseDeclarationOrFunctionDefinition"); > ``` > > Could you please let me know your thoughts? or any suggestion? > > Thanks, Maggie I think the suggestion from @nikic is to use the `TimeTraceScope` constructor accepting a function reference instead of the one accepting a string. e.g., change to using something like: ``` llvm::TimeTraceScope TimeScope( "ParseDeclarationOrFunctionDefinition", [&] { return Tok.getLocation().printToString( Actions.getASTContext().getSourceManager()) }); ``` https://github.com/llvm/llvm-project/pull/65268 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] ab1c97b - [AMDGPU] Accept/Ignore any -mcmodel arguments. (#70760)
Author: Pravin Jagtap Date: 2023-10-31T18:07:40+05:30 New Revision: ab1c97b6510c4ce4643469191080a16b4007244d URL: https://github.com/llvm/llvm-project/commit/ab1c97b6510c4ce4643469191080a16b4007244d DIFF: https://github.com/llvm/llvm-project/commit/ab1c97b6510c4ce4643469191080a16b4007244d.diff LOG: [AMDGPU] Accept/Ignore any -mcmodel arguments. (#70760) Authored-by: Pravin Jagtap Added: Modified: clang/lib/Driver/ToolChains/Clang.cpp Removed: diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index fb90fcd033b1ac3..79f7fba22570746 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -5743,9 +5743,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, } else if (Triple.getArch() == llvm::Triple::x86_64) { Ok = llvm::is_contained({"small", "kernel", "medium", "large", "tiny"}, CM); -} else if (Triple.isNVPTX()) { - // NVPTX does not care about the code model and will accept whatever works - // for the host. +} else if (Triple.isNVPTX() || Triple.isAMDGPU()) { + // NVPTX/AMDGPU does not care about the code model and will accept + // whatever works for the host. Ok = true; } if (Ok) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AMDGPU] Accept/Ignore any -mcmodel arguments. (PR #70760)
https://github.com/pravinjagtap closed https://github.com/llvm/llvm-project/pull/70760 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libc] [libcxx] [llvm] [clang] [flang] [clang-tools-extra] [compiler-rt] [LAA] Add a test case to show incorrect dependency classification (NFC). (PR #70473)
https://github.com/labrinea updated https://github.com/llvm/llvm-project/pull/70473 >From 454d423f0018db65dbbc0739ddf9ecbb8d38fef6 Mon Sep 17 00:00:00 2001 From: Alexandros Lamprineas Date: Fri, 27 Oct 2023 16:45:11 +0100 Subject: [PATCH] [LAA] Add a test case to show incorrect dependency classification (NFC). Currently the loop access analysis classifies this loop as unsafe to vectorize because the memory dependencies are 'ForwardButPreventsForwarding'. However, the access pattern is 'write-after-read' with no subsequent read accessing the written memory locations. I can't see how store-to-load forwarding is applicable here. void vectorizable_Read_Write(int *A) { for (unsigned i = 1022; i >= 0; i--) A[i+1] = A[i] + 1; } --- .../forward-negative-step.ll | 40 +++ 1 file changed, 40 insertions(+) create mode 100644 llvm/test/Analysis/LoopAccessAnalysis/forward-negative-step.ll diff --git a/llvm/test/Analysis/LoopAccessAnalysis/forward-negative-step.ll b/llvm/test/Analysis/LoopAccessAnalysis/forward-negative-step.ll new file mode 100644 index 000..89c1737fb730513 --- /dev/null +++ b/llvm/test/Analysis/LoopAccessAnalysis/forward-negative-step.ll @@ -0,0 +1,40 @@ +; RUN: opt -passes='print' -disable-output < %s 2>&1 | FileCheck %s + +target datalayout = "e-m:e-i64:64-i128:128-n32:64-S128" + +; FIXME: This should be vectorizable + +; void vectorizable_Read_Write(int *A) { +; for (unsigned i = 1022; i >= 0; i--) +;A[i+1] = A[i] + 1; +; } + +; CHECK: function 'vectorizable_Read_Write': +; CHECK-NEXT: for.body: +; CHECK-NEXT: Report: unsafe dependent memory operations in loop +; CHECK-NEXT: Forward loop carried data dependence that prevents store-to-load forwarding. +; CHECK-NEXT: Dependences: +; CHECK-NEXT: ForwardButPreventsForwarding: +; CHECK-NEXT: %0 = load i32, ptr %arrayidx, align 4 -> +; CHECK-NEXT: store i32 %add, ptr %gep, align 4 + +define void @vectorizable_Read_Write(ptr nocapture %A) { +entry: + %invariant.gep = getelementptr i32, ptr %A, i64 1 + br label %for.body + +for.cond.cleanup: + ret void + +for.body: + %indvars.iv = phi i64 [ 1022, %entry ], [ %indvars.iv.next, %for.body ] + %arrayidx = getelementptr inbounds i32, ptr %A, i64 %indvars.iv + %0 = load i32, ptr %arrayidx, align 4 + %add = add nsw i32 %0, 1 + %gep = getelementptr i32, ptr %invariant.gep, i64 %indvars.iv + store i32 %add, ptr %gep, align 4 + %indvars.iv.next = add nsw i64 %indvars.iv, -1 + %cmp.not = icmp eq i64 %indvars.iv, 0 + br i1 %cmp.not, label %for.cond.cleanup, label %for.body +} + ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [Clangd] Sanitize path before recording into IncludeStructure during buildPreamble (PR #70798)
https://github.com/Maddobun created https://github.com/llvm/llvm-project/pull/70798 Addresses https://github.com/clangd/clangd/issues/1800, where mismatching drive letter case can cause command inference for header files to fail on windows. >From 65c1b38c4eb83469794e53328caed492e956a728 Mon Sep 17 00:00:00 2001 From: Leo Zhu Date: Mon, 30 Oct 2023 16:50:57 -0400 Subject: [PATCH] Sanitize path before recording into IncludeStructure addresses https://github.com/clangd/clangd/issues/1800 --- clang-tools-extra/clangd/Headers.cpp | 7 --- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/clang-tools-extra/clangd/Headers.cpp b/clang-tools-extra/clangd/Headers.cpp index 6005069be01160d..5af7abd71ae1097 100644 --- a/clang-tools-extra/clangd/Headers.cpp +++ b/clang-tools-extra/clangd/Headers.cpp @@ -9,6 +9,7 @@ #include "Headers.h" #include "Preamble.h" #include "SourceCode.h" +#include "support/Logger.h" #include "clang/Basic/SourceLocation.h" #include "clang/Basic/SourceManager.h" #include "clang/Frontend/CompilerInstance.h" @@ -56,7 +57,7 @@ class IncludeStructure::RecordHeaders : public PPCallbacks { Inc.Written = (IsAngled ? "<" + FileName + ">" : "\"" + FileName + "\"").str(); Inc.Resolved = std::string( - File ? getCanonicalPath(*File, SM.getFileManager()).value_or("") + File ? maybeCaseFoldPath(getCanonicalPath(*File, SM.getFileManager()).value_or("")) : ""); Inc.HashOffset = SM.getFileOffset(HashLoc); Inc.HashLine = @@ -208,7 +209,7 @@ IncludeStructure::HeaderID IncludeStructure::getOrCreateID(FileEntryRef Entry) { // Main file's FileEntry was not known at IncludeStructure creation time. if (&Entry.getFileEntry() == MainFileEntry) { if (RealPathNames.front().empty()) - RealPathNames.front() = MainFileEntry->tryGetRealPathName().str(); + RealPathNames.front() = maybeCaseFoldPath(MainFileEntry->tryGetRealPathName().str()); return MainFileID; } auto R = UIDToIndex.try_emplace( @@ -219,7 +220,7 @@ IncludeStructure::HeaderID IncludeStructure::getOrCreateID(FileEntryRef Entry) { IncludeStructure::HeaderID Result = R.first->getSecond(); std::string &RealPathName = RealPathNames[static_cast(Result)]; if (RealPathName.empty()) -RealPathName = Entry.getFileEntry().tryGetRealPathName().str(); +RealPathName = maybeCaseFoldPath(Entry.getFileEntry().tryGetRealPathName().str()); return Result; } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [StackProtector] Do not emit the stack protector on GPU architectures (PR #70799)
https://github.com/jhuber6 created https://github.com/llvm/llvm-project/pull/70799 Summary: This patch changes the code generation to not emit the stack protector metadata on unsupported architectures. The issue was caused by system toolchains emitting stack protector option by default which would lead to errors when compiling for the GPU. I elected to change the code generation as we may want to update this in the future so we should keep the `clang` Driver code common. Although the user can use some combination of `-Xarch-device -fno-stack-protector` to override this, it is very irritating to do when we shouldn't emit this incompatible IR anyway. Fixes: https://github.com/llvm/llvm-project/issues/65911 >From c1c5174d9a9bb82ba42de0aabd0a3e129cc87aa5 Mon Sep 17 00:00:00 2001 From: Joseph Huber Date: Tue, 31 Oct 2023 08:12:01 -0500 Subject: [PATCH] [StackProtector] Do not emit the stack protector on GPU architectures Summary: This patch changes the code generation to not emit the stack protector metadata on unsupported architectures. The issue was caused by system toolchains emitting stack protector option by default which would lead to errors when compiling for the GPU. I elected to change the code generation as we may want to update this in the future so we should keep the `clang` Driver code common. Although the user can use some combination of `-Xarch-device -fno-stack-protector` to override this, it is very irritating to do when we shouldn't emit this incompatible IR anyway. Fixes: https://github.com/llvm/llvm-project/issues/65911 --- clang/lib/CodeGen/CodeGenModule.cpp | 15 +++ 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index b1a6683a66bd052..562f421aa2c36e8 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -761,6 +761,13 @@ static void setVisibilityFromDLLStorageClass(const clang::LangOptions &LO, } } +static bool isStackProtectorOn(const LangOptions &LangOpts, const llvm::Triple &Triple, + clang::LangOptions::StackProtectorMode Mode) { + if (Triple.isAMDGPU() || Triple.isNVPTX()) +return false; + return LangOpts.getStackProtector() == Mode; +} + void CodeGenModule::Release() { Module *Primary = getContext().getCurrentNamedModule(); if (CXX20ModuleInits && Primary && !Primary->isHeaderLikeModule()) @@ -2296,13 +2303,13 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D, if (D && D->hasAttr()) ; // Do nothing. else if (D && D->hasAttr() && - LangOpts.getStackProtector() == LangOptions::SSPOn) + isStackProtectorOn(LangOpts, getTriple(), LangOptions::SSPOn)) B.addAttribute(llvm::Attribute::StackProtectStrong); - else if (LangOpts.getStackProtector() == LangOptions::SSPOn) + else if (isStackProtectorOn(LangOpts, getTriple(), LangOptions::SSPOn)) B.addAttribute(llvm::Attribute::StackProtect); - else if (LangOpts.getStackProtector() == LangOptions::SSPStrong) + else if (isStackProtectorOn(LangOpts, getTriple(), LangOptions::SSPStrong)) B.addAttribute(llvm::Attribute::StackProtectStrong); - else if (LangOpts.getStackProtector() == LangOptions::SSPReq) + else if (isStackProtectorOn(LangOpts, getTriple(), LangOptions::SSPReq)) B.addAttribute(llvm::Attribute::StackProtectReq); if (!D) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [StackProtector] Do not emit the stack protector on GPU architectures (PR #70799)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Joseph Huber (jhuber6) Changes Summary: This patch changes the code generation to not emit the stack protector metadata on unsupported architectures. The issue was caused by system toolchains emitting stack protector option by default which would lead to errors when compiling for the GPU. I elected to change the code generation as we may want to update this in the future so we should keep the `clang` Driver code common. Although the user can use some combination of `-Xarch-device -fno-stack-protector` to override this, it is very irritating to do when we shouldn't emit this incompatible IR anyway. Fixes: https://github.com/llvm/llvm-project/issues/65911 --- Full diff: https://github.com/llvm/llvm-project/pull/70799.diff 1 Files Affected: - (modified) clang/lib/CodeGen/CodeGenModule.cpp (+11-4) ``diff diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index b1a6683a66bd052..562f421aa2c36e8 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -761,6 +761,13 @@ static void setVisibilityFromDLLStorageClass(const clang::LangOptions &LO, } } +static bool isStackProtectorOn(const LangOptions &LangOpts, const llvm::Triple &Triple, + clang::LangOptions::StackProtectorMode Mode) { + if (Triple.isAMDGPU() || Triple.isNVPTX()) +return false; + return LangOpts.getStackProtector() == Mode; +} + void CodeGenModule::Release() { Module *Primary = getContext().getCurrentNamedModule(); if (CXX20ModuleInits && Primary && !Primary->isHeaderLikeModule()) @@ -2296,13 +2303,13 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D, if (D && D->hasAttr()) ; // Do nothing. else if (D && D->hasAttr() && - LangOpts.getStackProtector() == LangOptions::SSPOn) + isStackProtectorOn(LangOpts, getTriple(), LangOptions::SSPOn)) B.addAttribute(llvm::Attribute::StackProtectStrong); - else if (LangOpts.getStackProtector() == LangOptions::SSPOn) + else if (isStackProtectorOn(LangOpts, getTriple(), LangOptions::SSPOn)) B.addAttribute(llvm::Attribute::StackProtect); - else if (LangOpts.getStackProtector() == LangOptions::SSPStrong) + else if (isStackProtectorOn(LangOpts, getTriple(), LangOptions::SSPStrong)) B.addAttribute(llvm::Attribute::StackProtectStrong); - else if (LangOpts.getStackProtector() == LangOptions::SSPReq) + else if (isStackProtectorOn(LangOpts, getTriple(), LangOptions::SSPReq)) B.addAttribute(llvm::Attribute::StackProtectReq); if (!D) { `` https://github.com/llvm/llvm-project/pull/70799 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [LoongArch] Fix ABI mismatch with gcc/g++ about empty structs passing (PR #70320)
SixWeining wrote: > LGTM. I've no permission to make a formal ("GitHub style") approval. Thanks. You can request to join the llvm organization via https://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access firstly. Then you can make formal ("Github style") approval. https://github.com/llvm/llvm-project/pull/70320 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 9ca6bf3 - [LoongArch] Fix ABI mismatch with gcc/g++ about empty structs passing (#70320)
Author: Lu Weining Date: 2023-10-31T21:18:06+08:00 New Revision: 9ca6bf3fb7b7df373723b3275730f101f9ff816b URL: https://github.com/llvm/llvm-project/commit/9ca6bf3fb7b7df373723b3275730f101f9ff816b DIFF: https://github.com/llvm/llvm-project/commit/9ca6bf3fb7b7df373723b3275730f101f9ff816b.diff LOG: [LoongArch] Fix ABI mismatch with gcc/g++ about empty structs passing (#70320) How empty structs (not as fields of container struct) are passed in C++ is not explicitly documented in psABI. However, this patch fixes the mismatch with g++. Note that the unnamed bitfield case `struct { int : 1; }` in C is also fixed. Previously clang regards it as an empty struct and then ignores it when passing. Now size of the struct is counted; since it's size is not 0, clang will not ignore it even in C. While https://reviews.llvm.org/D156116 fixed the handling of empty struct when considering eligibility of the container struct for the FP calling convention ('flattening'), this patch fixes the handling of passing the empty struct itself. Fix https://github.com/llvm/llvm-project/issues/70319 Added: Modified: clang/lib/CodeGen/Targets/LoongArch.cpp clang/test/CodeGen/LoongArch/abi-lp64d-empty-structs.c Removed: diff --git a/clang/lib/CodeGen/Targets/LoongArch.cpp b/clang/lib/CodeGen/Targets/LoongArch.cpp index 26c68c3583b2a19..c4d886eb40725f8 100644 --- a/clang/lib/CodeGen/Targets/LoongArch.cpp +++ b/clang/lib/CodeGen/Targets/LoongArch.cpp @@ -308,12 +308,14 @@ ABIArgInfo LoongArchABIInfo::classifyArgumentType(QualType Ty, bool IsFixed, CGCXXABI::RAA_DirectInMemory); } - // Ignore empty structs/unions. - if (isEmptyRecord(getContext(), Ty, true)) -return ABIArgInfo::getIgnore(); - uint64_t Size = getContext().getTypeSize(Ty); + // Ignore empty struct or union whose size is zero, e.g. `struct { }` in C or + // `struct { int a[0]; }` in C++. In C++, `struct { }` is empty but it's size + // is 1 byte and g++ doesn't ignore it; clang++ matches this behaviour. + if (isEmptyRecord(getContext(), Ty, true) && Size == 0) +return ABIArgInfo::getIgnore(); + // Pass floating point values via FARs if possible. if (IsFixed && Ty->isFloatingType() && !Ty->isComplexType() && FRLen >= Size && FARsLeft) { diff --git a/clang/test/CodeGen/LoongArch/abi-lp64d-empty-structs.c b/clang/test/CodeGen/LoongArch/abi-lp64d-empty-structs.c index d0daafac336ec0c..281b7b15841a999 100644 --- a/clang/test/CodeGen/LoongArch/abi-lp64d-empty-structs.c +++ b/clang/test/CodeGen/LoongArch/abi-lp64d-empty-structs.c @@ -93,7 +93,7 @@ struct s9 test_s9(struct s9 a) { } // CHECK-C: define{{.*}} void @test_s10() -// CHECK-CXX: define{{.*}} void @_Z8test_s103s10() +// CHECK-CXX: define{{.*}} i64 @_Z8test_s103s10(i64 {{.*}}) struct s10 { }; struct s10 test_s10(struct s10 a) { return a; @@ -128,14 +128,14 @@ struct s14 test_s14(struct s14 a) { } // CHECK-C: define{{.*}} void @test_s15() -// CHECK-CXX: define{{.*}} void @_Z8test_s153s15() +// CHECK-CXX: define{{.*}} i64 @_Z8test_s153s15(i64 {{.*}}) struct s15 { int : 0; }; struct s15 test_s15(struct s15 a) { return a; } -// CHECK-C: define{{.*}} void @test_s16() -// CHECK-CXX: define{{.*}} void @_Z8test_s163s16() +// CHECK-C: define{{.*}} i64 @test_s16(i64 {{.*}}) +// CHECK-CXX: define{{.*}} i64 @_Z8test_s163s16(i64 {{.*}}) struct s16 { int : 1; }; struct s16 test_s16(struct s16 a) { return a; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [LoongArch] Fix ABI mismatch with gcc/g++ about empty structs passing (PR #70320)
https://github.com/SixWeining closed https://github.com/llvm/llvm-project/pull/70320 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [StackProtector] Do not emit the stack protector on GPU architectures (PR #70799)
https://github.com/jhuber6 updated https://github.com/llvm/llvm-project/pull/70799 >From c791e527ee388659b35707816c0a67bee66dd0da Mon Sep 17 00:00:00 2001 From: Joseph Huber Date: Tue, 31 Oct 2023 08:12:01 -0500 Subject: [PATCH] [StackProtector] Do not emit the stack protector on GPU architectures Summary: This patch changes the code generation to not emit the stack protector metadata on unsupported architectures. The issue was caused by system toolchains emitting stack protector option by default which would lead to errors when compiling for the GPU. I elected to change the code generation as we may want to update this in the future so we should keep the `clang` Driver code common. Although the user can use some combination of `-Xarch-device -fno-stack-protector` to override this, it is very irritating to do when we shouldn't emit this incompatible IR anyway. Fixes: https://github.com/llvm/llvm-project/issues/65911 --- clang/lib/CodeGen/CodeGenModule.cpp | 16 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index b1a6683a66bd052..db4e0d6552a4264 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -761,6 +761,14 @@ static void setVisibilityFromDLLStorageClass(const clang::LangOptions &LO, } } +static bool isStackProtectorOn(const LangOptions &LangOpts, + const llvm::Triple &Triple, + clang::LangOptions::StackProtectorMode Mode) { + if (Triple.isAMDGPU() || Triple.isNVPTX()) +return false; + return LangOpts.getStackProtector() == Mode; +} + void CodeGenModule::Release() { Module *Primary = getContext().getCurrentNamedModule(); if (CXX20ModuleInits && Primary && !Primary->isHeaderLikeModule()) @@ -2296,13 +2304,13 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D, if (D && D->hasAttr()) ; // Do nothing. else if (D && D->hasAttr() && - LangOpts.getStackProtector() == LangOptions::SSPOn) + isStackProtectorOn(LangOpts, getTriple(), LangOptions::SSPOn)) B.addAttribute(llvm::Attribute::StackProtectStrong); - else if (LangOpts.getStackProtector() == LangOptions::SSPOn) + else if (isStackProtectorOn(LangOpts, getTriple(), LangOptions::SSPOn)) B.addAttribute(llvm::Attribute::StackProtect); - else if (LangOpts.getStackProtector() == LangOptions::SSPStrong) + else if (isStackProtectorOn(LangOpts, getTriple(), LangOptions::SSPStrong)) B.addAttribute(llvm::Attribute::StackProtectStrong); - else if (LangOpts.getStackProtector() == LangOptions::SSPReq) + else if (isStackProtectorOn(LangOpts, getTriple(), LangOptions::SSPReq)) B.addAttribute(llvm::Attribute::StackProtectReq); if (!D) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [Clangd] Sanitize path before recording into IncludeStructure during buildPreamble (PR #70798)
https://github.com/Maddobun edited https://github.com/llvm/llvm-project/pull/70798 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Fix uninitialized base class with initializer list when ctor is not declared in the base class (#70464) (PR #70792)
https://github.com/steakhal requested changes to this pull request. I must admit that I didn't look at the issue too much, but this patch speaks for itself. Clean, to the point, and meets our conventions. Kudos. I only have minor remarks. And be sure to mention `Fixes #70464` in the PR/commit message to auto-close the issue. https://github.com/llvm/llvm-project/pull/70792 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Fix uninitialized base class with initializer list when ctor is not declared in the base class (#70464) (PR #70792)
https://github.com/steakhal edited https://github.com/llvm/llvm-project/pull/70792 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits