[clang] [llvm] [clang][DependencyScanner] Remove unused -ivfsoverlay files (PR #73734)

2024-01-25 Thread Michael Spencer via cfe-commits

https://github.com/Bigcheese updated 
https://github.com/llvm/llvm-project/pull/73734

>From 3c7f36b087e09e1b7ab3231e8267bcdd8400fac4 Mon Sep 17 00:00:00 2001
From: Michael Spencer 
Date: Fri, 24 Feb 2023 17:18:51 -0800
Subject: [PATCH] [clang][DepScan] Remove unused -ivfsoverlay files

`-ivfsoverlay` files are unused when building most modules. Enable
removing them by,
* adding a way to visit the filesystem tree with extensible RTTI to
  access each `RedirectingFileSystem`.
* Adding tracking to `RedirectingFileSystem` to record when it
  actually redirects a file access.
* Storing this information in each PCM.

Usage tracking is only enabled when iterating over the source manager
and affecting modulemaps. Here each path is stated to cause an access.
During scanning these stats all hit the cache.
---
 .../Basic/DiagnosticSerializationKinds.td |   3 +
 clang/include/clang/Basic/FileManager.h   |   4 +
 clang/include/clang/Lex/HeaderSearch.h|   6 +
 .../include/clang/Serialization/ASTBitCodes.h |   3 +
 clang/include/clang/Serialization/ASTReader.h |   6 +-
 .../include/clang/Serialization/ModuleFile.h  |   3 +
 .../DependencyScanningFilesystem.h|   6 +-
 .../DependencyScanningService.h   |  11 +-
 clang/lib/Basic/FileManager.cpp   |   7 +
 clang/lib/Frontend/CompilerInvocation.cpp |   1 +
 clang/lib/Lex/HeaderSearch.cpp|  16 ++
 clang/lib/Serialization/ASTReader.cpp |  41 ++--
 clang/lib/Serialization/ASTWriter.cpp |  35 +++-
 .../DependencyScanningFilesystem.cpp  |   6 +-
 .../DependencyScanningWorker.cpp  |  74 +--
 .../DependencyScanning/ModuleDepCollector.cpp |  74 +--
 .../ClangScanDeps/optimize-vfs-edgecases.m|  84 
 clang/test/ClangScanDeps/optimize-vfs-leak.m  | 105 ++
 clang/test/ClangScanDeps/optimize-vfs-pch.m   | 129 
 clang/test/ClangScanDeps/optimize-vfs.m   | 193 ++
 clang/tools/clang-scan-deps/ClangScanDeps.cpp |   1 +
 llvm/include/llvm/Support/VirtualFileSystem.h |  55 -
 llvm/lib/Support/VirtualFileSystem.cpp|  26 +++
 .../Support/VirtualFileSystemTest.cpp |  84 
 24 files changed, 906 insertions(+), 67 deletions(-)
 create mode 100644 clang/test/ClangScanDeps/optimize-vfs-edgecases.m
 create mode 100644 clang/test/ClangScanDeps/optimize-vfs-leak.m
 create mode 100644 clang/test/ClangScanDeps/optimize-vfs-pch.m
 create mode 100644 clang/test/ClangScanDeps/optimize-vfs.m

diff --git a/clang/include/clang/Basic/DiagnosticSerializationKinds.td 
b/clang/include/clang/Basic/DiagnosticSerializationKinds.td
index 11c706ebf84b542..4c4659ed517e0a0 100644
--- a/clang/include/clang/Basic/DiagnosticSerializationKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSerializationKinds.td
@@ -44,6 +44,9 @@ def err_pch_diagopt_mismatch : Error<"%0 is currently 
enabled, but was not in "
   "the PCH file">;
 def err_pch_modulecache_mismatch : Error<"PCH was compiled with module cache "
   "path '%0', but the path is currently '%1'">;
+def err_pch_vfsoverlay_mismatch : Error<"PCH was compiled with different VFS 
overlay files than are currently in use">;
+def note_pch_vfsoverlay_files : Note<"%select{PCH|current translation unit}0 
has the following VFS overlays:\n%1">;
+def note_pch_vfsoverlay_empty : Note<"%select{PCH|current translation unit}0 
has no VFS overlays">;
 
 def err_pch_version_too_old : Error<
 "PCH file uses an older PCH format that is no longer supported">;
diff --git a/clang/include/clang/Basic/FileManager.h 
b/clang/include/clang/Basic/FileManager.h
index 56cb093dd8c376f..997c17a0ffcfcce 100644
--- a/clang/include/clang/Basic/FileManager.h
+++ b/clang/include/clang/Basic/FileManager.h
@@ -248,6 +248,10 @@ class FileManager : public RefCountedBase {
 return FS;
   }
 
+  /// Enable or disable tracking of VFS usage. Used to not track full header
+  /// search and implicit modulemap lookup.
+  void trackVFSUsage(bool Active);
+
   void setVirtualFileSystem(IntrusiveRefCntPtr FS) {
 this->FS = std::move(FS);
   }
diff --git a/clang/include/clang/Lex/HeaderSearch.h 
b/clang/include/clang/Lex/HeaderSearch.h
index a2c33842924b101..49e1a4a124b55df 100644
--- a/clang/include/clang/Lex/HeaderSearch.h
+++ b/clang/include/clang/Lex/HeaderSearch.h
@@ -576,6 +576,12 @@ class HeaderSearch {
   /// Note: implicit module maps don't contribute to entry usage.
   std::vector computeUserEntryUsage() const;
 
+  /// Determine which HeaderSearchOptions::VFSOverlayFiles have been
+  /// successfully used so far and mark their index with 'true' in the 
resulting
+  /// bit vector.
+  /// Note: implicit module maps don't contribute to entry usage.
+  std::vector computeVFSUsageAndClear() const;
+
   /// This method returns a HeaderMap for the specified
   /// FileEntry, uniquing them through the 'HeaderMaps' datastructure.
   const HeaderMap *CreateHeaderMap(FileEntryRef FE);
diff --git a/clang/include/clang/

[clang] [llvm] [clang][DependencyScanner] Remove unused -ivfsoverlay files (PR #73734)

2024-01-25 Thread via cfe-commits

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 df08350dcfc515c5a7c08e1e08047467263cb701 
3c7f36b087e09e1b7ab3231e8267bcdd8400fac4 -- 
clang/include/clang/Basic/FileManager.h clang/include/clang/Lex/HeaderSearch.h 
clang/include/clang/Serialization/ASTBitCodes.h 
clang/include/clang/Serialization/ASTReader.h 
clang/include/clang/Serialization/ModuleFile.h 
clang/include/clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h 
clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h 
clang/lib/Basic/FileManager.cpp clang/lib/Frontend/CompilerInvocation.cpp 
clang/lib/Lex/HeaderSearch.cpp clang/lib/Serialization/ASTReader.cpp 
clang/lib/Serialization/ASTWriter.cpp 
clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp 
clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp 
clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp 
clang/tools/clang-scan-deps/ClangScanDeps.cpp 
llvm/include/llvm/Support/VirtualFileSystem.h 
llvm/lib/Support/VirtualFileSystem.cpp 
llvm/unittests/Support/VirtualFileSystemTest.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index 117f50e3b7..c09869934b 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -1780,13 +1780,13 @@ public:
   /// Read the control block for the named AST file.
   ///
   /// \returns true if an error occurred, false otherwise.
-  static bool readASTFileControlBlock(StringRef Filename, FileManager &FileMgr,
-  const InMemoryModuleCache &ModuleCache,
-  const PCHContainerReader 
&PCHContainerRdr,
-  bool FindModuleFileExtensions,
-  ASTReaderListener &Listener,
-  bool ValidateDiagnosticOptions,
-  unsigned DefaultClientLoadCapabilities = 
ARR_ConfigurationMismatch | ARR_OutOfDate);
+  static bool readASTFileControlBlock(
+  StringRef Filename, FileManager &FileMgr,
+  const InMemoryModuleCache &ModuleCache,
+  const PCHContainerReader &PCHContainerRdr, bool FindModuleFileExtensions,
+  ASTReaderListener &Listener, bool ValidateDiagnosticOptions,
+  unsigned DefaultClientLoadCapabilities = ARR_ConfigurationMismatch |
+   ARR_OutOfDate);
 
   /// Determine whether the given AST file is acceptable to load into a
   /// translation unit with the given language and target options.
diff --git 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h
index b1409f9d6a..4f9867262a 100644
--- a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h
+++ b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h
@@ -45,8 +45,8 @@ enum class ScanningOutputFormat {
   P1689,
 };
 
-#define DSS_LAST_BITMASK_ENUM(Id) LLVM_MARK_AS_BITMASK_ENUM(Id), \
-  All = llvm::NextPowerOf2(Id) - 1
+#define DSS_LAST_BITMASK_ENUM(Id)  
\
+  LLVM_MARK_AS_BITMASK_ENUM(Id), All = llvm::NextPowerOf2(Id) - 1
 
 enum class ScanningOptimizations {
   None = 0,
diff --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index 8e61caedf9..8fc6e726c1 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -4701,7 +4701,8 @@ void ASTWriter::collectNonAffectingInputFiles() {
 
   FileManager &FileMgr = PP->getFileManager();
   FileMgr.trackVFSUsage(true);
-  for (StringRef Path : 
PP->getHeaderSearchInfo().getHeaderSearchOpts().VFSOverlayFiles)
+  for (StringRef Path :
+   PP->getHeaderSearchInfo().getHeaderSearchOpts().VFSOverlayFiles)
 FileMgr.getVirtualFileSystem().exists(Path);
 
   for (unsigned I = 1; I != N; ++I) {
@@ -4720,7 +4721,8 @@ void ASTWriter::collectNonAffectingInputFiles() {
 AffectingModuleMaps.empty() ||
 llvm::is_contained(AffectingModuleMaps, *Cache->OrigEntry)) {
   // Lookup the path in the VFS to trigger `-ivfsoverlay` usage tracking.
-  
FileMgr.getVirtualFileSystem().exists(File.getContentCache().OrigEntry->getNameAsRequested());
+  FileMgr.getVirtualFileSystem().exists(
+  File.getContentCache().OrigEntry->getNameAsRequested());
   continue;
 }
 
diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp 
b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
index d5511ef3c9..7f54f36eff 100644
--- a/clang/lib/Tooling/Depe

[llvm] [clang] [clang][DependencyScanner] Remove unused -ivfsoverlay files (PR #73734)

2024-01-25 Thread Michael Spencer via cfe-commits

Bigcheese wrote:

I've updated the patch to use the alternative implementation Jan suggested.

https://github.com/llvm/llvm-project/pull/73734
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][analyzer] Improve modeling of 'popen' and 'pclose' in StdLibraryFunctionsChecker (PR #78895)

2024-01-25 Thread Balázs Kéri via cfe-commits


@@ -2211,6 +2221,15 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
   ErrnoNEZeroIrrelevant, GenericFailureMsg)
 .ArgConstraint(NotNull(ArgNo(0;
 
+// int pclose(FILE *stream);
+addToFunctionSummaryMap(
+"pclose", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
+Summary(NoEvalCall)
+.Case({ReturnValueCondition(WithinRange, {{0, IntMax}})},
+  ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
+.ArgConstraint(NotNull(ArgNo(0;
+

balazske wrote:

The POSIX documentation does not tell if it is possible to get negative value 
from `fclose` other than -1. Because -1 is reserved for indication of error, it 
should not be a regular return value (if yes, there should be mentioned that 
`errno` is not changed at success, to make detection of error possible). If 
negative non-error return value is allowed, it can not be -1.
It looks like that negative return values from the process appear as positive 
values like in the example above. The returned value is not the value passed to 
`exit`, that can be extracted by `WEXITSTATUS` (see `waitpid`).

https://github.com/llvm/llvm-project/pull/78895
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][PowerPC] Add flag to enable compatibility with GNU for complex arguments (PR #77732)

2024-01-25 Thread Kishan Parmar via cfe-commits

Long5hot wrote:

ping! @chmeeedalf @nemanjai 

https://github.com/llvm/llvm-project/pull/77732
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Improved isSimpleTypeSpecifier (PR #79037)

2024-01-25 Thread Carl Peto via cfe-commits

https://github.com/carlos4242 updated 
https://github.com/llvm/llvm-project/pull/79037

>From 61a06b77e8e6f2b5c5a9a2aa0b7f46260545f5b4 Mon Sep 17 00:00:00 2001
From: Carl Peto 
Date: Mon, 22 Jan 2024 18:52:46 +
Subject: [PATCH 1/2] [clang] - Sema::isSimpleTypeSpecifier return true for
 _Bool in c99 (currently returns false for _Bool, regardless of C dialect).
 (Fixes #72203) - move simple type decision code into shared location
 (IdentifierInfo) - replace the logic with a check for simple types and a
 proper check for a valid keyword in the appropriate dialect - change all call
 sites to match the above new API

---
 clang/include/clang/Basic/IdentifierTable.h |  4 ++
 clang/include/clang/Sema/Sema.h |  2 +-
 clang/lib/Basic/IdentifierTable.cpp | 39 +
 clang/lib/Parse/ParseExpr.cpp   |  3 +-
 clang/lib/Parse/ParseObjc.cpp   |  3 +-
 clang/lib/Sema/SemaDecl.cpp | 48 +
 6 files changed, 50 insertions(+), 49 deletions(-)

diff --git a/clang/include/clang/Basic/IdentifierTable.h 
b/clang/include/clang/Basic/IdentifierTable.h
index 1ac182d4fce26f6..2c979e438e81bb3 100644
--- a/clang/include/clang/Basic/IdentifierTable.h
+++ b/clang/include/clang/Basic/IdentifierTable.h
@@ -427,6 +427,10 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
   /// language.
   bool isCPlusPlusKeyword(const LangOptions &LangOpts) const;
 
+  /// Return true if this token is a simple type specifier
+  /// in the specified language.
+  bool isSimpleTypeSpecifier(const LangOptions &LangOpts) const;
+
   /// Get and set FETokenInfo. The language front-end is allowed to associate
   /// arbitrary metadata with this token.
   void *getFETokenInfo() const { return FETokenInfo; }
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 0db39333b0ee347..bc1fd19b5c6de7b 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2636,7 +2636,7 @@ class Sema final {
 
   void DiagnoseUseOfUnimplementedSelectors();
 
-  bool isSimpleTypeSpecifier(tok::TokenKind Kind) const;
+  bool isSimpleTypeSpecifier(const IdentifierInfo &II) const;
 
   ParsedType getTypeName(const IdentifierInfo &II, SourceLocation NameLoc,
  Scope *S, CXXScopeSpec *SS = nullptr,
diff --git a/clang/lib/Basic/IdentifierTable.cpp 
b/clang/lib/Basic/IdentifierTable.cpp
index d0d8316385b452f..78c783cdff6b5ea 100644
--- a/clang/lib/Basic/IdentifierTable.cpp
+++ b/clang/lib/Basic/IdentifierTable.cpp
@@ -419,6 +419,45 @@ StringRef IdentifierInfo::deuglifiedName() const {
   return Name;
 }
 
+/// Determine whether the token kind starts a simple-type-specifier.
+bool IdentifierInfo::isSimpleTypeSpecifier(const LangOptions &LangOpts) const {
+  auto Kind = getTokenID();
+
+  switch (Kind) {
+  case tok::kw_short:
+  case tok::kw_long:
+  case tok::kw___int64:
+  case tok::kw___int128:
+  case tok::kw_signed:
+  case tok::kw_unsigned:
+  case tok::kw_void:
+  case tok::kw_char:
+  case tok::kw_int:
+  case tok::kw_half:
+  case tok::kw_float:
+  case tok::kw_double:
+  case tok::kw___bf16:
+  case tok::kw__Float16:
+  case tok::kw___float128:
+  case tok::kw_wchar_t:
+  case tok::kw_bool:
+  case tok::kw___underlying_type:
+  case tok::kw___auto_type:
+  case tok::kw__Bool:
+  case tok::annot_typename:
+  case tok::kw_char16_t:
+  case tok::kw_char32_t:
+  case tok::kw_typeof:
+  case tok::annot_decltype:
+  case tok::kw_decltype:
+  case tok::kw_char8_t:
+return isKeyword(LangOpts);
+
+  default:
+return false;
+  }
+}
+
 tok::PPKeywordKind IdentifierInfo::getPPKeywordID() const {
   // We use a perfect hash function here involving the length of the keyword,
   // the first and third character.  For preprocessor ID's there are no
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index e862856a08ca117..8f9f918bf544fd8 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -1597,7 +1597,8 @@ ExprResult Parser::ParseCastExpression(CastParseKind 
ParseKind,
   if (TryAnnotateTypeOrScopeToken())
 return ExprError();
 
-  if (!Actions.isSimpleTypeSpecifier(Tok.getKind()))
+  if (!Tok.getIdentifierInfo() ||
+  !Actions.isSimpleTypeSpecifier(*Tok.getIdentifierInfo()))
 // We are trying to parse a simple-type-specifier but might not get 
such
 // a token after error recovery.
 return ExprError();
diff --git a/clang/lib/Parse/ParseObjc.cpp b/clang/lib/Parse/ParseObjc.cpp
index 849fd1ac95a442e..5565770610c491b 100644
--- a/clang/lib/Parse/ParseObjc.cpp
+++ b/clang/lib/Parse/ParseObjc.cpp
@@ -2971,7 +2971,8 @@ bool Parser::ParseObjCXXMessageReceiver(bool &IsExpr, 
void *&TypeOrExpr) {
   tok::annot_cxxscope))
 TryAnnotateTypeOrScopeToken();
 
-  if (!Actions.isSimpleTypeSpecifier(Tok.getKind())) {
+  if (!Tok.getIdentifierInfo() ||
+  !Actions.isSimpleTypeSpecifier(*Tok.getId

[clang] [Clang][AST] fix crash in mangle lambda expression (PR #78896)

2024-01-25 Thread Qizhi Hu via cfe-commits

jcsxky wrote:

@cor3ntin I test this code
```cpp
inline auto XXXYYY = [](auto a) {
return [=]() {
return 1;
};
};

void foo(){
XXXYYY(1);
}

```
after name mangling, clang outputs:
```cpp
call void @_ZNK6XXXYYYMUlT_E_clIiEEDaS0_(ptr noundef nonnull align 1 
dereferenceable(1) @XXXYYY, i32 noundef 1)
```
and gcc output:
```cpp
call_ZNK6XXXYYYMUlT_E_clIiEEDaS_
```
Is this expected?



https://github.com/llvm/llvm-project/pull/78896
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [flang] [compiler-rt] [lldb] [libc] [clang] [libcxx] [libunwind] [llvm] [lld] [RISCV][MC] Add experimental support of Zaamo and Zalrsc (PR #78970)

2024-01-25 Thread Wang Pengcheng via cfe-commits

https://github.com/wangpc-pp updated 
https://github.com/llvm/llvm-project/pull/78970

>From 8cc71cb7ddb2e6691d31138ae2ef683a0690e171 Mon Sep 17 00:00:00 2001
From: wangpc 
Date: Mon, 22 Jan 2024 21:11:42 +0800
Subject: [PATCH 1/7] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 clang/lib/Basic/Targets/RISCV.cpp |   2 +-
 .../test/Preprocessor/riscv-target-features.c |  18 ++
 llvm/docs/RISCVUsage.rst  |   2 +
 llvm/lib/Support/RISCVISAInfo.cpp |   2 +
 llvm/lib/Target/RISCV/RISCVFeatures.td|  26 ++-
 llvm/test/CodeGen/RISCV/attributes.ll |   8 +
 llvm/test/MC/RISCV/rv32i-invalid.s|   2 +-
 llvm/test/MC/RISCV/rv32zaamo-invalid.s|  11 ++
 llvm/test/MC/RISCV/rv32zaamo-valid.s  | 122 ++
 llvm/test/MC/RISCV/rv32zalrsc-invalid.s   |   7 +
 llvm/test/MC/RISCV/rv32zalrsc-valid.s |  36 
 llvm/test/MC/RISCV/rv64zaamo-invalid.s|  11 ++
 llvm/test/MC/RISCV/rv64zaamo-valid.s  | 157 ++
 llvm/test/MC/RISCV/rv64zalrsc-invalid.s   |   7 +
 llvm/test/MC/RISCV/rv64zalrsc-valid.s |  42 +
 llvm/unittests/Support/RISCVISAInfoTest.cpp   |   2 +
 16 files changed, 452 insertions(+), 3 deletions(-)
 create mode 100644 llvm/test/MC/RISCV/rv32zaamo-invalid.s
 create mode 100644 llvm/test/MC/RISCV/rv32zaamo-valid.s
 create mode 100644 llvm/test/MC/RISCV/rv32zalrsc-invalid.s
 create mode 100644 llvm/test/MC/RISCV/rv32zalrsc-valid.s
 create mode 100644 llvm/test/MC/RISCV/rv64zaamo-invalid.s
 create mode 100644 llvm/test/MC/RISCV/rv64zaamo-valid.s
 create mode 100644 llvm/test/MC/RISCV/rv64zalrsc-invalid.s
 create mode 100644 llvm/test/MC/RISCV/rv64zalrsc-valid.s

diff --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index c71b2e9eeb6c172..9af9bdd1d74e9dd 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -175,7 +175,7 @@ void RISCVTargetInfo::getTargetDefines(const LangOptions 
&Opts,
 Builder.defineMacro("__riscv_muldiv");
   }
 
-  if (ISAInfo->hasExtension("a")) {
+  if (ISAInfo->hasExtension("a") || ISAInfo->hasExtension("zaamo")) {
 Builder.defineMacro("__riscv_atomic");
 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
diff --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index 5fde5ccdbeacfb0..38473d07004a574 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -141,7 +141,9 @@
 
 // Experimental extensions
 
+// CHECK-NOT: __riscv_zaamo {{.*$}}
 // CHECK-NOT: __riscv_zacas {{.*$}}
+// CHECK-NOT: __riscv_zalrsc {{.*$}}
 // CHECK-NOT: __riscv_zcmop {{.*$}}
 // CHECK-NOT: __riscv_zfbfmin {{.*$}}
 // CHECK-NOT: __riscv_zicfilp {{.*$}}
@@ -1307,6 +1309,14 @@
 // CHECK-ZVKT-EXT: __riscv_zvkt 100{{$}}
 
 // Experimental extensions
+// RUN: %clang --target=riscv32 -menable-experimental-extensions \
+// RUN: -march=rv32i_zaamo0p1 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZAAMO-EXT %s
+// RUN: %clang --target=riscv64 -menable-experimental-extensions \
+// RUN: -march=rv64i_zaamo0p1 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZAAMO-EXT %s
+// CHECK-ZAAMO-EXT: __riscv_atomic 1
+// CHECK-ZAAMO-EXT: __riscv_zaamo 1000{{$}}
 
 // RUN: %clang --target=riscv32 -menable-experimental-extensions \
 // RUN: -march=rv32i_zacas1p0 -x c -E -dM %s \
@@ -1316,6 +1326,14 @@
 // RUN: -o - | FileCheck --check-prefix=CHECK-ZACAS-EXT %s
 // CHECK-ZACAS-EXT: __riscv_zacas 100{{$}}
 
+// RUN: %clang --target=riscv32 -menable-experimental-extensions \
+// RUN: -march=rv32i_zalrsc0p1 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZALRSC-EXT %s
+// RUN: %clang --target=riscv64 -menable-experimental-extensions \
+// RUN: -march=rv64i_zalrsc0p1 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZALRSC-EXT %s
+// CHECK-ZALRSC-EXT: __riscv_zalrsc 1000{{$}}
+
 // RUN: %clang --target=riscv32 -menable-experimental-extensions \
 // RUN: -march=rv32izfbfmin1p0 -x c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-ZFBFMIN-EXT %s
diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index 6fdc945ad27078e..005e9f1d7324445 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -100,6 +100,8 @@ on support follow.
  ``V``Supported
  ``Za128rs``  Supported (`See note 
<#riscv-profiles-extensions-note>`__)
  ``Za64rs``   Supported (`See note 
<#riscv-profiles-extensions-note>`__)
+ ``Zaamo``Supported
+ ``Zalrsc``   Supported
  ``Zawrs``Assembly Support
  ``Zba``  Supported
  ``Zbb``  Sup

[clang] [Clang][Sema] fix crash of attribute transform (PR #78088)

2024-01-25 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/78088

>From 2d6a39f5d679d2a29f606a49f07c596855f2d9d0 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Sun, 14 Jan 2024 15:07:26 +0800
Subject: [PATCH] [Clang][Sema] fix crash of attribute transform

---
 clang/docs/ReleaseNotes.rst   | 205 ++
 clang/include/clang/AST/TypeLoc.h |   4 +
 clang/lib/Sema/TreeTransform.h|  12 +-
 .../test/Sema/attr-lifetimebound-no-crash.cpp |  17 ++
 4 files changed, 233 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/Sema/attr-lifetimebound-no-crash.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index db3d74e124e7d1d..f4bc30d279a10a4 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -103,6 +103,211 @@ Improvements to Clang's time-trace
 
 Bug Fixes in This Version
 -
+<<< HEAD
+===
+- Fixed an issue where a class template specialization whose declaration is
+  instantiated in one module and whose definition is instantiated in another
+  module may end up with members associated with the wrong declaration of the
+  class, which can result in miscompiles in some cases.
+- Fix crash on use of a variadic overloaded operator.
+  (`#42535 `_)
+- Fix a hang on valid C code passing a function type as an argument to
+  ``typeof`` to form a function declaration.
+  (`#64713 `_)
+- Clang now reports missing-field-initializers warning for missing designated
+  initializers in C++.
+  (`#56628 `_)
+- Clang now respects ``-fwrapv`` and ``-ftrapv`` for ``__builtin_abs`` and
+  ``abs`` builtins.
+  (`#45129 `_,
+  `#45794 `_)
+- Fixed an issue where accesses to the local variables of a coroutine during
+  ``await_suspend`` could be misoptimized, including accesses to the awaiter
+  object itself.
+  (`#56301 `_)
+  The current solution may bring performance regressions if the awaiters have
+  non-static data members. See
+  `#64945 `_ for details.
+- Clang now prints unnamed members in diagnostic messages instead of giving an
+  empty ''. Fixes
+  (`#63759 `_)
+- Fix crash in __builtin_strncmp and related builtins when the size value
+  exceeded the maximum value representable by int64_t. Fixes
+  (`#64876 `_)
+- Fixed an assertion if a function has cleanups and fatal erors.
+  (`#48974 `_)
+- Clang now emits an error if it is not possible to deduce array size for a
+  variable with incomplete array type.
+  (`#37257 `_)
+- Clang's ``-Wunused-private-field`` no longer warns on fields whose type is
+  declared with ``[[maybe_unused]]``.
+  (`#61334 `_)
+- For function multi-versioning using the ``target``, ``target_clones``, or
+  ``target_version`` attributes, remove comdat for internal linkage functions.
+  (`#65114 `_)
+- Clang now reports ``-Wformat`` for bool value and char specifier confusion
+  in scanf. Fixes
+  (`#64987 `_)
+- Support MSVC predefined macro expressions in constant expressions and in
+  local structs.
+- Correctly parse non-ascii identifiers that appear immediately after a line 
splicing
+  (`#65156 `_)
+- Clang no longer considers the loss of ``__unaligned`` qualifier from objects 
as
+  an invalid conversion during method function overload resolution.
+- Fix lack of comparison of declRefExpr in ASTStructuralEquivalence
+  (`#66047 `_)
+- Fix parser crash when dealing with ill-formed objective C++ header code. 
Fixes
+  (`#64836 `_)
+- Fix crash in implicit conversions from initialize list to arrays of unknown
+  bound for C++20. Fixes
+  (`#62945 `_)
+- Clang now allows an ``_Atomic`` qualified integer in a switch statement. 
Fixes
+  (`#65557 `_)
+- Fixes crash when trying to obtain the common sugared type of
+  `decltype(instantiation-dependent-expr)`.
+  Fixes (`#67603 `_)
+- Fixes a crash caused by a multidimensional array being captured by a lambda
+  (`#67722 `_).
+- Fixes a cr

[clang] [C++20] [Modules] [Itanium ABI] Generate the vtable in the module unit of dynamic classes (PR #75912)

2024-01-25 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 updated 
https://github.com/llvm/llvm-project/pull/75912

>From 630e59738990c3dd570065b8b7a050d822d68df0 Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Tue, 19 Dec 2023 17:00:59 +0800
Subject: [PATCH] [C++20] [Modules] [Itanium ABI] Generate the vtable in the
 module unit of dynamic classes

Close https://github.com/llvm/llvm-project/issues/70585 and reflect
https://github.com/itanium-cxx-abi/cxx-abi/issues/170.

The significant change of the patch is: for dynamic classes attached to
module units, we generate the vtable to the attached module units
directly and the key functions for such classes is meaningless.
---
 clang/lib/CodeGen/CGVTables.cpp   | 28 ++
 clang/lib/CodeGen/CodeGenModule.cpp   |  7 
 clang/lib/CodeGen/ItaniumCXXABI.cpp   |  6 +++
 clang/lib/Sema/SemaDecl.cpp   |  9 +
 clang/lib/Sema/SemaDeclCXX.cpp| 13 +--
 clang/lib/Serialization/ASTReaderDecl.cpp | 15 +++-
 clang/lib/Serialization/ASTWriterDecl.cpp | 15 +---
 clang/test/CodeGenCXX/modules-vtable.cppm | 27 -
 clang/test/CodeGenCXX/pr70585.cppm| 47 +++
 9 files changed, 139 insertions(+), 28 deletions(-)
 create mode 100644 clang/test/CodeGenCXX/pr70585.cppm

diff --git a/clang/lib/CodeGen/CGVTables.cpp b/clang/lib/CodeGen/CGVTables.cpp
index 27a2cab4f75319..5c8499d2594a1d 100644
--- a/clang/lib/CodeGen/CGVTables.cpp
+++ b/clang/lib/CodeGen/CGVTables.cpp
@@ -1046,6 +1046,11 @@ CodeGenModule::getVTableLinkage(const CXXRecordDecl *RD) 
{
   if (!RD->isExternallyVisible())
 return llvm::GlobalVariable::InternalLinkage;
 
+  // V-tables for non-template classes with an owning module are always
+  // uniquely emitted in that module.
+  if (Module *M = RD->getOwningModule(); M && M->isNamedModule())
+return llvm::GlobalVariable::ExternalLinkage;
+
   // We're at the end of the translation unit, so the current key
   // function is fully correct.
   const CXXMethodDecl *keyFunction = Context.getCurrentKeyFunction(RD);
@@ -1180,6 +1185,21 @@ bool CodeGenVTables::isVTableExternal(const 
CXXRecordDecl *RD) {
   TSK == TSK_ExplicitInstantiationDefinition)
 return false;
 
+  // Itanium C++ ABI [5.2.3]:
+  // Virtual tables for dynamic classes are emitted as follows:
+  //
+  // - If the class is templated, the tables are emitted in every object that
+  // references any of them.
+  // - Otherwise, if the class is attached to a module, the tables are uniquely
+  // emitted in the object for the module unit in which it is defined.
+  // - Otherwise, if the class has a key function (see below), the tables are
+  // emitted in the object for the translation unit containing the definition 
of
+  // the key function. This is unique if the key function is not inline.
+  // - Otherwise, the tables are emitted in every object that references any of
+  // them.
+  if (Module *M = RD->getOwningModule(); M && M->isNamedModule())
+return M != CGM.getContext().getCurrentNamedModule();
+
   // Otherwise, if the class doesn't have a key function (possibly
   // anymore), the vtable must be defined here.
   const CXXMethodDecl *keyFunction = 
CGM.getContext().getCurrentKeyFunction(RD);
@@ -1189,13 +1209,7 @@ bool CodeGenVTables::isVTableExternal(const 
CXXRecordDecl *RD) {
   const FunctionDecl *Def;
   // Otherwise, if we don't have a definition of the key function, the
   // vtable must be defined somewhere else.
-  if (!keyFunction->hasBody(Def))
-return true;
-
-  assert(Def && "The body of the key function is not assigned to Def?");
-  // If the non-inline key function comes from another module unit, the vtable
-  // must be defined there.
-  return Def->isInAnotherModuleUnit() && !Def->isInlineSpecified();
+  return !keyFunction->hasBody(Def);
 }
 
 /// Given that we're currently at the end of the translation unit, and
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index d78f2594a23764..b133695d90905b 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -6738,6 +6738,13 @@ void CodeGenModule::EmitTopLevelDecl(Decl *D) {
 if (ES->hasExternalDefinitions(D) == ExternalASTSource::EK_Never)
   DI->completeUnusedClass(*CRD);
 }
+// If we're emitting a dynamic class from the importable module we're 
emitting,
+// we always need to emit the virtual table according to the ABI 
requirement.
+if (CRD->getOwningModule() && 
CRD->getOwningModule()->isInterfaceOrPartition() &&
+CRD->getDefinition() && CRD->isDynamicClass() &&
+CRD->getOwningModule() == getContext().getCurrentNamedModule())
+  EmitVTable(CRD);
+
 // Emit any static data members, they may be definitions.
 for (auto *I : CRD->decls())
   if (isa(I) || isa(I))
diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp 
b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index d173806ec8ce53..1acf8b3e0659ff 100644
--- a/clang

[clang] [C++20] [Modules] [Itanium ABI] Generate the vtable in the module unit of dynamic classes (PR #75912)

2024-01-25 Thread Chuanqi Xu via cfe-commits


@@ -0,0 +1,50 @@
+// REQUIRES: !system-windows
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+//
+// RUN: %clang_cc1 -std=c++20 %t/layer1.cppm -triple %itanium_abi_triple \
+// RUN: -emit-module-interface -o %t/foo-layer1.pcm
+// RUN: %clang_cc1 -std=c++20 %t/layer2.cppm -triple %itanium_abi_triple  \
+// RUN: -emit-module-interface -fmodule-file=foo:layer1=%t/foo-layer1.pcm \
+// RUN: -o %t/foo-layer2.pcm
+// RUN: %clang_cc1 -std=c++20 %t/foo-layer1.pcm -S -emit-llvm -o - | FileCheck 
%t/layer1.cppm
+// RUN: %clang_cc1 -std=c++20 %t/foo-layer2.pcm -S -emit-llvm -o - \
+// RUN: -fmodule-file=foo:layer1=%t/foo-layer1.pcm | FileCheck 
%t/layer2.cppm
+
+//--- layer1.cppm
+export module foo:layer1;
+struct Fruit {
+virtual ~Fruit() = default;
+virtual void eval() = 0;
+};
+struct Banana : public Fruit {
+Banana() {}
+void eval() override;
+};
+

ChuanqiXu9 wrote:

I've just tried to update it here. If you feel it is too sparse, I can try to 
make it into 2 patches.

https://github.com/llvm/llvm-project/pull/75912
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [C++20] [Modules] [Itanium ABI] Generate the vtable in the module unit of dynamic classes (PR #75912)

2024-01-25 Thread Chuanqi Xu via cfe-commits


@@ -1801,6 +1801,12 @@ void ItaniumCXXABI::emitVTableDefinitions(CodeGenVTables 
&CGVT,
   if (VTable->hasInitializer())
 return;
 
+  // If the class are attached to a C++ named module other than the one

ChuanqiXu9 wrote:

Done

https://github.com/llvm/llvm-project/pull/75912
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [C++20] [Modules] [Itanium ABI] Generate the vtable in the module unit of dynamic classes (PR #75912)

2024-01-25 Thread Chuanqi Xu via cfe-commits


@@ -1046,6 +1046,15 @@ CodeGenModule::getVTableLinkage(const CXXRecordDecl *RD) 
{
   if (!RD->isExternallyVisible())
 return llvm::GlobalVariable::InternalLinkage;
 
+  // Previously we'll decide the linkage of the vtable by the linkage
+  // of the key function. But within modules, the concept of key functions
+  // becomes meaningless. So the linkage of the vtable should always be
+  // external if the class is externally visible.
+  //
+  // TODO: How about the case of AppleKext, DLLExportAttr and DLLImportAttr.

ChuanqiXu9 wrote:

I've updated the comments. And I'd like to leave the simplification to later 
patches.

https://github.com/llvm/llvm-project/pull/75912
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [C++20] [Modules] [Itanium ABI] Generate the vtable in the module unit of dynamic classes (PR #75912)

2024-01-25 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 updated 
https://github.com/llvm/llvm-project/pull/75912

>From 7a5c4ccd37b263a4d3d01df16591b576a64e839f Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Tue, 19 Dec 2023 17:00:59 +0800
Subject: [PATCH] [C++20] [Modules] [Itanium ABI] Generate the vtable in the
 module unit of dynamic classes

Close https://github.com/llvm/llvm-project/issues/70585 and reflect
https://github.com/itanium-cxx-abi/cxx-abi/issues/170.

The significant change of the patch is: for dynamic classes attached to
module units, we generate the vtable to the attached module units
directly and the key functions for such classes is meaningless.
---
 clang/lib/CodeGen/CGVTables.cpp   | 28 ++
 clang/lib/CodeGen/CodeGenModule.cpp   |  9 +
 clang/lib/CodeGen/ItaniumCXXABI.cpp   |  6 +++
 clang/lib/Sema/SemaDecl.cpp   |  9 +
 clang/lib/Sema/SemaDeclCXX.cpp| 13 +--
 clang/lib/Serialization/ASTReaderDecl.cpp | 13 ++-
 clang/lib/Serialization/ASTWriterDecl.cpp | 13 +--
 clang/test/CodeGenCXX/modules-vtable.cppm | 27 -
 clang/test/CodeGenCXX/pr70585.cppm| 47 +++
 9 files changed, 139 insertions(+), 26 deletions(-)
 create mode 100644 clang/test/CodeGenCXX/pr70585.cppm

diff --git a/clang/lib/CodeGen/CGVTables.cpp b/clang/lib/CodeGen/CGVTables.cpp
index 27a2cab4f75319..5c8499d2594a1d 100644
--- a/clang/lib/CodeGen/CGVTables.cpp
+++ b/clang/lib/CodeGen/CGVTables.cpp
@@ -1046,6 +1046,11 @@ CodeGenModule::getVTableLinkage(const CXXRecordDecl *RD) 
{
   if (!RD->isExternallyVisible())
 return llvm::GlobalVariable::InternalLinkage;
 
+  // V-tables for non-template classes with an owning module are always
+  // uniquely emitted in that module.
+  if (Module *M = RD->getOwningModule(); M && M->isNamedModule())
+return llvm::GlobalVariable::ExternalLinkage;
+
   // We're at the end of the translation unit, so the current key
   // function is fully correct.
   const CXXMethodDecl *keyFunction = Context.getCurrentKeyFunction(RD);
@@ -1180,6 +1185,21 @@ bool CodeGenVTables::isVTableExternal(const 
CXXRecordDecl *RD) {
   TSK == TSK_ExplicitInstantiationDefinition)
 return false;
 
+  // Itanium C++ ABI [5.2.3]:
+  // Virtual tables for dynamic classes are emitted as follows:
+  //
+  // - If the class is templated, the tables are emitted in every object that
+  // references any of them.
+  // - Otherwise, if the class is attached to a module, the tables are uniquely
+  // emitted in the object for the module unit in which it is defined.
+  // - Otherwise, if the class has a key function (see below), the tables are
+  // emitted in the object for the translation unit containing the definition 
of
+  // the key function. This is unique if the key function is not inline.
+  // - Otherwise, the tables are emitted in every object that references any of
+  // them.
+  if (Module *M = RD->getOwningModule(); M && M->isNamedModule())
+return M != CGM.getContext().getCurrentNamedModule();
+
   // Otherwise, if the class doesn't have a key function (possibly
   // anymore), the vtable must be defined here.
   const CXXMethodDecl *keyFunction = 
CGM.getContext().getCurrentKeyFunction(RD);
@@ -1189,13 +1209,7 @@ bool CodeGenVTables::isVTableExternal(const 
CXXRecordDecl *RD) {
   const FunctionDecl *Def;
   // Otherwise, if we don't have a definition of the key function, the
   // vtable must be defined somewhere else.
-  if (!keyFunction->hasBody(Def))
-return true;
-
-  assert(Def && "The body of the key function is not assigned to Def?");
-  // If the non-inline key function comes from another module unit, the vtable
-  // must be defined there.
-  return Def->isInAnotherModuleUnit() && !Def->isInlineSpecified();
+  return !keyFunction->hasBody(Def);
 }
 
 /// Given that we're currently at the end of the translation unit, and
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index d78f2594a23764..4863f7348ed99a 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -6738,6 +6738,15 @@ void CodeGenModule::EmitTopLevelDecl(Decl *D) {
 if (ES->hasExternalDefinitions(D) == ExternalASTSource::EK_Never)
   DI->completeUnusedClass(*CRD);
 }
+// If we're emitting a dynamic class from the importable module we're
+// emitting, we always need to emit the virtual table according to the ABI
+// requirement.
+if (CRD->getOwningModule() &&
+CRD->getOwningModule()->isInterfaceOrPartition() &&
+CRD->getDefinition() && CRD->isDynamicClass() &&
+CRD->getOwningModule() == getContext().getCurrentNamedModule())
+  EmitVTable(CRD);
+
 // Emit any static data members, they may be definitions.
 for (auto *I : CRD->decls())
   if (isa(I) || isa(I))
diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp 
b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index d173806ec8ce53..1acf8b3e0659ff 10064

[clang] [C++20] [Modules] [Itanium ABI] Generate the vtable in the module unit of dynamic classes (PR #75912)

2024-01-25 Thread via cfe-commits

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 7a3b0cbb143d02b70b2bfae5cd40e9867c124748 
630e59738990c3dd570065b8b7a050d822d68df0 -- clang/test/CodeGenCXX/pr70585.cppm 
clang/lib/CodeGen/CGVTables.cpp clang/lib/CodeGen/CodeGenModule.cpp 
clang/lib/CodeGen/ItaniumCXXABI.cpp clang/lib/Sema/SemaDecl.cpp 
clang/lib/Sema/SemaDeclCXX.cpp clang/lib/Serialization/ASTReaderDecl.cpp 
clang/lib/Serialization/ASTWriterDecl.cpp 
clang/test/CodeGenCXX/modules-vtable.cppm
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index b133695d90..4863f7348e 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -6738,9 +6738,11 @@ void CodeGenModule::EmitTopLevelDecl(Decl *D) {
 if (ES->hasExternalDefinitions(D) == ExternalASTSource::EK_Never)
   DI->completeUnusedClass(*CRD);
 }
-// If we're emitting a dynamic class from the importable module we're 
emitting,
-// we always need to emit the virtual table according to the ABI 
requirement.
-if (CRD->getOwningModule() && 
CRD->getOwningModule()->isInterfaceOrPartition() &&
+// If we're emitting a dynamic class from the importable module we're
+// emitting, we always need to emit the virtual table according to the ABI
+// requirement.
+if (CRD->getOwningModule() &&
+CRD->getOwningModule()->isInterfaceOrPartition() &&
 CRD->getDefinition() && CRD->isDynamicClass() &&
 CRD->getOwningModule() == getContext().getCurrentNamedModule())
   EmitVTable(CRD);
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index aaf4a3d0ba..646b94f670 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -18132,9 +18132,9 @@ void Sema::ActOnTagFinishDefinition(Scope *S, Decl 
*TagD,
 // need to produce the vtable for it even if the vtable is not used in the
 // current TU.
 //
-// The case that the current class is not dynamic is handled in 
MarkVTableUsed.
-if (getCurrentModule() &&
-getCurrentModule()->isInterfaceOrPartition())
+// The case that the current class is not dynamic is handled in
+// MarkVTableUsed.
+if (getCurrentModule() && getCurrentModule()->isInterfaceOrPartition())
   MarkVTableUsed(RD->getLocation(), RD, /*DefinitionRequired=*/true);
   }
 
diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp 
b/clang/lib/Serialization/ASTReaderDecl.cpp
index f5ff9115aa..e6b3f4a1b4 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -2255,7 +2255,7 @@ ASTDeclReader::VisitCXXRecordDeclImpl(CXXRecordDecl *D) {
   // compute it.
   //
   // The key function in named module is meaningless.
-  if (WasDefinition && (!D->getOwningModule() || 
+  if (WasDefinition && (!D->getOwningModule() ||
 !D->getOwningModule()->isInterfaceOrPartition())) {
 DeclID KeyFn = readDeclID();
 if (KeyFn && D->isCompleteDefinition())
@@ -3210,7 +3210,7 @@ static bool isConsumerInterestedIn(ASTContext &Ctx, Decl 
*D, bool HasBody) {
 OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(Var));
   if (const auto *Func = dyn_cast(D))
 return Func->doesThisDeclarationHaveABody() || HasBody;
-  
+
   if (auto *ES = D->getASTContext().getExternalSource())
 if (ES->hasExternalDefinitions(D) == ExternalASTSource::EK_Never)
   return true;
diff --git a/clang/lib/Serialization/ASTWriterDecl.cpp 
b/clang/lib/Serialization/ASTWriterDecl.cpp
index 33b2c1d392..b971dd0251 100644
--- a/clang/lib/Serialization/ASTWriterDecl.cpp
+++ b/clang/lib/Serialization/ASTWriterDecl.cpp
@@ -1482,7 +1482,7 @@ void ASTDeclWriter::VisitCXXRecordDecl(CXXRecordDecl *D) {
   Record.push_back(D->isThisDeclarationADefinition());
   if (D->isThisDeclarationADefinition())
 Record.AddCXXDefinitionData(D);
-  
+
   if (D->isCompleteDefinition()) {
 if (D->getOwningModule() && D->getOwningModule()->isInterfaceOrPartition())
   Writer.ModularCodegenDecls.push_back(Writer.GetDeclRef(D));

``




https://github.com/llvm/llvm-project/pull/75912
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang-tools-extra] [clang] [Clang] Fix : More Detailed "No expected directives found" (PR #78338)

2024-01-25 Thread Shourya Goel via cfe-commits


@@ -1098,7 +1098,13 @@ void VerifyDiagnosticConsumer::CheckDiagnostics() {
 // Produce an error if no expected-* directives could be found in the
 // source file(s) processed.
 if (Status == HasNoDirectives) {
-  Diags.Report(diag::err_verify_no_directives).setForceEmit();
+  std::string directives;
+  if (Diags.getDiagnosticOptions().VerifyPrefixes.empty()) {
+directives = "expected";

Sh0g0-1758 wrote:

Also there might be something wrong with buildkite as I only changed directives 
to Directive as you suggested but now it shows a build fail. 

https://github.com/llvm/llvm-project/pull/78338
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 1a14c44 - [RISCV][MC] Add experimental support of Zaamo and Zalrsc

2024-01-25 Thread via cfe-commits

Author: Wang Pengcheng
Date: 2024-01-25T17:03:25+08:00
New Revision: 1a14c446dd800b1d79fed1735c48e392d06e495d

URL: 
https://github.com/llvm/llvm-project/commit/1a14c446dd800b1d79fed1735c48e392d06e495d
DIFF: 
https://github.com/llvm/llvm-project/commit/1a14c446dd800b1d79fed1735c48e392d06e495d.diff

LOG: [RISCV][MC] Add experimental support of Zaamo and Zalrsc

`A` extension has been split into two parts: Zaamo (Atomic Memory
Operations) and Zalrsc (Load-Reserved/Store-Conditional). See also
https://github.com/riscv/riscv-zaamo-zalrsc.

This patch adds the MC support.

Reviewers: dtcxzyw, topperc, kito-cheng

Reviewed By: topperc

Pull Request: https://github.com/llvm/llvm-project/pull/78970

Added: 


Modified: 
clang/test/Preprocessor/riscv-target-features.c
llvm/docs/RISCVUsage.rst
llvm/lib/Support/RISCVISAInfo.cpp
llvm/lib/Target/RISCV/RISCVFeatures.td
llvm/lib/Target/RISCV/RISCVInstrInfoA.td
llvm/test/CodeGen/RISCV/attributes.ll
llvm/test/MC/RISCV/rv32i-invalid.s
llvm/test/MC/RISCV/rv32zaamo-invalid.s
llvm/test/MC/RISCV/rv32zaamo-valid.s
llvm/test/MC/RISCV/rv32zalrsc-invalid.s
llvm/test/MC/RISCV/rv32zalrsc-valid.s
llvm/test/MC/RISCV/rv64zaamo-invalid.s
llvm/test/MC/RISCV/rv64zaamo-valid.s
llvm/test/MC/RISCV/rv64zalrsc-invalid.s
llvm/test/MC/RISCV/rv64zalrsc-valid.s
llvm/unittests/Support/RISCVISAInfoTest.cpp

Removed: 




diff  --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index 4112e7d473d233..8f50126f1b3628 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -141,7 +141,9 @@
 
 // Experimental extensions
 
+// CHECK-NOT: __riscv_zaamo {{.*$}}
 // CHECK-NOT: __riscv_zacas {{.*$}}
+// CHECK-NOT: __riscv_zalrsc {{.*$}}
 // CHECK-NOT: __riscv_zcmop {{.*$}}
 // CHECK-NOT: __riscv_zfbfmin {{.*$}}
 // CHECK-NOT: __riscv_zicfilp {{.*$}}
@@ -1307,6 +1309,13 @@
 // CHECK-ZVKT-EXT: __riscv_zvkt 100{{$}}
 
 // Experimental extensions
+// RUN: %clang --target=riscv32 -menable-experimental-extensions \
+// RUN:   -march=rv32i_zaamo0p2 -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-ZAAMO-EXT %s
+// RUN: %clang --target=riscv64 -menable-experimental-extensions \
+// RUN:   -march=rv64i_zaamo0p2 -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-ZAAMO-EXT %s
+// CHECK-ZAAMO-EXT: __riscv_zaamo 2000{{$}}
 
 // RUN: %clang --target=riscv32 -menable-experimental-extensions \
 // RUN:   -march=rv32i_zacas1p0 -E -dM %s \
@@ -1316,6 +1325,14 @@
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZACAS-EXT %s
 // CHECK-ZACAS-EXT: __riscv_zacas 100{{$}}
 
+// RUN: %clang --target=riscv32 -menable-experimental-extensions \
+// RUN:   -march=rv32i_zalrsc0p2 -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-ZALRSC-EXT %s
+// RUN: %clang --target=riscv64 -menable-experimental-extensions \
+// RUN:   -march=rv64i_zalrsc0p2 -E -dM %s \
+// RUN:   -o - | FileCheck --check-prefix=CHECK-ZALRSC-EXT %s
+// CHECK-ZALRSC-EXT: __riscv_zalrsc 2000{{$}}
+
 // RUN: %clang --target=riscv32 -menable-experimental-extensions \
 // RUN:   -march=rv32izfbfmin1p0 -E -dM %s \
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZFBFMIN-EXT %s

diff  --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index 9dbbc3f04387b6..2cfbb10abc8a1c 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -246,6 +246,9 @@ The primary goal of experimental support is to assist in 
the process of ratifica
 ``experimental-zcmop``
   LLVM implements the `v0.2 proposed specification 
`__.
 
+``experimental-zaamo``, ``experimental-zalrsc``
+  LLVM implements the `v0.2 proposed specification 
`__.
+
 To use an experimental extension from `clang`, you must add 
`-menable-experimental-extensions` to the command line, and specify the exact 
version of the experimental extension you are using.  To use an experimental 
extension with LLVM's internal developer tools (e.g. `llc`, `llvm-objdump`, 
`llvm-mc`), you must prefix the extension name with `experimental-`.  Note that 
you don't need to specify the version with internal tools, and shouldn't 
include the `experimental-` prefix with `clang`.
 
 Vendor Extensions

diff  --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index 3c02492e99f1db..32b4ff5de86f1e 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -190,8 +190,11 @@ static const RISCVSupportedExtension SupportedExtensions[] 
= {
 };
 
 // NOTE: This table should be sorted alphabetically by extension name.
+// clang-format off
 static const RISCVSupportedExtension SupportedExperimentalExtensions[] = {
+{"zaamo", {0, 2}},
 {"zacas",

[flang] [lld] [libc] [clang-tools-extra] [clang] [libcxx] [libunwind] [llvm] [lldb] [compiler-rt] [RISCV][MC] Add experimental support of Zaamo and Zalrsc (PR #78970)

2024-01-25 Thread Wang Pengcheng via cfe-commits

https://github.com/wangpc-pp closed 
https://github.com/llvm/llvm-project/pull/78970
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Diagnostics] Highlight code snippets (PR #66514)

2024-01-25 Thread via cfe-commits

https://github.com/cor3ntin approved this pull request.

I am happy with that!
Lets merge it soon so that we can play with it :)

https://github.com/llvm/llvm-project/pull/66514
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [RISCV] Relax march string order constraint (PR #78120)

2024-01-25 Thread Piyou Chen via cfe-commits

https://github.com/BeMg updated https://github.com/llvm/llvm-project/pull/78120

>From 7ad5726d93e957050723a7df7a8384bc9ff694b3 Mon Sep 17 00:00:00 2001
From: Piyou Chen 
Date: Sun, 14 Jan 2024 19:41:59 -0800
Subject: [PATCH 1/8] [RISCV] Relax march string order constraint

---
 clang/test/Driver/riscv-arch.c  |  14 +-
 llvm/lib/Support/RISCVISAInfo.cpp   | 297 ++--
 llvm/unittests/Support/RISCVISAInfoTest.cpp |  91 --
 3 files changed, 226 insertions(+), 176 deletions(-)

diff --git a/clang/test/Driver/riscv-arch.c b/clang/test/Driver/riscv-arch.c
index 0ac81ea982f1b61..38de95e4fbf7aa4 100644
--- a/clang/test/Driver/riscv-arch.c
+++ b/clang/test/Driver/riscv-arch.c
@@ -156,9 +156,8 @@
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32L %s
 // RV32L: error: invalid arch name 'rv32l'
 
-// RUN: not %clang --target=riscv32-unknown-elf -march=rv32imadf -### %s \
-// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32IMADF %s
-// RV32IMADF: error: invalid arch name 'rv32imadf'
+// RUN: %clang --target=riscv32-unknown-elf -march=rv32imadf -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck %s
 
 // RUN: not %clang --target=riscv32-unknown-elf -march=rv32imm -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32IMM %s
@@ -184,9 +183,8 @@
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64L %s
 // RV64L: error: invalid arch name 'rv64l'
 
-// RUN: not %clang --target=riscv64-unknown-elf -march=rv64imadf -### %s \
-// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64IMADF %s
-// RV64IMADF: error: invalid arch name 'rv64imadf'
+// RUN: %clang --target=riscv64-unknown-elf -march=rv64imadf -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck %s
 
 // RUN: not %clang --target=riscv64-unknown-elf -march=rv64imm -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64IMM %s
@@ -216,7 +214,7 @@
 // RUN: not %clang --target=riscv32-unknown-elf -march=rv32imcq -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-ORDER %s
 // RV32-ORDER: error: invalid arch name 'rv32imcq',
-// RV32-ORDER: standard user-level extension not given in canonical order 'q'
+// RV32-ORDER: unsupported standard user-level extension 'q'
 
 // RUN: not %clang --target=riscv32-unknown-elf -march=rv32izvl64b -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-ZVL64B-ER %s
@@ -318,7 +316,7 @@
 // RUN: not %clang --target=riscv32-unknown-elf -march=rv32ixabc_a -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-PREFIX %s
 // RV32-PREFIX: error: invalid arch name 'rv32ixabc_a',
-// RV32-PREFIX: invalid extension prefix 'a'
+// RV32-PREFIX: unsupported non-standard user-level extension 'xabc'
 
 // RUN: not %clang --target=riscv32-unknown-elf -march=rv32ixdef_sabc -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-X-ORDER %s
diff --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index 3c02492e99f1db4..06579c20b2637a2 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -703,6 +703,106 @@ RISCVISAInfo::parseNormalizedArchString(StringRef Arch) {
   return std::move(ISAInfo);
 }
 
+static Error splitExtsByUnderscore(StringRef Exts,
+   std::vector &SplitedExts) {
+  SmallVector Split;
+  if (Exts.empty())
+return Error::success();
+
+  Exts.split(Split, "_");
+
+  for (auto Ext : Split) {
+if (Ext.empty())
+  return createStringError(errc::invalid_argument,
+   "extension name missing after separator '_'");
+
+SplitedExts.push_back(Ext.str());
+  }
+  return Error::success();
+}
+
+static Error processMultiLetterExtension(
+StringRef RawExt, SmallVector &SeenExts,
+SmallVector &ExtsVersion,
+bool IgnoreUnknown, bool EnableExperimentalExtension,
+bool ExperimentalExtensionVersionCheck) {
+  StringRef Type = getExtensionType(RawExt);
+  StringRef Desc = getExtensionTypeDesc(RawExt);
+  auto Pos = findLastNonVersionCharacter(RawExt) + 1;
+  StringRef Name(RawExt.substr(0, Pos));
+  StringRef Vers(RawExt.substr(Pos));
+
+  if (Type.empty()) {
+if (IgnoreUnknown)
+  return Error::success();
+return createStringError(errc::invalid_argument,
+ "invalid extension prefix '" + RawExt + "'");
+  }
+
+  if (!IgnoreUnknown && Name.size() == Type.size())
+return createStringError(errc::invalid_argument,
+ "%s name missing after '%s'", Desc.str().c_str(),
+ Type.str().c_str());
+
+  unsigned Major, Minor, ConsumeLength;
+  if (auto E = getExtensionVersion(Name, Vers, Major, Minor, ConsumeLength,
+   EnableExperimentalExtension,
+   ExperimentalExtensionVersionCheck)) {
+if (IgnoreUnknown) {
+  consumeError(std::move(E));
+  return Error::success();
+}
+return E;
+  }
+
+  // Check if du

[llvm] [clang] [RISCV] Relax march string order constraint (PR #78120)

2024-01-25 Thread Piyou Chen via cfe-commits

https://github.com/BeMg updated https://github.com/llvm/llvm-project/pull/78120

>From 7ad5726d93e957050723a7df7a8384bc9ff694b3 Mon Sep 17 00:00:00 2001
From: Piyou Chen 
Date: Sun, 14 Jan 2024 19:41:59 -0800
Subject: [PATCH 1/9] [RISCV] Relax march string order constraint

---
 clang/test/Driver/riscv-arch.c  |  14 +-
 llvm/lib/Support/RISCVISAInfo.cpp   | 297 ++--
 llvm/unittests/Support/RISCVISAInfoTest.cpp |  91 --
 3 files changed, 226 insertions(+), 176 deletions(-)

diff --git a/clang/test/Driver/riscv-arch.c b/clang/test/Driver/riscv-arch.c
index 0ac81ea982f1b6..38de95e4fbf7aa 100644
--- a/clang/test/Driver/riscv-arch.c
+++ b/clang/test/Driver/riscv-arch.c
@@ -156,9 +156,8 @@
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32L %s
 // RV32L: error: invalid arch name 'rv32l'
 
-// RUN: not %clang --target=riscv32-unknown-elf -march=rv32imadf -### %s \
-// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32IMADF %s
-// RV32IMADF: error: invalid arch name 'rv32imadf'
+// RUN: %clang --target=riscv32-unknown-elf -march=rv32imadf -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck %s
 
 // RUN: not %clang --target=riscv32-unknown-elf -march=rv32imm -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32IMM %s
@@ -184,9 +183,8 @@
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64L %s
 // RV64L: error: invalid arch name 'rv64l'
 
-// RUN: not %clang --target=riscv64-unknown-elf -march=rv64imadf -### %s \
-// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64IMADF %s
-// RV64IMADF: error: invalid arch name 'rv64imadf'
+// RUN: %clang --target=riscv64-unknown-elf -march=rv64imadf -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck %s
 
 // RUN: not %clang --target=riscv64-unknown-elf -march=rv64imm -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64IMM %s
@@ -216,7 +214,7 @@
 // RUN: not %clang --target=riscv32-unknown-elf -march=rv32imcq -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-ORDER %s
 // RV32-ORDER: error: invalid arch name 'rv32imcq',
-// RV32-ORDER: standard user-level extension not given in canonical order 'q'
+// RV32-ORDER: unsupported standard user-level extension 'q'
 
 // RUN: not %clang --target=riscv32-unknown-elf -march=rv32izvl64b -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-ZVL64B-ER %s
@@ -318,7 +316,7 @@
 // RUN: not %clang --target=riscv32-unknown-elf -march=rv32ixabc_a -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-PREFIX %s
 // RV32-PREFIX: error: invalid arch name 'rv32ixabc_a',
-// RV32-PREFIX: invalid extension prefix 'a'
+// RV32-PREFIX: unsupported non-standard user-level extension 'xabc'
 
 // RUN: not %clang --target=riscv32-unknown-elf -march=rv32ixdef_sabc -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-X-ORDER %s
diff --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index 3c02492e99f1db..06579c20b2637a 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -703,6 +703,106 @@ RISCVISAInfo::parseNormalizedArchString(StringRef Arch) {
   return std::move(ISAInfo);
 }
 
+static Error splitExtsByUnderscore(StringRef Exts,
+   std::vector &SplitedExts) {
+  SmallVector Split;
+  if (Exts.empty())
+return Error::success();
+
+  Exts.split(Split, "_");
+
+  for (auto Ext : Split) {
+if (Ext.empty())
+  return createStringError(errc::invalid_argument,
+   "extension name missing after separator '_'");
+
+SplitedExts.push_back(Ext.str());
+  }
+  return Error::success();
+}
+
+static Error processMultiLetterExtension(
+StringRef RawExt, SmallVector &SeenExts,
+SmallVector &ExtsVersion,
+bool IgnoreUnknown, bool EnableExperimentalExtension,
+bool ExperimentalExtensionVersionCheck) {
+  StringRef Type = getExtensionType(RawExt);
+  StringRef Desc = getExtensionTypeDesc(RawExt);
+  auto Pos = findLastNonVersionCharacter(RawExt) + 1;
+  StringRef Name(RawExt.substr(0, Pos));
+  StringRef Vers(RawExt.substr(Pos));
+
+  if (Type.empty()) {
+if (IgnoreUnknown)
+  return Error::success();
+return createStringError(errc::invalid_argument,
+ "invalid extension prefix '" + RawExt + "'");
+  }
+
+  if (!IgnoreUnknown && Name.size() == Type.size())
+return createStringError(errc::invalid_argument,
+ "%s name missing after '%s'", Desc.str().c_str(),
+ Type.str().c_str());
+
+  unsigned Major, Minor, ConsumeLength;
+  if (auto E = getExtensionVersion(Name, Vers, Major, Minor, ConsumeLength,
+   EnableExperimentalExtension,
+   ExperimentalExtensionVersionCheck)) {
+if (IgnoreUnknown) {
+  consumeError(std::move(E));
+  return Error::success();
+}
+return E;
+  }
+
+  // Check if duplic

[clang] [Clang][Sema] fix crash of attribute transform (PR #78088)

2024-01-25 Thread via cfe-commits

cor3ntin wrote:

There seems to be an issue with the rebasing of the PR.
As we branch clang 18, the new changelog (for 19) being empty is expected

https://github.com/llvm/llvm-project/pull/78088
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 03cf0e9 - [LTO] Fix Veclib flags correctly pass to LTO flags (#78749)

2024-01-25 Thread via cfe-commits

Author: Paschalis Mpeis
Date: 2024-01-25T09:29:46Z
New Revision: 03cf0e9354e7e56ff794e9efb682ed2971bc91ec

URL: 
https://github.com/llvm/llvm-project/commit/03cf0e9354e7e56ff794e9efb682ed2971bc91ec
DIFF: 
https://github.com/llvm/llvm-project/commit/03cf0e9354e7e56ff794e9efb682ed2971bc91ec.diff

LOG: [LTO] Fix Veclib flags correctly pass to LTO flags (#78749)

Flags `-fveclib=name` were not passed to LTO flags.
This pass fixes that by converting the `-fveclib` flags to their
relevant names for opt's `-vector-lib=name` flags.

For example:
`-fveclib=SLEEF` would become `-vector-library=sleefgnuabi` and passed
through the `-plugin-opt` flag.

Added: 


Modified: 
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/test/Driver/fveclib.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 48534bc1669e44d..f20dd9f3b28dd6f 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -781,6 +781,28 @@ void tools::addLTOOptions(const ToolChain &ToolChain, 
const ArgList &Args,
  "-generate-arange-section"));
   }
 
+  // Pass vector library arguments to LTO.
+  Arg *ArgVecLib = Args.getLastArg(options::OPT_fveclib);
+  if (ArgVecLib && ArgVecLib->getNumValues() == 1) {
+// Map the vector library names from clang front-end to opt front-end. The
+// values are taken from the TargetLibraryInfo class command line options.
+std::optional OptVal =
+llvm::StringSwitch>(ArgVecLib->getValue())
+.Case("Accelerate", "Accelerate")
+.Case("LIBMVEC", "LIBMVEC-X86")
+.Case("MASSV", "MASSV")
+.Case("SVML", "SVML")
+.Case("SLEEF", "sleefgnuabi")
+.Case("Darwin_libsystem_m", "Darwin_libsystem_m")
+.Case("ArmPL", "ArmPL")
+.Case("none", "none")
+.Default(std::nullopt);
+
+if (OptVal)
+  CmdArgs.push_back(Args.MakeArgString(
+  Twine(PluginOptPrefix) + "-vector-library=" + OptVal.value()));
+  }
+
   // Try to pass driver level flags relevant to LTO code generation down to
   // the plugin.
 

diff  --git a/clang/test/Driver/fveclib.c b/clang/test/Driver/fveclib.c
index e2a7619e9b89f7f..8a230284bcdfe4f 100644
--- a/clang/test/Driver/fveclib.c
+++ b/clang/test/Driver/fveclib.c
@@ -31,3 +31,21 @@
 
 // RUN: %clang -fveclib=Accelerate %s -nodefaultlibs -target 
arm64-apple-ios8.0.0 -### 2>&1 | FileCheck 
--check-prefix=CHECK-LINK-NODEFAULTLIBS %s
 // CHECK-LINK-NODEFAULTLIBS-NOT: "-framework" "Accelerate"
+
+
+/* Verify that the correct vector library is passed to LTO flags. */
+
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fveclib=LIBMVEC -flto 
%s 2>&1 | FileCheck -check-prefix CHECK-LTO-LIBMVEC %s
+// CHECK-LTO-LIBMVEC: "-plugin-opt=-vector-library=LIBMVEC-X86"
+
+// RUN: %clang -### --target=powerpc64-unknown-linux-gnu -fveclib=MASSV -flto 
%s 2>&1 | FileCheck -check-prefix CHECK-LTO-MASSV %s
+// CHECK-LTO-MASSV: "-plugin-opt=-vector-library=MASSV"
+
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fveclib=SVML -flto %s 
2>&1 | FileCheck -check-prefix CHECK-LTO-SVML %s
+// CHECK-LTO-SVML: "-plugin-opt=-vector-library=SVML"
+
+// RUN: %clang -### --target=aarch64-linux-gnu -fveclib=SLEEF -flto %s 2>&1 | 
FileCheck -check-prefix CHECK-LTO-SLEEF %s
+// CHECK-LTO-SLEEF: "-plugin-opt=-vector-library=sleefgnuabi"
+
+// RUN: %clang -### --target=aarch64-linux-gnu -fveclib=ArmPL -flto %s 2>&1 | 
FileCheck -check-prefix CHECK-LTO-ARMPL %s
+// CHECK-LTO-ARMPL: "-plugin-opt=-vector-library=ArmPL"



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [LTO] Fix Veclib flags correctly pass to LTO flags (PR #78749)

2024-01-25 Thread Paschalis Mpeis via cfe-commits

https://github.com/paschalis-mpeis closed 
https://github.com/llvm/llvm-project/pull/78749
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Sema]Substitue parameter packs when deduced from function parameter (PR #79371)

2024-01-25 Thread via cfe-commits


@@ -4371,6 +4397,41 @@ Sema::TemplateDeductionResult 
Sema::DeduceTemplateArguments(
   // corresponding argument is a list?
   PackScope.nextPackElement();
 }
+  } else if (!IsTrailingPack && !PackScope.isPartiallyExpanded() &&
+ PackScope.isDeducedFromEarlierParameter() &&
+ !isa(ParamTypes[ParamIdx + 1])) {
+// [temp.deduct.general#3]
+// When all template arguments have been deduced
+// or obtained from default template arguments, all uses of template
+// parameters in the template parameter list of the template are
+// replaced with the corresponding deduced or default argument values
+//
+// If we have a trailing parameter pack, that has been deduced
+// perviously we substitute the pack here in a similar fashion as seen
+// above with the trailing parameter packs. The main difference here is
+// that, in this case we are not processing all of the remaining
+// arguments. We are only process as many arguments as much we have in
+// the already deduced parameter.
+SmallVector Unexpanded;
+collectUnexpandedParameterPacks(ParamPattern, Unexpanded);
+if (Unexpanded.size() == 0)
+  continue;

cor3ntin wrote:

can `unexpanded` ever be empty? This should be an assert

https://github.com/llvm/llvm-project/pull/79371
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Sema]Substitue parameter packs when deduced from function parameter (PR #79371)

2024-01-25 Thread via cfe-commits


@@ -4371,6 +4397,41 @@ Sema::TemplateDeductionResult 
Sema::DeduceTemplateArguments(
   // corresponding argument is a list?
   PackScope.nextPackElement();
 }
+  } else if (!IsTrailingPack && !PackScope.isPartiallyExpanded() &&
+ PackScope.isDeducedFromEarlierParameter() &&
+ !isa(ParamTypes[ParamIdx + 1])) {
+// [temp.deduct.general#3]
+// When all template arguments have been deduced
+// or obtained from default template arguments, all uses of template
+// parameters in the template parameter list of the template are
+// replaced with the corresponding deduced or default argument values
+//
+// If we have a trailing parameter pack, that has been deduced
+// perviously we substitute the pack here in a similar fashion as seen

cor3ntin wrote:

```suggestion
// previously we substitute the pack here in a similar fashion as seen
```

https://github.com/llvm/llvm-project/pull/79371
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Sema]Substitue parameter packs when deduced from function parameter (PR #79371)

2024-01-25 Thread via cfe-commits


@@ -4371,6 +4397,41 @@ Sema::TemplateDeductionResult 
Sema::DeduceTemplateArguments(
   // corresponding argument is a list?
   PackScope.nextPackElement();
 }
+  } else if (!IsTrailingPack && !PackScope.isPartiallyExpanded() &&
+ PackScope.isDeducedFromEarlierParameter() &&
+ !isa(ParamTypes[ParamIdx + 1])) {
+// [temp.deduct.general#3]
+// When all template arguments have been deduced
+// or obtained from default template arguments, all uses of template
+// parameters in the template parameter list of the template are
+// replaced with the corresponding deduced or default argument values
+//
+// If we have a trailing parameter pack, that has been deduced
+// perviously we substitute the pack here in a similar fashion as seen

cor3ntin wrote:

```suggestion
// perviously we substitute the pack here in a similar fashion as
```

https://github.com/llvm/llvm-project/pull/79371
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Sema]Substitue parameter packs when deduced from function parameter (PR #79371)

2024-01-25 Thread via cfe-commits


@@ -431,6 +442,17 @@ namespace deduction_after_explicit_pack {
 i(0, 1, 2, 3, 4, 5); // expected-error {{no match}}
   }
 
+  template 
+  void bar(args_tag, type_identity_t..., int mid, 
type_identity_t...) {}

cor3ntin wrote:

What happens without the mid parameter ?

https://github.com/llvm/llvm-project/pull/79371
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] [lldb] [clang-tools-extra] [libc] [compiler-rt] [llvm] [clang] [flang] [lld] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-25 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

> So I guess we should set the DefaultedDestructorIsConstexpr to false and only 
> use it for warning?

I'm not sure? Switching all constexpr-related errors to warnings doesn't seem 
right, even though almost all functions now can be marked constexpr, they still 
can't be called from constexpr context. In addition, if we keep 
DefaultedDestructorIsConstexpr always `false` we still will produce _some_ 
diagnostic for code in 
https://github.com/llvm/llvm-project/pull/78195#issuecomment-1895950521 and we 
should not, I suppose?
Sorry if I'm misunderstanding and being slow.

https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Sema]Substitue parameter packs when deduced from function parameter (PR #79371)

2024-01-25 Thread via cfe-commits


@@ -858,6 +859,30 @@ class PackDeductionScope {
   Info.PendingDeducedPacks[Pack.Index] = Pack.Outer;
   }
 
+  std::optional getSavedPackSize(unsigned Index,
+   TemplateArgument Pattern) const {
+
+SmallVector Unexpanded;
+S.collectUnexpandedParameterPacks(Pattern, Unexpanded);
+if (Unexpanded.size() == 0 ||
+Packs[0].Saved.getKind() != clang::TemplateArgument::Pack)
+  return {};
+unsigned PackSize = Packs[0].Saved.pack_size();
+
+if (std::all_of(Packs.begin() + 1, Packs.end(), [&PackSize](auto P) {
+  return P.Saved.getKind() == TemplateArgument::Pack &&
+ P.Saved.pack_size() == PackSize;
+}))
+  return PackSize;
+return {};
+  }
+
+  /// Determine whether this pack has already been deduced from a previous
+  /// argument.
+  bool isDeducedFromEarlierParameter() const {
+return DeducedFromEarlierParameter;
+  }
+

cor3ntin wrote:

Can we save the size in PackDeductionScope instead of recomputeing it?
It should be ill-formed to deduce different sizes

https://github.com/llvm/llvm-project/pull/79371
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Sema] fix crash of attribute transform (PR #78088)

2024-01-25 Thread Qizhi Hu via cfe-commits

jcsxky wrote:

> There seems to be an issue with the rebasing of the PR. As we branch clang 
> 18, the new changelog (for 19) being empty is expected

I try to merge this PR and found `ReleaseNotes.rst` is changed because of 
clang-19 initialize. I don't know where should I add the release note.

https://github.com/llvm/llvm-project/pull/78088
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Sema]Substitue parameter packs when deduced from function parameter (PR #79371)

2024-01-25 Thread via cfe-commits

https://github.com/cor3ntin edited 
https://github.com/llvm/llvm-project/pull/79371
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Sema]Substitue parameter packs when deduced from function parameter (PR #79371)

2024-01-25 Thread via cfe-commits

https://github.com/cor3ntin commented:

Thanks for working on this!
It looks like a good direction.

I left a few comments

Can you add a changelog entry? Thanks

https://github.com/llvm/llvm-project/pull/79371
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[flang] [lld] [libc] [clang-tools-extra] [libclc] [clang] [libcxx] [libcxxabi] [llvm] [lldb] [compiler-rt] [VPlan] Add new VPUniformPerUFRecipe, use for step truncation. (PR #78113)

2024-01-25 Thread Florian Hahn via cfe-commits

https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/78113

>From 36b085f21b76d7bf7c9965a86a09d1cef4fe9329 Mon Sep 17 00:00:00 2001
From: Florian Hahn 
Date: Sun, 14 Jan 2024 14:13:08 +
Subject: [PATCH 1/5] [VPlan] Add new VPUniformPerUFRecipe, use for step
 truncation.

Add a new recipe to model uniform-per-UF instructions, without relying
on an underlying instruction. Initially, it supports uniform cast-ops
and is therefore storing the result type.

Not relying on an underlying instruction (like the current
VPReplicateRecipe) allows to create instances without a corresponding
instruction.

In the future, to plan is to extend this recipe to handle all opcodes
needed to replace the uniform part of VPReplicateRecipe.
---
 llvm/lib/Transforms/Vectorize/VPlan.h | 30 
 .../Transforms/Vectorize/VPlanAnalysis.cpp|  6 ++-
 .../lib/Transforms/Vectorize/VPlanRecipes.cpp | 49 ---
 .../Transforms/Vectorize/VPlanTransforms.cpp  |  9 
 llvm/lib/Transforms/Vectorize/VPlanValue.h|  1 +
 .../LoopVectorize/cast-induction.ll   |  4 +-
 .../interleave-and-scalarize-only.ll  |  3 +-
 .../pr46525-expander-insertpoint.ll   |  2 +-
 8 files changed, 93 insertions(+), 11 deletions(-)

diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h 
b/llvm/lib/Transforms/Vectorize/VPlan.h
index 4b4f4911eb6415..d598522448 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -1945,6 +1945,36 @@ class VPReplicateRecipe : public VPRecipeWithIRFlags, 
public VPValue {
   }
 };
 
+/// VPUniformPerUFRecipe represents an instruction with Opcode that is uniform
+/// per UF, i.e. it generates a single scalar instance per UF.
+/// TODO: at the moment, only Cast opcodes are supported, extend to support
+///   missing opcodes to replace uniform part of VPReplicateRecipe.
+class VPUniformPerUFRecipe : public VPRecipeBase, public VPValue {
+  unsigned Opcode;
+
+  /// Result type for the cast.
+  Type *ResultTy;
+
+  Value *generate(VPTransformState &State, unsigned Part);
+
+public:
+  VPUniformPerUFRecipe(Instruction::CastOps Opcode, VPValue *Op, Type 
*ResultTy)
+  : VPRecipeBase(VPDef::VPUniformPerUFSC, {Op}), VPValue(this),
+Opcode(Opcode), ResultTy(ResultTy) {}
+
+  ~VPUniformPerUFRecipe() override = default;
+
+  VP_CLASSOF_IMPL(VPDef::VPWidenIntOrFpInductionSC)
+
+  void execute(VPTransformState &State) override;
+
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+  /// Print the recipe.
+  void print(raw_ostream &O, const Twine &Indent,
+ VPSlotTracker &SlotTracker) const override;
+#endif
+};
+
 /// A recipe for generating conditional branches on the bits of a mask.
 class VPBranchOnMaskRecipe : public VPRecipeBase {
 public:
diff --git a/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp 
b/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp
index 97a8a1803bbf5a..d71b0703994450 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp
@@ -230,7 +230,11 @@ Type *VPTypeAnalysis::inferScalarType(const VPValue *V) {
 return V->getUnderlyingValue()->getType();
   })
   .Case(
-  [](const VPWidenCastRecipe *R) { return R->getResultType(); });
+  [](const VPWidenCastRecipe *R) { return R->getResultType(); })
+  .Case([](const VPExpandSCEVRecipe *R) {
+return R->getSCEV()->getType();
+  });
+
   assert(ResultTy && "could not infer type for the given VPValue");
   CachedTypes[V] = ResultTy;
   return ResultTy;
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp 
b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index 1f844bce23102e..423504e8f7e05e 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -164,6 +164,8 @@ bool VPRecipeBase::mayHaveSideEffects() const {
 auto *R = cast(this);
 return R->getUnderlyingInstr()->mayHaveSideEffects();
   }
+  case VPUniformPerUFSC:
+return false;
   default:
 return true;
   }
@@ -1117,13 +1119,7 @@ void VPScalarIVStepsRecipe::execute(VPTransformState 
&State) {
 
   // Ensure step has the same type as that of scalar IV.
   Type *BaseIVTy = BaseIV->getType()->getScalarType();
-  if (BaseIVTy != Step->getType()) {
-// TODO: Also use VPDerivedIVRecipe when only the step needs truncating, to
-// avoid separate truncate here.
-assert(Step->getType()->isIntegerTy() &&
-   "Truncation requires an integer step");
-Step = State.Builder.CreateTrunc(Step, BaseIVTy);
-  }
+  assert(BaseIVTy == Step->getType());
 
   // We build scalar steps for both integer and floating-point induction
   // variables. Here, we determine the kind of arithmetic we will perform.
@@ -1469,6 +1465,45 @@ void VPReplicateRecipe::print(raw_ostream &O, const 
Twine &Indent,
 }
 #endif
 
+Value *VPUniformPerUFRecipe ::generate(VPTransformState 

[clang] [Clang][AST] fix crash in mangle lambda expression (PR #78896)

2024-01-25 Thread via cfe-commits

cor3ntin wrote:

both compiler seems to mangkle it as `_ZNK6XXXYYYMUlT_E_clIiEEDaS0_` which 
looks correct
(`auto XXXYYY::{lambda(auto:1)#1}::operator()(int) const`) @rjmccall 

Compiler explorer let you demangle identifiers (in the output menu, under the 
compilers dropdown https://compiler-explorer.com/z/Th11TjM8K )

https://github.com/llvm/llvm-project/pull/78896
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 45fec0c - [clang-apply-replacements] Add support for the `.yml` file extension (#78842)

2024-01-25 Thread via cfe-commits

Author: Daniil Dudkin
Date: 2024-01-25T12:54:49+03:00
New Revision: 45fec0c110cccd5e0c9b60d51bc2ffc1645c9a40

URL: 
https://github.com/llvm/llvm-project/commit/45fec0c110cccd5e0c9b60d51bc2ffc1645c9a40
DIFF: 
https://github.com/llvm/llvm-project/commit/45fec0c110cccd5e0c9b60d51bc2ffc1645c9a40.diff

LOG: [clang-apply-replacements] Add support for the `.yml` file extension 
(#78842)

The `.yml` file extension is a valid extension for the YAML files, but
it was not previously supported by the Clang Apply Replacements tool.
This commit adds support for processing `.yml` files. Without this
change, running the tool on a folder containing `.yml` files generated
by clang-tidy would have no effect.

Added: 
clang-tools-extra/test/clang-apply-replacements/Inputs/yml-basic/basic.h
clang-tools-extra/test/clang-apply-replacements/Inputs/yml-basic/file1.yml
clang-tools-extra/test/clang-apply-replacements/Inputs/yml-basic/file2.yml
clang-tools-extra/test/clang-apply-replacements/yml-basic.cpp

Modified: 
clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp 
b/clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
index 87ed1b8797cb05e..9e0da82dfd3806d 100644
--- 
a/clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
+++ 
b/clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
@@ -23,11 +23,14 @@
 #include "clang/Tooling/DiagnosticsYaml.h"
 #include "clang/Tooling/ReplacementsYaml.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSet.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
+#include 
 #include 
 
 using namespace llvm;
@@ -39,6 +42,9 @@ namespace clang {
 namespace replace {
 
 namespace detail {
+
+static constexpr std::array AllowedExtensions = {".yaml", 
".yml"};
+
 template 
 static std::error_code collectReplacementsFromDirectory(
 const llvm::StringRef Directory, TranslationUnits &TUs,
@@ -56,7 +62,7 @@ static std::error_code collectReplacementsFromDirectory(
   continue;
 }
 
-if (extension(I->path()) != ".yaml")
+if (!is_contained(AllowedExtensions, extension(I->path(
   continue;
 
 TUFiles.push_back(I->path());

diff  --git 
a/clang-tools-extra/test/clang-apply-replacements/Inputs/yml-basic/basic.h 
b/clang-tools-extra/test/clang-apply-replacements/Inputs/yml-basic/basic.h
new file mode 100644
index 000..48509684b7725cd
--- /dev/null
+++ b/clang-tools-extra/test/clang-apply-replacements/Inputs/yml-basic/basic.h
@@ -0,0 +1,32 @@
+#ifndef BASIC_H
+#define BASIC_H
+
+
+class Parent {
+public:
+  virtual void func() {}
+};
+
+class Derived : public Parent {
+public:
+  virtual void func() {}
+  // CHECK: virtual void func() override {}
+};
+
+extern void ext(int (&)[5], const Parent &);
+
+void func(int t) {
+  int ints[5];
+  for (unsigned i = 0; i < 5; ++i) {
+int &e = ints[i];
+e = t;
+// CHECK: for (auto & elem : ints) {
+// CHECK-NEXT: elem = t;
+  }
+
+  Derived d;
+
+  ext(ints, d);
+}
+
+#endif // BASIC_H

diff  --git 
a/clang-tools-extra/test/clang-apply-replacements/Inputs/yml-basic/file1.yml 
b/clang-tools-extra/test/clang-apply-replacements/Inputs/yml-basic/file1.yml
new file mode 100644
index 000..757f8d2ac18529c
--- /dev/null
+++ b/clang-tools-extra/test/clang-apply-replacements/Inputs/yml-basic/file1.yml
@@ -0,0 +1,26 @@
+---
+MainSourceFile: source1.cpp
+Diagnostics:
+  - DiagnosticName: test-basic
+DiagnosticMessage:
+  Message: Fix
+  FilePath: $(path)/basic.h
+  FileOffset: 242
+  Replacements:
+- FilePath:$(path)/basic.h
+  Offset:  242
+  Length:  26
+  ReplacementText: 'auto & elem : ints'
+- FilePath:$(path)/basic.h
+  Offset:  276
+  Length:  22
+  ReplacementText: ''
+- FilePath:$(path)/basic.h
+  Offset:  298
+  Length:  1
+  ReplacementText: elem
+- FilePath:$(path)/../yml-basic/basic.h
+  Offset:  148
+  Length:  0
+  ReplacementText: 'override '
+...

diff  --git 
a/clang-tools-extra/test/clang-apply-replacements/Inputs/yml-basic/file2.yml 
b/clang-tools-extra/test/clang-apply-replacements/Inputs/yml-basic/file2.yml
new file mode 100644
index 000..e8b54e99bc101c8
--- /dev/null
+++ b/clang-tools-extra/test/clang-apply-replacements/Inputs/yml-basic/file2.yml
@@ -0,0 +1,14 @@
+---
+MainSourceFile: source2.cpp
+Diagnostics:
+  - DiagnosticName: test-basic
+DiagnosticMessag

[clang-tools-extra] [clang-apply-replacements] Add support for the `.yml` file extension (PR #78842)

2024-01-25 Thread Daniil Dudkin via cfe-commits

https://github.com/unterumarmung closed 
https://github.com/llvm/llvm-project/pull/78842
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenMP][Clang] Handle unsupported inscan modifier for generic types (PR #79431)

2024-01-25 Thread Animesh Kumar via cfe-commits

https://github.com/animeshk-amd created 
https://github.com/llvm/llvm-project/pull/79431

The https://reviews.llvm.org/D79948 patch had implemented the `omp scan` 
directive. The scan computation happens when the `reduction` clause with the 
`inscan` modifier is used. The present implementation doesn't support the 
reduction variable and the input list item to be of generic type. This patch 
handles this edge case by throwing a diagnostic error message when the `inscan` 
modifier is used on template type variables.

This fixes #67002:
=> [OpenMP][Clang] Scan Directive not supported for Generic types

>From 259a0da5b208d5f23d29c76f8ad24214780181e5 Mon Sep 17 00:00:00 2001
From: Animesh Kumar 
Date: Mon, 22 Jan 2024 05:28:07 -0600
Subject: [PATCH] [OpenMP][Clang] Handle unsupported inscan modifier for
 generic types

The https://reviews.llvm.org/D79948 patch had implemented the
'omp scan' directive. The scan computation happens when the
'reduction' clause with the 'inscan' modifier is used. The
present implementation doesn't support the reduction variable and
the input list item to be of generic type. This patch handles
this edge case by throwing a diagnostic error message when the
'inscan' modifier is used on template type variables.

This fixes #67002:
=> [OpenMP][Clang] Scan Directive not supported for Generic types
---
 .../clang/Basic/DiagnosticSemaKinds.td|  2 ++
 clang/lib/Sema/SemaOpenMP.cpp |  7 +
 clang/test/OpenMP/scan_ast_print.cpp  | 24 +
 clang/test/OpenMP/scan_messages.cpp   | 26 +++
 4 files changed, 25 insertions(+), 34 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index a1c32abb4dcd880..34efa9107a81ab8 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11254,6 +11254,8 @@ def err_omp_reduction_not_inclusive_exclusive : Error<
 def err_omp_wrong_inscan_reduction : Error<
   "'inscan' modifier can be used only in 'omp for', 'omp simd', 'omp for 
simd',"
   " 'omp parallel for', or 'omp parallel for simd' directive">;
+def err_omp_inscan_reduction_on_template_type: Error <
+  "'inscan' modifier currently does not support generic data types">;
 def err_omp_inscan_reduction_expected : Error<
   "expected 'reduction' clause with the 'inscan' modifier">;
 def note_omp_previous_inscan_reduction : Note<
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 217fcb979deea20..b0353bf9b287789 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -19520,6 +19520,13 @@ static bool actOnOMPReductionKindClause(
   bool FirstIter = true;
   for (Expr *RefExpr : VarList) {
 assert(RefExpr && "nullptr expr in OpenMP reduction clause.");
+if (ClauseKind == OMPC_reduction &&
+RD.RedModifier == OMPC_REDUCTION_inscan && RefExpr->isTypeDependent()) 
{
+  S.Diag(RefExpr->getExprLoc(),
+ diag::err_omp_inscan_reduction_on_template_type);
+  continue;
+}
+
 // OpenMP [2.1, C/C++]
 //  A list item is a variable or array section, subject to the restrictions
 //  specified in Section 2.4 on page 42 and in each of the sections
diff --git a/clang/test/OpenMP/scan_ast_print.cpp 
b/clang/test/OpenMP/scan_ast_print.cpp
index 3bbd3b60c3e8c4e..090f7d2cafc34f1 100644
--- a/clang/test/OpenMP/scan_ast_print.cpp
+++ b/clang/test/OpenMP/scan_ast_print.cpp
@@ -12,28 +12,6 @@
 
 void foo() {}
 
-template 
-T tmain(T argc) {
-  static T a;
-#pragma omp for reduction(inscan, +: a)
-  for (int i = 0; i < 10; ++i) {
-#pragma omp scan inclusive(a)
-  }
-  return a + argc;
-}
-// CHECK:  static T a;
-// CHECK-NEXT: #pragma omp for reduction(inscan, +: a)
-// CHECK-NEXT: for (int i = 0; i < 10; ++i) {
-// CHECK-NEXT: #pragma omp scan inclusive(a){{$}}
-// CHECK:  static int a;
-// CHECK-NEXT: #pragma omp for reduction(inscan, +: a)
-// CHECK-NEXT: for (int i = 0; i < 10; ++i) {
-// CHECK-NEXT: #pragma omp scan inclusive(a)
-// CHECK:  static char a;
-// CHECK-NEXT: #pragma omp for reduction(inscan, +: a)
-// CHECK-NEXT: for (int i = 0; i < 10; ++i) {
-// CHECK-NEXT: #pragma omp scan inclusive(a)
-
 int main(int argc, char **argv) {
   static int a;
 // CHECK: static int a;
@@ -46,7 +24,7 @@ int main(int argc, char **argv) {
 // CHECK-NEXT: #pragma omp for simd reduction(inscan, ^: a,argc)
 // CHECK-NEXT: for (int i = 0; i < 10; ++i) {
 // CHECK-NEXT: #pragma omp scan exclusive(a,argc){{$}}
-  return tmain(argc) + tmain(argv[0][0]) + a;
+  return 0;
 }
 
 #endif
diff --git a/clang/test/OpenMP/scan_messages.cpp 
b/clang/test/OpenMP/scan_messages.cpp
index 0de94898c65712f..3e889072bebf79b 100644
--- a/clang/test/OpenMP/scan_messages.cpp
+++ b/clang/test/OpenMP/scan_messages.cpp
@@ -16,32 +16,32 @@ T tmain() {
 #pragma omp scan untied  // expected-error {{unexpected OpenMP clause 'untied' 
in directive '#

[clang] [OpenMP][Clang] Handle unsupported inscan modifier for generic types (PR #79431)

2024-01-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Animesh Kumar (animeshk-amd)


Changes

The https://reviews.llvm.org/D79948 patch had implemented the `omp scan` 
directive. The scan computation happens when the `reduction` clause with the 
`inscan` modifier is used. The present implementation doesn't support the 
reduction variable and the input list item to be of generic type. This patch 
handles this edge case by throwing a diagnostic error message when the `inscan` 
modifier is used on template type variables.

This fixes #67002:
=> [OpenMP][Clang] Scan Directive not supported for Generic types

---
Full diff: https://github.com/llvm/llvm-project/pull/79431.diff


4 Files Affected:

- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+2) 
- (modified) clang/lib/Sema/SemaOpenMP.cpp (+7) 
- (modified) clang/test/OpenMP/scan_ast_print.cpp (+1-23) 
- (modified) clang/test/OpenMP/scan_messages.cpp (+15-11) 


``diff
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index a1c32abb4dcd880..34efa9107a81ab8 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11254,6 +11254,8 @@ def err_omp_reduction_not_inclusive_exclusive : Error<
 def err_omp_wrong_inscan_reduction : Error<
   "'inscan' modifier can be used only in 'omp for', 'omp simd', 'omp for 
simd',"
   " 'omp parallel for', or 'omp parallel for simd' directive">;
+def err_omp_inscan_reduction_on_template_type: Error <
+  "'inscan' modifier currently does not support generic data types">;
 def err_omp_inscan_reduction_expected : Error<
   "expected 'reduction' clause with the 'inscan' modifier">;
 def note_omp_previous_inscan_reduction : Note<
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 217fcb979deea20..b0353bf9b287789 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -19520,6 +19520,13 @@ static bool actOnOMPReductionKindClause(
   bool FirstIter = true;
   for (Expr *RefExpr : VarList) {
 assert(RefExpr && "nullptr expr in OpenMP reduction clause.");
+if (ClauseKind == OMPC_reduction &&
+RD.RedModifier == OMPC_REDUCTION_inscan && RefExpr->isTypeDependent()) 
{
+  S.Diag(RefExpr->getExprLoc(),
+ diag::err_omp_inscan_reduction_on_template_type);
+  continue;
+}
+
 // OpenMP [2.1, C/C++]
 //  A list item is a variable or array section, subject to the restrictions
 //  specified in Section 2.4 on page 42 and in each of the sections
diff --git a/clang/test/OpenMP/scan_ast_print.cpp 
b/clang/test/OpenMP/scan_ast_print.cpp
index 3bbd3b60c3e8c4e..090f7d2cafc34f1 100644
--- a/clang/test/OpenMP/scan_ast_print.cpp
+++ b/clang/test/OpenMP/scan_ast_print.cpp
@@ -12,28 +12,6 @@
 
 void foo() {}
 
-template 
-T tmain(T argc) {
-  static T a;
-#pragma omp for reduction(inscan, +: a)
-  for (int i = 0; i < 10; ++i) {
-#pragma omp scan inclusive(a)
-  }
-  return a + argc;
-}
-// CHECK:  static T a;
-// CHECK-NEXT: #pragma omp for reduction(inscan, +: a)
-// CHECK-NEXT: for (int i = 0; i < 10; ++i) {
-// CHECK-NEXT: #pragma omp scan inclusive(a){{$}}
-// CHECK:  static int a;
-// CHECK-NEXT: #pragma omp for reduction(inscan, +: a)
-// CHECK-NEXT: for (int i = 0; i < 10; ++i) {
-// CHECK-NEXT: #pragma omp scan inclusive(a)
-// CHECK:  static char a;
-// CHECK-NEXT: #pragma omp for reduction(inscan, +: a)
-// CHECK-NEXT: for (int i = 0; i < 10; ++i) {
-// CHECK-NEXT: #pragma omp scan inclusive(a)
-
 int main(int argc, char **argv) {
   static int a;
 // CHECK: static int a;
@@ -46,7 +24,7 @@ int main(int argc, char **argv) {
 // CHECK-NEXT: #pragma omp for simd reduction(inscan, ^: a,argc)
 // CHECK-NEXT: for (int i = 0; i < 10; ++i) {
 // CHECK-NEXT: #pragma omp scan exclusive(a,argc){{$}}
-  return tmain(argc) + tmain(argv[0][0]) + a;
+  return 0;
 }
 
 #endif
diff --git a/clang/test/OpenMP/scan_messages.cpp 
b/clang/test/OpenMP/scan_messages.cpp
index 0de94898c65712f..3e889072bebf79b 100644
--- a/clang/test/OpenMP/scan_messages.cpp
+++ b/clang/test/OpenMP/scan_messages.cpp
@@ -16,32 +16,32 @@ T tmain() {
 #pragma omp scan untied  // expected-error {{unexpected OpenMP clause 'untied' 
in directive '#pragma omp scan'}} expected-error {{exactly one of 'inclusive' 
or 'exclusive' clauses is expected}}
 #pragma omp scan unknown // expected-warning {{extra tokens at the end of 
'#pragma omp scan' are ignored}} expected-error {{exactly one of 'inclusive' or 
'exclusive' clauses is expected}}
   }
-#pragma omp for simd reduction(inscan, +: argc)
+#pragma omp for simd reduction(inscan, +: argc) // expected-error {{'inscan' 
modifier currently does not support generic data types}}
   for (int i = 0; i < 10; ++i)
 if (argc)
 #pragma omp scan inclusive(argc) // expected-error {{'#pragma omp scan' cannot 
be an immediate substatement}} expected-error {{orphaned 'omp scan' directives 
are pro

[lldb] [clang-tools-extra] [compiler-rt] [libcxx] [libc] [lld] [clang] [llvm] [flang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-01-25 Thread via cfe-commits

cor3ntin wrote:

> So I guess we should set the DefaultedDestructorIsConstexpr to false and only 
> use it for warning?

Oh gosh, I'm an idiot, i meant **`true`** 


https://github.com/llvm/llvm-project/pull/77753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Sema]Substitue parameter packs when deduced from function parameter (PR #79371)

2024-01-25 Thread Gábor Spaits via cfe-commits

https://github.com/spaits updated 
https://github.com/llvm/llvm-project/pull/79371

From d4ca5c2fcb87f424be23efc4513df491403c3811 Mon Sep 17 00:00:00 2001
From: Gabor Spaits 
Date: Wed, 24 Jan 2024 21:21:26 +0100
Subject: [PATCH 1/5] [Sema]Substitue template parameter packs when deduced
 from function parameter

---
 clang/lib/Sema/SemaTemplateDeduction.cpp | 63 +++-
 1 file changed, 62 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index e9e7ab5bb6698a0..46fa9eece3747a2 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -730,6 +730,7 @@ class PackDeductionScope {
   void addPack(unsigned Index) {
 // Save the deduced template argument for the parameter pack expanded
 // by this pack expansion, then clear out the deduction.
+DeducedFromEarlierParameter = !Deduced[Index].isNull();
 DeducedPack Pack(Index);
 Pack.Saved = Deduced[Index];
 Deduced[Index] = TemplateArgument();
@@ -858,6 +859,29 @@ class PackDeductionScope {
   Info.PendingDeducedPacks[Pack.Index] = Pack.Outer;
   }
 
+  std::optional getSavedPackSize(unsigned Index,
+   TemplateArgument Pattern) const {
+
+SmallVector Unexpanded;
+S.collectUnexpandedParameterPacks(Pattern, Unexpanded);
+if (Unexpanded.size() == 0 ||
+Packs[0].Saved.getKind() != clang::TemplateArgument::Pack)
+  return {};
+unsigned PackSize = Packs[0].Saved.pack_size();
+
+if (std::all_of(Packs.begin() + 1, Packs.end(),
+[&PackSize](auto P) {
+  return P.Saved.getKind() == TemplateArgument::Pack &&
+ P.Saved.pack_size() == PackSize;
+}))
+  return PackSize;
+return {};
+  }
+
+  /// Determine whether this pack has already been deduced from a previous
+  /// argument.
+  bool isDeducedFromEarlierParameter() const {return 
DeducedFromEarlierParameter;}
+
   /// Determine whether this pack has already been partially expanded into a
   /// sequence of (prior) function parameters / template arguments.
   bool isPartiallyExpanded() { return IsPartiallyExpanded; }
@@ -970,7 +994,6 @@ class PackDeductionScope {
 NewPack = Pack.DeferredDeduction;
 Result = checkDeducedTemplateArguments(S.Context, OldPack, NewPack);
   }
-
   NamedDecl *Param = TemplateParams->getParam(Pack.Index);
   if (Result.isNull()) {
 Info.Param = makeTemplateParameter(Param);
@@ -1003,9 +1026,12 @@ class PackDeductionScope {
   unsigned PackElements = 0;
   bool IsPartiallyExpanded = false;
   bool DeducePackIfNotAlreadyDeduced = false;
+  bool DeducedFromEarlierParameter = false;
+
   /// The number of expansions, if we have a fully-expanded pack in this scope.
   std::optional FixedNumExpansions;
 
+
   SmallVector Packs;
 };
 
@@ -4371,6 +4397,41 @@ Sema::TemplateDeductionResult 
Sema::DeduceTemplateArguments(
   // corresponding argument is a list?
   PackScope.nextPackElement();
 }
+  } else if (!IsTrailingPack && !PackScope.isPartiallyExpanded() &&
+ PackScope.isDeducedFromEarlierParameter() &&
+ !isa(ParamTypes[ParamIdx + 1])) {
+// [temp.deduct.general#3]
+// When all template arguments have been deduced
+// or obtained from default template arguments, all uses of template
+// parameters in the template parameter list of the template are
+// replaced with the corresponding deduced or default argument values
+//
+// If we have a trailing parameter pack, that has been deduced 
perviously
+// we substitute the pack here in a similar fashion as seen above with
+// the trailing parameter packs. The main difference here is that, in
+// this case we are not processing all of the remaining arguments. We
+// are only process as many arguments as much we have in the already
+// deduced parameter.
+SmallVector Unexpanded;
+collectUnexpandedParameterPacks(ParamPattern, Unexpanded);
+if (Unexpanded.size() == 0)
+  continue;
+
+std::optional ArgPosAfterSubstitution =
+PackScope.getSavedPackSize(getDepthAndIndex(Unexpanded[0]).second,
+   ParamPattern);
+if (!ArgPosAfterSubstitution)
+  continue;
+
+unsigned PackArgEnd = ArgIdx + *ArgPosAfterSubstitution;
+for (; ArgIdx < PackArgEnd && ArgIdx < Args.size(); ArgIdx++) {
+  ParamTypesForArgChecking.push_back(ParamPattern);
+  if (auto Result = DeduceCallArgument(ParamPattern, ArgIdx,
+   
/*ExplicitObjetArgument=*/false))
+return Result;
+
+  PackScope.nextPackElement();
+}
   }
 }
 

From 52de421b998481105e5522a04ad9e39a4a6cbb

[mlir] [compiler-rt] [clang-tools-extra] [clang] [llvm] [mlir][bufferization] Fix SimplifyClones with dealloc before cloneOp (PR #79098)

2024-01-25 Thread Matthias Springer via cfe-commits

https://github.com/matthias-springer closed 
https://github.com/llvm/llvm-project/pull/79098
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][analyzer] Add function 'fprintf' to StreamChecker. (PR #77613)

2024-01-25 Thread Balázs Kéri via cfe-commits


@@ -926,6 +932,49 @@ void StreamChecker::evalFputx(const FnDescription *Desc, 
const CallEvent &Call,
   C.addTransition(StateFailed);
 }
 
+void StreamChecker::evalFprintf(const FnDescription *Desc,
+const CallEvent &Call,
+CheckerContext &C) const {
+  ProgramStateRef State = C.getState();
+  if (Call.getNumArgs() < 2)
+return;
+  SymbolRef StreamSym = getStreamArg(Desc, Call).getAsSymbol();
+  if (!StreamSym)
+return;
+
+  const CallExpr *CE = dyn_cast_or_null(Call.getOriginExpr());
+  if (!CE)
+return;
+
+  const StreamState *OldSS = State->get(StreamSym);
+  if (!OldSS)
+return;
+
+  assertStreamStateOpened(OldSS);
+
+  NonLoc RetVal = makeRetVal(C, CE).castAs();
+  State = State->BindExpr(CE, C.getLocationContext(), RetVal);
+  SValBuilder &SVB = C.getSValBuilder();
+  auto &ACtx = C.getASTContext();
+  auto Cond = SVB.evalBinOp(State, BO_GE, RetVal, SVB.makeZeroVal(ACtx.IntTy),
+SVB.getConditionType())
+  .getAs();
+  if (!Cond)
+return;
+  ProgramStateRef StateNotFailed, StateFailed;
+  std::tie(StateNotFailed, StateFailed) = State->assume(*Cond);

balazske wrote:

Yes, some fixes can be done with `fprintf` and `fscanf` and the argument 
invalidation. I plan to do this with the following patches.

https://github.com/llvm/llvm-project/pull/77613
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][analyzer] Improve modeling of 'popen' and 'pclose' in StdLibraryFunctionsChecker (PR #78895)

2024-01-25 Thread Balazs Benics via cfe-commits


@@ -2211,6 +2221,15 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
   ErrnoNEZeroIrrelevant, GenericFailureMsg)
 .ArgConstraint(NotNull(ArgNo(0;
 
+// int pclose(FILE *stream);
+addToFunctionSummaryMap(
+"pclose", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
+Summary(NoEvalCall)
+.Case({ReturnValueCondition(WithinRange, {{0, IntMax}})},
+  ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
+.ArgConstraint(NotNull(ArgNo(0;
+

steakhal wrote:

Okay. Thanks for digging into this.
Consider this thread resolved.

https://github.com/llvm/llvm-project/pull/78895
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [AArch64] Simplify Clang's description of architecture extensions (PR #79311)

2024-01-25 Thread Anatoly Trosinenko via cfe-commits

https://github.com/atrosinenko updated 
https://github.com/llvm/llvm-project/pull/79311

>From e0d278d9fcdd01f574bbf5fa1bcbbaf7875525de Mon Sep 17 00:00:00 2001
From: Anatoly Trosinenko 
Date: Tue, 23 Jan 2024 12:40:00 +0300
Subject: [PATCH 1/2] [AArch64] Simplify Clang's description of architecture
 extensions

Core LLVM has AArch64TargetParser.h header describing the mapping from
Armv8.x and Armv9.x architecture extensions to the particular list of
features that are mandatory for the extension.

Clang partially reimplements this in AArch64TargetInfo::setArchFeatures()
function. This patch simplifies setArchFeatures() by dropping obvious
cases of duplication, though it seems not all the dependencies are
listed in AArch64TargetParser.h yet.

Specifically, this patch drops `HasX = true` statements for the
following features:
* v8.1-a: CRC, LSE, RDM
* v8.3-a: RCPC, NeonMode (it is enabled by the base Armv8-a and
  indirectly by -target-feature +fcma)
* v8.4-a: DOTPROD
* v8.6-a: BF16, MATMUL

In Clang's AArch64TargetInfo::handleTargetFeatures() function, the
string literal "+jscvt" is changed to "+jsconv" and "+cccp" to "+ccpp",
so the information is conveyed from TargetParser.

Additionally, this patch makes __ARM_FEATURE_BTI and __ARM_FEATURE_JCVT
conditional on the particular HasX flags instead of an architecture
extension as a whole, as using TargetParser makes it possible to specify
the requested architecture like "armv8.5+nojscvt".
---
 clang/lib/Basic/Targets/AArch64.cpp | 48 +
 1 file changed, 15 insertions(+), 33 deletions(-)

diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index d47181bfca4fc86..0ac890551fadb24 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -55,24 +55,19 @@ static constexpr Builtin::Info BuiltinInfo[] = {
 };
 
 void AArch64TargetInfo::setArchFeatures() {
+  // FIXME Could we drop this function altogether and migrate everything
+  //   to AArch64TargetParser in LLVM core?
   if (*ArchInfo == llvm::AArch64::ARMV8R) {
-HasDotProd = true;
 HasDIT = true;
 HasFlagM = true;
-HasRCPC = true;
 FPU |= NeonMode;
 HasCCPP = true;
-HasCRC = true;
 HasLSE = true;
-HasRDM = true;
   } else if (ArchInfo->Version.getMajor() == 8) {
 if (ArchInfo->Version.getMinor() >= 7u) {
   HasWFxT = true;
 }
-if (ArchInfo->Version.getMinor() >= 6u) {
-  HasBFloat16 = true;
-  HasMatMul = true;
-}
+// No special cases for Armv8.6-a
 if (ArchInfo->Version.getMinor() >= 5u) {
   HasAlternativeNZCV = true;
   HasFRInt3264 = true;
@@ -82,30 +77,19 @@ void AArch64TargetInfo::setArchFeatures() {
   HasBTI = true;
 }
 if (ArchInfo->Version.getMinor() >= 4u) {
-  HasDotProd = true;
   HasDIT = true;
   HasFlagM = true;
 }
-if (ArchInfo->Version.getMinor() >= 3u) {
-  HasRCPC = true;
-  FPU |= NeonMode;
-}
+// No special cases for Armv8.3-a
 if (ArchInfo->Version.getMinor() >= 2u) {
   HasCCPP = true;
 }
-if (ArchInfo->Version.getMinor() >= 1u) {
-  HasCRC = true;
-  HasLSE = true;
-  HasRDM = true;
-}
+// No special cases for Armv8.1-a
   } else if (ArchInfo->Version.getMajor() == 9) {
 if (ArchInfo->Version.getMinor() >= 2u) {
   HasWFxT = true;
 }
-if (ArchInfo->Version.getMinor() >= 1u) {
-  HasBFloat16 = true;
-  HasMatMul = true;
-}
+// No special cases for Armv9.1-a
 FPU |= SveMode;
 HasSVE2 = true;
 HasFullFP16 = true;
@@ -115,15 +99,9 @@ void AArch64TargetInfo::setArchFeatures() {
 HasSB = true;
 HasPredRes = true;
 HasBTI = true;
-HasDotProd = true;
 HasDIT = true;
 HasFlagM = true;
-HasRCPC = true;
-FPU |= NeonMode;
 HasCCPP = true;
-HasCRC = true;
-HasLSE = true;
-HasRDM = true;
   }
 }
 
@@ -257,7 +235,6 @@ void AArch64TargetInfo::getTargetDefinesARMV82A(const 
LangOptions &Opts,
 void AArch64TargetInfo::getTargetDefinesARMV83A(const LangOptions &Opts,
 MacroBuilder &Builder) const {
   Builder.defineMacro("__ARM_FEATURE_COMPLEX", "1");
-  Builder.defineMacro("__ARM_FEATURE_JCVT", "1");
   Builder.defineMacro("__ARM_FEATURE_PAUTH", "1");
   // Also include the Armv8.2 defines
   getTargetDefinesARMV82A(Opts, Builder);
@@ -272,7 +249,6 @@ void AArch64TargetInfo::getTargetDefinesARMV84A(const 
LangOptions &Opts,
 void AArch64TargetInfo::getTargetDefinesARMV85A(const LangOptions &Opts,
 MacroBuilder &Builder) const {
   Builder.defineMacro("__ARM_FEATURE_FRINT", "1");
-  Builder.defineMacro("__ARM_FEATURE_BTI", "1");
   // Also include the Armv8.4 defines
   getTargetDefinesARMV84A(Opts, Builder);
 }
@@ -472,7 +448,10 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
   if ((FPU & NeonMode) && HasFullFP16)
 Builder.defineMa

[clang] [AArch64] Simplify Clang's description of architecture extensions (PR #79311)

2024-01-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Anatoly Trosinenko (atrosinenko)


Changes

Core LLVM has AArch64TargetParser.h header describing the mapping from Armv8.x 
and Armv9.x architecture extensions to the particular list of features that are 
mandatory for the extension.

Clang partially reimplements this in AArch64TargetInfo::setArchFeatures() 
function. This patch simplifies setArchFeatures() by dropping obvious cases of 
duplication, though it seems not all the dependencies are listed in 
AArch64TargetParser.h yet.

Specifically, this patch drops `HasX = true` statements for the following 
features:
* v8.1-a: CRC, LSE, RDM
* v8.3-a: RCPC, NeonMode (it is enabled by the base Armv8-a and indirectly by 
-target-feature +fcma)
* v8.4-a: DOTPROD
* v8.6-a: BF16, MATMUL

In Clang's AArch64TargetInfo::handleTargetFeatures() function, the string 
literal "+jscvt" is changed to "+jsconv" and "+cccp" to "+ccpp", so the 
information is conveyed from TargetParser.

Additionally, this patch makes __ARM_FEATURE_BTI and __ARM_FEATURE_JCVT 
conditional on the particular HasX flags instead of an architecture extension 
as a whole, as using TargetParser makes it possible to specify the requested 
architecture like "armv8.5+nojscvt".

---
Full diff: https://github.com/llvm/llvm-project/pull/79311.diff


1 Files Affected:

- (modified) clang/lib/Basic/Targets/AArch64.cpp (+15-34) 


``diff
diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index d47181bfca4fc8..76bb60db41099e 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -55,24 +55,18 @@ static constexpr Builtin::Info BuiltinInfo[] = {
 };
 
 void AArch64TargetInfo::setArchFeatures() {
+  // FIXME Could we drop this function altogether and migrate everything
+  //   to AArch64TargetParser in LLVM core?
   if (*ArchInfo == llvm::AArch64::ARMV8R) {
-HasDotProd = true;
 HasDIT = true;
 HasFlagM = true;
-HasRCPC = true;
-FPU |= NeonMode;
 HasCCPP = true;
-HasCRC = true;
 HasLSE = true;
-HasRDM = true;
   } else if (ArchInfo->Version.getMajor() == 8) {
 if (ArchInfo->Version.getMinor() >= 7u) {
   HasWFxT = true;
 }
-if (ArchInfo->Version.getMinor() >= 6u) {
-  HasBFloat16 = true;
-  HasMatMul = true;
-}
+// No special cases for Armv8.6-a
 if (ArchInfo->Version.getMinor() >= 5u) {
   HasAlternativeNZCV = true;
   HasFRInt3264 = true;
@@ -82,30 +76,19 @@ void AArch64TargetInfo::setArchFeatures() {
   HasBTI = true;
 }
 if (ArchInfo->Version.getMinor() >= 4u) {
-  HasDotProd = true;
   HasDIT = true;
   HasFlagM = true;
 }
-if (ArchInfo->Version.getMinor() >= 3u) {
-  HasRCPC = true;
-  FPU |= NeonMode;
-}
+// No special cases for Armv8.3-a
 if (ArchInfo->Version.getMinor() >= 2u) {
   HasCCPP = true;
 }
-if (ArchInfo->Version.getMinor() >= 1u) {
-  HasCRC = true;
-  HasLSE = true;
-  HasRDM = true;
-}
+// No special cases for Armv8.1-a
   } else if (ArchInfo->Version.getMajor() == 9) {
 if (ArchInfo->Version.getMinor() >= 2u) {
   HasWFxT = true;
 }
-if (ArchInfo->Version.getMinor() >= 1u) {
-  HasBFloat16 = true;
-  HasMatMul = true;
-}
+// No special cases for Armv9.1-a
 FPU |= SveMode;
 HasSVE2 = true;
 HasFullFP16 = true;
@@ -115,15 +98,9 @@ void AArch64TargetInfo::setArchFeatures() {
 HasSB = true;
 HasPredRes = true;
 HasBTI = true;
-HasDotProd = true;
 HasDIT = true;
 HasFlagM = true;
-HasRCPC = true;
-FPU |= NeonMode;
 HasCCPP = true;
-HasCRC = true;
-HasLSE = true;
-HasRDM = true;
   }
 }
 
@@ -257,7 +234,6 @@ void AArch64TargetInfo::getTargetDefinesARMV82A(const 
LangOptions &Opts,
 void AArch64TargetInfo::getTargetDefinesARMV83A(const LangOptions &Opts,
 MacroBuilder &Builder) const {
   Builder.defineMacro("__ARM_FEATURE_COMPLEX", "1");
-  Builder.defineMacro("__ARM_FEATURE_JCVT", "1");
   Builder.defineMacro("__ARM_FEATURE_PAUTH", "1");
   // Also include the Armv8.2 defines
   getTargetDefinesARMV82A(Opts, Builder);
@@ -272,7 +248,6 @@ void AArch64TargetInfo::getTargetDefinesARMV84A(const 
LangOptions &Opts,
 void AArch64TargetInfo::getTargetDefinesARMV85A(const LangOptions &Opts,
 MacroBuilder &Builder) const {
   Builder.defineMacro("__ARM_FEATURE_FRINT", "1");
-  Builder.defineMacro("__ARM_FEATURE_BTI", "1");
   // Also include the Armv8.4 defines
   getTargetDefinesARMV84A(Opts, Builder);
 }
@@ -472,7 +447,10 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
   if ((FPU & NeonMode) && HasFullFP16)
 Builder.defineMacro("__ARM_FEATURE_FP16_VECTOR_ARITHMETIC", "1");
   if (HasFullFP16)
-   Builder.defineMacro("__ARM_FEATURE_FP16_SCALAR_ARITHMETIC", "1");
+Builder.defineMacro("__A

[clang] [clang][analyzer] Improve modeling of 'popen' and 'pclose' in StdLibraryFunctionsChecker (PR #78895)

2024-01-25 Thread Balazs Benics via cfe-commits

https://github.com/steakhal approved this pull request.


https://github.com/llvm/llvm-project/pull/78895
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][analyzer] Improve modeling of 'popen' and 'pclose' in StdLibraryFunctionsChecker (PR #78895)

2024-01-25 Thread Ben Shi via cfe-commits


@@ -2211,6 +2221,15 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
   ErrnoNEZeroIrrelevant, GenericFailureMsg)
 .ArgConstraint(NotNull(ArgNo(0;
 
+// int pclose(FILE *stream);
+addToFunctionSummaryMap(
+"pclose", Signature(ArgTypes{FilePtrTy}, RetType{IntTy}),
+Summary(NoEvalCall)
+.Case({ReturnValueCondition(WithinRange, {{0, IntMax}})},
+  ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
+.ArgConstraint(NotNull(ArgNo(0;
+

benshi001 wrote:

@balazske What is your opinion?

I think we can keep current form:
1. Negative but non -1 return values are not mentioned in the POSIX document.
2. Negative return values are not supported on real world linux&MacOS.

There may be negative but non -1 return values on other platforms, however we 
currently choose a conservative way as current form.

https://github.com/llvm/llvm-project/pull/78895
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Sema]Substitue parameter packs when deduced from function parameter (PR #79371)

2024-01-25 Thread Gábor Spaits via cfe-commits


@@ -4371,6 +4397,41 @@ Sema::TemplateDeductionResult 
Sema::DeduceTemplateArguments(
   // corresponding argument is a list?
   PackScope.nextPackElement();
 }
+  } else if (!IsTrailingPack && !PackScope.isPartiallyExpanded() &&
+ PackScope.isDeducedFromEarlierParameter() &&
+ !isa(ParamTypes[ParamIdx + 1])) {
+// [temp.deduct.general#3]
+// When all template arguments have been deduced
+// or obtained from default template arguments, all uses of template
+// parameters in the template parameter list of the template are
+// replaced with the corresponding deduced or default argument values
+//
+// If we have a trailing parameter pack, that has been deduced
+// perviously we substitute the pack here in a similar fashion as seen
+// above with the trailing parameter packs. The main difference here is
+// that, in this case we are not processing all of the remaining
+// arguments. We are only process as many arguments as much we have in
+// the already deduced parameter.
+SmallVector Unexpanded;
+collectUnexpandedParameterPacks(ParamPattern, Unexpanded);
+if (Unexpanded.size() == 0)
+  continue;

spaits wrote:

I think it could be. In that case that every template packs that are needed by 
the dependent name are all expanded. For example this could happen when we use 
explicitly specified template arguments.

https://github.com/llvm/llvm-project/pull/79371
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Unbreak [[clang::suppress]] on checkers without decl-with-issue. (PR #79398)

2024-01-25 Thread Balazs Benics via cfe-commits

https://github.com/steakhal commented:

I only have minor nits. No objections.

https://github.com/llvm/llvm-project/pull/79398
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Unbreak [[clang::suppress]] on checkers without decl-with-issue. (PR #79398)

2024-01-25 Thread Balazs Benics via cfe-commits


@@ -27,6 +28,8 @@ class PathDiagnosticLocation;
 
 class BugSuppression {
 public:
+  BugSuppression(ASTContext &ACtx) : ACtx(ACtx) {}

steakhal wrote:

```suggestion
  explicit BugSuppression(const ASTContext &ACtx) : ACtx(ACtx) {}
```

https://github.com/llvm/llvm-project/pull/79398
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Unbreak [[clang::suppress]] on checkers without decl-with-issue. (PR #79398)

2024-01-25 Thread Balazs Benics via cfe-commits


@@ -44,7 +47,9 @@ class BugSuppression {
   using CachedRanges =
   llvm::SmallVector;
 
-  llvm::DenseMap CachedSuppressionLocations;
+  llvm::DenseMap CachedSuppressionLocations{};
+
+  ASTContext &ACtx;

steakhal wrote:

```suggestion
  llvm::DenseMap CachedSuppressionLocations;

  const ASTContext &ACtx;
```

https://github.com/llvm/llvm-project/pull/79398
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Unbreak [[clang::suppress]] on checkers without decl-with-issue. (PR #79398)

2024-01-25 Thread Balazs Benics via cfe-commits

https://github.com/steakhal edited 
https://github.com/llvm/llvm-project/pull/79398
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Sema]Substitue parameter packs when deduced from function parameter (PR #79371)

2024-01-25 Thread Gábor Spaits via cfe-commits

https://github.com/spaits edited https://github.com/llvm/llvm-project/pull/79371
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Interp] Cleaning up `FIXME`s added during `ArrayInitLoopExpr` implementation. (PR #70053)

2024-01-25 Thread Timm Baeder via cfe-commits


@@ -389,10 +390,29 @@ template  class LocalScope : public 
VariableScope {
   if (!Local.Desc->isPrimitive() && !Local.Desc->isPrimitiveArray()) {
 this->Ctx->emitGetPtrLocal(Local.Offset, SourceInfo{});
 this->Ctx->emitRecordDestruction(Local.Desc);
+removeIfStoredOpaqueValue(Local);
   }
 }
   }
 
+  void removeStoredOpaqueValues() {
+if (!Idx)
+  return;
+
+for (const Scope::Local &Local : this->Ctx->Descriptors[*Idx]) {
+  removeIfStoredOpaqueValue(Local);
+}
+  }
+
+  void removeIfStoredOpaqueValue(const Scope::Local &Local) {
+if (auto *OVE =
+llvm::dyn_cast_if_present(Local.Desc->asExpr())) {
+  if (auto it = this->Ctx->OpaqueExprs.find(OVE);

tbaederr wrote:

```suggestion
  if (auto It = this->Ctx->OpaqueExprs.find(OVE);
```

https://github.com/llvm/llvm-project/pull/70053
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Interp] Cleaning up `FIXME`s added during `ArrayInitLoopExpr` implementation. (PR #70053)

2024-01-25 Thread Timm Baeder via cfe-commits


@@ -54,7 +54,7 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
 public:
   /// Initializes the compiler and the backend emitter.
   template 
-  ByteCodeExprGen(Context &Ctx, Program &P, Tys &&... Args)
+  ByteCodeExprGen(Context &Ctx, Program &P, Tys &&...Args)

tbaederr wrote:

This and the next one are irrelevant whitespace changes.

https://github.com/llvm/llvm-project/pull/70053
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Interp] Cleaning up `FIXME`s added during `ArrayInitLoopExpr` implementation. (PR #70053)

2024-01-25 Thread Timm Baeder via cfe-commits


@@ -389,10 +390,29 @@ template  class LocalScope : public 
VariableScope {
   if (!Local.Desc->isPrimitive() && !Local.Desc->isPrimitiveArray()) {
 this->Ctx->emitGetPtrLocal(Local.Offset, SourceInfo{});
 this->Ctx->emitRecordDestruction(Local.Desc);
+removeIfStoredOpaqueValue(Local);
   }
 }
   }
 
+  void removeStoredOpaqueValues() {
+if (!Idx)
+  return;
+
+for (const Scope::Local &Local : this->Ctx->Descriptors[*Idx]) {
+  removeIfStoredOpaqueValue(Local);
+}
+  }
+
+  void removeIfStoredOpaqueValue(const Scope::Local &Local) {
+if (auto *OVE =

tbaederr wrote:

```suggestion
if (const auto *OVE =
```

https://github.com/llvm/llvm-project/pull/70053
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Diagnostics] Highlight code snippets (PR #66514)

2024-01-25 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/66514

>From 2a0b02a285203228944d5dd206f968e776757993 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Fri, 15 Sep 2023 15:51:39 +0200
Subject: [PATCH] [clang][Diagnostics] Highlight code snippets

Add some primitive syntax highlighting to our code snippet output.
---
 clang/docs/ReleaseNotes.rst   |   2 +
 clang/include/clang/Frontend/TextDiagnostic.h |  18 +-
 clang/include/clang/Lex/Preprocessor.h|  10 +
 clang/lib/Frontend/TextDiagnostic.cpp | 211 +-
 clang/lib/Frontend/TextDiagnosticPrinter.cpp  |   2 +-
 clang/lib/Lex/Preprocessor.cpp|  24 ++
 clang/test/Frontend/diagnostic-pipe.c |   9 +
 7 files changed, 262 insertions(+), 14 deletions(-)
 create mode 100644 clang/test/Frontend/diagnostic-pipe.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index db3d74e124e7d1d..6f5fe2049e242fc 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -97,6 +97,8 @@ Attribute Changes in Clang
 
 Improvements to Clang's diagnostics
 ---
+- Clang now applies syntax highlighting to the code snippets it
+  prints.
 
 Improvements to Clang's time-trace
 --
diff --git a/clang/include/clang/Frontend/TextDiagnostic.h 
b/clang/include/clang/Frontend/TextDiagnostic.h
index 7eb0ab0cdc9bca8..a2fe8ae995423b9 100644
--- a/clang/include/clang/Frontend/TextDiagnostic.h
+++ b/clang/include/clang/Frontend/TextDiagnostic.h
@@ -16,6 +16,7 @@
 #define LLVM_CLANG_FRONTEND_TEXTDIAGNOSTIC_H
 
 #include "clang/Frontend/DiagnosticRenderer.h"
+#include "llvm/Support/raw_ostream.h"
 
 namespace clang {
 
@@ -33,14 +34,22 @@ namespace clang {
 /// printing coming out of libclang.
 class TextDiagnostic : public DiagnosticRenderer {
   raw_ostream &OS;
+  const Preprocessor *PP;
 
 public:
-  TextDiagnostic(raw_ostream &OS,
- const LangOptions &LangOpts,
- DiagnosticOptions *DiagOpts);
+  TextDiagnostic(raw_ostream &OS, const LangOptions &LangOpts,
+ DiagnosticOptions *DiagOpts, const Preprocessor *PP = 
nullptr);
 
   ~TextDiagnostic() override;
 
+  struct StyleRange {
+unsigned Start;
+unsigned End;
+enum llvm::raw_ostream::Colors Color;
+StyleRange(unsigned S, unsigned E, enum llvm::raw_ostream::Colors C)
+: Start(S), End(E), Color(C){};
+  };
+
   /// Print the diagonstic level to a raw_ostream.
   ///
   /// This is a static helper that handles colorizing the level and formatting
@@ -104,7 +113,8 @@ class TextDiagnostic : public DiagnosticRenderer {
ArrayRef Hints);
 
   void emitSnippet(StringRef SourceLine, unsigned MaxLineNoDisplayWidth,
-   unsigned LineNo);
+   unsigned LineNo, unsigned DisplayLineNo,
+   ArrayRef Styles);
 
   void emitParseableFixits(ArrayRef Hints, const SourceManager &SM);
 };
diff --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index 2d9c53cdf5bde8e..9d0d53129a12dd9 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -284,6 +284,13 @@ class Preprocessor {
   /// The kind of translation unit we are processing.
   const TranslationUnitKind TUKind;
 
+  /// Returns a pointer into the given file's buffer that's guaranteed
+  /// to be between tokens. The returned pointer is always before \p Start.
+  /// The maximum distance betweenthe returned pointer and \p Start is
+  /// limited by a constant value, but also an implementation detail.
+  /// If no such check point exists, \c nullptr is returned.
+  const char *getCheckPoint(FileID FID, const char *Start) const;
+
 private:
   /// The code-completion handler.
   CodeCompletionHandler *CodeComplete = nullptr;
@@ -311,6 +318,9 @@ class Preprocessor {
   /// The import path for named module that we're currently processing.
   SmallVector, 2> 
NamedModuleImportPath;
 
+  llvm::DenseMap> CheckPoints;
+  unsigned CheckPointCounter = 0;
+
   /// Whether the import is an `@import` or a standard c++ modules import.
   bool IsAtImport = false;
 
diff --git a/clang/lib/Frontend/TextDiagnostic.cpp 
b/clang/lib/Frontend/TextDiagnostic.cpp
index 779dead5d058d1a..291d71f6db61f17 100644
--- a/clang/lib/Frontend/TextDiagnostic.cpp
+++ b/clang/lib/Frontend/TextDiagnostic.cpp
@@ -12,6 +12,7 @@
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Lex/Lexer.h"
+#include "clang/Lex/Preprocessor.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/ConvertUTF.h"
@@ -41,6 +42,14 @@ static const enum raw_ostream::Colors fatalColor = 
raw_ostream::RED;
 static const enum raw_ostream::Colors savedColor =
   raw_ostream::SAVEDCOLOR;
 
+// Magenta is taken for 'warning'. Red is already 'error' and 'c

[clang] [clang][dataflow] Treat comma operator correctly in `getResultObjectLocation()`. (PR #78427)

2024-01-25 Thread via cfe-commits

martinboehme wrote:

> > You mean the publicness of `getResultObjectLocation()`?
> 
> Yeah, I was wondering if it would be more user friendly if something like 
> `State.Env.get(Expr);` would automatically recognize 
> that the user actually wants the result location and returned that without 
> the user having to consider this special case explicitly.

Thanks, I understand now.

I see the attraction, but I think it would dilute the semantics of 
`get>`. Currently, this method may only be called 
on glvalues, and that makes it very clear what it will return -- as a glvalue 
_is a_ storage location.

Extending `get>` to do what 
`getResultObjectLocation()` does today means that it would become permissible 
to call this method on prvalues (of record type), and the semantics of what 
this operation does would be quite different from what it does on glvalues, and 
more involved -- because it would now be returning the storage location of a 
_different_ AST node (the result object), and connecting the AST node for the 
result object to the prvalue is not entirely trivial.

I think it would therefore be better to make this difference in semantics clear 
by separating out the "get the result object location for a record prvalue" 
operation into a separate method.

https://github.com/llvm/llvm-project/pull/78427
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenMP][Clang] Handle unsupported inscan modifier for generic types (PR #79431)

2024-01-25 Thread Saiyedul Islam via cfe-commits


@@ -12,28 +12,6 @@
 
 void foo() {}
 
-template 

saiislam wrote:

How was this test case working till now when templates were not supported in 
scan?

https://github.com/llvm/llvm-project/pull/79431
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Sema]Substitue parameter packs when deduced from function parameter (PR #79371)

2024-01-25 Thread Gábor Spaits via cfe-commits

https://github.com/spaits updated 
https://github.com/llvm/llvm-project/pull/79371

From d4ca5c2fcb87f424be23efc4513df491403c3811 Mon Sep 17 00:00:00 2001
From: Gabor Spaits 
Date: Wed, 24 Jan 2024 21:21:26 +0100
Subject: [PATCH 1/6] [Sema]Substitue template parameter packs when deduced
 from function parameter

---
 clang/lib/Sema/SemaTemplateDeduction.cpp | 63 +++-
 1 file changed, 62 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index e9e7ab5bb6698a0..46fa9eece3747a2 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -730,6 +730,7 @@ class PackDeductionScope {
   void addPack(unsigned Index) {
 // Save the deduced template argument for the parameter pack expanded
 // by this pack expansion, then clear out the deduction.
+DeducedFromEarlierParameter = !Deduced[Index].isNull();
 DeducedPack Pack(Index);
 Pack.Saved = Deduced[Index];
 Deduced[Index] = TemplateArgument();
@@ -858,6 +859,29 @@ class PackDeductionScope {
   Info.PendingDeducedPacks[Pack.Index] = Pack.Outer;
   }
 
+  std::optional getSavedPackSize(unsigned Index,
+   TemplateArgument Pattern) const {
+
+SmallVector Unexpanded;
+S.collectUnexpandedParameterPacks(Pattern, Unexpanded);
+if (Unexpanded.size() == 0 ||
+Packs[0].Saved.getKind() != clang::TemplateArgument::Pack)
+  return {};
+unsigned PackSize = Packs[0].Saved.pack_size();
+
+if (std::all_of(Packs.begin() + 1, Packs.end(),
+[&PackSize](auto P) {
+  return P.Saved.getKind() == TemplateArgument::Pack &&
+ P.Saved.pack_size() == PackSize;
+}))
+  return PackSize;
+return {};
+  }
+
+  /// Determine whether this pack has already been deduced from a previous
+  /// argument.
+  bool isDeducedFromEarlierParameter() const {return 
DeducedFromEarlierParameter;}
+
   /// Determine whether this pack has already been partially expanded into a
   /// sequence of (prior) function parameters / template arguments.
   bool isPartiallyExpanded() { return IsPartiallyExpanded; }
@@ -970,7 +994,6 @@ class PackDeductionScope {
 NewPack = Pack.DeferredDeduction;
 Result = checkDeducedTemplateArguments(S.Context, OldPack, NewPack);
   }
-
   NamedDecl *Param = TemplateParams->getParam(Pack.Index);
   if (Result.isNull()) {
 Info.Param = makeTemplateParameter(Param);
@@ -1003,9 +1026,12 @@ class PackDeductionScope {
   unsigned PackElements = 0;
   bool IsPartiallyExpanded = false;
   bool DeducePackIfNotAlreadyDeduced = false;
+  bool DeducedFromEarlierParameter = false;
+
   /// The number of expansions, if we have a fully-expanded pack in this scope.
   std::optional FixedNumExpansions;
 
+
   SmallVector Packs;
 };
 
@@ -4371,6 +4397,41 @@ Sema::TemplateDeductionResult 
Sema::DeduceTemplateArguments(
   // corresponding argument is a list?
   PackScope.nextPackElement();
 }
+  } else if (!IsTrailingPack && !PackScope.isPartiallyExpanded() &&
+ PackScope.isDeducedFromEarlierParameter() &&
+ !isa(ParamTypes[ParamIdx + 1])) {
+// [temp.deduct.general#3]
+// When all template arguments have been deduced
+// or obtained from default template arguments, all uses of template
+// parameters in the template parameter list of the template are
+// replaced with the corresponding deduced or default argument values
+//
+// If we have a trailing parameter pack, that has been deduced 
perviously
+// we substitute the pack here in a similar fashion as seen above with
+// the trailing parameter packs. The main difference here is that, in
+// this case we are not processing all of the remaining arguments. We
+// are only process as many arguments as much we have in the already
+// deduced parameter.
+SmallVector Unexpanded;
+collectUnexpandedParameterPacks(ParamPattern, Unexpanded);
+if (Unexpanded.size() == 0)
+  continue;
+
+std::optional ArgPosAfterSubstitution =
+PackScope.getSavedPackSize(getDepthAndIndex(Unexpanded[0]).second,
+   ParamPattern);
+if (!ArgPosAfterSubstitution)
+  continue;
+
+unsigned PackArgEnd = ArgIdx + *ArgPosAfterSubstitution;
+for (; ArgIdx < PackArgEnd && ArgIdx < Args.size(); ArgIdx++) {
+  ParamTypesForArgChecking.push_back(ParamPattern);
+  if (auto Result = DeduceCallArgument(ParamPattern, ArgIdx,
+   
/*ExplicitObjetArgument=*/false))
+return Result;
+
+  PackScope.nextPackElement();
+}
   }
 }
 

From 52de421b998481105e5522a04ad9e39a4a6cbb

[clang] [clang][analyzer] Simplify code of StreamChecker (NFC). (PR #79312)

2024-01-25 Thread via cfe-commits

NagyDonat wrote:

I'm seconding the suggestions of @steakhal, and in particular I agree with
> I'd also advise against using more callables bundled with CallDescriptions. 
> They make debugging code more difficult, as the control-flow would become 
> also data-dependent. I'd suggest other ways to generalize.

Instead of creating this shared framework that calls different callbacks 
depending on the checked function, consider keeping separate top-level 
evaluator functions that rely on a shared set of smaller tool-like helper 
functions.

https://github.com/llvm/llvm-project/pull/79312
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][analyzer] Simplify code of StreamChecker (NFC). (PR #79312)

2024-01-25 Thread Balazs Benics via cfe-commits

steakhal wrote:

> I'm seconding the suggestions of @steakhal, and in particular I agree with
> 
> > I'd also advise against using more callables bundled with CallDescriptions. 
> > They make debugging code more difficult, as the control-flow would become 
> > also data-dependent. I'd suggest other ways to generalize.
> 
> Instead of creating this shared framework that calls different callbacks 
> depending on the checked function, consider keeping separate top-level 
> evaluator functions that rely on a shared set of smaller tool-like helper 
> functions.

One more not about composability.
In general, `addTransition` calls don't compose, thus limits reusability.
For example, `preReadWrite` should be reusable from other precondition 
handlers, such that the new one can just call `preReadWrite` and then do some 
other more specialized checks. However, once a handler calls `addTransition` we 
are done. We no longer can simply wrap it, aka. compose with other 
functionalities.
Consequently, I'd suggest to have some common pattern, such as return state 
pointers, or NULL if an error was reported. And leave the `addTransition` to 
the caller - if they chose to call it.

`eval*` handlers are more difficult to compose, given that they also need to 
bind the return value and apply their sideffects, but I believe we could 
achieve similar objectives there too (thus, have refined, composable handlers, 
combined in useful ways).

https://github.com/llvm/llvm-project/pull/79312
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libc] [compiler-rt] [libclc] [lldb] [clang-tools-extra] [flang] [libcxx] [libcxxabi] [llvm] [lld] [clang] [VPlan] Add new VPScalarCastRecipe, use for IV & step trunc. (PR #78113)

2024-01-25 Thread Florian Hahn via cfe-commits

https://github.com/fhahn edited https://github.com/llvm/llvm-project/pull/78113
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenMP][Clang] Handle unsupported inscan modifier for generic types (PR #79431)

2024-01-25 Thread Alexey Bataev via cfe-commits


@@ -19520,6 +19520,13 @@ static bool actOnOMPReductionKindClause(
   bool FirstIter = true;
   for (Expr *RefExpr : VarList) {
 assert(RefExpr && "nullptr expr in OpenMP reduction clause.");
+if (ClauseKind == OMPC_reduction &&
+RD.RedModifier == OMPC_REDUCTION_inscan && RefExpr->isTypeDependent()) 
{
+  S.Diag(RefExpr->getExprLoc(),
+ diag::err_omp_inscan_reduction_on_template_type);
+  continue;
+}
+

alexey-bataev wrote:

This is definetely wrong, templates should be supported

https://github.com/llvm/llvm-project/pull/79431
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] [libcxxabi] [clang] [flang] [lldb] [llvm] [libclc] [clang-tools-extra] [compiler-rt] [libc] [lld] [VPlan] Add new VPScalarCastRecipe, use for IV & step trunc. (PR #78113)

2024-01-25 Thread Florian Hahn via cfe-commits

https://github.com/fhahn edited https://github.com/llvm/llvm-project/pull/78113
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] [libcxxabi] [clang] [flang] [lldb] [llvm] [libclc] [clang-tools-extra] [compiler-rt] [libc] [lld] [VPlan] Add new VPScalarCastRecipe, use for IV & step trunc. (PR #78113)

2024-01-25 Thread Florian Hahn via cfe-commits

https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/78113

>From 36b085f21b76d7bf7c9965a86a09d1cef4fe9329 Mon Sep 17 00:00:00 2001
From: Florian Hahn 
Date: Sun, 14 Jan 2024 14:13:08 +
Subject: [PATCH 1/6] [VPlan] Add new VPUniformPerUFRecipe, use for step
 truncation.

Add a new recipe to model uniform-per-UF instructions, without relying
on an underlying instruction. Initially, it supports uniform cast-ops
and is therefore storing the result type.

Not relying on an underlying instruction (like the current
VPReplicateRecipe) allows to create instances without a corresponding
instruction.

In the future, to plan is to extend this recipe to handle all opcodes
needed to replace the uniform part of VPReplicateRecipe.
---
 llvm/lib/Transforms/Vectorize/VPlan.h | 30 
 .../Transforms/Vectorize/VPlanAnalysis.cpp|  6 ++-
 .../lib/Transforms/Vectorize/VPlanRecipes.cpp | 49 ---
 .../Transforms/Vectorize/VPlanTransforms.cpp  |  9 
 llvm/lib/Transforms/Vectorize/VPlanValue.h|  1 +
 .../LoopVectorize/cast-induction.ll   |  4 +-
 .../interleave-and-scalarize-only.ll  |  3 +-
 .../pr46525-expander-insertpoint.ll   |  2 +-
 8 files changed, 93 insertions(+), 11 deletions(-)

diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h 
b/llvm/lib/Transforms/Vectorize/VPlan.h
index 4b4f4911eb6415e..d5985224488 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -1945,6 +1945,36 @@ class VPReplicateRecipe : public VPRecipeWithIRFlags, 
public VPValue {
   }
 };
 
+/// VPUniformPerUFRecipe represents an instruction with Opcode that is uniform
+/// per UF, i.e. it generates a single scalar instance per UF.
+/// TODO: at the moment, only Cast opcodes are supported, extend to support
+///   missing opcodes to replace uniform part of VPReplicateRecipe.
+class VPUniformPerUFRecipe : public VPRecipeBase, public VPValue {
+  unsigned Opcode;
+
+  /// Result type for the cast.
+  Type *ResultTy;
+
+  Value *generate(VPTransformState &State, unsigned Part);
+
+public:
+  VPUniformPerUFRecipe(Instruction::CastOps Opcode, VPValue *Op, Type 
*ResultTy)
+  : VPRecipeBase(VPDef::VPUniformPerUFSC, {Op}), VPValue(this),
+Opcode(Opcode), ResultTy(ResultTy) {}
+
+  ~VPUniformPerUFRecipe() override = default;
+
+  VP_CLASSOF_IMPL(VPDef::VPWidenIntOrFpInductionSC)
+
+  void execute(VPTransformState &State) override;
+
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+  /// Print the recipe.
+  void print(raw_ostream &O, const Twine &Indent,
+ VPSlotTracker &SlotTracker) const override;
+#endif
+};
+
 /// A recipe for generating conditional branches on the bits of a mask.
 class VPBranchOnMaskRecipe : public VPRecipeBase {
 public:
diff --git a/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp 
b/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp
index 97a8a1803bbf5a5..d71b07039944500 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp
@@ -230,7 +230,11 @@ Type *VPTypeAnalysis::inferScalarType(const VPValue *V) {
 return V->getUnderlyingValue()->getType();
   })
   .Case(
-  [](const VPWidenCastRecipe *R) { return R->getResultType(); });
+  [](const VPWidenCastRecipe *R) { return R->getResultType(); })
+  .Case([](const VPExpandSCEVRecipe *R) {
+return R->getSCEV()->getType();
+  });
+
   assert(ResultTy && "could not infer type for the given VPValue");
   CachedTypes[V] = ResultTy;
   return ResultTy;
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp 
b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index 1f844bce23102e2..423504e8f7e05e7 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -164,6 +164,8 @@ bool VPRecipeBase::mayHaveSideEffects() const {
 auto *R = cast(this);
 return R->getUnderlyingInstr()->mayHaveSideEffects();
   }
+  case VPUniformPerUFSC:
+return false;
   default:
 return true;
   }
@@ -1117,13 +1119,7 @@ void VPScalarIVStepsRecipe::execute(VPTransformState 
&State) {
 
   // Ensure step has the same type as that of scalar IV.
   Type *BaseIVTy = BaseIV->getType()->getScalarType();
-  if (BaseIVTy != Step->getType()) {
-// TODO: Also use VPDerivedIVRecipe when only the step needs truncating, to
-// avoid separate truncate here.
-assert(Step->getType()->isIntegerTy() &&
-   "Truncation requires an integer step");
-Step = State.Builder.CreateTrunc(Step, BaseIVTy);
-  }
+  assert(BaseIVTy == Step->getType());
 
   // We build scalar steps for both integer and floating-point induction
   // variables. Here, we determine the kind of arithmetic we will perform.
@@ -1469,6 +1465,45 @@ void VPReplicateRecipe::print(raw_ostream &O, const 
Twine &Indent,
 }
 #endif
 
+Value *VPUniformPerUFRecipe ::generate(VPTransform

[libc] [compiler-rt] [libclc] [lldb] [clang-tools-extra] [flang] [libcxx] [libcxxabi] [llvm] [lld] [clang] [VPlan] Add new VPScalarCastRecipe, use for IV & step trunc. (PR #78113)

2024-01-25 Thread Florian Hahn via cfe-commits


@@ -1469,6 +1461,52 @@ void VPReplicateRecipe::print(raw_ostream &O, const 
Twine &Indent,
 }
 #endif
 
+static bool isUniformAcrossVFsAndUFs(VPScalarCastRecipe *C) {

fhahn wrote:

Added comment + TODO, thanks!

https://github.com/llvm/llvm-project/pull/78113
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] [libcxxabi] [clang] [flang] [lldb] [llvm] [libclc] [clang-tools-extra] [compiler-rt] [libc] [lld] [VPlan] Add new VPScalarCastRecipe, use for IV & step trunc. (PR #78113)

2024-01-25 Thread Florian Hahn via cfe-commits

https://github.com/fhahn edited https://github.com/llvm/llvm-project/pull/78113
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[compiler-rt] [lldb] [flang] [libc] [libcxxabi] [llvm] [lld] [libcxx] [clang] [libclc] [clang-tools-extra] [VPlan] Add new VPScalarCastRecipe, use for IV & step trunc. (PR #78113)

2024-01-25 Thread Florian Hahn via cfe-commits


@@ -230,7 +230,11 @@ Type *VPTypeAnalysis::inferScalarType(const VPValue *V) {
 return V->getUnderlyingValue()->getType();
   })
   .Case(
-  [](const VPWidenCastRecipe *R) { return R->getResultType(); });
+  [](const VPWidenCastRecipe *R) { return R->getResultType(); })
+  .Case([](const VPExpandSCEVRecipe *R) {

fhahn wrote:

VPDerivedIVRecipe getScalarType would be good to remove, will do as follow-up.

`VPWidenIntOrFpInductionRecipe's` trunc drives truncating the start value and 
step, effectively creating a narrow phi. I'll check to see if this can also be 
modeled with the new recipe.

https://github.com/llvm/llvm-project/pull/78113
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [flang] [libc] [lld] [libclc] [libcxx] [lldb] [clang] [clang-tools-extra] [libcxxabi] [compiler-rt] [VPlan] Add new VPScalarCastRecipe, use for IV & step trunc. (PR #78113)

2024-01-25 Thread Florian Hahn via cfe-commits

https://github.com/fhahn commented:

Comments should be addressed and title & description updated, thanks!

https://github.com/llvm/llvm-project/pull/78113
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libclc] [libcxx] [libcxxabi] [llvm] [clang-tools-extra] [flang] [libc] [compiler-rt] [lldb] [lld] [clang] [VPlan] Add new VPScalarCastRecipe, use for IV & step trunc. (PR #78113)

2024-01-25 Thread Florian Hahn via cfe-commits


@@ -1469,6 +1461,52 @@ void VPReplicateRecipe::print(raw_ostream &O, const 
Twine &Indent,
 }
 #endif
 
+static bool isUniformAcrossVFsAndUFs(VPScalarCastRecipe *C) {
+  return C->isDefinedOutsideVectorRegions() ||
+ isa(C->getOperand(0)) ||
+ isa(C->getOperand(0));
+}
+
+Value *VPScalarCastRecipe ::generate(VPTransformState &State, unsigned Part) {
+  assert(vputils::onlyFirstLaneUsed(this) &&
+ "Codegen only implemented for first lane.");
+  switch (Opcode) {
+  case Instruction::SExt:
+  case Instruction::ZExt:

fhahn wrote:

Yep, could remove if preferred, but `State.Builder.CreateCast` generically 
supports any cast

https://github.com/llvm/llvm-project/pull/78113
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] [lld] [lldb] [flang] [compiler-rt] [llvm] [libcxxabi] [libclc] [clang] [libc] [clang-tools-extra] [VPlan] Add new VPScalarCastRecipe, use for IV & step trunc. (PR #78113)

2024-01-25 Thread Florian Hahn via cfe-commits


@@ -498,10 +498,34 @@ static VPValue *createScalarIVSteps(VPlan &Plan, const 
InductionDescriptor &ID,
   VPCanonicalIVPHIRecipe *CanonicalIV = Plan.getCanonicalIV();
   Type *TruncTy = TruncI ? TruncI->getType() : IVTy;
   VPValue *BaseIV = CanonicalIV;

fhahn wrote:

Updated, thanks! This works well now with the refactoring in this patch. IVTy 
removed.

https://github.com/llvm/llvm-project/pull/78113
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [AArch64] Simplify Clang's description of architecture extensions (PR #79311)

2024-01-25 Thread via cfe-commits


@@ -741,7 +722,7 @@ bool 
AArch64TargetInfo::handleTargetFeatures(std::vector &Features,
 
 if (Feature == "+neon" || Feature == "+fp-armv8")
   FPU |= NeonMode;
-if (Feature == "+jscvt") {
+if (Feature == "+jsconv") {

ostannard wrote:

This looks like bug fix which would make a functional difference, does it need 
a test?

https://github.com/llvm/llvm-project/pull/79311
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [AArch64] Simplify Clang's description of architecture extensions (PR #79311)

2024-01-25 Thread via cfe-commits


@@ -860,7 +841,7 @@ bool 
AArch64TargetInfo::handleTargetFeatures(std::vector &Features,
 }
 if (Feature == "+dit")
   HasDIT = true;
-if (Feature == "+cccp")
+if (Feature == "+ccpp")

ostannard wrote:

Again, does this need a test?

https://github.com/llvm/llvm-project/pull/79311
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Coverage] Map regions from system headers (PR #76950)

2024-01-25 Thread NAKAMURA Takumi via cfe-commits

chapuni wrote:

Seems this causes the crash with `-fcoverage-mcdc -mllvm 
-system-headers-coverage`. Investigating.
See also #78920.

https://github.com/llvm/llvm-project/pull/76950
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [flang] [libc] [libcxx] [clang] [mlir] [clang-tools-extra] [openmp] [libcxxabi] [compiler-rt] [AArch64] Combine store (trunc X to <3 x i8>) to sequence of ST1.b. (PR #78637)

2024-01-25 Thread Florian Hahn via cfe-commits

https://github.com/fhahn updated https://github.com/llvm/llvm-project/pull/78637

>From efd07e93aed51049ad3783c701284617ae446330 Mon Sep 17 00:00:00 2001
From: Florian Hahn 
Date: Wed, 17 Jan 2024 11:11:59 +
Subject: [PATCH 1/7] [AArch64] Combine store (trunc X to <3 x i8>) to sequence
 of ST1.b.

Improve codegen for (trunc X to <3 x i8>) by converting it to a sequence
of 3 ST1.b, but first converting the truncate operand to either v8i8 or
v16i8, extracting the lanes for the truncate results and storing them.

At the moment, there are almost no cases in which such vector operations
will be generated automatically. The motivating case is non-power-of-2
SLP vectorization: https://github.com/llvm/llvm-project/pull/77790
---
 .../Target/AArch64/AArch64ISelLowering.cpp| 50 +++
 .../AArch64/vec3-loads-ext-trunc-stores.ll| 33 +---
 2 files changed, 62 insertions(+), 21 deletions(-)

diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp 
b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index 8a6f1dc7487bae..4be78f61fe7b65 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -21318,6 +21318,53 @@ bool isHalvingTruncateOfLegalScalableType(EVT SrcVT, 
EVT DstVT) {
  (SrcVT == MVT::nxv2i64 && DstVT == MVT::nxv2i32);
 }
 
+// Combine store (trunc X to <3 x i8>) to sequence of ST1.b.
+static SDValue combineI8TruncStore(StoreSDNode *ST, SelectionDAG &DAG,
+   const AArch64Subtarget *Subtarget) {
+  SDValue Value = ST->getValue();
+  EVT ValueVT = Value.getValueType();
+
+  if (ST->isVolatile() || !Subtarget->isLittleEndian() ||
+  ST->getOriginalAlign() >= 4 || Value.getOpcode() != ISD::TRUNCATE ||
+  ValueVT != EVT::getVectorVT(*DAG.getContext(), MVT::i8, 3))
+return SDValue();
+
+  SDLoc DL(ST);
+  auto WideVT = EVT::getVectorVT(
+  *DAG.getContext(),
+  Value->getOperand(0).getValueType().getVectorElementType(), 4);
+  SDValue UndefVector = DAG.getUNDEF(WideVT);
+  SDValue WideTrunc = DAG.getNode(
+  ISD::INSERT_SUBVECTOR, DL, WideVT,
+  {UndefVector, Value->getOperand(0), DAG.getVectorIdxConstant(0, DL)});
+  SDValue Cast = DAG.getNode(
+  ISD::BITCAST, DL, WideVT.getSizeInBits() == 64 ? MVT::v8i8 : MVT::v16i8,
+  WideTrunc);
+
+  SDValue Chain = ST->getChain();
+  SDValue E2 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::i8, Cast,
+   DAG.getConstant(8, DL, MVT::i64));
+
+  SDValue Ptr2 =
+  DAG.getMemBasePlusOffset(ST->getBasePtr(), TypeSize::getFixed(2), DL);
+  Chain = DAG.getStore(Chain, DL, E2, Ptr2, ST->getPointerInfo(),
+   ST->getOriginalAlign());
+
+  SDValue E1 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::i8, Cast,
+   DAG.getConstant(4, DL, MVT::i64));
+
+  SDValue Ptr1 =
+  DAG.getMemBasePlusOffset(ST->getBasePtr(), TypeSize::getFixed(1), DL);
+  Chain = DAG.getStore(Chain, DL, E1, Ptr1, ST->getPointerInfo(),
+   ST->getOriginalAlign());
+  SDValue E0 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::i8, Cast,
+   DAG.getConstant(0, DL, MVT::i64));
+  Chain = DAG.getStore(Chain, DL, E0, ST->getBasePtr(), ST->getPointerInfo(),
+   ST->getOriginalAlign());
+
+  return Chain;
+}
+
 static SDValue performSTORECombine(SDNode *N,
TargetLowering::DAGCombinerInfo &DCI,
SelectionDAG &DAG,
@@ -21333,6 +21380,9 @@ static SDValue performSTORECombine(SDNode *N,
 return EltVT == MVT::f32 || EltVT == MVT::f64;
   };
 
+  if (SDValue Res = combineI8TruncStore(ST, DAG, Subtarget))
+return Res;
+
   // If this is an FP_ROUND followed by a store, fold this into a truncating
   // store. We can do this even if this is already a truncstore.
   // We purposefully don't care about legality of the nodes here as we know
diff --git a/llvm/test/CodeGen/AArch64/vec3-loads-ext-trunc-stores.ll 
b/llvm/test/CodeGen/AArch64/vec3-loads-ext-trunc-stores.ll
index 9eeb194409df6f..60639ea91fbaa1 100644
--- a/llvm/test/CodeGen/AArch64/vec3-loads-ext-trunc-stores.ll
+++ b/llvm/test/CodeGen/AArch64/vec3-loads-ext-trunc-stores.ll
@@ -154,17 +154,12 @@ define <3 x i32> @load_v3i32(ptr %src) {
 define void @store_trunc_from_64bits(ptr %src, ptr %dst) {
 ; CHECK-LABEL: store_trunc_from_64bits:
 ; CHECK:   ; %bb.0: ; %entry
-; CHECK-NEXT:sub sp, sp, #16
-; CHECK-NEXT:.cfi_def_cfa_offset 16
-; CHECK-NEXT:ldr s0, [x0]
-; CHECK-NEXT:ldrh w8, [x0, #4]
-; CHECK-NEXT:mov.h v0[2], w8
-; CHECK-NEXT:xtn.8b v0, v0
-; CHECK-NEXT:str s0, [sp, #12]
-; CHECK-NEXT:ldrh w9, [sp, #12]
-; CHECK-NEXT:strb w8, [x1, #2]
-; CHECK-NEXT:strh w9, [x1]
-; CHECK-NEXT:add sp, sp, #16
+; CHECK-NEXT:add x8, x0, #4
+; CHECK-NEXT:ld1r.4h { v0 }, [x8]
+; CHECK-NEXT:ldr w8, [x0]
+; CHECK-NEXT:strb w8, [x1]
+; CHECK-NEX

[lld] [llvm] [clang] Embed the command line arguments during LTO (PR #79390)

2024-01-25 Thread Duncan Ogilvie via cfe-commits

https://github.com/mrexodia updated 
https://github.com/llvm/llvm-project/pull/79390

>From 67280cb8a77931271e685f7c92718d45cfea69a8 Mon Sep 17 00:00:00 2001
From: Duncan Ogilvie 
Date: Thu, 25 Jan 2024 00:08:49 +0100
Subject: [PATCH] Embed the command line arguments during LTO

---
 clang/lib/CodeGen/BackendUtil.cpp|  3 +-
 lld/COFF/Driver.cpp  |  1 +
 lld/COFF/LTO.cpp |  3 +-
 lld/Common/CommonLinkerContext.cpp   |  9 ++
 lld/ELF/Driver.cpp   |  1 +
 lld/ELF/LTO.cpp  |  3 +-
 lld/MachO/Driver.cpp |  1 +
 lld/MachO/LTO.cpp|  3 +-
 lld/MinGW/Driver.cpp |  1 +
 lld/include/lld/Common/CommonLinkerContext.h |  3 ++
 lld/wasm/Driver.cpp  |  1 +
 lld/wasm/LTO.cpp |  2 ++
 llvm/include/llvm/LTO/Config.h   |  2 +-
 llvm/include/llvm/LTO/LTOBackend.h   |  6 ++--
 llvm/lib/Bitcode/Writer/BitcodeWriter.cpp| 14 ++
 llvm/lib/LTO/LTO.cpp |  3 +-
 llvm/lib/LTO/LTOBackend.cpp  | 29 ++--
 llvm/lib/LTO/LTOCodeGenerator.cpp|  3 +-
 18 files changed, 52 insertions(+), 36 deletions(-)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index ec203f6f28bc173..71aee18e63574e8 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1208,6 +1208,7 @@ static void runThinLTOBackend(
   Conf.CPU = TOpts.CPU;
   Conf.CodeModel = getCodeModel(CGOpts);
   Conf.MAttrs = TOpts.Features;
+  Conf.EmbedCmdArgs = CGOpts.CmdArgs;
   Conf.RelocModel = CGOpts.RelocationModel;
   std::optional OptLevelOrNone =
   CodeGenOpt::getLevel(CGOpts.OptimizationLevel);
@@ -1269,7 +1270,7 @@ static void runThinLTOBackend(
   if (Error E =
   thinBackend(Conf, -1, AddStream, *M, *CombinedIndex, ImportList,
   ModuleToDefinedGVSummaries[M->getModuleIdentifier()],
-  /* ModuleMap */ nullptr, CGOpts.CmdArgs)) {
+  /* ModuleMap */ nullptr)) {
 handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) {
   errs() << "Error running ThinLTO backend: " << EIB.message() << '\n';
 });
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index e0afb6b18805b2e..941e6851c1bd4c5 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -1447,6 +1447,7 @@ void LinkerDriver::linkerMain(ArrayRef 
argsArr) {
   // Parse command line options.
   ArgParser parser(ctx);
   opt::InputArgList args = parser.parse(argsArr);
+  ctx.storeCmdArgs(args);
 
   // Initialize time trace profiler.
   config->timeTraceEnabled = args.hasArg(OPT_time_trace_eq);
diff --git a/lld/COFF/LTO.cpp b/lld/COFF/LTO.cpp
index 7df931911213672..26f5d42e847def9 100644
--- a/lld/COFF/LTO.cpp
+++ b/lld/COFF/LTO.cpp
@@ -52,8 +52,7 @@ lto::Config BitcodeCompiler::createConfig() {
   lto::Config c;
   c.Options = initTargetOptionsFromCodeGenFlags();
   c.Options.EmitAddrsig = true;
-  for (StringRef C : ctx.config.mllvmOpts)
-c.MllvmArgs.emplace_back(C.str());
+  c.EmbedCmdArgs = context().cmdArgs;
 
   // Always emit a section per function/datum with LTO. LLVM LTO should get 
most
   // of the benefit of linker GC, but there are still opportunities for ICF.
diff --git a/lld/Common/CommonLinkerContext.cpp 
b/lld/Common/CommonLinkerContext.cpp
index 12f56bc10ec9631..57aae8fd0a703d8 100644
--- a/lld/Common/CommonLinkerContext.cpp
+++ b/lld/Common/CommonLinkerContext.cpp
@@ -37,6 +37,15 @@ CommonLinkerContext::~CommonLinkerContext() {
   lctx = nullptr;
 }
 
+void CommonLinkerContext::storeCmdArgs(const llvm::opt::ArgList &args) {
+  cmdArgs.clear();
+  for (const llvm::opt::Arg *arg : args) {
+StringRef str(args.getArgString(arg->getIndex()));
+cmdArgs.insert(cmdArgs.end(), str.begin(), str.end());
+cmdArgs.push_back('\0');
+  }
+}
+
 CommonLinkerContext &lld::commonContext() {
   assert(lctx);
   return *lctx;
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index f4b7d1c9d5b9736..e760247f5ad9b0c 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -573,6 +573,7 @@ constexpr const char *saveTempsValues[] = {
 void LinkerDriver::linkerMain(ArrayRef argsArr) {
   ELFOptTable parser;
   opt::InputArgList args = parser.parse(argsArr.slice(1));
+  context().storeCmdArgs(args);
 
   // Interpret these flags early because error()/warn() depend on them.
   errorHandler().errorLimit = args::getInteger(args, OPT_error_limit, 20);
diff --git a/lld/ELF/LTO.cpp b/lld/ELF/LTO.cpp
index c39c6e6ea74ba33..02882865727be89 100644
--- a/lld/ELF/LTO.cpp
+++ b/lld/ELF/LTO.cpp
@@ -54,8 +54,7 @@ static lto::Config createConfig() {
   // LLD supports the new relocations and address-significance tables.
   c.Options = initTargetOptionsFromCodeGenFlags();
   c.Options.EmitAddrsig = true;
-  for (StringRef C : 

[lld] [llvm] [clang] Embed the command line arguments during LTO (PR #79390)

2024-01-25 Thread Duncan Ogilvie via cfe-commits


@@ -40,6 +41,7 @@ using namespace llvm;
 namespace lld::wasm {
 static std::unique_ptr createLTO() {
   lto::Config c;
+  c.EmbedCmdArgs = commonContext().cmdArgs;

mrexodia wrote:

I changed all the `commonContext()` to `context()` (or the `ctx` variable 
directly where possible). Feel free to reopen the discussion if you think it 
needs another revision.

https://github.com/llvm/llvm-project/pull/79390
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [flang] [libc] [libcxx] [clang] [mlir] [clang-tools-extra] [openmp] [libcxxabi] [compiler-rt] [AArch64] Combine store (trunc X to <3 x i8>) to sequence of ST1.b. (PR #78637)

2024-01-25 Thread Florian Hahn via cfe-commits


@@ -21471,6 +21471,53 @@ bool isHalvingTruncateOfLegalScalableType(EVT SrcVT, 
EVT DstVT) {
  (SrcVT == MVT::nxv2i64 && DstVT == MVT::nxv2i32);
 }
 
+// Combine store (trunc X to <3 x i8>) to sequence of ST1.b.
+static SDValue combineI8TruncStore(StoreSDNode *ST, SelectionDAG &DAG,
+   const AArch64Subtarget *Subtarget) {
+  SDValue Value = ST->getValue();
+  EVT ValueVT = Value.getValueType();
+
+  if (ST->isVolatile() || !Subtarget->isLittleEndian() ||
+  Value.getOpcode() != ISD::TRUNCATE ||
+  ValueVT != EVT::getVectorVT(*DAG.getContext(), MVT::i8, 3))
+return SDValue();
+
+  assert(ST->getOffset().isUndef() && "undef offset expected");
+  SDLoc DL(ST);
+  auto WideVT = EVT::getVectorVT(
+  *DAG.getContext(),
+  Value->getOperand(0).getValueType().getVectorElementType(), 4);
+  SDValue UndefVector = DAG.getUNDEF(WideVT);
+  SDValue WideTrunc = DAG.getNode(
+  ISD::INSERT_SUBVECTOR, DL, WideVT,
+  {UndefVector, Value->getOperand(0), DAG.getVectorIdxConstant(0, DL)});
+  SDValue Cast = DAG.getNode(
+  ISD::BITCAST, DL, WideVT.getSizeInBits() == 64 ? MVT::v8i8 : MVT::v16i8,
+  WideTrunc);
+
+  MachineFunction &MF = DAG.getMachineFunction();
+  SDValue Chain = ST->getChain();
+  MachineMemOperand *MMO = ST->getMemOperand();
+  unsigned IdxScale = WideVT.getScalarSizeInBits() / 8;
+  SDValue E2 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::i8, Cast,
+   DAG.getConstant(2 * IdxScale, DL, MVT::i64));
+  TypeSize Offset2 = TypeSize::getFixed(2);
+  SDValue Ptr2 = DAG.getMemBasePlusOffset(ST->getBasePtr(), Offset2, DL);
+  Chain = DAG.getStore(Chain, DL, E2, Ptr2, MF.getMachineMemOperand(MMO, 2, 
1));
+
+  SDValue E1 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::i8, Cast,
+   DAG.getConstant(1 * IdxScale, DL, MVT::i64));
+  TypeSize Offset1 = TypeSize::getFixed(1);
+  SDValue Ptr1 = DAG.getMemBasePlusOffset(ST->getBasePtr(), Offset1, DL);
+  Chain = DAG.getStore(Chain, DL, E1, Ptr1, MF.getMachineMemOperand(MMO, 1, 
1));
+
+  SDValue E0 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::i8, Cast,
+   DAG.getConstant(0, DL, MVT::i64));
+  Chain = DAG.getStore(Chain, DL, E0, ST->getBasePtr(), ST->getMemOperand());

fhahn wrote:

Updated, thanks!

https://github.com/llvm/llvm-project/pull/78637
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lld] [llvm] [clang] Embed the command line arguments during LTO (PR #79390)

2024-01-25 Thread Duncan Ogilvie via cfe-commits

mrexodia wrote:

> I haven't checked closely yet, but it seems like you need to add tests.

Could you provide some guidance on what kind of tests to add and how to 
actually run them locally? First I wanted to get the builtkite job to be green, 
but it seems to be failing on some unrelated test where LLD cannot be found.

https://github.com/llvm/llvm-project/pull/79390
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][analyzer] Simplify code of StreamChecker (NFC). (PR #79312)

2024-01-25 Thread Balázs Kéri via cfe-commits

balazske wrote:

My concern was the addition of many small functions that are used only from few 
other `eval*` calls and are relatively special. And all of these need a common 
big set of arguments like `StreamSym`, `CE`, `Call`. The build of states for 
success and failure cases in the thing that is really special for the calls.
But I can make another solution with "helper" functions.

https://github.com/llvm/llvm-project/pull/79312
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Sema]Substitue parameter packs when deduced from function parameter (PR #79371)

2024-01-25 Thread Gábor Spaits via cfe-commits


@@ -431,6 +442,17 @@ namespace deduction_after_explicit_pack {
 i(0, 1, 2, 3, 4, 5); // expected-error {{no match}}
   }
 
+  template 
+  void bar(args_tag, type_identity_t..., int mid, 
type_identity_t...) {}

spaits wrote:

It could work. It would cost only condition being removed. I deliberately put 
in the condition that disables this. Should I enable it?

I think enabling it would be standard compliant, but I played it safe and stuck 
to the example seen in the issue.  

https://github.com/llvm/llvm-project/pull/79371
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] f4ed7f8 - [clang][Parse][NFC] Make a local variable const

2024-01-25 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-01-25T13:29:39+01:00
New Revision: f4ed7f8d0a3830d05e53476fc64966e871bf9454

URL: 
https://github.com/llvm/llvm-project/commit/f4ed7f8d0a3830d05e53476fc64966e871bf9454
DIFF: 
https://github.com/llvm/llvm-project/commit/f4ed7f8d0a3830d05e53476fc64966e871bf9454.diff

LOG: [clang][Parse][NFC] Make a local variable const

Added: 


Modified: 
clang/lib/Parse/ParseDeclCXX.cpp

Removed: 




diff  --git a/clang/lib/Parse/ParseDeclCXX.cpp 
b/clang/lib/Parse/ParseDeclCXX.cpp
index ea79917cfc8e9e1..82fe12170f6660a 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -2362,7 +2362,7 @@ void Parser::HandleMemberFunctionDeclDelays(Declarator 
&DeclaratorInfo,
   if (!NeedLateParse) {
 // Look ahead to see if there are any default args
 for (unsigned ParamIdx = 0; ParamIdx < FTI.NumParams; ++ParamIdx) {
-  auto Param = cast(FTI.Params[ParamIdx].Param);
+  const auto *Param = cast(FTI.Params[ParamIdx].Param);
   if (Param->hasUnparsedDefaultArg()) {
 NeedLateParse = true;
 break;



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][analyzer] Simplify code of StreamChecker (NFC). (PR #79312)

2024-01-25 Thread via cfe-commits

NagyDonat wrote:

Yes, the "common big set of arguments" is an annoying problem. Perhaps you 
could consider my solution in core.BitwiseShift where I introduced a 
"validator" class that holds all the common arguments as data members, so 
instead of helper functions you have helper methods that can all access the 
common arguments. (The checker callback constructs a validator, and calls its 
"main" method, which will call the others as needed)

https://github.com/llvm/llvm-project/pull/79312
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [RISCV][clang] Optimize memory usage of intrinsic lookup table (PR #77487)

2024-01-25 Thread Brandon Wu via cfe-commits

https://github.com/4vtomat updated 
https://github.com/llvm/llvm-project/pull/77487

>From 84ea759c43d8e9cb450d95d00fd802be622153a2 Mon Sep 17 00:00:00 2001
From: Brandon Wu 
Date: Sun, 7 Jan 2024 18:10:59 -0800
Subject: [PATCH 1/2] [RISCV][clang] Optimize memory usage of intrinsic lookup
 table

This patch optimize:
  1. Reduce string size of RVVIntrinsicDef.
  2. Reduce the type size of the index of intrinsics.

I use valgrind --tool=massif to analyze a simple program:
```
#include 
vint32m1_t test(vint32m1_t v1, vint32m1_t v2, size_t vl) {
  return __riscv_vadd(v1, v2, vl);
}
```
and before optimization, the peak memory usage is 15.68MB,
after optimization, the peak memory usage is 13.69MB.
---
 clang/include/clang/Support/RISCVVIntrinsicUtils.h |  6 --
 clang/lib/Sema/SemaRISCVVectorLookup.cpp   | 13 +++--
 clang/lib/Support/RISCVVIntrinsicUtils.cpp |  5 -
 3 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/clang/include/clang/Support/RISCVVIntrinsicUtils.h 
b/clang/include/clang/Support/RISCVVIntrinsicUtils.h
index c525d3443331e0b..7e20f022c28b551 100644
--- a/clang/include/clang/Support/RISCVVIntrinsicUtils.h
+++ b/clang/include/clang/Support/RISCVVIntrinsicUtils.h
@@ -416,8 +416,10 @@ class RVVIntrinsic {
   RVVTypePtr getOutputType() const { return OutputType; }
   const RVVTypes &getInputTypes() const { return InputTypes; }
   llvm::StringRef getBuiltinName() const { return BuiltinName; }
-  llvm::StringRef getName() const { return Name; }
-  llvm::StringRef getOverloadedName() const { return OverloadedName; }
+  llvm::StringRef getName() const { return "__riscv_" + Name; }
+  llvm::StringRef getOverloadedName() const {
+return "__riscv_" + OverloadedName;
+  }
   bool hasMaskedOffOperand() const { return HasMaskedOffOperand; }
   bool hasVL() const { return HasVL; }
   bool hasPolicy() const { return Scheme != PolicyScheme::SchemeNone; }
diff --git a/clang/lib/Sema/SemaRISCVVectorLookup.cpp 
b/clang/lib/Sema/SemaRISCVVectorLookup.cpp
index 3ed3e6195441893..e9523871e9cd1fb 100644
--- a/clang/lib/Sema/SemaRISCVVectorLookup.cpp
+++ b/clang/lib/Sema/SemaRISCVVectorLookup.cpp
@@ -43,7 +43,7 @@ struct RVVIntrinsicDef {
 
 struct RVVOverloadIntrinsicDef {
   // Indexes of RISCVIntrinsicManagerImpl::IntrinsicList.
-  SmallVector Indexes;
+  SmallVector Indexes;
 };
 
 } // namespace
@@ -162,7 +162,7 @@ class RISCVIntrinsicManagerImpl : public 
sema::RISCVIntrinsicManager {
   // List of all RVV intrinsic.
   std::vector IntrinsicList;
   // Mapping function name to index of IntrinsicList.
-  StringMap Intrinsics;
+  StringMap Intrinsics;
   // Mapping function name to RVVOverloadIntrinsicDef.
   StringMap OverloadIntrinsics;
 
@@ -380,14 +380,14 @@ void RISCVIntrinsicManagerImpl::InitRVVIntrinsic(
 OverloadedName += "_" + OverloadedSuffixStr.str();
 
   // clang built-in function name, e.g. __builtin_rvv_vadd.
-  std::string BuiltinName = "__builtin_rvv_" + std::string(Record.Name);
+  std::string BuiltinName = std::string(Record.Name);
 
   RVVIntrinsic::updateNamesAndPolicy(IsMasked, HasPolicy, Name, BuiltinName,
  OverloadedName, PolicyAttrs,
  Record.HasFRMRoundModeOp);
 
   // Put into IntrinsicList.
-  uint32_t Index = IntrinsicList.size();
+  uint16_t Index = IntrinsicList.size();
   IntrinsicList.push_back({BuiltinName, Signature});
 
   // Creating mapping to Intrinsics.
@@ -452,7 +452,8 @@ void 
RISCVIntrinsicManagerImpl::CreateRVVIntrinsicDecl(LookupResult &LR,
 RVVIntrinsicDecl->addAttr(OverloadableAttr::CreateImplicit(Context));
 
   // Setup alias to __builtin_rvv_*
-  IdentifierInfo &IntrinsicII = PP.getIdentifierTable().get(IDef.BuiltinName);
+  IdentifierInfo &IntrinsicII =
+  PP.getIdentifierTable().get("__builtin_rvv_" + IDef.BuiltinName);
   RVVIntrinsicDecl->addAttr(
   BuiltinAliasAttr::CreateImplicit(S.Context, &IntrinsicII));
 
@@ -463,7 +464,7 @@ void 
RISCVIntrinsicManagerImpl::CreateRVVIntrinsicDecl(LookupResult &LR,
 bool RISCVIntrinsicManagerImpl::CreateIntrinsicIfFound(LookupResult &LR,
IdentifierInfo *II,
Preprocessor &PP) {
-  StringRef Name = II->getName();
+  StringRef Name = II->getName().substr(8);
 
   // Lookup the function name from the overload intrinsics first.
   auto OvIItr = OverloadIntrinsics.find(Name);
diff --git a/clang/lib/Support/RISCVVIntrinsicUtils.cpp 
b/clang/lib/Support/RISCVVIntrinsicUtils.cpp
index 2de977a3dc720bd..7d2a2d7e826f9cd 100644
--- a/clang/lib/Support/RISCVVIntrinsicUtils.cpp
+++ b/clang/lib/Support/RISCVVIntrinsicUtils.cpp
@@ -1150,11 +1150,6 @@ void RVVIntrinsic::updateNamesAndPolicy(
 OverloadedName += suffix;
   };
 
-  // This follows the naming guideline under riscv-c-api-doc to add the
-  // `__riscv_` suffix for all RVV intrinsics.
-  Name = "__riscv_" + Name;
-  OverloadedName = 

[clang] [RISCV][clang] Optimize memory usage of intrinsic lookup table (PR #77487)

2024-01-25 Thread Brandon Wu via cfe-commits


@@ -380,14 +380,14 @@ void RISCVIntrinsicManagerImpl::InitRVVIntrinsic(
 OverloadedName += "_" + OverloadedSuffixStr.str();
 
   // clang built-in function name, e.g. __builtin_rvv_vadd.
-  std::string BuiltinName = "__builtin_rvv_" + std::string(Record.Name);
+  std::string BuiltinName = std::string(Record.Name);
 
   RVVIntrinsic::updateNamesAndPolicy(IsMasked, HasPolicy, Name, BuiltinName,
  OverloadedName, PolicyAttrs,
  Record.HasFRMRoundModeOp);
 
   // Put into IntrinsicList.
-  uint32_t Index = IntrinsicList.size();
+  uint16_t Index = IntrinsicList.size();

4vtomat wrote:

I've added an assertion for checking whether intrinsics overflow.

https://github.com/llvm/llvm-project/pull/77487
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Sema]Substitue parameter packs when deduced from function parameter (PR #79371)

2024-01-25 Thread Gábor Spaits via cfe-commits

https://github.com/spaits updated 
https://github.com/llvm/llvm-project/pull/79371

From d4ca5c2fcb87f424be23efc4513df491403c3811 Mon Sep 17 00:00:00 2001
From: Gabor Spaits 
Date: Wed, 24 Jan 2024 21:21:26 +0100
Subject: [PATCH 1/7] [Sema]Substitue template parameter packs when deduced
 from function parameter

---
 clang/lib/Sema/SemaTemplateDeduction.cpp | 63 +++-
 1 file changed, 62 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index e9e7ab5bb6698a..46fa9eece3747a 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -730,6 +730,7 @@ class PackDeductionScope {
   void addPack(unsigned Index) {
 // Save the deduced template argument for the parameter pack expanded
 // by this pack expansion, then clear out the deduction.
+DeducedFromEarlierParameter = !Deduced[Index].isNull();
 DeducedPack Pack(Index);
 Pack.Saved = Deduced[Index];
 Deduced[Index] = TemplateArgument();
@@ -858,6 +859,29 @@ class PackDeductionScope {
   Info.PendingDeducedPacks[Pack.Index] = Pack.Outer;
   }
 
+  std::optional getSavedPackSize(unsigned Index,
+   TemplateArgument Pattern) const {
+
+SmallVector Unexpanded;
+S.collectUnexpandedParameterPacks(Pattern, Unexpanded);
+if (Unexpanded.size() == 0 ||
+Packs[0].Saved.getKind() != clang::TemplateArgument::Pack)
+  return {};
+unsigned PackSize = Packs[0].Saved.pack_size();
+
+if (std::all_of(Packs.begin() + 1, Packs.end(),
+[&PackSize](auto P) {
+  return P.Saved.getKind() == TemplateArgument::Pack &&
+ P.Saved.pack_size() == PackSize;
+}))
+  return PackSize;
+return {};
+  }
+
+  /// Determine whether this pack has already been deduced from a previous
+  /// argument.
+  bool isDeducedFromEarlierParameter() const {return 
DeducedFromEarlierParameter;}
+
   /// Determine whether this pack has already been partially expanded into a
   /// sequence of (prior) function parameters / template arguments.
   bool isPartiallyExpanded() { return IsPartiallyExpanded; }
@@ -970,7 +994,6 @@ class PackDeductionScope {
 NewPack = Pack.DeferredDeduction;
 Result = checkDeducedTemplateArguments(S.Context, OldPack, NewPack);
   }
-
   NamedDecl *Param = TemplateParams->getParam(Pack.Index);
   if (Result.isNull()) {
 Info.Param = makeTemplateParameter(Param);
@@ -1003,9 +1026,12 @@ class PackDeductionScope {
   unsigned PackElements = 0;
   bool IsPartiallyExpanded = false;
   bool DeducePackIfNotAlreadyDeduced = false;
+  bool DeducedFromEarlierParameter = false;
+
   /// The number of expansions, if we have a fully-expanded pack in this scope.
   std::optional FixedNumExpansions;
 
+
   SmallVector Packs;
 };
 
@@ -4371,6 +4397,41 @@ Sema::TemplateDeductionResult 
Sema::DeduceTemplateArguments(
   // corresponding argument is a list?
   PackScope.nextPackElement();
 }
+  } else if (!IsTrailingPack && !PackScope.isPartiallyExpanded() &&
+ PackScope.isDeducedFromEarlierParameter() &&
+ !isa(ParamTypes[ParamIdx + 1])) {
+// [temp.deduct.general#3]
+// When all template arguments have been deduced
+// or obtained from default template arguments, all uses of template
+// parameters in the template parameter list of the template are
+// replaced with the corresponding deduced or default argument values
+//
+// If we have a trailing parameter pack, that has been deduced 
perviously
+// we substitute the pack here in a similar fashion as seen above with
+// the trailing parameter packs. The main difference here is that, in
+// this case we are not processing all of the remaining arguments. We
+// are only process as many arguments as much we have in the already
+// deduced parameter.
+SmallVector Unexpanded;
+collectUnexpandedParameterPacks(ParamPattern, Unexpanded);
+if (Unexpanded.size() == 0)
+  continue;
+
+std::optional ArgPosAfterSubstitution =
+PackScope.getSavedPackSize(getDepthAndIndex(Unexpanded[0]).second,
+   ParamPattern);
+if (!ArgPosAfterSubstitution)
+  continue;
+
+unsigned PackArgEnd = ArgIdx + *ArgPosAfterSubstitution;
+for (; ArgIdx < PackArgEnd && ArgIdx < Args.size(); ArgIdx++) {
+  ParamTypesForArgChecking.push_back(ParamPattern);
+  if (auto Result = DeduceCallArgument(ParamPattern, ArgIdx,
+   
/*ExplicitObjetArgument=*/false))
+return Result;
+
+  PackScope.nextPackElement();
+}
   }
 }
 

From 52de421b998481105e5522a04ad9e39a4a6cbb82

[clang] [Clang][RISCV][RVV Intrinsic] Fix codegen redundant intrinsic names (PR #77889)

2024-01-25 Thread Brandon Wu via cfe-commits

https://github.com/4vtomat approved this pull request.

Thanks, LGTM~

https://github.com/llvm/llvm-project/pull/77889
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libc] [flang] [libunwind] [libcxx] [clang-tools-extra] [compiler-rt] [lldb] [clang] [llvm] [mlir] [lld] Reland: [libc++][format] P2637R3: Member visit (std::basic_format_arg) #76449 (PR #79032)

2024-01-25 Thread Hristo Hristov via cfe-commits

https://github.com/H-G-Hristov updated 
https://github.com/llvm/llvm-project/pull/79032

>From e03452fda84a5284420bba1913299b68caabb6cd Mon Sep 17 00:00:00 2001
From: Zingam 
Date: Mon, 22 Jan 2024 20:35:00 +0200
Subject: [PATCH 1/2] Revert "Revert "[libc++][format] P2637R3: Member `visit`
 (`std::basic_format_arg`) (#76449)""

This reverts commit 02f95b77515fe18ed1076b94cbb850ea0cf3c77e.
---
 libcxx/docs/ReleaseNotes/18.rst   |   1 +
 libcxx/docs/Status/Cxx2cPapers.csv|   2 +-
 libcxx/docs/Status/FormatIssues.csv   |   2 +-
 libcxx/include/__config   |   6 +
 libcxx/include/__format/format_arg.h  | 109 +-
 libcxx/include/__format/format_context.h  |  33 +-
 libcxx/include/format |   2 +-
 .../format.arg/visit.pass.cpp | 333 
 .../format.arg/visit.return_type.pass.cpp | 369 ++
 .../visit_format_arg.deprecated.verify.cpp|  38 ++
 .../format.arg/visit_format_arg.pass.cpp  |   6 +-
 .../format.arguments/format.args/get.pass.cpp |  48 ++-
 libcxx/test/support/test_basic_format_arg.h   |  20 +-
 libcxx/test/support/test_macros.h |   5 +
 .../generate_feature_test_macro_components.py |   1 +
 15 files changed, 927 insertions(+), 48 deletions(-)
 create mode 100644 
libcxx/test/std/utilities/format/format.arguments/format.arg/visit.pass.cpp
 create mode 100644 
libcxx/test/std/utilities/format/format.arguments/format.arg/visit.return_type.pass.cpp
 create mode 100644 
libcxx/test/std/utilities/format/format.arguments/format.arg/visit_format_arg.deprecated.verify.cpp

diff --git a/libcxx/docs/ReleaseNotes/18.rst b/libcxx/docs/ReleaseNotes/18.rst
index fd882bafe19a51..237a63022d55ff 100644
--- a/libcxx/docs/ReleaseNotes/18.rst
+++ b/libcxx/docs/ReleaseNotes/18.rst
@@ -79,6 +79,7 @@ Implemented Papers
 - P1759R6 - Native handles and file streams
 - P2868R3 - Remove Deprecated ``std::allocator`` Typedef From C++26
 - P2517R1 - Add a conditional ``noexcept`` specification to ``std::apply``
+- P2637R3 - Member ``visit``
 - P2447R6 - ``span`` over initializer list
 
 
diff --git a/libcxx/docs/Status/Cxx2cPapers.csv 
b/libcxx/docs/Status/Cxx2cPapers.csv
index f80b1f6b663f04..c45aa3c510072e 100644
--- a/libcxx/docs/Status/Cxx2cPapers.csv
+++ b/libcxx/docs/Status/Cxx2cPapers.csv
@@ -17,7 +17,7 @@
 "`P0792R14 `__","LWG","``function_ref``: a 
type-erased callable reference","Varna June 2023","","",""
 "`P2874R2 `__","LWG","Mandating Annex D Require No 
More","Varna June 2023","","",""
 "`P2757R3 `__","LWG","Type-checking format 
args","Varna June 2023","","","|format|"
-"`P2637R3 `__","LWG","Member ``visit``","Varna June 
2023","|Partial|","18.0",""
+"`P2637R3 `__","LWG","Member ``visit``","Varna June 
2023","|Complete|","18.0",""
 "`P2641R4 `__","CWG, LWG","Checking if a ``union`` 
alternative is active","Varna June 2023","","",""
 "`P1759R6 `__","LWG","Native handles and file 
streams","Varna June 2023","|Complete|","18.0",""
 "`P2697R1 `__","LWG","Interfacing ``bitset`` with 
``string_view``","Varna June 2023","|Complete|","18.0",""
diff --git a/libcxx/docs/Status/FormatIssues.csv 
b/libcxx/docs/Status/FormatIssues.csv
index 513988d08036ca..6e58e752191ea5 100644
--- a/libcxx/docs/Status/FormatIssues.csv
+++ b/libcxx/docs/Status/FormatIssues.csv
@@ -16,7 +16,7 @@ Number,Name,Standard,Assignee,Status,First released version
 "`P2693R1 `__","Formatting ``thread::id`` and 
``stacktrace``","C++23","Mark de Wever","|In Progress|"
 "`P2510R3 `__","Formatting pointers","C++26","Mark 
de Wever","|Complete|",17.0
 "`P2757R3 `__","Type-checking format 
args","C++26","","",
-"`P2637R3 `__","Member ``visit``","C++26","","",
+"`P2637R3 `__","Member ``visit``","C++26","Hristo 
Hristov","|Complete|",18.0
 "`P2905R2 `__","Runtime format strings","C++26 
DR","Mark de Wever","|Complete|",18.0
 "`P2918R2 `__","Runtime format strings 
II","C++26","Mark de Wever","|Complete|",18.0
 "`P2909R4 `__","Fix formatting of code units as 
integers (Dude, where’s my ``char``?)","C++26 DR","Mark de 
Wever","|Complete|",18.0
diff --git a/libcxx/include/__config b/libcxx/include/__config
index 9a64cdb489119d..00489d971c296c 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -995,6 +995,12 @@ typedef __char32_t char32_t;
 #define _LIBCPP_DEPRECATED_IN_CXX23
 #  endif
 
+#  if _LIBCPP_STD_VER >= 26
+#define _LIBCPP_DEPRECATED_IN_CXX26 _LIBCPP_DEPRECATED
+#  else
+#define _LIBCPP_DEPRECATED_IN_CXX26
+#  endif
+
 #  if !defined(_LIBCPP_HAS_NO_C

[clang] cd0b005 - [clang][Interp][NFC] Add some working _Complex tests

2024-01-25 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-01-25T14:21:59+01:00
New Revision: cd0b0055a730e55f2f14f35172e05dc27642f8ce

URL: 
https://github.com/llvm/llvm-project/commit/cd0b0055a730e55f2f14f35172e05dc27642f8ce
DIFF: 
https://github.com/llvm/llvm-project/commit/cd0b0055a730e55f2f14f35172e05dc27642f8ce.diff

LOG: [clang][Interp][NFC] Add some working _Complex tests

Added: 


Modified: 
clang/test/AST/Interp/complex.cpp

Removed: 




diff  --git a/clang/test/AST/Interp/complex.cpp 
b/clang/test/AST/Interp/complex.cpp
index 99c0dd141d0b77..836ea552adac86 100644
--- a/clang/test/AST/Interp/complex.cpp
+++ b/clang/test/AST/Interp/complex.cpp
@@ -8,6 +8,11 @@ constexpr _Complex double z1 = {1.0, 2.0};
 static_assert(__real(z1) == 1.0, "");
 static_assert(__imag(z1) == 2.0, "");
 
+static_assert(&__imag z1 == &__real z1 + 1, "");
+static_assert((*(&__imag z1)) == __imag z1, "");
+static_assert((*(&__real z1)) == __real z1, "");
+
+
 constexpr double setter() {
   _Complex float d = {1.0, 2.0};
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [AMDGPU][GFX12] Add tests for unsupported builtins (PR #78729)

2024-01-25 Thread Mariusz Sikora via cfe-commits

https://github.com/mariusz-sikora-at-amd updated 
https://github.com/llvm/llvm-project/pull/78729

>From 56cf06f1b530d5ec62de1cc3818bf2f76dfd Mon Sep 17 00:00:00 2001
From: Mariusz Sikora 
Date: Fri, 19 Jan 2024 16:29:46 +0100
Subject: [PATCH] [AMDGPU][GFX12] Add tests for unsupported builtins

__builtin_amdgcn_mfma* and __builtin_amdgcn_smfmac*
---
 .../builtins-amdgcn-gfx12-err.cl  | 86 ++-
 1 file changed, 85 insertions(+), 1 deletion(-)

diff --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx12-err.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx12-err.cl
index bcaea9a2482d186..f91fea17145102a 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx12-err.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx12-err.cl
@@ -4,10 +4,94 @@
 
 typedef unsigned int uint;
 
-kernel void test_builtins_amdgcn_gws_insts(uint a, uint b) {
+#pragma OPENCL EXTENSION cl_khr_fp64:enable
+
+typedef float  v2f   __attribute__((ext_vector_type(2)));
+typedef float  v4f   __attribute__((ext_vector_type(4)));
+typedef float  v16f  __attribute__((ext_vector_type(16)));
+typedef float  v32f  __attribute__((ext_vector_type(32)));
+typedef half   v4h   __attribute__((ext_vector_type(4)));
+typedef half   v8h   __attribute__((ext_vector_type(8)));
+typedef half   v16h  __attribute__((ext_vector_type(16)));
+typedef half   v32h  __attribute__((ext_vector_type(32)));
+typedef intv2i   __attribute__((ext_vector_type(2)));
+typedef intv4i   __attribute__((ext_vector_type(4)));
+typedef intv16i  __attribute__((ext_vector_type(16)));
+typedef intv32i  __attribute__((ext_vector_type(32)));
+typedef short  v2s   __attribute__((ext_vector_type(2)));
+typedef short  v4s   __attribute__((ext_vector_type(4)));
+typedef short  v8s   __attribute__((ext_vector_type(8)));
+typedef short  v16s  __attribute__((ext_vector_type(16)));
+typedef short  v32s  __attribute__((ext_vector_type(32)));
+typedef double v4d   __attribute__((ext_vector_type(4)));
+
+void builtin_test_unsupported(double a_double, float a_float,
+  int a_int, long  a_long,
+  v4d a_v4d,
+  v2s a_v2s, v4s a_v4s, v8s a_v8s,
+  v2i a_v2i, v4i a_v4i, v16i a_v16i, v32i a_v32i,
+  v2f a_v2f, v4f a_v4f, v16f a_v16f, v32f  a_v32f,
+  v4h a_v4h, v8h a_v8h,
+
+  uint a, uint b) {
+
   __builtin_amdgcn_ds_gws_init(a, b); // expected-error 
{{'__builtin_amdgcn_ds_gws_init' needs target feature gws}}
   __builtin_amdgcn_ds_gws_barrier(a, b); // expected-error 
{{'__builtin_amdgcn_ds_gws_barrier' needs target feature gws}}
   __builtin_amdgcn_ds_gws_sema_v(a); // expected-error 
{{'__builtin_amdgcn_ds_gws_sema_v' needs target feature gws}}
   __builtin_amdgcn_ds_gws_sema_br(a, b); // expected-error 
{{'__builtin_amdgcn_ds_gws_sema_br' needs target feature gws}}
   __builtin_amdgcn_ds_gws_sema_p(a); // expected-error 
{{'__builtin_amdgcn_ds_gws_sema_p' needs target feature gws}}
+
+  a_v32f = __builtin_amdgcn_mfma_f32_32x32x1f32(a_float, a_float, a_v32f, 0, 
0, 0); // expected-error {{'__builtin_amdgcn_mfma_f32_32x32x1f32' needs target 
feature mai-insts}}
+  a_v16f = __builtin_amdgcn_mfma_f32_16x16x1f32(a_float, a_float, a_v16f, 0, 
0, 0); // expected-error {{'__builtin_amdgcn_mfma_f32_16x16x1f32' needs target 
feature mai-insts}}
+  a_v4f =  __builtin_amdgcn_mfma_f32_4x4x1f32(a_float, a_float, a_v4f, 0, 0, 
0); // expected-error {{'__builtin_amdgcn_mfma_f32_4x4x1f32' needs target 
feature mai-insts}}
+  a_v16f = __builtin_amdgcn_mfma_f32_32x32x2f32(a_float, a_float, a_v16f, 0, 
0, 0); // expected-error {{'__builtin_amdgcn_mfma_f32_32x32x2f32' needs target 
feature mai-insts}}
+  a_v4f =  __builtin_amdgcn_mfma_f32_16x16x4f32(a_float, a_float, a_v4f, 0, 0, 
0); // expected-error {{'__builtin_amdgcn_mfma_f32_16x16x4f32' needs target 
feature mai-insts}}
+  a_v32f = __builtin_amdgcn_mfma_f32_32x32x4f16(a_v4h, a_v4h, a_v32f, 0, 0, 
0); // expected-error {{'__builtin_amdgcn_mfma_f32_32x32x4f16' needs target 
feature mai-insts}}
+  a_v16f = __builtin_amdgcn_mfma_f32_16x16x4f16(a_v4h, a_v4h, a_v16f, 0, 0, 
0); // expected-error {{'__builtin_amdgcn_mfma_f32_16x16x4f16' needs target 
feature mai-insts}}
+  a_v4f = __builtin_amdgcn_mfma_f32_4x4x4f16(a_v4h, a_v4h, a_v4f, 0, 0, 0); // 
expected-error {{'__builtin_amdgcn_mfma_f32_4x4x4f16' needs target feature 
mai-insts}}
+  a_v16f = __builtin_amdgcn_mfma_f32_32x32x8f16(a_v4h, a_v4h, a_v16f, 0, 0, 
0); // expected-error {{'__builtin_amdgcn_mfma_f32_32x32x8f16' needs target 
feature mai-insts}}
+  a_v4f = __builtin_amdgcn_mfma_f32_16x16x16f16(a_v4h, a_v4h, a_v4f, 0, 0, 0); 
// expected-error {{'__builtin_amdgcn_mfma_f32_16x16x16f16' needs target 
feature mai-insts}}
+  a_v32i = __builtin_amdgcn_mfma_i32_32x32x4i8(a_int, a_int, a_v32i, 0, 0, 0); 
// expected-error {{'__builtin_amdgcn_mfma_i32_32x32x4i8' needs 

[clang] [ObjC] Defer to the LLVM backend for unaligned atomic load and stores (PR #79191)

2024-01-25 Thread James Y Knight via cfe-commits

jyknight wrote:

Does this cause an ABI incompatibility? E.g. if we have a case where an 
existing object calls copyStruct on a given object (which presumably has its 
own internal mutex), and a newly compiled object file calls `__atomic_load` on 
the same object, implemented with its own internal mutex, the operations won't 
be atomic w.r.t. each-other.

I don't know enough about ObjC codegen stuff to be able to say if there are 
mitigating factors that make this OK (e.g. if it's all within one TU?).

Sidenote: please avoid rebase, amend, and force-pushing, because it makes it 
hard to review what's been changed -- instead, just keep adding more commits to 
your pull-request branch.


https://github.com/llvm/llvm-project/pull/79191
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [PowerPC] Diagnose invalid combination with Altivec, VSX and soft-float (PR #79109)

2024-01-25 Thread Chen Zheng via cfe-commits

https://github.com/chenzheng1030 updated 
https://github.com/llvm/llvm-project/pull/79109

>From 014b10f43e2d3f8564940e21033cee77c3c0c10e Mon Sep 17 00:00:00 2001
From: Nemanja Ivanovic 
Date: Tue, 23 Jan 2024 03:25:01 -0500
Subject: [PATCH 1/2] [PowerPC] Diagnose invalid combination with Altivec, VSX
 and soft-float

---
 clang/lib/Basic/Targets/PPC.cpp  | 43 
 clang/test/CodeGen/PowerPC/attr-target-ppc.c |  3 ++
 clang/test/Driver/ppc-dependent-options.cpp  | 15 +++
 3 files changed, 52 insertions(+), 9 deletions(-)

diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index 41935abfb65d3b..1341bf8b99c506 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -442,19 +442,44 @@ void PPCTargetInfo::getTargetDefines(const LangOptions 
&Opts,
   //   _CALL_DARWIN
 }
 
-// Handle explicit options being passed to the compiler here: if we've
-// explicitly turned off vsx and turned on any of:
-// - power8-vector
-// - direct-move
-// - float128
-// - power9-vector
-// - paired-vector-memops
-// - mma
-// - power10-vector
+// Handle explicit options being passed to the compiler here:
+// - if we've explicitly turned off vsx and turned on any of:
+//   - power8-vector
+//   - direct-move
+//   - float128
+//   - power9-vector
+//   - paired-vector-memops
+//   - mma
+//   - power10-vector
+// - if we've explicitly turned on vsx and turned off altivec.
+// - if we've explicitly turned on soft-float and altivec.
 // then go ahead and error since the customer has expressed an incompatible
 // set of options.
 static bool ppcUserFeaturesCheck(DiagnosticsEngine &Diags,
  const std::vector &FeaturesVec) {
+  // Cannot allow soft-float with Altivec.
+  if (llvm::is_contained(FeaturesVec, "-hard-float") &&
+  llvm::is_contained(FeaturesVec, "+altivec")) {
+Diags.Report(diag::err_opt_not_valid_with_opt) << "-msoft-float"
+   << "-maltivec";
+return false;
+  }
+
+  // Cannot allow soft-float with VSX.
+  if (llvm::is_contained(FeaturesVec, "-hard-float") &&
+  llvm::is_contained(FeaturesVec, "+vsx")) {
+Diags.Report(diag::err_opt_not_valid_with_opt) << "-msoft-float"
+   << "-mvsx";
+return false;
+  }
+
+  // Cannot allow VSX with no Altivec.
+  if (llvm::is_contained(FeaturesVec, "+vsx") &&
+  llvm::is_contained(FeaturesVec, "-altivec")) {
+Diags.Report(diag::err_opt_not_valid_with_opt) << "-mvsx"
+   << "-mno-altivec";
+return false;
+  }
 
   // vsx was not explicitly turned off.
   if (!llvm::is_contained(FeaturesVec, "-vsx"))
diff --git a/clang/test/CodeGen/PowerPC/attr-target-ppc.c 
b/clang/test/CodeGen/PowerPC/attr-target-ppc.c
index d2901748b37cb9..f185a0e6f49a05 100644
--- a/clang/test/CodeGen/PowerPC/attr-target-ppc.c
+++ b/clang/test/CodeGen/PowerPC/attr-target-ppc.c
@@ -1,4 +1,7 @@
 // RUN: not %clang_cc1 -triple powerpc64le-linux-gnu -emit-llvm %s -o -
 
 long __attribute__((target("power8-vector,no-vsx"))) foo (void) { return 0; }  
// expected-error {{option '-mpower8-vector' cannot be specified with 
'-mno-vsx'}}
+long __attribute__((target("no-altivec,vsx"))) foo2(void) { return 0; }
// expected-error {{option '-mvsx' cannot be specified with '-mno-altivec'}}
+long __attribute__((target("no-hard-float,altivec"))) foo3(void) { return 0; } 
// expected-error {{option '-msoft-float' cannot be specified with '-maltivec'}}
+long __attribute__((target("no-hard-float,vsx"))) foo3(void) { return 0; } // 
expected-error {{option '-msoft-float' cannot be specified with '-mvsx'}}
 
diff --git a/clang/test/Driver/ppc-dependent-options.cpp 
b/clang/test/Driver/ppc-dependent-options.cpp
index 65c40e9ce70f65..8286422185cad6 100644
--- a/clang/test/Driver/ppc-dependent-options.cpp
+++ b/clang/test/Driver/ppc-dependent-options.cpp
@@ -78,6 +78,18 @@
 // RUN: -mcpu=power10 -std=c++11 -mno-vsx -mpower10-vector %s 2>&1 | \
 // RUN: FileCheck %s -check-prefix=CHECK-NVSX-P10V
 
+// RUN: not %clang -target powerpc64le-unknown-unknown -fsyntax-only \
+// RUN: -std=c++11 -mvsx -mno-altivec %s 2>&1 | \
+// RUN: FileCheck %s -check-prefix=CHECK-NALTI-VSX
+
+// RUN: not %clang -target powerpc64le-unknown-unknown -fsyntax-only \
+// RUN: -std=c++11 -msoft-float -maltivec %s 2>&1 | \
+// RUN: FileCheck %s -check-prefix=CHECK-SOFTFLT-ALTI
+
+// RUN: not %clang -target powerpc64le-unknown-unknown -fsyntax-only \
+// RUN: -std=c++11 -msoft-float -mvsx %s 2>&1 | \
+// RUN: FileCheck %s -check-prefix=CHECK-SOFTFLT-VSX
+
 #ifdef __VSX__
 static_assert(false, "VSX enabled");
 #endif
@@ -114,3 +126,6 @@ static_assert(false, "Neither enabled");
 // CHECK-NVSX-MMA: error: option '-mmma' cannot be specified with '-mno-vsx'
 // CHECK-NVSX: Neither enabled
 // CHECK-VSX: VSX enabled
+// CHECK-NALTI-VSX: error: option '-mvsx' cannot be sp

[clang] [analyzer] Avoid a crash in a debug printout function (PR #79446)

2024-01-25 Thread via cfe-commits

https://github.com/NagyDonat created 
https://github.com/llvm/llvm-project/pull/79446

Previously the function `RangeConstraintManager::printValue()` crashed when it 
encountered an empty rangeset (because `RangeSet::getBitwidth()` and 
`RangeSet::isUnsigned()` assert that the rangeset is not empty). This commit 
adds a special case that avoids this behavior.

As `printValue()` is only used by the checker debug.ExprInspection (and during 
manual debugging), the impacts of this commit are very limited.

>From 2a1bb37fef538ecfde67f10c50df07100cc3b69a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Don=C3=A1t=20Nagy?= 
Date: Thu, 25 Jan 2024 14:13:03 +0100
Subject: [PATCH] [analyzer] Avoid a crash in a debug printout function

Previously the function `RangeConstraintManager::printValue()` crashed
when it encountered an empty rangeset (because `RangeSet::getBitwidth()`
and `RangeSet::isUnsigned()` assert that the rangeset is not empty).
This commit adds a special case that avoids this behavior.

As `printValue()` is only used by the checker debug.ExprInspection (and
during manual debugging), the impacts of this commit are very limited.
---
 clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp 
b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
index 25d066c4652f2b..cc1cad1e002cdf 100644
--- a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -3270,8 +3270,12 @@ void RangeConstraintManager::printJson(raw_ostream &Out, 
ProgramStateRef State,
 void RangeConstraintManager::printValue(raw_ostream &Out, ProgramStateRef 
State,
 SymbolRef Sym) {
   const RangeSet RS = getRange(State, Sym);
-  Out << RS.getBitWidth() << (RS.isUnsigned() ? "u:" : "s:");
-  RS.dump(Out);
+  if (RS.isEmpty()) {
+Out << "";
+  } else {
+Out << RS.getBitWidth() << (RS.isUnsigned() ? "u:" : "s:");
+RS.dump(Out);
+  }
 }
 
 static std::string toString(const SymbolRef &Sym) {

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [PowerPC] Diagnose invalid combination with Altivec, VSX and soft-float (PR #79109)

2024-01-25 Thread Chen Zheng via cfe-commits

chenzheng1030 wrote:

Patch updated.

https://github.com/llvm/llvm-project/pull/79109
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Avoid a crash in a debug printout function (PR #79446)

2024-01-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-static-analyzer-1

Author: None (NagyDonat)


Changes

Previously the function `RangeConstraintManager::printValue()` crashed when it 
encountered an empty rangeset (because `RangeSet::getBitwidth()` and 
`RangeSet::isUnsigned()` assert that the rangeset is not empty). This commit 
adds a special case that avoids this behavior.

As `printValue()` is only used by the checker debug.ExprInspection (and during 
manual debugging), the impacts of this commit are very limited.

---
Full diff: https://github.com/llvm/llvm-project/pull/79446.diff


1 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp (+6-2) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp 
b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
index 25d066c4652f2b..cc1cad1e002cdf 100644
--- a/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -3270,8 +3270,12 @@ void RangeConstraintManager::printJson(raw_ostream &Out, 
ProgramStateRef State,
 void RangeConstraintManager::printValue(raw_ostream &Out, ProgramStateRef 
State,
 SymbolRef Sym) {
   const RangeSet RS = getRange(State, Sym);
-  Out << RS.getBitWidth() << (RS.isUnsigned() ? "u:" : "s:");
-  RS.dump(Out);
+  if (RS.isEmpty()) {
+Out << "";
+  } else {
+Out << RS.getBitWidth() << (RS.isUnsigned() ? "u:" : "s:");
+RS.dump(Out);
+  }
 }
 
 static std::string toString(const SymbolRef &Sym) {

``




https://github.com/llvm/llvm-project/pull/79446
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NVPTX] Add support for -march=native in standalone NVPTX (PR #79373)

2024-01-25 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

> I think I'm with Art on this one.
> 
> > > Problem #2 [...] The arch=native will create a working configuration, but 
> > > would build more than necessary.
> > 
> > 
> > It will target the first GPU it finds. We could maybe change the behavior 
> > to detect the newest, but the idea is just to target the user's system.
> 
> OK, but I think this is worse.
> 
> Now it's basically always incorrect to ship a build system which uses 
> arch=native, because the people running the build might very reasonably have 
> multiple GPUs in their system, and which GPU clang picks is unspecified.

It's not unspecified per-se, it just picks the one the CUDA driver assigned to 
ID zero, so it will correspond to the layman using a default device if loaded 
into CUDA.

The AMDGPU version has a warning when multiple GPUs are found. I should 
probably add the same thing here as it would make this explicit.
 
> But we all know people are going to do it anyway.
> 
> Given that this feature cannot correctly be used with a build system, and 
> given that 99.99% of invocations of clang are from a build system that the 
> user running the build did not write, it seems to me that we should not add a 
> feature that is such a footgun when used with a build system.
> 
> (A non-CUDA C++ file compiled with march=native will almost surely run on 
> your computer, whereas this won't, and it's unpredictable whether or not it 
> will, depending on the order the nvidia driver returns GPUs in. So there's no 
> good analogy here.)
> 
> If we were going to add this, I think we should compile for all the GPUs in 
> your system, like Art had assumed. I think that's better, but it has other 
> problems, like slow builds and also the fact that your graphics GPU is likely 
> less powerful than your compute GPU, so now compilation is going to fail 
> because you're e.g. using tensorcores and compiling for a GPU that doesn't 
> have them. So again you can't really use arch=native in a build system, even 
> if you say "requires an sm80 GPU", because really the requirement is "has an 
> sm80 GPU and no others in the machine".

We already do this for CUDA with `--offload-arch=native`. This handling is for 
targeting NVPTX directly, similar to OpenCL. That means there is no concept of 
multiple device passes, there can only be a single target architecture just 
like compiling standard C++ code. I'd like to have `-march=native` because it 
makes it easier to just build something that works for testing purposes, and 
it's consistent with all the other native handling, since the NVPTX target is 
the only one that doesn't support it to my knowledge.

https://github.com/llvm/llvm-project/pull/79373
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang-tools-extra] [clang] [DebugInfo][RemoveDIs] Add a DPValue implementation for instcombine sinking (PR #77930)

2024-01-25 Thread Stephen Tozer via cfe-commits


@@ -4266,19 +4285,140 @@ bool 
InstCombinerImpl::tryToSinkInstruction(Instruction *I,
 
   // Perform salvaging without the clones, then sink the clones.
   if (!DIIClones.empty()) {
-// RemoveDIs: pass in empty vector of DPValues until we get to 
instrumenting
-// this pass.
-SmallVector DummyDPValues;
-salvageDebugInfoForDbgValues(*I, DbgUsersToSalvage, DummyDPValues);
+salvageDebugInfoForDbgValues(*I, DbgUsersToSalvage, {});
 // The clones are in reverse order of original appearance, reverse again to
 // maintain the original order.
 for (auto &DIIClone : llvm::reverse(DIIClones)) {
   DIIClone->insertBefore(&*InsertPos);
   LLVM_DEBUG(dbgs() << "SINK: " << *DIIClone << '\n');
 }
   }
+}
 
-  return true;
+void InstCombinerImpl::tryToSinkInstructionDPValues(
+Instruction *I, BasicBlock::iterator InsertPos, BasicBlock *SrcBlock,
+BasicBlock *DestBlock, SmallVectorImpl &DPValues) {
+  // Implementation of tryToSinkInstructionDbgValues, but for the DPValue of
+  // variable assignments rather than dbg.values.
+
+  // Fetch all DPValues not already in the destination.
+  SmallVector DPValuesToSalvage;
+  for (auto &DPV : DPValues)
+if (DPV->getParent() != DestBlock)
+  DPValuesToSalvage.push_back(DPV);
+
+  // Fetch a second collection, of DPValues in the source block that we're 
going
+  // to sink.
+  SmallVector DPValuesToSink;
+  for (DPValue *DPV : DPValuesToSalvage)
+if (DPV->getParent() == SrcBlock)
+  DPValuesToSink.push_back(DPV);
+
+  // Sort DPValues according to their position in the block. This is a partial

SLTozer wrote:

I actually thinking about the performance of removing all the 
filtermap/duplicate detection logic and just iterating over getDbgValueRange() 
to determine whether A or B comes first when they're attached to the same 
instruction - I submitted a quick test to the compile time tracker[0] though 
and it looks like it's neutral for most cases and a slowdown in the bad case 
(testing specifically with RemoveDIs enabled), so I'm happy with this approach.
[0] 
http://llvm-compile-time-tracker.com/compare.php?from=319280746b199b35c49798383b6dd4c01286c5ff&to=c29a7ff328a4148aabd7e147f2bfc04e9801fcb6&stat=instructions:u

https://github.com/llvm/llvm-project/pull/77930
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang-tools-extra] [clang] [DebugInfo][RemoveDIs] Add a DPValue implementation for instcombine sinking (PR #77930)

2024-01-25 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer approved this pull request.

LGTM with latest changes.

https://github.com/llvm/llvm-project/pull/77930
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   3   4   5   6   >