[clang] [Clang] Improve error for `-fsanitize=function/kcfi -mexecute-only` incompatibility (PR #118816)

2024-12-11 Thread Csanád Hajdú via cfe-commits

Il-Capitano wrote:

Thanks for reviewing!

I updated the code to use `err_drv_unsupported_opt_for_target`, and added test 
cases for the `-mpure-code` alias of `-mexecute-only` also.

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


[clang] [LoongArch] Add FreeBSD targets (PR #119191)

2024-12-11 Thread WÁNG Xuěruì via cfe-commits

xen0n wrote:

Also a `[Clang]` tag could be prepended to the PR title to make it clearer what 
part gets changed.

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


[clang-tools-extra] fix parse windows driver and provides support for WSL paths. (PR #119350)

2024-12-11 Thread via cfe-commits

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


[clang] [lldb] [Serialization] Support loading template specializations lazily (PR #119333)

2024-12-11 Thread Jonas Hahnfeld via cfe-commits

hahnjo wrote:

I believe 
https://github.com/llvm/llvm-project/commit/30ea0f0ce476bf4c12684a9a514af2ca660bbe44
 already addresses the cast. The bots are just slow...

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


[clang-tools-extra] fix parse windows driver and provides support for WSL paths. (PR #119350)

2024-12-11 Thread via cfe-commits

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


[clang-tools-extra] fix parse windows driver and provides support for WSL paths. (PR #119350)

2024-12-11 Thread via cfe-commits

https://github.com/95833 updated 
https://github.com/llvm/llvm-project/pull/119350

>From 1a37796fbb624a54b00cfff42674fbfa79616f61 Mon Sep 17 00:00:00 2001
From: root <987004...@qq.com>
Date: Sun, 8 Dec 2024 01:19:59 +0800
Subject: [PATCH] fix parse windows driver and wsl path

---
 clang-tools-extra/clangd/PathMapping.cpp | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/clang-tools-extra/clangd/PathMapping.cpp 
b/clang-tools-extra/clangd/PathMapping.cpp
index 4b93ff2c60c5c6..48a936867a738a 100644
--- a/clang-tools-extra/clangd/PathMapping.cpp
+++ b/clang-tools-extra/clangd/PathMapping.cpp
@@ -150,11 +150,11 @@ llvm::Expected parsePath(llvm::StringRef 
Path) {
   if (path::is_absolute(Path, path::Style::posix)) {
 return std::string(Path);
   }
-  if (path::is_absolute(Path, path::Style::windows)) {
-std::string Converted = path::convert_to_slash(Path, path::Style::windows);
-if (Converted.front() != '/')
-  Converted = "/" + Converted;
-return Converted;
+  llvm::StringRef Root = path::root_name(Path, path::Style::windows);
+  if (!Root.empty()) {
+std::string Converted = "/";
+return Converted.append(Root)
+  .append(path::convert_to_slash(Path.substr(Root.size()), 
path::Style::windows));
   }
   return error("Path not absolute: {0}", Path);
 }

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


[clang] [flang] [llvm] [mlir] [flang][OpenMP] Add frontend support for ompx_bare clause (PR #111106)

2024-12-11 Thread Ivan R. Ivanov via cfe-commits

https://github.com/ivanradanov updated 
https://github.com/llvm/llvm-project/pull/06

>From 85e1b6d318a4f11630588f95f964be645d6ddb9b Mon Sep 17 00:00:00 2001
From: Ivan Radanov Ivanov 
Date: Fri, 4 Oct 2024 16:20:36 +0900
Subject: [PATCH 01/15] [flang] Add frontend support for OpenMP extension bare
 clause

---
 flang/lib/Lower/OpenMP/ClauseProcessor.cpp|  4 
 flang/lib/Lower/OpenMP/ClauseProcessor.h  |  1 +
 flang/lib/Lower/OpenMP/Clauses.h  |  2 +-
 flang/lib/Lower/OpenMP/OpenMP.cpp |  2 ++
 flang/lib/Parser/openmp-parsers.cpp   |  1 +
 .../Frontend/OpenMP/ConstructDecompositionT.h |  9 +++
 llvm/include/llvm/Frontend/OpenMP/OMP.td  |  1 +
 .../mlir/Dialect/OpenMP/OpenMPClauses.td  | 24 +++
 mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td |  3 ++-
 mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp  |  2 +-
 10 files changed, 46 insertions(+), 3 deletions(-)

diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp 
b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
index 48c559a78b9bc4..99049cee3ff909 100644
--- a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
+++ b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
@@ -382,6 +382,10 @@ bool 
ClauseProcessor::processNowait(mlir::omp::NowaitClauseOps &result) const {
   return markClauseOccurrence(result.nowait);
 }
 
+bool ClauseProcessor::processBare(mlir::omp::BareClauseOps &result) const {
+  return markClauseOccurrence(result.bare);
+}
+
 bool ClauseProcessor::processNumTeams(
 lower::StatementContext &stmtCtx,
 mlir::omp::NumTeamsClauseOps &result) const {
diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.h 
b/flang/lib/Lower/OpenMP/ClauseProcessor.h
index e0fe917c50e8f8..c309da99263f13 100644
--- a/flang/lib/Lower/OpenMP/ClauseProcessor.h
+++ b/flang/lib/Lower/OpenMP/ClauseProcessor.h
@@ -73,6 +73,7 @@ class ClauseProcessor {
   bool processHint(mlir::omp::HintClauseOps &result) const;
   bool processMergeable(mlir::omp::MergeableClauseOps &result) const;
   bool processNowait(mlir::omp::NowaitClauseOps &result) const;
+  bool processBare(mlir::omp::BareClauseOps &result) const;
   bool processNumTeams(lower::StatementContext &stmtCtx,
mlir::omp::NumTeamsClauseOps &result) const;
   bool processNumThreads(lower::StatementContext &stmtCtx,
diff --git a/flang/lib/Lower/OpenMP/Clauses.h b/flang/lib/Lower/OpenMP/Clauses.h
index 65282d243d87af..e447989446a0e8 100644
--- a/flang/lib/Lower/OpenMP/Clauses.h
+++ b/flang/lib/Lower/OpenMP/Clauses.h
@@ -253,8 +253,8 @@ using NumTasks = tomp::clause::NumTasksT;
 using NumTeams = tomp::clause::NumTeamsT;
 using NumThreads = tomp::clause::NumThreadsT;
 using OmpxAttribute = tomp::clause::OmpxAttributeT;
-using OmpxBare = tomp::clause::OmpxBareT;
 using OmpxDynCgroupMem = tomp::clause::OmpxDynCgroupMemT;
+using OmpxBare = tomp::clause::OmpxBareT;
 using Ordered = tomp::clause::OrderedT;
 using Order = tomp::clause::OrderT;
 using Partial = tomp::clause::PartialT;
diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp 
b/flang/lib/Lower/OpenMP/OpenMP.cpp
index 2ef4d184a6321f..ffe5213961ef03 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -1194,6 +1194,7 @@ static void genTargetClauses(
 cp.processNowait(clauseOps);
 
   cp.processThreadLimit(stmtCtx, clauseOps);
+  cp.processBare(clauseOps);
 
   cp.processTODO(
@@ -2858,6 +2859,7 @@ static void genOMP(lower::AbstractConverter &converter, 
lower::SymMap &symTable,
 !std::holds_alternative(clause.u) &&
 !std::holds_alternative(clause.u) &&
 !std::holds_alternative(clause.u) &&
+!std::holds_alternative(clause.u) &&
 !std::holds_alternative(clause.u) &&
 !std::holds_alternative(clause.u) &&
 !std::holds_alternative(clause.u) &&
diff --git a/flang/lib/Parser/openmp-parsers.cpp 
b/flang/lib/Parser/openmp-parsers.cpp
index 86d475c1a15422..bfd6be646a066d 100644
--- a/flang/lib/Parser/openmp-parsers.cpp
+++ b/flang/lib/Parser/openmp-parsers.cpp
@@ -597,6 +597,7 @@ TYPE_PARSER(
parenthesized(scalarIntExpr))) ||
 "NUM_THREADS" >> construct(construct(
  parenthesized(scalarIntExpr))) ||
+"OMPX_BARE" >> construct(construct()) ||
 "ORDER" >> construct(construct(
parenthesized(Parser{}))) ||
 "ORDERED" >> construct(construct(
diff --git a/llvm/include/llvm/Frontend/OpenMP/ConstructDecompositionT.h 
b/llvm/include/llvm/Frontend/OpenMP/ConstructDecompositionT.h
index 4bdfa1cf4c1490..7c0dbe1aae1221 100644
--- a/llvm/include/llvm/Frontend/OpenMP/ConstructDecompositionT.h
+++ b/llvm/include/llvm/Frontend/OpenMP/ConstructDecompositionT.h
@@ -236,6 +236,8 @@ struct ConstructDecompositionT {
const ClauseTy *);
   bool applyClause(const tomp::clause::NowaitT &clause,
const ClauseTy *);
+  bool applyClause(const tomp::clause::OmpxBareT &clause,
+   const ClauseTy *);
   bool

[clang] [flang] [llvm] [mlir] [flang][OpenMP] Add frontend support for ompx_bare clause (PR #111106)

2024-12-11 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 8eb12f6775d288eece9a2bf090d2675c025bf457 
977c8394f5f838ee360485e0e01de94aae66e23d --extensions cpp,h -- 
clang/lib/Parse/ParseOpenMP.cpp flang/lib/Lower/OpenMP/ClauseProcessor.cpp 
flang/lib/Lower/OpenMP/ClauseProcessor.h flang/lib/Lower/OpenMP/OpenMP.cpp 
flang/lib/Parser/openmp-parsers.cpp flang/lib/Semantics/check-omp-structure.cpp 
llvm/include/llvm/Frontend/OpenMP/ConstructDecompositionT.h 
mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp 
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
``





View the diff from clang-format here.


``diff
diff --git a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp 
b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
index 77454a6f35..37d2257516 100644
--- a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
+++ b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp
@@ -1714,8 +1714,8 @@ void TargetOp::build(OpBuilder &builder, OperationState 
&state,
   clauses.ifExpr, /*in_reduction_vars=*/{},
   /*in_reduction_byref=*/nullptr, 
/*in_reduction_syms=*/nullptr,
   clauses.isDevicePtrVars, clauses.mapVars, clauses.nowait,
-  clauses.privateVars,
-  makeArrayAttr(ctx, clauses.privateSyms), 
clauses.threadLimit);
+  clauses.privateVars, makeArrayAttr(ctx, clauses.privateSyms),
+  clauses.threadLimit);
 }
 
 LogicalResult TargetOp::verify() {
diff --git 
a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp 
b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
index 4da659dfe1..3122873f30 100644
--- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -158,179 +158,185 @@ static LogicalResult 
checkImplementationStatus(Operation &op) {
 if (!op.getAllocateVars().empty() || !op.getAllocatorVars().empty())
   result = todo("allocate");
   };
-  auto checkBare = [&todo](auto op, LogicalResult &result) {
-if (op.getBare()) {
-  result = todo("ompx_bare");
-  };
-  auto checkDepend = [&todo](auto op, LogicalResult &result) {
-if (!op.getDependVars().empty() || op.getDependKinds())
-  result = todo("depend");
-  };
-  auto checkDevice = [&todo](auto op, LogicalResult &result) {
-if (op.getDevice())
-  result = todo("device");
-  };
-  auto checkHasDeviceAddr = [&todo](auto op, LogicalResult &result) {
-if (!op.getHasDeviceAddrVars().empty())
-  result = todo("has_device_addr");
-  };
-  auto checkHint = [](auto op, LogicalResult &) {
-if (op.getHint())
-  op.emitWarning("hint clause discarded");
-  };
-  auto checkIf = [&todo](auto op, LogicalResult &result) {
-if (op.getIfExpr())
-  result = todo("if");
-  };
-  auto checkInReduction = [&todo](auto op, LogicalResult &result) {
-if (!op.getInReductionVars().empty() || op.getInReductionByref() ||
-op.getInReductionSyms())
-  result = todo("in_reduction");
-  };
-  auto checkIsDevicePtr = [&todo](auto op, LogicalResult &result) {
-if (!op.getIsDevicePtrVars().empty())
-  result = todo("is_device_ptr");
-  };
-  auto checkLinear = [&todo](auto op, LogicalResult &result) {
-if (!op.getLinearVars().empty() || !op.getLinearStepVars().empty())
-  result = todo("linear");
-  };
-  auto checkNontemporal = [&todo](auto op, LogicalResult &result) {
-if (!op.getNontemporalVars().empty())
-  result = todo("nontemporal");
-  };
-  auto checkNowait = [&todo](auto op, LogicalResult &result) {
-if (op.getNowait())
-  result = todo("nowait");
-  };
-  auto checkOrder = [&todo](auto op, LogicalResult &result) {
-if (op.getOrder() || op.getOrderMod())
-  result = todo("order");
-  };
-  auto checkParLevelSimd = [&todo](auto op, LogicalResult &result) {
-if (op.getParLevelSimd())
-  result = todo("parallelization-level");
-  };
-  auto checkPriority = [&todo](auto op, LogicalResult &result) {
-if (op.getPriority())
-  result = todo("priority");
-  };
-  auto checkPrivate = [&todo](auto op, LogicalResult &result) {
-if (!op.getPrivateVars().empty() || op.getPrivateSyms())
-  result = todo("privatization");
-  };
-  auto checkReduction = [&todo](auto op, LogicalResult &result) {
-if (!op.getReductionVars().empty() || op.getReductionByref() ||
-op.getReductionSyms())
-  result = todo("reduction");
-  };
-  auto checkThreadLimit = [&todo](auto op, LogicalResult &result) {
-if (op.getThreadLimit())
-  result = todo("thread_limit");
-  };
-  auto checkTaskReduction = [&todo](auto op, LogicalResult &result) {
-if (!op.getTaskReductionVars().empty() || op.getTaskReductionByref() ||
-op.getTaskReductionSyms())
-  result = todo("

[clang] [flang] [llvm] [mlir] [flang][OpenMP] Add frontend support for ompx_bare clause (PR #111106)

2024-12-11 Thread Ivan R. Ivanov via cfe-commits

https://github.com/ivanradanov updated 
https://github.com/llvm/llvm-project/pull/06

>From 85e1b6d318a4f11630588f95f964be645d6ddb9b Mon Sep 17 00:00:00 2001
From: Ivan Radanov Ivanov 
Date: Fri, 4 Oct 2024 16:20:36 +0900
Subject: [PATCH 01/16] [flang] Add frontend support for OpenMP extension bare
 clause

---
 flang/lib/Lower/OpenMP/ClauseProcessor.cpp|  4 
 flang/lib/Lower/OpenMP/ClauseProcessor.h  |  1 +
 flang/lib/Lower/OpenMP/Clauses.h  |  2 +-
 flang/lib/Lower/OpenMP/OpenMP.cpp |  2 ++
 flang/lib/Parser/openmp-parsers.cpp   |  1 +
 .../Frontend/OpenMP/ConstructDecompositionT.h |  9 +++
 llvm/include/llvm/Frontend/OpenMP/OMP.td  |  1 +
 .../mlir/Dialect/OpenMP/OpenMPClauses.td  | 24 +++
 mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td |  3 ++-
 mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp  |  2 +-
 10 files changed, 46 insertions(+), 3 deletions(-)

diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp 
b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
index 48c559a78b9bc4..99049cee3ff909 100644
--- a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
+++ b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
@@ -382,6 +382,10 @@ bool 
ClauseProcessor::processNowait(mlir::omp::NowaitClauseOps &result) const {
   return markClauseOccurrence(result.nowait);
 }
 
+bool ClauseProcessor::processBare(mlir::omp::BareClauseOps &result) const {
+  return markClauseOccurrence(result.bare);
+}
+
 bool ClauseProcessor::processNumTeams(
 lower::StatementContext &stmtCtx,
 mlir::omp::NumTeamsClauseOps &result) const {
diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.h 
b/flang/lib/Lower/OpenMP/ClauseProcessor.h
index e0fe917c50e8f8..c309da99263f13 100644
--- a/flang/lib/Lower/OpenMP/ClauseProcessor.h
+++ b/flang/lib/Lower/OpenMP/ClauseProcessor.h
@@ -73,6 +73,7 @@ class ClauseProcessor {
   bool processHint(mlir::omp::HintClauseOps &result) const;
   bool processMergeable(mlir::omp::MergeableClauseOps &result) const;
   bool processNowait(mlir::omp::NowaitClauseOps &result) const;
+  bool processBare(mlir::omp::BareClauseOps &result) const;
   bool processNumTeams(lower::StatementContext &stmtCtx,
mlir::omp::NumTeamsClauseOps &result) const;
   bool processNumThreads(lower::StatementContext &stmtCtx,
diff --git a/flang/lib/Lower/OpenMP/Clauses.h b/flang/lib/Lower/OpenMP/Clauses.h
index 65282d243d87af..e447989446a0e8 100644
--- a/flang/lib/Lower/OpenMP/Clauses.h
+++ b/flang/lib/Lower/OpenMP/Clauses.h
@@ -253,8 +253,8 @@ using NumTasks = tomp::clause::NumTasksT;
 using NumTeams = tomp::clause::NumTeamsT;
 using NumThreads = tomp::clause::NumThreadsT;
 using OmpxAttribute = tomp::clause::OmpxAttributeT;
-using OmpxBare = tomp::clause::OmpxBareT;
 using OmpxDynCgroupMem = tomp::clause::OmpxDynCgroupMemT;
+using OmpxBare = tomp::clause::OmpxBareT;
 using Ordered = tomp::clause::OrderedT;
 using Order = tomp::clause::OrderT;
 using Partial = tomp::clause::PartialT;
diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp 
b/flang/lib/Lower/OpenMP/OpenMP.cpp
index 2ef4d184a6321f..ffe5213961ef03 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -1194,6 +1194,7 @@ static void genTargetClauses(
 cp.processNowait(clauseOps);
 
   cp.processThreadLimit(stmtCtx, clauseOps);
+  cp.processBare(clauseOps);
 
   cp.processTODO(
@@ -2858,6 +2859,7 @@ static void genOMP(lower::AbstractConverter &converter, 
lower::SymMap &symTable,
 !std::holds_alternative(clause.u) &&
 !std::holds_alternative(clause.u) &&
 !std::holds_alternative(clause.u) &&
+!std::holds_alternative(clause.u) &&
 !std::holds_alternative(clause.u) &&
 !std::holds_alternative(clause.u) &&
 !std::holds_alternative(clause.u) &&
diff --git a/flang/lib/Parser/openmp-parsers.cpp 
b/flang/lib/Parser/openmp-parsers.cpp
index 86d475c1a15422..bfd6be646a066d 100644
--- a/flang/lib/Parser/openmp-parsers.cpp
+++ b/flang/lib/Parser/openmp-parsers.cpp
@@ -597,6 +597,7 @@ TYPE_PARSER(
parenthesized(scalarIntExpr))) ||
 "NUM_THREADS" >> construct(construct(
  parenthesized(scalarIntExpr))) ||
+"OMPX_BARE" >> construct(construct()) ||
 "ORDER" >> construct(construct(
parenthesized(Parser{}))) ||
 "ORDERED" >> construct(construct(
diff --git a/llvm/include/llvm/Frontend/OpenMP/ConstructDecompositionT.h 
b/llvm/include/llvm/Frontend/OpenMP/ConstructDecompositionT.h
index 4bdfa1cf4c1490..7c0dbe1aae1221 100644
--- a/llvm/include/llvm/Frontend/OpenMP/ConstructDecompositionT.h
+++ b/llvm/include/llvm/Frontend/OpenMP/ConstructDecompositionT.h
@@ -236,6 +236,8 @@ struct ConstructDecompositionT {
const ClauseTy *);
   bool applyClause(const tomp::clause::NowaitT &clause,
const ClauseTy *);
+  bool applyClause(const tomp::clause::OmpxBareT &clause,
+   const ClauseTy *);
   bool

[clang] [llvm] [MTE] Apply alignment / size in AsmPrinter rather than IR (PR #111918)

2024-12-11 Thread Florian Mayer via cfe-commits

https://github.com/fmayer updated 
https://github.com/llvm/llvm-project/pull/111918

>From 3a962270521aa7b48b64e5ac5fa0edb900990023 Mon Sep 17 00:00:00 2001
From: Florian Mayer 
Date: Thu, 10 Oct 2024 16:05:50 -0700
Subject: [PATCH 1/5] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 clang/lib/CodeGen/SanitizerMetadata.cpp   |  45 -
 llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp|   7 +-
 llvm/lib/Target/AArch64/AArch64.h |   2 -
 .../Target/AArch64/AArch64GlobalsTagging.cpp  | 155 --
 .../Target/AArch64/AArch64TargetMachine.cpp   |   2 -
 llvm/lib/Target/AArch64/CMakeLists.txt|   1 -
 .../llvm/lib/Target/AArch64/BUILD.gn  |   1 -
 7 files changed, 46 insertions(+), 167 deletions(-)
 delete mode 100644 llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp

diff --git a/clang/lib/CodeGen/SanitizerMetadata.cpp 
b/clang/lib/CodeGen/SanitizerMetadata.cpp
index 5b212a163611dc..784d9061647f5c 100644
--- a/clang/lib/CodeGen/SanitizerMetadata.cpp
+++ b/clang/lib/CodeGen/SanitizerMetadata.cpp
@@ -34,6 +34,37 @@ static SanitizerMask 
expandKernelSanitizerMasks(SanitizerMask Mask) {
   return Mask;
 }
 
+static bool shouldTagGlobal(const llvm::GlobalVariable &G) {
+  // For now, don't instrument constant data, as it'll be in .rodata anyway. It
+  // may be worth instrumenting these in future to stop them from being used as
+  // gadgets.
+  if (G.getName().starts_with("llvm.") || G.isThreadLocal() || G.isConstant())
+return false;
+
+  // Globals can be placed implicitly or explicitly in sections. There's two
+  // different types of globals that meet this criteria that cause problems:
+  //  1. Function pointers that are going into various init arrays (either
+  // explicitly through `__attribute__((section()))` or implicitly
+  // through `__attribute__((constructor)))`, such as ".(pre)init(_array)",
+  // ".fini(_array)", ".ctors", and ".dtors". These function pointers end 
up
+  // overaligned and overpadded, making iterating over them problematic, 
and
+  // each function pointer is individually tagged (so the iteration over
+  // them causes SIGSEGV/MTE[AS]ERR).
+  //  2. Global variables put into an explicit section, where the section's 
name
+  // is a valid C-style identifier. The linker emits a `__start_` and
+  // `__stop_` symbol for the section, so that you can iterate over
+  // globals within this section. Unfortunately, again, these globals would
+  // be tagged and so iteration causes SIGSEGV/MTE[AS]ERR.
+  //
+  // To mitigate both these cases, and because specifying a section is rare
+  // outside of these two cases, disable MTE protection for globals in any
+  // section.
+  if (G.hasSection())
+return false;
+
+  return true;
+}
+
 void SanitizerMetadata::reportGlobal(llvm::GlobalVariable *GV,
  SourceLocation Loc, StringRef Name,
  QualType Ty,
@@ -60,11 +91,15 @@ void SanitizerMetadata::reportGlobal(llvm::GlobalVariable 
*GV,
   Meta.NoHWAddress |= CGM.isInNoSanitizeList(
   FsanitizeArgument.Mask & SanitizerKind::HWAddress, GV, Loc, Ty);
 
-  Meta.Memtag |=
-  static_cast(FsanitizeArgument.Mask & SanitizerKind::MemtagGlobals);
-  Meta.Memtag &= !NoSanitizeAttrSet.hasOneOf(SanitizerKind::MemTag);
-  Meta.Memtag &= !CGM.isInNoSanitizeList(
-  FsanitizeArgument.Mask & SanitizerKind::MemTag, GV, Loc, Ty);
+  if (shouldTagGlobal(*GV)) {
+Meta.Memtag |=
+static_cast(FsanitizeArgument.Mask & 
SanitizerKind::MemtagGlobals);
+Meta.Memtag &= !NoSanitizeAttrSet.hasOneOf(SanitizerKind::MemTag);
+Meta.Memtag &= !CGM.isInNoSanitizeList(
+FsanitizeArgument.Mask & SanitizerKind::MemTag, GV, Loc, Ty);
+  } else {
+Meta.Memtag = false;
+  }
 
   Meta.IsDynInit = IsDynInit && !Meta.NoAddress &&
FsanitizeArgument.has(SanitizerKind::Address) &&
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp 
b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 3a8cde7330efc0..6a2817f417d30d 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -764,11 +764,16 @@ void AsmPrinter::emitGlobalVariable(const GlobalVariable 
*GV) {
 
   const DataLayout &DL = GV->getDataLayout();
   uint64_t Size = DL.getTypeAllocSize(GV->getValueType());
+  if (GV->isTagged()) Size = alignTo(Size, 16);
 
   // If the alignment is specified, we *must* obey it.  Overaligning a global
   // with a specified alignment is a prompt way to break globals emitted to
   // sections and expected to be contiguous (e.g. ObjC metadata).
-  const Align Alignment = getGVAlignment(GV, DL);
+  Align Alignment = getGVAlignment(GV, DL);
+  if (GV->isTagged() && Alignment < 16) {
+assert(!GV->hasSection());
+Alignment = Al

[clang] 04379c9 - [SystemZ][z/OS] Update autoconversion functions to improve support for UTF-8 (#98652)

2024-12-11 Thread via cfe-commits

Author: Abhina Sree
Date: 2024-12-11T07:46:51-05:00
New Revision: 04379c98638ac3901257b5fa319f9ece828af767

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

LOG: [SystemZ][z/OS] Update autoconversion functions to improve support for 
UTF-8 (#98652)

This fixes the following error when reading source and header files on
z/OS: error: source file is not valid UTF-8

Added: 


Modified: 
clang/include/clang/Basic/FileEntry.h
clang/lib/Basic/SourceManager.cpp
llvm/include/llvm/Support/AutoConvert.h
llvm/lib/Support/AutoConvert.cpp
llvm/lib/Support/MemoryBuffer.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/FileEntry.h 
b/clang/include/clang/Basic/FileEntry.h
index 68d4bf60930037..ba6dfa69f214d8 100644
--- a/clang/include/clang/Basic/FileEntry.h
+++ b/clang/include/clang/Basic/FileEntry.h
@@ -70,6 +70,11 @@ class FileEntryRef {
   const FileEntry &getFileEntry() const {
 return *getBaseMapEntry().second->V.get();
   }
+
+  // This function is used if the buffer size needs to be increased
+  // due to potential z/OS EBCDIC -> UTF-8 conversion
+  inline void updateFileEntryBufferSize(unsigned BufferSize);
+
   DirectoryEntryRef getDir() const { return ME->second->Dir; }
 
   inline off_t getSize() const;
@@ -323,6 +328,8 @@ class FileEntry {
 
   StringRef tryGetRealPathName() const { return RealPathName; }
   off_t getSize() const { return Size; }
+  // Size may increase due to potential z/OS EBCDIC -> UTF-8 conversion.
+  void setSize(off_t NewSize) { Size = NewSize; }
   unsigned getUID() const { return UID; }
   const llvm::sys::fs::UniqueID &getUniqueID() const { return UniqueID; }
   time_t getModificationTime() const { return ModTime; }
@@ -353,6 +360,10 @@ bool FileEntryRef::isNamedPipe() const { return 
getFileEntry().isNamedPipe(); }
 
 void FileEntryRef::closeFile() const { getFileEntry().closeFile(); }
 
+void FileEntryRef::updateFileEntryBufferSize(unsigned BufferSize) {
+  getBaseMapEntry().second->V.get()->setSize(BufferSize);
+}
+
 } // end namespace clang
 
 #endif // LLVM_CLANG_BASIC_FILEENTRY_H

diff  --git a/clang/lib/Basic/SourceManager.cpp 
b/clang/lib/Basic/SourceManager.cpp
index 6e588ce63d813f..849c18f171f6e1 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -24,6 +24,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/Allocator.h"
+#include "llvm/Support/AutoConvert.h"
 #include "llvm/Support/Capacity.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/Endian.h"
@@ -156,8 +157,11 @@ ContentCache::getBufferOrNone(DiagnosticsEngine &Diag, 
FileManager &FM,
   // Unless this is a named pipe (in which case we can handle a mismatch),
   // check that the file's size is the same as in the file entry (which may
   // have come from a stat cache).
+  // The buffer will always be larger than the file size on z/OS in the 
presence
+  // of characters outside the base character set.
+  assert(Buffer->getBufferSize() >= (size_t)ContentsEntry->getSize());
   if (!ContentsEntry->isNamedPipe() &&
-  Buffer->getBufferSize() != (size_t)ContentsEntry->getSize()) {
+  Buffer->getBufferSize() < (size_t)ContentsEntry->getSize()) {
 Diag.Report(Loc, diag::err_file_modified) << ContentsEntry->getName();
 
 return std::nullopt;
@@ -583,6 +587,18 @@ SourceManager::getOrCreateFileID(FileEntryRef SourceFile,
  FileCharacter);
 }
 
+/// Helper function to determine if an input file requires conversion
+bool needConversion(StringRef Filename) {
+#ifdef __MVS__
+  llvm::ErrorOr NeedConversion =
+  llvm::needzOSConversion(Filename.str().c_str());
+  assert(NeedConversion && "Filename was not found");
+  return *NeedConversion;
+#else
+  return false;
+#endif
+}
+
 /// createFileID - Create a new FileID for the specified ContentCache and
 /// include position.  This works regardless of whether the ContentCache
 /// corresponds to a file or some other input source.
@@ -602,6 +618,20 @@ FileID SourceManager::createFileIDImpl(ContentCache &File, 
StringRef Filename,
 return FileID::get(LoadedID);
   }
   unsigned FileSize = File.getSize();
+  bool NeedConversion = needConversion(Filename);
+  if (NeedConversion) {
+// Buffer size may increase due to potential z/OS EBCDIC to UTF-8
+// conversion.
+if (std::optional Buffer =
+File.getBufferOrNone(Diag, getFileManager())) {
+  unsigned BufSize = Buffer->getBufferSize();
+  if (BufSize > FileSize) {
+if (File.ContentsEntry.has_value())
+  File.ContentsEntry->updateFileEntryBufferSize(BufSize);
+FileSize = BufSize;
+  }
+}
+  }
   if (!(NextLocalOffset + FileSize + 1 > NextLocalOffset &&
 

[clang] [llvm] [SystemZ][z/OS] Update autoconversion functions to improve support for UTF-8 (PR #98652)

2024-12-11 Thread Abhina Sree via cfe-commits

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


[clang] [analyzer] Handle [[assume(cond)]] as __builtin_assume(cond) (PR #116462)

2024-12-11 Thread Vinay Deshmukh via cfe-commits

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


[clang] [clang][bytecode][NFC] Use Pointer::pointToSameBlock (PR #119552)

2024-12-11 Thread Timm Baeder via cfe-commits

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

block() requires the pointer to be a block pointer.

>From 254b9ed55904777931f666a30110fd356c595243 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Wed, 11 Dec 2024 13:52:02 +0100
Subject: [PATCH] [clang][bytecode][NFC] Use Pointer::pointToSameBlock

block() requires the pointer to be a block pointer.
---
 clang/lib/AST/ByteCode/InterpBuiltin.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 4fe17ec01906e9..57175da32b31cd 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -1876,7 +1876,7 @@ static bool interp__builtin_memcpy(InterpState &S, 
CodePtr OpPC,
   }
 
   // Check for overlapping memory regions.
-  if (!Move && SrcPtr.block() == DestPtr.block()) {
+  if (!Move && Pointer::pointToSameBlock(SrcPtr, DestPtr)) {
 unsigned SrcIndex = SrcPtr.getIndex() * SrcPtr.elemSize();
 unsigned DstIndex = DestPtr.getIndex() * DestPtr.elemSize();
 unsigned N = Size.getZExtValue();

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


[clang] [clang][bytecode][NFC] Use Pointer::pointToSameBlock (PR #119552)

2024-12-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

block() requires the pointer to be a block pointer.

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


1 Files Affected:

- (modified) clang/lib/AST/ByteCode/InterpBuiltin.cpp (+1-1) 


``diff
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 4fe17ec01906e9..57175da32b31cd 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -1876,7 +1876,7 @@ static bool interp__builtin_memcpy(InterpState &S, 
CodePtr OpPC,
   }
 
   // Check for overlapping memory regions.
-  if (!Move && SrcPtr.block() == DestPtr.block()) {
+  if (!Move && Pointer::pointToSameBlock(SrcPtr, DestPtr)) {
 unsigned SrcIndex = SrcPtr.getIndex() * SrcPtr.elemSize();
 unsigned DstIndex = DestPtr.getIndex() * DestPtr.elemSize();
 unsigned N = Size.getZExtValue();

``




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


[clang] [llvm] [MTE] Apply alignment / size in AsmPrinter rather than IR (PR #111918)

2024-12-11 Thread Florian Mayer via cfe-commits

https://github.com/fmayer updated 
https://github.com/llvm/llvm-project/pull/111918

>From 3a962270521aa7b48b64e5ac5fa0edb900990023 Mon Sep 17 00:00:00 2001
From: Florian Mayer 
Date: Thu, 10 Oct 2024 16:05:50 -0700
Subject: [PATCH 1/5] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 clang/lib/CodeGen/SanitizerMetadata.cpp   |  45 -
 llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp|   7 +-
 llvm/lib/Target/AArch64/AArch64.h |   2 -
 .../Target/AArch64/AArch64GlobalsTagging.cpp  | 155 --
 .../Target/AArch64/AArch64TargetMachine.cpp   |   2 -
 llvm/lib/Target/AArch64/CMakeLists.txt|   1 -
 .../llvm/lib/Target/AArch64/BUILD.gn  |   1 -
 7 files changed, 46 insertions(+), 167 deletions(-)
 delete mode 100644 llvm/lib/Target/AArch64/AArch64GlobalsTagging.cpp

diff --git a/clang/lib/CodeGen/SanitizerMetadata.cpp 
b/clang/lib/CodeGen/SanitizerMetadata.cpp
index 5b212a163611dc..784d9061647f5c 100644
--- a/clang/lib/CodeGen/SanitizerMetadata.cpp
+++ b/clang/lib/CodeGen/SanitizerMetadata.cpp
@@ -34,6 +34,37 @@ static SanitizerMask 
expandKernelSanitizerMasks(SanitizerMask Mask) {
   return Mask;
 }
 
+static bool shouldTagGlobal(const llvm::GlobalVariable &G) {
+  // For now, don't instrument constant data, as it'll be in .rodata anyway. It
+  // may be worth instrumenting these in future to stop them from being used as
+  // gadgets.
+  if (G.getName().starts_with("llvm.") || G.isThreadLocal() || G.isConstant())
+return false;
+
+  // Globals can be placed implicitly or explicitly in sections. There's two
+  // different types of globals that meet this criteria that cause problems:
+  //  1. Function pointers that are going into various init arrays (either
+  // explicitly through `__attribute__((section()))` or implicitly
+  // through `__attribute__((constructor)))`, such as ".(pre)init(_array)",
+  // ".fini(_array)", ".ctors", and ".dtors". These function pointers end 
up
+  // overaligned and overpadded, making iterating over them problematic, 
and
+  // each function pointer is individually tagged (so the iteration over
+  // them causes SIGSEGV/MTE[AS]ERR).
+  //  2. Global variables put into an explicit section, where the section's 
name
+  // is a valid C-style identifier. The linker emits a `__start_` and
+  // `__stop_` symbol for the section, so that you can iterate over
+  // globals within this section. Unfortunately, again, these globals would
+  // be tagged and so iteration causes SIGSEGV/MTE[AS]ERR.
+  //
+  // To mitigate both these cases, and because specifying a section is rare
+  // outside of these two cases, disable MTE protection for globals in any
+  // section.
+  if (G.hasSection())
+return false;
+
+  return true;
+}
+
 void SanitizerMetadata::reportGlobal(llvm::GlobalVariable *GV,
  SourceLocation Loc, StringRef Name,
  QualType Ty,
@@ -60,11 +91,15 @@ void SanitizerMetadata::reportGlobal(llvm::GlobalVariable 
*GV,
   Meta.NoHWAddress |= CGM.isInNoSanitizeList(
   FsanitizeArgument.Mask & SanitizerKind::HWAddress, GV, Loc, Ty);
 
-  Meta.Memtag |=
-  static_cast(FsanitizeArgument.Mask & SanitizerKind::MemtagGlobals);
-  Meta.Memtag &= !NoSanitizeAttrSet.hasOneOf(SanitizerKind::MemTag);
-  Meta.Memtag &= !CGM.isInNoSanitizeList(
-  FsanitizeArgument.Mask & SanitizerKind::MemTag, GV, Loc, Ty);
+  if (shouldTagGlobal(*GV)) {
+Meta.Memtag |=
+static_cast(FsanitizeArgument.Mask & 
SanitizerKind::MemtagGlobals);
+Meta.Memtag &= !NoSanitizeAttrSet.hasOneOf(SanitizerKind::MemTag);
+Meta.Memtag &= !CGM.isInNoSanitizeList(
+FsanitizeArgument.Mask & SanitizerKind::MemTag, GV, Loc, Ty);
+  } else {
+Meta.Memtag = false;
+  }
 
   Meta.IsDynInit = IsDynInit && !Meta.NoAddress &&
FsanitizeArgument.has(SanitizerKind::Address) &&
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp 
b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 3a8cde7330efc0..6a2817f417d30d 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -764,11 +764,16 @@ void AsmPrinter::emitGlobalVariable(const GlobalVariable 
*GV) {
 
   const DataLayout &DL = GV->getDataLayout();
   uint64_t Size = DL.getTypeAllocSize(GV->getValueType());
+  if (GV->isTagged()) Size = alignTo(Size, 16);
 
   // If the alignment is specified, we *must* obey it.  Overaligning a global
   // with a specified alignment is a prompt way to break globals emitted to
   // sections and expected to be contiguous (e.g. ObjC metadata).
-  const Align Alignment = getGVAlignment(GV, DL);
+  Align Alignment = getGVAlignment(GV, DL);
+  if (GV->isTagged() && Alignment < 16) {
+assert(!GV->hasSection());
+Alignment = Al

[clang] [llvm] [MTE] Apply alignment / size in AsmPrinter rather than IR (PR #111918)

2024-12-11 Thread Florian Mayer via cfe-commits

fmayer wrote:

sorry, messed up the upload

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


[clang] [clang-tools-extra] [llvm] [MTE] Apply alignment / size in AsmPrinter rather than IR (PR #111918)

2024-12-11 Thread Florian Mayer via cfe-commits

https://github.com/fmayer updated 
https://github.com/llvm/llvm-project/pull/111918

error: too big or took too long to generate
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Switch builtin strings to use string tables (PR #118734)

2024-12-11 Thread via cfe-commits

dyung wrote:

No real updates here, but our internal builder did catch up to this commit and 
we are seeing the same (and a lot more) failures when this commit is merged 
into our downstream codebase. I was kind of hoping that it would pass so that 
it might indicate that the problem might be a configuration issue with our 
upstream build bot, but the fact that it fails in a similar manner likely 
points to some kind of bug in the version of MSVC that we are using.

@chandlerc could we consider reverting the change until we can figure out what 
the problem is? I will continue to take a look into it, but I don't really have 
any ideas what might be the cause at the moment, so have no ETA on a 
work-around, and in the meantime, this will continue to cause test failures for 
us internally.

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


[clang-tools-extra] [clang-tidy]detecting conversion directly by `make_unique` and `make_shared` in bugprone-optional-value-conversion (PR #119371)

2024-12-11 Thread Congcong Cai via cfe-commits

HerrCai0907 wrote:

> Note: Probably also std::make_optional could be supported.

I will do it in separated PR since std::make_optional is more complex stuff. 
see #119554

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


[clang-tools-extra] [clang-tidy]detecting conversion directly by `make_unique` and `make_shared` in bugprone-optional-value-conversion (PR #119371)

2024-12-11 Thread Congcong Cai via cfe-commits

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

>From 526e79fc6e15c7a72ed3867afbee3cbc747c7945 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Tue, 10 Dec 2024 20:44:12 +0800
Subject: [PATCH 1/2] [clang-tidy]detecting conversion directly by
 `make_unique` and `make_shared` in bugprone-optional-value-conversion

Inspired by #110964
---
 .../bugprone/OptionalValueConversionCheck.cpp | 37 ++---
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 ++
 ...al-value-conversion-construct-from-std.cpp | 53 +++
 3 files changed, 86 insertions(+), 8 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/optional-value-conversion-construct-from-std.cpp

diff --git 
a/clang-tools-extra/clang-tidy/bugprone/OptionalValueConversionCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/OptionalValueConversionCheck.cpp
index f2ff27d85fb004..0ed8c8d00f4222 100644
--- a/clang-tools-extra/clang-tidy/bugprone/OptionalValueConversionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/OptionalValueConversionCheck.cpp
@@ -12,20 +12,44 @@
 #include "../utils/OptionsUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include 
 
 using namespace clang::ast_matchers;
+using clang::ast_matchers::internal::Matcher;
 
 namespace clang::tidy::bugprone {
 
 namespace {
 
-AST_MATCHER_P(QualType, hasCleanType, 
ast_matchers::internal::Matcher,
-  InnerMatcher) {
+AST_MATCHER_P(QualType, hasCleanType, Matcher, InnerMatcher) {
   return InnerMatcher.matches(
   Node.getNonReferenceType().getUnqualifiedType().getCanonicalType(),
   Finder, Builder);
 }
 
+AST_MATCHER_P2(Expr, constructFrom, Matcher, TypeMatcher,
+   Matcher, ArgumentMatcher) {
+  std::array NameList{
+  "::std::make_unique",
+  "::std::make_shared",
+  };
+  return expr(anyOf(
+  // construct optional
+  cxxConstructExpr(argumentCountIs(1U), hasType(TypeMatcher),
+   hasArgument(0U, ArgumentMatcher)),
+  // known template methods in std
+  callExpr(
+  argumentCountIs(1),
+  callee(functionDecl(
+  matchers::matchesAnyListedName(NameList),
+  hasTemplateArgument(0, refersToType(TypeMatcher,
+  hasArgument(0, ArgumentMatcher))),
+  unless(
+  anyOf(hasAncestor(typeLoc()),
+hasAncestor(expr(matchers::hasUnevaluatedContext())
+  .matches(Node, Finder, Builder);
+}
+
 } // namespace
 
 OptionalValueConversionCheck::OptionalValueConversionCheck(
@@ -67,12 +91,9 @@ void 
OptionalValueConversionCheck::registerMatchers(MatchFinder *Finder) {
   callExpr(argumentCountIs(1), 
callee(functionDecl(hasName("::std::move"))),
hasArgument(0, ignoringImpCasts(OptionalDereferenceMatcher)));
   Finder->addMatcher(
-  cxxConstructExpr(
-  argumentCountIs(1U), hasType(BindOptionalType),
-  hasArgument(0U, ignoringImpCasts(anyOf(OptionalDereferenceMatcher,
- StdMoveCallMatcher))),
-  unless(anyOf(hasAncestor(typeLoc()),
-   hasAncestor(expr(matchers::hasUnevaluatedContext())
+  expr(constructFrom(BindOptionalType,
+ ignoringImpCasts(anyOf(OptionalDereferenceMatcher,
+StdMoveCallMatcher
   .bind("expr"),
   this);
 }
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index b2b66dca6ccf85..9c499159b73c7b 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -176,6 +176,10 @@ Changes in existing checks
   ` check by fixing
   a crash when determining if an ``enable_if[_t]`` was found.
 
+- Improved :doc:`bugprone-optional-value-conversion
+  ` to support detecting
+  conversion directly by ``std::make_unique`` and ``std::make_shared``.
+
 - Improved :doc:`bugprone-posix-return
   ` check to support integer literals
   as LHS and posix call as RHS of comparison.
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/optional-value-conversion-construct-from-std.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/optional-value-conversion-construct-from-std.cpp
new file mode 100644
index 00..768ab1ce014cec
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/optional-value-conversion-construct-from-std.cpp
@@ -0,0 +1,53 @@
+// RUN: %check_clang_tidy -std=c++17-or-later %s 
bugprone-optional-value-conversion %t
+
+namespace std {
+template  struct optional {
+  constexpr optional() noexcept;
+  constexpr optional(T &&) noexcept;
+  constexpr optional(const T &) noexcept;
+  template  constexpr optional(U &&) noexcept;

[clang] [clang] Fix the post-filtering heuristic for GSLPointer. (PR #114044)

2024-12-11 Thread Haojian Wu via cfe-commits

https://github.com/hokein updated 
https://github.com/llvm/llvm-project/pull/114044

>From 75a8bd038d6ba68eb70136c0be9ad66fac0c181f Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Fri, 1 Nov 2024 16:51:03 +0100
Subject: [PATCH 1/6] [clang] Fix the post-filtering heuristics for GSLPointer
 case.

---
 clang/docs/ReleaseNotes.rst   |   2 +
 clang/lib/Sema/CheckExprLifetime.cpp  | 113 ++
 .../Sema/warn-lifetime-analysis-nocfg.cpp |  48 +++-
 3 files changed, 139 insertions(+), 24 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a541d399d1e749..25de0cfd72eaaf 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -612,6 +612,8 @@ Improvements to Clang's diagnostics
 
 - Clang now diagnoses ``[[deprecated]]`` attribute usage on local variables 
(#GH90073).
 
+- Fix false positives when `[[gsl::Owner/Pointer]]` and 
`[[clang::lifetimebound]]` are used together.
+
 - Improved diagnostic message for ``__builtin_bit_cast`` size mismatch 
(#GH115870).
 
 - Clang now omits shadow warnings for enum constants in separate class scopes 
(#GH62588).
diff --git a/clang/lib/Sema/CheckExprLifetime.cpp 
b/clang/lib/Sema/CheckExprLifetime.cpp
index 868081292bc32c..07610f243f9169 100644
--- a/clang/lib/Sema/CheckExprLifetime.cpp
+++ b/clang/lib/Sema/CheckExprLifetime.cpp
@@ -1152,6 +1152,87 @@ static bool pathOnlyHandlesGslPointer(const 
IndirectLocalPath &Path) {
   }
   return false;
 }
+// Result of analyzing the Path for GSLPointer.
+enum AnalysisResult {
+  // Path does not correspond to a GSLPointer.
+  NotGSLPointer,
+
+  // A relevant case was identified.
+  Report,
+  // Stop the entire traversal.
+  Abandon,
+  // Skip this step and continue traversing inner AST nodes.
+  Skip,
+};
+// Analyze cases where a GSLPointer is initialized or assigned from a
+// temporary owner object.
+static AnalysisResult analyzePathForGSLPointer(const IndirectLocalPath &Path,
+   Local L) {
+  if (!pathOnlyHandlesGslPointer(Path))
+return NotGSLPointer;
+
+  // At this point, Path represents a series of operations involving a
+  // GSLPointer, either in the process of initialization or assignment.
+
+  // Note: A LifetimeBoundCall can appear interleaved in this sequence.
+  // For example:
+  //const std::string& Ref(const std::string& a [[clang::lifetimebound]]);
+  //string_view abc = Ref(std::string());
+  // The "Path" is [GSLPointerInit, LifetimeboundCall], where "L" is the
+  // temporary "std::string()" object. We need to check if the function with 
the
+  // lifetimebound attribute returns a "owner" type.
+  if (Path.back().Kind == IndirectLocalPathEntry::LifetimeBoundCall) {
+// The lifetimebound applies to the implicit object parameter of a method.
+if (const auto *Method = llvm::dyn_cast(Path.back().D)) {
+  if (Method->getReturnType()->isReferenceType() &&
+  isRecordWithAttr(
+  Method->getReturnType()->getPointeeType()))
+return Report;
+  return Abandon;
+}
+// The lifetimebound applies to a function parameter.
+const auto *PD = llvm::dyn_cast(Path.back().D);
+if (const auto *FD = llvm::dyn_cast(PD->getDeclContext())) {
+  if (isa(FD)) {
+// Constructor case: the parameter is annotated with lifetimebound
+//   e.g., GSLPointer(const S& s [[clang::lifetimebound]])
+// We still respect this case even the type S is not an owner.
+return Report;
+  }
+  // For regular functions, check if the return type has an Owner 
attribute.
+  //   e.g., const GSLOwner& func(const Foo& foo [[clang::lifetimebound]])
+  if (FD->getReturnType()->isReferenceType() &&
+  isRecordWithAttr(FD->getReturnType()->getPointeeType()))
+return Report;
+}
+return Abandon;
+  }
+
+  if (isa(L)) {
+// We do not want to follow the references when returning a pointer
+// originating from a local owner to avoid the following false positive:
+//   int &p = *localUniquePtr;
+//   someContainer.add(std::move(localUniquePtr));
+//   return p;
+if (!pathContainsInit(Path) && isRecordWithAttr(L->getType()))
+  return Report;
+return Abandon;
+  }
+
+  // The GSLPointer is from a temporary object.
+  auto *MTE = dyn_cast(L);
+
+  bool IsGslPtrValueFromGslTempOwner =
+  MTE && !MTE->getExtendingDecl() &&
+  isRecordWithAttr(MTE->getType());
+  // Skipping a chain of initializing gsl::Pointer annotated objects.
+  // We are looking only for the final source to find out if it was
+  // a local or temporary owner or the address of a local
+  // variable/param.
+  if (!IsGslPtrValueFromGslTempOwner)
+return Skip;
+  return Report;
+}
 
 static bool isAssignmentOperatorLifetimeBound(CXXMethodDecl *CMD) {
   return CMD && isNormalAssignmentOperator(CMD) && CMD->param_size() == 1 &&
@@ -1189,27 +1270,17 @@ checkExprLifetimeImpl(S

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

2024-12-11 Thread Victor Campos via cfe-commits

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

>From 3914f0f5afbc8549dbc3557b70abb21f96be2db7 Mon Sep 17 00:00:00 2001
From: Victor Campos 
Date: Thu, 26 Sep 2024 14:43:18 +0100
Subject: [PATCH 1/2] [Multilib] Custom flags YAML parsing

This patch adds support for custom flags in the multilib YAML file.

Details about this change can be found in:
https://discourse.llvm.org/t/rfc-multilib-custom-flags/81058

CustomFlagDeclaration objects are instantiated using shared_ptr. This is
motivated by the fact that each custom flag value,
CustomFlagValueDetail, contains a back reference to their corresponding
flag declaration.

Since the CustomFlagDeclaration objects are transferred from the YAML
parser to the MultilibSet instance after the parsing is finished, back
references implemented as raw pointers would become dangling. This would
need to be remediated in the copy/move constructors by updating the
pointer.

Therefore it's just simpler and less error-prone to have all references
to CustomFlagDeclaration, including the back reference, as shared_ptr.
This way dangling pointers are not a concern.
---
 clang/include/clang/Driver/Multilib.h |  28 +++-
 clang/lib/Driver/Multilib.cpp |  73 --
 ...remetal-multilib-custom-flags-parsing.yaml | 133 ++
 3 files changed, 223 insertions(+), 11 deletions(-)
 create mode 100644 
clang/test/Driver/baremetal-multilib-custom-flags-parsing.yaml

diff --git a/clang/include/clang/Driver/Multilib.h 
b/clang/include/clang/Driver/Multilib.h
index dbed70f4f9008f..69d0b9b31714ff 100644
--- a/clang/include/clang/Driver/Multilib.h
+++ b/clang/include/clang/Driver/Multilib.h
@@ -101,6 +101,25 @@ class Multilib {
 
 raw_ostream &operator<<(raw_ostream &OS, const Multilib &M);
 
+namespace custom_flag {
+struct Declaration;
+using DeclarationPtr = std::shared_ptr;
+
+struct ValueDetail {
+  std::string Name;
+  std::optional> DriverArgs;
+  DeclarationPtr Decl;
+};
+
+struct Declaration {
+  std::string Name;
+  SmallVector ValueList;
+  std::optional DefaultValueIdx;
+};
+
+static constexpr StringRef Prefix = "-fmultilib-flag=";
+} // namespace custom_flag
+
 /// See also MultilibSetBuilder for combining multilibs into a set.
 class MultilibSet {
 public:
@@ -120,15 +139,18 @@ class MultilibSet {
 
 private:
   multilib_list Multilibs;
-  std::vector FlagMatchers;
+  SmallVector FlagMatchers;
+  SmallVector CustomFlagDecls;
   IncludeDirsFunc IncludeCallback;
   IncludeDirsFunc FilePathsCallback;
 
 public:
   MultilibSet() = default;
   MultilibSet(multilib_list &&Multilibs,
-  std::vector &&FlagMatchers = {})
-  : Multilibs(Multilibs), FlagMatchers(FlagMatchers) {}
+  SmallVector &&FlagMatchers = {},
+  SmallVector &&CustomFlagDecls = {})
+  : Multilibs(std::move(Multilibs)), FlagMatchers(std::move(FlagMatchers)),
+CustomFlagDecls(std::move(CustomFlagDecls)) {}
 
   const multilib_list &getMultilibs() { return Multilibs; }
 
diff --git a/clang/lib/Driver/Multilib.cpp b/clang/lib/Driver/Multilib.cpp
index 0207e0f2eb2ded..0d7d590a0eed8b 100644
--- a/clang/lib/Driver/Multilib.cpp
+++ b/clang/lib/Driver/Multilib.cpp
@@ -10,6 +10,7 @@
 #include "clang/Basic/LLVM.h"
 #include "clang/Driver/Driver.h"
 #include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -201,13 +202,20 @@ struct MultilibGroupSerialization {
 
 struct MultilibSetSerialization {
   llvm::VersionTuple MultilibVersion;
-  std::vector Groups;
-  std::vector Multilibs;
-  std::vector FlagMatchers;
+  SmallVector Groups;
+  SmallVector Multilibs;
+  SmallVector FlagMatchers;
+  SmallVector CustomFlagDeclarations;
 };
 
 } // end anonymous namespace
 
+LLVM_YAML_IS_SEQUENCE_VECTOR(MultilibSerialization)
+LLVM_YAML_IS_SEQUENCE_VECTOR(MultilibGroupSerialization)
+LLVM_YAML_IS_SEQUENCE_VECTOR(MultilibSet::FlagMatcher)
+LLVM_YAML_IS_SEQUENCE_VECTOR(custom_flag::ValueDetail)
+LLVM_YAML_IS_SEQUENCE_VECTOR(custom_flag::DeclarationPtr)
+
 template <> struct llvm::yaml::MappingTraits {
   static void mapping(llvm::yaml::IO &io, MultilibSerialization &V) {
 io.mapOptional("Dir", V.Dir);
@@ -255,11 +263,63 @@ template <> struct 
llvm::yaml::MappingTraits {
   }
 };
 
+template <>
+struct llvm::yaml::MappingContextTraits> {
+  static void mapping(llvm::yaml::IO &io, custom_flag::ValueDetail &V,
+  llvm::SmallSet &) {
+io.mapRequired("Name", V.Name);
+io.mapOptional("DriverArgs", V.DriverArgs);
+  }
+  static std::string validate(IO &io, custom_flag::ValueDetail &V,
+  llvm::SmallSet &NameSet) {
+if (V.Name.empty())
+  return "custom flag value requires a name";
+if (!NameSet.insert(V.Name).second)
+  return "duplicate custom flag value name: \"" + V.Name + "\"";
+return {};
+  }
+};
+
+template <>
+struct llvm

[clang] [llvm] [AArch64] Implement FP8 SVE Intrinsics for narrowing conversions (PR #118124)

2024-12-11 Thread Momchil Velikov via cfe-commits

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


[clang] b1d8c60 - [AArch64] Implement FP8 SVE Intrinsics for narrowing conversions (#118124)

2024-12-11 Thread via cfe-commits

Author: Momchil Velikov
Date: 2024-12-11T13:37:15Z
New Revision: b1d8c60dd479d9c5d58bcfe33db57b68f834938d

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

LOG: [AArch64] Implement FP8 SVE Intrinsics for narrowing conversions (#118124)

This patch adds the following instrinsics:

* Half-precision and BFloat16 convert, narrow, and interleave to 8-bit
floating-point.

  // Variant is also available for: _bf16_x2
  svmfloat8_t svcvtn_mf8[_f16_x2]_fpm(svfloat16x2_t zn, fpm_t fpm);

* Single-precision convert, narrow, and interleave to 8-bit
floating-point (top and bottom).

svmfloat8_t svcvtnt_mf8[_f32_x2]_fpm(svmfloat8_t zd, svfloat32x2_t zn,
fpm_t fpm);
  svmfloat8_t svcvtnb_mf8[_f32_x2]_fpm(svfloat32x2_t zn, fpm_t fpm);

Added: 
clang/test/CodeGen/AArch64/fp8-intrinsics/acle_sve2_fp8_cvtn.c
llvm/test/CodeGen/AArch64/fp8-sve-cvtn.ll

Modified: 
clang/include/clang/Basic/arm_sve.td
clang/test/Sema/aarch64-sve2-intrinsics/acle_sve2_fp8.c
llvm/include/llvm/IR/IntrinsicsAArch64.td
llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td
llvm/lib/Target/AArch64/SVEInstrFormats.td

Removed: 




diff  --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index 30dc5c55d411ab..b9f40faf0b18e6 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -2468,4 +2468,11 @@ let SVETargetGuard = "sve2,fp8", SMETargetGuard = 
"sme2,fp8" in {
   // 8-bit floating-point convert to BFloat16/Float16 (top)
   def SVF1CVTLT : SInst<"svcvtlt1_{d}[_mf8]_fpm", "d~>", "bh", MergeNone, 
"aarch64_sve_fp8_cvtlt1", [VerifyRuntimeMode, SetsFPMR]>;
   def SVF2CVTLT : SInst<"svcvtlt2_{d}[_mf8]_fpm", "d~>", "bh", MergeNone, 
"aarch64_sve_fp8_cvtlt2", [VerifyRuntimeMode, SetsFPMR]>;
+
+  // BFloat16/Float16 convert, narrow and interleave to 8-bit floating-point
+  def SVFCVTN : SInst<"svcvtn_mf8[_{d}_x2]_fpm", "~2>", "bh", MergeNone, 
"aarch64_sve_fp8_cvtn", [VerifyRuntimeMode, SetsFPMR]>;
+
+  // Single-precision convert, narrow and interleave to 8-bit floating-point 
(top and bottom)
+  def SVFCVTNB : SInst<"svcvtnb_mf8[_f32_x2]_fpm", "~2>",  "f", MergeNone, 
"aarch64_sve_fp8_cvtnb", [VerifyRuntimeMode, SetsFPMR]>;
+  def SVFCVTNT : SInst<"svcvtnt_mf8[_f32_x2]_fpm", "~~2>", "f", MergeNone, 
"aarch64_sve_fp8_cvtnt", [VerifyRuntimeMode, SetsFPMR]>;
 }

diff  --git a/clang/test/CodeGen/AArch64/fp8-intrinsics/acle_sve2_fp8_cvtn.c 
b/clang/test/CodeGen/AArch64/fp8-intrinsics/acle_sve2_fp8_cvtn.c
new file mode 100644
index 00..ed5b0ce02af4bd
--- /dev/null
+++ b/clang/test/CodeGen/AArch64/fp8-intrinsics/acle_sve2_fp8_cvtn.c
@@ -0,0 +1,101 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// RUN: %clang_cc1-triple aarch64-none-linux-gnu -target-feature +sve 
-target-feature +sve2 -target-feature +fp8 -disable-O0-optnone -Werror -Wall 
-emit-llvm -o - %s | opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -x c++ -triple aarch64-none-linux-gnu -target-feature +sme 
-target-feature +sme2 -target-feature +fp8 -disable-O0-optnone -Werror -Wall 
-emit-llvm -o - %s | opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s 
-check-prefix=CHECK-CXX
+
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS-triple 
aarch64-none-linux-gnu -target-feature +sme -target-feature +sme2 
-target-feature +fp8 -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | opt 
-S -p mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -x c++ -triple 
aarch64-none-linux-gnu -target-feature +sve -target-feature +sve2 
-target-feature +fp8 -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | opt 
-S -p mem2reg,instcombine,tailcallelim | FileCheck %s -check-prefix=CHECK-CXX
+
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-target-feature +sve2 -target-feature +fp8 -S -disable-O0-optnone -Werror -Wall 
-o /dev/null %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme 
-target-feature +sme2 -target-feature +fp8 -S -disable-O0-optnone -Werror -Wall 
-o /dev/null %s
+
+// REQUIRES: aarch64-registered-target
+
+#ifdef __ARM_FEATURE_SME
+#include 
+#else
+#include 
+#endif
+
+#ifdef SVE_OVERLOADED_FORMS
+#define SVE_ACLE_FUNC(A1,A2_UNUSED,A3) A1##A3
+#else
+#define SVE_ACLE_FUNC(A1,A2,A3) A1##A2##A3
+#endif
+
+#ifdef __ARM_FEATURE_SME
+#define STREAMING __arm_streaming
+#else
+#define STREAMING
+#endif
+
+// CHECK-LABEL: define dso_local  @test_svcvtn_f8_bf16(
+// CHECK-SAME:  [[ZN_ZM_COERCE0:%.*]],  [[ZN_ZM_COERCE1:%.*]], i64 noundef [[FPM:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:tail call void @llvm.aarch64.set.fpmr(i64 [[FPM]])
+// CHECK-NEXT:[[TMP0:%

[clang] [llvm] [AArch64][FMV] Add missing feature dependencies and detect at runtime. (PR #119231)

2024-12-11 Thread Sander de Smalen via cfe-commits


@@ -61,13 +61,13 @@ unsigned AArch64::getFMVPriority(ArrayRef 
Features) {
   return Priority + MaxFMVPriority * NumFeatures;
 }
 
-uint64_t AArch64::getCpuSupportsMask(ArrayRef FeatureStrs) {
-  uint64_t FeaturesMask = 0;
-  for (const StringRef &FeatureStr : FeatureStrs) {
-if (auto Ext = parseFMVExtension(FeatureStr))
-  FeaturesMask |= (1ULL << Ext->Bit);
-  }
-  return FeaturesMask;
+uint64_t AArch64::getCpuSupportsMask(ArrayRef Features) {
+  ExtensionSet FeatureBits;
+  for (StringRef Feature : Features)
+if (auto Ext = parseFMVExtension(Feature))
+  if (Ext->ID)
+FeatureBits.enable(*Ext->ID);

sdesmalen-arm wrote:

Thanks. Could you make this more explicit in the documentation, i.e. that 
`AArch64::CPUFeatures` is a bitmask of features used by the FMV mechanism to 
test whether a certain feature is enabled at runtime?

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


[clang] [llvm] [AArch64][FMV] Add missing feature dependencies and detect at runtime. (PR #119231)

2024-12-11 Thread Sander de Smalen via cfe-commits


@@ -349,6 +349,14 @@ void AArch64::ExtensionSet::reconstructFromParsedFeatures(
   }
 }
 
+uint64_t AArch64::ExtensionSet::toCpuSupportsMask() const {

sdesmalen-arm wrote:

I guess you could always move the functionality back into a separate function 
if future changes require that. That said, I would prefer `getFMVFeatureMask` 
if you keep it, because it makes it clear that the bitmask describes features 
for the purpose of FMV.

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


[clang] [Clang][Xtensa] Add Xtensa target. (PR #118008)

2024-12-11 Thread Alexey Gerenkov via cfe-commits


@@ -0,0 +1,62 @@
+//===--- Xtensa.cpp - Implement Xtensa target feature support 
-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// 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 implements Xtensa TargetInfo objects.
+//
+//===--===//
+
+#include "Xtensa.h"
+#include "clang/Basic/Builtins.h"
+#include "clang/Basic/MacroBuilder.h"
+#include "clang/Basic/TargetBuiltins.h"
+
+using namespace clang;
+using namespace clang::targets;
+
+void XtensaTargetInfo::getTargetDefines(const LangOptions &Opts,
+MacroBuilder &Builder) const {
+  Builder.defineMacro("__xtensa__");
+  Builder.defineMacro("__XTENSA__");
+  if (BigEndian)

gerekon wrote:

Sorry. Do you mean to support for `-triple=xtensale` and `-triple=xtensaeb` and 
have corresponding checks in `clang/test/Preprocessor/init.c`?

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


[clang] [Clang][Xtensa] Add Xtensa target. (PR #118008)

2024-12-11 Thread Alexey Gerenkov via cfe-commits

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


[clang] [flang] [clang][driver] When -fveclib=ArmPL flag is in use, always link against libamath (PR #116432)

2024-12-11 Thread Paul Osmialowski via cfe-commits

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


[clang] 03019c6 - [clang][driver] When -fveclib=ArmPL flag is in use, always link against libamath (#116432)

2024-12-11 Thread via cfe-commits

Author: Paul Osmialowski
Date: 2024-12-11T14:01:29Z
New Revision: 03019c687f00cdd9d05fc1ace329a438c3ff6364

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

LOG: [clang][driver] When -fveclib=ArmPL flag is in use, always link against 
libamath (#116432)

Using `-fveclib=ArmPL` without `-lamath` likely effects in the link-time
errors.

Added: 


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

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 03dbdc27975b42..3c78b12b0741e0 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -494,6 +494,39 @@ void tools::AddLinkerInputs(const ToolChain &TC, const 
InputInfoList &Inputs,
 else
   A.renderAsInput(Args, CmdArgs);
   }
+  if (const Arg *A = Args.getLastArg(options::OPT_fveclib)) {
+const llvm::Triple &Triple = TC.getTriple();
+StringRef V = A->getValue();
+if (V == "ArmPL" && (Triple.isOSLinux() || Triple.isOSDarwin())) {
+  // To support -fveclib=ArmPL we need to link against libamath. Some of 
the
+  // libamath functions depend on libm, at the same time, libamath exports
+  // its own implementation of some of the libm functions. These are faster
+  // and potentially less accurate implementations, hence we need to be
+  // careful what is being linked in. Since here we are interested only in
+  // the subset of libamath functions that is covered by the veclib
+  // mappings, we need to prioritize libm functions by putting -lm before
+  // -lamath (and then -lm again, to fulfill libamath requirements).
+  //
+  // Therefore we need to do the following:
+  //
+  // 1. On Linux, link only when actually needed.
+  //
+  // 2. Prefer libm functions over libamath.
+  //
+  // 3. Link against libm to resolve libamath dependencies.
+  //
+  if (Triple.isOSLinux()) {
+CmdArgs.push_back(Args.MakeArgString("--push-state"));
+CmdArgs.push_back(Args.MakeArgString("--as-needed"));
+  }
+  CmdArgs.push_back(Args.MakeArgString("-lm"));
+  CmdArgs.push_back(Args.MakeArgString("-lamath"));
+  CmdArgs.push_back(Args.MakeArgString("-lm"));
+  if (Triple.isOSLinux())
+CmdArgs.push_back(Args.MakeArgString("--pop-state"));
+  addArchSpecificRPath(TC, Args, CmdArgs);
+}
+  }
 }
 
 void tools::addLinkerCompressDebugSectionsOption(

diff  --git a/clang/lib/Driver/ToolChains/MSVC.cpp 
b/clang/lib/Driver/ToolChains/MSVC.cpp
index 80799d1e715f07..752c2e2751ab67 100644
--- a/clang/lib/Driver/ToolChains/MSVC.cpp
+++ b/clang/lib/Driver/ToolChains/MSVC.cpp
@@ -84,6 +84,12 @@ void visualstudio::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   else if (TC.getTriple().isWindowsArm64EC())
 CmdArgs.push_back("-machine:arm64ec");
 
+  if (const Arg *A = Args.getLastArg(options::OPT_fveclib)) {
+StringRef V = A->getValue();
+if (V == "ArmPL")
+  CmdArgs.push_back(Args.MakeArgString("--dependent-lib=amath"));
+  }
+
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles) &&
   !C.getDriver().IsCLMode() && !C.getDriver().IsFlangMode()) {
 CmdArgs.push_back("-defaultlib:libcmt");

diff  --git a/clang/test/Driver/fveclib.c b/clang/test/Driver/fveclib.c
index 09a12c2327137c..7d0985c4dd4f48 100644
--- a/clang/test/Driver/fveclib.c
+++ b/clang/test/Driver/fveclib.c
@@ -112,3 +112,20 @@
 /* Verify no warning when math-errno is re-enabled for a 
diff erent veclib (that does not imply -fno-math-errno). */
 // RUN: %clang -### --target=aarch64-linux-gnu -fveclib=ArmPL -fmath-errno 
-fveclib=LIBMVEC %s 2>&1 | FileCheck --check-prefix=CHECK-REPEAT-VECLIB %s
 // CHECK-REPEAT-VECLIB-NOT: math errno enabled
+
+/// Verify that vectorized routines library is being linked in.
+// RUN: %clang -### --target=aarch64-pc-windows-msvc -fveclib=ArmPL %s 2>&1 | 
FileCheck --check-prefix=CHECK-LINKING-ARMPL-MSVC %s
+// RUN: %clang -### --target=aarch64-linux-gnu -fveclib=ArmPL %s 2>&1 | 
FileCheck --check-prefix=CHECK-LINKING-ARMPL-LINUX %s
+// RUN: %clang -### --target=aarch64-linux-gnu -fveclib=ArmPL %s -lamath 2>&1 
| FileCheck --check-prefix=CHECK-LINKING-AMATH-BEFORE-ARMPL-LINUX %s
+// RUN: %clang -### --target=arm64-apple-darwin -fveclib=ArmPL %s 2>&1 | 
FileCheck --check-prefix=CHECK-LINKING-ARMPL-DARWIN %s
+// RUN: %clang -### --target=arm64-apple-darwin -fveclib=ArmPL %s -lamath 2>&1 
| FileCheck --check-prefix=CHECK-LINKING-AMATH-BEFORE-ARMPL-DARWIN %s
+// CHECK-LINKING-ARMPL-LINUX: "--push-state" "--as-needed" "-lm" "-lamath" 
"-lm" "--pop-state"
+// CHECK-

[clang] [clang] Fix crashes when passing VLA to va_arg (PR #119563)

2024-12-11 Thread via cfe-commits

https://github.com/amane-ame created 
https://github.com/llvm/llvm-project/pull/119563

Closes #119360.

From 659eda3ec76b63418f8b621b004728d9d7bf26ad Mon Sep 17 00:00:00 2001
From: amane-ame 
Date: Wed, 11 Dec 2024 22:17:51 +0800
Subject: [PATCH] [clang] Fix crashes when passing VLA to va_arg

---
 clang/lib/CodeGen/CGExprAgg.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index 2ad6587089f101..a4111cb65c8b1c 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -2201,6 +2201,8 @@ void CodeGenFunction::EmitAggregateCopy(LValue Dest, 
LValue Src, QualType Ty,
 // But note that getTypeInfo returns 0 for a VLA.
 if (auto *VAT = dyn_cast_or_null(
 getContext().getAsArrayType(Ty))) {
+  assert(Ty->isVariableArrayType());
+  EmitVariablyModifiedType(Ty);
   QualType BaseEltTy;
   SizeVal = emitArrayLength(VAT, BaseEltTy, DestPtr);
   TypeInfo = getContext().getTypeInfoInChars(BaseEltTy);

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


[clang] [clang] Fix crashes when passing VLA to va_arg (PR #119563)

2024-12-11 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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

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

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


[clang] [clang] Fix crashes when passing VLA to va_arg (PR #119563)

2024-12-11 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-codegen

Author: 天音あめ (amane-ame)


Changes

Closes #119360.

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


1 Files Affected:

- (modified) clang/lib/CodeGen/CGExprAgg.cpp (+2) 


``diff
diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index 2ad6587089f101..a4111cb65c8b1c 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -2201,6 +2201,8 @@ void CodeGenFunction::EmitAggregateCopy(LValue Dest, 
LValue Src, QualType Ty,
 // But note that getTypeInfo returns 0 for a VLA.
 if (auto *VAT = dyn_cast_or_null(
 getContext().getAsArrayType(Ty))) {
+  assert(Ty->isVariableArrayType());
+  EmitVariablyModifiedType(Ty);
   QualType BaseEltTy;
   SizeVal = emitArrayLength(VAT, BaseEltTy, DestPtr);
   TypeInfo = getContext().getTypeInfoInChars(BaseEltTy);

``




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


[clang-tools-extra] fix parse windows driver and provides support for WSL paths. (PR #119350)

2024-12-11 Thread via cfe-commits

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


[clang] [Clang][Xtensa] Add Xtensa target. (PR #118008)

2024-12-11 Thread Alexey Gerenkov via cfe-commits


@@ -0,0 +1,62 @@
+//===--- Xtensa.cpp - Implement Xtensa target feature support 
-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// 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 implements Xtensa TargetInfo objects.
+//
+//===--===//
+
+#include "Xtensa.h"
+#include "clang/Basic/Builtins.h"
+#include "clang/Basic/MacroBuilder.h"
+#include "clang/Basic/TargetBuiltins.h"
+
+using namespace clang;
+using namespace clang::targets;
+
+void XtensaTargetInfo::getTargetDefines(const LangOptions &Opts,
+MacroBuilder &Builder) const {
+  Builder.defineMacro("__xtensa__");
+  Builder.defineMacro("__XTENSA__");
+  if (BigEndian)

gerekon wrote:

I can do like it is done in ARM: `xtensa` - little-endian and `xtensaeb` - 
big-endian. But for big endian support I will have to update LLVM Triple code 
also. If that will be acceptable to be a part of this Clang related patch I 
will do it.

Another option is to support `xtensa` only and hard-code `BigEndian = false` 
until the patch with big endianess support if any.

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


[clang] [clang][bytecode] Handle __builtin_memcmp (PR #119544)

2024-12-11 Thread Timm Baeder via cfe-commits

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

>From b10358067fa9b4e4d05293be168092cd2ea43d12 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Wed, 11 Dec 2024 12:35:29 +0100
Subject: [PATCH] [clang][bytecode] Handle __builtin_memcmp

---
 clang/lib/AST/ByteCode/BitcastBuffer.h|  9 +++
 clang/lib/AST/ByteCode/InterpBuiltin.cpp  | 74 ++-
 .../lib/AST/ByteCode/InterpBuiltinBitCast.cpp |  6 +-
 clang/lib/AST/ByteCode/InterpBuiltinBitCast.h |  8 +-
 clang/test/AST/ByteCode/builtin-functions.cpp | 25 +++
 clang/test/SemaCXX/constexpr-string.cpp   |  2 +-
 6 files changed, 117 insertions(+), 7 deletions(-)

diff --git a/clang/lib/AST/ByteCode/BitcastBuffer.h 
b/clang/lib/AST/ByteCode/BitcastBuffer.h
index b1b6b9e5173a7c..d1d6ee39ad17bc 100644
--- a/clang/lib/AST/ByteCode/BitcastBuffer.h
+++ b/clang/lib/AST/ByteCode/BitcastBuffer.h
@@ -18,6 +18,8 @@ namespace interp {
 
 enum class Endian { Little, Big };
 
+struct Bytes;
+
 /// A quantity in bits.
 struct Bits {
   size_t N = 0;
@@ -30,6 +32,7 @@ struct Bits {
   bool isFullByte() const { return N % 8 == 0; }
   bool nonZero() const { return N != 0; }
   bool isZero() const { return N == 0; }
+  Bytes toBytes() const;
 
   Bits operator-(Bits Other) const { return Bits(N - Other.N); }
   Bits operator+(Bits Other) const { return Bits(N + Other.N); }
@@ -56,6 +59,11 @@ struct Bytes {
   Bits toBits() const { return Bits(N * 8); }
 };
 
+inline Bytes Bits::toBytes() const {
+  assert(isFullByte());
+  return Bytes(N / 8);
+}
+
 /// A bit range. Both Start and End are inclusive.
 struct BitRange {
   Bits Start;
@@ -83,6 +91,7 @@ struct BitcastBuffer {
 
   /// Returns the buffer size in bits.
   Bits size() const { return FinalBitSize; }
+  Bytes byteSize() const { return FinalBitSize.toBytes(); }
 
   /// Returns \c true if all bits in the buffer have been initialized.
   bool allInitialized() const;
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 4fe17ec01906e9..5c40f4e52c71a0 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -190,6 +190,12 @@ static bool 
interp__builtin_is_constant_evaluated(InterpState &S, CodePtr OpPC,
   return true;
 }
 
+/// Determine if T is a character type for which we guarantee that
+/// sizeof(T) == 1.
+static bool isOneByteCharacterType(QualType T) {
+  return T->isCharType() || T->isChar8Type();
+}
+
 static bool interp__builtin_strcmp(InterpState &S, CodePtr OpPC,
const InterpFrame *Frame,
const Function *Func, const CallExpr *Call) 
{
@@ -219,6 +225,19 @@ static bool interp__builtin_strcmp(InterpState &S, CodePtr 
OpPC,
   assert(A.getFieldDesc()->isPrimitiveArray());
   assert(B.getFieldDesc()->isPrimitiveArray());
 
+#if 0
+  if (IsRawByte &&
+  (!isOneByteCharacterType(A.getFieldDesc()->getElemQualType()) ||
+   !isOneByteCharacterType(B.getFieldDesc()->getElemQualType( {
+QualType CharTy1 = A.getFieldDesc()->getElemQualType();
+QualType CharTy2 = B.getFieldDesc()->getElemQualType();
+S.FFDiag(S.Current->getSource(OpPC),
+ diag::note_constexpr_memcmp_unsupported)
+<< ("'" + S.getASTContext().BuiltinInfo.getName(ID) + "'").str()
+<< CharTy1 << CharTy2;
+return false;
+  }
+#endif
   unsigned IndexA = A.getIndex();
   unsigned IndexB = B.getIndex();
   int32_t Result = 0;
@@ -1830,6 +1849,7 @@ static bool 
interp__builtin_elementwise_popcount(InterpState &S, CodePtr OpPC,
 
   return true;
 }
+
 static bool interp__builtin_memcpy(InterpState &S, CodePtr OpPC,
const InterpFrame *Frame,
const Function *Func, const CallExpr *Call) 
{
@@ -1876,7 +1896,8 @@ static bool interp__builtin_memcpy(InterpState &S, 
CodePtr OpPC,
   }
 
   // Check for overlapping memory regions.
-  if (!Move && SrcPtr.block() == DestPtr.block()) {
+  if (!Move && Pointer::pointToSameBlock(
+   SrcPtr, DestPtr)) { // SrcPtr.block() == DestPtr.block()) {
 unsigned SrcIndex = SrcPtr.getIndex() * SrcPtr.elemSize();
 unsigned DstIndex = DestPtr.getIndex() * DestPtr.elemSize();
 unsigned N = Size.getZExtValue();
@@ -1900,6 +1921,51 @@ static bool interp__builtin_memcpy(InterpState &S, 
CodePtr OpPC,
   return true;
 }
 
+static bool interp__builtin_memcmp(InterpState &S, CodePtr OpPC,
+   const InterpFrame *Frame,
+   const Function *Func, const CallExpr *Call) 
{
+  assert(Call->getNumArgs() == 3);
+  unsigned ID = Func->getBuiltinID();
+  Pointer PtrA = getParam(Frame, 0);
+  const Pointer &PtrB = getParam(Frame, 1);
+  const APSInt &Size =
+  peekToAPSInt(S.Stk, *S.getContext().classify(Call->getArg(2)));
+
+  if (ID == Builtin::BImemcmp)
+diagnoseNonConstexprBuil

[clang] [clang] Fix sub-integer __builtin_elementwise_(add|sub)_sat (PR #119423)

2024-12-11 Thread Simon Pilgrim via cfe-commits

RKSimon wrote:

I thought bitreverse/popcount are only supposed to work with unsigned types?

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


[clang] [clang] Fix sub-integer __builtin_elementwise_(add|sub)_sat (PR #119423)

2024-12-11 Thread Fraser Cormack via cfe-commits

frasercrmck wrote:

> I thought bitreverse/popcount are only supposed to work with unsigned types?

Good question. The 
[documentation](https://clang.llvm.org/docs/LanguageExtensions.html) doesn't 
mention they're only for signed types, as `abs` does, for example. So if there 
is such a restriction, it's not documented, nor checked in the code.

Tangentially, in OpenCL (where I'm coming from) there's no restriction on 
`popcount` to be only on unsigned types.

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


[clang] [clang][bytecode] Handle __builtin_memcmp (PR #119544)

2024-12-11 Thread Timm Baeder via cfe-commits

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

>From 14ba7129a6c2dc45dff0bd2054f2da693d9ab77a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Wed, 11 Dec 2024 12:35:29 +0100
Subject: [PATCH] [clang][bytecode] Handle __builtin_memcmp

---
 clang/lib/AST/ByteCode/BitcastBuffer.h|  9 +++
 clang/lib/AST/ByteCode/InterpBuiltin.cpp  | 74 ++-
 .../lib/AST/ByteCode/InterpBuiltinBitCast.cpp |  6 +-
 clang/lib/AST/ByteCode/InterpBuiltinBitCast.h |  8 +-
 clang/test/AST/ByteCode/builtin-functions.cpp | 25 +++
 5 files changed, 116 insertions(+), 6 deletions(-)

diff --git a/clang/lib/AST/ByteCode/BitcastBuffer.h 
b/clang/lib/AST/ByteCode/BitcastBuffer.h
index b1b6b9e5173a7c..d1d6ee39ad17bc 100644
--- a/clang/lib/AST/ByteCode/BitcastBuffer.h
+++ b/clang/lib/AST/ByteCode/BitcastBuffer.h
@@ -18,6 +18,8 @@ namespace interp {
 
 enum class Endian { Little, Big };
 
+struct Bytes;
+
 /// A quantity in bits.
 struct Bits {
   size_t N = 0;
@@ -30,6 +32,7 @@ struct Bits {
   bool isFullByte() const { return N % 8 == 0; }
   bool nonZero() const { return N != 0; }
   bool isZero() const { return N == 0; }
+  Bytes toBytes() const;
 
   Bits operator-(Bits Other) const { return Bits(N - Other.N); }
   Bits operator+(Bits Other) const { return Bits(N + Other.N); }
@@ -56,6 +59,11 @@ struct Bytes {
   Bits toBits() const { return Bits(N * 8); }
 };
 
+inline Bytes Bits::toBytes() const {
+  assert(isFullByte());
+  return Bytes(N / 8);
+}
+
 /// A bit range. Both Start and End are inclusive.
 struct BitRange {
   Bits Start;
@@ -83,6 +91,7 @@ struct BitcastBuffer {
 
   /// Returns the buffer size in bits.
   Bits size() const { return FinalBitSize; }
+  Bytes byteSize() const { return FinalBitSize.toBytes(); }
 
   /// Returns \c true if all bits in the buffer have been initialized.
   bool allInitialized() const;
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 4fe17ec01906e9..5c40f4e52c71a0 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -190,6 +190,12 @@ static bool 
interp__builtin_is_constant_evaluated(InterpState &S, CodePtr OpPC,
   return true;
 }
 
+/// Determine if T is a character type for which we guarantee that
+/// sizeof(T) == 1.
+static bool isOneByteCharacterType(QualType T) {
+  return T->isCharType() || T->isChar8Type();
+}
+
 static bool interp__builtin_strcmp(InterpState &S, CodePtr OpPC,
const InterpFrame *Frame,
const Function *Func, const CallExpr *Call) 
{
@@ -219,6 +225,19 @@ static bool interp__builtin_strcmp(InterpState &S, CodePtr 
OpPC,
   assert(A.getFieldDesc()->isPrimitiveArray());
   assert(B.getFieldDesc()->isPrimitiveArray());
 
+#if 0
+  if (IsRawByte &&
+  (!isOneByteCharacterType(A.getFieldDesc()->getElemQualType()) ||
+   !isOneByteCharacterType(B.getFieldDesc()->getElemQualType( {
+QualType CharTy1 = A.getFieldDesc()->getElemQualType();
+QualType CharTy2 = B.getFieldDesc()->getElemQualType();
+S.FFDiag(S.Current->getSource(OpPC),
+ diag::note_constexpr_memcmp_unsupported)
+<< ("'" + S.getASTContext().BuiltinInfo.getName(ID) + "'").str()
+<< CharTy1 << CharTy2;
+return false;
+  }
+#endif
   unsigned IndexA = A.getIndex();
   unsigned IndexB = B.getIndex();
   int32_t Result = 0;
@@ -1830,6 +1849,7 @@ static bool 
interp__builtin_elementwise_popcount(InterpState &S, CodePtr OpPC,
 
   return true;
 }
+
 static bool interp__builtin_memcpy(InterpState &S, CodePtr OpPC,
const InterpFrame *Frame,
const Function *Func, const CallExpr *Call) 
{
@@ -1876,7 +1896,8 @@ static bool interp__builtin_memcpy(InterpState &S, 
CodePtr OpPC,
   }
 
   // Check for overlapping memory regions.
-  if (!Move && SrcPtr.block() == DestPtr.block()) {
+  if (!Move && Pointer::pointToSameBlock(
+   SrcPtr, DestPtr)) { // SrcPtr.block() == DestPtr.block()) {
 unsigned SrcIndex = SrcPtr.getIndex() * SrcPtr.elemSize();
 unsigned DstIndex = DestPtr.getIndex() * DestPtr.elemSize();
 unsigned N = Size.getZExtValue();
@@ -1900,6 +1921,51 @@ static bool interp__builtin_memcpy(InterpState &S, 
CodePtr OpPC,
   return true;
 }
 
+static bool interp__builtin_memcmp(InterpState &S, CodePtr OpPC,
+   const InterpFrame *Frame,
+   const Function *Func, const CallExpr *Call) 
{
+  assert(Call->getNumArgs() == 3);
+  unsigned ID = Func->getBuiltinID();
+  Pointer PtrA = getParam(Frame, 0);
+  const Pointer &PtrB = getParam(Frame, 1);
+  const APSInt &Size =
+  peekToAPSInt(S.Stk, *S.getContext().classify(Call->getArg(2)));
+
+  if (ID == Builtin::BImemcmp)
+diagnoseNonConstexprBuiltin(S, OpPC, ID);
+
+  if (Size.isZero()) {
+pushIn

[clang-tools-extra] [clang-tidy] Create a check for signed and unsigned integers comparison (PR #113144)

2024-12-11 Thread via cfe-commits

https://github.com/qt-tatiana updated 
https://github.com/llvm/llvm-project/pull/113144

>From a52c06e25a919f5d84f9ac4c373f4e0f9246b503 Mon Sep 17 00:00:00 2001
From: Tatiana Borisova 
Date: Thu, 17 Oct 2024 18:00:08 +0200
Subject: [PATCH] [clang-tidy] Create a check for signed and unsigned integers
 comparison

- modernize-use-integer-sign-comparison - replace comparisons between
signed and unsigned integers with their safe C++20 ``std::cmp_*``
alternative, if available.
---
 .../clang-tidy/modernize/CMakeLists.txt   |   1 +
 .../modernize/ModernizeTidyModule.cpp |   3 +
 .../UseIntegerSignComparisonCheck.cpp | 171 ++
 .../modernize/UseIntegerSignComparisonCheck.h |  42 +
 clang-tools-extra/docs/ReleaseNotes.rst   |   8 +-
 .../docs/clang-tidy/checks/list.rst   |   1 +
 .../modernize/use-integer-sign-comparison.rst |  36 
 .../modernize/use-integer-sign-comparison.cpp | 122 +
 8 files changed, 383 insertions(+), 1 deletion(-)
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-integer-sign-comparison.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-integer-sign-comparison.cpp

diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index c919d49b42873a..bab1167fb15ff2 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -36,6 +36,7 @@ add_clang_library(clangTidyModernizeModule STATIC
   UseEmplaceCheck.cpp
   UseEqualsDefaultCheck.cpp
   UseEqualsDeleteCheck.cpp
+  UseIntegerSignComparisonCheck.cpp
   UseNodiscardCheck.cpp
   UseNoexceptCheck.cpp
   UseNullptrCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index 18607593320635..fc46c72982fdce 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -37,6 +37,7 @@
 #include "UseEmplaceCheck.h"
 #include "UseEqualsDefaultCheck.h"
 #include "UseEqualsDeleteCheck.h"
+#include "UseIntegerSignComparisonCheck.h"
 #include "UseNodiscardCheck.h"
 #include "UseNoexceptCheck.h"
 #include "UseNullptrCheck.h"
@@ -76,6 +77,8 @@ class ModernizeModule : public ClangTidyModule {
 CheckFactories.registerCheck("modernize-pass-by-value");
 CheckFactories.registerCheck(
 "modernize-use-designated-initializers");
+CheckFactories.registerCheck(
+"modernize-use-integer-sign-comparison");
 CheckFactories.registerCheck("modernize-use-ranges");
 CheckFactories.registerCheck(
 "modernize-use-starts-ends-with");
diff --git 
a/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp
new file mode 100644
index 00..8f807bc0a96d56
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp
@@ -0,0 +1,171 @@
+//===--- UseIntegerSignComparisonCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseIntegerSignComparisonCheck.h"
+#include "clang/AST/Expr.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+using namespace clang::ast_matchers::internal;
+
+namespace clang::tidy::modernize {
+
+/// Find if the passed type is the actual "char" type,
+/// not applicable to explicit "signed char" or "unsigned char" types.
+static bool isActualCharType(const clang::QualType &Ty) {
+  using namespace clang;
+  const Type *DesugaredType = Ty->getUnqualifiedDesugaredType();
+  if (const auto *BT = llvm::dyn_cast(DesugaredType))
+return (BT->getKind() == BuiltinType::Char_U ||
+BT->getKind() == BuiltinType::Char_S);
+  return false;
+}
+
+namespace {
+AST_MATCHER(clang::QualType, isActualChar) {
+  return clang::tidy::modernize::isActualCharType(Node);
+}
+} // namespace
+
+static BindableMatcher
+intCastExpression(bool IsSigned,
+  const std::string &CastBindName = std::string()) {
+  // std::cmp_{} functions trigger a compile-time error if either LHS or RHS
+  // is a non-integer type, char, enum or bool
+  // (unsigned char/ signed char are Ok and can be used).
+  auto IntTypeExpr = expr(hasType(hasCanonicalType(qualType(
+  isInteger(), IsSigned ? isSignedInteger() : isUnsignedInt

[clang] d416cae - [clang][bytecode][NFC] Use Pointer::pointToSameBlock (#119552)

2024-12-11 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-12-11T16:14:19+01:00
New Revision: d416cae180a5c7e7325c0b55818056e328633a61

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

LOG: [clang][bytecode][NFC] Use Pointer::pointToSameBlock (#119552)

block() requires the pointer to be a block pointer.

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 4fe17ec01906e9..57175da32b31cd 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -1876,7 +1876,7 @@ static bool interp__builtin_memcpy(InterpState &S, 
CodePtr OpPC,
   }
 
   // Check for overlapping memory regions.
-  if (!Move && SrcPtr.block() == DestPtr.block()) {
+  if (!Move && Pointer::pointToSameBlock(SrcPtr, DestPtr)) {
 unsigned SrcIndex = SrcPtr.getIndex() * SrcPtr.elemSize();
 unsigned DstIndex = DestPtr.getIndex() * DestPtr.elemSize();
 unsigned N = Size.getZExtValue();



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


[clang] [clang][bytecode][NFC] Use Pointer::pointToSameBlock (PR #119552)

2024-12-11 Thread Timm Baeder via cfe-commits

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


[clang] [llvm] [AArch64][FMV] Add missing feature dependencies and detect at runtime. (PR #119231)

2024-12-11 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea updated 
https://github.com/llvm/llvm-project/pull/119231

>From f6f2fd6aac09a0f2c14545e1fbda9aec7eb2ed46 Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Mon, 9 Dec 2024 13:00:58 +
Subject: [PATCH 1/2] [AArch64][FMV] Add missing feature dependencies and
 detect at runtime.

i8mm -> simd
fp16fml -> simd
frintts -> fp
bf16 -> simd
sme -> fp16

Approved in ACLE as https://github.com/ARM-software/acle/pull/368
---
 clang/test/CodeGen/AArch64/cpu-supports.c |   8 +-
 clang/test/CodeGen/AArch64/fmv-dependencies.c |   8 +-
 .../CodeGen/AArch64/mixed-target-attributes.c |  32 ++---
 .../test/CodeGen/attr-target-clones-aarch64.c |  88 ++---
 clang/test/CodeGen/attr-target-version.c  | 120 +-
 .../CodeGenCXX/attr-target-clones-aarch64.cpp |  24 ++--
 clang/test/CodeGenCXX/attr-target-version.cpp |  20 +--
 clang/test/CodeGenCXX/fmv-namespace.cpp   |   4 +-
 .../llvm/TargetParser/AArch64TargetParser.h   |   3 +
 llvm/lib/Target/AArch64/AArch64Features.td|  11 +-
 llvm/lib/TargetParser/AArch64TargetParser.cpp |  22 +++-
 .../sve-streaming-mode-cvt-fp-int-fp.ll   |  16 ---
 .../SME/streaming-mode-neon-negative.s|   4 +-
 .../MC/AArch64/SME/streaming-sve-feature.s|   2 +-
 llvm/test/MC/AArch64/armv8a-fpmul.s   |  28 +---
 15 files changed, 180 insertions(+), 210 deletions(-)

diff --git a/clang/test/CodeGen/AArch64/cpu-supports.c 
b/clang/test/CodeGen/AArch64/cpu-supports.c
index 76fcea0be31581..406201781d4803 100644
--- a/clang/test/CodeGen/AArch64/cpu-supports.c
+++ b/clang/test/CodeGen/AArch64/cpu-supports.c
@@ -18,8 +18,8 @@
 // CHECK-NEXT:br label [[RETURN:%.*]]
 // CHECK:   if.end:
 // CHECK-NEXT:[[TMP4:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
-// CHECK-NEXT:[[TMP5:%.*]] = and i64 [[TMP4]], 17867063951360
-// CHECK-NEXT:[[TMP6:%.*]] = icmp eq i64 [[TMP5]], 17867063951360
+// CHECK-NEXT:[[TMP5:%.*]] = and i64 [[TMP4]], 17936857268992
+// CHECK-NEXT:[[TMP6:%.*]] = icmp eq i64 [[TMP5]], 17936857268992
 // CHECK-NEXT:[[TMP7:%.*]] = and i1 true, [[TMP6]]
 // CHECK-NEXT:br i1 [[TMP7]], label [[IF_THEN1:%.*]], label [[IF_END2:%.*]]
 // CHECK:   if.then1:
@@ -27,8 +27,8 @@
 // CHECK-NEXT:br label [[RETURN]]
 // CHECK:   if.end2:
 // CHECK-NEXT:[[TMP8:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
-// CHECK-NEXT:[[TMP9:%.*]] = and i64 [[TMP8]], 171136785840078848
-// CHECK-NEXT:[[TMP10:%.*]] = icmp eq i64 [[TMP9]], 171136785840078848
+// CHECK-NEXT:[[TMP9:%.*]] = and i64 [[TMP8]], 171141184020873984
+// CHECK-NEXT:[[TMP10:%.*]] = icmp eq i64 [[TMP9]], 171141184020873984
 // CHECK-NEXT:[[TMP11:%.*]] = and i1 true, [[TMP10]]
 // CHECK-NEXT:br i1 [[TMP11]], label [[IF_THEN3:%.*]], label 
[[IF_END4:%.*]]
 // CHECK:   if.then3:
diff --git a/clang/test/CodeGen/AArch64/fmv-dependencies.c 
b/clang/test/CodeGen/AArch64/fmv-dependencies.c
index f74b7aa32c7dca..3a524b89496e04 100644
--- a/clang/test/CodeGen/AArch64/fmv-dependencies.c
+++ b/clang/test/CodeGen/AArch64/fmv-dependencies.c
@@ -183,10 +183,10 @@ int caller() {
 // CHECK: attributes #[[sha2]] = { {{.*}} 
"target-features"="+fmv,+fp-armv8,+neon,+outline-atomics,+sha2,+v8a"
 // CHECK: attributes #[[sha3]] = { {{.*}} 
"target-features"="+fmv,+fp-armv8,+neon,+outline-atomics,+sha2,+sha3,+v8a"
 // CHECK: attributes #[[sm4]] = { {{.*}} 
"target-features"="+fmv,+fp-armv8,+neon,+outline-atomics,+sm4,+v8a"
-// CHECK: attributes #[[sme]] = { {{.*}} 
"target-features"="+bf16,+fmv,+fp-armv8,+neon,+outline-atomics,+sme,+v8a"
-// CHECK: attributes #[[sme_f64f64]] = { {{.*}} 
"target-features"="+bf16,+fmv,+fp-armv8,+neon,+outline-atomics,+sme,+sme-f64f64,+v8a"
-// CHECK: attributes #[[sme_i16i64]] = { {{.*}} 
"target-features"="+bf16,+fmv,+fp-armv8,+neon,+outline-atomics,+sme,+sme-i16i64,+v8a"
-// CHECK: attributes #[[sme2]] = { {{.*}} 
"target-features"="+bf16,+fmv,+fp-armv8,+neon,+outline-atomics,+sme,+sme2,+v8a"
+// CHECK: attributes #[[sme]] = { {{.*}} 
"target-features"="+bf16,+fmv,+fp-armv8,+fullfp16,+neon,+outline-atomics,+sme,+v8a"
+// CHECK: attributes #[[sme_f64f64]] = { {{.*}} 
"target-features"="+bf16,+fmv,+fp-armv8,+fullfp16,+neon,+outline-atomics,+sme,+sme-f64f64,+v8a"
+// CHECK: attributes #[[sme_i16i64]] = { {{.*}} 
"target-features"="+bf16,+fmv,+fp-armv8,+fullfp16,+neon,+outline-atomics,+sme,+sme-i16i64,+v8a"
+// CHECK: attributes #[[sme2]] = { {{.*}} 
"target-features"="+bf16,+fmv,+fp-armv8,+fullfp16,+neon,+outline-atomics,+sme,+sme2,+v8a"
 // CHECK: attributes #[[ssbs]] = { {{.*}} 
"target-features"="+fmv,+fp-armv8,+neon,+outline-atomics,+ssbs,+v8a"
 // CHECK: attributes #[[sve]] = { {{.*}} 
"target-features"="+fmv,+fp-armv8,+fullfp16,+neon,+outline-atomics,+sve,+v8a"
 // CHECK: attributes #[[sve2]] = { {{.*}} 
"target-features"="+fmv,+fp-armv8,+fullfp16,+neon,+outline-atomics,+sve,+sve2,+v8a"
diff --git a/clang/test/CodeGen/AArch64/mixed-target-attributes.c 
b/c

[clang] [clang][bytecode] Handle __builtin_memcmp (PR #119544)

2024-12-11 Thread Timm Baeder via cfe-commits

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

>From d4518ea52cab53861c242e335fbc75af46f4d208 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Wed, 11 Dec 2024 12:35:29 +0100
Subject: [PATCH] [clang][bytecode] Handle __builtin_memcmp

---
 clang/lib/AST/ByteCode/BitcastBuffer.h|  9 
 clang/lib/AST/ByteCode/InterpBuiltin.cpp  | 52 +++
 .../lib/AST/ByteCode/InterpBuiltinBitCast.cpp |  6 ++-
 clang/lib/AST/ByteCode/InterpBuiltinBitCast.h |  8 +--
 clang/test/AST/ByteCode/builtin-functions.cpp | 25 +
 5 files changed, 95 insertions(+), 5 deletions(-)

diff --git a/clang/lib/AST/ByteCode/BitcastBuffer.h 
b/clang/lib/AST/ByteCode/BitcastBuffer.h
index b1b6b9e5173a7c..d1d6ee39ad17bc 100644
--- a/clang/lib/AST/ByteCode/BitcastBuffer.h
+++ b/clang/lib/AST/ByteCode/BitcastBuffer.h
@@ -18,6 +18,8 @@ namespace interp {
 
 enum class Endian { Little, Big };
 
+struct Bytes;
+
 /// A quantity in bits.
 struct Bits {
   size_t N = 0;
@@ -30,6 +32,7 @@ struct Bits {
   bool isFullByte() const { return N % 8 == 0; }
   bool nonZero() const { return N != 0; }
   bool isZero() const { return N == 0; }
+  Bytes toBytes() const;
 
   Bits operator-(Bits Other) const { return Bits(N - Other.N); }
   Bits operator+(Bits Other) const { return Bits(N + Other.N); }
@@ -56,6 +59,11 @@ struct Bytes {
   Bits toBits() const { return Bits(N * 8); }
 };
 
+inline Bytes Bits::toBytes() const {
+  assert(isFullByte());
+  return Bytes(N / 8);
+}
+
 /// A bit range. Both Start and End are inclusive.
 struct BitRange {
   Bits Start;
@@ -83,6 +91,7 @@ struct BitcastBuffer {
 
   /// Returns the buffer size in bits.
   Bits size() const { return FinalBitSize; }
+  Bytes byteSize() const { return FinalBitSize.toBytes(); }
 
   /// Returns \c true if all bits in the buffer have been initialized.
   bool allInitialized() const;
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 57175da32b31cd..1064a7df7ca9b9 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -1830,6 +1830,7 @@ static bool 
interp__builtin_elementwise_popcount(InterpState &S, CodePtr OpPC,
 
   return true;
 }
+
 static bool interp__builtin_memcpy(InterpState &S, CodePtr OpPC,
const InterpFrame *Frame,
const Function *Func, const CallExpr *Call) 
{
@@ -1900,6 +1901,51 @@ static bool interp__builtin_memcpy(InterpState &S, 
CodePtr OpPC,
   return true;
 }
 
+static bool interp__builtin_memcmp(InterpState &S, CodePtr OpPC,
+   const InterpFrame *Frame,
+   const Function *Func, const CallExpr *Call) 
{
+  assert(Call->getNumArgs() == 3);
+  unsigned ID = Func->getBuiltinID();
+  Pointer PtrA = getParam(Frame, 0);
+  const Pointer &PtrB = getParam(Frame, 1);
+  const APSInt &Size =
+  peekToAPSInt(S.Stk, *S.getContext().classify(Call->getArg(2)));
+
+  if (ID == Builtin::BImemcmp)
+diagnoseNonConstexprBuiltin(S, OpPC, ID);
+
+  if (Size.isZero()) {
+pushInteger(S, 0, Call->getType());
+return true;
+  }
+
+  if (PtrA.isDummy() || PtrB.isDummy())
+return false;
+
+  // Now, read both pointers to a buffer and compare those.
+
+  BitcastBuffer BufferA(
+  Bits(S.getASTContext().getTypeSize(PtrA.getFieldDesc()->getType(;
+  readPointerToBuffer(S.getContext(), PtrA, BufferA, false);
+
+  BitcastBuffer BufferB(
+  Bits(S.getASTContext().getTypeSize(PtrB.getFieldDesc()->getType(;
+  readPointerToBuffer(S.getContext(), PtrB, BufferB, false);
+
+  size_t MinBufferSize = std::min(BufferA.byteSize().getQuantity(),
+  BufferB.byteSize().getQuantity());
+  size_t CmpSize = std::min(MinBufferSize, Size.getZExtValue());
+  int Result = std::memcmp(BufferA.Data.get(), BufferB.Data.get(), CmpSize);
+  if (Result == 0)
+pushInteger(S, 0, Call->getType());
+  else if (Result < 0)
+pushInteger(S, -1, Call->getType());
+  else
+pushInteger(S, 1, Call->getType());
+
+  return true;
+}
+
 bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
   const CallExpr *Call, uint32_t BuiltinID) {
   const InterpFrame *Frame = S.Current;
@@ -2373,6 +2419,12 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, 
const Function *F,
   return false;
 break;
 
+  case Builtin::BI__builtin_memcmp:
+  case Builtin::BImemcmp:
+if (!interp__builtin_memcmp(S, OpPC, Frame, F, Call))
+  return false;
+break;
+
   default:
 S.FFDiag(S.Current->getLocation(OpPC),
  diag::note_invalid_subexpr_in_const_expr)
diff --git a/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
index c9141c0fad2f57..c87993b8739a77 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
+++ b/clang/lib/AST/ByteCode

[clang] [llvm] [AArch64][FMV] Add missing feature dependencies and detect at runtime. (PR #119231)

2024-12-11 Thread Alexandros Lamprineas via cfe-commits

labrinea wrote:

@sdesmalen-arm thanks for reviewing. I have addressed your comments. Do the 
llvm tests look okay?

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


[clang] [llvm] [AArch64] Implement intrinsics for SME FP8 FMLAL/FMLALL (single) (PR #118869)

2024-12-11 Thread via cfe-commits

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


[clang] [llvm] [AArch64] Implement intrinsics for SME FP8 FMLAL/FMLALL (single) (PR #118869)

2024-12-11 Thread via cfe-commits

SpencerAbson wrote:

Please see https://github.com/llvm/llvm-project/pull/119568. Cheers.

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


[clang] [llvm] [AArch64] Implement intrinsics for FMLAL/FMLALL (single) (PR #119568)

2024-12-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-ir

Author: None (SpencerAbson)


Changes


Multi-vector 8-bit floating-point multiply-add long (single)
```c
// Only if __ARM_FEATURE_SME_F8F16 != 0
void svmla[_single]_za16[_mf8]_vg2x1_fpm(uint32_t slice, svmfloat8_t zn,
 svmfloat8_t zm, fpm_t fpm)
 __arm_streaming __arm_inout("za");

void svmla[_single]_za16[_mf8]_vg2x2_fpm(uint32_t slice, svmfloat8x2_t zn,
 svmfloat8_t zm, fpm_t fpm)
 __arm_streaming __arm_inout("za");

void svmla[_single]_za16[_mf8]_vg2x4_fpm(uint32_t slice, svmfloat8x4_t zn,
 svmfloat8_t zm, fpm_t fpm)
 __arm_streaming __arm_inout("za");
// Only if __ARM_FEATURE_SME_F8F32 != 0
void svmla[_single]_za32[_mf8]_vg4x1_fpm(uint32_t slice, svmfloat8_t zn,
 svmfloat8_t zm, fpm_t fpm)
 __arm_streaming __arm_inout("za");

void svmla[_single]_za32[_mf8]_vg4x2_fpm(uint32_t slice, svmfloat8x2_t zn,
 svmfloat8_t zm, fpm_t fpm)
 __arm_streaming __arm_inout("za");

void svmla[_single]_za32[_mf8]_vg4x4_fpm(uint32_t slice, svmfloat8x4_t zn,
 svmfloat8_t zm, fpm_t fpm)
 __arm_streaming __arm_inout("za");
 ```
 In accordance with https://github.com/ARM-software/acle/pull/323.
 
Co-authored-by: Momchil Velikov momchil.velikov@arm.com

---

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


7 Files Affected:

- (modified) clang/include/clang/Basic/arm_sme.td (+14) 
- (added) clang/test/CodeGen/AArch64/fp8-intrinsics/acle_sme2_fp8_mla.c (+128) 
- (added) clang/test/Sema/aarch64-fp8-intrinsics/acle_sme_fp8_mla.c (+26) 
- (modified) llvm/include/llvm/IR/IntrinsicsAArch64.td (+31) 
- (modified) llvm/lib/Target/AArch64/AArch64SMEInstrInfo.td (+30-26) 
- (modified) llvm/lib/Target/AArch64/SMEInstrFormats.td (+34-23) 
- (added) llvm/test/CodeGen/AArch64/sme2-fp8-intrinsics-mla.ll (+101) 


``diff
diff --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index 71b2c7cdd04f93..8e5786f196a288 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -827,11 +827,25 @@ let SMETargetGuard = "sme-lutv2" in {
 let SMETargetGuard = "sme-f8f32" in {
   def SVMOPA_FP8_ZA32 : Inst<"svmopa_za32[_mf8]_m_fpm", "viPPdd>", "m", 
MergeNone, "aarch64_sme_fp8_fmopa_za32",
  [IsStreaming, IsInOutZA, SetsFPMR, 
IsOverloadNone], [ImmCheck<0, ImmCheck0_3>]>;
+  // FMLAL (single)
+  def SVMLA_FP8_SINGLE_ZA32_VG4x1 : 
Inst<"svmla[_single]_za32[_mf8]_vg4x1_fpm", "vmdd>", "m", MergeNone, 
"aarch64_sme_fp8_fmlall_single_za32_vg4x1",
+ [IsStreaming, IsInOutZA, SetsFPMR, 
IsOverloadNone], []>;
+  def SVMLA_FP8_SINGLE_ZA32_VG4x2 : 
Inst<"svmla[_single]_za32[_mf8]_vg4x2_fpm", "vm2d>", "m", MergeNone, 
"aarch64_sme_fp8_fmlall_single_za32_vg4x2",
+ [IsStreaming, IsInOutZA, SetsFPMR, 
IsOverloadNone], []>;
+  def SVMLA_FP8_SINGLE_ZA32_VG4x4 : 
Inst<"svmla[_single]_za32[_mf8]_vg4x4_fpm", "vm4d>", "m", MergeNone, 
"aarch64_sme_fp8_fmlall_single_za32_vg4x4",
+ [IsStreaming, IsInOutZA, SetsFPMR, 
IsOverloadNone], []>;
 }
 
 let SMETargetGuard = "sme-f8f16" in {
   def SVMOPA_FP8_ZA16 : Inst<"svmopa_za16[_mf8]_m_fpm", "viPPdd>", "m", 
MergeNone, "aarch64_sme_fp8_fmopa_za16",
  [IsStreaming, IsInOutZA, SetsFPMR, 
IsOverloadNone], [ImmCheck<0, ImmCheck0_1>]>;
+  // FMLAL (single)
+  def SVMLA_FP8_SINGLE_ZA16_VG2x1 : 
Inst<"svmla[_single]_za16[_mf8]_vg2x1_fpm", "vmdd>", "m", MergeNone, 
"aarch64_sme_fp8_fmlal_single_za16_vg2x1",
+ [IsStreaming, IsInOutZA, SetsFPMR, 
IsOverloadNone], []>;
+  def SVMLA_FP8_SINGLE_ZA16_VG2x2 : 
Inst<"svmla[_single]_za16[_mf8]_vg2x2_fpm", "vm2d>", "m", MergeNone, 
"aarch64_sme_fp8_fmlal_single_za16_vg2x2",
+ [IsStreaming, IsInOutZA, SetsFPMR, 
IsOverloadNone], []>;
+  def SVMLA_FP8_SINGLE_ZA16_VG2x4 : 
Inst<"svmla[_single]_za16[_mf8]_vg2x4_fpm", "vm4d>", "m", MergeNone, 
"aarch64_sme_fp8_fmlal_single_za16_vg2x4",
+ [IsStreaming, IsInOutZA, SetsFPMR, 
IsOverloadNone], []>;
 }
 
 } // let SVETargetGuard = InvalidMode
diff --git a/clang/test/CodeGen/AArch64/fp8-intrinsics/acle_sme2_fp8_mla.c 
b/clang/test/CodeGen/AArch64/fp8-intrinsics/acle_sme2_fp8_mla.c
new file mode 100644
index 00..0f6d45474c363f
--- /dev/null
+++ b/clang/test/CodeGen/AArch64/fp8-intrinsics/acl

[clang] [llvm] [AArch64] Implement intrinsics for FMLAL/FMLALL (single) (PR #119568)

2024-12-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-aarch64

Author: None (SpencerAbson)


Changes


Multi-vector 8-bit floating-point multiply-add long (single)
```c
// Only if __ARM_FEATURE_SME_F8F16 != 0
void svmla[_single]_za16[_mf8]_vg2x1_fpm(uint32_t slice, svmfloat8_t zn,
 svmfloat8_t zm, fpm_t fpm)
 __arm_streaming __arm_inout("za");

void svmla[_single]_za16[_mf8]_vg2x2_fpm(uint32_t slice, svmfloat8x2_t zn,
 svmfloat8_t zm, fpm_t fpm)
 __arm_streaming __arm_inout("za");

void svmla[_single]_za16[_mf8]_vg2x4_fpm(uint32_t slice, svmfloat8x4_t zn,
 svmfloat8_t zm, fpm_t fpm)
 __arm_streaming __arm_inout("za");
// Only if __ARM_FEATURE_SME_F8F32 != 0
void svmla[_single]_za32[_mf8]_vg4x1_fpm(uint32_t slice, svmfloat8_t zn,
 svmfloat8_t zm, fpm_t fpm)
 __arm_streaming __arm_inout("za");

void svmla[_single]_za32[_mf8]_vg4x2_fpm(uint32_t slice, svmfloat8x2_t zn,
 svmfloat8_t zm, fpm_t fpm)
 __arm_streaming __arm_inout("za");

void svmla[_single]_za32[_mf8]_vg4x4_fpm(uint32_t slice, svmfloat8x4_t zn,
 svmfloat8_t zm, fpm_t fpm)
 __arm_streaming __arm_inout("za");
 ```
 In accordance with https://github.com/ARM-software/acle/pull/323.
 
Co-authored-by: Momchil Velikov momchil.velikov@arm.com

---

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


7 Files Affected:

- (modified) clang/include/clang/Basic/arm_sme.td (+14) 
- (added) clang/test/CodeGen/AArch64/fp8-intrinsics/acle_sme2_fp8_mla.c (+128) 
- (added) clang/test/Sema/aarch64-fp8-intrinsics/acle_sme_fp8_mla.c (+26) 
- (modified) llvm/include/llvm/IR/IntrinsicsAArch64.td (+31) 
- (modified) llvm/lib/Target/AArch64/AArch64SMEInstrInfo.td (+30-26) 
- (modified) llvm/lib/Target/AArch64/SMEInstrFormats.td (+34-23) 
- (added) llvm/test/CodeGen/AArch64/sme2-fp8-intrinsics-mla.ll (+101) 


``diff
diff --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index 71b2c7cdd04f93..8e5786f196a288 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -827,11 +827,25 @@ let SMETargetGuard = "sme-lutv2" in {
 let SMETargetGuard = "sme-f8f32" in {
   def SVMOPA_FP8_ZA32 : Inst<"svmopa_za32[_mf8]_m_fpm", "viPPdd>", "m", 
MergeNone, "aarch64_sme_fp8_fmopa_za32",
  [IsStreaming, IsInOutZA, SetsFPMR, 
IsOverloadNone], [ImmCheck<0, ImmCheck0_3>]>;
+  // FMLAL (single)
+  def SVMLA_FP8_SINGLE_ZA32_VG4x1 : 
Inst<"svmla[_single]_za32[_mf8]_vg4x1_fpm", "vmdd>", "m", MergeNone, 
"aarch64_sme_fp8_fmlall_single_za32_vg4x1",
+ [IsStreaming, IsInOutZA, SetsFPMR, 
IsOverloadNone], []>;
+  def SVMLA_FP8_SINGLE_ZA32_VG4x2 : 
Inst<"svmla[_single]_za32[_mf8]_vg4x2_fpm", "vm2d>", "m", MergeNone, 
"aarch64_sme_fp8_fmlall_single_za32_vg4x2",
+ [IsStreaming, IsInOutZA, SetsFPMR, 
IsOverloadNone], []>;
+  def SVMLA_FP8_SINGLE_ZA32_VG4x4 : 
Inst<"svmla[_single]_za32[_mf8]_vg4x4_fpm", "vm4d>", "m", MergeNone, 
"aarch64_sme_fp8_fmlall_single_za32_vg4x4",
+ [IsStreaming, IsInOutZA, SetsFPMR, 
IsOverloadNone], []>;
 }
 
 let SMETargetGuard = "sme-f8f16" in {
   def SVMOPA_FP8_ZA16 : Inst<"svmopa_za16[_mf8]_m_fpm", "viPPdd>", "m", 
MergeNone, "aarch64_sme_fp8_fmopa_za16",
  [IsStreaming, IsInOutZA, SetsFPMR, 
IsOverloadNone], [ImmCheck<0, ImmCheck0_1>]>;
+  // FMLAL (single)
+  def SVMLA_FP8_SINGLE_ZA16_VG2x1 : 
Inst<"svmla[_single]_za16[_mf8]_vg2x1_fpm", "vmdd>", "m", MergeNone, 
"aarch64_sme_fp8_fmlal_single_za16_vg2x1",
+ [IsStreaming, IsInOutZA, SetsFPMR, 
IsOverloadNone], []>;
+  def SVMLA_FP8_SINGLE_ZA16_VG2x2 : 
Inst<"svmla[_single]_za16[_mf8]_vg2x2_fpm", "vm2d>", "m", MergeNone, 
"aarch64_sme_fp8_fmlal_single_za16_vg2x2",
+ [IsStreaming, IsInOutZA, SetsFPMR, 
IsOverloadNone], []>;
+  def SVMLA_FP8_SINGLE_ZA16_VG2x4 : 
Inst<"svmla[_single]_za16[_mf8]_vg2x4_fpm", "vm4d>", "m", MergeNone, 
"aarch64_sme_fp8_fmlal_single_za16_vg2x4",
+ [IsStreaming, IsInOutZA, SetsFPMR, 
IsOverloadNone], []>;
 }
 
 } // let SVETargetGuard = InvalidMode
diff --git a/clang/test/CodeGen/AArch64/fp8-intrinsics/acle_sme2_fp8_mla.c 
b/clang/test/CodeGen/AArch64/fp8-intrinsics/acle_sme2_fp8_mla.c
new file mode 100644
index 00..0f6d45474c363f
--- /dev/null
+++ b/clang/test/CodeGen/AArch64/fp8-intrin

[clang] [llvm] [AArch64][FMV] Add missing feature dependencies and detect at runtime. (PR #119231)

2024-12-11 Thread Sander de Smalen via cfe-commits

https://github.com/sdesmalen-arm approved this pull request.


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


[clang] [llvm] [AArch64] Implement intrinsics for FMLAL/FMLALL (single) (PR #119568)

2024-12-11 Thread via cfe-commits


@@ -564,50 +564,50 @@ defm SMLALL_MZZI_BtoS  : 
sme2_mla_ll_array_index_32b<"smlall", 0b00, 0b000,
 defm SMLALL_VG2_M2ZZI_BtoS : sme2_mla_ll_array_vg2_index_32b<"smlall", 0b00, 
0b000, int_aarch64_sme_smla_za32_lane_vg4x2>;
 defm SMLALL_VG4_M4ZZI_BtoS : sme2_mla_ll_array_vg4_index_32b<"smlall", 0b00, 
0b, int_aarch64_sme_smla_za32_lane_vg4x4>;
 defm SMLALL_MZZ_BtoS   : sme2_mla_ll_array_single<"smlall", 0b0, 
MatrixOp32, ZPR8, ZPR4b8, nxv16i8, int_aarch64_sme_smla_za32_single_vg4x1>;
-defm SMLALL_VG2_M2ZZ_BtoS  : sme2_mla_ll_array_vg2_single<"smlall", 0b0, 
MatrixOp32, ZZ_b, ZPR4b8, nxv16i8, int_aarch64_sme_smla_za32_single_vg4x2>;
-defm SMLALL_VG4_M4ZZ_BtoS  : sme2_mla_ll_array_vg4_single<"smlall", 0b01000, 
MatrixOp32, _b, ZPR4b8, nxv16i8, int_aarch64_sme_smla_za32_single_vg4x4>;
+defm SMLALL_VG2_M2ZZ_BtoS  : sme2_mla_ll_array_vg2_single<"smlall", 0b00, 
MatrixOp32, ZZ_b, ZPR4b8, nxv16i8, int_aarch64_sme_smla_za32_single_vg4x2>;

SpencerAbson wrote:

These bit-strings have `0` appended to them as I removed the hard-coded `0b0` 
argument to `sme2_mla_ll_array_vg24_single` such that I could make use of the 
existing mutliclasses. I'd understand if it was preferred that I just create 
new multiclasses instead to simplify this patch.

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


[clang] [clang-tools-extra] [clangd] Update clangDaemonTweaks to set symbol visibility macros (PR #112304)

2024-12-11 Thread Vassil Vassilev via cfe-commits

vgvassilev wrote:

ping.

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


[clang] [llvm] [AArch64] Implement intrinsics for FMLAL/FMLALL (single) (PR #119568)

2024-12-11 Thread via cfe-commits

https://github.com/SpencerAbson created 
https://github.com/llvm/llvm-project/pull/119568


Multi-vector 8-bit floating-point multiply-add long (single)
```c
// Only if __ARM_FEATURE_SME_F8F16 != 0
void svmla[_single]_za16[_mf8]_vg2x1_fpm(uint32_t slice, svmfloat8_t zn,
 svmfloat8_t zm, fpm_t fpm)
 __arm_streaming __arm_inout("za");

void svmla[_single]_za16[_mf8]_vg2x2_fpm(uint32_t slice, svmfloat8x2_t zn,
 svmfloat8_t zm, fpm_t fpm)
 __arm_streaming __arm_inout("za");

void svmla[_single]_za16[_mf8]_vg2x4_fpm(uint32_t slice, svmfloat8x4_t zn,
 svmfloat8_t zm, fpm_t fpm)
 __arm_streaming __arm_inout("za");
// Only if __ARM_FEATURE_SME_F8F32 != 0
void svmla[_single]_za32[_mf8]_vg4x1_fpm(uint32_t slice, svmfloat8_t zn,
 svmfloat8_t zm, fpm_t fpm)
 __arm_streaming __arm_inout("za");

void svmla[_single]_za32[_mf8]_vg4x2_fpm(uint32_t slice, svmfloat8x2_t zn,
 svmfloat8_t zm, fpm_t fpm)
 __arm_streaming __arm_inout("za");

void svmla[_single]_za32[_mf8]_vg4x4_fpm(uint32_t slice, svmfloat8x4_t zn,
 svmfloat8_t zm, fpm_t fpm)
 __arm_streaming __arm_inout("za");
 ```
 In accordance with https://github.com/ARM-software/acle/pull/323.
 
Co-authored-by: Momchil Velikov momchil.veli...@arm.com




  
Unicorn! · GitHub

  body {
background-color: #f1f1f1;
margin: 0;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  }

  .container { margin: 50px auto 40px auto; width: 600px; text-align: 
center; }

  a { color: #4183c4; text-decoration: none; }
  a:hover { text-decoration: underline; }

  h1 { letter-spacing: -1px; line-height: 60px; font-size: 60px; 
font-weight: 100; margin: 0px; text-shadow: 0 1px 0 #fff; }
  p { color: rgba(0, 0, 0, 0.5); margin: 10px 0 10px; font-size: 18px; 
font-weight: 200; line-height: 1.6em;}

  ul { list-style: none; margin: 25px 0; padding: 0; }
  li { display: table-cell; font-weight: bold; width: 1%; }

  .logo { display: inline-block; margin-top: 35px; }
  .logo-img-2x { display: none; }
  @media
  only screen and (-webkit-min-device-pixel-ratio: 2),
  only screen and (   min--moz-device-pixel-ratio: 2),
  only screen and ( -o-min-device-pixel-ratio: 2/1),
  only screen and (min-device-pixel-ratio: 2),
  only screen and (min-resolution: 192dpi),
  only screen and (min-resolution: 2dppx) {
.logo-img-1x { display: none; }
.logo-img-2x { display: inline-block; }
  }

  #suggestions {
margin-top: 35px;
color: #ccc;
  }
  #suggestions a {
color: #66;
font-weight: 200;
font-size: 14px;
margin: 0 10px;
  }


  
  


  

  

  We had issues producing the response to your 
request.
  Sorry about that. Please try refreshing and contact us if the problem 
persists.
  
https://github.com/contact";>Contact Support —
https://www.githubstatus.com";>GitHub Status —
https://twitter.com/githubstatus";>@githubstatus
  

  

  

  

  

  


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


[clang] [llvm] [OpenMP]Initial parsing/sema support for target_device selector set (PR #118471)

2024-12-11 Thread Alexey Bataev via cfe-commits


@@ -15629,6 +15629,34 @@ ExprResult 
SemaOpenMP::VerifyPositiveIntegerConstantInClause(
   return ICE;
 }
 
+void SemaOpenMP::ActOnOpenMPDeviceNum(Expr *DeviceNumExpr) {
+  llvm::APSInt Result;
+  Expr::EvalResult EvalResult;
+  // Strip implicit casts from the expression
+  DeviceNumExpr = DeviceNumExpr->IgnoreImpCasts();

alexey-bataev wrote:

Why need to drop the casts here?

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


[clang] [clang-tools-extra] FunctionDecl::getFunctionTypeLoc: ignore function type attributes (PR #118420)

2024-12-11 Thread Robert Dazi via cfe-commits

https://github.com/v01dXYZ updated 
https://github.com/llvm/llvm-project/pull/118420

>From b6f013097c0003e37800ad13b420e50e3c84511b Mon Sep 17 00:00:00 2001
From: v01dxyz 
Date: Tue, 3 Dec 2024 04:52:33 +0100
Subject: [PATCH 1/6] FunctionDecl::getFunctionTypeLoc: ignore function type
 attributes

---
 clang/lib/AST/Decl.cpp | 13 +++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 741e908cf9bc56..7df66b3bb7e14d 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -3876,8 +3876,17 @@ bool 
FunctionDecl::doesDeclarationForceExternallyVisibleDefinition() const {
 
 FunctionTypeLoc FunctionDecl::getFunctionTypeLoc() const {
   const TypeSourceInfo *TSI = getTypeSourceInfo();
-  return TSI ? TSI->getTypeLoc().IgnoreParens().getAs()
- : FunctionTypeLoc();
+
+  if (!TSI)
+return FunctionTypeLoc();
+
+  TypeLoc TL = TSI->getTypeLoc().IgnoreParens();
+
+  // ignore function type attributes
+  while (auto ATL = TL.getAs())
+TL = ATL.getModifiedLoc();
+
+  return TL.getAs();
 }
 
 SourceRange FunctionDecl::getReturnTypeSourceRange() const {

>From d5faa43a7e9c27d9493b9a171fe4d283952a5103 Mon Sep 17 00:00:00 2001
From: v01dxyz 
Date: Sun, 8 Dec 2024 02:16:44 +0100
Subject: [PATCH 2/6] tmp: Add test and replace ignore parens by getAsAdjusted

---
 clang/lib/AST/Decl.cpp   |  8 +--
 clang/unittests/AST/AttrTest.cpp | 40 
 2 files changed, 41 insertions(+), 7 deletions(-)

diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 7df66b3bb7e14d..2ec5f5753427de 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -3880,13 +3880,7 @@ FunctionTypeLoc FunctionDecl::getFunctionTypeLoc() const 
{
   if (!TSI)
 return FunctionTypeLoc();
 
-  TypeLoc TL = TSI->getTypeLoc().IgnoreParens();
-
-  // ignore function type attributes
-  while (auto ATL = TL.getAs())
-TL = ATL.getModifiedLoc();
-
-  return TL.getAs();
+  return TSI->getTypeLoc().getAsAdjusted();
 }
 
 SourceRange FunctionDecl::getReturnTypeSourceRange() const {
diff --git a/clang/unittests/AST/AttrTest.cpp b/clang/unittests/AST/AttrTest.cpp
index 46c3f5729021ec..6cf879c4012510 100644
--- a/clang/unittests/AST/AttrTest.cpp
+++ b/clang/unittests/AST/AttrTest.cpp
@@ -86,6 +86,9 @@ TEST(Attr, AnnotateType) {
 struct S { int mem; };
 int [[clang::annotate_type("int")]]
 S::* [[clang::annotate_type("ptr_to_mem")]] ptr_to_member = &S::mem;
+
+// Function Type Attributes
+__attribute__((noreturn)) int f_noreturn();
   )cpp");
 
   {
@@ -153,6 +156,42 @@ TEST(Attr, AnnotateType) {
 EXPECT_EQ(IntTL.getType(), AST->getASTContext().IntTy);
   }
 
+  {
+const FunctionDecl *Func = getFunctionNode(AST.get(), "f_noreturn");
+const FunctionTypeLoc FTL = Func->getFunctionTypeLoc();
+const FunctionType *FT = FTL.getTypePtr();
+
+EXPECT_TRUE(FT->getExtInfo().getNoReturn());
+  }
+
+  // The following test verifies getFunctionTypeLoc returns a type
+  // which takes into account the attribute (instead of only the nake
+  // type).
+  //
+  // This is hard to do with C/C++ because it seems using a function
+  // type attribute with a C/C++ -function declaration only results
+  // with either:
+  //
+  // 1. It does NOT produce any AttributedType (for example it only
+  //   sets one flag of the FunctionType's ExtInfo, ie NoReturn).
+  // 2. It produces an AttributedType with modified type and
+  //   equivalent type that are equal (for example, that's what
+  //   happens with Calling Convention attributes).
+  //
+  // Fortunately, ObjC has one specific function type attribute that
+  // creates an AttributedType with different modified type and
+  // equivalent type.
+  auto AST_ObjC = buildASTFromCodeWithArgs(R"objc(
+__attribute__((ns_returns_retained)) id f();
+  )objc", {"-fobjc-arc",}, "input.mm");
+  {
+const FunctionDecl *f = getFunctionNode(AST_ObjC.get(), "f");
+const FunctionTypeLoc FTL = f->getFunctionTypeLoc();
+
+const FunctionType *FT = FTL.getTypePtr();
+EXPECT_TRUE(FT->getExtInfo().getProducesResult());
+  }
+
   // Test type annotation on an `__auto_type` type in C mode.
   AST = buildASTFromCodeWithArgs(R"c(
 __auto_type [[clang::annotate_type("auto")]] auto_var = 1;
@@ -166,6 +205,7 @@ TEST(Attr, AnnotateType) {
 AutoTypeLoc AutoTL;
 AssertAnnotatedAs(Var->getTypeSourceInfo()->getTypeLoc(), "auto", AutoTL);
   }
+
 }
 
 TEST(Attr, RegularKeywordAttribute) {

>From 7e647b98756f64fbcaccba808dae2abaf9bdb2d1 Mon Sep 17 00:00:00 2001
From: v01dxyz 
Date: Sun, 8 Dec 2024 02:55:33 +0100
Subject: [PATCH 3/6] tmp: getAsAdjusted use getModifiedLoc, replace the loop
 by a custom one

---
 clang/lib/AST/Decl.cpp | 14 +-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 2ec5f5753427de..110ef70562c72d 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clan

[clang] [llvm] [OpenMP]Initial parsing/sema support for target_device selector set (PR #118471)

2024-12-11 Thread Alexey Bataev via cfe-commits


@@ -15629,6 +15629,34 @@ ExprResult 
SemaOpenMP::VerifyPositiveIntegerConstantInClause(
   return ICE;
 }
 
+void SemaOpenMP::ActOnOpenMPDeviceNum(Expr *DeviceNumExpr) {
+  llvm::APSInt Result;
+  Expr::EvalResult EvalResult;
+  // Strip implicit casts from the expression
+  DeviceNumExpr = DeviceNumExpr->IgnoreImpCasts();
+  // Evaluate the expression to an integer value
+  if (DeviceNumExpr->EvaluateAsInt(EvalResult, SemaRef.Context)) {
+// The device expression must evaluate to a non-negative integer value.
+Result = EvalResult.Val.getInt();
+if (Result.isNonNegative()) {
+  OMPContext::DeviceNum = Result.getSExtValue();

alexey-bataev wrote:

`Result.getZExtValue()], since it is non-negative?

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


[clang-tools-extra] [clang-tidy] Create a check for signed and unsigned integers comparison (PR #113144)

2024-12-11 Thread via cfe-commits

qt-tatiana wrote:

> > if I already have 2 approvals, should I squash all fix-ups and merge?
> 
> see https://llvm.org/docs/CodeReview.html#lgtm-how-a-patch-is-accepted
> 
> I can help you to merge it. please feel free to ping me.

Thank you for help!

I squashed all fixups into the main change (used this instruction 
https://llvm.org/docs/GitHub.html#landing-your-change)

Whould it be possible to land the chamge? :-)

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


[clang] [C++20][Modules] Load function body from the module that gives canonical decl (PR #111992)

2024-12-11 Thread Dmitry Polukhin via cfe-commits

https://github.com/dmpolukhin updated 
https://github.com/llvm/llvm-project/pull/111992

>From 3eaaa7d70f4b57cc13bd00bd3a3a921f7914d599 Mon Sep 17 00:00:00 2001
From: Dmitry Polukhin 
Date: Fri, 11 Oct 2024 05:35:18 -0700
Subject: [PATCH 1/7] [C++20][Modules] Load function body from the module that
 gives cannonical decl

Summary:
Fix crash from reproducer provided in 
https://github.com/llvm/llvm-project/pull/109167#issuecomment-2405289565

Test Plan: TBD
---
 clang/lib/Serialization/ASTReader.cpp | 11 +++
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index ec85fad3389a1c..4184c32ea9eab5 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -10062,15 +10062,18 @@ void ASTReader::finishPendingActions() {
   // For a function defined inline within a class template, force the
   // canonical definition to be the one inside the canonical definition of
   // the template. This ensures that we instantiate from a correct view
-  // of the template.
+  // of the template. This behaviour seems to be important only for inline
+  // friend functions. For normal member functions, it might results in
+  // selecting canonical decl from module A but body from module B.
   //
   // Sadly we can't do this more generally: we can't be sure that all
   // copies of an arbitrary class definition will have the same members
   // defined (eg, some member functions may not be instantiated, and some
   // special members may or may not have been implicitly defined).
-  if (auto *RD = dyn_cast(FD->getLexicalParent()))
-if (RD->isDependentContext() && !RD->isThisDeclarationADefinition())
-  continue;
+  if (FD->getFriendObjectKind())
+if (auto *RD = dyn_cast(FD->getLexicalParent()))
+  if (RD->isDependentContext() && !RD->isThisDeclarationADefinition())
+continue;
 
   // FIXME: Check for =delete/=default?
   const FunctionDecl *Defn = nullptr;

>From d4e6cd0e074a5eaaaf09a3caafba0986ebb49949 Mon Sep 17 00:00:00 2001
From: Dmitry Polukhin 
Date: Fri, 11 Oct 2024 09:55:35 -0700
Subject: [PATCH 2/7] Add test case

---
 ...ash-instantiated-in-scope-cxx-modules4.cpp | 110 ++
 1 file changed, 110 insertions(+)
 create mode 100644 
clang/test/Headers/crash-instantiated-in-scope-cxx-modules4.cpp

diff --git a/clang/test/Headers/crash-instantiated-in-scope-cxx-modules4.cpp 
b/clang/test/Headers/crash-instantiated-in-scope-cxx-modules4.cpp
new file mode 100644
index 00..087eb135dc5f53
--- /dev/null
+++ b/clang/test/Headers/crash-instantiated-in-scope-cxx-modules4.cpp
@@ -0,0 +1,110 @@
+// RUN: rm -fR %t
+// RUN: split-file %s %t
+// RUN: cd %t
+// RUN: %clang_cc1 -verify -std=c++20 -x c++ -fmodule-map-file=modules.map 
-fmodule-name=foo1 -emit-module modules.map -o foo1.pcm
+// RUN: %clang_cc1 -verify -std=c++20 -x c++ -fmodule-map-file=modules.map 
-fmodule-name=foo2 -emit-module modules.map -o foo2.pcm
+// RUN: %clang_cc1 -verify -std=c++20 -x c++ -fmodule-map-file=modules.map 
-fmodule-file=foo1.pcm -fmodule-file=foo2.pcm server.cc
+
+//--- functional
+#pragma once
+
+namespace std {
+template  class function {};
+} // namespace std
+
+//--- foo.h
+#pragma once
+
+class MethodHandler {
+ public:
+  virtual ~MethodHandler() {}
+  struct HandlerParameter {
+HandlerParameter();
+  };
+  virtual void RunHandler(const HandlerParameter ¶m);
+};
+
+template 
+class CallbackUnaryHandler : public MethodHandler {
+ public:
+  explicit CallbackUnaryHandler();
+
+  void RunHandler(const HandlerParameter ¶m) final {
+void *call = nullptr;
+(void)[call](bool){};
+  }
+};
+
+//--- foo1.h
+// expected-no-diagnostics
+#pragma once
+
+#include "functional"
+
+#include "foo.h"
+
+class A;
+
+class ClientAsyncResponseReaderHelper {
+   public:
+  using t = std::function;
+static void SetupRequest(t finish);
+};
+
+//--- foo2.h
+// expected-no-diagnostics
+#pragma once
+
+#include "foo.h"
+
+template 
+class a : public BaseClass {
+ public:
+  a() { [[maybe_unused]] CallbackUnaryHandler a; }
+};
+
+//--- modules.map
+module "foo" {
+  export *
+  module "foo.h" {
+export *
+textual header "foo.h"
+  }
+}
+
+module "foo1" {
+  export *
+  module "foo1.h" {
+export *
+header "foo1.h"
+  }
+
+  use "foo"
+}
+
+module "foo2" {
+  export *
+  module "foo2.h" {
+export *
+header "foo2.h"
+  }
+
+  use "foo"
+}
+
+//--- server.cc
+// expected-no-diagnostics
+#include "functional"
+
+#include "foo1.h"
+#include "foo2.h"
+
+std::function on_emit;
+
+template 
+class CallbackUnaryHandler;
+
+class s {};
+class hs final : public a {
+  explicit hs() {}
+};

>From 51a60128fa9ea445228c12468caabc317e6adeb9 Mon Sep 17 00:00:00 2001
From: Dmitry Polukhin 
Date: Thu, 17 Oct 2024 06:44:23 -0700
Subject: [PATCH 3/7] Use mechanism for deserializing re

[clang-tools-extra] [clang-tidy][NFC][doc] clean out-dated clang-static-analyzer checks (PR #119580)

2024-12-11 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 created 
https://github.com/llvm/llvm-project/pull/119580

None

>From df8b95c76ef3b5be61b5cea6476eba80bcd16792 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Thu, 12 Dec 2024 00:20:01 +0800
Subject: [PATCH] [clang-tidy][NFC][doc] clean out-dated clang-static-analyzer
 checks

---
 .../clang-analyzer/cplusplus.PureVirtualCall.rst|  9 -
 .../clang-analyzer/cplusplus.SelfAssignment.rst | 13 +
 clang-tools-extra/docs/clang-tidy/checks/list.rst   | 13 +++--
 3 files changed, 16 insertions(+), 19 deletions(-)
 delete mode 100644 
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/cplusplus.PureVirtualCall.rst
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/cplusplus.SelfAssignment.rst

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/cplusplus.PureVirtualCall.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/cplusplus.PureVirtualCall.rst
deleted file mode 100644
index 9fab628b80d443..00
--- 
a/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/cplusplus.PureVirtualCall.rst
+++ /dev/null
@@ -1,9 +0,0 @@
-.. title:: clang-tidy - clang-analyzer-cplusplus.PureVirtualCall
-
-clang-analyzer-cplusplus.PureVirtualCall
-
-
-Check pure virtual function calls during construction/destruction.
-
-The clang-analyzer-cplusplus.PureVirtualCall check is an alias of
-Clang Static Analyzer cplusplus.PureVirtualCall.
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/cplusplus.SelfAssignment.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/cplusplus.SelfAssignment.rst
new file mode 100644
index 00..8e0deb4820d105
--- /dev/null
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/cplusplus.SelfAssignment.rst
@@ -0,0 +1,13 @@
+.. title:: clang-tidy - clang-analyzer-cplusplus.SelfAssignment
+.. meta::
+   :http-equiv=refresh: 
5;URL=https://clang.llvm.org/docs/analyzer/checkers.html#cplusplus-selfassignment
+
+clang-analyzer-cplusplus.SelfAssignment
+==
+
+Checks C++ copy and move assignment operators for self assignment.
+
+The `clang-analyzer-cplusplus.SelfAssignment` check is an alias, please see
+`Clang Static Analyzer Available Checkers
+`_
+for more information.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst 
b/clang-tools-extra/docs/clang-tidy/checks/list.rst
index d731b13fc0df44..d9e9cb67ef7a0b 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -458,7 +458,7 @@ Check aliases
:doc:`clang-analyzer-cplusplus.NewDelete 
`, `Clang Static Analyzer 
cplusplus.NewDelete 
`_,
:doc:`clang-analyzer-cplusplus.NewDeleteLeaks 
`, `Clang Static Analyzer 
cplusplus.NewDeleteLeaks 
`_,
:doc:`clang-analyzer-cplusplus.PlacementNew 
`, `Clang Static Analyzer 
cplusplus.PlacementNew 
`_,
-   :doc:`clang-analyzer-cplusplus.PureVirtualCall 
`, Clang Static Analyzer 
cplusplus.PureVirtualCall,
+   :doc:`clang-analyzer-cplusplus.SelfAssignment 
`, `Clang Static Analyzer 
cplusplus.SelfAssignment 
`_,
:doc:`clang-analyzer-cplusplus.StringChecker 
`, `Clang Static Analyzer 
cplusplus.StringChecker 
`_,
:doc:`clang-analyzer-deadcode.DeadStores 
`, `Clang Static Analyzer 
deadcode.DeadStores 
`_,
:doc:`clang-analyzer-fuchsia.HandleChecker 
`, `Clang Static Analyzer 
fuchsia.HandleChecker 
`_,
@@ -471,7 +471,6 @@ Check aliases
:doc:`clang-analyzer-optin.cplusplus.UninitializedObject 
`, `Clang Static Analyzer 
optin.cplusplus.UninitializedObject 
`_,
:doc:`clang-analyzer-optin.cplusplus.VirtualCall 
`, `Clang Static Analyzer 
optin.cplusplus.VirtualCall 
`_,
:doc:`clang-analyzer-optin.mpi.MPI-Checker 
`, `Clang Static Analyzer 
optin.mpi.MPI-Checker 
`_,
-   :doc:`clang-analyzer-optin.osx.OSObjectCStyleCast 
`, Clang Static Analyzer 
optin.osx.OSObjectCStyleCast,

:doc:`clang-analyzer-optin.osx.cocoa.localizability.EmptyLocalizationContextChecker
 
`,
 `Clang Static Analyzer 
optin.osx.cocoa.localizability.EmptyLocalizati

[clang] [C++20][Modules] Load function body from the module that gives canonical decl (PR #111992)

2024-12-11 Thread Dmitry Polukhin via cfe-commits


@@ -1976,14 +1976,16 @@ 
TemplateDeclInstantiator::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
   if (!InstParams)
 return nullptr;
 
+  // Use canonical templated decl because only canonical decl has body
+  // if declarations were merged during loading from modules.
+  FunctionDecl *TemplatedDecl = D->getTemplatedDecl()->getCanonicalDecl();

dmpolukhin wrote:

`FunctionDecl::hasBody` is doing what you described for `getRedeclWithDef`, see 
https://github.com/llvm/llvm-project/blob/main/clang/lib/AST/Decl.cpp#L3163 and 
if I used it here or implement similar code here, it fails several clang tests. 
It is very unfortunate that `Redeclarable` is used for two things: real 
redeclaration and AST merges. Moreover it look like there is no way to 
distinguish these two cases. I need to use different decl only if the decl was 
`doesThisDeclarationHaveABody() == true` but it is no longer the case due to 
AST merge.

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


[clang] [C++20][Modules] Load function body from the module that gives canonical decl (PR #111992)

2024-12-11 Thread Dmitry Polukhin via cfe-commits

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


[clang] [C++20][Modules] Load function body from the module that gives canonical decl (PR #111992)

2024-12-11 Thread Dmitry Polukhin via cfe-commits

https://github.com/dmpolukhin commented:

> The two problems I see are:
> 
> * invalid `no matching constructor for initialization of` errors for some 
> particular type,

I think it is due to applying my changes too wide (i.e. to normal member 
functions and use first decl for them). I hope I fixed it in the latest version.

> * a crash during template instantiations for some other particular type.

In this case it is harder to make a reasonable guess but perhaps also the same 
root.

> And a few things that seem minor at first glance, but would also need some 
> checking.
> 
> * some errors due to too long recursive template instantiations that we 
> didn't see before (probably correct and coming from instantiating those 
> bodies that were previously skipped?)
> * some compilation timeouts (probably just a flake or a slight increase that 
> we should mitigate on our end).
> 
> And there may be some long tail that's not visible because these issues take 
> all of my attention. I will try to get the reproducers for each of those. Or 
> would it make sense to wait until you finish the review and do that for the 
> new version?

Could you please try the latest version if it doesn't fix all issues, please 
create a reproducer to continue my investigation.

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


[clang-tools-extra] [clang-tidy][NFC][doc] clean out-dated clang-static-analyzer checks (PR #119580)

2024-12-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Congcong Cai (HerrCai0907)


Changes



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


3 Files Affected:

- (removed) 
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/cplusplus.PureVirtualCall.rst
 (-9) 
- (added) 
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/cplusplus.SelfAssignment.rst
 (+13) 
- (modified) clang-tools-extra/docs/clang-tidy/checks/list.rst (+3-10) 


``diff
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/cplusplus.PureVirtualCall.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/cplusplus.PureVirtualCall.rst
deleted file mode 100644
index 9fab628b80d443..00
--- 
a/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/cplusplus.PureVirtualCall.rst
+++ /dev/null
@@ -1,9 +0,0 @@
-.. title:: clang-tidy - clang-analyzer-cplusplus.PureVirtualCall
-
-clang-analyzer-cplusplus.PureVirtualCall
-
-
-Check pure virtual function calls during construction/destruction.
-
-The clang-analyzer-cplusplus.PureVirtualCall check is an alias of
-Clang Static Analyzer cplusplus.PureVirtualCall.
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/cplusplus.SelfAssignment.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/cplusplus.SelfAssignment.rst
new file mode 100644
index 00..8e0deb4820d105
--- /dev/null
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/cplusplus.SelfAssignment.rst
@@ -0,0 +1,13 @@
+.. title:: clang-tidy - clang-analyzer-cplusplus.SelfAssignment
+.. meta::
+   :http-equiv=refresh: 
5;URL=https://clang.llvm.org/docs/analyzer/checkers.html#cplusplus-selfassignment
+
+clang-analyzer-cplusplus.SelfAssignment
+==
+
+Checks C++ copy and move assignment operators for self assignment.
+
+The `clang-analyzer-cplusplus.SelfAssignment` check is an alias, please see
+`Clang Static Analyzer Available Checkers
+`_
+for more information.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst 
b/clang-tools-extra/docs/clang-tidy/checks/list.rst
index d731b13fc0df44..d9e9cb67ef7a0b 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -458,7 +458,7 @@ Check aliases
:doc:`clang-analyzer-cplusplus.NewDelete 
`, `Clang Static Analyzer 
cplusplus.NewDelete 
`_,
:doc:`clang-analyzer-cplusplus.NewDeleteLeaks 
`, `Clang Static Analyzer 
cplusplus.NewDeleteLeaks 
`_,
:doc:`clang-analyzer-cplusplus.PlacementNew 
`, `Clang Static Analyzer 
cplusplus.PlacementNew 
`_,
-   :doc:`clang-analyzer-cplusplus.PureVirtualCall 
`, Clang Static Analyzer 
cplusplus.PureVirtualCall,
+   :doc:`clang-analyzer-cplusplus.SelfAssignment 
`, `Clang Static Analyzer 
cplusplus.SelfAssignment 
`_,
:doc:`clang-analyzer-cplusplus.StringChecker 
`, `Clang Static Analyzer 
cplusplus.StringChecker 
`_,
:doc:`clang-analyzer-deadcode.DeadStores 
`, `Clang Static Analyzer 
deadcode.DeadStores 
`_,
:doc:`clang-analyzer-fuchsia.HandleChecker 
`, `Clang Static Analyzer 
fuchsia.HandleChecker 
`_,
@@ -471,7 +471,6 @@ Check aliases
:doc:`clang-analyzer-optin.cplusplus.UninitializedObject 
`, `Clang Static Analyzer 
optin.cplusplus.UninitializedObject 
`_,
:doc:`clang-analyzer-optin.cplusplus.VirtualCall 
`, `Clang Static Analyzer 
optin.cplusplus.VirtualCall 
`_,
:doc:`clang-analyzer-optin.mpi.MPI-Checker 
`, `Clang Static Analyzer 
optin.mpi.MPI-Checker 
`_,
-   :doc:`clang-analyzer-optin.osx.OSObjectCStyleCast 
`, Clang Static Analyzer 
optin.osx.OSObjectCStyleCast,

:doc:`clang-analyzer-optin.osx.cocoa.localizability.EmptyLocalizationContextChecker
 
`,
 `Clang Static Analyzer 
optin.osx.cocoa.localizability.EmptyLocalizationContextChecker 
`_,

:doc:`clang-analyzer-optin.osx.cocoa.localizability.NonLocalizedStringChecker 
`, 
`Clang Static Analyzer optin.osx.cocoa.localizability.NonLocalizedStringChecker 

[clang-tools-extra] [clang-tidy][NFC][doc] clean out-dated clang-static-analyzer checks (PR #119580)

2024-12-11 Thread via cfe-commits

llvmbot wrote:




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

Author: Congcong Cai (HerrCai0907)


Changes



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


3 Files Affected:

- (removed) 
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/cplusplus.PureVirtualCall.rst
 (-9) 
- (added) 
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/cplusplus.SelfAssignment.rst
 (+13) 
- (modified) clang-tools-extra/docs/clang-tidy/checks/list.rst (+3-10) 


``diff
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/cplusplus.PureVirtualCall.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/cplusplus.PureVirtualCall.rst
deleted file mode 100644
index 9fab628b80d443..00
--- 
a/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/cplusplus.PureVirtualCall.rst
+++ /dev/null
@@ -1,9 +0,0 @@
-.. title:: clang-tidy - clang-analyzer-cplusplus.PureVirtualCall
-
-clang-analyzer-cplusplus.PureVirtualCall
-
-
-Check pure virtual function calls during construction/destruction.
-
-The clang-analyzer-cplusplus.PureVirtualCall check is an alias of
-Clang Static Analyzer cplusplus.PureVirtualCall.
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/cplusplus.SelfAssignment.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/cplusplus.SelfAssignment.rst
new file mode 100644
index 00..8e0deb4820d105
--- /dev/null
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/cplusplus.SelfAssignment.rst
@@ -0,0 +1,13 @@
+.. title:: clang-tidy - clang-analyzer-cplusplus.SelfAssignment
+.. meta::
+   :http-equiv=refresh: 
5;URL=https://clang.llvm.org/docs/analyzer/checkers.html#cplusplus-selfassignment
+
+clang-analyzer-cplusplus.SelfAssignment
+==
+
+Checks C++ copy and move assignment operators for self assignment.
+
+The `clang-analyzer-cplusplus.SelfAssignment` check is an alias, please see
+`Clang Static Analyzer Available Checkers
+`_
+for more information.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst 
b/clang-tools-extra/docs/clang-tidy/checks/list.rst
index d731b13fc0df44..d9e9cb67ef7a0b 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -458,7 +458,7 @@ Check aliases
:doc:`clang-analyzer-cplusplus.NewDelete 
`, `Clang Static Analyzer 
cplusplus.NewDelete 
`_,
:doc:`clang-analyzer-cplusplus.NewDeleteLeaks 
`, `Clang Static Analyzer 
cplusplus.NewDeleteLeaks 
`_,
:doc:`clang-analyzer-cplusplus.PlacementNew 
`, `Clang Static Analyzer 
cplusplus.PlacementNew 
`_,
-   :doc:`clang-analyzer-cplusplus.PureVirtualCall 
`, Clang Static Analyzer 
cplusplus.PureVirtualCall,
+   :doc:`clang-analyzer-cplusplus.SelfAssignment 
`, `Clang Static Analyzer 
cplusplus.SelfAssignment 
`_,
:doc:`clang-analyzer-cplusplus.StringChecker 
`, `Clang Static Analyzer 
cplusplus.StringChecker 
`_,
:doc:`clang-analyzer-deadcode.DeadStores 
`, `Clang Static Analyzer 
deadcode.DeadStores 
`_,
:doc:`clang-analyzer-fuchsia.HandleChecker 
`, `Clang Static Analyzer 
fuchsia.HandleChecker 
`_,
@@ -471,7 +471,6 @@ Check aliases
:doc:`clang-analyzer-optin.cplusplus.UninitializedObject 
`, `Clang Static Analyzer 
optin.cplusplus.UninitializedObject 
`_,
:doc:`clang-analyzer-optin.cplusplus.VirtualCall 
`, `Clang Static Analyzer 
optin.cplusplus.VirtualCall 
`_,
:doc:`clang-analyzer-optin.mpi.MPI-Checker 
`, `Clang Static Analyzer 
optin.mpi.MPI-Checker 
`_,
-   :doc:`clang-analyzer-optin.osx.OSObjectCStyleCast 
`, Clang Static Analyzer 
optin.osx.OSObjectCStyleCast,

:doc:`clang-analyzer-optin.osx.cocoa.localizability.EmptyLocalizationContextChecker
 
`,
 `Clang Static Analyzer 
optin.osx.cocoa.localizability.EmptyLocalizationContextChecker 
`_,

:doc:`clang-analyzer-optin.osx.cocoa.localizability.NonLocalizedStringChecker 
`, 
`Clang Static Analyzer optin.osx.cocoa.localizability.NonLocalizedStringCh

[clang] [llvm] [clang][Modules] Fixing Build Breaks When -DLLVM_ENABLE_MODULES=ON (PR #119473)

2024-12-11 Thread Cyndy Ishida via cfe-commits


@@ -2,6 +2,7 @@ set(LLVM_LINK_COMPONENTS
   OrcShared
   OrcTargetProcess
   Support
+  Core

cyndyishida wrote:

Why did you need to add link dependencies? 

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


[clang] [C++20][Modules] Load function body from the module that gives canonical decl (PR #111992)

2024-12-11 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 0772a0bd29afa33520abf1c5a8bae09a718954b2 
936f4a705b91f958bfa531758222a14109f6a902 --extensions cpp,h -- 
clang/test/Headers/crash-instantiated-in-scope-cxx-modules4.cpp 
clang/test/Modules/friend-inline-function-body.cpp 
clang/include/clang/Serialization/ASTBitCodes.h 
clang/include/clang/Serialization/ASTReader.h 
clang/include/clang/Serialization/ASTWriter.h 
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
clang/lib/Serialization/ASTReader.cpp clang/lib/Serialization/ASTReaderDecl.cpp 
clang/lib/Serialization/ASTWriter.cpp clang/lib/Serialization/ASTWriterDecl.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index ede0257171..fa14e606a0 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -2155,9 +2155,9 @@ Decl *TemplateDeclInstantiator::VisitFunctionDecl(
   // definition during AST merges from different modules, in this case decl
   // with function body should be used for instantiation.
   if (isFriend) {
-const FunctionDecl* Defn = nullptr;
+const FunctionDecl *Defn = nullptr;
 if (D->hasBody(Defn)) {
-  D = const_cast(Defn);
+  D = const_cast(Defn);
   FunctionTemplate = Defn->getDescribedFunctionTemplate();
 }
   }

``




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


[clang-tools-extra] [clang-tidy][NFC][doc] clean out-dated clang-static-analyzer checks (PR #119580)

2024-12-11 Thread Congcong Cai via cfe-commits


@@ -0,0 +1,13 @@
+.. title:: clang-tidy - clang-analyzer-cplusplus.SelfAssignment
+.. meta::
+   :http-equiv=refresh: 
5;URL=https://clang.llvm.org/docs/analyzer/checkers.html#cplusplus-selfassignment
+
+clang-analyzer-cplusplus.SelfAssignment
+==

HerrCai0907 wrote:

```suggestion
===
```


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


[clang-tools-extra] [clang-tidy][NFC][doc] clean out-dated clang-static-analyzer checks (PR #119580)

2024-12-11 Thread Congcong Cai via cfe-commits

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

>From df8b95c76ef3b5be61b5cea6476eba80bcd16792 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Thu, 12 Dec 2024 00:20:01 +0800
Subject: [PATCH 1/2] [clang-tidy][NFC][doc] clean out-dated
 clang-static-analyzer checks

---
 .../clang-analyzer/cplusplus.PureVirtualCall.rst|  9 -
 .../clang-analyzer/cplusplus.SelfAssignment.rst | 13 +
 clang-tools-extra/docs/clang-tidy/checks/list.rst   | 13 +++--
 3 files changed, 16 insertions(+), 19 deletions(-)
 delete mode 100644 
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/cplusplus.PureVirtualCall.rst
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/cplusplus.SelfAssignment.rst

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/cplusplus.PureVirtualCall.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/cplusplus.PureVirtualCall.rst
deleted file mode 100644
index 9fab628b80d443..00
--- 
a/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/cplusplus.PureVirtualCall.rst
+++ /dev/null
@@ -1,9 +0,0 @@
-.. title:: clang-tidy - clang-analyzer-cplusplus.PureVirtualCall
-
-clang-analyzer-cplusplus.PureVirtualCall
-
-
-Check pure virtual function calls during construction/destruction.
-
-The clang-analyzer-cplusplus.PureVirtualCall check is an alias of
-Clang Static Analyzer cplusplus.PureVirtualCall.
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/cplusplus.SelfAssignment.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/cplusplus.SelfAssignment.rst
new file mode 100644
index 00..8e0deb4820d105
--- /dev/null
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/cplusplus.SelfAssignment.rst
@@ -0,0 +1,13 @@
+.. title:: clang-tidy - clang-analyzer-cplusplus.SelfAssignment
+.. meta::
+   :http-equiv=refresh: 
5;URL=https://clang.llvm.org/docs/analyzer/checkers.html#cplusplus-selfassignment
+
+clang-analyzer-cplusplus.SelfAssignment
+==
+
+Checks C++ copy and move assignment operators for self assignment.
+
+The `clang-analyzer-cplusplus.SelfAssignment` check is an alias, please see
+`Clang Static Analyzer Available Checkers
+`_
+for more information.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst 
b/clang-tools-extra/docs/clang-tidy/checks/list.rst
index d731b13fc0df44..d9e9cb67ef7a0b 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -458,7 +458,7 @@ Check aliases
:doc:`clang-analyzer-cplusplus.NewDelete 
`, `Clang Static Analyzer 
cplusplus.NewDelete 
`_,
:doc:`clang-analyzer-cplusplus.NewDeleteLeaks 
`, `Clang Static Analyzer 
cplusplus.NewDeleteLeaks 
`_,
:doc:`clang-analyzer-cplusplus.PlacementNew 
`, `Clang Static Analyzer 
cplusplus.PlacementNew 
`_,
-   :doc:`clang-analyzer-cplusplus.PureVirtualCall 
`, Clang Static Analyzer 
cplusplus.PureVirtualCall,
+   :doc:`clang-analyzer-cplusplus.SelfAssignment 
`, `Clang Static Analyzer 
cplusplus.SelfAssignment 
`_,
:doc:`clang-analyzer-cplusplus.StringChecker 
`, `Clang Static Analyzer 
cplusplus.StringChecker 
`_,
:doc:`clang-analyzer-deadcode.DeadStores 
`, `Clang Static Analyzer 
deadcode.DeadStores 
`_,
:doc:`clang-analyzer-fuchsia.HandleChecker 
`, `Clang Static Analyzer 
fuchsia.HandleChecker 
`_,
@@ -471,7 +471,6 @@ Check aliases
:doc:`clang-analyzer-optin.cplusplus.UninitializedObject 
`, `Clang Static Analyzer 
optin.cplusplus.UninitializedObject 
`_,
:doc:`clang-analyzer-optin.cplusplus.VirtualCall 
`, `Clang Static Analyzer 
optin.cplusplus.VirtualCall 
`_,
:doc:`clang-analyzer-optin.mpi.MPI-Checker 
`, `Clang Static Analyzer 
optin.mpi.MPI-Checker 
`_,
-   :doc:`clang-analyzer-optin.osx.OSObjectCStyleCast 
`, Clang Static Analyzer 
optin.osx.OSObjectCStyleCast,

:doc:`clang-analyzer-optin.osx.cocoa.localizability.EmptyLocalizationContextChecker
 
`,
 `Clang Static Analyzer 
optin.osx.cocoa.localizability.EmptyLocalization

[clang] [AST] Migrate away from PointerUnion::{is, get} (NFC) (PR #119523)

2024-12-11 Thread Kazu Hirata via cfe-commits

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


[clang] 624cc70 - [AST] Migrate away from PointerUnion::{is,get} (NFC) (#119523)

2024-12-11 Thread via cfe-commits

Author: Kazu Hirata
Date: 2024-12-11T08:35:41-08:00
New Revision: 624cc7048f604ed1087f63fdbe4cbf40f1d35b69

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

LOG: [AST] Migrate away from PointerUnion::{is,get} (NFC) (#119523)

Note that PointerUnion::{is,get} have been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //isa, cast and the llvm::dyn_cast

I'm not touching PointerUnion::dyn_cast for now because it's a bit
complicated; we could blindly migrate it to dyn_cast_if_present, but
we should probably use dyn_cast when the operand is known to be
non-null.

Added: 


Modified: 
clang/include/clang/AST/Decl.h
clang/include/clang/AST/DeclBase.h
clang/include/clang/AST/DeclCXX.h
clang/include/clang/AST/DeclTemplate.h
clang/include/clang/AST/ExprCXX.h
clang/include/clang/AST/ExprConcepts.h
clang/include/clang/AST/ExprObjC.h
clang/include/clang/AST/Redeclarable.h
clang/include/clang/AST/TemplateBase.h

Removed: 




diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 8c39ef3d5a9fa6..88d93a79d00f8f 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -747,9 +747,9 @@ class DeclaratorDecl : public ValueDecl {
   /// ignoring outer template declarations.
   SourceLocation InnerLocStart;
 
-  bool hasExtInfo() const { return DeclInfo.is(); }
-  ExtInfo *getExtInfo() { return DeclInfo.get(); }
-  const ExtInfo *getExtInfo() const { return DeclInfo.get(); }
+  bool hasExtInfo() const { return isa(DeclInfo); }
+  ExtInfo *getExtInfo() { return cast(DeclInfo); }
+  const ExtInfo *getExtInfo() const { return cast(DeclInfo); }
 
 protected:
   DeclaratorDecl(Kind DK, DeclContext *DC, SourceLocation L,
@@ -762,9 +762,8 @@ class DeclaratorDecl : public ValueDecl {
   friend class ASTDeclWriter;
 
   TypeSourceInfo *getTypeSourceInfo() const {
-return hasExtInfo()
-  ? getExtInfo()->TInfo
-  : DeclInfo.get();
+return hasExtInfo() ? getExtInfo()->TInfo
+: cast(DeclInfo);
   }
 
   void setTypeSourceInfo(TypeSourceInfo *TI) {
@@ -3587,10 +3586,10 @@ class TagDecl : public TypeDecl,
   /// otherwise, it is a null (TypedefNameDecl) pointer.
   llvm::PointerUnion TypedefNameDeclOrQualifier;
 
-  bool hasExtInfo() const { return TypedefNameDeclOrQualifier.is(); 
}
-  ExtInfo *getExtInfo() { return TypedefNameDeclOrQualifier.get(); }
+  bool hasExtInfo() const { return isa(TypedefNameDeclOrQualifier); 
}
+  ExtInfo *getExtInfo() { return cast(TypedefNameDeclOrQualifier); }
   const ExtInfo *getExtInfo() const {
-return TypedefNameDeclOrQualifier.get();
+return cast(TypedefNameDeclOrQualifier);
   }
 
 protected:
@@ -3793,7 +3792,7 @@ class TagDecl : public TypeDecl,
 
   TypedefNameDecl *getTypedefNameForAnonDecl() const {
 return hasExtInfo() ? nullptr
-: TypedefNameDeclOrQualifier.get();
+: cast(TypedefNameDeclOrQualifier);
   }
 
   void setTypedefNameForAnonDecl(TypedefNameDecl *TDD);
@@ -4011,7 +4010,7 @@ class EnumDecl : public TagDecl {
   return QualType();
 if (const Type *T = IntegerType.dyn_cast())
   return QualType(T, 0);
-return IntegerType.get()->getType().getUnqualifiedType();
+return cast(IntegerType)->getType().getUnqualifiedType();
   }
 
   /// Set the underlying integer type.

diff  --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index a3447d19909752..82932e098c86f0 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -271,16 +271,12 @@ class alignas(8) Decl {
   ///// LexicalDC == global namespace
   llvm::PointerUnion DeclCtx;
 
-  bool isInSemaDC() const { return DeclCtx.is(); }
-  bool isOutOfSemaDC() const { return DeclCtx.is(); }
+  bool isInSemaDC() const { return isa(DeclCtx); }
+  bool isOutOfSemaDC() const { return isa(DeclCtx); }
 
-  MultipleDC *getMultipleDC() const {
-return DeclCtx.get();
-  }
+  MultipleDC *getMultipleDC() const { return cast(DeclCtx); }
 
-  DeclContext *getSemanticDC() const {
-return DeclCtx.get();
-  }
+  DeclContext *getSemanticDC() const { return cast(DeclCtx); }
 
   /// Loc - The location of this decl.
   SourceLocation Loc;
@@ -1340,7 +1336,7 @@ class DeclListNode {
   assert(Ptr && "dereferencing end() iterator");
   if (DeclListNode *CurNode = Ptr.dyn_cast())
 return CurNode->D;
-  return Ptr.get();
+  return cast(Ptr);
 }
 void operator->() const { } // Unsupported.
 bool operator==(const iterator &X) const { return Ptr == X.Ptr; }

diff  --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index e389b5cd6df5b9

[clang-tools-extra] [clang-tidy] Create a check for signed and unsigned integers comparison (PR #113144)

2024-12-11 Thread Congcong Cai via cfe-commits

HerrCai0907 wrote:

> I squashed all fixups into the main change (used this instruction

actually github will do squash. please do not squash it manually in further pr.

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


[clang-tools-extra] [clang-tidy] Create a check for signed and unsigned integers comparison (PR #113144)

2024-12-11 Thread Congcong Cai via cfe-commits

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


[clang-tools-extra] 8b63bfb - [clang-tidy] Create a check for signed and unsigned integers comparison (#113144)

2024-12-11 Thread via cfe-commits

Author: qt-tatiana
Date: 2024-12-12T00:38:05+08:00
New Revision: 8b63bfbf6dd2ad0efd221407755300942a7ca35f

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

LOG: [clang-tidy] Create a check for signed and unsigned integers comparison 
(#113144)

- modernize-use-integer-sign-comparison replaces comparisons between
signed and unsigned integers with their safe C++20 ``std::cmp_*``
alternative, if available.

Added: 
clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp
clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.h

clang-tools-extra/docs/clang-tidy/checks/modernize/use-integer-sign-comparison.rst

clang-tools-extra/test/clang-tidy/checkers/modernize/use-integer-sign-comparison.cpp

Modified: 
clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index c919d49b42873a..bab1167fb15ff2 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -36,6 +36,7 @@ add_clang_library(clangTidyModernizeModule STATIC
   UseEmplaceCheck.cpp
   UseEqualsDefaultCheck.cpp
   UseEqualsDeleteCheck.cpp
+  UseIntegerSignComparisonCheck.cpp
   UseNodiscardCheck.cpp
   UseNoexceptCheck.cpp
   UseNullptrCheck.cpp

diff  --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index 18607593320635..fc46c72982fdce 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -37,6 +37,7 @@
 #include "UseEmplaceCheck.h"
 #include "UseEqualsDefaultCheck.h"
 #include "UseEqualsDeleteCheck.h"
+#include "UseIntegerSignComparisonCheck.h"
 #include "UseNodiscardCheck.h"
 #include "UseNoexceptCheck.h"
 #include "UseNullptrCheck.h"
@@ -76,6 +77,8 @@ class ModernizeModule : public ClangTidyModule {
 CheckFactories.registerCheck("modernize-pass-by-value");
 CheckFactories.registerCheck(
 "modernize-use-designated-initializers");
+CheckFactories.registerCheck(
+"modernize-use-integer-sign-comparison");
 CheckFactories.registerCheck("modernize-use-ranges");
 CheckFactories.registerCheck(
 "modernize-use-starts-ends-with");

diff  --git 
a/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp
new file mode 100644
index 00..8f807bc0a96d56
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp
@@ -0,0 +1,171 @@
+//===--- UseIntegerSignComparisonCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseIntegerSignComparisonCheck.h"
+#include "clang/AST/Expr.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+using namespace clang::ast_matchers::internal;
+
+namespace clang::tidy::modernize {
+
+/// Find if the passed type is the actual "char" type,
+/// not applicable to explicit "signed char" or "unsigned char" types.
+static bool isActualCharType(const clang::QualType &Ty) {
+  using namespace clang;
+  const Type *DesugaredType = Ty->getUnqualifiedDesugaredType();
+  if (const auto *BT = llvm::dyn_cast(DesugaredType))
+return (BT->getKind() == BuiltinType::Char_U ||
+BT->getKind() == BuiltinType::Char_S);
+  return false;
+}
+
+namespace {
+AST_MATCHER(clang::QualType, isActualChar) {
+  return clang::tidy::modernize::isActualCharType(Node);
+}
+} // namespace
+
+static BindableMatcher
+intCastExpression(bool IsSigned,
+  const std::string &CastBindName = std::string()) {
+  // std::cmp_{} functions trigger a compile-time error if either LHS or RHS
+  // is a non-integer type, char, enum or bool
+  // (unsigned char/ signed char are Ok and can be used).
+  auto IntTypeExpr = expr(hasType(hasCanonicalType(qualType(
+  isInteger(), IsSigned ? isSignedInteger() : isUnsignedInteger(),
+  unless(isActualChar()), unless(booleanType()), unless(enumType());
+
+  const auto ImplicitCastExpr =
+  CastBindName.empty() ? implicitCastExpr(hasSourceExpr

[clang] [llvm] [clang][Modules] Fixing Build Breaks When -DLLVM_ENABLE_MODULES=ON (PR #119473)

2024-12-11 Thread Qiongsi Wu via cfe-commits


@@ -2,6 +2,7 @@ set(LLVM_LINK_COMPONENTS
   OrcShared
   OrcTargetProcess
   Support
+  Core

qiongsiwu wrote:

Good question! @Bigcheese and myself discussed. We technically may not need 
`Core` here and I will revise. The dependency comes from 
https://github.com/llvm/llvm-project/blob/00e1cc4c9d002c78cf890b630343b052ebca0399/llvm/include/llvm/SandboxIR/Type.h#L286.
 Specifically, the new `SandBoxIR` code uses a function (`Type::print`) from 
`LLVMCore`.  Linking fails without the dependency.

The `SandBoxIR` code currently does not have module maps at all and I will go 
ahead and add them. Maybe we will no longer need the dependencies after the 
module maps are added. 

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


[clang-tools-extra] [clang-tidy] Create a check for signed and unsigned integers comparison (PR #113144)

2024-12-11 Thread via cfe-commits

github-actions[bot] wrote:



@qt-tatiana Congratulations on having your first Pull Request (PR) merged into 
the LLVM Project!

Your changes will be combined with recent changes from other authors, then 
tested by our [build bots](https://lab.llvm.org/buildbot/). If there is a 
problem with a build, you may receive a report in an email or a comment on this 
PR.

Please check whether problems have been caused by your change specifically, as 
the builds can include changes from many authors. It is not uncommon for your 
change to be included in a build that fails due to someone else's changes, or 
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail 
[here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr).

If your change does cause a problem, it may be reverted, or you can revert it 
yourself. This is a normal part of [LLVM 
development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy).
 You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are 
working as expected, well done!


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


[clang] [llvm] [clang][Modules] Fixing Build Breaks When -DLLVM_ENABLE_MODULES=ON (PR #119473)

2024-12-11 Thread Qiongsi Wu via cfe-commits

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


[clang] [AST] Migrate away from PointerUnion::{is, get} (NFC) (PR #119523)

2024-12-11 Thread Kazu Hirata via cfe-commits

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


[clang] [llvm] [clang][Modules] Fixing Build Breaks When -DLLVM_ENABLE_MODULES=ON (PR #119473)

2024-12-11 Thread Qiongsi Wu via cfe-commits

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


[clang] [llvm] [AArch64][FMV] Add missing feature dependencies and detect at runtime. (PR #119231)

2024-12-11 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea updated 
https://github.com/llvm/llvm-project/pull/119231

>From f6f2fd6aac09a0f2c14545e1fbda9aec7eb2ed46 Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Mon, 9 Dec 2024 13:00:58 +
Subject: [PATCH 1/2] [AArch64][FMV] Add missing feature dependencies and
 detect at runtime.

i8mm -> simd
fp16fml -> simd
frintts -> fp
bf16 -> simd
sme -> fp16

Approved in ACLE as https://github.com/ARM-software/acle/pull/368
---
 clang/test/CodeGen/AArch64/cpu-supports.c |   8 +-
 clang/test/CodeGen/AArch64/fmv-dependencies.c |   8 +-
 .../CodeGen/AArch64/mixed-target-attributes.c |  32 ++---
 .../test/CodeGen/attr-target-clones-aarch64.c |  88 ++---
 clang/test/CodeGen/attr-target-version.c  | 120 +-
 .../CodeGenCXX/attr-target-clones-aarch64.cpp |  24 ++--
 clang/test/CodeGenCXX/attr-target-version.cpp |  20 +--
 clang/test/CodeGenCXX/fmv-namespace.cpp   |   4 +-
 .../llvm/TargetParser/AArch64TargetParser.h   |   3 +
 llvm/lib/Target/AArch64/AArch64Features.td|  11 +-
 llvm/lib/TargetParser/AArch64TargetParser.cpp |  22 +++-
 .../sve-streaming-mode-cvt-fp-int-fp.ll   |  16 ---
 .../SME/streaming-mode-neon-negative.s|   4 +-
 .../MC/AArch64/SME/streaming-sve-feature.s|   2 +-
 llvm/test/MC/AArch64/armv8a-fpmul.s   |  28 +---
 15 files changed, 180 insertions(+), 210 deletions(-)

diff --git a/clang/test/CodeGen/AArch64/cpu-supports.c 
b/clang/test/CodeGen/AArch64/cpu-supports.c
index 76fcea0be31581..406201781d4803 100644
--- a/clang/test/CodeGen/AArch64/cpu-supports.c
+++ b/clang/test/CodeGen/AArch64/cpu-supports.c
@@ -18,8 +18,8 @@
 // CHECK-NEXT:br label [[RETURN:%.*]]
 // CHECK:   if.end:
 // CHECK-NEXT:[[TMP4:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
-// CHECK-NEXT:[[TMP5:%.*]] = and i64 [[TMP4]], 17867063951360
-// CHECK-NEXT:[[TMP6:%.*]] = icmp eq i64 [[TMP5]], 17867063951360
+// CHECK-NEXT:[[TMP5:%.*]] = and i64 [[TMP4]], 17936857268992
+// CHECK-NEXT:[[TMP6:%.*]] = icmp eq i64 [[TMP5]], 17936857268992
 // CHECK-NEXT:[[TMP7:%.*]] = and i1 true, [[TMP6]]
 // CHECK-NEXT:br i1 [[TMP7]], label [[IF_THEN1:%.*]], label [[IF_END2:%.*]]
 // CHECK:   if.then1:
@@ -27,8 +27,8 @@
 // CHECK-NEXT:br label [[RETURN]]
 // CHECK:   if.end2:
 // CHECK-NEXT:[[TMP8:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
-// CHECK-NEXT:[[TMP9:%.*]] = and i64 [[TMP8]], 171136785840078848
-// CHECK-NEXT:[[TMP10:%.*]] = icmp eq i64 [[TMP9]], 171136785840078848
+// CHECK-NEXT:[[TMP9:%.*]] = and i64 [[TMP8]], 171141184020873984
+// CHECK-NEXT:[[TMP10:%.*]] = icmp eq i64 [[TMP9]], 171141184020873984
 // CHECK-NEXT:[[TMP11:%.*]] = and i1 true, [[TMP10]]
 // CHECK-NEXT:br i1 [[TMP11]], label [[IF_THEN3:%.*]], label 
[[IF_END4:%.*]]
 // CHECK:   if.then3:
diff --git a/clang/test/CodeGen/AArch64/fmv-dependencies.c 
b/clang/test/CodeGen/AArch64/fmv-dependencies.c
index f74b7aa32c7dca..3a524b89496e04 100644
--- a/clang/test/CodeGen/AArch64/fmv-dependencies.c
+++ b/clang/test/CodeGen/AArch64/fmv-dependencies.c
@@ -183,10 +183,10 @@ int caller() {
 // CHECK: attributes #[[sha2]] = { {{.*}} 
"target-features"="+fmv,+fp-armv8,+neon,+outline-atomics,+sha2,+v8a"
 // CHECK: attributes #[[sha3]] = { {{.*}} 
"target-features"="+fmv,+fp-armv8,+neon,+outline-atomics,+sha2,+sha3,+v8a"
 // CHECK: attributes #[[sm4]] = { {{.*}} 
"target-features"="+fmv,+fp-armv8,+neon,+outline-atomics,+sm4,+v8a"
-// CHECK: attributes #[[sme]] = { {{.*}} 
"target-features"="+bf16,+fmv,+fp-armv8,+neon,+outline-atomics,+sme,+v8a"
-// CHECK: attributes #[[sme_f64f64]] = { {{.*}} 
"target-features"="+bf16,+fmv,+fp-armv8,+neon,+outline-atomics,+sme,+sme-f64f64,+v8a"
-// CHECK: attributes #[[sme_i16i64]] = { {{.*}} 
"target-features"="+bf16,+fmv,+fp-armv8,+neon,+outline-atomics,+sme,+sme-i16i64,+v8a"
-// CHECK: attributes #[[sme2]] = { {{.*}} 
"target-features"="+bf16,+fmv,+fp-armv8,+neon,+outline-atomics,+sme,+sme2,+v8a"
+// CHECK: attributes #[[sme]] = { {{.*}} 
"target-features"="+bf16,+fmv,+fp-armv8,+fullfp16,+neon,+outline-atomics,+sme,+v8a"
+// CHECK: attributes #[[sme_f64f64]] = { {{.*}} 
"target-features"="+bf16,+fmv,+fp-armv8,+fullfp16,+neon,+outline-atomics,+sme,+sme-f64f64,+v8a"
+// CHECK: attributes #[[sme_i16i64]] = { {{.*}} 
"target-features"="+bf16,+fmv,+fp-armv8,+fullfp16,+neon,+outline-atomics,+sme,+sme-i16i64,+v8a"
+// CHECK: attributes #[[sme2]] = { {{.*}} 
"target-features"="+bf16,+fmv,+fp-armv8,+fullfp16,+neon,+outline-atomics,+sme,+sme2,+v8a"
 // CHECK: attributes #[[ssbs]] = { {{.*}} 
"target-features"="+fmv,+fp-armv8,+neon,+outline-atomics,+ssbs,+v8a"
 // CHECK: attributes #[[sve]] = { {{.*}} 
"target-features"="+fmv,+fp-armv8,+fullfp16,+neon,+outline-atomics,+sve,+v8a"
 // CHECK: attributes #[[sve2]] = { {{.*}} 
"target-features"="+fmv,+fp-armv8,+fullfp16,+neon,+outline-atomics,+sve,+sve2,+v8a"
diff --git a/clang/test/CodeGen/AArch64/mixed-target-attributes.c 
b/c

[clang] 1946d32 - [Clang] Improve error for `-fsanitize=function/kcfi -mexecute-only` incompatibility (#118816)

2024-12-11 Thread via cfe-commits

Author: Csanád Hajdú
Date: 2024-12-11T09:06:56-08:00
New Revision: 1946d32f1fdfb2c4d5e866a5c1c5c32b8cdad5b8

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

LOG: [Clang] Improve error for `-fsanitize=function/kcfi -mexecute-only` 
incompatibility (#118816)

The current error message when using the `-fsanitize=function
-mexecute-only` flags together points to the target triple as the reason
that `-fsanitize=function` is not allowed to be used, even when the
function sanitizer is otherwise supported on the target when not using
`-mexecute-only`.

The error message is improved to give `-mexecute-only` as the reason for
disallowing `-fsanitize=function` if it was passed to the driver.

Fixes https://github.com/llvm/llvm-project/issues/117974

Added: 


Modified: 
clang/lib/Driver/SanitizerArgs.cpp
clang/test/Driver/fsanitize.c

Removed: 




diff  --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index 1abfe8fd92807e..e77857930996b2 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -418,8 +418,14 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
 Add & NotAllowedWithExecuteOnly & ~DiagnosedKinds) {
   if (DiagnoseErrors) {
 std::string Desc = describeSanitizeArg(Arg, KindsToDiagnose);
-D.Diag(diag::err_drv_argument_not_allowed_with)
-<< Desc << Triple.str();
+llvm::opt::Arg *A = Args.getLastArgNoClaim(
+options::OPT_mexecute_only, options::OPT_mno_execute_only);
+if (A && A->getOption().matches(options::OPT_mexecute_only))
+  D.Diag(diag::err_drv_argument_not_allowed_with)
+  << Desc << A->getAsString(Args);
+else
+  D.Diag(diag::err_drv_unsupported_opt_for_target)
+  << Desc << Triple.str();
   }
   DiagnosedKinds |= KindsToDiagnose;
 }

diff  --git a/clang/test/Driver/fsanitize.c b/clang/test/Driver/fsanitize.c
index 15f190165a7d73..bb692b2aeea1d3 100644
--- a/clang/test/Driver/fsanitize.c
+++ b/clang/test/Driver/fsanitize.c
@@ -989,19 +989,25 @@
 // RUN: not %clang --target=x86_64-linux-gnu -fsanitize=undefined,function 
-mcmodel=large %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-UBSAN-FUNCTION-CODE-MODEL
 // CHECK-UBSAN-FUNCTION-CODE-MODEL: error: invalid argument 
'-fsanitize=function' only allowed with '-mcmodel=small'
 
-// RUN: not %clang --target=x86_64-sie-ps5 -fsanitize=function %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-UBSAN-FUNCTION
-// RUN: not %clang --target=x86_64-sie-ps5 -fsanitize=undefined 
-fsanitize=function %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-UBSAN-FUNCTION
-// RUN: not %clang --target=x86_64-sie-ps5 -fsanitize=kcfi %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-UBSAN-KCFI
-// RUN: not %clang --target=x86_64-sie-ps5 -fsanitize=function -fsanitize=kcfi 
%s -### 2>&1 | FileCheck %s  --check-prefix=CHECK-UBSAN-KCFI 
--check-prefix=CHECK-UBSAN-FUNCTION
+// RUN: not %clang --target=x86_64-sie-ps5 -fsanitize=function %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-UBSAN-FUNCTION-TARGET
+// RUN: not %clang --target=x86_64-sie-ps5 -fsanitize=undefined 
-fsanitize=function %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-UBSAN-FUNCTION-TARGET
+// RUN: not %clang --target=x86_64-sie-ps5 -fsanitize=kcfi %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-UBSAN-KCFI-TARGET
+// RUN: not %clang --target=x86_64-sie-ps5 -fsanitize=function -fsanitize=kcfi 
%s -### 2>&1 | FileCheck %s  --check-prefix=CHECK-UBSAN-KCFI-TARGET 
--check-prefix=CHECK-UBSAN-FUNCTION-TARGET
 // RUN: %clang --target=x86_64-sie-ps5 -fsanitize=undefined %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-UBSAN-UNDEFINED
 // CHECK-UBSAN-UNDEFINED: 
"-fsanitize={{((alignment|array-bounds|bool|builtin|enum|float-cast-overflow|integer-divide-by-zero|nonnull-attribute|null|pointer-overflow|return|returns-nonnull-attribute|shift-base|shift-exponent|signed-integer-overflow|unreachable|vla-bound),?){17}"}}
 
-// RUN: not %clang --target=armv6t2-eabi -mexecute-only -fsanitize=function %s 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-FUNCTION
-// RUN: not %clang --target=armv6t2-eabi -mexecute-only -fsanitize=kcfi %s 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-KCFI
+// RUN: not %clang --target=armv6t2-eabi -mexecute-only -fsanitize=function %s 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-FUNCTION-MEXECUTE-ONLY
+// RUN: not %clang --target=armv6t2-eabi -mpure-code -fsanitize=function %s 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-FUNCTION-MPURE-CODE
+// RUN: not %clang --target=armv6t2-eabi -mexecute-only -fsanitize=kcfi %s 
-### 2>&1 | FileCheck %s --check-prefix=CHECK-UBSAN-KCFI

[clang] [Clang] Improve error for `-fsanitize=function/kcfi -mexecute-only` incompatibility (PR #118816)

2024-12-11 Thread Fangrui Song via cfe-commits
=?utf-8?q?Csanád_Hajdú?= 
Message-ID:
In-Reply-To: 


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


[clang-tools-extra] [clang-tidy] Create a check for signed and unsigned integers comparison (PR #113144)

2024-12-11 Thread via cfe-commits

qt-tatiana wrote:

> > I squashed all fixups into the main change (used this instruction
> 
> actually github will do squash. please do not squash it manually in further 
> pr.

Ooops, I didn't know. Thank you!

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


[clang-tools-extra] [analyzer] Split alpha core Identical Expression tests (PR #119543)

2024-12-11 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: None (vabridgers)


Changes

Split the remnant test from PR #114715, "Remove 
alpha.core.IdenticalExpr Checker" into seperate tests for 
misc-redundant-expression and bugprone-branch-clone per review comment requests.

---

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


2 Files Affected:

- (added) 
clang-tools-extra/test/clang-tidy/checkers/bugprone/bugprone-branch-clone.cpp 
(+772) 
- (renamed) 
clang-tools-extra/test/clang-tidy/checkers/misc/misc-redundant-expression.cpp 
(-416) 


``diff
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/bugprone-branch-clone.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/bugprone-branch-clone.cpp
new file mode 100644
index 00..fa19037cc437e3
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/bugprone-branch-clone.cpp
@@ -0,0 +1,772 @@
+// RUN: clang-tidy %s -checks="-*,bugprone-branch-clone" -- 2>&1 | FileCheck 
%s --check-prefix=CHECK-MESSAGES-BUGPRONEBRANCH
+
+/* Only one expected warning per function allowed at the very end. */
+
+int func(void)
+{
+  return 0;
+}
+
+int func2(void)
+{
+  return 0;
+}
+
+int funcParam(int a)
+{
+  return 0;
+}
+
+/* '!=' operator*/
+
+
+/* '!=' with int pointer */
+
+int checkNotEqualIntPointerLiteralCompare1(void) {
+  int* p = 0;
+  return (p != 0); // no warning
+}
+
+int checkNotEqualIntPointerLiteralCompare2(void) {
+  return (6 != 7); // no warning
+}
+
+int checkNotEqualIntPointerDeclCompare1(void) {
+  int k = 3;
+  int* f = &k;
+  int* g = &k;
+  return (f != g); // no warning
+}
+
+int checkNotEqualCastIntPointerDeclCompare11(void) {
+  int k = 7;
+  int* f = &k;
+  return ((int*)f != (int*)f);
+// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:19: warning: both sides of operator 
are equivalent [misc-redundant-expression]
+}
+int checkNotEqualCastIntPointerDeclCompare12(void) {
+  int k = 7;
+  int* f = &k;
+  return ((int*)((char*)f) != (int*)f); // no warning
+}
+int checkNotEqualBinaryOpIntPointerCompare1(void) {
+  int k = 7;
+  int res;
+  int* f= &k;
+  res = (f + 4 != f + 4);
+// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:16: warning: both sides of operator 
are equivalent [misc-redundant-expression]
+  return (0);
+}
+int checkNotEqualBinaryOpIntPointerCompare2(void) {
+  int k = 7;
+  int* f = &k;
+  int* g = &k;
+  return (f + 4 != g + 4); // no warning
+}
+
+
+int checkNotEqualBinaryOpIntPointerCompare3(void) {
+  int k = 7;
+  int res;
+  int* f= &k;
+  res = ((int*)f + 4 != (int*)f + 4);
+// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:22: warning: both sides of operator 
are equivalent [misc-redundant-expression]
+  return (0);
+}
+int checkNotEqualBinaryOpIntPointerCompare4(void) {
+  int k = 7;
+  int res;
+  int* f= &k;
+  res = ((int*)f + 4 != (int*)((char*)f) + 4);  // no warning
+  return (0);
+}
+
+int checkNotEqualNestedBinaryOpIntPointerCompare1(void) {
+  int res;
+  int k = 7;
+  int t= 1;
+  int* u= &k+2;
+  int* f= &k+3;
+  res = ((f + (3)*t) != (f + (3)*t));
+// CHECK-MESSAGES-IDENTEXPR: :[[@LINE-1]]:22: warning: both sides of operator 
are equivalent [misc-redundant-expression]
+  return (0);
+}
+
+int checkNotEqualNestedBinaryOpIntPointerCompare2(void) {
+  int res;
+  int k = 7;
+  int t= 1;
+  int* u= &k+2;
+  int* f= &k+3;
+  res = (((3)*t + f) != (f + (3)*t));  // no warning
+  return (0);
+}
+/*   end '!=' int*  */
+
+/* '!=' with function*/
+
+int checkNotEqualSameFunction() {
+  unsigned a = 0;
+  unsigned b = 1;
+  int res = (a+func() != a+func());  // no warning
+  return (0);
+}
+
+int checkNotEqualDifferentFunction() {
+  unsigned a = 0;
+  unsigned b = 1;
+  int res = (a+func() != a+func2());  // no warning
+  return (0);
+}
+
+int checkNotEqualSameFunctionSameParam() {
+  unsigned a = 0;
+  unsigned b = 1;
+  int res = (a+funcParam(a) != a+funcParam(a));  // no warning
+  return (0);
+}
+
+int checkNotEqualSameFunctionDifferentParam() {
+  unsigned a = 0;
+  unsigned b = 1;
+  int res = (a+funcParam(a) != a+funcParam(b));  // no warning
+  return (0);
+}
+
+/*   end '!=' with function*/
+
+/*   end '!=' */
+
+
+/* Checking use of identical expressions in conditional operator*/
+
+unsigned test_unsigned(unsigned a) {
+  unsigned b = 1;
+  a = a > 5 ? b : b;
+// CHECK-MESSAGES-BUGPRONEBRANCH: :[[@LINE-1]]:13: warning: conditional 
operator with identical true and false expressions [bugprone-branch-clone]
+  return a;
+}
+
+void test_signed() {
+  int a = 0;
+  a = a > 5 ? a : a;
+// CHECK-MESSAGES-BUGPRONEBRANCH: :[[@LINE-1]]:13: warning: conditional 
operator with identical true and false expressions [bugprone-branch-clone]
+}
+
+void test_bool(bool a) {
+  a = a > 0 ? a : a;
+// CHECK-MESSAGES-BUGPRONEBRANCH: :[[@LINE-1]]:13: warning: conditional 
operator with identical true and false expressions [bugprone-branch-clone]
+}
+
+void test_float() {
+  float a = 0;
+  float b = 0;
+  a = a >

[clang] [clang] Fix sub-integer __builtin_elementwise_(add|sub)_sat (PR #119423)

2024-12-11 Thread Fraser Cormack via cfe-commits

frasercrmck wrote:

I just realised this is also a problem with the `bitreverse` and `popcount` 
builtins on signed types for the same reason.

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


[clang] [C++20][Modules] Load function body from the module that gives canonical decl (PR #111992)

2024-12-11 Thread Dmitry Polukhin via cfe-commits

https://github.com/dmpolukhin updated 
https://github.com/llvm/llvm-project/pull/111992

>From 3eaaa7d70f4b57cc13bd00bd3a3a921f7914d599 Mon Sep 17 00:00:00 2001
From: Dmitry Polukhin 
Date: Fri, 11 Oct 2024 05:35:18 -0700
Subject: [PATCH 1/8] [C++20][Modules] Load function body from the module that
 gives cannonical decl

Summary:
Fix crash from reproducer provided in 
https://github.com/llvm/llvm-project/pull/109167#issuecomment-2405289565

Test Plan: TBD
---
 clang/lib/Serialization/ASTReader.cpp | 11 +++
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index ec85fad3389a1c..4184c32ea9eab5 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -10062,15 +10062,18 @@ void ASTReader::finishPendingActions() {
   // For a function defined inline within a class template, force the
   // canonical definition to be the one inside the canonical definition of
   // the template. This ensures that we instantiate from a correct view
-  // of the template.
+  // of the template. This behaviour seems to be important only for inline
+  // friend functions. For normal member functions, it might results in
+  // selecting canonical decl from module A but body from module B.
   //
   // Sadly we can't do this more generally: we can't be sure that all
   // copies of an arbitrary class definition will have the same members
   // defined (eg, some member functions may not be instantiated, and some
   // special members may or may not have been implicitly defined).
-  if (auto *RD = dyn_cast(FD->getLexicalParent()))
-if (RD->isDependentContext() && !RD->isThisDeclarationADefinition())
-  continue;
+  if (FD->getFriendObjectKind())
+if (auto *RD = dyn_cast(FD->getLexicalParent()))
+  if (RD->isDependentContext() && !RD->isThisDeclarationADefinition())
+continue;
 
   // FIXME: Check for =delete/=default?
   const FunctionDecl *Defn = nullptr;

>From d4e6cd0e074a5eaaaf09a3caafba0986ebb49949 Mon Sep 17 00:00:00 2001
From: Dmitry Polukhin 
Date: Fri, 11 Oct 2024 09:55:35 -0700
Subject: [PATCH 2/8] Add test case

---
 ...ash-instantiated-in-scope-cxx-modules4.cpp | 110 ++
 1 file changed, 110 insertions(+)
 create mode 100644 
clang/test/Headers/crash-instantiated-in-scope-cxx-modules4.cpp

diff --git a/clang/test/Headers/crash-instantiated-in-scope-cxx-modules4.cpp 
b/clang/test/Headers/crash-instantiated-in-scope-cxx-modules4.cpp
new file mode 100644
index 00..087eb135dc5f53
--- /dev/null
+++ b/clang/test/Headers/crash-instantiated-in-scope-cxx-modules4.cpp
@@ -0,0 +1,110 @@
+// RUN: rm -fR %t
+// RUN: split-file %s %t
+// RUN: cd %t
+// RUN: %clang_cc1 -verify -std=c++20 -x c++ -fmodule-map-file=modules.map 
-fmodule-name=foo1 -emit-module modules.map -o foo1.pcm
+// RUN: %clang_cc1 -verify -std=c++20 -x c++ -fmodule-map-file=modules.map 
-fmodule-name=foo2 -emit-module modules.map -o foo2.pcm
+// RUN: %clang_cc1 -verify -std=c++20 -x c++ -fmodule-map-file=modules.map 
-fmodule-file=foo1.pcm -fmodule-file=foo2.pcm server.cc
+
+//--- functional
+#pragma once
+
+namespace std {
+template  class function {};
+} // namespace std
+
+//--- foo.h
+#pragma once
+
+class MethodHandler {
+ public:
+  virtual ~MethodHandler() {}
+  struct HandlerParameter {
+HandlerParameter();
+  };
+  virtual void RunHandler(const HandlerParameter ¶m);
+};
+
+template 
+class CallbackUnaryHandler : public MethodHandler {
+ public:
+  explicit CallbackUnaryHandler();
+
+  void RunHandler(const HandlerParameter ¶m) final {
+void *call = nullptr;
+(void)[call](bool){};
+  }
+};
+
+//--- foo1.h
+// expected-no-diagnostics
+#pragma once
+
+#include "functional"
+
+#include "foo.h"
+
+class A;
+
+class ClientAsyncResponseReaderHelper {
+   public:
+  using t = std::function;
+static void SetupRequest(t finish);
+};
+
+//--- foo2.h
+// expected-no-diagnostics
+#pragma once
+
+#include "foo.h"
+
+template 
+class a : public BaseClass {
+ public:
+  a() { [[maybe_unused]] CallbackUnaryHandler a; }
+};
+
+//--- modules.map
+module "foo" {
+  export *
+  module "foo.h" {
+export *
+textual header "foo.h"
+  }
+}
+
+module "foo1" {
+  export *
+  module "foo1.h" {
+export *
+header "foo1.h"
+  }
+
+  use "foo"
+}
+
+module "foo2" {
+  export *
+  module "foo2.h" {
+export *
+header "foo2.h"
+  }
+
+  use "foo"
+}
+
+//--- server.cc
+// expected-no-diagnostics
+#include "functional"
+
+#include "foo1.h"
+#include "foo2.h"
+
+std::function on_emit;
+
+template 
+class CallbackUnaryHandler;
+
+class s {};
+class hs final : public a {
+  explicit hs() {}
+};

>From 51a60128fa9ea445228c12468caabc317e6adeb9 Mon Sep 17 00:00:00 2001
From: Dmitry Polukhin 
Date: Thu, 17 Oct 2024 06:44:23 -0700
Subject: [PATCH 3/8] Use mechanism for deserializing re

[clang] [clang] Apply internal buffering to clang diagnostics printing (PR #113440)

2024-12-11 Thread Tom Honermann via cfe-commits

tahonermann wrote:

Is it known which platforms are affected by this issue? I ask because I see 
some issues with how consoles/terminals are handled by `raw_fd_ostream`.

On Windows, `raw_fd_ostream` has a `bool` data member named `IsWindowsConsole` 
that is intended to indicate whether `FD` is a file descriptor for a Windows 
console. However, the code to detect a Windows console is incorrect.
https://github.com/llvm/llvm-project/blob/1946d32f1fdfb2c4d5e866a5c1c5c32b8cdad5b8/llvm/lib/Support/raw_ostream.cpp#L639-L641
The above code only checks that `FD` is directed to a character device, not a 
console specifically. The correct way to check for a console is already 
implemented elsewhere.
https://github.com/llvm/llvm-project/blob/1946d32f1fdfb2c4d5e866a5c1c5c32b8cdad5b8/llvm/lib/Support/Windows/Process.inc#L289-L292
Interestingly, the `llvm::Process` class is already used to detect a terminal 
for non-Windows systems via indirection through `is_displayed()`.
https://github.com/llvm/llvm-project/blob/1946d32f1fdfb2c4d5e866a5c1c5c32b8cdad5b8/llvm/lib/Support/raw_ostream.cpp#L866-L868
`is_displayed()` is also used on Windows, so there is some potential for 
inconsistent and surprising behavior across character devices.
https://github.com/llvm/llvm-project/blob/1946d32f1fdfb2c4d5e866a5c1c5c32b8cdad5b8/llvm/lib/Support/raw_ostream.cpp#L506-L520

The code for detecting a Windows console is specific to an actual Windows 
console device. It works for detecting a Windows console for processes running 
in a `cmd.exe` or Windows Terminal environment, but it won't detect the display 
used for a, e.g., Cygwin MinTTY terminal. That *might* be motivation for 
checking for a character device instead of a Windows console specifically, but 
comments should reflect that choice (and they currently suggest otherwise). 
Regardless, we should have one place where we determine whether output is 
directed to a console/terminal and the right place for that is 
`Process::FileDescriptorIsDisplayed()`.

For UNIX platforms, `isatty()` is used to detect output directed to a terminal.
https://github.com/llvm/llvm-project/blob/1946d32f1fdfb2c4d5e866a5c1c5c32b8cdad5b8/llvm/lib/Support/Unix/Process.inc#L309-L316
However, for reasons I don't understand, 
`raw_fd_ostream::preferred_buffer_size()` checks for both a character device 
and (indirectly) `isatty()` (this code used to call `isatty()` directly).
https://github.com/llvm/llvm-project/blob/1946d32f1fdfb2c4d5e866a5c1c5c32b8cdad5b8/llvm/lib/Support/raw_ostream.cpp#L851-L862

I think it is worth cleaning this up to see if that 1) fixes the reported 
problem, and 2) causes any regressions (which would then prompt improving the 
comments to better explain the intent).

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


[libclc] [libclc] Optimize ceil/fabs/floor/rint/trunc (PR #119596)

2024-12-11 Thread Fraser Cormack via cfe-commits

https://github.com/frasercrmck created 
https://github.com/llvm/llvm-project/pull/119596

These functions all map to the corresponding LLVM intrinsics, but the vector 
intrinsics weren't being generated. The intrinsic mapping from CLC vector 
function to vector intrinsic was working correctly, but the mapping from OpenCL 
builtin to CLC function was suboptimally recursively splitting vectors in 
halves.

For example, with this change, `ceil(float16)` calls `llvm.ceil.v16f32` 
directly.

The CLC versions of each of these builtins are also now enabled for SPIR-V 
targets. The LLVM -> SPIR-V translator maps the intrinsics to the appropriate 
OpExtInst. As such, there is no diff to the SPIR-V binaries before/after this 
change.

The clspv targets show a difference, but it's not expected to be a problem:

>   %call = tail call spir_func double @llvm.fabs.f64(double noundef %x) #9
<   %call = tail call spir_func double @_Z4fabsd(double noundef %x) #9

The AMDGPU targets make use of the same `_CLC_DEFINE_UNARY_BUILTIN` macro to 
override `sqrt`, so those functions also appear more optimal with this change, 
calling the vector `llvm.sqrt.vXf32` intrinsics directly.

>From 68df2622a3ca1b98a0cbf1fc9e6200e12fecbb2e Mon Sep 17 00:00:00 2001
From: Fraser Cormack 
Date: Wed, 11 Dec 2024 17:28:38 +
Subject: [PATCH] [libclc] Optimize ceil/fabs/floor/rint/trunc

These functions all map to the corresponding LLVM intrinsics, but the
vector intrinsics weren't being generated. The intrinsic mapping from
CLC vector function to vector intrinsic was working correctly, but the
mapping from OpenCL builtin to CLC function was suboptimally recursively
splitting vectors in halves.

For example, with this change, `ceil(float16)` calls `llvm.ceil.v16f32`
directly.

The CLC versions of each of these builtins are also now enabled for
SPIR-V targets. The LLVM -> SPIR-V translator maps the intrinsics to the
appropriate OpExtInst. As such, there is no diff to the SPIR-V binaries
before/after this change.

The clspv targets show a difference, but it's not expected to be a
problem:

>   %call = tail call spir_func double @llvm.fabs.f64(double noundef %x) #9
<   %call = tail call spir_func double @_Z4fabsd(double noundef %x) #9

The AMDGPU targets make use of the same _CLC_DEFINE_UNARY_BUILTIN macro
to override sqrt, so those functions also appear more optimal with this
change, calling the vector `llvm.sqrt.vXf32` intrinsics directly.
---
 libclc/clc/include/clc/clcmacro.h   | 16 +++-
 libclc/clc/include/clc/math/clc_ceil.h  |  7 ---
 libclc/clc/include/clc/math/clc_fabs.h  |  7 ---
 libclc/clc/include/clc/math/clc_floor.h |  7 ---
 libclc/clc/include/clc/math/clc_rint.h  |  7 ---
 libclc/clc/include/clc/math/clc_trunc.h |  7 ---
 6 files changed, 15 insertions(+), 36 deletions(-)

diff --git a/libclc/clc/include/clc/clcmacro.h 
b/libclc/clc/include/clc/clcmacro.h
index 244239284ecabc..c6583749eca661 100644
--- a/libclc/clc/include/clc/clcmacro.h
+++ b/libclc/clc/include/clc/clcmacro.h
@@ -191,7 +191,21 @@
 
 #define _CLC_DEFINE_UNARY_BUILTIN(RET_TYPE, FUNCTION, BUILTIN, ARG1_TYPE)  
\
   _CLC_DEF _CLC_OVERLOAD RET_TYPE FUNCTION(ARG1_TYPE x) { return BUILTIN(x); } 
\
-  _CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, RET_TYPE, FUNCTION, ARG1_TYPE)
+  _CLC_DEF _CLC_OVERLOAD RET_TYPE##2 FUNCTION(ARG1_TYPE##2 x) {
\
+return BUILTIN(x); 
\
+  }
\
+  _CLC_DEF _CLC_OVERLOAD RET_TYPE##3 FUNCTION(ARG1_TYPE##3 x) {
\
+return BUILTIN(x); 
\
+  }
\
+  _CLC_DEF _CLC_OVERLOAD RET_TYPE##4 FUNCTION(ARG1_TYPE##4 x) {
\
+return BUILTIN(x); 
\
+  }
\
+  _CLC_DEF _CLC_OVERLOAD RET_TYPE##8 FUNCTION(ARG1_TYPE##8 x) {
\
+return BUILTIN(x); 
\
+  }
\
+  _CLC_DEF _CLC_OVERLOAD RET_TYPE##16 FUNCTION(ARG1_TYPE##16 x) {  
\
+return BUILTIN(x); 
\
+  }
 
 #ifdef cl_khr_fp16
 
diff --git a/libclc/clc/include/clc/math/clc_ceil.h 
b/libclc/clc/include/clc/math/clc_ceil.h
index 66590687c34220..905aef37e11c66 100644
--- a/libclc/clc/include/clc/math/clc_ceil.h
+++ b/libclc/clc/include/clc/math/clc_ceil.h
@@ -1,11 +1,6 @@
 #ifndef __CLC_MATH_CLC_CEIL_H__
 #define __CLC_MATH_CLC_CEIL_H__
 
-#if defined(CLC_CLSPV) || defined(CLC_SPIRV)
-// clspv and spir-v targets provide their own OpenCL-compatible ceil
-#define __clc_ceil ceil
-#else
-
 // Map the functi

[libclc] [libclc] Optimize ceil/fabs/floor/rint/trunc (PR #119596)

2024-12-11 Thread Fraser Cormack via cfe-commits

frasercrmck wrote:

CC @rjodinchr, @karolherbst 

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


[clang] [llvm] [clang][Modules] Fixing Build Breaks When -DLLVM_ENABLE_MODULES=ON (PR #119473)

2024-12-11 Thread Qiongsi Wu via cfe-commits

https://github.com/qiongsiwu updated 
https://github.com/llvm/llvm-project/pull/119473

>From 06ae1ba1222f09e35ed428bcd6da91438b15e016 Mon Sep 17 00:00:00 2001
From: Qiongsi Wu 
Date: Tue, 10 Dec 2024 15:42:46 -0800
Subject: [PATCH 1/2] Fixing issues causing build break when
 -DLLVM_ENABLE_MODULES=ON

---
 clang/include/clang/Support/Compiler.h   | 2 --
 clang/include/module.modulemap   | 5 -
 llvm/include/llvm/DebugInfo/DWARF/DWARFTypePrinter.h | 1 +
 llvm/include/llvm/IR/NVVMIntrinsicFlags.h| 2 ++
 llvm/include/llvm/Support/Memory.h   | 1 +
 llvm/include/llvm/TargetParser/AArch64TargetParser.h | 1 +
 llvm/include/module.modulemap| 1 +
 llvm/tools/llvm-jitlink/llvm-jitlink-executor/CMakeLists.txt | 1 +
 llvm/unittests/tools/llvm-profgen/CMakeLists.txt | 1 +
 9 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/Support/Compiler.h 
b/clang/include/clang/Support/Compiler.h
index 13582b899dc2a6..0cba1ad7331682 100644
--- a/clang/include/clang/Support/Compiler.h
+++ b/clang/include/clang/Support/Compiler.h
@@ -14,8 +14,6 @@
 #ifndef CLANG_SUPPORT_COMPILER_H
 #define CLANG_SUPPORT_COMPILER_H
 
-#include "llvm/Support/Compiler.h"
-
 /// CLANG_ABI is the main export/visibility macro to mark something as
 /// explicitly exported when clang is built as a shared library with everything
 /// else that is unannotated having hidden visibility.
diff --git a/clang/include/module.modulemap b/clang/include/module.modulemap
index b399f0beee59a1..e9218c715147b0 100644
--- a/clang/include/module.modulemap
+++ b/clang/include/module.modulemap
@@ -115,7 +115,7 @@ module Clang_Diagnostics {
   module Driver { header "clang/Driver/DriverDiagnostic.h" export * }
   module Frontend { header "clang/Frontend/FrontendDiagnostic.h" export * }
   module Lex { header "clang/Lex/LexDiagnostic.h" export * }
-  module Parse { header "clang/Parse/ParseDiagnostic.h" export * }
+  module Parse { header "clang/Basic/DiagnosticParse.h" export * }
   module Serialization { header 
"clang/Serialization/SerializationDiagnostic.h" export * }
   module Refactoring { header 
"clang/Tooling/Refactoring/RefactoringDiagnostic.h" export * }
 }
@@ -186,6 +186,9 @@ module Clang_StaticAnalyzer_Frontend {
 module Clang_Testing {
   requires cplusplus
   umbrella "clang/Testing"
+
+  textual header "clang/Testing/TestLanguage.def"
+
   module * { export * }
 }
 
diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFTypePrinter.h 
b/llvm/include/llvm/DebugInfo/DWARF/DWARFTypePrinter.h
index 3c936b93865045..bd25f6c30ebf1f 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFTypePrinter.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFTypePrinter.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_DEBUGINFO_DWARF_DWARFTYPEPRINTER_H
 #define LLVM_DEBUGINFO_DWARF_DWARFTYPEPRINTER_H
 
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/BinaryFormat/Dwarf.h"
 #include "llvm/Support/Error.h"
diff --git a/llvm/include/llvm/IR/NVVMIntrinsicFlags.h 
b/llvm/include/llvm/IR/NVVMIntrinsicFlags.h
index 43dde42bbbd620..dfb6e857b3a6ad 100644
--- a/llvm/include/llvm/IR/NVVMIntrinsicFlags.h
+++ b/llvm/include/llvm/IR/NVVMIntrinsicFlags.h
@@ -15,6 +15,8 @@
 #ifndef LLVM_IR_NVVMINTRINSICFLAGS_H
 #define LLVM_IR_NVVMINTRINSICFLAGS_H
 
+#include 
+
 namespace llvm {
 namespace nvvm {
 
diff --git a/llvm/include/llvm/Support/Memory.h 
b/llvm/include/llvm/Support/Memory.h
index c02a3cc14dc7de..a587f2a8542b2e 100644
--- a/llvm/include/llvm/Support/Memory.h
+++ b/llvm/include/llvm/Support/Memory.h
@@ -15,6 +15,7 @@
 
 #include "llvm/Support/DataTypes.h"
 #include 
+#include 
 
 namespace llvm {
 
diff --git a/llvm/include/llvm/TargetParser/AArch64TargetParser.h 
b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
index 1311329821828f..11836e87d1b208 100644
--- a/llvm/include/llvm/TargetParser/AArch64TargetParser.h
+++ b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
@@ -16,6 +16,7 @@
 
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/Bitset.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/VersionTuple.h"
diff --git a/llvm/include/module.modulemap b/llvm/include/module.modulemap
index b00da6d7cd28c7..ac7bd257cbb422 100644
--- a/llvm/include/module.modulemap
+++ b/llvm/include/module.modulemap
@@ -346,6 +346,7 @@ extern module LLVM_Extern_Utils_DataTypes 
"module.extern.modulemap"
 // TargetParser module before building the TargetParser module itself.
 module TargetParserGen {
   module AArch64TargetParserDef {
+textual header "llvm/TargetParser/AArch64CPUFeatures.inc"
 header "llvm/TargetParser/AArch64TargetParser.h"
 extern module LLVM_Extern_TargetParser_Gen "module.extern.modulemap"
 export *
diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink-executor/CMakeLists.txt 
b/llvm/tools/llvm-ji

[clang] [AArch64] Refactor implementation of FP8 types (NFC) (PR #118969)

2024-12-11 Thread via cfe-commits


@@ -57,6 +57,11 @@
 //  - IsBF true for vector of brain float elements.
 
//===--===//
 
+#ifndef SVE_SCALAR_TYPE
+#define SVE_SCALAR_TYPE(Name, MangledName, Id, SingletonId, Bits) \

CarolineConcatto wrote:

Why not AARCH64, as this is not an SVE type. At least that was the suggestion 
in the past

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


[clang] [AArch64] Refactor implementation of FP8 types (NFC) (PR #118969)

2024-12-11 Thread via cfe-commits


@@ -243,6 +243,7 @@ AArch64ABIInfo::convertFixedToScalableVectorType(const 
VectorType *VT) const {
 
 case BuiltinType::SChar:
 case BuiltinType::UChar:
+case BuiltinType::MFloat8:

CarolineConcatto wrote:

Is this used by any intrinsic? Can we have test for this? 

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


[clang] [AArch64] Refactor implementation of FP8 types (NFC) (PR #118969)

2024-12-11 Thread via cfe-commits


@@ -761,8 +762,10 @@ bool AArch64ABIInfo::passAsPureScalableType(
   getContext().getBuiltinVectorTypeInfo(cast(Ty));
   assert(Info.NumVectors > 0 && Info.NumVectors <= 4 &&
  "Expected 1, 2, 3 or 4 vectors!");
-  auto VTy = llvm::ScalableVectorType::get(CGT.ConvertType(Info.ElementType),
-   Info.EC.getKnownMinValue());
+  llvm::Type *EltTy = Info.ElementType->isMFloat8Type()

CarolineConcatto wrote:

I am not sure when this is used? Can we have test for this?

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


[clang] [AArch64] Refactor implementation of FP8 types (NFC) (PR #118969)

2024-12-11 Thread via cfe-commits


@@ -529,6 +531,9 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {
   }
 case BuiltinType::SveCount:
   return llvm::TargetExtType::get(getLLVMContext(), "aarch64.svcount");
+case BuiltinType::MFloat8:

CarolineConcatto wrote:

What is the  difference between this change and before.
It looks like both are generation a vector of: . But in this case 
Info.EC  is replaced by 1.

Do we need case BuiltinType::MFloat8? Why the changes are not enough for the 
scalar type?

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


[clang] [AArch64] Refactor implementation of FP8 types (NFC) (PR #118969)

2024-12-11 Thread via cfe-commits


@@ -4374,15 +4379,18 @@ ASTContext::getBuiltinVectorTypeInfo(const BuiltinType 
*Ty) const {
ElBits, NF) 
\
   case BuiltinType::Id:
\
 return {BFloat16Ty, llvm::ElementCount::getScalable(NumEls), NF};
+#define SVE_VECTOR_TYPE_MFLOAT(Name, MangledName, Id, SingletonId, NumEls, 
\
+   ElBits, NF) 
\
+  case BuiltinType::Id:
\
+return {MFloat8Ty, llvm::ElementCount::getScalable(NumEls), NF};
 #define SVE_PREDICATE_TYPE_ALL(Name, MangledName, Id, SingletonId, NumEls, NF) 
\
   case BuiltinType::Id:
\
 return {BoolTy, llvm::ElementCount::getScalable(NumEls), NF};
 #define AARCH64_VECTOR_TYPE_MFLOAT(Name, MangledName, Id, SingletonId, NumEls, 
\
ElBits, NF) 
\
   case BuiltinType::Id:
\
-return {getIntTypeForBitwidth(ElBits, false),  
\
-llvm::ElementCount::getFixed(NumEls), NF};
-#define SVE_OPAQUE_TYPE(Name, MangledName, Id, SingletonId)
+return {MFloat8Ty, llvm::ElementCount::getFixed(NumEls), NF};

CarolineConcatto wrote:

Why are you returning MFloat8Ty it should be SingletonId, no?
At least it should have an explanation to why this is different.

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


[clang] [AArch64] Refactor implementation of FP8 types (NFC) (PR #118969)

2024-12-11 Thread via cfe-commits


@@ -4374,15 +4379,18 @@ ASTContext::getBuiltinVectorTypeInfo(const BuiltinType 
*Ty) const {
ElBits, NF) 
\
   case BuiltinType::Id:
\
 return {BFloat16Ty, llvm::ElementCount::getScalable(NumEls), NF};
+#define SVE_VECTOR_TYPE_MFLOAT(Name, MangledName, Id, SingletonId, NumEls, 
\
+   ElBits, NF) 
\
+  case BuiltinType::Id:
\
+return {MFloat8Ty, llvm::ElementCount::getScalable(NumEls), NF};

CarolineConcatto wrote:

Why are you returning MFloat8Ty it should be SingletonId, no?
At least it should have an explanation to why this is different.
Is it because of AArrch64.cpp to build the scalable vector.

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


[clang-tools-extra] [clang-tidy] Add readability-use-span-first-last check (PR #118074)

2024-12-11 Thread Julian Schmidt via cfe-commits


@@ -0,0 +1,96 @@
+//===--- UseSpanFirstLastCheck.cpp - clang-tidy -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseSpanFirstLastCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+void UseSpanFirstLastCheck::registerMatchers(MatchFinder *Finder) {
+  const auto HasSpanType =
+  hasType(hasUnqualifiedDesugaredType(recordType(hasDeclaration(
+  classTemplateSpecializationDecl(hasName("::std::span"));
+
+  // Match span.subspan(0, n) -> first(n)
+  Finder->addMatcher(
+  cxxMemberCallExpr(
+  
callee(memberExpr(hasDeclaration(cxxMethodDecl(hasName("subspan"),
+  on(expr(HasSpanType).bind("span_object")),
+  hasArgument(0, integerLiteral(equals(0))),
+  hasArgument(1, expr().bind("count")), argumentCountIs(2))
+  .bind("first_subspan"),
+  this);
+
+  // Match span.subspan(size() - n) or span.subspan(std::ranges::size(span) - 
n)
+  // -> last(n)
+  const auto SizeCall = anyOf(
+  cxxMemberCallExpr(
+  callee(memberExpr(hasDeclaration(cxxMethodDecl(hasName("size")),
+  callExpr(callee(
+  functionDecl(hasAnyName("::std::size", "::std::ranges::size");

5chmidti wrote:

This has generally been done with `utils::areStatementsIdentical` or its 
matcher equivalent, which is not 

See 
https://github.com/llvm/llvm-project/blob/3c464d23682b0f9e6f70965e8f8f3861c9ba5417/clang-tools-extra/clang-tidy/modernize/UseStartsEndsWithCheck.cpp#L73-L75

https://github.com/llvm/llvm-project/blob/3c464d23682b0f9e6f70965e8f8f3861c9ba5417/clang-tools-extra/clang-tidy/modernize/MinMaxUseInitializerListCheck.cpp#L151-L152

https://github.com/llvm/llvm-project/blob/3c464d23682b0f9e6f70965e8f8f3861c9ba5417/clang-tools-extra/clang-tidy/utils/Matchers.h#L164-L168

https://github.com/llvm/llvm-project/blob/3c464d23682b0f9e6f70965e8f8f3861c9ba5417/clang-tools-extra/clang-tidy/utils/ASTUtils.h#L40-L41

You can add `isStatementIdenticalToBoundNode` to your `SizeCall` matcher, 
checking the argument or object to be equivalent to `span_object`, e.g., 
`on(expr(isStatementIdenticalToBoundNode("span_object")))`

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


[clang] [AArch64] Refactor implementation of FP8 types (NFC) (PR #118969)

2024-12-11 Thread Momchil Velikov via cfe-commits


@@ -529,6 +531,9 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {
   }
 case BuiltinType::SveCount:
   return llvm::TargetExtType::get(getLLVMContext(), "aarch64.svcount");
+case BuiltinType::MFloat8:

momchil-velikov wrote:

How else would you expect this function to work when you call it with an 
argument that is `__mfp8` ?


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


[clang] [AArch64] Refactor implementation of FP8 types (NFC) (PR #118969)

2024-12-11 Thread Momchil Velikov via cfe-commits


@@ -57,6 +57,11 @@
 //  - IsBF true for vector of brain float elements.
 
//===--===//
 
+#ifndef SVE_SCALAR_TYPE
+#define SVE_SCALAR_TYPE(Name, MangledName, Id, SingletonId, Bits) \

momchil-velikov wrote:

No reason. Can be AARCH64.

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


[clang-tools-extra] [clang-tidy][NFC][doc] clean out-dated clang-static-analyzer checks (PR #119580)

2024-12-11 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti approved this pull request.


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


  1   2   3   >