[clang] [webkit.RefCntblBaseVirtualDtor] ThreadSafeRefCounted still generates warnings (PR #108656)

2024-09-17 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`openmp-offload-amdgpu-runtime` running on `omp-vega20-0` while building 
`clang` at step 7 "Add check check-offload".

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


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

```
Step 7 (Add check check-offload) failure: test (failure)
 TEST 'libomptarget :: amdgcn-amd-amdhsa :: 
sanitizer/kernel_crash_async.c' FAILED 
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 2
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/clang 
-fopenmp-I 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test -I 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -L 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload
 -L /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib -L 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
  -nogpulib 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload
 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib 
 -fopenmp-targets=amdgcn-amd-amdhsa -O3 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/sanitizer/kernel_crash_async.c
 -o 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/sanitizer/Output/kernel_crash_async.c.tmp
 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib/libomptarget.devicertl.a
# executed command: 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/clang 
-fopenmp -I 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test -I 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -L 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload
 -L /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib -L 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -nogpulib 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload
 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib 
-fopenmp-targets=amdgcn-amd-amdhsa -O3 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/sanitizer/kernel_crash_async.c
 -o 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/sanitizer/Output/kernel_crash_async.c.tmp
 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib/libomptarget.devicertl.a
# note: command had no output on stdout or stderr
# RUN: at line 3
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/not --crash 
env -u LLVM_DISABLE_SYMBOLIZATION OFFLOAD_TRACK_NUM_KERNEL_LAUNCH_TRACES=1 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/sanitizer/Output/kernel_crash_async.c.tmp
 2>&1 | 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/FileCheck 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/sanitizer/kernel_crash_async.c
 --check-prefixes=TRACE
# executed command: 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/not --crash 
env -u LLVM_DISABLE_SYMBOLIZATION OFFLOAD_TRACK_NUM_KERNEL_LAUNCH_TRACES=1 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/sanitizer/Output/kernel_crash_async.c.tmp
# note: command had no output on stdout or stderr
# executed command: 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/FileCheck 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/sanitizer/kernel_crash_async.c
 --check-prefixes=TRACE
# note: command had no output on stdout or stderr
# RUN: at line 4
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/not --crash 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/sanitizer/Output/kernel_crash_async.c.tmp
 2>&1 | 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/FileCheck 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/sanitizer/kernel_crash_async.c
 --check-prefixes=CHECK
# executed command: 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/not --crash 
/home/ompworker/bbot/op

[clang] [clang] check deduction consistency when partial ordering function templates (PR #100692)

2024-09-17 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

Regarding test case 2, that further reduces to:
```C++
template  class Q {};

template  void F(Q);
template  void F(Q) = delete;

void test() {
  F(Q());
}
```

The problem is that we consider the parenthesized expression significant in 
terms of forming a distinct type.
You can see the problem goes away if you remove that parenthesis in the default 
argument for Q.

I believe the parenthesis should not be significant in this case, and there is 
also some divergence between GCC and Clang in this area.
I am asking the core reflector for clarification here.

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


[clang] fd21b79 - [webkit.RefCntblBaseVirtualDtor] ThreadSafeRefCounted still generates warnings (#108656)

2024-09-17 Thread via cfe-commits

Author: Ryosuke Niwa
Date: 2024-09-17T22:23:27-07:00
New Revision: fd21b7911fbdddc80db2d3971ff10ee70a49b7e3

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

LOG: [webkit.RefCntblBaseVirtualDtor] ThreadSafeRefCounted still generates 
warnings (#108656)

Improve the fix in 203a2ca8cd6af505e11a38aebceeaf864271042c by allowing
variable references and more ignoring of parentheses.

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
clang/test/Analysis/Checkers/WebKit/ref-cntbl-crtp-base-no-virtual-dtor.cpp

Removed: 




diff  --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
index ecba5f9aa23ee3..e80246f49a3100 100644
--- 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
+++ 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp
@@ -72,7 +72,7 @@ class DerefFuncDeleteExprVisitor
   if (name == "ensureOnMainThread" || name == "ensureOnMainRunLoop") {
 for (unsigned i = 0; i < CE->getNumArgs(); ++i) {
   auto *Arg = CE->getArg(i);
-  if (VisitLabmdaArgument(Arg))
+  if (VisitLambdaArgument(Arg))
 return true;
 }
   }
@@ -80,17 +80,24 @@ class DerefFuncDeleteExprVisitor
 return false;
   }
 
-  bool VisitLabmdaArgument(const Expr *E) {
+  bool VisitLambdaArgument(const Expr *E) {
 E = E->IgnoreParenCasts();
 if (auto *TempE = dyn_cast(E))
   E = TempE->getSubExpr();
+E = E->IgnoreParenCasts();
+if (auto *Ref = dyn_cast(E)) {
+  if (auto *VD = dyn_cast_or_null(Ref->getDecl()))
+return VisitLambdaArgument(VD->getInit());
+  return false;
+}
+if (auto *Lambda = dyn_cast(E)) {
+  if (VisitBody(Lambda->getBody()))
+return true;
+}
 if (auto *ConstructE = dyn_cast(E)) {
   for (unsigned i = 0; i < ConstructE->getNumArgs(); ++i) {
-auto *Arg = ConstructE->getArg(i);
-if (auto *Lambda = dyn_cast(Arg)) {
-  if (VisitBody(Lambda->getBody()))
-return true;
-}
+if (VisitLambdaArgument(ConstructE->getArg(i)))
+  return true;
   }
 }
 return false;

diff  --git 
a/clang/test/Analysis/Checkers/WebKit/ref-cntbl-crtp-base-no-virtual-dtor.cpp 
b/clang/test/Analysis/Checkers/WebKit/ref-cntbl-crtp-base-no-virtual-dtor.cpp
index 01527addb52992..33c60ea8ca64d1 100644
--- 
a/clang/test/Analysis/Checkers/WebKit/ref-cntbl-crtp-base-no-virtual-dtor.cpp
+++ 
b/clang/test/Analysis/Checkers/WebKit/ref-cntbl-crtp-base-no-virtual-dtor.cpp
@@ -119,6 +119,11 @@ template
 ensureOnMainThread([this] {
 delete static_cast(this);
 });
+} else if constexpr (destructionThread == 
DestructionThread::MainRunLoop) {
+auto deleteThis = [this] {
+delete static_cast(this);
+};
+ensureOnMainThread(deleteThis);
 }
 }
 
@@ -230,3 +235,16 @@ class FancyRefCountedClass4 final : public 
BadNestedThreadSafeRefCounted {
+public:
+static Ref create()
+{
+return adoptRef(*new FancyRefCountedClass5());
+}
+
+virtual ~FancyRefCountedClass5();
+
+private:
+FancyRefCountedClass5();
+};



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


[clang] [webkit.RefCntblBaseVirtualDtor] ThreadSafeRefCounted still generates warnings (PR #108656)

2024-09-17 Thread Ryosuke Niwa via cfe-commits

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


[clang] Fix evaluation of the unsigned enumeration values, #108766 (PR #108769)

2024-09-17 Thread Dmitry Fursov via cfe-commits

fursov wrote:

@DeinAlptraum, thank you for the review. The findings are fixed now.
Could you say if the fix to be backported to other relelases, like 18.x or 
19rc? If yes, how this is done?

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


[clang] [HLSL][NFC] Remove RegisterBindingFlags struct (PR #108924)

2024-09-17 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/108924

>From 1dd552dfb6217804ba5e84a35e59e348622df581 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Mon, 16 Sep 2024 20:54:23 -0700
Subject: [PATCH 1/5] [HLSL][NFC] Remove RegisterBindingFlags struct

When diagnosing register bindings we just need to make sure there is
a resource that matches the provided register type. We can emit the
diagnostics right away instead of collecting flags in the
RegisterBindingFlags struct. That also enables early exit when scanning
user defined types because we can return as soon as we find a matching
resource for the given register type.
---
 clang/lib/Sema/SemaHLSL.cpp | 283 +---
 1 file changed, 101 insertions(+), 182 deletions(-)

diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 26de9a986257c5..9cc1860e52bd2c 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -41,6 +41,47 @@
 
 using namespace clang;
 
+enum class RegisterType { SRV, UAV, CBuffer, Sampler, C, I, Invalid };
+
+static RegisterType getRegisterType(llvm::dxil::ResourceClass RC) {
+  switch (RC) {
+  case llvm::dxil::ResourceClass::SRV:
+return RegisterType::SRV;
+  case llvm::dxil::ResourceClass::UAV:
+return RegisterType::UAV;
+  case llvm::dxil::ResourceClass::CBuffer:
+return RegisterType::CBuffer;
+  case llvm::dxil::ResourceClass::Sampler:
+return RegisterType::Sampler;
+  }
+  llvm_unreachable("unexpected ResourceClass value");
+}
+
+static RegisterType getRegisterType(StringRef Slot) {
+  switch (Slot[0]) {
+  case 't':
+  case 'T':
+return RegisterType::SRV;
+  case 'u':
+  case 'U':
+return RegisterType::UAV;
+  case 'b':
+  case 'B':
+return RegisterType::CBuffer;
+  case 's':
+  case 'S':
+return RegisterType::Sampler;
+  case 'c':
+  case 'C':
+return RegisterType::C;
+  case 'i':
+  case 'I':
+return RegisterType::I;
+  default:
+return RegisterType::Invalid;
+  }
+}
+
 SemaHLSL::SemaHLSL(Sema &S) : SemaBase(S) {}
 
 Decl *SemaHLSL::ActOnStartBuffer(Scope *BufferScope, bool CBuffer,
@@ -739,28 +780,6 @@ SemaHLSL::TakeLocForHLSLAttribute(const 
HLSLAttributedResourceType *RT) {
   return LocInfo;
 }
 
-struct RegisterBindingFlags {
-  bool Resource = false;
-  bool UDT = false;
-  bool Other = false;
-  bool Basic = false;
-
-  bool SRV = false;
-  bool UAV = false;
-  bool CBV = false;
-  bool Sampler = false;
-
-  bool ContainsNumeric = false;
-  bool DefaultGlobals = false;
-
-  // used only when Resource == true
-  std::optional ResourceClass;
-};
-
-static bool isDeclaredWithinCOrTBuffer(const Decl *TheDecl) {
-  return TheDecl && isa(TheDecl->getDeclContext());
-}
-
 // get the record decl from a var decl that we expect
 // represents a resource
 static CXXRecordDecl *getRecordDeclFromVarDecl(VarDecl *VD) {
@@ -775,24 +794,6 @@ static CXXRecordDecl *getRecordDeclFromVarDecl(VarDecl 
*VD) {
   return TheRecordDecl;
 }
 
-static void updateResourceClassFlagsFromDeclResourceClass(
-RegisterBindingFlags &Flags, llvm::hlsl::ResourceClass DeclResourceClass) {
-  switch (DeclResourceClass) {
-  case llvm::hlsl::ResourceClass::SRV:
-Flags.SRV = true;
-break;
-  case llvm::hlsl::ResourceClass::UAV:
-Flags.UAV = true;
-break;
-  case llvm::hlsl::ResourceClass::CBuffer:
-Flags.CBV = true;
-break;
-  case llvm::hlsl::ResourceClass::Sampler:
-Flags.Sampler = true;
-break;
-  }
-}
-
 const HLSLAttributedResourceType *
 findAttributedResourceTypeOnField(VarDecl *VD) {
   assert(VD != nullptr && "expected VarDecl");
@@ -806,8 +807,8 @@ findAttributedResourceTypeOnField(VarDecl *VD) {
   return nullptr;
 }
 
-static void updateResourceClassFlagsFromRecordType(RegisterBindingFlags &Flags,
-   const RecordType *RT) {
+// Iterate over RecordType fields and return true if any of them matched the 
register type
+static bool ContainsResourceForRegisterType(Sema &S, const RecordType *RT, 
RegisterType RegType) {
   llvm::SmallVector TypesToScan;
   TypesToScan.emplace_back(RT);
 
@@ -816,8 +817,8 @@ static void 
updateResourceClassFlagsFromRecordType(RegisterBindingFlags &Flags,
 while (T->isArrayType())
   T = T->getArrayElementTypeNoTypeQual();
 if (T->isIntegralOrEnumerationType() || T->isFloatingType()) {
-  Flags.ContainsNumeric = true;
-  continue;
+  if (RegType == RegisterType::C)
+return true;
 }
 const RecordType *RT = T->getAs();
 if (!RT)
@@ -828,101 +829,74 @@ static void 
updateResourceClassFlagsFromRecordType(RegisterBindingFlags &Flags,
   const Type *FieldTy = FD->getType().getTypePtr();
   if (const HLSLAttributedResourceType *AttrResType =
   dyn_cast(FieldTy)) {
-updateResourceClassFlagsFromDeclResourceClass(
-Flags, AttrResType->getAttrs().ResourceClass);
+llvm::dxil::ResourceClass RC = AttrResType->getAttrs()

[clang] [clang-tools-extra] [llvm] [Clang] Add __builtin_type_pack_dedup template to deduplicate types in template arguments (PR #106730)

2024-09-17 Thread Matheus Izvekov via cfe-commits


@@ -309,7 +309,10 @@ enum BuiltinTemplateKind : int {
   BTK__make_integer_seq,
 
   /// This names the __type_pack_element BuiltinTemplateDecl.
-  BTK__type_pack_element
+  BTK__type_pack_element,
+
+  /// This names the __type_list_dedup BuiltinTemplateDecl.
+  BTK__type_list_dedup,

mizvekov wrote:

One downside of builtin templates is that they can affect mangling, if we wish 
to support cases where we can't specialize them until dependencies are resolved.

For example, we can't do anything with __make_integer_seq if the count is value 
dependent, which means in order to support that case, we build a canonical TST 
which is named by the builtin template name, and this means 
`__make_integer_seq` will be mangled.

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


[clang] [llvm] Thin4 (PR #109081)

2024-09-17 Thread Kyungwoo Lee via cfe-commits

https://github.com/kyulee-com created 
https://github.com/llvm/llvm-project/pull/109081

None

>From c1a0219457a3c162d7fa6b9d70750ba7a040d9f2 Mon Sep 17 00:00:00 2001
From: Kyungwoo Lee 
Date: Fri, 26 Apr 2024 20:02:52 -0700
Subject: [PATCH 1/3] [ThinLTO][NFC] Prep for two-codegen rounds

---
 clang/lib/CodeGen/BackendUtil.cpp  |  8 ++--
 llvm/include/llvm/LTO/LTOBackend.h |  1 +
 llvm/lib/LTO/LTO.cpp   | 75 --
 llvm/lib/LTO/LTOBackend.cpp|  6 ++-
 4 files changed, 49 insertions(+), 41 deletions(-)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 7fa69420298160..a1909d45b4d944 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1286,10 +1286,10 @@ static void runThinLTOBackend(
 Conf.CGFileType = getCodeGenFileType(Action);
 break;
   }
-  if (Error E =
-  thinBackend(Conf, -1, AddStream, *M, *CombinedIndex, ImportList,
-  ModuleToDefinedGVSummaries[M->getModuleIdentifier()],
-  /* ModuleMap */ nullptr, CGOpts.CmdArgs)) {
+  if (Error E = thinBackend(
+  Conf, -1, AddStream, *M, *CombinedIndex, ImportList,
+  ModuleToDefinedGVSummaries[M->getModuleIdentifier()],
+  /* ModuleMap */ nullptr, Conf.CodeGenOnly, CGOpts.CmdArgs)) {
 handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) {
   errs() << "Error running ThinLTO backend: " << EIB.message() << '\n';
 });
diff --git a/llvm/include/llvm/LTO/LTOBackend.h 
b/llvm/include/llvm/LTO/LTOBackend.h
index de89f4bb10dff2..8516398510d4b8 100644
--- a/llvm/include/llvm/LTO/LTOBackend.h
+++ b/llvm/include/llvm/LTO/LTOBackend.h
@@ -56,6 +56,7 @@ Error thinBackend(const Config &C, unsigned Task, AddStreamFn 
AddStream,
   const FunctionImporter::ImportMapTy &ImportList,
   const GVSummaryMapTy &DefinedGlobals,
   MapVector *ModuleMap,
+  bool CodeGenOnly,
   const std::vector &CmdArgs = 
std::vector());
 
 Error finalizeOptimizationRemarks(
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp
index a88124dacfaefd..f4c25f80811a85 100644
--- a/llvm/lib/LTO/LTO.cpp
+++ b/llvm/lib/LTO/LTO.cpp
@@ -1473,7 +1473,8 @@ class InProcessThinBackend : public ThinBackendProc {
 return MOrErr.takeError();
 
   return thinBackend(Conf, Task, AddStream, **MOrErr, CombinedIndex,
- ImportList, DefinedGlobals, &ModuleMap);
+ ImportList, DefinedGlobals, &ModuleMap,
+ Conf.CodeGenOnly);
 };
 
 auto ModuleID = BM.getModuleIdentifier();
@@ -1839,45 +1840,49 @@ Error LTO::runThinLTO(AddStreamFn AddStream, FileCache 
Cache,
 
   TimeTraceScopeExit.release();
 
-  std::unique_ptr BackendProc =
-  ThinLTO.Backend(Conf, ThinLTO.CombinedIndex, ModuleToDefinedGVSummaries,
-  AddStream, Cache);
-
   auto &ModuleMap =
   ThinLTO.ModulesToCompile ? *ThinLTO.ModulesToCompile : ThinLTO.ModuleMap;
 
-  auto ProcessOneModule = [&](int I) -> Error {
-auto &Mod = *(ModuleMap.begin() + I);
-// Tasks 0 through ParallelCodeGenParallelismLevel-1 are reserved for
-// combined module and parallel code generation partitions.
-return BackendProc->start(RegularLTO.ParallelCodeGenParallelismLevel + I,
-  Mod.second, ImportLists[Mod.first],
-  ExportLists[Mod.first], ResolvedODR[Mod.first],
-  ThinLTO.ModuleMap);
+  auto RunBackends = [&](ThinBackendProc *BackendProcess) -> Error {
+auto ProcessOneModule = [&](int I) -> Error {
+  auto &Mod = *(ModuleMap.begin() + I);
+  // Tasks 0 through ParallelCodeGenParallelismLevel-1 are reserved for
+  // combined module and parallel code generation partitions.
+  return BackendProcess->start(
+  RegularLTO.ParallelCodeGenParallelismLevel + I, Mod.second,
+  ImportLists[Mod.first], ExportLists[Mod.first],
+  ResolvedODR[Mod.first], ThinLTO.ModuleMap);
+};
+
+if (BackendProcess->getThreadCount() == 1) {
+  // Process the modules in the order they were provided on the
+  // command-line. It is important for this codepath to be used for
+  // WriteIndexesThinBackend, to ensure the emitted LinkedObjectsFile lists
+  // ThinLTO objects in the same order as the inputs, which otherwise would
+  // affect the final link order.
+  for (int I = 0, E = ModuleMap.size(); I != E; ++I)
+if (Error E = ProcessOneModule(I))
+  return E;
+} else {
+  // When executing in parallel, process largest bitsize modules first to
+  // improve parallelism, and avoid starving the thread pool near the end.
+  // This saves about 15 sec on a 36-core machine while link `clang.exe`
+  // (out of 100 sec).
+  std::vector ModulesVec;
+  ModulesVec.reserve(ModuleMap.size());
+   

[clang] ddbe6c4 - [clang-format[NFC] Clean up FormatTestBase and Proto/TextProto tests (#108334)

2024-09-17 Thread via cfe-commits

Author: Owen Pan
Date: 2024-09-17T21:15:44-07:00
New Revision: ddbe6c412bab3fe7a3ffaf6f42c49849a518b4c6

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

LOG: [clang-format[NFC] Clean up FormatTestBase and Proto/TextProto tests 
(#108334)

Added: 


Modified: 
clang/unittests/Format/FormatTestBase.h
clang/unittests/Format/FormatTestProto.cpp
clang/unittests/Format/FormatTestTextProto.cpp

Removed: 




diff  --git a/clang/unittests/Format/FormatTestBase.h 
b/clang/unittests/Format/FormatTestBase.h
index 33110ca5d9edfd..9d9472964fd3b4 100644
--- a/clang/unittests/Format/FormatTestBase.h
+++ b/clang/unittests/Format/FormatTestBase.h
@@ -61,23 +61,23 @@ class FormatTestBase : public testing::Test {
 return *Result;
   }
 
-  FormatStyle getStyleWithColumns(FormatStyle Style, unsigned ColumnLimit) {
+  FormatStyle getStyleWithColumns(FormatStyle Style,
+  unsigned ColumnLimit) const {
 Style.ColumnLimit = ColumnLimit;
 return Style;
   }
 
-  FormatStyle getLLVMStyleWithColumns(unsigned ColumnLimit) {
+  FormatStyle getLLVMStyleWithColumns(unsigned ColumnLimit) const {
 return getStyleWithColumns(getLLVMStyle(), ColumnLimit);
   }
 
-  FormatStyle getGoogleStyleWithColumns(unsigned ColumnLimit) {
+  FormatStyle getGoogleStyleWithColumns(unsigned ColumnLimit) const {
 return getStyleWithColumns(getGoogleStyle(), ColumnLimit);
   }
 
-  FormatStyle getTextProtoStyleWithColumns(unsigned ColumnLimit) {
-FormatStyle Style = getGoogleStyle(FormatStyle::FormatStyle::LK_TextProto);
-Style.ColumnLimit = ColumnLimit;
-return Style;
+  FormatStyle getTextProtoStyleWithColumns(unsigned ColumnLimit) const {
+return getStyleWithColumns(getGoogleStyle(FormatStyle::LK_TextProto),
+   ColumnLimit);
   }
 
   bool _verifyFormat(const char *File, int Line, StringRef Expected,

diff  --git a/clang/unittests/Format/FormatTestProto.cpp 
b/clang/unittests/Format/FormatTestProto.cpp
index 5adb532ae4a412..30ce57c545ec76 100644
--- a/clang/unittests/Format/FormatTestProto.cpp
+++ b/clang/unittests/Format/FormatTestProto.cpp
@@ -516,8 +516,6 @@ TEST_F(FormatTestProto, AcceptsOperatorAsKeyInOptions) {
 }
 
 TEST_F(FormatTestProto, BreaksEntriesOfSubmessagesContainingSubmessages) {
-  FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
-  Style.ColumnLimit = 60;
   // The column limit allows for the keys submessage to be put on 1 line, but 
we
   // break it since it contains a submessage an another entry.
   verifyFormat("option (MyProto.options) = {\n"

diff  --git a/clang/unittests/Format/FormatTestTextProto.cpp 
b/clang/unittests/Format/FormatTestTextProto.cpp
index 23f46202a34637..fd65c9a58db5d8 100644
--- a/clang/unittests/Format/FormatTestTextProto.cpp
+++ b/clang/unittests/Format/FormatTestTextProto.cpp
@@ -18,9 +18,7 @@ namespace {
 class FormatTestTextProto : public FormatTestBase {
 protected:
   virtual FormatStyle getDefaultStyle() const override {
-FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
-Style.ColumnLimit = 60; // To make writing tests easier.
-return Style;
+return getTextProtoStyleWithColumns(60);
   }
 };
 
@@ -126,7 +124,8 @@ TEST_F(FormatTestTextProto, 
ImplicitStringLiteralConcatenation) {
" 'b'");
   verifyFormat("field_a: \"a\"\n"
" \"b\"");
-  FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
+
+  auto Style = getDefaultStyle();
   Style.AlwaysBreakBeforeMultilineStrings = true;
   verifyFormat("field_a:\n"
"'a'\n"
@@ -359,46 +358,40 @@ TEST_F(FormatTestTextProto, KeepsCommentsIndentedInList) {
 }
 
 TEST_F(FormatTestTextProto, UnderstandsHashComments) {
-  FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
-  Style.ColumnLimit = 60; // To make writing tests easier.
-  EXPECT_EQ("aaa: 100\n"
-"## this is a double-hash comment.\n"
-"bb: 100\n"
-"## another double-hash comment.\n"
-"### a triple-hash comment\n"
-"cc: 200\n"
-"### another triple-hash comment\n"
-" a quadriple-hash comment\n"
-"dd: 100\n"
-" another quadriple-hash comment",
-format("aaa: 100\n"
-   "##this is a double-hash comment.\n"
-   "bb: 100\n"
-   "## another double-hash comment.\n"
-   "###a triple-hash comment\n"
-   "cc: 200\n"
-   "### another triple-hash comment\n"
-   "a quadriple-hash comment\n"
-   "dd: 100\n"
-   " another quadriple-hash comment",
-   Style));

[clang] [clang-format[NFC] Clean up FormatTestBase and Proto/TextProto tests (PR #108334)

2024-09-17 Thread Owen Pan via cfe-commits

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


[clang] 7153a4b - [clang-format] Reimplement InsertNewlineAtEOF (#108513)

2024-09-17 Thread via cfe-commits

Author: Owen Pan
Date: 2024-09-17T21:16:20-07:00
New Revision: 7153a4bbf6d46e58ce32d59220515c5ab9f35691

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

LOG: [clang-format] Reimplement InsertNewlineAtEOF (#108513)

Fixes #108333.

Added: 


Modified: 
clang/lib/Format/FormatTokenLexer.cpp
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index e21b5a882b7773..63949b2e26bdc1 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -100,6 +100,13 @@ ArrayRef FormatTokenLexer::lex() {
 if (Tokens.back()->NewlinesBefore > 0 || Tokens.back()->IsMultiline)
   FirstInLineIndex = Tokens.size() - 1;
   } while (Tokens.back()->isNot(tok::eof));
+  if (Style.InsertNewlineAtEOF) {
+auto &TokEOF = *Tokens.back();
+if (TokEOF.NewlinesBefore == 0) {
+  TokEOF.NewlinesBefore = 1;
+  TokEOF.OriginalColumn = 0;
+}
+  }
   return Tokens;
 }
 

diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index dfa703aed0d34d..aa0d310a355ff6 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3704,11 +3704,6 @@ void TokenAnnotator::annotate(AnnotatedLine &Line) {
   auto *First = Line.First;
   First->SpacesRequiredBefore = 1;
   First->CanBreakBefore = First->MustBreakBefore;
-
-  if (First->is(tok::eof) && First->NewlinesBefore == 0 &&
-  Style.InsertNewlineAtEOF) {
-First->NewlinesBefore = 1;
-  }
 }
 
 // This function heuristically determines whether 'Current' starts the name of 
a

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 5ebf0d7068dd6c..033daa3645db0d 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -27577,6 +27577,12 @@ TEST_F(FormatTest, InsertNewlineAtEOF) {
 
   verifyNoChange("int i;\n", Style);
   verifyFormat("int i;\n", "int i;", Style);
+
+  constexpr StringRef Code{"namespace {\n"
+   "int i;\n"
+   "} // namespace"};
+  verifyFormat(Code.str() + '\n', Code, Style,
+   {tooling::Range(19, 13)}); // line 3
 }
 
 TEST_F(FormatTest, KeepEmptyLinesAtEOF) {



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


[clang] [clang-tools-extra] [llvm] [Clang] Add __builtin_type_pack_dedup template to deduplicate types in template arguments (PR #106730)

2024-09-17 Thread Matheus Izvekov via cfe-commits

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


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


[clang] [clang-tools-extra] [llvm] [Clang] Add __builtin_type_pack_dedup template to deduplicate types in template arguments (PR #106730)

2024-09-17 Thread Matheus Izvekov via cfe-commits


@@ -3158,6 +3161,33 @@ checkBuiltinTemplateIdType(Sema &SemaRef, 
BuiltinTemplateDecl *BTD,
 int64_t N = Index.getExtValue();
 return Ts.getPackAsArray()[N].getAsType();
   }
+  case BTK__type_pack_dedup: {
+assert(Converted.size() == 2 && "__builtin_type_pack_dedup should be given 
"
+"a template and a parameter pack");
+TemplateArgument Template = Converted[0];
+TemplateArgument Ts = Converted[1];
+if (Template.isDependent() || Ts.isDependent())

mizvekov wrote:

I think the only reason we would need to hold off on building the template 
specialization would be if Ts contains an unexpanded pack, otherwise we are 
good to go, subsequent substitutions will produce the correct type list anyway.

This would also reduce the size of the argument list.

Be aware that holding this specialization will make this builtin appear in 
mangling, so I'd avoid doing that unless necessary.

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


[clang] [PAC] Re-sign a pointer to a noexcept member function when it is converted to a pointer to a member function without noexcept (PR #109056)

2024-09-17 Thread Anton Korobeynikov via cfe-commits

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

This looks good to me, thanks!

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


[clang] [llvm] [CGData][ThinLTO] Global Outlining with Two-CodeGen Rounds (PR #90933)

2024-09-17 Thread Nuri Amari via cfe-commits


@@ -1558,6 +1562,60 @@ class InProcessThinBackend : public ThinBackendProc {
 return BackendThreadPool.getMaxConcurrency();
   }
 };
+
+/// This Backend will run ThinBackend process but throw away all the output 
from
+/// the codegen. This class facilitates the first codegen round.
+class NoOutputThinBackend : public InProcessThinBackend {
+public:
+  NoOutputThinBackend(
+  const Config &Conf, ModuleSummaryIndex &CombinedIndex,
+  ThreadPoolStrategy ThinLTOParallelism,
+  const DenseMap &ModuleToDefinedGVSummaries,
+  std::unique_ptr>> Scratch)
+  : InProcessThinBackend(
+Conf, CombinedIndex, ThinLTOParallelism, 
ModuleToDefinedGVSummaries,
+// Allocate a scratch buffer for each task to write output to.
+[Allocation = &*Scratch](unsigned Task, const Twine &ModuleName) {
+  return std::make_unique(
+  std::make_unique((*Allocation)[Task]));
+},
+FileCache(), nullptr, false, false),

NuriAmari wrote:

Do you mind labelling these arguments with a comment including the name of the 
parameter like you've done below: `/*CodeGenOnly=*/true`. Same with the 
`OptimizedBitcodeThinBackend` constructor.

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


[clang] a8dd8f6 - [clang-format] Fix a bug in SpacesInParens InConditionalStatements (#108797)

2024-09-17 Thread via cfe-commits

Author: Owen Pan
Date: 2024-09-17T21:17:30-07:00
New Revision: a8dd8f6302e5fd405de7ed2bbfe195f305279bf8

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

LOG: [clang-format] Fix a bug in SpacesInParens InConditionalStatements 
(#108797)

Fixes #64416.

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index aa0d310a355ff6..580f183419f78f 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4413,31 +4413,29 @@ bool TokenAnnotator::spaceRequiredBetween(const 
AnnotatedLine &Line,
   Right.MatchingParen == &Left && Line.Children.empty()) {
 return Style.SpaceInEmptyBlock;
   }
-  if ((Left.is(tok::l_paren) && Right.is(tok::r_paren)) ||
-  (Left.is(tok::l_brace) && Left.isNot(BK_Block) &&
-   Right.is(tok::r_brace) && Right.isNot(BK_Block))) {
-return Style.SpacesInParensOptions.InEmptyParentheses;
-  }
-  if (Style.SpacesInParens == FormatStyle::SIPO_Custom &&
-  Style.SpacesInParensOptions.ExceptDoubleParentheses &&
-  Left.is(tok::r_paren) && Right.is(tok::r_paren)) {
-auto *InnerLParen = Left.MatchingParen;
-if (InnerLParen && InnerLParen->Previous == Right.MatchingParen) {
-  InnerLParen->SpacesRequiredBefore = 0;
-  return false;
+  if (Style.SpacesInParens == FormatStyle::SIPO_Custom) {
+if ((Left.is(tok::l_paren) && Right.is(tok::r_paren)) ||
+(Left.is(tok::l_brace) && Left.isNot(BK_Block) &&
+ Right.is(tok::r_brace) && Right.isNot(BK_Block))) {
+  return Style.SpacesInParensOptions.InEmptyParentheses;
+}
+if (Style.SpacesInParensOptions.ExceptDoubleParentheses &&
+Left.is(tok::r_paren) && Right.is(tok::r_paren)) {
+  auto *InnerLParen = Left.MatchingParen;
+  if (InnerLParen && InnerLParen->Previous == Right.MatchingParen) {
+InnerLParen->SpacesRequiredBefore = 0;
+return false;
+  }
 }
-  }
-  if (Style.SpacesInParensOptions.InConditionalStatements) {
 const FormatToken *LeftParen = nullptr;
 if (Left.is(tok::l_paren))
   LeftParen = &Left;
 else if (Right.is(tok::r_paren) && Right.MatchingParen)
   LeftParen = Right.MatchingParen;
-if (LeftParen) {
-  if (LeftParen->is(TT_ConditionLParen))
-return true;
-  if (LeftParen->Previous && isKeywordWithCondition(*LeftParen->Previous))
-return true;
+if (LeftParen && (LeftParen->is(TT_ConditionLParen) ||
+  (LeftParen->Previous &&
+   isKeywordWithCondition(*LeftParen->Previous {
+  return Style.SpacesInParensOptions.InConditionalStatements;
 }
   }
 

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 033daa3645db0d..53aa93a7a4fb01 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -17282,6 +17282,12 @@ TEST_F(FormatTest, ConfigurableSpacesInParens) {
   Spaces.SpacesInParens = FormatStyle::SIPO_Custom;
   Spaces.SpacesInParensOptions = {};
   Spaces.SpacesInParensOptions.Other = true;
+
+  EXPECT_FALSE(Spaces.SpacesInParensOptions.InConditionalStatements);
+  verifyFormat("if (a)\n"
+   "  return;",
+   Spaces);
+
   Spaces.SpacesInParensOptions.InConditionalStatements = true;
   verifyFormat("do_something( ::globalVar );", Spaces);
   verifyFormat("call( x, y, z );", Spaces);



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


[clang] [clang-format] Fix a bug in SpacesInParens InConditionalStatements (PR #108797)

2024-09-17 Thread Owen Pan via cfe-commits

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


[clang] [clang-format] Reimplement InsertNewlineAtEOF (PR #108513)

2024-09-17 Thread Owen Pan via cfe-commits

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


[clang] [clang-format] Handle C-style cast of qualified type (PR #108929)

2024-09-17 Thread Owen Pan via cfe-commits

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


[clang] 4d18ce1 - [clang-format] Handle C-style cast of qualified type (#108929)

2024-09-17 Thread via cfe-commits

Author: Owen Pan
Date: 2024-09-17T21:19:56-07:00
New Revision: 4d18ce1dd2640829c3ad9cbb31e6ff92e2e29438

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

LOG: [clang-format] Handle C-style cast of qualified type (#108929)

Fixes #102874.

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 580f183419f78f..6f09835bad3a83 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2840,11 +2840,14 @@ class AnnotatingParser {
 if (AfterRParen->isOneOf(tok::identifier, tok::kw_this))
   return true;
 
-// Look for a cast `( x ) (`.
-if (AfterRParen->is(tok::l_paren) && BeforeRParen->Previous) {
-  if (BeforeRParen->is(tok::identifier) &&
-  BeforeRParen->Previous->is(tok::l_paren)) {
-return true;
+// Look for a cast `( x ) (`, where x may be a qualified identifier.
+if (AfterRParen->is(tok::l_paren)) {
+  for (const auto *Prev = BeforeRParen; Prev->is(tok::identifier);) {
+Prev = Prev->Previous;
+if (Prev->is(tok::coloncolon))
+  Prev = Prev->Previous;
+if (Prev == LParen)
+  return true;
   }
 }
 

diff  --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index baa5ab0ac5e456..34c03d668a9a0a 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -781,6 +781,14 @@ TEST_F(TokenAnnotatorTest, UnderstandsCasts) {
   EXPECT_TOKEN(Tokens[9], tok::r_paren, TT_Unknown);
   EXPECT_TOKEN(Tokens[10], tok::minus, TT_BinaryOperator);
 
+  Tokens = annotate("return (::Type)(1 + 2);");
+  ASSERT_EQ(Tokens.size(), 12u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::r_paren, TT_CastRParen);
+
+  Tokens = annotate("return (Namespace::Class)(1 + 2);");
+  ASSERT_EQ(Tokens.size(), 13u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::r_paren, TT_CastRParen);
+
   auto Style = getLLVMStyle();
   Style.TypeNames.push_back("Foo");
   Tokens = annotate("#define FOO(bar) foo((Foo)&bar)", Style);



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


[clang] [llvm] [CGData][ThinLTO] Global Outlining with Two-CodeGen Rounds (PR #90933)

2024-09-17 Thread Nuri Amari via cfe-commits


@@ -1558,6 +1562,60 @@ class InProcessThinBackend : public ThinBackendProc {
 return BackendThreadPool.getMaxConcurrency();
   }
 };
+
+/// This Backend will run ThinBackend process but throw away all the output 
from
+/// the codegen. This class facilitates the first codegen round.
+class NoOutputThinBackend : public InProcessThinBackend {

NuriAmari wrote:

If I'm following correctly, it's not as if this backend really throws results 
away, but it writes the produced object files into the scratch buffer rather 
than to files. It also writes the optimized bitcode files to disk right?

I don't have a strong opinion, but maybe we could name the backend / adjust the 
comment to reflect this. I wouldn't even be opposed to naming the backends 
something specific to two-codegen rounds, as I don't see anyone using them for 
other purposes.

Lastly just an idea:  We could just hold the optimized bitcode in a similar 
buffer in memory, rather than writing them to disk and reading them again 
between rounds. Might run a bit faster.

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


[clang] [analyzer] Indicate UnarySymExpr is not supported by Z3 (PR #108900)

2024-09-17 Thread Mikael Holmén via cfe-commits


@@ -278,6 +278,13 @@ class SMTConstraintManager : public 
clang::ento::SimpleConstraintManager {
 if (const SymbolCast *SC = dyn_cast(Sym))
   return canReasonAbout(SVB.makeSymbolVal(SC->getOperand()));
 
+// If a UnarySymExpr is encountered, the Z3
+// wrapper does not support those. So indicate Z3 does not
+// support those and return.
+if (dyn_cast(Sym)) {

mikaelholmen wrote:

You can use "isa" here instead of dyn_cast since we're not really using the 
casted value anyway.

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


[clang] [llvm] Thin4 (PR #109081)

2024-09-17 Thread Kyungwoo Lee via cfe-commits

https://github.com/kyulee-com updated 
https://github.com/llvm/llvm-project/pull/109081

>From c1a0219457a3c162d7fa6b9d70750ba7a040d9f2 Mon Sep 17 00:00:00 2001
From: Kyungwoo Lee 
Date: Fri, 26 Apr 2024 20:02:52 -0700
Subject: [PATCH 1/4] [ThinLTO][NFC] Prep for two-codegen rounds

---
 clang/lib/CodeGen/BackendUtil.cpp  |  8 ++--
 llvm/include/llvm/LTO/LTOBackend.h |  1 +
 llvm/lib/LTO/LTO.cpp   | 75 --
 llvm/lib/LTO/LTOBackend.cpp|  6 ++-
 4 files changed, 49 insertions(+), 41 deletions(-)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 7fa69420298160..a1909d45b4d944 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1286,10 +1286,10 @@ static void runThinLTOBackend(
 Conf.CGFileType = getCodeGenFileType(Action);
 break;
   }
-  if (Error E =
-  thinBackend(Conf, -1, AddStream, *M, *CombinedIndex, ImportList,
-  ModuleToDefinedGVSummaries[M->getModuleIdentifier()],
-  /* ModuleMap */ nullptr, CGOpts.CmdArgs)) {
+  if (Error E = thinBackend(
+  Conf, -1, AddStream, *M, *CombinedIndex, ImportList,
+  ModuleToDefinedGVSummaries[M->getModuleIdentifier()],
+  /* ModuleMap */ nullptr, Conf.CodeGenOnly, CGOpts.CmdArgs)) {
 handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) {
   errs() << "Error running ThinLTO backend: " << EIB.message() << '\n';
 });
diff --git a/llvm/include/llvm/LTO/LTOBackend.h 
b/llvm/include/llvm/LTO/LTOBackend.h
index de89f4bb10dff2..8516398510d4b8 100644
--- a/llvm/include/llvm/LTO/LTOBackend.h
+++ b/llvm/include/llvm/LTO/LTOBackend.h
@@ -56,6 +56,7 @@ Error thinBackend(const Config &C, unsigned Task, AddStreamFn 
AddStream,
   const FunctionImporter::ImportMapTy &ImportList,
   const GVSummaryMapTy &DefinedGlobals,
   MapVector *ModuleMap,
+  bool CodeGenOnly,
   const std::vector &CmdArgs = 
std::vector());
 
 Error finalizeOptimizationRemarks(
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp
index a88124dacfaefd..f4c25f80811a85 100644
--- a/llvm/lib/LTO/LTO.cpp
+++ b/llvm/lib/LTO/LTO.cpp
@@ -1473,7 +1473,8 @@ class InProcessThinBackend : public ThinBackendProc {
 return MOrErr.takeError();
 
   return thinBackend(Conf, Task, AddStream, **MOrErr, CombinedIndex,
- ImportList, DefinedGlobals, &ModuleMap);
+ ImportList, DefinedGlobals, &ModuleMap,
+ Conf.CodeGenOnly);
 };
 
 auto ModuleID = BM.getModuleIdentifier();
@@ -1839,45 +1840,49 @@ Error LTO::runThinLTO(AddStreamFn AddStream, FileCache 
Cache,
 
   TimeTraceScopeExit.release();
 
-  std::unique_ptr BackendProc =
-  ThinLTO.Backend(Conf, ThinLTO.CombinedIndex, ModuleToDefinedGVSummaries,
-  AddStream, Cache);
-
   auto &ModuleMap =
   ThinLTO.ModulesToCompile ? *ThinLTO.ModulesToCompile : ThinLTO.ModuleMap;
 
-  auto ProcessOneModule = [&](int I) -> Error {
-auto &Mod = *(ModuleMap.begin() + I);
-// Tasks 0 through ParallelCodeGenParallelismLevel-1 are reserved for
-// combined module and parallel code generation partitions.
-return BackendProc->start(RegularLTO.ParallelCodeGenParallelismLevel + I,
-  Mod.second, ImportLists[Mod.first],
-  ExportLists[Mod.first], ResolvedODR[Mod.first],
-  ThinLTO.ModuleMap);
+  auto RunBackends = [&](ThinBackendProc *BackendProcess) -> Error {
+auto ProcessOneModule = [&](int I) -> Error {
+  auto &Mod = *(ModuleMap.begin() + I);
+  // Tasks 0 through ParallelCodeGenParallelismLevel-1 are reserved for
+  // combined module and parallel code generation partitions.
+  return BackendProcess->start(
+  RegularLTO.ParallelCodeGenParallelismLevel + I, Mod.second,
+  ImportLists[Mod.first], ExportLists[Mod.first],
+  ResolvedODR[Mod.first], ThinLTO.ModuleMap);
+};
+
+if (BackendProcess->getThreadCount() == 1) {
+  // Process the modules in the order they were provided on the
+  // command-line. It is important for this codepath to be used for
+  // WriteIndexesThinBackend, to ensure the emitted LinkedObjectsFile lists
+  // ThinLTO objects in the same order as the inputs, which otherwise would
+  // affect the final link order.
+  for (int I = 0, E = ModuleMap.size(); I != E; ++I)
+if (Error E = ProcessOneModule(I))
+  return E;
+} else {
+  // When executing in parallel, process largest bitsize modules first to
+  // improve parallelism, and avoid starving the thread pool near the end.
+  // This saves about 15 sec on a 36-core machine while link `clang.exe`
+  // (out of 100 sec).
+  std::vector ModulesVec;
+  ModulesVec.reserve(ModuleMap.size());
+  for

[clang] [llvm] [CGData][ThinLTO] Global Outlining with Two-CodeGen Rounds (PR #90933)

2024-09-17 Thread Kyungwoo Lee via cfe-commits

https://github.com/kyulee-com updated 
https://github.com/llvm/llvm-project/pull/90933

>From c1a0219457a3c162d7fa6b9d70750ba7a040d9f2 Mon Sep 17 00:00:00 2001
From: Kyungwoo Lee 
Date: Fri, 26 Apr 2024 20:02:52 -0700
Subject: [PATCH 1/4] [ThinLTO][NFC] Prep for two-codegen rounds

---
 clang/lib/CodeGen/BackendUtil.cpp  |  8 ++--
 llvm/include/llvm/LTO/LTOBackend.h |  1 +
 llvm/lib/LTO/LTO.cpp   | 75 --
 llvm/lib/LTO/LTOBackend.cpp|  6 ++-
 4 files changed, 49 insertions(+), 41 deletions(-)

diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 7fa69420298160..a1909d45b4d944 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1286,10 +1286,10 @@ static void runThinLTOBackend(
 Conf.CGFileType = getCodeGenFileType(Action);
 break;
   }
-  if (Error E =
-  thinBackend(Conf, -1, AddStream, *M, *CombinedIndex, ImportList,
-  ModuleToDefinedGVSummaries[M->getModuleIdentifier()],
-  /* ModuleMap */ nullptr, CGOpts.CmdArgs)) {
+  if (Error E = thinBackend(
+  Conf, -1, AddStream, *M, *CombinedIndex, ImportList,
+  ModuleToDefinedGVSummaries[M->getModuleIdentifier()],
+  /* ModuleMap */ nullptr, Conf.CodeGenOnly, CGOpts.CmdArgs)) {
 handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) {
   errs() << "Error running ThinLTO backend: " << EIB.message() << '\n';
 });
diff --git a/llvm/include/llvm/LTO/LTOBackend.h 
b/llvm/include/llvm/LTO/LTOBackend.h
index de89f4bb10dff2..8516398510d4b8 100644
--- a/llvm/include/llvm/LTO/LTOBackend.h
+++ b/llvm/include/llvm/LTO/LTOBackend.h
@@ -56,6 +56,7 @@ Error thinBackend(const Config &C, unsigned Task, AddStreamFn 
AddStream,
   const FunctionImporter::ImportMapTy &ImportList,
   const GVSummaryMapTy &DefinedGlobals,
   MapVector *ModuleMap,
+  bool CodeGenOnly,
   const std::vector &CmdArgs = 
std::vector());
 
 Error finalizeOptimizationRemarks(
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp
index a88124dacfaefd..f4c25f80811a85 100644
--- a/llvm/lib/LTO/LTO.cpp
+++ b/llvm/lib/LTO/LTO.cpp
@@ -1473,7 +1473,8 @@ class InProcessThinBackend : public ThinBackendProc {
 return MOrErr.takeError();
 
   return thinBackend(Conf, Task, AddStream, **MOrErr, CombinedIndex,
- ImportList, DefinedGlobals, &ModuleMap);
+ ImportList, DefinedGlobals, &ModuleMap,
+ Conf.CodeGenOnly);
 };
 
 auto ModuleID = BM.getModuleIdentifier();
@@ -1839,45 +1840,49 @@ Error LTO::runThinLTO(AddStreamFn AddStream, FileCache 
Cache,
 
   TimeTraceScopeExit.release();
 
-  std::unique_ptr BackendProc =
-  ThinLTO.Backend(Conf, ThinLTO.CombinedIndex, ModuleToDefinedGVSummaries,
-  AddStream, Cache);
-
   auto &ModuleMap =
   ThinLTO.ModulesToCompile ? *ThinLTO.ModulesToCompile : ThinLTO.ModuleMap;
 
-  auto ProcessOneModule = [&](int I) -> Error {
-auto &Mod = *(ModuleMap.begin() + I);
-// Tasks 0 through ParallelCodeGenParallelismLevel-1 are reserved for
-// combined module and parallel code generation partitions.
-return BackendProc->start(RegularLTO.ParallelCodeGenParallelismLevel + I,
-  Mod.second, ImportLists[Mod.first],
-  ExportLists[Mod.first], ResolvedODR[Mod.first],
-  ThinLTO.ModuleMap);
+  auto RunBackends = [&](ThinBackendProc *BackendProcess) -> Error {
+auto ProcessOneModule = [&](int I) -> Error {
+  auto &Mod = *(ModuleMap.begin() + I);
+  // Tasks 0 through ParallelCodeGenParallelismLevel-1 are reserved for
+  // combined module and parallel code generation partitions.
+  return BackendProcess->start(
+  RegularLTO.ParallelCodeGenParallelismLevel + I, Mod.second,
+  ImportLists[Mod.first], ExportLists[Mod.first],
+  ResolvedODR[Mod.first], ThinLTO.ModuleMap);
+};
+
+if (BackendProcess->getThreadCount() == 1) {
+  // Process the modules in the order they were provided on the
+  // command-line. It is important for this codepath to be used for
+  // WriteIndexesThinBackend, to ensure the emitted LinkedObjectsFile lists
+  // ThinLTO objects in the same order as the inputs, which otherwise would
+  // affect the final link order.
+  for (int I = 0, E = ModuleMap.size(); I != E; ++I)
+if (Error E = ProcessOneModule(I))
+  return E;
+} else {
+  // When executing in parallel, process largest bitsize modules first to
+  // improve parallelism, and avoid starving the thread pool near the end.
+  // This saves about 15 sec on a 36-core machine while link `clang.exe`
+  // (out of 100 sec).
+  std::vector ModulesVec;
+  ModulesVec.reserve(ModuleMap.size());
+  for 

[clang] [RISCV][FMV] Support target_version (PR #99040)

2024-09-17 Thread Piyou Chen via cfe-commits

https://github.com/BeMg updated https://github.com/llvm/llvm-project/pull/99040

>From 54b5d6833a52271dfd1ca3912d5d9e886b1970c2 Mon Sep 17 00:00:00 2001
From: Piyou Chen 
Date: Tue, 19 Mar 2024 02:02:35 -0700
Subject: [PATCH 1/5] [RISCV][FMV] Support target_version

---
 clang/lib/AST/ASTContext.cpp  |  13 +-
 clang/lib/CodeGen/CodeGenModule.cpp   |   6 +-
 clang/lib/Sema/SemaDecl.cpp   |  43 +-
 clang/lib/Sema/SemaDeclAttr.cpp   |  39 ++
 .../attr-target-version-riscv-invalid.c   |  13 +
 .../test/CodeGen/attr-target-version-riscv.c  | 443 ++
 .../CodeGenCXX/attr-target-version-riscv.cpp  | 432 +
 .../SemaCXX/attr-target-version-riscv.cpp |  53 +++
 8 files changed, 1026 insertions(+), 16 deletions(-)
 create mode 100644 clang/test/CodeGen/attr-target-version-riscv-invalid.c
 create mode 100644 clang/test/CodeGen/attr-target-version-riscv.c
 create mode 100644 clang/test/CodeGenCXX/attr-target-version-riscv.cpp
 create mode 100644 clang/test/SemaCXX/attr-target-version-riscv.cpp

diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 7cc69ca4a8a814..4f20ccd67c9493 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -14270,9 +14270,16 @@ void 
ASTContext::getFunctionFeatureMap(llvm::StringMap &FeatureMap,
   Target->initFeatureMap(FeatureMap, getDiagnostics(), TargetCPU, 
Features);
 }
   } else if (const auto *TV = FD->getAttr()) {
-llvm::SmallVector Feats;
-TV->getFeatures(Feats);
-std::vector Features = getFMVBackendFeaturesFor(Feats);
+std::vector Features;
+if (Target->getTriple().isRISCV()) {
+  ParsedTargetAttr ParsedAttr = Target->parseTargetAttr(TV->getName());
+  Features.insert(Features.begin(), ParsedAttr.Features.begin(),
+  ParsedAttr.Features.end());
+} else {
+  llvm::SmallVector Feats;
+  TV->getFeatures(Feats);
+  Features = getFMVBackendFeaturesFor(Feats);
+}
 Features.insert(Features.begin(),
 Target->getTargetOpts().FeaturesAsWritten.begin(),
 Target->getTargetOpts().FeaturesAsWritten.end());
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index ba2d6588900a11..618b3ac75a9c4a 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4268,8 +4268,12 @@ void CodeGenModule::emitMultiVersionFunctions() {
   } else if (const auto *TVA = CurFD->getAttr()) {
 if (TVA->isDefaultVersion() && IsDefined)
   ShouldEmitResolver = true;
-TVA->getFeatures(Feats);
 llvm::Function *Func = createFunction(CurFD);
+if (getTarget().getTriple().isRISCV()) {
+  Feats.push_back(TVA->getName());
+} else {
+  TVA->getFeatures(Feats);
+}
 Options.emplace_back(Func, /*Architecture*/ "", Feats);
   } else if (const auto *TC = CurFD->getAttr()) {
 if (IsDefined)
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 8557c25b93a8da..b2b2417b47b8d8 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -10319,8 +10319,10 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, 
DeclContext *DC,
   // Handle attributes.
   ProcessDeclAttributes(S, NewFD, D);
   const auto *NewTVA = NewFD->getAttr();
-  if (NewTVA && !NewTVA->isDefaultVersion() &&
-  !Context.getTargetInfo().hasFeature("fmv")) {
+  if (Context.getTargetInfo().getTriple().isRISCV()) {
+// Go thought anyway.
+  } else if (NewTVA && !NewTVA->isDefaultVersion() &&
+ !Context.getTargetInfo().hasFeature("fmv")) {
 // Don't add to scope fmv functions declarations if fmv disabled
 AddToScope = false;
 return NewFD;
@@ -11027,13 +11029,27 @@ static bool CheckMultiVersionValue(Sema &S, const 
FunctionDecl *FD) {
   }
 
   if (TVA) {
-llvm::SmallVector Feats;
-TVA->getFeatures(Feats);
-for (const auto &Feat : Feats) {
-  if (!TargetInfo.validateCpuSupports(Feat)) {
-S.Diag(FD->getLocation(), diag::err_bad_multiversion_option)
-<< Feature << Feat;
-return true;
+if (S.getASTContext().getTargetInfo().getTriple().isRISCV()) {
+  ParsedTargetAttr ParseInfo =
+  S.getASTContext().getTargetInfo().parseTargetAttr(TVA->getName());
+  for (const auto &Feat : ParseInfo.Features) {
+StringRef BareFeat = StringRef{Feat}.substr(1);
+
+if (!TargetInfo.isValidFeatureName(BareFeat)) {
+  S.Diag(FD->getLocation(), diag::err_bad_multiversion_option)
+  << Feature << BareFeat;
+  return true;
+}
+  }
+} else {
+  llvm::SmallVector Feats;
+  TVA->getFeatures(Feats);
+  for (const auto &Feat : Feats) {
+if (!TargetInfo.validateCpuSupports(Feat)) {
+  S.Diag(FD->getLocation(), d

[clang] [llvm] [X86][AVX10.2] Support AVX10.2 MOVZXC new Instructions. (PR #108537)

2024-09-17 Thread via cfe-commits

https://github.com/mahesh-attarde updated 
https://github.com/llvm/llvm-project/pull/108537

>From d06ba3b08ddf7282da9e53705a4ca9b27f0c1c4d Mon Sep 17 00:00:00 2001
From: mattarde 
Date: Fri, 13 Sep 2024 03:26:14 -0700
Subject: [PATCH 1/6] update clr

---
 clang/lib/Headers/CMakeLists.txt  |  1 +
 clang/lib/Headers/avx10_2copyintrin.h | 34 ++
 clang/lib/Headers/immintrin.h |  1 +
 clang/test/CodeGen/X86/avx512copy-builtins.c  | 17 +
 llvm/lib/Target/X86/X86ISelLowering.cpp   |  5 +-
 llvm/lib/Target/X86/X86InstrAVX10.td  | 64 +++
 .../test/CodeGen/X86/avx512copy-intrinsics.ll | 35 ++
 .../MC/Disassembler/X86/avx10.2-copy-32.txt   | 34 ++
 .../MC/Disassembler/X86/avx10.2-copy-64.txt   | 34 ++
 llvm/test/MC/X86/avx10.2-copy-32-att.s| 17 +
 llvm/test/MC/X86/avx10.2-copy-32-intel.s  | 17 +
 llvm/test/MC/X86/avx10.2-copy-64-att.s| 17 +
 llvm/test/MC/X86/avx10.2-copy-64-intel.s  | 17 +
 llvm/test/TableGen/x86-fold-tables.inc|  2 +
 llvm/utils/TableGen/X86ManualInstrMapping.def |  1 +
 15 files changed, 294 insertions(+), 2 deletions(-)
 create mode 100644 clang/lib/Headers/avx10_2copyintrin.h
 create mode 100644 clang/test/CodeGen/X86/avx512copy-builtins.c
 create mode 100644 llvm/test/CodeGen/X86/avx512copy-intrinsics.ll
 create mode 100644 llvm/test/MC/Disassembler/X86/avx10.2-copy-32.txt
 create mode 100644 llvm/test/MC/Disassembler/X86/avx10.2-copy-64.txt
 create mode 100644 llvm/test/MC/X86/avx10.2-copy-32-att.s
 create mode 100644 llvm/test/MC/X86/avx10.2-copy-32-intel.s
 create mode 100644 llvm/test/MC/X86/avx10.2-copy-64-att.s
 create mode 100644 llvm/test/MC/X86/avx10.2-copy-64-intel.s

diff --git a/clang/lib/Headers/CMakeLists.txt b/clang/lib/Headers/CMakeLists.txt
index 4c75c638b41bae..f5cc07c303f9eb 100644
--- a/clang/lib/Headers/CMakeLists.txt
+++ b/clang/lib/Headers/CMakeLists.txt
@@ -156,6 +156,7 @@ set(x86_files
   avx10_2_512satcvtintrin.h
   avx10_2bf16intrin.h
   avx10_2convertintrin.h
+  avx10_2copyintrin.h
   avx10_2minmaxintrin.h
   avx10_2niintrin.h
   avx10_2satcvtdsintrin.h
diff --git a/clang/lib/Headers/avx10_2copyintrin.h 
b/clang/lib/Headers/avx10_2copyintrin.h
new file mode 100644
index 00..13e76c6abe8993
--- /dev/null
+++ b/clang/lib/Headers/avx10_2copyintrin.h
@@ -0,0 +1,34 @@
+/*=== avx10_2copyintrin.h - AVX10.2 Copy intrinsics ---===
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ *===---===
+ */
+#ifndef __IMMINTRIN_H
+#error 
\
+"Never use  directly; include  instead."
+#endif // __IMMINTRIN_H
+
+#ifndef __AVX10_2COPYINTRIN_H
+#define __AVX10_2COPYINTRIN_H
+
+/* Define the default attributes for the functions in this file. */
+#define __DEFAULT_FN_ATTRS128  
\
+  __attribute__((__always_inline__, __nodebug__, __target__("avx10.2-256"),
\
+ __min_vector_width__(128)))
+
+static __inline__ __m128i __DEFAULT_FN_ATTRS128 _mm_move_epi32(__m128i __A) {
+  return (__m128i)__builtin_shufflevector(
+  (__v4si)__A, (__v4si)_mm_setzero_si128(), 0, 4, 4, 4);
+}
+
+static __inline__ __m128i __DEFAULT_FN_ATTRS128 _mm_move_epi16(__m128i __A) {
+  return (__m128i)__builtin_shufflevector(
+  (__v8hi)__A, (__v8hi)_mm_setzero_si128(), 0, 8, 8, 8, 8, 8, 8, 8);
+}
+
+#undef __DEFAULT_FN_ATTRS128
+
+#endif // __AVX10_2COPYINTRIN_H
\ No newline at end of file
diff --git a/clang/lib/Headers/immintrin.h b/clang/lib/Headers/immintrin.h
index 280154f3c1026e..3fbabffa98df20 100644
--- a/clang/lib/Headers/immintrin.h
+++ b/clang/lib/Headers/immintrin.h
@@ -651,6 +651,7 @@ _storebe_i64(void * __P, long long __D) {
 #if !defined(__SCE__) || __has_feature(modules) || defined(__AVX10_2__)
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/clang/test/CodeGen/X86/avx512copy-builtins.c 
b/clang/test/CodeGen/X86/avx512copy-builtins.c
new file mode 100644
index 00..06f7507bde53ed
--- /dev/null
+++ b/clang/test/CodeGen/X86/avx512copy-builtins.c
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 %s -flax-vector-conversions=none -ffreestanding 
-triple=x86_64-unknown-unknown -target-feature +avx10.2-512 \
+// RUN: -emit-llvm -o - -Wall -Werror -pedantic -Wno-gnu-statement-expression 
| FileCheck %s
+
+#include 
+#include 
+
+__m128i test_mm_move_epi32(__m128i A) {
+  // CHECK-LABEL: test_mm_move_epi32
+  // CHECK: shufflevector <4 x i32> %{{.*}}, <4 x i32> %{{.*}}, <4 x i32> 
+  return _mm_move_epi32(A);
+}
+
+__m128i test_mm_move_epi16(__m128i A) {
+  // CHECK-LABEL: test_mm_move_epi16
+  // CHECK: shufflevector <8 x i16> %{{.*}}, <8 

[clang] [RISCV][FMV] Support target_version (PR #99040)

2024-09-17 Thread Piyou Chen via cfe-commits


@@ -11027,13 +11029,27 @@ static bool CheckMultiVersionValue(Sema &S, const 
FunctionDecl *FD) {
   }
 
   if (TVA) {
-llvm::SmallVector Feats;
-TVA->getFeatures(Feats);
-for (const auto &Feat : Feats) {
-  if (!TargetInfo.validateCpuSupports(Feat)) {
-S.Diag(FD->getLocation(), diag::err_bad_multiversion_option)
-<< Feature << Feat;
-return true;
+if (S.getASTContext().getTargetInfo().getTriple().isRISCV()) {

BeMg wrote:

I reduce the part of duplication, and the remain part is causing by different 
syntax between aarch64 and RISC-V.

To reducing the remain part of duplication, we could implement the RISC-V 
syntax inside `clang/include/clang/Basic/Attr.td getFeatures` or make Aarch64 
using the `AArch64TargetInfo::parseTargetAttr` for target_version, or make 
something like `parseTargetVersionAttr` hook here. 

By the way, the parsing of target_clones syntax is controlled by the target. 
(Reference: 
https://github.com/llvm/llvm-project/blob/9cd93774098c861c260090a690f428b7ae031c65/clang/lib/Sema/SemaDeclAttr.cpp#L3121)


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


[clang] [Clang][Sema] Fix templated array size calculation. (PR #96464)

2024-09-17 Thread via cfe-commits

https://github.com/awson updated https://github.com/llvm/llvm-project/pull/96464

>From 096b999120cc28844d780acbc16f8308b3a54160 Mon Sep 17 00:00:00 2001
From: awson 
Date: Mon, 24 Jun 2024 10:34:51 +0300
Subject: [PATCH 1/3] [Clang][Sema] don't handle ArraySize/AllocType early.

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

diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index f3af8dee6b090c..2f79540faea009 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -2174,7 +2174,8 @@ ExprResult Sema::BuildCXXNew(SourceRange Range, bool 
UseGlobal,
 
   // Per C++0x [expr.new]p5, the type being constructed may be a
   // typedef of an array type.
-  if (!ArraySize) {
+  // Dependent case will be handled separately.
+  if (!ArraySize && !AllocType->isDependentType()) {
 if (const ConstantArrayType *Array
   = Context.getAsConstantArrayType(AllocType)) {
   ArraySize = IntegerLiteral::Create(Context, Array->getSize(),

>From 50dbd2c8dce3a70f19ea6f2f22f6f1f9bda84a1e Mon Sep 17 00:00:00 2001
From: awson 
Date: Mon, 24 Jun 2024 11:07:58 +0300
Subject: [PATCH 2/3] [clang][Sema] Tests for GH41441

I've borrowed size-calculation test from PR89036 and added another test, which 
PR89036 fails on.
---
 clang/test/SemaCXX/GH41441.cpp | 46 ++
 1 file changed, 46 insertions(+)
 create mode 100644 clang/test/SemaCXX/GH41441.cpp

diff --git a/clang/test/SemaCXX/GH41441.cpp b/clang/test/SemaCXX/GH41441.cpp
new file mode 100644
index 00..7a6260fef91b56
--- /dev/null
+++ b/clang/test/SemaCXX/GH41441.cpp
@@ -0,0 +1,46 @@
+// RUN: %clang --target=x86_64-pc-linux -S -fno-discard-value-names -emit-llvm 
-o - %s | FileCheck %s
+// RUN: %clang_cc1 %s -fsyntax-only -verify
+
+namespace std {
+  using size_t = decltype(sizeof(int));
+};
+void* operator new[](std::size_t, void*) noexcept;
+
+// CHECK: call void @llvm.memset.p0.i64(ptr align 1 %x, i8 0, i64 8, i1 false)
+// CHECK: call void @llvm.memset.p0.i64(ptr align 16 %x, i8 0, i64 32, i1 
false)
+template 
+void f()
+{
+typedef TYPE TArray[8];
+
+TArray x;
+new(&x) TArray();
+}
+
+template 
+void f1() {
+  int (*x)[1] = new int[1][1];
+}
+template void f1();
+void f2() {
+  int (*x)[1] = new int[1][1];
+}
+
+int main()
+{
+f();
+f();
+}
+
+// expected-no-diagnostics
+template  struct unique_ptr {unique_ptr(T* p){}};
+
+template 
+unique_ptr make_unique(unsigned long long n) {
+  return unique_ptr(new T[n]());
+}
+
+auto boro(int n){
+   typedef double HistoryBuffer[4];
+   return make_unique(n);
+}

>From 81ea2f2233b769e75dc43b37933f78fe8c8f2e7d Mon Sep 17 00:00:00 2001
From: awson 
Date: Tue, 17 Sep 2024 10:22:36 +0300
Subject: [PATCH 3/3] [Clang][Sema] Update release notes on GH41441.

---
 clang/docs/ReleaseNotes.rst | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 69b2aea52aa9d3..6708167bf8b362 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -391,6 +391,7 @@ Bug Fixes to C++ Support
 - Fixed a crash when clang tries to subtitute parameter pack while retaining 
the parameter
   pack. #GH63819, #GH107560
 - Fix a crash when a static assert declaration has an invalid close location. 
(#GH108687)
+- Fix erroneous templated array size calculation leading to crashes in 
generated code. (#GH41441)
 
 Bug Fixes to AST Handling
 ^

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


[clang] [Clang][Sema] Fix templated array size calculation. (PR #96464)

2024-09-17 Thread via cfe-commits

awson wrote:

> It seems reasonable to me, but I want @cor3ntin to review this, he's the one 
> who got his foot stuck in array bounds for a while :D
> 
> However, this patch needs a few changes:
> 
> 1- A better patch title, perhaps improved commit message 2- Release note

1. Partially (patch title) done. After `llvm:main` merge (I've done it to sync 
release notes) "improved commit message" is a bit problematic, I fear.
2. Done.

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


[clang] [llvm] [Utils] Add new --update-tests flag to llvm-lit (PR #108425)

2024-09-17 Thread Nicolai Hähnle via cfe-commits

https://github.com/nhaehnle commented:

Thank you. This pretty much LGTM, but it just occurred to me that there's a 
docs/CommandGuide/lit.rst which should be updated to document the new option.

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


[clang] [llvm] [AMDGPU] Change CF intrinsics lowering to reconverge on predecessors (PR #108596)

2024-09-17 Thread Nicolai Hähnle via cfe-commits

nhaehnle wrote:

Thank you for going into a bit more detail. It does seem like distinguishing 
between SGPR reloads and VGPR reloads would help.

Hmm, what about a case where we run out of VGPRs to spill SGPRs into? What do 
we actually do in that case today?

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


[clang] [clang][bytecode] Fix definining extern variables (PR #108940)

2024-09-17 Thread Timm Baeder via cfe-commits

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

At the point of defintion of the variable, a function might already refert to 
the variable by its index. Replace the index with the new one.

>From db26626c766426d6d848f459d4a243319f9badbe Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Tue, 17 Sep 2024 08:49:55 +0200
Subject: [PATCH] [clang][bytecode] Fix definining extern variables

At the point of defintion of the variable, a function might already
refert to the variable by its index. Replace the index with the new one.
---
 clang/lib/AST/ByteCode/Program.cpp | 11 ++-
 clang/test/AST/ByteCode/extern.cpp | 13 +
 2 files changed, 23 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/AST/ByteCode/extern.cpp

diff --git a/clang/lib/AST/ByteCode/Program.cpp 
b/clang/lib/AST/ByteCode/Program.cpp
index bd5860beabaecd..79c645257306e0 100644
--- a/clang/lib/AST/ByteCode/Program.cpp
+++ b/clang/lib/AST/ByteCode/Program.cpp
@@ -204,9 +204,18 @@ std::optional Program::createGlobal(const 
ValueDecl *VD,
 IsStatic = false;
 IsExtern = true;
   }
+
+  // Register all previous declarations as well. For extern blocks, just 
replace
+  // the index with the new variable.
   if (auto Idx = createGlobal(VD, VD->getType(), IsStatic, IsExtern, Init)) {
-for (const Decl *P = VD; P; P = P->getPreviousDecl())
+for (const Decl *P = VD; P; P = P->getPreviousDecl()) {
+  if (P != VD) {
+unsigned PIdx = GlobalIndices[P];
+if (Globals[PIdx]->block()->isExtern())
+  Globals[PIdx] = Globals[*Idx];
+  }
   GlobalIndices[P] = *Idx;
+}
 return *Idx;
   }
   return std::nullopt;
diff --git a/clang/test/AST/ByteCode/extern.cpp 
b/clang/test/AST/ByteCode/extern.cpp
new file mode 100644
index 00..a616269911a7ec
--- /dev/null
+++ b/clang/test/AST/ByteCode/extern.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter 
-verify=both,expected %s
+// RUN: %clang_cc1 -verify=both,ref %s
+
+
+// both-no-diagnostics
+
+extern const int E;
+constexpr int getE() {
+  return E;
+}
+const int E = 10;
+static_assert(getE() == 10);
+

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


[clang] [llvm] [HLSL] Implement elementwise popcount (PR #108121)

2024-09-17 Thread Simon Pilgrim via cfe-commits

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

LGTM after @farzonl minors have been addressed - once this is committed I'm 
intending to use `__builtin_elementwise_popcount` to simplify a number of C++ 
target intrinsics that do the same thing.

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


[clang] [clang][bytecode] Fix definining extern variables (PR #108940)

2024-09-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

At the point of defintion of the variable, a function might already refert to 
the variable by its index. Replace the index with the new one.

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


2 Files Affected:

- (modified) clang/lib/AST/ByteCode/Program.cpp (+10-1) 
- (added) clang/test/AST/ByteCode/extern.cpp (+13) 


``diff
diff --git a/clang/lib/AST/ByteCode/Program.cpp 
b/clang/lib/AST/ByteCode/Program.cpp
index bd5860beabaecd..79c645257306e0 100644
--- a/clang/lib/AST/ByteCode/Program.cpp
+++ b/clang/lib/AST/ByteCode/Program.cpp
@@ -204,9 +204,18 @@ std::optional Program::createGlobal(const 
ValueDecl *VD,
 IsStatic = false;
 IsExtern = true;
   }
+
+  // Register all previous declarations as well. For extern blocks, just 
replace
+  // the index with the new variable.
   if (auto Idx = createGlobal(VD, VD->getType(), IsStatic, IsExtern, Init)) {
-for (const Decl *P = VD; P; P = P->getPreviousDecl())
+for (const Decl *P = VD; P; P = P->getPreviousDecl()) {
+  if (P != VD) {
+unsigned PIdx = GlobalIndices[P];
+if (Globals[PIdx]->block()->isExtern())
+  Globals[PIdx] = Globals[*Idx];
+  }
   GlobalIndices[P] = *Idx;
+}
 return *Idx;
   }
   return std::nullopt;
diff --git a/clang/test/AST/ByteCode/extern.cpp 
b/clang/test/AST/ByteCode/extern.cpp
new file mode 100644
index 00..a616269911a7ec
--- /dev/null
+++ b/clang/test/AST/ByteCode/extern.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter 
-verify=both,expected %s
+// RUN: %clang_cc1 -verify=both,ref %s
+
+
+// both-no-diagnostics
+
+extern const int E;
+constexpr int getE() {
+  return E;
+}
+const int E = 10;
+static_assert(getE() == 10);
+

``




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


[clang] [clang][bytecode] Fix definining extern variables (PR #108940)

2024-09-17 Thread Timm Baeder via cfe-commits

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

>From bdfe4454f2f2ad0b710b0e9036768d311a77f965 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Tue, 17 Sep 2024 08:49:55 +0200
Subject: [PATCH] [clang][bytecode] Fix defining extern variables

At the point of defintion of the variable, a function might already
refert to the variable by its index. Replace the index with the new one.
---
 clang/lib/AST/ByteCode/Program.cpp | 11 ++-
 clang/test/AST/ByteCode/extern.cpp | 13 +
 2 files changed, 23 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/AST/ByteCode/extern.cpp

diff --git a/clang/lib/AST/ByteCode/Program.cpp 
b/clang/lib/AST/ByteCode/Program.cpp
index bd5860beabaecd..79c645257306e0 100644
--- a/clang/lib/AST/ByteCode/Program.cpp
+++ b/clang/lib/AST/ByteCode/Program.cpp
@@ -204,9 +204,18 @@ std::optional Program::createGlobal(const 
ValueDecl *VD,
 IsStatic = false;
 IsExtern = true;
   }
+
+  // Register all previous declarations as well. For extern blocks, just 
replace
+  // the index with the new variable.
   if (auto Idx = createGlobal(VD, VD->getType(), IsStatic, IsExtern, Init)) {
-for (const Decl *P = VD; P; P = P->getPreviousDecl())
+for (const Decl *P = VD; P; P = P->getPreviousDecl()) {
+  if (P != VD) {
+unsigned PIdx = GlobalIndices[P];
+if (Globals[PIdx]->block()->isExtern())
+  Globals[PIdx] = Globals[*Idx];
+  }
   GlobalIndices[P] = *Idx;
+}
 return *Idx;
   }
   return std::nullopt;
diff --git a/clang/test/AST/ByteCode/extern.cpp 
b/clang/test/AST/ByteCode/extern.cpp
new file mode 100644
index 00..a616269911a7ec
--- /dev/null
+++ b/clang/test/AST/ByteCode/extern.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter 
-verify=both,expected %s
+// RUN: %clang_cc1 -verify=both,ref %s
+
+
+// both-no-diagnostics
+
+extern const int E;
+constexpr int getE() {
+  return E;
+}
+const int E = 10;
+static_assert(getE() == 10);
+

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


[clang] [llvm] [X86][AVX10.2] Support AVX10.2 MOVZXC new Instructions. (PR #108537)

2024-09-17 Thread Phoebe Wang via cfe-commits


@@ -2139,9 +2139,9 @@ define <8 x i16> @pr59628_xmm(i16 %arg) {
 ; X86-LABEL: pr59628_xmm:
 ; X86:   # %bb.0:
 ; X86-NEXT:movzwl {{[0-9]+}}(%esp), %eax
-; X86-NEXT:vxorps %xmm0, %xmm0, %xmm0
+; X86-NEXT:vpxor %xmm0, %xmm0, %xmm0
 ; X86-NEXT:vpbroadcastw %eax, %xmm1
-; X86-NEXT:vmovsh %xmm1, %xmm0, %xmm0
+; X86-NEXT:vpblendw {{.*#+}} xmm0 = xmm1[0],xmm0[1,2,3,4,5,6,7]

phoebewang wrote:

I mean keep `hasFP16` and remove `hasAVX10_2`.

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


[clang-tools-extra] [clang-tidy] Add user-defined functions to `bugprone-unsafe-functions` check (PR #106350)

2024-09-17 Thread via cfe-commits

https://github.com/Discookie updated 
https://github.com/llvm/llvm-project/pull/106350

>From c4e05bdb36e270cbf0557f38fad7c04edf011905 Mon Sep 17 00:00:00 2001
From: Viktor 
Date: Wed, 28 Aug 2024 08:47:20 +
Subject: [PATCH 01/10] [clang-tidy] Add user-defined functions to
 bugprone-unsafe-functions check

---
 .../bugprone/UnsafeFunctionsCheck.cpp | 225 +++---
 .../bugprone/UnsafeFunctionsCheck.h   |  12 +
 .../checks/bugprone/unsafe-functions.rst  |  49 
 .../bugprone/unsafe-functions-custom.c|  38 +++
 .../checkers/bugprone/unsafe-functions.c  |   6 +
 5 files changed, 295 insertions(+), 35 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/unsafe-functions-custom.c

diff --git a/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp
index ea7eaa0b0ff811..05c2063402b080 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp
@@ -7,6 +7,8 @@
 
//===--===//
 
 #include "UnsafeFunctionsCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Lex/PPCallbacks.h"
@@ -18,6 +20,12 @@ using namespace llvm;
 
 namespace clang::tidy::bugprone {
 
+static constexpr llvm::StringLiteral OptionNameCustomNormalFunctions =
+"CustomNormalFunctions";
+static constexpr llvm::StringLiteral OptionNameCustomAnnexKFunctions =
+"CustomAnnexKFunctions";
+static constexpr llvm::StringLiteral OptionNameReportDefaultFunctions =
+"ReportDefaultFunctions";
 static constexpr llvm::StringLiteral OptionNameReportMoreUnsafeFunctions =
 "ReportMoreUnsafeFunctions";
 
@@ -26,6 +34,10 @@ static constexpr llvm::StringLiteral 
FunctionNamesWithAnnexKReplacementId =
 static constexpr llvm::StringLiteral FunctionNamesId = "FunctionsNames";
 static constexpr llvm::StringLiteral AdditionalFunctionNamesId =
 "AdditionalFunctionsNames";
+static constexpr llvm::StringLiteral CustomFunctionNamesId =
+"CustomFunctionNames";
+static constexpr llvm::StringLiteral CustomAnnexKFunctionNamesId =
+"CustomAnnexKFunctionNames";
 static constexpr llvm::StringLiteral DeclRefId = "DRE";
 
 static std::optional
@@ -127,57 +139,155 @@ static bool isAnnexKAvailable(std::optional 
&CacheVar, Preprocessor *PP,
   return CacheVar.value();
 }
 
+static std::vector
+ParseCheckedFunctions(StringRef Option, StringRef OptionName,
+  ClangTidyContext *Context) {
+  std::vector Functions = utils::options::parseStringList(Option);
+  std::vector Result;
+  Result.reserve(Functions.size());
+
+  for (StringRef Function : Functions) {
+if (Function.empty()) {
+  continue;
+}
+
+auto [Name, Rest] = Function.split(',');
+auto [Replacement, Reason] = Rest.split(',');
+
+if (Name.trim().empty()) {
+  Context->configurationDiag("invalid configuration value for option '%0'; 
"
+ "expected the name of an unsafe function")
+  << OptionName;
+}
+
+if (Replacement.trim().empty()) {
+  Context->configurationDiag(
+  "invalid configuration value '%0' for option '%1'; "
+  "expected a replacement function name")
+  << Name.trim() << OptionName;
+}
+
+Result.push_back({Name.trim().str(), llvm::Regex(Name.trim()),
+  Replacement.trim().str(), Reason.trim().str()});
+  }
+
+  return Result;
+}
+
+static std::string SerializeCheckedFunctions(
+const std::vector &Functions) {
+  std::vector Result;
+  Result.reserve(Functions.size());
+
+  for (const auto &Entry : Functions) {
+if (Entry.Reason.empty())
+  Result.push_back(Entry.Name + "," + Entry.Replacement);
+else
+  Result.push_back(Entry.Name + "," + Entry.Replacement + "," +
+   Entry.Reason);
+  }
+
+  return llvm::join(Result, ";");
+}
+
 UnsafeFunctionsCheck::UnsafeFunctionsCheck(StringRef Name,
ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
+  CustomNormalFunctions(ParseCheckedFunctions(
+  Options.get(OptionNameCustomNormalFunctions, ""),
+  OptionNameCustomNormalFunctions, Context)),
+  CustomAnnexKFunctions(ParseCheckedFunctions(
+  Options.get(OptionNameCustomAnnexKFunctions, ""),
+  OptionNameCustomAnnexKFunctions, Context)),
+  ReportDefaultFunctions(
+  Options.get(OptionNameReportDefaultFunctions, true)),
   ReportMoreUnsafeFunctions(
   Options.get(OptionNameReportMoreUnsafeFunctions, true)) {}
 
 void UnsafeFunctionsCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, OptionNameCustomNormalFunctions,
+SerializeChec

[clang-tools-extra] 6357781 - [clang-tidy] fix nullptr dereference in bugprone-forwarding-reference (#106856)

2024-09-17 Thread via cfe-commits

Author: Julian Schmidt
Date: 2024-09-17T10:42:07+02:00
New Revision: 6357781e3f9fbc5a14a794b8769b451c863c65c7

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

LOG: [clang-tidy] fix nullptr dereference in bugprone-forwarding-reference 
(#106856)

Previously, when checking if a `TemplateSpecializationType` is either
`enable_if` or `enable_if_t`, the AST matcher would call
`getTemplateName`, `getASTemplateDecl` and `getTemplatedDecl` in
succession to check the `NamedDecl` returned from `getTemplatedDecl` is
an `std::enable_if[_t]`. In the linked issue, the pointer returned by 
`getTemplatedDecl` is a `nullptr` that is unconditionally accessed, 
resulting in a crash. Instead, the checking is done on the
`TemplateDecl`
returned by `getASTemplateDecl`.

Fixes #106333

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst

clang-tools-extra/test/clang-tidy/checkers/bugprone/forwarding-reference-overload.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp
index c87b3ea7e26163..00e8f7e514368b 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp
@@ -9,7 +9,6 @@
 #include "ForwardingReferenceOverloadCheck.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
-#include 
 
 using namespace clang::ast_matchers;
 
@@ -19,14 +18,14 @@ namespace {
 // Check if the given type is related to std::enable_if.
 AST_MATCHER(QualType, isEnableIf) {
   auto CheckTemplate = [](const TemplateSpecializationType *Spec) {
-if (!Spec || !Spec->getTemplateName().getAsTemplateDecl()) {
+if (!Spec)
   return false;
-}
-const NamedDecl *TypeDecl =
-Spec->getTemplateName().getAsTemplateDecl()->getTemplatedDecl();
-return TypeDecl->isInStdNamespace() &&
-   (TypeDecl->getName() == "enable_if" ||
-TypeDecl->getName() == "enable_if_t");
+
+const TemplateDecl *TDecl = Spec->getTemplateName().getAsTemplateDecl();
+
+return TDecl && TDecl->isInStdNamespace() &&
+   (TDecl->getName() == "enable_if" ||
+TDecl->getName() == "enable_if_t");
   };
   const Type *BaseType = Node.getTypePtr();
   // Case: pointer or reference to enable_if.

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 8d0c093b312dd5..465c333efdf38e 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -111,6 +111,10 @@ Changes in existing checks
   ` check to suggest replacing
   the offending code with ``reinterpret_cast``, to more clearly express intent.
 
+- Improved :doc:`bugprone-forwarding-reference-overload
+  ` check by fixing
+  a crash when determining if an ``enable_if[_t]`` was found.
+
 - Improved :doc:`cert-flp30-c` check to 
   fix false positive that floating point variable is only used in increment
   expression.

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/forwarding-reference-overload.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/forwarding-reference-overload.cpp
index 92dfb718bb51b7..27315199c7ebae 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/forwarding-reference-overload.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/forwarding-reference-overload.cpp
@@ -261,3 +261,9 @@ class Test11 {
   Test11(const Test11 &) = default;
   Test11(Test11 &&) = default;
 };
+
+template  typename T, typename U>
+struct gh106333
+{
+gh106333(U && arg1, T arg2) {}
+};



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


[clang-tools-extra] [clang-tidy] fix nullptr dereference in bugprone-forwarding-reference (PR #106856)

2024-09-17 Thread Julian Schmidt via cfe-commits

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


[clang-tools-extra] 50320ec - [NFC][clang-tidy] reword diagnostic note in definitions-in-headers (#106862)

2024-09-17 Thread via cfe-commits

Author: Julian Schmidt
Date: 2024-09-17T10:42:23+02:00
New Revision: 50320ec967a2c6546e53998225dddb76c4016dc5

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

LOG: [NFC][clang-tidy] reword diagnostic note in definitions-in-headers 
(#106862)

`make as inline` made little sense here, so I changed the `make` to
`mark`
and added `the definition` as well.

Added: 


Modified: 
clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/misc/definitions-in-headers.hpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
index 21008bc144b91a..ee869256898989 100644
--- a/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
@@ -102,7 +102,7 @@ void DefinitionsInHeadersCheck::check(const 
MatchFinder::MatchResult &Result) {
 // inline is not allowed for main function.
 if (FD->isMain())
   return;
-diag(FD->getLocation(), /*Description=*/"make as 'inline'",
+diag(FD->getLocation(), "mark the definition as 'inline'",
  DiagnosticIDs::Note)
 << FixItHint::CreateInsertion(FD->getInnerLocStart(), "inline ");
   } else if (const auto *VD = dyn_cast(ND)) {

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 465c333efdf38e..c297ed88ece0a2 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -124,6 +124,10 @@ Changes in existing checks
   false positive when member initialization depends on a structured binging
   variable.
 
+- Improved :doc:`misc-definitions-in-headers
+  ` check by rewording the
+  diagnostic note that suggests adding ``inline``.
+
 - Improved :doc:`modernize-use-std-format
   ` check to support replacing
   member function calls too.

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/definitions-in-headers.hpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/definitions-in-headers.hpp
index 4cf07077a230a5..9c91cb7033087d 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/definitions-in-headers.hpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/definitions-in-headers.hpp
@@ -2,7 +2,7 @@
 
 int f() {
 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'f' defined in a header 
file; function definitions in header files can lead to ODR violations 
[misc-definitions-in-headers]
-// CHECK-MESSAGES: :[[@LINE-2]]:5: note: make as 'inline'
+// CHECK-MESSAGES: :[[@LINE-2]]:5: note: mark the definition as 'inline'
 // CHECK-FIXES: inline int f() {
   return 1;
 }



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


[clang-tools-extra] [NFC][clang-tidy] reword diagnostic note in definitions-in-headers (PR #106862)

2024-09-17 Thread Julian Schmidt via cfe-commits

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


[clang-tools-extra] 605a9ad - [clang-tidy] fix false positive in modernize-min-max-use-initializer-list (#107649)

2024-09-17 Thread via cfe-commits

Author: Julian Schmidt
Date: 2024-09-17T10:43:40+02:00
New Revision: 605a9adb4340b347f480a95a6eef3c9045e8416f

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

LOG: [clang-tidy] fix false positive in modernize-min-max-use-initializer-list 
(#107649)

Previously, whenever a replacement was generated by the analysis, a
diagnostic was generated. This became an issue when a call to
`std::min` or `std::max` consisted only of an initializer list with at
least one argument to the list requiring a type cast.
In this case, a single replacement that added a `static_cast` was
created,
that resulted in a diagnostic being issued but with no nested call
to `std::min` or `std::max`.

Instead, explicitly track if a nested call was detected and only emit a
diagnostic if this is the case.

Fixes #107594

Added: 


Modified: 
clang-tools-extra/clang-tidy/modernize/MinMaxUseInitializerListCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst

clang-tools-extra/test/clang-tidy/checkers/modernize/min-max-use-initializer-list.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/modernize/MinMaxUseInitializerListCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/MinMaxUseInitializerListCheck.cpp
index 418699ffbc4d1a..9861f4681db1b4 100644
--- a/clang-tools-extra/clang-tidy/modernize/MinMaxUseInitializerListCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/MinMaxUseInitializerListCheck.cpp
@@ -72,7 +72,11 @@ static FindArgsResult findArgs(const CallExpr *Call) {
   return Result;
 }
 
-static SmallVector
+// Returns `true` as `first` only if a nested call to `std::min` or
+// `std::max` was found. Checking if `FixItHint`s were generated is not enough,
+// as the explicit casts that the check introduces may be generated without a
+// nested `std::min` or `std::max` call.
+static std::pair>
 generateReplacements(const MatchFinder::MatchResult &Match,
  const CallExpr *TopCall, const FindArgsResult &Result,
  const bool IgnoreNonTrivialTypes,
@@ -91,13 +95,15 @@ generateReplacements(const MatchFinder::MatchResult &Match,
   const bool IsResultTypeTrivial = ResultType.isTrivialType(*Match.Context);
 
   if ((!IsResultTypeTrivial && IgnoreNonTrivialTypes))
-return FixItHints;
+return {false, FixItHints};
 
   if (IsResultTypeTrivial &&
   static_cast(
   Match.Context->getTypeSizeInChars(ResultType).getQuantity()) >
   IgnoreTrivialTypesOfSizeAbove)
-return FixItHints;
+return {false, FixItHints};
+
+  bool FoundNestedCall = false;
 
   for (const Expr *Arg : Result.Args) {
 const auto *InnerCall = dyn_cast(Arg->IgnoreParenImpCasts());
@@ -146,6 +152,9 @@ generateReplacements(const MatchFinder::MatchResult &Match,
*Match.Context))
   continue;
 
+// We have found a nested call
+FoundNestedCall = true;
+
 // remove the function call
 FixItHints.push_back(
 FixItHint::CreateRemoval(InnerCall->getCallee()->getSourceRange()));
@@ -168,7 +177,7 @@ generateReplacements(const MatchFinder::MatchResult &Match,
   CharSourceRange::getTokenRange(InnerResult.First->getEndLoc(;
 }
 
-const SmallVector InnerReplacements = generateReplacements(
+const auto [_, InnerReplacements] = generateReplacements(
 Match, InnerCall, InnerResult, IgnoreNonTrivialTypes,
 IgnoreTrivialTypesOfSizeAbove);
 
@@ -189,7 +198,7 @@ generateReplacements(const MatchFinder::MatchResult &Match,
 }
   }
 
-  return FixItHints;
+  return {FoundNestedCall, FixItHints};
 }
 
 MinMaxUseInitializerListCheck::MinMaxUseInitializerListCheck(
@@ -238,11 +247,11 @@ void MinMaxUseInitializerListCheck::check(
   const auto *TopCall = Match.Nodes.getNodeAs("topCall");
 
   const FindArgsResult Result = findArgs(TopCall);
-  const SmallVector Replacements =
+  const auto [FoundNestedCall, Replacements] =
   generateReplacements(Match, TopCall, Result, IgnoreNonTrivialTypes,
IgnoreTrivialTypesOfSizeAbove);
 
-  if (Replacements.empty())
+  if (!FoundNestedCall)
 return;
 
   const DiagnosticBuilder Diagnostic =

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index c297ed88ece0a2..a72c22187d5b4c 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -136,6 +136,11 @@ Changes in existing checks
   ` check to avoid
   false positive for C++23 deducing this.
 
+- Improved :doc:`modernize-min-max-use-initializer-list
+  ` check by fixing
+  a false positive when only an implicit conversion happened inside an
+  initializer list.
+
 - Improved :doc:`modernize-use-std-print
   ` check to support replacing
   member function calls t

[clang-tools-extra] [clang-tidy] fix false positive in modernize-min-max-use-initializer-list (PR #107649)

2024-09-17 Thread Julian Schmidt via cfe-commits

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


[clang-tools-extra] caaac84 - [clang-tidy] only diagnose definitions in readability-enum-initial-value (#107652)

2024-09-17 Thread via cfe-commits

Author: Julian Schmidt
Date: 2024-09-17T10:44:22+02:00
New Revision: caaac84ab2ef3f56e5204c9fae5cddf7b6e9a1c0

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

LOG: [clang-tidy] only diagnose definitions in readability-enum-initial-value 
(#107652)

With the `isDefinition` matcher, the analysis and diagnostics will be
constrained to definitions only. Previously forward declarations were
diagnosed as well.

Fixes #107590

Added: 


Modified: 
clang-tools-extra/clang-tidy/readability/EnumInitialValueCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/readability/enum-initial-value.c

clang-tools-extra/test/clang-tidy/checkers/readability/enum-initial-value.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/EnumInitialValueCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/EnumInitialValueCheck.cpp
index 8f2841c32259a2..1cb95c2b2347b7 100644
--- a/clang-tools-extra/clang-tidy/readability/EnumInitialValueCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/EnumInitialValueCheck.cpp
@@ -141,16 +141,18 @@ void 
EnumInitialValueCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
 }
 
 void EnumInitialValueCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(
-  enumDecl(unless(isMacro()), unless(hasConsistentInitialValues()))
-  .bind("inconsistent"),
-  this);
+  Finder->addMatcher(enumDecl(isDefinition(), unless(isMacro()),
+  unless(hasConsistentInitialValues()))
+ .bind("inconsistent"),
+ this);
   if (!AllowExplicitZeroFirstInitialValue)
 Finder->addMatcher(
-enumDecl(hasZeroInitialValueForFirstEnumerator()).bind("zero_first"),
+enumDecl(isDefinition(), hasZeroInitialValueForFirstEnumerator())
+.bind("zero_first"),
 this);
   if (!AllowExplicitSequentialInitialValues)
-Finder->addMatcher(enumDecl(unless(isMacro()), 
hasSequentialInitialValues())
+Finder->addMatcher(enumDecl(isDefinition(), unless(isMacro()),
+hasSequentialInitialValues())
.bind("sequential"),
this);
 }
@@ -159,7 +161,7 @@ void EnumInitialValueCheck::check(const 
MatchFinder::MatchResult &Result) {
   if (const auto *Enum = Result.Nodes.getNodeAs("inconsistent")) {
 DiagnosticBuilder Diag =
 diag(Enum->getBeginLoc(),
- "inital values in enum %0 are not consistent, consider explicit "
+ "initial values in enum %0 are not consistent, consider explicit "
  "initialization of all, none or only the first enumerator")
 << Enum;
 for (const EnumConstantDecl *ECD : Enum->enumerators())

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index a72c22187d5b4c..b5b164833e1575 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -145,6 +145,11 @@ Changes in existing checks
   ` check to support replacing
   member function calls too.
 
+- Improved :doc:`readability-enum-initial-value
+  ` check by only issuing
+  diagnostics for the definition of an ``enum``, and by fixing a typo in the
+  diagnostic.
+
 - Improved :doc:`performance-avoid-endl
   ` check to use ``std::endl`` as
   placeholder when lexer cannot get source text.

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/enum-initial-value.c 
b/clang-tools-extra/test/clang-tidy/checkers/readability/enum-initial-value.c
index c66288cbe3e957..b9a34d0683d7f3 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/enum-initial-value.c
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/enum-initial-value.c
@@ -6,8 +6,8 @@
 // RUN: }}'
 
 enum EError {
-  // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: inital values in enum 'EError' 
are not consistent
-  // CHECK-MESSAGES-ENABLE: :[[@LINE-2]]:1: warning: inital values in enum 
'EError' are not consistent
+  // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: initial values in enum 'EError' 
are not consistent
+  // CHECK-MESSAGES-ENABLE: :[[@LINE-2]]:1: warning: initial values in enum 
'EError' are not consistent
   EError_a = 1,
   EError_b,
   // CHECK-FIXES: EError_b = 2,
@@ -34,8 +34,8 @@ enum EAll {
 
 #define ENUMERATOR_1 EMacro1_b
 enum EMacro1 {
-  // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: inital values in enum 'EMacro1' 
are not consistent
-  // CHECK-MESSAGES-ENABLE: :[[@LINE-2]]:1: warning: inital values in enum 
'EMacro1' are not consistent
+  // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: initial values in enum 'EMacro1' 
are not consistent
+  // CHECK-MESSAGES-ENABLE: :[[@LINE-2]]:1: warning: initial value

[clang-tools-extra] [clang-tidy] only diagnose definitions in readability-enum-initial-value (PR #107652)

2024-09-17 Thread Julian Schmidt via cfe-commits

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


[clang-tools-extra] [clang-tidy] Add user-defined functions to `bugprone-unsafe-functions` check (PR #106350)

2024-09-17 Thread via cfe-commits

https://github.com/Discookie updated 
https://github.com/llvm/llvm-project/pull/106350

>From c4e05bdb36e270cbf0557f38fad7c04edf011905 Mon Sep 17 00:00:00 2001
From: Viktor 
Date: Wed, 28 Aug 2024 08:47:20 +
Subject: [PATCH 01/11] [clang-tidy] Add user-defined functions to
 bugprone-unsafe-functions check

---
 .../bugprone/UnsafeFunctionsCheck.cpp | 225 +++---
 .../bugprone/UnsafeFunctionsCheck.h   |  12 +
 .../checks/bugprone/unsafe-functions.rst  |  49 
 .../bugprone/unsafe-functions-custom.c|  38 +++
 .../checkers/bugprone/unsafe-functions.c  |   6 +
 5 files changed, 295 insertions(+), 35 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/unsafe-functions-custom.c

diff --git a/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp
index ea7eaa0b0ff811..05c2063402b080 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp
@@ -7,6 +7,8 @@
 
//===--===//
 
 #include "UnsafeFunctionsCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Lex/PPCallbacks.h"
@@ -18,6 +20,12 @@ using namespace llvm;
 
 namespace clang::tidy::bugprone {
 
+static constexpr llvm::StringLiteral OptionNameCustomNormalFunctions =
+"CustomNormalFunctions";
+static constexpr llvm::StringLiteral OptionNameCustomAnnexKFunctions =
+"CustomAnnexKFunctions";
+static constexpr llvm::StringLiteral OptionNameReportDefaultFunctions =
+"ReportDefaultFunctions";
 static constexpr llvm::StringLiteral OptionNameReportMoreUnsafeFunctions =
 "ReportMoreUnsafeFunctions";
 
@@ -26,6 +34,10 @@ static constexpr llvm::StringLiteral 
FunctionNamesWithAnnexKReplacementId =
 static constexpr llvm::StringLiteral FunctionNamesId = "FunctionsNames";
 static constexpr llvm::StringLiteral AdditionalFunctionNamesId =
 "AdditionalFunctionsNames";
+static constexpr llvm::StringLiteral CustomFunctionNamesId =
+"CustomFunctionNames";
+static constexpr llvm::StringLiteral CustomAnnexKFunctionNamesId =
+"CustomAnnexKFunctionNames";
 static constexpr llvm::StringLiteral DeclRefId = "DRE";
 
 static std::optional
@@ -127,57 +139,155 @@ static bool isAnnexKAvailable(std::optional 
&CacheVar, Preprocessor *PP,
   return CacheVar.value();
 }
 
+static std::vector
+ParseCheckedFunctions(StringRef Option, StringRef OptionName,
+  ClangTidyContext *Context) {
+  std::vector Functions = utils::options::parseStringList(Option);
+  std::vector Result;
+  Result.reserve(Functions.size());
+
+  for (StringRef Function : Functions) {
+if (Function.empty()) {
+  continue;
+}
+
+auto [Name, Rest] = Function.split(',');
+auto [Replacement, Reason] = Rest.split(',');
+
+if (Name.trim().empty()) {
+  Context->configurationDiag("invalid configuration value for option '%0'; 
"
+ "expected the name of an unsafe function")
+  << OptionName;
+}
+
+if (Replacement.trim().empty()) {
+  Context->configurationDiag(
+  "invalid configuration value '%0' for option '%1'; "
+  "expected a replacement function name")
+  << Name.trim() << OptionName;
+}
+
+Result.push_back({Name.trim().str(), llvm::Regex(Name.trim()),
+  Replacement.trim().str(), Reason.trim().str()});
+  }
+
+  return Result;
+}
+
+static std::string SerializeCheckedFunctions(
+const std::vector &Functions) {
+  std::vector Result;
+  Result.reserve(Functions.size());
+
+  for (const auto &Entry : Functions) {
+if (Entry.Reason.empty())
+  Result.push_back(Entry.Name + "," + Entry.Replacement);
+else
+  Result.push_back(Entry.Name + "," + Entry.Replacement + "," +
+   Entry.Reason);
+  }
+
+  return llvm::join(Result, ";");
+}
+
 UnsafeFunctionsCheck::UnsafeFunctionsCheck(StringRef Name,
ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
+  CustomNormalFunctions(ParseCheckedFunctions(
+  Options.get(OptionNameCustomNormalFunctions, ""),
+  OptionNameCustomNormalFunctions, Context)),
+  CustomAnnexKFunctions(ParseCheckedFunctions(
+  Options.get(OptionNameCustomAnnexKFunctions, ""),
+  OptionNameCustomAnnexKFunctions, Context)),
+  ReportDefaultFunctions(
+  Options.get(OptionNameReportDefaultFunctions, true)),
   ReportMoreUnsafeFunctions(
   Options.get(OptionNameReportMoreUnsafeFunctions, true)) {}
 
 void UnsafeFunctionsCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, OptionNameCustomNormalFunctions,
+SerializeChec

[clang] [llvm] riscv: Support -mstack-protector-guard=tls (PR #108942)

2024-09-17 Thread Keith Packard via cfe-commits

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

Add support for using a thread-local variable with a specified offsetfor 
holding the stack guard canary value.

>From 7822a1ee2eed923a3014577668bdd8f1c8145d4c Mon Sep 17 00:00:00 2001
From: Keith Packard 
Date: Mon, 16 Sep 2024 15:41:38 +0200
Subject: [PATCH 1/3] riscv: Support -mstack-protector-guard=tls

Add support for using a thread-local variable with a specified offset
for holding the stack guard canary value.

Signed-off-by: Keith Packard 
---
 clang/lib/Driver/ToolChains/Clang.cpp   | 33 +++--
 llvm/lib/Target/RISCV/RISCVISelLowering.cpp |  8 +
 2 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 3fe4ce5d893b8d..4c7756b3883b8c 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -3604,7 +3604,8 @@ static void RenderSSPOptions(const Driver &D, const 
ToolChain &TC,
   if (Arg *A = Args.getLastArg(options::OPT_mstack_protector_guard_EQ)) {
 StringRef Value = A->getValue();
 if (!EffectiveTriple.isX86() && !EffectiveTriple.isAArch64() &&
-!EffectiveTriple.isARM() && !EffectiveTriple.isThumb())
+!EffectiveTriple.isARM() && !EffectiveTriple.isThumb() &&
+!EffectiveTriple.isRISCV())
   D.Diag(diag::err_drv_unsupported_opt_for_target)
   << A->getAsString(Args) << TripleStr;
 if ((EffectiveTriple.isX86() || EffectiveTriple.isARM() ||
@@ -3644,13 +3645,28 @@ static void RenderSSPOptions(const Driver &D, const 
ToolChain &TC,
   << A->getOption().getName() << Value << "sysreg global";
   return;
 }
+if (EffectiveTriple.isRISCV()) {
+  if (Value != "tls" && Value != "global") {
+D.Diag(diag::err_drv_invalid_value_with_suggestion)
+<< A->getOption().getName() << Value << "tls global";
+return;
+  }
+  if (Value == "tls") {
+if (!Args.hasArg(options::OPT_mstack_protector_guard_offset_EQ)) {
+  D.Diag(diag::err_drv_ssp_missing_offset_argument)
+  << A->getAsString(Args);
+  return;
+}
+  }
+}
 A->render(Args, CmdArgs);
   }
 
   if (Arg *A = Args.getLastArg(options::OPT_mstack_protector_guard_offset_EQ)) 
{
 StringRef Value = A->getValue();
 if (!EffectiveTriple.isX86() && !EffectiveTriple.isAArch64() &&
-!EffectiveTriple.isARM() && !EffectiveTriple.isThumb())
+!EffectiveTriple.isARM() && !EffectiveTriple.isThumb() &&
+!EffectiveTriple.isRISCV())
   D.Diag(diag::err_drv_unsupported_opt_for_target)
   << A->getAsString(Args) << TripleStr;
 int Offset;
@@ -3664,12 +3680,18 @@ static void RenderSSPOptions(const Driver &D, const 
ToolChain &TC,
   << A->getOption().getName() << Value;
   return;
 }
+if (EffectiveTriple.isRISCV() && (Offset <= -2048 || Offset >= 2048)) {
+  D.Diag(diag::err_drv_invalid_int_value)
+  << A->getOption().getName() << Value;
+  return;
+}
 A->render(Args, CmdArgs);
   }
 
   if (Arg *A = Args.getLastArg(options::OPT_mstack_protector_guard_reg_EQ)) {
 StringRef Value = A->getValue();
-if (!EffectiveTriple.isX86() && !EffectiveTriple.isAArch64())
+if (!EffectiveTriple.isX86() && !EffectiveTriple.isAArch64() &&
+!EffectiveTriple.isRISCV())
   D.Diag(diag::err_drv_unsupported_opt_for_target)
   << A->getAsString(Args) << TripleStr;
 if (EffectiveTriple.isX86() && (Value != "fs" && Value != "gs")) {
@@ -3681,6 +3703,11 @@ static void RenderSSPOptions(const Driver &D, const 
ToolChain &TC,
   D.Diag(diag::err_drv_invalid_value) << A->getOption().getName() << Value;
   return;
 }
+if (EffectiveTriple.isRISCV() && Value != "tp") {
+  D.Diag(diag::err_drv_invalid_value_with_suggestion)
+  << A->getOption().getName() << Value << "tp";
+  return;
+}
 A->render(Args, CmdArgs);
   }
 
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp 
b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index 7d2a7b20ba2508..c52ef550495052 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -21228,6 +21228,14 @@ Value 
*RISCVTargetLowering::getIRStackGuard(IRBuilderBase &IRB) const {
   if (Subtarget.isTargetAndroid())
 return useTpOffset(IRB, -0x18);
 
+  Module *M = IRB.GetInsertBlock()->getParent()->getParent();
+
+  if (M->getStackProtectorGuard() == "tls") {
+// Specially, some users may customize the base reg and offset.
+int Offset = M->getStackProtectorGuardOffset();
+return useTpOffset(IRB, Offset);
+  }
+
   return TargetLowering::getIRStackGuard(IRB);
 }
 

>From 9f589d801fa62a1bb46c2b8f3d56b653396028c6 Mon Sep 17 00:00:00 2001
From: Keith Packard 
Date: Mon, 16 Sep 2024 11:27:19 -0700
Subject: [PATCH 2/3] Driver: add stack protector tests for riscv

Ad

[clang] [llvm] riscv: Support -mstack-protector-guard=tls (PR #108942)

2024-09-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Keith Packard (keith-packard)


Changes

Add support for using a thread-local variable with a specified offsetfor 
holding the stack guard canary value.

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


5 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+30-3) 
- (modified) clang/test/CodeGen/stack-protector-guard.c (+9) 
- (modified) clang/test/Driver/stack-protector-guard.c (+10) 
- (modified) llvm/lib/Target/RISCV/RISCVISelLowering.cpp (+8) 
- (added) llvm/test/CodeGen/RISCV/stack-guard-tls.ll (+19) 


``diff
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 3fe4ce5d893b8d..4c7756b3883b8c 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -3604,7 +3604,8 @@ static void RenderSSPOptions(const Driver &D, const 
ToolChain &TC,
   if (Arg *A = Args.getLastArg(options::OPT_mstack_protector_guard_EQ)) {
 StringRef Value = A->getValue();
 if (!EffectiveTriple.isX86() && !EffectiveTriple.isAArch64() &&
-!EffectiveTriple.isARM() && !EffectiveTriple.isThumb())
+!EffectiveTriple.isARM() && !EffectiveTriple.isThumb() &&
+!EffectiveTriple.isRISCV())
   D.Diag(diag::err_drv_unsupported_opt_for_target)
   << A->getAsString(Args) << TripleStr;
 if ((EffectiveTriple.isX86() || EffectiveTriple.isARM() ||
@@ -3644,13 +3645,28 @@ static void RenderSSPOptions(const Driver &D, const 
ToolChain &TC,
   << A->getOption().getName() << Value << "sysreg global";
   return;
 }
+if (EffectiveTriple.isRISCV()) {
+  if (Value != "tls" && Value != "global") {
+D.Diag(diag::err_drv_invalid_value_with_suggestion)
+<< A->getOption().getName() << Value << "tls global";
+return;
+  }
+  if (Value == "tls") {
+if (!Args.hasArg(options::OPT_mstack_protector_guard_offset_EQ)) {
+  D.Diag(diag::err_drv_ssp_missing_offset_argument)
+  << A->getAsString(Args);
+  return;
+}
+  }
+}
 A->render(Args, CmdArgs);
   }
 
   if (Arg *A = Args.getLastArg(options::OPT_mstack_protector_guard_offset_EQ)) 
{
 StringRef Value = A->getValue();
 if (!EffectiveTriple.isX86() && !EffectiveTriple.isAArch64() &&
-!EffectiveTriple.isARM() && !EffectiveTriple.isThumb())
+!EffectiveTriple.isARM() && !EffectiveTriple.isThumb() &&
+!EffectiveTriple.isRISCV())
   D.Diag(diag::err_drv_unsupported_opt_for_target)
   << A->getAsString(Args) << TripleStr;
 int Offset;
@@ -3664,12 +3680,18 @@ static void RenderSSPOptions(const Driver &D, const 
ToolChain &TC,
   << A->getOption().getName() << Value;
   return;
 }
+if (EffectiveTriple.isRISCV() && (Offset <= -2048 || Offset >= 2048)) {
+  D.Diag(diag::err_drv_invalid_int_value)
+  << A->getOption().getName() << Value;
+  return;
+}
 A->render(Args, CmdArgs);
   }
 
   if (Arg *A = Args.getLastArg(options::OPT_mstack_protector_guard_reg_EQ)) {
 StringRef Value = A->getValue();
-if (!EffectiveTriple.isX86() && !EffectiveTriple.isAArch64())
+if (!EffectiveTriple.isX86() && !EffectiveTriple.isAArch64() &&
+!EffectiveTriple.isRISCV())
   D.Diag(diag::err_drv_unsupported_opt_for_target)
   << A->getAsString(Args) << TripleStr;
 if (EffectiveTriple.isX86() && (Value != "fs" && Value != "gs")) {
@@ -3681,6 +3703,11 @@ static void RenderSSPOptions(const Driver &D, const 
ToolChain &TC,
   D.Diag(diag::err_drv_invalid_value) << A->getOption().getName() << Value;
   return;
 }
+if (EffectiveTriple.isRISCV() && Value != "tp") {
+  D.Diag(diag::err_drv_invalid_value_with_suggestion)
+  << A->getOption().getName() << Value << "tp";
+  return;
+}
 A->render(Args, CmdArgs);
   }
 
diff --git a/clang/test/CodeGen/stack-protector-guard.c 
b/clang/test/CodeGen/stack-protector-guard.c
index 5839ab06033a15..81e0ddc8753966 100644
--- a/clang/test/CodeGen/stack-protector-guard.c
+++ b/clang/test/CodeGen/stack-protector-guard.c
@@ -9,6 +9,9 @@
 // RUN: %clang_cc1 -mstack-protector-guard=sysreg -triple aarch64-linux-gnu \
 // RUN:   -mstack-protector-guard-offset=1024 
-mstack-protector-guard-reg=sp_el0 \
 // RUN:   -emit-llvm %s -o - | FileCheck %s --check-prefix=AARCH64
+// RUN: %clang_cc1 -mstack-protector-guard=tls -triple riscv64-unknown-elf \
+// RUN:   -mstack-protector-guard-offset=44 -mstack-protector-guard-reg=tp \
+// RUN:   -emit-llvm %s -o - | FileCheck %s --check-prefix=RISCV
 void foo(int*);
 void bar(int x) {
   int baz[x];
@@ -23,3 +26,9 @@ void bar(int x) {
 // AARCH64: [[ATTR1]] = !{i32 1, !"stack-protector-guard", !"sysreg"}
 // AARCH64: [[ATTR2]] = !{i32 1, !"stack-protector-guard-reg", !"sp_el0"}
 // AARCH64: [[ATTR3]] = !{i32 1, !"stack-protector-guard-offset", i32 1024}
+
+// RISCV: !llvm.module.flags = 

[clang] [llvm] riscv: Support -mstack-protector-guard=tls (PR #108942)

2024-09-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Keith Packard (keith-packard)


Changes

Add support for using a thread-local variable with a specified offsetfor 
holding the stack guard canary value.

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


5 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+30-3) 
- (modified) clang/test/CodeGen/stack-protector-guard.c (+9) 
- (modified) clang/test/Driver/stack-protector-guard.c (+10) 
- (modified) llvm/lib/Target/RISCV/RISCVISelLowering.cpp (+8) 
- (added) llvm/test/CodeGen/RISCV/stack-guard-tls.ll (+19) 


``diff
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 3fe4ce5d893b8d..4c7756b3883b8c 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -3604,7 +3604,8 @@ static void RenderSSPOptions(const Driver &D, const 
ToolChain &TC,
   if (Arg *A = Args.getLastArg(options::OPT_mstack_protector_guard_EQ)) {
 StringRef Value = A->getValue();
 if (!EffectiveTriple.isX86() && !EffectiveTriple.isAArch64() &&
-!EffectiveTriple.isARM() && !EffectiveTriple.isThumb())
+!EffectiveTriple.isARM() && !EffectiveTriple.isThumb() &&
+!EffectiveTriple.isRISCV())
   D.Diag(diag::err_drv_unsupported_opt_for_target)
   << A->getAsString(Args) << TripleStr;
 if ((EffectiveTriple.isX86() || EffectiveTriple.isARM() ||
@@ -3644,13 +3645,28 @@ static void RenderSSPOptions(const Driver &D, const 
ToolChain &TC,
   << A->getOption().getName() << Value << "sysreg global";
   return;
 }
+if (EffectiveTriple.isRISCV()) {
+  if (Value != "tls" && Value != "global") {
+D.Diag(diag::err_drv_invalid_value_with_suggestion)
+<< A->getOption().getName() << Value << "tls global";
+return;
+  }
+  if (Value == "tls") {
+if (!Args.hasArg(options::OPT_mstack_protector_guard_offset_EQ)) {
+  D.Diag(diag::err_drv_ssp_missing_offset_argument)
+  << A->getAsString(Args);
+  return;
+}
+  }
+}
 A->render(Args, CmdArgs);
   }
 
   if (Arg *A = Args.getLastArg(options::OPT_mstack_protector_guard_offset_EQ)) 
{
 StringRef Value = A->getValue();
 if (!EffectiveTriple.isX86() && !EffectiveTriple.isAArch64() &&
-!EffectiveTriple.isARM() && !EffectiveTriple.isThumb())
+!EffectiveTriple.isARM() && !EffectiveTriple.isThumb() &&
+!EffectiveTriple.isRISCV())
   D.Diag(diag::err_drv_unsupported_opt_for_target)
   << A->getAsString(Args) << TripleStr;
 int Offset;
@@ -3664,12 +3680,18 @@ static void RenderSSPOptions(const Driver &D, const 
ToolChain &TC,
   << A->getOption().getName() << Value;
   return;
 }
+if (EffectiveTriple.isRISCV() && (Offset <= -2048 || Offset >= 2048)) {
+  D.Diag(diag::err_drv_invalid_int_value)
+  << A->getOption().getName() << Value;
+  return;
+}
 A->render(Args, CmdArgs);
   }
 
   if (Arg *A = Args.getLastArg(options::OPT_mstack_protector_guard_reg_EQ)) {
 StringRef Value = A->getValue();
-if (!EffectiveTriple.isX86() && !EffectiveTriple.isAArch64())
+if (!EffectiveTriple.isX86() && !EffectiveTriple.isAArch64() &&
+!EffectiveTriple.isRISCV())
   D.Diag(diag::err_drv_unsupported_opt_for_target)
   << A->getAsString(Args) << TripleStr;
 if (EffectiveTriple.isX86() && (Value != "fs" && Value != "gs")) {
@@ -3681,6 +3703,11 @@ static void RenderSSPOptions(const Driver &D, const 
ToolChain &TC,
   D.Diag(diag::err_drv_invalid_value) << A->getOption().getName() << Value;
   return;
 }
+if (EffectiveTriple.isRISCV() && Value != "tp") {
+  D.Diag(diag::err_drv_invalid_value_with_suggestion)
+  << A->getOption().getName() << Value << "tp";
+  return;
+}
 A->render(Args, CmdArgs);
   }
 
diff --git a/clang/test/CodeGen/stack-protector-guard.c 
b/clang/test/CodeGen/stack-protector-guard.c
index 5839ab06033a15..81e0ddc8753966 100644
--- a/clang/test/CodeGen/stack-protector-guard.c
+++ b/clang/test/CodeGen/stack-protector-guard.c
@@ -9,6 +9,9 @@
 // RUN: %clang_cc1 -mstack-protector-guard=sysreg -triple aarch64-linux-gnu \
 // RUN:   -mstack-protector-guard-offset=1024 
-mstack-protector-guard-reg=sp_el0 \
 // RUN:   -emit-llvm %s -o - | FileCheck %s --check-prefix=AARCH64
+// RUN: %clang_cc1 -mstack-protector-guard=tls -triple riscv64-unknown-elf \
+// RUN:   -mstack-protector-guard-offset=44 -mstack-protector-guard-reg=tp \
+// RUN:   -emit-llvm %s -o - | FileCheck %s --check-prefix=RISCV
 void foo(int*);
 void bar(int x) {
   int baz[x];
@@ -23,3 +26,9 @@ void bar(int x) {
 // AARCH64: [[ATTR1]] = !{i32 1, !"stack-protector-guard", !"sysreg"}
 // AARCH64: [[ATTR2]] = !{i32 1, !"stack-protector-guard-reg", !"sp_el0"}
 // AARCH64: [[ATTR3]] = !{i32 1, !"stack-protector-guard-offset", i32 1024}
+
+// RISCV: !llvm.module.f

[clang] [clang-format] Fix a bug in annotating angles containing FatArrow (PR #108671)

2024-09-17 Thread kadir çetinkaya via cfe-commits


@@ -243,14 +244,16 @@ class AnnotatingParser {
   // operator that was misinterpreted because we are parsing template
   // parameters.
   // FIXME: This is getting out of hand, write a decent parser.
-  if (InExpr && !Line.startsWith(tok::kw_template) &&
+  if (InExpr && !SeenFatArrow && !Line.startsWith(tok::kw_template) &&
   Prev.is(TT_BinaryOperator)) {
 const auto Precedence = Prev.getPrecedence();
 if (Precedence > prec::Conditional && Precedence < prec::Relational)
   return false;
   }
   if (Prev.isOneOf(tok::question, tok::colon) && !Style.isProto())
 SeenTernaryOperator = true;
+  else if (Prev.is(TT_FatArrow))

kadircet wrote:

i don't think new or empty parantheses are a must either, the logic around here 
is just checking that `<>` are inside an expression, hence that kind of code 
pattern is likely quite common as people tend to do arithmetic via 
metaprogramming using these patterns. e.g:
```cpp
constexpr auto foo() { return FixedInt(foo); }
```

this will be formatted as the following now:
```cpp
constexpr auto foo() { return FixedInt < N | M > (foo); }
```

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


[clang] 88a9bca - [clang][NFC] Update `cxx_dr_status.html`

2024-09-17 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-09-17T12:12:49+03:00
New Revision: 88a9bcaf7074d21aa818cfa3952300dc9547be77

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

LOG: [clang][NFC] Update `cxx_dr_status.html`

Added: 


Modified: 
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index f036fc5add2413..a7ce84b5fa7213 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -11809,11 +11809,11 @@ C++ defect report implementation 
status
 Reference list-initialization ignores conversion functions
 Not resolved
   
-  
+  
 https://cplusplus.github.io/CWG/issues/1997.html";>1997
-drafting
+DRWP
 Placement new and previous initialization
-Not resolved
+Unknown
   
   
 https://cplusplus.github.io/CWG/issues/1998.html";>1998
@@ -17350,7 +17350,7 @@ C++ defect report implementation 
status
   
   
 https://cplusplus.github.io/CWG/issues/2916.html";>2916
-tentatively ready
+review
 Variable template partial specializations should not be declared 
static
 Not resolved
   
@@ -17427,6 +17427,60 @@ C++ defect report implementation 
status
 open
 Unclear status of translation unit with module keyword
 Not resolved
+  
+  
+https://cplusplus.github.io/CWG/issues/2928.html";>2928
+open
+No ordering for initializing thread-local variables
+Not resolved
+  
+  
+https://cplusplus.github.io/CWG/issues/2929.html";>2929
+open
+Lifetime of trivially-destructible static or thread-local objects
+Not resolved
+  
+  
+https://cplusplus.github.io/CWG/issues/2930.html";>2930
+open
+Unclear term "copy/move operation" in specification of copy 
elision
+Not resolved
+  
+  
+https://cplusplus.github.io/CWG/issues/2931.html";>2931
+open
+Restrictions on operator functions that are explicit object member 
functions
+Not resolved
+  
+  
+https://cplusplus.github.io/CWG/issues/2932.html";>2932
+open
+Value range of empty enumeration
+Not resolved
+  
+  
+https://cplusplus.github.io/CWG/issues/2933.html";>2933
+open
+Dangling references
+Not resolved
+  
+  
+https://cplusplus.github.io/CWG/issues/2934.html";>2934
+open
+Unclear semantics of exception escaping from 
unhandled_exception
+Not resolved
+  
+  
+https://cplusplus.github.io/CWG/issues/2935.html";>2935
+open
+Destroying the coroutine state when initial-await-resume-called is 
false
+Not resolved
+  
+  
+https://cplusplus.github.io/CWG/issues/2936.html";>2936
+open
+Local classes of templated functions should be part of the current 
instantiation
+Not resolved
   
 
 



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


[clang] [Clang] Reject `this void` explicit object parameters (CWG2915) (PR #108817)

2024-09-17 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

> @Endilll: I've removed the other changes from `cxx_dr_status.html` manually 
> from this commit. Can you create the separate patch to add the new cwg 
> issues? Thanks!

Pushed 331d65d0e271d22da9f496f2bb628b93ab515725

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


[clang] [Clang] Reject `this void` explicit object parameters (CWG2915) (PR #108817)

2024-09-17 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

> @Endilll: I've removed the other changes from `cxx_dr_status.html` manually 
> from this commit. Can you create the separate patch to add the new cwg 
> issues? Thanks!

Pushed 88a9bcaf7074d21aa818cfa3952300dc9547be77

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


[clang-tools-extra] [clang-tidy] Create bugprone-bit-cast-pointers check (PR #108083)

2024-09-17 Thread Carlos Galvez via cfe-commits

https://github.com/carlosgalvezp updated 
https://github.com/llvm/llvm-project/pull/108083

>From d7eacb7d6614b374a959c33a7394f2652df32982 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Tue, 10 Sep 2024 13:46:51 +
Subject: [PATCH] [clang-tidy] Create bugprone-bit-cast-pointers check

To detect unsafe use of bit_cast. Otherwise, bit_cast bypasses all
checks done by compilers and linters.

Fixes #106987
---
 .../bugprone/BitCastPointersCheck.cpp | 45 ++
 .../bugprone/BitCastPointersCheck.h   | 34 +++
 .../bugprone/BugproneTidyModule.cpp   |  3 +
 .../clang-tidy/bugprone/CMakeLists.txt|  1 +
 clang-tools-extra/docs/ReleaseNotes.rst   |  6 ++
 .../checks/bugprone/bit-cast-pointers.rst | 52 
 .../checkers/bugprone/bit-cast-pointers.cpp   | 61 +++
 7 files changed, 202 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/BitCastPointersCheck.cpp
 create mode 100644 clang-tools-extra/clang-tidy/bugprone/BitCastPointersCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/bugprone/bit-cast-pointers.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/bit-cast-pointers.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BitCastPointersCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BitCastPointersCheck.cpp
new file mode 100644
index 00..30a700fc8c0062
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/BitCastPointersCheck.cpp
@@ -0,0 +1,45 @@
+//===--- BitCastPointersCheck.cpp - clang-tidy 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "BitCastPointersCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+void BitCastPointersCheck::registerMatchers(MatchFinder *Finder) {
+  auto IsPointerType = refersToType(qualType(isAnyPointer()));
+  Finder->addMatcher(callExpr(hasDeclaration(functionDecl(allOf(
+  hasName("::std::bit_cast"),
+  hasTemplateArgument(0, IsPointerType),
+  hasTemplateArgument(1, IsPointerType)
+ .bind("bit_cast"),
+ this);
+
+  auto IsDoublePointerType =
+  hasType(qualType(pointsTo(qualType(isAnyPointer();
+  Finder->addMatcher(callExpr(hasArgument(0, IsDoublePointerType),
+  hasArgument(1, IsDoublePointerType),
+  
hasDeclaration(functionDecl(hasName("::memcpy"
+ .bind("memcpy"),
+ this);
+}
+
+void BitCastPointersCheck::check(const MatchFinder::MatchResult &Result) {
+  if (const auto *MatchedDecl = Result.Nodes.getNodeAs("bit_cast"))
+diag(MatchedDecl->getBeginLoc(),
+ "do not use std::bit_cast to cast between pointers")
+<< MatchedDecl->getSourceRange();
+  if (const auto *MatchedDecl = Result.Nodes.getNodeAs("memcpy"))
+diag(MatchedDecl->getBeginLoc(),
+ "do not use memcpy to cast between pointers")
+<< MatchedDecl->getSourceRange();
+}
+
+} // namespace clang::tidy::bugprone
diff --git a/clang-tools-extra/clang-tidy/bugprone/BitCastPointersCheck.h 
b/clang-tools-extra/clang-tidy/bugprone/BitCastPointersCheck.h
new file mode 100644
index 00..857a35be13c72f
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/BitCastPointersCheck.h
@@ -0,0 +1,34 @@
+//===--- BitCastPointersCheck.h - clang-tidy *- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_BITCASTPOINTERSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_BITCASTPOINTERSCHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang::tidy::bugprone {
+
+/// Warns about usage of ``std::bit_cast`` when the input and output types are
+/// pointers.
+///
+/// For the user-facing documentation see:
+/// 
http://clang.llvm.org/extra/clang-tidy/checks/bugprone/bit-cast-pointers.html
+class BitCastPointersCheck : public ClangTidyCheck {
+public:
+  BitCastPointersCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  bool isLanguageVersionSupported(con

[clang-tools-extra] [clang-tidy] Create bugprone-bit-cast-pointers check (PR #108083)

2024-09-17 Thread Carlos Galvez via cfe-commits

https://github.com/carlosgalvezp updated 
https://github.com/llvm/llvm-project/pull/108083

>From c9e69b58e6c3e27fc6dd529783c02fec8fafbd9a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Tue, 10 Sep 2024 13:46:51 +
Subject: [PATCH] [clang-tidy] Create bugprone-bit-cast-pointers check

To detect unsafe use of bit_cast. Otherwise, bit_cast bypasses all
checks done by compilers and linters.

Fixes #106987
---
 .../bugprone/BitCastPointersCheck.cpp | 45 ++
 .../bugprone/BitCastPointersCheck.h   | 34 +++
 .../bugprone/BugproneTidyModule.cpp   |  3 +
 .../clang-tidy/bugprone/CMakeLists.txt|  1 +
 clang-tools-extra/docs/ReleaseNotes.rst   |  6 ++
 .../checks/bugprone/bit-cast-pointers.rst | 52 
 .../checkers/bugprone/bit-cast-pointers.cpp   | 61 +++
 7 files changed, 202 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/BitCastPointersCheck.cpp
 create mode 100644 clang-tools-extra/clang-tidy/bugprone/BitCastPointersCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/bugprone/bit-cast-pointers.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/bit-cast-pointers.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BitCastPointersCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BitCastPointersCheck.cpp
new file mode 100644
index 00..30a700fc8c0062
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/BitCastPointersCheck.cpp
@@ -0,0 +1,45 @@
+//===--- BitCastPointersCheck.cpp - clang-tidy 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "BitCastPointersCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+void BitCastPointersCheck::registerMatchers(MatchFinder *Finder) {
+  auto IsPointerType = refersToType(qualType(isAnyPointer()));
+  Finder->addMatcher(callExpr(hasDeclaration(functionDecl(allOf(
+  hasName("::std::bit_cast"),
+  hasTemplateArgument(0, IsPointerType),
+  hasTemplateArgument(1, IsPointerType)
+ .bind("bit_cast"),
+ this);
+
+  auto IsDoublePointerType =
+  hasType(qualType(pointsTo(qualType(isAnyPointer();
+  Finder->addMatcher(callExpr(hasArgument(0, IsDoublePointerType),
+  hasArgument(1, IsDoublePointerType),
+  
hasDeclaration(functionDecl(hasName("::memcpy"
+ .bind("memcpy"),
+ this);
+}
+
+void BitCastPointersCheck::check(const MatchFinder::MatchResult &Result) {
+  if (const auto *MatchedDecl = Result.Nodes.getNodeAs("bit_cast"))
+diag(MatchedDecl->getBeginLoc(),
+ "do not use std::bit_cast to cast between pointers")
+<< MatchedDecl->getSourceRange();
+  if (const auto *MatchedDecl = Result.Nodes.getNodeAs("memcpy"))
+diag(MatchedDecl->getBeginLoc(),
+ "do not use memcpy to cast between pointers")
+<< MatchedDecl->getSourceRange();
+}
+
+} // namespace clang::tidy::bugprone
diff --git a/clang-tools-extra/clang-tidy/bugprone/BitCastPointersCheck.h 
b/clang-tools-extra/clang-tidy/bugprone/BitCastPointersCheck.h
new file mode 100644
index 00..223ad95ddc90ba
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/BitCastPointersCheck.h
@@ -0,0 +1,34 @@
+//===--- BitCastPointersCheck.h - clang-tidy *- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_BITCASTPOINTERSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_BITCASTPOINTERSCHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang::tidy::bugprone {
+
+/// Warns about code that tries to cast between pointers by means of
+/// ``std::bit_cast`` or ``memcpy``.
+///
+/// For the user-facing documentation see:
+/// 
http://clang.llvm.org/extra/clang-tidy/checks/bugprone/bit-cast-pointers.html
+class BitCastPointersCheck : public ClangTidyCheck {
+public:
+  BitCastPointersCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  bool isLanguageVersion

[clang] [flang] [flang][Driver] Support -nostdlib and -nodefaultlibs (PR #108868)

2024-09-17 Thread Tom Eccles via cfe-commits

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

LGTM, thanks

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


[clang] [clang][bytecode] Implement arithmetic, bitwise and compound assignment operator (PR #108949)

2024-09-17 Thread via cfe-commits

https://github.com/yronglin created 
https://github.com/llvm/llvm-project/pull/108949

Implement `+`, `-`, `*`, `/` , `%`, `&`, `|`, `^`, `<<`, `>>` and compound 
assignment operator.

>From 3601f708847f70485fae640c5b5d96fed965e7c3 Mon Sep 17 00:00:00 2001
From: yronglin 
Date: Tue, 17 Sep 2024 17:39:47 +0800
Subject: [PATCH] [clang][bytecode] Implement arithmetic, bitwise and compound
 assignment operator

Signed-off-by: yronglin 
---
 clang/lib/AST/ByteCode/Compiler.cpp   | 121 +++-
 clang/test/AST/ByteCode/constexpr-vectors.cpp | 519 +-
 clang/test/SemaCXX/constexpr-vectors.cpp  |   1 +
 3 files changed, 611 insertions(+), 30 deletions(-)

diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 7e0775a51aee61..e7a6df58e6f1a6 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -1267,12 +1267,8 @@ bool Compiler::VisitVectorBinOp(const 
BinaryOperator *E) {
   assert(E->getLHS()->getType()->isVectorType());
   assert(E->getRHS()->getType()->isVectorType());
 
-  // FIXME: Current only support comparison binary operator, add support for
-  // other binary operator.
-  if (!E->isComparisonOp() && !E->isLogicalOp())
-return this->emitInvalid(E);
   // Prepare storage for result.
-  if (!Initializing) {
+  if (!Initializing || E->isCompoundAssignmentOp()) {
 unsigned LocalIndex = allocateTemporary(E);
 if (!this->emitGetPtrLocal(LocalIndex, E))
   return false;
@@ -1281,26 +1277,67 @@ bool Compiler::VisitVectorBinOp(const 
BinaryOperator *E) {
   const Expr *LHS = E->getLHS();
   const Expr *RHS = E->getRHS();
   const auto *VecTy = E->getType()->getAs();
+  auto Op = E->isCompoundAssignmentOp()
+? BinaryOperator::getOpForCompoundAssignment(E->getOpcode())
+: E->getOpcode();
 
   // The LHS and RHS of a comparison operator must have the same type. So we
   // just use LHS vector element type here.
   PrimType ElemT = this->classifyVectorElementType(LHS->getType());
   PrimType ResultElemT = this->classifyVectorElementType(E->getType());
 
-  // Evaluate LHS and save value to LHSOffset.
+  // Allocate a local pointer for LHS and RHS.
   unsigned LHSOffset = this->allocateLocalPrimitive(LHS, PT_Ptr, true, false);
+  unsigned RHSOffset = this->allocateLocalPrimitive(RHS, PT_Ptr, true, false);
+
+  // C++17 onwards require that we evaluate the RHS of the compound
+  // assignment op first.
+  if (E->isCompoundAssignmentOp()) {
+// Evaluate RHS and save value to RHSOffset.
+if (!this->visit(RHS))
+  return false;
+if (!this->emitSetLocal(PT_Ptr, RHSOffset, E))
+  return false;
+
+// Evaluate LHS and save value to LHSOffset.
+if (!this->visit(LHS))
+  return false;
+if (!this->emitSetLocal(PT_Ptr, LHSOffset, E))
+  return false;
+  } else {
+// Evaluate LHS and save value to LHSOffset.
+if (!this->visit(LHS))
+  return false;
+if (!this->emitSetLocal(PT_Ptr, LHSOffset, E))
+  return false;
+
+// Evaluate RHS and save value to RHSOffset.
+if (!this->visit(RHS))
+  return false;
+if (!this->emitSetLocal(PT_Ptr, RHSOffset, E))
+  return false;
+  }
+
+  // Evaluate LHS and save value to LHSOffset.
   if (!this->visit(LHS))
 return false;
   if (!this->emitSetLocal(PT_Ptr, LHSOffset, E))
 return false;
 
   // Evaluate RHS and save value to RHSOffset.
-  unsigned RHSOffset = this->allocateLocalPrimitive(RHS, PT_Ptr, true, false);
   if (!this->visit(RHS))
 return false;
   if (!this->emitSetLocal(PT_Ptr, RHSOffset, E))
 return false;
 
+  // BitAdd/BitOr/BitXor/Shl/Shr doesn't support bool type, we need perform the
+  // integer promotion.
+  bool NeedIntPromot = ElemT == PT_Bool && (E->isBitwiseOp() || 
E->isShiftOp());
+  QualType PromotTy =
+  Ctx.getASTContext().getPromotedIntegerType(Ctx.getASTContext().BoolTy);
+  PrimType PromotT = classifyPrim(PromotTy);
+  PrimType OpT = NeedIntPromot ? PromotT : ElemT;
+
   auto getElem = [=](unsigned Offset, unsigned Index) {
 if (!this->emitGetLocal(PT_Ptr, Offset, E))
   return false;
@@ -1311,16 +1348,63 @@ bool Compiler::VisitVectorBinOp(const 
BinaryOperator *E) {
 return false;
   if (!this->emitPrimCast(PT_Bool, ResultElemT, VecTy->getElementType(), 
E))
 return false;
+} else if (NeedIntPromot) {
+  if (!this->emitPrimCast(ElemT, PromotT, PromotTy, E))
+return false;
 }
 return true;
   };
 
+#define EMIT_ARITH_OP(OP)  
\
+  {
\
+if (ElemT == PT_Float) {   
\
+  if (!this->emit##OP##f(getFPOptions(E), E))  
\
+return false;  
\
+} else {  

[clang] [clang][bytecode] Implement arithmetic, bitwise and compound assignment operator (PR #108949)

2024-09-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (yronglin)


Changes

Implement `+`, `-`, `*`, `/` , `%`, `&`, `|`, `^`, `<<`, `>>` 
and compound assignment operator.

---

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


3 Files Affected:

- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+112-9) 
- (modified) clang/test/AST/ByteCode/constexpr-vectors.cpp (+498-21) 
- (modified) clang/test/SemaCXX/constexpr-vectors.cpp (+1) 


``diff
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 7e0775a51aee61..e7a6df58e6f1a6 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -1267,12 +1267,8 @@ bool Compiler::VisitVectorBinOp(const 
BinaryOperator *E) {
   assert(E->getLHS()->getType()->isVectorType());
   assert(E->getRHS()->getType()->isVectorType());
 
-  // FIXME: Current only support comparison binary operator, add support for
-  // other binary operator.
-  if (!E->isComparisonOp() && !E->isLogicalOp())
-return this->emitInvalid(E);
   // Prepare storage for result.
-  if (!Initializing) {
+  if (!Initializing || E->isCompoundAssignmentOp()) {
 unsigned LocalIndex = allocateTemporary(E);
 if (!this->emitGetPtrLocal(LocalIndex, E))
   return false;
@@ -1281,26 +1277,67 @@ bool Compiler::VisitVectorBinOp(const 
BinaryOperator *E) {
   const Expr *LHS = E->getLHS();
   const Expr *RHS = E->getRHS();
   const auto *VecTy = E->getType()->getAs();
+  auto Op = E->isCompoundAssignmentOp()
+? BinaryOperator::getOpForCompoundAssignment(E->getOpcode())
+: E->getOpcode();
 
   // The LHS and RHS of a comparison operator must have the same type. So we
   // just use LHS vector element type here.
   PrimType ElemT = this->classifyVectorElementType(LHS->getType());
   PrimType ResultElemT = this->classifyVectorElementType(E->getType());
 
-  // Evaluate LHS and save value to LHSOffset.
+  // Allocate a local pointer for LHS and RHS.
   unsigned LHSOffset = this->allocateLocalPrimitive(LHS, PT_Ptr, true, false);
+  unsigned RHSOffset = this->allocateLocalPrimitive(RHS, PT_Ptr, true, false);
+
+  // C++17 onwards require that we evaluate the RHS of the compound
+  // assignment op first.
+  if (E->isCompoundAssignmentOp()) {
+// Evaluate RHS and save value to RHSOffset.
+if (!this->visit(RHS))
+  return false;
+if (!this->emitSetLocal(PT_Ptr, RHSOffset, E))
+  return false;
+
+// Evaluate LHS and save value to LHSOffset.
+if (!this->visit(LHS))
+  return false;
+if (!this->emitSetLocal(PT_Ptr, LHSOffset, E))
+  return false;
+  } else {
+// Evaluate LHS and save value to LHSOffset.
+if (!this->visit(LHS))
+  return false;
+if (!this->emitSetLocal(PT_Ptr, LHSOffset, E))
+  return false;
+
+// Evaluate RHS and save value to RHSOffset.
+if (!this->visit(RHS))
+  return false;
+if (!this->emitSetLocal(PT_Ptr, RHSOffset, E))
+  return false;
+  }
+
+  // Evaluate LHS and save value to LHSOffset.
   if (!this->visit(LHS))
 return false;
   if (!this->emitSetLocal(PT_Ptr, LHSOffset, E))
 return false;
 
   // Evaluate RHS and save value to RHSOffset.
-  unsigned RHSOffset = this->allocateLocalPrimitive(RHS, PT_Ptr, true, false);
   if (!this->visit(RHS))
 return false;
   if (!this->emitSetLocal(PT_Ptr, RHSOffset, E))
 return false;
 
+  // BitAdd/BitOr/BitXor/Shl/Shr doesn't support bool type, we need perform the
+  // integer promotion.
+  bool NeedIntPromot = ElemT == PT_Bool && (E->isBitwiseOp() || 
E->isShiftOp());
+  QualType PromotTy =
+  Ctx.getASTContext().getPromotedIntegerType(Ctx.getASTContext().BoolTy);
+  PrimType PromotT = classifyPrim(PromotTy);
+  PrimType OpT = NeedIntPromot ? PromotT : ElemT;
+
   auto getElem = [=](unsigned Offset, unsigned Index) {
 if (!this->emitGetLocal(PT_Ptr, Offset, E))
   return false;
@@ -1311,16 +1348,63 @@ bool Compiler::VisitVectorBinOp(const 
BinaryOperator *E) {
 return false;
   if (!this->emitPrimCast(PT_Bool, ResultElemT, VecTy->getElementType(), 
E))
 return false;
+} else if (NeedIntPromot) {
+  if (!this->emitPrimCast(ElemT, PromotT, PromotTy, E))
+return false;
 }
 return true;
   };
 
+#define EMIT_ARITH_OP(OP)  
\
+  {
\
+if (ElemT == PT_Float) {   
\
+  if (!this->emit##OP##f(getFPOptions(E), E))  
\
+return false;  
\
+} else {   
\
+  if (!this->emit##OP(ElemT, E))   
\
+return false;   

[clang] [llvm] [X86][AVX10.2] Support AVX10.2 MOVZXC new Instructions. (PR #108537)

2024-09-17 Thread via cfe-commits

https://github.com/mahesh-attarde updated 
https://github.com/llvm/llvm-project/pull/108537

>From d8e76ea27679df40d0c796a5e8e5bc31433b6bff Mon Sep 17 00:00:00 2001
From: mattarde 
Date: Fri, 13 Sep 2024 03:26:14 -0700
Subject: [PATCH 1/6] update clr

---
 clang/lib/Headers/CMakeLists.txt  |  1 +
 clang/lib/Headers/avx10_2copyintrin.h | 34 ++
 clang/lib/Headers/immintrin.h |  1 +
 clang/test/CodeGen/X86/avx512copy-builtins.c  | 17 +
 llvm/lib/Target/X86/X86ISelLowering.cpp   |  5 +-
 llvm/lib/Target/X86/X86InstrAVX10.td  | 64 +++
 .../test/CodeGen/X86/avx512copy-intrinsics.ll | 35 ++
 .../MC/Disassembler/X86/avx10.2-copy-32.txt   | 34 ++
 .../MC/Disassembler/X86/avx10.2-copy-64.txt   | 34 ++
 llvm/test/MC/X86/avx10.2-copy-32-att.s| 17 +
 llvm/test/MC/X86/avx10.2-copy-32-intel.s  | 17 +
 llvm/test/MC/X86/avx10.2-copy-64-att.s| 17 +
 llvm/test/MC/X86/avx10.2-copy-64-intel.s  | 17 +
 llvm/test/TableGen/x86-fold-tables.inc|  2 +
 llvm/utils/TableGen/X86ManualInstrMapping.def |  1 +
 15 files changed, 294 insertions(+), 2 deletions(-)
 create mode 100644 clang/lib/Headers/avx10_2copyintrin.h
 create mode 100644 clang/test/CodeGen/X86/avx512copy-builtins.c
 create mode 100644 llvm/test/CodeGen/X86/avx512copy-intrinsics.ll
 create mode 100644 llvm/test/MC/Disassembler/X86/avx10.2-copy-32.txt
 create mode 100644 llvm/test/MC/Disassembler/X86/avx10.2-copy-64.txt
 create mode 100644 llvm/test/MC/X86/avx10.2-copy-32-att.s
 create mode 100644 llvm/test/MC/X86/avx10.2-copy-32-intel.s
 create mode 100644 llvm/test/MC/X86/avx10.2-copy-64-att.s
 create mode 100644 llvm/test/MC/X86/avx10.2-copy-64-intel.s

diff --git a/clang/lib/Headers/CMakeLists.txt b/clang/lib/Headers/CMakeLists.txt
index a21e3901f63fea..fb55dca0fda405 100644
--- a/clang/lib/Headers/CMakeLists.txt
+++ b/clang/lib/Headers/CMakeLists.txt
@@ -155,6 +155,7 @@ set(x86_files
   avx10_2_512satcvtintrin.h
   avx10_2bf16intrin.h
   avx10_2convertintrin.h
+  avx10_2copyintrin.h
   avx10_2minmaxintrin.h
   avx10_2niintrin.h
   avx10_2satcvtdsintrin.h
diff --git a/clang/lib/Headers/avx10_2copyintrin.h 
b/clang/lib/Headers/avx10_2copyintrin.h
new file mode 100644
index 00..13e76c6abe8993
--- /dev/null
+++ b/clang/lib/Headers/avx10_2copyintrin.h
@@ -0,0 +1,34 @@
+/*=== avx10_2copyintrin.h - AVX10.2 Copy intrinsics ---===
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ *===---===
+ */
+#ifndef __IMMINTRIN_H
+#error 
\
+"Never use  directly; include  instead."
+#endif // __IMMINTRIN_H
+
+#ifndef __AVX10_2COPYINTRIN_H
+#define __AVX10_2COPYINTRIN_H
+
+/* Define the default attributes for the functions in this file. */
+#define __DEFAULT_FN_ATTRS128  
\
+  __attribute__((__always_inline__, __nodebug__, __target__("avx10.2-256"),
\
+ __min_vector_width__(128)))
+
+static __inline__ __m128i __DEFAULT_FN_ATTRS128 _mm_move_epi32(__m128i __A) {
+  return (__m128i)__builtin_shufflevector(
+  (__v4si)__A, (__v4si)_mm_setzero_si128(), 0, 4, 4, 4);
+}
+
+static __inline__ __m128i __DEFAULT_FN_ATTRS128 _mm_move_epi16(__m128i __A) {
+  return (__m128i)__builtin_shufflevector(
+  (__v8hi)__A, (__v8hi)_mm_setzero_si128(), 0, 8, 8, 8, 8, 8, 8, 8);
+}
+
+#undef __DEFAULT_FN_ATTRS128
+
+#endif // __AVX10_2COPYINTRIN_H
\ No newline at end of file
diff --git a/clang/lib/Headers/immintrin.h b/clang/lib/Headers/immintrin.h
index 280154f3c1026e..3fbabffa98df20 100644
--- a/clang/lib/Headers/immintrin.h
+++ b/clang/lib/Headers/immintrin.h
@@ -651,6 +651,7 @@ _storebe_i64(void * __P, long long __D) {
 #if !defined(__SCE__) || __has_feature(modules) || defined(__AVX10_2__)
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/clang/test/CodeGen/X86/avx512copy-builtins.c 
b/clang/test/CodeGen/X86/avx512copy-builtins.c
new file mode 100644
index 00..06f7507bde53ed
--- /dev/null
+++ b/clang/test/CodeGen/X86/avx512copy-builtins.c
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 %s -flax-vector-conversions=none -ffreestanding 
-triple=x86_64-unknown-unknown -target-feature +avx10.2-512 \
+// RUN: -emit-llvm -o - -Wall -Werror -pedantic -Wno-gnu-statement-expression 
| FileCheck %s
+
+#include 
+#include 
+
+__m128i test_mm_move_epi32(__m128i A) {
+  // CHECK-LABEL: test_mm_move_epi32
+  // CHECK: shufflevector <4 x i32> %{{.*}}, <4 x i32> %{{.*}}, <4 x i32> 
+  return _mm_move_epi32(A);
+}
+
+__m128i test_mm_move_epi16(__m128i A) {
+  // CHECK-LABEL: test_mm_move_epi16
+  // CHECK: shufflevector <8 x i16> %{{.*}}, <8 

[clang] [llvm] [SPIR-V] Add SPIR-V structurizer (PR #107408)

2024-09-17 Thread Vyacheslav Levytskyy via cfe-commits
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= 
Message-ID:
In-Reply-To: 


VyacheslavLevytskyy wrote:

Thank you @Keenuts! I'll check it today against my test suites and get back to 
you. I'd like to to check what's wrong with 
llvm/test/CodeGen/SPIRV/instructions/ret-type.ll very briefly.

Meanwhile one more question, just out of curiosity. Between the pass of 
SPIRVPrepareFunctions.cpp with  its new `sortBlocks(F)` and up to 
SPIRVEmitIntrinsicsPass, just before IRTranslator, we should see a lot of 
optimization going on when we run with -O1,-O2,-O3. I'm curious how 
`sortBlocks(F)` and other changes would behave when inserted before vs. after 
those optimizations applied? In other words, I wonder what is the best place to 
do this sort of transformation in SPIRV Backend passes and does it depend on 
with/without optimization choice.

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


[clang] b1d7694 - [AArch64] Add missing ACLE predefined macros and update __ARM_ACLE. (#108857)

2024-09-17 Thread via cfe-commits

Author: Alexandros Lamprineas
Date: 2024-09-17T11:07:07+01:00
New Revision: b1d7694c128fd200a23f4494530aa3ae50fa76ce

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

LOG: [AArch64] Add missing ACLE predefined macros and update __ARM_ACLE. 
(#108857)

Adds __ARM_ACLE_VERSION and __FUNCTION_MULTI_VERSIONING_SUPPORT_LEVEL
as defined here https://github.com/ARM-software/acle/pull/301 and
here https://github.com/ARM-software/acle/pull/302.

Also bumps __ARM_ACLE to 202420.

Added: 


Modified: 
clang/lib/Basic/Targets/AArch64.cpp
clang/test/Preprocessor/aarch64-target-features.c
clang/test/Preprocessor/init-aarch64.c

Removed: 




diff  --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index 63fc15f916c558..586e4dd2a21b4e 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -399,7 +399,14 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
   Builder.defineMacro("__AARCH64_CMODEL_" + CodeModel + "__");
 
   // ACLE predefines. Many can only have one possible value on v8 AArch64.
-  Builder.defineMacro("__ARM_ACLE", "200");
+  Builder.defineMacro("__ARM_ACLE_VERSION(year, quarter, patch)",
+  "(100 * (year) + 10 * (quarter) + (patch))");
+#define __ARM_ACLE_VERSION(Y, Q, P) (100 * (Y) + 10 * (Q) + (P))
+  Builder.defineMacro("__ARM_ACLE",
+  std::to_string(__ARM_ACLE_VERSION(2024, 2, 0)));
+  Builder.defineMacro("__FUNCTION_MULTI_VERSIONING_SUPPORT_LEVEL",
+  std::to_string(__ARM_ACLE_VERSION(2024, 2, 0)));
+#undef __ARM_ACLE_VERSION
   Builder.defineMacro("__ARM_ARCH",
   std::to_string(ArchInfo->Version.getMajor()));
   Builder.defineMacro("__ARM_ARCH_PROFILE",

diff  --git a/clang/test/Preprocessor/aarch64-target-features.c 
b/clang/test/Preprocessor/aarch64-target-features.c
index ae2bdda6f536c5..bcc0640c55e35a 100644
--- a/clang/test/Preprocessor/aarch64-target-features.c
+++ b/clang/test/Preprocessor/aarch64-target-features.c
@@ -4,7 +4,6 @@
 // CHECK: __AARCH64EL__ 1
 // CHECK: __ARM_64BIT_STATE 1
 // CHECK-NOT: __ARM_32BIT_STATE
-// CHECK: __ARM_ACLE 200
 // CHECK: __ARM_ALIGN_MAX_STACK_PWR 4
 // CHECK: __ARM_ARCH 8
 // CHECK: __ARM_ARCH_ISA_A64 1

diff  --git a/clang/test/Preprocessor/init-aarch64.c 
b/clang/test/Preprocessor/init-aarch64.c
index 81c9a66f137512..c52c49a94e016e 100644
--- a/clang/test/Preprocessor/init-aarch64.c
+++ b/clang/test/Preprocessor/init-aarch64.c
@@ -12,7 +12,8 @@
 // AARCH64_LE-NEXT: #define __AARCH64EL__ 1
 // AARCH64_LE-NEXT: #define __AARCH64_CMODEL_SMALL__ 1
 // AARCH64-NEXT: #define __ARM_64BIT_STATE 1
-// AARCH64-NEXT: #define __ARM_ACLE 200
+// AARCH64-NEXT: #define __ARM_ACLE 202420
+// AARCH64-NEXT: #define __ARM_ACLE_VERSION(year,quarter,patch) (100 * (year) 
+ 10 * (quarter) + (patch))
 // AARCH64-NEXT: #define __ARM_ALIGN_MAX_STACK_PWR 4
 // AARCH64-NEXT: #define __ARM_ARCH 8
 // AARCH64-NEXT: #define __ARM_ARCH_ISA_A64 1
@@ -121,6 +122,7 @@
 // AARCH64-NEXT: #define __FPCLASS_SNAN 0x0001
 // AARCH64-NEXT: #define __FP_FAST_FMA 1
 // AARCH64-NEXT: #define __FP_FAST_FMAF 1
+// AARCH64-NEXT: #define __FUNCTION_MULTI_VERSIONING_SUPPORT_LEVEL 202420
 // AARCH64-NEXT: #define __GCC_ASM_FLAG_OUTPUTS__ 1
 // AARCH64-NEXT: #define __GCC_CONSTRUCTIVE_SIZE {{.+}}
 // AARCH64-NEXT: #define __GCC_DESTRUCTIVE_SIZE {{.+}}
@@ -393,6 +395,8 @@
 // AARCH64-DARWIN: #define __AARCH64EL__ 1
 // AARCH64-DARWIN-NOT: #define __AARCH_BIG_ENDIAN 1
 // AARCH64-DARWIN: #define __ARM_64BIT_STATE 1
+// AARCH64-DARWIN: #define __ARM_ACLE 202420
+// AARCH64-DARWIN: #define __ARM_ACLE_VERSION(year,quarter,patch) (100 * 
(year) + 10 * (quarter) + (patch))
 // AARCH64-DARWIN: #define __ARM_ARCH 8
 // AARCH64-DARWIN: #define __ARM_ARCH_ISA_A64 1
 // AARCH64-DARWIN-NOT: #define __ARM_BIG_ENDIAN 1
@@ -429,6 +433,7 @@
 // AARCH64-DARWIN: #define __FLT_MIN_EXP__ (-125)
 // AARCH64-DARWIN: #define __FLT_MIN__ 1.17549435e-38F
 // AARCH64-DARWIN: #define __FLT_RADIX__ 2
+// AARCH64-DARWIN: #define __FUNCTION_MULTI_VERSIONING_SUPPORT_LEVEL 202420
 // AARCH64-DARWIN: #define __INT16_C_SUFFIX__
 // AARCH64-DARWIN: #define __INT16_FMTd__ "hd"
 // AARCH64-DARWIN: #define __INT16_FMTi__ "hi"
@@ -588,7 +593,8 @@
 // AARCH64-MSVC: #define _WIN64 1
 // AARCH64-MSVC: #define __AARCH64EL__ 1
 // AARCH64-MSVC: #define __ARM_64BIT_STATE 1
-// AARCH64-MSVC: #define __ARM_ACLE 200
+// AARCH64-MSVC: #define __ARM_ACLE 202420
+// AARCH64-MSVC: #define __ARM_ACLE_VERSION(year,quarter,patch) (100 * (year) 
+ 10 * (quarter) + (patch))
 // AARCH64-MSVC: #define __ARM_ALIGN_MAX_STACK_PWR 4
 // AARCH64-MSVC: #define __ARM_ARCH 8
 // AARCH64-MSVC: #define __ARM_ARCH_ISA_A64 1
@@ -644,6 +650,7 @@
 // AARCH64-MSVC: #define _

[clang] [AArch64] Add missing ACLE predefined macros and update __ARM_ACLE. (PR #108857)

2024-09-17 Thread Alexandros Lamprineas via cfe-commits

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


[clang] [flang] [mlir] [clang][flang][mlir] Support -frecord-command-line option (PR #102975)

2024-09-17 Thread Tarun Prabhu via cfe-commits

https://github.com/tarunprabhu updated 
https://github.com/llvm/llvm-project/pull/102975

>From 4a37cec543f30bb122bf14573fdec8302a0afa3e Mon Sep 17 00:00:00 2001
From: Tarun Prabhu 
Date: Mon, 12 Aug 2024 14:32:08 -0600
Subject: [PATCH 1/5] [clang][flang][mlir] Support -frecord-command-line option

Add support for the -frecord-command-line option that will produce the
llvm.commandline metadata which will eventually be saved in the object file.
This behavior is also supported in clang. Some refactoring of the code in flang
to handle these command line options was carried out. The corresponding
-grecord-command-line option which saves the command line in the debug
information has not yet been enabled for flang.
---
 clang/include/clang/Driver/Options.td | 14 ++--
 clang/lib/Driver/CMakeLists.txt   |  1 +
 clang/lib/Driver/ToolChains/Clang.cpp | 48 ++--
 clang/lib/Driver/ToolChains/CommonUtils.cpp   | 76 +++
 clang/lib/Driver/ToolChains/CommonUtils.h | 44 +++
 clang/lib/Driver/ToolChains/Flang.cpp | 15 
 flang/include/flang/Frontend/CodeGenOptions.h |  3 +
 flang/include/flang/Lower/Bridge.h| 12 ++-
 .../Optimizer/Dialect/Support/FIRContext.h|  6 ++
 flang/lib/Frontend/CompilerInvocation.cpp |  6 ++
 flang/lib/Frontend/FrontendActions.cpp|  2 +-
 flang/lib/Lower/Bridge.cpp|  8 +-
 .../Optimizer/Dialect/Support/FIRContext.cpp  | 16 
 flang/test/Driver/frecord-command-line.f90| 16 
 flang/test/Lower/record-command-line.f90  |  9 +++
 flang/tools/bbc/CMakeLists.txt|  1 +
 flang/tools/bbc/bbc.cpp   | 10 ++-
 .../mlir/Dialect/LLVMIR/LLVMDialect.td|  1 +
 .../include/mlir/Target/LLVMIR/ModuleImport.h |  4 +
 .../mlir/Target/LLVMIR/ModuleTranslation.h|  3 +
 mlir/lib/Target/LLVMIR/ModuleImport.cpp   | 19 +
 mlir/lib/Target/LLVMIR/ModuleTranslation.cpp  | 17 +
 mlir/test/Target/LLVMIR/Import/commandline.ll |  6 ++
 mlir/test/Target/LLVMIR/commandline.mlir  |  6 ++
 24 files changed, 284 insertions(+), 59 deletions(-)
 create mode 100644 clang/lib/Driver/ToolChains/CommonUtils.cpp
 create mode 100644 clang/lib/Driver/ToolChains/CommonUtils.h
 create mode 100644 flang/test/Driver/frecord-command-line.f90
 create mode 100644 flang/test/Lower/record-command-line.f90
 create mode 100644 mlir/test/Target/LLVMIR/Import/commandline.ll
 create mode 100644 mlir/test/Target/LLVMIR/commandline.mlir

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 7f123335ce8cfa..aebcb5f0fbef61 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1994,16 +1994,18 @@ def fparse_all_comments : Flag<["-"], 
"fparse-all-comments">, Group,
   MarshallingInfoFlag>;
 def frecord_command_line : Flag<["-"], "frecord-command-line">,
-  DocBrief<[{Generate a section named ".GCC.command.line" containing the clang
+  DocBrief<[{Generate a section named ".GCC.command.line" containing the
 driver command-line. After linking, the section may contain multiple command
 lines, which will be individually terminated by null bytes. Separate arguments
 within a command line are combined with spaces; spaces and backslashes within 
an
 argument are escaped with backslashes. This format differs from the format of
 the equivalent section produced by GCC with the -frecord-gcc-switches flag.
 This option is currently only supported on ELF targets.}]>,
-  Group;
+  Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def fno_record_command_line : Flag<["-"], "fno-record-command-line">,
-  Group;
+  Group,
+  Visibility<[ClangOption, CLOption, DXCOption, FlangOption]>;
 def : Flag<["-"], "frecord-gcc-switches">, Alias;
 def : Flag<["-"], "fno-record-gcc-switches">, Alias;
 def fcommon : Flag<["-"], "fcommon">, Group,
@@ -7138,6 +7140,9 @@ def mrelocation_model : Separate<["-"], 
"mrelocation-model">,
   NormalizedValues<["Static", "PIC_", "ROPI", "RWPI", "ROPI_RWPI", 
"DynamicNoPIC"]>,
   MarshallingInfoEnum, "PIC_">;
 def debug_info_kind_EQ : Joined<["-"], "debug-info-kind=">;
+def record_command_line : Separate<["-"], "record-command-line">,
+  HelpText<"The string to embed in the .LLVM.command.line section.">,
+  MarshallingInfoString>;
 
 } // let Visibility = [CC1Option, CC1AsOption, FC1Option]
 
@@ -7158,9 +7163,6 @@ def debugger_tuning_EQ : Joined<["-"], 
"debugger-tuning=">,
 def dwarf_debug_flags : Separate<["-"], "dwarf-debug-flags">,
   HelpText<"The string to embed in the Dwarf debug flags record.">,
   MarshallingInfoString>;
-def record_command_line : Separate<["-"], "record-command-line">,
-  HelpText<"The string to embed in the .LLVM.command.line section.">,
-  MarshallingInfoString>;
 def compress_debug_sections_EQ : Joined<["-", "--"], 
"compress-debug-sections=">,
 HelpText<"DWARF debug sections compression type">, 
Values<"none,zlib,zstd">

[clang] [flang] [mlir] [clang][flang][mlir] Support -frecord-command-line option (PR #102975)

2024-09-17 Thread Tarun Prabhu via cfe-commits

tarunprabhu wrote:

Moved code to the `clang::driver::tools` namespace

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


[clang] [compiler-rt] [llvm] [FMV][AArch64] Unify ls64, ls64_v and ls64_accdata. (PR #108024)

2024-09-17 Thread Alexandros Lamprineas via cfe-commits

labrinea wrote:

This may sound like a bad idea in terms of future maintenance, but how about we 
guarded the enum entries I am removing with
`#if __FUNCTION_MULTI_VERSIONING_SUPPORT_LEVEL < __ARM_ACLE_VERSION(2024, 3, 
0)` ?

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


[clang] [llvm] [X86][AVX10.2] Support AVX10.2 MOVZXC new Instructions. (PR #108537)

2024-09-17 Thread Phoebe Wang via cfe-commits

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

LGTM.

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


[clang] [Clang] prevented assertion failure by handling integral to boolean conversions for boolean vectors (PR #108657)

2024-09-17 Thread Oleksandr T. via cfe-commits

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

>From 70d1be2a2a0f2f44cdd70bfb4397e7a36f1c9f30 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Sat, 14 Sep 2024 01:46:28 +0300
Subject: [PATCH 1/2] [Clang] prevented assertion failure by handling integral
 to boolean conversions for boolean vectors

---
 clang/docs/ReleaseNotes.rst| 1 +
 clang/lib/Sema/SemaExpr.cpp| 7 ++-
 clang/test/Sema/ext_vector_casts.c | 5 +
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3929a9fb599259..e9d8d1b789506d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -386,6 +386,7 @@ Bug Fixes to C++ Support
 - Fixed a crash in the typo correction of an invalid CTAD guide. (#GH107887)
 - Fixed a crash when clang tries to subtitute parameter pack while retaining 
the parameter
   pack. #GH63819, #GH107560
+- Fixed an assertion failure by adjusting integral to boolean vector 
conversions (#GH108326)
 
 
 Bug Fixes to AST Handling
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 8f3e15cc9a9bb7..15b233212b770b 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -9868,7 +9868,12 @@ static bool tryVectorConvertAndSplat(Sema &S, ExprResult 
*scalar,
   // if necessary.
   CastKind scalarCast = CK_NoOp;
 
-  if (vectorEltTy->isIntegralType(S.Context)) {
+  if (vectorEltTy->isBooleanType()) {
+if (scalarTy->isIntegralType(S.Context))
+  scalarCast = CK_IntegralToBoolean;
+else if (!scalarTy->isBooleanType())
+  return true;
+  } else if (vectorEltTy->isIntegralType(S.Context)) {
 if (S.getLangOpts().OpenCL && (scalarTy->isRealFloatingType() ||
 (scalarTy->isIntegerType() &&
  S.Context.getIntegerTypeOrder(vectorEltTy, scalarTy) < 0))) {
diff --git a/clang/test/Sema/ext_vector_casts.c 
b/clang/test/Sema/ext_vector_casts.c
index 48440735d88ea9..6338035a61aad6 100644
--- a/clang/test/Sema/ext_vector_casts.c
+++ b/clang/test/Sema/ext_vector_casts.c
@@ -11,6 +11,7 @@ typedef float t3 __attribute__ ((vector_size (16)));
 typedef __typeof__(sizeof(int)) size_t;
 typedef unsigned long ulong2 __attribute__ ((ext_vector_type(2)));
 typedef size_t stride4 __attribute__((ext_vector_type(4)));
+typedef float bool4 __attribute__(( ext_vector_type(4) ));
 
 static void test(void) {
 float2 vec2;
@@ -19,6 +20,7 @@ static void test(void) {
 int4 ivec4;
 short8 ish8;
 t3 vec4_3;
+bool4 bvec4 = 0;
 int *ptr;
 int i;
 
@@ -51,6 +53,9 @@ static void test(void) {
 ivec4 -= ivec4;
 ivec4 |= ivec4;
 ivec4 += ptr; // expected-error {{cannot convert between vector and 
non-scalar values ('int4' (vector of 4 'int' values) and 'int *')}}
+
+bvec4 != 0; // expected-warning {{inequality comparison result unused}} \
+// expected-note {{use '|=' to turn this inequality comparison 
into an or-assignment}}
 }
 
 typedef __attribute__(( ext_vector_type(2) )) float2 vecfloat2; // 
expected-error{{invalid vector element type 'float2' (vector of 2 'float' 
values)}}

>From b7dc3966847429864fc56886370833afd40e38a5 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Tue, 17 Sep 2024 13:36:52 +0300
Subject: [PATCH 2/2] eliminate redundant logic that disallows non-boolean
 scalar casts

---
 clang/lib/Sema/SemaExpr.cpp | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 15b233212b770b..17dd3aeb6e3b6f 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -9868,11 +9868,8 @@ static bool tryVectorConvertAndSplat(Sema &S, ExprResult 
*scalar,
   // if necessary.
   CastKind scalarCast = CK_NoOp;
 
-  if (vectorEltTy->isBooleanType()) {
-if (scalarTy->isIntegralType(S.Context))
-  scalarCast = CK_IntegralToBoolean;
-else if (!scalarTy->isBooleanType())
-  return true;
+  if (vectorEltTy->isBooleanType() && scalarTy->isIntegralType(S.Context)) {
+scalarCast = CK_IntegralToBoolean;
   } else if (vectorEltTy->isIntegralType(S.Context)) {
 if (S.getLangOpts().OpenCL && (scalarTy->isRealFloatingType() ||
 (scalarTy->isIntegerType() &&

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


[clang-tools-extra] [docs][clang-tidy] Correct StrictMode example in modernize-use-std-print (PR #108805)

2024-09-17 Thread Mike Crowe via cfe-commits

https://github.com/mikecrowe commented:

LGTM. Thanks for fixing this.

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


[clang] [Clang] prevented assertion failure by handling integral to boolean conversions for boolean vectors (PR #108657)

2024-09-17 Thread Oleksandr T. via cfe-commits

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

>From 70d1be2a2a0f2f44cdd70bfb4397e7a36f1c9f30 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Sat, 14 Sep 2024 01:46:28 +0300
Subject: [PATCH 1/2] [Clang] prevented assertion failure by handling integral
 to boolean conversions for boolean vectors

---
 clang/docs/ReleaseNotes.rst| 1 +
 clang/lib/Sema/SemaExpr.cpp| 7 ++-
 clang/test/Sema/ext_vector_casts.c | 5 +
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3929a9fb599259..e9d8d1b789506d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -386,6 +386,7 @@ Bug Fixes to C++ Support
 - Fixed a crash in the typo correction of an invalid CTAD guide. (#GH107887)
 - Fixed a crash when clang tries to subtitute parameter pack while retaining 
the parameter
   pack. #GH63819, #GH107560
+- Fixed an assertion failure by adjusting integral to boolean vector 
conversions (#GH108326)
 
 
 Bug Fixes to AST Handling
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 8f3e15cc9a9bb7..15b233212b770b 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -9868,7 +9868,12 @@ static bool tryVectorConvertAndSplat(Sema &S, ExprResult 
*scalar,
   // if necessary.
   CastKind scalarCast = CK_NoOp;
 
-  if (vectorEltTy->isIntegralType(S.Context)) {
+  if (vectorEltTy->isBooleanType()) {
+if (scalarTy->isIntegralType(S.Context))
+  scalarCast = CK_IntegralToBoolean;
+else if (!scalarTy->isBooleanType())
+  return true;
+  } else if (vectorEltTy->isIntegralType(S.Context)) {
 if (S.getLangOpts().OpenCL && (scalarTy->isRealFloatingType() ||
 (scalarTy->isIntegerType() &&
  S.Context.getIntegerTypeOrder(vectorEltTy, scalarTy) < 0))) {
diff --git a/clang/test/Sema/ext_vector_casts.c 
b/clang/test/Sema/ext_vector_casts.c
index 48440735d88ea9..6338035a61aad6 100644
--- a/clang/test/Sema/ext_vector_casts.c
+++ b/clang/test/Sema/ext_vector_casts.c
@@ -11,6 +11,7 @@ typedef float t3 __attribute__ ((vector_size (16)));
 typedef __typeof__(sizeof(int)) size_t;
 typedef unsigned long ulong2 __attribute__ ((ext_vector_type(2)));
 typedef size_t stride4 __attribute__((ext_vector_type(4)));
+typedef float bool4 __attribute__(( ext_vector_type(4) ));
 
 static void test(void) {
 float2 vec2;
@@ -19,6 +20,7 @@ static void test(void) {
 int4 ivec4;
 short8 ish8;
 t3 vec4_3;
+bool4 bvec4 = 0;
 int *ptr;
 int i;
 
@@ -51,6 +53,9 @@ static void test(void) {
 ivec4 -= ivec4;
 ivec4 |= ivec4;
 ivec4 += ptr; // expected-error {{cannot convert between vector and 
non-scalar values ('int4' (vector of 4 'int' values) and 'int *')}}
+
+bvec4 != 0; // expected-warning {{inequality comparison result unused}} \
+// expected-note {{use '|=' to turn this inequality comparison 
into an or-assignment}}
 }
 
 typedef __attribute__(( ext_vector_type(2) )) float2 vecfloat2; // 
expected-error{{invalid vector element type 'float2' (vector of 2 'float' 
values)}}

>From b7dc3966847429864fc56886370833afd40e38a5 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Tue, 17 Sep 2024 13:36:52 +0300
Subject: [PATCH 2/2] eliminate redundant logic that disallows non-boolean
 scalar casts

---
 clang/lib/Sema/SemaExpr.cpp | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 15b233212b770b..17dd3aeb6e3b6f 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -9868,11 +9868,8 @@ static bool tryVectorConvertAndSplat(Sema &S, ExprResult 
*scalar,
   // if necessary.
   CastKind scalarCast = CK_NoOp;
 
-  if (vectorEltTy->isBooleanType()) {
-if (scalarTy->isIntegralType(S.Context))
-  scalarCast = CK_IntegralToBoolean;
-else if (!scalarTy->isBooleanType())
-  return true;
+  if (vectorEltTy->isBooleanType() && scalarTy->isIntegralType(S.Context)) {
+scalarCast = CK_IntegralToBoolean;
   } else if (vectorEltTy->isIntegralType(S.Context)) {
 if (S.getLangOpts().OpenCL && (scalarTy->isRealFloatingType() ||
 (scalarTy->isIntegerType() &&

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


[clang] [analyzer] Indicate UnarySymExpr is not supported by Z3 (PR #108900)

2024-09-17 Thread Donát Nagy via cfe-commits

https://github.com/NagyDonat commented:

Do I understand it correctly that this deficiency affects the standalone Z3 
analysis mode (as opposed to the "Z3 refutation" where the analysis is 
performed with the native range-based constraint manager, and then the results 
are validated with Z3 to discard the logically impossible paths)?

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


[clang] [analyzer] Indicate UnarySymExpr is not supported by Z3 (PR #108900)

2024-09-17 Thread Donát Nagy via cfe-commits


@@ -0,0 +1,16 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify 
%s \
+// RUN:  -analyzer-constraints=z3 
+
+// REQUIRES: Z3
+//
+// This LIT covers a crash associated with this test.
+// The expectation is to not crash!

NagyDonat wrote:

```suggestion
// Previously Z3 analysis crashed when it encountered an UnarySymExpr, validate
// that this no longer happens.
```

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


[clang] [analyzer] Indicate UnarySymExpr is not supported by Z3 (PR #108900)

2024-09-17 Thread Donát Nagy via cfe-commits


@@ -0,0 +1,16 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify 
%s \
+// RUN:  -analyzer-constraints=z3 
+
+// REQUIRES: Z3
+//
+// This LIT covers a crash associated with this test.
+// The expectation is to not crash!
+//
+
+long a;
+void b() {
+  long c;
+  if (~(b && a)) // expected-warning {{address of function 'b' will always 
evaluate to 'true'}}
+  // expected-note@-1 {{prefix with the address-of operator to silence this 
warning}}
+c ^= 0; // expected-warning {{The left expression of the compound 
assignment is an uninitialized value. The computed value will also be garbage}}

NagyDonat wrote:

It would be better to have a simpler testcase, e.g.
```c
// expected-no-diagnostics
int negate(int x) {
  return -x;
}
```
or something similar.

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


[clang] [analyzer] Indicate UnarySymExpr is not supported by Z3 (PR #108900)

2024-09-17 Thread Donát Nagy via cfe-commits

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


[clang] [analyzer] Indicate UnarySymExpr is not supported by Z3 (PR #108900)

2024-09-17 Thread Donát Nagy via cfe-commits

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


[clang] [analyzer] Indicate UnarySymExpr is not supported by Z3 (PR #108900)

2024-09-17 Thread Donát Nagy via cfe-commits

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


[clang] [lldb] [ASTImporter][lldb] Avoid implicit imports in VisitFieldDecl (PR #107828)

2024-09-17 Thread Andrew Savonichev via cfe-commits

asavonic wrote:

> Our idea is summarized in 
> https://discourse.llvm.org/t/rfc-lldb-more-reliable-completion-of-record-types/77442.
>  Basically the goal is to guarantee that a call to `getDefinition`, _will_ 
> fetch the definition. This is something that Clang already does, but we just 
> never implement (via `CompleteRedeclChain`). You're right that the "minimal 
> import" mode was implemented for perf. reasons. Though we should probably 
> revisit this. I think we can make LLDB use non-minimal import for record 
> types while keeping the number of transitive imports contained. It would 
> still require changes to the importer to be smarter about what we import, but 
> we wouldn't have these "complete but incomplete" types floating around.

Thanks a lot Michael. It's a lot of work to get the redesign ready, considering 
both functional and performance requirements.

In the meantime, should we merge this patch to fix at least some current 
problems?


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


[clang] [Clang] prevented assertion failure by handling integral to boolean conversions for boolean vectors (PR #108657)

2024-09-17 Thread Oleksandr T. via cfe-commits


@@ -9868,7 +9868,12 @@ static bool tryVectorConvertAndSplat(Sema &S, ExprResult 
*scalar,
   // if necessary.
   CastKind scalarCast = CK_NoOp;
 
-  if (vectorEltTy->isIntegralType(S.Context)) {
+  if (vectorEltTy->isBooleanType()) {
+if (scalarTy->isIntegralType(S.Context))
+  scalarCast = CK_IntegralToBoolean;
+else if (!scalarTy->isBooleanType())

a-tarasyuk wrote:

@shafik thanks for the feedback. I've removed uncovered cases. The _assertion 
failure_ occurs because `CK_IntegralCast` is used for an implicit cast from a 
`bool` vector...

https://github.com/llvm/llvm-project/blob/b6f72fc1e202c749333bd5b8ecb879d661af16b6/clang/lib/Sema/SemaExpr.cpp#L9880

https://github.com/llvm/llvm-project/blob/b6f72fc1e202c749333bd5b8ecb879d661af16b6/clang/lib/Sema/SemaExpr.cpp#L9901

I found a more specific kind, `CK_IntegralToBoolean`, which seems more relevant 
to this case. However, I couldn’t find any details about this in the spec, so 
I’d appreciate it if someone could clarify this specific case. Is this _kind_ 
not acceptable for this case?

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


[clang] 1e23a61 - [PS4, PS5][Driver] Detangle --sysroot and -isysroot (#107410)

2024-09-17 Thread via cfe-commits

Author: Edd Dawson
Date: 2024-09-17T12:09:38+01:00
New Revision: 1e23a6142a827cda89fa4d8335afebd89701991d

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

LOG: [PS4,PS5][Driver] Detangle --sysroot and -isysroot (#107410)

The following discrepancies concerning `-isysroot` and `--sysroot`
motivated this change:

- The SDK directory can be specified via `-isysroot`, but `--sysroot`
has no influence over this. Yet, we check for the presence of either
switch to determine whether we ought to warn about a missing SDK
*headers*.

- The presence of `-isysroot` is ignored when deciding whether to warn
about missing SDK *libraries*, depsite it being the only switch capable
of specifying a non-default SDK location.

- The `--sysroot`s passed to the PlayStation linkers by the driver are
unrelated to the SDK directory resolved in the PS4PS5Base constructor.

Following this change, we attempt to derive an SDK root from a platform-
specific environment variable. Failing that, we derive it from the location of
the driver. This then becomes the default root directory for both header and
library search. `--sysroot` overrides both search roots. `-isysroot` overrides
only the header search root. If both are specified, `--sysroot` specifies the
library search root and `-isysroot` specifies the header search root.

For each search root that was not overridden, a warning is emitted if expected
header/library search paths are missing inside that root.

The test updates to ps{4,5}-sdk-root.c were of the scale of a rewrite so
I also took the opportunity to clarify the purpose of each part,
eliminate some redundancy and add some missing coverage.

SIE tracker: TOOLCHAIN-16704

Added: 


Modified: 
clang/lib/Driver/ToolChains/PS4CPU.cpp
clang/lib/Driver/ToolChains/PS4CPU.h
clang/test/Driver/ps4-linker.c
clang/test/Driver/ps4-ps5-header-search.c
clang/test/Driver/ps4-sdk-root.c
clang/test/Driver/ps5-linker.c
clang/test/Driver/ps5-sdk-root.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index 48d824171303cc..647580e4e235dc 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -135,8 +135,8 @@ void tools::PS4cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   // handled somewhere else.
   Args.ClaimAllArgs(options::OPT_w);
 
-  if (!D.SysRoot.empty())
-CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
+  CmdArgs.push_back(
+  Args.MakeArgString("--sysroot=" + TC.getSDKLibraryRootDir()));
 
   if (Args.hasArg(options::OPT_pie))
 CmdArgs.push_back("-pie");
@@ -234,8 +234,8 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   // handled somewhere else.
   Args.ClaimAllArgs(options::OPT_w);
 
-  if (!D.SysRoot.empty())
-CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
+  CmdArgs.push_back(
+  Args.MakeArgString("--sysroot=" + TC.getSDKLibraryRootDir()));
 
   // Default to PIE for non-static executables.
   const bool PIE =
@@ -325,46 +325,63 @@ toolchains::PS4PS5Base::PS4PS5Base(const Driver &D, const 
llvm::Triple &Triple,
const ArgList &Args, StringRef Platform,
const char *EnvVar)
 : Generic_ELF(D, Triple, Args) {
-  // Determine where to find the PS4/PS5 libraries.
-  // If -isysroot was passed, use that as the SDK base path.
-  // If not, we use the EnvVar if it exists; otherwise use the driver's
-  // installation path, which should be /host_tools/bin.
+  // Determine the baseline SDK directory from the environment, else
+  // the driver's location, which should be /host_tools/bin.
+  SmallString<128> SDKRootDir;
   SmallString<80> Whence;
-  if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
-SDKRootDir = A->getValue();
-if (!llvm::sys::fs::exists(SDKRootDir))
-  D.Diag(clang::diag::warn_missing_sysroot) << SDKRootDir;
-Whence = A->getSpelling();
-  } else if (const char *EnvValue = getenv(EnvVar)) {
+  if (const char *EnvValue = getenv(EnvVar)) {
 SDKRootDir = EnvValue;
-Whence = { "environment variable '", EnvVar, "'" };
+Whence = {"environment variable '", EnvVar, "'"};
   } else {
 SDKRootDir = D.Dir + "/../../";
 Whence = "compiler's location";
   }
 
-  SmallString<512> SDKIncludeDir(SDKRootDir);
-  llvm::sys::path::append(SDKIncludeDir, "target/include");
-  if (!Args.hasArg(options::OPT_nostdinc) &&
-  !Args.hasArg(options::OPT_nostdlibinc) &&
-  !Args.hasArg(options::OPT_isysroot) &&
-  !Args.hasArg(options::OPT__sysroot_EQ) &&
-  !llvm::sys::fs::exists(SDKIncludeDir)) {
-D.Diag(clang::diag::warn_drv_unable_to_find_directory_ex

[clang] [PS4, PS5][Driver] Detangle --sysroot and -isysroot (PR #107410)

2024-09-17 Thread Edd Dawson via cfe-commits

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


[clang] [llvm] [SPIR-V] Add SPIR-V structurizer (PR #107408)

2024-09-17 Thread Nathan Gauër via cfe-commits

Keenuts wrote:

> I'll check it today against my test suites and get back to you.

Thanks!


> I'm curious how `sortBlocks(F)` and other changes would behave when inserted 
> before vs. after those optimizations applied?

I'm not sure either. I'd be tempted to say we should put the `sortBlock` after 
passes which move blocks around (like the structurizer), but many others should 
be fine (DCE could remove blocks/edges, but shouldn't change the order no?)



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


[clang-tools-extra] [clang-tidy] Add new check bugprone-tagged-union-member-count (PR #89925)

2024-09-17 Thread Kristóf Umann via cfe-commits

Szelethus wrote:

My say doesn't quite have the same weight here are many others, but I see no 
problems with this patch after so many rounds of reviews -- would it be okay to 
merge?

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


[clang] Don't emit int TBAA metadata on more complex FP math libcalls. (PR #107598)

2024-09-17 Thread Zahira Ammarguellat via cfe-commits

https://github.com/zahiraam updated 
https://github.com/llvm/llvm-project/pull/107598

>From 0763f8d25194e18a040d4cd4cde7c88b6fccbb44 Mon Sep 17 00:00:00 2001
From: Zahira Ammarguellat 
Date: Fri, 6 Sep 2024 08:01:25 -0700
Subject: [PATCH 1/7] Don't emit int TBAA metadata on more complex FP math
 libcalls.

---
 clang/lib/CodeGen/CGBuiltin.cpp   | 15 +++--
 .../test/CodeGen/complex-math-libcalls-tbaa.c | 31 +++
 2 files changed, 44 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/CodeGen/complex-math-libcalls-tbaa.c

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index e4d169d2ad6030..a84c9ca4be8a72 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -699,9 +699,20 @@ static RValue emitLibraryCall(CodeGenFunction &CGF, const 
FunctionDecl *FD,
 bool ConstWithoutErrnoAndExceptions =
 Context.BuiltinInfo.isConstWithoutErrnoAndExceptions(BuiltinID);
 // Restrict to target with errno, for example, MacOS doesn't set errno.
-// TODO: Support builtin function with complex type returned, eg: cacosh
+bool CallWithPointerArgsOrPointerReturnType = false;
+if (Call.isScalar()) {
+  if (CallBase *CB = dyn_cast(Call.getScalarVal())) {
+for (Value *A : CB->args())
+  if (A->getType()->isPointerTy())
+CallWithPointerArgsOrPointerReturnType = true;
+CallWithPointerArgsOrPointerReturnType =
+  CallWithPointerArgsOrPointerReturnType ||
+  CB->getFunctionType()->getReturnType()->isPointerTy();
+  }
+}
 if (ConstWithoutErrnoAndExceptions && CGF.CGM.getLangOpts().MathErrno &&
-!CGF.Builder.getIsFPConstrained() && Call.isScalar()) {
+!CGF.Builder.getIsFPConstrained() && Call.isScalar() &&
+!CallWithPointerArgsOrPointerReturnType) {
   // Emit "int" TBAA metadata on FP math libcalls.
   clang::QualType IntTy = Context.IntTy;
   TBAAAccessInfo TBAAInfo = CGF.CGM.getTBAAAccessInfo(IntTy);
diff --git a/clang/test/CodeGen/complex-math-libcalls-tbaa.c 
b/clang/test/CodeGen/complex-math-libcalls-tbaa.c
new file mode 100644
index 00..957dae6361b6f6
--- /dev/null
+++ b/clang/test/CodeGen/complex-math-libcalls-tbaa.c
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 %s -O3  -fmath-errno -emit-llvm -triple 
x86_64-unknown-unknown -o - %s | FileCheck %s -check-prefixes=CHECK
+// RUN: %clang_cc1 %s -O3 -fmath-errno -emit-llvm -triple x86_64-pc-win64 -o - 
%s | FileCheck %s -check-prefixes=CHECK
+// RUN: %clang_cc1 %s -O3 -fmath-errno -emit-llvm -triple i686-unknown-unknown 
-o - %s | FileCheck %s -check-prefixes=CHECK
+// RUN: %clang_cc1 %s -O3 -fmath-errno -emit-llvm -triple 
powerpc-unknown-unknown -o - %s | FileCheck %s -check-prefixes=CHECK-PPC
+// RUN: %clang_cc1 %s -O3 -fmath-errno -emit-llvm -triple 
armv7-none-linux-gnueabi -o - %s | FileCheck %s -check-prefixes=CHECK-TBAA,TBAA
+// RUN: %clang_cc1 %s -O3 -fmath-errno -emit-llvm -triple 
armv7-none-linux-gnueabihf -o - %s | FileCheck %s -check-prefixes=CHECK-ARM,TBAA
+// RUN: %clang_cc1 %s -O3 -fmath-errno -emit-llvm -triple 
thumbv7k-apple-watchos2.0 -o - -target-abi aapcs16 %s | FileCheck %s 
-check-prefixes=CHECK-THUMB,TBAA
+// RUN: %clang_cc1 %s -O3 -fmath-errno -emit-llvm -triple 
aarch64-unknown-unknown -o - %s | FileCheck %s -check-prefixes=CHECK-AARCH,TBAA
+// RUN: %clang_cc1 %s -O3 -fmath-errno -emit-llvm -triple spir -o - %s | 
FileCheck %s -check-prefixes=CHECK-SPIR
+
+_Complex long double foo() {
+  _Complex long double cld;
+  long double v2 = __builtin_cargl(cld);
+  _Complex long double tmp = v2 * cld;
+  return tmp;
+}
+// CHECK: tail call x86_fp80 @cargl(ptr noundef nonnull byval({ {{.*}}, {{.*}} 
})
+// CHECK-PPC: tail call ppc_fp128 @cargl(ptr noundef nonnull byval({ 
ppc_fp128, ppc_fp128 })
+// CHECK-TBAA: tail call double @cargl([2 x i64] noundef undef) 
#[[ATTR1:[0-9]+]], !tbaa [[TBAA3:![0-9]+]]
+
+// CHECK-ARM: tail call double @cargl({ double, double } noundef undef) 
#[[ATTR1:[0-9]+]], !tbaa [[TBAA3:![0-9]+]]
+
+// CHECK-THUMB: tail call double @cargl([2 x double] noundef undef) 
#[[ATTR1:[0-9]+]], !tbaa [[TBAA3:![0-9]+]]
+
+// CHECK-AARCH: tail call fp128 @cargl([2 x fp128] noundef alignstack(16) 
undef) #[[ATTR1:[0-9]+]], !tbaa [[TBAA3:![0-9]+]]
+
+// CHECK-SPIR: tail call spir_func double @cargl(ptr noundef nonnull byval({ 
{{.*}}, {{.*}} })
+
+// TBAA: [[TBAA3]] = !{[[META4:![0-9]+]], [[META4]], i64 0}
+// TBAA: [[META4]] = !{!"int", [[META5:![0-9]+]], i64 0}
+// TBAA: [[META5]] = !{!"omnipotent char", [[META6:![0-9]+]], i64 0}

>From 358407997bee2c218bfc3a7e11704fd3191b8abb Mon Sep 17 00:00:00 2001
From: Zahira Ammarguellat 
Date: Fri, 6 Sep 2024 08:19:17 -0700
Subject: [PATCH 2/7] Fix format.

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

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index a84c9ca4be8a72..3b9d994041ecab 100644
--- a/cl

[clang] 07e0b8a - [ast-matcher] Fixed a crash when traverse lambda expr with invalid captures (#108689)

2024-09-17 Thread via cfe-commits

Author: Congcong Cai
Date: 2024-09-17T20:12:01+08:00
New Revision: 07e0b8a7717aecc1133a08bfe013b58fb4c596f5

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

LOG: [ast-matcher] Fixed a crash when traverse lambda expr with invalid 
captures (#108689)

Fixes: #106444

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/ASTMatchers/ASTMatchFinder.cpp
clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 69b2aea52aa9d3..8228055a1d861a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -506,6 +506,8 @@ AST Matchers
 - Fixed an ordering issue with the `hasOperands` matcher occurring when 
setting a
   binding in the first matcher and using it in the second matcher.
 
+- Fixed a crash when traverse lambda expr with invalid captures. (#GH106444)
+
 clang-format
 
 

diff  --git a/clang/lib/ASTMatchers/ASTMatchFinder.cpp 
b/clang/lib/ASTMatchers/ASTMatchFinder.cpp
index 0bac2ed63a927e..3d01a70395a9bb 100644
--- a/clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -285,12 +285,13 @@ class MatchChildASTVisitor
 ScopedIncrement ScopedDepth(&CurrentDepth);
 
 for (unsigned I = 0, N = Node->capture_size(); I != N; ++I) {
-  const auto *C = Node->capture_begin() + I;
+  const LambdaCapture *C = Node->capture_begin() + I;
   if (!C->isExplicit())
 continue;
   if (Node->isInitCapture(C) && !match(*C->getCapturedVar()))
 return false;
-  if (!match(*Node->capture_init_begin()[I]))
+  const Expr *CIE = Node->capture_init_begin()[I];
+  if (CIE != nullptr && !match(*CIE))
 return false;
 }
 

diff  --git a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
index 028392f499da3b..ec0be27774d8b2 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -5052,6 +5052,19 @@ TEST(ForEachConstructorInitializer, MatchesInitializers) 
{
 cxxConstructorDecl(forEachConstructorInitializer(cxxCtorInitializer();
 }
 
+TEST(LambdaCapture, InvalidLambdaCapture) {
+  // not crash
+  EXPECT_FALSE(matches(
+  R"(int main() {
+struct A { A()=default; A(A const&)=delete; };
+A a; [a]() -> void {}();
+return 0;
+  })",
+  traverse(TK_IgnoreUnlessSpelledInSource,
+   lambdaExpr(has(lambdaCapture(,
+  langCxx11OrLater()));
+}
+
 TEST(ForEachLambdaCapture, MatchesCaptures) {
   EXPECT_TRUE(matches(
   "int main() { int x, y; auto f = [x, y]() { return x + y; }; }",



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


[clang] [ast-matcher] Fixed a crash when traverse lambda expr with invalid captures (PR #108689)

2024-09-17 Thread Congcong Cai via cfe-commits

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


[clang] [compiler-rt] [llvm] [FMV][AArch64] Unify ls64, ls64_v and ls64_accdata. (PR #108024)

2024-09-17 Thread via cfe-commits


@@ -73,8 +73,6 @@ enum CPUFeatures {
   FEAT_SSBS,
   FEAT_SSBS2,
   FEAT_BTI,
-  FEAT_LS64,
-  FEAT_LS64_V,

Wilco1 wrote:

ABI compatibility means you can use different compilers to build object files, 
link them and they work correctly. If object A uses bit 36, object B uses bit 
35 and the runtime uses bit 34, how is it ever going to work?

So using an enum in the implementation is really a bug. The FEAT_xxx bits are 
defined as constants for a good reason. And yes, these are ABI too!

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


[clang] [Clang][AMDGPU] Simplify builtin type definitions. NFC. (PR #108968)

2024-09-17 Thread Jay Foad via cfe-commits

https://github.com/jayfoad created 
https://github.com/llvm/llvm-project/pull/108968

Remove the MangledName field since these types just use the normal Name
for mangling purposes.


>From 97fc6c239af3cadb61fe70cd07bb3b31c5da7a52 Mon Sep 17 00:00:00 2001
From: Jay Foad 
Date: Tue, 17 Sep 2024 12:57:19 +0100
Subject: [PATCH] [Clang][AMDGPU] Simplify builtin type definitions. NFC.

Remove the MangledName field since these types just use the normal Name
for mangling purposes.
---
 clang/include/clang/Basic/AMDGPUTypes.def | 4 ++--
 clang/lib/AST/ASTContext.cpp  | 3 +--
 clang/lib/CodeGen/CGDebugInfo.cpp | 7 +++
 clang/lib/CodeGen/CodeGenTypes.cpp| 3 +--
 4 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/clang/include/clang/Basic/AMDGPUTypes.def 
b/clang/include/clang/Basic/AMDGPUTypes.def
index e0d7be470a3259..7454d61f5dd516 100644
--- a/clang/include/clang/Basic/AMDGPUTypes.def
+++ b/clang/include/clang/Basic/AMDGPUTypes.def
@@ -11,11 +11,11 @@
 
//===--===//
 
 #ifndef AMDGPU_OPAQUE_PTR_TYPE
-#define AMDGPU_OPAQUE_PTR_TYPE(Name, MangledName, AS, Width, Align, Id, 
SingletonId) \
+#define AMDGPU_OPAQUE_PTR_TYPE(Name, AS, Width, Align, Id, SingletonId) \
   AMDGPU_TYPE(Name, Id, SingletonId)
 #endif
 
-AMDGPU_OPAQUE_PTR_TYPE("__amdgpu_buffer_rsrc_t", "__amdgpu_buffer_rsrc_t", 8, 
128, 128, AMDGPUBufferRsrc, AMDGPUBufferRsrcTy)
+AMDGPU_OPAQUE_PTR_TYPE("__amdgpu_buffer_rsrc_t", 8, 128, 128, 
AMDGPUBufferRsrc, AMDGPUBufferRsrcTy)
 
 #undef AMDGPU_TYPE
 #undef AMDGPU_OPAQUE_PTR_TYPE
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 7cc69ca4a8a814..67841a30a571f3 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -2243,8 +2243,7 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const 
{
 Align = 8; 
\
 break;
 #include "clang/Basic/WebAssemblyReferenceTypes.def"
-#define AMDGPU_OPAQUE_PTR_TYPE(NAME, MANGLEDNAME, AS, WIDTH, ALIGN, ID,
\
-   SINGLETONID)
\
+#define AMDGPU_OPAQUE_PTR_TYPE(NAME, AS, WIDTH, ALIGN, ID, SINGLETONID)
\
   case BuiltinType::ID:
\
 Width = WIDTH; 
\
 Align = ALIGN; 
\
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 6c433cf6a85d5e..2d2c280941bd64 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -900,13 +900,12 @@ llvm::DIType *CGDebugInfo::CreateType(const BuiltinType 
*BT) {
 return SingletonId;
\
   }
 #include "clang/Basic/WebAssemblyReferenceTypes.def"
-#define AMDGPU_OPAQUE_PTR_TYPE(Name, MangledName, AS, Width, Align, Id,
\
-   SingletonId)
\
+#define AMDGPU_OPAQUE_PTR_TYPE(Name, AS, Width, Align, Id, SingletonId)
\
   case BuiltinType::Id: {  
\
 if (!SingletonId)  
\
   SingletonId =
\
-  DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,   
\
- MangledName, TheCU, TheCU->getFile(), 0); 
\
+  DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type, Name, 
\
+ TheCU, TheCU->getFile(), 0);  
\
 return SingletonId;
\
   }
 #include "clang/Basic/AMDGPUTypes.def"
diff --git a/clang/lib/CodeGen/CodeGenTypes.cpp 
b/clang/lib/CodeGen/CodeGenTypes.cpp
index d087e714882b33..77c1b27cebf401 100644
--- a/clang/lib/CodeGen/CodeGenTypes.cpp
+++ b/clang/lib/CodeGen/CodeGenTypes.cpp
@@ -558,8 +558,7 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {
   llvm_unreachable("Unexpected wasm reference builtin type!"); 
\
   } break;
 #include "clang/Basic/WebAssemblyReferenceTypes.def"
-#define AMDGPU_OPAQUE_PTR_TYPE(Name, MangledName, AS, Width, Align, Id,
\
-   SingletonId)
\
+#define AMDGPU_OPAQUE_PTR_TYPE(Name, AS, Width, Align, Id, SingletonId)
\
   case BuiltinType::Id:
\
 return llvm::PointerType::get(getLLVMContext(), AS);
 #include "clang/Basic/AMDGPUTypes.def"

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


[clang] [Clang][AMDGPU] Simplify builtin type definitions. NFC. (PR #108968)

2024-09-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-debuginfo

Author: Jay Foad (jayfoad)


Changes

Remove the MangledName field since these types just use the normal Name
for mangling purposes.


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


4 Files Affected:

- (modified) clang/include/clang/Basic/AMDGPUTypes.def (+2-2) 
- (modified) clang/lib/AST/ASTContext.cpp (+1-2) 
- (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+3-4) 
- (modified) clang/lib/CodeGen/CodeGenTypes.cpp (+1-2) 


``diff
diff --git a/clang/include/clang/Basic/AMDGPUTypes.def 
b/clang/include/clang/Basic/AMDGPUTypes.def
index e0d7be470a3259..7454d61f5dd516 100644
--- a/clang/include/clang/Basic/AMDGPUTypes.def
+++ b/clang/include/clang/Basic/AMDGPUTypes.def
@@ -11,11 +11,11 @@
 
//===--===//
 
 #ifndef AMDGPU_OPAQUE_PTR_TYPE
-#define AMDGPU_OPAQUE_PTR_TYPE(Name, MangledName, AS, Width, Align, Id, 
SingletonId) \
+#define AMDGPU_OPAQUE_PTR_TYPE(Name, AS, Width, Align, Id, SingletonId) \
   AMDGPU_TYPE(Name, Id, SingletonId)
 #endif
 
-AMDGPU_OPAQUE_PTR_TYPE("__amdgpu_buffer_rsrc_t", "__amdgpu_buffer_rsrc_t", 8, 
128, 128, AMDGPUBufferRsrc, AMDGPUBufferRsrcTy)
+AMDGPU_OPAQUE_PTR_TYPE("__amdgpu_buffer_rsrc_t", 8, 128, 128, 
AMDGPUBufferRsrc, AMDGPUBufferRsrcTy)
 
 #undef AMDGPU_TYPE
 #undef AMDGPU_OPAQUE_PTR_TYPE
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 7cc69ca4a8a814..67841a30a571f3 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -2243,8 +2243,7 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const 
{
 Align = 8; 
\
 break;
 #include "clang/Basic/WebAssemblyReferenceTypes.def"
-#define AMDGPU_OPAQUE_PTR_TYPE(NAME, MANGLEDNAME, AS, WIDTH, ALIGN, ID,
\
-   SINGLETONID)
\
+#define AMDGPU_OPAQUE_PTR_TYPE(NAME, AS, WIDTH, ALIGN, ID, SINGLETONID)
\
   case BuiltinType::ID:
\
 Width = WIDTH; 
\
 Align = ALIGN; 
\
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 6c433cf6a85d5e..2d2c280941bd64 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -900,13 +900,12 @@ llvm::DIType *CGDebugInfo::CreateType(const BuiltinType 
*BT) {
 return SingletonId;
\
   }
 #include "clang/Basic/WebAssemblyReferenceTypes.def"
-#define AMDGPU_OPAQUE_PTR_TYPE(Name, MangledName, AS, Width, Align, Id,
\
-   SingletonId)
\
+#define AMDGPU_OPAQUE_PTR_TYPE(Name, AS, Width, Align, Id, SingletonId)
\
   case BuiltinType::Id: {  
\
 if (!SingletonId)  
\
   SingletonId =
\
-  DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,   
\
- MangledName, TheCU, TheCU->getFile(), 0); 
\
+  DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type, Name, 
\
+ TheCU, TheCU->getFile(), 0);  
\
 return SingletonId;
\
   }
 #include "clang/Basic/AMDGPUTypes.def"
diff --git a/clang/lib/CodeGen/CodeGenTypes.cpp 
b/clang/lib/CodeGen/CodeGenTypes.cpp
index d087e714882b33..77c1b27cebf401 100644
--- a/clang/lib/CodeGen/CodeGenTypes.cpp
+++ b/clang/lib/CodeGen/CodeGenTypes.cpp
@@ -558,8 +558,7 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {
   llvm_unreachable("Unexpected wasm reference builtin type!"); 
\
   } break;
 #include "clang/Basic/WebAssemblyReferenceTypes.def"
-#define AMDGPU_OPAQUE_PTR_TYPE(Name, MangledName, AS, Width, Align, Id,
\
-   SingletonId)
\
+#define AMDGPU_OPAQUE_PTR_TYPE(Name, AS, Width, Align, Id, SingletonId)
\
   case BuiltinType::Id:
\
 return llvm::PointerType::get(getLLVMContext(), AS);
 #include "clang/Basic/AMDGPUTypes.def"

``




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


[clang] [Clang][AMDGPU] Simplify builtin type definitions. NFC. (PR #108968)

2024-09-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Jay Foad (jayfoad)


Changes

Remove the MangledName field since these types just use the normal Name
for mangling purposes.


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


4 Files Affected:

- (modified) clang/include/clang/Basic/AMDGPUTypes.def (+2-2) 
- (modified) clang/lib/AST/ASTContext.cpp (+1-2) 
- (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+3-4) 
- (modified) clang/lib/CodeGen/CodeGenTypes.cpp (+1-2) 


``diff
diff --git a/clang/include/clang/Basic/AMDGPUTypes.def 
b/clang/include/clang/Basic/AMDGPUTypes.def
index e0d7be470a3259..7454d61f5dd516 100644
--- a/clang/include/clang/Basic/AMDGPUTypes.def
+++ b/clang/include/clang/Basic/AMDGPUTypes.def
@@ -11,11 +11,11 @@
 
//===--===//
 
 #ifndef AMDGPU_OPAQUE_PTR_TYPE
-#define AMDGPU_OPAQUE_PTR_TYPE(Name, MangledName, AS, Width, Align, Id, 
SingletonId) \
+#define AMDGPU_OPAQUE_PTR_TYPE(Name, AS, Width, Align, Id, SingletonId) \
   AMDGPU_TYPE(Name, Id, SingletonId)
 #endif
 
-AMDGPU_OPAQUE_PTR_TYPE("__amdgpu_buffer_rsrc_t", "__amdgpu_buffer_rsrc_t", 8, 
128, 128, AMDGPUBufferRsrc, AMDGPUBufferRsrcTy)
+AMDGPU_OPAQUE_PTR_TYPE("__amdgpu_buffer_rsrc_t", 8, 128, 128, 
AMDGPUBufferRsrc, AMDGPUBufferRsrcTy)
 
 #undef AMDGPU_TYPE
 #undef AMDGPU_OPAQUE_PTR_TYPE
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 7cc69ca4a8a814..67841a30a571f3 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -2243,8 +2243,7 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const 
{
 Align = 8; 
\
 break;
 #include "clang/Basic/WebAssemblyReferenceTypes.def"
-#define AMDGPU_OPAQUE_PTR_TYPE(NAME, MANGLEDNAME, AS, WIDTH, ALIGN, ID,
\
-   SINGLETONID)
\
+#define AMDGPU_OPAQUE_PTR_TYPE(NAME, AS, WIDTH, ALIGN, ID, SINGLETONID)
\
   case BuiltinType::ID:
\
 Width = WIDTH; 
\
 Align = ALIGN; 
\
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 6c433cf6a85d5e..2d2c280941bd64 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -900,13 +900,12 @@ llvm::DIType *CGDebugInfo::CreateType(const BuiltinType 
*BT) {
 return SingletonId;
\
   }
 #include "clang/Basic/WebAssemblyReferenceTypes.def"
-#define AMDGPU_OPAQUE_PTR_TYPE(Name, MangledName, AS, Width, Align, Id,
\
-   SingletonId)
\
+#define AMDGPU_OPAQUE_PTR_TYPE(Name, AS, Width, Align, Id, SingletonId)
\
   case BuiltinType::Id: {  
\
 if (!SingletonId)  
\
   SingletonId =
\
-  DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,   
\
- MangledName, TheCU, TheCU->getFile(), 0); 
\
+  DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type, Name, 
\
+ TheCU, TheCU->getFile(), 0);  
\
 return SingletonId;
\
   }
 #include "clang/Basic/AMDGPUTypes.def"
diff --git a/clang/lib/CodeGen/CodeGenTypes.cpp 
b/clang/lib/CodeGen/CodeGenTypes.cpp
index d087e714882b33..77c1b27cebf401 100644
--- a/clang/lib/CodeGen/CodeGenTypes.cpp
+++ b/clang/lib/CodeGen/CodeGenTypes.cpp
@@ -558,8 +558,7 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {
   llvm_unreachable("Unexpected wasm reference builtin type!"); 
\
   } break;
 #include "clang/Basic/WebAssemblyReferenceTypes.def"
-#define AMDGPU_OPAQUE_PTR_TYPE(Name, MangledName, AS, Width, Align, Id,
\
-   SingletonId)
\
+#define AMDGPU_OPAQUE_PTR_TYPE(Name, AS, Width, Align, Id, SingletonId)
\
   case BuiltinType::Id:
\
 return llvm::PointerType::get(getLLVMContext(), AS);
 #include "clang/Basic/AMDGPUTypes.def"

``




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


[clang] [HLSL][NFC] Remove RegisterBindingFlags struct (PR #108924)

2024-09-17 Thread Xiang Li via cfe-commits

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


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


[clang] [HLSL][NFC] Update resource attribute tests (PR #108919)

2024-09-17 Thread Xiang Li via cfe-commits


@@ -1,16 +1,25 @@
 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -x hlsl -ast-dump -o 
- %s | FileCheck %s
 
 // CHECK: CXXRecordDecl 0x{{[0-9a-f]+}} {{.*}} struct MyBuffer definition
-// CHECK: FieldDecl 0x{{[0-9a-f]+}}  col:68 h 
'__hlsl_resource_t {{\[\[}}hlsl::resource_class(UAV)]] 
{{\[\[}}hlsl::is_rov]]':'__hlsl_resource_t'
+// CHECK: FieldDecl 0x{{[0-9a-f]+}}  col:68 h 
'__hlsl_resource_t
+// CHECK-SAME{LITERAL}: hlsl::resource_class(UAV)]]
+// CHECK-SAME{LITERAL}: hlsl::is_rov]]
+// CHECK-SAME: ':'__hlsl_resource_t'
 struct MyBuffer {
   __hlsl_resource_t [[hlsl::resource_class(UAV)]] [[hlsl::is_rov]] h;
 };
 
-// CHECK: VarDecl 0x{{[0-9a-f]+}}  col:66 res 
'__hlsl_resource_t {{\[\[}}hlsl::resource_class(SRV)]] 
{{\[\[}}hlsl::is_rov]]':'__hlsl_resource_t'
+// CHECK: VarDecl 0x{{[0-9a-f]+}}  col:66 res 
'__hlsl_resource_t
+// CHECK-SAME{LITERAL}: hlsl::resource_class(SRV)]]
+// CHECK-SAME{LITERAL}: hlsl::is_rov]]
+// CHECK-SAME: ':'__hlsl_resource_t'
 __hlsl_resource_t [[hlsl::is_rov]] [[hlsl::resource_class(SRV)]] res;
 
-// CHECK: FunctionDecl 0x{{[0-9a-f]+}}  line:14:6 f 
'void ()
-// CHECK: VarDecl 0x{{[0-9a-f]+}}  col:72 r '__hlsl_resource_t 
{{\[\[}}hlsl::resource_class(Sampler)]] 
{{\[\[}}hlsl::is_rov]]':'__hlsl_resource_t'
+// CHECK: FunctionDecl 0x{{[0-9a-f]+}}  line:[[# @LINE + 5]]:6 f 'void ()
+// CHECK: VarDecl 0x{{[0-9a-f]+}}  col:72 r '__hlsl_resource_t
+// CHECK-SAME{LITERAL}: hlsl::resource_class(Sampler)]]

python3kgae wrote:

Why some time we check with the `[[` like `[[hlsl::resource_class(Sampler)]]`, 
sometime don't?

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


[clang] [HLSL][NFC] Update resource attribute tests (PR #108919)

2024-09-17 Thread Xiang Li via cfe-commits

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


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


[clang] [llvm] [AMDGPU] Change CF intrinsics lowering to reconverge on predecessors (PR #108596)

2024-09-17 Thread via cfe-commits

alex-t wrote:

> Thank you for going into a bit more detail. It does seem like distinguishing 
> between SGPR reloads and VGPR reloads would help.
> 
> Hmm, what about a case where we run out of VGPRs to spill SGPRs into? What do 
> we actually do in that case today?

Not sure if I understand your concern. We allocate SGPRs in a separate pass 
before VGPRs. So, we have the whole amount of VGPRs available on a given target 
to spill SGPRs. I hardly can imagine a kernel that requires 256x32 SGPRs.

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


[clang] [clang][codegen] Don't mark "int" TBAA on FP libcalls with indirect args (PR #108853)

2024-09-17 Thread Zahira Ammarguellat via cfe-commits

zahiraam wrote:

> > How does this interact with #107598?
> 
>Though this also changes things to ensure when TBAA data is set, it's always 
>set on the call.

Wasn't already doing that? (setting the TBAA on the call?).

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


[clang] [Clang] Add and use mangleVendorType helper. NFC. (PR #108970)

2024-09-17 Thread Jay Foad via cfe-commits

https://github.com/jayfoad created 
https://github.com/llvm/llvm-project/pull/108970

None

>From 9c2e1d8470b7b1a0647baece8fa41cf8ce7b4f5d Mon Sep 17 00:00:00 2001
From: Jay Foad 
Date: Tue, 17 Sep 2024 13:28:11 +0100
Subject: [PATCH] [Clang] Add and use mangleVendorType helper. NFC.

---
 clang/lib/AST/ItaniumMangle.cpp | 52 +++--
 1 file changed, 24 insertions(+), 28 deletions(-)

diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index b6e1da0c3192da..ef8e91b7cbdf9f 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -468,6 +468,7 @@ class CXXNameMangler {
   void mangleLambdaSig(const CXXRecordDecl *Lambda);
   void mangleModuleNamePrefix(StringRef Name, bool IsPartition = false);
   void mangleVendorQualifier(StringRef Name);
+  void mangleVendorType(StringRef Name);
 
 private:
 
@@ -2871,6 +2872,10 @@ void CXXNameMangler::mangleVendorQualifier(StringRef 
name) {
   Out << 'U' << name.size() << name;
 }
 
+void CXXNameMangler::mangleVendorType(StringRef name) {
+  Out << 'u' << name.size() << name;
+}
+
 void CXXNameMangler::mangleRefQualifier(RefQualifierKind RefQualifier) {
   //  ::= R# lvalue reference
   // ::= O# rvalue-reference
@@ -3389,8 +3394,7 @@ void CXXNameMangler::mangleType(const BuiltinType *T) {
 if (T->getKind() == BuiltinType::SveBFloat16 &&
\
 isCompatibleWith(LangOptions::ClangABI::Ver17)) {  
\
   /* Prior to Clang 18.0 we used this incorrect mangled name */
\
-  type_name = "__SVBFloat16_t";
\
-  Out << "u" << type_name.size() << type_name; 
\
+  mangleVendorType("__SVBFloat16_t");  
\
 } else {   
\
   type_name = MangledName; 
\
   Out << (type_name == Name ? "u" : "") << type_name.size() << type_name;  
\
@@ -3407,35 +3411,30 @@ void CXXNameMangler::mangleType(const BuiltinType *T) {
 Out << (type_name == Name ? "u" : "") << type_name.size() << type_name;
\
 break;
 #include "clang/Basic/AArch64SVEACLETypes.def"
-#define PPC_VECTOR_TYPE(Name, Id, Size) \
-  case BuiltinType::Id: \
-type_name = #Name; \
-Out << 'u' << type_name.size() << type_name; \
+#define PPC_VECTOR_TYPE(Name, Id, Size)
\
+  case BuiltinType::Id:
\
+mangleVendorType(#Name);   
\
 break;
 #include "clang/Basic/PPCTypes.def"
 // TODO: Check the mangling scheme for RISC-V V.
 #define RVV_TYPE(Name, Id, SingletonId)
\
   case BuiltinType::Id:
\
-type_name = Name;  
\
-Out << 'u' << type_name.size() << type_name;   
\
+mangleVendorType(Name);
\
 break;
 #include "clang/Basic/RISCVVTypes.def"
 #define WASM_REF_TYPE(InternalName, MangledName, Id, SingletonId, AS)  
\
   case BuiltinType::Id:
\
-type_name = MangledName;   
\
-Out << 'u' << type_name.size() << type_name;   
\
+mangleVendorType(MangledName); 
\
 break;
 #include "clang/Basic/WebAssemblyReferenceTypes.def"
 #define AMDGPU_TYPE(Name, Id, SingletonId) 
\
   case BuiltinType::Id:
\
-type_name = Name;  
\
-Out << 'u' << type_name.size() << type_name;   
\
+mangleVendorType(Name);
\
 break;
 #include "clang/Basic/AMDGPUTypes.def"
 #define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId)
\
   case BuiltinType::Id:
\
-type_name = #Name; 
\
-Out << 'u' << type_name.size() << type_name;   
\
+mangleVendorType(#Name);   
\
 break;
 #include "clang/Basic/HLSLIntangibleTypes.def"
   }
@@ -4006,8 +4005,9 @@ void 
CXXNameMangler::mangleAArch64FixedSveVectorType(const VectorType *T) {
   if (T->getVectorKind() == VectorKind::SveFixedLengthPredicate)
 VecSizeInBits *= 8;
 
-  Out << "9__SVE_VLSI" << 'u' << TypeName.size() << TypeName << 

[clang] [Clang] Add and use mangleVendorType helper. NFC. (PR #108970)

2024-09-17 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Jay Foad (jayfoad)


Changes



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


1 Files Affected:

- (modified) clang/lib/AST/ItaniumMangle.cpp (+24-28) 


``diff
diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index b6e1da0c3192da..ef8e91b7cbdf9f 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -468,6 +468,7 @@ class CXXNameMangler {
   void mangleLambdaSig(const CXXRecordDecl *Lambda);
   void mangleModuleNamePrefix(StringRef Name, bool IsPartition = false);
   void mangleVendorQualifier(StringRef Name);
+  void mangleVendorType(StringRef Name);
 
 private:
 
@@ -2871,6 +2872,10 @@ void CXXNameMangler::mangleVendorQualifier(StringRef 
name) {
   Out << 'U' << name.size() << name;
 }
 
+void CXXNameMangler::mangleVendorType(StringRef name) {
+  Out << 'u' << name.size() << name;
+}
+
 void CXXNameMangler::mangleRefQualifier(RefQualifierKind RefQualifier) {
   //  ::= R# lvalue reference
   // ::= O# rvalue-reference
@@ -3389,8 +3394,7 @@ void CXXNameMangler::mangleType(const BuiltinType *T) {
 if (T->getKind() == BuiltinType::SveBFloat16 &&
\
 isCompatibleWith(LangOptions::ClangABI::Ver17)) {  
\
   /* Prior to Clang 18.0 we used this incorrect mangled name */
\
-  type_name = "__SVBFloat16_t";
\
-  Out << "u" << type_name.size() << type_name; 
\
+  mangleVendorType("__SVBFloat16_t");  
\
 } else {   
\
   type_name = MangledName; 
\
   Out << (type_name == Name ? "u" : "") << type_name.size() << type_name;  
\
@@ -3407,35 +3411,30 @@ void CXXNameMangler::mangleType(const BuiltinType *T) {
 Out << (type_name == Name ? "u" : "") << type_name.size() << type_name;
\
 break;
 #include "clang/Basic/AArch64SVEACLETypes.def"
-#define PPC_VECTOR_TYPE(Name, Id, Size) \
-  case BuiltinType::Id: \
-type_name = #Name; \
-Out << 'u' << type_name.size() << type_name; \
+#define PPC_VECTOR_TYPE(Name, Id, Size)
\
+  case BuiltinType::Id:
\
+mangleVendorType(#Name);   
\
 break;
 #include "clang/Basic/PPCTypes.def"
 // TODO: Check the mangling scheme for RISC-V V.
 #define RVV_TYPE(Name, Id, SingletonId)
\
   case BuiltinType::Id:
\
-type_name = Name;  
\
-Out << 'u' << type_name.size() << type_name;   
\
+mangleVendorType(Name);
\
 break;
 #include "clang/Basic/RISCVVTypes.def"
 #define WASM_REF_TYPE(InternalName, MangledName, Id, SingletonId, AS)  
\
   case BuiltinType::Id:
\
-type_name = MangledName;   
\
-Out << 'u' << type_name.size() << type_name;   
\
+mangleVendorType(MangledName); 
\
 break;
 #include "clang/Basic/WebAssemblyReferenceTypes.def"
 #define AMDGPU_TYPE(Name, Id, SingletonId) 
\
   case BuiltinType::Id:
\
-type_name = Name;  
\
-Out << 'u' << type_name.size() << type_name;   
\
+mangleVendorType(Name);
\
 break;
 #include "clang/Basic/AMDGPUTypes.def"
 #define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId)
\
   case BuiltinType::Id:
\
-type_name = #Name; 
\
-Out << 'u' << type_name.size() << type_name;   
\
+mangleVendorType(#Name);   
\
 break;
 #include "clang/Basic/HLSLIntangibleTypes.def"
   }
@@ -4006,8 +4005,9 @@ void 
CXXNameMangler::mangleAArch64FixedSveVectorType(const VectorType *T) {
   if (T->getVectorKind() == VectorKind::SveFixedLengthPredicate)
 VecSizeInBits *= 8;
 
-  Out << "9__SVE_VLSI" << 'u' << TypeName.size() << TypeName << "Lj"
-  << VecSizeInBits << "EE";
+  Out << "9__SVE_VLSI";
+  mangleVendorType(TypeName);
+  Out << "Lj" << VecSizeInBits << "EE";
 }
 
 void CXXNameMangler::man

[clang] [llvm] [AMDGPU] Convert AMDGPUResourceUsageAnalysis pass from Module to MF pass (PR #102913)

2024-09-17 Thread Janek van Oirschot via cfe-commits


@@ -40,12 +42,19 @@ class AMDGPUAsmPrinter final : public AsmPrinter {
 
   AMDGPUResourceUsageAnalysis *ResourceUsage;
 
+  MCResourceInfo RI;
+
   SIProgramInfo CurrentProgramInfo;
 
   std::unique_ptr HSAMetadataStream;
 
   MCCodeEmitter *DumpCodeInstEmitter = nullptr;
 
+  // validateMCResourceInfo cannot recompute parts of the occupancy as it does
+  // for other metadata to validate (e.g., NumSGPRs) so a map is necessary if 
we
+  // really want to track and validate the occupancy.

JanekvO wrote:

Yeah, I thought I needed access to the `MachineFunction` for 
`SIMachineFunctionInfo` but I can reconstruct it using just the `Function` and 
`GCNSubTarget`. It now recomputes the occupancy instead of this caching.

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


[clang] [clang][codegen] Don't mark "int" TBAA on FP libcalls with indirect args (PR #108853)

2024-09-17 Thread Benjamin Maxwell via cfe-commits

MacDue wrote:

> > > How does this interact with #107598?
> > 
> > 
> > Though this also changes things to ensure when TBAA data is set, it's 
> > always set on the call.
> 
> Wasn't already doing that? (setting the TBAA on the call?).

It was setting it on `cast(Call.getScalarVal());` not the 
call (which you can get via an output on `EmitCall()`). At least in this case 
that meant it was putting the TBAA metadata on the `load x86_fp80` after the 
call. I'm not sure if there's other cases where something similar could happen. 


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


[clang] [llvm] [AMDGPU] Convert AMDGPUResourceUsageAnalysis pass from Module to MF pass (PR #102913)

2024-09-17 Thread Janek van Oirschot via cfe-commits


@@ -0,0 +1,225 @@
+//===- AMDGPUMCResourceInfo.cpp --- MC Resource Info 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+/// \file
+/// \brief MC infrastructure to propagate the function level resource usage
+/// info.
+///
+//===--===//
+
+#include "AMDGPUMCResourceInfo.h"
+#include "Utils/AMDGPUBaseInfo.h"
+#include "llvm/ADT/SmallSet.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/MC/MCContext.h"
+#include "llvm/MC/MCSymbol.h"
+
+using namespace llvm;
+
+MCSymbol *MCResourceInfo::getSymbol(StringRef FuncName, ResourceInfoKind RIK,
+MCContext &OutContext) {
+  auto GOCS = [this, FuncName, &OutContext](StringRef Suffix) {
+return OutContext.getOrCreateSymbol(FuncName + Twine(Suffix));
+  };
+  switch (RIK) {
+  case RIK_NumVGPR:
+return GOCS(".num_vgpr");
+  case RIK_NumAGPR:
+return GOCS(".num_agpr");
+  case RIK_NumSGPR:
+return GOCS(".numbered_sgpr");
+  case RIK_PrivateSegSize:
+return GOCS(".private_seg_size");
+  case RIK_UsesVCC:
+return GOCS(".uses_vcc");
+  case RIK_UsesFlatScratch:
+return GOCS(".uses_flat_scratch");
+  case RIK_HasDynSizedStack:
+return GOCS(".has_dyn_sized_stack");
+  case RIK_HasRecursion:
+return GOCS(".has_recursion");
+  case RIK_HasIndirectCall:
+return GOCS(".has_indirect_call");
+  }
+  llvm_unreachable("Unexpected ResourceInfoKind.");
+}
+
+const MCExpr *MCResourceInfo::getSymRefExpr(StringRef FuncName,
+ResourceInfoKind RIK,
+MCContext &Ctx) {
+  return MCSymbolRefExpr::create(getSymbol(FuncName, RIK, Ctx), Ctx);
+}
+
+void MCResourceInfo::assignMaxRegs(MCContext &OutContext) {
+  // Assign expression to get the max register use to the max_num_Xgpr symbol.
+  MCSymbol *MaxVGPRSym = getMaxVGPRSymbol(OutContext);
+  MCSymbol *MaxAGPRSym = getMaxAGPRSymbol(OutContext);
+  MCSymbol *MaxSGPRSym = getMaxSGPRSymbol(OutContext);
+
+  auto assignMaxRegSym = [this, &OutContext](MCSymbol *Sym, int32_t RegCount) {
+const MCExpr *MaxExpr = MCConstantExpr::create(RegCount, OutContext);
+Sym->setVariableValue(MaxExpr);
+  };
+
+  assignMaxRegSym(MaxVGPRSym, MaxVGPR);
+  assignMaxRegSym(MaxAGPRSym, MaxAGPR);
+  assignMaxRegSym(MaxSGPRSym, MaxSGPR);
+}
+
+void MCResourceInfo::finalize(MCContext &OutContext) {
+  assert(!Finalized && "Cannot finalize ResourceInfo again.");
+  Finalized = true;
+  assignMaxRegs(OutContext);
+}
+
+MCSymbol *MCResourceInfo::getMaxVGPRSymbol(MCContext &OutContext) {
+  return OutContext.getOrCreateSymbol("max_num_vgpr");
+}
+
+MCSymbol *MCResourceInfo::getMaxAGPRSymbol(MCContext &OutContext) {
+  return OutContext.getOrCreateSymbol("max_num_agpr");
+}
+
+MCSymbol *MCResourceInfo::getMaxSGPRSymbol(MCContext &OutContext) {
+  return OutContext.getOrCreateSymbol("max_num_sgpr");
+}

JanekvO wrote:

I've put these in their own section for now, albeit without any module-unique 
identifiers (`.AMDGPU.gpr_maximums`).

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


[clang] [clang] check deduction consistency when partial ordering function templates (PR #100692)

2024-09-17 Thread Alexander Kornienko via cfe-commits

alexfh wrote:

@mizvekov any news here? I think, I'll come up with two more reduced tests 
later today.

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


[clang] [clang][codegen] Don't mark "int" TBAA on FP libcalls with indirect args (PR #108853)

2024-09-17 Thread Benjamin Maxwell via cfe-commits

https://github.com/MacDue updated 
https://github.com/llvm/llvm-project/pull/108853

>From 6db9f6d56f0bbd56d017156f858eae68653fbd1b Mon Sep 17 00:00:00 2001
From: Benjamin Maxwell 
Date: Mon, 16 Sep 2024 16:27:23 +
Subject: [PATCH 1/3] Precommit math-libcalls-tbaa-indirect-args.c

---
 .../math-libcalls-tbaa-indirect-args.c| 38 +++
 1 file changed, 38 insertions(+)
 create mode 100644 clang/test/CodeGen/math-libcalls-tbaa-indirect-args.c

diff --git a/clang/test/CodeGen/math-libcalls-tbaa-indirect-args.c 
b/clang/test/CodeGen/math-libcalls-tbaa-indirect-args.c
new file mode 100644
index 00..dd013dcc8b3ca8
--- /dev/null
+++ b/clang/test/CodeGen/math-libcalls-tbaa-indirect-args.c
@@ -0,0 +1,38 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// RUN: %clang_cc1 -triple=x86_64-w64-mingw32 -fmath-errno -O3 -emit-llvm -o - 
%s | FileCheck %s -check-prefixes=CHECK
+
+long double powl(long double a, long double b);
+
+// Negative test: powl is a floating-point math function that is
+// ConstWithoutErrnoAndExceptions, however, for this target long doubles are
+// passed indirectly via a pointer. Annotating the call with "int" TBAA 
metadata
+// will cause the setup for the BYVAL arguments to be incorrectly optimized 
out.
+
+// CHECK-LABEL: define dso_local void @test_powl(
+// CHECK-SAME: ptr dead_on_unwind noalias nocapture writable writeonly 
sret(x86_fp80) align 16 [[AGG_RESULT:%.*]]) local_unnamed_addr 
#[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:[[TMP:%.*]] = alloca x86_fp80, align 16
+// CHECK-NEXT:[[BYVAL_TEMP:%.*]] = alloca x86_fp80, align 16
+// CHECK-NEXT:[[BYVAL_TEMP1:%.*]] = alloca x86_fp80, align 16
+// CHECK-NEXT:call void @llvm.lifetime.start.p0(i64 16, ptr nonnull 
[[BYVAL_TEMP]]) #[[ATTR3:[0-9]+]]
+// CHECK-NEXT:store x86_fp80 0xK40008000, ptr [[BYVAL_TEMP]], 
align 16, !tbaa [[TBAA3:![0-9]+]]
+// CHECK-NEXT:call void @llvm.lifetime.start.p0(i64 16, ptr nonnull 
[[BYVAL_TEMP1]]) #[[ATTR3]]
+// CHECK-NEXT:store x86_fp80 0xK40008000, ptr [[BYVAL_TEMP1]], 
align 16, !tbaa [[TBAA3]]
+// CHECK-NEXT:call void @powl(ptr dead_on_unwind nonnull writable 
sret(x86_fp80) align 16 [[TMP]], ptr noundef nonnull [[BYVAL_TEMP]], ptr 
noundef nonnull [[BYVAL_TEMP1]]) #[[ATTR3]]
+// CHECK-NEXT:[[TMP0:%.*]] = load x86_fp80, ptr [[TMP]], align 16, !tbaa 
[[TBAA7:![0-9]+]]
+// CHECK-NEXT:call void @llvm.lifetime.end.p0(i64 16, ptr nonnull 
[[BYVAL_TEMP]]) #[[ATTR3]]
+// CHECK-NEXT:call void @llvm.lifetime.end.p0(i64 16, ptr nonnull 
[[BYVAL_TEMP1]]) #[[ATTR3]]
+// CHECK-NEXT:store x86_fp80 [[TMP0]], ptr [[AGG_RESULT]], align 16, !tbaa 
[[TBAA3]]
+// CHECK-NEXT:ret void
+//
+long double test_powl() {
+   return powl(2.0L, 2.0L); // Don't emit TBAA metadata
+}
+//.
+// CHECK: [[TBAA3]] = !{[[META4:![0-9]+]], [[META4]], i64 0}
+// CHECK: [[META4]] = !{!"long double", [[META5:![0-9]+]], i64 0}
+// CHECK: [[META5]] = !{!"omnipotent char", [[META6:![0-9]+]], i64 0}
+// CHECK: [[META6]] = !{!"Simple C/C++ TBAA"}
+// CHECK: [[TBAA7]] = !{[[META8:![0-9]+]], [[META8]], i64 0}
+// CHECK: [[META8]] = !{!"int", [[META5]], i64 0}
+//.

>From 482639f9a8df7785d1b24c723571f477eb5febd7 Mon Sep 17 00:00:00 2001
From: Benjamin Maxwell 
Date: Mon, 16 Sep 2024 16:14:01 +
Subject: [PATCH 2/3] [clang][codegen] Don't mark "int" TBAA on FP libcalls
 with indirect args

On some targets, an FP libcall with argument types such as long double
will be lowered to pass arguments indirectly via pointers. When this is
the case we should not mark the libcall with "int" TBAA as it may lead
to incorrect optimizations.

Currently, this can be seen for long doubles on x86_64-w64-mingw32. The
`load x86_fp80` after the call is (incorrectly) marked with "int" TBAA
(overwriting the previous metadata for "long double").

Nothing seems to break due to this currently as the metadata is being
incorrectly placed on the load and not the call. But if the metadata
is moved to the call (which this patch ensures), LLVM will optimize out
the setup for the arguments.
---
 clang/lib/CodeGen/CGBuiltin.cpp   | 24 +++
 clang/lib/CodeGen/CGExpr.cpp  |  6 -
 clang/lib/CodeGen/CodeGenFunction.h   |  3 ++-
 .../math-libcalls-tbaa-indirect-args.c|  4 +---
 4 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 27abeba92999b3..5730e7867a648f 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -690,23 +690,37 @@ static RValue emitLibraryCall(CodeGenFunction &CGF, const 
FunctionDecl *FD,
   const CallExpr *E, llvm::Constant *calleeValue) {
   CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
   CGCallee callee = CGCallee::forDirect(calleeValue, GlobalDecl(FD));
+  llvm::CallBase *

  1   2   3   4   5   >