[clang] [clang] Reject constexpr-unknown values as constant expressions more consistently (PR #129952)

2025-03-05 Thread Timm Baeder via cfe-commits


@@ -154,3 +154,26 @@ int g() {
 static_assert(f(arr) == 5);
 }
 }
+
+namespace GH128409 {
+  int &ff();
+  int &x = ff(); // nointerpreter-note {{declared here}}
+  constinit int &z = x; // expected-error {{variable does not have a constant 
initializer}}

tbaederr wrote:

If you end the comments in `\`, you don't need to add the `@-2` stuff.

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


[clang] [clang] Reject constexpr-unknown values as constant expressions more consistently (PR #129952)

2025-03-05 Thread Timm Baeder via cfe-commits


@@ -154,3 +154,26 @@ int g() {
 static_assert(f(arr) == 5);
 }
 }
+
+namespace GH128409 {
+  int &ff();
+  int &x = ff(); // nointerpreter-note {{declared here}}
+  constinit int &z = x; // expected-error {{variable does not have a constant 
initializer}}
+// expected-note@-1 {{required by 'constinit' 
specifier here}}
+// nointerpreter-note@-2 {{initializer of 'x' is not a 
constant expression}}

tbaederr wrote:

I don't want to block on this, but the diagnostic here is a little off... Even 
_if_ the initializer of `x` was a constant expression, the declaration of `z` 
would still not be valid because `x` is not const (or constexpr).

In other words, if I saw this error in practice, I'd try to fix `x`'s 
initializer, just to be greeted by another diagnostic.

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


[clang] [C++20][Modules] Fix incomplete decl chains (PR #129982)

2025-03-05 Thread Chuanqi Xu via cfe-commits


@@ -9180,6 +9180,12 @@ bool Sema::hasAcceptableDefinition(NamedDecl *D, 
NamedDecl **Suggested,
   if (!getLangOpts().Modules && !getLangOpts().ModulesLocalVisibility)
 return true;
 
+  // The external source may have additional definitions of this entity that 
are
+  // visible, so complete the redeclaration chain now.
+  if (auto *Source = Context.getExternalSource()) {
+Source->CompleteRedeclChain(D);
+  }

ChuanqiXu9 wrote:

To be honest, the completing redecl chain logic is more or less is in a mess. 
But let's try to do make things better if possible. I feel better to do this in 
redecls.


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


[clang] [llvm] [RISCV] Add Qualcomm uC Xqcibm (Bit Manipulation) extension (PR #129504)

2025-03-05 Thread via cfe-commits

https://github.com/hchandel updated 
https://github.com/llvm/llvm-project/pull/129504

>From c93d0db7c67ca5bac425b2ecc1579afff93e747a Mon Sep 17 00:00:00 2001
From: Harsh Chandel 
Date: Wed, 26 Feb 2025 16:52:54 +0530
Subject: [PATCH 1/8] [RISCV] Add Qualcomm uC Xqcibm (Bit Manipulation)
 extension This extension adds thirty eight  bit manipulation instructions.

The current spec can be found at:
https://github.com/quic/riscv-unified-db/releases/latest

This patch adds assembler only support.

Change-Id: Ie4cbec5d86ca015088cf8fecd634c0ce43903885
---
 .../Driver/print-supported-extensions-riscv.c |   1 +
 llvm/docs/RISCVUsage.rst  |   3 +
 llvm/docs/ReleaseNotes.md |   2 +
 .../Target/RISCV/AsmParser/RISCVAsmParser.cpp |  24 +
 .../RISCV/Disassembler/RISCVDisassembler.cpp  |  10 +-
 .../Target/RISCV/MCTargetDesc/RISCVBaseInfo.h |   1 +
 llvm/lib/Target/RISCV/RISCVFeatures.td|   8 +
 llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td   | 116 -
 llvm/lib/TargetParser/RISCVISAInfo.cpp|   6 +-
 llvm/test/CodeGen/RISCV/attributes.ll |   2 +
 llvm/test/MC/RISCV/xqcibm-invalid.s   | 474 ++
 llvm/test/MC/RISCV/xqcibm-valid.s | 123 +
 .../TargetParser/RISCVISAInfoTest.cpp |   2 +-
 13 files changed, 760 insertions(+), 12 deletions(-)
 create mode 100644 llvm/test/MC/RISCV/xqcibm-invalid.s
 create mode 100644 llvm/test/MC/RISCV/xqcibm-valid.s

diff --git a/clang/test/Driver/print-supported-extensions-riscv.c 
b/clang/test/Driver/print-supported-extensions-riscv.c
index fcd820464e2d1..740e4a437524c 100644
--- a/clang/test/Driver/print-supported-extensions-riscv.c
+++ b/clang/test/Driver/print-supported-extensions-riscv.c
@@ -195,6 +195,7 @@
 // CHECK-NEXT: svukte   0.3   'Svukte' 
(Address-Independent Latency of User-Mode Faults to Supervisor Addresses)
 // CHECK-NEXT: xqcia0.2   'Xqcia' (Qualcomm uC 
Arithmetic Extension)
 // CHECK-NEXT: xqciac   0.3   'Xqciac' (Qualcomm uC 
Load-Store Address Calculation Extension)
+// CHECK-NEXT: xqcibm   0.4   'Xqcibm' (Qualcomm uC Bit 
Manipulation Extension)
 // CHECK-NEXT: xqcicli  0.2   'Xqcicli' (Qualcomm uC 
Conditional Load Immediate Extension)
 // CHECK-NEXT: xqcicm   0.2   'Xqcicm' (Qualcomm uC 
Conditional Move Extension)
 // CHECK-NEXT: xqcics   0.2   'Xqcics' (Qualcomm uC 
Conditional Select Extension)
diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index 051eaf6999edb..20a1f0dafccc0 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -435,6 +435,9 @@ The current vendor extensions supported are:
 ``experimental-Xqciac``
   LLVM implements `version 0.3 of the Qualcomm uC Load-Store Address 
Calculation extension specification 
`__ by Qualcomm.  All 
instructions are prefixed with `qc.` as described in the specification. These 
instructions are only available for riscv32.
 
+``experimental-Xqcibm``
+  LLVM implements `version 0.4 of the Qualcomm uC Bit Manipulation extension 
specification `__ by 
Qualcomm.  All instructions are prefixed with `qc.` as described in the 
specification. These instructions are only available for riscv32.
+
 ``experimental-Xqcicli``
   LLVM implements `version 0.2 of the Qualcomm uC Conditional Load Immediate 
extension specification 
`__ by Qualcomm.  All 
instructions are prefixed with `qc.` as described in the specification. These 
instructions are only available for riscv32.
 
diff --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index 2a617901a1146..f8eafea7ab120 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -109,6 +109,8 @@ Changes to the RISC-V Backend
 
 * Adds experimental assembler support for the Qualcomm uC 'Xqcilia` (Large 
Immediate Arithmetic)
   extension.
+* Adds experimental assembler support for the Qualcomm uC 'Xqcibm` (Bit 
Manipulation)
+  extension.
 
 Changes to the WebAssembly Backend
 --
diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp 
b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
index 650ad48e50de0..ac24db30be325 100644
--- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
+++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
@@ -745,6 +745,26 @@ struct RISCVOperand final : public MCParsedAsmOperand {
VK == RISCVMCExpr::VK_RISCV_None;
   }
 
+  bool isUImm5Plus1() const {
+if (!isImm())
+  return false;
+RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None;
+int64_t Imm;
+bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
+return IsConstantImm && ((isUInt<5>(Imm) && (Imm != 0)) || (Imm == 32)) &&
+   V

[clang] clang: Do not implicitly addrspacecast in EmitAggExprToLValue (PR #129837)

2025-03-05 Thread Yaxun Liu via cfe-commits

yxsamliu wrote:

I have some doubt whether this will work for CUDA/HIP since their AST is not 
aware of address space. When translated to IR, any pointer is expected to 
pointing to default addr space. That is why alloca is immediately casted to 
generic pointer and used as generic pointer to match other parts of AST. For 
example:

```
__device__ void f(int*);
__device__ void g() {
  int a[10];
  int *p = a;
  f(a);
}
```
both p and f is expecting generic pointer in IR. Actually anywhere a is used, 
it is expected to be a generic pointer. That's why we need to cast it to 
generic pointer and use it as a generic pointer in the beginning.

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


[clang] [C++20][Modules] Fix incomplete decl chains (PR #129982)

2025-03-05 Thread Michael Park via cfe-commits


@@ -9180,6 +9180,12 @@ bool Sema::hasAcceptableDefinition(NamedDecl *D, 
NamedDecl **Suggested,
   if (!getLangOpts().Modules && !getLangOpts().ModulesLocalVisibility)
 return true;
 
+  // The external source may have additional definitions of this entity that 
are
+  // visible, so complete the redeclaration chain now.
+  if (auto *Source = Context.getExternalSource()) {
+Source->CompleteRedeclChain(D);
+  }

mpark wrote:

Yeah, I agree. I'm kind of trying to figure out what the most recent pattern 
(😂) is for most recent decls.

Some options I've come across are:

1. `CompleteRedeclChain` if `getExternalSource()` is present. e.g. 
[SemaType.cpp](https://github.com/llvm/llvm-project/blob/release/20.x/clang/lib/Sema/SemaType.cpp#L9225-L9230)
 (current state of the PR)
```cpp
  // The external source may have additional definitions of this entity that are
  // visible, so complete the redeclaration chain now.
  if (auto *Source = Context.getExternalSource()) {
Source->CompleteRedeclChain(D);
  }
```

2. "Dummy" invocation of `getMostRecentDecl()` if `getExternalSource()` is 
present. e.g. 
[DeclBase.cpp](https://github.com/llvm/llvm-project/blob/release/20.x/clang/lib/AST/DeclBase.cpp#L1884-L1889)
```cpp
  // If we have an external source, ensure that any later redeclarations of this
  // context have been loaded, since they may add names to the result of this
  // lookup (or add external visible storage).
  ExternalASTSource *Source = getParentASTContext().getExternalSource();
  if (Source)
(void)cast(this)->getMostRecentDecl();
```

3. Unconditional "dummy" invocation of `getMostRecentDecl()`. e.g. 
[CXXRecordDecl::dataPtr](https://github.com/llvm/llvm-project/blob/release/20.x/clang/include/clang/AST/DeclCXX.h#L457-L461)
 and 
[RecordLayoutBuilder.cpp](https://github.com/llvm/llvm-project/blob/release/20.x/clang/lib/AST/RecordLayoutBuilder.cpp#L3329-L3330)

I'm not quite sure I fully understood what you meant by:
> I feel better to do this in redecls.

We don't need to iterate through the `redecls()` here, and while I see dummy 
invocations of `getMostRecentDecl` as a way to trigger redecl completion, I 
don't see examples of `redecls` being called to force that to happen.

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


[clang] [C++20][Modules] Fix incomplete decl chains (PR #129982)

2025-03-05 Thread Michael Park via cfe-commits

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


[clang] [Feature]: merge host and kernel dependencies for heterogeneous compilation (PR #119513)

2025-03-05 Thread via cfe-commits

https://github.com/zhouronghua updated 
https://github.com/llvm/llvm-project/pull/119513

>From 3eb1ad33fa6b081cc399a61acd680009c54e42e2 Mon Sep 17 00:00:00 2001
From: "ronghua.zhou" 
Date: Fri, 14 Feb 2025 01:04:51 +
Subject: [PATCH] [Feature]: support for the BC library file into the compile
 dependencies

---
 clang/lib/Driver/ToolChains/Clang.cpp   |  19 +++-
 clang/lib/Frontend/CompilerInstance.cpp |  10 +-
 clang/lib/Frontend/DependencyFile.cpp   | 118 ++--
 3 files changed, 136 insertions(+), 11 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 55ec3db0ee994..e27c1fe95af42 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1056,8 +1056,23 @@ void Clang::AddPreprocessingOptions(Compilation &C, 
const JobAction &JA,
 DepFile = getDependencyFileName(Args, Inputs);
 C.addFailureResultFile(DepFile, &JA);
   }
-  CmdArgs.push_back("-dependency-file");
-  CmdArgs.push_back(DepFile);
+  // for host compile, we changed the dep file name to *.d.CUID.host
+  // so it will not overide kernel dep file,
+  // and merge it with *.d (kernel dep) file in DependencyFile.cpp
+  // for example, abc.d -> abc.d.2282B80C.host
+  auto AT = getToolChain().getAuxTriple();
+  if (!AT && std::string(DepFile) != "-") {
+SmallString<128> NewDepFile(DepFile);
+NewDepFile.append(
+"." + llvm::utohexstr(llvm::sys::Process::GetRandomNumber()) +
+".host");
+CmdArgs.push_back("-dependency-file");
+CmdArgs.push_back(Args.MakeArgString(NewDepFile));
+// else keep the original dep file name
+  } else {
+CmdArgs.push_back("-dependency-file");
+CmdArgs.push_back(DepFile);
+  }
 }
 
 bool HasTarget = false;
diff --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index c11c857ea0606..60ac343391e18 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -494,8 +494,14 @@ void 
CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) {
 
   // Handle generating dependencies, if requested.
   const DependencyOutputOptions &DepOpts = getDependencyOutputOpts();
-  if (!DepOpts.OutputFile.empty())
-addDependencyCollector(std::make_shared(DepOpts));
+  if (!DepOpts.OutputFile.empty()) {
+auto DFG = std::make_shared(DepOpts);
+for (auto F : getCodeGenOpts().LinkBitcodeFiles) {
+  DFG->maybeAddDependency(F.Filename, false, false, false, false);
+}
+addDependencyCollector(DFG);
+  }
+
   if (!DepOpts.DOTOutputFile.empty())
 AttachDependencyGraphGen(*PP, DepOpts.DOTOutputFile,
  getHeaderSearchOpts().Sysroot);
diff --git a/clang/lib/Frontend/DependencyFile.cpp 
b/clang/lib/Frontend/DependencyFile.cpp
index 15fa7de35df97..e018b5d596771 100644
--- a/clang/lib/Frontend/DependencyFile.cpp
+++ b/clang/lib/Frontend/DependencyFile.cpp
@@ -10,6 +10,9 @@
 //
 
//===--===//
 
+#include 
+#include 
+
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Frontend/DependencyOutputOptions.h"
@@ -343,20 +346,121 @@ static void PrintFilename(raw_ostream &OS, StringRef 
Filename,
   }
 }
 
+static std::vector SplitToLines(llvm::StringRef &Dep) {
+  std::vector Deps;
+
+  for (const auto &line : llvm::split(KernelDepContent, '\n'))
+// Remove empty lines and comment lines
+if (!tmpline.empty() && tmpline[0] != '#')
+  Deps.insert(line);
+
+  return Deps;
+}
+
+static std::string GetKernelDepFileName(std::string &HostDepFileName) {
+
+  // merge host dependency file (*.d.CUID.host)
+  // to kernel dependency file (*.d) for tops target
+  // for example, abc.d -> abc.d.2282B80C.host
+  const int CUIDLEN = 9;
+  llvm::StringRef SubStr = ".host";
+  SmallString<128> OutputFileS(HostDepFileName);
+  size_t Pos = OutputFileS.find(SubStr);
+  // for tops target, trim .CUID.host in dep file name
+  if (Pos != llvm::StringRef::npos)
+// abc.d.2282B80C.host -> abc.d
+return OutputFileS.substr(0, Pos - CUIDLEN);
+  else
+return "";
+}
+
+static void TryMergeDependencyFile(std::vector &KD,
+   std::vector &HD,
+   std::string &KDFN) {
+  // both kernel and host dep file is empty
+  if (HD.empty() && KD.empty())
+return;
+
+  // Write merged dep file
+  llvm::raw_fd_ostream DF(KDFN, EC, llvm::sys::fs::OF_Text);
+  if (EC) {
+Diags.Report(diag::err_fe_error_opening) << KDFN << EC.message();
+return;
+  }
+  // if host dep file is empty, just write kernel dep file
+  if (HD.empty())
+for (const auto &DL : KD)
+  DF << DL << "\n";
+  // if kernel dep file is empty, just write host dep file
+  else if (KD.empty())
+for (const auto &DL : HD)
+   

[clang] [Feature]: merge host and kernel dependencies for heterogeneous compilation (PR #119513)

2025-03-05 Thread via cfe-commits

https://github.com/zhouronghua updated 
https://github.com/llvm/llvm-project/pull/119513

>From 4792249a45c1445954b01e08ca1de571424a12d5 Mon Sep 17 00:00:00 2001
From: "ronghua.zhou" 
Date: Fri, 14 Feb 2025 01:04:51 +
Subject: [PATCH] [Feature]: support for the BC library file into the compile
 dependencies

---
 clang/lib/Driver/ToolChains/Clang.cpp   |  19 +++-
 clang/lib/Frontend/CompilerInstance.cpp |  10 +-
 clang/lib/Frontend/DependencyFile.cpp   | 119 ++--
 3 files changed, 137 insertions(+), 11 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 55ec3db0ee994..e27c1fe95af42 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1056,8 +1056,23 @@ void Clang::AddPreprocessingOptions(Compilation &C, 
const JobAction &JA,
 DepFile = getDependencyFileName(Args, Inputs);
 C.addFailureResultFile(DepFile, &JA);
   }
-  CmdArgs.push_back("-dependency-file");
-  CmdArgs.push_back(DepFile);
+  // for host compile, we changed the dep file name to *.d.CUID.host
+  // so it will not overide kernel dep file,
+  // and merge it with *.d (kernel dep) file in DependencyFile.cpp
+  // for example, abc.d -> abc.d.2282B80C.host
+  auto AT = getToolChain().getAuxTriple();
+  if (!AT && std::string(DepFile) != "-") {
+SmallString<128> NewDepFile(DepFile);
+NewDepFile.append(
+"." + llvm::utohexstr(llvm::sys::Process::GetRandomNumber()) +
+".host");
+CmdArgs.push_back("-dependency-file");
+CmdArgs.push_back(Args.MakeArgString(NewDepFile));
+// else keep the original dep file name
+  } else {
+CmdArgs.push_back("-dependency-file");
+CmdArgs.push_back(DepFile);
+  }
 }
 
 bool HasTarget = false;
diff --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index c11c857ea0606..60ac343391e18 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -494,8 +494,14 @@ void 
CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) {
 
   // Handle generating dependencies, if requested.
   const DependencyOutputOptions &DepOpts = getDependencyOutputOpts();
-  if (!DepOpts.OutputFile.empty())
-addDependencyCollector(std::make_shared(DepOpts));
+  if (!DepOpts.OutputFile.empty()) {
+auto DFG = std::make_shared(DepOpts);
+for (auto F : getCodeGenOpts().LinkBitcodeFiles) {
+  DFG->maybeAddDependency(F.Filename, false, false, false, false);
+}
+addDependencyCollector(DFG);
+  }
+
   if (!DepOpts.DOTOutputFile.empty())
 AttachDependencyGraphGen(*PP, DepOpts.DOTOutputFile,
  getHeaderSearchOpts().Sysroot);
diff --git a/clang/lib/Frontend/DependencyFile.cpp 
b/clang/lib/Frontend/DependencyFile.cpp
index 15fa7de35df97..5febce2e0a324 100644
--- a/clang/lib/Frontend/DependencyFile.cpp
+++ b/clang/lib/Frontend/DependencyFile.cpp
@@ -10,6 +10,9 @@
 //
 
//===--===//
 
+#include 
+#include 
+
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Frontend/DependencyOutputOptions.h"
@@ -343,20 +346,122 @@ static void PrintFilename(raw_ostream &OS, StringRef 
Filename,
   }
 }
 
+static std::vector SplitToLines(llvm::StringRef &Dep) {
+  std::vector Deps;
+
+  for (const auto &line : llvm::split(KernelDepContent, '\n'))
+// Remove empty lines and comment lines
+if (!tmpline.empty() && tmpline[0] != '#')
+  Deps.insert(line);
+
+  return Deps;
+}
+
+static std::string GetKernelDepFileName(std::string &HostDepFileName) {
+
+  // merge host dependency file (*.d.CUID.host)
+  // to kernel dependency file (*.d) for tops target
+  // for example, abc.d -> abc.d.2282B80C.host
+  const int CUIDLEN = 9;
+  llvm::StringRef SubStr = ".host";
+  SmallString<128> OutputFileS(HostDepFileName);
+  size_t Pos = OutputFileS.find(SubStr);
+  // for tops target, trim .CUID.host in dep file name
+  if (Pos != llvm::StringRef::npos)
+// abc.d.2282B80C.host -> abc.d
+return OutputFileS.substr(0, Pos - CUIDLEN);
+  else
+return "";
+}
+
+static void TryMergeDependencyFile(std::vector &KD,
+   std::vector &HD,
+   std::string &KDFN) {
+  // both kernel and host dep file is empty
+  if (HD.empty() && KD.empty())
+return;
+
+  // Write merged dep file
+  llvm::raw_fd_ostream DF(KDFN, EC, llvm::sys::fs::OF_Text);
+  if (EC) {
+Diags.Report(diag::err_fe_error_opening) << KDFN << EC.message();
+return;
+  }
+  // if host dep file is empty, just write kernel dep file
+  if (HD.empty())
+for (const auto &DL : KD)
+  DF << DL << "\n";
+  // if kernel dep file is empty, just write host dep file
+  else if (KD.empty())
+for (const auto &DL : HD)
+   

[clang] [Feature]: merge host and kernel dependencies for heterogeneous compilation (PR #119513)

2025-03-05 Thread via cfe-commits

https://github.com/zhouronghua updated 
https://github.com/llvm/llvm-project/pull/119513

>From 3dc7d8f9a7bd7f27ae8aa49e373c5febb0813d30 Mon Sep 17 00:00:00 2001
From: "ronghua.zhou" 
Date: Fri, 14 Feb 2025 01:04:51 +
Subject: [PATCH] [Feature]: support for the BC library file into the compile
 dependencies

---
 clang/lib/Driver/ToolChains/Clang.cpp   |  19 +++-
 clang/lib/Frontend/CompilerInstance.cpp |  10 +-
 clang/lib/Frontend/DependencyFile.cpp   | 119 ++--
 3 files changed, 137 insertions(+), 11 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 55ec3db0ee994..e27c1fe95af42 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1056,8 +1056,23 @@ void Clang::AddPreprocessingOptions(Compilation &C, 
const JobAction &JA,
 DepFile = getDependencyFileName(Args, Inputs);
 C.addFailureResultFile(DepFile, &JA);
   }
-  CmdArgs.push_back("-dependency-file");
-  CmdArgs.push_back(DepFile);
+  // for host compile, we changed the dep file name to *.d.CUID.host
+  // so it will not overide kernel dep file,
+  // and merge it with *.d (kernel dep) file in DependencyFile.cpp
+  // for example, abc.d -> abc.d.2282B80C.host
+  auto AT = getToolChain().getAuxTriple();
+  if (!AT && std::string(DepFile) != "-") {
+SmallString<128> NewDepFile(DepFile);
+NewDepFile.append(
+"." + llvm::utohexstr(llvm::sys::Process::GetRandomNumber()) +
+".host");
+CmdArgs.push_back("-dependency-file");
+CmdArgs.push_back(Args.MakeArgString(NewDepFile));
+// else keep the original dep file name
+  } else {
+CmdArgs.push_back("-dependency-file");
+CmdArgs.push_back(DepFile);
+  }
 }
 
 bool HasTarget = false;
diff --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index c11c857ea0606..60ac343391e18 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -494,8 +494,14 @@ void 
CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) {
 
   // Handle generating dependencies, if requested.
   const DependencyOutputOptions &DepOpts = getDependencyOutputOpts();
-  if (!DepOpts.OutputFile.empty())
-addDependencyCollector(std::make_shared(DepOpts));
+  if (!DepOpts.OutputFile.empty()) {
+auto DFG = std::make_shared(DepOpts);
+for (auto F : getCodeGenOpts().LinkBitcodeFiles) {
+  DFG->maybeAddDependency(F.Filename, false, false, false, false);
+}
+addDependencyCollector(DFG);
+  }
+
   if (!DepOpts.DOTOutputFile.empty())
 AttachDependencyGraphGen(*PP, DepOpts.DOTOutputFile,
  getHeaderSearchOpts().Sysroot);
diff --git a/clang/lib/Frontend/DependencyFile.cpp 
b/clang/lib/Frontend/DependencyFile.cpp
index 15fa7de35df97..e62e5dc8e0223 100644
--- a/clang/lib/Frontend/DependencyFile.cpp
+++ b/clang/lib/Frontend/DependencyFile.cpp
@@ -10,6 +10,9 @@
 //
 
//===--===//
 
+#include 
+#include 
+
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Frontend/DependencyOutputOptions.h"
@@ -343,20 +346,122 @@ static void PrintFilename(raw_ostream &OS, StringRef 
Filename,
   }
 }
 
+static std::vector SplitToLines(llvm::StringRef &Dep) {
+  std::vector Deps;
+
+  for (const auto &line : llvm::split(KernelDepContent, '\n'))
+// Remove empty lines and comment lines
+if (!line.empty() && line[0] != '#')
+  Deps.insert(line);
+
+  return Deps;
+}
+
+static std::string GetKernelDepFileName(std::string &HostDepFileName) {
+
+  // merge host dependency file (*.d.CUID.host)
+  // to kernel dependency file (*.d) for tops target
+  // for example, abc.d -> abc.d.2282B80C.host
+  const int CUIDLEN = 9;
+  llvm::StringRef SubStr = ".host";
+  SmallString<128> OutputFileS(HostDepFileName);
+  size_t Pos = OutputFileS.find(SubStr);
+  // for tops target, trim .CUID.host in dep file name
+  if (Pos != llvm::StringRef::npos)
+// abc.d.2282B80C.host -> abc.d
+return OutputFileS.substr(0, Pos - CUIDLEN);
+  else
+return "";
+}
+
+static void TryMergeDependencyFile(std::vector &KD,
+   std::vector &HD,
+   std::string &KDFN) {
+  // both kernel and host dep file is empty
+  if (HD.empty() && KD.empty())
+return;
+
+  // Write merged dep file
+  llvm::raw_fd_ostream DF(KDFN, EC, llvm::sys::fs::OF_Text);
+  if (EC) {
+Diags.Report(diag::err_fe_error_opening) << KDFN << EC.message();
+return;
+  }
+  // if host dep file is empty, just write kernel dep file
+  if (HD.empty())
+for (const auto &DL : KD)
+  DF << DL << "\n";
+  // if kernel dep file is empty, just write host dep file
+  else if (KD.empty())
+for (const auto &DL : HD)
+  DF 

[clang] [llvm] [RISCV] QCI Interrupt Support (PR #129957)

2025-03-05 Thread Sam Elliott via cfe-commits


@@ -382,6 +410,10 @@ void 
RISCVFrameLowering::determineFrameLayout(MachineFunction &MF) const {
   // Get the number of bytes to allocate from the FrameInfo.
   uint64_t FrameSize = MFI.getStackSize();
 
+  // QCI Interrupts use at least 96 bytes of stack space
+  if (RVFI->useQCIInterrupt(MF))
+FrameSize = std::max(FrameSize, QCIInterruptPushAmount);

lenary wrote:

I think a previous version of my patch had a different type for the Push 
Amount, but yes I will drop this.

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


[clang] [HLSL] add extra scalar vector overloads for clamp (PR #129939)

2025-03-05 Thread Sarah Spall via cfe-commits


@@ -35,25 +35,48 @@ namespace hlsl {
 #define _HLSL_16BIT_AVAILABILITY_STAGE(environment, version, stage)
 #endif
 
-#define GEN_VEC_SCALAR_OVERLOADS(FUNC_NAME, BASE_TYPE, AVAIL)  
\
-  GEN_BOTH_OVERLOADS(FUNC_NAME, BASE_TYPE, BASE_TYPE##2, AVAIL)
\
-  GEN_BOTH_OVERLOADS(FUNC_NAME, BASE_TYPE, BASE_TYPE##3, AVAIL)
\
-  GEN_BOTH_OVERLOADS(FUNC_NAME, BASE_TYPE, BASE_TYPE##4, AVAIL)
-
-#define GEN_BOTH_OVERLOADS(FUNC_NAME, BASE_TYPE, VECTOR_TYPE, AVAIL)   
\
-  IF_TRUE_##AVAIL( 
\
-  _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)) constexpr VECTOR_TYPE
\
-  FUNC_NAME(VECTOR_TYPE p0, BASE_TYPE p1) {
\
-return __builtin_elementwise_##FUNC_NAME(p0, (VECTOR_TYPE)p1); 
\
+#define _HLSL_CAT(a, b) a##b
+#define _HLSL_VEC_SCALAR_OVERLOADS(NAME, BASE_T, AVAIL)
\
+  _HLSL_ALL_OVERLOADS(NAME, BASE_T, AVAIL, _HLSL_CAT(_HLSL_NUM_ARGS_, NAME))
+
+#define _HLSL_ALL_OVERLOADS(NAME, BASE_T, AVAIL, NUM_ARGS) 
\
+  _HLSL_CAT(_HLSL_BOTH_OVERLOADS_, NUM_ARGS)   
\
+  (NAME, BASE_T, _HLSL_CAT(BASE_T, 2), AVAIL)  
\
+  _HLSL_CAT(_HLSL_BOTH_OVERLOADS_, NUM_ARGS)(NAME, BASE_T, 
\
+ _HLSL_CAT(BASE_T, 3), AVAIL)  
\
+  _HLSL_CAT(_HLSL_BOTH_OVERLOADS_, 
\
+NUM_ARGS)(NAME, BASE_T, _HLSL_CAT(BASE_T, 4), AVAIL)
+
+#define _HLSL_BOTH_OVERLOADS_2(NAME, BASE_T, VECTOR_T, AVAIL)  
\
+  _HLSL_CAT(_HLSL_IF_TRUE_, AVAIL) 
\
+  (_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)) constexpr VECTOR_T NAME(
\
+  VECTOR_T p0, BASE_T p1) {
\
+return _HLSL_CAT(__builtin_elementwise_, NAME)(p0, (VECTOR_T)p1);  
\
   }
\
-  IF_TRUE_##AVAIL( 
\
-  _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)) constexpr VECTOR_TYPE
\
-  FUNC_NAME(BASE_TYPE p0, VECTOR_TYPE p1) {
\
-return __builtin_elementwise_##FUNC_NAME((VECTOR_TYPE)p0, p1); 
\
+  _HLSL_CAT(_HLSL_IF_TRUE_, AVAIL) 
\
+  (_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)) constexpr VECTOR_T NAME(
\
+  BASE_T p0, VECTOR_T p1) {
\
+return _HLSL_CAT(__builtin_elementwise_, NAME)((VECTOR_T)p0, p1);  
\
   }
 
-#define IF_TRUE_0(EXPR)
-#define IF_TRUE_1(EXPR) EXPR
+#define _HLSL_BOTH_OVERLOADS_3(NAME, BASE_T, VECTOR_T, AVAIL)  
\
+  _HLSL_CAT(_HLSL_IF_TRUE_, AVAIL) 
\
+  (_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)) constexpr VECTOR_T NAME(
\
+  VECTOR_T p0, VECTOR_T p1, BASE_T p2) {   
\
+return _HLSL_CAT(__builtin_hlsl_elementwise_, NAME)(p0, p1, (VECTOR_T)p2); 
\
+  }
\
+  _HLSL_CAT(_HLSL_IF_TRUE_, AVAIL) 
\
+  (_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)) constexpr VECTOR_T NAME(
\
+  VECTOR_T p0, BASE_T p1, VECTOR_T p2) {   
\
+return _HLSL_CAT(__builtin_hlsl_elementwise_, NAME)(p0, (VECTOR_T)p1, p2); 
\

spall wrote:

> For clamp, I looked through lines 596 - 698 and didn't find the overload for 
> clamp where args 2 and 3 are the base type. Am I missing something?

int16_t clamp(int16_t, int16_t, int16_t); 
Is this what you mean? This is what I was referring to at least.

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


[clang] [HLSL] add extra scalar vector overloads for clamp (PR #129939)

2025-03-05 Thread Sarah Spall via cfe-commits


@@ -35,25 +35,48 @@ namespace hlsl {
 #define _HLSL_16BIT_AVAILABILITY_STAGE(environment, version, stage)
 #endif
 
-#define GEN_VEC_SCALAR_OVERLOADS(FUNC_NAME, BASE_TYPE, AVAIL)  
\
-  GEN_BOTH_OVERLOADS(FUNC_NAME, BASE_TYPE, BASE_TYPE##2, AVAIL)
\
-  GEN_BOTH_OVERLOADS(FUNC_NAME, BASE_TYPE, BASE_TYPE##3, AVAIL)
\
-  GEN_BOTH_OVERLOADS(FUNC_NAME, BASE_TYPE, BASE_TYPE##4, AVAIL)
-
-#define GEN_BOTH_OVERLOADS(FUNC_NAME, BASE_TYPE, VECTOR_TYPE, AVAIL)   
\
-  IF_TRUE_##AVAIL( 
\
-  _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)) constexpr VECTOR_TYPE
\
-  FUNC_NAME(VECTOR_TYPE p0, BASE_TYPE p1) {
\
-return __builtin_elementwise_##FUNC_NAME(p0, (VECTOR_TYPE)p1); 
\
+#define _HLSL_CAT(a, b) a##b
+#define _HLSL_VEC_SCALAR_OVERLOADS(NAME, BASE_T, AVAIL)
\
+  _HLSL_ALL_OVERLOADS(NAME, BASE_T, AVAIL, _HLSL_CAT(_HLSL_NUM_ARGS_, NAME))
+
+#define _HLSL_ALL_OVERLOADS(NAME, BASE_T, AVAIL, NUM_ARGS) 
\
+  _HLSL_CAT(_HLSL_BOTH_OVERLOADS_, NUM_ARGS)   
\
+  (NAME, BASE_T, _HLSL_CAT(BASE_T, 2), AVAIL)  
\
+  _HLSL_CAT(_HLSL_BOTH_OVERLOADS_, NUM_ARGS)(NAME, BASE_T, 
\
+ _HLSL_CAT(BASE_T, 3), AVAIL)  
\
+  _HLSL_CAT(_HLSL_BOTH_OVERLOADS_, 
\
+NUM_ARGS)(NAME, BASE_T, _HLSL_CAT(BASE_T, 4), AVAIL)
+
+#define _HLSL_BOTH_OVERLOADS_2(NAME, BASE_T, VECTOR_T, AVAIL)  
\
+  _HLSL_CAT(_HLSL_IF_TRUE_, AVAIL) 
\
+  (_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)) constexpr VECTOR_T NAME(
\
+  VECTOR_T p0, BASE_T p1) {
\
+return _HLSL_CAT(__builtin_elementwise_, NAME)(p0, (VECTOR_T)p1);  
\
   }
\
-  IF_TRUE_##AVAIL( 
\
-  _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)) constexpr VECTOR_TYPE
\
-  FUNC_NAME(BASE_TYPE p0, VECTOR_TYPE p1) {
\
-return __builtin_elementwise_##FUNC_NAME((VECTOR_TYPE)p0, p1); 
\
+  _HLSL_CAT(_HLSL_IF_TRUE_, AVAIL) 
\
+  (_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)) constexpr VECTOR_T NAME(
\
+  BASE_T p0, VECTOR_T p1) {
\
+return _HLSL_CAT(__builtin_elementwise_, NAME)((VECTOR_T)p0, p1);  
\
   }
 
-#define IF_TRUE_0(EXPR)
-#define IF_TRUE_1(EXPR) EXPR
+#define _HLSL_BOTH_OVERLOADS_3(NAME, BASE_T, VECTOR_T, AVAIL)  
\
+  _HLSL_CAT(_HLSL_IF_TRUE_, AVAIL) 
\
+  (_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)) constexpr VECTOR_T NAME(
\
+  VECTOR_T p0, VECTOR_T p1, BASE_T p2) {   
\
+return _HLSL_CAT(__builtin_hlsl_elementwise_, NAME)(p0, p1, (VECTOR_T)p2); 
\
+  }
\
+  _HLSL_CAT(_HLSL_IF_TRUE_, AVAIL) 
\
+  (_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)) constexpr VECTOR_T NAME(
\
+  VECTOR_T p0, BASE_T p1, VECTOR_T p2) {   
\
+return _HLSL_CAT(__builtin_hlsl_elementwise_, NAME)(p0, (VECTOR_T)p1, p2); 
\

spall wrote:

Do you mean where 2 and 3 are the base type but the first is a vector? I'm not 
sure if that is meant to be allowed.

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


[clang] [llvm] [RISCV] QCI Interrupt Support (PR #129957)

2025-03-05 Thread Craig Topper via cfe-commits


@@ -382,6 +410,10 @@ void 
RISCVFrameLowering::determineFrameLayout(MachineFunction &MF) const {
   // Get the number of bytes to allocate from the FrameInfo.
   uint64_t FrameSize = MFI.getStackSize();
 
+  // QCI Interrupts use at least 96 bytes of stack space
+  if (RVFI->useQCIInterrupt(MF))
+FrameSize = std::max(FrameSize, QCIInterruptPushAmount);

topperc wrote:

why is the `` needed? I think both operands have the same type so it 
should be inferred

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


[clang] [Feature]: merge host and kernel dependencies for heterogeneous compilation (PR #119513)

2025-03-05 Thread via cfe-commits


@@ -1056,8 +1056,20 @@ void Clang::AddPreprocessingOptions(Compilation &C, 
const JobAction &JA,
 DepFile = getDependencyFileName(Args, Inputs);
 C.addFailureResultFile(DepFile, &JA);
   }
-  CmdArgs.push_back("-dependency-file");
-  CmdArgs.push_back(DepFile);
+  // for host compile, if OPT_MMMD is on, default to create *.d.host file
+  // and merge it with *.d (kernel dep) file in DependencyFile.cpp
+  Arg *ArgMMD = Args.getLastArg(options::OPT_MMMD);
+  auto at = getToolChain().getAuxTriple();
+  if (ArgMMD && !at && std::string(DepFile) != "-") {
+SmallString<128> NewDepFile(DepFile);
+NewDepFile.append(".host");

zhouronghua wrote:

this patten of ".host" is an interface for 
DependencyFileGenerator::outputDependencyFile
so if we chang it to some CUID, we now do not get any good way to let host 
compiler know if we need to merge two or more dep file.
I will think over it, and try to find some way to fixed it.

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


[clang] [clang][dataflow] Add test for crash repro and clean up const accessor handling (PR #129930)

2025-03-05 Thread Jan Voung via cfe-commits

https://github.com/jvoung updated 
https://github.com/llvm/llvm-project/pull/129930

>From 81f5cfde1029b3c9ddd62eb0587ed370d67cccab Mon Sep 17 00:00:00 2001
From: Jan Voung 
Date: Wed, 5 Mar 2025 20:15:48 +
Subject: [PATCH 1/4] [clang][dataflow] Add test for crash repro and clean up
 const accessor handling

Add test for https://github.com/llvm/llvm-project/issues/125589

The crash is actually incidentally fixed by
https://github.com/llvm/llvm-project/pull/128437 since it added a branch
for the reference case and would no longer fall through when the return
type is a reference to a pointer.

Clean up a bit as well:
- make the fallback for early returns more consistent (check if
  returning optional and call transfer function for that case)
- check RecordLoc == nullptr in one place

Add some init for the reference to pointer/bool cases.
---
 .../Models/UncheckedOptionalAccessModel.cpp   | 70 +++
 .../UncheckedOptionalAccessModelTest.cpp  | 24 +++
 2 files changed, 64 insertions(+), 30 deletions(-)

diff --git 
a/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp 
b/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
index 9381c5c42e566..914f29c243248 100644
--- a/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
@@ -551,15 +551,17 @@ void transferCallReturningOptional(const CallExpr *E,
   setHasValue(*Loc, State.Env.makeAtomicBoolValue(), State.Env);
 }
 
-void handleConstMemberCall(const CallExpr *CE,
+bool handleConstMemberCall(const CallExpr *CE,
dataflow::RecordStorageLocation *RecordLoc,
const MatchFinder::MatchResult &Result,
LatticeTransferState &State) {
+  if (RecordLoc == nullptr) return false;
+
   // If the const method returns an optional or reference to an optional.
-  if (RecordLoc != nullptr && isSupportedOptionalType(CE->getType())) {
+  if (isSupportedOptionalType(CE->getType())) {
 const FunctionDecl *DirectCallee = CE->getDirectCallee();
 if (DirectCallee == nullptr)
-  return;
+  return false;
 StorageLocation &Loc =
 State.Lattice.getOrCreateConstMethodReturnStorageLocation(
 *RecordLoc, DirectCallee, State.Env, [&](StorageLocation &Loc) {
@@ -577,57 +579,65 @@ void handleConstMemberCall(const CallExpr *CE,
   auto &ResultLoc = State.Env.getResultObjectLocation(*CE);
   copyRecord(cast(Loc), ResultLoc, State.Env);
 }
-return;
+return true;
   }
 
+  bool IsBooleanOrPointer = CE->getType()->isBooleanType() ||
+CE->getType()->isPointerType();
+
   // Cache if the const method returns a reference
-  if (RecordLoc != nullptr && CE->isGLValue()) {
+  if (CE->isGLValue()) {
 const FunctionDecl *DirectCallee = CE->getDirectCallee();
 if (DirectCallee == nullptr)
-  return;
+  return false;
 
 StorageLocation &Loc =
 State.Lattice.getOrCreateConstMethodReturnStorageLocation(
 *RecordLoc, DirectCallee, State.Env, [&](StorageLocation &Loc) {
-  // no-op
+  if (IsBooleanOrPointer) {
+State.Env.setValue(Loc, *State.Env.createValue(CE->getType()));
+  }
 });
 
 State.Env.setStorageLocation(*CE, Loc);
-return;
-  }
-
-  // Cache if the const method returns a boolean or pointer type.
-  // We may decide to cache other return types in the future.
-  if (RecordLoc != nullptr &&
-  (CE->getType()->isBooleanType() || CE->getType()->isPointerType())) {
+return true;
+  } else if (IsBooleanOrPointer) {
+// Cache if the const method returns a boolean or pointer type.
 Value *Val = State.Lattice.getOrCreateConstMethodReturnValue(*RecordLoc, 
CE,
  State.Env);
 if (Val == nullptr)
-  return;
+  return false;
 State.Env.setValue(*CE, *Val);
-return;
+return true;
   }
 
-  // Perform default handling if the call returns an optional
-  // but wasn't handled above (if RecordLoc is nullptr).
-  if (isSupportedOptionalType(CE->getType())) {
-transferCallReturningOptional(CE, Result, State);
-  }
+  return false;
 }
 
-void transferValue_ConstMemberCall(const CXXMemberCallExpr *MCE,
-   const MatchFinder::MatchResult &Result,
-   LatticeTransferState &State) {
-  handleConstMemberCall(
-  MCE, dataflow::getImplicitObjectLocation(*MCE, State.Env), Result, 
State);
+void transferConstMemberCall(const CXXMemberCallExpr *MCE,
+ const MatchFinder::MatchResult &Result,
+ LatticeTransferState &State) {
+  if (!handleConstMemberCall(
+  MCE, dataflow::getImplicitObjectLocation(*MCE, State.Env), Result,
+  State)) {
+// Perfor

[clang] [llvm] [HLSL][RootSignature] Implement Parsing of Descriptor Tables (PR #122982)

2025-03-05 Thread Finn Plummer via cfe-commits

https://github.com/inbelic updated 
https://github.com/llvm/llvm-project/pull/122982

>From 9fe6b897b161f7e40e4a5662ab2cad4dceed174e Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Thu, 13 Feb 2025 22:56:52 +
Subject: [PATCH 01/15] [HLSL][RootSignature] Parse empty Descriptor Table Root
 Element

- defines the Parser class and an initial set of helper methods to
support consuming tokens. functionality is demonstrated through a simple
empty descriptor table test case
- defines an initial in-memory representation of a DescriptorTable
- implements a test harness that will be used to validate the correct
diagnostics are generated. it will construct a dummy pre-processor with
diagnostics consumer to do so
---
 .../clang/Basic/DiagnosticParseKinds.td   |   2 +
 .../clang/Parse/ParseHLSLRootSignature.h  |  69 ++
 clang/lib/Parse/CMakeLists.txt|   1 +
 clang/lib/Parse/ParseHLSLRootSignature.cpp| 138 +++
 clang/unittests/CMakeLists.txt|   1 +
 clang/unittests/Parse/CMakeLists.txt  |  23 ++
 .../Parse/ParseHLSLRootSignatureTest.cpp  | 217 ++
 .../llvm/Frontend/HLSL/HLSLRootSignature.h|  37 +++
 8 files changed, 488 insertions(+)
 create mode 100644 clang/include/clang/Parse/ParseHLSLRootSignature.h
 create mode 100644 clang/lib/Parse/ParseHLSLRootSignature.cpp
 create mode 100644 clang/unittests/Parse/CMakeLists.txt
 create mode 100644 clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp
 create mode 100644 llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index c513dab810d1f..4c6adab80e60e 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1818,4 +1818,6 @@ def ext_hlsl_access_specifiers : ExtWarn<
 def err_hlsl_unsupported_component : Error<"invalid component '%0' used; 
expected 'x', 'y', 'z', or 'w'">;
 def err_hlsl_packoffset_invalid_reg : Error<"invalid resource class specifier 
'%0' for packoffset, expected 'c'">;
 
+// HLSL Root Signature Parser Diagnostics
+def err_hlsl_rootsig_unexpected_token_kind : Error<"got %1 but expected 
%select{|one of}0 the following token kind%select{|s}0: %2">;
 } // end of Parser diagnostics
diff --git a/clang/include/clang/Parse/ParseHLSLRootSignature.h 
b/clang/include/clang/Parse/ParseHLSLRootSignature.h
new file mode 100644
index 0..fa46bdd663a2c
--- /dev/null
+++ b/clang/include/clang/Parse/ParseHLSLRootSignature.h
@@ -0,0 +1,69 @@
+//===--- ParseHLSLRootSignature.h ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+//  This file defines the ParseHLSLRootSignature interface.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_PARSE_PARSEHLSLROOTSIGNATURE_H
+#define LLVM_CLANG_PARSE_PARSEHLSLROOTSIGNATURE_H
+
+#include "clang/Basic/DiagnosticParse.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Lex/LexHLSLRootSignature.h"
+
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+
+#include "llvm/Frontend/HLSL/HLSLRootSignature.h"
+
+namespace clang {
+namespace hlsl {
+
+class RootSignatureParser {
+public:
+  RootSignatureParser(SmallVector &Elements,
+  RootSignatureLexer &Lexer, clang::Preprocessor &PP);
+
+  /// Consumes tokens from the Lexer and constructs the in-memory
+  /// representations of the RootElements. Tokens are consumed until an
+  /// error is encountered or the end of the buffer.
+  ///
+  /// Returns true if a parsing error is encountered.
+  bool Parse();
+
+  DiagnosticsEngine &Diags() { return PP.getDiagnostics(); }
+
+private:
+  // Root Element helpers
+  bool ParseRootElement();
+  bool ParseDescriptorTable();
+
+  /// Invoke the Lexer to consume a token and update CurToken with the result
+  void ConsumeNextToken() { CurToken = Lexer.ConsumeToken(); }
+
+  /// Consumes the next token and report an error if it is not of the expected
+  /// kind.
+  ///
+  /// Returns true if there was an error reported.
+  bool ConsumeExpectedToken(TokenKind Expected);
+  bool ConsumeExpectedToken(ArrayRef AnyExpected);
+
+private:
+  SmallVector &Elements;
+  RootSignatureLexer &Lexer;
+
+  clang::Preprocessor &PP;
+
+  RootSignatureToken CurToken;
+};
+
+} // namespace hlsl
+} // namespace clang
+
+#endif // LLVM_CLANG_PARSE_PARSEHLSLROOTSIGNATURE_H
diff --git a/clang/lib/Parse/CMakeLists.txt b/clang/lib/Parse/CMakeLists.txt
index 22e902f7e1bc5..00fde537bb9c6 100644
--- a/clang/lib/Parse/CMakeLists.txt
+++ b/clang/lib/Parse/CMakeLists.txt
@@ -14,6 +14,7 @@ add_clang_library(clangPa

[clang] [llvm] [HLSL][RootSignature] Implement Parsing of Descriptor Tables (PR #122982)

2025-03-05 Thread Finn Plummer via cfe-commits


@@ -0,0 +1,417 @@
+#include "clang/Parse/ParseHLSLRootSignature.h"
+
+#include "clang/Lex/LiteralSupport.h"
+
+#include "llvm/Support/raw_ostream.h"
+
+using namespace llvm::hlsl::rootsig;
+
+namespace clang {
+namespace hlsl {
+
+static std::string FormatTokenKinds(ArrayRef Kinds) {
+  std::string TokenString;
+  llvm::raw_string_ostream Out(TokenString);
+  bool First = true;
+  for (auto Kind : Kinds) {
+if (!First)
+  Out << ", ";
+switch (Kind) {
+#define TOK(X, SPELLING)   
\
+  case TokenKind::X:   
\
+Out << SPELLING;   
\
+break;
+#include "clang/Lex/HLSLRootSignatureTokenKinds.def"
+}
+First = false;
+  }
+
+  return TokenString;
+}
+
+// Parser Definitions
+
+RootSignatureParser::RootSignatureParser(SmallVector &Elements,
+ RootSignatureLexer &Lexer,
+ Preprocessor &PP)
+: Elements(Elements), Lexer(Lexer), PP(PP), CurToken(SourceLocation()) {}
+
+bool RootSignatureParser::Parse() {
+  // Handle edge-case of empty RootSignature()
+  if (Lexer.EndOfBuffer())
+return false;
+
+  // Iterate as many RootElements as possible
+  while (!ParseRootElement()) {
+if (Lexer.EndOfBuffer())
+  return false;
+if (ConsumeExpectedToken(TokenKind::pu_comma))
+  return true;
+  }
+
+  return true;
+}
+
+bool RootSignatureParser::ParseRootElement() {
+  if (ConsumeExpectedToken(TokenKind::kw_DescriptorTable))
+return true;
+
+  // Dispatch onto the correct parse method
+  switch (CurToken.Kind) {
+  case TokenKind::kw_DescriptorTable:
+return ParseDescriptorTable();
+  default:
+break;
+  }
+  llvm_unreachable("Switch for an expected token was not provided");
+}
+
+bool RootSignatureParser::ParseDescriptorTable() {
+  DescriptorTable Table;
+
+  if (ConsumeExpectedToken(TokenKind::pu_l_paren))
+return true;
+
+  // Empty case:
+  if (TryConsumeExpectedToken(TokenKind::pu_r_paren)) {
+Elements.push_back(Table);
+return false;
+  }
+
+  bool SeenVisibility = false;
+  // Iterate through all the defined clauses
+  do {
+// Handle the visibility parameter
+if (TryConsumeExpectedToken(TokenKind::kw_visibility)) {
+  if (SeenVisibility) {
+Diags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param)
+<< FormatTokenKinds(CurToken.Kind);
+return true;
+  }
+  SeenVisibility = true;
+  if (ParseParam(&Table.Visibility))
+return true;
+  continue;
+}
+
+// Otherwise, we expect a clause
+if (ParseDescriptorTableClause())
+  return true;
+Table.NumClauses++;
+  } while (TryConsumeExpectedToken(TokenKind::pu_comma));
+
+  if (ConsumeExpectedToken(TokenKind::pu_r_paren))
+return true;
+
+  Elements.push_back(Table);
+  return false;
+}
+
+bool RootSignatureParser::ParseDescriptorTableClause() {
+  if (ConsumeExpectedToken({TokenKind::kw_CBV, TokenKind::kw_SRV,
+TokenKind::kw_UAV, TokenKind::kw_Sampler}))
+return true;
+
+  DescriptorTableClause Clause;
+  switch (CurToken.Kind) {
+  case TokenKind::kw_CBV:
+Clause.Type = ClauseType::CBuffer;
+break;
+  case TokenKind::kw_SRV:
+Clause.Type = ClauseType::SRV;
+break;
+  case TokenKind::kw_UAV:
+Clause.Type = ClauseType::UAV;
+break;
+  case TokenKind::kw_Sampler:
+Clause.Type = ClauseType::Sampler;
+break;
+  default:
+llvm_unreachable("Switch for an expected token was not provided");
+  }
+  Clause.SetDefaultFlags();
+
+  if (ConsumeExpectedToken(TokenKind::pu_l_paren))
+return true;
+
+  // Consume mandatory Register paramater
+  if (ParseRegister(&Clause.Register))
+return true;
+
+  // Define optional paramaters
+  llvm::SmallDenseMap RefMap = {
+  {TokenKind::kw_numDescriptors, &Clause.NumDescriptors},
+  {TokenKind::kw_space, &Clause.Space},
+  {TokenKind::kw_offset, &Clause.Offset},
+  {TokenKind::kw_flags, &Clause.Flags},
+  };
+  if (ParseOptionalParams({RefMap}))
+return true;
+
+  if (ConsumeExpectedToken(TokenKind::pu_r_paren))
+return true;
+
+  Elements.push_back(Clause);
+  return false;
+}
+
+// Helper struct so that we can use the overloaded notation of std::visit
+template  struct ParseMethods : Ts... { using Ts::operator()...; 
};
+template  ParseMethods(Ts...) -> ParseMethods;
+
+bool RootSignatureParser::ParseParam(ParamType Ref) {
+  if (ConsumeExpectedToken(TokenKind::pu_equal))
+return true;
+
+  bool Error;
+  std::visit(
+  ParseMethods{
+  [&](uint32_t *X) { Error = ParseUInt(X); },
+  [&](DescriptorRangeOffset *X) {
+Error = ParseDescriptorRangeOffset(X);
+  },
+  [&](ShaderVisibility *Enum) { Error = ParseShaderVisibility(Enum); },
+  [&](DescriptorRangeFlags *Flags) {

[clang] [clang][dataflow] Add test for crash repro and clean up const accessor handling (PR #129930)

2025-03-05 Thread Jan Voung via cfe-commits

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


[clang] [Feature]: merge host and kernel dependencies for heterogeneous compilation (PR #119513)

2025-03-05 Thread via cfe-commits

https://github.com/zhouronghua updated 
https://github.com/llvm/llvm-project/pull/119513

>From 9553daf86c466f8137fd588c3aee21b3ae20d762 Mon Sep 17 00:00:00 2001
From: "ronghua.zhou" 
Date: Fri, 14 Feb 2025 01:04:51 +
Subject: [PATCH] [Feature]: support for the BC library file into the compile
 dependencies

---
 clang/lib/Driver/ToolChains/Clang.cpp   |  19 +++-
 clang/lib/Frontend/CompilerInstance.cpp |  10 ++-
 clang/lib/Frontend/DependencyFile.cpp   | 111 ++--
 3 files changed, 130 insertions(+), 10 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 55ec3db0ee994..e27c1fe95af42 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1056,8 +1056,23 @@ void Clang::AddPreprocessingOptions(Compilation &C, 
const JobAction &JA,
 DepFile = getDependencyFileName(Args, Inputs);
 C.addFailureResultFile(DepFile, &JA);
   }
-  CmdArgs.push_back("-dependency-file");
-  CmdArgs.push_back(DepFile);
+  // for host compile, we changed the dep file name to *.d.CUID.host
+  // so it will not overide kernel dep file,
+  // and merge it with *.d (kernel dep) file in DependencyFile.cpp
+  // for example, abc.d -> abc.d.2282B80C.host
+  auto AT = getToolChain().getAuxTriple();
+  if (!AT && std::string(DepFile) != "-") {
+SmallString<128> NewDepFile(DepFile);
+NewDepFile.append(
+"." + llvm::utohexstr(llvm::sys::Process::GetRandomNumber()) +
+".host");
+CmdArgs.push_back("-dependency-file");
+CmdArgs.push_back(Args.MakeArgString(NewDepFile));
+// else keep the original dep file name
+  } else {
+CmdArgs.push_back("-dependency-file");
+CmdArgs.push_back(DepFile);
+  }
 }
 
 bool HasTarget = false;
diff --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index c11c857ea0606..60ac343391e18 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -494,8 +494,14 @@ void 
CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) {
 
   // Handle generating dependencies, if requested.
   const DependencyOutputOptions &DepOpts = getDependencyOutputOpts();
-  if (!DepOpts.OutputFile.empty())
-addDependencyCollector(std::make_shared(DepOpts));
+  if (!DepOpts.OutputFile.empty()) {
+auto DFG = std::make_shared(DepOpts);
+for (auto F : getCodeGenOpts().LinkBitcodeFiles) {
+  DFG->maybeAddDependency(F.Filename, false, false, false, false);
+}
+addDependencyCollector(DFG);
+  }
+
   if (!DepOpts.DOTOutputFile.empty())
 AttachDependencyGraphGen(*PP, DepOpts.DOTOutputFile,
  getHeaderSearchOpts().Sysroot);
diff --git a/clang/lib/Frontend/DependencyFile.cpp 
b/clang/lib/Frontend/DependencyFile.cpp
index 15fa7de35df97..79549e46b9052 100644
--- a/clang/lib/Frontend/DependencyFile.cpp
+++ b/clang/lib/Frontend/DependencyFile.cpp
@@ -10,6 +10,9 @@
 //
 
//===--===//
 
+#include 
+#include 
+
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Frontend/DependencyOutputOptions.h"
@@ -343,6 +346,76 @@ static void PrintFilename(raw_ostream &OS, StringRef 
Filename,
   }
 }
 
+static std::vector SplitLines(llvm::StringRef &Dep) {
+  std::vector Deps;
+
+  for (const auto &line : llvm::split(KernelDepContent, '\n'))
+// Remove empty lines and comment lines
+if (!tmpline.empty() && tmpline[0] != '#')
+  Deps.insert(line);
+
+  return Deps;
+}
+
+static std::string GetKernelDepFileName(std::string &HostDepFileName) {
+
+  // merge host dependency file (*.d.host)
+  // to kernel dependency file (*.d.host) for tops target
+  // for example, abc.d -> abc.d.2282B80C.host
+  const int CUIDLEN = 9;
+  llvm::StringRef SubStr = ".host";
+  SmallString<128> OutputFileS(HostDepFileName);
+  size_t Pos = OutputFileS.find(SubStr);
+  // for tops target, trim .host in dep file
+  if (Pos != llvm::StringRef::npos)
+// abc.d.2282B80C.host -> abc.d
+return OutputFileS.substr(0, Pos - CUIDLEN);
+  else
+return "";  
+}
+
+static void TryMergeDependencyFile(std::vector &KD,
+   std::vector &HD,
+   std::string &KDFN) {
+  if (HD.empty() && KD.empty())
+// both kernel and host dep file is empty
+return;
+
+  // Write merged dep file
+  llvm::raw_fd_ostream DF(KDFN, EC, llvm::sys::fs::OF_Text);
+  if (EC) {
+Diags.Report(diag::err_fe_error_opening) << KDFN << EC.message();
+return;
+  }
+  if (HD.empty())
+for (const auto &DL : KD)
+  DF << DL << "\n";
+  else if (KD.empty())
+for (const auto &DL : HD)
+  DF << DL << "\n";
+  else {
+if (KD.front() != HD.front())
+  Diags.Report(diag::err_fe_error_opening)
+  << O

[clang] [C++20][Modules] Fix incomplete decl chains (PR #129982)

2025-03-05 Thread Chuanqi Xu via cfe-commits


@@ -9180,6 +9180,12 @@ bool Sema::hasAcceptableDefinition(NamedDecl *D, 
NamedDecl **Suggested,
   if (!getLangOpts().Modules && !getLangOpts().ModulesLocalVisibility)
 return true;
 
+  // The external source may have additional definitions of this entity that 
are
+  // visible, so complete the redeclaration chain now.
+  if (auto *Source = Context.getExternalSource()) {
+Source->CompleteRedeclChain(D);
+  }

ChuanqiXu9 wrote:

Maybe some gaps here. What I asked previously is:
1. According to the comments, it looks like we're trying to load all other 
redeclarations of the current declaration, since we want to see if any 
redeclaration of the current declaration is acceptable.
2. In Sema, ideally, when we want to the things above, we should call 
`redecls()`.

then my question is, what is the problem?
1. There is a path in Sema that meant to look at redeclarations but not called 
redecls().
2. Redecls get called but didn't work as expceted (not work well).
3. Or do I misunderstand the problem?

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


[clang] [C++20][Modules] Fix incomplete decl chains (PR #129982)

2025-03-05 Thread Michael Park via cfe-commits


@@ -10178,12 +10178,12 @@ void ASTReader::visitTopLevelModuleMaps(
 }
 
 void ASTReader::finishPendingActions() {
-  while (
-  !PendingIdentifierInfos.empty() || !PendingDeducedFunctionTypes.empty() 
||
-  !PendingDeducedVarTypes.empty() || !PendingIncompleteDeclChains.empty() 
||
-  !PendingDeclChains.empty() || !PendingMacroIDs.empty() ||
-  !PendingDeclContextInfos.empty() || !PendingUpdateRecords.empty() ||
-  !PendingObjCExtensionIvarRedeclarations.empty()) {
+  while (!PendingIdentifierInfos.empty() ||
+ !PendingDeducedFunctionTypes.empty() ||
+ !PendingDeducedVarTypes.empty() || !PendingDeclChains.empty() ||
+ !PendingMacroIDs.empty() || !PendingDeclContextInfos.empty() ||
+ !PendingUpdateRecords.empty() ||
+ !PendingObjCExtensionIvarRedeclarations.empty()) {

mpark wrote:

This is the effect of reapplying #121245, which moved 
`PendingIncompleteDeclChains` out of this loop.

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


[clang] Reapply "[analyzer] Handle [[assume(cond)]] as __builtin_assume(cond)" (PR #129234)

2025-03-05 Thread Balazs Benics via cfe-commits

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


[clang] [Feature]: merge host and kernel dependencies for heterogeneous compilation (PR #119513)

2025-03-05 Thread via cfe-commits

https://github.com/zhouronghua updated 
https://github.com/llvm/llvm-project/pull/119513

>From b8a0f37d4d408be7877c8134ff4654c6289e7e21 Mon Sep 17 00:00:00 2001
From: "ronghua.zhou" 
Date: Fri, 14 Feb 2025 01:04:51 +
Subject: [PATCH] [Feature]: support for the BC library file into the compile
 dependencies

---
 clang/lib/Driver/ToolChains/Clang.cpp   |  19 +++-
 clang/lib/Frontend/CompilerInstance.cpp |  10 ++-
 clang/lib/Frontend/DependencyFile.cpp   | 114 ++--
 3 files changed, 133 insertions(+), 10 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 55ec3db0ee994..e27c1fe95af42 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1056,8 +1056,23 @@ void Clang::AddPreprocessingOptions(Compilation &C, 
const JobAction &JA,
 DepFile = getDependencyFileName(Args, Inputs);
 C.addFailureResultFile(DepFile, &JA);
   }
-  CmdArgs.push_back("-dependency-file");
-  CmdArgs.push_back(DepFile);
+  // for host compile, we changed the dep file name to *.d.CUID.host
+  // so it will not overide kernel dep file,
+  // and merge it with *.d (kernel dep) file in DependencyFile.cpp
+  // for example, abc.d -> abc.d.2282B80C.host
+  auto AT = getToolChain().getAuxTriple();
+  if (!AT && std::string(DepFile) != "-") {
+SmallString<128> NewDepFile(DepFile);
+NewDepFile.append(
+"." + llvm::utohexstr(llvm::sys::Process::GetRandomNumber()) +
+".host");
+CmdArgs.push_back("-dependency-file");
+CmdArgs.push_back(Args.MakeArgString(NewDepFile));
+// else keep the original dep file name
+  } else {
+CmdArgs.push_back("-dependency-file");
+CmdArgs.push_back(DepFile);
+  }
 }
 
 bool HasTarget = false;
diff --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index c11c857ea0606..60ac343391e18 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -494,8 +494,14 @@ void 
CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) {
 
   // Handle generating dependencies, if requested.
   const DependencyOutputOptions &DepOpts = getDependencyOutputOpts();
-  if (!DepOpts.OutputFile.empty())
-addDependencyCollector(std::make_shared(DepOpts));
+  if (!DepOpts.OutputFile.empty()) {
+auto DFG = std::make_shared(DepOpts);
+for (auto F : getCodeGenOpts().LinkBitcodeFiles) {
+  DFG->maybeAddDependency(F.Filename, false, false, false, false);
+}
+addDependencyCollector(DFG);
+  }
+
   if (!DepOpts.DOTOutputFile.empty())
 AttachDependencyGraphGen(*PP, DepOpts.DOTOutputFile,
  getHeaderSearchOpts().Sysroot);
diff --git a/clang/lib/Frontend/DependencyFile.cpp 
b/clang/lib/Frontend/DependencyFile.cpp
index 15fa7de35df97..9b3955e1d333e 100644
--- a/clang/lib/Frontend/DependencyFile.cpp
+++ b/clang/lib/Frontend/DependencyFile.cpp
@@ -10,6 +10,9 @@
 //
 
//===--===//
 
+#include 
+#include 
+
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Frontend/DependencyOutputOptions.h"
@@ -343,6 +346,79 @@ static void PrintFilename(raw_ostream &OS, StringRef 
Filename,
   }
 }
 
+static std::vector SplitLines(llvm::StringRef &Dep) {
+  std::vector Deps;
+
+  for (const auto &line : llvm::split(KernelDepContent, '\n'))
+// Remove empty lines and comment lines
+if (!tmpline.empty() && tmpline[0] != '#')
+  Deps.insert(line);
+
+  return Deps;
+}
+
+static std::string GetKernelDepFileName(std::string &HostDepFileName) {
+
+  // merge host dependency file (*.d.host)
+  // to kernel dependency file (*.d.host) for tops target
+  // for example, abc.d -> abc.d.2282B80C.host
+  const int CUIDLEN = 9;
+  llvm::StringRef SubStr = ".host";
+  SmallString<128> OutputFileS(HostDepFileName);
+  size_t Pos = OutputFileS.find(SubStr);
+  // for tops target, trim .host in dep file
+  if (Pos != llvm::StringRef::npos)
+// abc.d.2282B80C.host -> abc.d
+return OutputFileS.substr(0, Pos - CUIDLEN);
+  else
+return "";  
+}
+
+static std::set
+TryMergeDependencyFile(std::vector &KD,
+   std::vector &HD,
+   std::string &KDFN) {
+if (HD.empty() && KD.empty())
+  // both kernel and host dep file is empty
+  return;
+
+// Write merged dep file
+llvm::raw_fd_ostream DF(KDFN, EC, llvm::sys::fs::OF_Text);
+if (EC) {
+  Diags.Report(diag::err_fe_error_opening) << KDFN << EC.message();
+  return;
+}
+if (HD.empty())
+  for (const auto &DL : KD)
+DF << DL << "\n";
+else if (KD.empty())
+  for (const auto &DL : HD)
+DF << DL << "\n";
+else {
+  if (KD.front() != HD.front())
+Diags.Report(diag::err_fe_error_opening

[clang] [Feature]: merge host and kernel dependencies for heterogeneous compilation (PR #119513)

2025-03-05 Thread via cfe-commits

https://github.com/zhouronghua updated 
https://github.com/llvm/llvm-project/pull/119513

>From fce925f908d0d2603927509ed2d78725e47ba2c7 Mon Sep 17 00:00:00 2001
From: "ronghua.zhou" 
Date: Fri, 14 Feb 2025 01:04:51 +
Subject: [PATCH] [Feature]: support for the BC library file into the compile
 dependencies

---
 clang/lib/Driver/ToolChains/Clang.cpp   |  19 +++-
 clang/lib/Frontend/CompilerInstance.cpp |  10 +-
 clang/lib/Frontend/DependencyFile.cpp   | 116 ++--
 3 files changed, 135 insertions(+), 10 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 55ec3db0ee994..e27c1fe95af42 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1056,8 +1056,23 @@ void Clang::AddPreprocessingOptions(Compilation &C, 
const JobAction &JA,
 DepFile = getDependencyFileName(Args, Inputs);
 C.addFailureResultFile(DepFile, &JA);
   }
-  CmdArgs.push_back("-dependency-file");
-  CmdArgs.push_back(DepFile);
+  // for host compile, we changed the dep file name to *.d.CUID.host
+  // so it will not overide kernel dep file,
+  // and merge it with *.d (kernel dep) file in DependencyFile.cpp
+  // for example, abc.d -> abc.d.2282B80C.host
+  auto AT = getToolChain().getAuxTriple();
+  if (!AT && std::string(DepFile) != "-") {
+SmallString<128> NewDepFile(DepFile);
+NewDepFile.append(
+"." + llvm::utohexstr(llvm::sys::Process::GetRandomNumber()) +
+".host");
+CmdArgs.push_back("-dependency-file");
+CmdArgs.push_back(Args.MakeArgString(NewDepFile));
+// else keep the original dep file name
+  } else {
+CmdArgs.push_back("-dependency-file");
+CmdArgs.push_back(DepFile);
+  }
 }
 
 bool HasTarget = false;
diff --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index c11c857ea0606..60ac343391e18 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -494,8 +494,14 @@ void 
CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) {
 
   // Handle generating dependencies, if requested.
   const DependencyOutputOptions &DepOpts = getDependencyOutputOpts();
-  if (!DepOpts.OutputFile.empty())
-addDependencyCollector(std::make_shared(DepOpts));
+  if (!DepOpts.OutputFile.empty()) {
+auto DFG = std::make_shared(DepOpts);
+for (auto F : getCodeGenOpts().LinkBitcodeFiles) {
+  DFG->maybeAddDependency(F.Filename, false, false, false, false);
+}
+addDependencyCollector(DFG);
+  }
+
   if (!DepOpts.DOTOutputFile.empty())
 AttachDependencyGraphGen(*PP, DepOpts.DOTOutputFile,
  getHeaderSearchOpts().Sysroot);
diff --git a/clang/lib/Frontend/DependencyFile.cpp 
b/clang/lib/Frontend/DependencyFile.cpp
index 15fa7de35df97..edc54b0f403c5 100644
--- a/clang/lib/Frontend/DependencyFile.cpp
+++ b/clang/lib/Frontend/DependencyFile.cpp
@@ -10,6 +10,9 @@
 //
 
//===--===//
 
+#include 
+#include 
+
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Frontend/DependencyOutputOptions.h"
@@ -343,6 +346,81 @@ static void PrintFilename(raw_ostream &OS, StringRef 
Filename,
   }
 }
 
+static std::vector SplitToLines(llvm::StringRef &Dep) {
+  std::vector Deps;
+
+  for (const auto &line : llvm::split(KernelDepContent, '\n'))
+// Remove empty lines and comment lines
+if (!tmpline.empty() && tmpline[0] != '#')
+  Deps.insert(line);
+
+  return Deps;
+}
+
+static std::string GetKernelDepFileName(std::string &HostDepFileName) {
+
+  // merge host dependency file (*.d.CUID.host)
+  // to kernel dependency file (*.d) for tops target
+  // for example, abc.d -> abc.d.2282B80C.host
+  const int CUIDLEN = 9;
+  llvm::StringRef SubStr = ".host";
+  SmallString<128> OutputFileS(HostDepFileName);
+  size_t Pos = OutputFileS.find(SubStr);
+  // for tops target, trim .CUID.host in dep file name
+  if (Pos != llvm::StringRef::npos)
+// abc.d.2282B80C.host -> abc.d
+return OutputFileS.substr(0, Pos - CUIDLEN);
+  else
+return "";
+}
+
+static void TryMergeDependencyFile(std::vector &KD,
+   std::vector &HD,
+   std::string &KDFN) {
+  // both kernel and host dep file is empty
+  if (HD.empty() && KD.empty())
+return;
+
+  // Write merged dep file
+  llvm::raw_fd_ostream DF(KDFN, EC, llvm::sys::fs::OF_Text);
+  if (EC) {
+Diags.Report(diag::err_fe_error_opening) << KDFN << EC.message();
+return;
+  }
+  // if host dep file is empty, just write kernel dep file
+  if (HD.empty())
+for (const auto &DL : KD)
+  DF << DL << "\n";
+  // if kernel dep file is empty, just write host dep file
+  else if (KD.empty())
+for (const auto &DL : HD)
+ 

[clang] [clang] Emitting a warning if optimizations are enabled with sanitizers (PR #95934)

2025-03-05 Thread via cfe-commits

https://github.com/Ritanya-B-Bharadwaj closed 
https://github.com/llvm/llvm-project/pull/95934
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [RISCV] Add Qualcomm uC Xqcibm (Bit Manipulation) extension (PR #129504)

2025-03-05 Thread via cfe-commits

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


[clang] b4ecebe - [HLSL] [DXIL] Implement the AddUint64 HLSL function and the UAddc DXIL op (#127137)

2025-03-05 Thread via cfe-commits

Author: Deric C.
Date: 2025-03-05T17:04:10-08:00
New Revision: b4ecebe745ddebf30449435203deeb6463ecf9f0

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

LOG: [HLSL] [DXIL] Implement the AddUint64 HLSL function and the UAddc DXIL op 
(#127137)

Fixes #99205.

- Implements the HLSL intrinsic `AddUint64` used to perform unsigned
64-bit integer addition by using pairs of unsigned 32-bit integers
instead of native 64-bit types
- The LLVM intrinsic `uadd_with_overflow` is used in the implementation
of `AddUint64` in `CGBuiltin.cpp`
- The DXIL op `UAddc` was defined in `DXIL.td`, and a lowering of the
LLVM intrinsic `uadd_with_overflow` to the `UAddc` DXIL op was
implemented in `DXILOpLowering.cpp`

Notes:
- `__builtin_addc` was not able to be used to implement `AddUint64` in
`hlsl_intrinsics.h` because its `CarryOut` argument is a pointer, and
pointers are not supported in HLSL
- A lowering of the LLVM intrinsic `uadd_with_overflow` to SPIR-V
[already
exists](https://github.com/llvm/llvm-project/blob/main/llvm/test/CodeGen/SPIRV/llvm-intrinsics/uadd.with.overflow.ll)
- When lowering the LLVM intrinsic `uadd_with_overflow` to the `UAddc`
DXIL op, the anonymous struct type `{ i32, i1 }` is replaced with a
named struct type `%dx.types.i32c`. This aspect of the implementation
may be changed when issue #113192 gets addressed
- Fixes issues mentioned in the comments on the original PR #125319

-

Co-authored-by: Finn Plummer <50529406+inbe...@users.noreply.github.com>
Co-authored-by: Farzon Lotfi 
Co-authored-by: Chris B 
Co-authored-by: Justin Bogner 

Added: 
clang/test/CodeGenHLSL/builtins/AddUint64.hlsl
clang/test/SemaHLSL/BuiltIns/AddUint64-errors.hlsl
llvm/test/CodeGen/DirectX/UAddc.ll
llvm/test/CodeGen/DirectX/UAddc_errors.ll
llvm/test/CodeGen/SPIRV/hlsl-intrinsics/AddUint64.ll

Modified: 
clang/include/clang/Basic/Builtins.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h
clang/lib/Sema/SemaHLSL.cpp
llvm/lib/Target/DirectX/DXIL.td
llvm/lib/Target/DirectX/DXILOpBuilder.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index f7027331cd6c5..2268df70927a7 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4765,6 +4765,12 @@ def GetDeviceSideMangledName : LangBuiltin<"CUDA_LANG"> {
 }
 
 // HLSL
+def HLSLAddUint64: LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_adduint64"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "void(...)";
+}
+
 def HLSLResourceGetPointer : LangBuiltin<"HLSL_LANG"> {
   let Spellings = ["__builtin_hlsl_resource_getpointer"];
   let Attributes = [NoThrow];

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index ed2da2b355e11..5e5902cdf0cd7 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10709,6 +10709,11 @@ def err_vector_incorrect_num_elements : Error<
   "%select{too many|too few}0 elements in vector 
%select{initialization|operand}3 (expected %1 elements, have %2)">;
 def err_altivec_empty_initializer : Error<"expected initializer">;
 
+def err_vector_incorrect_bit_count : Error<
+  "incorrect number of bits in vector operand (expected %select{|a multiple 
of}0 %1 bits, have %2)">;
+def err_integer_incorrect_bit_count : Error<
+  "incorrect number of bits in integer (expected %0 bits, have %1)">;
+
 def err_invalid_neon_type_code : Error<
   "incompatible constant for this __builtin_neon function">;
 def err_argument_invalid_range : Error<

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index ab8f19b25fa66..20b793c06 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -19470,6 +19470,62 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
 return nullptr;
 
   switch (BuiltinID) {
+  case Builtin::BI__builtin_hlsl_adduint64: {
+Value *OpA = EmitScalarExpr(E->getArg(0));
+Value *OpB = EmitScalarExpr(E->getArg(1));
+QualType Arg0Ty = E->getArg(0)->getType();
+uint64_t NumElements = Arg0Ty->castAs()->getNumElements();
+assert(Arg0Ty == E->getArg(1)->getType() &&
+   "AddUint64 operand types must match");
+assert(Arg0Ty->hasIntegerRepresentation() &&
+   "AddUint64 operands must have an integer representation");
+assert((NumElements == 2 || NumElements == 4) &&
+   "AddUint64 operands must have 2 or 4 elements");
+
+llvm::Value *LowA;
+llvm::Value *HighA;
+llvm::Value *LowB;
+llvm::Value *HighB;
+
+// Obta

[clang] [Clang] [Sema] Allow non-local/non-variable declarations in for loop (PR #129737)

2025-03-05 Thread via cfe-commits

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


[clang] c-index-test: fix buffer overflow (PR #129922)

2025-03-05 Thread Matt Arsenault via cfe-commits

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


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


[clang] [HLSL] add extra scalar vector overloads for clamp (PR #129939)

2025-03-05 Thread Sarah Spall via cfe-commits


@@ -35,25 +35,48 @@ namespace hlsl {
 #define _HLSL_16BIT_AVAILABILITY_STAGE(environment, version, stage)
 #endif
 
-#define GEN_VEC_SCALAR_OVERLOADS(FUNC_NAME, BASE_TYPE, AVAIL)  
\
-  GEN_BOTH_OVERLOADS(FUNC_NAME, BASE_TYPE, BASE_TYPE##2, AVAIL)
\
-  GEN_BOTH_OVERLOADS(FUNC_NAME, BASE_TYPE, BASE_TYPE##3, AVAIL)
\
-  GEN_BOTH_OVERLOADS(FUNC_NAME, BASE_TYPE, BASE_TYPE##4, AVAIL)
-
-#define GEN_BOTH_OVERLOADS(FUNC_NAME, BASE_TYPE, VECTOR_TYPE, AVAIL)   
\
-  IF_TRUE_##AVAIL( 
\
-  _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)) constexpr VECTOR_TYPE
\
-  FUNC_NAME(VECTOR_TYPE p0, BASE_TYPE p1) {
\
-return __builtin_elementwise_##FUNC_NAME(p0, (VECTOR_TYPE)p1); 
\
+#define _HLSL_CAT(a, b) a##b
+#define _HLSL_VEC_SCALAR_OVERLOADS(NAME, BASE_T, AVAIL)
\
+  _HLSL_ALL_OVERLOADS(NAME, BASE_T, AVAIL, _HLSL_CAT(_HLSL_NUM_ARGS_, NAME))
+
+#define _HLSL_ALL_OVERLOADS(NAME, BASE_T, AVAIL, NUM_ARGS) 
\
+  _HLSL_CAT(_HLSL_BOTH_OVERLOADS_, NUM_ARGS)   
\
+  (NAME, BASE_T, _HLSL_CAT(BASE_T, 2), AVAIL)  
\
+  _HLSL_CAT(_HLSL_BOTH_OVERLOADS_, NUM_ARGS)(NAME, BASE_T, 
\
+ _HLSL_CAT(BASE_T, 3), AVAIL)  
\
+  _HLSL_CAT(_HLSL_BOTH_OVERLOADS_, 
\
+NUM_ARGS)(NAME, BASE_T, _HLSL_CAT(BASE_T, 4), AVAIL)
+
+#define _HLSL_BOTH_OVERLOADS_2(NAME, BASE_T, VECTOR_T, AVAIL)  
\
+  _HLSL_CAT(_HLSL_IF_TRUE_, AVAIL) 
\
+  (_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)) constexpr VECTOR_T NAME(
\
+  VECTOR_T p0, BASE_T p1) {
\
+return _HLSL_CAT(__builtin_elementwise_, NAME)(p0, (VECTOR_T)p1);  
\
   }
\
-  IF_TRUE_##AVAIL( 
\
-  _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)) constexpr VECTOR_TYPE
\
-  FUNC_NAME(BASE_TYPE p0, VECTOR_TYPE p1) {
\
-return __builtin_elementwise_##FUNC_NAME((VECTOR_TYPE)p0, p1); 
\
+  _HLSL_CAT(_HLSL_IF_TRUE_, AVAIL) 
\
+  (_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)) constexpr VECTOR_T NAME(
\
+  BASE_T p0, VECTOR_T p1) {
\
+return _HLSL_CAT(__builtin_elementwise_, NAME)((VECTOR_T)p0, p1);  
\
   }
 
-#define IF_TRUE_0(EXPR)
-#define IF_TRUE_1(EXPR) EXPR
+#define _HLSL_BOTH_OVERLOADS_3(NAME, BASE_T, VECTOR_T, AVAIL)  
\
+  _HLSL_CAT(_HLSL_IF_TRUE_, AVAIL) 
\
+  (_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)) constexpr VECTOR_T NAME(
\
+  VECTOR_T p0, VECTOR_T p1, BASE_T p2) {   
\
+return _HLSL_CAT(__builtin_hlsl_elementwise_, NAME)(p0, p1, (VECTOR_T)p2); 
\
+  }
\
+  _HLSL_CAT(_HLSL_IF_TRUE_, AVAIL) 
\
+  (_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)) constexpr VECTOR_T NAME(
\
+  VECTOR_T p0, BASE_T p1, VECTOR_T p2) {   
\
+return _HLSL_CAT(__builtin_hlsl_elementwise_, NAME)(p0, (VECTOR_T)p1, p2); 
\

spall wrote:

> Also, a thought: Would we also need to do further possibilities such as if 
> arg 1 and 3 are the base type, or 2 and 3? Or do we only want overloads when 
> exactly one argument is the base type?

Yes to the last question. There should already be an overload, for clamp and 
min and max, where args 2 and 3 are the base type. 

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


[clang] [llvm] [RISCV] QCI Interrupt Support (PR #129957)

2025-03-05 Thread Craig Topper via cfe-commits


@@ -2116,6 +2214,11 @@ bool RISCVFrameLowering::canUseAsEpilogue(const 
MachineBasicBlock &MBB) const {
   MachineBasicBlock *TmpMBB = const_cast(&MBB);
   const auto *RVFI = MF->getInfo();
 
+  // Qe do not want QC.C.MILEAVERET to be subject to shrink-wrapping - it must

topperc wrote:

"Qe" -> "We"?

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


[clang] [CIR] Upstream emitAndUpdateRetAlloca (PR #129933)

2025-03-05 Thread David Olsen via cfe-commits

dkolsen-pgi wrote:

I have mixed feelings about this change.  It mostly overlaps with what I am 
working on, which is class `LexicalScope`, which has a bunch of the code for 
handling the return value.  I think I would prefer that this PR be dropped, as 
the changes will be part of the PR I am working on.


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


[clang] [Feature]: merge host and kernel dependencies for heterogeneous compilation (PR #119513)

2025-03-05 Thread via cfe-commits


@@ -350,13 +353,105 @@ void 
DependencyFileGenerator::outputDependencyFile(DiagnosticsEngine &Diags) {
   }
 
   std::error_code EC;
-  llvm::raw_fd_ostream OS(OutputFile, EC, llvm::sys::fs::OF_TextWithCRLF);
-  if (EC) {
-Diags.Report(diag::err_fe_error_opening) << OutputFile << EC.message();
-return;
-  }
 
-  outputDependencyFile(OS);
+  // merge host dependency file (*.d.host)
+  // to kernel dependency file (*.d.host) for tops target
+  llvm::StringRef SubStr = ".host";
+  SmallString<128> OutputFileS(OutputFile);
+  size_t Pos = OutputFileS.find(SubStr);
+  // for tops target, trim .host in dep file
+  if (Pos != llvm::StringRef::npos) {
+auto ndf = OutputFileS.substr(0, Pos);
+// dependencies is a set to auto merge duplicate dependencies
+std::set dependencies;
+
+std::string line;
+std::string tmpline;
+std::string KernelStartLine;
+std::string HostStartLine;
+std::string Endline;
+
+// Read kernel dep file
+llvm::ErrorOr> KernelDepFile =
+llvm::MemoryBuffer::getFile(ndf.str());
+if (KernelDepFile) {
+  llvm::StringRef KernelDepContent = KernelDepFile.get()->getBuffer();
+  for (const auto &tmpline : llvm::split(KernelDepContent, '\n')) {
+// Remove empty lines and comment lines
+if (!tmpline.empty() && tmpline[0] != '#') {
+  line = tmpline.str();
+  if (KernelStartLine.empty()) {
+KernelStartLine = line;
+  } else {
+dependencies.insert(line);
+  }
+}
+  }
+  // Process Endline
+  Endline = line;
+  dependencies.erase(Endline); // Remove Endline from dependencies
+}
+
+// Read host dep file
+std::string HostDep;
+llvm::raw_string_ostream OSS(HostDep);
+outputDependencyFile(OSS);
+if (!HostDep.empty()) {
+  for (const auto &tmpline : llvm::split(HostDep, '\n')) {
+// Remove empty lines and comment lines
+if (!tmpline.empty() && tmpline[0] != '#') {
+  line = tmpline.str();
+  if (HostStartLine.empty()) {
+HostStartLine = line;
+// if KernelStartLine is not empty
+if (!KernelStartLine.empty() && HostStartLine != KernelStartLine) {
+  Diags.Report(diag::err_fe_error_opening)
+  << OutputFile << "host dep file is not match kernel dep 
file";
+  return;
+}
+  } else {
+dependencies.insert(line);
+  }
+}
+  }
+  // Process Endline
+  dependencies.erase(line);
+  if (!Endline.empty()) {
+if (line != Endline) {
+  dependencies.insert(line + " \\");
+}
+  } else {
+Endline = line;
+  }
+}
+
+// Write merged dep file
+llvm::raw_fd_ostream DepFile(ndf.str(), EC, llvm::sys::fs::OF_Text);
+if (EC) {
+  Diags.Report(diag::err_fe_error_opening) << ndf.str() << EC.message();
+  return;
+}
+// Write HostStartLine, KernelStartLine maybe is empty.
+if (!HostStartLine.empty()) {
+  DepFile << HostStartLine << "\n";
+}
+for (const auto &dep : dependencies) {
+  DepFile << dep << "\n";
+}
+// Write Endline
+if (!Endline.empty()) {
+  DepFile << Endline << "\n";
+}
+  } else {
+
+llvm::raw_fd_ostream OS(OutputFile, EC, llvm::sys::fs::OF_Text);
+if (EC) {
+  Diags.Report(diag::err_fe_error_opening) << OutputFile << EC.message();
+  return;
+}
+
+outputDependencyFile(OS);

zhouronghua wrote:

This DEP file was also retained before.

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


[clang] [NFC][c-index-test] factor data len out (PR #129971)

2025-03-05 Thread Jinsong Ji via cfe-commits

https://github.com/jsji updated https://github.com/llvm/llvm-project/pull/129971

>From 801d92357366d95bc5bd044125eefc25862b6fee Mon Sep 17 00:00:00 2001
From: Jinsong Ji 
Date: Wed, 5 Mar 2025 17:54:48 -0800
Subject: [PATCH 1/2] [NFC][c-index-test] factor data len out

---
 clang/tools/c-index-test/c-index-test.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/clang/tools/c-index-test/c-index-test.c 
b/clang/tools/c-index-test/c-index-test.c
index 50f32c0a20e5a..1ad2e44aae3f7 100644
--- a/clang/tools/c-index-test/c-index-test.c
+++ b/clang/tools/c-index-test/c-index-test.c
@@ -3554,13 +3554,11 @@ static CXIdxClientContainer 
makeClientContainer(CXClientData *client_data,
 
   clang_indexLoc_getFileLocation(loc, &file, 0, &line, &column, 0);
 
-  len = sizeof(IndexDataStringList) + strlen(name) + digitCount(line) +
-digitCount(column) + 3;
-  node = (IndexDataStringList *)malloc(len);
+  datalen = strlen(name) + digitCount(line) + digitCount(column) + 3;
+  node = (IndexDataStringList *)malloc(len + sizeof(IndexDataStringList));
   assert(node);
   newStr = node->data;
-  snprintf(newStr, len - sizeof(IndexDataStringList), "%s:%d:%d", name, line,
-   column);
+  snprintf(newStr, datalen, "%s:%d:%d", name, line, column);
 
   /* Remember string so it can be freed later. */
   index_data = (IndexData *)client_data;

>From b0e77d2a6ebe51bf0f35524c9afb337c65881fc9 Mon Sep 17 00:00:00 2001
From: Jinsong Ji 
Date: Wed, 5 Mar 2025 18:00:25 -0800
Subject: [PATCH 2/2] fix

---
 clang/tools/c-index-test/c-index-test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/tools/c-index-test/c-index-test.c 
b/clang/tools/c-index-test/c-index-test.c
index 1ad2e44aae3f7..d6021036d11ef 100644
--- a/clang/tools/c-index-test/c-index-test.c
+++ b/clang/tools/c-index-test/c-index-test.c
@@ -3546,7 +3546,7 @@ static CXIdxClientContainer 
makeClientContainer(CXClientData *client_data,
   char *newStr;
   CXIdxClientFile file;
   unsigned line, column;
-  size_t len;
+  size_t datalen;
 
   name = info->name;
   if (!name)

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


[clang] [Feature]: merge host and kernel dependencies for heterogeneous compilation (PR #119513)

2025-03-05 Thread via cfe-commits


@@ -1056,8 +1056,20 @@ void Clang::AddPreprocessingOptions(Compilation &C, 
const JobAction &JA,
 DepFile = getDependencyFileName(Args, Inputs);
 C.addFailureResultFile(DepFile, &JA);
   }
-  CmdArgs.push_back("-dependency-file");
-  CmdArgs.push_back(DepFile);
+  // for host compile, if OPT_MMMD is on, default to create *.d.host file
+  // and merge it with *.d (kernel dep) file in DependencyFile.cpp
+  Arg *ArgMMD = Args.getLastArg(options::OPT_MMMD);
+  auto at = getToolChain().getAuxTriple();

zhouronghua wrote:

if delete MMMD option, this change is no needed anymore.

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


[clang] [Feature]: merge host and kernel dependencies for heterogeneous compilation (PR #119513)

2025-03-05 Thread via cfe-commits


@@ -350,13 +353,105 @@ void 
DependencyFileGenerator::outputDependencyFile(DiagnosticsEngine &Diags) {
   }
 
   std::error_code EC;
-  llvm::raw_fd_ostream OS(OutputFile, EC, llvm::sys::fs::OF_TextWithCRLF);
-  if (EC) {
-Diags.Report(diag::err_fe_error_opening) << OutputFile << EC.message();
-return;
-  }
 
-  outputDependencyFile(OS);
+  // merge host dependency file (*.d.host)
+  // to kernel dependency file (*.d.host) for tops target
+  llvm::StringRef SubStr = ".host";
+  SmallString<128> OutputFileS(OutputFile);
+  size_t Pos = OutputFileS.find(SubStr);
+  // for tops target, trim .host in dep file
+  if (Pos != llvm::StringRef::npos) {
+auto ndf = OutputFileS.substr(0, Pos);
+// dependencies is a set to auto merge duplicate dependencies
+std::set dependencies;
+
+std::string line;
+std::string tmpline;
+std::string KernelStartLine;
+std::string HostStartLine;
+std::string Endline;
+
+// Read kernel dep file
+llvm::ErrorOr> KernelDepFile =
+llvm::MemoryBuffer::getFile(ndf.str());
+if (KernelDepFile) {
+  llvm::StringRef KernelDepContent = KernelDepFile.get()->getBuffer();
+  for (const auto &tmpline : llvm::split(KernelDepContent, '\n')) {
+// Remove empty lines and comment lines
+if (!tmpline.empty() && tmpline[0] != '#') {
+  line = tmpline.str();
+  if (KernelStartLine.empty()) {
+KernelStartLine = line;
+  } else {
+dependencies.insert(line);
+  }
+}
+  }
+  // Process Endline
+  Endline = line;
+  dependencies.erase(Endline); // Remove Endline from dependencies
+}
+
+// Read host dep file
+std::string HostDep;
+llvm::raw_string_ostream OSS(HostDep);
+outputDependencyFile(OSS);
+if (!HostDep.empty()) {
+  for (const auto &tmpline : llvm::split(HostDep, '\n')) {
+// Remove empty lines and comment lines
+if (!tmpline.empty() && tmpline[0] != '#') {
+  line = tmpline.str();
+  if (HostStartLine.empty()) {
+HostStartLine = line;
+// if KernelStartLine is not empty
+if (!KernelStartLine.empty() && HostStartLine != KernelStartLine) {
+  Diags.Report(diag::err_fe_error_opening)
+  << OutputFile << "host dep file is not match kernel dep 
file";
+  return;
+}
+  } else {
+dependencies.insert(line);
+  }
+}
+  }
+  // Process Endline
+  dependencies.erase(line);
+  if (!Endline.empty()) {
+if (line != Endline) {
+  dependencies.insert(line + " \\");
+}
+  } else {

zhouronghua wrote:

Okay, I'll update it and keep the style consistent.

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


[clang] [Feature]: merge host and kernel dependencies for heterogeneous compilation (PR #119513)

2025-03-05 Thread via cfe-commits


@@ -350,13 +353,105 @@ void 
DependencyFileGenerator::outputDependencyFile(DiagnosticsEngine &Diags) {
   }
 
   std::error_code EC;
-  llvm::raw_fd_ostream OS(OutputFile, EC, llvm::sys::fs::OF_TextWithCRLF);
-  if (EC) {
-Diags.Report(diag::err_fe_error_opening) << OutputFile << EC.message();
-return;
-  }
 
-  outputDependencyFile(OS);
+  // merge host dependency file (*.d.host)
+  // to kernel dependency file (*.d.host) for tops target
+  llvm::StringRef SubStr = ".host";
+  SmallString<128> OutputFileS(OutputFile);
+  size_t Pos = OutputFileS.find(SubStr);
+  // for tops target, trim .host in dep file
+  if (Pos != llvm::StringRef::npos) {
+auto ndf = OutputFileS.substr(0, Pos);

zhouronghua wrote:

I see, i will update it.

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


[clang] [C++20][Modules] Fix incomplete decl chains (PR #129982)

2025-03-05 Thread Michael Park via cfe-commits

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


[clang] [C++20][Modules] Fix incomplete decl chains (PR #129982)

2025-03-05 Thread Michael Park via cfe-commits

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


[clang] [C++20][Modules] Fix incomplete decl chains (PR #129982)

2025-03-05 Thread Michael Park via cfe-commits


@@ -9180,6 +9180,12 @@ bool Sema::hasAcceptableDefinition(NamedDecl *D, 
NamedDecl **Suggested,
   if (!getLangOpts().Modules && !getLangOpts().ModulesLocalVisibility)
 return true;
 
+  // The external source may have additional definitions of this entity that 
are
+  // visible, so complete the redeclaration chain now.
+  if (auto *Source = Context.getExternalSource()) {
+Source->CompleteRedeclChain(D);
+  }

mpark wrote:

Yes, calling `redecls` or `getMostRecentDecl` (similar to 
[CXXRecordDecl::dataPtr](https://github.com/llvm/llvm-project/blob/e4c3d258b7a1f335cfd3a90bcf3d28ea220c999d/clang/include/clang/AST/DeclCXX.h#L457-L461)
 here would work as well. The reason I used this "pattern" here is because of 
[this 
code](https://github.com/llvm/llvm-project/blob/d6dbfd6f01710b8fed2303e66f60903efd2283f2/clang/lib/Sema/SemaType.cpp#L9257-L9262)
 at the end of the same function.

I'm very much open to refining the solution. I wanted to submit this PR now 
because the unit-test-level repro was something we were missing from #126973 

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


[clang] [C++20][Modules] Fix incomplete decl chains (PR #129982)

2025-03-05 Thread Chuanqi Xu via cfe-commits


@@ -10178,12 +10178,12 @@ void ASTReader::visitTopLevelModuleMaps(
 }
 
 void ASTReader::finishPendingActions() {
-  while (
-  !PendingIdentifierInfos.empty() || !PendingDeducedFunctionTypes.empty() 
||
-  !PendingDeducedVarTypes.empty() || !PendingIncompleteDeclChains.empty() 
||
-  !PendingDeclChains.empty() || !PendingMacroIDs.empty() ||
-  !PendingDeclContextInfos.empty() || !PendingUpdateRecords.empty() ||
-  !PendingObjCExtensionIvarRedeclarations.empty()) {
+  while (!PendingIdentifierInfos.empty() ||
+ !PendingDeducedFunctionTypes.empty() ||
+ !PendingDeducedVarTypes.empty() || !PendingDeclChains.empty() ||
+ !PendingMacroIDs.empty() || !PendingDeclContextInfos.empty() ||
+ !PendingUpdateRecords.empty() ||
+ !PendingObjCExtensionIvarRedeclarations.empty()) {

ChuanqiXu9 wrote:

my bad, my reading misses PendingIncompleteDeclChains somehow. Sorry.

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


[clang] a6ccda2 - [clang-format][NFC] Use better names for a couple of data members

2025-03-05 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2025-03-05T21:45:01-08:00
New Revision: a6ccda28f7569c1a03620d7520de7cfadc11f4a5

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

LOG: [clang-format][NFC] Use better names for a couple of data members

Added: 


Modified: 
clang/lib/Format/ContinuationIndenter.cpp
clang/lib/Format/FormatToken.h
clang/lib/Format/UnwrappedLineParser.cpp
clang/lib/Format/UnwrappedLineParser.h

Removed: 




diff  --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 4cb24dbca5ad0..1969f4297b211 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -629,7 +629,7 @@ bool ContinuationIndenter::mustBreak(const LineState 
&State) {
   !Style.isJavaScript() && Previous.isNot(tok::kw_template) &&
   CurrentState.BreakBeforeParameter) {
 for (const auto *Tok = &Previous; Tok; Tok = Tok->Previous)
-  if (Tok->FirstAfterPPDirectiveLine || Tok->is(TT_LineComment))
+  if (Tok->FirstAfterPPLine || Tok->is(TT_LineComment))
 return false;
 
 return true;

diff  --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 2cace7c3f060e..77935e75d4b4c 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -594,8 +594,8 @@ struct FormatToken {
   /// Has "\n\f\n" or "\n\f\r\n" before TokenText.
   bool HasFormFeedBefore = false;
 
-  /// Is the first token after a PPDirective line.
-  bool FirstAfterPPDirectiveLine = false;
+  /// Is the first token after a preprocessor line.
+  bool FirstAfterPPLine = false;
 
   /// Number of optional braces to be inserted after this token:
   ///   -1: a single left brace

diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 2da0432816df7..efb22bcdbe53f 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -119,7 +119,7 @@ class ScopedLineState {
 assert(Parser.Line->Tokens.empty());
 Parser.Line = std::move(PreBlockLine);
 if (Parser.CurrentLines == &Parser.PreprocessorDirectives)
-  Parser.MustBreakBeforeNextToken = true;
+  Parser.AtEndOfPPLine = true;
 Parser.CurrentLines = OriginalLines;
   }
 
@@ -158,8 +158,8 @@ UnwrappedLineParser::UnwrappedLineParser(
 ArrayRef Tokens, UnwrappedLineConsumer &Callback,
 llvm::SpecificBumpPtrAllocator &Allocator,
 IdentifierTable &IdentTable)
-: Line(new UnwrappedLine), MustBreakBeforeNextToken(false),
-  CurrentLines(&Lines), Style(Style), IsCpp(Style.isCpp()),
+: Line(new UnwrappedLine), AtEndOfPPLine(false), CurrentLines(&Lines),
+  Style(Style), IsCpp(Style.isCpp()),
   LangOpts(getFormattingLangOpts(Style)), Keywords(Keywords),
   CommentPragmasRegex(Style.CommentPragmas), Tokens(nullptr),
   Callback(Callback), AllTokens(Tokens), PPBranchLevel(-1),
@@ -180,7 +180,7 @@ void UnwrappedLineParser::reset() {
   Line.reset(new UnwrappedLine);
   CommentsBeforeNextToken.clear();
   FormatTok = nullptr;
-  MustBreakBeforeNextToken = false;
+  AtEndOfPPLine = false;
   IsDecltypeAutoFunction = false;
   PreprocessorDirectives.clear();
   CurrentLines = &Lines;
@@ -5090,12 +5090,12 @@ UnwrappedLineParser::parseMacroCall() {
 
 void UnwrappedLineParser::pushToken(FormatToken *Tok) {
   Line->Tokens.push_back(UnwrappedLineNode(Tok));
-  if (MustBreakBeforeNextToken) {
+  if (AtEndOfPPLine) {
 auto &Tok = *Line->Tokens.back().Tok;
 Tok.MustBreakBefore = true;
 Tok.MustBreakBeforeFinalized = true;
-Tok.FirstAfterPPDirectiveLine = true;
-MustBreakBeforeNextToken = false;
+Tok.FirstAfterPPLine = true;
+AtEndOfPPLine = false;
   }
 }
 

diff  --git a/clang/lib/Format/UnwrappedLineParser.h 
b/clang/lib/Format/UnwrappedLineParser.h
index 08bff2748eb8f..87650c2756cd1 100644
--- a/clang/lib/Format/UnwrappedLineParser.h
+++ b/clang/lib/Format/UnwrappedLineParser.h
@@ -298,8 +298,11 @@ class UnwrappedLineParser {
   // Since the next token might already be in a new unwrapped line, we need to
   // store the comments belonging to that token.
   SmallVector CommentsBeforeNextToken;
+
   FormatToken *FormatTok = nullptr;
-  bool MustBreakBeforeNextToken;
+
+  // Has just finished parsing a preprocessor line.
+  bool AtEndOfPPLine;
 
   // The parsed lines. Only added to through \c CurrentLines.
   SmallVector Lines;



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


[clang] [Clang] Check for uninitialized use in lambda within CXXOperatorCallExpr (PR #129198)

2025-03-05 Thread Yanzuo Liu via cfe-commits

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


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


[clang] [llvm] [RISCV] QCI Interrupt Support (PR #129957)

2025-03-05 Thread Craig Topper via cfe-commits

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

LGTM

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


[clang] [llvm] [RISCV] QCI Interrupt Support (PR #129957)

2025-03-05 Thread Craig Topper via cfe-commits


@@ -1892,9 +1970,23 @@ bool RISCVFrameLowering::spillCalleeSavedRegisters(
   if (MI != MBB.end() && !MI->isDebugInstr())
 DL = MI->getDebugLoc();
 
-  // Emit CM.PUSH with base SPimm & evaluate Push stack
   RISCVMachineFunctionInfo *RVFI = MF->getInfo();
-  if (RVFI->isPushable(*MF)) {
+  if (RVFI->useQCIInterrupt(*MF)) {
+// Emit QC.C.MIENTER(.NEST)
+BuildMI(
+MBB, MI, DL,
+TII.get(RVFI->getInterruptStackKind(*MF) ==
+RISCVMachineFunctionInfo::InterruptStackKind::QCINest
+? RISCV::QC_C_MIENTER_NEST
+: RISCV::QC_C_MIENTER))
+.setMIFlag(MachineInstr::FrameSetup);
+
+for (auto [Reg, _Offset] : FixedCSRFIQCIInterruptMap) {

topperc wrote:

Dropy curly braces

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


[clang] c-index-test: fix buffer overflow (PR #129922)

2025-03-05 Thread Matt Arsenault via cfe-commits


@@ -3555,11 +3555,12 @@ static CXIdxClientContainer 
makeClientContainer(CXClientData *client_data,
   clang_indexLoc_getFileLocation(loc, &file, 0, &line, &column, 0);
 
   len = sizeof(IndexDataStringList) + strlen(name) + digitCount(line) +
-digitCount(column) + 2;
+digitCount(column) + 3;
   node = (IndexDataStringList *)malloc(len);
   assert(node);
   newStr = node->data;
-  snprintf(newStr, len, "%s:%d:%d", name, line, column);
+  snprintf(newStr, len - sizeof(IndexDataStringList), "%s:%d:%d", name, line,

arsenm wrote:

Maybe factor len out of the original part and add to the malloc arg 

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


[clang] C89 doesn't have `math.h` functions (PR #129979)

2025-03-05 Thread Vinay Deshmukh via cfe-commits

https://github.com/vinay-deshmukh updated 
https://github.com/llvm/llvm-project/pull/129979

>From e9c7869550d9fd1eba4d4d42ee644540e6b6d445 Mon Sep 17 00:00:00 2001
From: Vinay Deshmukh <32487576+vinay-deshm...@users.noreply.github.com>
Date: Tue, 4 Mar 2025 22:30:34 -0500
Subject: [PATCH 1/4] add failing test

---
 clang/test/C/drs/c89_with_c99_functions.c | 7 +++
 1 file changed, 7 insertions(+)
 create mode 100644 clang/test/C/drs/c89_with_c99_functions.c

diff --git a/clang/test/C/drs/c89_with_c99_functions.c 
b/clang/test/C/drs/c89_with_c99_functions.c
new file mode 100644
index 0..d848727001562
--- /dev/null
+++ b/clang/test/C/drs/c89_with_c99_functions.c
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -std=c89 -verify %s
+
+// From: https://github.com/llvm/llvm-project/issues/15522#issue-1071059939
+int logf = 5;
+int main() {
+return logf;
+}

>From 966aa6a735722063d7ea9727e36136f4f39c3d88 Mon Sep 17 00:00:00 2001
From: Vinay Deshmukh <32487576+vinay-deshm...@users.noreply.github.com>
Date: Wed, 5 Mar 2025 22:09:02 -0500
Subject: [PATCH 2/4] Update test to `expect-no-diagnostics`

---
 clang/test/C/drs/c89_with_c99_functions.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/test/C/drs/c89_with_c99_functions.c 
b/clang/test/C/drs/c89_with_c99_functions.c
index d848727001562..de525313fbba5 100644
--- a/clang/test/C/drs/c89_with_c99_functions.c
+++ b/clang/test/C/drs/c89_with_c99_functions.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c89 -verify %s
+// expected-no-diagnostics
 
 // From: https://github.com/llvm/llvm-project/issues/15522#issue-1071059939
 int logf = 5;

>From 28c58718d76be9c62635cdeffebc9d812b192e50 Mon Sep 17 00:00:00 2001
From: Vinay Deshmukh <32487576+vinay-deshm...@users.noreply.github.com>
Date: Wed, 5 Mar 2025 22:13:50 -0500
Subject: [PATCH 3/4] Add exclusion for C89 / math.h functions

---
 clang/lib/Basic/Builtins.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Basic/Builtins.cpp b/clang/lib/Basic/Builtins.cpp
index e7829a461bbc5..cfcbefdce2a24 100644
--- a/clang/lib/Basic/Builtins.cpp
+++ b/clang/lib/Basic/Builtins.cpp
@@ -14,6 +14,7 @@
 #include "BuiltinTargetFeatures.h"
 #include "clang/Basic/IdentifierTable.h"
 #include "clang/Basic/LangOptions.h"
+#include "clang/Basic/LangStandard.h"
 #include "clang/Basic/TargetInfo.h"
 #include "llvm/ADT/StringRef.h"
 using namespace clang;
@@ -148,7 +149,7 @@ static bool builtinIsSupported(const llvm::StringTable 
&Strings,
   if (!LangOpts.Coroutines && (BuiltinInfo.Langs & COR_LANG))
 return false;
   /* MathBuiltins Unsupported */
-  if (LangOpts.NoMathBuiltin && BuiltinInfo.Header.ID == HeaderDesc::MATH_H)
+  if ((LangOpts.NoMathBuiltin || /*C89*/ LangOpts.LangStd == 
LangStandard::lang_c89)&& BuiltinInfo.Header.ID == HeaderDesc::MATH_H)
 return false;
   /* GnuMode Unsupported */
   if (!LangOpts.GNUMode && (BuiltinInfo.Langs & GNU_LANG))

>From 6e790580b3859cd68ca6ea87c1601979047310ab Mon Sep 17 00:00:00 2001
From: Vinay Deshmukh <32487576+vinay-deshm...@users.noreply.github.com>
Date: Wed, 5 Mar 2025 22:25:07 -0500
Subject: [PATCH 4/4] clang-format

---
 clang/lib/Basic/Builtins.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Basic/Builtins.cpp b/clang/lib/Basic/Builtins.cpp
index cfcbefdce2a24..81f85bb5454e4 100644
--- a/clang/lib/Basic/Builtins.cpp
+++ b/clang/lib/Basic/Builtins.cpp
@@ -149,7 +149,9 @@ static bool builtinIsSupported(const llvm::StringTable 
&Strings,
   if (!LangOpts.Coroutines && (BuiltinInfo.Langs & COR_LANG))
 return false;
   /* MathBuiltins Unsupported */
-  if ((LangOpts.NoMathBuiltin || /*C89*/ LangOpts.LangStd == 
LangStandard::lang_c89)&& BuiltinInfo.Header.ID == HeaderDesc::MATH_H)
+  if ((LangOpts.NoMathBuiltin ||
+   /*C89*/ LangOpts.LangStd == LangStandard::lang_c89) &&
+  BuiltinInfo.Header.ID == HeaderDesc::MATH_H)
 return false;
   /* GnuMode Unsupported */
   if (!LangOpts.GNUMode && (BuiltinInfo.Langs & GNU_LANG))

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


[clang] C89 doesn't have `math.h` functions (PR #129979)

2025-03-05 Thread A. Jiang via cfe-commits

frederick-vs-ja wrote:

> Essentially all of math.h doesn't exist until `C99`: 
> https://en.cppreference.com/w/c/numeric/math/log

You seemed to misread the page. `logf` and `logl` exist since C99, while `log` 
exists since C89.

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


[clang] [NFC][c-index-test] factor data len out (PR #129971)

2025-03-05 Thread Jinsong Ji via cfe-commits

https://github.com/jsji updated https://github.com/llvm/llvm-project/pull/129971

>From 801d92357366d95bc5bd044125eefc25862b6fee Mon Sep 17 00:00:00 2001
From: Jinsong Ji 
Date: Wed, 5 Mar 2025 17:54:48 -0800
Subject: [PATCH 1/3] [NFC][c-index-test] factor data len out

---
 clang/tools/c-index-test/c-index-test.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/clang/tools/c-index-test/c-index-test.c 
b/clang/tools/c-index-test/c-index-test.c
index 50f32c0a20e5a..1ad2e44aae3f7 100644
--- a/clang/tools/c-index-test/c-index-test.c
+++ b/clang/tools/c-index-test/c-index-test.c
@@ -3554,13 +3554,11 @@ static CXIdxClientContainer 
makeClientContainer(CXClientData *client_data,
 
   clang_indexLoc_getFileLocation(loc, &file, 0, &line, &column, 0);
 
-  len = sizeof(IndexDataStringList) + strlen(name) + digitCount(line) +
-digitCount(column) + 3;
-  node = (IndexDataStringList *)malloc(len);
+  datalen = strlen(name) + digitCount(line) + digitCount(column) + 3;
+  node = (IndexDataStringList *)malloc(len + sizeof(IndexDataStringList));
   assert(node);
   newStr = node->data;
-  snprintf(newStr, len - sizeof(IndexDataStringList), "%s:%d:%d", name, line,
-   column);
+  snprintf(newStr, datalen, "%s:%d:%d", name, line, column);
 
   /* Remember string so it can be freed later. */
   index_data = (IndexData *)client_data;

>From b0e77d2a6ebe51bf0f35524c9afb337c65881fc9 Mon Sep 17 00:00:00 2001
From: Jinsong Ji 
Date: Wed, 5 Mar 2025 18:00:25 -0800
Subject: [PATCH 2/3] fix

---
 clang/tools/c-index-test/c-index-test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/tools/c-index-test/c-index-test.c 
b/clang/tools/c-index-test/c-index-test.c
index 1ad2e44aae3f7..d6021036d11ef 100644
--- a/clang/tools/c-index-test/c-index-test.c
+++ b/clang/tools/c-index-test/c-index-test.c
@@ -3546,7 +3546,7 @@ static CXIdxClientContainer 
makeClientContainer(CXClientData *client_data,
   char *newStr;
   CXIdxClientFile file;
   unsigned line, column;
-  size_t len;
+  size_t datalen;
 
   name = info->name;
   if (!name)

>From b48ada578b80a48b2b07e4cdaec5eb39fc950ee0 Mon Sep 17 00:00:00 2001
From: Jinsong Ji 
Date: Wed, 5 Mar 2025 19:30:21 -0800
Subject: [PATCH 3/3] fix

---
 clang/tools/c-index-test/c-index-test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/tools/c-index-test/c-index-test.c 
b/clang/tools/c-index-test/c-index-test.c
index d6021036d11ef..7711df3fd9209 100644
--- a/clang/tools/c-index-test/c-index-test.c
+++ b/clang/tools/c-index-test/c-index-test.c
@@ -3555,7 +3555,7 @@ static CXIdxClientContainer 
makeClientContainer(CXClientData *client_data,
   clang_indexLoc_getFileLocation(loc, &file, 0, &line, &column, 0);
 
   datalen = strlen(name) + digitCount(line) + digitCount(column) + 3;
-  node = (IndexDataStringList *)malloc(len + sizeof(IndexDataStringList));
+  node = (IndexDataStringList *)malloc(datalen + sizeof(IndexDataStringList));
   assert(node);
   newStr = node->data;
   snprintf(newStr, datalen, "%s:%d:%d", name, line, column);

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


[clang] C89 doesn't have `math.h` functions (PR #129979)

2025-03-05 Thread Vinay Deshmukh via cfe-commits

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


[clang] [NFC][c-index-test] factor data len out (PR #129971)

2025-03-05 Thread Matt Arsenault via cfe-commits

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


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


[clang] 4b454af - Convert unreachable return statement into llvm_unreachable (#129627)

2025-03-05 Thread via cfe-commits

Author: Shafik Yaghmour
Date: 2025-03-05T16:59:44-08:00
New Revision: 4b454afc45cdd69ad7d8d6bdba785b00bda7808c

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

LOG: Convert unreachable return statement into llvm_unreachable (#129627)

Static analysis flags the final return statement in `ReadExtensionBlock`
as unreachable and indeed it is since there is no way to exit the
`while(true)` loop besides a *return statement*.

So I am converting it into a `llvm_unreachable` to explicitly document
this.

Added: 


Modified: 
clang/lib/Serialization/ASTReader.cpp

Removed: 




diff  --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index ea4b233a6c573..ca09c3d79d941 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -5329,7 +5329,7 @@ llvm::Error ASTReader::ReadExtensionBlock(ModuleFile &F) {
 }
   }
 
-  return llvm::Error::success();
+  llvm_unreachable("ReadExtensionBlock should return from while loop");
 }
 
 void ASTReader::InitializeContext() {



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


[clang] Convert unreachable return statement into llvm_unreachable (PR #129627)

2025-03-05 Thread Shafik Yaghmour via cfe-commits

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


[clang] [clang] Use TargetInfo to decide Mangling for C (PR #129920)

2025-03-05 Thread via cfe-commits

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


[clang] [llvm] [RISCV] QCI Interrupt Support (PR #129957)

2025-03-05 Thread Sam Elliott via cfe-commits


@@ -2116,6 +2214,11 @@ bool RISCVFrameLowering::canUseAsEpilogue(const 
MachineBasicBlock &MBB) const {
   MachineBasicBlock *TmpMBB = const_cast(&MBB);
   const auto *RVFI = MF->getInfo();
 
+  // Qe do not want QC.C.MILEAVERET to be subject to shrink-wrapping - it must

lenary wrote:

Done

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


[clang] 12c5a46 - [Clang] Fix incorrect condition on ballot

2025-03-05 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2025-03-05T19:15:23-06:00
New Revision: 12c5a46c300eedb6cafc68b987abb9c1fa913e96

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

LOG: [Clang] Fix incorrect condition on ballot

Summary:
Somehow these got the `!` dropped and it wasn't tested because the
existing test only used the 32-bit variant.

Added: 


Modified: 
clang/lib/Headers/amdgpuintrin.h
clang/lib/Headers/nvptxintrin.h

Removed: 




diff  --git a/clang/lib/Headers/amdgpuintrin.h 
b/clang/lib/Headers/amdgpuintrin.h
index 6ad8e54f4aadd..15409eacf7716 100644
--- a/clang/lib/Headers/amdgpuintrin.h
+++ b/clang/lib/Headers/amdgpuintrin.h
@@ -187,7 +187,7 @@ __gpu_match_any_u64(uint64_t __lane_mask, uint64_t __x) {
   uint64_t __match_mask = 0;
 
   bool __done = 0;
-  while (__gpu_ballot(__lane_mask, __done)) {
+  while (__gpu_ballot(__lane_mask, !__done)) {
 if (!__done) {
   uint64_t __first = __gpu_read_first_lane_u64(__lane_mask, __x);
   if (__first == __x) {

diff  --git a/clang/lib/Headers/nvptxintrin.h b/clang/lib/Headers/nvptxintrin.h
index 03594dd9bd6cb..7af22baccb511 100644
--- a/clang/lib/Headers/nvptxintrin.h
+++ b/clang/lib/Headers/nvptxintrin.h
@@ -207,7 +207,7 @@ __gpu_match_any_u64(uint64_t __lane_mask, uint64_t __x) {
   uint64_t __match_mask = 0;
 
   bool __done = 0;
-  while (__gpu_ballot(__lane_mask, __done)) {
+  while (__gpu_ballot(__lane_mask, !__done)) {
 if (!__done) {
   uint64_t __first = __gpu_read_first_lane_u64(__lane_mask, __x);
   if (__first == __x) {



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


[clang] [alpha.webkit.UncountedCallArgsChecker] Fix a false negative when a call argument is a local variable. (PR #129974)

2025-03-05 Thread Ryosuke Niwa via cfe-commits

https://github.com/rniwa created 
https://github.com/llvm/llvm-project/pull/129974

isASafeCallArg erroneously returns true when a call argument is a local 
variable regardless of its type. This is incorrect. We should only allow any 
local variable of a safe pointer type.

Fix the bug by moving the logic to check for a function parameter and local 
variable from isASafeCallArg to a lambda in isPtrOriginSafe, and check that the 
local variable is a safe pointer type.

Also fix a bug in isPtrOfType that it was not recognizing 
DeducedTemplateSpecializationType.

>From 1f0d65a410f88adb5e9737d5c78bef1cd4e3b0df Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Wed, 5 Mar 2025 18:06:52 -0800
Subject: [PATCH] [alpha.webkit.UncountedCallArgsChecker] Fix a false negative
 when a call argument is a local variable.

isASafeCallArg erroneously returns true when a call argument is a local 
variable regardless of its type.
This is incorrect. We should only allow any local variable of a safe pointer 
type.

Fix the bug by moving the logic to check for a function parameter and local 
variable from isASafeCallArg
to a lambda in isPtrOriginSafe, and check that the local variable is a safe 
pointer type.

Also fix a bug in isPtrOfType that it was not recognizing 
DeducedTemplateSpecializationType.
---
 .../StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp |  2 +-
 .../Checkers/WebKit/PtrTypesSemantics.cpp   | 17 ++---
 .../WebKit/RawPtrRefCallArgsChecker.cpp |  8 
 .../test/Analysis/Checkers/WebKit/call-args.cpp |  9 -
 4 files changed, 27 insertions(+), 9 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
index dc86c4fcc64b1..73b6afd3642c7 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
@@ -141,7 +141,7 @@ bool isASafeCallArg(const Expr *E) {
   assert(E);
   if (auto *Ref = dyn_cast(E)) {
 if (auto *D = dyn_cast_or_null(Ref->getFoundDecl())) {
-  if (isa(D) || D->isLocalVarDecl())
+  if (isa(D))
 return true;
 }
   }
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 7899b19854806..cbb207bcb9df0 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -162,13 +162,16 @@ static bool isPtrOfType(const clang::QualType T, 
Predicate Pred) {
   type = elaboratedT->desugar();
   continue;
 }
-auto *SpecialT = type->getAs();
-if (!SpecialT)
-  return false;
-auto *Decl = SpecialT->getTemplateName().getAsTemplateDecl();
-if (!Decl)
-  return false;
-return Pred(Decl->getNameAsString());
+if (auto *SpecialT = type->getAs()) {
+  auto *Decl = SpecialT->getTemplateName().getAsTemplateDecl();
+  if (!Decl)
+return false;
+  return Pred(Decl->getNameAsString());
+} else if (auto *DTS = type->getAs()) {
+  auto *Decl = DTS->getTemplateName().getAsTemplateDecl();
+  return Pred(Decl->getNameAsString());
+} else
+  break;
   }
   return false;
 }
diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefCallArgsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefCallArgsChecker.cpp
index d633fbcbd798b..fbb6a06afbdac 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefCallArgsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefCallArgsChecker.cpp
@@ -158,6 +158,14 @@ class RawPtrRefCallArgsChecker
 // foo(NULL)
 return true;
   }
+  if (auto *Ref = dyn_cast(ArgOrigin)) {
+if (auto *D = dyn_cast_or_null(Ref->getFoundDecl())) {
+  if (isa(D))
+return true; // Parameters are transitively safe.
+  if (D->isLocalVarDecl() && isSafePtrType(D->getType()))
+return true;
+}
+  }
   if (isASafeCallArg(ArgOrigin))
 return true;
   if (EFA.isACallToEnsureFn(ArgOrigin))
diff --git a/clang/test/Analysis/Checkers/WebKit/call-args.cpp 
b/clang/test/Analysis/Checkers/WebKit/call-args.cpp
index b4613d5090f29..4fc5a574f9e69 100644
--- a/clang/test/Analysis/Checkers/WebKit/call-args.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/call-args.cpp
@@ -374,7 +374,14 @@ namespace call_with_explicit_temporary_obj {
   }
 }
 
-namespace call_with_explicit_construct {
+namespace call_via_local_var {
+  RefCountable* provide();
+  void bar(RefCountable*);
+  void foo() {
+auto* obj = provide();
+bar(obj);
+// expected-warning@-1{{Call argument is uncounted and unsafe}}
+  }
 }
 
 namespace call_with_adopt_ref {

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


[clang] [llvm] [SYCL][DOC] Add documentation for SYCL compilation flow (PR #129973)

2025-03-05 Thread Arvind Sudarsanam via cfe-commits

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


[clang] [alpha.webkit.UncountedCallArgsChecker] Fix a false negative when a call argument is a local variable. (PR #129974)

2025-03-05 Thread via cfe-commits

llvmbot wrote:




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

Author: Ryosuke Niwa (rniwa)


Changes

isASafeCallArg erroneously returns true when a call argument is a local 
variable regardless of its type. This is incorrect. We should only allow any 
local variable of a safe pointer type.

Fix the bug by moving the logic to check for a function parameter and local 
variable from isASafeCallArg to a lambda in isPtrOriginSafe, and check that the 
local variable is a safe pointer type.

Also fix a bug in isPtrOfType that it was not recognizing 
DeducedTemplateSpecializationType.

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


4 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp (+1-1) 
- (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
(+10-7) 
- (modified) 
clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefCallArgsChecker.cpp (+8) 
- (modified) clang/test/Analysis/Checkers/WebKit/call-args.cpp (+8-1) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
index dc86c4fcc64b1..73b6afd3642c7 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
@@ -141,7 +141,7 @@ bool isASafeCallArg(const Expr *E) {
   assert(E);
   if (auto *Ref = dyn_cast(E)) {
 if (auto *D = dyn_cast_or_null(Ref->getFoundDecl())) {
-  if (isa(D) || D->isLocalVarDecl())
+  if (isa(D))
 return true;
 }
   }
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 7899b19854806..cbb207bcb9df0 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -162,13 +162,16 @@ static bool isPtrOfType(const clang::QualType T, 
Predicate Pred) {
   type = elaboratedT->desugar();
   continue;
 }
-auto *SpecialT = type->getAs();
-if (!SpecialT)
-  return false;
-auto *Decl = SpecialT->getTemplateName().getAsTemplateDecl();
-if (!Decl)
-  return false;
-return Pred(Decl->getNameAsString());
+if (auto *SpecialT = type->getAs()) {
+  auto *Decl = SpecialT->getTemplateName().getAsTemplateDecl();
+  if (!Decl)
+return false;
+  return Pred(Decl->getNameAsString());
+} else if (auto *DTS = type->getAs()) {
+  auto *Decl = DTS->getTemplateName().getAsTemplateDecl();
+  return Pred(Decl->getNameAsString());
+} else
+  break;
   }
   return false;
 }
diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefCallArgsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefCallArgsChecker.cpp
index d633fbcbd798b..fbb6a06afbdac 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefCallArgsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefCallArgsChecker.cpp
@@ -158,6 +158,14 @@ class RawPtrRefCallArgsChecker
 // foo(NULL)
 return true;
   }
+  if (auto *Ref = dyn_cast(ArgOrigin)) {
+if (auto *D = dyn_cast_or_null(Ref->getFoundDecl())) {
+  if (isa(D))
+return true; // Parameters are transitively safe.
+  if (D->isLocalVarDecl() && isSafePtrType(D->getType()))
+return true;
+}
+  }
   if (isASafeCallArg(ArgOrigin))
 return true;
   if (EFA.isACallToEnsureFn(ArgOrigin))
diff --git a/clang/test/Analysis/Checkers/WebKit/call-args.cpp 
b/clang/test/Analysis/Checkers/WebKit/call-args.cpp
index b4613d5090f29..4fc5a574f9e69 100644
--- a/clang/test/Analysis/Checkers/WebKit/call-args.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/call-args.cpp
@@ -374,7 +374,14 @@ namespace call_with_explicit_temporary_obj {
   }
 }
 
-namespace call_with_explicit_construct {
+namespace call_via_local_var {
+  RefCountable* provide();
+  void bar(RefCountable*);
+  void foo() {
+auto* obj = provide();
+bar(obj);
+// expected-warning@-1{{Call argument is uncounted and unsafe}}
+  }
 }
 
 namespace call_with_adopt_ref {

``




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


[clang] [alpha.webkit.UncountedCallArgsChecker] Fix a false negative when a call argument is a local variable. (PR #129974)

2025-03-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Ryosuke Niwa (rniwa)


Changes

isASafeCallArg erroneously returns true when a call argument is a local 
variable regardless of its type. This is incorrect. We should only allow any 
local variable of a safe pointer type.

Fix the bug by moving the logic to check for a function parameter and local 
variable from isASafeCallArg to a lambda in isPtrOriginSafe, and check that the 
local variable is a safe pointer type.

Also fix a bug in isPtrOfType that it was not recognizing 
DeducedTemplateSpecializationType.

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


4 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp (+1-1) 
- (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
(+10-7) 
- (modified) 
clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefCallArgsChecker.cpp (+8) 
- (modified) clang/test/Analysis/Checkers/WebKit/call-args.cpp (+8-1) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
index dc86c4fcc64b1..73b6afd3642c7 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
@@ -141,7 +141,7 @@ bool isASafeCallArg(const Expr *E) {
   assert(E);
   if (auto *Ref = dyn_cast(E)) {
 if (auto *D = dyn_cast_or_null(Ref->getFoundDecl())) {
-  if (isa(D) || D->isLocalVarDecl())
+  if (isa(D))
 return true;
 }
   }
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 7899b19854806..cbb207bcb9df0 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -162,13 +162,16 @@ static bool isPtrOfType(const clang::QualType T, 
Predicate Pred) {
   type = elaboratedT->desugar();
   continue;
 }
-auto *SpecialT = type->getAs();
-if (!SpecialT)
-  return false;
-auto *Decl = SpecialT->getTemplateName().getAsTemplateDecl();
-if (!Decl)
-  return false;
-return Pred(Decl->getNameAsString());
+if (auto *SpecialT = type->getAs()) {
+  auto *Decl = SpecialT->getTemplateName().getAsTemplateDecl();
+  if (!Decl)
+return false;
+  return Pred(Decl->getNameAsString());
+} else if (auto *DTS = type->getAs()) {
+  auto *Decl = DTS->getTemplateName().getAsTemplateDecl();
+  return Pred(Decl->getNameAsString());
+} else
+  break;
   }
   return false;
 }
diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefCallArgsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefCallArgsChecker.cpp
index d633fbcbd798b..fbb6a06afbdac 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefCallArgsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefCallArgsChecker.cpp
@@ -158,6 +158,14 @@ class RawPtrRefCallArgsChecker
 // foo(NULL)
 return true;
   }
+  if (auto *Ref = dyn_cast(ArgOrigin)) {
+if (auto *D = dyn_cast_or_null(Ref->getFoundDecl())) {
+  if (isa(D))
+return true; // Parameters are transitively safe.
+  if (D->isLocalVarDecl() && isSafePtrType(D->getType()))
+return true;
+}
+  }
   if (isASafeCallArg(ArgOrigin))
 return true;
   if (EFA.isACallToEnsureFn(ArgOrigin))
diff --git a/clang/test/Analysis/Checkers/WebKit/call-args.cpp 
b/clang/test/Analysis/Checkers/WebKit/call-args.cpp
index b4613d5090f29..4fc5a574f9e69 100644
--- a/clang/test/Analysis/Checkers/WebKit/call-args.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/call-args.cpp
@@ -374,7 +374,14 @@ namespace call_with_explicit_temporary_obj {
   }
 }
 
-namespace call_with_explicit_construct {
+namespace call_via_local_var {
+  RefCountable* provide();
+  void bar(RefCountable*);
+  void foo() {
+auto* obj = provide();
+bar(obj);
+// expected-warning@-1{{Call argument is uncounted and unsafe}}
+  }
 }
 
 namespace call_with_adopt_ref {

``




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


[libclc] [libclc] Stop installing CLC headers (PR #126908)

2025-03-05 Thread Matt Arsenault via cfe-commits

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


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


[clang] [Feature]: merge host and kernel dependencies for heterogeneous compilation (PR #119513)

2025-03-05 Thread via cfe-commits


@@ -798,6 +798,8 @@ def MD : Flag<["-"], "MD">, Group,
 HelpText<"Write a depfile containing user and system headers">;
 def MMD : Flag<["-"], "MMD">, Group,
 HelpText<"Write a depfile containing user headers">;
+def MMMD : Flag<["-"], "MMMD">, Group,

zhouronghua wrote:

OK, I added the MMMD option primarily to avoid altering the existing user 
habits as much as possible. If everyone agrees that this behavior can be 
enabled by default, then I will remove this option.

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


[clang] [NFC][c-index-test] factor data len out (PR #129971)

2025-03-05 Thread Jinsong Ji via cfe-commits

https://github.com/jsji updated https://github.com/llvm/llvm-project/pull/129971

>From 801d92357366d95bc5bd044125eefc25862b6fee Mon Sep 17 00:00:00 2001
From: Jinsong Ji 
Date: Wed, 5 Mar 2025 17:54:48 -0800
Subject: [PATCH 1/2] [NFC][c-index-test] factor data len out

---
 clang/tools/c-index-test/c-index-test.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/clang/tools/c-index-test/c-index-test.c 
b/clang/tools/c-index-test/c-index-test.c
index 50f32c0a20e5a..1ad2e44aae3f7 100644
--- a/clang/tools/c-index-test/c-index-test.c
+++ b/clang/tools/c-index-test/c-index-test.c
@@ -3554,13 +3554,11 @@ static CXIdxClientContainer 
makeClientContainer(CXClientData *client_data,
 
   clang_indexLoc_getFileLocation(loc, &file, 0, &line, &column, 0);
 
-  len = sizeof(IndexDataStringList) + strlen(name) + digitCount(line) +
-digitCount(column) + 3;
-  node = (IndexDataStringList *)malloc(len);
+  datalen = strlen(name) + digitCount(line) + digitCount(column) + 3;
+  node = (IndexDataStringList *)malloc(len + sizeof(IndexDataStringList));
   assert(node);
   newStr = node->data;
-  snprintf(newStr, len - sizeof(IndexDataStringList), "%s:%d:%d", name, line,
-   column);
+  snprintf(newStr, datalen, "%s:%d:%d", name, line, column);
 
   /* Remember string so it can be freed later. */
   index_data = (IndexData *)client_data;

>From b0e77d2a6ebe51bf0f35524c9afb337c65881fc9 Mon Sep 17 00:00:00 2001
From: Jinsong Ji 
Date: Wed, 5 Mar 2025 18:00:25 -0800
Subject: [PATCH 2/2] fix

---
 clang/tools/c-index-test/c-index-test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/tools/c-index-test/c-index-test.c 
b/clang/tools/c-index-test/c-index-test.c
index 1ad2e44aae3f7..d6021036d11ef 100644
--- a/clang/tools/c-index-test/c-index-test.c
+++ b/clang/tools/c-index-test/c-index-test.c
@@ -3546,7 +3546,7 @@ static CXIdxClientContainer 
makeClientContainer(CXClientData *client_data,
   char *newStr;
   CXIdxClientFile file;
   unsigned line, column;
-  size_t len;
+  size_t datalen;
 
   name = info->name;
   if (!name)

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


[clang] Fix incomplete decl chains (PR #129982)

2025-03-05 Thread Michael Park via cfe-commits

https://github.com/mpark created 
https://github.com/llvm/llvm-project/pull/129982

None

>From 3f883067a2fda4147003de9a53b88e52c33d1280 Mon Sep 17 00:00:00 2001
From: Michael Park 
Date: Tue, 25 Feb 2025 14:33:41 -0800
Subject: [PATCH 1/3] =?UTF-8?q?Reapply=20"[C++20][Modules][Serialization]?=
 =?UTF-8?q?=20Delay=20marking=20pending=20incompl=E2=80=A6=20(#127136)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This reverts commit 912b154f3a3f8c3cebf5cc5731fd8b0749762da5.
---
 clang/lib/Serialization/ASTReader.cpp | 25 ---
 clang/test/Modules/pr121245.cpp   | 93 +++
 2 files changed, 105 insertions(+), 13 deletions(-)
 create mode 100644 clang/test/Modules/pr121245.cpp

diff --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index ca09c3d79d941..17d07f8535346 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -10178,12 +10178,12 @@ void ASTReader::visitTopLevelModuleMaps(
 }
 
 void ASTReader::finishPendingActions() {
-  while (
-  !PendingIdentifierInfos.empty() || !PendingDeducedFunctionTypes.empty() 
||
-  !PendingDeducedVarTypes.empty() || !PendingIncompleteDeclChains.empty() 
||
-  !PendingDeclChains.empty() || !PendingMacroIDs.empty() ||
-  !PendingDeclContextInfos.empty() || !PendingUpdateRecords.empty() ||
-  !PendingObjCExtensionIvarRedeclarations.empty()) {
+  while (!PendingIdentifierInfos.empty() ||
+ !PendingDeducedFunctionTypes.empty() ||
+ !PendingDeducedVarTypes.empty() || !PendingDeclChains.empty() ||
+ !PendingMacroIDs.empty() || !PendingDeclContextInfos.empty() ||
+ !PendingUpdateRecords.empty() ||
+ !PendingObjCExtensionIvarRedeclarations.empty()) {
 // If any identifiers with corresponding top-level declarations have
 // been loaded, load those declarations now.
 using TopLevelDeclsMap =
@@ -10231,13 +10231,6 @@ void ASTReader::finishPendingActions() {
 }
 PendingDeducedVarTypes.clear();
 
-// For each decl chain that we wanted to complete while deserializing, mark
-// it as "still needs to be completed".
-for (unsigned I = 0; I != PendingIncompleteDeclChains.size(); ++I) {
-  markIncompleteDeclChain(PendingIncompleteDeclChains[I]);
-}
-PendingIncompleteDeclChains.clear();
-
 // Load pending declaration chains.
 for (unsigned I = 0; I != PendingDeclChains.size(); ++I)
   loadPendingDeclChain(PendingDeclChains[I].first,
@@ -10475,6 +10468,12 @@ void ASTReader::finishPendingActions() {
   for (auto *ND : PendingMergedDefinitionsToDeduplicate)
 getContext().deduplicateMergedDefinitonsFor(ND);
   PendingMergedDefinitionsToDeduplicate.clear();
+
+  // For each decl chain that we wanted to complete while deserializing, mark
+  // it as "still needs to be completed".
+  for (Decl *D : PendingIncompleteDeclChains)
+markIncompleteDeclChain(D);
+  PendingIncompleteDeclChains.clear();
 }
 
 void ASTReader::diagnoseOdrViolations() {
diff --git a/clang/test/Modules/pr121245.cpp b/clang/test/Modules/pr121245.cpp
new file mode 100644
index 0..0e276ad0e435d
--- /dev/null
+++ b/clang/test/Modules/pr121245.cpp
@@ -0,0 +1,93 @@
+// If this test fails, it should be investigated under Debug builds.
+// Before the PR, this test was encountering an `llvm_unreachable()`.
+
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+// RUN: cd %t
+
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header %t/hu-01.h \
+// RUN:  -fcxx-exceptions -o %t/hu-01.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header %t/hu-02.h \
+// RUN:  -Wno-experimental-header-units -fcxx-exceptions \
+// RUN:  -fmodule-file=%t/hu-01.pcm -o %t/hu-02.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header %t/hu-03.h \
+// RUN:  -Wno-experimental-header-units -fcxx-exceptions \
+// RUN:  -fmodule-file=%t/hu-01.pcm -o %t/hu-03.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header %t/hu-04.h \
+// RUN:  -Wno-experimental-header-units -fcxx-exceptions \
+// RUN:  -fmodule-file=%t/hu-01.pcm -o %t/hu-04.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header %t/hu-05.h \
+// RUN:  -Wno-experimental-header-units -fcxx-exceptions \
+// RUN:  -fmodule-file=%t/hu-03.pcm -fmodule-file=%t/hu-04.pcm \
+// RUN:  -fmodule-file=%t/hu-01.pcm -o %t/hu-05.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-obj %t/main.cpp \
+// RUN:  -Wno-experimental-header-units -fcxx-exceptions \
+// RUN:  -fmodule-file=%t/hu-02.pcm -fmodule-file=%t/hu-05.pcm \
+// RUN:  -fmodule-file=%t/hu-04.pcm -fmodule-file=%t/hu-03.pcm \
+// RUN:  -fmodule-file=%t/hu-01.pcm
+
+//--- hu-01.h
+template 
+struct A {
+  A() {}
+  ~A() {}
+};
+
+template 
+struct EBO : T {
+  EBO() = default;
+};
+
+template 
+struct HT : EBO> {};
+
+//--- hu-02.h
+import "hu-01.h";
+
+inline void f() {
+  HT();
+}
+
+//--- hu-0

[clang] Fix incomplete decl chains (PR #129982)

2025-03-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Michael Park (mpark)


Changes



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


4 Files Affected:

- (modified) clang/lib/Sema/SemaType.cpp (+6) 
- (modified) clang/lib/Serialization/ASTReader.cpp (+12-13) 
- (added) clang/test/Modules/mpark.cpp (+107) 
- (added) clang/test/Modules/pr121245.cpp (+93) 


``diff
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 11943c0b53591..e2002bb410110 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -9180,6 +9180,12 @@ bool Sema::hasAcceptableDefinition(NamedDecl *D, 
NamedDecl **Suggested,
   if (!getLangOpts().Modules && !getLangOpts().ModulesLocalVisibility)
 return true;
 
+  // The external source may have additional definitions of this entity that 
are
+  // visible, so complete the redeclaration chain now.
+  if (auto *Source = Context.getExternalSource()) {
+Source->CompleteRedeclChain(D);
+  }
+
   // If this definition was instantiated from a template, map back to the
   // pattern from which it was instantiated.
   if (isa(D) && cast(D)->isBeingDefined()) {
diff --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index ca09c3d79d941..17d07f8535346 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -10178,12 +10178,12 @@ void ASTReader::visitTopLevelModuleMaps(
 }
 
 void ASTReader::finishPendingActions() {
-  while (
-  !PendingIdentifierInfos.empty() || !PendingDeducedFunctionTypes.empty() 
||
-  !PendingDeducedVarTypes.empty() || !PendingIncompleteDeclChains.empty() 
||
-  !PendingDeclChains.empty() || !PendingMacroIDs.empty() ||
-  !PendingDeclContextInfos.empty() || !PendingUpdateRecords.empty() ||
-  !PendingObjCExtensionIvarRedeclarations.empty()) {
+  while (!PendingIdentifierInfos.empty() ||
+ !PendingDeducedFunctionTypes.empty() ||
+ !PendingDeducedVarTypes.empty() || !PendingDeclChains.empty() ||
+ !PendingMacroIDs.empty() || !PendingDeclContextInfos.empty() ||
+ !PendingUpdateRecords.empty() ||
+ !PendingObjCExtensionIvarRedeclarations.empty()) {
 // If any identifiers with corresponding top-level declarations have
 // been loaded, load those declarations now.
 using TopLevelDeclsMap =
@@ -10231,13 +10231,6 @@ void ASTReader::finishPendingActions() {
 }
 PendingDeducedVarTypes.clear();
 
-// For each decl chain that we wanted to complete while deserializing, mark
-// it as "still needs to be completed".
-for (unsigned I = 0; I != PendingIncompleteDeclChains.size(); ++I) {
-  markIncompleteDeclChain(PendingIncompleteDeclChains[I]);
-}
-PendingIncompleteDeclChains.clear();
-
 // Load pending declaration chains.
 for (unsigned I = 0; I != PendingDeclChains.size(); ++I)
   loadPendingDeclChain(PendingDeclChains[I].first,
@@ -10475,6 +10468,12 @@ void ASTReader::finishPendingActions() {
   for (auto *ND : PendingMergedDefinitionsToDeduplicate)
 getContext().deduplicateMergedDefinitonsFor(ND);
   PendingMergedDefinitionsToDeduplicate.clear();
+
+  // For each decl chain that we wanted to complete while deserializing, mark
+  // it as "still needs to be completed".
+  for (Decl *D : PendingIncompleteDeclChains)
+markIncompleteDeclChain(D);
+  PendingIncompleteDeclChains.clear();
 }
 
 void ASTReader::diagnoseOdrViolations() {
diff --git a/clang/test/Modules/mpark.cpp b/clang/test/Modules/mpark.cpp
new file mode 100644
index 0..d3b45767526f2
--- /dev/null
+++ b/clang/test/Modules/mpark.cpp
@@ -0,0 +1,107 @@
+// If this test fails, it should be investigated under Debug builds.
+// Before the PR, this test was violating an assertion.
+
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -std=c++17 -emit-obj -fmodules \
+// RUN:  -fmodule-map-file=%t/module.modulemap \
+// RUN:  -fmodules-cache-path=%t %t/a.cpp
+
+//--- module.modulemap
+module ebo {
+  header "ebo.h"
+}
+
+module fwd {
+  header "fwd.h"
+}
+
+module s {
+  header "s.h"
+  export *
+}
+
+module mod {
+  header "a.h"
+  header "b.h"
+}
+
+//--- ebo.h
+#pragma once
+
+namespace N { inline namespace __1 {
+
+template 
+struct EBO : T {
+  EBO() = default;
+};
+
+}}
+
+//--- fwd.h
+#pragma once
+
+namespace N { inline namespace __1 {
+
+template 
+struct Empty;
+
+template 
+struct BS;
+
+using S = BS>;
+
+}}
+
+//--- s.h
+#pragma once
+
+#include "fwd.h"
+#include "ebo.h"
+
+namespace N { inline namespace __1 {
+
+template 
+struct Empty {};
+
+template 
+struct BS {
+EBO _;
+void f();
+};
+
+extern template void BS>::f();
+
+}}
+
+//--- b.h
+#pragma once
+
+#include "s.h"
+
+struct B {
+  void f() {
+N::S{}.f();
+  }
+};
+
+//--- a.h
+#pragma once
+
+#include "s.h"
+
+struct A {
+  void f(int) {}
+  void f(const N::S &) {}
+
+  void g();
+};
+
+//--- a.cpp
+#include "a.h"
+
+void A::

[clang] Fix incomplete decl chains (PR #129982)

2025-03-05 Thread Michael Park via cfe-commits

https://github.com/mpark updated 
https://github.com/llvm/llvm-project/pull/129982

>From 3f883067a2fda4147003de9a53b88e52c33d1280 Mon Sep 17 00:00:00 2001
From: Michael Park 
Date: Tue, 25 Feb 2025 14:33:41 -0800
Subject: [PATCH 1/3] =?UTF-8?q?Reapply=20"[C++20][Modules][Serialization]?=
 =?UTF-8?q?=20Delay=20marking=20pending=20incompl=E2=80=A6=20(#127136)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This reverts commit 912b154f3a3f8c3cebf5cc5731fd8b0749762da5.
---
 clang/lib/Serialization/ASTReader.cpp | 25 ---
 clang/test/Modules/pr121245.cpp   | 93 +++
 2 files changed, 105 insertions(+), 13 deletions(-)
 create mode 100644 clang/test/Modules/pr121245.cpp

diff --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index ca09c3d79d941..17d07f8535346 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -10178,12 +10178,12 @@ void ASTReader::visitTopLevelModuleMaps(
 }
 
 void ASTReader::finishPendingActions() {
-  while (
-  !PendingIdentifierInfos.empty() || !PendingDeducedFunctionTypes.empty() 
||
-  !PendingDeducedVarTypes.empty() || !PendingIncompleteDeclChains.empty() 
||
-  !PendingDeclChains.empty() || !PendingMacroIDs.empty() ||
-  !PendingDeclContextInfos.empty() || !PendingUpdateRecords.empty() ||
-  !PendingObjCExtensionIvarRedeclarations.empty()) {
+  while (!PendingIdentifierInfos.empty() ||
+ !PendingDeducedFunctionTypes.empty() ||
+ !PendingDeducedVarTypes.empty() || !PendingDeclChains.empty() ||
+ !PendingMacroIDs.empty() || !PendingDeclContextInfos.empty() ||
+ !PendingUpdateRecords.empty() ||
+ !PendingObjCExtensionIvarRedeclarations.empty()) {
 // If any identifiers with corresponding top-level declarations have
 // been loaded, load those declarations now.
 using TopLevelDeclsMap =
@@ -10231,13 +10231,6 @@ void ASTReader::finishPendingActions() {
 }
 PendingDeducedVarTypes.clear();
 
-// For each decl chain that we wanted to complete while deserializing, mark
-// it as "still needs to be completed".
-for (unsigned I = 0; I != PendingIncompleteDeclChains.size(); ++I) {
-  markIncompleteDeclChain(PendingIncompleteDeclChains[I]);
-}
-PendingIncompleteDeclChains.clear();
-
 // Load pending declaration chains.
 for (unsigned I = 0; I != PendingDeclChains.size(); ++I)
   loadPendingDeclChain(PendingDeclChains[I].first,
@@ -10475,6 +10468,12 @@ void ASTReader::finishPendingActions() {
   for (auto *ND : PendingMergedDefinitionsToDeduplicate)
 getContext().deduplicateMergedDefinitonsFor(ND);
   PendingMergedDefinitionsToDeduplicate.clear();
+
+  // For each decl chain that we wanted to complete while deserializing, mark
+  // it as "still needs to be completed".
+  for (Decl *D : PendingIncompleteDeclChains)
+markIncompleteDeclChain(D);
+  PendingIncompleteDeclChains.clear();
 }
 
 void ASTReader::diagnoseOdrViolations() {
diff --git a/clang/test/Modules/pr121245.cpp b/clang/test/Modules/pr121245.cpp
new file mode 100644
index 0..0e276ad0e435d
--- /dev/null
+++ b/clang/test/Modules/pr121245.cpp
@@ -0,0 +1,93 @@
+// If this test fails, it should be investigated under Debug builds.
+// Before the PR, this test was encountering an `llvm_unreachable()`.
+
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+// RUN: cd %t
+
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header %t/hu-01.h \
+// RUN:  -fcxx-exceptions -o %t/hu-01.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header %t/hu-02.h \
+// RUN:  -Wno-experimental-header-units -fcxx-exceptions \
+// RUN:  -fmodule-file=%t/hu-01.pcm -o %t/hu-02.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header %t/hu-03.h \
+// RUN:  -Wno-experimental-header-units -fcxx-exceptions \
+// RUN:  -fmodule-file=%t/hu-01.pcm -o %t/hu-03.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header %t/hu-04.h \
+// RUN:  -Wno-experimental-header-units -fcxx-exceptions \
+// RUN:  -fmodule-file=%t/hu-01.pcm -o %t/hu-04.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header %t/hu-05.h \
+// RUN:  -Wno-experimental-header-units -fcxx-exceptions \
+// RUN:  -fmodule-file=%t/hu-03.pcm -fmodule-file=%t/hu-04.pcm \
+// RUN:  -fmodule-file=%t/hu-01.pcm -o %t/hu-05.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-obj %t/main.cpp \
+// RUN:  -Wno-experimental-header-units -fcxx-exceptions \
+// RUN:  -fmodule-file=%t/hu-02.pcm -fmodule-file=%t/hu-05.pcm \
+// RUN:  -fmodule-file=%t/hu-04.pcm -fmodule-file=%t/hu-03.pcm \
+// RUN:  -fmodule-file=%t/hu-01.pcm
+
+//--- hu-01.h
+template 
+struct A {
+  A() {}
+  ~A() {}
+};
+
+template 
+struct EBO : T {
+  EBO() = default;
+};
+
+template 
+struct HT : EBO> {};
+
+//--- hu-02.h
+import "hu-01.h";
+
+inline void f() {
+  HT();
+}
+
+//--- hu-03.h
+i

[clang] Fix incomplete decl chains (PR #129982)

2025-03-05 Thread Michael Park via cfe-commits

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


[clang] Fix incomplete decl chains (PR #129982)

2025-03-05 Thread Michael Park via cfe-commits

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


[clang] [C++20][Modules][Serialization] Fix incomplete decl chains (PR #129982)

2025-03-05 Thread Michael Park via cfe-commits

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


[clang] [C++20][Modules] Fix incomplete decl chains (PR #129982)

2025-03-05 Thread Michael Park via cfe-commits

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


[clang] [clang-format] Remove special handling of C++ access specifiers in C (PR #129983)

2025-03-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)


Changes

This effectively reverts d1aed486efc6d35a81ca4acbabb4203c4b91cda9 because of

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


3 Files Affected:

- (modified) clang/lib/Format/UnwrappedLineFormatter.cpp (+6-24) 
- (modified) clang/lib/Format/UnwrappedLineParser.cpp (+2-62) 
- (modified) clang/unittests/Format/FormatTest.cpp (+25-24) 


``diff
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Format/UnwrappedLineFormatter.cpp
index 14e984529d640..000a5105ca407 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -116,36 +116,18 @@ class LevelIndentTracker {
 Style.isCSharp()) {
   return 0;
 }
-
-auto IsAccessModifier = [&](const FormatToken &RootToken) {
-  if (Line.Type == LT_AccessModifier || RootToken.isObjCAccessSpecifier())
-return true;
-
-  const auto *Next = RootToken.Next;
-
-  // Handle Qt signals.
-  if (RootToken.isOneOf(Keywords.kw_signals, Keywords.kw_qsignals) &&
-  Next && Next->is(tok::colon)) {
-return true;
-  }
-
-  if (Next && Next->isOneOf(Keywords.kw_slots, Keywords.kw_qslots) &&
-  Next->Next && Next->Next->is(tok::colon)) {
-return true;
-  }
-
-  // Handle malformed access specifier e.g. 'private' without trailing ':'.
-  return !Next && RootToken.isAccessSpecifier(false);
-};
-
-if (IsAccessModifier(*Line.First)) {
+const auto &RootToken = *Line.First;
+if (Line.Type == LT_AccessModifier ||
+RootToken.isAccessSpecifier(/*ColonRequired=*/false) ||
+RootToken.isObjCAccessSpecifier() ||
+(RootToken.isOneOf(Keywords.kw_signals, Keywords.kw_qsignals) &&
+ RootToken.Next && RootToken.Next->is(tok::colon))) {
   // The AccessModifierOffset may be overridden by IndentAccessModifiers,
   // in which case we take a negative value of the IndentWidth to simulate
   // the upper indent level.
   return Style.IndentAccessModifiers ? -Style.IndentWidth
  : Style.AccessModifierOffset;
 }
-
 return 0;
   }
 
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 2da0432816df7..3714d4e22a28a 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -3386,75 +3386,15 @@ void UnwrappedLineParser::parseSwitch(bool IsExpr) {
 NestedTooDeep.pop_back();
 }
 
-// Operators that can follow a C variable.
-static bool isCOperatorFollowingVar(tok::TokenKind Kind) {
-  switch (Kind) {
-  case tok::ampamp:
-  case tok::ampequal:
-  case tok::arrow:
-  case tok::caret:
-  case tok::caretequal:
-  case tok::comma:
-  case tok::ellipsis:
-  case tok::equal:
-  case tok::equalequal:
-  case tok::exclaim:
-  case tok::exclaimequal:
-  case tok::greater:
-  case tok::greaterequal:
-  case tok::greatergreater:
-  case tok::greatergreaterequal:
-  case tok::l_paren:
-  case tok::l_square:
-  case tok::less:
-  case tok::lessequal:
-  case tok::lessless:
-  case tok::lesslessequal:
-  case tok::minus:
-  case tok::minusequal:
-  case tok::minusminus:
-  case tok::percent:
-  case tok::percentequal:
-  case tok::period:
-  case tok::pipe:
-  case tok::pipeequal:
-  case tok::pipepipe:
-  case tok::plus:
-  case tok::plusequal:
-  case tok::plusplus:
-  case tok::question:
-  case tok::r_brace:
-  case tok::r_paren:
-  case tok::r_square:
-  case tok::semi:
-  case tok::slash:
-  case tok::slashequal:
-  case tok::star:
-  case tok::starequal:
-return true;
-  default:
-return false;
-  }
-}
-
 void UnwrappedLineParser::parseAccessSpecifier() {
-  FormatToken *AccessSpecifierCandidate = FormatTok;
   nextToken();
   // Understand Qt's slots.
   if (FormatTok->isOneOf(Keywords.kw_slots, Keywords.kw_qslots))
 nextToken();
   // Otherwise, we don't know what it is, and we'd better keep the next token.
-  if (FormatTok->is(tok::colon)) {
+  if (FormatTok->is(tok::colon))
 nextToken();
-addUnwrappedLine();
-  } else if (FormatTok->isNot(tok::coloncolon) &&
- !isCOperatorFollowingVar(FormatTok->Tok.getKind())) {
-// Not a variable name nor namespace name.
-addUnwrappedLine();
-  } else if (AccessSpecifierCandidate) {
-// Consider the access specifier to be a C identifier.
-AccessSpecifierCandidate->Tok.setKind(tok::identifier);
-  }
+  addUnwrappedLine();
 }
 
 /// \brief Parses a requires, decides if it is a clause or an expression.
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index ae2eaf70de1c2..bd335f4b6a21b 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -3501,46 +3501,47 @@ TEST_F(FormatTest, UnderstandsAccessSpecifiers) {
"label:\n"
"  signals.baz();

[clang] Fix incomplete decl chains (PR #129982)

2025-03-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-modules

Author: Michael Park (mpark)


Changes



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


4 Files Affected:

- (modified) clang/lib/Sema/SemaType.cpp (+6) 
- (modified) clang/lib/Serialization/ASTReader.cpp (+12-13) 
- (added) clang/test/Modules/mpark.cpp (+107) 
- (added) clang/test/Modules/pr121245.cpp (+93) 


``diff
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 11943c0b53591..e2002bb410110 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -9180,6 +9180,12 @@ bool Sema::hasAcceptableDefinition(NamedDecl *D, 
NamedDecl **Suggested,
   if (!getLangOpts().Modules && !getLangOpts().ModulesLocalVisibility)
 return true;
 
+  // The external source may have additional definitions of this entity that 
are
+  // visible, so complete the redeclaration chain now.
+  if (auto *Source = Context.getExternalSource()) {
+Source->CompleteRedeclChain(D);
+  }
+
   // If this definition was instantiated from a template, map back to the
   // pattern from which it was instantiated.
   if (isa(D) && cast(D)->isBeingDefined()) {
diff --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index ca09c3d79d941..17d07f8535346 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -10178,12 +10178,12 @@ void ASTReader::visitTopLevelModuleMaps(
 }
 
 void ASTReader::finishPendingActions() {
-  while (
-  !PendingIdentifierInfos.empty() || !PendingDeducedFunctionTypes.empty() 
||
-  !PendingDeducedVarTypes.empty() || !PendingIncompleteDeclChains.empty() 
||
-  !PendingDeclChains.empty() || !PendingMacroIDs.empty() ||
-  !PendingDeclContextInfos.empty() || !PendingUpdateRecords.empty() ||
-  !PendingObjCExtensionIvarRedeclarations.empty()) {
+  while (!PendingIdentifierInfos.empty() ||
+ !PendingDeducedFunctionTypes.empty() ||
+ !PendingDeducedVarTypes.empty() || !PendingDeclChains.empty() ||
+ !PendingMacroIDs.empty() || !PendingDeclContextInfos.empty() ||
+ !PendingUpdateRecords.empty() ||
+ !PendingObjCExtensionIvarRedeclarations.empty()) {
 // If any identifiers with corresponding top-level declarations have
 // been loaded, load those declarations now.
 using TopLevelDeclsMap =
@@ -10231,13 +10231,6 @@ void ASTReader::finishPendingActions() {
 }
 PendingDeducedVarTypes.clear();
 
-// For each decl chain that we wanted to complete while deserializing, mark
-// it as "still needs to be completed".
-for (unsigned I = 0; I != PendingIncompleteDeclChains.size(); ++I) {
-  markIncompleteDeclChain(PendingIncompleteDeclChains[I]);
-}
-PendingIncompleteDeclChains.clear();
-
 // Load pending declaration chains.
 for (unsigned I = 0; I != PendingDeclChains.size(); ++I)
   loadPendingDeclChain(PendingDeclChains[I].first,
@@ -10475,6 +10468,12 @@ void ASTReader::finishPendingActions() {
   for (auto *ND : PendingMergedDefinitionsToDeduplicate)
 getContext().deduplicateMergedDefinitonsFor(ND);
   PendingMergedDefinitionsToDeduplicate.clear();
+
+  // For each decl chain that we wanted to complete while deserializing, mark
+  // it as "still needs to be completed".
+  for (Decl *D : PendingIncompleteDeclChains)
+markIncompleteDeclChain(D);
+  PendingIncompleteDeclChains.clear();
 }
 
 void ASTReader::diagnoseOdrViolations() {
diff --git a/clang/test/Modules/mpark.cpp b/clang/test/Modules/mpark.cpp
new file mode 100644
index 0..d3b45767526f2
--- /dev/null
+++ b/clang/test/Modules/mpark.cpp
@@ -0,0 +1,107 @@
+// If this test fails, it should be investigated under Debug builds.
+// Before the PR, this test was violating an assertion.
+
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -std=c++17 -emit-obj -fmodules \
+// RUN:  -fmodule-map-file=%t/module.modulemap \
+// RUN:  -fmodules-cache-path=%t %t/a.cpp
+
+//--- module.modulemap
+module ebo {
+  header "ebo.h"
+}
+
+module fwd {
+  header "fwd.h"
+}
+
+module s {
+  header "s.h"
+  export *
+}
+
+module mod {
+  header "a.h"
+  header "b.h"
+}
+
+//--- ebo.h
+#pragma once
+
+namespace N { inline namespace __1 {
+
+template 
+struct EBO : T {
+  EBO() = default;
+};
+
+}}
+
+//--- fwd.h
+#pragma once
+
+namespace N { inline namespace __1 {
+
+template 
+struct Empty;
+
+template 
+struct BS;
+
+using S = BS>;
+
+}}
+
+//--- s.h
+#pragma once
+
+#include "fwd.h"
+#include "ebo.h"
+
+namespace N { inline namespace __1 {
+
+template 
+struct Empty {};
+
+template 
+struct BS {
+EBO _;
+void f();
+};
+
+extern template void BS>::f();
+
+}}
+
+//--- b.h
+#pragma once
+
+#include "s.h"
+
+struct B {
+  void f() {
+N::S{}.f();
+  }
+};
+
+//--- a.h
+#pragma once
+
+#include "s.h"
+
+struct A {
+  void f(int) {}
+  void f(const N::S &) {}
+
+  void g();
+};
+
+//--- a.cpp
+#include "a.h"
+
+

[clang] [clang-format] Remove special handling of C++ access specifiers in C (PR #129983)

2025-03-05 Thread Owen Pan via cfe-commits

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


[clang] [clang-format] Remove special handling of C++ access specifiers in C (PR #129983)

2025-03-05 Thread Owen Pan via cfe-commits

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/129983

This effectively reverts d1aed486efc6d35a81ca4acbabb4203c4b91cda9 because of

>From 2cd96b9948147d9bc5cc402e647fc378c2efd212 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Wed, 5 Mar 2025 20:05:01 -0800
Subject: [PATCH] [clang-format] Remove special handling of C++ access
 specifiers in C

This effectively reverts d1aed486efc6d35a81ca4acbabb4203c4b91cda9 because of
---
 clang/lib/Format/UnwrappedLineFormatter.cpp | 30 ++
 clang/lib/Format/UnwrappedLineParser.cpp| 64 +
 clang/unittests/Format/FormatTest.cpp   | 49 
 3 files changed, 33 insertions(+), 110 deletions(-)

diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Format/UnwrappedLineFormatter.cpp
index 14e984529d640..000a5105ca407 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -116,36 +116,18 @@ class LevelIndentTracker {
 Style.isCSharp()) {
   return 0;
 }
-
-auto IsAccessModifier = [&](const FormatToken &RootToken) {
-  if (Line.Type == LT_AccessModifier || RootToken.isObjCAccessSpecifier())
-return true;
-
-  const auto *Next = RootToken.Next;
-
-  // Handle Qt signals.
-  if (RootToken.isOneOf(Keywords.kw_signals, Keywords.kw_qsignals) &&
-  Next && Next->is(tok::colon)) {
-return true;
-  }
-
-  if (Next && Next->isOneOf(Keywords.kw_slots, Keywords.kw_qslots) &&
-  Next->Next && Next->Next->is(tok::colon)) {
-return true;
-  }
-
-  // Handle malformed access specifier e.g. 'private' without trailing ':'.
-  return !Next && RootToken.isAccessSpecifier(false);
-};
-
-if (IsAccessModifier(*Line.First)) {
+const auto &RootToken = *Line.First;
+if (Line.Type == LT_AccessModifier ||
+RootToken.isAccessSpecifier(/*ColonRequired=*/false) ||
+RootToken.isObjCAccessSpecifier() ||
+(RootToken.isOneOf(Keywords.kw_signals, Keywords.kw_qsignals) &&
+ RootToken.Next && RootToken.Next->is(tok::colon))) {
   // The AccessModifierOffset may be overridden by IndentAccessModifiers,
   // in which case we take a negative value of the IndentWidth to simulate
   // the upper indent level.
   return Style.IndentAccessModifiers ? -Style.IndentWidth
  : Style.AccessModifierOffset;
 }
-
 return 0;
   }
 
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 2da0432816df7..3714d4e22a28a 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -3386,75 +3386,15 @@ void UnwrappedLineParser::parseSwitch(bool IsExpr) {
 NestedTooDeep.pop_back();
 }
 
-// Operators that can follow a C variable.
-static bool isCOperatorFollowingVar(tok::TokenKind Kind) {
-  switch (Kind) {
-  case tok::ampamp:
-  case tok::ampequal:
-  case tok::arrow:
-  case tok::caret:
-  case tok::caretequal:
-  case tok::comma:
-  case tok::ellipsis:
-  case tok::equal:
-  case tok::equalequal:
-  case tok::exclaim:
-  case tok::exclaimequal:
-  case tok::greater:
-  case tok::greaterequal:
-  case tok::greatergreater:
-  case tok::greatergreaterequal:
-  case tok::l_paren:
-  case tok::l_square:
-  case tok::less:
-  case tok::lessequal:
-  case tok::lessless:
-  case tok::lesslessequal:
-  case tok::minus:
-  case tok::minusequal:
-  case tok::minusminus:
-  case tok::percent:
-  case tok::percentequal:
-  case tok::period:
-  case tok::pipe:
-  case tok::pipeequal:
-  case tok::pipepipe:
-  case tok::plus:
-  case tok::plusequal:
-  case tok::plusplus:
-  case tok::question:
-  case tok::r_brace:
-  case tok::r_paren:
-  case tok::r_square:
-  case tok::semi:
-  case tok::slash:
-  case tok::slashequal:
-  case tok::star:
-  case tok::starequal:
-return true;
-  default:
-return false;
-  }
-}
-
 void UnwrappedLineParser::parseAccessSpecifier() {
-  FormatToken *AccessSpecifierCandidate = FormatTok;
   nextToken();
   // Understand Qt's slots.
   if (FormatTok->isOneOf(Keywords.kw_slots, Keywords.kw_qslots))
 nextToken();
   // Otherwise, we don't know what it is, and we'd better keep the next token.
-  if (FormatTok->is(tok::colon)) {
+  if (FormatTok->is(tok::colon))
 nextToken();
-addUnwrappedLine();
-  } else if (FormatTok->isNot(tok::coloncolon) &&
- !isCOperatorFollowingVar(FormatTok->Tok.getKind())) {
-// Not a variable name nor namespace name.
-addUnwrappedLine();
-  } else if (AccessSpecifierCandidate) {
-// Consider the access specifier to be a C identifier.
-AccessSpecifierCandidate->Tok.setKind(tok::identifier);
-  }
+  addUnwrappedLine();
 }
 
 /// \brief Parses a requires, decides if it is a clause or an expression.
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index ae2eaf70de1c2

[clang] [clang][modules][deps] Add mutex as an alternative to file lock (PR #129751)

2025-03-05 Thread Jan Svoboda via cfe-commits

https://github.com/jansvoboda11 updated 
https://github.com/llvm/llvm-project/pull/129751

>From 5f119a3a4ae8642d6ab0498c1cf6b39d5099c835 Mon Sep 17 00:00:00 2001
From: Jan Svoboda 
Date: Thu, 27 Feb 2025 15:23:18 -0800
Subject: [PATCH 1/5] [clang][modules][deps] Add mutex as an alternative to
 file lock

---
 .../include/clang/Frontend/CompilerInstance.h | 13 ++-
 .../clang/Serialization/ModuleCacheLock.h | 31 +++
 .../DependencyScanningService.h   |  7 ++
 .../DependencyScanning/ModuleCacheMutexLock.h | 31 +++
 clang/lib/Frontend/CompilerInstance.cpp   | 47 ++-
 clang/lib/Serialization/CMakeLists.txt|  1 +
 clang/lib/Serialization/ModuleCacheLock.cpp   | 60 ++
 .../Tooling/DependencyScanning/CMakeLists.txt |  1 +
 .../DependencyScanningWorker.cpp  |  7 +-
 .../ModuleCacheMutexLock.cpp  | 81 +++
 10 files changed, 254 insertions(+), 25 deletions(-)
 create mode 100644 clang/include/clang/Serialization/ModuleCacheLock.h
 create mode 100644 
clang/include/clang/Tooling/DependencyScanning/ModuleCacheMutexLock.h
 create mode 100644 clang/lib/Serialization/ModuleCacheLock.cpp
 create mode 100644 
clang/lib/Tooling/DependencyScanning/ModuleCacheMutexLock.cpp

diff --git a/clang/include/clang/Frontend/CompilerInstance.h 
b/clang/include/clang/Frontend/CompilerInstance.h
index 8b539dfc92960..bede160991443 100644
--- a/clang/include/clang/Frontend/CompilerInstance.h
+++ b/clang/include/clang/Frontend/CompilerInstance.h
@@ -53,6 +53,7 @@ class FileManager;
 class FrontendAction;
 class InMemoryModuleCache;
 class Module;
+class ModuleCacheLock;
 class Preprocessor;
 class Sema;
 class SourceManager;
@@ -96,9 +97,12 @@ class CompilerInstance : public ModuleLoader {
   /// The source manager.
   IntrusiveRefCntPtr SourceMgr;
 
-  /// The cache of PCM files.
+  /// The local in-memory cache of PCM files.
   IntrusiveRefCntPtr ModuleCache;
 
+  /// The lock managing the global cache of PCM files.
+  std::shared_ptr ModuleCacheLck;
+
   /// The preprocessor.
   std::shared_ptr PP;
 
@@ -209,7 +213,8 @@ class CompilerInstance : public ModuleLoader {
   explicit CompilerInstance(
   std::shared_ptr PCHContainerOps =
   std::make_shared(),
-  InMemoryModuleCache *SharedModuleCache = nullptr);
+  InMemoryModuleCache *SharedModuleCache = nullptr,
+  std::shared_ptr ModuleCacheLck = nullptr);
   ~CompilerInstance() override;
 
   /// @name High-Level Operations
@@ -897,6 +902,10 @@ class CompilerInstance : public ModuleLoader {
   void setExternalSemaSource(IntrusiveRefCntPtr ESS);
 
   InMemoryModuleCache &getModuleCache() const { return *ModuleCache; }
+
+  std::shared_ptr getModuleCacheLockPtr() const {
+return ModuleCacheLck;
+  }
 };
 
 } // end namespace clang
diff --git a/clang/include/clang/Serialization/ModuleCacheLock.h 
b/clang/include/clang/Serialization/ModuleCacheLock.h
new file mode 100644
index 0..9435735b1a1bd
--- /dev/null
+++ b/clang/include/clang/Serialization/ModuleCacheLock.h
@@ -0,0 +1,31 @@
+#ifndef LLVM_CLANG_SERIALIZATION_MODULECACHELOCK_H
+#define LLVM_CLANG_SERIALIZATION_MODULECACHELOCK_H
+
+#include "clang/Basic/LLVM.h"
+#include "llvm/Support/LockFileManager.h"
+
+namespace clang {
+enum class LockResult { Owned, Shared, Error };
+enum class WaitForUnlockResult { Success, OwnerDied, Timeout };
+
+class ModuleCacheLockManager {
+public:
+  virtual operator LockResult() const = 0;
+  virtual WaitForUnlockResult waitForUnlock() = 0;
+  virtual void unsafeRemoveLock() = 0;
+  virtual std::string getErrorMessage() const = 0;
+  virtual ~ModuleCacheLockManager() = default;
+};
+
+class ModuleCacheLock {
+public:
+  virtual void prepareLock(StringRef ModuleFilename) = 0;
+  virtual std::unique_ptr
+  tryLock(StringRef ModuleFilename) = 0;
+  virtual ~ModuleCacheLock() = default;
+};
+
+std::shared_ptr getModuleCacheFileLock();
+} // namespace clang
+
+#endif
diff --git 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h
index f002f8645d3f6..f6914b90ac67e 100644
--- a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h
+++ b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_CLANG_TOOLING_DEPENDENCYSCANNING_DEPENDENCYSCANNINGSERVICE_H
 #define LLVM_CLANG_TOOLING_DEPENDENCYSCANNING_DEPENDENCYSCANNINGSERVICE_H
 
+#include "clang/Tooling/DependencyScanning/ModuleCacheMutexLock.h"
 #include "clang/Tooling/DependencyScanning/DependencyScanningFilesystem.h"
 #include "llvm/ADT/BitmaskEnum.h"
 
@@ -95,6 +96,10 @@ class DependencyScanningService {
 return SharedCache;
   }
 
+  ModuleCacheMutexes &getSharedModuleCacheMutexes() {
+return ModuleCacheMutexes;
+  }
+
 private:
   const ScanningMode Mode;
   const ScanningOutputFormat Format;
@@ -106,6 +111,8 @@ class DependencyScanningService

[clang] [HLSL] add extra scalar vector overloads for clamp (PR #129939)

2025-03-05 Thread Joshua Batista via cfe-commits


@@ -35,25 +35,48 @@ namespace hlsl {
 #define _HLSL_16BIT_AVAILABILITY_STAGE(environment, version, stage)
 #endif
 
-#define GEN_VEC_SCALAR_OVERLOADS(FUNC_NAME, BASE_TYPE, AVAIL)  
\
-  GEN_BOTH_OVERLOADS(FUNC_NAME, BASE_TYPE, BASE_TYPE##2, AVAIL)
\
-  GEN_BOTH_OVERLOADS(FUNC_NAME, BASE_TYPE, BASE_TYPE##3, AVAIL)
\
-  GEN_BOTH_OVERLOADS(FUNC_NAME, BASE_TYPE, BASE_TYPE##4, AVAIL)
-
-#define GEN_BOTH_OVERLOADS(FUNC_NAME, BASE_TYPE, VECTOR_TYPE, AVAIL)   
\
-  IF_TRUE_##AVAIL( 
\
-  _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)) constexpr VECTOR_TYPE
\
-  FUNC_NAME(VECTOR_TYPE p0, BASE_TYPE p1) {
\
-return __builtin_elementwise_##FUNC_NAME(p0, (VECTOR_TYPE)p1); 
\
+#define _HLSL_CAT(a, b) a##b
+#define _HLSL_VEC_SCALAR_OVERLOADS(NAME, BASE_T, AVAIL)
\
+  _HLSL_ALL_OVERLOADS(NAME, BASE_T, AVAIL, _HLSL_CAT(_HLSL_NUM_ARGS_, NAME))
+
+#define _HLSL_ALL_OVERLOADS(NAME, BASE_T, AVAIL, NUM_ARGS) 
\
+  _HLSL_CAT(_HLSL_BOTH_OVERLOADS_, NUM_ARGS)   
\
+  (NAME, BASE_T, _HLSL_CAT(BASE_T, 2), AVAIL)  
\
+  _HLSL_CAT(_HLSL_BOTH_OVERLOADS_, NUM_ARGS)(NAME, BASE_T, 
\
+ _HLSL_CAT(BASE_T, 3), AVAIL)  
\
+  _HLSL_CAT(_HLSL_BOTH_OVERLOADS_, 
\
+NUM_ARGS)(NAME, BASE_T, _HLSL_CAT(BASE_T, 4), AVAIL)
+
+#define _HLSL_BOTH_OVERLOADS_2(NAME, BASE_T, VECTOR_T, AVAIL)  
\
+  _HLSL_CAT(_HLSL_IF_TRUE_, AVAIL) 
\
+  (_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)) constexpr VECTOR_T NAME(
\
+  VECTOR_T p0, BASE_T p1) {
\
+return _HLSL_CAT(__builtin_elementwise_, NAME)(p0, (VECTOR_T)p1);  
\
   }
\
-  IF_TRUE_##AVAIL( 
\
-  _HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)) constexpr VECTOR_TYPE
\
-  FUNC_NAME(BASE_TYPE p0, VECTOR_TYPE p1) {
\
-return __builtin_elementwise_##FUNC_NAME((VECTOR_TYPE)p0, p1); 
\
+  _HLSL_CAT(_HLSL_IF_TRUE_, AVAIL) 
\
+  (_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)) constexpr VECTOR_T NAME(
\
+  BASE_T p0, VECTOR_T p1) {
\
+return _HLSL_CAT(__builtin_elementwise_, NAME)((VECTOR_T)p0, p1);  
\
   }
 
-#define IF_TRUE_0(EXPR)
-#define IF_TRUE_1(EXPR) EXPR
+#define _HLSL_BOTH_OVERLOADS_3(NAME, BASE_T, VECTOR_T, AVAIL)  
\
+  _HLSL_CAT(_HLSL_IF_TRUE_, AVAIL) 
\
+  (_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)) constexpr VECTOR_T NAME(
\
+  VECTOR_T p0, VECTOR_T p1, BASE_T p2) {   
\
+return _HLSL_CAT(__builtin_hlsl_elementwise_, NAME)(p0, p1, (VECTOR_T)p2); 
\
+  }
\
+  _HLSL_CAT(_HLSL_IF_TRUE_, AVAIL) 
\
+  (_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)) constexpr VECTOR_T NAME(
\
+  VECTOR_T p0, BASE_T p1, VECTOR_T p2) {   
\
+return _HLSL_CAT(__builtin_hlsl_elementwise_, NAME)(p0, (VECTOR_T)p1, p2); 
\

bob80905 wrote:

For clamp, I looked through lines 596 - 698 and didn't find the overload for 
clamp where args 2 and 3 are the base type. Am I missing something?

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


[clang] 5b3ba26 - [Clang] [Sema] Allow non-local/non-variable declarations in for loop (#129737)

2025-03-05 Thread via cfe-commits

Author: Sirraide
Date: 2025-03-06T02:03:22+01:00
New Revision: 5b3ba261c49bee35debdd54e23a6a181126f798e

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

LOG: [Clang] [Sema] Allow non-local/non-variable declarations in for loop 
(#129737)

Currently, we error on non-variable or non-local variable declarations
in `for` loops such as `for (struct S {}; 0; ) {}`. However, this is
valid in C23, so this patch changes the error to a compatibilty warning
and also allows this as an extension in earlier language modes. This
also matches GCC’s behaviour.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaStmt.cpp
clang/test/Sema/for.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 32db3fe5740ed..629149bf459b1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -248,6 +248,8 @@ Bug Fixes in This Version
   (#GH125500).
 - Fixed clang crash when #embed data does not fit into an array
   (#GH128987).
+- Non-local variable and non-variable declarations in the first clause of a 
``for`` loop in C are no longer incorrectly
+  considered an error in C23 mode and are allowed as an extension in earlier 
language modes.
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 0b121c04cd3c0..ed2da2b355e11 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10797,6 +10797,23 @@ def err_non_local_variable_decl_in_for : Error<
   "declaration of non-local variable in 'for' loop">;
 def err_non_variable_decl_in_for : Error<
   "non-variable declaration in 'for' loop">;
+
+def ext_c23_non_local_variable_decl_in_for : Extension<
+  "declaration of non-local variable in 'for' loop is a C23 extension">,
+  InGroup;
+
+def warn_c17_non_local_variable_decl_in_for : Warning<
+  "declaration of non-local variable in 'for' loop is incompatible with C 
standards before C23">,
+  DefaultIgnore, InGroup;
+
+def ext_c23_non_variable_decl_in_for : Extension<
+  "non-variable declaration in 'for' loop is a C23 extension">,
+  InGroup;
+
+def warn_c17_non_variable_decl_in_for : Warning<
+  "non-variable declaration in 'for' loop is incompatible with C standards 
before C23">,
+  DefaultIgnore, InGroup;
+
 def err_toomany_element_decls : Error<
   "only one element declaration is allowed">;
 def err_selector_element_not_lvalue : Error<

diff  --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index d0b713f074c33..0a193b5299bcc 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -2269,10 +2269,11 @@ StmtResult Sema::ActOnForStmt(SourceLocation ForLoc, 
SourceLocation LParenLoc,
   for (auto *DI : DS->decls()) {
 if (VarDecl *VD = dyn_cast(DI)) {
   VarDeclSeen = true;
-  if (VD->isLocalVarDecl() && !VD->hasLocalStorage()) {
-Diag(DI->getLocation(), diag::err_non_local_variable_decl_in_for);
-DI->setInvalidDecl();
-  }
+  if (VD->isLocalVarDecl() && !VD->hasLocalStorage())
+Diag(DI->getLocation(),
+ getLangOpts().C23
+ ? diag::warn_c17_non_local_variable_decl_in_for
+ : diag::ext_c23_non_local_variable_decl_in_for);
 } else if (!NonVarSeen) {
   // Keep track of the first non-variable declaration we saw so that
   // we can diagnose if we don't see any variable declarations. This
@@ -2284,7 +2285,9 @@ StmtResult Sema::ActOnForStmt(SourceLocation ForLoc, 
SourceLocation LParenLoc,
   // Diagnose if we saw a non-variable declaration but no variable
   // declarations.
   if (NonVarSeen && !VarDeclSeen)
-Diag(NonVarSeen->getLocation(), diag::err_non_variable_decl_in_for);
+Diag(NonVarSeen->getLocation(),
+ getLangOpts().C23 ? diag::warn_c17_non_variable_decl_in_for
+   : diag::ext_c23_non_variable_decl_in_for);
 }
   }
 

diff  --git a/clang/test/Sema/for.c b/clang/test/Sema/for.c
index d0c2f7f21a960..c21ef62247037 100644
--- a/clang/test/Sema/for.c
+++ b/clang/test/Sema/for.c
@@ -1,13 +1,21 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify=c11 -std=c11 -pedantic %s
+// RUN: %clang_cc1 -fsyntax-only -verify=c23 -std=c23 -Wpre-c23-compat %s
 
 // Check C99 6.8.5p3
 void b1 (void) { for (void (*f) (void);;); }
-void b2 (void) { for (void f (void);;); }   // expected-error {{non-variable 
declaration in 'for' loop}}
-void b3 (void) { for (static int f;;); }// expected-err

[clang] [llvm] [RISCV] QCI Interrupt Support (PR #129957)

2025-03-05 Thread Sam Elliott via cfe-commits


@@ -1892,9 +1970,23 @@ bool RISCVFrameLowering::spillCalleeSavedRegisters(
   if (MI != MBB.end() && !MI->isDebugInstr())
 DL = MI->getDebugLoc();
 
-  // Emit CM.PUSH with base SPimm & evaluate Push stack
   RISCVMachineFunctionInfo *RVFI = MF->getInfo();
-  if (RVFI->isPushable(*MF)) {
+  if (RVFI->useQCIInterrupt(*MF)) {
+// Emit QC.C.MIENTER(.NEST)
+BuildMI(
+MBB, MI, DL,
+TII.get(RVFI->getInterruptStackKind(*MF) ==
+RISCVMachineFunctionInfo::InterruptStackKind::QCINest
+? RISCV::QC_C_MIENTER_NEST
+: RISCV::QC_C_MIENTER))
+.setMIFlag(MachineInstr::FrameSetup);
+
+for (auto [Reg, _Offset] : FixedCSRFIQCIInterruptMap) {

lenary wrote:

Done

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


[clang] [llvm] [RISCV] QCI Interrupt Support (PR #129957)

2025-03-05 Thread Sam Elliott via cfe-commits


@@ -20831,9 +20831,20 @@ SDValue RISCVTargetLowering::LowerFormalArguments(
 StringRef Kind =
   MF.getFunction().getFnAttribute("interrupt").getValueAsString();
 
-if (!(Kind == "supervisor" || Kind == "machine"))
+constexpr StringRef SupportedInterruptKinds[] = {

lenary wrote:

Done

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


[clang] Reduce memory usage in AST parent map generation by lazily checking if nodes have been seen (PR #129934)

2025-03-05 Thread via cfe-commits

higher-performance wrote:

Ah sorry I forgot to reply to your review.

> We might take a look at `SetVector` and see if there are any learnings we can 
> take from that. It has a set and a vector together, but might have some 
> interesting things.

I did take a look at this actually, but it looked equivalent to what I was 
doing before, particularly with respect to storing the expensive keys 
(`DynTypedNode`) twice. It just uses `SmallVector` and `DenseSet` 
underneath, whereas I just happened to use `SmallDenseSet` instead of 
`DenseSet`.

> Finally... I wonder if we were to just store this as a sorted-vector of 
> `DynTypedNode` + `insert order`, then do a copy & sort on access of `view`.

I don't think that works. You don't want to do a ton of work on every `view()` 
-- it's assumed to be cheap, and called often. Also, maintaining sort order 
gets expensive the more nodes you add; you don't want to do it every insertion.

Furthermore not elements without memoization data aren't comparable, but they 
still need to appear in the `view` *in the same order as they were inserted*. 
This means either they need to be in the same vector as the comparable elements 
(which makes it impossible to sort the comparable portion), or we need to 
create a façade over two completely disjoint containers.

The implementation in this PR addresses all of those constraints without any 
drawbacks, I think. There's less code compared to writing a facade, and 
performance-wise it feels just about optimal.

> Can we do some benchmarking to figure out which things are done the 'most 
> often' with what values of `N`? it might better guide this.

Re: benchmarking -- note that I did a general benchmark both with the test case 
that was provided in the associated issue, as well as with an expensive TU that 
we had internally. It had great performance in both cases. Regarding N -- I 
assume N is referring to the total container sizes (per the other comment)? The 
thing is, I don't get the impression there's much room for improvement here. 
The memory usage was just high by a constant (10x) factor. Some ~5x of that 
almost certainly came from the data type itself (storing `DynTypedNode` in the 
cache which is 40 bytes, instead of `DynTypedNode*`, which is 8 bytes). Adding 
laziness on top of that has shrunk the difference so much that the performance 
plots are already very close to coinciding.

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


[clang] [NFC][c-index-test] factor data len out (PR #129971)

2025-03-05 Thread Jinsong Ji via cfe-commits

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


[clang] [NFC][c-index-test] factor data len out (PR #129971)

2025-03-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Jinsong Ji (jsji)


Changes



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


1 Files Affected:

- (modified) clang/tools/c-index-test/c-index-test.c (+3-5) 


``diff
diff --git a/clang/tools/c-index-test/c-index-test.c 
b/clang/tools/c-index-test/c-index-test.c
index 50f32c0a20e5a..1ad2e44aae3f7 100644
--- a/clang/tools/c-index-test/c-index-test.c
+++ b/clang/tools/c-index-test/c-index-test.c
@@ -3554,13 +3554,11 @@ static CXIdxClientContainer 
makeClientContainer(CXClientData *client_data,
 
   clang_indexLoc_getFileLocation(loc, &file, 0, &line, &column, 0);
 
-  len = sizeof(IndexDataStringList) + strlen(name) + digitCount(line) +
-digitCount(column) + 3;
-  node = (IndexDataStringList *)malloc(len);
+  datalen = strlen(name) + digitCount(line) + digitCount(column) + 3;
+  node = (IndexDataStringList *)malloc(len + sizeof(IndexDataStringList));
   assert(node);
   newStr = node->data;
-  snprintf(newStr, len - sizeof(IndexDataStringList), "%s:%d:%d", name, line,
-   column);
+  snprintf(newStr, datalen, "%s:%d:%d", name, line, column);
 
   /* Remember string so it can be freed later. */
   index_data = (IndexData *)client_data;

``




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


[clang] [NFC][c-index-test] factor data len out (PR #129971)

2025-03-05 Thread Jinsong Ji via cfe-commits

https://github.com/jsji created https://github.com/llvm/llvm-project/pull/129971

None

>From 801d92357366d95bc5bd044125eefc25862b6fee Mon Sep 17 00:00:00 2001
From: Jinsong Ji 
Date: Wed, 5 Mar 2025 17:54:48 -0800
Subject: [PATCH] [NFC][c-index-test] factor data len out

---
 clang/tools/c-index-test/c-index-test.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/clang/tools/c-index-test/c-index-test.c 
b/clang/tools/c-index-test/c-index-test.c
index 50f32c0a20e5a..1ad2e44aae3f7 100644
--- a/clang/tools/c-index-test/c-index-test.c
+++ b/clang/tools/c-index-test/c-index-test.c
@@ -3554,13 +3554,11 @@ static CXIdxClientContainer 
makeClientContainer(CXClientData *client_data,
 
   clang_indexLoc_getFileLocation(loc, &file, 0, &line, &column, 0);
 
-  len = sizeof(IndexDataStringList) + strlen(name) + digitCount(line) +
-digitCount(column) + 3;
-  node = (IndexDataStringList *)malloc(len);
+  datalen = strlen(name) + digitCount(line) + digitCount(column) + 3;
+  node = (IndexDataStringList *)malloc(len + sizeof(IndexDataStringList));
   assert(node);
   newStr = node->data;
-  snprintf(newStr, len - sizeof(IndexDataStringList), "%s:%d:%d", name, line,
-   column);
+  snprintf(newStr, datalen, "%s:%d:%d", name, line, column);
 
   /* Remember string so it can be freed later. */
   index_data = (IndexData *)client_data;

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


[clang] [Feature]: merge host and kernel dependencies for heterogeneous compilation (PR #119513)

2025-03-05 Thread via cfe-commits


@@ -350,13 +353,105 @@ void 
DependencyFileGenerator::outputDependencyFile(DiagnosticsEngine &Diags) {
   }
 
   std::error_code EC;
-  llvm::raw_fd_ostream OS(OutputFile, EC, llvm::sys::fs::OF_TextWithCRLF);
-  if (EC) {
-Diags.Report(diag::err_fe_error_opening) << OutputFile << EC.message();
-return;
-  }
 
-  outputDependencyFile(OS);
+  // merge host dependency file (*.d.host)

zhouronghua wrote:

Okay, I will push a static function version.

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


[clang] [NFC][c-index-test] factor data len out (PR #129971)

2025-03-05 Thread Jinsong Ji via cfe-commits

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


[clang] e4c3d25 - [NFC][c-index-test] factor data len out (#129971)

2025-03-05 Thread via cfe-commits

Author: Jinsong Ji
Date: 2025-03-05T23:21:07-05:00
New Revision: e4c3d258b7a1f335cfd3a90bcf3d28ea220c999d

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

LOG: [NFC][c-index-test] factor data len out (#129971)

Follow up of #129922

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 50f32c0a20e5a..7711df3fd9209 100644
--- a/clang/tools/c-index-test/c-index-test.c
+++ b/clang/tools/c-index-test/c-index-test.c
@@ -3546,7 +3546,7 @@ static CXIdxClientContainer 
makeClientContainer(CXClientData *client_data,
   char *newStr;
   CXIdxClientFile file;
   unsigned line, column;
-  size_t len;
+  size_t datalen;
 
   name = info->name;
   if (!name)
@@ -3554,13 +3554,11 @@ static CXIdxClientContainer 
makeClientContainer(CXClientData *client_data,
 
   clang_indexLoc_getFileLocation(loc, &file, 0, &line, &column, 0);
 
-  len = sizeof(IndexDataStringList) + strlen(name) + digitCount(line) +
-digitCount(column) + 3;
-  node = (IndexDataStringList *)malloc(len);
+  datalen = strlen(name) + digitCount(line) + digitCount(column) + 3;
+  node = (IndexDataStringList *)malloc(datalen + sizeof(IndexDataStringList));
   assert(node);
   newStr = node->data;
-  snprintf(newStr, len - sizeof(IndexDataStringList), "%s:%d:%d", name, line,
-   column);
+  snprintf(newStr, datalen, "%s:%d:%d", name, line, column);
 
   /* Remember string so it can be freed later. */
   index_data = (IndexData *)client_data;



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


[clang] [C++20][Modules] Fix incomplete decl chains (PR #129982)

2025-03-05 Thread Michael Park via cfe-commits

https://github.com/mpark updated 
https://github.com/llvm/llvm-project/pull/129982

>From 3f883067a2fda4147003de9a53b88e52c33d1280 Mon Sep 17 00:00:00 2001
From: Michael Park 
Date: Tue, 25 Feb 2025 14:33:41 -0800
Subject: [PATCH 1/3] =?UTF-8?q?Reapply=20"[C++20][Modules][Serialization]?=
 =?UTF-8?q?=20Delay=20marking=20pending=20incompl=E2=80=A6=20(#127136)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This reverts commit 912b154f3a3f8c3cebf5cc5731fd8b0749762da5.
---
 clang/lib/Serialization/ASTReader.cpp | 25 ---
 clang/test/Modules/pr121245.cpp   | 93 +++
 2 files changed, 105 insertions(+), 13 deletions(-)
 create mode 100644 clang/test/Modules/pr121245.cpp

diff --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index ca09c3d79d941..17d07f8535346 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -10178,12 +10178,12 @@ void ASTReader::visitTopLevelModuleMaps(
 }
 
 void ASTReader::finishPendingActions() {
-  while (
-  !PendingIdentifierInfos.empty() || !PendingDeducedFunctionTypes.empty() 
||
-  !PendingDeducedVarTypes.empty() || !PendingIncompleteDeclChains.empty() 
||
-  !PendingDeclChains.empty() || !PendingMacroIDs.empty() ||
-  !PendingDeclContextInfos.empty() || !PendingUpdateRecords.empty() ||
-  !PendingObjCExtensionIvarRedeclarations.empty()) {
+  while (!PendingIdentifierInfos.empty() ||
+ !PendingDeducedFunctionTypes.empty() ||
+ !PendingDeducedVarTypes.empty() || !PendingDeclChains.empty() ||
+ !PendingMacroIDs.empty() || !PendingDeclContextInfos.empty() ||
+ !PendingUpdateRecords.empty() ||
+ !PendingObjCExtensionIvarRedeclarations.empty()) {
 // If any identifiers with corresponding top-level declarations have
 // been loaded, load those declarations now.
 using TopLevelDeclsMap =
@@ -10231,13 +10231,6 @@ void ASTReader::finishPendingActions() {
 }
 PendingDeducedVarTypes.clear();
 
-// For each decl chain that we wanted to complete while deserializing, mark
-// it as "still needs to be completed".
-for (unsigned I = 0; I != PendingIncompleteDeclChains.size(); ++I) {
-  markIncompleteDeclChain(PendingIncompleteDeclChains[I]);
-}
-PendingIncompleteDeclChains.clear();
-
 // Load pending declaration chains.
 for (unsigned I = 0; I != PendingDeclChains.size(); ++I)
   loadPendingDeclChain(PendingDeclChains[I].first,
@@ -10475,6 +10468,12 @@ void ASTReader::finishPendingActions() {
   for (auto *ND : PendingMergedDefinitionsToDeduplicate)
 getContext().deduplicateMergedDefinitonsFor(ND);
   PendingMergedDefinitionsToDeduplicate.clear();
+
+  // For each decl chain that we wanted to complete while deserializing, mark
+  // it as "still needs to be completed".
+  for (Decl *D : PendingIncompleteDeclChains)
+markIncompleteDeclChain(D);
+  PendingIncompleteDeclChains.clear();
 }
 
 void ASTReader::diagnoseOdrViolations() {
diff --git a/clang/test/Modules/pr121245.cpp b/clang/test/Modules/pr121245.cpp
new file mode 100644
index 0..0e276ad0e435d
--- /dev/null
+++ b/clang/test/Modules/pr121245.cpp
@@ -0,0 +1,93 @@
+// If this test fails, it should be investigated under Debug builds.
+// Before the PR, this test was encountering an `llvm_unreachable()`.
+
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+// RUN: cd %t
+
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header %t/hu-01.h \
+// RUN:  -fcxx-exceptions -o %t/hu-01.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header %t/hu-02.h \
+// RUN:  -Wno-experimental-header-units -fcxx-exceptions \
+// RUN:  -fmodule-file=%t/hu-01.pcm -o %t/hu-02.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header %t/hu-03.h \
+// RUN:  -Wno-experimental-header-units -fcxx-exceptions \
+// RUN:  -fmodule-file=%t/hu-01.pcm -o %t/hu-03.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header %t/hu-04.h \
+// RUN:  -Wno-experimental-header-units -fcxx-exceptions \
+// RUN:  -fmodule-file=%t/hu-01.pcm -o %t/hu-04.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header %t/hu-05.h \
+// RUN:  -Wno-experimental-header-units -fcxx-exceptions \
+// RUN:  -fmodule-file=%t/hu-03.pcm -fmodule-file=%t/hu-04.pcm \
+// RUN:  -fmodule-file=%t/hu-01.pcm -o %t/hu-05.pcm
+
+// RUN: %clang_cc1 -std=c++20 -emit-obj %t/main.cpp \
+// RUN:  -Wno-experimental-header-units -fcxx-exceptions \
+// RUN:  -fmodule-file=%t/hu-02.pcm -fmodule-file=%t/hu-05.pcm \
+// RUN:  -fmodule-file=%t/hu-04.pcm -fmodule-file=%t/hu-03.pcm \
+// RUN:  -fmodule-file=%t/hu-01.pcm
+
+//--- hu-01.h
+template 
+struct A {
+  A() {}
+  ~A() {}
+};
+
+template 
+struct EBO : T {
+  EBO() = default;
+};
+
+template 
+struct HT : EBO> {};
+
+//--- hu-02.h
+import "hu-01.h";
+
+inline void f() {
+  HT();
+}
+
+//--- hu-03.h
+i

[clang] [llvm] [RISCV] QCI Interrupt Support (PR #129957)

2025-03-05 Thread Craig Topper via cfe-commits


@@ -20831,9 +20831,20 @@ SDValue RISCVTargetLowering::LowerFormalArguments(
 StringRef Kind =
   MF.getFunction().getFnAttribute("interrupt").getValueAsString();
 
-if (!(Kind == "supervisor" || Kind == "machine"))
+constexpr StringRef SupportedInterruptKinds[] = {

topperc wrote:

StringRef -> StringLiteral

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


[clang] [llvm] [RISCV] QCI Interrupt Support (PR #129957)

2025-03-05 Thread Craig Topper via cfe-commits


@@ -2828,8 +2828,17 @@ targets. This attribute may be attached to a function 
definition and instructs
 the backend to generate appropriate function entry/exit code so that it can be
 used directly as an interrupt service routine.
 
-Permissible values for this parameter are ``supervisor`` and ``machine``. If
-there is no parameter, then it defaults to ``machine``.
+Permissible values for this parameter are ``supervisor``, ``machine``,
+``qci-nest`` and ``qci-nonest``. If there is no parameter, then it defaults to
+``machine``.
+
+The ``qci-nest`` and ``qci-nonest`` values require the Qualcomm's Xqciint

topperc wrote:

"the Qualcomm's" drop the "the"?

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


[clang] [llvm] [RISCV] QCI Interrupt Support (PR #129957)

2025-03-05 Thread Sam Elliott via cfe-commits


@@ -2828,8 +2828,17 @@ targets. This attribute may be attached to a function 
definition and instructs
 the backend to generate appropriate function entry/exit code so that it can be
 used directly as an interrupt service routine.
 
-Permissible values for this parameter are ``supervisor`` and ``machine``. If
-there is no parameter, then it defaults to ``machine``.
+Permissible values for this parameter are ``supervisor``, ``machine``,
+``qci-nest`` and ``qci-nonest``. If there is no parameter, then it defaults to
+``machine``.
+
+The ``qci-nest`` and ``qci-nonest`` values require the Qualcomm's Xqciint

lenary wrote:

Done

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


[clang-tools-extra] [clang-tidy] 'modernize-use-starts-ends-with': fixed false positives on `find` and `rfind` (PR #129564)

2025-03-05 Thread Nicolas van Kempen via cfe-commits

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


[clang-tools-extra] [clang-tidy] 'modernize-use-starts-ends-with': fixed false positives on `find` and `rfind` (PR #129564)

2025-03-05 Thread Nicolas van Kempen via cfe-commits

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

LGTM, thanks!!

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


[clang-tools-extra] [clang-tidy] 'modernize-use-starts-ends-with': fixed false positives on `find` and `rfind` (PR #129564)

2025-03-05 Thread Nicolas van Kempen via cfe-commits


@@ -128,7 +128,12 @@ Changes in existing checks
   ` check by providing additional
   examples and fixing some macro related false positives.
 
-- Improved :doc:`performance/unnecessary-value-param
+- Improved :doc:`modernize-use-starts-ends-with
+  ` check by adding more
+  matched scenarios of ``find`` and ``rfind`` methods and fixing false
+  positives when those methods were called with 3 arguments.
+
+- Improved :doc:`performance-unnecessary-value-param

nicovank wrote:

While you're at it, place below `performance-move-const-arg` for ordering.

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


[clang] [flang] [lldb] [llvm] [mlir] [polly] [IR] Store Triple in Module (NFC) (PR #129868)

2025-03-05 Thread Yingwei Zheng via cfe-commits

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

LGTM. Thank you!

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


[clang] [Clang] Fix 'gpuintrin.h' match when included with no arch set (PR #129927)

2025-03-05 Thread Matt Arsenault via cfe-commits

https://github.com/arsenm commented:

Should drop the nvvm reflect here. Really shouldn't have any subtarget 
dependent code here. Injecting implementation details into the source program 
is part of the fundamental issue with device lib linking 

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


[clang] [C++20][Modules] Fix incomplete decl chains (PR #129982)

2025-03-05 Thread Chuanqi Xu via cfe-commits


@@ -10178,12 +10178,12 @@ void ASTReader::visitTopLevelModuleMaps(
 }
 
 void ASTReader::finishPendingActions() {
-  while (
-  !PendingIdentifierInfos.empty() || !PendingDeducedFunctionTypes.empty() 
||
-  !PendingDeducedVarTypes.empty() || !PendingIncompleteDeclChains.empty() 
||
-  !PendingDeclChains.empty() || !PendingMacroIDs.empty() ||
-  !PendingDeclContextInfos.empty() || !PendingUpdateRecords.empty() ||
-  !PendingObjCExtensionIvarRedeclarations.empty()) {
+  while (!PendingIdentifierInfos.empty() ||
+ !PendingDeducedFunctionTypes.empty() ||
+ !PendingDeducedVarTypes.empty() || !PendingDeclChains.empty() ||
+ !PendingMacroIDs.empty() || !PendingDeclContextInfos.empty() ||
+ !PendingUpdateRecords.empty() ||
+ !PendingObjCExtensionIvarRedeclarations.empty()) {

ChuanqiXu9 wrote:

nit: please don't update unrelated code.

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


[clang] [C++20][Modules] Fix incomplete decl chains (PR #129982)

2025-03-05 Thread Chuanqi Xu via cfe-commits


@@ -9180,6 +9180,12 @@ bool Sema::hasAcceptableDefinition(NamedDecl *D, 
NamedDecl **Suggested,
   if (!getLangOpts().Modules && !getLangOpts().ModulesLocalVisibility)
 return true;
 
+  // The external source may have additional definitions of this entity that 
are
+  // visible, so complete the redeclaration chain now.
+  if (auto *Source = Context.getExternalSource()) {
+Source->CompleteRedeclChain(D);
+  }

ChuanqiXu9 wrote:

the fix here looks a little bit random to me. If we need to look at other 
declarations, we need to call `redecls()`. But `redecls()` should complete the 
redecl chain, right?

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


[clang] [C++20][Modules] Fix incomplete decl chains (PR #129982)

2025-03-05 Thread Michael Park via cfe-commits

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


[clang] [clang] Pass fp128 indirectly and return in xmm0 on Windows (PR #115052)

2025-03-05 Thread Trevor Gross via cfe-commits

tgross35 wrote:

@rnk (or anyone) would you be able to land this?

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


  1   2   3   4   5   >