[clang] [Driver] DragonFly also needs libexecinfo (PR #125179)

2025-01-30 Thread Brad Smith via cfe-commits

https://github.com/brad0 updated 
https://github.com/llvm/llvm-project/pull/125179

>From 984c3bb992bbc3d9c5c9af3b02e72914424f00c1 Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Fri, 31 Jan 2025 02:15:00 -0500
Subject: [PATCH] [Driver] DragonFly also needs libexecinfo

---
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 2c4b082bcce4a62..9f2cf1eefd0f933 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1444,9 +1444,8 @@ void tools::linkSanitizerRuntimeDeps(const ToolChain &TC,
   TC.getTriple().getOS() != llvm::Triple::RTEMS)
 CmdArgs.push_back("-ldl");
   // Required for backtrace on some OSes
-  if (TC.getTriple().isOSFreeBSD() ||
-  TC.getTriple().isOSNetBSD() ||
-  TC.getTriple().isOSOpenBSD())
+  if (TC.getTriple().isOSFreeBSD() || TC.getTriple().isOSNetBSD() ||
+  TC.getTriple().isOSOpenBSD() || TC.getTriple().isOSDragonFly())
 CmdArgs.push_back("-lexecinfo");
   // There is no libresolv on Android, FreeBSD, OpenBSD, etc. On musl
   // libresolv.a, even if exists, is an empty archive to satisfy POSIX -lresolv

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


[clang] [clang:frontend] Move helper functions to common location for SemaSPIRV (PR #125045)

2025-01-30 Thread Muhammad Bassiouni via cfe-commits

https://github.com/bassiounix updated 
https://github.com/llvm/llvm-project/pull/125045

>From d938f75b1a5638f013ae2f7fb4f0ac2f6e28c6a4 Mon Sep 17 00:00:00 2001
From: Muhammad Bassiouni 
Date: Thu, 30 Jan 2025 12:02:25 +0200
Subject: [PATCH 1/5] [clang:frontend] Move helper functions in SemaHLSL to
 common location for SemaSPIRV

---
 clang/include/clang/Sema/Common.h | 22 +++
 clang/lib/Sema/CMakeLists.txt |  1 +
 clang/lib/Sema/Common.cpp | 65 +++
 clang/lib/Sema/SemaHLSL.cpp   | 28 +
 clang/lib/Sema/SemaSPIRV.cpp  | 52 +++--
 5 files changed, 95 insertions(+), 73 deletions(-)
 create mode 100644 clang/include/clang/Sema/Common.h
 create mode 100644 clang/lib/Sema/Common.cpp

diff --git a/clang/include/clang/Sema/Common.h 
b/clang/include/clang/Sema/Common.h
new file mode 100644
index 000..3f775df8bddb649
--- /dev/null
+++ b/clang/include/clang/Sema/Common.h
@@ -0,0 +1,22 @@
+#ifndef LLVM_CLANG_SEMA_COMMON_H
+#define LLVM_CLANG_SEMA_COMMON_H
+
+#include "clang/Sema/Sema.h"
+
+namespace clang {
+
+using LLVMFnRef = llvm::function_ref;
+using PairParam = std::pair;
+using CheckParam = std::variant;
+
+bool CheckArgTypeIsCorrect(
+Sema *S, Expr *Arg, QualType ExpectedType,
+llvm::function_ref Check);
+
+bool CheckAllArgTypesAreCorrect(
+Sema *SemaPtr, CallExpr *TheCall,
+std::variant ExpectedType, CheckParam Check);
+
+} // namespace clang
+
+#endif
diff --git a/clang/lib/Sema/CMakeLists.txt b/clang/lib/Sema/CMakeLists.txt
index 19cf3a2db00fdcd..ddc340a51a3b2d1 100644
--- a/clang/lib/Sema/CMakeLists.txt
+++ b/clang/lib/Sema/CMakeLists.txt
@@ -17,6 +17,7 @@ add_clang_library(clangSema
   AnalysisBasedWarnings.cpp
   CheckExprLifetime.cpp
   CodeCompleteConsumer.cpp
+  Common.cpp
   DeclSpec.cpp
   DelayedDiagnostic.cpp
   HeuristicResolver.cpp
diff --git a/clang/lib/Sema/Common.cpp b/clang/lib/Sema/Common.cpp
new file mode 100644
index 000..72a9e4a2c99ae11
--- /dev/null
+++ b/clang/lib/Sema/Common.cpp
@@ -0,0 +1,65 @@
+#include "clang/Sema/Common.h"
+
+namespace clang {
+
+bool CheckArgTypeIsCorrect(
+Sema *S, Expr *Arg, QualType ExpectedType,
+llvm::function_ref Check) {
+  QualType PassedType = Arg->getType();
+  if (Check(PassedType)) {
+if (auto *VecTyA = PassedType->getAs())
+  ExpectedType = S->Context.getVectorType(
+  ExpectedType, VecTyA->getNumElements(), VecTyA->getVectorKind());
+S->Diag(Arg->getBeginLoc(), diag::err_typecheck_convert_incompatible)
+<< PassedType << ExpectedType << 1 << 0 << 0;
+return true;
+  }
+  return false;
+}
+
+bool CheckAllArgTypesAreCorrect(
+Sema *SemaPtr, CallExpr *TheCall,
+std::variant ExpectedType, CheckParam Check) {
+  unsigned int NumElts;
+  unsigned int expected;
+  if (auto *n = std::get_if(&Check)) {
+if (SemaPtr->checkArgCount(TheCall, n->first)) {
+  return true;
+}
+NumElts = n->first;
+expected = n->second;
+  } else {
+NumElts = TheCall->getNumArgs();
+  }
+
+  for (unsigned i = 0; i < NumElts; i++) {
+Expr *localArg = TheCall->getArg(i);
+if (auto *val = std::get_if(&ExpectedType)) {
+  if (auto *fn = std::get_if(&Check)) {
+return CheckArgTypeIsCorrect(SemaPtr, localArg, *val, *fn);
+  }
+}
+
+QualType PassedType = localArg->getType();
+if (PassedType->getAs() == nullptr) {
+  SemaPtr->Diag(localArg->getBeginLoc(),
+diag::err_typecheck_convert_incompatible)
+  << PassedType
+  << SemaPtr->Context.getVectorType(PassedType, expected,
+VectorKind::Generic)
+  << 1 << 0 << 0;
+  return true;
+}
+  }
+
+  if (std::get_if(&Check)) {
+if (auto *localArgVecTy =
+TheCall->getArg(0)->getType()->getAs()) {
+  TheCall->setType(localArgVecTy->getElementType());
+}
+  }
+
+  return false;
+}
+
+} // namespace clang
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index d748c10455289b9..0cc71e4122666c0 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -27,6 +27,7 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/Specifiers.h"
 #include "clang/Basic/TargetInfo.h"
+#include "clang/Sema/Common.h"
 #include "clang/Sema/Initialization.h"
 #include "clang/Sema/ParsedAttr.h"
 #include "clang/Sema/Sema.h"
@@ -1996,33 +1997,6 @@ static bool CheckArgTypeMatches(Sema *S, Expr *Arg, 
QualType ExpectedType) {
   return false;
 }
 
-static bool CheckArgTypeIsCorrect(
-Sema *S, Expr *Arg, QualType ExpectedType,
-llvm::function_ref Check) {
-  QualType PassedType = Arg->getType();
-  if (Check(PassedType)) {
-if (auto *VecTyA = PassedType->getAs())
-  ExpectedType = S->Context.getVectorType(
-  ExpectedType, VecTyA->getNumElements(), VecTyA->getVectorKind());
-S->Diag(Arg->getBeginLoc(), diag::err_typecheck_convert_incompatible)
-

[clang] [Driver] DragonFly also needs libexecinfo (PR #125179)

2025-01-30 Thread Brad Smith via cfe-commits

https://github.com/brad0 updated 
https://github.com/llvm/llvm-project/pull/125179

>From 30642359e2e88bb9807cd9142c27f3b0b544bbe5 Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Fri, 31 Jan 2025 02:15:00 -0500
Subject: [PATCH] [Driver] Add DragonFly for handling of libdl and libexecinfo

---
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 2c4b082bcce4a6..c3c22a419f352a 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1440,13 +1440,12 @@ void tools::linkSanitizerRuntimeDeps(const ToolChain 
&TC,
   CmdArgs.push_back("-lm");
   // There's no libdl on all OSes.
   if (!TC.getTriple().isOSFreeBSD() && !TC.getTriple().isOSNetBSD() &&
-  !TC.getTriple().isOSOpenBSD() &&
+  !TC.getTriple().isOSOpenBSD() && !TC.getTriple().isOSDragonFly() &&
   TC.getTriple().getOS() != llvm::Triple::RTEMS)
 CmdArgs.push_back("-ldl");
   // Required for backtrace on some OSes
-  if (TC.getTriple().isOSFreeBSD() ||
-  TC.getTriple().isOSNetBSD() ||
-  TC.getTriple().isOSOpenBSD())
+  if (TC.getTriple().isOSFreeBSD() || TC.getTriple().isOSNetBSD() ||
+  TC.getTriple().isOSOpenBSD() || TC.getTriple().isOSDragonFly())
 CmdArgs.push_back("-lexecinfo");
   // There is no libresolv on Android, FreeBSD, OpenBSD, etc. On musl
   // libresolv.a, even if exists, is an empty archive to satisfy POSIX -lresolv

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


[clang] [Driver] Add DragonFly for handling of libdl and libexecinfo (PR #125179)

2025-01-30 Thread Brad Smith via cfe-commits

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


[clang] [clang:frontend] Move helper functions to common location for SemaSPIRV (PR #125045)

2025-01-30 Thread Muhammad Bassiouni via cfe-commits

bassiounix wrote:

Huh.. this shouldn't fail! I tested locally before pushing the commits!

Looks like these files aren't mine .. I guess ..

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


[clang] [AArch64] Enable vscale_range with +sme (PR #124466)

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

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


[clang] 9f1c825 - [AArch64] Enable vscale_range with +sme (#124466)

2025-01-30 Thread via cfe-commits

Author: David Green
Date: 2025-01-31T07:57:43Z
New Revision: 9f1c825fb62319b94ac9604f733afd59e9eb461b

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

LOG: [AArch64] Enable vscale_range with +sme (#124466)

If we have +sme but not +sve, we would not set vscale_range on
functions. It should be valid to apply it with the same range with just
+sme, which can help mitigate some performance regressions in cases such
as scalable vector bitcasts (https://godbolt.org/z/exhe4jd8d).

Added: 


Modified: 
clang/include/clang/Basic/TargetInfo.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/ItaniumMangle.cpp
clang/lib/Basic/Targets/AArch64.cpp
clang/lib/Basic/Targets/AArch64.h
clang/lib/Basic/Targets/RISCV.cpp
clang/lib/Basic/Targets/RISCV.h
clang/lib/CodeGen/CodeGenFunction.cpp
clang/lib/CodeGen/Targets/RISCV.cpp
clang/lib/Sema/SemaType.cpp
clang/test/CodeGen/AArch64/sme-intrinsics/aarch64-sme-attrs.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 43c09cf1f973e3..d762144478b489 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -1023,7 +1023,8 @@ class TargetInfo : public TransferrableTargetInfo,
 
   /// Returns target-specific min and max values VScale_Range.
   virtual std::optional>
-  getVScaleRange(const LangOptions &LangOpts) const {
+  getVScaleRange(const LangOptions &LangOpts,
+ bool IsArmStreamingFunction) const {
 return std::nullopt;
   }
   /// The __builtin_clz* and __builtin_ctz* built-in

diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 4e387da6dccd6f..2dc96691f1da70 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -10363,7 +10363,8 @@ bool ASTContext::areLaxCompatibleSveTypes(QualType 
FirstType,
 /// getRVVTypeSize - Return RVV vector register size.
 static uint64_t getRVVTypeSize(ASTContext &Context, const BuiltinType *Ty) {
   assert(Ty->isRVVVLSBuiltinType() && "Invalid RVV Type");
-  auto VScale = Context.getTargetInfo().getVScaleRange(Context.getLangOpts());
+  auto VScale =
+  Context.getTargetInfo().getVScaleRange(Context.getLangOpts(), false);
   if (!VScale)
 return 0;
 

diff  --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index e889b74a5cdae3..e380d41b2d4020 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -4198,7 +4198,7 @@ void CXXNameMangler::mangleRISCVFixedRVVVectorType(const 
VectorType *T) {
 
   // Apend the LMUL suffix.
   auto VScale = getASTContext().getTargetInfo().getVScaleRange(
-  getASTContext().getLangOpts());
+  getASTContext().getLangOpts(), false);
   unsigned VLen = VScale->first * llvm::RISCV::RVVBitsPerBlock;
 
   if (T->getVectorKind() == VectorKind::RVVFixedLengthData) {

diff  --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index 0b899137bbb5c7..57c9849ef2a728 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -703,12 +703,13 @@ ArrayRef 
AArch64TargetInfo::getTargetBuiltins() const {
 }
 
 std::optional>
-AArch64TargetInfo::getVScaleRange(const LangOptions &LangOpts) const {
+AArch64TargetInfo::getVScaleRange(const LangOptions &LangOpts,
+  bool IsArmStreamingFunction) const {
   if (LangOpts.VScaleMin || LangOpts.VScaleMax)
 return std::pair(
 LangOpts.VScaleMin ? LangOpts.VScaleMin : 1, LangOpts.VScaleMax);
 
-  if (hasFeature("sve"))
+  if (hasFeature("sve") || (IsArmStreamingFunction && hasFeature("sme")))
 return std::pair(1, 16);
 
   return std::nullopt;

diff  --git a/clang/lib/Basic/Targets/AArch64.h 
b/clang/lib/Basic/Targets/AArch64.h
index 8695c0750ee32d..79e012f48e65b7 100644
--- a/clang/lib/Basic/Targets/AArch64.h
+++ b/clang/lib/Basic/Targets/AArch64.h
@@ -184,7 +184,8 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public 
TargetInfo {
   ArrayRef getTargetBuiltins() const override;
 
   std::optional>
-  getVScaleRange(const LangOptions &LangOpts) const override;
+  getVScaleRange(const LangOptions &LangOpts,
+ bool IsArmStreamingFunction) const override;
   bool doesFeatureAffectCodeGen(StringRef Name) const override;
   bool validateCpuSupports(StringRef FeatureStr) const override;
   bool hasFeature(StringRef Feature) const override;

diff  --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index 8167d7603b0e14..61b8ae9d098abc 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -222,7 +222,7 @@ void RISCVTargetInfo::getTargetDefines(const LangOptions 
&Opts,
   // Currently we support the v1

[clang] [clang][bytecode] Handle invalid temporary descriptors (PR #125033)

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `flang-aarch64-dylib` 
running on `linaro-flang-aarch64-dylib` while building `clang` at step 5 
"build-unified-tree".

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


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

```
Step 5 (build-unified-tree) failure: build (failure)
...
89.177 [888/1/5911] Building CXX object 
tools/mlir/lib/CAPI/Dialect/CMakeFiles/obj.MLIRCAPISPIRV.dir/SPIRV.cpp.o
89.317 [887/1/5912] Building CXX object 
tools/mlir/lib/CAPI/Dialect/CMakeFiles/obj.MLIRCAPITensor.dir/Tensor.cpp.o
89.477 [886/1/5913] Building CXX object 
tools/mlir/lib/CAPI/Dialect/CMakeFiles/obj.MLIRCAPITransformDialect.dir/Transform.cpp.o
89.587 [885/1/5914] Building CXX object 
tools/mlir/lib/CAPI/Dialect/CMakeFiles/obj.MLIRCAPITransformDialectTransforms.dir/TransformInterpreter.cpp.o
89.693 [884/1/5915] Building CXX object 
tools/mlir/lib/CAPI/Dialect/CMakeFiles/obj.MLIRCAPIQuant.dir/Quant.cpp.o
89.799 [883/1/5916] Building CXX object 
tools/mlir/lib/CAPI/Dialect/CMakeFiles/obj.MLIRCAPIOpenMP.dir/OpenMP.cpp.o
90.028 [882/1/5917] Building CXX object 
tools/mlir/lib/CAPI/Dialect/CMakeFiles/obj.MLIRCAPIPDL.dir/PDL.cpp.o
90.119 [881/1/5918] Building CXX object 
tools/mlir/lib/CAPI/Dialect/CMakeFiles/obj.MLIRCAPIVector.dir/Vector.cpp.o
90.231 [880/1/5919] Building CXX object 
tools/mlir/test/lib/Pass/CMakeFiles/MLIRTestPass.dir/TestSPIRVCPURunnerPipeline.cpp.o
101.999 [879/1/5920] Building CXX object 
tools/mlir/test/lib/Pass/CMakeFiles/MLIRTestPass.dir/TestPassManager.cpp.o
FAILED: 
tools/mlir/test/lib/Pass/CMakeFiles/MLIRTestPass.dir/TestPassManager.cpp.o 
/usr/local/bin/c++ -DGTEST_HAS_RTTI=0 -DMLIR_INCLUDE_TESTS -D_DEBUG 
-D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS 
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-I/home/tcwg-buildbot/worker/flang-aarch64-dylib/build/tools/mlir/test/lib/Pass 
-I/home/tcwg-buildbot/worker/flang-aarch64-dylib/llvm-project/mlir/test/lib/Pass
 -I/home/tcwg-buildbot/worker/flang-aarch64-dylib/build/tools/mlir/include 
-I/home/tcwg-buildbot/worker/flang-aarch64-dylib/llvm-project/mlir/include 
-I/home/tcwg-buildbot/worker/flang-aarch64-dylib/build/include 
-I/home/tcwg-buildbot/worker/flang-aarch64-dylib/llvm-project/llvm/include 
-I/home/tcwg-buildbot/worker/flang-aarch64-dylib/llvm-project/mlir/test/lib/Pass/../Dialect/Test
 
-I/home/tcwg-buildbot/worker/flang-aarch64-dylib/build/tools/mlir/test/lib/Pass/../Dialect/Test
 -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden 
-Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra 
-Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers 
-pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough 
-Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor 
-Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion 
-Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color 
-ffunction-sections -fdata-sections -Wundef -Werror=mismatched-tags -O3 
-DNDEBUG -std=c++17  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT 
tools/mlir/test/lib/Pass/CMakeFiles/MLIRTestPass.dir/TestPassManager.cpp.o -MF 
tools/mlir/test/lib/Pass/CMakeFiles/MLIRTestPass.dir/TestPassManager.cpp.o.d -o 
tools/mlir/test/lib/Pass/CMakeFiles/MLIRTestPass.dir/TestPassManager.cpp.o -c 
/home/tcwg-buildbot/worker/flang-aarch64-dylib/llvm-project/mlir/test/lib/Pass/TestPassManager.cpp
In file included from 
/home/tcwg-buildbot/worker/flang-aarch64-dylib/llvm-project/mlir/test/lib/Pass/TestPassManager.cpp:10:
/home/tcwg-buildbot/worker/flang-aarch64-dylib/llvm-project/mlir/test/lib/Pass/../Dialect/Test/TestOps.h:148:10:
 fatal error: 'TestOps.h.inc' file not found
  148 | #include "TestOps.h.inc"
  |  ^~~
1 error generated.
ninja: build stopped: subcommand failed.

```



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


[clang] [AArch64] Enable vscale_range with +sme (PR #124466)

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

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


[clang] bc47dae - [Driver] Add DragonFly for handling of libdl and libexecinfo (#125179)

2025-01-30 Thread via cfe-commits

Author: Brad Smith
Date: 2025-01-31T02:59:27-05:00
New Revision: bc47daed6d5491a7c65d4dd42da6bb11d3b1ab00

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

LOG: [Driver] Add DragonFly for handling of libdl and libexecinfo (#125179)

Added: 


Modified: 
clang/lib/Driver/ToolChains/CommonArgs.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 2c4b082bcce4a6..c3c22a419f352a 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1440,13 +1440,12 @@ void tools::linkSanitizerRuntimeDeps(const ToolChain 
&TC,
   CmdArgs.push_back("-lm");
   // There's no libdl on all OSes.
   if (!TC.getTriple().isOSFreeBSD() && !TC.getTriple().isOSNetBSD() &&
-  !TC.getTriple().isOSOpenBSD() &&
+  !TC.getTriple().isOSOpenBSD() && !TC.getTriple().isOSDragonFly() &&
   TC.getTriple().getOS() != llvm::Triple::RTEMS)
 CmdArgs.push_back("-ldl");
   // Required for backtrace on some OSes
-  if (TC.getTriple().isOSFreeBSD() ||
-  TC.getTriple().isOSNetBSD() ||
-  TC.getTriple().isOSOpenBSD())
+  if (TC.getTriple().isOSFreeBSD() || TC.getTriple().isOSNetBSD() ||
+  TC.getTriple().isOSOpenBSD() || TC.getTriple().isOSDragonFly())
 CmdArgs.push_back("-lexecinfo");
   // There is no libresolv on Android, FreeBSD, OpenBSD, etc. On musl
   // libresolv.a, even if exists, is an empty archive to satisfy POSIX -lresolv



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


[clang] [Driver] Add DragonFly for handling of libdl and libexecinfo (PR #125179)

2025-01-30 Thread Brad Smith via cfe-commits

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


[clang] [Driver] DragonFly also needs libexecinfo (PR #125179)

2025-01-30 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 e6d16f93b329f2f9618d18d0b99c6060e206cf08 
b3a80b3ff84a6e7523defca8dfa33d6c524445f0 --extensions cpp -- 
clang/lib/Driver/ToolChains/CommonArgs.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 6ec19dbb89..9f2cf1eefd 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1444,10 +1444,8 @@ void tools::linkSanitizerRuntimeDeps(const ToolChain &TC,
   TC.getTriple().getOS() != llvm::Triple::RTEMS)
 CmdArgs.push_back("-ldl");
   // Required for backtrace on some OSes
-  if (TC.getTriple().isOSFreeBSD() ||
-  TC.getTriple().isOSNetBSD() ||
-  TC.getTriple().isOSOpenBSD() ||
-  TC.getTriple().isOSDragonFly())
+  if (TC.getTriple().isOSFreeBSD() || TC.getTriple().isOSNetBSD() ||
+  TC.getTriple().isOSOpenBSD() || TC.getTriple().isOSDragonFly())
 CmdArgs.push_back("-lexecinfo");
   // There is no libresolv on Android, FreeBSD, OpenBSD, etc. On musl
   // libresolv.a, even if exists, is an empty archive to satisfy POSIX -lresolv

``




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


[clang] [clang:frontend] Move helper functions to common location for SemaSPIRV (PR #125045)

2025-01-30 Thread Muhammad Bassiouni via cfe-commits

bassiounix wrote:

> 1. If we were to introduce new helpers, then instead of making a new 
> header for this, these functions should just become member functions of the 
> `Sema` class.

`Sema` or `SemaBase`?
 
> 2. The new version of `CheckAllArgTypesAreCorrect()` is... way too 
> complicated, in my opinion; I have trouble trying to figure out what two 
> parameters that are a variant and a pair are supposed to mean from looking at 
> the function, and it does feel like this function wants to be at least two or 
> three separate functions...

I'll split the implementation in 2 functions.

> I think a better approach would be to leave the HLSL functions alone and just 
> factor out a separate helper and put it in `SemaSPIRV.cpp`, because as-is, 
> this pr isn’t exactly simplifying things...

Since there is a common functionalities, I think I'll go with the first 
approach, that is, declaring them in a common class.
This class is `Sema` for now as mentioned in the review.

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


[clang] [clang:frontend] Move helper functions to common location for SemaSPIRV (PR #125045)

2025-01-30 Thread via cfe-commits

Sirraide wrote:

> `Sema` or `SemaBase`?

Typically we just put those in `Sema`; I think the only thing in `SemaBase` at 
the moment are some diagnostics helpers.

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


[clang] [Driver] DragonFly also needs libexecinfo (PR #125179)

2025-01-30 Thread Brad Smith via cfe-commits

https://github.com/brad0 created 
https://github.com/llvm/llvm-project/pull/125179

None

>From b3a80b3ff84a6e7523defca8dfa33d6c524445f0 Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Fri, 31 Jan 2025 02:15:00 -0500
Subject: [PATCH] [Driver] DragonFly also needs libexecinfo

---
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 2c4b082bcce4a6..6ec19dbb89403c 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1446,7 +1446,8 @@ void tools::linkSanitizerRuntimeDeps(const ToolChain &TC,
   // Required for backtrace on some OSes
   if (TC.getTriple().isOSFreeBSD() ||
   TC.getTriple().isOSNetBSD() ||
-  TC.getTriple().isOSOpenBSD())
+  TC.getTriple().isOSOpenBSD() ||
+  TC.getTriple().isOSDragonFly())
 CmdArgs.push_back("-lexecinfo");
   // There is no libresolv on Android, FreeBSD, OpenBSD, etc. On musl
   // libresolv.a, even if exists, is an empty archive to satisfy POSIX -lresolv

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


[clang] [Driver] DragonFly also needs libexecinfo (PR #125179)

2025-01-30 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Brad Smith (brad0)


Changes



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


1 Files Affected:

- (modified) clang/lib/Driver/ToolChains/CommonArgs.cpp (+2-1) 


``diff
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 2c4b082bcce4a6..6ec19dbb89403c 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1446,7 +1446,8 @@ void tools::linkSanitizerRuntimeDeps(const ToolChain &TC,
   // Required for backtrace on some OSes
   if (TC.getTriple().isOSFreeBSD() ||
   TC.getTriple().isOSNetBSD() ||
-  TC.getTriple().isOSOpenBSD())
+  TC.getTriple().isOSOpenBSD() ||
+  TC.getTriple().isOSDragonFly())
 CmdArgs.push_back("-lexecinfo");
   // There is no libresolv on Android, FreeBSD, OpenBSD, etc. On musl
   // libresolv.a, even if exists, is an empty archive to satisfy POSIX -lresolv

``




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


[clang] d2d8e2e - [clang][bytecode] Handle invalid temporary descriptors (#125033)

2025-01-30 Thread via cfe-commits

Author: Timm Baeder
Date: 2025-01-31T08:53:31+01:00
New Revision: d2d8e2e0306ab1f0eac6406b5f2ec4d231b1f7ff

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

LOG: [clang][bytecode] Handle invalid temporary descriptors (#125033)

This happens e.g. when a vector element type is not primitive.

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 4659d0e00784d9b..f7f4f713c787f25 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -562,8 +562,10 @@ bool Compiler::VisitCastExpr(const CastExpr *CE) {
 // We're creating a complex value here, so we need to
 // allocate storage for it.
 if (!Initializing) {
-  unsigned LocalIndex = allocateTemporary(CE);
-  if (!this->emitGetPtrLocal(LocalIndex, CE))
+  std::optional LocalIndex = allocateTemporary(CE);
+  if (!LocalIndex)
+return false;
+  if (!this->emitGetPtrLocal(*LocalIndex, CE))
 return false;
 }
 
@@ -679,8 +681,10 @@ bool Compiler::VisitCastExpr(const CastExpr *CE) {
 assert(CE->getType()->isVectorType());
 
 if (!Initializing) {
-  unsigned LocalIndex = allocateTemporary(CE);
-  if (!this->emitGetPtrLocal(LocalIndex, CE))
+  std::optional LocalIndex = allocateTemporary(CE);
+  if (!LocalIndex)
+return false;
+  if (!this->emitGetPtrLocal(*LocalIndex, CE))
 return false;
 }
 unsigned ToSize = CE->getType()->getAs()->getNumElements();
@@ -759,8 +763,10 @@ bool Compiler::VisitImaginaryLiteral(const 
ImaginaryLiteral *E) {
 return true;
 
   if (!Initializing) {
-unsigned LocalIndex = allocateTemporary(E);
-if (!this->emitGetPtrLocal(LocalIndex, E))
+std::optional LocalIndex = allocateTemporary(E);
+if (!LocalIndex)
+  return false;
+if (!this->emitGetPtrLocal(*LocalIndex, E))
   return false;
   }
 
@@ -1118,8 +1124,10 @@ template 
 bool Compiler::VisitComplexBinOp(const BinaryOperator *E) {
   // Prepare storage for result.
   if (!Initializing) {
-unsigned LocalIndex = allocateTemporary(E);
-if (!this->emitGetPtrLocal(LocalIndex, E))
+std::optional LocalIndex = allocateTemporary(E);
+if (!LocalIndex)
+  return false;
+if (!this->emitGetPtrLocal(*LocalIndex, E))
   return false;
   }
 
@@ -1175,7 +1183,10 @@ bool Compiler::VisitComplexBinOp(const 
BinaryOperator *E) {
 
 if (!LHSIsComplex) {
   // This is using the RHS type for the fake-complex LHS.
-  LHSOffset = allocateTemporary(RHS);
+  std::optional LocalIndex = allocateTemporary(RHS);
+  if (!LocalIndex)
+return false;
+  LHSOffset = *LocalIndex;
 
   if (!this->emitGetPtrLocal(LHSOffset, E))
 return false;
@@ -1347,8 +1358,10 @@ bool Compiler::VisitVectorBinOp(const 
BinaryOperator *E) {
 
   // Prepare storage for result.
   if (!Initializing && !E->isCompoundAssignmentOp()) {
-unsigned LocalIndex = allocateTemporary(E);
-if (!this->emitGetPtrLocal(LocalIndex, E))
+std::optional LocalIndex = allocateTemporary(E);
+if (!LocalIndex)
+  return false;
+if (!this->emitGetPtrLocal(*LocalIndex, E))
   return false;
   }
 
@@ -4170,14 +4183,16 @@ Compiler::allocateLocal(DeclTy &&Src, QualType 
Ty,
 }
 
 template 
-unsigned Compiler::allocateTemporary(const Expr *E) {
+std::optional Compiler::allocateTemporary(const Expr *E) {
   QualType Ty = E->getType();
   assert(!Ty->isRecordType());
 
   Descriptor *D = P.createDescriptor(
   E, Ty.getTypePtr(), Descriptor::InlineDescMD, Ty.isConstQualified(),
   /*IsTemporary=*/true, /*IsMutable=*/false, /*Init=*/nullptr);
-  assert(D);
+
+  if (!D)
+return std::nullopt;
 
   Scope::Local Local = this->createLocal(D);
   VariableScope *S = VarScope;

diff  --git a/clang/lib/AST/ByteCode/Compiler.h 
b/clang/lib/AST/ByteCode/Compiler.h
index f9a597a16ef4aeb..5a02f38d78dec82 100644
--- a/clang/lib/AST/ByteCode/Compiler.h
+++ b/clang/lib/AST/ByteCode/Compiler.h
@@ -309,7 +309,7 @@ class Compiler : public ConstStmtVisitor, 
bool>,
   std::optional
   allocateLocal(DeclTy &&Decl, QualType Ty = QualType(),
 const ValueDecl *ExtendingDecl = nullptr);
-  unsigned allocateTemporary(const Expr *E);
+  std::optional allocateTemporary(const Expr *E);
 
 private:
   friend class VariableScope;



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


[clang] [clang][bytecode] Handle invalid temporary descriptors (PR #125033)

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

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


[clang] [CIR] Add framework for CIR to LLVM IR lowering (PR #124650)

2025-01-30 Thread Erich Keane via cfe-commits

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


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


[clang] [clang module] Current Working Directory Pruning (PR #124786)

2025-01-30 Thread Qiongsi Wu via cfe-commits

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


[clang] [TBAA] Don't emit pointer-tbaa for void pointers. (PR #122116)

2025-01-30 Thread John McCall via cfe-commits


@@ -2489,6 +2489,81 @@ are listed below.
 
 $ clang -fuse-ld=lld -Oz -Wl,--icf=safe -fcodegen-data-use code.cc
 
+Strict Aliasing
+---
+
+The C and C++ standards require accesses to objects in memory to use l-values 
of
+an appropriate type for the object. This is called *strict aliasing* or
+*type-based alias analysis*. Strict aliasing enhances a variety of powerful
+memory optimizations, including reordering, combining, and eliminating memory
+accesses. These optimizations can lead to unexpected behavior in code that
+violates the strict aliasing rules. For example:
+
+.. code-block:: c++
+
+void advance(size_t *index, double *data) {
+  double value = data[*index];
+  /* Clang may assume that this store does not change the contents of 
`data`. */
+  *index += 1;
+  /* Clang may assume that this store does not change the contents of 
`index`. */
+  data[*index] = value;
+  /* Either of these facts may create significant optimization 
opportunities
+   if Clang is able to inline this function. */
+  }
+
+Strict aliasing can be explicitly enabled with ``-fstrict-aliasing`` and
+disabled with ``-fno-strict-aliasing``. ``clang-cl`` defaults to
+``-fno-strict-aliasing``; see :ref:`Strict aliasing in clang-cl.
+`. Otherwise, Clang defaults to 
``-fstrict-aliasing``.
+
+C and C++ specify slightly different rules for strict aliasing. To improve
+language interoperability, Clang allows two types to alias if either language
+would permit it. This includes applying the C++ similar types rule to C,
+allowing ``int **`` to alias ``int const * const *``. Clang also relaxes the
+standard aliasing rules in the following ways:
+
+* All integer types of the same size are permitted to alias each other,
+  including signed and unsigned types.
+* ``void*`` is permitted to alias any pointer type, ``void**`` is permitted to
+  alias any pointer to pointer type, and so on.

rjmccall wrote:

Yeah, that's fine to not document. We aren't promising to not improve that in 
the future.

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


[clang] [clang] Add 'instantiated_from' for enums to the output of TextNodeDumper (PR #124409)

2025-01-30 Thread André Brand via cfe-commits

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


[clang] [clang] Add 'instantiated_from' for enums to the output of TextNodeDumper (PR #124409)

2025-01-30 Thread André Brand via cfe-commits

thebrandre wrote:

@shafik @Sirraide I don't have any experience writing (robust) tests for AST 
dumps. I hope it makes sense. 🙈

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


[clang] [clang module] Current Working Directory Pruning (PR #124786)

2025-01-30 Thread Steven Wu via cfe-commits

https://github.com/cachemeifyoucan commented:

Is it better if this optimization happens really early in the process since you 
only visit all the options in CI? In that case, you can just reset the 
`CurrentWorkingDirectory` in the VFS so all the searching is done without CWD. 
This avoids any hard to debug issues if some options are not taken care of 
(needs CWD but not checked) but the trade off is more explicit errors during 
scanning.

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


[clang] WIP: [clang] MicrosoftCXXABI: Serialize the exception copy constructor table in the AST (PR #114075)

2025-01-30 Thread Andrey Glebov via cfe-commits

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


[clang] [compiler-rt] [llvm] Revert "Reapply "[ORC] Enable JIT support for the compact-unwind frame..." with fixes." (PR #125098)

2025-01-30 Thread Ben Langmuir via cfe-commits

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


[clang] [compiler-rt] [llvm] Revert "Reapply "[ORC] Enable JIT support for the compact-unwind frame..." with fixes." (PR #125098)

2025-01-30 Thread Ben Langmuir via cfe-commits

benlangmuir wrote:

Failure looks unrelated. Merging.

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


[clang] [CIR] Add framework for CIR to LLVM IR lowering (PR #124650)

2025-01-30 Thread Aaron Ballman via cfe-commits

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

LGTM!

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


[clang] [clang module] Current Working Directory Pruning (PR #124786)

2025-01-30 Thread Qiongsi Wu via cfe-commits

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

>From 7060564de1bb6062639f4b4839fa17958f212755 Mon Sep 17 00:00:00 2001
From: Qiongsi Wu 
Date: Mon, 27 Jan 2025 16:44:30 -0800
Subject: [PATCH 1/3] Initial implementation of clang modules current working
 directory pruning.

---
 .../DependencyScanningService.h   |   5 +-
 .../DependencyScanning/ModuleDepCollector.cpp |  92 -
 .../ClangScanDeps/modules-context-hash-cwd.c  | 123 ++
 clang/test/ClangScanDeps/working-dir.m|   2 +-
 clang/tools/clang-scan-deps/ClangScanDeps.cpp |   2 +
 5 files changed, 219 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/ClangScanDeps/modules-context-hash-cwd.c

diff --git 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h
index 4a343f2872d8d9..9ad8e68c33eb10 100644
--- a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h
+++ b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningService.h
@@ -63,7 +63,10 @@ enum class ScanningOptimizations {
   /// Canonicalize -D and -U options.
   Macros = 8,
 
-  DSS_LAST_BITMASK_ENUM(Macros),
+  /// Ignore the compiler's working directory if it is safe.
+  IgnoreCWD = 0x10,
+
+  DSS_LAST_BITMASK_ENUM(IgnoreCWD),
   Default = All
 };
 
diff --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp 
b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
index 2e97cac0796cee..714efb86fa3796 100644
--- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -397,9 +397,92 @@ void 
ModuleDepCollector::applyDiscoveredDependencies(CompilerInvocation &CI) {
   }
 }
 
+static bool isSafeToIgnoreCWD(const CowCompilerInvocation &CI) {
+  // Check if the command line input uses relative paths.
+  // It is not safe to ignore the current working directory if any of the
+  // command line inputs use relative paths.
+#define IF_RELATIVE_RETURN_FALSE(PATH) 
\
+  do { 
\
+if (!PATH.empty() && !llvm::sys::path::is_absolute(PATH))  
\
+  return false;
\
+  } while (0)
+
+#define IF_ANY_RELATIVE_RETURN_FALSE(PATHS)
\
+  do { 
\
+if (std::any_of(PATHS.begin(), PATHS.end(), [](const auto &P) {
\
+  return !P.empty() && !llvm::sys::path::is_absolute(P);   
\
+}))
\
+  return false;
\
+  } while (0)
+
+  // Header search paths.
+  const auto &HeaderSearchOpts = CI.getHeaderSearchOpts();
+  IF_RELATIVE_RETURN_FALSE(HeaderSearchOpts.Sysroot);
+  for (auto &Entry : HeaderSearchOpts.UserEntries)
+if (Entry.IgnoreSysRoot)
+  IF_RELATIVE_RETURN_FALSE(Entry.Path);
+  IF_RELATIVE_RETURN_FALSE(HeaderSearchOpts.ResourceDir);
+  IF_RELATIVE_RETURN_FALSE(HeaderSearchOpts.ModuleCachePath);
+  IF_RELATIVE_RETURN_FALSE(HeaderSearchOpts.ModuleUserBuildPath);
+  for (auto I = HeaderSearchOpts.PrebuiltModuleFiles.begin(),
+E = HeaderSearchOpts.PrebuiltModuleFiles.end();
+   I != E;) {
+auto Current = I++;
+IF_RELATIVE_RETURN_FALSE(Current->second);
+  }
+  IF_ANY_RELATIVE_RETURN_FALSE(HeaderSearchOpts.PrebuiltModulePaths);
+  IF_ANY_RELATIVE_RETURN_FALSE(HeaderSearchOpts.VFSOverlayFiles);
+
+  // Preprocessor options.
+  const auto &PPOpts = CI.getPreprocessorOpts();
+  IF_ANY_RELATIVE_RETURN_FALSE(PPOpts.MacroIncludes);
+  IF_ANY_RELATIVE_RETURN_FALSE(PPOpts.Includes);
+  IF_RELATIVE_RETURN_FALSE(PPOpts.ImplicitPCHInclude);
+
+  // Frontend options.
+  const auto &FrontendOpts = CI.getFrontendOpts();
+  for (const FrontendInputFile &Input : FrontendOpts.Inputs) {
+if (Input.isBuffer())
+  continue; // FIXME: Can this happen when parsing command-line?
+
+IF_RELATIVE_RETURN_FALSE(Input.getFile());
+  }
+  IF_RELATIVE_RETURN_FALSE(FrontendOpts.CodeCompletionAt.FileName);
+  IF_ANY_RELATIVE_RETURN_FALSE(FrontendOpts.ModuleMapFiles);
+  IF_ANY_RELATIVE_RETURN_FALSE(FrontendOpts.ModuleFiles);
+  IF_ANY_RELATIVE_RETURN_FALSE(FrontendOpts.ModulesEmbedFiles);
+  IF_ANY_RELATIVE_RETURN_FALSE(FrontendOpts.ASTMergeFiles);
+  IF_RELATIVE_RETURN_FALSE(FrontendOpts.OverrideRecordLayoutsFile);
+  IF_RELATIVE_RETURN_FALSE(FrontendOpts.StatsFile);
+
+  // Filesystem options.
+  const auto &FileSystemOpts = CI.getFileSystemOpts();
+  IF_RELATIVE_RETURN_FALSE(FileSystemOpts.WorkingDir);
+
+  // Codegen options.
+  const auto &CodeGenOpts = CI.getCodeGenOpts();
+  IF_RELATIVE_RETURN_FALSE(CodeGenOpts.DebugComp

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

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

chandlerc wrote:

I know it's only been a few days, but pinging in the hope of landing this 
week... This seems to finally be in a good state and is somewhat hard to keep 
rebasing. Happy to do anything I can to help make review easier.

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


[clang] [llvm] [AMDGPU][True16][MC][CodeGen] true16 for v_alignbyte_b32 (PR #119750)

2025-01-30 Thread Joe Nash via cfe-commits

https://github.com/Sisyph commented:

LGTM but please wait for the other reviewers. 

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


[clang] [llvm] [AMDGPU][True16][MC][CodeGen] true16 for v_alignbyte_b32 (PR #119750)

2025-01-30 Thread Joe Nash via cfe-commits

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


[clang] [llvm] [AMDGPU][True16][MC][CodeGen] true16 for v_alignbyte_b32 (PR #119750)

2025-01-30 Thread Joe Nash via cfe-commits


@@ -1,10 +1,48 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 
UTC_ARGS: --version 5
 ; RUN: llc -mtriple=amdgcn -verify-machineinstrs < %s | FileCheck 
-check-prefix=GCN %s
+; RUN: llc -mtriple=amdgcn -mcpu=gfx1100 -mattr=+real-true16 
-verify-machineinstrs < %s | FileCheck -check-prefixes=GFX11-TRUE16 %s
+; RUN: llc -mtriple=amdgcn -mcpu=gfx1100 -mattr=-real-true16 
-verify-machineinstrs < %s | FileCheck -check-prefixes=GFX11-FAKE16 %s
 
 declare i32 @llvm.amdgcn.alignbyte(i32, i32, i32) #0
 
-; GCN-LABEL: {{^}}v_alignbyte_b32:
-; GCN: v_alignbyte_b32 {{[vs][0-9]+}}, {{[vs][0-9]+}}, {{[vs][0-9]+}}
 define amdgpu_kernel void @v_alignbyte_b32(ptr addrspace(1) %out, i32 %src1, 
i32 %src2, i32 %src3) #1 {
+; GCN-LABEL: v_alignbyte_b32:
+; GCN:   ; %bb.0:
+; GCN-NEXT:s_load_dwordx4 s[0:3], s[4:5], 0xb
+; GCN-NEXT:s_load_dwordx2 s[4:5], s[4:5], 0x9
+; GCN-NEXT:s_mov_b32 s7, 0xf000
+; GCN-NEXT:s_mov_b32 s6, -1
+; GCN-NEXT:s_waitcnt lgkmcnt(0)
+; GCN-NEXT:v_mov_b32_e32 v0, s1
+; GCN-NEXT:v_mov_b32_e32 v1, s2
+; GCN-NEXT:v_alignbyte_b32 v0, s0, v0, v1
+; GCN-NEXT:buffer_store_dword v0, off, s[4:7], 0
+; GCN-NEXT:s_endpgm
+;
+; GFX11-TRUE16-LABEL: v_alignbyte_b32:
+; GFX11-TRUE16:   ; %bb.0:
+; GFX11-TRUE16-NEXT:s_clause 0x1
+; GFX11-TRUE16-NEXT:s_load_b128 s[0:3], s[4:5], 0x2c
+; GFX11-TRUE16-NEXT:s_load_b64 s[4:5], s[4:5], 0x24
+; GFX11-TRUE16-NEXT:v_mov_b32_e32 v1, 0
+; GFX11-TRUE16-NEXT:s_waitcnt lgkmcnt(0)
+; GFX11-TRUE16-NEXT:v_mov_b16_e32 v0.l, s2
+; GFX11-TRUE16-NEXT:s_delay_alu instid0(VALU_DEP_1)
+; GFX11-TRUE16-NEXT:v_alignbyte_b32 v0, s0, s1, v0.l

Sisyph wrote:

Nit: Can you add another test in this file where s0 and s1 are vgpr arguments 
instead, so we can see if s2 can be folded into src2 of alignbyte?

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


[clang] [TBAA] Don't emit pointer-tbaa for void pointers. (PR #122116)

2025-01-30 Thread John McCall via cfe-commits

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

LGTM, thanks!

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


[clang] WIP: [clang] MicrosoftCXXABI: Serialize the exception copy constructor table in the AST (PR #114075)

2025-01-30 Thread Andrey Glebov via cfe-commits


@@ -1082,6 +1082,10 @@ bool Sema::CheckCXXThrowOperand(SourceLocation ThrowLoc,
   // friendship or any other means).
   Context.addCopyConstructorForExceptionObject(Subobject, CD);

glebov-andrey wrote:

The implementation has changed, and this code has been removed

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


[clang] [Clang] Fix __{add, remove}_pointer in Objective-C++ (PR #123678)

2025-01-30 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/123678

>From 3c1c9bf41d39d33123b33c5b131f7a0c0eb62581 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Tue, 21 Jan 2025 02:16:02 +0100
Subject: [PATCH] [Clang] Fix __{add,remove}_pointer in Objective-C++

---
 clang/docs/ReleaseNotes.rst  |  2 ++
 clang/lib/Sema/SemaType.cpp  |  6 +++---
 clang/test/SemaCXX/remove_pointer.mm |  8 
 clang/test/SemaObjCXX/type-traits.mm | 17 +
 4 files changed, 22 insertions(+), 11 deletions(-)
 delete mode 100644 clang/test/SemaCXX/remove_pointer.mm
 create mode 100644 clang/test/SemaObjCXX/type-traits.mm

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8be1ea2fb01455f..8c290437fe16fe1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -122,6 +122,8 @@ Bug Fixes in This Version
 Bug Fixes to Compiler Builtins
 ^^
 
+- The behvaiour of ``__add_pointer`` and ``__remove_pointer`` for 
Objective-C++'s ``id`` and interfaces has been fixed.
+
 Bug Fixes to Attribute Support
 ^^
 
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 33d5378944ddbfb..2781651b5d8f7d5 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -1826,7 +1826,8 @@ QualType Sema::BuildPointerType(QualType T,
   if (checkQualifiedFunction(*this, T, Loc, QFK_Pointer))
 return QualType();
 
-  assert(!T->isObjCObjectType() && "Should build ObjCObjectPointerType");
+  if (T->isObjCObjectType())
+return Context.getObjCObjectPointerType(T);
 
   // In ARC, it is forbidden to build pointers to unqualified pointers.
   if (getLangOpts().ObjCAutoRefCount)
@@ -9807,8 +9808,7 @@ QualType Sema::BuiltinAddPointer(QualType BaseType, 
SourceLocation Loc) {
 }
 
 QualType Sema::BuiltinRemovePointer(QualType BaseType, SourceLocation Loc) {
-  // We don't want block pointers or ObjectiveC's id type.
-  if (!BaseType->isAnyPointerType() || BaseType->isObjCIdType())
+  if (!BaseType->isAnyPointerType())
 return BaseType;
 
   return BaseType->getPointeeType();
diff --git a/clang/test/SemaCXX/remove_pointer.mm 
b/clang/test/SemaCXX/remove_pointer.mm
deleted file mode 100644
index d1cf1fa9f4efcaa..000
--- a/clang/test/SemaCXX/remove_pointer.mm
+++ /dev/null
@@ -1,8 +0,0 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
-
-// expected-no-diagnostics
-
-@class X;
-
-static_assert(__is_same(__remove_pointer(X *), X), "");
-static_assert(__is_same(__remove_pointer(id), id), "");
diff --git a/clang/test/SemaObjCXX/type-traits.mm 
b/clang/test/SemaObjCXX/type-traits.mm
new file mode 100644
index 000..81b9573b5219292
--- /dev/null
+++ b/clang/test/SemaObjCXX/type-traits.mm
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify 
-std=c++17  %s
+
+// expected-no-diagnostics
+
+@interface I;
+@end
+
+@class C;
+
+static_assert(__is_same(__add_pointer(id), id*));
+static_assert(__is_same(__add_pointer(I), I*));
+
+static_assert(__is_same(__remove_pointer(C*), C));
+static_assert(!__is_same(__remove_pointer(id), id));
+static_assert(__is_same(__remove_pointer(id*), id));
+static_assert(__is_same(__remove_pointer(__add_pointer(id)), id));
+static_assert(__is_same(__add_pointer(__remove_pointer(id)), id));

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


[clang] WIP: [clang] MicrosoftCXXABI: Serialize the exception copy constructor table in the AST (PR #114075)

2025-01-30 Thread Andrey Glebov via cfe-commits


@@ -1082,6 +1082,10 @@ bool Sema::CheckCXXThrowOperand(SourceLocation ThrowLoc,
   // friendship or any other means).
   Context.addCopyConstructorForExceptionObject(Subobject, CD);
 
+  // Store the bit in CXXRecordDecl so that ASTReader can restore this
+  // mapping later.
+  Subobject->setHasCopyConstructorForExceptionObject();

glebov-andrey wrote:

The implementation has changed, and this code has been removed

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


[clang] WIP: [clang] MicrosoftCXXABI: Serialize the exception copy constructor table in the AST (PR #114075)

2025-01-30 Thread Andrey Glebov via cfe-commits

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


[clang] 74d7f43 - [Clang] Fix __{add, remove}_pointer in Objective-C++ (#123678)

2025-01-30 Thread via cfe-commits

Author: Nikolas Klauser
Date: 2025-01-30T20:34:29+01:00
New Revision: 74d7f43b98910a110bc194752fca829eb19c265a

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

LOG: [Clang] Fix __{add,remove}_pointer in Objective-C++ (#123678)

This aligns the builtins with how implementations work which don't use
the buitins.

Added: 
clang/test/SemaObjCXX/type-traits.mm

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaType.cpp

Removed: 
clang/test/SemaCXX/remove_pointer.mm



diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8be1ea2fb01455..8c290437fe16fe 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -122,6 +122,8 @@ Bug Fixes in This Version
 Bug Fixes to Compiler Builtins
 ^^
 
+- The behvaiour of ``__add_pointer`` and ``__remove_pointer`` for 
Objective-C++'s ``id`` and interfaces has been fixed.
+
 Bug Fixes to Attribute Support
 ^^
 

diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 33d5378944ddbf..2781651b5d8f7d 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -1826,7 +1826,8 @@ QualType Sema::BuildPointerType(QualType T,
   if (checkQualifiedFunction(*this, T, Loc, QFK_Pointer))
 return QualType();
 
-  assert(!T->isObjCObjectType() && "Should build ObjCObjectPointerType");
+  if (T->isObjCObjectType())
+return Context.getObjCObjectPointerType(T);
 
   // In ARC, it is forbidden to build pointers to unqualified pointers.
   if (getLangOpts().ObjCAutoRefCount)
@@ -9807,8 +9808,7 @@ QualType Sema::BuiltinAddPointer(QualType BaseType, 
SourceLocation Loc) {
 }
 
 QualType Sema::BuiltinRemovePointer(QualType BaseType, SourceLocation Loc) {
-  // We don't want block pointers or ObjectiveC's id type.
-  if (!BaseType->isAnyPointerType() || BaseType->isObjCIdType())
+  if (!BaseType->isAnyPointerType())
 return BaseType;
 
   return BaseType->getPointeeType();

diff  --git a/clang/test/SemaCXX/remove_pointer.mm 
b/clang/test/SemaCXX/remove_pointer.mm
deleted file mode 100644
index d1cf1fa9f4efca..00
--- a/clang/test/SemaCXX/remove_pointer.mm
+++ /dev/null
@@ -1,8 +0,0 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
-
-// expected-no-diagnostics
-
-@class X;
-
-static_assert(__is_same(__remove_pointer(X *), X), "");
-static_assert(__is_same(__remove_pointer(id), id), "");

diff  --git a/clang/test/SemaObjCXX/type-traits.mm 
b/clang/test/SemaObjCXX/type-traits.mm
new file mode 100644
index 00..81b9573b521929
--- /dev/null
+++ b/clang/test/SemaObjCXX/type-traits.mm
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify 
-std=c++17  %s
+
+// expected-no-diagnostics
+
+@interface I;
+@end
+
+@class C;
+
+static_assert(__is_same(__add_pointer(id), id*));
+static_assert(__is_same(__add_pointer(I), I*));
+
+static_assert(__is_same(__remove_pointer(C*), C));
+static_assert(!__is_same(__remove_pointer(id), id));
+static_assert(__is_same(__remove_pointer(id*), id));
+static_assert(__is_same(__remove_pointer(__add_pointer(id)), id));
+static_assert(__is_same(__add_pointer(__remove_pointer(id)), id));



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


[clang] [Clang] Fix __{add, remove}_pointer in Objective-C++ (PR #123678)

2025-01-30 Thread Nikolas Klauser via cfe-commits

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


[clang] WIP: [clang] MicrosoftCXXABI: Fix exception copy constructor LUT after loading AST (PR #114075)

2025-01-30 Thread Andrey Glebov via cfe-commits

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


[clang] [Clang] Fix __{add, remove}_pointer in Objective-C++ (PR #123678)

2025-01-30 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

/cherry-pick 74d7f43b98910a110bc194752fca829eb19c265a

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


[clang] WIP: [clang] MicrosoftCXXABI: Serialize the exception copy constructor table in the AST (PR #114075)

2025-01-30 Thread Andrey Glebov via cfe-commits


@@ -249,6 +249,11 @@ FIELD(HasDeclaredCopyAssignmentWithConstParam, 1, MERGE_OR)
 /// base classes or fields have a no-return destructor
 FIELD(IsAnyDestructorNoReturn, 1, NO_MERGE)
 
+/// Microsoft CXX ABI specific:
+/// Whether the copy constructor is used by a `throw` expression.
+/// Used by ASTReader to restore the sidecar RecordToCopyCtor LUT.

glebov-andrey wrote:

The code has been removed, and I've fixed the title of the PR

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


[clang] 0e62c74 - [analyzer][NFC] Remove a redundant container lookup (#125064)

2025-01-30 Thread via cfe-commits

Author: Balazs Benics
Date: 2025-01-30T20:48:43+01:00
New Revision: 0e62c748d440a6d12d190e951c987efe309f40d6

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

LOG: [analyzer][NFC] Remove a redundant container lookup (#125064)

I found this using my experimental checker present at:
https://github.com/steakhal/llvm-project/tree/bb/add-redundant-lookup-checker

The idea for looking for redundant container lookups was inspired by
#123376

If there is interest, I could think of upstreaming this alpha checker.
(For the StaticAnalyzer sources it was the only TP, and I had no FPs
from the checker btw.)

Added: 


Modified: 
clang/lib/StaticAnalyzer/Core/ExplodedGraph.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/ExplodedGraph.cpp 
b/clang/lib/StaticAnalyzer/Core/ExplodedGraph.cpp
index 55bcb6e220e1ec..7b2e93cfe6 100644
--- a/clang/lib/StaticAnalyzer/Core/ExplodedGraph.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExplodedGraph.cpp
@@ -488,15 +488,17 @@ ExplodedGraph::trim(ArrayRef Sinks,
   while (!WL2.empty()) {
 const ExplodedNode *N = WL2.pop_back_val();
 
+auto [Place, Inserted] = Pass2.try_emplace(N);
+
 // Skip this node if we have already processed it.
-if (Pass2.contains(N))
+if (!Inserted)
   continue;
 
 // Create the corresponding node in the new graph and record the mapping
 // from the old node to the new node.
 ExplodedNode *NewN = G->createUncachedNode(N->getLocation(), N->State,
N->getID(), N->isSink());
-Pass2[N] = NewN;
+Place->second = NewN;
 
 // Also record the reverse mapping from the new node to the old node.
 if (InverseMap) (*InverseMap)[NewN] = N;



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


[clang] WIP: [clang] MicrosoftCXXABI: Serialize the exception copy constructor table in the AST (PR #114075)

2025-01-30 Thread Andrey Glebov via cfe-commits


@@ -2316,6 +2316,20 @@ void 
ASTDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
   }
 
   VisitCXXMethodDecl(D);
+
+  // Microsoft CXX ABI specific:
+  // Restore the RecordToCopyCtor sidecar LUT entry so that `throw` expressions
+  // find the correct copy constructor for exceptions during codegen.
+  // There is no need to check the target info because the
+  // HasCopyConstructorForExceptionObject bit only gets set for the MS ABI.
+  if (D->isCopyConstructor()) {
+// TODO What if this is not the same copy constructor which was chosen by
+//  LookupCopyingConstructor() in SemaExprCXX? Is there a better way?

glebov-andrey wrote:

Sorry, I haven't had as much time to work on this over the last few days.
But now I think I have a working version.

I created a serialization record with `CXXRecordDecl, CXXConstrctorDecl` pairs 
in it. It is written and read with all other record like `VTABLE_USES`, but 
only loaded into the AST on demand (is this correct?).
Generally some things seem dirty, like exposing the internal map in the 
interface. Also I'm not sure about naming - should MS ABI be mentioned 
everywhere, should it be called a "copy" constructor (even though that doesn't 
match the standard)?

> I'm proud of the depth of the test cases we added when implementing this the 
> first time. There may be modules bugs, but at least there are good tests, and 
> I remembered how to leverage them, so we don't have to rediscover all the 
> edge cases. :)

Absolutely! Regarding tests, what kind of tests do we need for this feature? I 
assume something like `CodeGenCXX/microsoft-abi-throw.cpp`, but for 
deserialized ASTs? And there's probably something specific to AST 
reading/writing?

> I think we don't have to worry about cases involving deleted copy ctors 
> because they will be diagnosed at the catch site (attempting to catch an 
> uncopyable type by value), so the catchable type entry will effectively be 
> dead.

I'm pretty sure there will still be a problem with `std::current_exception()` 
though - I'll have to test that.



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


[clang] [analyzer][NFC] Remove a redundant container lookup (PR #125064)

2025-01-30 Thread Balazs Benics via cfe-commits

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


[clang] [DependencyScanning] Add ability to scan TU with a buffer input (PR #125111)

2025-01-30 Thread Steven Wu via cfe-commits

https://github.com/cachemeifyoucan created 
https://github.com/llvm/llvm-project/pull/125111

Update Dependency scanner so it can scan the dependency of a TU with
a provided buffer rather than relying on the on disk file system to
provide the input file.


>From d836f2f5da850f0d985f34253873c6c461606db0 Mon Sep 17 00:00:00 2001
From: Steven Wu 
Date: Thu, 30 Jan 2025 11:51:41 -0800
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5
---
 .../DependencyScanningTool.h  |  13 +-
 .../DependencyScanningWorker.h|  47 -
 .../DependencyScanningTool.cpp|   8 +-
 .../DependencyScanningWorker.cpp  | 160 --
 clang/test/ClangScanDeps/tu-with-modules.c| 111 
 clang/tools/clang-scan-deps/ClangScanDeps.cpp |  36 ++--
 clang/tools/clang-scan-deps/Opts.td   |   2 +
 7 files changed, 305 insertions(+), 72 deletions(-)
 create mode 100644 clang/test/ClangScanDeps/tu-with-modules.c

diff --git 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
index ddb078dc16e3cd..bcc9ea17e2588f 100644
--- a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
+++ b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
@@ -128,14 +128,17 @@ class DependencyScanningTool {
   /// \param LookupModuleOutput This function is called to fill in
   ///   "-fmodule-file=", "-o" and other output
   ///   arguments for dependencies.
+  /// \param TUBuffer Optional memory buffer for translation unit input. If
+  /// TUBuffer is nullopt, the input should be included in the
+  /// Commandline already.
   ///
   /// \returns a \c StringError with the diagnostic output if clang errors
   /// occurred, \c TranslationUnitDeps otherwise.
-  llvm::Expected
-  getTranslationUnitDependencies(const std::vector &CommandLine,
- StringRef CWD,
- const llvm::DenseSet &AlreadySeen,
- LookupModuleOutputCallback 
LookupModuleOutput);
+  llvm::Expected getTranslationUnitDependencies(
+  const std::vector &CommandLine, StringRef CWD,
+  const llvm::DenseSet &AlreadySeen,
+  LookupModuleOutputCallback LookupModuleOutput,
+  std::optional TUBuffer = std::nullopt);
 
   /// Given a compilation context specified via the Clang driver command-line,
   /// gather modular dependencies of module with the given name, and return the
diff --git 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
index da6e0401411a34..ee7582b8510208 100644
--- a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
+++ b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
@@ -17,6 +17,7 @@
 #include "clang/Tooling/DependencyScanning/ModuleDepCollector.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/MemoryBufferRef.h"
 #include 
 #include 
 
@@ -83,9 +84,21 @@ class DependencyScanningWorker {
llvm::IntrusiveRefCntPtr FS);
 
   /// Run the dependency scanning tool for a given clang driver command-line,
-  /// and report the discovered dependencies to the provided consumer. If \p
-  /// ModuleName isn't empty, this function reports the dependencies of module
-  /// \p ModuleName.
+  /// and report the discovered dependencies to the provided consumer. If
+  /// TUBuffer is not nullopt, it is used as TU input for the dependency
+  /// scanning. Otherwise, the input should be included as part of the
+  /// command-line.
+  ///
+  /// \returns false if clang errors occurred (with diagnostics reported to
+  /// \c DiagConsumer), true otherwise.
+  bool computeDependencies(
+  StringRef WorkingDirectory, const std::vector &CommandLine,
+  DependencyConsumer &DepConsumer, DependencyActionController &Controller,
+  DiagnosticConsumer &DiagConsumer,
+  std::optional TUBuffer = std::nullopt);
+
+  /// Run the dependency scanning tool for a given clang driver command-line
+  /// for a specific module.
   ///
   /// \returns false if clang errors occurred (with diagnostics reported to
   /// \c DiagConsumer), true otherwise.
@@ -94,13 +107,28 @@ class DependencyScanningWorker {
DependencyConsumer &DepConsumer,
DependencyActionController &Controller,
DiagnosticConsumer &DiagConsumer,
-   std::optional ModuleName = std::nullopt);
+   StringRef ModuleName);
+
+  /// Run t

[clang] [DependencyScanning] Add ability to scan TU with a buffer input (PR #125111)

2025-01-30 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Steven Wu (cachemeifyoucan)


Changes

Update Dependency scanner so it can scan the dependency of a TU with
a provided buffer rather than relying on the on disk file system to
provide the input file.


---

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


7 Files Affected:

- (modified) 
clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h (+8-5) 
- (modified) 
clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h 
(+42-5) 
- (modified) clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp 
(+5-3) 
- (modified) clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp 
(+111-49) 
- (added) clang/test/ClangScanDeps/tu-with-modules.c (+111) 
- (modified) clang/tools/clang-scan-deps/ClangScanDeps.cpp (+26-10) 
- (modified) clang/tools/clang-scan-deps/Opts.td (+2) 


``diff
diff --git 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
index ddb078dc16e3cd..bcc9ea17e2588f 100644
--- a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
+++ b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
@@ -128,14 +128,17 @@ class DependencyScanningTool {
   /// \param LookupModuleOutput This function is called to fill in
   ///   "-fmodule-file=", "-o" and other output
   ///   arguments for dependencies.
+  /// \param TUBuffer Optional memory buffer for translation unit input. If
+  /// TUBuffer is nullopt, the input should be included in the
+  /// Commandline already.
   ///
   /// \returns a \c StringError with the diagnostic output if clang errors
   /// occurred, \c TranslationUnitDeps otherwise.
-  llvm::Expected
-  getTranslationUnitDependencies(const std::vector &CommandLine,
- StringRef CWD,
- const llvm::DenseSet &AlreadySeen,
- LookupModuleOutputCallback 
LookupModuleOutput);
+  llvm::Expected getTranslationUnitDependencies(
+  const std::vector &CommandLine, StringRef CWD,
+  const llvm::DenseSet &AlreadySeen,
+  LookupModuleOutputCallback LookupModuleOutput,
+  std::optional TUBuffer = std::nullopt);
 
   /// Given a compilation context specified via the Clang driver command-line,
   /// gather modular dependencies of module with the given name, and return the
diff --git 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
index da6e0401411a34..ee7582b8510208 100644
--- a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
+++ b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
@@ -17,6 +17,7 @@
 #include "clang/Tooling/DependencyScanning/ModuleDepCollector.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/MemoryBufferRef.h"
 #include 
 #include 
 
@@ -83,9 +84,21 @@ class DependencyScanningWorker {
llvm::IntrusiveRefCntPtr FS);
 
   /// Run the dependency scanning tool for a given clang driver command-line,
-  /// and report the discovered dependencies to the provided consumer. If \p
-  /// ModuleName isn't empty, this function reports the dependencies of module
-  /// \p ModuleName.
+  /// and report the discovered dependencies to the provided consumer. If
+  /// TUBuffer is not nullopt, it is used as TU input for the dependency
+  /// scanning. Otherwise, the input should be included as part of the
+  /// command-line.
+  ///
+  /// \returns false if clang errors occurred (with diagnostics reported to
+  /// \c DiagConsumer), true otherwise.
+  bool computeDependencies(
+  StringRef WorkingDirectory, const std::vector &CommandLine,
+  DependencyConsumer &DepConsumer, DependencyActionController &Controller,
+  DiagnosticConsumer &DiagConsumer,
+  std::optional TUBuffer = std::nullopt);
+
+  /// Run the dependency scanning tool for a given clang driver command-line
+  /// for a specific module.
   ///
   /// \returns false if clang errors occurred (with diagnostics reported to
   /// \c DiagConsumer), true otherwise.
@@ -94,13 +107,28 @@ class DependencyScanningWorker {
DependencyConsumer &DepConsumer,
DependencyActionController &Controller,
DiagnosticConsumer &DiagConsumer,
-   std::optional ModuleName = std::nullopt);
+   StringRef ModuleName);
+
+  /// Run the dependency scanning tool for a given clang driver command-line
+  /// for a specific translation unit via file system or memory buffer.
+  ///
   /// \returns A \c Stri

[clang] [Clang] Fix __{add, remove}_pointer in Objective-C++ (PR #123678)

2025-01-30 Thread via cfe-commits

llvmbot wrote:


>/cherry-pick 74d7f43b98910a110bc194752fca829eb19c265a

Error: Command failed due to missing milestone.

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


[clang] [Clang] Fix __{add, remove}_pointer in Objective-C++ (PR #123678)

2025-01-30 Thread Nikolas Klauser via cfe-commits

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


[clang] [Clang] Fix __{add, remove}_pointer in Objective-C++ (PR #123678)

2025-01-30 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

/cherry-pick 74d7f43b98910a110bc194752fca829eb19c265a

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


[clang] [libcxx] [libc++] Rename `__` prefix to `__libcpp_` for locale related functions (PR #119241)

2025-01-30 Thread Louis Dionne via cfe-commits

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


[clang] 20fd7df - Fix false negative when value initializing a field annotated with [[clang::require_field_initialization]] (#124329)

2025-01-30 Thread via cfe-commits

Author: higher-performance
Date: 2025-01-30T15:34:08-05:00
New Revision: 20fd7df0b847bb46aac2f0b5b71d242220027cbc

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

LOG: Fix false negative when value initializing a field annotated with 
[[clang::require_field_initialization]] (#124329)

It turns out we weren't handling one case: the value-initialization of a
field inside a struct.

I'm not sure why this falls under `IK_Direct` rather than `IK_Value` in
Clang, but it seems to work.

Added: 


Modified: 
clang/lib/Sema/SemaInit.cpp
clang/test/SemaCXX/uninitialized.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index b95cbbf4222056..450edcb52ae15b 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -4573,7 +4573,9 @@ static void TryConstructorInitialization(Sema &S,
 
   CXXConstructorDecl *CtorDecl = cast(Best->Function);
   if (Result != OR_Deleted) {
-if (!IsListInit && Kind.getKind() == InitializationKind::IK_Default &&
+if (!IsListInit &&
+(Kind.getKind() == InitializationKind::IK_Default ||
+ Kind.getKind() == InitializationKind::IK_Direct) &&
 DestRecordDecl != nullptr && DestRecordDecl->isAggregate() &&
 DestRecordDecl->hasUninitializedExplicitInitFields()) {
   S.Diag(Kind.getLocation(), diag::warn_field_requires_explicit_init)

diff  --git a/clang/test/SemaCXX/uninitialized.cpp 
b/clang/test/SemaCXX/uninitialized.cpp
index 52d9897cf9be6e..7578b288d7b3fe 100644
--- a/clang/test/SemaCXX/uninitialized.cpp
+++ b/clang/test/SemaCXX/uninitialized.cpp
@@ -2,6 +2,8 @@
 // RUN: %clang_cc1 -fsyntax-only -Wall -Wc++20-compat -Wuninitialized 
-Wno-unused-value -Wno-unused-lambda-capture -Wno-uninitialized-const-reference 
-std=c++1z -verify %s -fexperimental-new-constant-interpreter
 // RUN: %clang_cc1 -fsyntax-only -Wall -Wc++20-compat -Wuninitialized 
-Wno-unused-value -Wno-unused-lambda-capture -Wno-uninitialized-const-reference 
-std=c++20 -verify %s
 
+void* operator new(__SIZE_TYPE__, void*);
+
 // definitions for std::move
 namespace std {
 inline namespace foo {
@@ -1540,6 +1542,48 @@ void aggregate() {
 };
   };
 
+  struct Embed {
+int embed1;  // #FIELD_EMBED1
+int embed2 [[clang::require_explicit_initialization]];  // #FIELD_EMBED2
+  };
+  struct EmbedDerived : Embed {};
+  struct F {
+Embed f1;
+// expected-warning@+1 {{field in 'Embed' requires explicit initialization 
but is not explicitly initialized}} expected-note@#FIELD_EMBED2 {{'embed2' 
declared here}}
+explicit F(const char(&)[1]) : f1() {
+  // expected-warning@+1 {{field in 'Embed' requires explicit 
initialization but is not explicitly initialized}} expected-note@#FIELD_EMBED2 
{{'embed2' declared here}}
+  ::new(static_cast(&f1)) decltype(f1);
+  // expected-warning@+1 {{field in 'Embed' requires explicit 
initialization but is not explicitly initialized}} expected-note@#FIELD_EMBED2 
{{'embed2' declared here}}
+  ::new(static_cast(&f1)) decltype(f1)();
+#if __cplusplus >= 202002L
+  // expected-warning@+1 {{field 'embed2' requires explicit initialization 
but is not explicitly initialized}} expected-note@#FIELD_EMBED2 {{'embed2' 
declared here}}
+  ::new(static_cast(&f1)) decltype(f1)(1);
+#endif
+  // expected-warning@+1 {{field 'embed2' requires explicit initialization 
but is not explicitly initialized}} expected-note@#FIELD_EMBED2 {{'embed2' 
declared here}}
+  ::new(static_cast(&f1)) decltype(f1){1};
+}
+#if __cplusplus >= 202002L
+// expected-warning@+1 {{field 'embed2' requires explicit initialization 
but is not explicitly initialized}} expected-note@#FIELD_EMBED2 {{'embed2' 
declared here}}
+explicit F(const char(&)[2]) : f1(1) {}
+#else
+explicit F(const char(&)[2]) : f1{1, 2} { }
+#endif
+// expected-warning@+1 {{field 'embed2' requires explicit initialization 
but is not explicitly initialized}} expected-note@#FIELD_EMBED2 {{'embed2' 
declared here}}
+explicit F(const char(&)[3]) : f1{} {}
+// expected-warning@+1 {{field 'embed2' requires explicit initialization 
but is not explicitly initialized}} expected-note@#FIELD_EMBED2 {{'embed2' 
declared here}}
+explicit F(const char(&)[4]) : f1{1} {}
+// expected-warning@+1 {{field 'embed2' requires explicit initialization 
but is not explicitly initialized}} expected-note@#FIELD_EMBED2 {{'embed2' 
declared here}}
+explicit F(const char(&)[5]) : f1{.embed1 = 1} {}
+  };
+  F ctors[] = {
+  F(""),
+  F("_"),
+  F("__"),
+  F("___"),
+  F("")
+  };
+  (void)ctors;
+
   S::foo(S{1, 2, 3, 4});
   S::foo(S{.s1 = 100, .s4 = 100});
   S::foo(S{.s1 = 100}); // expected-warning {{field 's4' requires explicit 
initialization bu

[clang] Fix false negative when value initializing a field annotated with [[clang::require_field_initialization]] (PR #124329)

2025-01-30 Thread Aaron Ballman via cfe-commits

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


[clang] [llvm] [NVPTX] Add tcgen05 alloc/dealloc intrinsics (PR #124961)

2025-01-30 Thread Artem Belevich via cfe-commits


@@ -962,6 +962,109 @@ The ``griddepcontrol`` intrinsics allows the dependent 
grids and prerequisite gr
 For more information, refer 
 `PTX ISA 
`__.
 
+TCGEN05 family of Intrinsics
+
+
+The llvm.nvvm.tcgen05.* intrinsics model the TCGEN05 family of instructions
+exposed by PTX. These intrinsics use 'Tensor Memory' (henceforth ``tmem``).
+NVPTX represents this memory using ``addrspace(6)`` and is always 32-bits.
+
+For more information, refer PTX ISA
+``_.
+
+The tensor-memory pointers may only be used with the tcgen05 intrinsics.
+There are specialized load/store instructions provided (tcgen05.ld/st) to
+work with tensor-memory.
+
+For more information on tensor-memory load/store instructions, refer
+``_.
+
+All tcgen05 intrinsics use a ``null`` pointer in tmem address
+space as their last operand. This helps to preserve ordering among the tcgen05
+operations especially when the intrinsic lacks any tmem operands. This
+last operand is dropped during Codegen.

Artem-B wrote:

After reading PTX docs here's my understanding of the situation.
- there's a new kind of memory, so creating a separate AS for tmem is 
reasonable.
- tcgen05.alloc returns allocation result indirectly, by storing it in a shared 
memory. So LLVM has no direct indication that the intrinsic operates on tmem 
and affects both shared memory and tmem
- it's not clear from PTX docs what's the input for tcgen05.dealloc. It just 
says "The operand taddr must point to a previous [Tensor 
Memory](https://docs.nvidia.com/cuda/parallel-thread-execution/#tensor-memory) 
allocation" but I can't tell if that means the previous location in the shared 
memory where it stored a tmem pointer, or the tmem pointer itself. Judging by 
the proposed intrinsic signature, it's the latter. In this case LLVM knows that 
we're touching tmem.
- relinquish_alloc_permit blocks subsequent allocations, so it must not be 
reordered vs allocs.

So, the only odd thing is the allocation returning the result indirectly.

Proposed design adds artificial tmem pointer to let LLVM know that all tcgen05 
intrinsics operate on tmem and we can give LLVM sufficient hints on how they 
should be ordered. However, the dummy argument is a crutch. 

The gist of the problem here is that LLVM's existing intrinsic annotation is 
not flexible enough to describe what we have here, exactly. I.e. there's no way 
to tell LLVM that alloc and relinquish_alloc_permit operate on tmem. 
Our current options are to either make all intrinsics conservatively with 
`HasSideEffects` or, with a more relaxed "IntrInaccessibleMemOnly". I think the 
latter would be a reasonable trade-off for the time being.

A longer-term approach would be to add a new intrinsic property allowing to 
specify specific AS accessed by the intrinsic. E.g. we may extend existing 
`IntrWriteMem` and `IntrWriteMem`  to allow narrowing the scope to particular 
AS, and allow specifying more than one. E.g. alloc would indicate that it 
writes both shared and tmem.
I think that would be a useful addition to a handful of other intrinsics we 
already have, not just in NVPTX, but in the other back-ends that need to deal 
with multiple AS.


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


[clang] [StaticAnalyzer] Fix state update in VisitObjCForCollectionStmt (PR #124477)

2025-01-30 Thread Balazs Benics via cfe-commits

steakhal wrote:

> I wish I could see your reply earlier! It took me a while to reduce the 
> downstream reproducer and come up a minimal test. This way of testing looks 
> great. Maybe I should add this test anyway. Thank you steakhal!

I think I'd still prefer the unittest over a lit test because its way less 
fragile.

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


[clang] [Clang] disallow attributes on void parameters (PR #124920)

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

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/124920

>From bd731e4be65fc9c1746aa6a8f63d206eb54bb2be Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Wed, 29 Jan 2025 15:17:06 +0200
Subject: [PATCH 1/4] [Clang] disallow attributes on void parameters

---
 clang/docs/ReleaseNotes.rst| 2 ++
 clang/lib/Parse/ParseDecl.cpp  | 7 +++
 clang/test/Parser/cxx0x-attributes.cpp | 9 +
 3 files changed, 18 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7fafe2807bd388..0c87e52007d546 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -100,6 +100,8 @@ Removed Compiler Flags
 Attribute Changes in Clang
 --
 
+- Clang now disallows the use of attributes on void parameters. (#GH108819)
+
 Improvements to Clang's diagnostics
 ---
 
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index f136d5007e8a5f..0b88dd4449b1e2 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -7986,6 +7986,13 @@ void Parser::ParseParameterDeclarationClause(
 if (getLangOpts().HLSL)
   MaybeParseHLSLAnnotations(DS.getAttributes());
 
+if (ParmDeclarator.getIdentifier() == nullptr &&
+ParmDeclarator.getDeclarationAttributes().size() &&
+ParmDeclarator.getDeclSpec().getTypeSpecType() == DeclSpec::TST_void) {
+  SourceRange AttrRange = ParmDeclarator.getDeclarationAttributes().Range;
+  Diag(AttrRange.getBegin(), diag::err_attributes_not_allowed) << 
AttrRange;
+}
+
 if (Tok.is(tok::kw_requires)) {
   // User tried to define a requires clause in a parameter declaration,
   // which is surely not a function declaration.
diff --git a/clang/test/Parser/cxx0x-attributes.cpp 
b/clang/test/Parser/cxx0x-attributes.cpp
index fad3010c98b9c2..13fcdd142fa841 100644
--- a/clang/test/Parser/cxx0x-attributes.cpp
+++ b/clang/test/Parser/cxx0x-attributes.cpp
@@ -453,3 +453,12 @@ namespace P2361 {
 }
 
 alignas(int) struct AlignAsAttribute {}; // expected-error {{misplaced 
attributes; expected attributes here}}
+
+namespace GH108819 {
+void a([[maybe_unused]] void) {} // expected-error {{an 
attribute list cannot appear here}} \
+ // expected-warning {{use of 
the 'maybe_unused' attribute is a C++17 extension}}
+void b([[deprecated]] void) {}   // expected-error {{an 
attribute list cannot appear here}} \
+ // expected-warning {{use of 
the 'deprecated' attribute is a C++14 extension}}
+void c([[clang::lifetimebound]] void) {} // expected-error {{an 
attribute list cannot appear here}}
+void d([[clang::annotate("a", "b", 1)]] void) {} // expected-error {{an 
attribute list cannot appear here}}
+}

>From 063f76730ebfd289f5340d0d8477a43a5ea965c2 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Wed, 29 Jan 2025 15:54:48 +0200
Subject: [PATCH 2/4] remove unnecessary name check

---
 clang/lib/Parse/ParseDecl.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 0b88dd4449b1e2..934c16c9591520 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -7986,8 +7986,7 @@ void Parser::ParseParameterDeclarationClause(
 if (getLangOpts().HLSL)
   MaybeParseHLSLAnnotations(DS.getAttributes());
 
-if (ParmDeclarator.getIdentifier() == nullptr &&
-ParmDeclarator.getDeclarationAttributes().size() &&
+if (ParmDeclarator.getDeclarationAttributes().size() &&
 ParmDeclarator.getDeclSpec().getTypeSpecType() == DeclSpec::TST_void) {
   SourceRange AttrRange = ParmDeclarator.getDeclarationAttributes().Range;
   Diag(AttrRange.getBegin(), diag::err_attributes_not_allowed) << 
AttrRange;

>From 3f3431513ad59111794953d27e64608b3ce2e6e1 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Wed, 29 Jan 2025 16:07:18 +0200
Subject: [PATCH 3/4] use empty instead of size

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

diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 934c16c9591520..963b59565953d4 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -7986,7 +7986,7 @@ void Parser::ParseParameterDeclarationClause(
 if (getLangOpts().HLSL)
   MaybeParseHLSLAnnotations(DS.getAttributes());
 
-if (ParmDeclarator.getDeclarationAttributes().size() &&
+if (!ParmDeclarator.getDeclarationAttributes().empty() &&
 ParmDeclarator.getDeclSpec().getTypeSpecType() == DeclSpec::TST_void) {
   SourceRange AttrRange = ParmDeclarator.getDeclarationAttributes().Range;
   Diag(AttrRange.getBegin(), diag::err_attributes_not_allowed) << 
AttrRange;

>From 9919006df9ec32023b2bf179b72f9ebaf977bd08 Mon Sep 17 00:0

[clang] [Win/X86] Make _m_prefetch[w] builtins to avoid winnt.h conflicts (PR #115099)

2025-01-30 Thread Reid Kleckner via cfe-commits

https://github.com/rnk updated https://github.com/llvm/llvm-project/pull/115099

>From e5f485ad8000c296229794346fdd627b90e504d2 Mon Sep 17 00:00:00 2001
From: Reid Kleckner 
Date: Tue, 5 Nov 2024 16:05:53 -0800
Subject: [PATCH 1/3] [Win/X86] Make _m_prefetch[w] builtins to avoid winnt.h
 conflicts

---
 clang/include/clang/Basic/BuiltinsX86.td |  7 ++-
 clang/lib/CodeGen/CGBuiltin.cpp  | 10 ++
 clang/lib/Headers/prfchwintrin.h | 23 ++-
 3 files changed, 26 insertions(+), 14 deletions(-)

diff --git a/clang/include/clang/Basic/BuiltinsX86.td 
b/clang/include/clang/Basic/BuiltinsX86.td
index 572ac7235be02f..00bee2051caa85 100644
--- a/clang/include/clang/Basic/BuiltinsX86.td
+++ b/clang/include/clang/Basic/BuiltinsX86.td
@@ -146,10 +146,15 @@ let Attributes = [Const, NoThrow, 
RequiredVectorWidth<256>], Features = "avx" in
 // current formulation is based on what was easiest to recognize from the
 // pre-TableGen version.
 
-let Features = "mmx", Attributes = [NoThrow, Const] in {
+let Features = "mmx", Header = "immintrin.h", Attributes = [NoThrow, Const] in 
{
   def _mm_prefetch : X86NoPrefixBuiltin<"void(char const *, int)">;
 }
 
+let Features = "mmx", Header = "intrin.h", Attributes = [NoThrow, Const] in {
+  def _m_prefetch : X86NoPrefixBuiltin<"void(void *)">;
+  def _m_prefetchw : X86NoPrefixBuiltin<"void(const void *)">;
+}
+
 let Features = "sse", Attributes = [NoThrow] in {
   def ldmxcsr : X86Builtin<"void(unsigned int)">;
 }
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 7ec9d59bfed5cf..0224238d976193 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -15254,6 +15254,16 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned 
BuiltinID,
 Function *F = CGM.getIntrinsic(Intrinsic::prefetch, Address->getType());
 return Builder.CreateCall(F, {Address, RW, Locality, Data});
   }
+  case X86::BI_m_prefetch:
+  case X86::BI_m_prefetchw: {
+Value *Address = Ops[0];
+// The 'w' suffix implies write.
+Value *RW = ConstantInt::get(Int32Ty, BuiltinID == X86::BI_m_prefetchw ? 1 
: 0);
+Value *Locality = ConstantInt::get(Int32Ty, 0x3);
+Value *Data = ConstantInt::get(Int32Ty, 1);
+Function *F = CGM.getIntrinsic(Intrinsic::prefetch, Address->getType());
+return Builder.CreateCall(F, {Address, RW, Locality, Data});
+  }
   case X86::BI_mm_clflush: {
 return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse2_clflush),
   Ops[0]);
diff --git a/clang/lib/Headers/prfchwintrin.h b/clang/lib/Headers/prfchwintrin.h
index eaea5f3cf8febf..8ec55d7073716f 100644
--- a/clang/lib/Headers/prfchwintrin.h
+++ b/clang/lib/Headers/prfchwintrin.h
@@ -14,6 +14,10 @@
 #ifndef __PRFCHWINTRIN_H
 #define __PRFCHWINTRIN_H
 
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
 /// Loads a memory sequence containing the specified memory address into
 ///all data cache levels.
 ///
@@ -26,11 +30,7 @@
 ///
 /// \param __P
 ///A pointer specifying the memory address to be prefetched.
-static __inline__ void __attribute__((__always_inline__, __nodebug__))
-_m_prefetch(void *__P)
-{
-  __builtin_prefetch (__P, 0, 3 /* _MM_HINT_T0 */);
-}
+void _m_prefetch(void *__P);
 
 /// Loads a memory sequence containing the specified memory address into
 ///the L1 data cache and sets the cache-coherency state to modified.
@@ -48,13 +48,10 @@ _m_prefetch(void *__P)
 ///
 /// \param __P
 ///A pointer specifying the memory address to be prefetched.
-static __inline__ void __attribute__((__always_inline__, __nodebug__))
-_m_prefetchw(volatile const void *__P)
-{
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wcast-qual"
-  __builtin_prefetch ((const void*)__P, 1, 3 /* _MM_HINT_T0 */);
-#pragma clang diagnostic pop
-}
+void _m_prefetchw(volatile const void *__P);
+
+#if defined(__cplusplus)
+} // extern "C"
+#endif
 
 #endif /* __PRFCHWINTRIN_H */

>From 80e6138ccc1e970d12c86be937562a2ac96e8685 Mon Sep 17 00:00:00 2001
From: Reid Kleckner 
Date: Wed, 6 Nov 2024 00:45:51 +
Subject: [PATCH 2/3] format

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

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 0224238d976193..ce3b9f1d99c947 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -15258,7 +15258,8 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned 
BuiltinID,
   case X86::BI_m_prefetchw: {
 Value *Address = Ops[0];
 // The 'w' suffix implies write.
-Value *RW = ConstantInt::get(Int32Ty, BuiltinID == X86::BI_m_prefetchw ? 1 
: 0);
+Value *RW =
+ConstantInt::get(Int32Ty, BuiltinID == X86::BI_m_prefetchw ? 1 : 0);
 Value *Locality = ConstantInt::get(Int32Ty, 0x3);
 Value *Data = ConstantInt::get(Int32Ty, 1);
 Function *F = CGM.getIntrinsic(Intrinsic::prefetch, Address->getType());


[clang] [Win/X86] Make _m_prefetch[w] builtins to avoid winnt.h conflicts (PR #115099)

2025-01-30 Thread Reid Kleckner via cfe-commits

https://github.com/rnk commented:

I had to rebase this over the table-gen-ification of the builtins, but I think 
this is still relevant.

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


[clang] [Win/X86] Make _m_prefetch[w] builtins to avoid winnt.h conflicts (PR #115099)

2025-01-30 Thread Reid Kleckner via cfe-commits


@@ -31,10 +31,13 @@
 // All MMX instructions will be generated via builtins. Any MMX vector
 // types (<1 x i64>, <2 x i32>, etc.) that aren't used by these builtins will 
be
 // expanded by the back-end.
+//
 // FIXME: _mm_prefetch must be a built-in because it takes a compile-time 
constant
 // argument and our prior approach of using a #define to the current built-in
 // doesn't work in the presence of re-declaration of _mm_prefetch for windows.
-TARGET_BUILTIN(_mm_prefetch, "vcC*i", "nc", "mmx")
+TARGET_HEADER_BUILTIN(_mm_prefetch, "vcC*i", "nc", IMMINTRIN_H, ALL_LANGUAGES, 
"mmx")
+TARGET_HEADER_BUILTIN(_m_prefetch, "vv*", "nc", INTRIN_H, ALL_LANGUAGES, "")
+TARGET_HEADER_BUILTIN(_m_prefetchw, "vvDC*", "nc", INTRIN_H, ALL_LANGUAGES, "")

rnk wrote:

Yes, we should, good catch

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


[clang] [Win/X86] Make _m_prefetch[w] builtins to avoid winnt.h conflicts (PR #115099)

2025-01-30 Thread Reid Kleckner via cfe-commits

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


[clang-tools-extra] [clang-tidy] Address false positives in misc-redundant-expression checker (PR #122841)

2025-01-30 Thread via cfe-commits

https://github.com/earnol updated 
https://github.com/llvm/llvm-project/pull/122841

>From c26434fea8a3ebf546139805ab4f7ef5d2f4252d Mon Sep 17 00:00:00 2001
From: Vladislav Aranov 
Date: Mon, 13 Jan 2025 20:19:58 -0500
Subject: [PATCH 1/2] [clang-tidy] Address false positives in
 misc-redundant-expression checker

Address situations when misc-redundant-expression checker provides excessive
diagnostics for situations with different macros having the same value.
In perticular situations described in the initial report of
https://github.com/llvm/llvm-project/issues/118885 are addressed.
The situations which are popped inside discussion like
if (A + B == B + A) for macros are not properly addressed by this patch.
But I still believe even in the current state the patch can be useful.
---
 .../misc/RedundantExpressionCheck.cpp | 145 ++--
 clang-tools-extra/docs/ReleaseNotes.rst   |   2 +-
 .../checks/misc/redundant-expression.rst  |  14 +-
 .../checkers/misc/redundant-expression.cpp| 218 ++
 4 files changed, 348 insertions(+), 31 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
index fc35bc22c52e04..c249244b1a1b27 100644
--- a/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
@@ -139,10 +139,8 @@ static bool areEquivalentExpr(const Expr *Left, const Expr 
*Right) {
 return cast(Left)->getOpcode() ==
cast(Right)->getOpcode();
   case Stmt::UnaryExprOrTypeTraitExprClass:
-const auto *LeftUnaryExpr =
-cast(Left);
-const auto *RightUnaryExpr =
-cast(Right);
+const auto *LeftUnaryExpr = cast(Left);
+const auto *RightUnaryExpr = cast(Right);
 if (LeftUnaryExpr->isArgumentType() && RightUnaryExpr->isArgumentType())
   return LeftUnaryExpr->getKind() == RightUnaryExpr->getKind() &&
  LeftUnaryExpr->getArgumentType() ==
@@ -699,7 +697,8 @@ static bool retrieveRelationalIntegerConstantExpr(
 
 Symbol = OverloadedOperatorExpr->getArg(IntegerConstantIsFirstArg ? 1 : 0);
 OperandExpr = OverloadedOperatorExpr;
-Opcode = 
BinaryOperator::getOverloadedOpcode(OverloadedOperatorExpr->getOperator());
+Opcode = BinaryOperator::getOverloadedOpcode(
+OverloadedOperatorExpr->getOperator());
 
 if (!retrieveIntegerConstantExpr(Result, Id, Value, ConstExpr))
   return false;
@@ -728,7 +727,8 @@ static bool retrieveRelationalIntegerConstantExpr(
 }
 
 // Checks for expressions like (X == 4) && (Y != 9)
-static bool areSidesBinaryConstExpressions(const BinaryOperator *&BinOp, const 
ASTContext *AstCtx) {
+static bool areSidesBinaryConstExpressions(const BinaryOperator *&BinOp,
+   const ASTContext *AstCtx) {
   const auto *LhsBinOp = dyn_cast(BinOp->getLHS());
   const auto *RhsBinOp = dyn_cast(BinOp->getRHS());
 
@@ -747,6 +747,28 @@ static bool areSidesBinaryConstExpressions(const 
BinaryOperator *&BinOp, const A
   return false;
 }
 
+static bool areSidesBinaryConstExpressionsOrDefinesOrIntegerConstant(
+const BinaryOperator *&BinOp, const ASTContext *AstCtx) {
+  if (areSidesBinaryConstExpressions(BinOp, AstCtx))
+return true;
+
+  const Expr *Lhs = BinOp->getLHS();
+  const Expr *Rhs = BinOp->getRHS();
+
+  if (!Lhs || !Rhs)
+return false;
+
+  auto IsDefineExpr = [AstCtx](const Expr *E) {
+const SourceRange Lsr = E->getSourceRange();
+if (!Lsr.getBegin().isMacroID() || E->isValueDependent() ||
+!E->isIntegerConstantExpr(*AstCtx))
+  return false;
+return true;
+  };
+
+  return IsDefineExpr(Lhs) || IsDefineExpr(Rhs);
+}
+
 // Retrieves integer constant subexpressions from binary operator expressions
 // that have two equivalent sides.
 // E.g.: from (X == 5) && (X == 5) retrieves 5 and 5.
@@ -785,7 +807,7 @@ static bool retrieveConstExprFromBothSides(const 
BinaryOperator *&BinOp,
 }
 
 static bool isSameRawIdentifierToken(const Token &T1, const Token &T2,
-const SourceManager &SM) {
+ const SourceManager &SM) {
   if (T1.getKind() != T2.getKind())
 return false;
   if (T1.isNot(tok::raw_identifier))
@@ -808,8 +830,8 @@ static bool areExprsFromDifferentMacros(const Expr *LhsExpr,
 const ASTContext *AstCtx) {
   if (!LhsExpr || !RhsExpr)
 return false;
-  SourceRange Lsr = LhsExpr->getSourceRange();
-  SourceRange Rsr = RhsExpr->getSourceRange();
+  const SourceRange Lsr = LhsExpr->getSourceRange();
+  const SourceRange Rsr = RhsExpr->getSourceRange();
   if (!Lsr.getBegin().isMacroID() || !Rsr.getBegin().isMacroID())
 return false;
 
@@ -847,11 +869,83 @@ static bool areExprsMacroAndNonMacro(const Expr *&LhsExpr,
   if (!LhsExpr || !RhsExpr)
 return false;
 
-  SourceLocation LhsLoc = LhsExpr->getExprLoc();
-  Source

[clang] [Win/X86] Make _m_prefetch[w] builtins to avoid winnt.h conflicts (PR #115099)

2025-01-30 Thread Reid Kleckner via cfe-commits

https://github.com/rnk updated https://github.com/llvm/llvm-project/pull/115099

>From e5f485ad8000c296229794346fdd627b90e504d2 Mon Sep 17 00:00:00 2001
From: Reid Kleckner 
Date: Tue, 5 Nov 2024 16:05:53 -0800
Subject: [PATCH 1/5] [Win/X86] Make _m_prefetch[w] builtins to avoid winnt.h
 conflicts

---
 clang/include/clang/Basic/BuiltinsX86.td |  7 ++-
 clang/lib/CodeGen/CGBuiltin.cpp  | 10 ++
 clang/lib/Headers/prfchwintrin.h | 23 ++-
 3 files changed, 26 insertions(+), 14 deletions(-)

diff --git a/clang/include/clang/Basic/BuiltinsX86.td 
b/clang/include/clang/Basic/BuiltinsX86.td
index 572ac7235be02f..00bee2051caa85 100644
--- a/clang/include/clang/Basic/BuiltinsX86.td
+++ b/clang/include/clang/Basic/BuiltinsX86.td
@@ -146,10 +146,15 @@ let Attributes = [Const, NoThrow, 
RequiredVectorWidth<256>], Features = "avx" in
 // current formulation is based on what was easiest to recognize from the
 // pre-TableGen version.
 
-let Features = "mmx", Attributes = [NoThrow, Const] in {
+let Features = "mmx", Header = "immintrin.h", Attributes = [NoThrow, Const] in 
{
   def _mm_prefetch : X86NoPrefixBuiltin<"void(char const *, int)">;
 }
 
+let Features = "mmx", Header = "intrin.h", Attributes = [NoThrow, Const] in {
+  def _m_prefetch : X86NoPrefixBuiltin<"void(void *)">;
+  def _m_prefetchw : X86NoPrefixBuiltin<"void(const void *)">;
+}
+
 let Features = "sse", Attributes = [NoThrow] in {
   def ldmxcsr : X86Builtin<"void(unsigned int)">;
 }
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 7ec9d59bfed5cf..0224238d976193 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -15254,6 +15254,16 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned 
BuiltinID,
 Function *F = CGM.getIntrinsic(Intrinsic::prefetch, Address->getType());
 return Builder.CreateCall(F, {Address, RW, Locality, Data});
   }
+  case X86::BI_m_prefetch:
+  case X86::BI_m_prefetchw: {
+Value *Address = Ops[0];
+// The 'w' suffix implies write.
+Value *RW = ConstantInt::get(Int32Ty, BuiltinID == X86::BI_m_prefetchw ? 1 
: 0);
+Value *Locality = ConstantInt::get(Int32Ty, 0x3);
+Value *Data = ConstantInt::get(Int32Ty, 1);
+Function *F = CGM.getIntrinsic(Intrinsic::prefetch, Address->getType());
+return Builder.CreateCall(F, {Address, RW, Locality, Data});
+  }
   case X86::BI_mm_clflush: {
 return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse2_clflush),
   Ops[0]);
diff --git a/clang/lib/Headers/prfchwintrin.h b/clang/lib/Headers/prfchwintrin.h
index eaea5f3cf8febf..8ec55d7073716f 100644
--- a/clang/lib/Headers/prfchwintrin.h
+++ b/clang/lib/Headers/prfchwintrin.h
@@ -14,6 +14,10 @@
 #ifndef __PRFCHWINTRIN_H
 #define __PRFCHWINTRIN_H
 
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
 /// Loads a memory sequence containing the specified memory address into
 ///all data cache levels.
 ///
@@ -26,11 +30,7 @@
 ///
 /// \param __P
 ///A pointer specifying the memory address to be prefetched.
-static __inline__ void __attribute__((__always_inline__, __nodebug__))
-_m_prefetch(void *__P)
-{
-  __builtin_prefetch (__P, 0, 3 /* _MM_HINT_T0 */);
-}
+void _m_prefetch(void *__P);
 
 /// Loads a memory sequence containing the specified memory address into
 ///the L1 data cache and sets the cache-coherency state to modified.
@@ -48,13 +48,10 @@ _m_prefetch(void *__P)
 ///
 /// \param __P
 ///A pointer specifying the memory address to be prefetched.
-static __inline__ void __attribute__((__always_inline__, __nodebug__))
-_m_prefetchw(volatile const void *__P)
-{
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wcast-qual"
-  __builtin_prefetch ((const void*)__P, 1, 3 /* _MM_HINT_T0 */);
-#pragma clang diagnostic pop
-}
+void _m_prefetchw(volatile const void *__P);
+
+#if defined(__cplusplus)
+} // extern "C"
+#endif
 
 #endif /* __PRFCHWINTRIN_H */

>From 80e6138ccc1e970d12c86be937562a2ac96e8685 Mon Sep 17 00:00:00 2001
From: Reid Kleckner 
Date: Wed, 6 Nov 2024 00:45:51 +
Subject: [PATCH 2/5] format

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

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 0224238d976193..ce3b9f1d99c947 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -15258,7 +15258,8 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned 
BuiltinID,
   case X86::BI_m_prefetchw: {
 Value *Address = Ops[0];
 // The 'w' suffix implies write.
-Value *RW = ConstantInt::get(Int32Ty, BuiltinID == X86::BI_m_prefetchw ? 1 
: 0);
+Value *RW =
+ConstantInt::get(Int32Ty, BuiltinID == X86::BI_m_prefetchw ? 1 : 0);
 Value *Locality = ConstantInt::get(Int32Ty, 0x3);
 Value *Data = ConstantInt::get(Int32Ty, 1);
 Function *F = CGM.getIntrinsic(Intrinsic::prefetch, Address->getType());


[clang] [clang-format] Fix mismatched break in BlockIndent (PR #124998)

2025-01-30 Thread Gedare Bloom via cfe-commits


@@ -9608,6 +9608,10 @@ TEST_F(FormatTest, AlignsAfterOpenBracket) {
   "\"a aaa a aaa a\"\n"
   ");",
   Style);
+  verifyFormat("aaa(\n"
+   "&bbb\n"

gedare wrote:

Relocated and trimmed.

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


[clang] [clang-format] Fix annotation of Java/JavaScript keyword extends (PR #125038)

2025-01-30 Thread Owen Pan via cfe-commits

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


[clang] 1a25bea - [clang-format] Add ClassHeadName to help annotating StartOfName (#124891)

2025-01-30 Thread via cfe-commits

Author: Owen Pan
Date: 2025-01-30T19:33:15-08:00
New Revision: 1a25bea852cd4f7d99e644953c31278f7f257ccd

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

LOG: [clang-format] Add ClassHeadName to help annotating StartOfName (#124891)

Fixes #124574.

Added: 


Modified: 
clang/lib/Format/FormatToken.h
clang/lib/Format/TokenAnnotator.cpp
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 




diff  --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index d97b6522f1fefa..29aba281ae1037 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -44,6 +44,8 @@ namespace format {
   TYPE(CaseLabelColon) 
\
   TYPE(CastRParen) 
\
   TYPE(ClassLBrace)
\
+  /* Name of class/struct/union/interface definition. */   
\
+  TYPE(ClassHeadName)  
\
   TYPE(ClassRBrace)
\
   TYPE(CompoundRequirementLBrace)  
\
   /* ternary ?: expression */  
\

diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index c1714a19e2d182..f25332e3a5f4e1 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2581,7 +2581,7 @@ class AnnotatingParser {
 if (Style.isVerilog())
   return false;
 
-if (Tok.isNot(tok::identifier) || !Tok.Previous)
+if (!Tok.Previous || Tok.isNot(tok::identifier) || 
Tok.is(TT_ClassHeadName))
   return false;
 
 if ((Style.isJavaScript() || Style.Language == FormatStyle::LK_Java) &&

diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 120922d271aab7..1411197e325549 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -4029,7 +4029,7 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
   const FormatToken &InitialToken = *FormatTok;
   nextToken();
 
-  const FormatToken *ClassName = nullptr;
+  FormatToken *ClassName = nullptr;
   bool IsDerived = false;
   auto IsNonMacroIdentifier = [](const FormatToken *Tok) {
 return Tok->is(tok::identifier) && Tok->TokenText != 
Tok->TokenText.upper();
@@ -4059,7 +4059,7 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
 }
 if (FormatTok->is(tok::l_square) && handleCppAttributes())
   continue;
-const auto *Previous = FormatTok;
+auto *Previous = FormatTok;
 nextToken();
 switch (FormatTok->Tok.getKind()) {
 case tok::l_paren:
@@ -4074,9 +4074,12 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
 case tok::hashhash:
   break;
 default:
-  if (!JSPastExtendsOrImplements && !ClassName &&
-  Previous->is(tok::identifier) && Previous->isNot(TT_AttributeMacro) 
&&
-  Previous->TokenText != Previous->TokenText.upper()) {
+  if (JSPastExtendsOrImplements || ClassName ||
+  Previous->isNot(tok::identifier) || Previous->is(TT_AttributeMacro)) 
{
+break;
+  }
+  if (const auto Text = Previous->TokenText;
+  Text.size() == 1 || Text != Text.upper()) {
 ClassName = Previous;
   }
 }
@@ -4160,6 +4163,8 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
   if (FormatTok->is(tok::l_brace)) {
 if (IsListInitialization())
   return;
+if (ClassName)
+  ClassName->setFinalizedType(TT_ClassHeadName);
 auto [OpenBraceType, ClosingBraceType] = GetBraceTypes(InitialToken);
 FormatTok->setFinalizedType(OpenBraceType);
 if (ParseAsExpr) {

diff  --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 81512d6116110e..9995f090d441f7 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -479,11 +479,13 @@ TEST_F(TokenAnnotatorTest, UnderstandsUsesOfPlusAndMinus) 
{
 TEST_F(TokenAnnotatorTest, UnderstandsClasses) {
   auto Tokens = annotate("class C {};");
   ASSERT_EQ(Tokens.size(), 6u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::identifier, TT_ClassHeadName);
   EXPECT_TOKEN(Tokens[2], tok::l_brace, TT_ClassLBrace);
   EXPECT_TOKEN(Tokens[3], tok::r_brace, TT_ClassRBrace);
 
   Tokens = annotate("const class C {} c;");
   ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::identifier, TT_ClassHeadName);
   EXPECT_TOKEN(Tokens[3], tok::l_brace, TT_ClassLBrace);
  

[clang] [clang-format] Add ClassHeadName to help annotating StartOfName (PR #124891)

2025-01-30 Thread Owen Pan via cfe-commits

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


[clang] [Clang] Add GCC's __builtin_stack_address() to Clang. (PR #121332)

2025-01-30 Thread Aaron Ballman via cfe-commits


@@ -4782,6 +4857,34 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 Function *F = CGM.getIntrinsic(Intrinsic::frameaddress, AllocaInt8PtrTy);
 return RValue::get(Builder.CreateCall(F, Depth));
   }
+  case Builtin::BI__builtin_stack_address: {
+switch (getTarget().getTriple().getArch()) {
+case Triple::x86:
+  return RValue::get(EmitSpecialRegisterBuiltin(
+  *this, E, Int32Ty, VoidPtrTy, NormalRead, "esp"));
+case Triple::x86_64:
+  return RValue::get(EmitSpecialRegisterBuiltin(
+  *this, E, Int64Ty, VoidPtrTy, NormalRead, "rsp"));
+case Triple::arm:
+case Triple::armeb:
+case Triple::thumb:
+case Triple::thumbeb:
+case Triple::aarch64:
+case Triple::aarch64_be:
+case Triple::aarch64_32:
+case Triple::riscv32:
+case Triple::riscv64: {
+  llvm::IntegerType *SPRegIntTy =
+  getTarget().getTriple().getArchPointerBitWidth() == 64 ? Int64Ty
+ : Int32Ty;
+  return RValue::get(EmitSpecialRegisterBuiltin(
+  *this, E, SPRegIntTy, VoidPtrTy, NormalRead, "sp"));
+}
+default:
+  ErrorUnsupported(E, "__builtin_stack_address");

AaronBallman wrote:

We're missing test coverage for unsupported architectures; this seems like 
something that should be rejected before CodeGen too (in SemaChecking.cpp)

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


[clang] [Clang] Add GCC's __builtin_stack_address() to Clang. (PR #121332)

2025-01-30 Thread Aaron Ballman via cfe-commits


@@ -899,6 +899,12 @@ def FrameAddress : Builtin {
   let Prototype = "void*(_Constant unsigned int)";
 }
 
+def StackAddress : Builtin {
+  let Spellings = ["__builtin_stack_address"];
+  let Attributes = [NoThrow];

AaronBallman wrote:

Should this be marked `Const` (or maybe `Pure`)?

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


[clang] [clang module] Current Working Directory Pruning (PR #124786)

2025-01-30 Thread Michael Spencer via cfe-commits

Bigcheese wrote:

It has to happen after the header search optimization in case that removes 
relative header search paths.

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


[clang] [clang:frontend] Move helper functions to common location for SemaSPIRV (PR #125045)

2025-01-30 Thread via cfe-commits

https://github.com/Sirraide requested changes to this pull request.

I think there may be some code duplication here, so moving *some* of this code 
around *might* make sense, but I see a few issues with how this is done at the 
moment:
1. If we were to introduce new helpers, then instead of making a new header for 
this, these functions should just become member functions of the `Sema` class.

2. The new version of `CheckAllArgTypesAreCorrect()` is... way too complicated, 
in my opinion; I have trouble trying to figure out what two parameters that are 
a variant and a pair are supposed to mean from looking at the function, and it 
does feel like this function wants to be at least two or three separate 
functions...

I think a better approach would be to leave the HLSL functions alone and just 
factor out a separate helper and put it in `SemaSPIRV.cpp`, because as-is, this 
pr isn’t exactly simplifying things...

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


[clang] [StaticAnalyzer] Fix state update in VisitObjCForCollectionStmt (PR #124477)

2025-01-30 Thread Balazs Benics via cfe-commits

steakhal wrote:

> @steakhal I have added your test on behalf of you here: 
> https://github.com/llvm/llvm-project/pull/124477/commits/b932fb61338ed6ec47db351240dc65b9454ba28c

Yea, thanks. Please drop all the refs to my name. Otherwise LGTM.

Thanks for fixing this. I think you can merge this to unblock your CI.
Please come back if other reviewers have further comments.

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


[clang] [clang][X86] Support __attribute__((model("small"/"large"))) (PR #124834)

2025-01-30 Thread Arthur Eubanks via cfe-commits


@@ -1,64 +1,40 @@
-// RUN: %clang_cc1 -triple aarch64 -verify=expected,aarch64 -fsyntax-only %s
+// RUN: %clang_cc1 -triple aarch64 -verify=expected,unsupported -fsyntax-only 
%s
 // RUN: %clang_cc1 -triple loongarch64 -verify=expected,loongarch64 
-fsyntax-only %s
-// RUN: %clang_cc1 -triple mips64 -verify=expected,mips64 -fsyntax-only %s
-// RUN: %clang_cc1 -triple powerpc64 -verify=expected,powerpc64 -fsyntax-only 
%s
-// RUN: %clang_cc1 -triple riscv64 -verify=expected,riscv64 -fsyntax-only %s
+// RUN: %clang_cc1 -triple mips64 -verify=expected,unsupported -fsyntax-only %s
+// RUN: %clang_cc1 -triple powerpc64 -verify=expected,unsupported 
-fsyntax-only %s
+// RUN: %clang_cc1 -triple riscv64 -verify=expected,unsupported -fsyntax-only 
%s
 // RUN: %clang_cc1 -triple x86_64 -verify=expected,x86_64 -fsyntax-only %s
+// RUN: %clang_cc1 -triple nvptx64-unknown-cuda -fcuda-is-device -x cuda 
-verify=expected,unsupported -fsyntax-only %s

aeubanks wrote:

I'm tempted to keep things as is since it seems like this is not the only issue 
that can come up with nvptx compiles. For example, the `thread_local` global in 
the variable has the same issue where nvptx doesn't support thread local 
globals, which clang complains about, and I don't really see a difference 
between `__attribute__((model()))` and `thread_local` in that they can both be 
used on arbitrary globals.

Do you think it's reasonable to postpone this suggestion until people actually 
hit it? For example, if people aren't hitting the `thread_local` issue, then 
perhaps people won't hit a warning with this attribute.

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


[clang] [Clang][counted_by] Refactor __builtin_dynamic_object_size on FAMs (PR #122198)

2025-01-30 Thread Bill Wendling via cfe-commits

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


[clang] [Win/X86] Make _m_prefetch[w] builtins to avoid winnt.h conflicts (PR #115099)

2025-01-30 Thread Reid Kleckner via cfe-commits


@@ -2225,9 +2221,10 @@ _mm_storer_ps(float *__p, __m128 __a)
 ///be generated. \n
 ///_MM_HINT_T2: Move data using the T2 hint. The PREFETCHT2 instruction 
will
 ///be generated.
-#define _mm_prefetch(a, sel) (__builtin_prefetch((const void *)(a), \
- ((sel) >> 2) & 1, (sel) & 
0x3))
-#endif
+///
+/// _mm_prefetch is implemented as a "library builtin" directly in Clang,

rnk wrote:

Probably not well. I can put this inside an `#if 0` block or some other macro 
construct so that Doxygen sees it but it never interacts with user code, but I 
don't have a working doxygen install to confirm if it will work.

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


[clang] [Win/X86] Make _m_prefetch[w] builtins to avoid winnt.h conflicts (PR #115099)

2025-01-30 Thread Reid Kleckner via cfe-commits

https://github.com/rnk updated https://github.com/llvm/llvm-project/pull/115099

>From e5f485ad8000c296229794346fdd627b90e504d2 Mon Sep 17 00:00:00 2001
From: Reid Kleckner 
Date: Tue, 5 Nov 2024 16:05:53 -0800
Subject: [PATCH 1/6] [Win/X86] Make _m_prefetch[w] builtins to avoid winnt.h
 conflicts

---
 clang/include/clang/Basic/BuiltinsX86.td |  7 ++-
 clang/lib/CodeGen/CGBuiltin.cpp  | 10 ++
 clang/lib/Headers/prfchwintrin.h | 23 ++-
 3 files changed, 26 insertions(+), 14 deletions(-)

diff --git a/clang/include/clang/Basic/BuiltinsX86.td 
b/clang/include/clang/Basic/BuiltinsX86.td
index 572ac7235be02f..00bee2051caa85 100644
--- a/clang/include/clang/Basic/BuiltinsX86.td
+++ b/clang/include/clang/Basic/BuiltinsX86.td
@@ -146,10 +146,15 @@ let Attributes = [Const, NoThrow, 
RequiredVectorWidth<256>], Features = "avx" in
 // current formulation is based on what was easiest to recognize from the
 // pre-TableGen version.
 
-let Features = "mmx", Attributes = [NoThrow, Const] in {
+let Features = "mmx", Header = "immintrin.h", Attributes = [NoThrow, Const] in 
{
   def _mm_prefetch : X86NoPrefixBuiltin<"void(char const *, int)">;
 }
 
+let Features = "mmx", Header = "intrin.h", Attributes = [NoThrow, Const] in {
+  def _m_prefetch : X86NoPrefixBuiltin<"void(void *)">;
+  def _m_prefetchw : X86NoPrefixBuiltin<"void(const void *)">;
+}
+
 let Features = "sse", Attributes = [NoThrow] in {
   def ldmxcsr : X86Builtin<"void(unsigned int)">;
 }
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 7ec9d59bfed5cf..0224238d976193 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -15254,6 +15254,16 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned 
BuiltinID,
 Function *F = CGM.getIntrinsic(Intrinsic::prefetch, Address->getType());
 return Builder.CreateCall(F, {Address, RW, Locality, Data});
   }
+  case X86::BI_m_prefetch:
+  case X86::BI_m_prefetchw: {
+Value *Address = Ops[0];
+// The 'w' suffix implies write.
+Value *RW = ConstantInt::get(Int32Ty, BuiltinID == X86::BI_m_prefetchw ? 1 
: 0);
+Value *Locality = ConstantInt::get(Int32Ty, 0x3);
+Value *Data = ConstantInt::get(Int32Ty, 1);
+Function *F = CGM.getIntrinsic(Intrinsic::prefetch, Address->getType());
+return Builder.CreateCall(F, {Address, RW, Locality, Data});
+  }
   case X86::BI_mm_clflush: {
 return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse2_clflush),
   Ops[0]);
diff --git a/clang/lib/Headers/prfchwintrin.h b/clang/lib/Headers/prfchwintrin.h
index eaea5f3cf8febf..8ec55d7073716f 100644
--- a/clang/lib/Headers/prfchwintrin.h
+++ b/clang/lib/Headers/prfchwintrin.h
@@ -14,6 +14,10 @@
 #ifndef __PRFCHWINTRIN_H
 #define __PRFCHWINTRIN_H
 
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
 /// Loads a memory sequence containing the specified memory address into
 ///all data cache levels.
 ///
@@ -26,11 +30,7 @@
 ///
 /// \param __P
 ///A pointer specifying the memory address to be prefetched.
-static __inline__ void __attribute__((__always_inline__, __nodebug__))
-_m_prefetch(void *__P)
-{
-  __builtin_prefetch (__P, 0, 3 /* _MM_HINT_T0 */);
-}
+void _m_prefetch(void *__P);
 
 /// Loads a memory sequence containing the specified memory address into
 ///the L1 data cache and sets the cache-coherency state to modified.
@@ -48,13 +48,10 @@ _m_prefetch(void *__P)
 ///
 /// \param __P
 ///A pointer specifying the memory address to be prefetched.
-static __inline__ void __attribute__((__always_inline__, __nodebug__))
-_m_prefetchw(volatile const void *__P)
-{
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wcast-qual"
-  __builtin_prefetch ((const void*)__P, 1, 3 /* _MM_HINT_T0 */);
-#pragma clang diagnostic pop
-}
+void _m_prefetchw(volatile const void *__P);
+
+#if defined(__cplusplus)
+} // extern "C"
+#endif
 
 #endif /* __PRFCHWINTRIN_H */

>From 80e6138ccc1e970d12c86be937562a2ac96e8685 Mon Sep 17 00:00:00 2001
From: Reid Kleckner 
Date: Wed, 6 Nov 2024 00:45:51 +
Subject: [PATCH 2/6] format

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

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 0224238d976193..ce3b9f1d99c947 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -15258,7 +15258,8 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned 
BuiltinID,
   case X86::BI_m_prefetchw: {
 Value *Address = Ops[0];
 // The 'w' suffix implies write.
-Value *RW = ConstantInt::get(Int32Ty, BuiltinID == X86::BI_m_prefetchw ? 1 
: 0);
+Value *RW =
+ConstantInt::get(Int32Ty, BuiltinID == X86::BI_m_prefetchw ? 1 : 0);
 Value *Locality = ConstantInt::get(Int32Ty, 0x3);
 Value *Data = ConstantInt::get(Int32Ty, 1);
 Function *F = CGM.getIntrinsic(Intrinsic::prefetch, Address->getType());


[clang] [Serialization] Migrate away from PointerUnion::dyn_cast (NFC) (#124884) (PR #125024)

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`openmp-offload-libc-amdgpu-runtime` running on `omp-vega20-1` while building 
`clang` at step 6 "test-openmp".

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


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

```
Step 6 (test-openmp) failure: test (failure)
 TEST 'libomp :: tasking/issue-94260-2.c' FAILED 

Exit Code: -11

Command Output (stdout):
--
# RUN: at line 1
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/clang 
-fopenmp   -I 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -I 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/openmp/runtime/test
 -L 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
  -fno-omit-frame-pointer -I 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/openmp/runtime/test/ompt
 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/openmp/runtime/test/tasking/issue-94260-2.c
 -o 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
 -lm -latomic && 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
# executed command: 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/./bin/clang 
-fopenmp -I 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -I 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/openmp/runtime/test
 -L 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -fno-omit-frame-pointer -I 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/openmp/runtime/test/ompt
 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.src/openmp/runtime/test/tasking/issue-94260-2.c
 -o 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
 -lm -latomic
# executed command: 
/home/ompworker/bbot/openmp-offload-libc-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
# note: command had no output on stdout or stderr
# error: command failed with exit status: -11

--




```



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


[clang] [clang][Index] Use HeuristicResolver in libIndex (PR #125153)

2025-01-30 Thread Nathan Ridge via cfe-commits

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

None

>From ddb04e547e312884c63739600829b58c242211b3 Mon Sep 17 00:00:00 2001
From: Nathan Ridge 
Date: Thu, 30 Jan 2025 21:31:12 -0500
Subject: [PATCH] [clang][Index] Use HeuristicResolver in libIndex

---
 clang/lib/Index/CMakeLists.txt  |  1 +
 clang/lib/Index/IndexBody.cpp   | 49 ++---
 clang/lib/Index/IndexingContext.cpp | 12 +++
 clang/lib/Index/IndexingContext.h   | 10 --
 4 files changed, 36 insertions(+), 36 deletions(-)

diff --git a/clang/lib/Index/CMakeLists.txt b/clang/lib/Index/CMakeLists.txt
index b4e294304f1159..f0d2b579c8df67 100644
--- a/clang/lib/Index/CMakeLists.txt
+++ b/clang/lib/Index/CMakeLists.txt
@@ -23,6 +23,7 @@ add_clang_library(clangIndex
   clangFormat
   clangFrontend
   clangLex
+  clangSema
   clangSerialization
   clangToolingCore
 
diff --git a/clang/lib/Index/IndexBody.cpp b/clang/lib/Index/IndexBody.cpp
index c18daf7faa7497..e0ff182f04ad4d 100644
--- a/clang/lib/Index/IndexBody.cpp
+++ b/clang/lib/Index/IndexBody.cpp
@@ -13,6 +13,7 @@
 #include "clang/AST/ExprConcepts.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/Type.h"
+#include "clang/Sema/HeuristicResolver.h"
 
 using namespace clang;
 using namespace clang::index;
@@ -165,51 +166,33 @@ class BodyIndexer : public 
RecursiveASTVisitor {
 Parent, ParentDC, Roles, Relations, E);
   }
 
-  bool indexDependentReference(
-  const Expr *E, const Type *T, const DeclarationNameInfo &NameInfo,
-  llvm::function_ref Filter) {
-if (!T)
-  return true;
-const TemplateSpecializationType *TST =
-T->getAs();
-if (!TST)
-  return true;
-TemplateName TN = TST->getTemplateName();
-const ClassTemplateDecl *TD =
-dyn_cast_or_null(TN.getAsTemplateDecl());
-if (!TD)
-  return true;
-CXXRecordDecl *RD = TD->getTemplatedDecl();
-if (!RD->hasDefinition())
-  return true;
-RD = RD->getDefinition();
-std::vector Symbols =
-RD->lookupDependentName(NameInfo.getName(), Filter);
+  bool indexDependentReference(const Expr *E, SourceLocation Loc,
+   std::vector TargetSymbols) {
 // FIXME: Improve overload handling.
-if (Symbols.size() != 1)
+if (TargetSymbols.size() != 1)
   return true;
-SourceLocation Loc = NameInfo.getLoc();
 if (Loc.isInvalid())
   Loc = E->getBeginLoc();
 SmallVector Relations;
 SymbolRoleSet Roles = getRolesForRef(E, Relations);
-return IndexCtx.handleReference(Symbols[0], Loc, Parent, ParentDC, Roles,
-Relations, E);
+return IndexCtx.handleReference(TargetSymbols[0], Loc, Parent, ParentDC,
+Roles, Relations, E);
   }
 
   bool VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E) {
-const DeclarationNameInfo &Info = E->getMemberNameInfo();
-return indexDependentReference(
-E, E->getBaseType().getTypePtrOrNull(), Info,
-[](const NamedDecl *D) { return D->isCXXInstanceMember(); });
+auto *Resolver = IndexCtx.getResolver();
+if (!Resolver)
+  return true;
+return indexDependentReference(E, E->getMemberNameInfo().getLoc(),
+   Resolver->resolveMemberExpr(E));
   }
 
   bool VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E) {
-const DeclarationNameInfo &Info = E->getNameInfo();
-const NestedNameSpecifier *NNS = E->getQualifier();
-return indexDependentReference(
-E, NNS->getAsType(), Info,
-[](const NamedDecl *D) { return !D->isCXXInstanceMember(); });
+auto *Resolver = IndexCtx.getResolver();
+if (!Resolver)
+  return true;
+return indexDependentReference(E, E->getNameInfo().getLoc(),
+   Resolver->resolveDeclRefExpr(E));
   }
 
   bool VisitDesignatedInitExpr(DesignatedInitExpr *E) {
diff --git a/clang/lib/Index/IndexingContext.cpp 
b/clang/lib/Index/IndexingContext.cpp
index 2dd68dfcc5a708..bdd6c5acf1d34f 100644
--- a/clang/lib/Index/IndexingContext.cpp
+++ b/clang/lib/Index/IndexingContext.cpp
@@ -14,6 +14,7 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Index/IndexDataConsumer.h"
+#include "clang/Sema/HeuristicResolver.h"
 
 using namespace clang;
 using namespace index;
@@ -25,6 +26,17 @@ static bool isGeneratedDecl(const Decl *D) {
   return false;
 }
 
+IndexingContext::IndexingContext(IndexingOptions IndexOpts,
+ IndexDataConsumer &DataConsumer)
+: IndexOpts(IndexOpts), DataConsumer(DataConsumer) {}
+
+IndexingContext::~IndexingContext() = default;
+
+void IndexingContext::setASTContext(ASTContext &ctx) {
+  Ctx = &ctx;
+  Resolver = Ctx ? std::make_unique(*Ctx) : nullptr;
+}
+
 bool IndexingContext::shouldIndex(const Decl *D) {
   return !isGenerat

[clang] [clang-format] Fix mismatched break in BlockIndent (PR #124998)

2025-01-30 Thread Owen Pan via cfe-commits


@@ -349,6 +349,13 @@ bool ContinuationIndenter::canBreak(const LineState 
&State) {
 }
   }
 
+  // Allow breaking before the right parens with block indentation if there was
+  // a break after the left parens, which is tracked by BreakBeforeClosingParen

owenca wrote:

```suggestion
  // a break after the left parens, which is tracked by BreakBeforeClosingParen.
```

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


[clang] [clang-format] Fix mismatched break in BlockIndent (PR #124998)

2025-01-30 Thread Owen Pan via cfe-commits


@@ -9608,6 +9608,10 @@ TEST_F(FormatTest, AlignsAfterOpenBracket) {
   "\"a aaa a aaa a\"\n"
   ");",
   Style);
+  verifyFormat("aaa(\n"
+   "&bbb\n"

owenca wrote:

```suggestion
   "&bb\n"
```
Better still, trim another 20 `b`s and move the test case to the end of the 
unit test.

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


[clang] [clang-format] Fix mismatched break in BlockIndent (PR #124998)

2025-01-30 Thread Owen Pan via cfe-commits

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


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


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

2025-01-30 Thread via cfe-commits

Andarwinux wrote:

Will LLVM 20 miss this?

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


[clang] [clang-format] Add ClassHeadName to help annotating StartOfName (PR #124891)

2025-01-30 Thread Owen Pan via cfe-commits


@@ -1146,6 +1175,8 @@ TEST_F(TokenAnnotatorTest, 
UnderstandsRequiresClausesAndConcepts) {
   EXPECT_TOKEN(Tokens[31], tok::greater, TT_TemplateCloser);
   EXPECT_EQ(Tokens[31]->FakeRParens, 1u);
   EXPECT_TRUE(Tokens[31]->ClosesRequiresClause);
+  // FIXME:
+  // EXPECT_TOKEN(Tokens[33], tok::identifier, TT_Unknown); // Not 
ClassHeadName

owenca wrote:

```suggestion
  // FIXME:
  // EXPECT_TOKEN(Tokens[33], tok::identifier, TT_Unknown); // Not 
TrailingAnnotation
```

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


[clang] [clang-format] Add ClassHeadName to help annotating StartOfName (PR #124891)

2025-01-30 Thread Owen Pan via cfe-commits


@@ -1146,6 +1175,8 @@ TEST_F(TokenAnnotatorTest, 
UnderstandsRequiresClausesAndConcepts) {
   EXPECT_TOKEN(Tokens[31], tok::greater, TT_TemplateCloser);
   EXPECT_EQ(Tokens[31]->FakeRParens, 1u);
   EXPECT_TRUE(Tokens[31]->ClosesRequiresClause);
+  // FIXME:
+  // EXPECT_TOKEN(Tokens[33], tok::identifier, TT_Unknown); // Not 
ClassHeadName

owenca wrote:

Fixed in 4fb80788872e1c1c789fc9a06edd123414a427e6.

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


[clang] [clang-format] Add ClassHeadName to help annotating StartOfName (PR #124891)

2025-01-30 Thread Owen Pan via cfe-commits


@@ -3458,6 +3509,9 @@ TEST_F(TokenAnnotatorTest, BraceKind) {
   Tokens = annotate("a = class Foo extends goog.a {};",
 getGoogleStyle(FormatStyle::LK_JavaScript));
   ASSERT_EQ(Tokens.size(), 12u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::identifier, TT_ClassHeadName);
+  // FIXME:
+  // EXPECT_TOKEN(Tokens[4], tok::identifier, TT_Unknown); // Not StartOfName

owenca wrote:

Fixed in ea84474966f19af4f1f4a1250ec258af1c6e2571.

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


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

2025-01-30 Thread via cfe-commits

h-vetinari wrote:

You'd have to merge and request a backport pretty quickly. Historically 
features could still be argued to land between rc1 (which is imminent) and rc2, 
but the windows is definitely closing fast

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


[clang] [libcxxabi] [llvm] [Clang] Mangling of pack indexing type and expression for itanium (PR #123513)

2025-01-30 Thread Shafik Yaghmour via cfe-commits


@@ -30220,6 +30220,11 @@ const char* cases[][2] = {
 {"_ZZNH3Foo3fooES_iENK4Foo24foo2Ev", "Foo::foo(this Foo, 
int)::Foo2::foo2() const" },
 {"_ZNH3FooclERKS_", "Foo::operator()(this Foo const&)"},
 
+
+// C++26 pack indexing

shafik wrote:

We should add invalid cases as well see `invalid_cases` and make sure we cover 
each case that can return a `nullptr` in `AbstractManglingParser` (I think)

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


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

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

chandlerc wrote:

Given the benefit to binary size and compile time in things like `configure` 
scripts, I'd certainly like to see it land...

Erich already reviewed an earlier version. Maybe @rnk can help with reviews?

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


[clang] [clang-format] Fix mismatched break in BlockIndent (PR #124998)

2025-01-30 Thread Gedare Bloom via cfe-commits

https://github.com/gedare updated 
https://github.com/llvm/llvm-project/pull/124998

>From 69658e8c2beb787b90ea29765bf428892d4e5ec4 Mon Sep 17 00:00:00 2001
From: Gedare Bloom 
Date: Wed, 29 Jan 2025 14:53:10 -0700
Subject: [PATCH 1/2] [clang-format] Fix mismatched break in BlockIndent

Near the ColumnLimit a break could be inserted before a right parens with
BlockIndent without a break after the matching left parens. Avoid these
hanging right parens by disallowing breaks before right parens unless
there was a break after the left parens.

Fixes #103306
---
 clang/lib/Format/ContinuationIndenter.cpp | 7 +++
 clang/unittests/Format/FormatTest.cpp | 4 
 2 files changed, 11 insertions(+)

diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index c311deaa17bb0e..d0a09d305baaf7 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -349,6 +349,13 @@ bool ContinuationIndenter::canBreak(const LineState 
&State) {
 }
   }
 
+  // Allow breaking before the right parens with block indentation if there was
+  // a break after the left parens, which is tracked by BreakBeforeClosingParen
+  if (Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent &&
+  Current.is(tok::r_paren)) {
+return CurrentState.BreakBeforeClosingParen;
+  }
+
   // Don't allow breaking before a closing brace of a block-indented braced 
list
   // initializer if there isn't already a break.
   if (Current.is(tok::r_brace) && Current.MatchingParen &&
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 57f12221cdc7e6..e647c4fff78b0e 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -9608,6 +9608,10 @@ TEST_F(FormatTest, AlignsAfterOpenBracket) {
   "\"a aaa a aaa a\"\n"
   ");",
   Style);
+  verifyFormat("aaa(\n"
+   "&bbb\n"
+   ");",
+   Style);
   Style.ColumnLimit = 60;
   verifyFormat("auto lambda =\n"
"[&b](\n"

>From f83576121f98831ea894076371fc60aaae3d4402 Mon Sep 17 00:00:00 2001
From: Gedare Bloom 
Date: Thu, 30 Jan 2025 19:44:03 -0700
Subject: [PATCH 2/2] Accept suggestions from review

---
 clang/lib/Format/ContinuationIndenter.cpp | 2 +-
 clang/unittests/Format/FormatTest.cpp | 8 
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index d0a09d305baaf7..6f7d213c0b5599 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -350,7 +350,7 @@ bool ContinuationIndenter::canBreak(const LineState &State) 
{
   }
 
   // Allow breaking before the right parens with block indentation if there was
-  // a break after the left parens, which is tracked by BreakBeforeClosingParen
+  // a break after the left parens, which is tracked by 
BreakBeforeClosingParen.
   if (Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent &&
   Current.is(tok::r_paren)) {
 return CurrentState.BreakBeforeClosingParen;
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index e647c4fff78b0e..8bdcfa30f2efb7 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -9608,16 +9608,16 @@ TEST_F(FormatTest, AlignsAfterOpenBracket) {
   "\"a aaa a aaa a\"\n"
   ");",
   Style);
-  verifyFormat("aaa(\n"
-   "&bbb\n"
-   ");",
-   Style);
   Style.ColumnLimit = 60;
   verifyFormat("auto lambda =\n"
"[&b](\n"
"auto a\n"
") {};",
Style);
+  verifyFormat("(\n"
+   "bb\n"
+   ");",
+   Style);
 }
 
 TEST_F(FormatTest, ParenthesesAndOperandAlignment) {

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


[clang] [clang-format] Add ClassHeadName to help annotating StartOfName (PR #124891)

2025-01-30 Thread Owen Pan via cfe-commits

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/124891

>From 04fd96533a48b0f6fdbacb6c9947740bf4c58992 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Tue, 28 Jan 2025 23:16:10 -0800
Subject: [PATCH] [clang-format] Add ClassHeadName to help annotating
 StartOfName

Fixes #124574.
---
 clang/lib/Format/FormatToken.h|  2 +
 clang/lib/Format/TokenAnnotator.cpp   |  2 +-
 clang/lib/Format/UnwrappedLineParser.cpp  | 15 +++--
 clang/unittests/Format/TokenAnnotatorTest.cpp | 57 +++
 4 files changed, 70 insertions(+), 6 deletions(-)

diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index d97b6522f1fefa..29aba281ae1037 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -44,6 +44,8 @@ namespace format {
   TYPE(CaseLabelColon) 
\
   TYPE(CastRParen) 
\
   TYPE(ClassLBrace)
\
+  /* Name of class/struct/union/interface definition. */   
\
+  TYPE(ClassHeadName)  
\
   TYPE(ClassRBrace)
\
   TYPE(CompoundRequirementLBrace)  
\
   /* ternary ?: expression */  
\
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index a172df5291ae62..328fb55e072262 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2580,7 +2580,7 @@ class AnnotatingParser {
 if (Style.isVerilog())
   return false;
 
-if (Tok.isNot(tok::identifier) || !Tok.Previous)
+if (!Tok.Previous || Tok.isNot(tok::identifier) || 
Tok.is(TT_ClassHeadName))
   return false;
 
 if (const auto *NextNonComment = Tok.getNextNonComment();
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 906fc11a07d5ee..77d4afed9ba807 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -4029,7 +4029,7 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
   const FormatToken &InitialToken = *FormatTok;
   nextToken();
 
-  const FormatToken *ClassName = nullptr;
+  FormatToken *ClassName = nullptr;
   bool IsDerived = false;
   auto IsNonMacroIdentifier = [](const FormatToken *Tok) {
 return Tok->is(tok::identifier) && Tok->TokenText != 
Tok->TokenText.upper();
@@ -4059,7 +4059,7 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
 }
 if (FormatTok->is(tok::l_square) && handleCppAttributes())
   continue;
-const auto *Previous = FormatTok;
+auto *Previous = FormatTok;
 nextToken();
 switch (FormatTok->Tok.getKind()) {
 case tok::l_paren:
@@ -4074,9 +4074,12 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
 case tok::hashhash:
   break;
 default:
-  if (!JSPastExtendsOrImplements && !ClassName &&
-  Previous->is(tok::identifier) && Previous->isNot(TT_AttributeMacro) 
&&
-  Previous->TokenText != Previous->TokenText.upper()) {
+  if (JSPastExtendsOrImplements || ClassName ||
+  Previous->isNot(tok::identifier) || Previous->is(TT_AttributeMacro)) 
{
+break;
+  }
+  if (const auto Text = Previous->TokenText;
+  Text.size() == 1 || Text != Text.upper()) {
 ClassName = Previous;
   }
 }
@@ -4160,6 +4163,8 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
   if (FormatTok->is(tok::l_brace)) {
 if (IsListInitialization())
   return;
+if (ClassName)
+  ClassName->setFinalizedType(TT_ClassHeadName);
 auto [OpenBraceType, ClosingBraceType] = GetBraceTypes(InitialToken);
 FormatTok->setFinalizedType(OpenBraceType);
 if (ParseAsExpr) {
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index fc77e277947c56..2d848ac79bddc3 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -479,11 +479,13 @@ TEST_F(TokenAnnotatorTest, UnderstandsUsesOfPlusAndMinus) 
{
 TEST_F(TokenAnnotatorTest, UnderstandsClasses) {
   auto Tokens = annotate("class C {};");
   ASSERT_EQ(Tokens.size(), 6u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::identifier, TT_ClassHeadName);
   EXPECT_TOKEN(Tokens[2], tok::l_brace, TT_ClassLBrace);
   EXPECT_TOKEN(Tokens[3], tok::r_brace, TT_ClassRBrace);
 
   Tokens = annotate("const class C {} c;");
   ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::identifier, TT_ClassHeadName);
   EXPECT_TOKEN(Tokens[3], tok::l_brace, TT_ClassLBrace);
   EXPECT_TOKEN(Tokens[4], tok::r_brace, TT_ClassRBrace);
 
@@ -494,6 +496,7 @@ TEST_F(TokenAnnotatorTe

[clang] [clang-format] Fix mismatched break in BlockIndent (PR #124998)

2025-01-30 Thread Gedare Bloom via cfe-commits

https://github.com/gedare updated 
https://github.com/llvm/llvm-project/pull/124998

>From 69658e8c2beb787b90ea29765bf428892d4e5ec4 Mon Sep 17 00:00:00 2001
From: Gedare Bloom 
Date: Wed, 29 Jan 2025 14:53:10 -0700
Subject: [PATCH 1/3] [clang-format] Fix mismatched break in BlockIndent

Near the ColumnLimit a break could be inserted before a right parens with
BlockIndent without a break after the matching left parens. Avoid these
hanging right parens by disallowing breaks before right parens unless
there was a break after the left parens.

Fixes #103306
---
 clang/lib/Format/ContinuationIndenter.cpp | 7 +++
 clang/unittests/Format/FormatTest.cpp | 4 
 2 files changed, 11 insertions(+)

diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index c311deaa17bb0ea..d0a09d305baaf7f 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -349,6 +349,13 @@ bool ContinuationIndenter::canBreak(const LineState 
&State) {
 }
   }
 
+  // Allow breaking before the right parens with block indentation if there was
+  // a break after the left parens, which is tracked by BreakBeforeClosingParen
+  if (Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent &&
+  Current.is(tok::r_paren)) {
+return CurrentState.BreakBeforeClosingParen;
+  }
+
   // Don't allow breaking before a closing brace of a block-indented braced 
list
   // initializer if there isn't already a break.
   if (Current.is(tok::r_brace) && Current.MatchingParen &&
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 57f12221cdc7e66..e647c4fff78b0e3 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -9608,6 +9608,10 @@ TEST_F(FormatTest, AlignsAfterOpenBracket) {
   "\"a aaa a aaa a\"\n"
   ");",
   Style);
+  verifyFormat("aaa(\n"
+   "&bbb\n"
+   ");",
+   Style);
   Style.ColumnLimit = 60;
   verifyFormat("auto lambda =\n"
"[&b](\n"

>From f83576121f98831ea894076371fc60aaae3d4402 Mon Sep 17 00:00:00 2001
From: Gedare Bloom 
Date: Thu, 30 Jan 2025 19:44:03 -0700
Subject: [PATCH 2/3] Accept suggestions from review

---
 clang/lib/Format/ContinuationIndenter.cpp | 2 +-
 clang/unittests/Format/FormatTest.cpp | 8 
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index d0a09d305baaf7f..6f7d213c0b55996 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -350,7 +350,7 @@ bool ContinuationIndenter::canBreak(const LineState &State) 
{
   }
 
   // Allow breaking before the right parens with block indentation if there was
-  // a break after the left parens, which is tracked by BreakBeforeClosingParen
+  // a break after the left parens, which is tracked by 
BreakBeforeClosingParen.
   if (Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent &&
   Current.is(tok::r_paren)) {
 return CurrentState.BreakBeforeClosingParen;
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index e647c4fff78b0e3..8bdcfa30f2efb73 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -9608,16 +9608,16 @@ TEST_F(FormatTest, AlignsAfterOpenBracket) {
   "\"a aaa a aaa a\"\n"
   ");",
   Style);
-  verifyFormat("aaa(\n"
-   "&bbb\n"
-   ");",
-   Style);
   Style.ColumnLimit = 60;
   verifyFormat("auto lambda =\n"
"[&b](\n"
"auto a\n"
") {};",
Style);
+  verifyFormat("(\n"
+   "bb\n"
+   ");",
+   Style);
 }
 
 TEST_F(FormatTest, ParenthesesAndOperandAlignment) {

>From 0c2c568d4d6d5cc776731fbffbcc7e2613ae1061 Mon Sep 17 00:00:00 2001
From: Gedare Bloom 
Date: Thu, 30 Jan 2025 19:57:39 -0700
Subject: [PATCH 3/3] fix typo in test

---
 clang/unittests/Format/FormatTest.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 8bdcfa30f2efb73..02347e0f15201a1 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -9615,7 +9615,7 @@ TEST_F(FormatTest, AlignsAfterOpenBracket) {
") {};",
Style);
   verifyFormat("(\n"
-   "b

[clang] [Clang] Add GCC's __builtin_stack_address() to Clang. (PR #121332)

2025-01-30 Thread Aaron Ballman via cfe-commits


@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -triple i686-unknown-unknown -emit-llvm -o - %s | FileCheck 
-check-prefix=X86 %s
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s | 
FileCheck -check-prefix=X86_64 %s
+// RUN: %clang_cc1 -triple riscv32-unknown-unknown -emit-llvm -o - %s | 
FileCheck -check-prefix=RISCV_ARM_32 %s
+// RUN: %clang_cc1 -triple riscv64-unknown-unknown -emit-llvm -o - %s | 
FileCheck -check-prefix=RISCV_ARM_64 %s
+// RUN: %clang_cc1 -triple arm-unknown-unknown -emit-llvm -o - %s | FileCheck 
-check-prefix=RISCV_ARM_32 %s
+// RUN: %clang_cc1 -triple arm64-unknown-unknown -emit-llvm -o - %s | 
FileCheck -check-prefix=RISCV_ARM_64 %s
+
+void* a() {
+  // X86_64: [[INT_SP:%.*]] = call i64 @llvm.read_register.i64(metadata 
[[SPREG:![0-9]+]])
+  // X86_64: inttoptr i64 [[INT_SP]]
+  // X86_64: [[SPREG]] = !{!"rsp"}
+  //
+  // X86: [[INT_SP:%.*]] = call i32 @llvm.read_register.i32(metadata 
[[SPREG:![0-9]+]])
+  // X86: inttoptr i32 [[INT_SP]]
+  // X86: [[SPREG]] = !{!"esp"}
+  //
+  // RISCV_ARM_32: [[INT_SP:%.*]] = call i32 @llvm.read_register.i32(metadata 
[[SPREG:![0-9]+]])
+  // RISCV_ARM_32: inttoptr i32 [[INT_SP]]
+  // RISCV_ARM_32: [[SPREG]] = !{!"sp"}
+  //
+  // RISCV_ARM_64: [[INT_SP:%.*]] = call i64 @llvm.read_register.i64(metadata 
[[SPREG:![0-9]+]])
+  // RISCV_ARM_64: inttoptr i64 [[INT_SP]]
+  // RISCV_ARM_64: [[SPREG]] = !{!"sp"}
+  return __builtin_stack_address();

AaronBallman wrote:

We definitely need some tests in `clang/test/Sema` for things like diagnosing 
passing arguments to the function and verifying the function's return type.

But also, we may want codegen tests for more interesting scenarios (member 
functions in C++, lambdas in C++, functions marked with the `leaf` attribute, 
etc).

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


[clang] [Clang] Add GCC's __builtin_stack_address() to Clang. (PR #121332)

2025-01-30 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman commented:

Thank you for this!

Please also be sure to add a release note to `clang/docs/ReleaseNotes.rst` as 
well as document the extension in `clang/docs/LanguageExtensions.rst` so users 
know about the functionality.

Should we be supporting `STACK_ADDRESS_OFFSET` similar to what GCC does?

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


[clang] Fix false negative when value initializing a field annotated with [[clang::require_field_initialization]] (PR #124329)

2025-01-30 Thread via cfe-commits

higher-performance wrote:

> Sorry for the delayed review, this fell off my radar this week! :-/
> 
> Changes LGTM! The release branch did get cut, so this would need to be 
> backported 
> (https://releases.llvm.org/19.1.0/docs/GitHub.html#backporting-fixes-to-the-release-branches).

Ah okay no worries, thanks! So I guess you'll need to merge this into mainline 
and then I can make a PR to backport it?

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


[clang] [StaticAnalyzer] Fix state update in VisitObjCForCollectionStmt (PR #124477)

2025-01-30 Thread Ziqing Luo via cfe-commits


@@ -124,24 +124,26 @@ void ExprEngine::VisitObjCForCollectionStmt(const 
ObjCForCollectionStmt *S,
 
   bool isContainerNull = state->isNull(collectionV).isConstrainedTrue();
 
-  ExplodedNodeSet dstLocation;
-  evalLocation(dstLocation, S, elem, Pred, state, elementV, false);
+  ExplodedNodeSet NewPreds; // evalLocation may alter `Pred`
+  evalLocation(NewPreds, S, elem, Pred, state, elementV, false);
 
-  ExplodedNodeSet Tmp;
-  StmtNodeBuilder Bldr(Pred, Tmp, *currBldrCtx);
+  for (ExplodedNode *Pred : NewPreds) {
+ExplodedNodeSet PredSingleton{Pred}, Tmp;
+StmtNodeBuilder Bldr(Pred, Tmp, *currBldrCtx);
 
-  if (!isContainerNull)
-populateObjCForDestinationSet(dstLocation, svalBuilder, S, elem, elementV,
-  SymMgr, currBldrCtx, Bldr,
-  /*hasElements=*/true);
+if (!isContainerNull)
+  populateObjCForDestinationSet(PredSingleton, svalBuilder, S, elem,
+elementV, SymMgr, currBldrCtx, Bldr,
+/*hasElements=*/true);
 
-  populateObjCForDestinationSet(dstLocation, svalBuilder, S, elem, elementV,
-SymMgr, currBldrCtx, Bldr,
-/*hasElements=*/false);
+populateObjCForDestinationSet(PredSingleton, svalBuilder, S, elem, 
elementV,
+  SymMgr, currBldrCtx, Bldr,
+  /*hasElements=*/false);

ziqingluo-90 wrote:

Can we do this in a separate NFC PR?  I'd like to have this PR merged ASAP 
because it is blocking our CI.

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


[clang] Fix false negative when value initializing a field annotated with [[clang::require_field_initialization]] (PR #124329)

2025-01-30 Thread via cfe-commits

higher-performance wrote:

> this would need to be backported 
> (https://releases.llvm.org/19.1.0/docs/GitHub.html#backporting-fixes-to-the-release-branches).

Oh, @AaronBallman - would you mind adding this as a milestone so I can 
`/cherry-pick` here?

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


[clang] [DependencyScanning] Add ability to scan TU with a buffer input (PR #125111)

2025-01-30 Thread Ben Langmuir via cfe-commits


@@ -0,0 +1,111 @@
+// UNSUPPORTED: target=powerpc64-ibm-aix{{.*}}
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+//--- module.modulemap
+module root { header "root.h" }
+module direct { header "direct.h" }
+module transitive { header "transitive.h" }
+module addition { header "addition.h" }
+//--- root.h
+#include "direct.h"
+#include "root/textual.h"
+//--- direct.h
+#include "transitive.h"
+//--- transitive.h
+// empty
+
+//--- addition.h
+// empty
+
+//--- tu.c
+#include "root.h"
+
+//--- root/textual.h
+// This is here to verify that the "root" directory doesn't clash with name of
+// the "root" module.
+
+//--- cdb.json.template
+[{
+  "file": "",
+  "directory": "DIR",
+  "command": "clang -fmodules -fmodules-cache-path=DIR/cache -I DIR -x c -c"
+}]
+
+// RUN: sed "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+// RUN: clang-scan-deps -compilation-database %t/cdb.json -format 
experimental-full -tu-buffer-path %t/tu.c > %t/result.json
+// RUN: cat %t/result.json | sed 's:\?:/:g' | FileCheck -DPREFIX=%/t %s 
--check-prefix=CHECK
+
+// CHECK:  {
+// CHECK-NEXT:   "modules": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "clang-module-deps": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "context-hash": "{{.*}}",
+// CHECK-NEXT:   "module-name": "transitive"
+// CHECK-NEXT: }
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "clang-modulemap-file": "[[PREFIX]]/module.modulemap",
+// CHECK-NEXT:   "command-line": [
+// CHECK:],
+// CHECK-NEXT:   "context-hash": "{{.*}}",
+// CHECK-NEXT:   "file-deps": [
+// CHECK-NEXT: "[[PREFIX]]/module.modulemap"
+// CHECK-NEXT: "[[PREFIX]]/direct.h"
+// CHECK-NEXT:   ],
+// CHECK:"name": "direct"
+// CHECK-NEXT: },
+// CHECK-NEXT: {
+// CHECK-NEXT:   "clang-module-deps": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "context-hash": "{{.*}}",
+// CHECK-NEXT:   "module-name": "direct"
+// CHECK-NEXT: }
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "clang-modulemap-file": "[[PREFIX]]/module.modulemap",
+// CHECK-NEXT:   "command-line": [
+// CHECK:],
+// CHECK-NEXT:   "context-hash": "{{.*}}",
+// CHECK-NEXT:   "file-deps": [
+// CHECK-NEXT: "[[PREFIX]]/module.modulemap"
+// CHECK-NEXT: "[[PREFIX]]/root.h"
+// CHECK-NEXT: "[[PREFIX]]/root/textual.h"
+// CHECK-NEXT:   ],
+// CHECK:"name": "root"
+// CHECK-NEXT: },
+// CHECK-NEXT: {
+// CHECK-NEXT:   "clang-module-deps": [],
+// CHECK-NEXT:   "clang-modulemap-file": "[[PREFIX]]/module.modulemap",
+// CHECK-NEXT:   "command-line": [
+// CHECK:],
+// CHECK-NEXT:   "context-hash": "{{.*}}",
+// CHECK-NEXT:   "file-deps": [
+// CHECK-NEXT: "[[PREFIX]]/module.modulemap"
+// CHECK-NEXT: "[[PREFIX]]/transitive.h"
+// CHECK-NEXT:   ],
+// CHECK:"name": "transitive"
+// CHECK-NEXT: }
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "translation-units": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "commands": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "clang-context-hash": "{{.*}}",
+// CHECK-NEXT:   "clang-module-deps": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "context-hash": "{{.*}}",
+// CHECK-NEXT:   "module-name": "root"
+// CHECK-NEXT: }
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "command-line": [
+// CHECK:],
+// CHECK:"file-deps": [
+// CHECK-NEXT: [[PREFIX]]/tu.c
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "input-file": ""

benlangmuir wrote:

@Bigcheese does this empty input file seem okay? 

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


[clang] [Clang] Make OpenMP offloading consistently use the bound architecture (PR #125135)

2025-01-30 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 created 
https://github.com/llvm/llvm-project/pull/125135

Summary:
OpenMP was weirdly split between using the bound architecture from
`--offload-arch=` and the old `-march=` option which only worked for
single jobs. This patch removes that special handling. The main benefit
here is that we can now use `getToolchainArgs` without it throwing an
error.

I'm assuming SYCL doesn't care about this because they don't use an
architecture.


>From 010ac5fccbe55b4f3ec139e99cf33de4a752eb00 Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Thu, 30 Jan 2025 17:18:15 -0600
Subject: [PATCH] [Clang] Make OpenMP offloading consistently use the bound
 architecture

Summary:
OpenMP was weirdly split between using the bound architecture from
`--offload-arch=` and the old `-march=` option which only worked for
single jobs. This patch removes that special handling. The main benefit
here is that we can now use `getToolchainArgs` without it throwing an
error.

I'm assuming SYCL doesn't care about this because they don't use an
architecture.
---
 clang/lib/Driver/Driver.cpp   | 45 ++-
 clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp  | 28 +---
 clang/lib/Driver/ToolChains/Cuda.cpp  | 28 
 .../Driver/amdgpu-openmp-system-arch-fail.c   |  4 +-
 clang/test/Driver/amdgpu-openmp-toolchain.c   | 12 ++---
 clang/test/Driver/openmp-offload-gpu.c| 16 +++
 clang/test/Driver/openmp-offload-jit.c|  8 ++--
 clang/test/Driver/openmp-system-arch.c|  8 ++--
 8 files changed, 49 insertions(+), 100 deletions(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 87855fdb799710..fb6e46070afdc2 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4708,23 +4708,7 @@ Driver::getOffloadArchs(Compilation &C, const 
llvm::opt::DerivedArgList &Args,
 return KnownArchs.lookup(TC);
 
   llvm::DenseSet Archs;
-  for (auto *Arg : Args) {
-// Extract any '--[no-]offload-arch' arguments intended for this toolchain.
-std::unique_ptr ExtractedArg = nullptr;
-if (Arg->getOption().matches(options::OPT_Xopenmp_target_EQ) &&
-ToolChain::getOpenMPTriple(Arg->getValue(0)) == TC->getTriple()) {
-  Arg->claim();
-  unsigned Index = Args.getBaseArgs().MakeIndex(Arg->getValue(1));
-  unsigned Prev = Index;
-  ExtractedArg = getOpts().ParseOneArg(Args, Index);
-  if (!ExtractedArg || Index > Prev + 1) {
-TC->getDriver().Diag(diag::err_drv_invalid_Xopenmp_target_with_args)
-<< Arg->getAsString(Args);
-continue;
-  }
-  Arg = ExtractedArg.get();
-}
-
+  for (auto *Arg : C.getArgsForToolChain(TC, /*BoundArch=*/"", Kind)) {
 // Add or remove the seen architectures in order of appearance. If an
 // invalid architecture is given we simply exit.
 if (Arg->getOption().matches(options::OPT_offload_arch_EQ)) {
@@ -4781,14 +4765,31 @@ Driver::getOffloadArchs(Compilation &C, const 
llvm::opt::DerivedArgList &Args,
 return Archs;
 
   if (Archs.empty()) {
-if (Kind == Action::OFK_Cuda)
+if (Kind == Action::OFK_Cuda) {
   Archs.insert(OffloadArchToString(OffloadArch::CudaDefault));
-else if (Kind == Action::OFK_HIP)
+} else if (Kind == Action::OFK_HIP) {
   Archs.insert(OffloadArchToString(OffloadArch::HIPDefault));
-else if (Kind == Action::OFK_OpenMP)
-  Archs.insert(StringRef());
-else if (Kind == Action::OFK_SYCL)
+} else if (Kind == Action::OFK_SYCL) {
   Archs.insert(StringRef());
+} else if (Kind == Action::OFK_OpenMP) {
+  // Accept legacy `-march` device arguments for OpenMP.
+  if (auto *Arg = C.getArgsForToolChain(TC, /*BoundArch=*/"", Kind)
+  .getLastArg(options::OPT_march_EQ)) {
+Archs.insert(Arg->getValue());
+  } else {
+auto ArchsOrErr = TC->getSystemGPUArchs(Args);
+if (!ArchsOrErr) {
+  TC->getDriver().Diag(diag::err_drv_undetermined_gpu_arch)
+  << llvm::Triple::getArchTypeName(TC->getArch())
+  << llvm::toString(ArchsOrErr.takeError()) << "--offload-arch";
+} else if (!ArchsOrErr->empty()) {
+  for (auto Arch : *ArchsOrErr)
+Archs.insert(Args.MakeArgStringRef(Arch));
+} else {
+  Archs.insert(StringRef());
+}
+  }
+}
   } else {
 Args.ClaimAllArgs(options::OPT_offload_arch_EQ);
 Args.ClaimAllArgs(options::OPT_no_offload_arch_EQ);
diff --git a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp 
b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
index 3f0b3f2d86b3ed..f59e8584abbcb9 100644
--- a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
@@ -71,33 +71,9 @@ llvm::opt::DerivedArgList 
*AMDGPUOpenMPToolChain::TranslateArgs(
 
   const OptTable &Opts = getDriver().getOpts();
 
-  if (DeviceOffloadKind == Action::OFK_OpenMP) {
-for (Arg *A : Args)
-  if (!llvm

[clang] [DependencyScanning] Add ability to scan TU with a buffer input (PR #125111)

2025-01-30 Thread Ben Langmuir via cfe-commits


@@ -0,0 +1,111 @@
+// UNSUPPORTED: target=powerpc64-ibm-aix{{.*}}
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+//--- module.modulemap
+module root { header "root.h" }
+module direct { header "direct.h" }
+module transitive { header "transitive.h" }
+module addition { header "addition.h" }
+//--- root.h
+#include "direct.h"
+#include "root/textual.h"
+//--- direct.h
+#include "transitive.h"
+//--- transitive.h
+// empty
+
+//--- addition.h
+// empty
+
+//--- tu.c
+#include "root.h"
+
+//--- root/textual.h
+// This is here to verify that the "root" directory doesn't clash with name of
+// the "root" module.
+
+//--- cdb.json.template
+[{
+  "file": "",
+  "directory": "DIR",
+  "command": "clang -fmodules -fmodules-cache-path=DIR/cache -I DIR -x c -c"
+}]
+
+// RUN: sed "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+// RUN: clang-scan-deps -compilation-database %t/cdb.json -format 
experimental-full -tu-buffer-path %t/tu.c > %t/result.json
+// RUN: cat %t/result.json | sed 's:\?:/:g' | FileCheck -DPREFIX=%/t %s 
--check-prefix=CHECK
+
+// CHECK:  {
+// CHECK-NEXT:   "modules": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "clang-module-deps": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "context-hash": "{{.*}}",
+// CHECK-NEXT:   "module-name": "transitive"
+// CHECK-NEXT: }
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "clang-modulemap-file": "[[PREFIX]]/module.modulemap",
+// CHECK-NEXT:   "command-line": [
+// CHECK:],
+// CHECK-NEXT:   "context-hash": "{{.*}}",
+// CHECK-NEXT:   "file-deps": [
+// CHECK-NEXT: "[[PREFIX]]/module.modulemap"
+// CHECK-NEXT: "[[PREFIX]]/direct.h"
+// CHECK-NEXT:   ],
+// CHECK:"name": "direct"
+// CHECK-NEXT: },
+// CHECK-NEXT: {
+// CHECK-NEXT:   "clang-module-deps": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "context-hash": "{{.*}}",
+// CHECK-NEXT:   "module-name": "direct"
+// CHECK-NEXT: }
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "clang-modulemap-file": "[[PREFIX]]/module.modulemap",
+// CHECK-NEXT:   "command-line": [
+// CHECK:],
+// CHECK-NEXT:   "context-hash": "{{.*}}",
+// CHECK-NEXT:   "file-deps": [
+// CHECK-NEXT: "[[PREFIX]]/module.modulemap"
+// CHECK-NEXT: "[[PREFIX]]/root.h"
+// CHECK-NEXT: "[[PREFIX]]/root/textual.h"
+// CHECK-NEXT:   ],
+// CHECK:"name": "root"
+// CHECK-NEXT: },
+// CHECK-NEXT: {
+// CHECK-NEXT:   "clang-module-deps": [],
+// CHECK-NEXT:   "clang-modulemap-file": "[[PREFIX]]/module.modulemap",
+// CHECK-NEXT:   "command-line": [
+// CHECK:],
+// CHECK-NEXT:   "context-hash": "{{.*}}",
+// CHECK-NEXT:   "file-deps": [
+// CHECK-NEXT: "[[PREFIX]]/module.modulemap"
+// CHECK-NEXT: "[[PREFIX]]/transitive.h"
+// CHECK-NEXT:   ],
+// CHECK:"name": "transitive"
+// CHECK-NEXT: }
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "translation-units": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "commands": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "clang-context-hash": "{{.*}}",
+// CHECK-NEXT:   "clang-module-deps": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "context-hash": "{{.*}}",
+// CHECK-NEXT:   "module-name": "root"
+// CHECK-NEXT: }
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "command-line": [
+// CHECK:],
+// CHECK:"file-deps": [
+// CHECK-NEXT: [[PREFIX]]/tu.c

benlangmuir wrote:

How does tu.c become a file dep?

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


[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-30 Thread Matheus Izvekov via cfe-commits


@@ -11714,27 +11714,44 @@ static void DiagnoseBadDeduction(Sema &S, NamedDecl 
*Found, Decl *Templated,
 return;
   }
 
-  case TemplateDeductionResult::InvalidExplicitArguments:
+  case TemplateDeductionResult::InvalidExplicitArguments: {
 assert(ParamD && "no parameter found for invalid explicit arguments");
-if (ParamD->getDeclName())
-  S.Diag(Templated->getLocation(),
- diag::note_ovl_candidate_explicit_arg_mismatch_named)
-  << ParamD->getDeclName();
-else {
-  int index = 0;
-  if (TemplateTypeParmDecl *TTP = dyn_cast(ParamD))
-index = TTP->getIndex();
-  else if (NonTypeTemplateParmDecl *NTTP
-  = dyn_cast(ParamD))
-index = NTTP->getIndex();
+int Which = 0;
+int Index = 0;
+TemplateArgument FirstArg = *DeductionFailure.getFirstArg();
+TemplateArgument SecondArg = *DeductionFailure.getSecondArg();
+QualType Type;
+SourceRange SrcRange;
+
+if (auto *TTPD = dyn_cast(ParamD)) {
+  Which = 1;
+  Index = TTPD->getIndex();
+  SrcRange = TTPD->getSourceRange();
+} else if (auto *NTTPD = dyn_cast(ParamD)) {
+  if (SecondArg.isNull())
+Which = 2;

mizvekov wrote:

An immediately invoked lambda + decomposition might be cleaner, but it's up to 
you:

```suggestion
  auto [Which, Index, Type, SrcRange] = [] -> std::tuple {
switch(ParamD->getKind()) {
case Decl::TemplateTypeParm: {
  auto *TTPD = cast(ParamD);
  return {1, TTPD->getIndex(), QualType(), TTPD->getSourceRange()};
}
case Decl::NonTypeTemplateParm: {
   ...
}
...
}
llvm_unreachable("unexpected param decl kind");
  }();
```

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


  1   2   3   4   5   >