[clang] 2c34632 - [C++20] [Modules] [Driver] Support -print-library-module-manifest-path for libstdc++

2025-01-15 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2025-01-15T17:01:18+08:00
New Revision: 2c34632a9977a82ce6262d95f07addb772ba7014

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

LOG: [C++20] [Modules] [Driver] Support -print-library-module-manifest-path for 
libstdc++

Given libstdc++ has landed std module, the build systems may need clang
to find the configuration file to understand how to build the std
module. This patch did this. Tested with locally installed GCC-trunk.

Added: 


Modified: 
clang/lib/Driver/Driver.cpp
clang/test/Driver/modules-print-library-module-manifest-path.cpp

Removed: 




diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 9a947f32283c3a..eefbdca805739e 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -6501,9 +6501,24 @@ std::string Driver::GetStdModuleManifestPath(const 
Compilation &C,
 return evaluate("libc++.a").value_or(error);
   }
 
-  case ToolChain::CST_Libstdcxx:
-// libstdc++ does not provide Standard library modules yet.
-return error;
+  case ToolChain::CST_Libstdcxx: {
+auto evaluate = [&](const char *library) -> std::optional {
+  std::string lib = GetFilePath(library, TC);
+
+  SmallString<128> path(lib.begin(), lib.end());
+  llvm::sys::path::remove_filename(path);
+  llvm::sys::path::append(path, "libstdc++.modules.json");
+  if (TC.getVFS().exists(path))
+return static_cast(path);
+
+  return {};
+};
+
+if (std::optional result = evaluate("libstdc++.so"); result)
+  return *result;
+
+return evaluate("libstdc++.a").value_or(error);
+  }
   }
 
   return error;

diff  --git a/clang/test/Driver/modules-print-library-module-manifest-path.cpp 
b/clang/test/Driver/modules-print-library-module-manifest-path.cpp
index 8d17fe1549e34b..7606713bfa22a5 100644
--- a/clang/test/Driver/modules-print-library-module-manifest-path.cpp
+++ b/clang/test/Driver/modules-print-library-module-manifest-path.cpp
@@ -48,6 +48,9 @@
 // RUN: --target=x86_64-linux-gnu 2>&1 \
 // RUN:   | FileCheck libcxx-no-shared-lib.cpp
 
+// Testing with libstdc++
+// RUN: touch %t/Inputs/usr/lib/x86_64-linux-gnu/libstdc++.so
+// RUN: touch %t/Inputs/usr/lib/x86_64-linux-gnu/libstdc++.modules.json
 // RUN: %clang -print-library-module-manifest-path \
 // RUN: -stdlib=libstdc++ \
 // RUN: -resource-dir=%t/Inputs/usr/lib/x86_64-linux-gnu \
@@ -74,4 +77,4 @@
 
 //--- libstdcxx.cpp
 
-// CHECK: 
+// CHECK: {{.*}}libstdc++.modules.json
\ No newline at end of file



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


[clang-tools-extra] [include-cleaner] Add special mappings for operator new/delete (PR #123027)

2025-01-15 Thread kadir çetinkaya via cfe-commits

https://github.com/kadircet updated 
https://github.com/llvm/llvm-project/pull/123027

From 5339f8e303a99b8a75320b24a3a371e531fa6140 Mon Sep 17 00:00:00 2001
From: Kadir Cetinkaya 
Date: Wed, 15 Jan 2025 10:11:09 +0100
Subject: [PATCH 1/2] [include-cleaner] Add special mappings for operator
 new/delete

Our stdlib mappings are based on names, hence they can't handle special
symbols like oprators.

Global operator new/delete show up often enough in practice to create
some user frustration, so we map these to .
---
 .../include-cleaner/lib/FindHeaders.cpp   | 17 ++-
 .../unittests/FindHeadersTest.cpp | 45 +++
 2 files changed, 61 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/include-cleaner/lib/FindHeaders.cpp 
b/clang-tools-extra/include-cleaner/lib/FindHeaders.cpp
index 7b28d1c252d715..e6a642ae8ed48a 100644
--- a/clang-tools-extra/include-cleaner/lib/FindHeaders.cpp
+++ b/clang-tools-extra/include-cleaner/lib/FindHeaders.cpp
@@ -16,6 +16,7 @@
 #include "clang/AST/DeclCXX.h"
 #include "clang/Basic/Builtins.h"
 #include "clang/Basic/FileEntry.h"
+#include "clang/Basic/OperatorKinds.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
@@ -157,8 +158,22 @@ headersForSpecialSymbol(const Symbol &S, const 
SourceManager &SM,
   if (!ND)
 return std::nullopt;
   auto *II = ND->getIdentifier();
-  if (!II)
+  if (!II) {
+// Special case global operator new/delete, these show up often enough in
+// practice and stdlib mappings can't work with them as they're symbol-name
+// based.
+if (ND->getDeclContext()->isTranslationUnit()) {
+  switch (ND->getDeclName().getCXXOverloadedOperator()) {
+  case OverloadedOperatorKind::OO_New:
+  case OverloadedOperatorKind::OO_Delete:
+return hintedHeadersForStdHeaders(
+{tooling::stdlib::Header::named("").value()}, SM, PI);
+  default:
+break;
+  }
+}
 return std::nullopt;
+  }
 
   // Check first for symbols that are part of our stdlib mapping. As we have
   // header names for those.
diff --git a/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp 
b/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
index 84e02e1d0d621b..d5b0a61ed1dfcb 100644
--- a/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
@@ -11,11 +11,13 @@
 #include "clang-include-cleaner/Analysis.h"
 #include "clang-include-cleaner/Record.h"
 #include "clang-include-cleaner/Types.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/Basic/FileEntry.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/LLVM.h"
+#include "clang/Basic/OperatorKinds.h"
 #include "clang/Frontend/FrontendActions.h"
 #include "clang/Testing/TestAST.h"
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
@@ -617,6 +619,49 @@ TEST_F(HeadersForSymbolTest, 
AmbiguousStdSymbolsUsingShadow) {
   Header(*tooling::stdlib::Header::named("";
 }
 
+TEST_F(HeadersForSymbolTest, GlobalOperatorNewDelete) {
+  Inputs.Code = R"cpp(
+void k() {
+  int *x;
+  // make sure operator new/delete are part of TU.
+  x = static_cast(::operator new(sizeof(int)));
+  ::operator delete(x);
+}
+  )cpp";
+  buildAST();
+
+  // Find global new/delete operators.
+  struct Visitor : public DynamicRecursiveASTVisitor {
+const NamedDecl *New = nullptr;
+const NamedDecl *Delete = nullptr;
+bool VisitNamedDecl(NamedDecl *ND) override {
+  if (!ND->getDeclContext()->isTranslationUnit())
+return true;
+  switch (ND->getDeclName().getCXXOverloadedOperator()) {
+  case OO_New:
+New = ND;
+break;
+  case OO_Delete:
+Delete = ND;
+break;
+  default:
+break;
+  }
+  return true;
+}
+  };
+  Visitor V;
+  V.ShouldVisitImplicitCode = true;
+  V.TraverseDecl(AST->context().getTranslationUnitDecl());
+  ASSERT_TRUE(V.New) << "Couldn't find global new!";
+  ASSERT_TRUE(V.Delete) << "Couldn't find global delete!";
+  EXPECT_THAT(headersForSymbol(*V.New, AST->sourceManager(), &PI),
+  UnorderedElementsAre(
+  Header(*tooling::stdlib::Header::named("";
+  EXPECT_THAT(headersForSymbol(*V.Delete, AST->sourceManager(), &PI),
+  UnorderedElementsAre(
+  Header(*tooling::stdlib::Header::named("";
+}
 
 TEST_F(HeadersForSymbolTest, StandardHeaders) {
   Inputs.Code = R"cpp(

From 31ee98aa1896fd77380749ad90e7c452f36e2ce2 Mon Sep 17 00:00:00 2001
From: Kadir Cetinkaya 
Date: Wed, 15 Jan 2025 10:34:17 +0100
Subject: [PATCH 2/2] formatting

---
 .../include-cleaner/unittests/FindHeadersTest.cpp| 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/clang-tool

[clang] [Clang] Correct the order of substituted arguments in CTAD alias guides (PR #123022)

2025-01-15 Thread Younan Zhang via cfe-commits

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


[clang] [clang-format] Fix greatergreater (PR #122282)

2025-01-15 Thread via cfe-commits


@@ -28188,6 +28188,17 @@ TEST_F(FormatTest, BreakBinaryOperations) {
"  | byte_buffer[2] << 16\n"
"  | byte_buffer[3] << 24;",
Style);

andergnet wrote:

I'm not sure I get what you are trying to tell me. Do you want the unit test to 
be the minimal reproducer of the error?

As far as I have tested the changes work, these are some unit tests I have done 
(but not commited) to check it:
```
{
  auto Style = getLLVMStyleWithColumns(60);
  Style.BreakBeforeBinaryOperators = FormatStyle::BOS_NonAssignment;

  Style.BreakBinaryOperations = FormatStyle::BBO_OnePerLine;

  verifyFormat("std::cin\n"
   ">> longOperand_1\n"
   ">> longOperand_2\n"
   ">> longOperand_3_;",
   Style);

  verifyFormat("std::cin >> longOperand_1 >> longOperand_2 >> longOperand_3;",
   Style);

  Style.BreakBinaryOperations = FormatStyle::BBO_RespectPrecedence;
  verifyFormat("std::cin\n"
   ">> longOperand_1\n"
   ">> longOperand_2\n"
   ">> longOperand_3_;",
   Style);

  verifyFormat("std::cin >> longOperand_1 >> longOperand_2 >> longOperand_3;",
   Style);
}
```

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


[clang] [llvm] [RISCV] Add MIPS extensions (PR #121394)

2025-01-15 Thread Djordje Todorovic via cfe-commits


@@ -62,6 +62,15 @@ static cl::opt RISCVMinimumJumpTableEntries(
 "riscv-min-jump-table-entries", cl::Hidden,
 cl::desc("Set minimum number of entries to use a jump table on RISCV"));
 
+static cl::opt
+UseLoadStorePairsOpt("riscv-load-store-pairs",

djtodoro wrote:

Well, we have not seen benefits on some important applications/benchmarks for 
us when using this extension with `p8700` CPU, so that is why we keep it `OFF` 
by default for now.

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


[clang] [llvm] [RISCV] Add MIPS extensions (PR #121394)

2025-01-15 Thread Djordje Todorovic via cfe-commits

djtodoro wrote:

@topperc Thanks for the comments!

> This still isn't broken down enough. We usually like to see assembler support 
> in separate patches from code generation.

I have removed `RISCVLoadStoreOptimizer` Pass, and will add it in a separate 
PR/commit.

> Missing tests in test/MC/RISCV for the assembler and disassembler

Added.



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


[clang] [clang] Add support for passing FileSystem to buildASTFromCodeWithArgs() (PR #123042)

2025-01-15 Thread Boaz Brickner via cfe-commits


@@ -223,7 +223,11 @@ buildASTFromCode(StringRef Code, StringRef FileName = 
"input.cc",
 /// \param PCHContainerOps The PCHContainerOperations for loading and creating
 /// clang modules.
 ///
-/// \param Adjuster A function to filter the command line arguments as 
specified.
+/// \param Adjuster A function to filter the command line arguments as
+/// specified.
+///
+/// \param FileSystem FileSystem for managing and looking up files.

bricknerb wrote:

Done.

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


[clang] [FMV][AArch64][clang] Advance __FUNCTION_MULTI_VERSIONING_SUPPORT_LEVEL to ACLE Q3 (PR #123056)

2025-01-15 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea created 
https://github.com/llvm/llvm-project/pull/123056

None

>From e113c583644afb7a042e73d3ccd697d9dd0b4dd8 Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Wed, 15 Jan 2025 13:35:37 +
Subject: [PATCH] [FMV][AArch64][clang] Advance
 __FUNCTION_MULTI_VERSIONING_SUPPORT_LEVEL to ACLE Q3

---
 clang/lib/Basic/Targets/AArch64.cpp| 2 +-
 clang/test/Preprocessor/init-aarch64.c | 8 
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index 4e211deb9fabab..0b899137bbb5c7 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -421,7 +421,7 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
 #define ARM_ACLE_VERSION(Y, Q, P) (100 * (Y) + 10 * (Q) + (P))
   Builder.defineMacro("__ARM_ACLE", Twine(ARM_ACLE_VERSION(2024, 2, 0)));
   Builder.defineMacro("__FUNCTION_MULTI_VERSIONING_SUPPORT_LEVEL",
-  Twine(ARM_ACLE_VERSION(2024, 2, 0)));
+  Twine(ARM_ACLE_VERSION(2024, 3, 0)));
 #undef ARM_ACLE_VERSION
   Builder.defineMacro("__ARM_ARCH",
   std::to_string(ArchInfo->Version.getMajor()));
diff --git a/clang/test/Preprocessor/init-aarch64.c 
b/clang/test/Preprocessor/init-aarch64.c
index 3d2f4b83abcb88..8578993dbfaeb9 100644
--- a/clang/test/Preprocessor/init-aarch64.c
+++ b/clang/test/Preprocessor/init-aarch64.c
@@ -123,7 +123,7 @@
 // AARCH64-NEXT: #define __FPCLASS_SNAN 0x0001
 // AARCH64-NEXT: #define __FP_FAST_FMA 1
 // AARCH64-NEXT: #define __FP_FAST_FMAF 1
-// AARCH64-NEXT: #define __FUNCTION_MULTI_VERSIONING_SUPPORT_LEVEL 202420
+// AARCH64-NEXT: #define __FUNCTION_MULTI_VERSIONING_SUPPORT_LEVEL 202430
 // AARCH64-NEXT: #define __GCC_ASM_FLAG_OUTPUTS__ 1
 // AARCH64-NEXT: #define __GCC_CONSTRUCTIVE_SIZE {{.+}}
 // AARCH64-NEXT: #define __GCC_DESTRUCTIVE_SIZE {{.+}}
@@ -434,7 +434,7 @@
 // AARCH64-DARWIN: #define __FLT_MIN_EXP__ (-125)
 // AARCH64-DARWIN: #define __FLT_MIN__ 1.17549435e-38F
 // AARCH64-DARWIN: #define __FLT_RADIX__ 2
-// AARCH64-DARWIN: #define __FUNCTION_MULTI_VERSIONING_SUPPORT_LEVEL 202420
+// AARCH64-DARWIN: #define __FUNCTION_MULTI_VERSIONING_SUPPORT_LEVEL 202430
 // AARCH64-DARWIN: #define __INT16_C_SUFFIX__
 // AARCH64-DARWIN: #define __INT16_FMTd__ "hd"
 // AARCH64-DARWIN: #define __INT16_FMTi__ "hi"
@@ -651,7 +651,7 @@
 // AARCH64-MSVC: #define __FLT_MIN_EXP__ (-125)
 // AARCH64-MSVC: #define __FLT_MIN__ 1.17549435e-38F
 // AARCH64-MSVC: #define __FLT_RADIX__ 2
-// AARCH64-MSVC: #define __FUNCTION_MULTI_VERSIONING_SUPPORT_LEVEL 202420
+// AARCH64-MSVC: #define __FUNCTION_MULTI_VERSIONING_SUPPORT_LEVEL 202430
 // AARCH64-MSVC: #define __INT_MAX__ 2147483647
 // AARCH64-MSVC: #define __LDBL_DECIMAL_DIG__ 17
 // AARCH64-MSVC: #define __LDBL_DENORM_MIN__ 4.9406564584124654e-324L
@@ -859,7 +859,7 @@
 // ARM64EC-MSVC: #define __FPCLASS_SNAN 0x0001
 // ARM64EC-MSVC: #define __FP_FAST_FMA 1
 // ARM64EC-MSVC: #define __FP_FAST_FMAF 1
-// ARM64EC-MSVC: #define __FUNCTION_MULTI_VERSIONING_SUPPORT_LEVEL 202420
+// ARM64EC-MSVC: #define __FUNCTION_MULTI_VERSIONING_SUPPORT_LEVEL 202430
 // ARM64EC-MSVC: #define __GCC_ASM_FLAG_OUTPUTS__ 1
 // ARM64EC-MSVC: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
 // ARM64EC-MSVC: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16 1

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


[clang] [FMV][AArch64][clang] Advance __FUNCTION_MULTI_VERSIONING_SUPPORT_LEVEL to ACLE Q3 (PR #123056)

2025-01-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Alexandros Lamprineas (labrinea)


Changes



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


2 Files Affected:

- (modified) clang/lib/Basic/Targets/AArch64.cpp (+1-1) 
- (modified) clang/test/Preprocessor/init-aarch64.c (+4-4) 


``diff
diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index 4e211deb9fabab..0b899137bbb5c7 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -421,7 +421,7 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
 #define ARM_ACLE_VERSION(Y, Q, P) (100 * (Y) + 10 * (Q) + (P))
   Builder.defineMacro("__ARM_ACLE", Twine(ARM_ACLE_VERSION(2024, 2, 0)));
   Builder.defineMacro("__FUNCTION_MULTI_VERSIONING_SUPPORT_LEVEL",
-  Twine(ARM_ACLE_VERSION(2024, 2, 0)));
+  Twine(ARM_ACLE_VERSION(2024, 3, 0)));
 #undef ARM_ACLE_VERSION
   Builder.defineMacro("__ARM_ARCH",
   std::to_string(ArchInfo->Version.getMajor()));
diff --git a/clang/test/Preprocessor/init-aarch64.c 
b/clang/test/Preprocessor/init-aarch64.c
index 3d2f4b83abcb88..8578993dbfaeb9 100644
--- a/clang/test/Preprocessor/init-aarch64.c
+++ b/clang/test/Preprocessor/init-aarch64.c
@@ -123,7 +123,7 @@
 // AARCH64-NEXT: #define __FPCLASS_SNAN 0x0001
 // AARCH64-NEXT: #define __FP_FAST_FMA 1
 // AARCH64-NEXT: #define __FP_FAST_FMAF 1
-// AARCH64-NEXT: #define __FUNCTION_MULTI_VERSIONING_SUPPORT_LEVEL 202420
+// AARCH64-NEXT: #define __FUNCTION_MULTI_VERSIONING_SUPPORT_LEVEL 202430
 // AARCH64-NEXT: #define __GCC_ASM_FLAG_OUTPUTS__ 1
 // AARCH64-NEXT: #define __GCC_CONSTRUCTIVE_SIZE {{.+}}
 // AARCH64-NEXT: #define __GCC_DESTRUCTIVE_SIZE {{.+}}
@@ -434,7 +434,7 @@
 // AARCH64-DARWIN: #define __FLT_MIN_EXP__ (-125)
 // AARCH64-DARWIN: #define __FLT_MIN__ 1.17549435e-38F
 // AARCH64-DARWIN: #define __FLT_RADIX__ 2
-// AARCH64-DARWIN: #define __FUNCTION_MULTI_VERSIONING_SUPPORT_LEVEL 202420
+// AARCH64-DARWIN: #define __FUNCTION_MULTI_VERSIONING_SUPPORT_LEVEL 202430
 // AARCH64-DARWIN: #define __INT16_C_SUFFIX__
 // AARCH64-DARWIN: #define __INT16_FMTd__ "hd"
 // AARCH64-DARWIN: #define __INT16_FMTi__ "hi"
@@ -651,7 +651,7 @@
 // AARCH64-MSVC: #define __FLT_MIN_EXP__ (-125)
 // AARCH64-MSVC: #define __FLT_MIN__ 1.17549435e-38F
 // AARCH64-MSVC: #define __FLT_RADIX__ 2
-// AARCH64-MSVC: #define __FUNCTION_MULTI_VERSIONING_SUPPORT_LEVEL 202420
+// AARCH64-MSVC: #define __FUNCTION_MULTI_VERSIONING_SUPPORT_LEVEL 202430
 // AARCH64-MSVC: #define __INT_MAX__ 2147483647
 // AARCH64-MSVC: #define __LDBL_DECIMAL_DIG__ 17
 // AARCH64-MSVC: #define __LDBL_DENORM_MIN__ 4.9406564584124654e-324L
@@ -859,7 +859,7 @@
 // ARM64EC-MSVC: #define __FPCLASS_SNAN 0x0001
 // ARM64EC-MSVC: #define __FP_FAST_FMA 1
 // ARM64EC-MSVC: #define __FP_FAST_FMAF 1
-// ARM64EC-MSVC: #define __FUNCTION_MULTI_VERSIONING_SUPPORT_LEVEL 202420
+// ARM64EC-MSVC: #define __FUNCTION_MULTI_VERSIONING_SUPPORT_LEVEL 202430
 // ARM64EC-MSVC: #define __GCC_ASM_FLAG_OUTPUTS__ 1
 // ARM64EC-MSVC: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
 // ARM64EC-MSVC: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16 1

``




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


[clang] [FMV][AArch64][clang] Advance __FUNCTION_MULTI_VERSIONING_SUPPORT_LEVEL to ACLE Q3 (PR #123056)

2025-01-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-aarch64

Author: Alexandros Lamprineas (labrinea)


Changes



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


2 Files Affected:

- (modified) clang/lib/Basic/Targets/AArch64.cpp (+1-1) 
- (modified) clang/test/Preprocessor/init-aarch64.c (+4-4) 


``diff
diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index 4e211deb9fabab..0b899137bbb5c7 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -421,7 +421,7 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
 #define ARM_ACLE_VERSION(Y, Q, P) (100 * (Y) + 10 * (Q) + (P))
   Builder.defineMacro("__ARM_ACLE", Twine(ARM_ACLE_VERSION(2024, 2, 0)));
   Builder.defineMacro("__FUNCTION_MULTI_VERSIONING_SUPPORT_LEVEL",
-  Twine(ARM_ACLE_VERSION(2024, 2, 0)));
+  Twine(ARM_ACLE_VERSION(2024, 3, 0)));
 #undef ARM_ACLE_VERSION
   Builder.defineMacro("__ARM_ARCH",
   std::to_string(ArchInfo->Version.getMajor()));
diff --git a/clang/test/Preprocessor/init-aarch64.c 
b/clang/test/Preprocessor/init-aarch64.c
index 3d2f4b83abcb88..8578993dbfaeb9 100644
--- a/clang/test/Preprocessor/init-aarch64.c
+++ b/clang/test/Preprocessor/init-aarch64.c
@@ -123,7 +123,7 @@
 // AARCH64-NEXT: #define __FPCLASS_SNAN 0x0001
 // AARCH64-NEXT: #define __FP_FAST_FMA 1
 // AARCH64-NEXT: #define __FP_FAST_FMAF 1
-// AARCH64-NEXT: #define __FUNCTION_MULTI_VERSIONING_SUPPORT_LEVEL 202420
+// AARCH64-NEXT: #define __FUNCTION_MULTI_VERSIONING_SUPPORT_LEVEL 202430
 // AARCH64-NEXT: #define __GCC_ASM_FLAG_OUTPUTS__ 1
 // AARCH64-NEXT: #define __GCC_CONSTRUCTIVE_SIZE {{.+}}
 // AARCH64-NEXT: #define __GCC_DESTRUCTIVE_SIZE {{.+}}
@@ -434,7 +434,7 @@
 // AARCH64-DARWIN: #define __FLT_MIN_EXP__ (-125)
 // AARCH64-DARWIN: #define __FLT_MIN__ 1.17549435e-38F
 // AARCH64-DARWIN: #define __FLT_RADIX__ 2
-// AARCH64-DARWIN: #define __FUNCTION_MULTI_VERSIONING_SUPPORT_LEVEL 202420
+// AARCH64-DARWIN: #define __FUNCTION_MULTI_VERSIONING_SUPPORT_LEVEL 202430
 // AARCH64-DARWIN: #define __INT16_C_SUFFIX__
 // AARCH64-DARWIN: #define __INT16_FMTd__ "hd"
 // AARCH64-DARWIN: #define __INT16_FMTi__ "hi"
@@ -651,7 +651,7 @@
 // AARCH64-MSVC: #define __FLT_MIN_EXP__ (-125)
 // AARCH64-MSVC: #define __FLT_MIN__ 1.17549435e-38F
 // AARCH64-MSVC: #define __FLT_RADIX__ 2
-// AARCH64-MSVC: #define __FUNCTION_MULTI_VERSIONING_SUPPORT_LEVEL 202420
+// AARCH64-MSVC: #define __FUNCTION_MULTI_VERSIONING_SUPPORT_LEVEL 202430
 // AARCH64-MSVC: #define __INT_MAX__ 2147483647
 // AARCH64-MSVC: #define __LDBL_DECIMAL_DIG__ 17
 // AARCH64-MSVC: #define __LDBL_DENORM_MIN__ 4.9406564584124654e-324L
@@ -859,7 +859,7 @@
 // ARM64EC-MSVC: #define __FPCLASS_SNAN 0x0001
 // ARM64EC-MSVC: #define __FP_FAST_FMA 1
 // ARM64EC-MSVC: #define __FP_FAST_FMAF 1
-// ARM64EC-MSVC: #define __FUNCTION_MULTI_VERSIONING_SUPPORT_LEVEL 202420
+// ARM64EC-MSVC: #define __FUNCTION_MULTI_VERSIONING_SUPPORT_LEVEL 202430
 // ARM64EC-MSVC: #define __GCC_ASM_FLAG_OUTPUTS__ 1
 // ARM64EC-MSVC: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
 // ARM64EC-MSVC: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16 1

``




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


[clang] 6ca560a - [clang] Add support for passing FileSystem to buildASTFromCodeWithArgs() (#123042)

2025-01-15 Thread via cfe-commits

Author: Boaz Brickner
Date: 2025-01-15T14:56:07+01:00
New Revision: 6ca560a9092e29c9f9817db6d6da09edd5f0ded7

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

LOG: [clang] Add support for passing FileSystem to buildASTFromCodeWithArgs() 
(#123042)

This would allow tools that don't use the real file system to use this
function.

Added: 


Modified: 
clang/include/clang/Tooling/Tooling.h
clang/lib/Tooling/Tooling.cpp
clang/unittests/Tooling/ToolingTest.cpp

Removed: 




diff  --git a/clang/include/clang/Tooling/Tooling.h 
b/clang/include/clang/Tooling/Tooling.h
index 070706e8fa6d11..200fb30839a951 100644
--- a/clang/include/clang/Tooling/Tooling.h
+++ b/clang/include/clang/Tooling/Tooling.h
@@ -223,7 +223,11 @@ buildASTFromCode(StringRef Code, StringRef FileName = 
"input.cc",
 /// \param PCHContainerOps The PCHContainerOperations for loading and creating
 /// clang modules.
 ///
-/// \param Adjuster A function to filter the command line arguments as 
specified.
+/// \param Adjuster A function to filter the command line arguments as
+/// specified.
+///
+/// \param BaseFS FileSystem for managing and looking up files.
+/// VirtualMappedFiles takes precedence.
 ///
 /// \return The resulting AST or null if an error occurred.
 std::unique_ptr buildASTFromCodeWithArgs(
@@ -233,7 +237,9 @@ std::unique_ptr buildASTFromCodeWithArgs(
 std::make_shared(),
 ArgumentsAdjuster Adjuster = getClangStripDependencyFileAdjuster(),
 const FileContentMappings &VirtualMappedFiles = FileContentMappings(),
-DiagnosticConsumer *DiagConsumer = nullptr);
+DiagnosticConsumer *DiagConsumer = nullptr,
+IntrusiveRefCntPtr BaseFS =
+llvm::vfs::getRealFileSystem());
 
 /// Utility to run a FrontendAction in a single clang invocation.
 class ToolInvocation {

diff  --git a/clang/lib/Tooling/Tooling.cpp b/clang/lib/Tooling/Tooling.cpp
index 88b7349ce8fed6..03523c3f17eda5 100644
--- a/clang/lib/Tooling/Tooling.cpp
+++ b/clang/lib/Tooling/Tooling.cpp
@@ -692,11 +692,12 @@ std::unique_ptr buildASTFromCodeWithArgs(
 StringRef Code, const std::vector &Args, StringRef FileName,
 StringRef ToolName, std::shared_ptr 
PCHContainerOps,
 ArgumentsAdjuster Adjuster, const FileContentMappings &VirtualMappedFiles,
-DiagnosticConsumer *DiagConsumer) {
+DiagnosticConsumer *DiagConsumer,
+IntrusiveRefCntPtr BaseFS) {
   std::vector> ASTs;
   ASTBuilderAction Action(ASTs);
   llvm::IntrusiveRefCntPtr OverlayFileSystem(
-  new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem()));
+  new llvm::vfs::OverlayFileSystem(std::move(BaseFS)));
   llvm::IntrusiveRefCntPtr InMemoryFileSystem(
   new llvm::vfs::InMemoryFileSystem);
   OverlayFileSystem->pushOverlay(InMemoryFileSystem);

diff  --git a/clang/unittests/Tooling/ToolingTest.cpp 
b/clang/unittests/Tooling/ToolingTest.cpp
index 0b65577a05193f..8cdfffb54390e0 100644
--- a/clang/unittests/Tooling/ToolingTest.cpp
+++ b/clang/unittests/Tooling/ToolingTest.cpp
@@ -152,6 +152,20 @@ TEST(buildASTFromCode, ReportsErrors) {
   EXPECT_EQ(1u, Consumer.NumDiagnosticsSeen);
 }
 
+TEST(buildASTFromCode, FileSystem) {
+  llvm::IntrusiveRefCntPtr InMemoryFileSystem(
+  new llvm::vfs::InMemoryFileSystem);
+  InMemoryFileSystem->addFile("included_file.h", 0,
+  llvm::MemoryBuffer::getMemBufferCopy("class 
X;"));
+  std::unique_ptr AST = buildASTFromCodeWithArgs(
+  R"(#include "included_file.h")", {}, "input.cc", "clang-tool",
+  std::make_shared(),
+  getClangStripDependencyFileAdjuster(), FileContentMappings(), nullptr,
+  InMemoryFileSystem);
+  ASSERT_TRUE(AST.get());
+  EXPECT_TRUE(FindClassDeclX(AST.get()));
+}
+
 TEST(newFrontendActionFactory, CreatesFrontendActionFactoryFromType) {
   std::unique_ptr Factory(
   newFrontendActionFactory());



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


[clang] [clang] Add support for passing FileSystem to buildASTFromCodeWithArgs() (PR #123042)

2025-01-15 Thread Boaz Brickner via cfe-commits

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


[clang] [Hexagon] Add default clang symlinks to CLANG_LINKS_TO_CREATE (PR #123011)

2025-01-15 Thread via cfe-commits

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


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


[clang] [clang] Add support for passing FileSystem to buildASTFromCodeWithArgs() (PR #123042)

2025-01-15 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `lldb-x86_64-debian` 
running on `lldb-x86_64-debian` while building `clang` at step 6 "test".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/162/builds/14147


Here is the relevant piece of the build log for the reference

```
Step 6 (test) failure: build (failure)
...
PASS: lldb-api :: tools/lldb-dap/variables/TestDAP_variables.py (32 of 2741)
PASS: lldb-api :: 
functionalities/breakpoint/breakpoint_callback_command_source/TestBreakpointCallbackCommandSource.py
 (33 of 2741)
PASS: lldb-api :: iohandler/stdio/TestIOHandlerProcessSTDIO.py (34 of 2741)
PASS: lldb-api :: tools/lldb-server/TestGdbRemoteThreadsInStopReply.py (35 of 
2741)
PASS: lldb-api :: 
functionalities/data-formatter/data-formatter-stl/generic/forward_list/TestDataFormatterGenericForwardList.py
 (36 of 2741)
PASS: lldb-api :: functionalities/gdb_remote_client/TestRegDefinitionInParts.py 
(37 of 2741)
PASS: lldb-api :: lang/cpp/namespace/TestNamespace.py (38 of 2741)
PASS: lldb-api :: driver/quit_speed/TestQuitWithProcess.py (39 of 2741)
PASS: lldb-api :: iohandler/completion/TestIOHandlerCompletion.py (40 of 2741)
PASS: lldb-api :: tools/lldb-server/TestGdbRemoteLaunch.py (41 of 2741)
FAIL: lldb-api :: tools/lldb-dap/launch/TestDAP_launch.py (42 of 2741)
 TEST 'lldb-api :: tools/lldb-dap/launch/TestDAP_launch.py' 
FAILED 
Script:
--
/usr/bin/python3 
/home/worker/2.0.1/lldb-x86_64-debian/llvm-project/lldb/test/API/dotest.py -u 
CXXFLAGS -u CFLAGS --env 
LLVM_LIBS_DIR=/home/worker/2.0.1/lldb-x86_64-debian/build/./lib --env 
LLVM_INCLUDE_DIR=/home/worker/2.0.1/lldb-x86_64-debian/build/include --env 
LLVM_TOOLS_DIR=/home/worker/2.0.1/lldb-x86_64-debian/build/./bin --arch x86_64 
--build-dir /home/worker/2.0.1/lldb-x86_64-debian/build/lldb-test-build.noindex 
--lldb-module-cache-dir 
/home/worker/2.0.1/lldb-x86_64-debian/build/lldb-test-build.noindex/module-cache-lldb/lldb-api
 --clang-module-cache-dir 
/home/worker/2.0.1/lldb-x86_64-debian/build/lldb-test-build.noindex/module-cache-clang/lldb-api
 --executable /home/worker/2.0.1/lldb-x86_64-debian/build/./bin/lldb --compiler 
/home/worker/2.0.1/lldb-x86_64-debian/build/./bin/clang --dsymutil 
/home/worker/2.0.1/lldb-x86_64-debian/build/./bin/dsymutil --make 
/usr/bin/gmake --llvm-tools-dir 
/home/worker/2.0.1/lldb-x86_64-debian/build/./bin --lldb-obj-root 
/home/worker/2.0.1/lldb-x86_64-debian/build/tools/lldb --lldb-libs-dir 
/home/worker/2.0.1/lldb-x86_64-debian/build/./lib -t 
/home/worker/2.0.1/lldb-x86_64-debian/llvm-project/lldb/test/API/tools/lldb-dap/launch
 -p TestDAP_launch.py
--
Exit Code: 1

Command Output (stdout):
--
lldb version 20.0.0git (https://github.com/llvm/llvm-project.git revision 
6ca560a9092e29c9f9817db6d6da09edd5f0ded7)
  clang revision 6ca560a9092e29c9f9817db6d6da09edd5f0ded7
  llvm revision 6ca560a9092e29c9f9817db6d6da09edd5f0ded7
Skipping the following test categories: ['libc++', 'dsym', 'gmodules', 
'debugserver', 'objc']
= DEBUG ADAPTER PROTOCOL LOGS =
1736949506.943223715 --> 
Content-Length: 344

{
  "arguments": {
"adapterID": "lldb-native",
"clientID": "vscode",
"columnsStartAt1": true,
"linesStartAt1": true,
"locale": "en-us",
"pathFormat": "path",
"sourceInitFile": false,
"supportsRunInTerminalRequest": true,
"supportsStartDebuggingRequest": true,
"supportsVariablePaging": true,
"supportsVariableType": true
  },
  "command": "initialize",
  "seq": 1,
  "type": "request"
}
1736949506.945176601 <-- 
Content-Length: 1589


```



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


[clang] [analyzer] Add MemSpace trait to program state (PR #123003)

2025-01-15 Thread Donát Nagy via cfe-commits

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


[clang] [analyzer] Add MemSpace trait to program state (PR #123003)

2025-01-15 Thread Donát Nagy via cfe-commits

https://github.com/NagyDonat commented:

I strongly support the idea that we should eventually represent the memory 
space of a memory region by a state trait (instead of the "fake" super-region) 
and I am grateful that you're working on this.

I added a few suggestions in inline comments that could simplify the logic and 
ensure better behavior w.r.t. element and field subregions. (Also there are a 
few trivial nitpicks about comments.)

In my opinion it would be nice to have some code path that sets and uses these 
MemSpace traits (even in this initial commit), because that would let us test 
the code and verify that it's working correctly.

However, I'm not totally opposed to accepting this as an NFC (no functional 
change) commit, but in that case, please add `[NFC]` to the review/commit title 
(before merging the commit) as that helps developers who want to quickly find a 
commit which is responsible for a certain issue. 

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


[clang] [analyzer] Add MemSpace trait to program state (PR #123003)

2025-01-15 Thread Donát Nagy via cfe-commits


@@ -0,0 +1,62 @@
+//===-- MemSpaces.cpp -*- C++ 
-*--//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// TODO
+//
+//===--===//
+
+#include "clang/StaticAnalyzer/Core/PathSensitive/MemSpaces.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
+#include 
+
+REGISTER_MAP_WITH_PROGRAMSTATE(MemSpacesMap, const clang::ento::MemRegion *,
+   const clang::ento::MemSpaceRegion *)
+
+namespace clang {
+namespace ento {
+namespace memspace {
+
+ProgramStateRef setMemSpaceTrait(ProgramStateRef State, const MemRegion *MR,
+ const MemSpaceRegion *MS) {
+  // for now, this should only be called to update the trait for mem regions
+  // that have an unknown mem spaces since we assume everywhere else that the
+  // memspace trait is set only for unknown mem spaces (setting this info
+  // otherwise would go unused).
+  assert(isa(MR->getMemorySpace()));
+
+  // Shouldn't use the memspace trait to associate UnknownSpaceRegion with an
+  // already UnknownSpaceRegion
+  assert(!isa(MS));
+
+  ProgramStateRef NewState = State->set(MR, MS);

NagyDonat wrote:

Your code can bind a memory space trait to any memory region, including regions 
like `ElementRegion`, `FieldRegion` etc. that are just parts of a bigger 
region. This could cause ugly inconsistencies, e.g. the analyzer could assume 
that one field of a `struct` object is on the heap, while another field is on 
the stack.

To avoid these issues, you should "canonicalize" your regions by using 
`MR->getBaseRegion()` (which would convert e.g. the region corresponding to 
`obj.field[5].subfield[2]` to the "base" region of `obj`). Obviously, you 
should perform this canonicalization both in this setter function and the 
corresponding getter.

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


[clang] [analyzer] Add MemSpace trait to program state (PR #123003)

2025-01-15 Thread Donát Nagy via cfe-commits


@@ -0,0 +1,62 @@
+//===-- MemSpaces.cpp -*- C++ 
-*--//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// TODO
+//
+//===--===//
+
+#include "clang/StaticAnalyzer/Core/PathSensitive/MemSpaces.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
+#include 
+
+REGISTER_MAP_WITH_PROGRAMSTATE(MemSpacesMap, const clang::ento::MemRegion *,
+   const clang::ento::MemSpaceRegion *)
+
+namespace clang {
+namespace ento {
+namespace memspace {
+
+ProgramStateRef setMemSpaceTrait(ProgramStateRef State, const MemRegion *MR,
+ const MemSpaceRegion *MS) {
+  // for now, this should only be called to update the trait for mem regions
+  // that have an unknown mem spaces since we assume everywhere else that the
+  // memspace trait is set only for unknown mem spaces (setting this info
+  // otherwise would go unused).
+  assert(isa(MR->getMemorySpace()));
+
+  // Shouldn't use the memspace trait to associate UnknownSpaceRegion with an
+  // already UnknownSpaceRegion
+  assert(!isa(MS));
+
+  ProgramStateRef NewState = State->set(MR, MS);
+  return NewState;
+}
+
+bool hasMemSpaceTrait(ProgramStateRef State, const MemRegion *MR) {
+  if (!isa(MR->getMemorySpace()))
+return false;
+
+  const MemSpaceRegion *const *Result = State->get(MR);
+  return Result;
+}
+
+const MemSpaceRegion *getMemSpaceTrait(ProgramStateRef State,
+   const MemRegion *MR) {
+  if (!isa(MR->getMemorySpace()))
+return nullptr;
+
+  const MemSpaceRegion *const *Result = State->get(MR);
+  if (!Result)
+return nullptr;
+  return *Result;
+}

NagyDonat wrote:

Instead this function, you should introduce a function that returns
- either `State->get(MR)` if it's non-null
- or `MR->getMemorySpace()` otherwise.
This function would reflect the fact that there is no underlying semantic 
difference between the two ways of storing the memory space (if a region _is on 
the heap_, we don't care if the region was initially created that way or we 
determined this later).

If you introduce this, you can simplify many complicated `if` conditions that 
currently use `II` to handle the two case.

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


[clang] [analyzer] Add MemSpace trait to program state (PR #123003)

2025-01-15 Thread Donát Nagy via cfe-commits


@@ -0,0 +1,62 @@
+//===-- MemSpaces.cpp -*- C++ 
-*--//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// TODO
+//
+//===--===//
+
+#include "clang/StaticAnalyzer/Core/PathSensitive/MemSpaces.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
+#include 
+
+REGISTER_MAP_WITH_PROGRAMSTATE(MemSpacesMap, const clang::ento::MemRegion *,
+   const clang::ento::MemSpaceRegion *)
+
+namespace clang {
+namespace ento {
+namespace memspace {
+
+ProgramStateRef setMemSpaceTrait(ProgramStateRef State, const MemRegion *MR,
+ const MemSpaceRegion *MS) {
+  // for now, this should only be called to update the trait for mem regions

NagyDonat wrote:

```suggestion
  // For now, this should only be called to update the trait for mem regions
```
Comments (especially long comments like this) are capitalized.

Also, personally I'd write "memory" instead of "mem" in the flowing text of the 
comment.

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


[clang] [analyzer] Add MemSpace trait to program state (PR #123003)

2025-01-15 Thread Donát Nagy via cfe-commits


@@ -0,0 +1,47 @@
+//===-- MemSpaces.h ---*- C++ 
-*--//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// TODO

NagyDonat wrote:

Don't forget to fill this before the commit is merged.

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


[clang] [analyzer] Add MemSpace trait to program state (PR #123003)

2025-01-15 Thread Donát Nagy via cfe-commits


@@ -0,0 +1,62 @@
+//===-- MemSpaces.cpp -*- C++ 
-*--//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// TODO

NagyDonat wrote:

Don't forget to fill this before the commit is merged.

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


[clang] [llvm] [LLVM][Clang][AArch64] Implement AArch64 build attributes (PR #118771)

2025-01-15 Thread via cfe-commits


@@ -7806,6 +7815,267 @@ bool 
AArch64AsmParser::parseDirectiveSEHSaveAnyReg(SMLoc L, bool Paired,
   return false;
 }
 
+bool AArch64AsmParser::parseDirectiveAeabiSubSectionHeader(SMLoc L) {
+  // Expecting 3 AsmToken::Identifier after '.aeabi_subsection', a name and 2
+  // parameters, e.g.: .aeabi_subsection (1)aeabi_feature_and_bits, 
(2)optional,
+  // (3)uleb128 separated by 2 commas.
+  MCAsmParser &Parser = getParser();
+
+  bool HasActiveSubsection = true;
+  std::unique_ptr ActiveSubsection =
+  getTargetStreamer().getActiveAtributesSubsection();
+  if (nullptr == ActiveSubsection) {
+HasActiveSubsection = false;
+  }
+
+  // Consume the name (subsection name)
+  StringRef SubsectionName;
+  AArch64BuildAttributes::VendorID SubsectionNameID;
+  if (Parser.getTok().is(AsmToken::Identifier)) {
+SubsectionName = Parser.getTok().getIdentifier();
+SubsectionNameID = AArch64BuildAttributes::getVendorID(SubsectionName);
+  } else {
+Error(Parser.getTok().getLoc(), "subsection name not found");
+return true;
+  }
+  Parser.Lex();
+  // consume a comma
+  // parseComma() return *false* on success, and call Lex(), no need to call
+  // Lex() again.
+  if (Parser.parseComma()) {
+return true;
+  }
+
+  // Consume the first parameter (optionality parameter)
+  AArch64BuildAttributes::SubsectionOptional IsOptional;
+  // options: optional/required
+  if (Parser.getTok().is(AsmToken::Identifier)) {
+StringRef Optionality = Parser.getTok().getIdentifier();
+IsOptional = AArch64BuildAttributes::getOptionalID(Optionality);
+if (AArch64BuildAttributes::OPTIONAL_NOT_FOUND == IsOptional) {
+  Error(Parser.getTok().getLoc(),
+AArch64BuildAttributes::getSubsectionOptionalUnknownError() + ": " 
+
+Optionality);
+  return true;
+}
+if (HasActiveSubsection &&

sivan-shani wrote:

fixed + test added

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


[clang] [C++20] [Modules] Makes sure internal declaration won't be found by other TU (PR #123059)

2025-01-15 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 created 
https://github.com/llvm/llvm-project/pull/123059

Close https://github.com/llvm/llvm-project/issues/61427

And this is also helpful to implement
https://github.com/llvm/llvm-project/issues/112294 partially.

The implementation strategy mimics
https://github.com/llvm/llvm-project/pull/122887. This patch split the internal 
declarations from the general lookup table so that other TU can't find the 
internal declarations.

>From 8ab290b840c07cfb225d24fa2a048866cfb98160 Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Wed, 15 Jan 2025 11:33:54 +0800
Subject: [PATCH] [C++20] [Modules] Makes sure internal declaration won't be
 found by other TU

Close https://github.com/llvm/llvm-project/issues/61427

And this is also helpful to implement
https://github.com/llvm/llvm-project/issues/112294 partially.

The implementation strategy mimics
https://github.com/llvm/llvm-project/pull/122887. This patch split the
internal declarations from the general lookup table so that other TU
can't find the internal declarations.
---
 .../include/clang/Serialization/ASTBitCodes.h |   6 +
 clang/include/clang/Serialization/ASTReader.h |  20 +-
 clang/include/clang/Serialization/ASTWriter.h |  11 +-
 clang/lib/Serialization/ASTReader.cpp |  89 ++--
 clang/lib/Serialization/ASTReaderDecl.cpp |  45 +++-
 clang/lib/Serialization/ASTWriter.cpp | 216 +-
 clang/lib/Serialization/ASTWriterDecl.cpp |  12 +-
 .../basic.lookup.argdep/p5-ex2.cpp|   4 +-
 .../basic.scope/basic.scope.namespace/p2.cpp  |  12 +-
 .../CXX/module/basic/basic.def.odr/p4.cppm|   5 -
 .../test/CXX/module/basic/basic.link/p2.cppm  |  13 +-
 11 files changed, 318 insertions(+), 115 deletions(-)

diff --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization/ASTBitCodes.h
index 40dae25f7b54b7..d568d2fd7aa301 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -740,6 +740,8 @@ enum ASTRecordTypes {
   CXX_ADDED_TEMPLATE_PARTIAL_SPECIALIZATION = 75,
 
   UPDATE_MODULE_LOCAL_VISIBLE = 76,
+
+  UPDATE_TU_LOCAL_VISIBLE = 77,
 };
 
 /// Record types used within a source manager block.
@@ -1340,6 +1342,10 @@ enum DeclCode {
   /// only visible from DeclContext in the same module.
   DECL_CONTEXT_MODULE_LOCAL_VISIBLE,
 
+  /// A record that stores the set of declarations that are only visible
+  /// to the TU.
+  DECL_CONTEXT_TU_LOCAL_VISIBLE,
+
   /// A LabelDecl record.
   DECL_LABEL,
 
diff --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index ea12adaec3ee81..1459c9f9b083f1 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -528,6 +528,7 @@ class ASTReader
 uint64_t LexicalOffset;
 uint64_t VisibleOffset;
 uint64_t ModuleLocalOffset;
+uint64_t TULocalOffset;
   };
 
   using DelayedNamespaceOffsetMapTy =
@@ -640,6 +641,9 @@ class ASTReader
   llvm::DenseMap
   ModuleLocalLookups;
+  llvm::DenseMap
+  TULocalLookups;
 
   using SpecLookupTableTy =
   llvm::DenseMap 
PendingVisibleUpdates;
   llvm::DenseMap
   PendingModuleLocalVisibleUpdates;
+  llvm::DenseMap TULocalUpdates;
 
   using SpecializationsUpdate = SmallVector;
   using SpecializationsUpdateMap =
@@ -704,11 +709,17 @@ class ASTReader
  llvm::BitstreamCursor &Cursor,
  uint64_t Offset, DeclContext *DC);
 
+  enum class VisibleDeclContextStorageKind {
+GenerallyVisible,
+ModuleLocalVisible,
+TULocalVisible,
+  };
+
   /// Read the record that describes the visible contents of a DC.
   bool ReadVisibleDeclContextStorage(ModuleFile &M,
  llvm::BitstreamCursor &Cursor,
  uint64_t Offset, GlobalDeclID ID,
- bool IsModuleLocal);
+ VisibleDeclContextStorageKind 
VisibleKind);
 
   bool ReadSpecializations(ModuleFile &M, llvm::BitstreamCursor &Cursor,
uint64_t Offset, Decl *D, bool IsPartial);
@@ -1148,6 +1159,10 @@ class ASTReader
   unsigned NumModuleLocalVisibleDeclContexts = 0,
TotalModuleLocalVisibleDeclContexts = 0;
 
+  /// Number of TU Local decl contexts read/total
+  unsigned NumTULocalVisibleDeclContexts = 0,
+   TotalTULocalVisibleDeclContexts = 0;
+
   /// Total size of modules, in bits, currently loaded
   uint64_t TotalModulesSizeInBits = 0;
 
@@ -1463,6 +1478,9 @@ class ASTReader
   const serialization::reader::ModuleLocalLookupTable *
   getModuleLocalLookupTables(DeclContext *Primary) const;
 
+  const serialization::reader::DeclContextLookupTable *
+  getTULocalLookupTables(DeclContext *Primary) const;
+
   /// Get the loaded specializations lookup tables for \p D,
   /// if any.
   serializat

[clang] [Driver][ARM] Fix hardcoding of NEON FPU for armv8 (PR #122969)

2025-01-15 Thread David Spickett via cfe-commits

DavidSpickett wrote:

Yeah, my first impression from the commit message was that you removed the 
check entirely.

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


[clang] [AST] Migrate away from PointerUnion::dyn_cast (NFC) (PR #123012)

2025-01-15 Thread Nikita Popov via cfe-commits

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


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


[clang] [Sema] Migrate away from PointerUnion::dyn_cast (NFC) (PR #123014)

2025-01-15 Thread Nikita Popov via cfe-commits

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


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


[clang-tools-extra] [clang-tidy][clangd] Fixed removeFunctionArgs don't remove comma for use-ranges check (PR #118568)

2025-01-15 Thread Richard Li via cfe-commits

https://github.com/chomosuke updated 
https://github.com/llvm/llvm-project/pull/118568

>From b43a2602025bdacea06ced5171904fb5d765de9f Mon Sep 17 00:00:00 2001
From: chomosuke 
Date: Tue, 3 Dec 2024 07:10:33 +
Subject: [PATCH 1/4] fixed removeFunctionArgs don't remove comma

---
 .../clang-tidy/utils/UseRangesCheck.cpp   | 19 ++-
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp 
b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
index aba4d17ccd035e..88cba70b931d5d 100644
--- a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
@@ -28,6 +28,7 @@
 #include "llvm/ADT/Twine.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
+#include 
 #include 
 #include 
 
@@ -173,21 +174,21 @@ static void removeFunctionArgs(DiagnosticBuilder &Diag, 
const CallExpr &Call,
   for (unsigned Index : Sorted) {
 const Expr *Arg = Call.getArg(Index);
 if (Commas[Index]) {
-  if (Index >= Commas.size()) {
-Diag << FixItHint::CreateRemoval(Arg->getSourceRange());
-  } else {
+  if (Index + 1 < Call.getNumArgs()) {
 // Remove the next comma
 Commas[Index + 1] = true;
+const Expr *NextArg = Call.getArg(Index + 1);
 Diag << FixItHint::CreateRemoval(CharSourceRange::getTokenRange(
-{Arg->getBeginLoc(),
- Lexer::getLocForEndOfToken(
- Arg->getEndLoc(), 0, Ctx.getSourceManager(), 
Ctx.getLangOpts())
- .getLocWithOffset(1)}));
+{Arg->getBeginLoc(), 
NextArg->getBeginLoc().getLocWithOffset(-1)}));
+  } else {
+Diag << FixItHint::CreateRemoval(Arg->getSourceRange());
   }
 } else {
-  Diag << FixItHint::CreateRemoval(CharSourceRange::getTokenRange(
-  Arg->getBeginLoc().getLocWithOffset(-1), Arg->getEndLoc()));
+  // At this point we know Index > 0 because `Commas[0] = true` earlier
   Commas[Index] = true;
+  const Expr *PrevArg = Call.getArg(Index - 1);
+  Diag << FixItHint::CreateRemoval(CharSourceRange::getTokenRange(
+  PrevArg->getEndLoc().getLocWithOffset(1), Arg->getEndLoc()));
 }
   }
 }

>From 644c8491e0fba203e89595827781d0c2c0609081 Mon Sep 17 00:00:00 2001
From: chomosuke 
Date: Mon, 23 Dec 2024 05:17:08 +1100
Subject: [PATCH 2/4] find , and remove only ,

---
 .../clang-tidy/utils/UseRangesCheck.cpp   | 49 +++
 1 file changed, 40 insertions(+), 9 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp 
b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
index 88cba70b931d5d..8b8e44a9898fdd 100644
--- a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
@@ -28,7 +28,6 @@
 #include "llvm/ADT/Twine.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
-#include 
 #include 
 #include 
 
@@ -165,6 +164,33 @@ void UseRangesCheck::registerMatchers(MatchFinder *Finder) 
{
 static void removeFunctionArgs(DiagnosticBuilder &Diag, const CallExpr &Call,
ArrayRef Indexes,
const ASTContext &Ctx) {
+  auto GetCommaLoc =
+  [&](SourceLocation BeginLoc,
+  SourceLocation EndLoc) -> std::optional {
+auto Invalid = false;
+auto SourceText = Lexer::getSourceText(
+CharSourceRange::getCharRange({BeginLoc, EndLoc}),
+Ctx.getSourceManager(), Ctx.getLangOpts(), &Invalid);
+assert(!Invalid);
+
+size_t I = 0;
+while (I < SourceText.size() && SourceText[I] != ',') {
+  I++;
+}
+
+if (I < SourceText.size()) {
+  // also remove space after ,
+  size_t J = I + 1;
+  while (J < SourceText.size() && SourceText[J] == ' ') {
+J++;
+  }
+
+  return std::make_optional(CharSourceRange::getCharRange(
+  {BeginLoc.getLocWithOffset(I), BeginLoc.getLocWithOffset(J)}));
+}
+return std::nullopt;
+  };
+
   llvm::SmallVector Sorted(Indexes);
   llvm::sort(Sorted);
   // Keep track of commas removed
@@ -176,20 +202,25 @@ static void removeFunctionArgs(DiagnosticBuilder &Diag, 
const CallExpr &Call,
 if (Commas[Index]) {
   if (Index + 1 < Call.getNumArgs()) {
 // Remove the next comma
-Commas[Index + 1] = true;
 const Expr *NextArg = Call.getArg(Index + 1);
-Diag << FixItHint::CreateRemoval(CharSourceRange::getTokenRange(
-{Arg->getBeginLoc(), 
NextArg->getBeginLoc().getLocWithOffset(-1)}));
-  } else {
-Diag << FixItHint::CreateRemoval(Arg->getSourceRange());
+auto CommaLoc = GetCommaLoc(Arg->getEndLoc().getLocWithOffset(1),
+NextArg->getBeginLoc());
+if (CommaLoc) {
+  Commas[Index + 1] = true;
+  Diag << FixItHint::CreateRemoval(*CommaLoc);
+}
   }
 } else {
   // At this point we know Index > 0 becau

[clang] [clang] Fix a use-after-free in expression evaluation (PR #118480)

2025-01-15 Thread kadir çetinkaya via cfe-commits

kadircet wrote:

sample in 
https://github.com/llvm/llvm-project/pull/118480#issuecomment-2538988006 still 
triggers the crash for me, need to pass `-std=c++20`.
but note that it isn't the sample that should be built with ASAN, it's the 
clang itself that needs to be built with ASAN. passing 
`-DLLVM_USE_SANITIZER=Address` in your cmake configuration should be enough for 
that.

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


[clang] 4cec0ba - [clang][bytecode][NFC] Simplify VisitCXXDefaultArgExpr (#123024)

2025-01-15 Thread via cfe-commits

Author: Timm Baeder
Date: 2025-01-15T10:09:10+01:00
New Revision: 4cec0ba92955c353c52efe728b2cfef3fbdf60f8

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

LOG: [clang][bytecode][NFC] Simplify VisitCXXDefaultArgExpr (#123024)

We have `discard()` these days.

Added: 


Modified: 
clang/lib/AST/ByteCode/Compiler.cpp

Removed: 




diff  --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index c6e2a1e50a2aa7..4bfb80589620c1 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -4815,12 +4815,7 @@ template 
 bool Compiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E) {
   SourceLocScope SLS(this, E);
 
-  const Expr *SubExpr = E->getExpr();
-  if (std::optional T = classify(E->getExpr()))
-return this->visit(SubExpr);
-
-  assert(Initializing);
-  return this->visitInitializer(SubExpr);
+  return this->delegate(E->getExpr());
 }
 
 template 



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


[clang] [clang][bytecode][NFC] Simplify VisitCXXDefaultArgExpr (PR #123024)

2025-01-15 Thread Timm Baeder via cfe-commits

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


[clang] 85fdf50 - [Multilib] Custom flags YAML parsing (#122903)

2025-01-15 Thread via cfe-commits

Author: Victor Campos
Date: 2025-01-15T10:11:39Z
New Revision: 85fdf501461e8ee00401f06ee6c7d21ac6622484

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

LOG: [Multilib] Custom flags YAML parsing (#122903)

This patch is the first step to extend the current multilib system to
support the selection of library variants which do not correspond to
existing command-line options.

Proposal can be found in
https://discourse.llvm.org/t/rfc-multilib-custom-flags/81058

The multilib mechanism supports libraries that target code generation or
language options such as `--target`, `-mcpu`, `-mfpu`,
`-mbranch-protection`. However, some library variants are particular to
features that do not correspond to any command-line options. Examples
include variants for multithreading and semihosting.

This work introduces a way to instruct the multilib system to consider
these features in library selection. This particular patch comprises a
new section in `multilib.yaml` to declare flags for which no option
exists. Henceforth this sort of flag will be called `custom flag` for
clarity.

The `multilib.yaml` file will have a new section called Flags which
contains the declarations of the target’s custom flags:

```yaml
Flags:
- Name: multithreaded
  Values:
  - Name: no-multithreaded
MacroDefines: [__SINGLE_THREAD__]
  - Name: multithreaded
  Default: no-multithreaded

- Name: io
  Values:
- Name: io-none
- Name: io-semihosting
  MacroDefines: [SEMIHOSTING]
- Name: io-linux-syscalls
  MacroDefines: [LINUX_SYSCALLS, HOSTED=1]
   Default: io-none
```
- Name: the name to categorize a flag.
- Values: a list of possible values.
- Default: it specifies which value this flag should take if not
specified in the command-line invocation. It must be one value from the
Values field.

Each flag Value follows this description:
- Name (required): the name of the custom flag value (string). This is
the string to be used in `-fmultilib-flag=`.
- MacroDefines (optional): a list of strings to be used as macro
definitions. Each string
  is fed into the driver as ``-D``.

A Default value is useful to save users from specifying custom flags
that have a most commonly used value.

The namespace of flag values is common across all flags. This means that
flag values must be unique.

Added: 
clang/test/Driver/baremetal-multilib-custom-flags-parsing.yaml

Modified: 
clang/include/clang/Driver/Multilib.h
clang/lib/Driver/Multilib.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Multilib.h 
b/clang/include/clang/Driver/Multilib.h
index dbed70f4f9008f..0a533ed2804e25 100644
--- a/clang/include/clang/Driver/Multilib.h
+++ b/clang/include/clang/Driver/Multilib.h
@@ -101,6 +101,30 @@ class Multilib {
 
 raw_ostream &operator<<(raw_ostream &OS, const Multilib &M);
 
+namespace custom_flag {
+struct Declaration;
+
+struct ValueDetail {
+  std::string Name;
+  std::optional> MacroDefines;
+  Declaration *Decl;
+};
+
+struct Declaration {
+  std::string Name;
+  SmallVector ValueList;
+  std::optional DefaultValueIdx;
+
+  Declaration() = default;
+  Declaration(const Declaration &);
+  Declaration(Declaration &&);
+  Declaration &operator=(const Declaration &);
+  Declaration &operator=(Declaration &&);
+};
+
+static constexpr StringRef Prefix = "-fmultilib-flag=";
+} // namespace custom_flag
+
 /// See also MultilibSetBuilder for combining multilibs into a set.
 class MultilibSet {
 public:
@@ -120,15 +144,18 @@ class MultilibSet {
 
 private:
   multilib_list Multilibs;
-  std::vector FlagMatchers;
+  SmallVector FlagMatchers;
+  SmallVector CustomFlagDecls;
   IncludeDirsFunc IncludeCallback;
   IncludeDirsFunc FilePathsCallback;
 
 public:
   MultilibSet() = default;
   MultilibSet(multilib_list &&Multilibs,
-  std::vector &&FlagMatchers = {})
-  : Multilibs(Multilibs), FlagMatchers(FlagMatchers) {}
+  SmallVector &&FlagMatchers = {},
+  SmallVector &&CustomFlagDecls = {})
+  : Multilibs(std::move(Multilibs)), FlagMatchers(std::move(FlagMatchers)),
+CustomFlagDecls(std::move(CustomFlagDecls)) {}
 
   const multilib_list &getMultilibs() { return Multilibs; }
 

diff  --git a/clang/lib/Driver/Multilib.cpp b/clang/lib/Driver/Multilib.cpp
index 0207e0f2eb2ded..ccf747e90cb2ca 100644
--- a/clang/lib/Driver/Multilib.cpp
+++ b/clang/lib/Driver/Multilib.cpp
@@ -10,6 +10,7 @@
 #include "clang/Basic/LLVM.h"
 #include "clang/Driver/Driver.h"
 #include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -201,13 +202,20 @@ struct MultilibGroupSerialization {
 
 struct MultilibSetSerialization {
   llvm::VersionTuple MultilibVersion;
-  std::vector 

[clang] [Multilib] Custom flags processing for library selection (PR #110659)

2025-01-15 Thread Victor Campos via cfe-commits

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


[clang] [Multilib] Custom flags YAML parsing (PR #122903)

2025-01-15 Thread Victor Campos via cfe-commits

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


[clang-tools-extra] 6affc18 - [clang-reorder-fields] Move trailing comments. (#122918)

2025-01-15 Thread via cfe-commits

Author: Clement Courbet
Date: 2025-01-15T13:07:42+01:00
New Revision: 6affc1837537a802531a5394535f1f0b7ca865cb

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

LOG: [clang-reorder-fields] Move trailing comments. (#122918)

Currently, trailing comments get mixed up:

```
struct Foo {
  int a; // This one is the cool field
 // within the struct.
  int b;
};
```

becomes:

```
struct Foo {
  int b; // This one is the cool field
 // within the struct.
  int a;
};
```

This should be:

```
struct Foo {
  int b;
  int a; // This one is the cool field
 // within the struct.
};
```

Added: 
clang-tools-extra/test/clang-reorder-fields/Comments.cpp

Modified: 
clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp 
b/clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp
index dc3a3b6211b7e4..80ee31368fe9a5 100644
--- a/clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp
+++ b/clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp
@@ -63,7 +63,9 @@ getNewFieldsOrder(const RecordDecl *Definition,
 NameToIndex[Field->getName()] = Field->getFieldIndex();
 
   if (DesiredFieldsOrder.size() != NameToIndex.size()) {
-llvm::errs() << "Number of provided fields doesn't match definition.\n";
+llvm::errs() << "Number of provided fields (" << DesiredFieldsOrder.size()
+ << ") doesn't match definition (" << NameToIndex.size()
+ << ").\n";
 return {};
   }
   SmallVector NewFieldsOrder;
@@ -116,26 +118,77 @@ findMembersUsedInInitExpr(const CXXCtorInitializer 
*Initializer,
   return Results;
 }
 
-/// Returns the full source range for the field declaration up to (not
-/// including) the trailing semicolumn, including potential macro invocations,
-/// e.g. `int a GUARDED_BY(mu);`.
+/// Returns the next token after `Loc` (including comment tokens).
+static std::optional getTokenAfter(SourceLocation Loc,
+  const SourceManager &SM,
+  const LangOptions &LangOpts) {
+  if (Loc.isMacroID()) {
+return std::nullopt;
+  }
+  Loc = Lexer::getLocForEndOfToken(Loc, 0, SM, LangOpts);
+
+  // Break down the source location.
+  std::pair LocInfo = SM.getDecomposedLoc(Loc);
+
+  // Try to load the file buffer.
+  bool InvalidTemp = false;
+  StringRef File = SM.getBufferData(LocInfo.first, &InvalidTemp);
+  if (InvalidTemp)
+return std::nullopt;
+
+  const char *TokenBegin = File.data() + LocInfo.second;
+
+  Lexer lexer(SM.getLocForStartOfFile(LocInfo.first), LangOpts, File.begin(),
+  TokenBegin, File.end());
+  lexer.SetCommentRetentionState(true);
+  // Find the token.
+  Token Tok;
+  lexer.LexFromRawLexer(Tok);
+  return Tok;
+}
+
+/// Returns the end of the trailing comments after `Loc`.
+static SourceLocation getEndOfTrailingComment(SourceLocation Loc,
+  const SourceManager &SM,
+  const LangOptions &LangOpts) {
+  // We consider any following comment token that is indented more than the
+  // first comment to be part of the trailing comment.
+  const unsigned Column = SM.getPresumedColumnNumber(Loc);
+  std::optional Tok = getTokenAfter(Loc, SM, LangOpts);
+  while (Tok && Tok->is(tok::comment) &&
+ SM.getPresumedColumnNumber(Tok->getLocation()) > Column) {
+Loc = Tok->getEndLoc();
+Tok = getTokenAfter(Loc, SM, LangOpts);
+  }
+  return Loc;
+}
+
+/// Returns the full source range for the field declaration up to (including)
+/// the trailing semicolumn, including potential macro invocations,
+/// e.g. `int a GUARDED_BY(mu);`. If there is a trailing comment, include it.
 static SourceRange getFullFieldSourceRange(const FieldDecl &Field,
const ASTContext &Context) {
-  SourceRange Range = Field.getSourceRange();
+  const SourceRange Range = Field.getSourceRange();
+  SourceLocation Begin = Range.getBegin();
   SourceLocation End = Range.getEnd();
   const SourceManager &SM = Context.getSourceManager();
   const LangOptions &LangOpts = Context.getLangOpts();
   while (true) {
 std::optional CurrentToken = Lexer::findNextToken(End, SM, 
LangOpts);
 
-if (!CurrentToken || CurrentToken->is(tok::semi))
-  break;
+if (!CurrentToken)
+  return SourceRange(Begin, End);
 
 if (CurrentToken->is(tok::eof))
   return Range; // Something is wrong, return the original range.
+
 End = CurrentToken->getLastLoc();
+
+if (CurrentToken->is(tok::semi))
+  break;
   }
-  return SourceRange(Range.getBegin(), End);
+  End = getEndOfTrailingComment(End

[clang-tools-extra] [clang-reorder-fields] Move trailing comments. (PR #122918)

2025-01-15 Thread Clement Courbet via cfe-commits

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


[clang] [llvm] Add the initializes attribute inference (PR #117104)

2025-01-15 Thread Florian Hahn via cfe-commits

fhahn wrote:

Looks like this is causing a crash when building with sanitizers enabled on 
macOS

Reduced reproducer: https://llvm.godbolt.org/z/fn83n4oz4

End-to-end crash on GreenDragon: 
https://green.lab.llvm.org/job/llvm.org/job/clang-stage2-cmake-RgSan/664/console

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


[clang] [clang] Add support for passing FileSystem to buildASTFromCodeWithArgs() (PR #123042)

2025-01-15 Thread Boaz Brickner via cfe-commits

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


[clang] [SPIR-V] Add hlsl_private address space for HLSL/SPIR-V (PR #122103)

2025-01-15 Thread Nathan Gauër via cfe-commits


@@ -5362,6 +5362,23 @@ LangAS CodeGenModule::GetGlobalVarAddressSpace(const 
VarDecl *D) {
 if (OpenMPRuntime->hasAllocateAttributeForGlobalVar(D, AS))
   return AS;
   }
+
+  if (LangOpts.HLSL) {
+if (D == nullptr)
+  return LangAS::hlsl_private;
+
+// Except resources (Uniform, UniformConstant) & instanglble (handles)
+if (D->getType()->isHLSLResourceType() ||
+D->getType()->isHLSLIntangibleType())
+  return D->getType().getAddressSpace();
+
+if (D->getStorageClass() != SC_Static)
+  return D->getType().getAddressSpace();
+
+LangAS AS = D->getType().getAddressSpace();
+return AS == LangAS::Default ? LangAS::hlsl_private : AS;
+  }
+

Keenuts wrote:

I recall having tried this method first, but for some reasons moved it to 
Codegen, but I don't recall the full context.

I just tried moving it in sema again, and seems there is a slight issue with 
`this-reference-template.hlsl` since the VarDecl type is from a template, 
something goes wrong (but works if the AS fixup is done in codegen).

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


[clang] [clang] Add support for passing FileSystem to buildASTFromCodeWithArgs() (PR #123042)

2025-01-15 Thread Boaz Brickner via cfe-commits


@@ -692,11 +692,12 @@ std::unique_ptr buildASTFromCodeWithArgs(
 StringRef Code, const std::vector &Args, StringRef FileName,
 StringRef ToolName, std::shared_ptr 
PCHContainerOps,
 ArgumentsAdjuster Adjuster, const FileContentMappings &VirtualMappedFiles,
-DiagnosticConsumer *DiagConsumer) {
+DiagnosticConsumer *DiagConsumer,
+IntrusiveRefCntPtr FileSystem) {
   std::vector> ASTs;
   ASTBuilderAction Action(ASTs);
   llvm::IntrusiveRefCntPtr OverlayFileSystem(
-  new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem()));
+  new llvm::vfs::OverlayFileSystem(FileSystem));

bricknerb wrote:

Done.

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


[clang] [flang] [Flang][Driver] Deprecate Ofast (PR #101701)

2025-01-15 Thread Kiran Chandramohan via cfe-commits

https://github.com/kiranchandramohan updated 
https://github.com/llvm/llvm-project/pull/101701

>From b33ae618fafdad93660eb31368a462e728a2cff9 Mon Sep 17 00:00:00 2001
From: Kiran Chandramohan 
Date: Fri, 19 Jul 2024 12:46:08 +
Subject: [PATCH 1/2] [Flang][Driver] Deprecate Ofast

---
 clang/include/clang/Basic/DiagnosticDriverKinds.td | 4 
 clang/include/clang/Driver/Options.td  | 7 +--
 clang/lib/Driver/ToolChains/Flang.cpp  | 1 +
 flang/test/Driver/fast-math.f90| 5 +
 4 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 42c39ac6606c7f..7408d58cdb7722 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -452,6 +452,10 @@ def warn_drv_deprecated_arg_ofast : Warning<
   "argument '-Ofast' is deprecated; use '-O3 -ffast-math' for the same 
behavior,"
   " or '-O3' to enable only conforming optimizations">,
   InGroup;
+def warn_drv_deprecated_arg_ofast_for_flang : Warning<
+  "argument '-Ofast' is deprecated; use '-O3 -ffast-math -fstack-arrays' for 
the same behavior,"
+  " or '-O3 -fstack-arrays' to enable only conforming optimizations">,
+  InGroup;
 def warn_drv_deprecated_custom : Warning<
   "argument '%0' is deprecated, %1">, InGroup;
 def warn_drv_assuming_mfloat_abi_is : Warning<
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2721c1b5d8dc55..2106581a86c1ee 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -933,10 +933,13 @@ def O : Joined<["-"], "O">, Group,
 def O_flag : Flag<["-"], "O">, Visibility<[ClangOption, CC1Option, FC1Option]>,
   Alias, AliasArgs<["1"]>;
 def Ofast : Joined<["-"], "Ofast">, Group,
-  Visibility<[ClangOption, CC1Option, FlangOption]>,
+  Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
   HelpTextForVariants<[ClangOption, CC1Option],
   "Deprecated; use '-O3 -ffast-math' for the same 
behavior,"
-  " or '-O3' to enable only conforming optimizations">;
+  " or '-O3' to enable only conforming optimizations">,
+  HelpTextForVariants<[FlangOption, FC1Option],
+"Deprecated; use '-O3 -ffast-math -fstack-arrays' for the same behavior,"
+" or '-O3 -fstack-arrays' to enable only conforming optimizations">;
 def P : Flag<["-"], "P">,
   Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
   Group,
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index a7d0cc99f27d2d..7e59080b680ec1 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -934,6 +934,7 @@ void Flang::ConstructJob(Compilation &C, const JobAction 
&JA,
   D.Diag(diag::warn_O4_is_O3);
 } else if (A->getOption().matches(options::OPT_Ofast)) {
   CmdArgs.push_back("-O3");
+  D.Diag(diag::warn_drv_deprecated_arg_ofast_for_flang);
 } else {
   A->render(Args, CmdArgs);
 }
diff --git a/flang/test/Driver/fast-math.f90 b/flang/test/Driver/fast-math.f90
index 47175488b98bcc..e677432bc04fae 100644
--- a/flang/test/Driver/fast-math.f90
+++ b/flang/test/Driver/fast-math.f90
@@ -1,6 +1,11 @@
 ! Test for correct forwarding of fast-math flags from the compiler driver to 
the
 ! frontend driver
 
+! Check warning message for Ofast deprecation
+! RUN: %flang -Ofast -### %s -o %t 2>&1 | FileCheck %s
+! CHECK: warning: argument '-Ofast' is deprecated; use '-O3 -ffast-math 
-fstack-arrays' for the same behavior, or '-O3
+! -fstack-arrays' to enable only conforming optimizations [-Wdeprecated-ofast]
+
 ! -Ofast => -ffast-math -O3 -fstack-arrays
 ! RUN: %flang -Ofast -fsyntax-only -### %s -o %t 2>&1 \
 ! RUN: | FileCheck --check-prefix=CHECK-OFAST %s

>From 88f77927b2c16036b66225bed3cb436a9bccc8d6 Mon Sep 17 00:00:00 2001
From: Kiran Chandramohan 
Date: Wed, 15 Jan 2025 12:48:25 +
Subject: [PATCH 2/2] Changes for rebase

---
 clang/include/clang/Driver/Options.td | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2106581a86c1ee..aea32bfc9df63a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -934,12 +934,11 @@ def O_flag : Flag<["-"], "O">, Visibility<[ClangOption, 
CC1Option, FC1Option]>,
   Alias, AliasArgs<["1"]>;
 def Ofast : Joined<["-"], "Ofast">, Group,
   Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
-  HelpTextForVariants<[ClangOption, CC1Option],
-  "Deprecated; use '-O3 -ffast-math' for the same 
behavior,"
-  " or '-O3' to enable only conforming optimizations">,
   HelpTextForVariants<[FlangOption, FC1Option],
 "Deprecated; use '-O3 -ffast-math -fstack-arrays' 

[clang] [clang] Add support for passing FileSystem to buildASTFromCodeWithArgs() (PR #123042)

2025-01-15 Thread kadir çetinkaya via cfe-commits


@@ -223,7 +223,11 @@ buildASTFromCode(StringRef Code, StringRef FileName = 
"input.cc",
 /// \param PCHContainerOps The PCHContainerOperations for loading and creating
 /// clang modules.
 ///
-/// \param Adjuster A function to filter the command line arguments as 
specified.
+/// \param Adjuster A function to filter the command line arguments as
+/// specified.
+///
+/// \param FileSystem FileSystem for managing and looking up files.

kadircet wrote:

can we refer to this as `BaseFS` instead and mention that `VirtualMappedFiles` 
will take precedence over contents in `BaseFS`?

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


[clang] [clang] Add support for passing FileSystem to buildASTFromCodeWithArgs() (PR #123042)

2025-01-15 Thread kadir çetinkaya via cfe-commits

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


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


[clang] [flang] [Flang][Driver] Add a flag to control zero initialization of global v… (PR #122144)

2025-01-15 Thread Kiran Chandramohan via cfe-commits

https://github.com/kiranchandramohan updated 
https://github.com/llvm/llvm-project/pull/122144

>From 483501549b910d1e91dab05cce65793c44aaa6f6 Mon Sep 17 00:00:00 2001
From: Kiran Chandramohan 
Date: Wed, 8 Jan 2025 17:26:24 +
Subject: [PATCH 1/7] [Flang][Driver] Add a flag to control zero initialization
 of global variables

Patch adds a flag to control zero initialization of global variables
without default initialization. The default is to zero initialize.
---
 clang/include/clang/Driver/Options.td |  3 +++
 clang/lib/Driver/ToolChains/Flang.cpp |  1 +
 flang/include/flang/Lower/LoweringOptions.def |  3 +++
 flang/lib/Frontend/CompilerInvocation.cpp |  6 ++
 flang/lib/Lower/ConvertVariable.cpp   |  6 +-
 flang/test/Driver/fno-zero-init.f90   |  5 +
 flang/test/Lower/zero_init.f90| 16 
 flang/test/Lower/zero_init_default_init.f90   | 18 ++
 8 files changed, 57 insertions(+), 1 deletion(-)
 create mode 100644 flang/test/Driver/fno-zero-init.f90
 create mode 100644 flang/test/Lower/zero_init.f90
 create mode 100644 flang/test/Lower/zero_init_default_init.f90

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 52823430919de4..e8d18cf78e985a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3494,6 +3494,9 @@ def fno_struct_path_tbaa : Flag<["-"], 
"fno-struct-path-tbaa">, Group;
 def fno_strict_enums : Flag<["-"], "fno-strict-enums">, Group;
 def fno_strict_overflow : Flag<["-"], "fno-strict-overflow">, Group,
   Visibility<[ClangOption, FlangOption]>;
+def fno_zero_init_global_without_init : Flag<["-"], 
"fno-zero-init-global-without-init">, Group,
+  Visibility<[FlangOption, FC1Option]>,
+  HelpText<"Do not zero initialize globals without default initialization">;
 def fno_pointer_tbaa : Flag<["-"], "fno-pointer-tbaa">, Group;
 def fno_temp_file : Flag<["-"], "fno-temp-file">, Group,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>, HelpText<
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 75b10e88371ae7..609f5315426977 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -153,6 +153,7 @@ void Flang::addCodegenOptions(const ArgList &Args,
   Args.addAllArgs(CmdArgs, {options::OPT_flang_experimental_hlfir,
 options::OPT_flang_deprecated_no_hlfir,
 options::OPT_fno_ppc_native_vec_elem_order,
+options::OPT_fno_zero_init_global_without_init,
 options::OPT_fppc_native_vec_elem_order});
 }
 
diff --git a/flang/include/flang/Lower/LoweringOptions.def 
b/flang/include/flang/Lower/LoweringOptions.def
index 5a6debfdffe030..acce21f5faab8b 100644
--- a/flang/include/flang/Lower/LoweringOptions.def
+++ b/flang/include/flang/Lower/LoweringOptions.def
@@ -44,5 +44,8 @@ ENUM_LOWERINGOPT(IntegerWrapAround, unsigned, 1, 0)
 /// If false, assume that the shapes/types/allocation-status match.
 ENUM_LOWERINGOPT(ReallocateLHS, unsigned, 1, 1)
 
+/// If true, initialize globals without initialization to zero.
+/// On by default.
+ENUM_LOWERINGOPT(ZeroInitGlobalsWithoutInit, unsigned, 1, 1)
 #undef LOWERINGOPT
 #undef ENUM_LOWERINGOPT
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index 340efb1c63a5e5..fa91a0e2642bc8 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -1373,6 +1373,12 @@ bool CompilerInvocation::createFromArgs(
 invoc.loweringOpts.setNoPPCNativeVecElemOrder(true);
   }
 
+  // -fno-zero-init-global-without-init
+  if (args.hasArg(
+  clang::driver::options::OPT_fno_zero_init_global_without_init)) {
+invoc.loweringOpts.setZeroInitGlobalsWithoutInit(false);
+  }
+
   // Preserve all the remark options requested, i.e. -Rpass, -Rpass-missed or
   // -Rpass-analysis. This will be used later when processing and outputting 
the
   // remarks generated by LLVM in ExecuteCompilerInvocation.cpp.
diff --git a/flang/lib/Lower/ConvertVariable.cpp 
b/flang/lib/Lower/ConvertVariable.cpp
index 9ee42d5cd88002..db8a57d416274c 100644
--- a/flang/lib/Lower/ConvertVariable.cpp
+++ b/flang/lib/Lower/ConvertVariable.cpp
@@ -635,7 +635,11 @@ static fir::GlobalOp 
defineGlobal(Fortran::lower::AbstractConverter &converter,
   global.setLinkName(builder.createCommonLinkage());
 Fortran::lower::createGlobalInitialization(
 builder, global, [&](fir::FirOpBuilder &builder) {
-  mlir::Value initValue = builder.create(loc, symTy);
+  mlir::Value initValue;
+  if (converter.getLoweringOptions().getZeroInitGlobalsWithoutInit())
+initValue = builder.create(loc, symTy);
+  else
+initValue = builder.create(loc, symTy);
   builder.create(loc, 

[clang] [Multilib] Custom flags processing for library selection (PR #110659)

2025-01-15 Thread Victor Campos via cfe-commits

https://github.com/vhscampos updated 
https://github.com/llvm/llvm-project/pull/110659

>From 16aa4a010c22288ba363e4ab680a38fe0b6a327d Mon Sep 17 00:00:00 2001
From: Victor Campos 
Date: Mon, 13 Jan 2025 13:51:52 +
Subject: [PATCH 1/8] [Multilib] Custom flags YAML parsing
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This patch is the first step to extend the current multilib system to
support the selection of library variants which do not correspond to
existing command-line options.

Proposal can be found in
https://discourse.llvm.org/t/rfc-multilib-custom-flags/81058

The multilib mechanism supports libraries that target code generation or
language options such as `--target`, `-mcpu`, `-mfpu`,
`-mbranch-protection`. However, some library variants are particular to
features that do not correspond to any command-line options. Examples
include variants for multithreading and semihosting.

This work introduces a way to instruct the multilib system to consider
these features in library selection. This particular patch comprises a
new section in `multilib.yaml` to declare flags for which no option
exists. Henceforth this sort of flag will be called `custom flag` for
clarity.

The `multilib.yaml` file will have a new section called Flags which
contains the declarations of the target’s custom flags:

```yaml
Flags:
- Name: multithreaded
  Values:
  - Name: no-multithreaded
MacroDefines: [__SINGLE_THREAD__]
  - Name: multithreaded
  Default: no-multithreaded

- Name: io
  Values:
- Name: io-none
- Name: io-semihosting
  MacroDefines: [SEMIHOSTING]
- Name: io-linux-syscalls
  MacroDefines: [LINUX_SYSCALLS, HOSTED=1]
   Default: io-none
```
- Name: the name to categorize a flag.
- Values: a list of possible values.
- Default: it specifies which value this flag should take if not
specified in the command-line invocation. It must be one value from the
Values field.

Each flag Value follows this description:
- Name (required): the name of the custom flag value (string). This is
the string to be used in `-fmultilib-flag=`.
- MacroDefines (optional): a list of strings to be used as macro
definitions. Each string
  is fed into the driver as ``-D``.

A Default value is useful to save users from specifying custom flags
that have a most commonly used value.

The namespace of flag values is common across all flags. This means that
flag values must be unique.
---
 clang/include/clang/Driver/Multilib.h |  33 -
 clang/lib/Driver/Multilib.cpp | 109 --
 ...remetal-multilib-custom-flags-parsing.yaml | 133 ++
 3 files changed, 264 insertions(+), 11 deletions(-)
 create mode 100644 
clang/test/Driver/baremetal-multilib-custom-flags-parsing.yaml

diff --git a/clang/include/clang/Driver/Multilib.h 
b/clang/include/clang/Driver/Multilib.h
index dbed70f4f9008f..0a533ed2804e25 100644
--- a/clang/include/clang/Driver/Multilib.h
+++ b/clang/include/clang/Driver/Multilib.h
@@ -101,6 +101,30 @@ class Multilib {
 
 raw_ostream &operator<<(raw_ostream &OS, const Multilib &M);
 
+namespace custom_flag {
+struct Declaration;
+
+struct ValueDetail {
+  std::string Name;
+  std::optional> MacroDefines;
+  Declaration *Decl;
+};
+
+struct Declaration {
+  std::string Name;
+  SmallVector ValueList;
+  std::optional DefaultValueIdx;
+
+  Declaration() = default;
+  Declaration(const Declaration &);
+  Declaration(Declaration &&);
+  Declaration &operator=(const Declaration &);
+  Declaration &operator=(Declaration &&);
+};
+
+static constexpr StringRef Prefix = "-fmultilib-flag=";
+} // namespace custom_flag
+
 /// See also MultilibSetBuilder for combining multilibs into a set.
 class MultilibSet {
 public:
@@ -120,15 +144,18 @@ class MultilibSet {
 
 private:
   multilib_list Multilibs;
-  std::vector FlagMatchers;
+  SmallVector FlagMatchers;
+  SmallVector CustomFlagDecls;
   IncludeDirsFunc IncludeCallback;
   IncludeDirsFunc FilePathsCallback;
 
 public:
   MultilibSet() = default;
   MultilibSet(multilib_list &&Multilibs,
-  std::vector &&FlagMatchers = {})
-  : Multilibs(Multilibs), FlagMatchers(FlagMatchers) {}
+  SmallVector &&FlagMatchers = {},
+  SmallVector &&CustomFlagDecls = {})
+  : Multilibs(std::move(Multilibs)), FlagMatchers(std::move(FlagMatchers)),
+CustomFlagDecls(std::move(CustomFlagDecls)) {}
 
   const multilib_list &getMultilibs() { return Multilibs; }
 
diff --git a/clang/lib/Driver/Multilib.cpp b/clang/lib/Driver/Multilib.cpp
index 0207e0f2eb2ded..ccf747e90cb2ca 100644
--- a/clang/lib/Driver/Multilib.cpp
+++ b/clang/lib/Driver/Multilib.cpp
@@ -10,6 +10,7 @@
 #include "clang/Basic/LLVM.h"
 #include "clang/Driver/Driver.h"
 #include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -201,13 +202,20 @@ struct MultilibGroupSerializati

[clang] [clang] Add support for passing FileSystem to buildASTFromCodeWithArgs() (PR #123042)

2025-01-15 Thread kadir çetinkaya via cfe-commits


@@ -692,11 +692,12 @@ std::unique_ptr buildASTFromCodeWithArgs(
 StringRef Code, const std::vector &Args, StringRef FileName,
 StringRef ToolName, std::shared_ptr 
PCHContainerOps,
 ArgumentsAdjuster Adjuster, const FileContentMappings &VirtualMappedFiles,
-DiagnosticConsumer *DiagConsumer) {
+DiagnosticConsumer *DiagConsumer,
+IntrusiveRefCntPtr FileSystem) {
   std::vector> ASTs;
   ASTBuilderAction Action(ASTs);
   llvm::IntrusiveRefCntPtr OverlayFileSystem(
-  new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem()));
+  new llvm::vfs::OverlayFileSystem(FileSystem));

kadircet wrote:

nit: `std::move(FileSystem)`

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


[clang] fix armv6kz LDREX definition (PR #122965)

2025-01-15 Thread via cfe-commits

Un1q32 wrote:

Yeah I don't have access, please merge

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


[clang] [flang] [Flang][Driver] Deprecate Ofast (PR #101701)

2025-01-15 Thread Kiran Chandramohan via cfe-commits

kiranchandramohan wrote:

I did not see any opposition in 
https://discourse.llvm.org/t/rfc-deprecate-ofast-in-flang/80243. So would like 
to land this before llvm 20.

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


[clang] e00d1dd - [ARM] Fix armv6kz LDREX definition (#122965)

2025-01-15 Thread via cfe-commits

Author: Un1q32
Date: 2025-01-15T13:31:54Z
New Revision: e00d1dd6eaf46cf17080cdf506348ab8f037f6f2

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

LOG: [ARM] Fix armv6kz LDREX definition (#122965)

Fixes #37901

This behavior is consistent with GCC

Added: 


Modified: 
clang/lib/Basic/Targets/ARM.cpp
clang/test/Preprocessor/arm-acle-6.4.c

Removed: 




diff  --git a/clang/lib/Basic/Targets/ARM.cpp b/clang/lib/Basic/Targets/ARM.cpp
index 61ee26d8863832..0fd5433a76402e 100644
--- a/clang/lib/Basic/Targets/ARM.cpp
+++ b/clang/lib/Basic/Targets/ARM.cpp
@@ -617,7 +617,8 @@ bool 
ARMTargetInfo::handleTargetFeatures(std::vector &Features,
   case 6:
 if (ArchProfile == llvm::ARM::ProfileKind::M)
   LDREX = 0;
-else if (ArchKind == llvm::ARM::ArchKind::ARMV6K)
+else if (ArchKind == llvm::ARM::ArchKind::ARMV6K ||
+ ArchKind == llvm::ARM::ArchKind::ARMV6KZ)
   LDREX = LDREX_D | LDREX_W | LDREX_H | LDREX_B;
 else
   LDREX = LDREX_W;

diff  --git a/clang/test/Preprocessor/arm-acle-6.4.c 
b/clang/test/Preprocessor/arm-acle-6.4.c
index fcabe028b9559c..2c8f4868263a61 100644
--- a/clang/test/Preprocessor/arm-acle-6.4.c
+++ b/clang/test/Preprocessor/arm-acle-6.4.c
@@ -93,6 +93,10 @@
  
 // CHECK-V6K: __ARM_FEATURE_LDREX 0xf
 
+// RUN: %clang -target arm-none-linux-eabi -march=armv6kz -x c -E -dM %s -o - 
| FileCheck %s -check-prefix CHECK-V6KZ
+ 
+// CHECK-V6KZ: __ARM_FEATURE_LDREX 0xf
+
 // RUN: %clang -target arm-none-linux-eabi -march=armv7-a -x c -E -dM %s -o - 
| FileCheck %s -check-prefix CHECK-V7A
 
 // CHECK-V7A: __ARM_ARCH 7



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


[clang] fix armv6kz LDREX definition (PR #122965)

2025-01-15 Thread David Green via cfe-commits

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


[clang] Patch series to reapply #118734 and substantially improve it (PR #120534)

2025-01-15 Thread Chandler Carruth via cfe-commits

chandlerc wrote:

@dyung -- this PR is updated with new fixes. NVPTX hopefully works and neither 
of my debugging checks fires. But there may still be some other failures I need 
to chase down, let me know?

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


[clang] [llvm] [AArch64] Improve bcvtn2 and remove aarch64_neon_bfcvt intrinsics (PR #120363)

2025-01-15 Thread David Green via cfe-commits

https://github.com/davemgreen updated 
https://github.com/llvm/llvm-project/pull/120363

>From ff5b62875738cc89266aeec6f0b06f4b55d30a3a Mon Sep 17 00:00:00 2001
From: David Green 
Date: Wed, 15 Jan 2025 08:21:31 +
Subject: [PATCH] [AArch64] Improve bcvtn2 and remove aarch64_neon_bfcvt
 intrinscs

This started out as trying to combine bf16 fpround to BFCVT2 instructions, but
ended up removing the aarch64.neon.nfcvt intrinsics in favour of generating
fpround instructions directly. This simplifies the patterns and can lead to
other optimizations. The BFCVT2 instruction is adjusted to makes sure the types
are more valid, and a bfcvt2 is now generated in more place. The old intrinsics
are auto-upgraded to fptrunc instructions too.
---
 clang/include/clang/Basic/arm_neon.td |  10 +-
 clang/lib/CodeGen/CGBuiltin.cpp   |  41 +-
 .../CodeGen/arm-bf16-convert-intrinsics.c |  23 ++-
 llvm/include/llvm/IR/IntrinsicsAArch64.td |  11 --
 llvm/lib/IR/AutoUpgrade.cpp   |  86 
 .../lib/Target/AArch64/AArch64InstrFormats.td |  11 +-
 llvm/lib/Target/AArch64/AArch64InstrInfo.td   |  24 ++--
 .../AArch64/bf16-convert-intrinsics.ll|   3 +
 .../CodeGen/AArch64/bf16-v4-instructions.ll   |  14 --
 .../CodeGen/AArch64/bf16-v8-instructions.ll   | 132 --
 10 files changed, 190 insertions(+), 165 deletions(-)

diff --git a/clang/include/clang/Basic/arm_neon.td 
b/clang/include/clang/Basic/arm_neon.td
index ef89fa4358dfeb..ddc5391eb3fa23 100644
--- a/clang/include/clang/Basic/arm_neon.td
+++ b/clang/include/clang/Basic/arm_neon.td
@@ -259,11 +259,6 @@ def OP_VCVT_F32_BF16_LO
 def OP_VCVT_F32_BF16_HI
 : Op<(call "vcvt_f32_bf16", (call "vget_high", $p0))>;
 
-def OP_VCVT_BF16_F32_LO_A64
-: Op<(call "__a64_vcvtq_low_bf16", $p0)>;
-def OP_VCVT_BF16_F32_A64
-: Op<(call "vget_low", (call "__a64_vcvtq_low_bf16", $p0))>;
-
 def OP_VCVT_BF16_F32_A32
 : Op<(call "__a32_vcvt_bf16", $p0)>;
 
@@ -2061,10 +2056,9 @@ let ArchGuard = "!defined(__aarch64__) && 
!defined(__arm64ec__)", TargetGuard =
 }
 
 let ArchGuard = "defined(__aarch64__) || defined(__arm64ec__)", TargetGuard = 
"bf16,neon" in {
-  def VCVT_LOW_BF16_F32_A64_INTERNAL : WInst<"__a64_vcvtq_low_bf16", "BQ", 
"Hf">;
-  def VCVT_LOW_BF16_F32_A64 : SOpInst<"vcvt_low_bf16", "BQ", "Qf", 
OP_VCVT_BF16_F32_LO_A64>;
+  def VCVT_LOW_BF16_F32_A64 : SInst<"vcvt_low_bf16", "BQ", "Qf">;
   def VCVT_HIGH_BF16_F32_A64 : SInst<"vcvt_high_bf16", "BBQ", "Qf">;
-  def VCVT_BF16_F32 : SOpInst<"vcvt_bf16","BQ", "f", OP_VCVT_BF16_F32_A64>;
+  def VCVT_BF16_F32 : SInst<"vcvt_bf16", "BQ", "f">;
 
   def COPY_LANE_BF16 : IOpInst<"vcopy_lane", "..I.I", "b", OP_COPY_LN>;
   def COPYQ_LANE_BF16 : IOpInst<"vcopy_lane", "..IqI", "Qb", OP_COPY_LN>;
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 1b25d365932c30..063cd0cc09fc63 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -7307,7 +7307,6 @@ static const ARMVectorIntrinsicInfo ARMSIMDIntrinsicMap 
[] = {
 };
 
 static const ARMVectorIntrinsicInfo AArch64SIMDIntrinsicMap[] = {
-  NEONMAP1(__a64_vcvtq_low_bf16_f32, aarch64_neon_bfcvtn, 0),
   NEONMAP0(splat_lane_v),
   NEONMAP0(splat_laneq_v),
   NEONMAP0(splatq_lane_v),
@@ -7407,7 +7406,8 @@ static const ARMVectorIntrinsicInfo 
AArch64SIMDIntrinsicMap[] = {
   NEONMAP0(vcvtq_f16_s16),
   NEONMAP0(vcvtq_f16_u16),
   NEONMAP0(vcvtq_f32_v),
-  NEONMAP1(vcvtq_high_bf16_f32, aarch64_neon_bfcvtn2, 0),
+  NEONMAP0(vcvtq_high_bf16_f32),
+  NEONMAP0(vcvtq_low_bf16_f32),
   NEONMAP1(vcvtq_n_f16_s16, aarch64_neon_vcvtfxs2fp, 0),
   NEONMAP1(vcvtq_n_f16_u16, aarch64_neon_vcvtfxu2fp, 0),
   NEONMAP2(vcvtq_n_f32_v, aarch64_neon_vcvtfxu2fp, aarch64_neon_vcvtfxs2fp, 0),
@@ -7616,7 +7616,7 @@ static const ARMVectorIntrinsicInfo 
AArch64SISDIntrinsicMap[] = {
   NEONMAP1(vcvtd_n_u64_f64, aarch64_neon_vcvtfp2fxu, AddRetType | Add1ArgType),
   NEONMAP1(vcvtd_s64_f64, aarch64_neon_fcvtzs, AddRetType | Add1ArgType),
   NEONMAP1(vcvtd_u64_f64, aarch64_neon_fcvtzu, AddRetType | Add1ArgType),
-  NEONMAP1(vcvth_bf16_f32, aarch64_neon_bfcvt, 0),
+  NEONMAP0(vcvth_bf16_f32),
   NEONMAP1(vcvtmd_s64_f64, aarch64_neon_fcvtms, AddRetType | Add1ArgType),
   NEONMAP1(vcvtmd_u64_f64, aarch64_neon_fcvtmu, AddRetType | Add1ArgType),
   NEONMAP1(vcvtms_s32_f32, aarch64_neon_fcvtms, AddRetType | Add1ArgType),
@@ -12083,6 +12083,12 @@ Value 
*CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID,
 return ConstantInt::get(Builder.getInt32Ty(), 0);
   }
 
+  if (BuiltinID == NEON::BI__builtin_neon_vcvth_bf16_f32)
+return Builder.CreateFPTrunc(
+Builder.CreateBitCast(EmitScalarExpr(E->getArg(0)),
+  Builder.getFloatTy()),
+Builder.getBFloatTy());
+
   // Handle MSVC intrinsics before argument evaluation to prevent double
   // evaluation.
   if (std::optional MsvcIntId =
@@ -12808,6 +12814,35 @@ Value 
*CodeGenFunction::Em

[clang] [llvm] [AArch64] Improve bcvtn2 and remove aarch64_neon_bfcvt intrinsics (PR #120363)

2025-01-15 Thread David Green via cfe-commits

davemgreen wrote:

Rebase and ping - thanks.

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


[clang] [CodeGen] Migrate away from PointerUnion::dyn_cast (NFC) (PR #123013)

2025-01-15 Thread Nikita Popov via cfe-commits

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


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


[clang] [lldb] [C++20] [Modules] Support module level lookup (PR #122887)

2025-01-15 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `openmp-s390x-linux` 
running on `systemz-1` while building `clang,lldb` at step 6 "test-openmp".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/88/builds/6804


Here is the relevant piece of the build log for the reference

```
Step 6 (test-openmp) failure: 1200 seconds without output running [b'ninja', 
b'-j 4', b'check-openmp'], attempting to kill

```



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


[clang-tools-extra] [clang-tidy][clangd] Fixed removeFunctionArgs don't remove comma for use-ranges check (PR #118568)

2025-01-15 Thread Richard Li via cfe-commits

https://github.com/chomosuke updated 
https://github.com/llvm/llvm-project/pull/118568

>From b43a2602025bdacea06ced5171904fb5d765de9f Mon Sep 17 00:00:00 2001
From: chomosuke 
Date: Tue, 3 Dec 2024 07:10:33 +
Subject: [PATCH 1/4] fixed removeFunctionArgs don't remove comma

---
 .../clang-tidy/utils/UseRangesCheck.cpp   | 19 ++-
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp 
b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
index aba4d17ccd035e..88cba70b931d5d 100644
--- a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
@@ -28,6 +28,7 @@
 #include "llvm/ADT/Twine.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
+#include 
 #include 
 #include 
 
@@ -173,21 +174,21 @@ static void removeFunctionArgs(DiagnosticBuilder &Diag, 
const CallExpr &Call,
   for (unsigned Index : Sorted) {
 const Expr *Arg = Call.getArg(Index);
 if (Commas[Index]) {
-  if (Index >= Commas.size()) {
-Diag << FixItHint::CreateRemoval(Arg->getSourceRange());
-  } else {
+  if (Index + 1 < Call.getNumArgs()) {
 // Remove the next comma
 Commas[Index + 1] = true;
+const Expr *NextArg = Call.getArg(Index + 1);
 Diag << FixItHint::CreateRemoval(CharSourceRange::getTokenRange(
-{Arg->getBeginLoc(),
- Lexer::getLocForEndOfToken(
- Arg->getEndLoc(), 0, Ctx.getSourceManager(), 
Ctx.getLangOpts())
- .getLocWithOffset(1)}));
+{Arg->getBeginLoc(), 
NextArg->getBeginLoc().getLocWithOffset(-1)}));
+  } else {
+Diag << FixItHint::CreateRemoval(Arg->getSourceRange());
   }
 } else {
-  Diag << FixItHint::CreateRemoval(CharSourceRange::getTokenRange(
-  Arg->getBeginLoc().getLocWithOffset(-1), Arg->getEndLoc()));
+  // At this point we know Index > 0 because `Commas[0] = true` earlier
   Commas[Index] = true;
+  const Expr *PrevArg = Call.getArg(Index - 1);
+  Diag << FixItHint::CreateRemoval(CharSourceRange::getTokenRange(
+  PrevArg->getEndLoc().getLocWithOffset(1), Arg->getEndLoc()));
 }
   }
 }

>From 644c8491e0fba203e89595827781d0c2c0609081 Mon Sep 17 00:00:00 2001
From: chomosuke 
Date: Mon, 23 Dec 2024 05:17:08 +1100
Subject: [PATCH 2/4] find , and remove only ,

---
 .../clang-tidy/utils/UseRangesCheck.cpp   | 49 +++
 1 file changed, 40 insertions(+), 9 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp 
b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
index 88cba70b931d5d..8b8e44a9898fdd 100644
--- a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
@@ -28,7 +28,6 @@
 #include "llvm/ADT/Twine.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
-#include 
 #include 
 #include 
 
@@ -165,6 +164,33 @@ void UseRangesCheck::registerMatchers(MatchFinder *Finder) 
{
 static void removeFunctionArgs(DiagnosticBuilder &Diag, const CallExpr &Call,
ArrayRef Indexes,
const ASTContext &Ctx) {
+  auto GetCommaLoc =
+  [&](SourceLocation BeginLoc,
+  SourceLocation EndLoc) -> std::optional {
+auto Invalid = false;
+auto SourceText = Lexer::getSourceText(
+CharSourceRange::getCharRange({BeginLoc, EndLoc}),
+Ctx.getSourceManager(), Ctx.getLangOpts(), &Invalid);
+assert(!Invalid);
+
+size_t I = 0;
+while (I < SourceText.size() && SourceText[I] != ',') {
+  I++;
+}
+
+if (I < SourceText.size()) {
+  // also remove space after ,
+  size_t J = I + 1;
+  while (J < SourceText.size() && SourceText[J] == ' ') {
+J++;
+  }
+
+  return std::make_optional(CharSourceRange::getCharRange(
+  {BeginLoc.getLocWithOffset(I), BeginLoc.getLocWithOffset(J)}));
+}
+return std::nullopt;
+  };
+
   llvm::SmallVector Sorted(Indexes);
   llvm::sort(Sorted);
   // Keep track of commas removed
@@ -176,20 +202,25 @@ static void removeFunctionArgs(DiagnosticBuilder &Diag, 
const CallExpr &Call,
 if (Commas[Index]) {
   if (Index + 1 < Call.getNumArgs()) {
 // Remove the next comma
-Commas[Index + 1] = true;
 const Expr *NextArg = Call.getArg(Index + 1);
-Diag << FixItHint::CreateRemoval(CharSourceRange::getTokenRange(
-{Arg->getBeginLoc(), 
NextArg->getBeginLoc().getLocWithOffset(-1)}));
-  } else {
-Diag << FixItHint::CreateRemoval(Arg->getSourceRange());
+auto CommaLoc = GetCommaLoc(Arg->getEndLoc().getLocWithOffset(1),
+NextArg->getBeginLoc());
+if (CommaLoc) {
+  Commas[Index + 1] = true;
+  Diag << FixItHint::CreateRemoval(*CommaLoc);
+}
   }
 } else {
   // At this point we know Index > 0 becau

[compiler-rt] [libunwind] [libunwind][cmake] Compile _Unwind* routines with -fexceptions (PR #121819)

2025-01-15 Thread Petr Hosek via cfe-commits


@@ -20,7 +20,12 @@ set(LIBUNWIND_C_SOURCES
 )
 set_source_files_properties(${LIBUNWIND_C_SOURCES}
 PROPERTIES
-  COMPILE_FLAGS "-std=c99")
+  # We need to set `-fexceptions` here so that key
+  # unwinding functions, like
+  # _UNWIND_RaiseExcpetion, are not marked as

petrhosek wrote:

```suggestion
  # _UNWIND_RaiseException, are not marked as
```

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


[clang-tools-extra] [include-cleaner] Add special mappings for operator new/delete (PR #123027)

2025-01-15 Thread kadir çetinkaya via cfe-commits

https://github.com/kadircet created 
https://github.com/llvm/llvm-project/pull/123027

Our stdlib mappings are based on names, hence they can't handle special
symbols like oprators.

Global operator new/delete show up often enough in practice to create
some user frustration, so we map these to .


From 5339f8e303a99b8a75320b24a3a371e531fa6140 Mon Sep 17 00:00:00 2001
From: Kadir Cetinkaya 
Date: Wed, 15 Jan 2025 10:11:09 +0100
Subject: [PATCH] [include-cleaner] Add special mappings for operator
 new/delete

Our stdlib mappings are based on names, hence they can't handle special
symbols like oprators.

Global operator new/delete show up often enough in practice to create
some user frustration, so we map these to .
---
 .../include-cleaner/lib/FindHeaders.cpp   | 17 ++-
 .../unittests/FindHeadersTest.cpp | 45 +++
 2 files changed, 61 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/include-cleaner/lib/FindHeaders.cpp 
b/clang-tools-extra/include-cleaner/lib/FindHeaders.cpp
index 7b28d1c252d715..e6a642ae8ed48a 100644
--- a/clang-tools-extra/include-cleaner/lib/FindHeaders.cpp
+++ b/clang-tools-extra/include-cleaner/lib/FindHeaders.cpp
@@ -16,6 +16,7 @@
 #include "clang/AST/DeclCXX.h"
 #include "clang/Basic/Builtins.h"
 #include "clang/Basic/FileEntry.h"
+#include "clang/Basic/OperatorKinds.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
@@ -157,8 +158,22 @@ headersForSpecialSymbol(const Symbol &S, const 
SourceManager &SM,
   if (!ND)
 return std::nullopt;
   auto *II = ND->getIdentifier();
-  if (!II)
+  if (!II) {
+// Special case global operator new/delete, these show up often enough in
+// practice and stdlib mappings can't work with them as they're symbol-name
+// based.
+if (ND->getDeclContext()->isTranslationUnit()) {
+  switch (ND->getDeclName().getCXXOverloadedOperator()) {
+  case OverloadedOperatorKind::OO_New:
+  case OverloadedOperatorKind::OO_Delete:
+return hintedHeadersForStdHeaders(
+{tooling::stdlib::Header::named("").value()}, SM, PI);
+  default:
+break;
+  }
+}
 return std::nullopt;
+  }
 
   // Check first for symbols that are part of our stdlib mapping. As we have
   // header names for those.
diff --git a/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp 
b/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
index 84e02e1d0d621b..d5b0a61ed1dfcb 100644
--- a/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
@@ -11,11 +11,13 @@
 #include "clang-include-cleaner/Analysis.h"
 #include "clang-include-cleaner/Record.h"
 #include "clang-include-cleaner/Types.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/Basic/FileEntry.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/LLVM.h"
+#include "clang/Basic/OperatorKinds.h"
 #include "clang/Frontend/FrontendActions.h"
 #include "clang/Testing/TestAST.h"
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
@@ -617,6 +619,49 @@ TEST_F(HeadersForSymbolTest, 
AmbiguousStdSymbolsUsingShadow) {
   Header(*tooling::stdlib::Header::named("";
 }
 
+TEST_F(HeadersForSymbolTest, GlobalOperatorNewDelete) {
+  Inputs.Code = R"cpp(
+void k() {
+  int *x;
+  // make sure operator new/delete are part of TU.
+  x = static_cast(::operator new(sizeof(int)));
+  ::operator delete(x);
+}
+  )cpp";
+  buildAST();
+
+  // Find global new/delete operators.
+  struct Visitor : public DynamicRecursiveASTVisitor {
+const NamedDecl *New = nullptr;
+const NamedDecl *Delete = nullptr;
+bool VisitNamedDecl(NamedDecl *ND) override {
+  if (!ND->getDeclContext()->isTranslationUnit())
+return true;
+  switch (ND->getDeclName().getCXXOverloadedOperator()) {
+  case OO_New:
+New = ND;
+break;
+  case OO_Delete:
+Delete = ND;
+break;
+  default:
+break;
+  }
+  return true;
+}
+  };
+  Visitor V;
+  V.ShouldVisitImplicitCode = true;
+  V.TraverseDecl(AST->context().getTranslationUnitDecl());
+  ASSERT_TRUE(V.New) << "Couldn't find global new!";
+  ASSERT_TRUE(V.Delete) << "Couldn't find global delete!";
+  EXPECT_THAT(headersForSymbol(*V.New, AST->sourceManager(), &PI),
+  UnorderedElementsAre(
+  Header(*tooling::stdlib::Header::named("";
+  EXPECT_THAT(headersForSymbol(*V.Delete, AST->sourceManager(), &PI),
+  UnorderedElementsAre(
+  Header(*tooling::stdlib::Header::named("";
+}
 
 TEST_F(HeadersForSymbolTest, StandardHeaders) {
   Inputs.Code = R"cpp(

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https:

[clang-tools-extra] [include-cleaner] Add special mappings for operator new/delete (PR #123027)

2025-01-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tools-extra

Author: kadir çetinkaya (kadircet)


Changes

Our stdlib mappings are based on names, hence they can't handle special
symbols like oprators.

Global operator new/delete show up often enough in practice to create
some user frustration, so we map these to .


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


2 Files Affected:

- (modified) clang-tools-extra/include-cleaner/lib/FindHeaders.cpp (+16-1) 
- (modified) clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp 
(+45) 


``diff
diff --git a/clang-tools-extra/include-cleaner/lib/FindHeaders.cpp 
b/clang-tools-extra/include-cleaner/lib/FindHeaders.cpp
index 7b28d1c252d715..e6a642ae8ed48a 100644
--- a/clang-tools-extra/include-cleaner/lib/FindHeaders.cpp
+++ b/clang-tools-extra/include-cleaner/lib/FindHeaders.cpp
@@ -16,6 +16,7 @@
 #include "clang/AST/DeclCXX.h"
 #include "clang/Basic/Builtins.h"
 #include "clang/Basic/FileEntry.h"
+#include "clang/Basic/OperatorKinds.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
@@ -157,8 +158,22 @@ headersForSpecialSymbol(const Symbol &S, const 
SourceManager &SM,
   if (!ND)
 return std::nullopt;
   auto *II = ND->getIdentifier();
-  if (!II)
+  if (!II) {
+// Special case global operator new/delete, these show up often enough in
+// practice and stdlib mappings can't work with them as they're symbol-name
+// based.
+if (ND->getDeclContext()->isTranslationUnit()) {
+  switch (ND->getDeclName().getCXXOverloadedOperator()) {
+  case OverloadedOperatorKind::OO_New:
+  case OverloadedOperatorKind::OO_Delete:
+return hintedHeadersForStdHeaders(
+{tooling::stdlib::Header::named("").value()}, SM, PI);
+  default:
+break;
+  }
+}
 return std::nullopt;
+  }
 
   // Check first for symbols that are part of our stdlib mapping. As we have
   // header names for those.
diff --git a/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp 
b/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
index 84e02e1d0d621b..d5b0a61ed1dfcb 100644
--- a/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
@@ -11,11 +11,13 @@
 #include "clang-include-cleaner/Analysis.h"
 #include "clang-include-cleaner/Record.h"
 #include "clang-include-cleaner/Types.h"
+#include "clang/AST/DynamicRecursiveASTVisitor.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/Basic/FileEntry.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/LLVM.h"
+#include "clang/Basic/OperatorKinds.h"
 #include "clang/Frontend/FrontendActions.h"
 #include "clang/Testing/TestAST.h"
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
@@ -617,6 +619,49 @@ TEST_F(HeadersForSymbolTest, 
AmbiguousStdSymbolsUsingShadow) {
   Header(*tooling::stdlib::Header::named("";
 }
 
+TEST_F(HeadersForSymbolTest, GlobalOperatorNewDelete) {
+  Inputs.Code = R"cpp(
+void k() {
+  int *x;
+  // make sure operator new/delete are part of TU.
+  x = static_cast(::operator new(sizeof(int)));
+  ::operator delete(x);
+}
+  )cpp";
+  buildAST();
+
+  // Find global new/delete operators.
+  struct Visitor : public DynamicRecursiveASTVisitor {
+const NamedDecl *New = nullptr;
+const NamedDecl *Delete = nullptr;
+bool VisitNamedDecl(NamedDecl *ND) override {
+  if (!ND->getDeclContext()->isTranslationUnit())
+return true;
+  switch (ND->getDeclName().getCXXOverloadedOperator()) {
+  case OO_New:
+New = ND;
+break;
+  case OO_Delete:
+Delete = ND;
+break;
+  default:
+break;
+  }
+  return true;
+}
+  };
+  Visitor V;
+  V.ShouldVisitImplicitCode = true;
+  V.TraverseDecl(AST->context().getTranslationUnitDecl());
+  ASSERT_TRUE(V.New) << "Couldn't find global new!";
+  ASSERT_TRUE(V.Delete) << "Couldn't find global delete!";
+  EXPECT_THAT(headersForSymbol(*V.New, AST->sourceManager(), &PI),
+  UnorderedElementsAre(
+  Header(*tooling::stdlib::Header::named("";
+  EXPECT_THAT(headersForSymbol(*V.Delete, AST->sourceManager(), &PI),
+  UnorderedElementsAre(
+  Header(*tooling::stdlib::Header::named("";
+}
 
 TEST_F(HeadersForSymbolTest, StandardHeaders) {
   Inputs.Code = R"cpp(

``




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


[clang] [Clang] Re-write codegen for atomic_test_and_set and atomic_clear (PR #121943)

2025-01-15 Thread Oliver Stannard via cfe-commits

https://github.com/ostannard updated 
https://github.com/llvm/llvm-project/pull/121943

>From 2a69ca9ba3b67967e0f88a9b96ac8bea44220842 Mon Sep 17 00:00:00 2001
From: Oliver Stannard 
Date: Thu, 19 Dec 2024 09:12:19 +
Subject: [PATCH 1/3] [Clang] Re-write codegen for atomic_test_and_set and
 atomic_clear (#120449)

Re-write the sema and codegen for the atomic_test_and_set and
atomic_clear builtin functions to go via AtomicExpr, like the other
atomic builtins do. This simplifies the code, because AtomicExpr already
handles things like generating code for to dynamically select the memory
ordering, which was duplicated for these builtins. This also fixes a few
crash bugs, one when passing an integer to the pointer argument, and one
when using an array.

This also adds diagnostics for the memory orderings which are not valid
for atomic_clear according to
https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html, which
were missing before.

Fixes #111293.
---
 clang/include/clang/Basic/Builtins.td|  12 +-
 clang/lib/AST/Expr.cpp   |   2 +
 clang/lib/CodeGen/CGAtomic.cpp   |  25 ++-
 clang/lib/CodeGen/CGBuiltin.cpp  | 141 -
 clang/lib/Sema/SemaChecking.cpp  |  35 +++-
 clang/test/CodeGen/atomic-test-and-set.c | 250 +++
 clang/test/Sema/atomic-ops.c |   8 +-
 7 files changed, 316 insertions(+), 157 deletions(-)
 create mode 100644 clang/test/CodeGen/atomic-test-and-set.c

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 468c16050e2bf0..5bbab148f50a9d 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -1977,16 +1977,16 @@ def AtomicNandFetch : AtomicBuiltin {
   let Prototype = "void(...)";
 }
 
-def AtomicTestAndSet : Builtin {
+def AtomicTestAndSet : AtomicBuiltin {
   let Spellings = ["__atomic_test_and_set"];
-  let Attributes = [NoThrow];
-  let Prototype = "bool(void volatile*, int)";
+  let Attributes = [NoThrow, CustomTypeChecking];
+  let Prototype = "void(...)";
 }
 
-def AtomicClear : Builtin {
+def AtomicClear : AtomicBuiltin {
   let Spellings = ["__atomic_clear"];
-  let Attributes = [NoThrow];
-  let Prototype = "void(void volatile*, int)";
+  let Attributes = [NoThrow, CustomTypeChecking];
+  let Prototype = "void(...)";
 }
 
 def AtomicThreadFence : Builtin {
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index ba66d362785674..b6a86d82473d3d 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -5070,6 +5070,8 @@ unsigned AtomicExpr::getNumSubExprs(AtomicOp Op) {
   case AO__opencl_atomic_init:
   case AO__c11_atomic_load:
   case AO__atomic_load_n:
+  case AO__atomic_test_and_set:
+  case AO__atomic_clear:
 return 2;
 
   case AO__scoped_atomic_load_n:
diff --git a/clang/lib/CodeGen/CGAtomic.cpp b/clang/lib/CodeGen/CGAtomic.cpp
index f6cb2ad421e906..3adb2a7ad207f0 100644
--- a/clang/lib/CodeGen/CGAtomic.cpp
+++ b/clang/lib/CodeGen/CGAtomic.cpp
@@ -723,6 +723,24 @@ static void EmitAtomicOp(CodeGenFunction &CGF, AtomicExpr 
*E, Address Dest,
   case AtomicExpr::AO__scoped_atomic_fetch_nand:
 Op = llvm::AtomicRMWInst::Nand;
 break;
+
+  case AtomicExpr::AO__atomic_test_and_set: {
+llvm::AtomicRMWInst *RMWI =
+CGF.emitAtomicRMWInst(llvm::AtomicRMWInst::Xchg, Ptr,
+  CGF.Builder.getInt8(1), Order, Scope, E);
+RMWI->setVolatile(E->isVolatile());
+llvm::Value *Result = CGF.Builder.CreateIsNotNull(RMWI, "tobool");
+CGF.Builder.CreateStore(Result, Dest);
+return;
+  }
+
+  case AtomicExpr::AO__atomic_clear: {
+llvm::StoreInst *Store =
+CGF.Builder.CreateStore(CGF.Builder.getInt8(0), Ptr);
+Store->setAtomic(Order, Scope);
+Store->setVolatile(E->isVolatile());
+return;
+  }
   }
 
   llvm::Value *LoadVal1 = CGF.Builder.CreateLoad(Val1);
@@ -878,6 +896,8 @@ RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E) {
   case AtomicExpr::AO__c11_atomic_load:
   case AtomicExpr::AO__opencl_atomic_load:
   case AtomicExpr::AO__hip_atomic_load:
+  case AtomicExpr::AO__atomic_test_and_set:
+  case AtomicExpr::AO__atomic_clear:
 break;
 
   case AtomicExpr::AO__atomic_load:
@@ -1200,6 +1220,8 @@ RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E) {
 case AtomicExpr::AO__opencl_atomic_fetch_max:
 case AtomicExpr::AO__scoped_atomic_fetch_max:
 case AtomicExpr::AO__scoped_atomic_max_fetch:
+case AtomicExpr::AO__atomic_test_and_set:
+case AtomicExpr::AO__atomic_clear:
   llvm_unreachable("Integral atomic operations always become atomicrmw!");
 }
 
@@ -1239,7 +1261,8 @@ RValue CodeGenFunction::EmitAtomicExpr(AtomicExpr *E) {
  E->getOp() == AtomicExpr::AO__atomic_store ||
  E->getOp() == AtomicExpr::AO__atomic_store_n ||
  E->getOp() == AtomicExpr::AO__scoped_atomic_store ||
- E->getOp() == AtomicExpr::AO__scoped_atom

[libclc] [libclc] Move several integer functions to CLC library (PR #116786)

2025-01-15 Thread Fraser Cormack via cfe-commits

frasercrmck wrote:

ping

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


[clang] [Clang] Re-write codegen for atomic_test_and_set and atomic_clear (PR #121943)

2025-01-15 Thread Oliver Stannard via cfe-commits


@@ -3686,12 +3687,18 @@ ExprResult Sema::BuildAtomicExpr(SourceRange CallRange, 
SourceRange ExprRange,
 C11CmpXchg,
 
 // bool __atomic_compare_exchange(A *, C *, CP, bool, int, int)
-GNUCmpXchg
+GNUCmpXchg,
+
+// bool __atomic_test_and_set(A *, int)
+TestAndSet,

ostannard wrote:

Done

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


[clang] [Clang] Re-write codegen for atomic_test_and_set and atomic_clear (PR #121943)

2025-01-15 Thread Oliver Stannard via cfe-commits


@@ -3911,14 +3926,31 @@ ExprResult Sema::BuildAtomicExpr(SourceRange CallRange, 
SourceRange ExprRange,
 }
   }
 
-  // Pointer to object of size zero is not allowed.
-  if (RequireCompleteType(Ptr->getBeginLoc(), AtomTy,
-  diag::err_incomplete_type))
-return ExprError();
-  if (Context.getTypeInfoInChars(AtomTy).Width.isZero()) {
-Diag(ExprRange.getBegin(), diag::err_atomic_builtin_must_be_pointer)
-<< Ptr->getType() << 1 << Ptr->getSourceRange();
-return ExprError();
+  if (Form != TestAndSet && Form != Clear) {
+// Pointer to object of size zero is not allowed.
+if (RequireCompleteType(Ptr->getBeginLoc(), AtomTy,
+diag::err_incomplete_type))
+  return ExprError();
+
+if (Context.getTypeInfoInChars(AtomTy).Width.isZero()) {
+  Diag(ExprRange.getBegin(), diag::err_atomic_builtin_must_be_pointer)
+  << Ptr->getType() << 1 << Ptr->getSourceRange();
+  return ExprError();
+}
+  } else {
+// The __atomic_clear and __atomic_test_and_set intrinsics accept any

ostannard wrote:

I've tried that, but it results in the block above, which reports an error is a 
const pointer is used, always printing a `char *` type instead of the actual 
type from the source code. However I can update this to keep `AtomTy` and 
`ValType` up to date when the pointer type changes, so that the rest of the 
checks work correctly.

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


[clang] [Clang] Re-write codegen for atomic_test_and_set and atomic_clear (PR #121943)

2025-01-15 Thread Oliver Stannard via cfe-commits


@@ -3963,8 +3995,8 @@ ExprResult Sema::BuildAtomicExpr(SourceRange CallRange, 
SourceRange ExprRange,
 return ExprError();
   }
 
-  if (!IsC11 && !AtomTy.isTriviallyCopyableType(Context) &&
-  !AtomTy->isScalarType()) {
+  if (!IsC11 && Form != TestAndSet && Form != Clear &&
+  !AtomTy.isTriviallyCopyableType(Context) && !AtomTy->isScalarType()) {

ostannard wrote:

Done.

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


[clang] [Clang] Re-write codegen for atomic_test_and_set and atomic_clear (PR #121943)

2025-01-15 Thread Oliver Stannard via cfe-commits


@@ -284,11 +284,26 @@ void f(_Atomic(int) *i, const _Atomic(int) *ci,
 
   const volatile int flag_k = 0;
   volatile int flag = 0;
-  (void)(int)__atomic_test_and_set(&flag_k, memory_order_seq_cst); // 
expected-warning {{passing 'const volatile int *' to parameter of type 
'volatile void *'}}
+  (void)(int)__atomic_test_and_set(&flag_k, memory_order_seq_cst); // 
expected-error {{address argument to atomic operation must be a pointer to 
non-const type ('const volatile int *' invalid)}}
   (void)(int)__atomic_test_and_set(&flag, memory_order_seq_cst);
-  __atomic_clear(&flag_k, memory_order_seq_cst); // expected-warning {{passing 
'const volatile int *' to parameter of type 'volatile void *'}}
+  __atomic_clear(&flag_k, memory_order_seq_cst); // expected-error {{address 
argument to atomic operation must be a pointer to non-const type ('const 
volatile int *' invalid)}}
   __atomic_clear(&flag, memory_order_seq_cst);
   (int)__atomic_clear(&flag, memory_order_seq_cst); // expected-error 
{{operand of type 'void'}}
+  __atomic_clear(0x8000, memory_order_seq_cst); // expected-error {{address 
argument to atomic builtin must be a pointer ('int' invalid)}}
+  __atomic_clear(&flag, memory_order_consume); // expected-warning {{memory 
order argument to atomic operation is invalid}}
+  __atomic_clear(&flag, memory_order_acquire); // expected-warning {{memory 
order argument to atomic operation is invalid}}
+  __atomic_clear(&flag, memory_order_acq_rel); // expected-warning {{memory 
order argument to atomic operation is invalid}}
+
+  // These intrinsics accept any non-const pointer type (including
+  // pointer-to-incomplete), and access the first byte.
+  __atomic_test_and_set((void*)0x8000, memory_order_seq_cst);
+  __atomic_test_and_set((char*)0x8000, memory_order_seq_cst);
+  __atomic_test_and_set((int*)0x8000, memory_order_seq_cst);
+  __atomic_test_and_set((struct incomplete*)0x8000, memory_order_seq_cst);
+  __atomic_clear((void*)0x8000, memory_order_seq_cst);
+  __atomic_clear((char*)0x8000, memory_order_seq_cst);
+  __atomic_clear((int*)0x8000, memory_order_seq_cst);
+  __atomic_clear((struct incomplete*)0x8000, memory_order_seq_cst);

ostannard wrote:

Done

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


[clang] [Clang] Re-write codegen for atomic_test_and_set and atomic_clear (PR #121943)

2025-01-15 Thread Oliver Stannard via cfe-commits


@@ -1977,16 +1977,16 @@ def AtomicNandFetch : AtomicBuiltin {
   let Prototype = "void(...)";
 }
 
-def AtomicTestAndSet : Builtin {
+def AtomicTestAndSet : AtomicBuiltin {
   let Spellings = ["__atomic_test_and_set"];
-  let Attributes = [NoThrow];
-  let Prototype = "bool(void volatile*, int)";
+  let Attributes = [NoThrow, CustomTypeChecking];
+  let Prototype = "void(...)";

ostannard wrote:

Done

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


[clang] [clang-tools-extra] [clangd] Make clangd run `format::cleanupAroundReplacements()` for all code actions just as clang-tidy does (PR #118569)

2025-01-15 Thread Richard Li via cfe-commits

https://github.com/chomosuke updated 
https://github.com/llvm/llvm-project/pull/118569

>From efc17a803c9c22543de7d5f9e960a7267ade1f2e Mon Sep 17 00:00:00 2001
From: chomosuke 
Date: Wed, 4 Dec 2024 14:42:24 +
Subject: [PATCH 1/3] [clangd][clang-tidy] Make clangd run
 `format::cleanupAroundReplacements()` for all code actions just as clang-tidy
 does

---
 clang-tools-extra/clang-tidy/ClangTidy.cpp| 22 ++--
 clang-tools-extra/clangd/Diagnostics.cpp  | 35 -
 .../clangd/unittests/DiagnosticsTests.cpp | 51 ---
 .../include/clang/Tooling/Core/Replacement.h  |  4 ++
 clang/lib/Tooling/Core/Replacement.cpp| 16 +-
 5 files changed, 99 insertions(+), 29 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp 
b/clang-tools-extra/clang-tidy/ClangTidy.cpp
index 9c8c93c5d16c72..82331c724eaaf2 100644
--- a/clang-tools-extra/clang-tidy/ClangTidy.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp
@@ -149,26 +149,12 @@ class ErrorReporter {
Repl.getLength(), 
Repl.getReplacementText());
 auto &Entry = FileReplacements[R.getFilePath()];
 Replacements &Replacements = Entry.Replaces;
-llvm::Error Err = Replacements.add(R);
+llvm::Error Err = Replacements.addOrMerge(R);
 if (Err) {
   // FIXME: Implement better conflict handling.
-  llvm::errs() << "Trying to resolve conflict: "
-   << llvm::toString(std::move(Err)) << "\n";
-  unsigned NewOffset =
-  Replacements.getShiftedCodePosition(R.getOffset());
-  unsigned NewLength = Replacements.getShiftedCodePosition(
-   R.getOffset() + R.getLength()) -
-   NewOffset;
-  if (NewLength == R.getLength()) {
-R = Replacement(R.getFilePath(), NewOffset, NewLength,
-R.getReplacementText());
-Replacements = Replacements.merge(tooling::Replacements(R));
-CanBeApplied = true;
-++AppliedFixes;
-  } else {
-llvm::errs()
-<< "Can't resolve conflict, skipping the replacement.\n";
-  }
+  llvm::errs()
+  << "Can't resolve conflict, skipping the replacement: "
+  << llvm::toString(std::move(Err)) << '\n';
 } else {
   CanBeApplied = true;
   ++AppliedFixes;
diff --git a/clang-tools-extra/clangd/Diagnostics.cpp 
b/clang-tools-extra/clangd/Diagnostics.cpp
index a59d1e7ac84096..60c6ac7256b58c 100644
--- a/clang-tools-extra/clangd/Diagnostics.cpp
+++ b/clang-tools-extra/clangd/Diagnostics.cpp
@@ -19,6 +19,7 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TokenKinds.h"
+#include "clang/Format/Format.h"
 #include "clang/Lex/Lexer.h"
 #include "clang/Lex/Token.h"
 #include "llvm/ADT/ArrayRef.h"
@@ -741,7 +742,7 @@ void StoreDiags::HandleDiagnostic(DiagnosticsEngine::Level 
DiagLevel,
   return false;
 // Copy as we may modify the ranges.
 auto FixIts = Info.getFixItHints().vec();
-llvm::SmallVector Edits;
+auto Replacements = std::make_optional();
 for (auto &FixIt : FixIts) {
   // Allow fixits within a single macro-arg expansion to be applied.
   // This can be incorrect if the argument is expanded multiple times in
@@ -761,7 +762,37 @@ void StoreDiags::HandleDiagnostic(DiagnosticsEngine::Level 
DiagLevel,
 return false;
   if (!isInsideMainFile(FixIt.RemoveRange.getBegin(), SM))
 return false;
-  Edits.push_back(toTextEdit(FixIt, SM, *LangOpts));
+
+  auto R = tooling::Replacement(SM, FixIt.RemoveRange, FixIt.CodeToInsert,
+*LangOpts);
+  auto Err = Replacements->addOrMerge(R);
+  if (Err) {
+log("Skipping formatting the replacement due to conflict: {0}",
+llvm::toString(std::move(Err)));
+Replacements = std::nullopt;
+break;
+  }
+}
+
+llvm::SmallVector Edits;
+
+if (Replacements) {
+  StringRef Code = SM.getBufferData(SM.getMainFileID());
+  auto Repl = format::cleanupAroundReplacements(Code, *Replacements,
+format::getNoStyle());
+  if (!Repl) {
+log("Skipping formatting the replacement due to conflict: {0}",
+llvm::toString(std::move(Repl.takeError(;
+Replacements = std::nullopt;
+  } else {
+auto Es = replacementsToEdits(Code, *Repl);
+Edits.append(Es.begin(), Es.end());
+  }
+}
+if (!Replacements) {
+  for (auto &FixIt : FixIts) {
+Edits.push_back(toTextEdit(FixIt, SM, *LangOpts));
+  }
 }
 
 llvm::SmallString<64> Message;
diff --git a/clang-tools-extra/clangd/unitte

[clang] [AArch64] FP8 implicit bitcast (PR #122893)

2025-01-15 Thread Jonathan Thackray via cfe-commits


@@ -7429,6 +7429,11 @@ class Sema final : public SemaBase {
   /// the perspective of SVE bitcasts.
   bool isValidSveBitcast(QualType srcType, QualType destType);
 
+  /// Check for bitcast beween a regular vector type and builtin Neon vector

jthackray wrote:

typo:
```suggestion
  /// Check for bitcast between a regular vector type and builtin Neon vector
```

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


[clang] [AArch64] FP8 implicit bitcast (PR #122893)

2025-01-15 Thread Jonathan Thackray via cfe-commits

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

LGTM

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


[clang] [clang] Add support for passing FileSystem to buildASTFromCodeWithArgs() (PR #123042)

2025-01-15 Thread Boaz Brickner via cfe-commits

https://github.com/bricknerb created 
https://github.com/llvm/llvm-project/pull/123042

This would allow tools that don't use the real file system to use this function.

>From 197fa433e56c875b4098806576f14b33a37a4300 Mon Sep 17 00:00:00 2001
From: Boaz Brickner 
Date: Wed, 15 Jan 2025 11:48:20 +0100
Subject: [PATCH] [clang] Add support for passing FileSystem to
 buildASTFromCodeWithArgs()

---
 clang/include/clang/Tooling/Tooling.h   |  7 ++-
 clang/lib/Tooling/Tooling.cpp   |  5 +++--
 clang/unittests/Tooling/ToolingTest.cpp | 14 ++
 3 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/Tooling/Tooling.h 
b/clang/include/clang/Tooling/Tooling.h
index 070706e8fa6d11..30ee02d2cf5f12 100644
--- a/clang/include/clang/Tooling/Tooling.h
+++ b/clang/include/clang/Tooling/Tooling.h
@@ -225,6 +225,9 @@ buildASTFromCode(StringRef Code, StringRef FileName = 
"input.cc",
 ///
 /// \param Adjuster A function to filter the command line arguments as 
specified.
 ///
+/// \param FileSystem FileSystem for managing and looking up files.
+///
+///
 /// \return The resulting AST or null if an error occurred.
 std::unique_ptr buildASTFromCodeWithArgs(
 StringRef Code, const std::vector &Args,
@@ -233,7 +236,9 @@ std::unique_ptr buildASTFromCodeWithArgs(
 std::make_shared(),
 ArgumentsAdjuster Adjuster = getClangStripDependencyFileAdjuster(),
 const FileContentMappings &VirtualMappedFiles = FileContentMappings(),
-DiagnosticConsumer *DiagConsumer = nullptr);
+DiagnosticConsumer *DiagConsumer = nullptr,
+IntrusiveRefCntPtr FileSystem =
+llvm::vfs::getRealFileSystem());
 
 /// Utility to run a FrontendAction in a single clang invocation.
 class ToolInvocation {
diff --git a/clang/lib/Tooling/Tooling.cpp b/clang/lib/Tooling/Tooling.cpp
index 88b7349ce8fed6..385811d3dab9e1 100644
--- a/clang/lib/Tooling/Tooling.cpp
+++ b/clang/lib/Tooling/Tooling.cpp
@@ -692,11 +692,12 @@ std::unique_ptr buildASTFromCodeWithArgs(
 StringRef Code, const std::vector &Args, StringRef FileName,
 StringRef ToolName, std::shared_ptr 
PCHContainerOps,
 ArgumentsAdjuster Adjuster, const FileContentMappings &VirtualMappedFiles,
-DiagnosticConsumer *DiagConsumer) {
+DiagnosticConsumer *DiagConsumer,
+IntrusiveRefCntPtr FileSystem) {
   std::vector> ASTs;
   ASTBuilderAction Action(ASTs);
   llvm::IntrusiveRefCntPtr OverlayFileSystem(
-  new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem()));
+  new llvm::vfs::OverlayFileSystem(FileSystem));
   llvm::IntrusiveRefCntPtr InMemoryFileSystem(
   new llvm::vfs::InMemoryFileSystem);
   OverlayFileSystem->pushOverlay(InMemoryFileSystem);
diff --git a/clang/unittests/Tooling/ToolingTest.cpp 
b/clang/unittests/Tooling/ToolingTest.cpp
index 0b65577a05193f..8cdfffb54390e0 100644
--- a/clang/unittests/Tooling/ToolingTest.cpp
+++ b/clang/unittests/Tooling/ToolingTest.cpp
@@ -152,6 +152,20 @@ TEST(buildASTFromCode, ReportsErrors) {
   EXPECT_EQ(1u, Consumer.NumDiagnosticsSeen);
 }
 
+TEST(buildASTFromCode, FileSystem) {
+  llvm::IntrusiveRefCntPtr InMemoryFileSystem(
+  new llvm::vfs::InMemoryFileSystem);
+  InMemoryFileSystem->addFile("included_file.h", 0,
+  llvm::MemoryBuffer::getMemBufferCopy("class 
X;"));
+  std::unique_ptr AST = buildASTFromCodeWithArgs(
+  R"(#include "included_file.h")", {}, "input.cc", "clang-tool",
+  std::make_shared(),
+  getClangStripDependencyFileAdjuster(), FileContentMappings(), nullptr,
+  InMemoryFileSystem);
+  ASSERT_TRUE(AST.get());
+  EXPECT_TRUE(FindClassDeclX(AST.get()));
+}
+
 TEST(newFrontendActionFactory, CreatesFrontendActionFactoryFromType) {
   std::unique_ptr Factory(
   newFrontendActionFactory());

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


[clang] [clang] Add support for passing FileSystem to buildASTFromCodeWithArgs() (PR #123042)

2025-01-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Boaz Brickner (bricknerb)


Changes

This would allow tools that don't use the real file system to use this function.

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


3 Files Affected:

- (modified) clang/include/clang/Tooling/Tooling.h (+6-1) 
- (modified) clang/lib/Tooling/Tooling.cpp (+3-2) 
- (modified) clang/unittests/Tooling/ToolingTest.cpp (+14) 


``diff
diff --git a/clang/include/clang/Tooling/Tooling.h 
b/clang/include/clang/Tooling/Tooling.h
index 070706e8fa6d11..30ee02d2cf5f12 100644
--- a/clang/include/clang/Tooling/Tooling.h
+++ b/clang/include/clang/Tooling/Tooling.h
@@ -225,6 +225,9 @@ buildASTFromCode(StringRef Code, StringRef FileName = 
"input.cc",
 ///
 /// \param Adjuster A function to filter the command line arguments as 
specified.
 ///
+/// \param FileSystem FileSystem for managing and looking up files.
+///
+///
 /// \return The resulting AST or null if an error occurred.
 std::unique_ptr buildASTFromCodeWithArgs(
 StringRef Code, const std::vector &Args,
@@ -233,7 +236,9 @@ std::unique_ptr buildASTFromCodeWithArgs(
 std::make_shared(),
 ArgumentsAdjuster Adjuster = getClangStripDependencyFileAdjuster(),
 const FileContentMappings &VirtualMappedFiles = FileContentMappings(),
-DiagnosticConsumer *DiagConsumer = nullptr);
+DiagnosticConsumer *DiagConsumer = nullptr,
+IntrusiveRefCntPtr FileSystem =
+llvm::vfs::getRealFileSystem());
 
 /// Utility to run a FrontendAction in a single clang invocation.
 class ToolInvocation {
diff --git a/clang/lib/Tooling/Tooling.cpp b/clang/lib/Tooling/Tooling.cpp
index 88b7349ce8fed6..385811d3dab9e1 100644
--- a/clang/lib/Tooling/Tooling.cpp
+++ b/clang/lib/Tooling/Tooling.cpp
@@ -692,11 +692,12 @@ std::unique_ptr buildASTFromCodeWithArgs(
 StringRef Code, const std::vector &Args, StringRef FileName,
 StringRef ToolName, std::shared_ptr 
PCHContainerOps,
 ArgumentsAdjuster Adjuster, const FileContentMappings &VirtualMappedFiles,
-DiagnosticConsumer *DiagConsumer) {
+DiagnosticConsumer *DiagConsumer,
+IntrusiveRefCntPtr FileSystem) {
   std::vector> ASTs;
   ASTBuilderAction Action(ASTs);
   llvm::IntrusiveRefCntPtr OverlayFileSystem(
-  new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem()));
+  new llvm::vfs::OverlayFileSystem(FileSystem));
   llvm::IntrusiveRefCntPtr InMemoryFileSystem(
   new llvm::vfs::InMemoryFileSystem);
   OverlayFileSystem->pushOverlay(InMemoryFileSystem);
diff --git a/clang/unittests/Tooling/ToolingTest.cpp 
b/clang/unittests/Tooling/ToolingTest.cpp
index 0b65577a05193f..8cdfffb54390e0 100644
--- a/clang/unittests/Tooling/ToolingTest.cpp
+++ b/clang/unittests/Tooling/ToolingTest.cpp
@@ -152,6 +152,20 @@ TEST(buildASTFromCode, ReportsErrors) {
   EXPECT_EQ(1u, Consumer.NumDiagnosticsSeen);
 }
 
+TEST(buildASTFromCode, FileSystem) {
+  llvm::IntrusiveRefCntPtr InMemoryFileSystem(
+  new llvm::vfs::InMemoryFileSystem);
+  InMemoryFileSystem->addFile("included_file.h", 0,
+  llvm::MemoryBuffer::getMemBufferCopy("class 
X;"));
+  std::unique_ptr AST = buildASTFromCodeWithArgs(
+  R"(#include "included_file.h")", {}, "input.cc", "clang-tool",
+  std::make_shared(),
+  getClangStripDependencyFileAdjuster(), FileContentMappings(), nullptr,
+  InMemoryFileSystem);
+  ASSERT_TRUE(AST.get());
+  EXPECT_TRUE(FindClassDeclX(AST.get()));
+}
+
 TEST(newFrontendActionFactory, CreatesFrontendActionFactoryFromType) {
   std::unique_ptr Factory(
   newFrontendActionFactory());

``




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


[clang] [llvm] [SPIRV] add pre legalization instruction combine (PR #122839)

2025-01-15 Thread Michal Paszkowski via cfe-commits


@@ -0,0 +1,26 @@
+//=- SPIRVCombine.td - Define SPIRV Combine Rules -*-tablegen 
-*-=//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//

michalpaszkowski wrote:

Should the file include some comment? Otherwise, I think this part could be 
removed.

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


[clang] [clang] Add support for passing FileSystem to buildASTFromCodeWithArgs() (PR #123042)

2025-01-15 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 2a044f8a092efb27fa1837f953bce8237d41e59b 
197fa433e56c875b4098806576f14b33a37a4300 --extensions cpp,h -- 
clang/include/clang/Tooling/Tooling.h clang/lib/Tooling/Tooling.cpp 
clang/unittests/Tooling/ToolingTest.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/include/clang/Tooling/Tooling.h 
b/clang/include/clang/Tooling/Tooling.h
index 30ee02d2cf..473157f08e 100644
--- a/clang/include/clang/Tooling/Tooling.h
+++ b/clang/include/clang/Tooling/Tooling.h
@@ -223,7 +223,8 @@ buildASTFromCode(StringRef Code, StringRef FileName = 
"input.cc",
 /// \param PCHContainerOps The PCHContainerOperations for loading and creating
 /// clang modules.
 ///
-/// \param Adjuster A function to filter the command line arguments as 
specified.
+/// \param Adjuster A function to filter the command line arguments as
+/// specified.
 ///
 /// \param FileSystem FileSystem for managing and looking up files.
 ///

``




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


[clang] Fixed some warn-override tests in SemaCXX (PR #122680)

2025-01-15 Thread via cfe-commits

2LoS wrote:

@cor3ntin , can you merge the pull request, please? 

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


[clang] [Clang][Arch] Disable mve.fp when explicit -mfpu option (PR #123028)

2025-01-15 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-clang

Author: None (flopop01)


Changes

-mfpu=fpv5-d16 or -mfpu=fpv5-sp-d16 disables the scalar half-precision 
floating-point operations feature. Therefore, because the M-profile Vector 
Extension (MVE) floating-point feature requires the scalar half-precision 
floating-point operations, this option also disables the MVE floating-point 
feature, -mve.fp

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


1 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Arch/ARM.cpp (+9) 


``diff
diff --git a/clang/lib/Driver/ToolChains/Arch/ARM.cpp 
b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
index b8181ce6dc012a..cec2c4f24d676d 100644
--- a/clang/lib/Driver/ToolChains/Arch/ARM.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
@@ -748,6 +748,15 @@ llvm::ARM::FPUKind arm::getARMTargetFeatures(const Driver 
&D,
   Features.push_back("-crc");
   }
 
+  // Invalid value of the __ARM_FEATURE_MVE macro when an explicit -mfpu= 
option
+  // disables MVE-FP -mfpu=fpv5-d16 or -mfpu=fpv5-sp-d16 disables the scalar
+  // half-precision floating-point operations feature. Therefore, because the
+  // M-profile Vector Extension (MVE) floating-point feature requires the 
scalar
+  // half-precision floating-point operations, this option also disables the 
MVE
+  // floating-point feature: -mve.fp
+  if (FPUKind == llvm::ARM::FK_FPV5_D16 || FPUKind == 
llvm::ARM::FK_FPV5_SP_D16)
+Features.push_back("-mve.fp");
+
   // For Arch >= ARMv8.0 && A or R profile:  crypto = sha2 + aes
   // Rather than replace within the feature vector, determine whether each
   // algorithm is enabled and append this to the end of the vector.

``




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


[clang-tools-extra] [include-cleaner] Add special mappings for operator new/delete (PR #123027)

2025-01-15 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 d1d25641f4cb87ab2c07a4136ba1cec4fb6cf578 
5339f8e303a99b8a75320b24a3a371e531fa6140 --extensions cpp -- 
clang-tools-extra/include-cleaner/lib/FindHeaders.cpp 
clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp 
b/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
index d5b0a61ed1..5553958f1d 100644
--- a/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp
@@ -655,12 +655,12 @@ TEST_F(HeadersForSymbolTest, GlobalOperatorNewDelete) {
   V.TraverseDecl(AST->context().getTranslationUnitDecl());
   ASSERT_TRUE(V.New) << "Couldn't find global new!";
   ASSERT_TRUE(V.Delete) << "Couldn't find global delete!";
-  EXPECT_THAT(headersForSymbol(*V.New, AST->sourceManager(), &PI),
-  UnorderedElementsAre(
-  Header(*tooling::stdlib::Header::named("";
-  EXPECT_THAT(headersForSymbol(*V.Delete, AST->sourceManager(), &PI),
-  UnorderedElementsAre(
-  Header(*tooling::stdlib::Header::named("";
+  EXPECT_THAT(
+  headersForSymbol(*V.New, AST->sourceManager(), &PI),
+  UnorderedElementsAre(Header(*tooling::stdlib::Header::named("";
+  EXPECT_THAT(
+  headersForSymbol(*V.Delete, AST->sourceManager(), &PI),
+  UnorderedElementsAre(Header(*tooling::stdlib::Header::named("";
 }
 
 TEST_F(HeadersForSymbolTest, StandardHeaders) {

``




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


[clang] [Clang][Arch] Disable mve.fp when explicit -mfpu option (PR #123028)

2025-01-15 Thread via cfe-commits

https://github.com/flopop01 created 
https://github.com/llvm/llvm-project/pull/123028

-mfpu=fpv5-d16 or -mfpu=fpv5-sp-d16 disables the scalar half-precision 
floating-point operations feature. Therefore, because the M-profile Vector 
Extension (MVE) floating-point feature requires the scalar half-precision 
floating-point operations, this option also disables the MVE floating-point 
feature, -mve.fp

>From dbb412b925a01fec354fe0bcadf9db3a766730d7 Mon Sep 17 00:00:00 2001
From: Florin Popa 
Date: Wed, 15 Jan 2025 09:15:23 +
Subject: [PATCH] [Clang][Arch]Disable mve.fp when explicit -mfpu option

-mfpu=fpv5-d16 or -mfpu=fpv5-sp-d16 disables the scalar half-precision 
floating-point operations feature. Therefore, because the M-profile Vector 
Extension (MVE) floating-point feature requires the scalar half-precision 
floating-point operations, this option also disables the MVE floating-point 
feature, -mve.fp
---
 clang/lib/Driver/ToolChains/Arch/ARM.cpp | 9 +
 1 file changed, 9 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/Arch/ARM.cpp 
b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
index b8181ce6dc012a..cec2c4f24d676d 100644
--- a/clang/lib/Driver/ToolChains/Arch/ARM.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
@@ -748,6 +748,15 @@ llvm::ARM::FPUKind arm::getARMTargetFeatures(const Driver 
&D,
   Features.push_back("-crc");
   }
 
+  // Invalid value of the __ARM_FEATURE_MVE macro when an explicit -mfpu= 
option
+  // disables MVE-FP -mfpu=fpv5-d16 or -mfpu=fpv5-sp-d16 disables the scalar
+  // half-precision floating-point operations feature. Therefore, because the
+  // M-profile Vector Extension (MVE) floating-point feature requires the 
scalar
+  // half-precision floating-point operations, this option also disables the 
MVE
+  // floating-point feature: -mve.fp
+  if (FPUKind == llvm::ARM::FK_FPV5_D16 || FPUKind == 
llvm::ARM::FK_FPV5_SP_D16)
+Features.push_back("-mve.fp");
+
   // For Arch >= ARMv8.0 && A or R profile:  crypto = sha2 + aes
   // Rather than replace within the feature vector, determine whether each
   // algorithm is enabled and append this to the end of the vector.

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


[clang] [Clang][Arch] Disable mve.fp when explicit -mfpu option (PR #123028)

2025-01-15 Thread via cfe-commits

github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write 
permissions for the repository. In which case you can instead tag reviewers by 
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a 
review by "ping"ing the PR by adding a comment “Ping”. The common courtesy 
"ping" rate is once a week. Please remember that you are asking for valuable 
time from other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

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


[clang] [CMake] Add a cache file for building a highly-optimized LLVM toolchain (PR #117802)

2025-01-15 Thread Petr Hosek via cfe-commits

petrhosek wrote:

These cache files seem to be largely the same as 
[PGO.cmake](https://github.com/llvm/llvm-project/blob/4cec0ba92955c353c52efe728b2cfef3fbdf60f8/clang/cmake/caches/PGO.cmake),
 
[PGO-stage2.cmake](https://github.com/llvm/llvm-project/blob/04b002bbb838bc502bd6d5f602af95efd6cc96b3/clang/cmake/caches/PGO-stage2.cmake),
 
[PGO-stage2-instrumented.cmake](https://github.com/llvm/llvm-project/blob/04b002bbb838bc502bd6d5f602af95efd6cc96b3/clang/cmake/caches/PGO-stage2-instrumented.cmake),
 the only difference appears to be the inclusion of BOLT. Do we really need 
separate cache files for that? Could we just extend the existing files?

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


[clang] Patch series to reapply #118734 and substantially improve it (PR #120534)

2025-01-15 Thread Chandler Carruth via cfe-commits

chandlerc wrote:

> @dyung -- this PR is updated with new fixes. NVPTX hopefully works and 
> neither of my debugging checks fires. But there may still be some other 
> failures I need to chase down, let me know?

Hmm, looks like there are likely to be ARM and Hexagon failures remaining at 
least. An interesting question is whether there are any AArch64 failures as if 
so that will end all ideas I have to dodge this miscompile. I've now pushed a 
new update (cf4762f) that should help isolate exactly which targets continue to 
hit this.

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


[clang] e33f456 - Fixed some warn-override tests in SemaCXX (#122680)

2025-01-15 Thread via cfe-commits

Author: LoS
Date: 2025-01-15T12:26:36+01:00
New Revision: e33f456ae591559883e89a1f18b2dec21225e90f

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

LOG: Fixed some warn-override tests in SemaCXX (#122680)

The `.cpp` extension have been added to test files, so that they can be
runned. Besides, the `warn-suggest-override.cpp` tests have been fixed.

-

Co-authored-by: LoS 

Added: 
clang/test/SemaCXX/warn-inconsistent-missing-destructor-override.cpp
clang/test/SemaCXX/warn-suggest-destructor-override.cpp
clang/test/SemaCXX/warn-suggest-override.cpp

Modified: 


Removed: 
clang/test/SemaCXX/warn-inconsistent-missing-destructor-override
clang/test/SemaCXX/warn-suggest-destructor-override
clang/test/SemaCXX/warn-suggest-override



diff  --git a/clang/test/SemaCXX/warn-inconsistent-missing-destructor-override 
b/clang/test/SemaCXX/warn-inconsistent-missing-destructor-override.cpp
similarity index 100%
rename from clang/test/SemaCXX/warn-inconsistent-missing-destructor-override
rename to clang/test/SemaCXX/warn-inconsistent-missing-destructor-override.cpp

diff  --git a/clang/test/SemaCXX/warn-suggest-destructor-override 
b/clang/test/SemaCXX/warn-suggest-destructor-override.cpp
similarity index 100%
rename from clang/test/SemaCXX/warn-suggest-destructor-override
rename to clang/test/SemaCXX/warn-suggest-destructor-override.cpp

diff  --git a/clang/test/SemaCXX/warn-suggest-override 
b/clang/test/SemaCXX/warn-suggest-override.cpp
similarity index 58%
rename from clang/test/SemaCXX/warn-suggest-override
rename to clang/test/SemaCXX/warn-suggest-override.cpp
index e06c939ff001fc..c4b5149c681a40 100644
--- a/clang/test/SemaCXX/warn-suggest-override
+++ b/clang/test/SemaCXX/warn-suggest-override.cpp
@@ -17,13 +17,13 @@ struct C {
 
 struct D : public C {
   void run();
-  // expected-warning@-1 {{'run()' overrides a member function but is not 
marked 'override'}}
+  // expected-warning@-1 {{'run' overrides a member function but is not marked 
'override'}}
   ~D();
 };
 
 struct E : public C {
   virtual void run();
-  // expected-warning@-1 {{'run()' overrides a member function but is not 
marked 'override'}}
+  // expected-warning@-1 {{'run' overrides a member function but is not marked 
'override'}}
   virtual ~E();
 };
 
@@ -32,7 +32,8 @@ struct F : public C {
   ~F() override;
 };
 
-struct G : public C {
+struct G : public C { // expected-note {{mark 'G' as 'final'}}
   void run() final;
   ~G() final;
+  // expected-warning@-1 {{class with destructor marked 'final' cannot be 
inherited from}}
 };



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


[clang] Fixed some warn-override tests in SemaCXX (PR #122680)

2025-01-15 Thread via cfe-commits

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


[clang] [clang] Add support for passing FileSystem to buildASTFromCodeWithArgs() (PR #123042)

2025-01-15 Thread Boaz Brickner via cfe-commits

https://github.com/bricknerb updated 
https://github.com/llvm/llvm-project/pull/123042

>From 197fa433e56c875b4098806576f14b33a37a4300 Mon Sep 17 00:00:00 2001
From: Boaz Brickner 
Date: Wed, 15 Jan 2025 11:48:20 +0100
Subject: [PATCH 1/2] [clang] Add support for passing FileSystem to
 buildASTFromCodeWithArgs()

---
 clang/include/clang/Tooling/Tooling.h   |  7 ++-
 clang/lib/Tooling/Tooling.cpp   |  5 +++--
 clang/unittests/Tooling/ToolingTest.cpp | 14 ++
 3 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/Tooling/Tooling.h 
b/clang/include/clang/Tooling/Tooling.h
index 070706e8fa6d11..30ee02d2cf5f12 100644
--- a/clang/include/clang/Tooling/Tooling.h
+++ b/clang/include/clang/Tooling/Tooling.h
@@ -225,6 +225,9 @@ buildASTFromCode(StringRef Code, StringRef FileName = 
"input.cc",
 ///
 /// \param Adjuster A function to filter the command line arguments as 
specified.
 ///
+/// \param FileSystem FileSystem for managing and looking up files.
+///
+///
 /// \return The resulting AST or null if an error occurred.
 std::unique_ptr buildASTFromCodeWithArgs(
 StringRef Code, const std::vector &Args,
@@ -233,7 +236,9 @@ std::unique_ptr buildASTFromCodeWithArgs(
 std::make_shared(),
 ArgumentsAdjuster Adjuster = getClangStripDependencyFileAdjuster(),
 const FileContentMappings &VirtualMappedFiles = FileContentMappings(),
-DiagnosticConsumer *DiagConsumer = nullptr);
+DiagnosticConsumer *DiagConsumer = nullptr,
+IntrusiveRefCntPtr FileSystem =
+llvm::vfs::getRealFileSystem());
 
 /// Utility to run a FrontendAction in a single clang invocation.
 class ToolInvocation {
diff --git a/clang/lib/Tooling/Tooling.cpp b/clang/lib/Tooling/Tooling.cpp
index 88b7349ce8fed6..385811d3dab9e1 100644
--- a/clang/lib/Tooling/Tooling.cpp
+++ b/clang/lib/Tooling/Tooling.cpp
@@ -692,11 +692,12 @@ std::unique_ptr buildASTFromCodeWithArgs(
 StringRef Code, const std::vector &Args, StringRef FileName,
 StringRef ToolName, std::shared_ptr 
PCHContainerOps,
 ArgumentsAdjuster Adjuster, const FileContentMappings &VirtualMappedFiles,
-DiagnosticConsumer *DiagConsumer) {
+DiagnosticConsumer *DiagConsumer,
+IntrusiveRefCntPtr FileSystem) {
   std::vector> ASTs;
   ASTBuilderAction Action(ASTs);
   llvm::IntrusiveRefCntPtr OverlayFileSystem(
-  new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem()));
+  new llvm::vfs::OverlayFileSystem(FileSystem));
   llvm::IntrusiveRefCntPtr InMemoryFileSystem(
   new llvm::vfs::InMemoryFileSystem);
   OverlayFileSystem->pushOverlay(InMemoryFileSystem);
diff --git a/clang/unittests/Tooling/ToolingTest.cpp 
b/clang/unittests/Tooling/ToolingTest.cpp
index 0b65577a05193f..8cdfffb54390e0 100644
--- a/clang/unittests/Tooling/ToolingTest.cpp
+++ b/clang/unittests/Tooling/ToolingTest.cpp
@@ -152,6 +152,20 @@ TEST(buildASTFromCode, ReportsErrors) {
   EXPECT_EQ(1u, Consumer.NumDiagnosticsSeen);
 }
 
+TEST(buildASTFromCode, FileSystem) {
+  llvm::IntrusiveRefCntPtr InMemoryFileSystem(
+  new llvm::vfs::InMemoryFileSystem);
+  InMemoryFileSystem->addFile("included_file.h", 0,
+  llvm::MemoryBuffer::getMemBufferCopy("class 
X;"));
+  std::unique_ptr AST = buildASTFromCodeWithArgs(
+  R"(#include "included_file.h")", {}, "input.cc", "clang-tool",
+  std::make_shared(),
+  getClangStripDependencyFileAdjuster(), FileContentMappings(), nullptr,
+  InMemoryFileSystem);
+  ASSERT_TRUE(AST.get());
+  EXPECT_TRUE(FindClassDeclX(AST.get()));
+}
+
 TEST(newFrontendActionFactory, CreatesFrontendActionFactoryFromType) {
   std::unique_ptr Factory(
   newFrontendActionFactory());

>From c56f7e98c6c1484da6dbe56db5a8b408e65038a3 Mon Sep 17 00:00:00 2001
From: Boaz Brickner 
Date: Wed, 15 Jan 2025 12:26:43 +0100
Subject: [PATCH 2/2] Fix formatting

---
 clang/include/clang/Tooling/Tooling.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Tooling/Tooling.h 
b/clang/include/clang/Tooling/Tooling.h
index 30ee02d2cf5f12..473157f08e9ab3 100644
--- a/clang/include/clang/Tooling/Tooling.h
+++ b/clang/include/clang/Tooling/Tooling.h
@@ -223,7 +223,8 @@ buildASTFromCode(StringRef Code, StringRef FileName = 
"input.cc",
 /// \param PCHContainerOps The PCHContainerOperations for loading and creating
 /// clang modules.
 ///
-/// \param Adjuster A function to filter the command line arguments as 
specified.
+/// \param Adjuster A function to filter the command line arguments as
+/// specified.
 ///
 /// \param FileSystem FileSystem for managing and looking up files.
 ///

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


[clang] Fixed some warn-override tests in SemaCXX (PR #122680)

2025-01-15 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`clang-cmake-x86_64-avx512-linux` running on `avx512-intel64` while building 
`clang` at step 12 "setup lit".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/133/builds/9735


Here is the relevant piece of the build log for the reference

```
Step 12 (setup lit) failure: 
'/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/test/sandbox/bin/python
 
/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/test/lnt/setup.py
 ...' (failure)
...
no previously-included directories found matching 'tests/*/Output'
no previously-included directories found matching 'tests/*/*/Output'
adding license file 'LICENSE.TXT'
writing manifest file 'LNT.egg-info/SOURCES.txt'
running build_ext
copying 
build/lib.linux-x86_64-cpython-39/lnt/testing/profile/cPerf.cpython-39-x86_64-linux-gnu.so
 -> lnt/testing/profile
Creating 
/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/test/sandbox/lib64/python3.9/site-packages/LNT.egg-link
 (link to .)
Adding LNT 0.4.2.dev0 to easy-install.pth file
Installing lnt script to 
/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/test/sandbox/bin

Installed 
/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/test/lnt
Processing dependencies for LNT==0.4.2.dev0
Searching for certifi
Reading https://pypi.org/simple/certifi/
Downloading 
https://files.pythonhosted.org/packages/a5/32/8f6669fc4798494966bf446c8c4a162e0b5d893dff088afddf76414f70e1/certifi-2024.12.14-py3-none-any.whl#sha256=1275f7a45be9464efc1173084eaa30f866fe2e47d389406136d332ed4967ec56
Best match: certifi 2024.12.14
Processing certifi-2024.12.14-py3-none-any.whl
Installing certifi-2024.12.14-py3-none-any.whl to 
/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/test/sandbox/lib64/python3.9/site-packages
Adding certifi 2024.12.14 to easy-install.pth file

Installed 
/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/test/sandbox/lib64/python3.9/site-packages/certifi-2024.12.14-py3.9.egg
Searching for lit==0.11.1
Reading https://pypi.org/simple/lit/
Downloading 
https://files.pythonhosted.org/packages/c8/20/a1c3f83acd15874d953b26f87d94d92bde23d614a711c9e75f60744df2f3/lit-0.11.1-py3-none-any.whl#sha256=4fa0cafcedf9e278d4ffa69bfa1a0482db41fdb1d055c8b9fc29501511abeb16
Best match: lit 0.11.1
Processing lit-0.11.1-py3-none-any.whl
Installing lit-0.11.1-py3-none-any.whl to 
/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/test/sandbox/lib64/python3.9/site-packages
Adding lit 0.11.1 to easy-install.pth file
detected new path './certifi-2024.12.14-py3.9.egg'
Installing lit script to 
/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/test/sandbox/bin

Installed 
/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/test/sandbox/lib64/python3.9/site-packages/lit-0.11.1-py3.9.egg
Searching for requests
Reading https://pypi.org/simple/requests/
Downloading 
https://files.pythonhosted.org/packages/f9/9b/335f9764261e915ed497fcdeb11df5dfd6f7bf257d4a6a2a686d80da4d54/requests-2.32.3-py3-none-any.whl#sha256=70761cfe03c773ceb22aa2f671b4757976145175cdfca038c02654d061d6dcc6
Best match: requests 2.32.3
Processing requests-2.32.3-py3-none-any.whl
Installing requests-2.32.3-py3-none-any.whl to 
/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/test/sandbox/lib64/python3.9/site-packages
Adding requests 2.32.3 to easy-install.pth file
detected new path './lit-0.11.1-py3.9.egg'

Installed 
/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/test/sandbox/lib64/python3.9/site-packages/requests-2.32.3-py3.9.egg
Searching for pyyaml==5.1.2
Reading https://pypi.org/simple/pyyaml/
Download error on https://pypi.org/simple/pyyaml/: [Errno -2] Name or service 
not known -- Some packages may not be found!
Couldn't find index page for 'pyyaml' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading https://pypi.org/simple/
No local packages or working download links found for pyyaml==5.1.2
error: Could not find suitable distribution for 
Requirement.parse('pyyaml==5.1.2')

```



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


[clang] [flang] [Flang][Driver] Add a flag to control zero initialization of global v… (PR #122144)

2025-01-15 Thread Kiran Chandramohan via cfe-commits

https://github.com/kiranchandramohan updated 
https://github.com/llvm/llvm-project/pull/122144

>From 483501549b910d1e91dab05cce65793c44aaa6f6 Mon Sep 17 00:00:00 2001
From: Kiran Chandramohan 
Date: Wed, 8 Jan 2025 17:26:24 +
Subject: [PATCH 1/6] [Flang][Driver] Add a flag to control zero initialization
 of global variables

Patch adds a flag to control zero initialization of global variables
without default initialization. The default is to zero initialize.
---
 clang/include/clang/Driver/Options.td |  3 +++
 clang/lib/Driver/ToolChains/Flang.cpp |  1 +
 flang/include/flang/Lower/LoweringOptions.def |  3 +++
 flang/lib/Frontend/CompilerInvocation.cpp |  6 ++
 flang/lib/Lower/ConvertVariable.cpp   |  6 +-
 flang/test/Driver/fno-zero-init.f90   |  5 +
 flang/test/Lower/zero_init.f90| 16 
 flang/test/Lower/zero_init_default_init.f90   | 18 ++
 8 files changed, 57 insertions(+), 1 deletion(-)
 create mode 100644 flang/test/Driver/fno-zero-init.f90
 create mode 100644 flang/test/Lower/zero_init.f90
 create mode 100644 flang/test/Lower/zero_init_default_init.f90

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 52823430919de4..e8d18cf78e985a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3494,6 +3494,9 @@ def fno_struct_path_tbaa : Flag<["-"], 
"fno-struct-path-tbaa">, Group;
 def fno_strict_enums : Flag<["-"], "fno-strict-enums">, Group;
 def fno_strict_overflow : Flag<["-"], "fno-strict-overflow">, Group,
   Visibility<[ClangOption, FlangOption]>;
+def fno_zero_init_global_without_init : Flag<["-"], 
"fno-zero-init-global-without-init">, Group,
+  Visibility<[FlangOption, FC1Option]>,
+  HelpText<"Do not zero initialize globals without default initialization">;
 def fno_pointer_tbaa : Flag<["-"], "fno-pointer-tbaa">, Group;
 def fno_temp_file : Flag<["-"], "fno-temp-file">, Group,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>, HelpText<
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 75b10e88371ae7..609f5315426977 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -153,6 +153,7 @@ void Flang::addCodegenOptions(const ArgList &Args,
   Args.addAllArgs(CmdArgs, {options::OPT_flang_experimental_hlfir,
 options::OPT_flang_deprecated_no_hlfir,
 options::OPT_fno_ppc_native_vec_elem_order,
+options::OPT_fno_zero_init_global_without_init,
 options::OPT_fppc_native_vec_elem_order});
 }
 
diff --git a/flang/include/flang/Lower/LoweringOptions.def 
b/flang/include/flang/Lower/LoweringOptions.def
index 5a6debfdffe030..acce21f5faab8b 100644
--- a/flang/include/flang/Lower/LoweringOptions.def
+++ b/flang/include/flang/Lower/LoweringOptions.def
@@ -44,5 +44,8 @@ ENUM_LOWERINGOPT(IntegerWrapAround, unsigned, 1, 0)
 /// If false, assume that the shapes/types/allocation-status match.
 ENUM_LOWERINGOPT(ReallocateLHS, unsigned, 1, 1)
 
+/// If true, initialize globals without initialization to zero.
+/// On by default.
+ENUM_LOWERINGOPT(ZeroInitGlobalsWithoutInit, unsigned, 1, 1)
 #undef LOWERINGOPT
 #undef ENUM_LOWERINGOPT
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index 340efb1c63a5e5..fa91a0e2642bc8 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -1373,6 +1373,12 @@ bool CompilerInvocation::createFromArgs(
 invoc.loweringOpts.setNoPPCNativeVecElemOrder(true);
   }
 
+  // -fno-zero-init-global-without-init
+  if (args.hasArg(
+  clang::driver::options::OPT_fno_zero_init_global_without_init)) {
+invoc.loweringOpts.setZeroInitGlobalsWithoutInit(false);
+  }
+
   // Preserve all the remark options requested, i.e. -Rpass, -Rpass-missed or
   // -Rpass-analysis. This will be used later when processing and outputting 
the
   // remarks generated by LLVM in ExecuteCompilerInvocation.cpp.
diff --git a/flang/lib/Lower/ConvertVariable.cpp 
b/flang/lib/Lower/ConvertVariable.cpp
index 9ee42d5cd88002..db8a57d416274c 100644
--- a/flang/lib/Lower/ConvertVariable.cpp
+++ b/flang/lib/Lower/ConvertVariable.cpp
@@ -635,7 +635,11 @@ static fir::GlobalOp 
defineGlobal(Fortran::lower::AbstractConverter &converter,
   global.setLinkName(builder.createCommonLinkage());
 Fortran::lower::createGlobalInitialization(
 builder, global, [&](fir::FirOpBuilder &builder) {
-  mlir::Value initValue = builder.create(loc, symTy);
+  mlir::Value initValue;
+  if (converter.getLoweringOptions().getZeroInitGlobalsWithoutInit())
+initValue = builder.create(loc, symTy);
+  else
+initValue = builder.create(loc, symTy);
   builder.create(loc, 

[clang] [llvm] [RISCV] Add MIPS extensions (PR #121394)

2025-01-15 Thread Djordje Todorovic via cfe-commits


@@ -0,0 +1,370 @@
+//===- RISCVLoadStoreOptimizer.cpp 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Bundle loads and stores that operate on consecutive memory locations to take
+// the advantage of hardware load/store bonding.
+//
+//===--===//
+
+#include "RISCV.h"
+#include "RISCVTargetMachine.h"
+#include "llvm/Analysis/AliasAnalysis.h"
+#include "llvm/CodeGen/Passes.h"
+#include "llvm/MC/TargetRegistry.h"
+#include "llvm/Support/Debug.h"
+#include "llvm/Target/TargetOptions.h"
+
+using namespace llvm;
+
+#define DEBUG_TYPE "riscv-load-store-opt"
+#define RISCV_LOAD_STORE_OPT_NAME "RISCV Load / Store Optimizer"
+namespace {
+
+struct RISCVLoadStoreOpt : public MachineFunctionPass {
+  static char ID;
+  bool runOnMachineFunction(MachineFunction &Fn) override;
+
+  RISCVLoadStoreOpt() : MachineFunctionPass(ID) {}
+
+  MachineFunctionProperties getRequiredProperties() const override {
+return MachineFunctionProperties().set(
+MachineFunctionProperties::Property::NoVRegs);
+  }
+
+  void getAnalysisUsage(AnalysisUsage &AU) const override {
+AU.addRequired();
+MachineFunctionPass::getAnalysisUsage(AU);
+  }
+
+  StringRef getPassName() const override { return RISCV_LOAD_STORE_OPT_NAME; }
+
+  // Find and pair load/store instructions.
+  bool tryToPairLdStInst(MachineBasicBlock::iterator &MBBI);
+
+  // Convert load/store pairs to single instructions.
+  bool tryConvertToLdStPair(MachineBasicBlock::iterator First,
+MachineBasicBlock::iterator Second);
+
+  // Scan the instructions looking for a load/store that can be combined
+  // with the current instruction into a load/store pair.
+  // Return the matching instruction if one is found, else MBB->end().
+  MachineBasicBlock::iterator findMatchingInsn(MachineBasicBlock::iterator I,
+   bool &MergeForward);
+
+  MachineBasicBlock::iterator
+  mergePairedInsns(MachineBasicBlock::iterator I,
+   MachineBasicBlock::iterator Paired, bool MergeForward);
+
+private:
+  AliasAnalysis *AA;
+  MachineRegisterInfo *MRI;
+  const RISCVInstrInfo *TII;
+  const RISCVRegisterInfo *TRI;
+  LiveRegUnits ModifiedRegUnits, UsedRegUnits;
+  bool UseLoadStorePair = false;
+};
+} // end anonymous namespace
+
+char RISCVLoadStoreOpt::ID = 0;
+INITIALIZE_PASS(RISCVLoadStoreOpt, DEBUG_TYPE, RISCV_LOAD_STORE_OPT_NAME, 
false,
+false)
+
+bool RISCVLoadStoreOpt::runOnMachineFunction(MachineFunction &Fn) {
+  if (skipFunction(Fn.getFunction()))
+return false;
+  const RISCVSubtarget &Subtarget = Fn.getSubtarget();
+
+  if (!Subtarget.useLoadStorePairs())
+return false;
+
+  bool MadeChange = false;
+  TII = Subtarget.getInstrInfo();
+  TRI = Subtarget.getRegisterInfo();
+  MRI = &Fn.getRegInfo();
+  AA = &getAnalysis().getAAResults();
+  ModifiedRegUnits.init(*TRI);
+  UsedRegUnits.init(*TRI);
+  UseLoadStorePair = Subtarget.useLoadStorePairs();

djtodoro wrote:

No need any more, thanks

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


[clang] [llvm] [RISCV] Add MIPS extensions (PR #121394)

2025-01-15 Thread Djordje Todorovic via cfe-commits


@@ -389,6 +390,13 @@ class RISCVPassConfig : public TargetPassConfig {
   DAG->addMutation(createStoreClusterDAGMutation(
   DAG->TII, DAG->TRI, /*ReorderWhileClustering=*/true));
 }
+
+const RISCVSubtarget &ST = C->MF->getSubtarget();
+if (!ST.getMacroFusions().empty() && ST.useLoadStorePairs()) {

djtodoro wrote:

Hm, I agree

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


[clang] [llvm] [RISCV] Add MIPS extensions (PR #121394)

2025-01-15 Thread Djordje Todorovic via cfe-commits


@@ -257,6 +257,146 @@ def simm12 : RISCVSImmLeafOp<12> {
   }];
 }
 
+// A 7-bit unsigned immediate where the least significant two bits are zero.

djtodoro wrote:

No need any more, thanks

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


[clang] [llvm] [RISCV] Add MIPS extensions (PR #121394)

2025-01-15 Thread Djordje Todorovic via cfe-commits


@@ -0,0 +1,82 @@
+//===-- RISCVInstrInfoXMips.td -*- tablegen 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file describes the vendor extensions defined by MIPS.
+//
+//===--===//
+
+//===--===//
+
+// MIPS extensions
+//===--===//
+
+let Predicates = [HasVendorMIPSCMove], hasSideEffects = 0, mayLoad = 0, 
mayStore = 0, DecoderNamespace = "Xmipscomve" in {
+def CCMOV : RVInstR4<0b11, 0b011, OPC_CUSTOM_0, (outs GPR:$rd),
+(ins GPR:$rs1, GPR:$rs2, GPR:$rs3),
+"ccmov", "$rd, $rs2, $rs1, $rs3">,

djtodoro wrote:

Yep, I have added it. The PR for `mips.` prefix is here 
https://github.com/riscv-non-isa/riscv-toolchain-conventions/pull/69.

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


[clang] [C++20] [Modules] Makes sure internal declaration won't be found by other TU (PR #123059)

2025-01-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-modules

Author: Chuanqi Xu (ChuanqiXu9)


Changes

Close https://github.com/llvm/llvm-project/issues/61427

And this is also helpful to implement
https://github.com/llvm/llvm-project/issues/112294 partially.

The implementation strategy mimics
https://github.com/llvm/llvm-project/pull/122887. This patch split the internal 
declarations from the general lookup table so that other TU can't find the 
internal declarations.

---

Patch is 40.52 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/123059.diff


11 Files Affected:

- (modified) clang/include/clang/Serialization/ASTBitCodes.h (+6) 
- (modified) clang/include/clang/Serialization/ASTReader.h (+19-1) 
- (modified) clang/include/clang/Serialization/ASTWriter.h (+9-2) 
- (modified) clang/lib/Serialization/ASTReader.cpp (+74-15) 
- (modified) clang/lib/Serialization/ASTReaderDecl.cpp (+35-10) 
- (modified) clang/lib/Serialization/ASTWriter.cpp (+155-61) 
- (modified) clang/lib/Serialization/ASTWriterDecl.cpp (+11-1) 
- (modified) clang/test/CXX/basic/basic.lookup/basic.lookup.argdep/p5-ex2.cpp 
(+2-2) 
- (modified) clang/test/CXX/basic/basic.scope/basic.scope.namespace/p2.cpp 
(+2-10) 
- (modified) clang/test/CXX/module/basic/basic.def.odr/p4.cppm (-5) 
- (modified) clang/test/CXX/module/basic/basic.link/p2.cppm (+5-8) 


``diff
diff --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization/ASTBitCodes.h
index 40dae25f7b54b7..d568d2fd7aa301 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -740,6 +740,8 @@ enum ASTRecordTypes {
   CXX_ADDED_TEMPLATE_PARTIAL_SPECIALIZATION = 75,
 
   UPDATE_MODULE_LOCAL_VISIBLE = 76,
+
+  UPDATE_TU_LOCAL_VISIBLE = 77,
 };
 
 /// Record types used within a source manager block.
@@ -1340,6 +1342,10 @@ enum DeclCode {
   /// only visible from DeclContext in the same module.
   DECL_CONTEXT_MODULE_LOCAL_VISIBLE,
 
+  /// A record that stores the set of declarations that are only visible
+  /// to the TU.
+  DECL_CONTEXT_TU_LOCAL_VISIBLE,
+
   /// A LabelDecl record.
   DECL_LABEL,
 
diff --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index ea12adaec3ee81..1459c9f9b083f1 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -528,6 +528,7 @@ class ASTReader
 uint64_t LexicalOffset;
 uint64_t VisibleOffset;
 uint64_t ModuleLocalOffset;
+uint64_t TULocalOffset;
   };
 
   using DelayedNamespaceOffsetMapTy =
@@ -640,6 +641,9 @@ class ASTReader
   llvm::DenseMap
   ModuleLocalLookups;
+  llvm::DenseMap
+  TULocalLookups;
 
   using SpecLookupTableTy =
   llvm::DenseMap 
PendingVisibleUpdates;
   llvm::DenseMap
   PendingModuleLocalVisibleUpdates;
+  llvm::DenseMap TULocalUpdates;
 
   using SpecializationsUpdate = SmallVector;
   using SpecializationsUpdateMap =
@@ -704,11 +709,17 @@ class ASTReader
  llvm::BitstreamCursor &Cursor,
  uint64_t Offset, DeclContext *DC);
 
+  enum class VisibleDeclContextStorageKind {
+GenerallyVisible,
+ModuleLocalVisible,
+TULocalVisible,
+  };
+
   /// Read the record that describes the visible contents of a DC.
   bool ReadVisibleDeclContextStorage(ModuleFile &M,
  llvm::BitstreamCursor &Cursor,
  uint64_t Offset, GlobalDeclID ID,
- bool IsModuleLocal);
+ VisibleDeclContextStorageKind 
VisibleKind);
 
   bool ReadSpecializations(ModuleFile &M, llvm::BitstreamCursor &Cursor,
uint64_t Offset, Decl *D, bool IsPartial);
@@ -1148,6 +1159,10 @@ class ASTReader
   unsigned NumModuleLocalVisibleDeclContexts = 0,
TotalModuleLocalVisibleDeclContexts = 0;
 
+  /// Number of TU Local decl contexts read/total
+  unsigned NumTULocalVisibleDeclContexts = 0,
+   TotalTULocalVisibleDeclContexts = 0;
+
   /// Total size of modules, in bits, currently loaded
   uint64_t TotalModulesSizeInBits = 0;
 
@@ -1463,6 +1478,9 @@ class ASTReader
   const serialization::reader::ModuleLocalLookupTable *
   getModuleLocalLookupTables(DeclContext *Primary) const;
 
+  const serialization::reader::DeclContextLookupTable *
+  getTULocalLookupTables(DeclContext *Primary) const;
+
   /// Get the loaded specializations lookup tables for \p D,
   /// if any.
   serialization::reader::LazySpecializationInfoLookupTable *
diff --git a/clang/include/clang/Serialization/ASTWriter.h 
b/clang/include/clang/Serialization/ASTWriter.h
index 53b09cc914392e..079e39a9fb678b 100644
--- a/clang/include/clang/Serialization/ASTWriter.h
+++ b/clang/include/clang/Serialization/ASTWriter.h
@@ -496,6 +496,9 @@ class ASTWriter : public ASTDeser

[clang] [llvm] [LLVM][Clang][AArch64] Implement AArch64 build attributes (PR #118771)

2025-01-15 Thread via cfe-commits


@@ -7806,6 +7815,267 @@ bool 
AArch64AsmParser::parseDirectiveSEHSaveAnyReg(SMLoc L, bool Paired,
   return false;
 }
 
+bool AArch64AsmParser::parseDirectiveAeabiSubSectionHeader(SMLoc L) {
+  // Expecting 3 AsmToken::Identifier after '.aeabi_subsection', a name and 2
+  // parameters, e.g.: .aeabi_subsection (1)aeabi_feature_and_bits, 
(2)optional,
+  // (3)uleb128 separated by 2 commas.
+  MCAsmParser &Parser = getParser();
+
+  bool HasActiveSubsection = true;
+  std::unique_ptr ActiveSubsection =
+  getTargetStreamer().getActiveAtributesSubsection();
+  if (nullptr == ActiveSubsection) {
+HasActiveSubsection = false;
+  }
+
+  // Consume the name (subsection name)
+  StringRef SubsectionName;
+  AArch64BuildAttributes::VendorID SubsectionNameID;
+  if (Parser.getTok().is(AsmToken::Identifier)) {
+SubsectionName = Parser.getTok().getIdentifier();
+SubsectionNameID = AArch64BuildAttributes::getVendorID(SubsectionName);
+  } else {
+Error(Parser.getTok().getLoc(), "subsection name not found");
+return true;
+  }
+  Parser.Lex();
+  // consume a comma
+  // parseComma() return *false* on success, and call Lex(), no need to call
+  // Lex() again.
+  if (Parser.parseComma()) {
+return true;
+  }
+
+  // Consume the first parameter (optionality parameter)
+  AArch64BuildAttributes::SubsectionOptional IsOptional;
+  // options: optional/required
+  if (Parser.getTok().is(AsmToken::Identifier)) {
+StringRef Optionality = Parser.getTok().getIdentifier();
+IsOptional = AArch64BuildAttributes::getOptionalID(Optionality);
+if (AArch64BuildAttributes::OPTIONAL_NOT_FOUND == IsOptional) {
+  Error(Parser.getTok().getLoc(),
+AArch64BuildAttributes::getSubsectionOptionalUnknownError() + ": " 
+
+Optionality);
+  return true;
+}
+if (HasActiveSubsection &&
+(SubsectionName == ActiveSubsection->VendorName)) {
+  if (IsOptional != ActiveSubsection->IsOptional) {
+Error(Parser.getTok().getLoc(),
+  "optionality mismatch! subsection '" + SubsectionName +
+  "' already exists with optionality defined as '" +
+  Twine(ActiveSubsection->IsOptional) + "' and not '" +
+  Twine(IsOptional) + "' (0: required, 1: optional)");
+return true;
+  }
+}
+  } else {
+Error(Parser.getTok().getLoc(),
+  "optionality parameter not found, expected required|optinal");
+return true;
+  }
+  // Check for possible IsOptional unaccepted values for known subsections
+  if (AArch64BuildAttributes::AEABI_FEATURE_AND_BITS == SubsectionNameID) {
+if (AArch64BuildAttributes::REQUIRED == IsOptional) {
+  Error(Parser.getTok().getLoc(),
+"aeabi_feature_and_bits must be marked as optional");
+  return true;
+}
+  }
+  if (AArch64BuildAttributes::AEABI_PAUTHABI == SubsectionNameID) {
+if (AArch64BuildAttributes::OPTIONAL == IsOptional) {
+  Error(Parser.getTok().getLoc(),
+"aeabi_pauthabi must be marked as required");
+  return true;
+}
+  }
+  Parser.Lex();
+  // consume a comma
+  if (Parser.parseComma()) {
+return true;
+  }
+
+  // Consume the second parameter (type parameter)
+  AArch64BuildAttributes::SubsectionType Type;
+  if (Parser.getTok().is(AsmToken::Identifier)) {
+StringRef Name = Parser.getTok().getIdentifier();
+Type = AArch64BuildAttributes::getTypeID(Name);
+if (AArch64BuildAttributes::TYPE_NOT_FOUND == Type) {
+  Error(Parser.getTok().getLoc(),
+AArch64BuildAttributes::getSubsectionTypeUnknownError() + ": " +
+Name);
+  return true;
+}
+if (HasActiveSubsection &&
+(SubsectionName == ActiveSubsection->VendorName)) {

sivan-shani wrote:

fixed + test added

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


[clang] [clang-tools-extra] [clang][refactor] Refactor `findNextTokenIncludingComments` (PR #123060)

2025-01-15 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-tidy

Author: Clement Courbet (legrosbuffle)


Changes

We have two copies of the same code in clang-tidy and clang-reorder-fields, and 
those are extremenly similar to `Lexer::findNextToken`, so just add an extra 
agument to the latter.

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


7 Files Affected:

- (modified) clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp 
(+3-31) 
- (modified) 
clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp (+1-1) 
- (modified) clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp (+2-3) 
- (modified) clang-tools-extra/clang-tidy/utils/LexerUtils.cpp (-23) 
- (modified) clang-tools-extra/clang-tidy/utils/LexerUtils.h (-4) 
- (modified) clang/include/clang/Lex/Lexer.h (+2-1) 
- (modified) clang/lib/Lex/Lexer.cpp (+3-1) 


``diff
diff --git a/clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp 
b/clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp
index 80ee31368fe9a5..40c96f92254e42 100644
--- a/clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp
+++ b/clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp
@@ -118,35 +118,6 @@ findMembersUsedInInitExpr(const CXXCtorInitializer 
*Initializer,
   return Results;
 }
 
-/// Returns the next token after `Loc` (including comment tokens).
-static std::optional getTokenAfter(SourceLocation Loc,
-  const SourceManager &SM,
-  const LangOptions &LangOpts) {
-  if (Loc.isMacroID()) {
-return std::nullopt;
-  }
-  Loc = Lexer::getLocForEndOfToken(Loc, 0, SM, LangOpts);
-
-  // Break down the source location.
-  std::pair LocInfo = SM.getDecomposedLoc(Loc);
-
-  // Try to load the file buffer.
-  bool InvalidTemp = false;
-  StringRef File = SM.getBufferData(LocInfo.first, &InvalidTemp);
-  if (InvalidTemp)
-return std::nullopt;
-
-  const char *TokenBegin = File.data() + LocInfo.second;
-
-  Lexer lexer(SM.getLocForStartOfFile(LocInfo.first), LangOpts, File.begin(),
-  TokenBegin, File.end());
-  lexer.SetCommentRetentionState(true);
-  // Find the token.
-  Token Tok;
-  lexer.LexFromRawLexer(Tok);
-  return Tok;
-}
-
 /// Returns the end of the trailing comments after `Loc`.
 static SourceLocation getEndOfTrailingComment(SourceLocation Loc,
   const SourceManager &SM,
@@ -154,11 +125,12 @@ static SourceLocation 
getEndOfTrailingComment(SourceLocation Loc,
   // We consider any following comment token that is indented more than the
   // first comment to be part of the trailing comment.
   const unsigned Column = SM.getPresumedColumnNumber(Loc);
-  std::optional Tok = getTokenAfter(Loc, SM, LangOpts);
+  std::optional Tok =
+  Lexer::findNextToken(Loc, SM, LangOpts, /*IncludeComments*/ true);
   while (Tok && Tok->is(tok::comment) &&
  SM.getPresumedColumnNumber(Tok->getLocation()) > Column) {
 Loc = Tok->getEndLoc();
-Tok = getTokenAfter(Loc, SM, LangOpts);
+Tok = Lexer::findNextToken(Loc, SM, LangOpts, /*IncludeComments*/ true);
   }
   return Loc;
 }
diff --git 
a/clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
index d24b613015d8ee..b4f54d02fc3362 100644
--- a/clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
@@ -59,7 +59,7 @@ SourceRange NS::getNamespaceBackRange(const SourceManager &SM,
   // Back from '}' to conditional '// namespace xxx'
   SourceLocation Loc = front()->getRBraceLoc();
   std::optional Tok =
-  utils::lexer::findNextTokenIncludingComments(Loc, SM, LangOpts);
+  Lexer::findNextToken(Loc, SM, LangOpts, /*IncludeComments*/ true);
   if (!Tok)
 return getDefaultNamespaceBackRange();
   if (Tok->getKind() != tok::TokenKind::comment)
diff --git a/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
index fd5bd9f0b181b1..6191ebfbfb01f0 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
@@ -229,9 +229,8 @@ void UseOverrideCheck::check(const MatchFinder::MatchResult 
&Result) {
   if (HasVirtual) {
 for (Token Tok : Tokens) {
   if (Tok.is(tok::kw_virtual)) {
-std::optional NextToken =
-utils::lexer::findNextTokenIncludingComments(
-Tok.getEndLoc(), Sources, getLangOpts());
+std::optional NextToken = Lexer::findNextToken(
+Tok.getEndLoc(), Sources, getLangOpts(), /*IncludeComments*/ true);
 if (NextToken.has_value()) {
   Diag << FixItHint::CreateRemoval(CharSourceRange::getCharRange(
   Tok.getLocation(), NextToken->getLocati

[clang] [FMV][AArch64][clang] Advance __FUNCTION_MULTI_VERSIONING_SUPPORT_LEVEL to ACLE Q3 (PR #123056)

2025-01-15 Thread Jonathan Thackray via cfe-commits

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

LGTM

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


[clang] [clang-tools-extra] [clang][refactor] Refactor `findNextTokenIncludingComments` (PR #123060)

2025-01-15 Thread Clement Courbet via cfe-commits

https://github.com/legrosbuffle created 
https://github.com/llvm/llvm-project/pull/123060

We have two copies of the same code in clang-tidy and clang-reorder-fields, and 
those are extremenly similar to `Lexer::findNextToken`, so just add an extra 
agument to the latter.

>From cb9d5e978474b0a5cadb0d7125826427425fc2d6 Mon Sep 17 00:00:00 2001
From: Clement Courbet 
Date: Wed, 15 Jan 2025 12:19:58 +
Subject: [PATCH] [clang][refactor] Refactor `findNextTokenIncludingComments`

We have two copies of the same code in clang-tidy and
clang-reorder-fields, and those are extremenly similar to
`Lexer::findNextToken`, so just add an extra agument to the latter.
---
 .../ReorderFieldsAction.cpp   | 34 ++-
 .../modernize/ConcatNestedNamespacesCheck.cpp |  2 +-
 .../clang-tidy/modernize/UseOverrideCheck.cpp |  5 ++-
 .../clang-tidy/utils/LexerUtils.cpp   | 23 -
 .../clang-tidy/utils/LexerUtils.h |  4 ---
 clang/include/clang/Lex/Lexer.h   |  3 +-
 clang/lib/Lex/Lexer.cpp   |  4 ++-
 7 files changed, 11 insertions(+), 64 deletions(-)

diff --git a/clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp 
b/clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp
index 80ee31368fe9a5..40c96f92254e42 100644
--- a/clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp
+++ b/clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp
@@ -118,35 +118,6 @@ findMembersUsedInInitExpr(const CXXCtorInitializer 
*Initializer,
   return Results;
 }
 
-/// Returns the next token after `Loc` (including comment tokens).
-static std::optional getTokenAfter(SourceLocation Loc,
-  const SourceManager &SM,
-  const LangOptions &LangOpts) {
-  if (Loc.isMacroID()) {
-return std::nullopt;
-  }
-  Loc = Lexer::getLocForEndOfToken(Loc, 0, SM, LangOpts);
-
-  // Break down the source location.
-  std::pair LocInfo = SM.getDecomposedLoc(Loc);
-
-  // Try to load the file buffer.
-  bool InvalidTemp = false;
-  StringRef File = SM.getBufferData(LocInfo.first, &InvalidTemp);
-  if (InvalidTemp)
-return std::nullopt;
-
-  const char *TokenBegin = File.data() + LocInfo.second;
-
-  Lexer lexer(SM.getLocForStartOfFile(LocInfo.first), LangOpts, File.begin(),
-  TokenBegin, File.end());
-  lexer.SetCommentRetentionState(true);
-  // Find the token.
-  Token Tok;
-  lexer.LexFromRawLexer(Tok);
-  return Tok;
-}
-
 /// Returns the end of the trailing comments after `Loc`.
 static SourceLocation getEndOfTrailingComment(SourceLocation Loc,
   const SourceManager &SM,
@@ -154,11 +125,12 @@ static SourceLocation 
getEndOfTrailingComment(SourceLocation Loc,
   // We consider any following comment token that is indented more than the
   // first comment to be part of the trailing comment.
   const unsigned Column = SM.getPresumedColumnNumber(Loc);
-  std::optional Tok = getTokenAfter(Loc, SM, LangOpts);
+  std::optional Tok =
+  Lexer::findNextToken(Loc, SM, LangOpts, /*IncludeComments*/ true);
   while (Tok && Tok->is(tok::comment) &&
  SM.getPresumedColumnNumber(Tok->getLocation()) > Column) {
 Loc = Tok->getEndLoc();
-Tok = getTokenAfter(Loc, SM, LangOpts);
+Tok = Lexer::findNextToken(Loc, SM, LangOpts, /*IncludeComments*/ true);
   }
   return Loc;
 }
diff --git 
a/clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
index d24b613015d8ee..b4f54d02fc3362 100644
--- a/clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
@@ -59,7 +59,7 @@ SourceRange NS::getNamespaceBackRange(const SourceManager &SM,
   // Back from '}' to conditional '// namespace xxx'
   SourceLocation Loc = front()->getRBraceLoc();
   std::optional Tok =
-  utils::lexer::findNextTokenIncludingComments(Loc, SM, LangOpts);
+  Lexer::findNextToken(Loc, SM, LangOpts, /*IncludeComments*/ true);
   if (!Tok)
 return getDefaultNamespaceBackRange();
   if (Tok->getKind() != tok::TokenKind::comment)
diff --git a/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
index fd5bd9f0b181b1..6191ebfbfb01f0 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
@@ -229,9 +229,8 @@ void UseOverrideCheck::check(const MatchFinder::MatchResult 
&Result) {
   if (HasVirtual) {
 for (Token Tok : Tokens) {
   if (Tok.is(tok::kw_virtual)) {
-std::optional NextToken =
-utils::lexer::findNextTokenIncludingComments(
-Tok.getEndLoc(), Sources, getLangOpts());
+std::optional NextToken = Lexer::findNextToken(
+Tok.getEndL

[clang] [libcxx] [Clang] emit -Wignored-qualifiers diagnostic for cv-qualified base classes (PR #121419)

2025-01-15 Thread Oleksandr T. via cfe-commits

a-tarasyuk wrote:

@ldionne could you take a look at the latest changes? thanks

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


[clang] [HLSL][RootSignature] Implement Lexing of DescriptorTables (PR #122981)

2025-01-15 Thread Ashley Coleman via cfe-commits


@@ -0,0 +1,130 @@
+//=== ParseHLSLRootSignatureTest.cpp - Parse Root Signature tests 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/DiagnosticOptions.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/Basic/LangOptions.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Basic/TargetInfo.h"
+#include "clang/Lex/HeaderSearch.h"
+#include "clang/Lex/HeaderSearchOptions.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Lex/ModuleLoader.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Lex/PreprocessorOptions.h"
+
+#include "clang/Parse/ParseHLSLRootSignature.h"
+#include "gtest/gtest.h"
+
+using namespace llvm::hlsl::root_signature;
+using namespace clang;
+
+namespace {
+
+// The test fixture.
+class ParseHLSLRootSignatureTest : public ::testing::Test {
+protected:
+  ParseHLSLRootSignatureTest()
+  : FileMgr(FileMgrOpts), DiagID(new DiagnosticIDs()),
+Diags(DiagID, new DiagnosticOptions, new IgnoringDiagConsumer()),
+SourceMgr(Diags, FileMgr), TargetOpts(new TargetOptions) {
+TargetOpts->Triple = "x86_64-apple-darwin11.1.0";
+Target = TargetInfo::CreateTargetInfo(Diags, TargetOpts);
+  }
+
+  Preprocessor *CreatePP(StringRef Source, TrivialModuleLoader &ModLoader) {
+std::unique_ptr Buf =
+llvm::MemoryBuffer::getMemBuffer(Source);
+SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(Buf)));
+
+HeaderSearch HeaderInfo(std::make_shared(), SourceMgr,
+Diags, LangOpts, Target.get());
+Preprocessor *PP =
+new Preprocessor(std::make_shared(), Diags,

V-FEXrt wrote:

imo unless you have a strong reason for it, you should _really_ avoid 
new/delete and instead use C++ smart pointers for allocating/freeing heap 
memory. It takes care of the memory management for you and prevents accidental 
memory leaks.

In this case, `std::unique_ptr` would work perfectly 
https://en.cppreference.com/w/cpp/memory/unique_ptr


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


[clang] [HLSL][RootSignature] Implement Lexing of DescriptorTables (PR #122981)

2025-01-15 Thread Ashley Coleman via cfe-commits


@@ -0,0 +1,152 @@
+#include "clang/Parse/ParseHLSLRootSignature.h"
+
+namespace llvm {
+namespace hlsl {
+namespace root_signature {
+
+// Lexer Definitions
+
+static bool IsPreprocessorNumberChar(char C) {
+  // TODO: extend for float support with or without hexadecimal/exponent
+  return isdigit(C); // integer support
+}
+
+bool RootSignatureLexer::LexNumber(RootSignatureToken &Result) {
+  // NumericLiteralParser does not handle the sign so we will manually apply it
+  Result.Signed = Buffer.front() == '-';
+  if (Result.Signed)
+AdvanceBuffer();
+
+  // Retrieve the possible number
+  StringRef NumSpelling = Buffer.take_while(IsPreprocessorNumberChar);
+
+  // Parse the numeric value and so semantic checks on its specification
+  clang::NumericLiteralParser Literal(NumSpelling, SourceLoc,
+  PP.getSourceManager(), PP.getLangOpts(),
+  PP.getTargetInfo(), PP.getDiagnostics());
+  if (Literal.hadError)
+return true; // Error has already been reported so just return
+
+  // Retrieve the number value to store into the token
+  if (Literal.isIntegerLiteral()) {
+Result.Kind = TokenKind::int_literal;
+
+APSInt X = APSInt(32, Result.Signed);
+if (Literal.GetIntegerValue(X))
+  return true; // TODO: Report overflow error
+
+X = Result.Signed ? -X : X;
+Result.IntLiteral = (uint32_t)X.getZExtValue();
+  } else {
+return true; // TODO: report unsupported number literal specification
+  }
+
+  AdvanceBuffer(NumSpelling.size());
+  return false;
+}
+
+bool RootSignatureLexer::Lex(SmallVector &Tokens) {
+  // Discard any leading whitespace
+  AdvanceBuffer(Buffer.take_while(isspace).size());
+
+  while (!Buffer.empty()) {
+RootSignatureToken Result;
+if (LexToken(Result))
+  return true;
+
+// Successfully Lexed the token so we can store it
+Tokens.push_back(Result);
+
+// Discard any trailing whitespace
+AdvanceBuffer(Buffer.take_while(isspace).size());
+  }
+
+  return false;
+}
+
+bool RootSignatureLexer::LexToken(RootSignatureToken &Result) {
+  // Record where this token is in the text for usage in parser diagnostics
+  Result.TokLoc = SourceLoc;
+
+  char C = Buffer.front();
+
+  // Punctuators
+  switch (C) {
+#define PUNCTUATOR(X, Y)   
\
+  case Y: {
\
+Result.Kind = TokenKind::pu_##X;   
\
+AdvanceBuffer();   
\
+return false;  
\
+  }
+#include "clang/Parse/HLSLRootSignatureTokenKinds.def"

V-FEXrt wrote:

Is there a particular reason you define `PUNCTUATOR` both here and in the 
`.def` file? It makes the `.def` file harder to follow since the `#define 
PUNCTUATOR` there isn't actually used

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


[clang] [HLSL][RootSignature] Implement Lexing of DescriptorTables (PR #122981)

2025-01-15 Thread Ashley Coleman via cfe-commits


@@ -0,0 +1,152 @@
+#include "clang/Parse/ParseHLSLRootSignature.h"
+
+namespace llvm {
+namespace hlsl {
+namespace root_signature {
+
+// Lexer Definitions
+
+static bool IsPreprocessorNumberChar(char C) {
+  // TODO: extend for float support with or without hexadecimal/exponent
+  return isdigit(C); // integer support
+}
+
+bool RootSignatureLexer::LexNumber(RootSignatureToken &Result) {
+  // NumericLiteralParser does not handle the sign so we will manually apply it
+  Result.Signed = Buffer.front() == '-';
+  if (Result.Signed)
+AdvanceBuffer();
+
+  // Retrieve the possible number
+  StringRef NumSpelling = Buffer.take_while(IsPreprocessorNumberChar);
+
+  // Parse the numeric value and so semantic checks on its specification
+  clang::NumericLiteralParser Literal(NumSpelling, SourceLoc,
+  PP.getSourceManager(), PP.getLangOpts(),
+  PP.getTargetInfo(), PP.getDiagnostics());
+  if (Literal.hadError)
+return true; // Error has already been reported so just return
+
+  // Retrieve the number value to store into the token
+  if (Literal.isIntegerLiteral()) {
+Result.Kind = TokenKind::int_literal;
+
+APSInt X = APSInt(32, Result.Signed);
+if (Literal.GetIntegerValue(X))
+  return true; // TODO: Report overflow error
+
+X = Result.Signed ? -X : X;
+Result.IntLiteral = (uint32_t)X.getZExtValue();
+  } else {
+return true; // TODO: report unsupported number literal specification
+  }
+
+  AdvanceBuffer(NumSpelling.size());
+  return false;
+}
+
+bool RootSignatureLexer::Lex(SmallVector &Tokens) {
+  // Discard any leading whitespace
+  AdvanceBuffer(Buffer.take_while(isspace).size());
+
+  while (!Buffer.empty()) {
+RootSignatureToken Result;
+if (LexToken(Result))
+  return true;
+
+// Successfully Lexed the token so we can store it
+Tokens.push_back(Result);
+
+// Discard any trailing whitespace
+AdvanceBuffer(Buffer.take_while(isspace).size());
+  }
+
+  return false;
+}
+
+bool RootSignatureLexer::LexToken(RootSignatureToken &Result) {
+  // Record where this token is in the text for usage in parser diagnostics
+  Result.TokLoc = SourceLoc;
+
+  char C = Buffer.front();
+
+  // Punctuators
+  switch (C) {
+#define PUNCTUATOR(X, Y)   
\
+  case Y: {
\
+Result.Kind = TokenKind::pu_##X;   
\
+AdvanceBuffer();   
\
+return false;  
\
+  }
+#include "clang/Parse/HLSLRootSignatureTokenKinds.def"

V-FEXrt wrote:

if it must always be defined before inclusion you could do

```
#ifndef PUNCTUATOR 
#error some message
#endif
```

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


[clang] [HLSL][RootSignature] Implement Lexing of DescriptorTables (PR #122981)

2025-01-15 Thread Ashley Coleman via cfe-commits


@@ -0,0 +1,152 @@
+#include "clang/Parse/ParseHLSLRootSignature.h"
+
+namespace llvm {
+namespace hlsl {
+namespace root_signature {
+
+// Lexer Definitions
+
+static bool IsPreprocessorNumberChar(char C) {
+  // TODO: extend for float support with or without hexadecimal/exponent
+  return isdigit(C); // integer support
+}
+
+bool RootSignatureLexer::LexNumber(RootSignatureToken &Result) {
+  // NumericLiteralParser does not handle the sign so we will manually apply it
+  Result.Signed = Buffer.front() == '-';

V-FEXrt wrote:

I'm assuming no, but is unary `+` allowed here?

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


[clang] [HLSL][RootSignature] Implement Lexing of DescriptorTables (PR #122981)

2025-01-15 Thread Ashley Coleman via cfe-commits


@@ -0,0 +1,152 @@
+#include "clang/Parse/ParseHLSLRootSignature.h"
+
+namespace llvm {
+namespace hlsl {
+namespace root_signature {
+
+// Lexer Definitions
+
+static bool IsPreprocessorNumberChar(char C) {
+  // TODO: extend for float support with or without hexadecimal/exponent
+  return isdigit(C); // integer support
+}
+
+bool RootSignatureLexer::LexNumber(RootSignatureToken &Result) {
+  // NumericLiteralParser does not handle the sign so we will manually apply it
+  Result.Signed = Buffer.front() == '-';
+  if (Result.Signed)
+AdvanceBuffer();
+
+  // Retrieve the possible number
+  StringRef NumSpelling = Buffer.take_while(IsPreprocessorNumberChar);
+
+  // Parse the numeric value and so semantic checks on its specification
+  clang::NumericLiteralParser Literal(NumSpelling, SourceLoc,
+  PP.getSourceManager(), PP.getLangOpts(),
+  PP.getTargetInfo(), PP.getDiagnostics());
+  if (Literal.hadError)
+return true; // Error has already been reported so just return
+
+  // Retrieve the number value to store into the token
+  if (Literal.isIntegerLiteral()) {
+Result.Kind = TokenKind::int_literal;
+
+APSInt X = APSInt(32, Result.Signed);
+if (Literal.GetIntegerValue(X))
+  return true; // TODO: Report overflow error
+
+X = Result.Signed ? -X : X;
+Result.IntLiteral = (uint32_t)X.getZExtValue();
+  } else {
+return true; // TODO: report unsupported number literal specification
+  }

V-FEXrt wrote:

nit: invert the condition and early exit

```suggestion
  if (!Literal.isIntegerLiteral()) {
return true; // TODO: report unsupported number literal specification
  }
  
  Result.Kind = TokenKind::int_literal;

  APSInt X = APSInt(32, Result.Signed);
  if (Literal.GetIntegerValue(X))
return true; // TODO: Report overflow error

  X = Result.Signed ? -X : X;
  Result.IntLiteral = (uint32_t)X.getZExtValue();
```

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


[clang] [HLSL][RootSignature] Implement Lexing of DescriptorTables (PR #122981)

2025-01-15 Thread Ashley Coleman via cfe-commits

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


  1   2   3   4   5   >