[clang] [Driver][MSVC] Pass profile file to lld-link via -lto-sample-profile option (PR #127442)

2025-02-18 Thread via cfe-commits

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


[clang] [clang][X86] Only define __CET__ macro for X86 targets (PR #127616)

2025-02-18 Thread Ming-Yi Lai via cfe-commits

mylai-mtk wrote:

> Can you update the description to mention which PR makes RISCV targets 
> inspect -fcf-protection=?

Added PR links. Thanks!

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


[clang] [Driver][MSVC] Add lto-sample-profile option for lld-link (PR #127442)

2025-02-18 Thread via cfe-commits

https://github.com/tianleliu updated 
https://github.com/llvm/llvm-project/pull/127442

>From ad4d2857220e5e5b31cd66a79eac7d8dca438864 Mon Sep 17 00:00:00 2001
From: tianleli 
Date: Mon, 17 Feb 2025 11:24:10 +0800
Subject: [PATCH 1/3] [SPGO][Driver] Add lto-sample-profile option for lld-link

SPGO in lto mode, linker needs -lto-sample-profile option to set
sample profile file. Linux adds this option by transfering
fprofile-sample-use but lld-link on Windows misses the transfering.
So add it now.
---
 clang/lib/Driver/ToolChains/MSVC.cpp | 3 +++
 clang/test/Driver/cl-link.c  | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/MSVC.cpp 
b/clang/lib/Driver/ToolChains/MSVC.cpp
index bae41fc06c036..1c6854e3ef775 100644
--- a/clang/lib/Driver/ToolChains/MSVC.cpp
+++ b/clang/lib/Driver/ToolChains/MSVC.cpp
@@ -232,6 +232,9 @@ void visualstudio::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
 }
   }
 
+  if (Arg *A = Args.getLastArg(options::OPT_fprofile_sample_use_EQ))
+CmdArgs.push_back(Args.MakeArgString(std::string("-lto-sample-profile:") +
+ A->getValue()));
   Args.AddAllArgValues(CmdArgs, options::OPT__SLASH_link);
 
   // Control Flow Guard checks
diff --git a/clang/test/Driver/cl-link.c b/clang/test/Driver/cl-link.c
index 9bf8a8137926d..f1097ad0be9bf 100644
--- a/clang/test/Driver/cl-link.c
+++ b/clang/test/Driver/cl-link.c
@@ -71,3 +71,6 @@
 // RUN: %clang_cl -m32 -arch:IA32 --target=i386-pc-win32 /Tc%s -fuse-ld=lld 
-### -fsanitize=address 2>&1 | FileCheck --check-prefix=INFER-LLD %s
 // INFER-LLD: lld-link
 // INFER-LLD-NOT: INFERASANLIBS
+
+// RUN: %clang_cl --target=x86_64-unknown-windows-msvc -fuse-ld=lld -### -S 
-fprofile-sample-use=%S/Inputs/file.prof %s 2>&1 | FileCheck 
-check-prefix=CHECK-SAMPLE-PROFILE %s
+// CHECK-SAMPLE-PROFILE: "-lto-sample-profile:{{.*}}/file.prof"

>From 1a61846294298a6800be225f8fe6c8ebacc0a9d1 Mon Sep 17 00:00:00 2001
From: tianleli 
Date: Mon, 17 Feb 2025 15:50:51 +0800
Subject: [PATCH 2/3] Add flto condition for the option.

---
 clang/lib/Driver/ToolChains/MSVC.cpp | 8 +---
 clang/test/Driver/cl-link.c  | 2 +-
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/MSVC.cpp 
b/clang/lib/Driver/ToolChains/MSVC.cpp
index 1c6854e3ef775..18b1b0330bcf7 100644
--- a/clang/lib/Driver/ToolChains/MSVC.cpp
+++ b/clang/lib/Driver/ToolChains/MSVC.cpp
@@ -232,9 +232,11 @@ void visualstudio::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
 }
   }
 
-  if (Arg *A = Args.getLastArg(options::OPT_fprofile_sample_use_EQ))
-CmdArgs.push_back(Args.MakeArgString(std::string("-lto-sample-profile:") +
- A->getValue()));
+  if (C.getDriver().isUsingLTO()) {
+if (Arg *A = Args.getLastArg(options::OPT_fprofile_sample_use_EQ))
+  CmdArgs.push_back(Args.MakeArgString(std::string("-lto-sample-profile:") 
+
+   A->getValue()));
+  }
   Args.AddAllArgValues(CmdArgs, options::OPT__SLASH_link);
 
   // Control Flow Guard checks
diff --git a/clang/test/Driver/cl-link.c b/clang/test/Driver/cl-link.c
index f1097ad0be9bf..3fd7dccec2267 100644
--- a/clang/test/Driver/cl-link.c
+++ b/clang/test/Driver/cl-link.c
@@ -72,5 +72,5 @@
 // INFER-LLD: lld-link
 // INFER-LLD-NOT: INFERASANLIBS
 
-// RUN: %clang_cl --target=x86_64-unknown-windows-msvc -fuse-ld=lld -### -S 
-fprofile-sample-use=%S/Inputs/file.prof %s 2>&1 | FileCheck 
-check-prefix=CHECK-SAMPLE-PROFILE %s
+// RUN: %clang_cl --target=x86_64-unknown-windows-msvc -flto -fuse-ld=lld -### 
-S -fprofile-sample-use=%S/Inputs/file.prof %s 2>&1 | FileCheck 
-check-prefix=CHECK-SAMPLE-PROFILE %s
 // CHECK-SAMPLE-PROFILE: "-lto-sample-profile:{{.*}}/file.prof"

>From 54e5be4b4327f66359d6aa41aee8ae1005b8612b Mon Sep 17 00:00:00 2001
From: tianleli 
Date: Wed, 19 Feb 2025 11:11:49 +0800
Subject: [PATCH 3/3] Use getLastProfileSampleUseArg instead and remove -S in
 test.

---
 clang/lib/Driver/ToolChains/MSVC.cpp | 2 +-
 clang/test/Driver/cl-link.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/MSVC.cpp 
b/clang/lib/Driver/ToolChains/MSVC.cpp
index 18b1b0330bcf7..d5a7fc7e85230 100644
--- a/clang/lib/Driver/ToolChains/MSVC.cpp
+++ b/clang/lib/Driver/ToolChains/MSVC.cpp
@@ -233,7 +233,7 @@ void visualstudio::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   }
 
   if (C.getDriver().isUsingLTO()) {
-if (Arg *A = Args.getLastArg(options::OPT_fprofile_sample_use_EQ))
+if (Arg *A = tools::getLastProfileSampleUseArg(Args))
   CmdArgs.push_back(Args.MakeArgString(std::string("-lto-sample-profile:") 
+
A->getValue()));
   }
diff --git a/clang/test/Driver/cl-link.c b/clang/test/Driver/cl-link.c
index 3fd7dccec2267..726bc26a64edd 100644
--- a/clang/test/Driver/cl-link.c
+++ b/clang/test/Driver/cl-li

[clang] Inital support for privavate variable reduction (PR #127740)

2025-02-18 Thread CHANDRA GHALE via cfe-commits

https://github.com/chandraghale created 
https://github.com/llvm/llvm-project/pull/127740

None

>From cf392f05f9499fd0621ffec91a3b852d4b91820b Mon Sep 17 00:00:00 2001
From: Chandra Ghale 
Date: Tue, 18 Feb 2025 21:24:22 -0600
Subject: [PATCH] Inital support for privavate variable reduction

---
 clang/include/clang/Basic/OpenMPKinds.def |  7 +++
 clang/include/clang/Basic/OpenMPKinds.h   |  7 +++
 clang/include/clang/Sema/SemaOpenMP.h |  5 +-
 clang/lib/Parse/ParseOpenMP.cpp   | 27 ++
 clang/lib/Sema/SemaOpenMP.cpp | 65 +++
 5 files changed, 101 insertions(+), 10 deletions(-)

diff --git a/clang/include/clang/Basic/OpenMPKinds.def 
b/clang/include/clang/Basic/OpenMPKinds.def
index 3f25e7aafe23b..4f8396dc34ea8 100644
--- a/clang/include/clang/Basic/OpenMPKinds.def
+++ b/clang/include/clang/Basic/OpenMPKinds.def
@@ -71,6 +71,9 @@
 #ifndef OPENMP_REDUCTION_MODIFIER
 #define OPENMP_REDUCTION_MODIFIER(Name)
 #endif
+#ifndef OPENMP_ORIGINAL_SHARING_MODIFIER
+#define OPENMP_ORIGINAL_SHARING_MODIFIER(Name)
+#endif
 #ifndef OPENMP_ADJUST_ARGS_KIND
 #define OPENMP_ADJUST_ARGS_KIND(Name)
 #endif
@@ -202,6 +205,9 @@ OPENMP_REDUCTION_MODIFIER(default)
 OPENMP_REDUCTION_MODIFIER(inscan)
 OPENMP_REDUCTION_MODIFIER(task)
 
+OPENMP_ORIGINAL_SHARING_MODIFIER(shared)
+OPENMP_ORIGINAL_SHARING_MODIFIER(private)
+
 // Adjust-op kinds for the 'adjust_args' clause.
 OPENMP_ADJUST_ARGS_KIND(nothing)
 OPENMP_ADJUST_ARGS_KIND(need_device_ptr)
@@ -231,6 +237,7 @@ OPENMP_DOACROSS_MODIFIER(source_omp_cur_iteration)
 #undef OPENMP_BIND_KIND
 #undef OPENMP_ADJUST_ARGS_KIND
 #undef OPENMP_REDUCTION_MODIFIER
+#undef OPENMP_ORIGINAL_SHARING_MODIFIER
 #undef OPENMP_DEVICE_MODIFIER
 #undef OPENMP_ORDER_KIND
 #undef OPENMP_ORDER_MODIFIER
diff --git a/clang/include/clang/Basic/OpenMPKinds.h 
b/clang/include/clang/Basic/OpenMPKinds.h
index 900ad6ca6d66f..bbadda9fb03b4 100644
--- a/clang/include/clang/Basic/OpenMPKinds.h
+++ b/clang/include/clang/Basic/OpenMPKinds.h
@@ -190,6 +190,13 @@ enum OpenMPReductionClauseModifier {
   OMPC_REDUCTION_unknown,
 };
 
+/// OpenMP original sharing modifiers
+enum OpenMPOriginalSharingModifier {
+#define OPENMP_ORIGINAL_SHARING_MODIFIER(Name) OMPC_ORIGINAL_SHARING_##Name,
+#include "clang/Basic/OpenMPKinds.def"
+  OMPC_ORIGINAL_SHARING_default,
+};
+
 /// OpenMP adjust-op kinds for 'adjust_args' clause.
 enum OpenMPAdjustArgsOpKind {
 #define OPENMP_ADJUST_ARGS_KIND(Name) OMPC_ADJUST_ARGS_##Name,
diff --git a/clang/include/clang/Sema/SemaOpenMP.h 
b/clang/include/clang/Sema/SemaOpenMP.h
index 3d1cc4fab1c10..40e300f099826 100644
--- a/clang/include/clang/Sema/SemaOpenMP.h
+++ b/clang/include/clang/Sema/SemaOpenMP.h
@@ -1136,6 +1136,7 @@ class SemaOpenMP : public SemaBase {
 DeclarationNameInfo ReductionOrMapperId;
 int ExtraModifier = -1; ///< Additional modifier for linear, map, depend or
 ///< lastprivate clause.
+int OriginalSharingModifier = 0;  // Default is shared
 SmallVector
 MapTypeModifiers;
 SmallVector
@@ -1145,6 +1146,7 @@ class SemaOpenMP : public SemaBase {
 SmallVector MotionModifiersLoc;
 bool IsMapTypeImplicit = false;
 SourceLocation ExtraModifierLoc;
+SourceLocation OriginalSharingModifierLoc;
 SourceLocation OmpAllMemoryLoc;
 SourceLocation
 StepModifierLoc; /// 'step' modifier location for linear clause
@@ -1197,7 +1199,8 @@ class SemaOpenMP : public SemaBase {
   SourceLocation ModifierLoc, SourceLocation ColonLoc,
   SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec,
   const DeclarationNameInfo &ReductionId,
-  ArrayRef UnresolvedReductions = {});
+  ArrayRef UnresolvedReductions = {}, 
+  OpenMPOriginalSharingModifier OriginalShareModifier = 
OMPC_ORIGINAL_SHARING_default);
   /// Called on well-formed 'task_reduction' clause.
   OMPClause *ActOnOpenMPTaskReductionClause(
   ArrayRef VarList, SourceLocation StartLoc,
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index b4e973bc84a7b..f59ecd93de6d3 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -4594,6 +4594,33 @@ bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind 
DKind,
   assert(Tok.is(tok::comma) && "Expected comma.");
   (void)ConsumeToken();
 }
+// Handle original(private / shared) Modifier
+if (Kind == OMPC_reduction && getLangOpts().OpenMP >= 60  &&
+Tok.is(tok::identifier) && PP.getSpelling(Tok) == "original" &&
+NextToken().is(tok::l_paren)) {
+  // Parse original(private) modifier.
+  ConsumeToken(); 
+  BalancedDelimiterTracker ParenT(*this, tok::l_paren, tok::r_paren);
+  ParenT.consumeOpen();
+  if (Tok.is(tok::kw_private)) {
+Data.OriginalSharingModifier = OMPC_ORIGINAL_SHARING_private;
+Data.OriginalSharingModifierLoc = Tok.getLocation();
+ConsumeToken(); 
+  }
+  else if (Tok.is(tok::

[clang] [clang][LoongArch] Add OHOS target (PR #127555)

2025-02-18 Thread via cfe-commits

https://github.com/Ami-zhang updated 
https://github.com/llvm/llvm-project/pull/127555

>From c6df3aa9b9769d096d2cd63fc2353665ec9edbd1 Mon Sep 17 00:00:00 2001
From: Ami-zhang 
Date: Tue, 18 Feb 2025 10:00:25 +0800
Subject: [PATCH] [clang][LoongArch] Add OHOS target

Add support for OHOS on loongarch64.
---
 clang/lib/Basic/Targets.cpp  | 10 --
 clang/lib/Driver/ToolChains/OHOS.cpp |  6 +-
 clang/test/Preprocessor/ohos.c   |  2 ++
 3 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index 281aebdb1c35d..c6d228fe98100 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -749,8 +749,14 @@ std::unique_ptr AllocateTarget(const 
llvm::Triple &Triple,
   case llvm::Triple::loongarch64:
 switch (os) {
 case llvm::Triple::Linux:
-  return std::make_unique>(Triple,
-  Opts);
+  switch (Triple.getEnvironment()) {
+  default:
+return std::make_unique>(Triple,
+Opts);
+  case llvm::Triple::OpenHOS:
+return std::make_unique>(Triple,
+   Opts);
+  }
 case llvm::Triple::FreeBSD:
   return std::make_unique>(Triple,
 Opts);
diff --git a/clang/lib/Driver/ToolChains/OHOS.cpp 
b/clang/lib/Driver/ToolChains/OHOS.cpp
index 6e1a09ae908b2..e213c695a9fef 100644
--- a/clang/lib/Driver/ToolChains/OHOS.cpp
+++ b/clang/lib/Driver/ToolChains/OHOS.cpp
@@ -111,6 +111,8 @@ std::string OHOS::getMultiarchTriple(const llvm::Triple &T) 
const {
 return "x86_64-linux-ohos";
   case llvm::Triple::aarch64:
 return "aarch64-linux-ohos";
+  case llvm::Triple::loongarch64:
+return "loongarch64-linux-ohos";
   }
   return T.str();
 }
@@ -368,7 +370,9 @@ void OHOS::addExtraOpts(llvm::opt::ArgStringList &CmdArgs) 
const {
   CmdArgs.push_back("-z");
   CmdArgs.push_back("relro");
   CmdArgs.push_back("-z");
-  CmdArgs.push_back("max-page-size=4096");
+  CmdArgs.push_back(getArch() == llvm::Triple::loongarch64
+? "max-page-size=16384"
+: "max-page-size=4096");
   // .gnu.hash section is not compatible with the MIPS target
   if (getArch() != llvm::Triple::mipsel)
 CmdArgs.push_back("--hash-style=both");
diff --git a/clang/test/Preprocessor/ohos.c b/clang/test/Preprocessor/ohos.c
index 0c435c7ed5ab4..7017c9847ccae 100644
--- a/clang/test/Preprocessor/ohos.c
+++ b/clang/test/Preprocessor/ohos.c
@@ -3,6 +3,7 @@
 // RUN: %clang_cc1 -x c++ -E -dM -ffreestanding -triple=riscv64-linux-ohos < 
/dev/null | FileCheck %s -match-full-lines -check-prefix=RISCV64-OHOS-CXX
 // RUN: %clang_cc1 -x c++ -E -dM -ffreestanding -triple=mipsel-linux-ohos < 
/dev/null | FileCheck %s -match-full-lines -check-prefix=MIPSEL-OHOS-CXX
 // RUN: %clang_cc1 -x c++ -E -dM -ffreestanding -triple=x86_64-linux-ohos < 
/dev/null | FileCheck %s -match-full-lines -check-prefix=X86_64-OHOS-CXX
+// RUN: %clang_cc1 -x c++ -E -dM -ffreestanding -triple=loongarch64-linux-ohos 
< /dev/null | FileCheck %s -match-full-lines -check-prefix=LOONGARCH64-OHOS-CXX
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=arm-linux-ohos < /dev/null | 
FileCheck %s -check-prefix=OHOS-DEFS
 
 // ARM-OHOS-CXX: #define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 8U
@@ -10,6 +11,7 @@
 // RISCV64-OHOS-CXX: #define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 16UL
 // MIPSEL-OHOS-CXX: #define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 8U
 // X86_64-OHOS-CXX: #define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 16UL
+// LOONGARCH64-OHOS-CXX: #define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 16UL
 // OHOS-DEFS: __OHOS_FAMILY__
 // OHOS-DEFS: __OHOS__
 // OHOS-DEFS-NOT: __OHOS__

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


[clang] [CUDA] Add support for sm101 and sm120 target architectures (PR #127187)

2025-02-18 Thread Artem Belevich via cfe-commits

https://github.com/Artem-B approved this pull request.

LGTM. 

Do you need help merging the patch?

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


[clang] [-Wunsafe-buffer-usage] Add absl::{Span,string_view} to UnsafeBufferUsage analysis (PR #127698)

2025-02-18 Thread via cfe-commits

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


[clang-tools-extra] [clang-tidy]add new check bugprone-unintended-char-ostream-output (PR #127720)

2025-02-18 Thread via cfe-commits


@@ -0,0 +1,30 @@
+.. title:: clang-tidy - bugprone-unintended-char-ostream-output
+
+bugprone-unintended-char-ostream-output
+===
+
+Finds unintended character output from `unsigned char` and `signed char` to an

EugeneZelenko wrote:

Please synchronize with Release Notes.

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


[clang] [llvm] [RISCV] Assembler support for XRivosVizip (PR #127694)

2025-02-18 Thread Sam Elliott via cfe-commits


@@ -721,6 +721,8 @@ DecodeStatus RISCVDisassembler::getInstruction32(MCInst 
&MI, uint64_t &Size,
 "Qualcomm uC Conditional Move custom opcode table");
   TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXqciint, DecoderTableXqciint32,
 "Qualcomm uC Interrupts custom opcode table");
+  TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXRivosVizip, DecoderTableXRivos32,

lenary wrote:

I'm glad you've pointed this out, as it did seem like we are trying to 
side-step the encoding conflict checking that LLVM is capable of, as well as 
the fact that the decode tables will also check specific predicates for 
specific instructions.

I will look at merging all the Qualcomm decode tables, given that all the Xqci 
instructions are intended not to conflict with each other's encodings. I am 
less clear on which other vendor extensions should or should not conflict with 
each other.

I think the `TRY_TO_DECODE_FEATURE(...` encouraged one decode table per feature 
- it's relatively more difficult to write an equivalent for when you have any 
of a few different features - but we can solve this with yet more macros of 
course.

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


[clang] [clang][Tooling] Support relative directory in compilation database (PR #127734)

2025-02-18 Thread Keith Smiley via cfe-commits

https://github.com/keith updated 
https://github.com/llvm/llvm-project/pull/127734

>From b8c294fcd30153842e1c0741fc623f45317618b1 Mon Sep 17 00:00:00 2001
From: Keith Smiley 
Date: Wed, 19 Feb 2025 01:54:42 +
Subject: [PATCH] [clang][Tooling] Support relative directory in compilation
 database

This allows you to use `"directory": ".",` in `compile_commands.json`
and have it be understood for file lookup by `clangd`.
---
 clang/lib/Tooling/JSONCompilationDatabase.cpp |  1 +
 .../Tooling/CompilationDatabaseTest.cpp   | 26 +++
 2 files changed, 27 insertions(+)

diff --git a/clang/lib/Tooling/JSONCompilationDatabase.cpp 
b/clang/lib/Tooling/JSONCompilationDatabase.cpp
index 5ecba5dfece3d..625ac034d639a 100644
--- a/clang/lib/Tooling/JSONCompilationDatabase.cpp
+++ b/clang/lib/Tooling/JSONCompilationDatabase.cpp
@@ -419,6 +419,7 @@ bool JSONCompilationDatabase::parse(std::string 
&ErrorMessage) {
 if (llvm::sys::path::is_relative(FileName)) {
   SmallString<8> DirectoryStorage;
   SmallString<128> AbsolutePath(Directory->getValue(DirectoryStorage));
+  llvm::sys::fs::make_absolute(AbsolutePath);
   llvm::sys::path::append(AbsolutePath, FileName);
   llvm::sys::path::native(AbsolutePath, NativeFilePath);
 } else {
diff --git a/clang/unittests/Tooling/CompilationDatabaseTest.cpp 
b/clang/unittests/Tooling/CompilationDatabaseTest.cpp
index 2032b13726c45..0221d6a3c7177 100644
--- a/clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ b/clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -399,6 +399,32 @@ TEST(findCompileArgsInJsonDatabase, FindsEntry) {
   EXPECT_EQ("command4", FoundCommand.CommandLine[0]) << ErrorMessage;
 }
 
+TEST(findCompileArgsInJsonDatabase, FindsEntryRelativeDirectory) {
+  StringRef Directory(".");
+  StringRef FileName("file");
+  StringRef Command("command");
+  std::string JsonDatabase = "[";
+  JsonDatabase +=
+  ("{\"directory\":\"" + Directory + "\"," + "\"command\":\"" + Command +
+   "\","
+   "\"file\":\"" +
+   FileName + "\"}")
+  .str();
+  JsonDatabase += "]";
+
+  SmallString<256> Result;
+  llvm::sys::fs::current_path(Result);
+  llvm::sys::path::append(Result, FileName);
+
+  std::string ErrorMessage;
+  CompileCommand FoundCommand =
+  findCompileArgsInJsonDatabase(Result, JsonDatabase, ErrorMessage);
+
+  EXPECT_EQ(".", FoundCommand.Directory) << ErrorMessage;
+  ASSERT_EQ(1u, FoundCommand.CommandLine.size()) << ErrorMessage;
+  EXPECT_EQ("command", FoundCommand.CommandLine[0]) << ErrorMessage;
+}
+
 TEST(findCompileArgsInJsonDatabase, ParsesCompilerWrappers) {
   std::vector> Cases = {
   {"distcc gcc foo.c", "gcc foo.c"},

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


[clang] Check the type of Objective-C++ instance variables in WebKit member variable checkers. (PR #127570)

2025-02-18 Thread Rashmi Mudduluru via cfe-commits

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


[clang] [Driver][MSVC] Pass profile file to lld-link via -lto-sample-profile option (PR #127442)

2025-02-18 Thread Fangrui Song via cfe-commits

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


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


[clang] Check the type of Objective-C++ instance variables in WebKit member variable checkers. (PR #127570)

2025-02-18 Thread Rashmi Mudduluru via cfe-commits


@@ -87,6 +92,31 @@ class RawPtrRefMemberChecker
 }
   }
 
+  void visitObjCDecl(const ObjCContainerDecl *CD) const {
+if (auto *ID = dyn_cast(CD)) {

t-rasmud wrote:

Ah ok. I was wondering if we should check for dullness before dereferencing 
`ID` in the next line `ID->ivars()`

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


[clang] [flang] [flang][OpenMP] Upstream first part of `do concurrent` mapping (PR #126026)

2025-02-18 Thread Kareem Ergawy via cfe-commits

ergawy wrote:

@mjklemm suggested to add a warning that the pass is still experimental, which 
I think is a good idea. However, I am wondering what the best place for that 
warning would be? I prefer not to do that in 
`CodeGenAction::beginSourceFileAction()` (where we inspect the flag and 
actually use it) since that would emit one warning per source file and get 
annoying quickly. Any suggestions?

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


[clang] 6c39ee7 - [Driver][MSVC] Pass profile file to lld-link via -lto-sample-profile option (#127442)

2025-02-18 Thread via cfe-commits

Author: tianleliu
Date: 2025-02-19T12:45:45+08:00
New Revision: 6c39ee717f03a0fe28f563d525fa5aff09804ba8

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

LOG: [Driver][MSVC] Pass profile file to lld-link via -lto-sample-profile 
option (#127442)

In SPGO lto mode, linker needs -lto-sample-profile option to set sample
profile file.
Linux adds this option by transferring fprofile-sample-use to
-plugin-opt=sample-profile=, which is alias of lto-sample-profile. (in
clang\lib\Driver\ToolChains\CommonArgs.cpp: tools::addLTOOptions()).
But clang on Windows misses the transferring. So add it now.

Added: 


Modified: 
clang/lib/Driver/ToolChains/MSVC.cpp
clang/test/Driver/cl-link.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/MSVC.cpp 
b/clang/lib/Driver/ToolChains/MSVC.cpp
index bae41fc06c036..d5a7fc7e85230 100644
--- a/clang/lib/Driver/ToolChains/MSVC.cpp
+++ b/clang/lib/Driver/ToolChains/MSVC.cpp
@@ -232,6 +232,11 @@ void visualstudio::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
 }
   }
 
+  if (C.getDriver().isUsingLTO()) {
+if (Arg *A = tools::getLastProfileSampleUseArg(Args))
+  CmdArgs.push_back(Args.MakeArgString(std::string("-lto-sample-profile:") 
+
+   A->getValue()));
+  }
   Args.AddAllArgValues(CmdArgs, options::OPT__SLASH_link);
 
   // Control Flow Guard checks

diff  --git a/clang/test/Driver/cl-link.c b/clang/test/Driver/cl-link.c
index 9bf8a8137926d..726bc26a64edd 100644
--- a/clang/test/Driver/cl-link.c
+++ b/clang/test/Driver/cl-link.c
@@ -71,3 +71,6 @@
 // RUN: %clang_cl -m32 -arch:IA32 --target=i386-pc-win32 /Tc%s -fuse-ld=lld 
-### -fsanitize=address 2>&1 | FileCheck --check-prefix=INFER-LLD %s
 // INFER-LLD: lld-link
 // INFER-LLD-NOT: INFERASANLIBS
+
+// RUN: %clang_cl --target=x86_64-unknown-windows-msvc /Tc%s -flto 
-fuse-ld=lld -### -fprofile-sample-use=%S/Inputs/file.prof 2>&1 | FileCheck 
-check-prefix=CHECK-SAMPLE-PROFILE %s
+// CHECK-SAMPLE-PROFILE: "-lto-sample-profile:{{.*}}/file.prof"



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


[clang] [Driver][MSVC] Pass profile file to lld-link via -lto-sample-profile option (PR #127442)

2025-02-18 Thread via cfe-commits

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


[clang] [lld] [llvm] Integrated Distributed ThinLTO (DTLTO): Initial support (PR #126654)

2025-02-18 Thread via cfe-commits

bd1976bris wrote:

> Some high level comments:
> * Should we just call it distributedLTO, or DLTO? Feel like we can drop the 
> thin part for less typing, and from the user's point of view, using thinLTO 
> infrastructure is just implementation details.

Thanks! I'll discuss this and get back to you tomorrow. It's worth noting that 
both `DTLTO` and `DLTO` have the potential to be confusing - given the 
existence of the current "Bazel-style" (`--thinlto-index-only`) distribution 
for ThinLTO.

> * Are you going to implement some ways to speed up archive or that will come 
> as follow ups? During previous discussion at dev meeting, there are few 
> suggestions for how to do it without extracting archives.

We plan to do that as follow up work. We will eventually want to support 
archives. The point of this feature is to make it easy for a user to enable 
distribution - so we don't want restrictions such as "archives are not 
supported". I think it would be best to start with an RFC-like discussion 
thread, we will start preparing that.

Thanks to everyone that contributed ideas at the roundtable. 


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


[clang] Check the type of Objective-C++ instance variables in WebKit member variable checkers. (PR #127570)

2025-02-18 Thread Ryosuke Niwa via cfe-commits


@@ -87,6 +92,31 @@ class RawPtrRefMemberChecker
 }
   }
 
+  void visitObjCDecl(const ObjCContainerDecl *CD) const {
+if (auto *ID = dyn_cast(CD)) {

rniwa wrote:

oh, but this if statement does that already, right? as in, this if will only 
evaluate to true if ID wasn't nullptr so I think we have a null check here 
already in that regard.

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


[clang] [llvm] [ARM] Adding diagnostics for mcmodel=tiny when used in invalid targets (PR #125643)

2025-02-18 Thread via cfe-commits

https://github.com/ShashwathiNavada updated 
https://github.com/llvm/llvm-project/pull/125643

>From 0aebcd7119fbcd51154c5d9706752e8ff3f041bc Mon Sep 17 00:00:00 2001
From: ShashwathiNavada 
Date: Tue, 4 Feb 2025 00:16:09 -0600
Subject: [PATCH 1/6] Adding diagnostics for unsupported option

---
 clang/lib/Frontend/CompilerInvocation.cpp | 9 +
 1 file changed, 9 insertions(+)

diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 11fd6ab7f52a7..ac8d8be572012 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1897,6 +1897,15 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions 
&Opts, ArgList &Args,
 Opts.setInlining(CodeGenOptions::NormalInlining);
   }
 
+// -mcmodel option.
+if (const llvm::opt::Arg *A = 
Args.getLastArg(clang::driver::options::OPT_mcmodel_EQ)) 
+{
+llvm::StringRef modelName = A->getValue();
+if(modelName=="tiny" && !T.isARM())
+  Diags.Report(diag::err_drv_unsupported_option_argument_for_target) 
+  << A->getSpelling() getValue();
 if(modelName=="tiny" && !T.isARM())
-  Diags.Report(diag::err_drv_unsupported_option_argument_for_target) 
-  << A->getSpelling() From 689dc3a3472ff8270ee9631b235e776f5fa1a27f Mon Sep 17 00:00:00 2001
From: ShashwathiNavada 
Date: Tue, 4 Feb 2025 00:49:37 -0600
Subject: [PATCH 3/6] minor changes

---
 clang/lib/Frontend/CompilerInvocation.cpp | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 1242073ea6746..15d382620d279 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1896,13 +1896,15 @@ bool 
CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
   } else {
 Opts.setInlining(CodeGenOptions::NormalInlining);
   }
-
- // -mcmodel option.
-  if (const llvm::opt::Arg *A = 
Args.getLastArg(clang::driver::options::OPT_mcmodel_EQ)){
+ 
+  // -mcmodel option.
+  if (const llvm::opt::Arg *A =
+  Args.getLastArg(clang::driver::options::OPT_mcmodel_EQ)) {
 llvm::StringRef modelName = A->getValue();
-if(modelName=="tiny" && !T.isARM())
+if (modelName == "tiny" && !T.isARM()) {
   Diags.Report(diag::err_drv_unsupported_option_argument_for_target)
-  << A->getSpelling() << modelName << T.getTriple();  
+  << A->getSpelling() << modelName << T.getTriple();
+}
   }
 
   // PIC defaults to -fno-direct-access-external-data while non-PIC defaults to

>From 28fcb0ee20645cd1d30dd15bfd7f6eff402ba2b9 Mon Sep 17 00:00:00 2001
From: ShashwathiNavada 
Date: Tue, 4 Feb 2025 01:01:00 -0600
Subject: [PATCH 4/6] minor changes

---
 clang/lib/Frontend/CompilerInvocation.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 15d382620d279..f858ec2234cb5 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1896,7 +1896,7 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions 
&Opts, ArgList &Args,
   } else {
 Opts.setInlining(CodeGenOptions::NormalInlining);
   }
- 
+
   // -mcmodel option.
   if (const llvm::opt::Arg *A =
   Args.getLastArg(clang::driver::options::OPT_mcmodel_EQ)) {

>From 843d4ccf4c41a78397e14eb5d9459a4921325741 Mon Sep 17 00:00:00 2001
From: ShashwathiNavada 
Date: Tue, 4 Feb 2025 21:39:44 +0530
Subject: [PATCH 5/6] Addressed build fail

---
 clang/lib/Frontend/CompilerInvocation.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index f858ec2234cb5..48f66931af06c 10064

[clang] Check the type of Objective-C++ instance variables in WebKit member variable checkers. (PR #127570)

2025-02-18 Thread Ryosuke Niwa via cfe-commits


@@ -87,6 +92,31 @@ class RawPtrRefMemberChecker
 }
   }
 
+  void visitObjCDecl(const ObjCContainerDecl *CD) const {
+if (auto *ID = dyn_cast(CD)) {
+  for (auto *Ivar : ID->ivars())
+visitIvarDecl(CD, Ivar);
+  return;
+}
+if (auto *ID = dyn_cast(CD)) {
+  for (auto *Ivar : ID->ivars())
+visitIvarDecl(CD, Ivar);
+  return;
+}
+  }
+
+  void visitIvarDecl(const ObjCContainerDecl *CD,
+ const ObjCIvarDecl *Ivar) const {
+const Type *IvarType = Ivar->getType().getTypePtrOrNull();
+if (!IvarType)
+  return;
+if (auto *IvarCXXRD = IvarType->getPointeeCXXRecordDecl()) {

rniwa wrote:

But again, we're doing a nullptr check here with if statement so I think we're 
good :)

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


[clang] [llvm] [AMDGPU] Add builtins for wave reduction intrinsics (PR #127013)

2025-02-18 Thread Matt Arsenault via cfe-commits


@@ -346,6 +346,24 @@ BUILTIN(__builtin_amdgcn_endpgm, "v", "nr")
 BUILTIN(__builtin_amdgcn_get_fpenv, "WUi", "n")
 BUILTIN(__builtin_amdgcn_set_fpenv, "vWUi", "n")
 
+//===--===//
+
+// Wave Reduction builtins.
+
+//===--===//
+
+BUILTIN(__builtin_amdgcn_wave_reduce_add_i32, "ii", "nc")
+BUILTIN(__builtin_amdgcn_wave_reduce_uadd_i32, "ii", "nc")
+BUILTIN(__builtin_amdgcn_wave_reduce_sub_i32, "ii", "nc")
+BUILTIN(__builtin_amdgcn_wave_reduce_usub_i32, "ii", "nc")
+BUILTIN(__builtin_amdgcn_wave_reduce_min_i32, "ii", "nc")
+BUILTIN(__builtin_amdgcn_wave_reduce_umin_i32, "ii", "nc")
+BUILTIN(__builtin_amdgcn_wave_reduce_max_i32, "ii", "nc")
+BUILTIN(__builtin_amdgcn_wave_reduce_umax_i32, "ii", "nc")
+BUILTIN(__builtin_amdgcn_wave_reduce_and_i32, "ii", "nc")

arsenm wrote:

and_b32? 

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


[clang-tools-extra] [clang-tidy]add new check bugprone-unintended-char-ostream-output (PR #127720)

2025-02-18 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/127720

>From b69bb465a24f2175f2f9f91f220252d3bcb27bde Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Wed, 19 Feb 2025 07:38:37 +0800
Subject: [PATCH 1/2] [clang-tidy]add new check
 bugprone-unintended-char-ostream-output

It wants to find unintended character output from  and  to an ostream.
e.g.
uint8_t v = 9;
std::cout << v;
---
 .../bugprone/BugproneTidyModule.cpp   |  3 +
 .../clang-tidy/bugprone/CMakeLists.txt|  1 +
 .../UnintendedCharOstreamOutputCheck.cpp  | 70 +++
 .../UnintendedCharOstreamOutputCheck.h| 34 +
 clang-tools-extra/docs/ReleaseNotes.rst   |  6 ++
 .../unintended-char-ostream-output.rst| 30 
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../unintended-char-ostream-output.cpp| 70 +++
 8 files changed, 215 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/UnintendedCharOstreamOutputCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/UnintendedCharOstreamOutputCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/bugprone/unintended-char-ostream-output.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/unintended-char-ostream-output.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index c5f0b5b28418f..0a3376949b6e5 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -90,6 +90,7 @@
 #include "UndelegatedConstructorCheck.h"
 #include "UnhandledExceptionAtNewCheck.h"
 #include "UnhandledSelfAssignmentCheck.h"
+#include "UnintendedCharOstreamOutputCheck.h"
 #include "UniquePtrArrayMismatchCheck.h"
 #include "UnsafeFunctionsCheck.h"
 #include "UnusedLocalNonTrivialVariableCheck.h"
@@ -147,6 +148,8 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-incorrect-enable-if");
 CheckFactories.registerCheck(
 "bugprone-incorrect-enable-shared-from-this");
+CheckFactories.registerCheck(
+"bugprone-unintended-char-ostream-output");
 CheckFactories.registerCheck(
 "bugprone-return-const-ref-from-parameter");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index e8309c68b7fca..9758d7259bf65 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -29,6 +29,7 @@ add_clang_library(clangTidyBugproneModule STATIC
   InaccurateEraseCheck.cpp
   IncorrectEnableIfCheck.cpp
   IncorrectEnableSharedFromThisCheck.cpp
+  UnintendedCharOstreamOutputCheck.cpp
   ReturnConstRefFromParameterCheck.cpp
   SuspiciousStringviewDataUsageCheck.cpp
   SwitchMissingDefaultCaseCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/UnintendedCharOstreamOutputCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/UnintendedCharOstreamOutputCheck.cpp
new file mode 100644
index 0..7c54ef1486b2f
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/UnintendedCharOstreamOutputCheck.cpp
@@ -0,0 +1,70 @@
+//===--- UnintendedCharOstreamOutputCheck.cpp - clang-tidy
+//-===//
+//
+// 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 "UnintendedCharOstreamOutputCheck.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+namespace {
+
+// check if the type is unsigned char or signed char
+AST_MATCHER(Type, isNumericChar) {
+  const auto *BT = dyn_cast(&Node);
+  if (BT == nullptr)
+return false;
+  const BuiltinType::Kind K = BT->getKind();
+  return K == BuiltinType::UChar || K == BuiltinType::SChar;
+}
+
+// check if the type is char
+AST_MATCHER(Type, isChar) {
+  const auto *BT = dyn_cast(&Node);
+  if (BT == nullptr)
+return false;
+  const BuiltinType::Kind K = BT->getKind();
+  return K == BuiltinType::Char_U || K == BuiltinType::Char_S;
+}
+
+} // namespace
+
+void UnintendedCharOstreamOutputCheck::registerMatchers(MatchFinder *Finder) {
+  auto BasicOstream =
+  cxxRecordDecl(hasName("::std::basic_ostream"),
+// only basic_ostream has overload operator<<
+// with char / unsigned char / signed char
+classTemplateSpecializationDecl(
+hasTemplateArgument(0, refersToType(isChar();
+  Finder->addMatcher(
+  cxxOperatorCallExp

[clang] [llvm] [AMDGPU] Add builtins for wave reduction intrinsics (PR #127013)

2025-02-18 Thread via cfe-commits


@@ -20212,6 +20212,59 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned 
BuiltinID,
 llvm::Value *Env = EmitScalarExpr(E->getArg(0));
 return Builder.CreateCall(F, {Env});
   }
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_add_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_uadd_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_sub_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_usub_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_min_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_umin_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_max_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_umax_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_and_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_or_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_xor_i32: {
+Intrinsic::ID IID;
+switch (BuiltinID) {

easyonaadit wrote:

Okay sure.

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


[clang] [clang-repl] fix error recovery while parsing completely fails (PR #127087)

2025-02-18 Thread Anutosh Bhat via cfe-commits

anutosh491 wrote:

Maybe @vgvassilev might know more about this behaviour and if it is expected.

For some context you can read the discussion from here 
https://github.com/llvm/llvm-project/pull/127087#issuecomment-2664564232

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


[clang] [clang] fix use after free in clang/tools/c-index-test/c-index-test.c (PR #127063)

2025-02-18 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `sanitizer-aarch64-linux` 
running on `sanitizer-buildbot8` while building `clang` at step 2 "annotate".

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


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

```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
[5324/5435] Linking CXX static library lib/libclangHandleCXX.a
[5325/5435] Linking CXX static library lib/libclangDependencyScanning.a
[5326/5435] Linking CXX static library lib/liblldWasm.a
[5327/5435] Linking CXX static library lib/liblldCOFF.a
[5328/5435] Linking CXX static library lib/liblldMachO.a
[5329/5435] Linking CXX static library lib/libLLVMOptDriver.a
[5330/5435] Linking CXX static library lib/liblldELF.a
[5331/5435] Linking CXX static library lib/liblldMinGW.a
[5332/5435] Linking CXX executable bin/llvm-cxxdump
[5333/5435] Building C object 
tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/c-index-test.c.o
FAILED: 
tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/c-index-test.c.o 
CCACHE_CPP2=yes CCACHE_HASHDIR=yes /usr/bin/ccache 
/home/b/sanitizer-aarch64-linux/build/llvm_build0/bin/clang -DGTEST_HAS_RTTI=0 
-DLLVM_BUILD_STATIC -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE 
-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-I/home/b/sanitizer-aarch64-linux/build/build_default/tools/clang/tools/c-index-test
 -I/home/b/sanitizer-aarch64-linux/build/llvm-project/clang/tools/c-index-test 
-I/home/b/sanitizer-aarch64-linux/build/llvm-project/clang/include 
-I/home/b/sanitizer-aarch64-linux/build/build_default/tools/clang/include 
-I/home/b/sanitizer-aarch64-linux/build/build_default/include 
-I/home/b/sanitizer-aarch64-linux/build/llvm-project/llvm/include -isystem 
/usr/include/libxml2 -fPIC -fno-semantic-interposition -Werror 
-Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra 
-Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers 
-pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough 
-Wcovered-switch-default -Wstring-conversion -Wmisleading-indentation 
-Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections 
-fdata-sections -O3 -DNDEBUG -UNDEBUG -std=gnu89 -MD -MT 
tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/c-index-test.c.o -MF 
tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/c-index-test.c.o.d 
-o tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/c-index-test.c.o 
-c 
/home/b/sanitizer-aarch64-linux/build/llvm-project/clang/tools/c-index-test/c-index-test.c
/home/b/sanitizer-aarch64-linux/build/llvm-project/clang/tools/c-index-test/c-index-test.c:1240:15:
 error: mixing declarations and code is a C99 extension 
[-Werror,-Wdeclaration-after-statement]
 1240 |   const char *b = basename(clang_getCString(source));
  |   ^
/home/b/sanitizer-aarch64-linux/build/llvm-project/clang/tools/c-index-test/c-index-test.c:1367:14:
 error: mixing declarations and code is a C99 extension 
[-Werror,-Wdeclaration-after-statement]
 1367 | CXString source = GetCursorSource(Cursor);
  |  ^
/home/b/sanitizer-aarch64-linux/build/llvm-project/clang/tools/c-index-test/c-index-test.c:1468:14:
 error: mixing declarations and code is a C99 extension 
[-Werror,-Wdeclaration-after-statement]
 1468 | CXString CursorSource = GetCursorSource(C);
  |  ^
3 errors generated.
[5334/5435] Building CXX object 
tools/clang/tools/driver/CMakeFiles/clang.dir/cc1gen_reproducer_main.cpp.o
[5335/5435] Building CXX object 
tools/clang/tools/libclang/CMakeFiles/libclang.dir/CIndexer.cpp.o
[5336/5435] Building CXX object 
tools/clang/tools/driver/CMakeFiles/clang.dir/cc1as_main.cpp.o
[5337/5435] Building CXX object 
tools/clang/tools/libclang/CMakeFiles/libclang.dir/CIndexDiagnostic.cpp.o
[5338/5435] Building CXX object 
tools/clang/tools/libclang/CMakeFiles/libclang.dir/CIndexUSRs.cpp.o
[5339/5435] Linking CXX executable bin/clang-fuzzer-dictionary
[5340/5435] Building CXX object 
tools/clang/tools/libclang/CMakeFiles/libclang.dir/CXString.cpp.o
[5341/5435] Building CXX object 
tools/clang/tools/libclang/CMakeFiles/libclang.dir/CXComment.cpp.o
[5342/5435] Building CXX object 
tools/clang/tools/libclang/CMakeFiles/libclang.dir/CXType.cpp.o
[5343/5435] Building CXX object 
tools/clang/tools/libclang/CMakeFiles/libclang.dir/Rewrite.cpp.o
[5344/5435] Linking CXX executable bin/clang-sycl-linker
[5345/5435] Building CXX object 
tools/clang/tools/libclang/CMakeFiles/libclang.dir/CXStoredDiagnostic.cpp.o
[5346/5435] Building CXX object 
tools/clang/tools/libclang/CMakeFiles/libclang.dir/CIndexHigh.cpp.o
[5347/5435] Building CXX object 
tools/clang/tools/libclang/CMakeFiles/libclang.dir/CXSourceLocation.cpp.o
[5348/5435] Building CXX object 
tools/clang/tools/libclang/CMakeFiles/lib

[clang] 8f41d28 - [c-index-test] Fix warnings

2025-02-18 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2025-02-18T23:18:08-08:00
New Revision: 8f41d28d89ee287d0f5a6518116ab316be2657b8

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

LOG: [c-index-test] Fix warnings

This patch fixes:

  clang/tools/c-index-test/c-index-test.c:1240:15: error: mixing
  declarations and code is a C99 extension
  [-Werror,-Wdeclaration-after-statement]

  clang/tools/c-index-test/c-index-test.c:1367:14: error: mixing
  declarations and code is a C99 extension
  [-Werror,-Wdeclaration-after-statement]

  clang/tools/c-index-test/c-index-test.c:1468:14: error: mixing
  declarations and code is a C99 extension
  [-Werror,-Wdeclaration-after-statement]

Added: 


Modified: 
clang/tools/c-index-test/c-index-test.c

Removed: 




diff  --git a/clang/tools/c-index-test/c-index-test.c 
b/clang/tools/c-index-test/c-index-test.c
index fed6fe0736904..0e7de8b98ea07 100644
--- a/clang/tools/c-index-test/c-index-test.c
+++ b/clang/tools/c-index-test/c-index-test.c
@@ -1231,14 +1231,16 @@ static CXString GetCursorSource(CXCursor Cursor) {
   CXSourceLocation Loc = clang_getCursorLocation(Cursor);
   CXString source;
   CXFile file;
+  const char *b;
+  CXString result;
   clang_getExpansionLocation(Loc, &file, 0, 0, 0);
   source = clang_getFileName(file);
   if (!clang_getCString(source)) {
 clang_disposeString(source);
 return createCXString("");
   }
-  const char *b = basename(clang_getCString(source));
-  CXString result = duplicateCXString(b);
+  b = basename(clang_getCString(source));
+  result = duplicateCXString(b);
   clang_disposeString(source);
   return result;
 }
@@ -1363,8 +1365,9 @@ enum CXChildVisitResult FilteredPrintingVisitor(CXCursor 
Cursor,
   if (!Data->Filter || (Cursor.kind == *(enum CXCursorKind *)Data->Filter)) {
 CXSourceLocation Loc = clang_getCursorLocation(Cursor);
 unsigned line, column;
+CXString source;
 clang_getFileLocation(Loc, 0, &line, &column, 0);
-CXString source = GetCursorSource(Cursor);
+source = GetCursorSource(Cursor);
 printf("// %s: %s:%d:%d: ", FileCheckPrefix, clang_getCString(source), 
line,
column);
 clang_disposeString(source);
@@ -1461,11 +1464,12 @@ enum CXChildVisitResult USRVisitor(CXCursor C, CXCursor 
parent,
   if (!Data->Filter || (C.kind == *(enum CXCursorKind *)Data->Filter)) {
 CXString USR = clang_getCursorUSR(C);
 const char *cstr = clang_getCString(USR);
+CXString CursorSource;
 if (!cstr || cstr[0] == '\0') {
   clang_disposeString(USR);
   return CXChildVisit_Recurse;
 }
-CXString CursorSource = GetCursorSource(C);
+CursorSource = GetCursorSource(C);
 printf("// %s: %s %s", FileCheckPrefix, clang_getCString(CursorSource),
cstr);
 clang_disposeString(CursorSource);



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


[clang-tools-extra] [clang-tidy]add new check bugprone-unintended-char-ostream-output (PR #127720)

2025-02-18 Thread Carlos Galvez via cfe-commits


@@ -0,0 +1,30 @@
+.. title:: clang-tidy - bugprone-unintended-char-ostream-output
+
+bugprone-unintended-char-ostream-output
+===
+
+Finds unintended character output from ``unsigned char`` and ``signed char`` 
to an
+``ostream``.
+
+Normally, when ``unsigned char (uint8_t)`` or ``signed char (int8_t)`` is 
used, it
+is more likely a number than a character. However, when it is passed directly 
to
+``std::ostream``'s ``operator<<``, resulting in character-based output instead
+of numeric value. This often contradicts the developer's intent to print
+integer values.
+
+.. code-block:: c++
+
+uint8_t v = 9;
+std::cout << v; // output '\t' instead of '9'
+
+It could be fixed as
+
+.. code-block:: c++
+
+std::cout << (uint32_t)v;

carlosgalvezp wrote:

Nit: since we are in C++, it would be good to use C++ casts, i.e. 
`static_cast(v)`

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


[clang-tools-extra] [clang-tidy]add new check bugprone-unintended-char-ostream-output (PR #127720)

2025-02-18 Thread Carlos Galvez via cfe-commits


@@ -0,0 +1,69 @@
+// RUN: %check_clang_tidy %s bugprone-unintended-char-ostream-output %t
+
+namespace std {
+
+template  class basic_ostream {
+public:
+  basic_ostream &operator<<(int);
+  basic_ostream &operator<<(unsigned int);
+};
+
+template 
+basic_ostream &operator<<(basic_ostream &, 
CharT);
+template 
+basic_ostream &operator<<(basic_ostream &, char);
+template 
+basic_ostream &operator<<(basic_ostream &, char);
+template 
+basic_ostream &operator<<(basic_ostream &,
+  signed char);
+template 
+basic_ostream &operator<<(basic_ostream &,
+  unsigned char);
+
+using ostream = basic_ostream;
+
+} // namespace std
+
+class A : public std::ostream {};
+
+void origin_ostream(std::ostream &os) {
+  unsigned char unsigned_value = 9;
+  os << unsigned_value;
+  // CHECK-MESSAGES: [[@LINE-1]]:6: warning: ('unsigned char' passed to
+  // 'operator<<' outputs as character instead of integer
+
+  signed char signed_value = 9;
+  os << signed_value;
+  // CHECK-MESSAGES: [[@LINE-1]]:6: warning: ('signed char' passed to
+  // 'operator<<' outputs as character instead of integer
+
+  char char_value = 9;
+  os << char_value;
+}
+
+void based_on_ostream(A &os) {
+  unsigned char unsigned_value = 9;
+  os << unsigned_value;
+  // CHECK-MESSAGES: [[@LINE-1]]:6: warning: ('unsigned char' passed to

carlosgalvezp wrote:

Remove the opening parenthesis

('unsigned char'
^

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


[clang] [clang] fix use after free in clang/tools/c-index-test/c-index-test.c (PR #127063)

2025-02-18 Thread Vitaly Buka via cfe-commits

vitalybuka wrote:

> @metaflow @vitalybuka I've checked in 
> [8f41d28](https://github.com/llvm/llvm-project/commit/8f41d28d89ee287d0f5a6518116ab316be2657b8)
>  to fix warnings. Thanks!

Thank You!

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


[clang] Reland "[libclang] Always Dup in createRef(StringRef)" (PR #127078)

2025-02-18 Thread Vitaly Buka via cfe-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/127078

>From a831b96cc2eb4b65e7157ee3cb519cf9b4a6af76 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Thu, 13 Feb 2025 07:42:46 -0800
Subject: [PATCH] Revert "Revert "[libclang] Always Dup in
 createRef(StringRef)" (#127076)"

This reverts commit a1345eb240c9456ce1c339106f066217eb5e6984.
---
 clang/docs/ReleaseNotes.rst   |  3 +++
 clang/tools/libclang/CXString.cpp | 14 +-
 2 files changed, 4 insertions(+), 13 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 03bddbe3e983a..e41ad384b84f7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -257,6 +257,9 @@ clang-format
 libclang
 
 
+- Fixed a buffer overflow in ``CXString`` implementation. The fix may result in
+  increased memory allocation.
+
 Code Completion
 ---
 
diff --git a/clang/tools/libclang/CXString.cpp 
b/clang/tools/libclang/CXString.cpp
index 5e427957a1092..aaa8f8eeb67a1 100644
--- a/clang/tools/libclang/CXString.cpp
+++ b/clang/tools/libclang/CXString.cpp
@@ -87,19 +87,7 @@ CXString createRef(StringRef String) {
   if (String.empty())
 return createEmpty();
 
-  // If the string is not nul-terminated, we have to make a copy.
-
-  // FIXME: This is doing a one past end read, and should be removed! For 
memory
-  // we don't manage, the API string can become unterminated at any time 
outside
-  // our control.
-
-  if (String.data()[String.size()] != 0)
-return createDup(String);
-
-  CXString Result;
-  Result.data = String.data();
-  Result.private_flags = (unsigned) CXS_Unmanaged;
-  return Result;
+  return createDup(String);
 }
 
 CXString createDup(StringRef String) {

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


[clang-tools-extra] [clangd] Avoid round-trip from SourceLocation to clangd::Range and back in SymbolCollector::handleMacros() (PR #127757)

2025-02-18 Thread Nathan Ridge via cfe-commits

https://github.com/HighCommander4 created 
https://github.com/llvm/llvm-project/pull/127757

…

>From d7f83b154b17856b1de2d97cf0a3aca72dd0379c Mon Sep 17 00:00:00 2001
From: Nathan Ridge 
Date: Wed, 19 Feb 2025 02:25:16 -0500
Subject: [PATCH] [clangd] Avoid round-trip from SourceLocation to
 clangd::Range and back in SymbolCollector::handleMacros()

---
 clang-tools-extra/clangd/CollectMacros.cpp | 9 ++---
 clang-tools-extra/clangd/CollectMacros.h   | 1 +
 clang-tools-extra/clangd/index/SymbolCollector.cpp | 7 +++
 3 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/clang-tools-extra/clangd/CollectMacros.cpp 
b/clang-tools-extra/clangd/CollectMacros.cpp
index 96298ee3ea50a..1e7d765f0b6f1 100644
--- a/clang-tools-extra/clangd/CollectMacros.cpp
+++ b/clang-tools-extra/clangd/CollectMacros.cpp
@@ -18,10 +18,13 @@
 namespace clang {
 namespace clangd {
 
-Range MacroOccurrence::toRange(const SourceManager &SM) const {
+CharSourceRange MacroOccurrence::toSourceRange(const SourceManager &SM) const {
   auto MainFile = SM.getMainFileID();
-  return halfOpenToRange(
-  SM, syntax::FileRange(MainFile, StartOffset, EndOffset).toCharRange(SM));
+  return syntax::FileRange(MainFile, StartOffset, EndOffset).toCharRange(SM);
+}
+
+Range MacroOccurrence::toRange(const SourceManager &SM) const {
+  return halfOpenToRange(SM, toSourceRange(SM));
 }
 
 void CollectMainFileMacros::add(const Token &MacroNameTok, const MacroInfo *MI,
diff --git a/clang-tools-extra/clangd/CollectMacros.h 
b/clang-tools-extra/clangd/CollectMacros.h
index e7198641d8d53..20a3fc24d759c 100644
--- a/clang-tools-extra/clangd/CollectMacros.h
+++ b/clang-tools-extra/clangd/CollectMacros.h
@@ -31,6 +31,7 @@ struct MacroOccurrence {
   // True if the occurence is used in a conditional directive, e.g. #ifdef 
MACRO
   bool InConditionalDirective;
 
+  CharSourceRange toSourceRange(const SourceManager &SM) const;
   Range toRange(const SourceManager &SM) const;
 };
 
diff --git a/clang-tools-extra/clangd/index/SymbolCollector.cpp 
b/clang-tools-extra/clangd/index/SymbolCollector.cpp
index 1de7faf81746e..3f5633357073d 100644
--- a/clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ b/clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -713,7 +713,8 @@ void SymbolCollector::handleMacros(const MainFileMacros 
&MacroRefsToIndex) {
   // Add macro references.
   for (const auto &IDToRefs : MacroRefsToIndex.MacroRefs) {
 for (const auto &MacroRef : IDToRefs.second) {
-  const auto &Range = MacroRef.toRange(SM);
+  const auto &SR = MacroRef.toSourceRange(SM);
+  auto Range = halfOpenToRange(SM, SR);
   bool IsDefinition = MacroRef.IsDefinition;
   Ref R;
   R.Location.Start.setLine(Range.start.line);
@@ -726,9 +727,7 @@ void SymbolCollector::handleMacros(const MainFileMacros 
&MacroRefsToIndex) {
   if (IsDefinition) {
 Symbol S;
 S.ID = IDToRefs.first;
-auto StartLoc = cantFail(sourceLocationInMainFile(SM, Range.start));
-auto EndLoc = cantFail(sourceLocationInMainFile(SM, Range.end));
-S.Name = toSourceCode(SM, SourceRange(StartLoc, EndLoc));
+S.Name = toSourceCode(SM, SR.getAsRange());
 S.SymInfo.Kind = index::SymbolKind::Macro;
 S.SymInfo.SubKind = index::SymbolSubKind::None;
 S.SymInfo.Properties = index::SymbolPropertySet();

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


[clang-tools-extra] [clangd] Avoid round-trip from SourceLocation to clangd::Range and back in SymbolCollector::handleMacros() (PR #127757)

2025-02-18 Thread via cfe-commits

llvmbot wrote:




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

Author: Nathan Ridge (HighCommander4)


Changes

…

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


3 Files Affected:

- (modified) clang-tools-extra/clangd/CollectMacros.cpp (+6-3) 
- (modified) clang-tools-extra/clangd/CollectMacros.h (+1) 
- (modified) clang-tools-extra/clangd/index/SymbolCollector.cpp (+3-4) 


``diff
diff --git a/clang-tools-extra/clangd/CollectMacros.cpp 
b/clang-tools-extra/clangd/CollectMacros.cpp
index 96298ee3ea50a..1e7d765f0b6f1 100644
--- a/clang-tools-extra/clangd/CollectMacros.cpp
+++ b/clang-tools-extra/clangd/CollectMacros.cpp
@@ -18,10 +18,13 @@
 namespace clang {
 namespace clangd {
 
-Range MacroOccurrence::toRange(const SourceManager &SM) const {
+CharSourceRange MacroOccurrence::toSourceRange(const SourceManager &SM) const {
   auto MainFile = SM.getMainFileID();
-  return halfOpenToRange(
-  SM, syntax::FileRange(MainFile, StartOffset, EndOffset).toCharRange(SM));
+  return syntax::FileRange(MainFile, StartOffset, EndOffset).toCharRange(SM);
+}
+
+Range MacroOccurrence::toRange(const SourceManager &SM) const {
+  return halfOpenToRange(SM, toSourceRange(SM));
 }
 
 void CollectMainFileMacros::add(const Token &MacroNameTok, const MacroInfo *MI,
diff --git a/clang-tools-extra/clangd/CollectMacros.h 
b/clang-tools-extra/clangd/CollectMacros.h
index e7198641d8d53..20a3fc24d759c 100644
--- a/clang-tools-extra/clangd/CollectMacros.h
+++ b/clang-tools-extra/clangd/CollectMacros.h
@@ -31,6 +31,7 @@ struct MacroOccurrence {
   // True if the occurence is used in a conditional directive, e.g. #ifdef 
MACRO
   bool InConditionalDirective;
 
+  CharSourceRange toSourceRange(const SourceManager &SM) const;
   Range toRange(const SourceManager &SM) const;
 };
 
diff --git a/clang-tools-extra/clangd/index/SymbolCollector.cpp 
b/clang-tools-extra/clangd/index/SymbolCollector.cpp
index 1de7faf81746e..3f5633357073d 100644
--- a/clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ b/clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -713,7 +713,8 @@ void SymbolCollector::handleMacros(const MainFileMacros 
&MacroRefsToIndex) {
   // Add macro references.
   for (const auto &IDToRefs : MacroRefsToIndex.MacroRefs) {
 for (const auto &MacroRef : IDToRefs.second) {
-  const auto &Range = MacroRef.toRange(SM);
+  const auto &SR = MacroRef.toSourceRange(SM);
+  auto Range = halfOpenToRange(SM, SR);
   bool IsDefinition = MacroRef.IsDefinition;
   Ref R;
   R.Location.Start.setLine(Range.start.line);
@@ -726,9 +727,7 @@ void SymbolCollector::handleMacros(const MainFileMacros 
&MacroRefsToIndex) {
   if (IsDefinition) {
 Symbol S;
 S.ID = IDToRefs.first;
-auto StartLoc = cantFail(sourceLocationInMainFile(SM, Range.start));
-auto EndLoc = cantFail(sourceLocationInMainFile(SM, Range.end));
-S.Name = toSourceCode(SM, SourceRange(StartLoc, EndLoc));
+S.Name = toSourceCode(SM, SR.getAsRange());
 S.SymInfo.Kind = index::SymbolKind::Macro;
 S.SymInfo.SubKind = index::SymbolSubKind::None;
 S.SymInfo.Properties = index::SymbolPropertySet();

``




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


[clang-tools-extra] [clangd] Store full decl/def range with symbol locations (PR #118102)

2025-02-18 Thread Nathan Ridge via cfe-commits

HighCommander4 wrote:

> (For example `ClangdModules` was an action we were trying to take in this 
> direction. It actually aims to provide people infrastructure to implement 
> their desired functionality in clangd, while limiting resource and 
> maintenance costs to only that specific feature and its users. but then we 
> took an arrow in the knee)

Could you say more about this? What happened to `ClangdModules`?

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


[clang-tools-extra] [clangd] Avoid round-trip from SourceLocation to clangd::Range and back in SymbolCollector::handleMacros() (PR #127757)

2025-02-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clangd

Author: Nathan Ridge (HighCommander4)


Changes

…

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


3 Files Affected:

- (modified) clang-tools-extra/clangd/CollectMacros.cpp (+6-3) 
- (modified) clang-tools-extra/clangd/CollectMacros.h (+1) 
- (modified) clang-tools-extra/clangd/index/SymbolCollector.cpp (+3-4) 


``diff
diff --git a/clang-tools-extra/clangd/CollectMacros.cpp 
b/clang-tools-extra/clangd/CollectMacros.cpp
index 96298ee3ea50a..1e7d765f0b6f1 100644
--- a/clang-tools-extra/clangd/CollectMacros.cpp
+++ b/clang-tools-extra/clangd/CollectMacros.cpp
@@ -18,10 +18,13 @@
 namespace clang {
 namespace clangd {
 
-Range MacroOccurrence::toRange(const SourceManager &SM) const {
+CharSourceRange MacroOccurrence::toSourceRange(const SourceManager &SM) const {
   auto MainFile = SM.getMainFileID();
-  return halfOpenToRange(
-  SM, syntax::FileRange(MainFile, StartOffset, EndOffset).toCharRange(SM));
+  return syntax::FileRange(MainFile, StartOffset, EndOffset).toCharRange(SM);
+}
+
+Range MacroOccurrence::toRange(const SourceManager &SM) const {
+  return halfOpenToRange(SM, toSourceRange(SM));
 }
 
 void CollectMainFileMacros::add(const Token &MacroNameTok, const MacroInfo *MI,
diff --git a/clang-tools-extra/clangd/CollectMacros.h 
b/clang-tools-extra/clangd/CollectMacros.h
index e7198641d8d53..20a3fc24d759c 100644
--- a/clang-tools-extra/clangd/CollectMacros.h
+++ b/clang-tools-extra/clangd/CollectMacros.h
@@ -31,6 +31,7 @@ struct MacroOccurrence {
   // True if the occurence is used in a conditional directive, e.g. #ifdef 
MACRO
   bool InConditionalDirective;
 
+  CharSourceRange toSourceRange(const SourceManager &SM) const;
   Range toRange(const SourceManager &SM) const;
 };
 
diff --git a/clang-tools-extra/clangd/index/SymbolCollector.cpp 
b/clang-tools-extra/clangd/index/SymbolCollector.cpp
index 1de7faf81746e..3f5633357073d 100644
--- a/clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ b/clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -713,7 +713,8 @@ void SymbolCollector::handleMacros(const MainFileMacros 
&MacroRefsToIndex) {
   // Add macro references.
   for (const auto &IDToRefs : MacroRefsToIndex.MacroRefs) {
 for (const auto &MacroRef : IDToRefs.second) {
-  const auto &Range = MacroRef.toRange(SM);
+  const auto &SR = MacroRef.toSourceRange(SM);
+  auto Range = halfOpenToRange(SM, SR);
   bool IsDefinition = MacroRef.IsDefinition;
   Ref R;
   R.Location.Start.setLine(Range.start.line);
@@ -726,9 +727,7 @@ void SymbolCollector::handleMacros(const MainFileMacros 
&MacroRefsToIndex) {
   if (IsDefinition) {
 Symbol S;
 S.ID = IDToRefs.first;
-auto StartLoc = cantFail(sourceLocationInMainFile(SM, Range.start));
-auto EndLoc = cantFail(sourceLocationInMainFile(SM, Range.end));
-S.Name = toSourceCode(SM, SourceRange(StartLoc, EndLoc));
+S.Name = toSourceCode(SM, SR.getAsRange());
 S.SymInfo.Kind = index::SymbolKind::Macro;
 S.SymInfo.SubKind = index::SymbolSubKind::None;
 S.SymInfo.Properties = index::SymbolPropertySet();

``




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


[clang] [clang][bytecode] Fix three-way unordered non-pointer comparisions (PR #127759)

2025-02-18 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/127759

This _can_ happen with non-pointers, but we shouldn't diagnose it in that case.

>From 1b4f4b78741e297e8d257af427206f3dbc3501d2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Wed, 19 Feb 2025 08:52:35 +0100
Subject: [PATCH] [clang][bytecode] Fix three-way unordered non-pointer
 comparisions

This _can_ happen with non-pointers, but we shouldn't diagnose it in
that case.
---
 clang/lib/AST/ByteCode/Interp.h   | 15 ---
 clang/test/AST/ByteCode/cxx20.cpp |  2 ++
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index ca74046038072..fa113aa0bb157 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -1132,13 +1132,14 @@ bool CMP3(InterpState &S, CodePtr OpPC, const 
ComparisonCategoryInfo *CmpInfo) {
   const Pointer &P = S.Stk.peek();
 
   ComparisonCategoryResult CmpResult = LHS.compare(RHS);
-  if (CmpResult == ComparisonCategoryResult::Unordered) {
-// This should only happen with pointers.
-const SourceInfo &Loc = S.Current->getSource(OpPC);
-S.FFDiag(Loc, diag::note_constexpr_pointer_comparison_unspecified)
-<< LHS.toDiagnosticString(S.getASTContext())
-<< RHS.toDiagnosticString(S.getASTContext());
-return false;
+  if constexpr (std::is_same_v) {
+if (CmpResult == ComparisonCategoryResult::Unordered) {
+  const SourceInfo &Loc = S.Current->getSource(OpPC);
+  S.FFDiag(Loc, diag::note_constexpr_pointer_comparison_unspecified)
+  << LHS.toDiagnosticString(S.getASTContext())
+  << RHS.toDiagnosticString(S.getASTContext());
+  return false;
+}
   }
 
   assert(CmpInfo);
diff --git a/clang/test/AST/ByteCode/cxx20.cpp 
b/clang/test/AST/ByteCode/cxx20.cpp
index 6f65fa5c7cfd3..06501de64916a 100644
--- a/clang/test/AST/ByteCode/cxx20.cpp
+++ b/clang/test/AST/ByteCode/cxx20.cpp
@@ -626,6 +626,8 @@ namespace ThreeWayCmp {
   constexpr int k = (1 <=> 1, 0); // both-warning {{comparison result unused}}
   static_assert(k== 0, "");
 
+  static_assert(__builtin_nanf("") <=> __builtin_nanf("") == -127, "");
+
   /// Pointers.
   constexpr int a[] = {1,2,3};
   constexpr int b[] = {1,2,3};

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


[clang] [clang] fix use after free in clang/tools/c-index-test/c-index-test.c (PR #127063)

2025-02-18 Thread Kazu Hirata via cfe-commits

kazutakahirata wrote:

@metaflow @vitalybuka I've checked in 8f41d28d89ee287d0f5a6518116ab316be2657b8 
to fix warnings.  Thanks!


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


[clang] [clang] fix use after free in clang/tools/c-index-test/c-index-test.c (PR #127063)

2025-02-18 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `sanitizer-x86_64-linux` 
running on `sanitizer-buildbot1` while building `clang` at step 2 "annotate".

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


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

```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
-- For x86_64 builtins preferring x86_64/floatdidf.c to floatdidf.c
-- For x86_64 builtins preferring x86_64/floatdisf.c to floatdisf.c
-- For x86_64 builtins preferring x86_64/floatundidf.S to floatundidf.c
-- For x86_64 builtins preferring x86_64/floatundisf.S to floatundisf.c
-- For x86_64 builtins preferring x86_64/floatdixf.c to floatdixf.c
-- For x86_64 builtins preferring x86_64/floatundixf.S to floatundixf.c
-- Configuring done (11.0s)
-- Generating done (0.0s)
-- Build files have been written to: 
/home/b/sanitizer-x86_64-linux/build/build_default/runtimes/builtins-bins
[5410/5439] Building C object 
tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/c-index-test.c.o
FAILED: 
tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/c-index-test.c.o 
CCACHE_CPP2=yes CCACHE_HASHDIR=yes /usr/bin/ccache 
/home/b/sanitizer-x86_64-linux/build/llvm_build0/bin/clang -DGTEST_HAS_RTTI=0 
-DLLVM_BUILD_STATIC -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE 
-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-I/home/b/sanitizer-x86_64-linux/build/build_default/tools/clang/tools/c-index-test
 -I/home/b/sanitizer-x86_64-linux/build/llvm-project/clang/tools/c-index-test 
-I/home/b/sanitizer-x86_64-linux/build/llvm-project/clang/include 
-I/home/b/sanitizer-x86_64-linux/build/build_default/tools/clang/include 
-I/home/b/sanitizer-x86_64-linux/build/build_default/include 
-I/home/b/sanitizer-x86_64-linux/build/llvm-project/llvm/include -isystem 
/usr/include/libxml2 -fPIC -fno-semantic-interposition -Werror 
-Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra 
-Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers 
-pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough 
-Wcovered-switch-default -Wstring-conversion -Wmisleading-indentation 
-Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections 
-fdata-sections -O3 -DNDEBUG -UNDEBUG -std=gnu89 -MD -MT 
tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/c-index-test.c.o -MF 
tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/c-index-test.c.o.d 
-o tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/c-index-test.c.o 
-c 
/home/b/sanitizer-x86_64-linux/build/llvm-project/clang/tools/c-index-test/c-index-test.c
/home/b/sanitizer-x86_64-linux/build/llvm-project/clang/tools/c-index-test/c-index-test.c:1240:15:
 error: mixing declarations and code is a C99 extension 
[-Werror,-Wdeclaration-after-statement]
 1240 |   const char *b = basename(clang_getCString(source));
  |   ^
/home/b/sanitizer-x86_64-linux/build/llvm-project/clang/tools/c-index-test/c-index-test.c:1367:14:
 error: mixing declarations and code is a C99 extension 
[-Werror,-Wdeclaration-after-statement]
 1367 | CXString source = GetCursorSource(Cursor);
  |  ^
/home/b/sanitizer-x86_64-linux/build/llvm-project/clang/tools/c-index-test/c-index-test.c:1468:14:
 error: mixing declarations and code is a C99 extension 
[-Werror,-Wdeclaration-after-statement]
 1468 | CXString CursorSource = GetCursorSource(C);
  |  ^
3 errors generated.
[5420/5439] Building CXX object 
tools/clang/tools/libclang/CMakeFiles/libclang.dir/CXExtractAPI.cpp.o
ninja: build stopped: subcommand failed.

How to reproduce locally: 
https://github.com/google/sanitizers/wiki/SanitizerBotReproduceBuild

@@@STEP_FAILURE@@@
@@@BUILD_STEP test compiler-rt symbolizer@@@
ninja: Entering directory `build_default'
[0/10] Performing build step for 'builtins'
[1/324] Building C object CMakeFiles/clang_rt.builtins-i386.dir/absvdi2.c.o
[2/324] Building C object CMakeFiles/clang_rt.builtins-i386.dir/absvsi2.c.o
[3/324] Building C object CMakeFiles/clang_rt.builtins-i386.dir/absvti2.c.o
[4/324] Building C object CMakeFiles/clang_rt.builtins-i386.dir/addvdi3.c.o
[5/324] Building C object CMakeFiles/clang_rt.builtins-i386.dir/addvsi3.c.o
[6/324] Building C object CMakeFiles/clang_rt.builtins-i386.dir/addvti3.c.o
[7/324] Building C object 
CMakeFiles/clang_rt.builtins-i386.dir/apple_versioning.c.o
[8/324] Building C object CMakeFiles/clang_rt.builtins-i386.dir/ashlti3.c.o
[9/324] Building C object CMakeFiles/clang_rt.builtins-i386.dir/ashrti3.c.o
[10/324] Building C object CMakeFiles/clang_rt.builtins-i386.dir/bswapdi2.c.o
[11/324] Building C object CMakeFiles/clang_rt.builtins-i386.dir/bswapsi2.c.o
[12/324] Building C object CMakeFiles/clang_rt.builtins-i386.dir/clzdi2.c.o
[13/324] Building C object CMakeFiles/clang_rt.builtin

[clang] [clang] fix use after free in clang/tools/c-index-test/c-index-test.c (PR #127063)

2025-02-18 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`ppc64le-lld-multistage-test` running on `ppc64le-lld-multistage-test` while 
building `clang` at step 12 "build-stage2-unified-tree".

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


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

```
Step 12 (build-stage2-unified-tree) failure: build (failure)
...
461.394 [151/650/5664] Building C object 
tools/llvm-c-test/CMakeFiles/llvm-c-test.dir/module.c.o
461.395 [151/649/5665] Building C object 
tools/llvm-c-test/CMakeFiles/llvm-c-test.dir/metadata.c.o
461.399 [151/648/5666] Building C object 
tools/llvm-c-test/CMakeFiles/llvm-c-test.dir/object.c.o
461.400 [151/647/5667] Building C object 
tools/llvm-c-test/CMakeFiles/llvm-c-test.dir/targets.c.o
461.400 [151/646/5668] Building CXX object 
tools/llvm-isel-fuzzer/CMakeFiles/llvm-isel-fuzzer.dir/DummyISelFuzzer.cpp.o
461.401 [151/645/5669] Building CXX object 
tools/llvm-opt-fuzzer/CMakeFiles/llvm-opt-fuzzer.dir/DummyOptFuzzer.cpp.o
461.426 [151/644/5670] Building C object 
tools/llvm-c-test/CMakeFiles/llvm-c-test.dir/calc.c.o
461.596 [151/643/5671] Building C object 
tools/llvm-c-test/CMakeFiles/llvm-c-test.dir/debuginfo.c.o
461.616 [151/642/5672] Building C object 
tools/llvm-c-test/CMakeFiles/llvm-c-test.dir/disassemble.c.o
461.857 [151/641/5673] Building C object 
tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/c-index-test.c.o
FAILED: 
tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/c-index-test.c.o 
ccache 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/install/stage1/bin/clang
 -DGTEST_HAS_RTTI=0 -DLLVM_BUILD_STATIC -D_DEBUG -D_GLIBCXX_ASSERTIONS 
-D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS 
-D__STDC_LIMIT_MACROS 
-I/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/build/stage2/tools/clang/tools/c-index-test
 
-I/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/clang/tools/c-index-test
 
-I/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/clang/include
 
-I/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/build/stage2/tools/clang/include
 
-I/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/build/stage2/include
 
-I/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/llvm/include
 -fPIC -fno-semantic-interposition -Werror -Werror=date-time 
-Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter 
-Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic 
-Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough 
-Wcovered-switch-default -Wstring-conversion -Wmisleading-indentation 
-Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections 
-fdata-sections -O3 -DNDEBUG -UNDEBUG -std=gnu89 -MD -MT 
tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/c-index-test.c.o -MF 
tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/c-index-test.c.o.d 
-o tools/clang/tools/c-index-test/CMakeFiles/c-index-test.dir/c-index-test.c.o 
-c 
/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/clang/tools/c-index-test/c-index-test.c
/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/clang/tools/c-index-test/c-index-test.c:1240:15:
 error: mixing declarations and code is a C99 extension 
[-Werror,-Wdeclaration-after-statement]
 1240 |   const char *b = basename(clang_getCString(source));
  |   ^
/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/clang/tools/c-index-test/c-index-test.c:1367:14:
 error: mixing declarations and code is a C99 extension 
[-Werror,-Wdeclaration-after-statement]
 1367 | CXString source = GetCursorSource(Cursor);
  |  ^
/home/buildbots/llvm-external-buildbots/workers/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/clang/tools/c-index-test/c-index-test.c:1468:14:
 error: mixing declarations and code is a C99 extension 
[-Werror,-Wdeclaration-after-statement]
 1468 | CXString CursorSource = GetCursorSource(C);
  |  ^
3 errors generated.
462.764 [151/640/5674] Building CXX object 
lib/Target/AMDGPU/TargetInfo/CMakeFiles/LLVMAMDGPUInfo.dir/AMDGPUTargetInfo.cpp.o
462.977 [151/639/5675] Building CXX object 
tools/llvm-cxxdump/CMakeFiles/llvm-cxxdump.dir/Error.cpp.o
463.397 [151/638/5676] Building CXX object 
lib/Target/AMDGPU/MCTargetDesc/CMakeFiles/LLVMAMDGPUDesc.dir/R600InstPrinter.cpp.o
464.723 [151/637/5677] Building

[clang] [llvm] [AMDGPU] Add builtins for wave reduction intrinsics (PR #127013)

2025-02-18 Thread Matt Arsenault via cfe-commits


@@ -20212,6 +20212,59 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned 
BuiltinID,
 llvm::Value *Env = EmitScalarExpr(E->getArg(0));
 return Builder.CreateCall(F, {Env});
   }
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_add_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_uadd_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_sub_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_usub_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_min_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_umin_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_max_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_umax_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_and_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_or_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_xor_i32: {
+Intrinsic::ID IID;
+switch (BuiltinID) {
+case AMDGPU::BI__builtin_amdgcn_wave_reduce_add_i32:
+  IID = Intrinsic::amdgcn_wave_reduce_add;
+  break;
+case AMDGPU::BI__builtin_amdgcn_wave_reduce_uadd_i32:
+  IID = Intrinsic::amdgcn_wave_reduce_uadd;
+  break;
+case AMDGPU::BI__builtin_amdgcn_wave_reduce_sub_i32:
+  IID = Intrinsic::amdgcn_wave_reduce_sub;
+  break;
+case AMDGPU::BI__builtin_amdgcn_wave_reduce_usub_i32:
+  IID = Intrinsic::amdgcn_wave_reduce_usub;
+  break;
+case AMDGPU::BI__builtin_amdgcn_wave_reduce_min_i32:
+  IID = Intrinsic::amdgcn_wave_reduce_min;
+  break;
+case AMDGPU::BI__builtin_amdgcn_wave_reduce_umin_i32:
+  IID = Intrinsic::amdgcn_wave_reduce_umin;
+  break;
+case AMDGPU::BI__builtin_amdgcn_wave_reduce_max_i32:
+  IID = Intrinsic::amdgcn_wave_reduce_max;
+  break;
+case AMDGPU::BI__builtin_amdgcn_wave_reduce_umax_i32:
+  IID = Intrinsic::amdgcn_wave_reduce_umax;
+  break;
+case AMDGPU::BI__builtin_amdgcn_wave_reduce_and_i32:
+  IID = Intrinsic::amdgcn_wave_reduce_and;
+  break;
+case AMDGPU::BI__builtin_amdgcn_wave_reduce_or_i32:
+  IID = Intrinsic::amdgcn_wave_reduce_or;
+  break;
+case AMDGPU::BI__builtin_amdgcn_wave_reduce_xor_i32:
+  IID = Intrinsic::amdgcn_wave_reduce_xor;
+  break;
+}
+llvm::Value *Src0 = EmitScalarExpr(E->getArg(0));
+llvm::Function *F = CGM.getIntrinsic(IID, {Src0->getType()});
+llvm::Value *Strategy =
+llvm::ConstantInt::get(llvm::Type::getInt32Ty(getLLVMContext()), 0);

arsenm wrote:

It's a request for an implementation detail. There's no point in having the 
intrinsic argument if it's not exposed in the builtin 

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


[clang] [clang][TSA] Make RequiresCapability a DeclOrType attribute (PR #67095)

2025-02-18 Thread Timm Baeder via cfe-commits

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

>From 1bb62210a2ec5342111a0407cbfa8a73d761357f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Fri, 22 Sep 2023 08:42:05 +0200
Subject: [PATCH] [clang][TSA] Make RequiresCapability a DeclOrType attribute

---
 clang/include/clang/Basic/Attr.td |  4 +-
 clang/include/clang/Sema/Sema.h   |  6 +++
 clang/lib/AST/TypePrinter.cpp |  3 ++
 clang/lib/Sema/SemaDeclAttr.cpp   | 43 +--
 clang/lib/Sema/SemaType.cpp   | 25 +++
 clang/test/Sema/warn-thread-safety-analysis.c | 10 +
 .../SemaCXX/warn-thread-safety-parsing.cpp|  2 +
 7 files changed, 68 insertions(+), 25 deletions(-)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 65c91ccd75ecc..b63ff25a828e2 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -3851,7 +3851,7 @@ def ReleaseCapability : InheritableAttr {
   let Documentation = [ReleaseCapabilityDocs];
 }
 
-def RequiresCapability : InheritableAttr {
+def RequiresCapability : DeclOrTypeAttr {
   let Spellings = [Clang<"requires_capability", 0>,
Clang<"exclusive_locks_required", 0>,
Clang<"requires_shared_capability", 0>,
@@ -3861,7 +3861,7 @@ def RequiresCapability : InheritableAttr {
   let TemplateDependent = 1;
   let ParseArgumentsAsUnevaluated = 1;
   let InheritEvenIfAlreadyPresent = 1;
-  let Subjects = SubjectList<[Function, ParmVar]>;
+  let Subjects = SubjectList<[Function, FunctionPointer, ParmVar]>;
   let Accessors = [Accessor<"isShared", [Clang<"requires_shared_capability", 
0>,
  Clang<"shared_locks_required", 0>]>];
   let Documentation = [Undocumented];
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index c55b964650323..ae623957896ac 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -13895,6 +13895,12 @@ class Sema final : public SemaBase {
   LocalInstantiationScope &Scope,
   const MultiLevelTemplateArgumentList &TemplateArgs);
 
+public:
+  void checkAttrArgsAreCapabilityObjs(Decl *D, const ParsedAttr &AL,
+  SmallVectorImpl &Args,
+  unsigned Sidx = 0,
+  bool ParamIdxOk = false);
+
   int ParsingClassDepth = 0;
 
   class SavePendingParsedClassStateRAII {
diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index 31695374cb52b..1f40f5d4e7096 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -2073,6 +2073,9 @@ void TypePrinter::printAttributedAfter(const 
AttributedType *T,
   case attr::ArmMveStrictPolymorphism:
 OS << "__clang_arm_mve_strict_polymorphism";
 break;
+  case attr::RequiresCapability:
+OS << "requires_capability(...)";
+break;
   }
   OS << "))";
 }
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 620290af9509f..a20b300e8c04b 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -337,12 +337,10 @@ static bool isCapabilityExpr(Sema &S, const Expr *Ex) {
 /// \param Sidx The attribute argument index to start checking with.
 /// \param ParamIdxOk Whether an argument can be indexing into a function
 /// parameter list.
-static void checkAttrArgsAreCapabilityObjs(Sema &S, Decl *D,
-   const ParsedAttr &AL,
-   SmallVectorImpl &Args,
-   unsigned Sidx = 0,
-   bool ParamIdxOk = false) {
-  if (Sidx == AL.getNumArgs()) {
+void Sema::checkAttrArgsAreCapabilityObjs(Decl *D, const ParsedAttr &AL,
+  SmallVectorImpl &Args,
+  unsigned Sidx, bool ParamIdxOk) {
+  if (D && Sidx == AL.getNumArgs()) {
 // If we don't have any capability arguments, the attribute implicitly
 // refers to 'this'. So we need to make sure that 'this' exists, i.e. we're
 // a non-static method, and that the class is a (scoped) capability.
@@ -352,11 +350,10 @@ static void checkAttrArgsAreCapabilityObjs(Sema &S, Decl 
*D,
   // FIXME -- need to check this again on template instantiation
   if (!checkRecordDeclForAttr(RD) &&
   !checkRecordDeclForAttr(RD))
-S.Diag(AL.getLoc(),
-   diag::warn_thread_attribute_not_on_capability_member)
+Diag(AL.getLoc(), diag::warn_thread_attribute_not_on_capability_member)
 << AL << MD->getParent();
 } else {
-  S.Diag(AL.getLoc(), diag::warn_thread_attribute_not_on_non_static_member)
+  Diag(AL.getLoc(), diag::warn_thread_attribute_not_on_non_static_member)
   << AL;
 }
   }

[clang] [llvm] [AMDGPU] Add builtins for wave reduction intrinsics (PR #127013)

2025-02-18 Thread via cfe-commits


@@ -20212,6 +20212,59 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned 
BuiltinID,
 llvm::Value *Env = EmitScalarExpr(E->getArg(0));
 return Builder.CreateCall(F, {Env});
   }
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_add_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_uadd_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_sub_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_usub_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_min_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_umin_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_max_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_umax_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_and_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_or_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_xor_i32: {
+Intrinsic::ID IID;
+switch (BuiltinID) {
+case AMDGPU::BI__builtin_amdgcn_wave_reduce_add_i32:
+  IID = Intrinsic::amdgcn_wave_reduce_add;
+  break;
+case AMDGPU::BI__builtin_amdgcn_wave_reduce_uadd_i32:
+  IID = Intrinsic::amdgcn_wave_reduce_uadd;
+  break;
+case AMDGPU::BI__builtin_amdgcn_wave_reduce_sub_i32:
+  IID = Intrinsic::amdgcn_wave_reduce_sub;
+  break;
+case AMDGPU::BI__builtin_amdgcn_wave_reduce_usub_i32:
+  IID = Intrinsic::amdgcn_wave_reduce_usub;
+  break;
+case AMDGPU::BI__builtin_amdgcn_wave_reduce_min_i32:
+  IID = Intrinsic::amdgcn_wave_reduce_min;
+  break;
+case AMDGPU::BI__builtin_amdgcn_wave_reduce_umin_i32:
+  IID = Intrinsic::amdgcn_wave_reduce_umin;
+  break;
+case AMDGPU::BI__builtin_amdgcn_wave_reduce_max_i32:
+  IID = Intrinsic::amdgcn_wave_reduce_max;
+  break;
+case AMDGPU::BI__builtin_amdgcn_wave_reduce_umax_i32:
+  IID = Intrinsic::amdgcn_wave_reduce_umax;
+  break;
+case AMDGPU::BI__builtin_amdgcn_wave_reduce_and_i32:
+  IID = Intrinsic::amdgcn_wave_reduce_and;
+  break;
+case AMDGPU::BI__builtin_amdgcn_wave_reduce_or_i32:
+  IID = Intrinsic::amdgcn_wave_reduce_or;
+  break;
+case AMDGPU::BI__builtin_amdgcn_wave_reduce_xor_i32:
+  IID = Intrinsic::amdgcn_wave_reduce_xor;
+  break;
+}
+llvm::Value *Src0 = EmitScalarExpr(E->getArg(0));
+llvm::Function *F = CGM.getIntrinsic(IID, {Src0->getType()});
+llvm::Value *Strategy =
+llvm::ConstantInt::get(llvm::Type::getInt32Ty(getLLVMContext()), 0);

easyonaadit wrote:

Right got it got it. I'll add it.

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


[clang] [analyzer] Do list initialization for CXXNewExpr with initializer list arg (PR #127702)

2025-02-18 Thread Michael Flanders via cfe-commits

https://github.com/Flandini updated 
https://github.com/llvm/llvm-project/pull/127702

>From 12791f2c89f7e42bd261ac573c2497857c42b6f3 Mon Sep 17 00:00:00 2001
From: Michael Flanders 
Date: Tue, 18 Feb 2025 15:56:13 -0600
Subject: [PATCH 1/4] [analyzer] Do list initialization for CXXNewExpr with
 initializer list arg

---
 clang/lib/StaticAnalyzer/Core/RegionStore.cpp |  18 +-
 clang/test/Analysis/initializer.cpp   | 185 ++
 2 files changed, 194 insertions(+), 9 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp 
b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
index d01b6ae55f611..e376b84f8219f 100644
--- a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -2425,6 +2425,15 @@ RegionStoreManager::bind(RegionBindingsConstRef B, Loc 
L, SVal V) {
 
   const MemRegion *R = MemRegVal->getRegion();
 
+  // Binding directly to a symbolic region should be treated as binding
+  // to element 0.
+  if (const auto *SymReg = dyn_cast(R)) {
+QualType Ty = SymReg->getPointeeStaticType();
+if (Ty->isVoidType())
+  Ty = StateMgr.getContext().CharTy;
+R = GetElementZeroRegion(SymReg, Ty);
+  }
+
   // Check if the region is a struct region.
   if (const TypedValueRegion* TR = dyn_cast(R)) {
 QualType Ty = TR->getValueType();
@@ -2438,15 +2447,6 @@ RegionStoreManager::bind(RegionBindingsConstRef B, Loc 
L, SVal V) {
   return bindAggregate(B, TR, V);
   }
 
-  // Binding directly to a symbolic region should be treated as binding
-  // to element 0.
-  if (const auto *SymReg = dyn_cast(R)) {
-QualType Ty = SymReg->getPointeeStaticType();
-if (Ty->isVoidType())
-  Ty = StateMgr.getContext().CharTy;
-R = GetElementZeroRegion(SymReg, Ty);
-  }
-
   assert((!isa(R) || !B.lookup(R)) &&
  "'this' pointer is not an l-value and is not assignable");
 
diff --git a/clang/test/Analysis/initializer.cpp 
b/clang/test/Analysis/initializer.cpp
index f50afff25d245..edc41d29e1df1 100644
--- a/clang/test/Analysis/initializer.cpp
+++ b/clang/test/Analysis/initializer.cpp
@@ -254,6 +254,191 @@ void foo() {
 }
 } // namespace CXX17_aggregate_construction
 
+namespace newexpr_init_list_initialization {
+struct S {
+  int foo;
+  int bar;
+};
+void none_designated() {
+  S *s = new S{13,1};
+  clang_analyzer_eval(13 == s->foo); // expected-warning{{TRUE}}
+  clang_analyzer_eval(1 == s->bar); // expected-warning{{TRUE}}
+  delete s;
+}
+void none_designated_swapped() {
+  S *s = new S{1,13};
+  clang_analyzer_eval(1 == s->foo); // expected-warning{{TRUE}}
+  clang_analyzer_eval(13 == s->bar); // expected-warning{{TRUE}}
+  delete s;
+}
+void one_designated_one_not() {
+  S *s = new S{ 1, .bar = 13 };
+  clang_analyzer_eval(1 == s->foo); // expected-warning{{TRUE}}
+  clang_analyzer_eval(13 == s->bar); // expected-warning{{TRUE}}
+  delete s;
+}
+void all_designated() {
+  S *s = new S{
+  .foo = 13,
+  .bar = 1,
+  };
+  clang_analyzer_eval(13 == s->foo); // expected-warning{{TRUE}}
+  clang_analyzer_eval(1 == s->bar); // expected-warning{{TRUE}}
+  delete s;
+}
+void non_designated_array_of_aggr_struct() {
+  S *s = new S[2] { {1, 2}, {3, 4} };
+  clang_analyzer_eval(1 == s[0].foo); // expected-warning{{TRUE}}
+  clang_analyzer_eval(2 == s[0].bar); // expected-warning{{TRUE}}
+  clang_analyzer_eval(3 == s[1].foo); // expected-warning{{TRUE}}
+  clang_analyzer_eval(4 == s[1].bar); // expected-warning{{TRUE}}
+  delete[] s;
+}
+
+struct WithGaps {
+  int foo;
+  int bar;
+  int baz;
+};
+void out_of_order_designated_initializers_with_gaps() {
+  WithGaps *s = new WithGaps{
+.foo = 13,
+.baz = 1,
+  };
+  clang_analyzer_eval(13 == s->foo); // expected-warning{{TRUE}}
+  clang_analyzer_eval(0 == s->bar); // expected-warning{{TRUE}}
+  clang_analyzer_eval(1 == s->baz); // expected-warning{{TRUE}}
+  delete s;
+}
+
+// https://eel.is/c++draft/dcl.init.aggr#note-6:
+// Static data members, non-static data members of anonymous
+// union members, and unnamed bit-fields are not considered
+// elements of the aggregate.
+struct NonConsideredFields {
+  int i;
+  static int s;
+  int j;
+  int :17;
+  int k;
+};
+void considered_fields_initd() {
+  auto S = new NonConsideredFields { 1, 2, 3 };
+  clang_analyzer_eval(1 == S->i); // expected-warning{{TRUE}}
+  clang_analyzer_eval(2 == S->j); // expected-warning{{TRUE}}
+  clang_analyzer_eval(3 == S->k); // expected-warning{{TRUE}}
+  delete S;
+}
+
+class PubClass {
+public:
+  int foo;
+  int bar;
+};
+void public_class_designated_initializers() {
+  S *s = new S{
+  .foo = 13,
+  .bar = 1,
+  };
+  clang_analyzer_eval(13 == s->foo); // expected-warning{{TRUE}}
+  clang_analyzer_eval(1 == s->bar); // expected-warning{{TRUE}}
+  delete s;
+}
+
+union UnionTestTy {
+  int x;
+  char y;
+};
+void new_expr_aggr_init_union_no_designator() {
+  UnionTestTy *u = new UnionTestTy{};
+  clang_analyzer_eval(0 == u->x); // expected-warning{{UNKNOWN}} TODO:

[clang] [flang] [flang][OpenMP] Upstream first part of `do concurrent` mapping (PR #126026)

2025-02-18 Thread Michael Klemm via cfe-commits

mjklemm wrote:

One warning per source file is what is being done for -fopenmp at the moment. 
So, it should be fine to do that. 

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


[clang] [clang-repl] fix error recovery while parsing completely fails (PR #127087)

2025-02-18 Thread Anutosh Bhat via cfe-commits

anutosh491 wrote:

Hmmm confused !

So does it really come down to the flag responsible for enabling assertions.
`LLVM_ENABLE_ASSERTIONS=ON`

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


[clang] [analyzer] Do list initialization for CXXNewExpr with initializer list arg (PR #127702)

2025-02-18 Thread Michael Flanders via cfe-commits

Flandini wrote:

Going to add tests for placement new and user-defined placement new operator 
with list initializers also

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


[clang] [analyzer] Do list initialization for CXXNewExpr with initializer list arg (PR #127702)

2025-02-18 Thread Michael Flanders via cfe-commits

https://github.com/Flandini updated 
https://github.com/llvm/llvm-project/pull/127702

>From 12791f2c89f7e42bd261ac573c2497857c42b6f3 Mon Sep 17 00:00:00 2001
From: Michael Flanders 
Date: Tue, 18 Feb 2025 15:56:13 -0600
Subject: [PATCH 1/5] [analyzer] Do list initialization for CXXNewExpr with
 initializer list arg

---
 clang/lib/StaticAnalyzer/Core/RegionStore.cpp |  18 +-
 clang/test/Analysis/initializer.cpp   | 185 ++
 2 files changed, 194 insertions(+), 9 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp 
b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
index d01b6ae55f611..e376b84f8219f 100644
--- a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -2425,6 +2425,15 @@ RegionStoreManager::bind(RegionBindingsConstRef B, Loc 
L, SVal V) {
 
   const MemRegion *R = MemRegVal->getRegion();
 
+  // Binding directly to a symbolic region should be treated as binding
+  // to element 0.
+  if (const auto *SymReg = dyn_cast(R)) {
+QualType Ty = SymReg->getPointeeStaticType();
+if (Ty->isVoidType())
+  Ty = StateMgr.getContext().CharTy;
+R = GetElementZeroRegion(SymReg, Ty);
+  }
+
   // Check if the region is a struct region.
   if (const TypedValueRegion* TR = dyn_cast(R)) {
 QualType Ty = TR->getValueType();
@@ -2438,15 +2447,6 @@ RegionStoreManager::bind(RegionBindingsConstRef B, Loc 
L, SVal V) {
   return bindAggregate(B, TR, V);
   }
 
-  // Binding directly to a symbolic region should be treated as binding
-  // to element 0.
-  if (const auto *SymReg = dyn_cast(R)) {
-QualType Ty = SymReg->getPointeeStaticType();
-if (Ty->isVoidType())
-  Ty = StateMgr.getContext().CharTy;
-R = GetElementZeroRegion(SymReg, Ty);
-  }
-
   assert((!isa(R) || !B.lookup(R)) &&
  "'this' pointer is not an l-value and is not assignable");
 
diff --git a/clang/test/Analysis/initializer.cpp 
b/clang/test/Analysis/initializer.cpp
index f50afff25d245..edc41d29e1df1 100644
--- a/clang/test/Analysis/initializer.cpp
+++ b/clang/test/Analysis/initializer.cpp
@@ -254,6 +254,191 @@ void foo() {
 }
 } // namespace CXX17_aggregate_construction
 
+namespace newexpr_init_list_initialization {
+struct S {
+  int foo;
+  int bar;
+};
+void none_designated() {
+  S *s = new S{13,1};
+  clang_analyzer_eval(13 == s->foo); // expected-warning{{TRUE}}
+  clang_analyzer_eval(1 == s->bar); // expected-warning{{TRUE}}
+  delete s;
+}
+void none_designated_swapped() {
+  S *s = new S{1,13};
+  clang_analyzer_eval(1 == s->foo); // expected-warning{{TRUE}}
+  clang_analyzer_eval(13 == s->bar); // expected-warning{{TRUE}}
+  delete s;
+}
+void one_designated_one_not() {
+  S *s = new S{ 1, .bar = 13 };
+  clang_analyzer_eval(1 == s->foo); // expected-warning{{TRUE}}
+  clang_analyzer_eval(13 == s->bar); // expected-warning{{TRUE}}
+  delete s;
+}
+void all_designated() {
+  S *s = new S{
+  .foo = 13,
+  .bar = 1,
+  };
+  clang_analyzer_eval(13 == s->foo); // expected-warning{{TRUE}}
+  clang_analyzer_eval(1 == s->bar); // expected-warning{{TRUE}}
+  delete s;
+}
+void non_designated_array_of_aggr_struct() {
+  S *s = new S[2] { {1, 2}, {3, 4} };
+  clang_analyzer_eval(1 == s[0].foo); // expected-warning{{TRUE}}
+  clang_analyzer_eval(2 == s[0].bar); // expected-warning{{TRUE}}
+  clang_analyzer_eval(3 == s[1].foo); // expected-warning{{TRUE}}
+  clang_analyzer_eval(4 == s[1].bar); // expected-warning{{TRUE}}
+  delete[] s;
+}
+
+struct WithGaps {
+  int foo;
+  int bar;
+  int baz;
+};
+void out_of_order_designated_initializers_with_gaps() {
+  WithGaps *s = new WithGaps{
+.foo = 13,
+.baz = 1,
+  };
+  clang_analyzer_eval(13 == s->foo); // expected-warning{{TRUE}}
+  clang_analyzer_eval(0 == s->bar); // expected-warning{{TRUE}}
+  clang_analyzer_eval(1 == s->baz); // expected-warning{{TRUE}}
+  delete s;
+}
+
+// https://eel.is/c++draft/dcl.init.aggr#note-6:
+// Static data members, non-static data members of anonymous
+// union members, and unnamed bit-fields are not considered
+// elements of the aggregate.
+struct NonConsideredFields {
+  int i;
+  static int s;
+  int j;
+  int :17;
+  int k;
+};
+void considered_fields_initd() {
+  auto S = new NonConsideredFields { 1, 2, 3 };
+  clang_analyzer_eval(1 == S->i); // expected-warning{{TRUE}}
+  clang_analyzer_eval(2 == S->j); // expected-warning{{TRUE}}
+  clang_analyzer_eval(3 == S->k); // expected-warning{{TRUE}}
+  delete S;
+}
+
+class PubClass {
+public:
+  int foo;
+  int bar;
+};
+void public_class_designated_initializers() {
+  S *s = new S{
+  .foo = 13,
+  .bar = 1,
+  };
+  clang_analyzer_eval(13 == s->foo); // expected-warning{{TRUE}}
+  clang_analyzer_eval(1 == s->bar); // expected-warning{{TRUE}}
+  delete s;
+}
+
+union UnionTestTy {
+  int x;
+  char y;
+};
+void new_expr_aggr_init_union_no_designator() {
+  UnionTestTy *u = new UnionTestTy{};
+  clang_analyzer_eval(0 == u->x); // expected-warning{{UNKNOWN}} TODO:

[clang] [llvm] [AMDGPU] Add builtins for wave reduction intrinsics (PR #127013)

2025-02-18 Thread Matt Arsenault via cfe-commits


@@ -20212,6 +20212,59 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned 
BuiltinID,
 llvm::Value *Env = EmitScalarExpr(E->getArg(0));
 return Builder.CreateCall(F, {Env});
   }
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_add_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_uadd_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_sub_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_usub_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_min_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_umin_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_max_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_umax_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_and_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_or_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_xor_i32: {
+Intrinsic::ID IID;
+switch (BuiltinID) {

arsenm wrote:

We should have a builtin -> intrinsic switch function somewhere 

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


[clang] [llvm] [AMDGPU] Add builtins for wave reduction intrinsics (PR #127013)

2025-02-18 Thread Matt Arsenault via cfe-commits


@@ -20212,6 +20212,59 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned 
BuiltinID,
 llvm::Value *Env = EmitScalarExpr(E->getArg(0));
 return Builder.CreateCall(F, {Env});
   }
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_add_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_uadd_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_sub_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_usub_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_min_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_umin_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_max_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_umax_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_and_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_or_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_xor_i32: {
+Intrinsic::ID IID;
+switch (BuiltinID) {
+case AMDGPU::BI__builtin_amdgcn_wave_reduce_add_i32:
+  IID = Intrinsic::amdgcn_wave_reduce_add;
+  break;
+case AMDGPU::BI__builtin_amdgcn_wave_reduce_uadd_i32:
+  IID = Intrinsic::amdgcn_wave_reduce_uadd;
+  break;
+case AMDGPU::BI__builtin_amdgcn_wave_reduce_sub_i32:
+  IID = Intrinsic::amdgcn_wave_reduce_sub;
+  break;
+case AMDGPU::BI__builtin_amdgcn_wave_reduce_usub_i32:
+  IID = Intrinsic::amdgcn_wave_reduce_usub;
+  break;
+case AMDGPU::BI__builtin_amdgcn_wave_reduce_min_i32:
+  IID = Intrinsic::amdgcn_wave_reduce_min;
+  break;
+case AMDGPU::BI__builtin_amdgcn_wave_reduce_umin_i32:
+  IID = Intrinsic::amdgcn_wave_reduce_umin;
+  break;
+case AMDGPU::BI__builtin_amdgcn_wave_reduce_max_i32:
+  IID = Intrinsic::amdgcn_wave_reduce_max;
+  break;
+case AMDGPU::BI__builtin_amdgcn_wave_reduce_umax_i32:
+  IID = Intrinsic::amdgcn_wave_reduce_umax;
+  break;
+case AMDGPU::BI__builtin_amdgcn_wave_reduce_and_i32:
+  IID = Intrinsic::amdgcn_wave_reduce_and;
+  break;
+case AMDGPU::BI__builtin_amdgcn_wave_reduce_or_i32:
+  IID = Intrinsic::amdgcn_wave_reduce_or;
+  break;
+case AMDGPU::BI__builtin_amdgcn_wave_reduce_xor_i32:
+  IID = Intrinsic::amdgcn_wave_reduce_xor;
+  break;
+}
+llvm::Value *Src0 = EmitScalarExpr(E->getArg(0));
+llvm::Function *F = CGM.getIntrinsic(IID, {Src0->getType()});
+llvm::Value *Strategy =
+llvm::ConstantInt::get(llvm::Type::getInt32Ty(getLLVMContext()), 0);

arsenm wrote:

Missing strategy argument? 

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


[clang] [llvm] [AMDGPU] Add builtins for wave reduction intrinsics (PR #127013)

2025-02-18 Thread Matt Arsenault via cfe-commits


@@ -346,6 +346,24 @@ BUILTIN(__builtin_amdgcn_endpgm, "v", "nr")
 BUILTIN(__builtin_amdgcn_get_fpenv, "WUi", "n")
 BUILTIN(__builtin_amdgcn_set_fpenv, "vWUi", "n")
 
+//===--===//
+
+// Wave Reduction builtins.
+
+//===--===//
+
+BUILTIN(__builtin_amdgcn_wave_reduce_add_i32, "ii", "nc")
+BUILTIN(__builtin_amdgcn_wave_reduce_uadd_i32, "ii", "nc")

arsenm wrote:

uadd_i32 -> add_u32 would be the more consistent naming convention. You're also 
using signed integer types for all of these, should use unsigned for the 
unsigned operations 

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


[clang] [llvm] [AMDGPU] Add builtins for wave reduction intrinsics (PR #127013)

2025-02-18 Thread via cfe-commits


@@ -20212,6 +20212,59 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned 
BuiltinID,
 llvm::Value *Env = EmitScalarExpr(E->getArg(0));
 return Builder.CreateCall(F, {Env});
   }
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_add_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_uadd_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_sub_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_usub_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_min_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_umin_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_max_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_umax_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_and_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_or_i32:
+  case AMDGPU::BI__builtin_amdgcn_wave_reduce_xor_i32: {
+Intrinsic::ID IID;
+switch (BuiltinID) {
+case AMDGPU::BI__builtin_amdgcn_wave_reduce_add_i32:
+  IID = Intrinsic::amdgcn_wave_reduce_add;
+  break;
+case AMDGPU::BI__builtin_amdgcn_wave_reduce_uadd_i32:
+  IID = Intrinsic::amdgcn_wave_reduce_uadd;
+  break;
+case AMDGPU::BI__builtin_amdgcn_wave_reduce_sub_i32:
+  IID = Intrinsic::amdgcn_wave_reduce_sub;
+  break;
+case AMDGPU::BI__builtin_amdgcn_wave_reduce_usub_i32:
+  IID = Intrinsic::amdgcn_wave_reduce_usub;
+  break;
+case AMDGPU::BI__builtin_amdgcn_wave_reduce_min_i32:
+  IID = Intrinsic::amdgcn_wave_reduce_min;
+  break;
+case AMDGPU::BI__builtin_amdgcn_wave_reduce_umin_i32:
+  IID = Intrinsic::amdgcn_wave_reduce_umin;
+  break;
+case AMDGPU::BI__builtin_amdgcn_wave_reduce_max_i32:
+  IID = Intrinsic::amdgcn_wave_reduce_max;
+  break;
+case AMDGPU::BI__builtin_amdgcn_wave_reduce_umax_i32:
+  IID = Intrinsic::amdgcn_wave_reduce_umax;
+  break;
+case AMDGPU::BI__builtin_amdgcn_wave_reduce_and_i32:
+  IID = Intrinsic::amdgcn_wave_reduce_and;
+  break;
+case AMDGPU::BI__builtin_amdgcn_wave_reduce_or_i32:
+  IID = Intrinsic::amdgcn_wave_reduce_or;
+  break;
+case AMDGPU::BI__builtin_amdgcn_wave_reduce_xor_i32:
+  IID = Intrinsic::amdgcn_wave_reduce_xor;
+  break;
+}
+llvm::Value *Src0 = EmitScalarExpr(E->getArg(0));
+llvm::Function *F = CGM.getIntrinsic(IID, {Src0->getType()});
+llvm::Value *Strategy =
+llvm::ConstantInt::get(llvm::Type::getInt32Ty(getLLVMContext()), 0);

easyonaadit wrote:

This is more of an implementation detail right? I wasn't sure if it should be 
exposed in the builtin.
Should I add it there?

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


[clang] [llvm] [RISCV] Assembler support for XRivosVizip (PR #127694)

2025-02-18 Thread Philip Reames via cfe-commits


@@ -202,6 +202,7 @@
 // CHECK-NEXT: xqcilo   0.2   'Xqcilo' (Qualcomm uC Large 
Offset Load Store Extension)
 // CHECK-NEXT: xqcilsm  0.2   'Xqcilsm' (Qualcomm uC Load 
Store Multiple Extension)
 // CHECK-NEXT: xqcisls  0.2   'Xqcisls' (Qualcomm uC 
Scaled Load Store Extension)
+// CHECK-NEXT: xrivosvizip  0.1   'XRivosVizip' (Rivos Vector 
Register Zips)

preames wrote:

As noted in my original comment, there is no existing consistency.  Ventana and 
THead both use vendor name in the extension name, not the instruction mnemonic 
prefix.  Examples:
```
$ fgrep ventana test/Driver/print-supported-extensions-riscv.c
// CHECK-NEXT: xventanacondops  1.0   'XVentanaCondOps' (Ventana 
Conditional Ops)
$ fgrep thead /test/Driver/print-supported-extensions-riscv.c 
// CHECK-NEXT: xtheadba 1.0   'XTHeadBa' (T-Head address 
calculation instructions)
// CHECK-NEXT: xtheadbb 1.0   'XTHeadBb' (T-Head basic 
bit-manipulation instructions)
// CHECK-NEXT: xtheadbs 1.0   'XTHeadBs' (T-Head single-bit 
instructions)
// CHECK-NEXT: xtheadcmo1.0   'XTHeadCmo' (T-Head cache 
management instructions)
// CHECK-NEXT: xtheadcondmov1.0   'XTHeadCondMov' (T-Head 
conditional move instructions)
// CHECK-NEXT: xtheadfmemidx1.0   'XTHeadFMemIdx' (T-Head FP 
Indexed Memory Operations)
// CHECK-NEXT: xtheadmac1.0   'XTHeadMac' (T-Head 
Multiply-Accumulate Instructions)
// CHECK-NEXT: xtheadmemidx 1.0   'XTHeadMemIdx' (T-Head 
Indexed Memory Operations)
// CHECK-NEXT: xtheadmempair1.0   'XTHeadMemPair' (T-Head 
two-GPR Memory Operations)
// CHECK-NEXT: xtheadsync   1.0   'XTHeadSync' (T-Head 
multicore synchronization instructions)
// CHECK-NEXT: xtheadvdot   1.0   'XTHeadVdot' (T-Head Vector 
Extensions for Dot)

```

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


[clang] [CIR] Upstream simple function bodies (PR #127674)

2025-02-18 Thread David Olsen via cfe-commits


@@ -11,8 +11,8 @@
 ///
 
//===--===//
 
-#ifndef LLVM_CLANG_CIR_DIALECT_IR_CIROPS
-#define LLVM_CLANG_CIR_DIALECT_IR_CIROPS
+#ifndef CLANG_CIR_DIALECT_IR_CIROPS_TD

dkolsen-pgi wrote:

Because the LLVM [coding 
guidelines](https://llvm.org/docs/CodingStandards.html#header-guard) for 
include guards only talk about that path that would be used when including the 
file.  `LLVM` isn't part of that.

(The guidelines don't say what to do for headers that are outside the `include` 
directory, such as those in `clang/lib/CIR/CodeGen`.  So I have been leaving 
the `LLVM` in those include guard macros.)


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


[clang] 9bf582f - [clang][docs] Fix typos concerning wasm __funcref (#124365)

2025-02-18 Thread via cfe-commits

Author: Timothy Herchen
Date: 2025-02-18T14:55:38-08:00
New Revision: 9bf582fc090f28c2423fdf472635c39145a13bc9

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

LOG: [clang][docs] Fix typos concerning wasm __funcref (#124365)

The docs conflate `__funcref` with an actual type in a couple places.

Added: 


Modified: 
clang/docs/LanguageExtensions.rst

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 2a956ad5b2909..5d9b68d4a7f2a 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -2629,7 +2629,7 @@ with the current table size.
 .. code-block:: c++
 
   typedef void (*__funcref funcref_t)();
-  static __funcref table[0];
+  static funcref_t table[0];
 
   size_t getSize() {
 return __builtin_wasm_table_size(table);
@@ -2651,10 +2651,10 @@ or -1. It will return -1 if not enough space could be 
allocated.
 .. code-block:: c++
 
   typedef void (*__funcref funcref_t)();
-  static __funcref table[0];
+  static funcref_t table[0];
 
   // grow returns the new table size or -1 on error.
-  int grow(__funcref fn, int delta) {
+  int grow(funcref_t fn, int delta) {
 int prevSize = __builtin_wasm_table_grow(table, fn, delta);
 if (prevSize == -1)
   return -1;



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


[clang] [clang][docs] Fix typos concerning wasm __funcref (PR #124365)

2025-02-18 Thread Heejin Ahn via cfe-commits

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


[clang] [llvm] [RISCV] Assembler support for XRivosVizip (PR #127694)

2025-02-18 Thread Jessica Clarke via cfe-commits


@@ -202,6 +202,7 @@
 // CHECK-NEXT: xqcilo   0.2   'Xqcilo' (Qualcomm uC Large 
Offset Load Store Extension)
 // CHECK-NEXT: xqcilsm  0.2   'Xqcilsm' (Qualcomm uC Load 
Store Multiple Extension)
 // CHECK-NEXT: xqcisls  0.2   'Xqcisls' (Qualcomm uC 
Scaled Load Store Extension)
+// CHECK-NEXT: xrivosvizip  0.1   'XRivosVizip' (Rivos Vector 
Register Zips)

jrtc27 wrote:

Both are acceptable:

> To make it easier to identify and prevent naming conflict, vendor extensions 
> should start with a vendor name, which could be an abbreviation of the full 
> name.

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


[clang] [clang][LoongArch] Add OHOS target (PR #127555)

2025-02-18 Thread Lu Weining via cfe-commits


@@ -368,7 +370,12 @@ void OHOS::addExtraOpts(llvm::opt::ArgStringList &CmdArgs) 
const {
   CmdArgs.push_back("-z");
   CmdArgs.push_back("relro");
   CmdArgs.push_back("-z");
-  CmdArgs.push_back("max-page-size=4096");
+  // LoongArch needs page size 16K

SixWeining wrote:

The comment is unnecessary as the code explains itself.

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


[clang] [clang][LoongArch] Add OHOS target (PR #127555)

2025-02-18 Thread Lu Weining via cfe-commits


@@ -368,7 +370,12 @@ void OHOS::addExtraOpts(llvm::opt::ArgStringList &CmdArgs) 
const {
   CmdArgs.push_back("-z");
   CmdArgs.push_back("relro");
   CmdArgs.push_back("-z");
-  CmdArgs.push_back("max-page-size=4096");
+  // LoongArch needs page size 16K
+  if (getArch() == llvm::Triple::loongarch64) {
+CmdArgs.push_back("max-page-size=16384");
+  } else {
+CmdArgs.push_back("max-page-size=4096");
+  }

SixWeining wrote:

```suggestion
  CmdArgs.push_back(getArch() == llvm::Triple::loongarch64
? "max-page-size=16384"
: "max-page-size=4096");
```

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


[clang] [clang][LoongArch] Add OHOS target (PR #127555)

2025-02-18 Thread Lu Weining via cfe-commits

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


[clang] [clang][LoongArch] Add OHOS target (PR #127555)

2025-02-18 Thread Lu Weining via cfe-commits

https://github.com/SixWeining commented:

LGTM for the LoongArch change. We'll see if @kpdev has any objections later.

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


[clang] [Driver][MSVC] Add lto-sample-profile option for lld-link (PR #127442)

2025-02-18 Thread Haohai Wen via cfe-commits

HaohaiWen wrote:

This tittle looks like you are adding a new option -lto-sample-profile for LLD.
It's recommended to rename the tittle so that other developer can easily know 
you are trying to pass profile file to lto backend via -lto-sample-profile.

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


[clang] [HLSL] Implement the 'and' HLSL function (PR #127098)

2025-02-18 Thread Farzon Lotfi via cfe-commits

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


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


[clang] [C++20] [Modules] Instantiate pending instantiations when GMF ends (PR #126842)

2025-02-18 Thread Chuanqi Xu via cfe-commits


@@ -1104,9 +1104,13 @@ void Sema::ActOnStartOfTranslationUnit() {
 }
 
 void Sema::ActOnEndOfTranslationUnitFragment(TUFragmentKind Kind) {
-  // No explicit actions are required at the end of the global module fragment.
-  if (Kind == TUFragmentKind::Global)
+  if (Kind == TUFragmentKind::Global) {
+// Perform Pending Instantiations at the end of global module fragment so
+// that the module ownership of TU-level decls won't get messed.
+llvm::TimeTraceScope TimeScope("PerformPendingInstantiations");
+PerformPendingInstantiations();

ChuanqiXu9 wrote:

@mizvekov ping~

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


[clang] [clang][LoongArch] Add OHOS target (PR #127555)

2025-02-18 Thread Lu Weining via cfe-commits


@@ -741,16 +741,28 @@ std::unique_ptr AllocateTarget(const 
llvm::Triple &Triple,
   case llvm::Triple::loongarch32:
 switch (os) {
 case llvm::Triple::Linux:
-  return std::make_unique>(Triple,
-  Opts);
+  switch (Triple.getEnvironment()) {
+  default:
+return std::make_unique>(Triple,
+Opts);
+  case llvm::Triple::OpenHOS:
+return std::make_unique>(Triple,
+   Opts);
+  }

SixWeining wrote:

I think this patch should only focus on LoongArch64. LoongArch32 could be added 
in future.

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


[clang] [clang][LoongArch] Add OHOS target (PR #127555)

2025-02-18 Thread Lu Weining via cfe-commits


@@ -2458,7 +2458,8 @@ void 
Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
 
   static const char *const LoongArch64LibDirs[] = {"/lib64", "/lib"};
   static const char *const LoongArch64Triples[] = {
-  "loongarch64-linux-gnu", "loongarch64-unknown-linux-gnu"};
+  "loongarch64-linux-gnu", "loongarch64-unknown-linux-gnu",
+  "loongarch64-linux-ohos"};

SixWeining wrote:

Why the ohos triple is added to `Gnu.cpp`. Seems that aarch64 and x86-64 don't 
add them.

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


[clang] [clang][LoongArch] Add OHOS target (PR #127555)

2025-02-18 Thread Lu Weining via cfe-commits

https://github.com/SixWeining commented:

I think you should add more tests like 
`clang/test/Driver/loongarch-toolchain.c` and https://reviews.llvm.org/D55029.

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


[clang] [HLSL] Constant buffers codegen (PR #124886)

2025-02-18 Thread Helena Kotas via cfe-commits


@@ -115,48 +83,176 @@ llvm::Triple::ArchType CGHLSLRuntime::getArch() {
   return CGM.getTarget().getTriple().getArch();
 }
 
-void CGHLSLRuntime::addConstant(VarDecl *D, Buffer &CB) {
-  if (D->getStorageClass() == SC_Static) {
-// For static inside cbuffer, take as global static.
-// Don't add to cbuffer.
-CGM.EmitGlobal(D);
-return;
-  }
+// Returns true if the type is an HLSL resource class
+static bool isResourceRecordType(const clang::Type *Ty) {
+  return HLSLAttributedResourceType::findHandleTypeOnResource(Ty) != nullptr;
+}
 
-  auto *GV = cast(CGM.GetAddrOfGlobalVar(D));
-  GV->setExternallyInitialized(true);
-  // Add debug info for constVal.
-  if (CGDebugInfo *DI = CGM.getModuleDebugInfo())
-if (CGM.getCodeGenOpts().getDebugInfo() >=
-codegenoptions::DebugInfoKind::LimitedDebugInfo)
-  DI->EmitGlobalVariable(cast(GV), D);
-
-  // FIXME: support packoffset.
-  // See https://github.com/llvm/llvm-project/issues/57914.
-  uint32_t Offset = 0;
-  bool HasUserOffset = false;
-
-  unsigned LowerBound = HasUserOffset ? Offset : UINT_MAX;
-  CB.Constants.emplace_back(std::make_pair(GV, LowerBound));
+// Returns true if the type is an HLSL resource class or an array of them
+static bool isResourceRecordTypeOrArrayOf(const clang::Type *Ty) {
+  while (const ConstantArrayType *CAT = dyn_cast(Ty))
+Ty = CAT->getArrayElementTypeNoTypeQual();
+  return isResourceRecordType(Ty);
 }
 
-void CGHLSLRuntime::addBufferDecls(const DeclContext *DC, Buffer &CB) {
-  for (Decl *it : DC->decls()) {
-if (auto *ConstDecl = dyn_cast(it)) {
-  addConstant(ConstDecl, CB);
-} else if (isa(it)) {
+// Emits constant global variables for buffer constants declarations
+// and creates metadata linking the constant globals with the buffer global.
+void CGHLSLRuntime::emitBufferGlobalsAndMetadata(const HLSLBufferDecl *BufDecl,
+ llvm::GlobalVariable *BufGV) {
+  LLVMContext &Ctx = CGM.getLLVMContext();
+
+  // get the layout struct from constant buffer target type
+  llvm::Type *BufType = BufGV->getValueType();
+  assert(isa(BufType) &&
+ "expected target type for HLSL buffer resource");
+  llvm::Type *BufLayoutType =
+  cast(BufType)->getTypeParameter(0);
+  assert(isa(BufLayoutType) &&
+ "expected target type for buffer layout struct");
+  llvm::StructType *LayoutStruct = cast(
+  cast(BufLayoutType)->getTypeParameter(0));

hekota wrote:

I know, I wanted more descriptive messages, but you are right, it is redundant.

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


[clang] [clang][LoongArch] Add OHOS target (PR #127555)

2025-02-18 Thread Lu Weining via cfe-commits

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


[clang] [clang][Tooling] Support relative directory in compilation database (PR #127734)

2025-02-18 Thread Keith Smiley via cfe-commits

https://github.com/keith created 
https://github.com/llvm/llvm-project/pull/127734

This allows you to use `"directory": ".",` in `compile_commands.json`
and have it be understood for file lookup by `clangd`.


>From 6ad2014e4c69c3d949f081b522630f804a4db567 Mon Sep 17 00:00:00 2001
From: Keith Smiley 
Date: Wed, 19 Feb 2025 01:54:42 +
Subject: [PATCH] [clang][Tooling] Support relative directory in compilation
 database

This allows you to use `"directory": ".",` in `compile_commands.json`
and have it be understood for file lookup by `clangd`.
---
 clang/lib/Tooling/JSONCompilationDatabase.cpp |  1 +
 .../Tooling/CompilationDatabaseTest.cpp   | 24 +++
 2 files changed, 25 insertions(+)

diff --git a/clang/lib/Tooling/JSONCompilationDatabase.cpp 
b/clang/lib/Tooling/JSONCompilationDatabase.cpp
index 5ecba5dfece3d..625ac034d639a 100644
--- a/clang/lib/Tooling/JSONCompilationDatabase.cpp
+++ b/clang/lib/Tooling/JSONCompilationDatabase.cpp
@@ -419,6 +419,7 @@ bool JSONCompilationDatabase::parse(std::string 
&ErrorMessage) {
 if (llvm::sys::path::is_relative(FileName)) {
   SmallString<8> DirectoryStorage;
   SmallString<128> AbsolutePath(Directory->getValue(DirectoryStorage));
+  llvm::sys::fs::make_absolute(AbsolutePath);
   llvm::sys::path::append(AbsolutePath, FileName);
   llvm::sys::path::native(AbsolutePath, NativeFilePath);
 } else {
diff --git a/clang/unittests/Tooling/CompilationDatabaseTest.cpp 
b/clang/unittests/Tooling/CompilationDatabaseTest.cpp
index 2032b13726c45..c5d3de7fb2384 100644
--- a/clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ b/clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -399,6 +399,30 @@ TEST(findCompileArgsInJsonDatabase, FindsEntry) {
   EXPECT_EQ("command4", FoundCommand.CommandLine[0]) << ErrorMessage;
 }
 
+TEST(findCompileArgsInJsonDatabase, FindsEntryRelativeDirectory) {
+  StringRef Directory(".");
+  StringRef FileName("file");
+  StringRef Command("command");
+  std::string JsonDatabase = "[";
+  JsonDatabase +=
+("{\"directory\":\"" + Directory + "\"," +
+  "\"command\":\"" + Command + "\","
+  "\"file\":\"" + FileName + "\"}").str();
+  JsonDatabase += "]";
+
+  SmallString<256> Result;
+  llvm::sys::fs::current_path(Result);
+  llvm::sys::path::append(Result, FileName);
+
+  std::string ErrorMessage;
+  CompileCommand FoundCommand = findCompileArgsInJsonDatabase(
+Result, JsonDatabase, ErrorMessage);
+
+  EXPECT_EQ(".", FoundCommand.Directory) << ErrorMessage;
+  ASSERT_EQ(1u, FoundCommand.CommandLine.size()) << ErrorMessage;
+  EXPECT_EQ("command", FoundCommand.CommandLine[0]) << ErrorMessage;
+}
+
 TEST(findCompileArgsInJsonDatabase, ParsesCompilerWrappers) {
   std::vector> Cases = {
   {"distcc gcc foo.c", "gcc foo.c"},

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


[clang] [HLSL] Constant buffers codegen (PR #124886)

2025-02-18 Thread Helena Kotas via cfe-commits


@@ -115,48 +83,176 @@ llvm::Triple::ArchType CGHLSLRuntime::getArch() {
   return CGM.getTarget().getTriple().getArch();
 }
 
-void CGHLSLRuntime::addConstant(VarDecl *D, Buffer &CB) {
-  if (D->getStorageClass() == SC_Static) {
-// For static inside cbuffer, take as global static.
-// Don't add to cbuffer.
-CGM.EmitGlobal(D);
-return;
-  }
+// Returns true if the type is an HLSL resource class
+static bool isResourceRecordType(const clang::Type *Ty) {
+  return HLSLAttributedResourceType::findHandleTypeOnResource(Ty) != nullptr;
+}
 
-  auto *GV = cast(CGM.GetAddrOfGlobalVar(D));
-  GV->setExternallyInitialized(true);
-  // Add debug info for constVal.
-  if (CGDebugInfo *DI = CGM.getModuleDebugInfo())
-if (CGM.getCodeGenOpts().getDebugInfo() >=
-codegenoptions::DebugInfoKind::LimitedDebugInfo)
-  DI->EmitGlobalVariable(cast(GV), D);
-
-  // FIXME: support packoffset.
-  // See https://github.com/llvm/llvm-project/issues/57914.
-  uint32_t Offset = 0;
-  bool HasUserOffset = false;
-
-  unsigned LowerBound = HasUserOffset ? Offset : UINT_MAX;
-  CB.Constants.emplace_back(std::make_pair(GV, LowerBound));
+// Returns true if the type is an HLSL resource class or an array of them
+static bool isResourceRecordTypeOrArrayOf(const clang::Type *Ty) {
+  while (const ConstantArrayType *CAT = dyn_cast(Ty))
+Ty = CAT->getArrayElementTypeNoTypeQual();
+  return isResourceRecordType(Ty);
 }
 
-void CGHLSLRuntime::addBufferDecls(const DeclContext *DC, Buffer &CB) {
-  for (Decl *it : DC->decls()) {
-if (auto *ConstDecl = dyn_cast(it)) {
-  addConstant(ConstDecl, CB);
-} else if (isa(it)) {
+// Emits constant global variables for buffer constants declarations
+// and creates metadata linking the constant globals with the buffer global.
+void CGHLSLRuntime::emitBufferGlobalsAndMetadata(const HLSLBufferDecl *BufDecl,
+ llvm::GlobalVariable *BufGV) {
+  LLVMContext &Ctx = CGM.getLLVMContext();
+
+  // get the layout struct from constant buffer target type
+  llvm::Type *BufType = BufGV->getValueType();
+  assert(isa(BufType) &&
+ "expected target type for HLSL buffer resource");
+  llvm::Type *BufLayoutType =
+  cast(BufType)->getTypeParameter(0);
+  assert(isa(BufLayoutType) &&
+ "expected target type for buffer layout struct");
+  llvm::StructType *LayoutStruct = cast(
+  cast(BufLayoutType)->getTypeParameter(0));
+
+  // Start metadata list associating the buffer global variable with its
+  // constatns
+  SmallVector BufGlobals;
+  BufGlobals.push_back(ValueAsMetadata::get(BufGV));
+
+  const auto *ElemIt = LayoutStruct->element_begin();
+  for (Decl *D : BufDecl->decls()) {
+if (isa(D))
   // Nothing to do for this declaration.
-} else if (isa(it)) {
-  // A function within an cbuffer is effectively a top-level function,
-  // as it only refers to globally scoped declarations.
-  CGM.EmitTopLevelDecl(it);
+  continue;
+if (isa(D)) {
+  // A function within an cbuffer is effectively a top-level function.
+  CGM.EmitTopLevelDecl(D);
+  continue;
+}
+VarDecl *VD = dyn_cast(D);
+if (!VD)
+  continue;
+
+QualType VDTy = VD->getType();
+if (VDTy.getAddressSpace() != LangAS::hlsl_constant) {
+  if (VD->getStorageClass() == SC_Static ||
+  VDTy.getAddressSpace() == LangAS::hlsl_groupshared ||
+  isResourceRecordTypeOrArrayOf(VDTy.getTypePtr())) {
+// Emit static and groupshared variables and resource classes inside
+// cbuffer as regular globals
+CGM.EmitGlobal(VD);
+  }
+  // Anything else that is not in the hlsl_constant address space must be
+  // an empty struct or a zero-sized array and can be ignored
+  continue;
+}
+
+assert(ElemIt != LayoutStruct->element_end() &&
+   "number of elements in layout struct does not match");
+llvm::Type *LayoutType = *ElemIt++;
+
+// there might be resources inside the used defined structs
+if (VDTy->isStructureType() && VDTy->isHLSLIntangibleType())
+  // FIXME: handle resources in cbuffer structs
+  llvm_unreachable("resources in cbuffer are not supported yet");

hekota wrote:

I am actually removing the `llvm_unreachable` in an [upcoming 
PR](https://github.com/llvm/llvm-project/pull/125807) because we have many 
existing tests that use resources in user structs. Issue that tracks adding 
codegen support for this is [here](https://github.com/llvm/wg-hlsl/issues/175).

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


[clang] [clang][Tooling] Support relative directory in compilation database (PR #127734)

2025-02-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Keith Smiley (keith)


Changes

This allows you to use `"directory": ".",` in `compile_commands.json`
and have it be understood for file lookup by `clangd`.


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


2 Files Affected:

- (modified) clang/lib/Tooling/JSONCompilationDatabase.cpp (+1) 
- (modified) clang/unittests/Tooling/CompilationDatabaseTest.cpp (+24) 


``diff
diff --git a/clang/lib/Tooling/JSONCompilationDatabase.cpp 
b/clang/lib/Tooling/JSONCompilationDatabase.cpp
index 5ecba5dfece3d..625ac034d639a 100644
--- a/clang/lib/Tooling/JSONCompilationDatabase.cpp
+++ b/clang/lib/Tooling/JSONCompilationDatabase.cpp
@@ -419,6 +419,7 @@ bool JSONCompilationDatabase::parse(std::string 
&ErrorMessage) {
 if (llvm::sys::path::is_relative(FileName)) {
   SmallString<8> DirectoryStorage;
   SmallString<128> AbsolutePath(Directory->getValue(DirectoryStorage));
+  llvm::sys::fs::make_absolute(AbsolutePath);
   llvm::sys::path::append(AbsolutePath, FileName);
   llvm::sys::path::native(AbsolutePath, NativeFilePath);
 } else {
diff --git a/clang/unittests/Tooling/CompilationDatabaseTest.cpp 
b/clang/unittests/Tooling/CompilationDatabaseTest.cpp
index 2032b13726c45..c5d3de7fb2384 100644
--- a/clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ b/clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -399,6 +399,30 @@ TEST(findCompileArgsInJsonDatabase, FindsEntry) {
   EXPECT_EQ("command4", FoundCommand.CommandLine[0]) << ErrorMessage;
 }
 
+TEST(findCompileArgsInJsonDatabase, FindsEntryRelativeDirectory) {
+  StringRef Directory(".");
+  StringRef FileName("file");
+  StringRef Command("command");
+  std::string JsonDatabase = "[";
+  JsonDatabase +=
+("{\"directory\":\"" + Directory + "\"," +
+  "\"command\":\"" + Command + "\","
+  "\"file\":\"" + FileName + "\"}").str();
+  JsonDatabase += "]";
+
+  SmallString<256> Result;
+  llvm::sys::fs::current_path(Result);
+  llvm::sys::path::append(Result, FileName);
+
+  std::string ErrorMessage;
+  CompileCommand FoundCommand = findCompileArgsInJsonDatabase(
+Result, JsonDatabase, ErrorMessage);
+
+  EXPECT_EQ(".", FoundCommand.Directory) << ErrorMessage;
+  ASSERT_EQ(1u, FoundCommand.CommandLine.size()) << ErrorMessage;
+  EXPECT_EQ("command", FoundCommand.CommandLine[0]) << ErrorMessage;
+}
+
 TEST(findCompileArgsInJsonDatabase, ParsesCompilerWrappers) {
   std::vector> Cases = {
   {"distcc gcc foo.c", "gcc foo.c"},

``




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


[clang] [clang][Tooling] Support relative directory in compilation database (PR #127734)

2025-02-18 Thread Keith Smiley via cfe-commits


@@ -399,6 +399,32 @@ TEST(findCompileArgsInJsonDatabase, FindsEntry) {
   EXPECT_EQ("command4", FoundCommand.CommandLine[0]) << ErrorMessage;
 }
 
+TEST(findCompileArgsInJsonDatabase, FindsEntryRelativeDirectory) {
+  StringRef Directory(".");
+  StringRef FileName("file");
+  StringRef Command("command");
+  std::string JsonDatabase = "[";
+  JsonDatabase +=
+  ("{\"directory\":\"" + Directory + "\"," + "\"command\":\"" + Command +
+   "\","
+   "\"file\":\"" +
+   FileName + "\"}")

keith wrote:

clang-format fighting me on this one

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


[clang] [HLSL] Constant buffers codegen (PR #124886)

2025-02-18 Thread Helena Kotas via cfe-commits


@@ -115,48 +83,176 @@ llvm::Triple::ArchType CGHLSLRuntime::getArch() {
   return CGM.getTarget().getTriple().getArch();
 }
 
-void CGHLSLRuntime::addConstant(VarDecl *D, Buffer &CB) {
-  if (D->getStorageClass() == SC_Static) {
-// For static inside cbuffer, take as global static.
-// Don't add to cbuffer.
-CGM.EmitGlobal(D);
-return;
-  }
+// Returns true if the type is an HLSL resource class
+static bool isResourceRecordType(const clang::Type *Ty) {
+  return HLSLAttributedResourceType::findHandleTypeOnResource(Ty) != nullptr;
+}
 
-  auto *GV = cast(CGM.GetAddrOfGlobalVar(D));
-  GV->setExternallyInitialized(true);
-  // Add debug info for constVal.
-  if (CGDebugInfo *DI = CGM.getModuleDebugInfo())
-if (CGM.getCodeGenOpts().getDebugInfo() >=
-codegenoptions::DebugInfoKind::LimitedDebugInfo)
-  DI->EmitGlobalVariable(cast(GV), D);
-
-  // FIXME: support packoffset.
-  // See https://github.com/llvm/llvm-project/issues/57914.
-  uint32_t Offset = 0;
-  bool HasUserOffset = false;
-
-  unsigned LowerBound = HasUserOffset ? Offset : UINT_MAX;
-  CB.Constants.emplace_back(std::make_pair(GV, LowerBound));
+// Returns true if the type is an HLSL resource class or an array of them
+static bool isResourceRecordTypeOrArrayOf(const clang::Type *Ty) {
+  while (const ConstantArrayType *CAT = dyn_cast(Ty))
+Ty = CAT->getArrayElementTypeNoTypeQual();
+  return isResourceRecordType(Ty);
 }
 
-void CGHLSLRuntime::addBufferDecls(const DeclContext *DC, Buffer &CB) {
-  for (Decl *it : DC->decls()) {
-if (auto *ConstDecl = dyn_cast(it)) {
-  addConstant(ConstDecl, CB);
-} else if (isa(it)) {
+// Emits constant global variables for buffer constants declarations
+// and creates metadata linking the constant globals with the buffer global.
+void CGHLSLRuntime::emitBufferGlobalsAndMetadata(const HLSLBufferDecl *BufDecl,
+ llvm::GlobalVariable *BufGV) {
+  LLVMContext &Ctx = CGM.getLLVMContext();
+
+  // get the layout struct from constant buffer target type
+  llvm::Type *BufType = BufGV->getValueType();
+  assert(isa(BufType) &&
+ "expected target type for HLSL buffer resource");
+  llvm::Type *BufLayoutType =
+  cast(BufType)->getTypeParameter(0);
+  assert(isa(BufLayoutType) &&
+ "expected target type for buffer layout struct");
+  llvm::StructType *LayoutStruct = cast(
+  cast(BufLayoutType)->getTypeParameter(0));
+
+  // Start metadata list associating the buffer global variable with its
+  // constatns
+  SmallVector BufGlobals;
+  BufGlobals.push_back(ValueAsMetadata::get(BufGV));
+
+  const auto *ElemIt = LayoutStruct->element_begin();
+  for (Decl *D : BufDecl->decls()) {
+if (isa(D))
   // Nothing to do for this declaration.
-} else if (isa(it)) {
-  // A function within an cbuffer is effectively a top-level function,
-  // as it only refers to globally scoped declarations.
-  CGM.EmitTopLevelDecl(it);
+  continue;
+if (isa(D)) {
+  // A function within an cbuffer is effectively a top-level function.
+  CGM.EmitTopLevelDecl(D);
+  continue;
+}
+VarDecl *VD = dyn_cast(D);
+if (!VD)
+  continue;
+
+QualType VDTy = VD->getType();
+if (VDTy.getAddressSpace() != LangAS::hlsl_constant) {
+  if (VD->getStorageClass() == SC_Static ||
+  VDTy.getAddressSpace() == LangAS::hlsl_groupshared ||
+  isResourceRecordTypeOrArrayOf(VDTy.getTypePtr())) {
+// Emit static and groupshared variables and resource classes inside
+// cbuffer as regular globals
+CGM.EmitGlobal(VD);
+  }
+  // Anything else that is not in the hlsl_constant address space must be
+  // an empty struct or a zero-sized array and can be ignored
+  continue;
+}
+
+assert(ElemIt != LayoutStruct->element_end() &&
+   "number of elements in layout struct does not match");
+llvm::Type *LayoutType = *ElemIt++;
+
+// there might be resources inside the used defined structs
+if (VDTy->isStructureType() && VDTy->isHLSLIntangibleType())
+  // FIXME: handle resources in cbuffer structs
+  llvm_unreachable("resources in cbuffer are not supported yet");

hekota wrote:

I'll actually remove the `llvm_unreachable` now in this PR.

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


[clang] [CIR] Upstream simple function bodies (PR #127674)

2025-02-18 Thread David Olsen via cfe-commits


@@ -0,0 +1,203 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+//
+// Internal per-function state used for AST-to-ClangIR code gen
+//
+//===--===//
+
+#include "CIRGenFunction.h"
+
+#include "clang/AST/GlobalDecl.h"
+
+#include 
+
+namespace clang::CIRGen {
+
+CIRGenFunction::CIRGenFunction(CIRGenModule &cgm, CIRGenBuilderTy &builder,
+   bool suppressNewContext)
+: CIRGenTypeCache(cgm), cgm{cgm}, builder(builder) {}
+
+CIRGenFunction::~CIRGenFunction() {}
+
+// This is copied from clang/lib/CodeGen/CodeGenFunction.cpp
+cir::TypeEvaluationKind CIRGenFunction::getEvaluationKind(QualType type) {
+  type = type.getCanonicalType();
+  while (true) {
+switch (type->getTypeClass()) {
+#define TYPE(name, parent)
+#define ABSTRACT_TYPE(name, parent)
+#define NON_CANONICAL_TYPE(name, parent) case Type::name:
+#define DEPENDENT_TYPE(name, parent) case Type::name:
+#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(name, parent) case Type::name:
+#include "clang/AST/TypeNodes.inc"
+  llvm_unreachable("non-canonical or dependent type in IR-generation");
+
+case Type::ArrayParameter:
+case Type::HLSLAttributedResource:
+  llvm_unreachable("NYI");
+
+case Type::Auto:
+case Type::DeducedTemplateSpecialization:
+  llvm_unreachable("undeduced type in IR-generation");
+
+// Various scalar types.
+case Type::Builtin:
+case Type::Pointer:
+case Type::BlockPointer:
+case Type::LValueReference:
+case Type::RValueReference:
+case Type::MemberPointer:
+case Type::Vector:
+case Type::ExtVector:
+case Type::ConstantMatrix:
+case Type::FunctionProto:
+case Type::FunctionNoProto:
+case Type::Enum:
+case Type::ObjCObjectPointer:
+case Type::Pipe:
+case Type::BitInt:
+  return cir::TEK_Scalar;
+
+// Complexes.
+case Type::Complex:
+  return cir::TEK_Complex;
+
+// Arrays, records, and Objective-C objects.
+case Type::ConstantArray:
+case Type::IncompleteArray:
+case Type::VariableArray:
+case Type::Record:
+case Type::ObjCObject:
+case Type::ObjCInterface:
+  return cir::TEK_Aggregate;
+
+// We operate on atomic values according to their underlying type.
+case Type::Atomic:
+  type = cast(type)->getValueType();
+  continue;
+}
+llvm_unreachable("unknown type kind!");
+  }
+}
+
+mlir::Type CIRGenFunction::convertTypeForMem(QualType t) {
+  return cgm.getTypes().convertTypeForMem(t);
+}
+
+mlir::Type CIRGenFunction::convertType(QualType t) {
+  return cgm.getTypes().convertType(t);
+}
+
+mlir::Location CIRGenFunction::getLoc(SourceLocation srcLoc) {
+  // Some AST nodes might contain invalid source locations (e.g.
+  // CXXDefaultArgExpr), workaround that to still get something out.
+  if (srcLoc.isValid()) {
+const SourceManager &sm = getContext().getSourceManager();
+PresumedLoc pLoc = sm.getPresumedLoc(srcLoc);
+StringRef filename = pLoc.getFilename();
+return mlir::FileLineColLoc::get(builder.getStringAttr(filename),
+ pLoc.getLine(), pLoc.getColumn());
+  } else {
+// Do our best...
+assert(currSrcLoc && "expected to inherit some source location");
+return *currSrcLoc;
+  }
+}
+
+mlir::Location CIRGenFunction::getLoc(SourceRange srcLoc) {
+  // Some AST nodes might contain invalid source locations (e.g.
+  // CXXDefaultArgExpr), workaround that to still get something out.
+  if (srcLoc.isValid()) {
+mlir::Location beg = getLoc(srcLoc.getBegin());
+mlir::Location end = getLoc(srcLoc.getEnd());
+SmallVector locs = {beg, end};
+mlir::Attribute metadata;
+return mlir::FusedLoc::get(locs, metadata, &getMLIRContext());
+  } else if (currSrcLoc) {
+return *currSrcLoc;
+  }
+
+  // We're brave, but time to give up.
+  return builder.getUnknownLoc();
+}
+
+mlir::Location CIRGenFunction::getLoc(mlir::Location lhs, mlir::Location rhs) {

dkolsen-pgi wrote:

Not that I know of.

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


[clang] [llvm] [WebAssembly] Enable extended-const feature by default (PR #127721)

2025-02-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-webassembly

Author: Sam Clegg (sbc100)


Changes



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


6 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+7) 
- (modified) clang/lib/Basic/Targets/WebAssembly.cpp (+1) 
- (modified) clang/test/Preprocessor/wasm-target-features.c (+1-1) 
- (modified) llvm/docs/ReleaseNotes.md (+7) 
- (modified) llvm/lib/Target/WebAssembly/WebAssembly.td (+4-3) 
- (modified) llvm/test/CodeGen/WebAssembly/target-features-cpus.ll (+4-1) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6056a6964fbcc..7b90d4686d96f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -235,6 +235,13 @@ NetBSD Support
 WebAssembly Support
 ^^^
 
+The default target CPU, "generic", now enables the `-mextended-const`
+flag, which correspond to the [Extended Const] proposal, which is
+[widely implemented in engines].
+
+[Extended Const]: https://github.com/WebAssembly/extended-const
+[widely implemented in engines]: https://webassembly.org/features/
+
 AVR Support
 ^^^
 
diff --git a/clang/lib/Basic/Targets/WebAssembly.cpp 
b/clang/lib/Basic/Targets/WebAssembly.cpp
index f19c57f1a3a50..848b28441e22d 100644
--- a/clang/lib/Basic/Targets/WebAssembly.cpp
+++ b/clang/lib/Basic/Targets/WebAssembly.cpp
@@ -168,6 +168,7 @@ bool WebAssemblyTargetInfo::initFeatureMap(
 Features["bulk-memory"] = true;
 Features["bulk-memory-opt"] = true;
 Features["call-indirect-overlong"] = true;
+Features["extended-const"] = true;
 Features["multivalue"] = true;
 Features["mutable-globals"] = true;
 Features["nontrapping-fptoint"] = true;
diff --git a/clang/test/Preprocessor/wasm-target-features.c 
b/clang/test/Preprocessor/wasm-target-features.c
index 71b7cf6a5d43c..ed1917b7e1b77 100644
--- a/clang/test/Preprocessor/wasm-target-features.c
+++ b/clang/test/Preprocessor/wasm-target-features.c
@@ -164,6 +164,7 @@
 // RUN:   | FileCheck %s -check-prefix=GENERIC-INCLUDE
 //
 // GENERIC-INCLUDE-DAG: #define __wasm_bulk_memory__ 1{{$}}
+// GENERIC-INCLUDE-DAG: #define __wasm_extended_const__ 1{{$}}
 // GENERIC-INCLUDE-DAG: #define __wasm_multivalue__ 1{{$}}
 // GENERIC-INCLUDE-DAG: #define __wasm_mutable_globals__ 1{{$}}
 // GENERIC-INCLUDE-DAG: #define __wasm_nontrapping_fptoint__ 1{{$}}
@@ -179,7 +180,6 @@
 //
 // GENERIC-NOT: #define __wasm_atomics__ 1{{$}}
 // GENERIC-NOT: #define __wasm_exception_handling__ 1{{$}}
-// GENERIC-NOT: #define __wasm_extended_const__ 1{{$}}
 // GENERIC-NOT: #define __wasm__fp16__ 1{{$}}
 // GENERIC-NOT: #define __wasm_multimemory__ 1{{$}}
 // GENERIC-NOT: #define __wasm_relaxed_simd__ 1{{$}}
diff --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index c9543ff09217a..e83962184d953 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -110,6 +110,13 @@ Changes to the RISC-V Backend
 Changes to the WebAssembly Backend
 --
 
+The default target CPU, "generic", now enables the `-mextended-const`
+flag, which correspond to the [Extended Const] proposal, which is
+[widely implemented in engines].
+
+[Extended Const]: https://github.com/WebAssembly/extended-const
+[widely implemented in engines]: https://webassembly.org/features/
+
 Changes to the Windows Target
 -
 
diff --git a/llvm/lib/Target/WebAssembly/WebAssembly.td 
b/llvm/lib/Target/WebAssembly/WebAssembly.td
index 13603f8181198..d574f27f2f226 100644
--- a/llvm/lib/Target/WebAssembly/WebAssembly.td
+++ b/llvm/lib/Target/WebAssembly/WebAssembly.td
@@ -123,9 +123,10 @@ def : ProcessorModel<"mvp", NoSchedModel, []>;
 // the importance of the features.
 def : ProcessorModel<"generic", NoSchedModel,
   [FeatureBulkMemory, FeatureBulkMemoryOpt,
-   FeatureCallIndirectOverlong, FeatureMultivalue,
-   FeatureMutableGlobals, FeatureNontrappingFPToInt,
-   FeatureReferenceTypes, FeatureSignExt]>;
+   FeatureCallIndirectOverlong, FeatureExtendedConst,
+   FeatureMultivalue, FeatureMutableGlobals,
+   FeatureNontrappingFPToInt, FeatureReferenceTypes,
+   FeatureSignExt]>;
 
 // Lime1: 

 def : ProcessorModel<"lime1", NoSchedModel,
diff --git a/llvm/test/CodeGen/WebAssembly/target-features-cpus.ll 
b/llvm/test/CodeGen/WebAssembly/target-features-cpus.ll
index 1c77ad5c049a5..e363910726934 100644
--- a/llvm/test/CodeGen/WebAssembly/target-features-cpus.ll
+++ b/llvm/test/CodeGen/WebAssembly/target-features-cpus.ll
@@ -14,7 +14,7 @@ target triple = "wasm32-unknown-unknown"
 
 ; generic: +call-indirect-overlong, +multivalue, +mutable-globals, 
+reference-types, +sign-ext
 ; GENERIC-LABEL: .custom_section.target_features,"",@
-; GENERIC-NEXT: .int8 

[clang] [llvm] [WebAssembly] Enable extended-const feature by default (PR #127721)

2025-02-18 Thread Sam Clegg via cfe-commits

https://github.com/sbc100 created 
https://github.com/llvm/llvm-project/pull/127721

None

>From 6d8b255090f08835b8b6b22e7c3d2abfe5ef7531 Mon Sep 17 00:00:00 2001
From: Sam Clegg 
Date: Tue, 18 Feb 2025 15:34:13 -0800
Subject: [PATCH] [WebAssembly] Enable extended-const feature by default

---
 clang/docs/ReleaseNotes.rst   | 7 +++
 clang/lib/Basic/Targets/WebAssembly.cpp   | 1 +
 clang/test/Preprocessor/wasm-target-features.c| 2 +-
 llvm/docs/ReleaseNotes.md | 7 +++
 llvm/lib/Target/WebAssembly/WebAssembly.td| 7 ---
 llvm/test/CodeGen/WebAssembly/target-features-cpus.ll | 5 -
 6 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6056a6964fbcc..7b90d4686d96f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -235,6 +235,13 @@ NetBSD Support
 WebAssembly Support
 ^^^
 
+The default target CPU, "generic", now enables the `-mextended-const`
+flag, which correspond to the [Extended Const] proposal, which is
+[widely implemented in engines].
+
+[Extended Const]: https://github.com/WebAssembly/extended-const
+[widely implemented in engines]: https://webassembly.org/features/
+
 AVR Support
 ^^^
 
diff --git a/clang/lib/Basic/Targets/WebAssembly.cpp 
b/clang/lib/Basic/Targets/WebAssembly.cpp
index f19c57f1a3a50..848b28441e22d 100644
--- a/clang/lib/Basic/Targets/WebAssembly.cpp
+++ b/clang/lib/Basic/Targets/WebAssembly.cpp
@@ -168,6 +168,7 @@ bool WebAssemblyTargetInfo::initFeatureMap(
 Features["bulk-memory"] = true;
 Features["bulk-memory-opt"] = true;
 Features["call-indirect-overlong"] = true;
+Features["extended-const"] = true;
 Features["multivalue"] = true;
 Features["mutable-globals"] = true;
 Features["nontrapping-fptoint"] = true;
diff --git a/clang/test/Preprocessor/wasm-target-features.c 
b/clang/test/Preprocessor/wasm-target-features.c
index 71b7cf6a5d43c..ed1917b7e1b77 100644
--- a/clang/test/Preprocessor/wasm-target-features.c
+++ b/clang/test/Preprocessor/wasm-target-features.c
@@ -164,6 +164,7 @@
 // RUN:   | FileCheck %s -check-prefix=GENERIC-INCLUDE
 //
 // GENERIC-INCLUDE-DAG: #define __wasm_bulk_memory__ 1{{$}}
+// GENERIC-INCLUDE-DAG: #define __wasm_extended_const__ 1{{$}}
 // GENERIC-INCLUDE-DAG: #define __wasm_multivalue__ 1{{$}}
 // GENERIC-INCLUDE-DAG: #define __wasm_mutable_globals__ 1{{$}}
 // GENERIC-INCLUDE-DAG: #define __wasm_nontrapping_fptoint__ 1{{$}}
@@ -179,7 +180,6 @@
 //
 // GENERIC-NOT: #define __wasm_atomics__ 1{{$}}
 // GENERIC-NOT: #define __wasm_exception_handling__ 1{{$}}
-// GENERIC-NOT: #define __wasm_extended_const__ 1{{$}}
 // GENERIC-NOT: #define __wasm__fp16__ 1{{$}}
 // GENERIC-NOT: #define __wasm_multimemory__ 1{{$}}
 // GENERIC-NOT: #define __wasm_relaxed_simd__ 1{{$}}
diff --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index c9543ff09217a..e83962184d953 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -110,6 +110,13 @@ Changes to the RISC-V Backend
 Changes to the WebAssembly Backend
 --
 
+The default target CPU, "generic", now enables the `-mextended-const`
+flag, which correspond to the [Extended Const] proposal, which is
+[widely implemented in engines].
+
+[Extended Const]: https://github.com/WebAssembly/extended-const
+[widely implemented in engines]: https://webassembly.org/features/
+
 Changes to the Windows Target
 -
 
diff --git a/llvm/lib/Target/WebAssembly/WebAssembly.td 
b/llvm/lib/Target/WebAssembly/WebAssembly.td
index 13603f8181198..d574f27f2f226 100644
--- a/llvm/lib/Target/WebAssembly/WebAssembly.td
+++ b/llvm/lib/Target/WebAssembly/WebAssembly.td
@@ -123,9 +123,10 @@ def : ProcessorModel<"mvp", NoSchedModel, []>;
 // the importance of the features.
 def : ProcessorModel<"generic", NoSchedModel,
   [FeatureBulkMemory, FeatureBulkMemoryOpt,
-   FeatureCallIndirectOverlong, FeatureMultivalue,
-   FeatureMutableGlobals, FeatureNontrappingFPToInt,
-   FeatureReferenceTypes, FeatureSignExt]>;
+   FeatureCallIndirectOverlong, FeatureExtendedConst,
+   FeatureMultivalue, FeatureMutableGlobals,
+   FeatureNontrappingFPToInt, FeatureReferenceTypes,
+   FeatureSignExt]>;
 
 // Lime1: 

 def : ProcessorModel<"lime1", NoSchedModel,
diff --git a/llvm/test/CodeGen/WebAssembly/target-features-cpus.ll 
b/llvm/test/CodeGen/WebAssembly/target-features-cpus.ll
index 1c77ad5c049a5..e363910726934 100644
--- a/llvm/test/CodeGen/WebAssembly/target-features-cpus.ll
+++ b/llvm/test/CodeGen/WebAssembly/target-features-cpus.ll
@@ -14,7 +14,7 @@ target triple = "wasm32-unknown-unknown"
 
 ; ge

[clang] [llvm] [WebAssembly] Enable extended-const feature by default (PR #127721)

2025-02-18 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Sam Clegg (sbc100)


Changes



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


6 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+7) 
- (modified) clang/lib/Basic/Targets/WebAssembly.cpp (+1) 
- (modified) clang/test/Preprocessor/wasm-target-features.c (+1-1) 
- (modified) llvm/docs/ReleaseNotes.md (+7) 
- (modified) llvm/lib/Target/WebAssembly/WebAssembly.td (+4-3) 
- (modified) llvm/test/CodeGen/WebAssembly/target-features-cpus.ll (+4-1) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6056a6964fbcc..7b90d4686d96f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -235,6 +235,13 @@ NetBSD Support
 WebAssembly Support
 ^^^
 
+The default target CPU, "generic", now enables the `-mextended-const`
+flag, which correspond to the [Extended Const] proposal, which is
+[widely implemented in engines].
+
+[Extended Const]: https://github.com/WebAssembly/extended-const
+[widely implemented in engines]: https://webassembly.org/features/
+
 AVR Support
 ^^^
 
diff --git a/clang/lib/Basic/Targets/WebAssembly.cpp 
b/clang/lib/Basic/Targets/WebAssembly.cpp
index f19c57f1a3a50..848b28441e22d 100644
--- a/clang/lib/Basic/Targets/WebAssembly.cpp
+++ b/clang/lib/Basic/Targets/WebAssembly.cpp
@@ -168,6 +168,7 @@ bool WebAssemblyTargetInfo::initFeatureMap(
 Features["bulk-memory"] = true;
 Features["bulk-memory-opt"] = true;
 Features["call-indirect-overlong"] = true;
+Features["extended-const"] = true;
 Features["multivalue"] = true;
 Features["mutable-globals"] = true;
 Features["nontrapping-fptoint"] = true;
diff --git a/clang/test/Preprocessor/wasm-target-features.c 
b/clang/test/Preprocessor/wasm-target-features.c
index 71b7cf6a5d43c..ed1917b7e1b77 100644
--- a/clang/test/Preprocessor/wasm-target-features.c
+++ b/clang/test/Preprocessor/wasm-target-features.c
@@ -164,6 +164,7 @@
 // RUN:   | FileCheck %s -check-prefix=GENERIC-INCLUDE
 //
 // GENERIC-INCLUDE-DAG: #define __wasm_bulk_memory__ 1{{$}}
+// GENERIC-INCLUDE-DAG: #define __wasm_extended_const__ 1{{$}}
 // GENERIC-INCLUDE-DAG: #define __wasm_multivalue__ 1{{$}}
 // GENERIC-INCLUDE-DAG: #define __wasm_mutable_globals__ 1{{$}}
 // GENERIC-INCLUDE-DAG: #define __wasm_nontrapping_fptoint__ 1{{$}}
@@ -179,7 +180,6 @@
 //
 // GENERIC-NOT: #define __wasm_atomics__ 1{{$}}
 // GENERIC-NOT: #define __wasm_exception_handling__ 1{{$}}
-// GENERIC-NOT: #define __wasm_extended_const__ 1{{$}}
 // GENERIC-NOT: #define __wasm__fp16__ 1{{$}}
 // GENERIC-NOT: #define __wasm_multimemory__ 1{{$}}
 // GENERIC-NOT: #define __wasm_relaxed_simd__ 1{{$}}
diff --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index c9543ff09217a..e83962184d953 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -110,6 +110,13 @@ Changes to the RISC-V Backend
 Changes to the WebAssembly Backend
 --
 
+The default target CPU, "generic", now enables the `-mextended-const`
+flag, which correspond to the [Extended Const] proposal, which is
+[widely implemented in engines].
+
+[Extended Const]: https://github.com/WebAssembly/extended-const
+[widely implemented in engines]: https://webassembly.org/features/
+
 Changes to the Windows Target
 -
 
diff --git a/llvm/lib/Target/WebAssembly/WebAssembly.td 
b/llvm/lib/Target/WebAssembly/WebAssembly.td
index 13603f8181198..d574f27f2f226 100644
--- a/llvm/lib/Target/WebAssembly/WebAssembly.td
+++ b/llvm/lib/Target/WebAssembly/WebAssembly.td
@@ -123,9 +123,10 @@ def : ProcessorModel<"mvp", NoSchedModel, []>;
 // the importance of the features.
 def : ProcessorModel<"generic", NoSchedModel,
   [FeatureBulkMemory, FeatureBulkMemoryOpt,
-   FeatureCallIndirectOverlong, FeatureMultivalue,
-   FeatureMutableGlobals, FeatureNontrappingFPToInt,
-   FeatureReferenceTypes, FeatureSignExt]>;
+   FeatureCallIndirectOverlong, FeatureExtendedConst,
+   FeatureMultivalue, FeatureMutableGlobals,
+   FeatureNontrappingFPToInt, FeatureReferenceTypes,
+   FeatureSignExt]>;
 
 // Lime1: 

 def : ProcessorModel<"lime1", NoSchedModel,
diff --git a/llvm/test/CodeGen/WebAssembly/target-features-cpus.ll 
b/llvm/test/CodeGen/WebAssembly/target-features-cpus.ll
index 1c77ad5c049a5..e363910726934 100644
--- a/llvm/test/CodeGen/WebAssembly/target-features-cpus.ll
+++ b/llvm/test/CodeGen/WebAssembly/target-features-cpus.ll
@@ -14,7 +14,7 @@ target triple = "wasm32-unknown-unknown"
 
 ; generic: +call-indirect-overlong, +multivalue, +mutable-globals, 
+reference-types, +sign-ext
 ; GENERIC-LABEL: .custom_section.target_features,"",@
-; GENERIC-NEXT: .int8  8
+; GENERIC-

[clang] [HLSL] Constant buffers codegen (PR #124886)

2025-02-18 Thread Justin Bogner via cfe-commits


@@ -0,0 +1,39 @@
+//===- HLSLTargetInfo.h 
---===//
+//
+// 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 "ABIInfoImpl.h"
+#include "TargetInfo.h"
+
+using namespace clang;
+using namespace clang::CodeGen;
+
+//===--===//
+// Target codegen info implementation common between DirectX and SPIR/SPIR-V.
+//===--===//
+
+class CommonHLSLTargetCodeGenInfo : public TargetCodeGenInfo {
+public:
+  CommonHLSLTargetCodeGenInfo(std::unique_ptr Info)
+  : TargetCodeGenInfo(std::move(Info)) {}
+
+  // Returns LLVM target extension type "dx.Layout" or "spv.Layout"
+  // for given structure type and layout data. The first number in
+  // the Layout is the size followed by offsets for each struct element.
+  virtual llvm::Type *getHLSLLayoutType(CodeGenModule &CGM,
+llvm::StructType *LayoutStructTy,
+SmallVector Layout) const {
+return nullptr;

bogner wrote:

Should this be a pure virtual function? Deriving from 
CommonHLSLTargetCodeGenInfo but not defining this function seems like it would 
be a hard error.

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


[clang] [HLSL] Constant buffers codegen (PR #124886)

2025-02-18 Thread Justin Bogner via cfe-commits

https://github.com/bogner commented:

This is looking pretty good, though I have some misgivings about 
`CommonHLSLTargetCodeGenInfo` and think it might be better to introduce a 
`HLSLLayoutBuilder` that can be used by targets as necessary instead. If you 
take that suggestion a couple of my comments become moot.

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


[clang] [HLSL] Constant buffers codegen (PR #124886)

2025-02-18 Thread Justin Bogner via cfe-commits

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


[clang] [HLSL] Constant buffers codegen (PR #124886)

2025-02-18 Thread Justin Bogner via cfe-commits


@@ -115,48 +83,176 @@ llvm::Triple::ArchType CGHLSLRuntime::getArch() {
   return CGM.getTarget().getTriple().getArch();
 }
 
-void CGHLSLRuntime::addConstant(VarDecl *D, Buffer &CB) {
-  if (D->getStorageClass() == SC_Static) {
-// For static inside cbuffer, take as global static.
-// Don't add to cbuffer.
-CGM.EmitGlobal(D);
-return;
-  }
+// Returns true if the type is an HLSL resource class
+static bool isResourceRecordType(const clang::Type *Ty) {
+  return HLSLAttributedResourceType::findHandleTypeOnResource(Ty) != nullptr;
+}
 
-  auto *GV = cast(CGM.GetAddrOfGlobalVar(D));
-  GV->setExternallyInitialized(true);
-  // Add debug info for constVal.
-  if (CGDebugInfo *DI = CGM.getModuleDebugInfo())
-if (CGM.getCodeGenOpts().getDebugInfo() >=
-codegenoptions::DebugInfoKind::LimitedDebugInfo)
-  DI->EmitGlobalVariable(cast(GV), D);
-
-  // FIXME: support packoffset.
-  // See https://github.com/llvm/llvm-project/issues/57914.
-  uint32_t Offset = 0;
-  bool HasUserOffset = false;
-
-  unsigned LowerBound = HasUserOffset ? Offset : UINT_MAX;
-  CB.Constants.emplace_back(std::make_pair(GV, LowerBound));
+// Returns true if the type is an HLSL resource class or an array of them
+static bool isResourceRecordTypeOrArrayOf(const clang::Type *Ty) {
+  while (const ConstantArrayType *CAT = dyn_cast(Ty))
+Ty = CAT->getArrayElementTypeNoTypeQual();
+  return isResourceRecordType(Ty);
 }
 
-void CGHLSLRuntime::addBufferDecls(const DeclContext *DC, Buffer &CB) {
-  for (Decl *it : DC->decls()) {
-if (auto *ConstDecl = dyn_cast(it)) {
-  addConstant(ConstDecl, CB);
-} else if (isa(it)) {
+// Emits constant global variables for buffer constants declarations
+// and creates metadata linking the constant globals with the buffer global.
+void CGHLSLRuntime::emitBufferGlobalsAndMetadata(const HLSLBufferDecl *BufDecl,
+ llvm::GlobalVariable *BufGV) {
+  LLVMContext &Ctx = CGM.getLLVMContext();
+
+  // get the layout struct from constant buffer target type
+  llvm::Type *BufType = BufGV->getValueType();
+  assert(isa(BufType) &&
+ "expected target type for HLSL buffer resource");
+  llvm::Type *BufLayoutType =
+  cast(BufType)->getTypeParameter(0);
+  assert(isa(BufLayoutType) &&
+ "expected target type for buffer layout struct");
+  llvm::StructType *LayoutStruct = cast(
+  cast(BufLayoutType)->getTypeParameter(0));
+
+  // Start metadata list associating the buffer global variable with its
+  // constatns
+  SmallVector BufGlobals;
+  BufGlobals.push_back(ValueAsMetadata::get(BufGV));
+
+  const auto *ElemIt = LayoutStruct->element_begin();
+  for (Decl *D : BufDecl->decls()) {
+if (isa(D))
   // Nothing to do for this declaration.
-} else if (isa(it)) {
-  // A function within an cbuffer is effectively a top-level function,
-  // as it only refers to globally scoped declarations.
-  CGM.EmitTopLevelDecl(it);
+  continue;
+if (isa(D)) {
+  // A function within an cbuffer is effectively a top-level function.
+  CGM.EmitTopLevelDecl(D);
+  continue;
+}
+VarDecl *VD = dyn_cast(D);
+if (!VD)
+  continue;
+
+QualType VDTy = VD->getType();
+if (VDTy.getAddressSpace() != LangAS::hlsl_constant) {
+  if (VD->getStorageClass() == SC_Static ||
+  VDTy.getAddressSpace() == LangAS::hlsl_groupshared ||
+  isResourceRecordTypeOrArrayOf(VDTy.getTypePtr())) {
+// Emit static and groupshared variables and resource classes inside
+// cbuffer as regular globals
+CGM.EmitGlobal(VD);
+  }
+  // Anything else that is not in the hlsl_constant address space must be
+  // an empty struct or a zero-sized array and can be ignored
+  continue;
+}
+
+assert(ElemIt != LayoutStruct->element_end() &&
+   "number of elements in layout struct does not match");
+llvm::Type *LayoutType = *ElemIt++;
+
+// there might be resources inside the used defined structs
+if (VDTy->isStructureType() && VDTy->isHLSLIntangibleType())
+  // FIXME: handle resources in cbuffer structs
+  llvm_unreachable("resources in cbuffer are not supported yet");
+
+// create global variable for the constant and to metadata list
+GlobalVariable *ElemGV =
+cast(CGM.GetAddrOfGlobalVar(VD, LayoutType));
+BufGlobals.push_back(ValueAsMetadata::get(ElemGV));
+  }
+  assert(ElemIt == LayoutStruct->element_end() &&
+ "number of elements in layout struct does not match");
+  // set the size of the buffer
+

bogner wrote:

Stray comment?

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


[clang] [HLSL] Constant buffers codegen (PR #124886)

2025-02-18 Thread Justin Bogner via cfe-commits


@@ -0,0 +1,39 @@
+//===- HLSLTargetInfo.h 
---===//
+//
+// 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 "ABIInfoImpl.h"
+#include "TargetInfo.h"
+
+using namespace clang;
+using namespace clang::CodeGen;
+
+//===--===//
+// Target codegen info implementation common between DirectX and SPIR/SPIR-V.
+//===--===//
+
+class CommonHLSLTargetCodeGenInfo : public TargetCodeGenInfo {
+public:
+  CommonHLSLTargetCodeGenInfo(std::unique_ptr Info)
+  : TargetCodeGenInfo(std::move(Info)) {}
+
+  // Returns LLVM target extension type "dx.Layout" or "spv.Layout"
+  // for given structure type and layout data. The first number in
+  // the Layout is the size followed by offsets for each struct element.
+  virtual llvm::Type *getHLSLLayoutType(CodeGenModule &CGM,
+llvm::StructType *LayoutStructTy,
+SmallVector Layout) const {
+return nullptr;
+  };
+
+protected:
+  // Creates a layout type for given struct with HLSL constant buffer layout
+  // taking into account Packoffsets, if provided.
+  virtual llvm::Type *createHLSLBufferLayoutType(
+  CodeGenModule &CGM, const clang::RecordType *StructType,
+  const SmallVector *Packoffsets = nullptr) const;

bogner wrote:

Does this need to be virtual? I don't see why subclasses would override this...

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


[clang] [HLSL] Constant buffers codegen (PR #124886)

2025-02-18 Thread Justin Bogner via cfe-commits


@@ -56,9 +75,18 @@ llvm::Type 
*DirectXTargetCodeGenInfo::getHLSLType(CodeGenModule &CGM,
 
 return llvm::TargetExtType::get(Ctx, TypeName, {ElemType}, Ints);
   }
-  case llvm::dxil::ResourceClass::CBuffer:
-llvm_unreachable("dx.CBuffer handles are not implemented yet");
-break;
+  case llvm::dxil::ResourceClass::CBuffer: {
+QualType ContainedTy = ResType->getContainedType();
+if (ContainedTy.isNull() || !ContainedTy->isStructureType())

bogner wrote:

Should this be an assert then?

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


[clang] [HLSL] Constant buffers codegen (PR #124886)

2025-02-18 Thread Justin Bogner via cfe-commits


@@ -115,48 +83,176 @@ llvm::Triple::ArchType CGHLSLRuntime::getArch() {
   return CGM.getTarget().getTriple().getArch();
 }
 
-void CGHLSLRuntime::addConstant(VarDecl *D, Buffer &CB) {
-  if (D->getStorageClass() == SC_Static) {
-// For static inside cbuffer, take as global static.
-// Don't add to cbuffer.
-CGM.EmitGlobal(D);
-return;
-  }
+// Returns true if the type is an HLSL resource class
+static bool isResourceRecordType(const clang::Type *Ty) {
+  return HLSLAttributedResourceType::findHandleTypeOnResource(Ty) != nullptr;
+}
 
-  auto *GV = cast(CGM.GetAddrOfGlobalVar(D));
-  GV->setExternallyInitialized(true);
-  // Add debug info for constVal.
-  if (CGDebugInfo *DI = CGM.getModuleDebugInfo())
-if (CGM.getCodeGenOpts().getDebugInfo() >=
-codegenoptions::DebugInfoKind::LimitedDebugInfo)
-  DI->EmitGlobalVariable(cast(GV), D);
-
-  // FIXME: support packoffset.
-  // See https://github.com/llvm/llvm-project/issues/57914.
-  uint32_t Offset = 0;
-  bool HasUserOffset = false;
-
-  unsigned LowerBound = HasUserOffset ? Offset : UINT_MAX;
-  CB.Constants.emplace_back(std::make_pair(GV, LowerBound));
+// Returns true if the type is an HLSL resource class or an array of them
+static bool isResourceRecordTypeOrArrayOf(const clang::Type *Ty) {
+  while (const ConstantArrayType *CAT = dyn_cast(Ty))
+Ty = CAT->getArrayElementTypeNoTypeQual();
+  return isResourceRecordType(Ty);
 }
 
-void CGHLSLRuntime::addBufferDecls(const DeclContext *DC, Buffer &CB) {
-  for (Decl *it : DC->decls()) {
-if (auto *ConstDecl = dyn_cast(it)) {
-  addConstant(ConstDecl, CB);
-} else if (isa(it)) {
+// Emits constant global variables for buffer constants declarations
+// and creates metadata linking the constant globals with the buffer global.
+void CGHLSLRuntime::emitBufferGlobalsAndMetadata(const HLSLBufferDecl *BufDecl,
+ llvm::GlobalVariable *BufGV) {
+  LLVMContext &Ctx = CGM.getLLVMContext();
+
+  // get the layout struct from constant buffer target type
+  llvm::Type *BufType = BufGV->getValueType();
+  assert(isa(BufType) &&
+ "expected target type for HLSL buffer resource");
+  llvm::Type *BufLayoutType =
+  cast(BufType)->getTypeParameter(0);
+  assert(isa(BufLayoutType) &&
+ "expected target type for buffer layout struct");
+  llvm::StructType *LayoutStruct = cast(
+  cast(BufLayoutType)->getTypeParameter(0));
+
+  // Start metadata list associating the buffer global variable with its
+  // constatns
+  SmallVector BufGlobals;
+  BufGlobals.push_back(ValueAsMetadata::get(BufGV));
+
+  const auto *ElemIt = LayoutStruct->element_begin();
+  for (Decl *D : BufDecl->decls()) {
+if (isa(D))
   // Nothing to do for this declaration.
-} else if (isa(it)) {
-  // A function within an cbuffer is effectively a top-level function,
-  // as it only refers to globally scoped declarations.
-  CGM.EmitTopLevelDecl(it);
+  continue;
+if (isa(D)) {
+  // A function within an cbuffer is effectively a top-level function.
+  CGM.EmitTopLevelDecl(D);
+  continue;
+}
+VarDecl *VD = dyn_cast(D);
+if (!VD)
+  continue;
+
+QualType VDTy = VD->getType();
+if (VDTy.getAddressSpace() != LangAS::hlsl_constant) {
+  if (VD->getStorageClass() == SC_Static ||
+  VDTy.getAddressSpace() == LangAS::hlsl_groupshared ||
+  isResourceRecordTypeOrArrayOf(VDTy.getTypePtr())) {
+// Emit static and groupshared variables and resource classes inside
+// cbuffer as regular globals
+CGM.EmitGlobal(VD);
+  }
+  // Anything else that is not in the hlsl_constant address space must be
+  // an empty struct or a zero-sized array and can be ignored
+  continue;
+}
+
+assert(ElemIt != LayoutStruct->element_end() &&
+   "number of elements in layout struct does not match");
+llvm::Type *LayoutType = *ElemIt++;
+
+// there might be resources inside the used defined structs
+if (VDTy->isStructureType() && VDTy->isHLSLIntangibleType())
+  // FIXME: handle resources in cbuffer structs
+  llvm_unreachable("resources in cbuffer are not supported yet");
+
+// create global variable for the constant and to metadata list
+GlobalVariable *ElemGV =
+cast(CGM.GetAddrOfGlobalVar(VD, LayoutType));
+BufGlobals.push_back(ValueAsMetadata::get(ElemGV));
+  }
+  assert(ElemIt == LayoutStruct->element_end() &&
+ "number of elements in layout struct does not match");
+  // set the size of the buffer
+
+  // add buffer metadata to the module
+  CGM.getModule()
+  .getOrInsertNamedMetadata("hlsl.cbs")
+  ->addOperand(MDNode::get(Ctx, BufGlobals));
+}
+
+// Creates resource handle type for the HLSL buffer declaration
+static const clang::HLSLAttributedResourceType *
+createBufferHandleType(const HLSLBufferDecl *BufDecl) {
+  ASTContext &AST = BufDecl->getASTCon

[clang] [HLSL] Constant buffers codegen (PR #124886)

2025-02-18 Thread Justin Bogner via cfe-commits


@@ -115,48 +83,176 @@ llvm::Triple::ArchType CGHLSLRuntime::getArch() {
   return CGM.getTarget().getTriple().getArch();
 }
 
-void CGHLSLRuntime::addConstant(VarDecl *D, Buffer &CB) {
-  if (D->getStorageClass() == SC_Static) {
-// For static inside cbuffer, take as global static.
-// Don't add to cbuffer.
-CGM.EmitGlobal(D);
-return;
-  }
+// Returns true if the type is an HLSL resource class
+static bool isResourceRecordType(const clang::Type *Ty) {
+  return HLSLAttributedResourceType::findHandleTypeOnResource(Ty) != nullptr;
+}
 
-  auto *GV = cast(CGM.GetAddrOfGlobalVar(D));
-  GV->setExternallyInitialized(true);
-  // Add debug info for constVal.
-  if (CGDebugInfo *DI = CGM.getModuleDebugInfo())
-if (CGM.getCodeGenOpts().getDebugInfo() >=
-codegenoptions::DebugInfoKind::LimitedDebugInfo)
-  DI->EmitGlobalVariable(cast(GV), D);
-
-  // FIXME: support packoffset.
-  // See https://github.com/llvm/llvm-project/issues/57914.
-  uint32_t Offset = 0;
-  bool HasUserOffset = false;
-
-  unsigned LowerBound = HasUserOffset ? Offset : UINT_MAX;
-  CB.Constants.emplace_back(std::make_pair(GV, LowerBound));
+// Returns true if the type is an HLSL resource class or an array of them
+static bool isResourceRecordTypeOrArrayOf(const clang::Type *Ty) {
+  while (const ConstantArrayType *CAT = dyn_cast(Ty))
+Ty = CAT->getArrayElementTypeNoTypeQual();
+  return isResourceRecordType(Ty);
 }
 
-void CGHLSLRuntime::addBufferDecls(const DeclContext *DC, Buffer &CB) {
-  for (Decl *it : DC->decls()) {
-if (auto *ConstDecl = dyn_cast(it)) {
-  addConstant(ConstDecl, CB);
-} else if (isa(it)) {
+// Emits constant global variables for buffer constants declarations
+// and creates metadata linking the constant globals with the buffer global.
+void CGHLSLRuntime::emitBufferGlobalsAndMetadata(const HLSLBufferDecl *BufDecl,
+ llvm::GlobalVariable *BufGV) {
+  LLVMContext &Ctx = CGM.getLLVMContext();
+
+  // get the layout struct from constant buffer target type
+  llvm::Type *BufType = BufGV->getValueType();
+  assert(isa(BufType) &&
+ "expected target type for HLSL buffer resource");
+  llvm::Type *BufLayoutType =
+  cast(BufType)->getTypeParameter(0);
+  assert(isa(BufLayoutType) &&
+ "expected target type for buffer layout struct");
+  llvm::StructType *LayoutStruct = cast(
+  cast(BufLayoutType)->getTypeParameter(0));
+
+  // Start metadata list associating the buffer global variable with its
+  // constatns
+  SmallVector BufGlobals;
+  BufGlobals.push_back(ValueAsMetadata::get(BufGV));
+
+  const auto *ElemIt = LayoutStruct->element_begin();
+  for (Decl *D : BufDecl->decls()) {
+if (isa(D))
   // Nothing to do for this declaration.
-} else if (isa(it)) {
-  // A function within an cbuffer is effectively a top-level function,
-  // as it only refers to globally scoped declarations.
-  CGM.EmitTopLevelDecl(it);
+  continue;
+if (isa(D)) {
+  // A function within an cbuffer is effectively a top-level function.
+  CGM.EmitTopLevelDecl(D);
+  continue;
+}
+VarDecl *VD = dyn_cast(D);
+if (!VD)
+  continue;
+
+QualType VDTy = VD->getType();
+if (VDTy.getAddressSpace() != LangAS::hlsl_constant) {
+  if (VD->getStorageClass() == SC_Static ||
+  VDTy.getAddressSpace() == LangAS::hlsl_groupshared ||
+  isResourceRecordTypeOrArrayOf(VDTy.getTypePtr())) {
+// Emit static and groupshared variables and resource classes inside
+// cbuffer as regular globals
+CGM.EmitGlobal(VD);
+  }
+  // Anything else that is not in the hlsl_constant address space must be
+  // an empty struct or a zero-sized array and can be ignored

bogner wrote:

Should we have an assert here if something other than an empty struct or 
zero-sized array shows up somehow?

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


[clang] [HLSL] Constant buffers codegen (PR #124886)

2025-02-18 Thread Justin Bogner via cfe-commits


@@ -115,48 +83,176 @@ llvm::Triple::ArchType CGHLSLRuntime::getArch() {
   return CGM.getTarget().getTriple().getArch();
 }
 
-void CGHLSLRuntime::addConstant(VarDecl *D, Buffer &CB) {
-  if (D->getStorageClass() == SC_Static) {
-// For static inside cbuffer, take as global static.
-// Don't add to cbuffer.
-CGM.EmitGlobal(D);
-return;
-  }
+// Returns true if the type is an HLSL resource class
+static bool isResourceRecordType(const clang::Type *Ty) {
+  return HLSLAttributedResourceType::findHandleTypeOnResource(Ty) != nullptr;
+}
 
-  auto *GV = cast(CGM.GetAddrOfGlobalVar(D));
-  GV->setExternallyInitialized(true);
-  // Add debug info for constVal.
-  if (CGDebugInfo *DI = CGM.getModuleDebugInfo())
-if (CGM.getCodeGenOpts().getDebugInfo() >=
-codegenoptions::DebugInfoKind::LimitedDebugInfo)
-  DI->EmitGlobalVariable(cast(GV), D);
-
-  // FIXME: support packoffset.
-  // See https://github.com/llvm/llvm-project/issues/57914.
-  uint32_t Offset = 0;
-  bool HasUserOffset = false;
-
-  unsigned LowerBound = HasUserOffset ? Offset : UINT_MAX;
-  CB.Constants.emplace_back(std::make_pair(GV, LowerBound));
+// Returns true if the type is an HLSL resource class or an array of them
+static bool isResourceRecordTypeOrArrayOf(const clang::Type *Ty) {
+  while (const ConstantArrayType *CAT = dyn_cast(Ty))
+Ty = CAT->getArrayElementTypeNoTypeQual();
+  return isResourceRecordType(Ty);
 }
 
-void CGHLSLRuntime::addBufferDecls(const DeclContext *DC, Buffer &CB) {
-  for (Decl *it : DC->decls()) {
-if (auto *ConstDecl = dyn_cast(it)) {
-  addConstant(ConstDecl, CB);
-} else if (isa(it)) {
+// Emits constant global variables for buffer constants declarations
+// and creates metadata linking the constant globals with the buffer global.
+void CGHLSLRuntime::emitBufferGlobalsAndMetadata(const HLSLBufferDecl *BufDecl,
+ llvm::GlobalVariable *BufGV) {
+  LLVMContext &Ctx = CGM.getLLVMContext();
+
+  // get the layout struct from constant buffer target type
+  llvm::Type *BufType = BufGV->getValueType();
+  assert(isa(BufType) &&
+ "expected target type for HLSL buffer resource");
+  llvm::Type *BufLayoutType =
+  cast(BufType)->getTypeParameter(0);
+  assert(isa(BufLayoutType) &&
+ "expected target type for buffer layout struct");
+  llvm::StructType *LayoutStruct = cast(
+  cast(BufLayoutType)->getTypeParameter(0));

bogner wrote:

You don't need the `assert(isa<>)` right before these casts here - `cast<>` 
asserts internally on a mismatch.

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


[clang] [HLSL] Constant buffers codegen (PR #124886)

2025-02-18 Thread Justin Bogner via cfe-commits


@@ -0,0 +1,39 @@
+//===- HLSLTargetInfo.h 
---===//
+//
+// 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 "ABIInfoImpl.h"
+#include "TargetInfo.h"
+
+using namespace clang;
+using namespace clang::CodeGen;
+
+//===--===//
+// Target codegen info implementation common between DirectX and SPIR/SPIR-V.
+//===--===//
+
+class CommonHLSLTargetCodeGenInfo : public TargetCodeGenInfo {

bogner wrote:

(in fact, maybe just a `StringRef Name` rather than having `getHLSLLayoutType` 
- `createHLSLBufferLayoutType` seems to depend pretty heavily on this returning 
a very specific type)

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


[clang-tools-extra] [clang-tidy]add new check bugprone-unintended-char-ostream-output (PR #127720)

2025-02-18 Thread via cfe-commits


@@ -0,0 +1,70 @@
+//===--- UnintendedCharOstreamOutputCheck.cpp - clang-tidy
+//-===//

EugeneZelenko wrote:

Should be merged into previous line.

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


[clang] [HLSL] Constant buffers codegen (PR #124886)

2025-02-18 Thread Justin Bogner via cfe-commits


@@ -0,0 +1,39 @@
+//===- HLSLTargetInfo.h 
---===//
+//
+// 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 "ABIInfoImpl.h"
+#include "TargetInfo.h"
+
+using namespace clang;
+using namespace clang::CodeGen;
+
+//===--===//
+// Target codegen info implementation common between DirectX and SPIR/SPIR-V.
+//===--===//
+
+class CommonHLSLTargetCodeGenInfo : public TargetCodeGenInfo {

bogner wrote:

I worry a little bit about the composability of interposing this class between 
TargetCodeGenInfo and the DirectX and SPIRV targets. Imagine if we added a 
second language-specific codegeninfo - how would a backend be able to opt-in to 
supporting both?

I guess it would be better to make this a CRTP mixin, or to have 
`createHLSLBufferLayoutType` as a free function with a callback for 
`getHLSLLayoutType`.

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


[clang-tools-extra] [clang-tidy]add new check bugprone-unintended-char-ostream-output (PR #127720)

2025-02-18 Thread via cfe-commits


@@ -0,0 +1,70 @@
+// RUN: %check_clang_tidy %s bugprone-unintended-char-ostream-output %t
+
+namespace std {
+
+template  class basic_ostream {
+public:
+  basic_ostream &operator<<(int);
+  basic_ostream &operator<<(unsigned int);
+};
+
+template 
+basic_ostream &operator<<(basic_ostream &, 
CharT);
+template 
+basic_ostream &operator<<(basic_ostream &, char);
+template 
+basic_ostream &operator<<(basic_ostream &, char);
+template 
+basic_ostream &operator<<(basic_ostream &,
+  signed char);
+template 
+basic_ostream &operator<<(basic_ostream &,
+  unsigned char);
+
+using ostream = basic_ostream;
+
+

EugeneZelenko wrote:

Excessive newline.

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


[clang] [clang][Sema] Combine fallout warnings to just one warning (PR #127546)

2025-02-18 Thread via cfe-commits


@@ -696,12 +661,12 @@ static void CheckFallThroughForBody(Sema &S, const Decl 
*D, const Stmt *Body,
   if (CD.checkDiagnostics(Diags, ReturnsVoid, HasNoReturn))
   return;
   SourceLocation LBrace = Body->getBeginLoc(), RBrace = Body->getEndLoc();
-  auto EmitDiag = [&](SourceLocation Loc, unsigned DiagID) {
+  auto EmitDiag = [&](SourceLocation Loc, unsigned DiagID, unsigned FunMode) {

foxtran wrote:

Unfortunately, in `diag_FallThrough_HasNoReturn` case, we have one argument, 
and in `diag_FallThrough_ReturnsNonVoid` we have two arguments, so I just 
removed `EmitDiag` since it can not check how many arguments diag message have 
and use a proper branch. 

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


[clang] [CIR] Upstream simple function bodies (PR #127674)

2025-02-18 Thread David Olsen via cfe-commits


@@ -0,0 +1,203 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+//
+// Internal per-function state used for AST-to-ClangIR code gen
+//
+//===--===//
+
+#include "CIRGenFunction.h"
+
+#include "clang/AST/GlobalDecl.h"
+
+#include 
+
+namespace clang::CIRGen {
+
+CIRGenFunction::CIRGenFunction(CIRGenModule &cgm, CIRGenBuilderTy &builder,
+   bool suppressNewContext)
+: CIRGenTypeCache(cgm), cgm{cgm}, builder(builder) {}
+
+CIRGenFunction::~CIRGenFunction() {}
+
+// This is copied from clang/lib/CodeGen/CodeGenFunction.cpp
+cir::TypeEvaluationKind CIRGenFunction::getEvaluationKind(QualType type) {
+  type = type.getCanonicalType();
+  while (true) {
+switch (type->getTypeClass()) {
+#define TYPE(name, parent)
+#define ABSTRACT_TYPE(name, parent)
+#define NON_CANONICAL_TYPE(name, parent) case Type::name:
+#define DEPENDENT_TYPE(name, parent) case Type::name:
+#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(name, parent) case Type::name:
+#include "clang/AST/TypeNodes.inc"
+  llvm_unreachable("non-canonical or dependent type in IR-generation");
+
+case Type::ArrayParameter:
+case Type::HLSLAttributedResource:
+  llvm_unreachable("NYI");
+
+case Type::Auto:
+case Type::DeducedTemplateSpecialization:
+  llvm_unreachable("undeduced type in IR-generation");
+
+// Various scalar types.
+case Type::Builtin:
+case Type::Pointer:
+case Type::BlockPointer:
+case Type::LValueReference:
+case Type::RValueReference:
+case Type::MemberPointer:
+case Type::Vector:
+case Type::ExtVector:
+case Type::ConstantMatrix:
+case Type::FunctionProto:
+case Type::FunctionNoProto:
+case Type::Enum:
+case Type::ObjCObjectPointer:
+case Type::Pipe:
+case Type::BitInt:
+  return cir::TEK_Scalar;
+
+// Complexes.
+case Type::Complex:
+  return cir::TEK_Complex;
+
+// Arrays, records, and Objective-C objects.
+case Type::ConstantArray:
+case Type::IncompleteArray:
+case Type::VariableArray:
+case Type::Record:
+case Type::ObjCObject:
+case Type::ObjCInterface:
+  return cir::TEK_Aggregate;
+
+// We operate on atomic values according to their underlying type.
+case Type::Atomic:
+  type = cast(type)->getValueType();
+  continue;
+}
+llvm_unreachable("unknown type kind!");
+  }
+}
+
+mlir::Type CIRGenFunction::convertTypeForMem(QualType t) {
+  return cgm.getTypes().convertTypeForMem(t);
+}
+
+mlir::Type CIRGenFunction::convertType(QualType t) {
+  return cgm.getTypes().convertType(t);
+}
+
+mlir::Location CIRGenFunction::getLoc(SourceLocation srcLoc) {
+  // Some AST nodes might contain invalid source locations (e.g.
+  // CXXDefaultArgExpr), workaround that to still get something out.
+  if (srcLoc.isValid()) {
+const SourceManager &sm = getContext().getSourceManager();
+PresumedLoc pLoc = sm.getPresumedLoc(srcLoc);
+StringRef filename = pLoc.getFilename();
+return mlir::FileLineColLoc::get(builder.getStringAttr(filename),
+ pLoc.getLine(), pLoc.getColumn());
+  } else {
+// Do our best...
+assert(currSrcLoc && "expected to inherit some source location");
+return *currSrcLoc;
+  }
+}
+
+mlir::Location CIRGenFunction::getLoc(SourceRange srcLoc) {
+  // Some AST nodes might contain invalid source locations (e.g.
+  // CXXDefaultArgExpr), workaround that to still get something out.
+  if (srcLoc.isValid()) {
+mlir::Location beg = getLoc(srcLoc.getBegin());
+mlir::Location end = getLoc(srcLoc.getEnd());
+SmallVector locs = {beg, end};
+mlir::Attribute metadata;
+return mlir::FusedLoc::get(locs, metadata, &getMLIRContext());
+  } else if (currSrcLoc) {
+return *currSrcLoc;
+  }
+
+  // We're brave, but time to give up.
+  return builder.getUnknownLoc();
+}
+
+mlir::Location CIRGenFunction::getLoc(mlir::Location lhs, mlir::Location rhs) {
+  SmallVector locs = {lhs, rhs};
+  mlir::Attribute metadata;
+  return mlir::FusedLoc::get(locs, metadata, &getMLIRContext());
+}
+
+void CIRGenFunction::startFunction(GlobalDecl gd, QualType returnType,
+   cir::FuncOp fn, cir::FuncType funcType,
+   SourceLocation loc,
+   SourceLocation startLoc) {
+  assert(!curFn &&
+ "CIRGenFunction can only be used for one function at a time");
+
+  fnRetTy = returnType;
+  curFn = fn;
+
+  mlir::Block *entryBB = &fn.getBlocks().front();
+  builder.setInsertionPointToStart(entryB

[clang] [CIR] Upstream simple function bodies (PR #127674)

2025-02-18 Thread David Olsen via cfe-commits


@@ -0,0 +1,134 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+//
+// Internal per-function state used for AST-to-ClangIR code gen
+//
+//===--===//
+
+#ifndef LLVM_CLANG_LIB_CIR_CODEGEN_CIRGENFUNCTION_H
+#define LLVM_CLANG_LIB_CIR_CODEGEN_CIRGENFUNCTION_H
+
+#include "CIRGenBuilder.h"
+#include "CIRGenModule.h"
+#include "CIRGenTypeCache.h"
+
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Type.h"
+#include "clang/CIR/Dialect/IR/CIRDialect.h"
+#include "clang/CIR/TypeEvaluationKind.h"
+
+#include "llvm/ADT/ScopedHashTable.h"
+
+namespace clang::CIRGen {
+
+class CIRGenFunction : public CIRGenTypeCache {
+public:
+  CIRGenModule &cgm;
+
+private:
+  /// The builder is a helper class to create IR inside a function. The
+  /// builder is stateful, in particular it keeps an "insertion point": this
+  /// is where the next operations will be introduced.
+  CIRGenBuilderTy &builder;
+
+public:
+  clang::QualType fnRetTy;
+
+  /// This is the current function or global initializer that is generated code
+  /// for.
+  mlir::Operation *curFn = nullptr;
+
+  clang::ASTContext &getContext() const { return cgm.getASTContext(); }
+
+  CIRGenBuilderTy &getBuilder() { return builder; }
+
+  CIRGenModule &getCIRGenModule() { return cgm; }
+  const CIRGenModule &getCIRGenModule() const { return cgm; }
+
+  mlir::Type convertTypeForMem(QualType T);

dkolsen-pgi wrote:

This code was copy-pasted from the incubator, where initial-caps is used.  When 
I manually went through and fixed all the capitalization stuff, I missed this 
declaration and the others you pointed out.  I will fix these.


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


[clang-tools-extra] [clang-tidy]add new check bugprone-unintended-char-ostream-output (PR #127720)

2025-02-18 Thread via cfe-commits


@@ -91,6 +91,12 @@ Improvements to clang-tidy
 New checks
 ^^
 
+- New :doc:`bugprone-unintended-char-ostream-output
+  ` check.
+
+  Finds unintended character output from `unsigned char` and `signed char` to 
an

EugeneZelenko wrote:

```suggestion
  Finds unintended character output from ``unsigned char`` and ``signed char`` 
to an
```

Language construct.

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


[clang] [HLSL] Constant buffers codegen (PR #124886)

2025-02-18 Thread Justin Bogner via cfe-commits


@@ -115,48 +83,176 @@ llvm::Triple::ArchType CGHLSLRuntime::getArch() {
   return CGM.getTarget().getTriple().getArch();
 }
 
-void CGHLSLRuntime::addConstant(VarDecl *D, Buffer &CB) {
-  if (D->getStorageClass() == SC_Static) {
-// For static inside cbuffer, take as global static.
-// Don't add to cbuffer.
-CGM.EmitGlobal(D);
-return;
-  }
+// Returns true if the type is an HLSL resource class
+static bool isResourceRecordType(const clang::Type *Ty) {
+  return HLSLAttributedResourceType::findHandleTypeOnResource(Ty) != nullptr;
+}
 
-  auto *GV = cast(CGM.GetAddrOfGlobalVar(D));
-  GV->setExternallyInitialized(true);
-  // Add debug info for constVal.
-  if (CGDebugInfo *DI = CGM.getModuleDebugInfo())
-if (CGM.getCodeGenOpts().getDebugInfo() >=
-codegenoptions::DebugInfoKind::LimitedDebugInfo)
-  DI->EmitGlobalVariable(cast(GV), D);
-
-  // FIXME: support packoffset.
-  // See https://github.com/llvm/llvm-project/issues/57914.
-  uint32_t Offset = 0;
-  bool HasUserOffset = false;
-
-  unsigned LowerBound = HasUserOffset ? Offset : UINT_MAX;
-  CB.Constants.emplace_back(std::make_pair(GV, LowerBound));
+// Returns true if the type is an HLSL resource class or an array of them
+static bool isResourceRecordTypeOrArrayOf(const clang::Type *Ty) {
+  while (const ConstantArrayType *CAT = dyn_cast(Ty))
+Ty = CAT->getArrayElementTypeNoTypeQual();
+  return isResourceRecordType(Ty);
 }
 
-void CGHLSLRuntime::addBufferDecls(const DeclContext *DC, Buffer &CB) {
-  for (Decl *it : DC->decls()) {
-if (auto *ConstDecl = dyn_cast(it)) {
-  addConstant(ConstDecl, CB);
-} else if (isa(it)) {
+// Emits constant global variables for buffer constants declarations
+// and creates metadata linking the constant globals with the buffer global.
+void CGHLSLRuntime::emitBufferGlobalsAndMetadata(const HLSLBufferDecl *BufDecl,
+ llvm::GlobalVariable *BufGV) {
+  LLVMContext &Ctx = CGM.getLLVMContext();
+
+  // get the layout struct from constant buffer target type
+  llvm::Type *BufType = BufGV->getValueType();
+  assert(isa(BufType) &&
+ "expected target type for HLSL buffer resource");
+  llvm::Type *BufLayoutType =
+  cast(BufType)->getTypeParameter(0);
+  assert(isa(BufLayoutType) &&
+ "expected target type for buffer layout struct");
+  llvm::StructType *LayoutStruct = cast(
+  cast(BufLayoutType)->getTypeParameter(0));
+
+  // Start metadata list associating the buffer global variable with its
+  // constatns
+  SmallVector BufGlobals;
+  BufGlobals.push_back(ValueAsMetadata::get(BufGV));
+
+  const auto *ElemIt = LayoutStruct->element_begin();
+  for (Decl *D : BufDecl->decls()) {
+if (isa(D))
   // Nothing to do for this declaration.
-} else if (isa(it)) {
-  // A function within an cbuffer is effectively a top-level function,
-  // as it only refers to globally scoped declarations.
-  CGM.EmitTopLevelDecl(it);
+  continue;
+if (isa(D)) {
+  // A function within an cbuffer is effectively a top-level function.
+  CGM.EmitTopLevelDecl(D);
+  continue;
+}
+VarDecl *VD = dyn_cast(D);
+if (!VD)
+  continue;
+
+QualType VDTy = VD->getType();
+if (VDTy.getAddressSpace() != LangAS::hlsl_constant) {
+  if (VD->getStorageClass() == SC_Static ||
+  VDTy.getAddressSpace() == LangAS::hlsl_groupshared ||
+  isResourceRecordTypeOrArrayOf(VDTy.getTypePtr())) {
+// Emit static and groupshared variables and resource classes inside
+// cbuffer as regular globals
+CGM.EmitGlobal(VD);
+  }
+  // Anything else that is not in the hlsl_constant address space must be
+  // an empty struct or a zero-sized array and can be ignored
+  continue;
+}
+
+assert(ElemIt != LayoutStruct->element_end() &&
+   "number of elements in layout struct does not match");
+llvm::Type *LayoutType = *ElemIt++;
+
+// there might be resources inside the used defined structs
+if (VDTy->isStructureType() && VDTy->isHLSLIntangibleType())
+  // FIXME: handle resources in cbuffer structs
+  llvm_unreachable("resources in cbuffer are not supported yet");

bogner wrote:

`report_fatal_error` might be better here - I imagine something will crash 
later anyway if we get here.

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


[clang] [NFC][Clang][CodeGen] Remove vestigial assertion (PR #127528)

2025-02-18 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

The fix will need to be backported, but I don't think this fixed it all the way 
so we'll need another follow-up.

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


[clang] [HLSL] Constant buffers codegen (PR #124886)

2025-02-18 Thread Helena Kotas via cfe-commits


@@ -56,9 +75,18 @@ llvm::Type 
*DirectXTargetCodeGenInfo::getHLSLType(CodeGenModule &CGM,
 
 return llvm::TargetExtType::get(Ctx, TypeName, {ElemType}, Ints);
   }
-  case llvm::dxil::ResourceClass::CBuffer:
-llvm_unreachable("dx.CBuffer handles are not implemented yet");
-break;
+  case llvm::dxil::ResourceClass::CBuffer: {
+QualType ContainedTy = ResType->getContainedType();
+if (ContainedTy.isNull() || !ContainedTy->isStructureType())

hekota wrote:

The pattern has been to return `nullptr` for types we don't know how to 
convert. An assert with message "Generic handling of HLSL types is not 
supported." will fire in `CGHLSLRuntime::convertHLSLSpecificType` if the 
converted type is null.

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


[clang] [HLSL] Constant buffers codegen (PR #124886)

2025-02-18 Thread Helena Kotas via cfe-commits

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


[clang] [Coroutines] Mark parameter allocas with coro.outside.frame metadata (PR #127653)

2025-02-18 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

I'm not really happy with that... but if the semantics were never properly 
defined in the first place, I guess this isn't making things worse.

Not sure if marking the allocas themselves is actually the right approach 
long-term.  It seems like there's a distinction between code that's "inside" 
the coroutine (between the begin/end) and "outside" the coroutine, and there 
are a bunch of restrictions on code that's "outside" the coroutine.  I'm not 
sure I really understand the mechanics of that, though.

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


[clang] Check the type of Objective-C++ instance variables in WebKit member variable checkers. (PR #127570)

2025-02-18 Thread Ryosuke Niwa via cfe-commits


@@ -87,6 +92,31 @@ class RawPtrRefMemberChecker
 }
   }
 
+  void visitObjCDecl(const ObjCContainerDecl *CD) const {
+if (auto *ID = dyn_cast(CD)) {

rniwa wrote:

I don't think so. `ObjCContainerDecl` could be `ObjCCategoryDecl` or 
`ObjCProtocolDecl` as well.
Or are you saying CD could be null?

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


[clang] Check the type of Objective-C++ instance variables in WebKit member variable checkers. (PR #127570)

2025-02-18 Thread Ryosuke Niwa via cfe-commits


@@ -87,6 +92,31 @@ class RawPtrRefMemberChecker
 }
   }
 
+  void visitObjCDecl(const ObjCContainerDecl *CD) const {
+if (auto *ID = dyn_cast(CD)) {
+  for (auto *Ivar : ID->ivars())
+visitIvarDecl(CD, Ivar);
+  return;
+}
+if (auto *ID = dyn_cast(CD)) {
+  for (auto *Ivar : ID->ivars())
+visitIvarDecl(CD, Ivar);
+  return;
+}
+  }
+
+  void visitIvarDecl(const ObjCContainerDecl *CD,
+ const ObjCIvarDecl *Ivar) const {
+const Type *IvarType = Ivar->getType().getTypePtrOrNull();
+if (!IvarType)
+  return;
+if (auto *IvarCXXRD = IvarType->getPointeeCXXRecordDecl()) {

rniwa wrote:

I think so. If `IvarType` isn't a pointer to a C++ type, 
`getPointeeCXXRecordDecl` can return `nullptr`. e.g. Objective-C interface type.

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


  1   2   3   4   5   6   >