[clang] Revert "[AMDGPU][OpenMP] Do not attach -fcuda-is-device flag for AMDGPU OpenMP" (PR #97531)

2024-07-03 Thread Dominik Adamski via cfe-commits

https://github.com/DominikAdamski created 
https://github.com/llvm/llvm-project/pull/97531

Reverts llvm/llvm-project#96909

It breaks CI: 
https://gitlab.e4s.io/uo-public/llvm-openmp-offloading/-/jobs/283716 

>From f165b2279dc663cee7dc31d8213afb8c8fb48ab7 Mon Sep 17 00:00:00 2001
From: Dominik Adamski 
Date: Wed, 3 Jul 2024 09:06:47 +0200
Subject: [PATCH] =?UTF-8?q?Revert=20"[AMDGPU][OpenMP]=20Do=20not=20attach?=
 =?UTF-8?q?=20-fcuda-is-device=20flag=20for=20AMDGPU=20OpenM=E2=80=A6"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This reverts commit 8bb00cb160830ec8f6029c2aae79d3e46b04b99c.
---
 clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp | 2 ++
 clang/test/Driver/amdgpu-openmp-toolchain.c  | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp 
b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
index b75d400e6ce91..1c0fb4babe3a5 100644
--- a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
@@ -47,6 +47,8 @@ void AMDGPUOpenMPToolChain::addClangTargetOptions(
   assert(DeviceOffloadingKind == Action::OFK_OpenMP &&
  "Only OpenMP offloading kinds are supported.");
 
+  CC1Args.push_back("-fcuda-is-device");
+
   if (DriverArgs.hasArg(options::OPT_nogpulib))
 return;
 
diff --git a/clang/test/Driver/amdgpu-openmp-toolchain.c 
b/clang/test/Driver/amdgpu-openmp-toolchain.c
index a153c4afb0ce8..49af04acc4639 100644
--- a/clang/test/Driver/amdgpu-openmp-toolchain.c
+++ b/clang/test/Driver/amdgpu-openmp-toolchain.c
@@ -7,7 +7,7 @@
 
 // verify the tools invocations
 // CHECK: "-cc1" "-triple" 
"x86_64-unknown-linux-gnu"{{.*}}"-emit-llvm-bc"{{.*}}"-x" "c"
-// CHECK: "-cc1" "-triple" "amdgcn-amd-amdhsa" "-aux-triple" 
"x86_64-unknown-linux-gnu"{{.*}}"-target-cpu" "gfx906"
+// CHECK: "-cc1" "-triple" "amdgcn-amd-amdhsa" "-aux-triple" 
"x86_64-unknown-linux-gnu"{{.*}}"-fcuda-is-device"{{.*}}"-target-cpu" "gfx906"
 // CHECK: "-cc1" "-triple" "x86_64-unknown-linux-gnu"{{.*}}"-emit-obj"
 // CHECK: clang-linker-wrapper{{.*}} "-o" "a.out"
 

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


[clang] Revert "[AMDGPU][OpenMP] Do not attach -fcuda-is-device flag for AMDGPU OpenMP" (PR #97531)

2024-07-03 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-clang

Author: Dominik Adamski (DominikAdamski)


Changes

Reverts llvm/llvm-project#96909

It breaks CI: 
https://gitlab.e4s.io/uo-public/llvm-openmp-offloading/-/jobs/283716 

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


2 Files Affected:

- (modified) clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp (+2) 
- (modified) clang/test/Driver/amdgpu-openmp-toolchain.c (+1-1) 


``diff
diff --git a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp 
b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
index b75d400e6ce91..1c0fb4babe3a5 100644
--- a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
@@ -47,6 +47,8 @@ void AMDGPUOpenMPToolChain::addClangTargetOptions(
   assert(DeviceOffloadingKind == Action::OFK_OpenMP &&
  "Only OpenMP offloading kinds are supported.");
 
+  CC1Args.push_back("-fcuda-is-device");
+
   if (DriverArgs.hasArg(options::OPT_nogpulib))
 return;
 
diff --git a/clang/test/Driver/amdgpu-openmp-toolchain.c 
b/clang/test/Driver/amdgpu-openmp-toolchain.c
index a153c4afb0ce8..49af04acc4639 100644
--- a/clang/test/Driver/amdgpu-openmp-toolchain.c
+++ b/clang/test/Driver/amdgpu-openmp-toolchain.c
@@ -7,7 +7,7 @@
 
 // verify the tools invocations
 // CHECK: "-cc1" "-triple" 
"x86_64-unknown-linux-gnu"{{.*}}"-emit-llvm-bc"{{.*}}"-x" "c"
-// CHECK: "-cc1" "-triple" "amdgcn-amd-amdhsa" "-aux-triple" 
"x86_64-unknown-linux-gnu"{{.*}}"-target-cpu" "gfx906"
+// CHECK: "-cc1" "-triple" "amdgcn-amd-amdhsa" "-aux-triple" 
"x86_64-unknown-linux-gnu"{{.*}}"-fcuda-is-device"{{.*}}"-target-cpu" "gfx906"
 // CHECK: "-cc1" "-triple" "x86_64-unknown-linux-gnu"{{.*}}"-emit-obj"
 // CHECK: clang-linker-wrapper{{.*}} "-o" "a.out"
 

``




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


[clang] [Clang] [WIP] Added builtin_alloca right Address Space for OpenCL (PR #95750)

2024-07-03 Thread Vikash Gupta via cfe-commits

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


[clang] [clang-format] Add BinPackBinaryOperations configuration (PR #95013)

2024-07-03 Thread Björn Schäpers via cfe-commits

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


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


[clang] [clang] Define ATOMIC_FLAG_INIT correctly for C++. (PR #97534)

2024-07-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Chris Copeland (chrisnc)


Changes



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


2 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/lib/Headers/stdatomic.h (+4) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1537eaaba0c66..3d85065a7ff8a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -750,6 +750,8 @@ Bug Fixes in This Version
 
 - Fixed `static_cast` to array of unknown bound. Fixes (#GH62863).
 
+- Fixed the definition of ATOMIC_FLAG_INIT in stdatomic.h so it can be used in 
C++.
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/lib/Headers/stdatomic.h b/clang/lib/Headers/stdatomic.h
index 9c103d98af8c5..88172038be5c4 100644
--- a/clang/lib/Headers/stdatomic.h
+++ b/clang/lib/Headers/stdatomic.h
@@ -166,7 +166,11 @@ typedef _Atomic(uintmax_t)  atomic_uintmax_t;
 
 typedef struct atomic_flag { atomic_bool _Value; } atomic_flag;
 
+#ifdef __cplusplus
+#define ATOMIC_FLAG_INIT { false }
+#else
 #define ATOMIC_FLAG_INIT { 0 }
+#endif
 
 /* These should be provided by the libc implementation. */
 #ifdef __cplusplus

``




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


[clang] [llvm] Assume (PR #97535)

2024-07-03 Thread via cfe-commits

https://github.com/SunilKuravinakop created 
https://github.com/llvm/llvm-project/pull/97535

Support for assume directive : Parse and AST modules

>From a331d2343a43a9ca2030ef07a25ca93ff26a5778 Mon Sep 17 00:00:00 2001
From: Sunil Kuravinakop 
Date: Mon, 1 Jul 2024 03:29:45 -0500
Subject: [PATCH 1/2] Support for "#pragma omp assume" Directive in Parse and
 AST.

  Changes to be committed:
modified:   clang/include/clang/Parse/Parser.h
modified:   clang/include/clang/Sema/Sema.h
modified:   clang/lib/Basic/OpenMPKinds.cpp
modified:   clang/lib/Parse/ParseOpenMP.cpp
modified:   clang/lib/Sema/SemaOpenMP.cpp
modified:   llvm/include/llvm/Frontend/OpenMP/OMP.td
---
 clang/include/clang/Parse/Parser.h   |  4 +-
 clang/include/clang/Sema/Sema.h  |  3 ++
 clang/lib/Basic/OpenMPKinds.cpp  |  3 ++
 clang/lib/Parse/ParseOpenMP.cpp  | 33 +++-
 clang/lib/Sema/SemaOpenMP.cpp| 67 +++-
 llvm/include/llvm/Frontend/OpenMP/OMP.td |  3 ++
 6 files changed, 108 insertions(+), 5 deletions(-)

diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 5950dd74cfe83..7568c053eb77f 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -3380,8 +3380,8 @@ class Parser : public CodeCompletionHandler {
  SourceLocation Loc);
 
   /// Parse 'omp [begin] assume[s]' directive.
-  void ParseOpenMPAssumesDirective(OpenMPDirectiveKind DKind,
-   SourceLocation Loc);
+  StmtResult ParseOpenMPAssumesDirective(OpenMPDirectiveKind DKind,
+ SourceLocation Loc);
 
   /// Parse 'omp end assumes' directive.
   void ParseOpenMPEndAssumesDirective(SourceLocation Loc);
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index c6035445e9019..652df4a16e62d 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -12966,6 +12966,9 @@ class Sema final : public SemaBase {
   /// Act on \p D, a function definition inside of an `omp [begin/end] 
assumes`.
   void ActOnFinishedFunctionDefinitionInOpenMPAssumeScope(Decl *D);
 
+  /// Act on \p D, Associated statements of `omp assume`.
+  StmtResult ActOnFinishedStatementInOpenMPAssumeScope(Stmt *);
+
   /// Can we exit an OpenMP declare variant scope at the moment.
   bool isInOpenMPDeclareVariantScope() const {
 return !OMPDeclareVariantScopes.empty();
diff --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp
index b3e9affbb3e58..97a0dd508c0a5 100644
--- a/clang/lib/Basic/OpenMPKinds.cpp
+++ b/clang/lib/Basic/OpenMPKinds.cpp
@@ -721,6 +721,9 @@ void clang::getOpenMPCaptureRegions(
   case OMPD_parallel_loop:
 CaptureRegions.push_back(OMPD_parallel);
 break;
+  case OMPD_assume:
+CaptureRegions.push_back(OMPD_assume);
+break;
   case OMPD_target_teams:
   case OMPD_target_teams_distribute:
   case OMPD_target_teams_distribute_simd:
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 814126e321d3b..3d1a9564897af 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -1673,8 +1673,8 @@ void Parser::ParseOpenMPClauses(OpenMPDirectiveKind DKind,
 /// 'no_openmp_routines'
 /// 'no_parallelism'
 ///
-void Parser::ParseOpenMPAssumesDirective(OpenMPDirectiveKind DKind,
- SourceLocation Loc) {
+StmtResult Parser::ParseOpenMPAssumesDirective(OpenMPDirectiveKind DKind,
+   SourceLocation Loc) {
   SmallVector Assumptions;
   bool SkippedClauses = false;
 
@@ -1750,7 +1750,33 @@ void 
Parser::ParseOpenMPAssumesDirective(OpenMPDirectiveKind DKind,
 Assumptions.push_back(Assumption);
   }
 
+  StmtResult AssociatedStmt;
+
+  // Fix the scope for assume.
+  if (DKind == llvm::omp::Directive::OMPD_assume) {
+
+if (Tok.getKind() == clang::tok::annot_pragma_openmp_end)
+  ConsumeAnyToken();
+
+DeclarationNameInfo DirName;
+Actions.StartOpenMPDSABlock(DKind, DirName, Actions.getCurScope(), Loc);
+  }
+
   Actions.ActOnOpenMPAssumesDirective(Loc, DKind, Assumptions, SkippedClauses);
+
+  if (DKind == llvm::omp::Directive::OMPD_assume) {
+
+AssociatedStmt = ParseStatement();
+AssociatedStmt =
+
Actions.ActOnFinishedStatementInOpenMPAssumeScope(AssociatedStmt.get());
+
+// End the scope for assume.
+ParseOpenMPEndAssumesDirective(Loc);
+Actions.EndOpenMPDSABlock(nullptr);
+if (Tok.getKind() == clang::tok::annot_pragma_openmp_end)
+  ConsumeAnyToken();
+  }
+  return AssociatedStmt;
 }
 
 void Parser::ParseOpenMPEndAssumesDirective(SourceLocation Loc) {
@@ -2759,6 +2785,9 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
 }
 break;
   }
+  case OMPD_assume:
+Directive = ParseOpenMPAssumesDirective(DKind, Con

[clang] [llvm] Assume (PR #97535)

2024-07-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-flang-openmp

Author: None (SunilKuravinakop)


Changes

Support for assume directive : Parse and AST modules

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


7 Files Affected:

- (modified) clang/include/clang/Parse/Parser.h (+2-2) 
- (modified) clang/include/clang/Sema/SemaOpenMP.h (+3) 
- (modified) clang/lib/Basic/OpenMPKinds.cpp (+3) 
- (modified) clang/lib/Parse/ParseOpenMP.cpp (+31-2) 
- (modified) clang/lib/Sema/SemaOpenMP.cpp (+65-1) 
- (added) clang/test/OpenMP/assume_ast.cpp (+43) 
- (modified) llvm/include/llvm/Frontend/OpenMP/OMP.td (+4) 


``diff
diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 6880fa4bb0b03..e9083e98e2baa 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -3434,8 +3434,8 @@ class Parser : public CodeCompletionHandler {
  SourceLocation Loc);
 
   /// Parse 'omp [begin] assume[s]' directive.
-  void ParseOpenMPAssumesDirective(OpenMPDirectiveKind DKind,
-   SourceLocation Loc);
+  StmtResult ParseOpenMPAssumesDirective(OpenMPDirectiveKind DKind,
+ SourceLocation Loc);
 
   /// Parse 'omp end assumes' directive.
   void ParseOpenMPEndAssumesDirective(SourceLocation Loc);
diff --git a/clang/include/clang/Sema/SemaOpenMP.h 
b/clang/include/clang/Sema/SemaOpenMP.h
index 3edf1cc7c12f2..1831d417877b5 100644
--- a/clang/include/clang/Sema/SemaOpenMP.h
+++ b/clang/include/clang/Sema/SemaOpenMP.h
@@ -106,6 +106,9 @@ class SemaOpenMP : public SemaBase {
   /// Act on \p D, a function definition inside of an `omp [begin/end] 
assumes`.
   void ActOnFinishedFunctionDefinitionInOpenMPAssumeScope(Decl *D);
 
+  /// Act on \p D, Associated statements of `omp assume`.
+  StmtResult ActOnFinishedStatementInOpenMPAssumeScope(Stmt *);
+
   /// Can we exit an OpenMP declare variant scope at the moment.
   bool isInOpenMPDeclareVariantScope() const {
 return !OMPDeclareVariantScopes.empty();
diff --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp
index 766d6a8418a6a..696a819086af1 100644
--- a/clang/lib/Basic/OpenMPKinds.cpp
+++ b/clang/lib/Basic/OpenMPKinds.cpp
@@ -760,6 +760,9 @@ void clang::getOpenMPCaptureRegions(
 case OMPD_parallel:
   CaptureRegions.push_back(OMPD_parallel);
   break;
+case OMPD_assume:
+  CaptureRegions.push_back(OMPD_assume);
+  break;
 case OMPD_target:
   CaptureRegions.push_back(OMPD_task);
   CaptureRegions.push_back(OMPD_target);
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 326cd22ff9005..9267e8792f0bf 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -1682,8 +1682,8 @@ void Parser::ParseOpenMPClauses(OpenMPDirectiveKind DKind,
 /// 'no_openmp_routines'
 /// 'no_parallelism'
 ///
-void Parser::ParseOpenMPAssumesDirective(OpenMPDirectiveKind DKind,
- SourceLocation Loc) {
+StmtResult Parser::ParseOpenMPAssumesDirective(OpenMPDirectiveKind DKind,
+   SourceLocation Loc) {
   SmallVector Assumptions;
   bool SkippedClauses = false;
 
@@ -1759,8 +1759,34 @@ void 
Parser::ParseOpenMPAssumesDirective(OpenMPDirectiveKind DKind,
 Assumptions.push_back(Assumption);
   }
 
+  StmtResult AssociatedStmt;
+
+  // Fix the scope for assume.
+  if (DKind == llvm::omp::Directive::OMPD_assume) {
+
+if (Tok.getKind() == clang::tok::annot_pragma_openmp_end)
+  ConsumeAnyToken();
+
+DeclarationNameInfo DirName;
+Actions.OpenMP().StartOpenMPDSABlock(DKind, DirName, 
Actions.getCurScope(), Loc);
+  }
+
   Actions.OpenMP().ActOnOpenMPAssumesDirective(Loc, DKind, Assumptions,
SkippedClauses);
+
+  if (DKind == llvm::omp::Directive::OMPD_assume) {
+
+AssociatedStmt = ParseStatement();
+AssociatedStmt =
+
Actions.OpenMP().ActOnFinishedStatementInOpenMPAssumeScope(AssociatedStmt.get());
+
+// End the scope for assume.
+ParseOpenMPEndAssumesDirective(Loc);
+Actions.OpenMP().EndOpenMPDSABlock(nullptr);
+if (Tok.getKind() == clang::tok::annot_pragma_openmp_end)
+  ConsumeAnyToken();
+  }
+  return AssociatedStmt;
 }
 
 void Parser::ParseOpenMPEndAssumesDirective(SourceLocation Loc) {
@@ -2885,6 +2911,9 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
 }
 break;
   }
+  case OMPD_assume:
+Directive = ParseOpenMPAssumesDirective(DKind, ConsumeToken());
+break;
   case OMPD_declare_target: {
 SourceLocation DTLoc = ConsumeAnyToken();
 bool HasClauses = Tok.isNot(tok::annot_pragma_openmp_end);
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 8f064f35d..043559c052d57 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpe

[clang] [clang] Define ATOMIC_FLAG_INIT correctly for C++. (PR #97534)

2024-07-03 Thread Chris Copeland via cfe-commits

chrisnc wrote:

Without this change, trying to use `ATOMIC_FLAG_INIT` in a constant 
initialization context yields the following:

https://godbolt.org/z/sTvMs5a95

```
:3:17: error: non-constant-expression cannot be narrowed from type 
'int' to 'atomic_bool' (aka '_Atomic(bool)') in initializer list 
[-Wc++11-narrowing]
3 | atomic_flag x = ATOMIC_FLAG_INIT;
  | ^~~~
/opt/compiler-explorer/clang-trunk-20240703/lib/clang/19/include/stdatomic.h:169:28:
 note: expanded from macro 'ATOMIC_FLAG_INIT'
  169 | #define ATOMIC_FLAG_INIT { 0 }
  |^
:3:17: note: insert an explicit cast to silence this issue
3 | atomic_flag x = ATOMIC_FLAG_INIT;
  | ^~~~
/opt/compiler-explorer/clang-trunk-20240703/lib/clang/19/include/stdatomic.h:169:28:
 note: expanded from macro 'ATOMIC_FLAG_INIT'
  169 | #define ATOMIC_FLAG_INIT { 0 }
  |^
1 error generated.
Compiler returned: 1
```

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


[clang] [flang] [Driver][X86] Add flang visibility for -mapx-features= (PR #97525)

2024-07-03 Thread Shengchen Kan via cfe-commits

https://github.com/KanRobert updated 
https://github.com/llvm/llvm-project/pull/97525

>From 1aab0a95629371c61273c80f6335a6723c7d27c4 Mon Sep 17 00:00:00 2001
From: Shengchen Kan 
Date: Wed, 3 Jul 2024 11:30:47 +0800
Subject: [PATCH 1/2] [Driver][X86] Add flang visibility for -mapx-features=

---
 clang/include/clang/Driver/Options.td | 2 +-
 flang/test/Driver/target-cpu-features.f90 | 6 ++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1c2b8cfeef6ce..e1e6a6e3a0fcd 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6319,7 +6319,7 @@ def mno_gather : Flag<["-"], "mno-gather">, 
Group,
 def mno_scatter : Flag<["-"], "mno-scatter">, Group,
   HelpText<"Disable generation of scatter instructions in 
auto-vectorization(x86 only)">;
 def mapx_features_EQ : CommaJoined<["-"], "mapx-features=">, 
Group,
-HelpText<"Enable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,nf,cf,zu">;
+HelpText<"Enable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,nf,cf,zu">,  Visibility<[ClangOption, 
CLOption, FlangOption]>;
 def mno_apx_features_EQ : CommaJoined<["-"], "mno-apx-features=">, 
Group,
 HelpText<"Disable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,nf,cf,zu">;
 // For stability, we only add a feature to -mapxf after it passes the 
validation of llvm-test-suite && cpu2017 on Intel SDE.
diff --git a/flang/test/Driver/target-cpu-features.f90 
b/flang/test/Driver/target-cpu-features.f90
index e78c3516db45a..2728fb90afa41 100644
--- a/flang/test/Driver/target-cpu-features.f90
+++ b/flang/test/Driver/target-cpu-features.f90
@@ -17,6 +17,9 @@
 ! RUN: %flang --target=x86_64-linux-gnu -march=skylake -c %s -### 2>&1 \
 ! RUN: | FileCheck %s -check-prefix=CHECK-SKYLAKE
 
+! RUN: %flang --target=x86_64-linux-gnu -mapx-features=egpr -c %s -### 2>&1 \
+! RUN: | FileCheck %s -check-prefix=CHECK-APX
+
 ! RUN: %flang --target=x86_64h-linux-gnu -c %s -### 2>&1 \
 ! RUN: | FileCheck %s -check-prefix=CHECK-X86_64H
 
@@ -51,6 +54,9 @@
 ! CHECK-SKYLAKE: "-fc1" "-triple" "x86_64-unknown-linux-gnu"
 ! CHECK-SKYLAKE-SAME: "-target-cpu" "skylake"
 
+! CHECK-APX: "-fc1" "-triple" "x86_64-unknown-linux-gnu"
+! CHECK-APX-SAME: "-target-feature" "+egpr"
+
 ! CHECK-X86_64H: "-fc1" "-triple" "x86_64h-unknown-linux-gnu"
 ! CHECK-X86_64H-SAME: "-target-cpu" "x86-64" "-target-feature" "-rdrnd" 
"-target-feature" "-aes" "-target-feature" "-pclmul" "-target-feature" "-rtm" 
"-target-feature" "-fsgsbase"
 

>From ba538ee16385bdedfae770b712646546dfc6b54c Mon Sep 17 00:00:00 2001
From: Shengchen Kan 
Date: Wed, 3 Jul 2024 15:32:04 +0800
Subject: [PATCH 2/2] minor improve

---
 clang/include/clang/Driver/Options.td | 2 +-
 flang/test/Driver/target-cpu-features.f90 | 6 ++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index e1e6a6e3a0fcd..1ede75d3782cd 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6321,7 +6321,7 @@ def mno_scatter : Flag<["-"], "mno-scatter">, 
Group,
 def mapx_features_EQ : CommaJoined<["-"], "mapx-features=">, 
Group,
 HelpText<"Enable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,nf,cf,zu">,  Visibility<[ClangOption, 
CLOption, FlangOption]>;
 def mno_apx_features_EQ : CommaJoined<["-"], "mno-apx-features=">, 
Group,
-HelpText<"Disable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,nf,cf,zu">;
+HelpText<"Disable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,nf,cf,zu">, Visibility<[ClangOption, 
CLOption, FlangOption]>;
 // For stability, we only add a feature to -mapxf after it passes the 
validation of llvm-test-suite && cpu2017 on Intel SDE.
 def mapxf : Flag<["-"], "mapxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx","ndd","ccmp","nf","cf"]>;
 def mno_apxf : Flag<["-"], "mno-apxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx","ndd","ccmp","nf","cf"]>;
diff --git a/flang/test/Driver/target-cpu-features.f90 
b/flang/test/Driver/target-cpu-features.f90
index 2728fb90afa41..0f19e4ebff2a0 100644
--- a/flang/test/Driver/target-cpu-features.f90
+++ b/flang/test/Driver/target-cpu-features.f90
@@ -20,6 +20,9 @@
 ! RUN: %flang --target=x86_64-linux-gnu -mapx-features=egpr -c %s -### 2>&1 \
 ! RUN: | FileCheck %s -check-prefix=CHECK-APX
 
+! RUN: %flang --target=x86_64-linux-gnu -mno-apx-features=ccmp -c %s -### 2>&1 
\
+! RUN: | FileCheck %s -check-prefix=CHECK-NO-APX
+
 ! RUN: %flang --target=x86_64h-linux-gnu -c %s -### 2>&1 \
 ! RUN: | FileCheck %s -check-prefix=CHECK-X86_64H
 
@@ -57,6 +60,9 @@
 ! CHECK-APX: "-fc1" "-triple" "x86_64-unknown-linux-gnu"
 ! CHECK-APX-SAME: "-target-feature" "+egpr"
 
+! CHECK-NO-APX: "-fc1" "-triple" "x86_64-unknown-linux-gnu"
+! CHECK-NO-APX-SAME: "-target-feature" "-ccmp"
+
 ! CHECK-X86_64H: "-fc1" "-triple

[clang] [llvm] Assume (PR #97535)

2024-07-03 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff e1094dd889c516da0c3181bf2be44ad631a84255 
287d8974994d46542971e3b077712f5b53864c11 -- clang/test/OpenMP/assume_ast.cpp 
clang/include/clang/Parse/Parser.h clang/include/clang/Sema/SemaOpenMP.h 
clang/lib/Basic/OpenMPKinds.cpp clang/lib/Parse/ParseOpenMP.cpp 
clang/lib/Sema/SemaOpenMP.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 9267e8792f..78c0211e20 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -1768,7 +1768,8 @@ StmtResult 
Parser::ParseOpenMPAssumesDirective(OpenMPDirectiveKind DKind,
   ConsumeAnyToken();
 
 DeclarationNameInfo DirName;
-Actions.OpenMP().StartOpenMPDSABlock(DKind, DirName, 
Actions.getCurScope(), Loc);
+Actions.OpenMP().StartOpenMPDSABlock(DKind, DirName, Actions.getCurScope(),
+ Loc);
   }
 
   Actions.OpenMP().ActOnOpenMPAssumesDirective(Loc, DKind, Assumptions,
@@ -1777,8 +1778,8 @@ StmtResult 
Parser::ParseOpenMPAssumesDirective(OpenMPDirectiveKind DKind,
   if (DKind == llvm::omp::Directive::OMPD_assume) {
 
 AssociatedStmt = ParseStatement();
-AssociatedStmt =
-
Actions.OpenMP().ActOnFinishedStatementInOpenMPAssumeScope(AssociatedStmt.get());
+AssociatedStmt = 
Actions.OpenMP().ActOnFinishedStatementInOpenMPAssumeScope(
+AssociatedStmt.get());
 
 // End the scope for assume.
 ParseOpenMPEndAssumesDirective(Loc);

``




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


[clang] [clang] Define ATOMIC_FLAG_INIT correctly for C++. (PR #97534)

2024-07-03 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 690ecee40cd2f3d6655af09272c89a2ea15ada60 
34a618e2ac88291cf44b84f1c22cddefdb34bc29 -- clang/lib/Headers/stdatomic.h
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Headers/stdatomic.h b/clang/lib/Headers/stdatomic.h
index 88172038be..51a5d004e8 100644
--- a/clang/lib/Headers/stdatomic.h
+++ b/clang/lib/Headers/stdatomic.h
@@ -167,7 +167,7 @@ typedef _Atomic(uintmax_t)  atomic_uintmax_t;
 typedef struct atomic_flag { atomic_bool _Value; } atomic_flag;
 
 #ifdef __cplusplus
-#define ATOMIC_FLAG_INIT { false }
+#define ATOMIC_FLAG_INIT {false}
 #else
 #define ATOMIC_FLAG_INIT { 0 }
 #endif

``




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


[clang] [clang] Define ATOMIC_FLAG_INIT correctly for C++. (PR #97534)

2024-07-03 Thread Chris Copeland via cfe-commits

https://github.com/chrisnc updated 
https://github.com/llvm/llvm-project/pull/97534

>From b7857c25e56ea59956d8ae0aac068358bcf67a03 Mon Sep 17 00:00:00 2001
From: Chris Copeland 
Date: Wed, 3 Jul 2024 00:11:39 -0700
Subject: [PATCH] [clang] Define ATOMIC_FLAG_INIT correctly for C++.

---
 clang/docs/ReleaseNotes.rst   | 2 ++
 clang/lib/Headers/stdatomic.h | 4 
 2 files changed, 6 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1537eaaba0c66..3d85065a7ff8a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -750,6 +750,8 @@ Bug Fixes in This Version
 
 - Fixed `static_cast` to array of unknown bound. Fixes (#GH62863).
 
+- Fixed the definition of ATOMIC_FLAG_INIT in stdatomic.h so it can be used in 
C++.
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/lib/Headers/stdatomic.h b/clang/lib/Headers/stdatomic.h
index 9c103d98af8c5..51a5d004e82d8 100644
--- a/clang/lib/Headers/stdatomic.h
+++ b/clang/lib/Headers/stdatomic.h
@@ -166,7 +166,11 @@ typedef _Atomic(uintmax_t)  atomic_uintmax_t;
 
 typedef struct atomic_flag { atomic_bool _Value; } atomic_flag;
 
+#ifdef __cplusplus
+#define ATOMIC_FLAG_INIT {false}
+#else
 #define ATOMIC_FLAG_INIT { 0 }
+#endif
 
 /* These should be provided by the libc implementation. */
 #ifdef __cplusplus

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


[clang] [analyzer][NFC] Add some docs for LazyCompoundValue (PR #97407)

2024-07-03 Thread Donát Nagy via cfe-commits


@@ -346,6 +352,39 @@ class CompoundVal : public NonLoc {
   static bool classof(SVal V) { return V.getKind() == CompoundValKind; }
 };
 
+/// The simplest example of a concrete compound value is nonloc::CompoundVal,
+/// which represents a concrete r-value of an initializer-list or a string.
+/// Internally, it contains an llvm::ImmutableList of SVal's stored inside the
+/// literal.
+///
+/// However, there is another compound value used in the analyzer, which 
appears
+/// much more often during analysis, which is nonloc::LazyCompoundVal. This
+/// value is an r-value that represents a snapshot of any structure "as a 
whole"
+/// at a given moment during the analysis. Such value is already quite far from
+/// being re- ferred to as "concrete", as many fields inside it would be 
unknown
+/// or symbolic. nonloc::LazyCompoundVal operates by storing two things:
+///   * a reference to the TypedValueRegion being snapshotted (yes, it is 
always
+/// typed), and also
+///   * a copy of the whole Store object, obtained from the ProgramState in

NagyDonat wrote:

I do understand functional programming (I had a phase when I learnt Haskell and 
for a few years I thought that it's the absolutely perfect language 
:star_struck: -- since then I'm more realistic but I still like it), I was just 
confused by the fact that this line emphasizes "a copy of the whole Store 
object" as opposed to the "reference to" in the previous line.

In a functional language the word "copy" is practically non-existent (we speak 
about values, not objects and their identity, so there is no reason to say that 
this is _a copy of_ e.g. that list -- we simply say that "this is that list"), 
while in C++ saying "copy" instead of "move" or "pointer/reference" is an 
important synonym of "we allocate lots of new memory", so I'd still prefer 
tweaking this line.

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


[clang] [llvm] Assume (PR #97535)

2024-07-03 Thread via cfe-commits

https://github.com/SunilKuravinakop updated 
https://github.com/llvm/llvm-project/pull/97535

>From a331d2343a43a9ca2030ef07a25ca93ff26a5778 Mon Sep 17 00:00:00 2001
From: Sunil Kuravinakop 
Date: Mon, 1 Jul 2024 03:29:45 -0500
Subject: [PATCH 1/3] Support for "#pragma omp assume" Directive in Parse and
 AST.

  Changes to be committed:
modified:   clang/include/clang/Parse/Parser.h
modified:   clang/include/clang/Sema/Sema.h
modified:   clang/lib/Basic/OpenMPKinds.cpp
modified:   clang/lib/Parse/ParseOpenMP.cpp
modified:   clang/lib/Sema/SemaOpenMP.cpp
modified:   llvm/include/llvm/Frontend/OpenMP/OMP.td
---
 clang/include/clang/Parse/Parser.h   |  4 +-
 clang/include/clang/Sema/Sema.h  |  3 ++
 clang/lib/Basic/OpenMPKinds.cpp  |  3 ++
 clang/lib/Parse/ParseOpenMP.cpp  | 33 +++-
 clang/lib/Sema/SemaOpenMP.cpp| 67 +++-
 llvm/include/llvm/Frontend/OpenMP/OMP.td |  3 ++
 6 files changed, 108 insertions(+), 5 deletions(-)

diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 5950dd74cfe83..7568c053eb77f 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -3380,8 +3380,8 @@ class Parser : public CodeCompletionHandler {
  SourceLocation Loc);
 
   /// Parse 'omp [begin] assume[s]' directive.
-  void ParseOpenMPAssumesDirective(OpenMPDirectiveKind DKind,
-   SourceLocation Loc);
+  StmtResult ParseOpenMPAssumesDirective(OpenMPDirectiveKind DKind,
+ SourceLocation Loc);
 
   /// Parse 'omp end assumes' directive.
   void ParseOpenMPEndAssumesDirective(SourceLocation Loc);
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index c6035445e9019..652df4a16e62d 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -12966,6 +12966,9 @@ class Sema final : public SemaBase {
   /// Act on \p D, a function definition inside of an `omp [begin/end] 
assumes`.
   void ActOnFinishedFunctionDefinitionInOpenMPAssumeScope(Decl *D);
 
+  /// Act on \p D, Associated statements of `omp assume`.
+  StmtResult ActOnFinishedStatementInOpenMPAssumeScope(Stmt *);
+
   /// Can we exit an OpenMP declare variant scope at the moment.
   bool isInOpenMPDeclareVariantScope() const {
 return !OMPDeclareVariantScopes.empty();
diff --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp
index b3e9affbb3e58..97a0dd508c0a5 100644
--- a/clang/lib/Basic/OpenMPKinds.cpp
+++ b/clang/lib/Basic/OpenMPKinds.cpp
@@ -721,6 +721,9 @@ void clang::getOpenMPCaptureRegions(
   case OMPD_parallel_loop:
 CaptureRegions.push_back(OMPD_parallel);
 break;
+  case OMPD_assume:
+CaptureRegions.push_back(OMPD_assume);
+break;
   case OMPD_target_teams:
   case OMPD_target_teams_distribute:
   case OMPD_target_teams_distribute_simd:
diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp
index 814126e321d3b..3d1a9564897af 100644
--- a/clang/lib/Parse/ParseOpenMP.cpp
+++ b/clang/lib/Parse/ParseOpenMP.cpp
@@ -1673,8 +1673,8 @@ void Parser::ParseOpenMPClauses(OpenMPDirectiveKind DKind,
 /// 'no_openmp_routines'
 /// 'no_parallelism'
 ///
-void Parser::ParseOpenMPAssumesDirective(OpenMPDirectiveKind DKind,
- SourceLocation Loc) {
+StmtResult Parser::ParseOpenMPAssumesDirective(OpenMPDirectiveKind DKind,
+   SourceLocation Loc) {
   SmallVector Assumptions;
   bool SkippedClauses = false;
 
@@ -1750,7 +1750,33 @@ void 
Parser::ParseOpenMPAssumesDirective(OpenMPDirectiveKind DKind,
 Assumptions.push_back(Assumption);
   }
 
+  StmtResult AssociatedStmt;
+
+  // Fix the scope for assume.
+  if (DKind == llvm::omp::Directive::OMPD_assume) {
+
+if (Tok.getKind() == clang::tok::annot_pragma_openmp_end)
+  ConsumeAnyToken();
+
+DeclarationNameInfo DirName;
+Actions.StartOpenMPDSABlock(DKind, DirName, Actions.getCurScope(), Loc);
+  }
+
   Actions.ActOnOpenMPAssumesDirective(Loc, DKind, Assumptions, SkippedClauses);
+
+  if (DKind == llvm::omp::Directive::OMPD_assume) {
+
+AssociatedStmt = ParseStatement();
+AssociatedStmt =
+
Actions.ActOnFinishedStatementInOpenMPAssumeScope(AssociatedStmt.get());
+
+// End the scope for assume.
+ParseOpenMPEndAssumesDirective(Loc);
+Actions.EndOpenMPDSABlock(nullptr);
+if (Tok.getKind() == clang::tok::annot_pragma_openmp_end)
+  ConsumeAnyToken();
+  }
+  return AssociatedStmt;
 }
 
 void Parser::ParseOpenMPEndAssumesDirective(SourceLocation Loc) {
@@ -2759,6 +2785,9 @@ StmtResult 
Parser::ParseOpenMPDeclarativeOrExecutableDirective(
 }
 break;
   }
+  case OMPD_assume:
+Directive = ParseOpenMPAssumesDirective(DKind, ConsumeToken());
+break;
   case OMPD_flush:
   case 

[clang] [clang] Extend lifetimebound analysis to detect within-initializer assignments between pointer-like objects. (PR #97473)

2024-07-03 Thread Haojian Wu via cfe-commits

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


[clang] [clang] Extend lifetimebound analysis to detect within-initializer assignments between pointer-like objects. (PR #97473)

2024-07-03 Thread Haojian Wu via cfe-commits

hokein wrote:

Withdrawing it from review now. I seem to find a potentially better approach 
and will upload a revised version.

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


[clang] [analyzer][NFC] Add some docs for LazyCompoundValue (PR #97407)

2024-07-03 Thread Donát Nagy via cfe-commits


@@ -346,6 +352,39 @@ class CompoundVal : public NonLoc {
   static bool classof(SVal V) { return V.getKind() == CompoundValKind; }
 };
 
+/// The simplest example of a concrete compound value is nonloc::CompoundVal,
+/// which represents a concrete r-value of an initializer-list or a string.
+/// Internally, it contains an llvm::ImmutableList of SVal's stored inside the
+/// literal.
+///
+/// However, there is another compound value used in the analyzer, which 
appears
+/// much more often during analysis, which is nonloc::LazyCompoundVal. This
+/// value is an r-value that represents a snapshot of any structure "as a 
whole"
+/// at a given moment during the analysis. Such value is already quite far from
+/// being re- ferred to as "concrete", as many fields inside it would be 
unknown
+/// or symbolic. nonloc::LazyCompoundVal operates by storing two things:
+///   * a reference to the TypedValueRegion being snapshotted (yes, it is 
always
+/// typed), and also
+///   * a copy of the whole Store object, obtained from the ProgramState in
+/// which it was created.

NagyDonat wrote:

```suggestion
///  * a reference to the whole Store object, obtained from the ProgramState in
///which the nonloc::LazyCompoundVal was created.
///
/// Note that the old ProgramState and its Store is kept alive during the
/// analysis because these are immutable functional data structures and each new
/// Store value is represented as "earlier Store" + "additional binding".
```

What would you think about this phrasing?

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


[clang] 76c84e7 - [Driver][X86] Add flang visibility for -mapx-features= (#97525)

2024-07-03 Thread via cfe-commits

Author: Shengchen Kan
Date: 2024-07-03T16:02:58+08:00
New Revision: 76c84e702bd9af7db2bb9373ba6de0508f1e57a9

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

LOG: [Driver][X86] Add flang visibility for -mapx-features= (#97525)

The default visibility of `m_x86_Features_Group` is `ClangOption,
CLOption`. For x86, we expose `-march` to flang but not `-m`.
`apxf` is special b/c it contains several independent features like
`egpr, ndd, ppx, push2pop2, ccmp, nf, cf` and `zu`.

Users may would like to turn on part of features in different cases

1. enable `ndd` only when writing a code-size sensitive library 
2. disable `ccmp`, `cf` when building component has strong security
request on caches

Hence, we expose `-mapx-features=` to flang for Fortran users.

Added: 


Modified: 
clang/include/clang/Driver/Options.td
flang/test/Driver/target-cpu-features.f90

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1c2b8cfeef6ce..1ede75d3782cd 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6319,9 +6319,9 @@ def mno_gather : Flag<["-"], "mno-gather">, 
Group,
 def mno_scatter : Flag<["-"], "mno-scatter">, Group,
   HelpText<"Disable generation of scatter instructions in 
auto-vectorization(x86 only)">;
 def mapx_features_EQ : CommaJoined<["-"], "mapx-features=">, 
Group,
-HelpText<"Enable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,nf,cf,zu">;
+HelpText<"Enable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,nf,cf,zu">,  Visibility<[ClangOption, 
CLOption, FlangOption]>;
 def mno_apx_features_EQ : CommaJoined<["-"], "mno-apx-features=">, 
Group,
-HelpText<"Disable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,nf,cf,zu">;
+HelpText<"Disable features of APX">, 
Values<"egpr,push2pop2,ppx,ndd,ccmp,nf,cf,zu">, Visibility<[ClangOption, 
CLOption, FlangOption]>;
 // For stability, we only add a feature to -mapxf after it passes the 
validation of llvm-test-suite && cpu2017 on Intel SDE.
 def mapxf : Flag<["-"], "mapxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx","ndd","ccmp","nf","cf"]>;
 def mno_apxf : Flag<["-"], "mno-apxf">, Alias, 
AliasArgs<["egpr","push2pop2","ppx","ndd","ccmp","nf","cf"]>;

diff  --git a/flang/test/Driver/target-cpu-features.f90 
b/flang/test/Driver/target-cpu-features.f90
index e78c3516db45a..0f19e4ebff2a0 100644
--- a/flang/test/Driver/target-cpu-features.f90
+++ b/flang/test/Driver/target-cpu-features.f90
@@ -17,6 +17,12 @@
 ! RUN: %flang --target=x86_64-linux-gnu -march=skylake -c %s -### 2>&1 \
 ! RUN: | FileCheck %s -check-prefix=CHECK-SKYLAKE
 
+! RUN: %flang --target=x86_64-linux-gnu -mapx-features=egpr -c %s -### 2>&1 \
+! RUN: | FileCheck %s -check-prefix=CHECK-APX
+
+! RUN: %flang --target=x86_64-linux-gnu -mno-apx-features=ccmp -c %s -### 2>&1 
\
+! RUN: | FileCheck %s -check-prefix=CHECK-NO-APX
+
 ! RUN: %flang --target=x86_64h-linux-gnu -c %s -### 2>&1 \
 ! RUN: | FileCheck %s -check-prefix=CHECK-X86_64H
 
@@ -51,6 +57,12 @@
 ! CHECK-SKYLAKE: "-fc1" "-triple" "x86_64-unknown-linux-gnu"
 ! CHECK-SKYLAKE-SAME: "-target-cpu" "skylake"
 
+! CHECK-APX: "-fc1" "-triple" "x86_64-unknown-linux-gnu"
+! CHECK-APX-SAME: "-target-feature" "+egpr"
+
+! CHECK-NO-APX: "-fc1" "-triple" "x86_64-unknown-linux-gnu"
+! CHECK-NO-APX-SAME: "-target-feature" "-ccmp"
+
 ! CHECK-X86_64H: "-fc1" "-triple" "x86_64h-unknown-linux-gnu"
 ! CHECK-X86_64H-SAME: "-target-cpu" "x86-64" "-target-feature" "-rdrnd" 
"-target-feature" "-aes" "-target-feature" "-pclmul" "-target-feature" "-rtm" 
"-target-feature" "-fsgsbase"
 



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


[clang] [flang] [Driver][X86] Add flang visibility for -mapx-features= (PR #97525)

2024-07-03 Thread Shengchen Kan via cfe-commits

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


[clang] 1787d4b - [clang-repl] Fix RuntimeInterfaceBuilder for 32-bit systems (#97071)

2024-07-03 Thread via cfe-commits

Author: Stefan Gränitz
Date: 2024-07-03T10:32:50+02:00
New Revision: 1787d4b28417ea9f26c0213e8f597cc5bb289144

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

LOG: [clang-repl] Fix RuntimeInterfaceBuilder for 32-bit systems (#97071)

When generating runtime interface bindings, extend integral types to the
native register size rather than 64-bit per se

Fixes #94994

Added: 


Modified: 
clang/lib/Interpreter/Interpreter.cpp
clang/unittests/Interpreter/InterpreterTest.cpp

Removed: 




diff  --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index 49dc92d60233a..b4882ab5d2236 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -686,10 +686,12 @@ class InterfaceKindVisitor
   }
 
 private:
-  // Force cast these types to uint64 to reduce the number of overloads of
-  // `__clang_Interpreter_SetValueNoAlloc`.
+  // Force cast these types to the uint that fits the register size. That way 
we
+  // reduce the number of overloads of `__clang_Interpreter_SetValueNoAlloc`.
   void HandleIntegralOrEnumType(const Type *Ty) {
-TypeSourceInfo *TSI = Ctx.getTrivialTypeSourceInfo(Ctx.UnsignedLongLongTy);
+uint64_t PtrBits = Ctx.getTypeSize(Ctx.VoidPtrTy);
+QualType UIntTy = Ctx.getBitIntType(/*Unsigned=*/true, PtrBits);
+TypeSourceInfo *TSI = Ctx.getTrivialTypeSourceInfo(UIntTy);
 ExprResult CastedExpr =
 S.BuildCStyleCastExpr(SourceLocation(), TSI, SourceLocation(), E);
 assert(!CastedExpr.isInvalid() && "Cannot create cstyle cast expr");

diff  --git a/clang/unittests/Interpreter/InterpreterTest.cpp 
b/clang/unittests/Interpreter/InterpreterTest.cpp
index 29c5ead60b81e..a2e960f143111 100644
--- a/clang/unittests/Interpreter/InterpreterTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterTest.cpp
@@ -282,9 +282,6 @@ TEST_F(InterpreterTest, InstantiateTemplate) {
   EXPECT_EQ(42, fn(NewA.getPtr()));
 }
 
-// This test exposes an ARM specific problem in the interpreter, see
-// https://github.com/llvm/llvm-project/issues/94994.
-#ifndef __arm__
 TEST_F(InterpreterTest, Value) {
   std::vector Args = {"-fno-sized-deallocation"};
   std::unique_ptr Interp = createInterpreter(Args);
@@ -383,6 +380,5 @@ TEST_F(InterpreterTest, Value) {
   EXPECT_EQ(V9.getKind(), Value::K_PtrOrObj);
   EXPECT_TRUE(V9.isManuallyAlloc());
 }
-#endif /* ifndef __arm__ */
 
 } // end anonymous namespace



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


[clang] [clang-repl] Fix RuntimeInterfaceBuilder for 32-bit systems (PR #97071)

2024-07-03 Thread Stefan Gränitz via cfe-commits

https://github.com/weliveindetail closed 
https://github.com/llvm/llvm-project/pull/97071
___
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 `bugprone-pointer-arithmetic-on-polymorphic-object` check (PR #91951)

2024-07-03 Thread via cfe-commits


@@ -0,0 +1,81 @@
+//===--- PointerArithmeticOnPolymorphicObjectCheck.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 "PointerArithmeticOnPolymorphicObjectCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+namespace {
+AST_MATCHER(CXXRecordDecl, isAbstract) { return Node.isAbstract(); }
+AST_MATCHER(CXXRecordDecl, isPolymorphic) { return Node.isPolymorphic(); }
+} // namespace
+
+PointerArithmeticOnPolymorphicObjectCheck::
+PointerArithmeticOnPolymorphicObjectCheck(StringRef Name,
+  ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  IgnoreInheritedVirtualFunctions(
+  Options.get("IgnoreInheritedVirtualFunctions", false)) {}
+
+void PointerArithmeticOnPolymorphicObjectCheck::storeOptions(
+ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "IgnoreInheritedVirtualFunctions",
+IgnoreInheritedVirtualFunctions);
+}
+
+void PointerArithmeticOnPolymorphicObjectCheck::registerMatchers(
+MatchFinder *Finder) {
+  const auto PolymorphicPointerExpr =
+  expr(hasType(hasCanonicalType(pointerType(pointee(hasCanonicalType(
+   hasDeclaration(cxxRecordDecl(unless(isFinal()), isPolymorphic())
+  .bind("pointee"
+  .bind("pointer");
+
+  const auto PointerExprWithVirtualMethod =
+  expr(hasType(hasCanonicalType(
+   pointerType(pointee(hasCanonicalType(hasDeclaration(
+   cxxRecordDecl(
+   unless(isFinal()),
+   anyOf(hasMethod(isVirtualAsWritten()), isAbstract()))
+   .bind("pointee"
+  .bind("pointer");
+
+  const auto SelectedPointerExpr = IgnoreInheritedVirtualFunctions
+   ? PointerExprWithVirtualMethod
+   : PolymorphicPointerExpr;
+
+  const auto ArraySubscript = arraySubscriptExpr(hasBase(SelectedPointerExpr));
+
+  const auto BinaryOperators =
+  binaryOperator(hasAnyOperatorName("+", "-", "+=", "-="),
+ hasEitherOperand(SelectedPointerExpr));
+
+  const auto UnaryOperators = unaryOperator(
+  hasAnyOperatorName("++", "--"), hasUnaryOperand(SelectedPointerExpr));
+
+  Finder->addMatcher(ArraySubscript, this);
+  Finder->addMatcher(BinaryOperators, this);
+  Finder->addMatcher(UnaryOperators, this);
+}
+
+void PointerArithmeticOnPolymorphicObjectCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *PointerExpr = Result.Nodes.getNodeAs("pointer");
+  const auto *PointeeDecl = Result.Nodes.getNodeAs("pointee");
+
+  diag(PointerExpr->getBeginLoc(),
+   "pointer arithmetic on polymorphic object of type '%0', which can "
+   "result in undefined behavior if the pointee is a different object")

Discookie wrote:

Seems much clearer, fixed.

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


[clang-tools-extra] [clang-doc] fix path bug introduced by asset test (PR #97540)

2024-07-03 Thread via cfe-commits

https://github.com/PeterChou1 created 
https://github.com/llvm/llvm-project/pull/97540

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

this patch fixes the bug by copying assets to the correct repository for 
windows builds

>From b8dd4f6f2005d2e08ae13023905d0f36edd6348b Mon Sep 17 00:00:00 2001
From: PeterChou1 
Date: Wed, 3 Jul 2024 04:42:33 -0400
Subject: [PATCH] [clang-doc] fix path bug introduced by asset test

---
 clang-tools-extra/clang-doc/tool/CMakeLists.txt | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/clang-tools-extra/clang-doc/tool/CMakeLists.txt 
b/clang-tools-extra/clang-doc/tool/CMakeLists.txt
index e93a5728d6b6b..3fd41f187a617 100644
--- a/clang-tools-extra/clang-doc/tool/CMakeLists.txt
+++ b/clang-tools-extra/clang-doc/tool/CMakeLists.txt
@@ -25,7 +25,11 @@ set(assets
 )
 
 set(asset_dir "${CMAKE_CURRENT_SOURCE_DIR}/../assets")
-set(resource_dir "${CMAKE_BINARY_DIR}/share/clang-doc")
+if(MSVC)
+  set(resource_dir "${CMAKE_BINARY_DIR}/$/share/clang-doc")
+else()
+  set(resource_dir "${CMAKE_BINARY_DIR}/share/clang-doc")
+endif()
 set(out_files)
 
 function(copy_files_to_dst src_dir dst_dir file)
@@ -52,4 +56,4 @@ add_custom_target(copy-clang-doc-assets
   COMMENT "Copying Clang-Doc Assets"
 )
 set_target_properties(copy-clang-doc-assets PROPERTIES FOLDER 
"Clang-Doc/Assets")
-add_dependencies(clang-doc copy-clang-doc-assets)
+add_dependencies(clang-doc copy-clang-doc-assets)
\ No newline at end of file

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


[clang-tools-extra] [clang-doc] fix path bug introduced by asset test (PR #97540)

2024-07-03 Thread via cfe-commits

llvmbot wrote:




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

Author: None (PeterChou1)


Changes

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

this patch fixes the bug by copying assets to the correct repository for 
windows builds

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


1 Files Affected:

- (modified) clang-tools-extra/clang-doc/tool/CMakeLists.txt (+6-2) 


``diff
diff --git a/clang-tools-extra/clang-doc/tool/CMakeLists.txt 
b/clang-tools-extra/clang-doc/tool/CMakeLists.txt
index e93a5728d6b6b..3fd41f187a617 100644
--- a/clang-tools-extra/clang-doc/tool/CMakeLists.txt
+++ b/clang-tools-extra/clang-doc/tool/CMakeLists.txt
@@ -25,7 +25,11 @@ set(assets
 )
 
 set(asset_dir "${CMAKE_CURRENT_SOURCE_DIR}/../assets")
-set(resource_dir "${CMAKE_BINARY_DIR}/share/clang-doc")
+if(MSVC)
+  set(resource_dir "${CMAKE_BINARY_DIR}/$/share/clang-doc")
+else()
+  set(resource_dir "${CMAKE_BINARY_DIR}/share/clang-doc")
+endif()
 set(out_files)
 
 function(copy_files_to_dst src_dir dst_dir file)
@@ -52,4 +56,4 @@ add_custom_target(copy-clang-doc-assets
   COMMENT "Copying Clang-Doc Assets"
 )
 set_target_properties(copy-clang-doc-assets PROPERTIES FOLDER 
"Clang-Doc/Assets")
-add_dependencies(clang-doc copy-clang-doc-assets)
+add_dependencies(clang-doc copy-clang-doc-assets)
\ No newline at end of file

``




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


[clang] [llvm] [PowerPC] add TargetParser for PPC target (PR #97541)

2024-07-03 Thread Chen Zheng via cfe-commits

https://github.com/chenzheng1030 created 
https://github.com/llvm/llvm-project/pull/97541

For now only focus on the CPU type, will work on the CPU features part later.

With the CPU handling in TargetParser, clang and llc/opt are able to query 
common interfaces.

So we can set same default CPU and CPU features with same interfaces.

>From 5a2787925bc05453763b2577fd95daa8f39acb1b Mon Sep 17 00:00:00 2001
From: Chen Zheng 
Date: Wed, 3 Jul 2024 04:42:25 -0400
Subject: [PATCH] [PowerPC] add TargetParser for PPC target For now only focus
 on the CPU type, will work on the CPU features part later.

---
 clang/lib/Basic/Targets/PPC.cpp   |  18 +--
 clang/lib/Driver/ToolChains/Arch/PPC.cpp  |  72 ---
 clang/lib/Driver/ToolChains/Arch/PPC.h|   4 -
 clang/lib/Driver/ToolChains/Clang.cpp |   8 +-
 clang/lib/Driver/ToolChains/CommonArgs.cpp|   5 +-
 clang/test/CodeGen/aix-builtin-cpu-is.c   |  42 +++---
 clang/test/Misc/target-invalid-cpu-note.c |   2 +-
 .../llvm/TargetParser/PPCTargetParser.def |  53 +++-
 .../llvm/TargetParser/PPCTargetParser.h   |  37 ++
 llvm/lib/TargetParser/CMakeLists.txt  |   1 +
 llvm/lib/TargetParser/PPCTargetParser.cpp | 121 ++
 .../secondary/llvm/lib/TargetParser/BUILD.gn  |   1 +
 12 files changed, 251 insertions(+), 113 deletions(-)
 create mode 100644 llvm/include/llvm/TargetParser/PPCTargetParser.h
 create mode 100644 llvm/lib/TargetParser/PPCTargetParser.cpp

diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index 89c5566f7ad09..5543f4a100c46 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -14,6 +14,7 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/MacroBuilder.h"
 #include "clang/Basic/TargetBuiltins.h"
+#include "llvm/TargetParser/PPCTargetParser.h"
 
 using namespace clang;
 using namespace clang::targets;
@@ -866,25 +867,12 @@ ArrayRef 
PPCTargetInfo::getGCCAddlRegNames() const {
   return llvm::ArrayRef(GCCAddlRegNames);
 }
 
-static constexpr llvm::StringLiteral ValidCPUNames[] = {
-{"generic"}, {"440"}, {"450"},{"601"},   {"602"},
-{"603"}, {"603e"},{"603ev"},  {"604"},   {"604e"},
-{"620"}, {"630"}, {"g3"}, {"7400"},  {"g4"},
-{"7450"},{"g4+"}, {"750"},{"8548"},  {"970"},
-{"g5"},  {"a2"},  {"e500"},   {"e500mc"},{"e5500"},
-{"power3"},  {"pwr3"},{"power4"}, {"pwr4"},  {"power5"},
-{"pwr5"},{"power5x"}, {"pwr5x"},  {"power6"},{"pwr6"},
-{"power6x"}, {"pwr6x"},   {"power7"}, {"pwr7"},  {"power8"},
-{"pwr8"},{"power9"},  {"pwr9"},   {"power10"},   {"pwr10"},
-{"powerpc"}, {"ppc"}, {"ppc32"},  {"powerpc64"}, {"ppc64"},
-{"powerpc64le"}, {"ppc64le"}, {"future"}};
-
 bool PPCTargetInfo::isValidCPUName(StringRef Name) const {
-  return llvm::is_contained(ValidCPUNames, Name);
+  return llvm::PPC::isValidCPU(Name);
 }
 
 void PPCTargetInfo::fillValidCPUList(SmallVectorImpl &Values) const 
{
-  Values.append(std::begin(ValidCPUNames), std::end(ValidCPUNames));
+  llvm::PPC::fillValidCPUList(Values);
 }
 
 void PPCTargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
diff --git a/clang/lib/Driver/ToolChains/Arch/PPC.cpp 
b/clang/lib/Driver/ToolChains/Arch/PPC.cpp
index 634c096523319..b63e16c22370d 100644
--- a/clang/lib/Driver/ToolChains/Arch/PPC.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/PPC.cpp
@@ -20,78 +20,6 @@ using namespace clang::driver::tools;
 using namespace clang;
 using namespace llvm::opt;
 
-static std::string getPPCGenericTargetCPU(const llvm::Triple &T) {
-  // LLVM may default to generating code for the native CPU,
-  // but, like gcc, we default to a more generic option for
-  // each architecture. (except on AIX)
-  if (T.isOSAIX())
-return "pwr7";
-  else if (T.getArch() == llvm::Triple::ppc64le)
-return "ppc64le";
-  else if (T.getArch() == llvm::Triple::ppc64)
-return "ppc64";
-  else
-return "ppc";
-}
-
-static std::string normalizeCPUName(StringRef CPUName, const llvm::Triple &T) {
-  // Clang/LLVM does not actually support code generation
-  // for the 405 CPU. However, there are uses of this CPU ID
-  // in projects that previously used GCC and rely on Clang
-  // accepting it. Clang has always ignored it and passed the
-  // generic CPU ID to the back end.
-  if (CPUName == "generic" || CPUName == "405")
-return getPPCGenericTargetCPU(T);
-
-  if (CPUName == "native") {
-std::string CPU = std::string(llvm::sys::getHostCPUName());
-if (!CPU.empty() && CPU != "generic")
-  return CPU;
-else
-  return getPPCGenericTargetCPU(T);
-  }
-
-  return llvm::StringSwitch(CPUName)
-  .Case("common", "generic")
-  .Case("440fp", "440")
-  .Case("630", "pwr3")
-  .Case("G3", "g3")
-  .Case("G4", "g4")
-  .Case("G4+", "g4+")
-  .Case("8548

[clang] [llvm] [PowerPC] add TargetParser for PPC target (PR #97541)

2024-07-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-powerpc

Author: Chen Zheng (chenzheng1030)


Changes

For now only focus on the CPU type, will work on the CPU features part later.

With the CPU handling in TargetParser, clang and llc/opt are able to query 
common interfaces.

So we can set same default CPU and CPU features with same interfaces.

---

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


12 Files Affected:

- (modified) clang/lib/Basic/Targets/PPC.cpp (+3-15) 
- (modified) clang/lib/Driver/ToolChains/Arch/PPC.cpp (-72) 
- (modified) clang/lib/Driver/ToolChains/Arch/PPC.h (-4) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+6-2) 
- (modified) clang/lib/Driver/ToolChains/CommonArgs.cpp (+4-1) 
- (modified) clang/test/CodeGen/aix-builtin-cpu-is.c (+25-17) 
- (modified) clang/test/Misc/target-invalid-cpu-note.c (+1-1) 
- (modified) llvm/include/llvm/TargetParser/PPCTargetParser.def (+52-1) 
- (added) llvm/include/llvm/TargetParser/PPCTargetParser.h (+37) 
- (modified) llvm/lib/TargetParser/CMakeLists.txt (+1) 
- (added) llvm/lib/TargetParser/PPCTargetParser.cpp (+121) 
- (modified) llvm/utils/gn/secondary/llvm/lib/TargetParser/BUILD.gn (+1) 


``diff
diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index 89c5566f7ad09..5543f4a100c46 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -14,6 +14,7 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/MacroBuilder.h"
 #include "clang/Basic/TargetBuiltins.h"
+#include "llvm/TargetParser/PPCTargetParser.h"
 
 using namespace clang;
 using namespace clang::targets;
@@ -866,25 +867,12 @@ ArrayRef 
PPCTargetInfo::getGCCAddlRegNames() const {
   return llvm::ArrayRef(GCCAddlRegNames);
 }
 
-static constexpr llvm::StringLiteral ValidCPUNames[] = {
-{"generic"}, {"440"}, {"450"},{"601"},   {"602"},
-{"603"}, {"603e"},{"603ev"},  {"604"},   {"604e"},
-{"620"}, {"630"}, {"g3"}, {"7400"},  {"g4"},
-{"7450"},{"g4+"}, {"750"},{"8548"},  {"970"},
-{"g5"},  {"a2"},  {"e500"},   {"e500mc"},{"e5500"},
-{"power3"},  {"pwr3"},{"power4"}, {"pwr4"},  {"power5"},
-{"pwr5"},{"power5x"}, {"pwr5x"},  {"power6"},{"pwr6"},
-{"power6x"}, {"pwr6x"},   {"power7"}, {"pwr7"},  {"power8"},
-{"pwr8"},{"power9"},  {"pwr9"},   {"power10"},   {"pwr10"},
-{"powerpc"}, {"ppc"}, {"ppc32"},  {"powerpc64"}, {"ppc64"},
-{"powerpc64le"}, {"ppc64le"}, {"future"}};
-
 bool PPCTargetInfo::isValidCPUName(StringRef Name) const {
-  return llvm::is_contained(ValidCPUNames, Name);
+  return llvm::PPC::isValidCPU(Name);
 }
 
 void PPCTargetInfo::fillValidCPUList(SmallVectorImpl &Values) const 
{
-  Values.append(std::begin(ValidCPUNames), std::end(ValidCPUNames));
+  llvm::PPC::fillValidCPUList(Values);
 }
 
 void PPCTargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
diff --git a/clang/lib/Driver/ToolChains/Arch/PPC.cpp 
b/clang/lib/Driver/ToolChains/Arch/PPC.cpp
index 634c096523319..b63e16c22370d 100644
--- a/clang/lib/Driver/ToolChains/Arch/PPC.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/PPC.cpp
@@ -20,78 +20,6 @@ using namespace clang::driver::tools;
 using namespace clang;
 using namespace llvm::opt;
 
-static std::string getPPCGenericTargetCPU(const llvm::Triple &T) {
-  // LLVM may default to generating code for the native CPU,
-  // but, like gcc, we default to a more generic option for
-  // each architecture. (except on AIX)
-  if (T.isOSAIX())
-return "pwr7";
-  else if (T.getArch() == llvm::Triple::ppc64le)
-return "ppc64le";
-  else if (T.getArch() == llvm::Triple::ppc64)
-return "ppc64";
-  else
-return "ppc";
-}
-
-static std::string normalizeCPUName(StringRef CPUName, const llvm::Triple &T) {
-  // Clang/LLVM does not actually support code generation
-  // for the 405 CPU. However, there are uses of this CPU ID
-  // in projects that previously used GCC and rely on Clang
-  // accepting it. Clang has always ignored it and passed the
-  // generic CPU ID to the back end.
-  if (CPUName == "generic" || CPUName == "405")
-return getPPCGenericTargetCPU(T);
-
-  if (CPUName == "native") {
-std::string CPU = std::string(llvm::sys::getHostCPUName());
-if (!CPU.empty() && CPU != "generic")
-  return CPU;
-else
-  return getPPCGenericTargetCPU(T);
-  }
-
-  return llvm::StringSwitch(CPUName)
-  .Case("common", "generic")
-  .Case("440fp", "440")
-  .Case("630", "pwr3")
-  .Case("G3", "g3")
-  .Case("G4", "g4")
-  .Case("G4+", "g4+")
-  .Case("8548", "e500")
-  .Case("G5", "g5")
-  .Case("power3", "pwr3")
-  .Case("power4", "pwr4")
-  .Case("power5", "pwr5")
-  .Case("power5x", "pwr5x")
-  .Case("power6", "pwr6")
-  .Case("power6x", "pwr6x")
-  .Case("p

[clang] [llvm] [PowerPC] add TargetParser for PPC target (PR #97541)

2024-07-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Chen Zheng (chenzheng1030)


Changes

For now only focus on the CPU type, will work on the CPU features part later.

With the CPU handling in TargetParser, clang and llc/opt are able to query 
common interfaces.

So we can set same default CPU and CPU features with same interfaces.

---

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


12 Files Affected:

- (modified) clang/lib/Basic/Targets/PPC.cpp (+3-15) 
- (modified) clang/lib/Driver/ToolChains/Arch/PPC.cpp (-72) 
- (modified) clang/lib/Driver/ToolChains/Arch/PPC.h (-4) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+6-2) 
- (modified) clang/lib/Driver/ToolChains/CommonArgs.cpp (+4-1) 
- (modified) clang/test/CodeGen/aix-builtin-cpu-is.c (+25-17) 
- (modified) clang/test/Misc/target-invalid-cpu-note.c (+1-1) 
- (modified) llvm/include/llvm/TargetParser/PPCTargetParser.def (+52-1) 
- (added) llvm/include/llvm/TargetParser/PPCTargetParser.h (+37) 
- (modified) llvm/lib/TargetParser/CMakeLists.txt (+1) 
- (added) llvm/lib/TargetParser/PPCTargetParser.cpp (+121) 
- (modified) llvm/utils/gn/secondary/llvm/lib/TargetParser/BUILD.gn (+1) 


``diff
diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index 89c5566f7ad09..5543f4a100c46 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -14,6 +14,7 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/MacroBuilder.h"
 #include "clang/Basic/TargetBuiltins.h"
+#include "llvm/TargetParser/PPCTargetParser.h"
 
 using namespace clang;
 using namespace clang::targets;
@@ -866,25 +867,12 @@ ArrayRef 
PPCTargetInfo::getGCCAddlRegNames() const {
   return llvm::ArrayRef(GCCAddlRegNames);
 }
 
-static constexpr llvm::StringLiteral ValidCPUNames[] = {
-{"generic"}, {"440"}, {"450"},{"601"},   {"602"},
-{"603"}, {"603e"},{"603ev"},  {"604"},   {"604e"},
-{"620"}, {"630"}, {"g3"}, {"7400"},  {"g4"},
-{"7450"},{"g4+"}, {"750"},{"8548"},  {"970"},
-{"g5"},  {"a2"},  {"e500"},   {"e500mc"},{"e5500"},
-{"power3"},  {"pwr3"},{"power4"}, {"pwr4"},  {"power5"},
-{"pwr5"},{"power5x"}, {"pwr5x"},  {"power6"},{"pwr6"},
-{"power6x"}, {"pwr6x"},   {"power7"}, {"pwr7"},  {"power8"},
-{"pwr8"},{"power9"},  {"pwr9"},   {"power10"},   {"pwr10"},
-{"powerpc"}, {"ppc"}, {"ppc32"},  {"powerpc64"}, {"ppc64"},
-{"powerpc64le"}, {"ppc64le"}, {"future"}};
-
 bool PPCTargetInfo::isValidCPUName(StringRef Name) const {
-  return llvm::is_contained(ValidCPUNames, Name);
+  return llvm::PPC::isValidCPU(Name);
 }
 
 void PPCTargetInfo::fillValidCPUList(SmallVectorImpl &Values) const 
{
-  Values.append(std::begin(ValidCPUNames), std::end(ValidCPUNames));
+  llvm::PPC::fillValidCPUList(Values);
 }
 
 void PPCTargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
diff --git a/clang/lib/Driver/ToolChains/Arch/PPC.cpp 
b/clang/lib/Driver/ToolChains/Arch/PPC.cpp
index 634c096523319..b63e16c22370d 100644
--- a/clang/lib/Driver/ToolChains/Arch/PPC.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/PPC.cpp
@@ -20,78 +20,6 @@ using namespace clang::driver::tools;
 using namespace clang;
 using namespace llvm::opt;
 
-static std::string getPPCGenericTargetCPU(const llvm::Triple &T) {
-  // LLVM may default to generating code for the native CPU,
-  // but, like gcc, we default to a more generic option for
-  // each architecture. (except on AIX)
-  if (T.isOSAIX())
-return "pwr7";
-  else if (T.getArch() == llvm::Triple::ppc64le)
-return "ppc64le";
-  else if (T.getArch() == llvm::Triple::ppc64)
-return "ppc64";
-  else
-return "ppc";
-}
-
-static std::string normalizeCPUName(StringRef CPUName, const llvm::Triple &T) {
-  // Clang/LLVM does not actually support code generation
-  // for the 405 CPU. However, there are uses of this CPU ID
-  // in projects that previously used GCC and rely on Clang
-  // accepting it. Clang has always ignored it and passed the
-  // generic CPU ID to the back end.
-  if (CPUName == "generic" || CPUName == "405")
-return getPPCGenericTargetCPU(T);
-
-  if (CPUName == "native") {
-std::string CPU = std::string(llvm::sys::getHostCPUName());
-if (!CPU.empty() && CPU != "generic")
-  return CPU;
-else
-  return getPPCGenericTargetCPU(T);
-  }
-
-  return llvm::StringSwitch(CPUName)
-  .Case("common", "generic")
-  .Case("440fp", "440")
-  .Case("630", "pwr3")
-  .Case("G3", "g3")
-  .Case("G4", "g4")
-  .Case("G4+", "g4+")
-  .Case("8548", "e500")
-  .Case("G5", "g5")
-  .Case("power3", "pwr3")
-  .Case("power4", "pwr4")
-  .Case("power5", "pwr5")
-  .Case("power5x", "pwr5x")
-  .Case("power6", "pwr6")
-  .Case("power6x", "pwr6x")
-  .Case("power7", "p

[clang-tools-extra] [clang-doc] fix bug introduced by asset test (PR #97540)

2024-07-03 Thread via cfe-commits

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


[clang] [llvm] [PowerPC] add TargetParser for PPC target (PR #97541)

2024-07-03 Thread Chen Zheng via cfe-commits

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


[clang] [llvm] [PowerPC] add TargetParser for PPC target (PR #97541)

2024-07-03 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 6a992bc89f5ca25d132abd044d78ecf27ae6e162 
5a2787925bc05453763b2577fd95daa8f39acb1b -- 
llvm/include/llvm/TargetParser/PPCTargetParser.h 
llvm/lib/TargetParser/PPCTargetParser.cpp clang/lib/Basic/Targets/PPC.cpp 
clang/lib/Driver/ToolChains/Arch/PPC.cpp clang/lib/Driver/ToolChains/Arch/PPC.h 
clang/lib/Driver/ToolChains/Clang.cpp 
clang/lib/Driver/ToolChains/CommonArgs.cpp 
clang/test/CodeGen/aix-builtin-cpu-is.c 
clang/test/Misc/target-invalid-cpu-note.c
``





View the diff from clang-format here.


``diff
diff --git a/llvm/lib/TargetParser/PPCTargetParser.cpp 
b/llvm/lib/TargetParser/PPCTargetParser.cpp
index 3c7a64c215..c9942c3d8a 100644
--- a/llvm/lib/TargetParser/PPCTargetParser.cpp
+++ b/llvm/lib/TargetParser/PPCTargetParser.cpp
@@ -11,9 +11,9 @@
 //
 
//===--===//
 
+#include "llvm/TargetParser/PPCTargetParser.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/TargetParser/Host.h"
-#include "llvm/TargetParser/PPCTargetParser.h"
 
 namespace llvm {
 namespace PPC {
@@ -118,4 +118,3 @@ StringRef getPPCGenericTuneCPU(const Triple &T, StringRef 
CPUName) {
 
 } // namespace PPC
 } // namespace llvm
-

``




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


[clang] Implement resource binding type prefix mismatch flag setting logic (PR #97103)

2024-07-03 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/97103

>From c784272b3f66ca06be4ab8e72a0963e5ebb6a869 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Fri, 28 Jun 2024 12:40:56 -0700
Subject: [PATCH 01/10] update tests, update code

---
 clang/include/clang/Basic/Attr.td |   2 +-
 .../clang/Basic/DiagnosticSemaKinds.td|   5 +-
 clang/include/clang/Sema/SemaHLSL.h   |   2 +
 clang/lib/Sema/HLSLExternalSemaSource.cpp |  26 +-
 clang/lib/Sema/SemaHLSL.cpp   | 232 +-
 .../ast-dump-comment-cbuffe-tbufferr.hlsl |   2 +
 clang/test/AST/HLSL/cbuffer_tbuffer.hlsl  |   6 +-
 clang/test/AST/HLSL/packoffset.hlsl   |   1 +
 clang/test/AST/HLSL/pch_hlsl_buffer.hlsl  |   2 +
 .../test/AST/HLSL/resource_binding_attr.hlsl  |   6 +-
 .../SemaHLSL/resource_binding_attr_error.hlsl |  21 +-
 .../resource_binding_attr_error_mismatch.hlsl |  74 ++
 12 files changed, 346 insertions(+), 33 deletions(-)
 create mode 100644 
clang/test/SemaHLSL/resource_binding_attr_error_mismatch.hlsl

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 452cd1810f653..c3d67e19656da 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4467,7 +4467,7 @@ def HLSLSV_GroupIndex: HLSLAnnotationAttr {
 
 def HLSLResourceBinding: InheritableAttr {
   let Spellings = [HLSLAnnotation<"register">];
-  let Subjects = SubjectList<[HLSLBufferObj, ExternalGlobalVar]>;
+  let Subjects = SubjectList<[HLSLBufferObj, ExternalGlobalVar], ErrorDiag>;
   let LangOpts = [HLSL];
   let Args = [StringArgument<"Slot">, StringArgument<"Space", 1>];
   let Documentation = [HLSLResourceBindingDocs];
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 96f0c0f0205c2..3bf15ff5f2657 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12303,7 +12303,10 @@ def err_hlsl_missing_semantic_annotation : Error<
 def err_hlsl_init_priority_unsupported : Error<
   "initializer priorities are not supported in HLSL">;
 
-def err_hlsl_unsupported_register_type : Error<"invalid resource class 
specifier '%0' used; expected 'b', 's', 't', or 'u'">;
+def err_hlsl_mismatching_register_resource_type_and_name: Error<"invalid 
register name prefix '%0' for register resource type '%1' (expected 
%select{'t'|'u'|'b'|'s'}2)">;
+def err_hlsl_mismatching_register_builtin_type_and_name: Error<"invalid 
register name prefix '%0' for '%1' (expected %2)">;
+def err_hlsl_unsupported_register_prefix : Error<"invalid resource class 
specifier '%0' used; expected 't', 'u', 'b', or 's'">;
+def err_hlsl_unsupported_register_resource_type : Error<"invalid resource '%0' 
used">;
 def err_hlsl_unsupported_register_number : Error<"register number should be an 
integer">;
 def err_hlsl_expected_space : Error<"invalid space specifier '%0' used; 
expected 'space' followed by an integer, like space1">;
 def warn_hlsl_packoffset_mix : Warning<"cannot mix packoffset elements with 
nonpackoffset elements in a cbuffer">,
diff --git a/clang/include/clang/Sema/SemaHLSL.h 
b/clang/include/clang/Sema/SemaHLSL.h
index 4d6958a1be3e5..d3d36d04d1019 100644
--- a/clang/include/clang/Sema/SemaHLSL.h
+++ b/clang/include/clang/Sema/SemaHLSL.h
@@ -22,6 +22,7 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Sema/Scope.h"
 #include "clang/Sema/SemaBase.h"
+#include "clang/Sema/Sema.h"
 #include 
 
 namespace clang {
@@ -31,6 +32,7 @@ class SemaHLSL : public SemaBase {
 public:
   SemaHLSL(Sema &S);
 
+  HLSLResourceAttr *mergeHLSLResourceAttr(bool CBuffer);
   Decl *ActOnStartBuffer(Scope *BufferScope, bool CBuffer, SourceLocation 
KwLoc,
  IdentifierInfo *Ident, SourceLocation IdentLoc,
  SourceLocation LBrace);
diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp 
b/clang/lib/Sema/HLSLExternalSemaSource.cpp
index a2b29a7bdf505..b82cd8373403a 100644
--- a/clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -490,23 +490,24 @@ void HLSLExternalSemaSource::defineTrivialHLSLTypes() {
 }
 
 /// Set up common members and attributes for buffer types
-static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl *Decl, Sema &S,
-  ResourceClass RC, ResourceKind 
RK,
-  bool IsROV) {
+static BuiltinTypeDeclBuilder setupBufferHandle(CXXRecordDecl *Decl, Sema &S,
+ResourceClass RC) {
   return BuiltinTypeDeclBuilder(Decl)
   .addHandleMember()
-  .addDefaultHandleConstructor(S, RC)
-  .annotateResourceClass(RC, RK, IsROV);
+  .addDefaultHandleConstructor(S, RC);
 }
 
 void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
   CXXRecordDecl *Decl;
-  Decl = 

[clang] [llvm] [Hashing] Use a non-deterministic seed if LLVM_ENABLE_ABI_BREAKING_CHECKS (PR #96282)

2024-07-03 Thread Slava Zakharin via cfe-commits


@@ -322,24 +306,20 @@ struct hash_state {
   }
 };
 
-
-/// A global, fixed seed-override variable.
-///
-/// This variable can be set using the \see llvm::set_fixed_execution_seed
-/// function. See that function for details. Do not, under any circumstances,
-/// set or read this variable.
-extern uint64_t fixed_seed_override;
-
+/// In LLVM_ENABLE_ABI_BREAKING_CHECKS builds, the seed is non-deterministic
+/// (address of a variable) to prevent having users depend on the particular
+/// hash values. On platforms without ASLR, this is still likely
+/// non-deterministic per build.
 inline uint64_t get_execution_seed() {
-  // FIXME: This needs to be a per-execution seed. This is just a placeholder
-  // implementation. Switching to a per-execution seed is likely to flush out
-  // instability bugs and so will happen as its own commit.
-  //
-  // However, if there is a fixed seed override set the first time this is
-  // called, return that instead of the per-execution seed.
-  const uint64_t seed_prime = 0xff51afd7ed558ccdULL;
-  static uint64_t seed = fixed_seed_override ? fixed_seed_override : 
seed_prime;
-  return seed;
+  // Work around x86-64 negative offset folding for old Clang -fno-pic
+  // https://reviews.llvm.org/D93931
+#if LLVM_ENABLE_ABI_BREAKING_CHECKS && 
\
+(!defined(__clang__) || __clang_major__ > 11)

vzakhari wrote:

In my case it is a `Release` build with GCC and `-DLLVM_ENABLE_ASSERTIONS=ON`.

Could you please explain how `__PIC__` check helps?

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


[clang] [compiler-rt] [llvm] [CMake] Use Clang to infer the target triple (PR #89425)

2024-07-03 Thread Petr Hosek via cfe-commits


@@ -183,6 +183,24 @@ message(STATUS "LLVM default target triple: 
${LLVM_DEFAULT_TARGET_TRIPLE}")
 
 set(LLVM_TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}")
 
+if(CMAKE_C_COMPILER_ID MATCHES "Clang")
+  set(option_prefix "")
+  if (CMAKE_C_SIMULATE_ID MATCHES "MSVC")
+set(option_prefix "/clang:")
+  endif()
+  set(print_target_triple ${CMAKE_C_COMPILER} 
${option_prefix}--target=${LLVM_DEFAULT_TARGET_TRIPLE} 
${option_prefix}-print-target-triple)
+  execute_process(COMMAND ${print_target_triple}
+RESULT_VARIABLE result
+OUTPUT_VARIABLE output
+OUTPUT_STRIP_TRAILING_WHITESPACE)
+  if(result EQUAL 0)
+set(LLVM_DEFAULT_TARGET_TRIPLE ${output})
+  else()
+string(REPLACE ";" " " print_target_triple "${print_target_triple}")

petrhosek wrote:

Ditto.

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


[clang] [compiler-rt] [llvm] [CMake] Use Clang to infer the target triple (PR #89425)

2024-07-03 Thread Petr Hosek via cfe-commits


@@ -368,14 +368,22 @@ macro(construct_compiler_rt_default_triple)
   "Default triple for which compiler-rt runtimes will be built.")
   endif()
 
-  if ("${CMAKE_C_COMPILER_ID}" MATCHES "Clang")
+  if(CMAKE_C_COMPILER_ID MATCHES "Clang")
 set(option_prefix "")
 if (CMAKE_C_SIMULATE_ID MATCHES "MSVC")
   set(option_prefix "/clang:")
 endif()
-execute_process(COMMAND ${CMAKE_C_COMPILER} 
${option_prefix}--target=${COMPILER_RT_DEFAULT_TARGET_TRIPLE} 
${option_prefix}-print-target-triple
-OUTPUT_VARIABLE COMPILER_RT_DEFAULT_TARGET_TRIPLE
-OUTPUT_STRIP_TRAILING_WHITESPACE)
+set(print_target_triple ${CMAKE_C_COMPILER} 
${option_prefix}--target=${COMPILER_RT_DEFAULT_TARGET_TRIPLE} 
${option_prefix}-print-target-triple)
+execute_process(COMMAND ${print_target_triple}
+  RESULT_VARIABLE result
+  OUTPUT_VARIABLE output
+  OUTPUT_STRIP_TRAILING_WHITESPACE)
+if(result EQUAL 0)
+  set(COMPILER_RT_DEFAULT_TARGET_TRIPLE ${output})
+else()
+  string(REPLACE ";" " " print_target_triple "${print_target_triple}")
+  message(WARNING "Failed to execute `${print_target_triple}` to normalize 
target triple.")

petrhosek wrote:

Currently we ignore any errors so my preference would be to start with a 
warning and change it to an error in a follow up change after we verify there 
are no issues.

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


[clang] [llvm] [PowerPC] add TargetParser for PPC target (PR #97541)

2024-07-03 Thread Chen Zheng via cfe-commits

https://github.com/chenzheng1030 updated 
https://github.com/llvm/llvm-project/pull/97541

>From 405639a8847111e401d5c2b69bb801c1c0ccadb7 Mon Sep 17 00:00:00 2001
From: Chen Zheng 
Date: Wed, 3 Jul 2024 04:42:25 -0400
Subject: [PATCH] [PowerPC] add TargetParser for PPC target For now only focus
 on the CPU type, will work on the CPU features part later.

---
 clang/lib/Basic/Targets/PPC.cpp   |  18 +--
 clang/lib/Driver/ToolChains/Arch/PPC.cpp  |  72 ---
 clang/lib/Driver/ToolChains/Arch/PPC.h|   4 -
 clang/lib/Driver/ToolChains/Clang.cpp |   8 +-
 clang/lib/Driver/ToolChains/CommonArgs.cpp|   5 +-
 clang/test/CodeGen/aix-builtin-cpu-is.c   |  42 +++---
 clang/test/Misc/target-invalid-cpu-note.c |   2 +-
 .../llvm/TargetParser/PPCTargetParser.def |  53 +++-
 .../llvm/TargetParser/PPCTargetParser.h   |  37 ++
 llvm/lib/TargetParser/CMakeLists.txt  |   1 +
 llvm/lib/TargetParser/PPCTargetParser.cpp | 120 ++
 .../secondary/llvm/lib/TargetParser/BUILD.gn  |   1 +
 12 files changed, 250 insertions(+), 113 deletions(-)
 create mode 100644 llvm/include/llvm/TargetParser/PPCTargetParser.h
 create mode 100644 llvm/lib/TargetParser/PPCTargetParser.cpp

diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index 89c5566f7ad09..5543f4a100c46 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -14,6 +14,7 @@
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/MacroBuilder.h"
 #include "clang/Basic/TargetBuiltins.h"
+#include "llvm/TargetParser/PPCTargetParser.h"
 
 using namespace clang;
 using namespace clang::targets;
@@ -866,25 +867,12 @@ ArrayRef 
PPCTargetInfo::getGCCAddlRegNames() const {
   return llvm::ArrayRef(GCCAddlRegNames);
 }
 
-static constexpr llvm::StringLiteral ValidCPUNames[] = {
-{"generic"}, {"440"}, {"450"},{"601"},   {"602"},
-{"603"}, {"603e"},{"603ev"},  {"604"},   {"604e"},
-{"620"}, {"630"}, {"g3"}, {"7400"},  {"g4"},
-{"7450"},{"g4+"}, {"750"},{"8548"},  {"970"},
-{"g5"},  {"a2"},  {"e500"},   {"e500mc"},{"e5500"},
-{"power3"},  {"pwr3"},{"power4"}, {"pwr4"},  {"power5"},
-{"pwr5"},{"power5x"}, {"pwr5x"},  {"power6"},{"pwr6"},
-{"power6x"}, {"pwr6x"},   {"power7"}, {"pwr7"},  {"power8"},
-{"pwr8"},{"power9"},  {"pwr9"},   {"power10"},   {"pwr10"},
-{"powerpc"}, {"ppc"}, {"ppc32"},  {"powerpc64"}, {"ppc64"},
-{"powerpc64le"}, {"ppc64le"}, {"future"}};
-
 bool PPCTargetInfo::isValidCPUName(StringRef Name) const {
-  return llvm::is_contained(ValidCPUNames, Name);
+  return llvm::PPC::isValidCPU(Name);
 }
 
 void PPCTargetInfo::fillValidCPUList(SmallVectorImpl &Values) const 
{
-  Values.append(std::begin(ValidCPUNames), std::end(ValidCPUNames));
+  llvm::PPC::fillValidCPUList(Values);
 }
 
 void PPCTargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
diff --git a/clang/lib/Driver/ToolChains/Arch/PPC.cpp 
b/clang/lib/Driver/ToolChains/Arch/PPC.cpp
index 634c096523319..b63e16c22370d 100644
--- a/clang/lib/Driver/ToolChains/Arch/PPC.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/PPC.cpp
@@ -20,78 +20,6 @@ using namespace clang::driver::tools;
 using namespace clang;
 using namespace llvm::opt;
 
-static std::string getPPCGenericTargetCPU(const llvm::Triple &T) {
-  // LLVM may default to generating code for the native CPU,
-  // but, like gcc, we default to a more generic option for
-  // each architecture. (except on AIX)
-  if (T.isOSAIX())
-return "pwr7";
-  else if (T.getArch() == llvm::Triple::ppc64le)
-return "ppc64le";
-  else if (T.getArch() == llvm::Triple::ppc64)
-return "ppc64";
-  else
-return "ppc";
-}
-
-static std::string normalizeCPUName(StringRef CPUName, const llvm::Triple &T) {
-  // Clang/LLVM does not actually support code generation
-  // for the 405 CPU. However, there are uses of this CPU ID
-  // in projects that previously used GCC and rely on Clang
-  // accepting it. Clang has always ignored it and passed the
-  // generic CPU ID to the back end.
-  if (CPUName == "generic" || CPUName == "405")
-return getPPCGenericTargetCPU(T);
-
-  if (CPUName == "native") {
-std::string CPU = std::string(llvm::sys::getHostCPUName());
-if (!CPU.empty() && CPU != "generic")
-  return CPU;
-else
-  return getPPCGenericTargetCPU(T);
-  }
-
-  return llvm::StringSwitch(CPUName)
-  .Case("common", "generic")
-  .Case("440fp", "440")
-  .Case("630", "pwr3")
-  .Case("G3", "g3")
-  .Case("G4", "g4")
-  .Case("G4+", "g4+")
-  .Case("8548", "e500")
-  .Case("G5", "g5")
-  .Case("power3", "pwr3")
-  .Case("power4", "pwr4")
-  .Case("power5", "pwr5")
-  .Case("power5x", "pwr5x")
-  .Case("power6", "pwr6")
-  .Case("power6x", "pwr6x")
-  .Case("power7

[clang] [clang][analyzer][doc] Migrate checkers-related docs from HTML to RST (PR #97032)

2024-07-03 Thread via cfe-commits
Endre =?utf-8?q?Fülöp?= ,
Endre =?utf-8?q?Fülöp?= 
Message-ID:
In-Reply-To: 



@@ -678,7 +678,7 @@ Debug Prints and Tricks
 
 Making Your Checker Better
 
-User facing documentation is important for adoption! Make sure the checker list is updated
+User facing documentation is important for adoption! Make sure the https://clang.llvm.org/docs/analyzer/checkers.html";>checker list is 
updated

whisperity wrote:

```suggestion
User facing documentation is important for adoption! Make sure the https://clang.llvm.org/docs/analyzer/checkers.html";>checker list is 
updated
```

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


[clang] [clang][analyzer][doc] Migrate checkers-related docs from HTML to RST (PR #97032)

2024-07-03 Thread via cfe-commits
Endre =?utf-8?q?Fülöp?= ,
Endre =?utf-8?q?Fülöp?= 
Message-ID:
In-Reply-To: 



@@ -126,7 +126,7 @@ Cocoa & Core Foundation Memory 
Management
 Annotations
 
 

whisperity wrote:

This is just a comment, I think we can remove this completely. Also, the 
original URL contained an anchor tag, but the new one does not, so the two 
sides aren't actually equivalent.

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


[clang] [clang][analyzer][doc] Migrate checkers-related docs from HTML to RST (PR #97032)

2024-07-03 Thread via cfe-commits
Endre =?utf-8?q?Fülöp?= ,
Endre =?utf-8?q?Fülöp?= 
Message-ID:
In-Reply-To: 


whisperity wrote:

> > 🤔 Deleting the html files could break some links on external sites, so I 
> > think it would be better to replace them with a very simple "This content 
> > was moved to ``" placeholder.
> 
> Maybe something like this could help: 
> https://stackoverflow.com/questions/5411538/how-to-redirect-one-html-page-to-another-on-load

@gamesh411 Yes, please. :slightly_smiling_face: I think we could do it in a way 
that we say that from 19.0 to 21.0 or something, the redirects (and the 
clickable URL) is there, and then remove everything completely later. Just put 
up a warning that we are redirecting now but the links will break!

(FYI, Tidy check aliases are also implemented via such redirect pages.)

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


[clang] [llvm] Revert changes in AddDefaultGCCPrefixes() for SystemZTriples. (PR #94729)

2024-07-03 Thread Ilya Leoshkevich via cfe-commits

iii-i wrote:

Looking at the code, this is because 
`Generic_GCC::GCCInstallationDetector::init()` will not try to strip any vendor 
except `unknown`. This will in turn cause `s390x-ibm-linux-gnu` to not detect 
GCC installation with prefix `s390x-linux-gnu`, which Debian and Ubuntu have. 
On the other hand, precisely for the same reason, `s390x-unknown-linux-gnu` 
works. Therefore I propose in #95407 to use that.

As to why the code written this way now, I don't have a good explanation, but, 
according to the comments in this PR, this looks intentional.

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


[clang] [Clang] [WIP] Added builtin_alloca right Address Space for OpenCL (PR #95750)

2024-07-03 Thread Matt Arsenault via cfe-commits


@@ -0,0 +1,255 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL1.2 \
+// RUN: -emit-llvm -o - | FileCheck --check-prefix=OPENCL12 %s
+// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL2.0 \
+// RUN: -emit-llvm -o - | FileCheck --check-prefix=OPENCL20 %s
+// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL3.0 \
+// RUN: -emit-llvm -o - | FileCheck --check-prefix=OPENCL30 %s

arsenm wrote:

I meant common prefix. -check-prefixes=OPENCL,OPENCL12 etc. But I don't think 
you should ever get different code 

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


[clang] [Clang] [WIP] Added builtin_alloca right Address Space for OpenCL (PR #95750)

2024-07-03 Thread Vikash Gupta via cfe-commits


@@ -0,0 +1,255 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL1.2 \
+// RUN: -emit-llvm -o - | FileCheck --check-prefix=OPENCL12 %s
+// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL2.0 \
+// RUN: -emit-llvm -o - | FileCheck --check-prefix=OPENCL20 %s
+// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL3.0 \
+// RUN: -emit-llvm -o - | FileCheck --check-prefix=OPENCL30 %s

vg0204 wrote:

yeah, that's true, as now no more address space casting is happening for any 
version of OpenCL!

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


[clang-tools-extra] d8c0734 - [Support] Move raw_ostream::tie to raw_fd_ostream (#97396)

2024-07-03 Thread via cfe-commits

Author: Alexis Engelke
Date: 2024-07-03T11:15:02+02:00
New Revision: d8c07342c021f31f08dee7d15e17f7eca0d1aae0

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

LOG: [Support] Move raw_ostream::tie to raw_fd_ostream (#97396)

Originally, tie was introduced by D81156 to flush stdout before writing
to stderr. 030897523 reverted this due to race conditions. Nonetheless,
it does cost performance, causing an extra check in the "cold" path,
which is actually the hot path for raw_svector_ostream. Given that this
feature is only used for errs(), move it to raw_fd_ostream so that it no
longer affects performance of other stream classes.

Added: 


Modified: 
clang-tools-extra/clangd/index/remote/server/Server.cpp
clang-tools-extra/clangd/tool/ClangdMain.cpp
llvm/include/llvm/Support/raw_ostream.h
llvm/lib/Support/raw_ostream.cpp
llvm/unittests/Support/raw_ostream_test.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/index/remote/server/Server.cpp 
b/clang-tools-extra/clangd/index/remote/server/Server.cpp
index 4ef3ab6f9af9c..52fca53260a16 100644
--- a/clang-tools-extra/clangd/index/remote/server/Server.cpp
+++ b/clang-tools-extra/clangd/index/remote/server/Server.cpp
@@ -499,8 +499,6 @@ int main(int argc, char *argv[]) {
   }
 
   llvm::errs().SetBuffered();
-  // Don't flush stdout when logging for thread safety.
-  llvm::errs().tie(nullptr);
   auto Logger = makeLogger(LogPrefix.getValue(), llvm::errs());
   clang::clangd::LoggingSession LoggingSession(*Logger);
 

diff  --git a/clang-tools-extra/clangd/tool/ClangdMain.cpp 
b/clang-tools-extra/clangd/tool/ClangdMain.cpp
index c3ba655ee2dc6..73000d96c6ca8 100644
--- a/clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ b/clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -840,8 +840,6 @@ clangd accepts flags on the commandline, and in the 
CLANGD_FLAGS environment var
   // Use buffered stream to stderr (we still flush each log message). 
Unbuffered
   // stream can cause significant (non-deterministic) latency for the logger.
   llvm::errs().SetBuffered();
-  // Don't flush stdout when logging, this would be both slow and racy!
-  llvm::errs().tie(nullptr);
   StreamLogger Logger(llvm::errs(), LogLevel);
   LoggingSession LoggingSession(Logger);
   // Write some initial logs before we start doing any real work.

diff  --git a/llvm/include/llvm/Support/raw_ostream.h 
b/llvm/include/llvm/Support/raw_ostream.h
index 0951ffb19ffa1..df9ee2e5a7858 100644
--- a/llvm/include/llvm/Support/raw_ostream.h
+++ b/llvm/include/llvm/Support/raw_ostream.h
@@ -82,10 +82,6 @@ class raw_ostream {
   char *OutBufStart, *OutBufEnd, *OutBufCur;
   bool ColorEnabled = false;
 
-  /// Optional stream this stream is tied to. If this stream is written to, the
-  /// tied-to stream will be flushed first.
-  raw_ostream *TiedStream = nullptr;
-
   enum class BufferKind {
 Unbuffered = 0,
 InternalBuffer,
@@ -360,10 +356,6 @@ class raw_ostream {
 
   bool colors_enabled() const { return ColorEnabled; }
 
-  /// Tie this stream to the specified stream. Replaces any existing tied-to
-  /// stream. Specifying a nullptr unties the stream.
-  void tie(raw_ostream *TieTo) { TiedStream = TieTo; }
-
   
//======//
   // Subclass Interface
   
//======//
@@ -422,9 +414,6 @@ class raw_ostream {
   /// flushing. The result is affected by calls to enable_color().
   bool prepare_colors();
 
-  /// Flush the tied-to stream (if present) and then write the required data.
-  void flush_tied_then_write(const char *Ptr, size_t Size);
-
   virtual void anchor();
 };
 
@@ -475,6 +464,10 @@ class raw_fd_ostream : public raw_pwrite_stream {
   bool IsRegularFile = false;
   mutable std::optional HasColors;
 
+  /// Optional stream this stream is tied to. If this stream is written to, the
+  /// tied-to stream will be flushed first.
+  raw_ostream *TiedStream = nullptr;
+
 #ifdef _WIN32
   /// True if this fd refers to a Windows console device. Mintty and other
   /// terminal emulators are TTYs, but they are not consoles.
@@ -553,6 +546,13 @@ class raw_fd_ostream : public raw_pwrite_stream {
 
   bool has_colors() const override;
 
+  /// Tie this stream to the specified stream. Replaces any existing tied-to
+  /// stream. Specifying a nullptr unties the stream. This is intended for to
+  /// tie errs() to outs(), so that outs() is flushed whenever something is
+  /// written to errs(), preventing weird and hard-to-test output when stderr
+  /// is redirected to stdout.
+  void tie(raw_ostream *TieTo) { TiedStream = TieTo; }
+
   std::error_code error() const { return EC; }
 
   /// Return the value of the flag in this raw_fd_

[clang-tools-extra] [llvm] [Support] Move raw_ostream::tie to raw_fd_ostream (PR #97396)

2024-07-03 Thread Alexis Engelke via cfe-commits

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


[clang] [Clang] [WIP] Added builtin_alloca right Address Space for OpenCL (PR #95750)

2024-07-03 Thread Vikash Gupta via cfe-commits

https://github.com/vg0204 updated 
https://github.com/llvm/llvm-project/pull/95750

>From cbe656fa6db50319e74c0fab166538518506974e Mon Sep 17 00:00:00 2001
From: vg0204 
Date: Mon, 17 Jun 2024 11:20:02 +0530
Subject: [PATCH 1/3] [Clang] [WIP] Added builtin_alloca support for OpenCL1.2
 and below

The __builtin_alloca was returning a flat pointer with no address
space when compiled using openCL1.2 or below but worked fine with
openCL2.0 and above. This accounts to the fact that later uses the
concept of generic address space which supports cast to other address
space(i.e to private address space which is used for stack allocation)
.

So, in  case of openCL1.2 and below __built_alloca is supposed to
return pointer to private address space to eliminate the need of
casting as not supported here. Thus,it requires redefintion of the
builtin function with appropraite return pointer to appropriate
address space.
---
 clang/lib/Sema/SemaExpr.cpp | 23 +-
 clang/test/CodeGenOpenCL/builtins-alloca.cl | 86 +
 clang/test/CodeGenOpenCL/memcpy.cl  |  0
 3 files changed, 106 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/CodeGenOpenCL/builtins-alloca.cl
 mode change 100644 => 100755 clang/test/CodeGenOpenCL/memcpy.cl

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 4db8b4130c3c7..bb63020dadb83 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6231,7 +6231,10 @@ bool Sema::CheckArgsForPlaceholders(MultiExprArg args) {
 ///  it does not contain any pointer arguments without
 ///  an address space qualifer.  Otherwise the rewritten
 ///  FunctionDecl is returned.
-/// TODO: Handle pointer return types.
+///
+/// Pointer return type with no explicit address space is assigned the
+/// default address space where pointer points to based on the language
+/// option used to compile it.
 static FunctionDecl *rewriteBuiltinFunctionDecl(Sema *Sema, ASTContext 
&Context,
 FunctionDecl *FDecl,
 MultiExprArg ArgExprs) {
@@ -6275,13 +6278,27 @@ static FunctionDecl *rewriteBuiltinFunctionDecl(Sema 
*Sema, ASTContext &Context,
 OverloadParams.push_back(Context.getPointerType(PointeeType));
   }
 
+  QualType ReturnTy = FT->getReturnType();
+  QualType OverloadReturnTy = ReturnTy;
+  if (ReturnTy->isPointerType() &&
+  !ReturnTy->getPointeeType().hasAddressSpace()) {
+if (Sema->getLangOpts().OpenCL) {
+  NeedsNewDecl = true;
+
+  QualType ReturnPtTy = ReturnTy->getPointeeType();
+  LangAS defClAS = Context.getDefaultOpenCLPointeeAddrSpace();
+  ReturnPtTy = Context.getAddrSpaceQualType(ReturnPtTy, defClAS);
+  OverloadReturnTy = Context.getPointerType(ReturnPtTy);
+}
+  }
+
   if (!NeedsNewDecl)
 return nullptr;
 
   FunctionProtoType::ExtProtoInfo EPI;
   EPI.Variadic = FT->isVariadic();
-  QualType OverloadTy = Context.getFunctionType(FT->getReturnType(),
-OverloadParams, EPI);
+  QualType OverloadTy =
+  Context.getFunctionType(OverloadReturnTy, OverloadParams, EPI);
   DeclContext *Parent = FDecl->getParent();
   FunctionDecl *OverloadDecl = FunctionDecl::Create(
   Context, Parent, FDecl->getLocation(), FDecl->getLocation(),
diff --git a/clang/test/CodeGenOpenCL/builtins-alloca.cl 
b/clang/test/CodeGenOpenCL/builtins-alloca.cl
new file mode 100644
index 0..74a86955f2e4f
--- /dev/null
+++ b/clang/test/CodeGenOpenCL/builtins-alloca.cl
@@ -0,0 +1,86 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL1.2 -emit-llvm 
-o - | FileCheck --check-prefix=OPENCL12 %s
+// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL2.0 -emit-llvm 
-o - | FileCheck --check-prefix=OPENCL20 %s
+// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL3.0 -emit-llvm 
-o - | FileCheck --check-prefix=OPENCL30 %s
+// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL3.0 
-cl-ext=+__opencl_c_generic_address_space -emit-llvm -o - | FileCheck 
--check-prefix=OPENCL30-EXT %s
+
+// OPENCL12-LABEL: define dso_local ptr addrspace(5) @test1(
+// OPENCL12-SAME: ) #[[ATTR0:[0-9]+]] {
+// OPENCL12-NEXT:  [[ENTRY:.*:]]
+// OPENCL12-NEXT:[[ALLOC_PTR:%.*]] = alloca ptr addrspace(5), align 4, 
addrspace(5)
+// OPENCL12-NEXT:[[TMP0:%.*]] = alloca i8, i64 128, align 8, addrspace(5)
+// OPENCL12-NEXT:store ptr addrspace(5) [[TMP0]], ptr addrspace(5) 
[[ALLOC_PTR]], align 4
+// OPENCL12-NEXT:[[TMP1:%.*]] = load ptr addrspace(5), ptr addrspace(5) 
[[ALLOC_PTR]], align 4
+// OPENCL12-NEXT:ret ptr addrspace(5) [[TMP1]]
+//
+// OPENCL20-LABEL: define dso_local ptr @test1(
+// OPENCL20-SAME: ) #[[ATTR0:[0-9]+]] {
+// OPENCL20-NEXT:  [[ENTRY:.*:]]
+// OPENCL20-NEXT:  

[clang] 5a1a467 - Revert "[AMDGPU][OpenMP] Do not attach -fcuda-is-device flag for AMDGPU OpenMP" (#97531)

2024-07-03 Thread via cfe-commits

Author: Dominik Adamski
Date: 2024-07-03T11:42:32+02:00
New Revision: 5a1a46722948b79803826f1b11877ffcf102c094

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

LOG: Revert "[AMDGPU][OpenMP] Do not attach -fcuda-is-device flag for AMDGPU 
OpenMP" (#97531)

Reverts llvm/llvm-project#96909 (commit ID: 
8bb00cb160830ec8f6029c2aae79d3e46b04b99c)

It breaks OpenMP CI:
https://gitlab.e4s.io/uo-public/llvm-openmp-offloading/-/jobs/283716

Added: 


Modified: 
clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
clang/test/Driver/amdgpu-openmp-toolchain.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp 
b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
index b75d400e6ce91..1c0fb4babe3a5 100644
--- a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
@@ -47,6 +47,8 @@ void AMDGPUOpenMPToolChain::addClangTargetOptions(
   assert(DeviceOffloadingKind == Action::OFK_OpenMP &&
  "Only OpenMP offloading kinds are supported.");
 
+  CC1Args.push_back("-fcuda-is-device");
+
   if (DriverArgs.hasArg(options::OPT_nogpulib))
 return;
 

diff  --git a/clang/test/Driver/amdgpu-openmp-toolchain.c 
b/clang/test/Driver/amdgpu-openmp-toolchain.c
index a153c4afb0ce8..49af04acc4639 100644
--- a/clang/test/Driver/amdgpu-openmp-toolchain.c
+++ b/clang/test/Driver/amdgpu-openmp-toolchain.c
@@ -7,7 +7,7 @@
 
 // verify the tools invocations
 // CHECK: "-cc1" "-triple" 
"x86_64-unknown-linux-gnu"{{.*}}"-emit-llvm-bc"{{.*}}"-x" "c"
-// CHECK: "-cc1" "-triple" "amdgcn-amd-amdhsa" "-aux-triple" 
"x86_64-unknown-linux-gnu"{{.*}}"-target-cpu" "gfx906"
+// CHECK: "-cc1" "-triple" "amdgcn-amd-amdhsa" "-aux-triple" 
"x86_64-unknown-linux-gnu"{{.*}}"-fcuda-is-device"{{.*}}"-target-cpu" "gfx906"
 // CHECK: "-cc1" "-triple" "x86_64-unknown-linux-gnu"{{.*}}"-emit-obj"
 // CHECK: clang-linker-wrapper{{.*}} "-o" "a.out"
 



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


[clang] Revert "[AMDGPU][OpenMP] Do not attach -fcuda-is-device flag for AMDGPU OpenMP" (PR #97531)

2024-07-03 Thread Dominik Adamski via cfe-commits

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


[clang] [Clang] [WIP] Added builtin_alloca right Address Space for OpenCL (PR #95750)

2024-07-03 Thread Vikash Gupta via cfe-commits

https://github.com/vg0204 updated 
https://github.com/llvm/llvm-project/pull/95750

>From cbe656fa6db50319e74c0fab166538518506974e Mon Sep 17 00:00:00 2001
From: vg0204 
Date: Mon, 17 Jun 2024 11:20:02 +0530
Subject: [PATCH 1/4] [Clang] [WIP] Added builtin_alloca support for OpenCL1.2
 and below

The __builtin_alloca was returning a flat pointer with no address
space when compiled using openCL1.2 or below but worked fine with
openCL2.0 and above. This accounts to the fact that later uses the
concept of generic address space which supports cast to other address
space(i.e to private address space which is used for stack allocation)
.

So, in  case of openCL1.2 and below __built_alloca is supposed to
return pointer to private address space to eliminate the need of
casting as not supported here. Thus,it requires redefintion of the
builtin function with appropraite return pointer to appropriate
address space.
---
 clang/lib/Sema/SemaExpr.cpp | 23 +-
 clang/test/CodeGenOpenCL/builtins-alloca.cl | 86 +
 clang/test/CodeGenOpenCL/memcpy.cl  |  0
 3 files changed, 106 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/CodeGenOpenCL/builtins-alloca.cl
 mode change 100644 => 100755 clang/test/CodeGenOpenCL/memcpy.cl

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 4db8b4130c3c7..bb63020dadb83 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6231,7 +6231,10 @@ bool Sema::CheckArgsForPlaceholders(MultiExprArg args) {
 ///  it does not contain any pointer arguments without
 ///  an address space qualifer.  Otherwise the rewritten
 ///  FunctionDecl is returned.
-/// TODO: Handle pointer return types.
+///
+/// Pointer return type with no explicit address space is assigned the
+/// default address space where pointer points to based on the language
+/// option used to compile it.
 static FunctionDecl *rewriteBuiltinFunctionDecl(Sema *Sema, ASTContext 
&Context,
 FunctionDecl *FDecl,
 MultiExprArg ArgExprs) {
@@ -6275,13 +6278,27 @@ static FunctionDecl *rewriteBuiltinFunctionDecl(Sema 
*Sema, ASTContext &Context,
 OverloadParams.push_back(Context.getPointerType(PointeeType));
   }
 
+  QualType ReturnTy = FT->getReturnType();
+  QualType OverloadReturnTy = ReturnTy;
+  if (ReturnTy->isPointerType() &&
+  !ReturnTy->getPointeeType().hasAddressSpace()) {
+if (Sema->getLangOpts().OpenCL) {
+  NeedsNewDecl = true;
+
+  QualType ReturnPtTy = ReturnTy->getPointeeType();
+  LangAS defClAS = Context.getDefaultOpenCLPointeeAddrSpace();
+  ReturnPtTy = Context.getAddrSpaceQualType(ReturnPtTy, defClAS);
+  OverloadReturnTy = Context.getPointerType(ReturnPtTy);
+}
+  }
+
   if (!NeedsNewDecl)
 return nullptr;
 
   FunctionProtoType::ExtProtoInfo EPI;
   EPI.Variadic = FT->isVariadic();
-  QualType OverloadTy = Context.getFunctionType(FT->getReturnType(),
-OverloadParams, EPI);
+  QualType OverloadTy =
+  Context.getFunctionType(OverloadReturnTy, OverloadParams, EPI);
   DeclContext *Parent = FDecl->getParent();
   FunctionDecl *OverloadDecl = FunctionDecl::Create(
   Context, Parent, FDecl->getLocation(), FDecl->getLocation(),
diff --git a/clang/test/CodeGenOpenCL/builtins-alloca.cl 
b/clang/test/CodeGenOpenCL/builtins-alloca.cl
new file mode 100644
index 0..74a86955f2e4f
--- /dev/null
+++ b/clang/test/CodeGenOpenCL/builtins-alloca.cl
@@ -0,0 +1,86 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL1.2 -emit-llvm 
-o - | FileCheck --check-prefix=OPENCL12 %s
+// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL2.0 -emit-llvm 
-o - | FileCheck --check-prefix=OPENCL20 %s
+// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL3.0 -emit-llvm 
-o - | FileCheck --check-prefix=OPENCL30 %s
+// RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL3.0 
-cl-ext=+__opencl_c_generic_address_space -emit-llvm -o - | FileCheck 
--check-prefix=OPENCL30-EXT %s
+
+// OPENCL12-LABEL: define dso_local ptr addrspace(5) @test1(
+// OPENCL12-SAME: ) #[[ATTR0:[0-9]+]] {
+// OPENCL12-NEXT:  [[ENTRY:.*:]]
+// OPENCL12-NEXT:[[ALLOC_PTR:%.*]] = alloca ptr addrspace(5), align 4, 
addrspace(5)
+// OPENCL12-NEXT:[[TMP0:%.*]] = alloca i8, i64 128, align 8, addrspace(5)
+// OPENCL12-NEXT:store ptr addrspace(5) [[TMP0]], ptr addrspace(5) 
[[ALLOC_PTR]], align 4
+// OPENCL12-NEXT:[[TMP1:%.*]] = load ptr addrspace(5), ptr addrspace(5) 
[[ALLOC_PTR]], align 4
+// OPENCL12-NEXT:ret ptr addrspace(5) [[TMP1]]
+//
+// OPENCL20-LABEL: define dso_local ptr @test1(
+// OPENCL20-SAME: ) #[[ATTR0:[0-9]+]] {
+// OPENCL20-NEXT:  [[ENTRY:.*:]]
+// OPENCL20-NEXT:  

[clang] [Clang] fix cast failures by adjusting the resolution of record declaration contexts to handle semantic and lexical distinctions (PR #96228)

2024-07-03 Thread Oleksandr T. via cfe-commits

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


[clang] [Clang] fix cast failures by adjusting the resolution of record declaration contexts to handle semantic and lexical distinctions (PR #96228)

2024-07-03 Thread Oleksandr T. via cfe-commits


@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s

a-tarasyuk wrote:

@shafik @zyn0217 could you review the latest changes? thanks

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


[clang] [Clang] fix cast failures by adjusting the resolution of record declaration contexts to handle semantic and lexical distinctions (PR #96228)

2024-07-03 Thread Oleksandr T. via cfe-commits

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

>From 9e2730da07df0ee5102912490a687ba40bf06def Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Mon, 24 Jun 2024 18:55:51 +0300
Subject: [PATCH] [Clang] fix cast failures by adjusting the resolution of
 record declaration contexts to handle semantic and lexical distinctions

---
 clang/docs/ReleaseNotes.rst|  1 +
 clang/lib/Sema/SemaDeclCXX.cpp |  5 -
 .../class.compare/class.compare.default/p1.cpp | 18 ++
 3 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index df579ae398c5e..86bd8cf4a6210 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -934,6 +934,7 @@ Bug Fixes to C++ Support
 - Fix an assertion failure caused by parsing a lambda used as a default 
argument for the value of a
   forward-declared class. (#GH93512).
 - Fixed a bug in access checking inside return-type-requirement of compound 
requirements. (#GH93788).
+- Fixed failed assertion when resolving context of defaulted comparison method 
outside of struct. (#GH96043).
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 9b220103247dd..0ecad756d4499 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -9192,7 +9192,10 @@ ComputeDefaultedComparisonExceptionSpec(Sema &S, 
SourceLocation Loc,
 EnterExpressionEvaluationContext Context(
 S, Sema::ExpressionEvaluationContext::Unevaluated);
 
-CXXRecordDecl *RD = cast(FD->getLexicalParent());
+CXXRecordDecl *RD =
+cast(FD->getFriendObjectKind() == Decl::FOK_None
+? FD->getDeclContext()
+: FD->getLexicalDeclContext());
 SourceLocation BodyLoc =
 FD->getEndLoc().isValid() ? FD->getEndLoc() : FD->getLocation();
 StmtResult Body =
diff --git a/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp 
b/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
index 252860bfc4de0..ddf82f432c2ea 100644
--- a/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
+++ b/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
@@ -265,3 +265,21 @@ void f2() {
// access info for unnamed bit-field
 }
 }
+
+namespace GH96043 {
+template  class a {};
+template  b c(a);
+template  class e {
+public:
+  typedef a f;
+  f begin();
+};
+template  constexpr bool operator==(d h, g i) {
+  return *c(h.begin()) == *c(i.begin());
+}
+struct j {
+  e bar;
+  bool operator==(const j &) const;
+};
+bool j::operator==(const j &) const = default;
+}

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


[clang] [llvm] [PAC][Driver] Implement `-mbranch-protection=pauthabi` option (PR #97237)

2024-07-03 Thread Daniil Kovalev via cfe-commits

https://github.com/kovdan01 updated 
https://github.com/llvm/llvm-project/pull/97237

>From 3b4b1b1739b810d758e68f30c48b648963cff740 Mon Sep 17 00:00:00 2001
From: Daniil Kovalev 
Date: Mon, 1 Jul 2024 00:50:21 +0300
Subject: [PATCH 1/2] [PAC][Driver] Implement `-mbranch-protection=pauthabi`
 option

Enable the following ptrauth flags when `pauthabi` is passed as branch
protection:

- `intrinsics`;
- `calls`;
- `returns`;
- `auth-traps`;
- `vtable-pointer-address-discrimination`;
- `vtable-pointer-type-discrimination`;
- `init-fini`.

Co-authored-by: Anatoly Trosinenko 
---
 clang/lib/Driver/ToolChains/Clang.cpp | 38 +++
 clang/test/Driver/aarch64-ptrauth.c   | 36 ++
 .../llvm/TargetParser/ARMTargetParserCommon.h |  1 +
 .../TargetParser/ARMTargetParserCommon.cpp|  6 ++-
 4 files changed, 72 insertions(+), 9 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 1b7cc82ea816e..4ed1ece22b7aa 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1484,6 +1484,39 @@ void AddUnalignedAccessWarning(ArgStringList &CmdArgs) {
 }
 }
 
+static void handlePAuthABIOption(const ArgList &DriverArgs,
+ ArgStringList &CC1Args, const Driver &D) {
+  if (!DriverArgs.hasArg(options::OPT_fptrauth_intrinsics,
+ options::OPT_fno_ptrauth_intrinsics))
+CC1Args.push_back("-fptrauth-intrinsics");
+
+  if (!DriverArgs.hasArg(options::OPT_fptrauth_calls,
+ options::OPT_fno_ptrauth_calls))
+CC1Args.push_back("-fptrauth-calls");
+
+  if (!DriverArgs.hasArg(options::OPT_fptrauth_returns,
+ options::OPT_fno_ptrauth_returns))
+CC1Args.push_back("-fptrauth-returns");
+
+  if (!DriverArgs.hasArg(options::OPT_fptrauth_auth_traps,
+ options::OPT_fno_ptrauth_auth_traps))
+CC1Args.push_back("-fptrauth-auth-traps");
+
+  if (!DriverArgs.hasArg(
+  options::OPT_fptrauth_vtable_pointer_address_discrimination,
+  options::OPT_fno_ptrauth_vtable_pointer_address_discrimination))
+CC1Args.push_back("-fptrauth-vtable-pointer-address-discrimination");
+
+  if (!DriverArgs.hasArg(
+  options::OPT_fptrauth_vtable_pointer_type_discrimination,
+  options::OPT_fno_ptrauth_vtable_pointer_type_discrimination))
+CC1Args.push_back("-fptrauth-vtable-pointer-type-discrimination");
+
+  if (!DriverArgs.hasArg(options::OPT_fptrauth_init_fini,
+ options::OPT_fno_ptrauth_init_fini))
+CC1Args.push_back("-fptrauth-init-fini");
+}
+
 static void CollectARMPACBTIOptions(const ToolChain &TC, const ArgList &Args,
 ArgStringList &CmdArgs, bool isAArch64) {
   const Arg *A = isAArch64
@@ -1537,11 +1570,16 @@ static void CollectARMPACBTIOptions(const ToolChain 
&TC, const ArgList &Args,
 if (!isAArch64 && PBP.Key == "b_key")
   D.Diag(diag::warn_unsupported_branch_protection)
   << "b-key" << A->getAsString(Args);
+if (!isAArch64 && PBP.HasPauthABI)
+  D.Diag(diag::warn_unsupported_branch_protection)
+  << "pauthabi" << A->getAsString(Args);
 Scope = PBP.Scope;
 Key = PBP.Key;
 BranchProtectionPAuthLR = PBP.BranchProtectionPAuthLR;
 IndirectBranches = PBP.BranchTargetEnforcement;
 GuardedControlStack = PBP.GuardedControlStack;
+if (isAArch64 && PBP.HasPauthABI)
+  handlePAuthABIOption(Args, CmdArgs, D);
   }
 
   CmdArgs.push_back(
diff --git a/clang/test/Driver/aarch64-ptrauth.c 
b/clang/test/Driver/aarch64-ptrauth.c
index fa0125f4b22a9..dc63545a47a86 100644
--- a/clang/test/Driver/aarch64-ptrauth.c
+++ b/clang/test/Driver/aarch64-ptrauth.c
@@ -13,13 +13,33 @@
 // RUN:   %s 2>&1 | FileCheck %s --check-prefix=ALL
 // ALL: "-cc1"{{.*}} "-fptrauth-intrinsics" "-fptrauth-calls" 
"-fptrauth-returns" "-fptrauth-auth-traps" 
"-fptrauth-vtable-pointer-address-discrimination" 
"-fptrauth-vtable-pointer-type-discrimination" "-fptrauth-init-fini"
 
+// RUN: %clang -### -c --target=aarch64 -mbranch-protection=pauthabi %s 2>&1 | 
\
+// RUN:   FileCheck %s --check-prefix=PAUTHABI1
+// PAUTHABI1: "-cc1"{{.*}} "-fptrauth-intrinsics" "-fptrauth-calls" 
"-fptrauth-returns" "-fptrauth-auth-traps" 
"-fptrauth-vtable-pointer-address-discrimination" 
"-fptrauth-vtable-pointer-type-discrimination" "-fptrauth-init-fini"
+
+// RUN: %clang -### -c --target=aarch64 -mbranch-protection=pauthabi 
-fno-ptrauth-intrinsics \
+// RUN:   -fno-ptrauth-calls -fno-ptrauth-returns -fno-ptrauth-auth-traps \
+// RUN:   -fno-ptrauth-vtable-pointer-address-discrimination 
-fno-ptrauth-vtable-pointer-type-discrimination \
+// RUN:   -fno-ptrauth-init-fini %s 2>&1 | FileCheck %s 
--check-prefix=PAUTHABI2
+// PAUTHABI2-NOT: "-fptrauth-intrinsics"
+// PAUTHABI2-NOT: "-fptrauth-calls"
+// PAUTHABI2-NOT: "-fptrauth-returns"
+// PAUTHABI2-NOT: "-fptrauth-auth-traps"
+//

[clang] [llvm] [PAC][Driver] Implement `-mbranch-protection=pauthabi` option (PR #97237)

2024-07-03 Thread Daniil Kovalev via cfe-commits


@@ -1484,6 +1484,39 @@ void AddUnalignedAccessWarning(ArgStringList &CmdArgs) {
 }
 }
 
+static void handlePAuthABIOption(const ArgList &DriverArgs,

kovdan01 wrote:

I've added the comment, thanks! See fcd090caac9ede6b915db991819298bed4a5d44e

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


[clang] [llvm] [PAC][Driver] Implement `-mbranch-protection=pauthabi` option (PR #97237)

2024-07-03 Thread Daniil Kovalev via cfe-commits


@@ -1484,6 +1484,39 @@ void AddUnalignedAccessWarning(ArgStringList &CmdArgs) {
 }
 }
 
+static void handlePAuthABIOption(const ArgList &DriverArgs,
+ ArgStringList &CC1Args, const Driver &D) {
+  if (!DriverArgs.hasArg(options::OPT_fptrauth_intrinsics,

kovdan01 wrote:

> See addOptInFlag.

Do you mean that we need to replace

```
  if (!DriverArgs.hasArg(options::OPT_fptrauth_xxx,
 options::OPT_fno_ptrauth_xxx))
CC1Args.push_back("-fptrauth-xxx");
```

with

```
  DriverArgs.addOptInFlag(CC1Args, options::OPT_fptrauth_xxx,
  options::OPT_fno_ptrauth_xxx);
```

...?

If so, this does not look correct - `addOptInFlag` would add the flag present 
(if any) in `DriverArgs` to `CC1Args`, but we want to append a list of ptrauth 
flags to cc1 args unconditionally if `pauthabi` is passed as branch protection.

Do I miss smth? I suppose I might have misunderstood you point.

> But the implementation seems quite different from the title/description.

Hmm, it actually looks consistent to me, the implementation seems matching the 
description from my point of view - we want to add a bunch of arguments with 
`-mbranch-protection=pauthabi` used as a shortcut, we do that. Could you please 
describe what is inconsistent between description and implementation in a bit 
more detail?

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


[clang] [Sema] Fix crash in Sema::FindInstantiatedDecl (PR #96509)

2024-07-03 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll commented:

Makes sense to me, but wait for other reviewers.
You published this PR on the first day of WG21 meeting, so it didn't get the 
usual amount of attention.

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


[clang-tools-extra] Fix Default Asset File locator for clang docs (PR #97505)

2024-07-03 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/97505

>From 1c190c9c6b55aec23bab6d7b2a0f489c59285dc7 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Tue, 2 Jul 2024 18:38:24 -0700
Subject: [PATCH 1/3] if debug exists, go up an extra dir

---
 clang-tools-extra/clang-doc/tool/ClangDocMain.cpp | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp 
b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index 6198a6e0cdcc3..b97fa715f9e67 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -167,7 +167,13 @@ llvm::Error getDefaultAssetFiles(const char *Argv0,
 
   llvm::SmallString<128> AssetsPath;
   AssetsPath = llvm::sys::path::parent_path(NativeClangDocPath);
-  llvm::sys::path::append(AssetsPath, "..", "share", "clang-doc");
+  llvm::sys::path::append(AssetsPath, "..");
+  llvm::SmallString<128> tempCopyDbg = AssetsPath;
+  llvm::sys::path::append(tempCopyDbg, "Debug");
+  // index.js may be in the debug
+  if (!llvm::sys::fs::is_directory(tempCopyDbg))
+llvm::sys::path::append(AssetsPath, "..");
+  llvm::sys::path::append(AssetsPath, "share", "clang-doc");
   llvm::SmallString<128> DefaultStylesheet;
   llvm::sys::path::native(AssetsPath, DefaultStylesheet);
   llvm::sys::path::append(DefaultStylesheet,

>From 07662a63e1b3ab2886871f3960246be8219c6ecd Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Tue, 2 Jul 2024 18:45:23 -0700
Subject: [PATCH 2/3] cleanup comment

---
 clang-tools-extra/clang-doc/tool/ClangDocMain.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp 
b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index b97fa715f9e67..ebd0675cd5501 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -170,7 +170,7 @@ llvm::Error getDefaultAssetFiles(const char *Argv0,
   llvm::sys::path::append(AssetsPath, "..");
   llvm::SmallString<128> tempCopyDbg = AssetsPath;
   llvm::sys::path::append(tempCopyDbg, "Debug");
-  // index.js may be in the debug
+  // The executable that ran clangDoc may be in the Debug directory.
   if (!llvm::sys::fs::is_directory(tempCopyDbg))
 llvm::sys::path::append(AssetsPath, "..");
   llvm::sys::path::append(AssetsPath, "share", "clang-doc");

>From ea1d0ce1c2893297e67eebf0a52885681c6a866d Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Wed, 3 Jul 2024 03:12:38 -0700
Subject: [PATCH 3/3] use native to copy path, instead of assignment operator

---
 clang-tools-extra/clang-doc/tool/ClangDocMain.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp 
b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
index ebd0675cd5501..6ec35acfc2db3 100644
--- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -168,7 +168,8 @@ llvm::Error getDefaultAssetFiles(const char *Argv0,
   llvm::SmallString<128> AssetsPath;
   AssetsPath = llvm::sys::path::parent_path(NativeClangDocPath);
   llvm::sys::path::append(AssetsPath, "..");
-  llvm::SmallString<128> tempCopyDbg = AssetsPath;
+  llvm::SmallString<128> tempCopyDbg;
+  llvm::sys::path::native(AssetsPath, tempCopyDbg);
   llvm::sys::path::append(tempCopyDbg, "Debug");
   // The executable that ran clangDoc may be in the Debug directory.
   if (!llvm::sys::fs::is_directory(tempCopyDbg))

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


[clang] [Clang] [WIP] Added builtin_alloca right Address Space for OpenCL (PR #95750)

2024-07-03 Thread Anastasia Stulova via cfe-commits


@@ -1981,6 +1981,29 @@ static bool OpenCLBuiltinToAddr(Sema &S, unsigned 
BuiltinID, CallExpr *Call) {
   return false;
 }
 
+// In OpenCL, __builtin_alloca_* should return a pointer to address space
+// that corresponds to the stack address space i.e private address space.
+static bool OpenCLBuiltinAllocaAddrSpace(Sema &S, CallExpr *TheCall) {

AnastasiaStulova wrote:

Just a nit, since this function also has non-OpenCL specific code, it would 
make more sense to remove OpenCL from the name.

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


[clang] [OpenCL] Emit opencl.cxx.version metadata for C++ (PR #92140)

2024-07-03 Thread Anastasia Stulova via cfe-commits

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

Makes sense! Thanks.

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


[clang] [llvm] [OpenMP] Fix stack corruption due to argument mismatch (PR #96386)

2024-07-03 Thread Sushant Gokhale via cfe-commits

https://github.com/sushgokh updated 
https://github.com/llvm/llvm-project/pull/96386

>From b376f84d9f7debffdb8815628952188c6516dafd Mon Sep 17 00:00:00 2001
From: sgokhale 
Date: Sat, 22 Jun 2024 17:16:24 +0530
Subject: [PATCH] [OpenMP] Fix stack corruption due to argument mismatch

While lowering (#pragma omp target update from), clang's generated
.omp_task_entry. is setting up 9 arguments while calling
__tgt_target_data_update_nowait_mapper.

At the same time, in __tgt_target_data_update_nowait_mapper, call to
targetData() is converted to a sibcall assuming
it has the argument count listed in the signature.

AARCH64 asm sequence for this is as follows (removed unrelated insns):

.omp_task_entry..108:
  sub   sp, sp, #32
  stp   x29, x30, sp, #16   // 16-byte Folded Spill
  add   x29, sp, #16
  str   x8, sp, #8. // stack canary
  str   xzr, [sp]
  bl   __tgt_target_data_update_nowait_mapper

__tgt_target_data_update_nowait_mapper:
  sub   sp, sp, #32
  stp   x29, x30, sp, #16   // 16-byte Folded Spill
  add   x29, sp, #16
  str   x8, sp, #8 // stack canary
  // Sibcall argument setup
  adrp  x8, 
:got:_Z16targetDataUpdateP7ident_tR8DeviceTyiPPvS4_PlS5_S4_S4_R11AsyncInfoTyb
  ldr   x8, [x8, 
:got_lo12:_Z16targetDataUpdateP7ident_tR8DeviceTyiPPvS4_PlS5_S4_S4_R11AsyncInfoTyb]
  stp   x9, x8, x29, #16
  adrp  x8, .L.str.8
  add   x8, x8, :lo12:.L.str.8
  str   x8, x29, #32. <==. This is the insn that erases $fp

  ldp   x29, x30, sp, #16   // 16-byte Folded Reload
  add   sp, sp, #32
  // Sibcall
  b
ZL10targetDataI22TaskAsyncInfoWrapperTyEvP7ident_tliPPvS4_PlS5_S4_S4_PFiS2_R8DeviceTyiS4_S4_S5_S5_S4_S4_R11AsyncInfoTybEPKcSD

On AArch64, call to __tgt_target_data_update_nowait_mapper in .omp_task_entry.
sets up only single space on stack and this results in ovewriting $fp
and subsequent stack corruption. This issue can be credited to discrepancy of
__tgt_target_data_update_nowait_mapper signature in
openmp/libomptarget/include/omptarget.h taking 13 arguments while
clang/lib/CodeGen/CGOpenMPRuntime.cpp and
llvm/include/llvm/Frontend/OpenMP/OMPKinds.def taking only 9 arguments.

This patch modifies __tgt_target_data_update_nowait_mapper signature
to match .omp_task_entry usage(and other 2 files mentioned above).

Co-authored-by: Kugan Vivekanandarajah 
---
 clang/lib/CodeGen/CGOpenMPRuntime.cpp | 23 +++---
 clang/test/OpenMP/declare_mapper_codegen.cpp  |  6 ++--
 .../test/OpenMP/target_enter_data_codegen.cpp |  2 +-
 .../test/OpenMP/target_exit_data_codegen.cpp  |  2 +-
 clang/test/OpenMP/target_update_codegen.cpp   |  2 +-
 .../include/llvm/Frontend/OpenMP/OMPKinds.def | 30 ---
 llvm/test/Transforms/OpenMP/add_attributes.ll | 24 +++
 7 files changed, 50 insertions(+), 39 deletions(-)

diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index b47b521edd32c..f79e8f5f01a56 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -30,6 +30,7 @@
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SetOperations.h"
 #include "llvm/ADT/SmallBitVector.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Bitcode/BitcodeReader.h"
 #include "llvm/IR/Constants.h"
@@ -10341,16 +10342,12 @@ void CGOpenMPRuntime::emitTargetDataStandAloneCall(
 // Source location for the ident struct
 llvm::Value *RTLoc = emitUpdateLocation(CGF, D.getBeginLoc());
 
-llvm::Value *OffloadingArgs[] = {
-RTLoc,
-DeviceID,
-PointerNum,
-InputInfo.BasePointersArray.emitRawPointer(CGF),
-InputInfo.PointersArray.emitRawPointer(CGF),
-InputInfo.SizesArray.emitRawPointer(CGF),
-MapTypesArray,
-MapNamesArray,
-InputInfo.MappersArray.emitRawPointer(CGF)};
+SmallVector OffloadingArgs(
+{RTLoc, DeviceID, PointerNum,
+ InputInfo.BasePointersArray.emitRawPointer(CGF),
+ InputInfo.PointersArray.emitRawPointer(CGF),
+ InputInfo.SizesArray.emitRawPointer(CGF), MapTypesArray, 
MapNamesArray,
+ InputInfo.MappersArray.emitRawPointer(CGF)});
 
 // Select the right runtime function call for each standalone
 // directive.
@@ -10439,6 +10436,12 @@ void CGOpenMPRuntime::emitTargetDataStandAloneCall(
   llvm_unreachable("Unexpected standalone target data directive.");
   break;
 }
+if (HasNowait) {
+  OffloadingArgs.push_back(llvm::Constant::getNullValue(CGF.Int32Ty));
+  OffloadingArgs.push_back(llvm::Constant::getNullValue(CGF.VoidPtrTy));
+  OffloadingArgs.push_back(llvm::Constant::getNullValue(CGF.Int32Ty));
+  OffloadingArgs.push_back(llvm::Constant::getNullValue(CGF.VoidPtrTy));
+}
 CGF.EmitRuntimeCall(
 OMPBuilder.getOrCreateRuntimeFunction(CGM.getModule(), RTLFn),
 OffloadingArgs);
diff --git a/clang/test/OpenMP/declare_mapper_codegen.cpp 
b/clang/test/OpenMP/declare_mapper_codegen.cpp
index 647e2a0

[clang] [Clang][Sema] Treat explicit specializations of static data member templates declared without 'static' as static data members when diagnosing uses of 'auto' (PR #97425)

2024-07-03 Thread Alexander Kornienko via cfe-commits

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


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


[clang] [TBAA] Emit int TBAA metadata on FP math libcalls (PR #96025)

2024-07-03 Thread via cfe-commits

vfdff wrote:

ping ?

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


[clang] [llvm] [X86][CodeGen] security check cookie execute only when needed (PR #95904)

2024-07-03 Thread Simon Pilgrim via cfe-commits


@@ -0,0 +1,247 @@
+//=== X86FixupBufferSecurityCheck.cpp Fix Buffer Security Check 
Call---===//

RKSimon wrote:

X86WinFixupBufferSecurityCheck.cpp

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


[clang] [llvm] [X86][CodeGen] security check cookie execute only when needed (PR #95904)

2024-07-03 Thread Simon Pilgrim via cfe-commits


@@ -0,0 +1,247 @@
+//=== X86FixupBufferSecurityCheck.cpp Fix Buffer Security Check 
Call---===//
+//
+// 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
+//
+//===--===//
+// Buffer Security Check implementation inserts platform specific callback into
+// code. For windows __security_check_cookie call gets call everytime function
+// is return without fixup. Since this function is defined in runtime library,
+// it incures cost of call in dll which simply does comparison and returns most
+// time. With Fixup, We selective move to call in DLL only if comparison fails.
+//===--===//
+
+#include "X86.h"
+#include "X86FrameLowering.h"
+#include "X86InstrInfo.h"
+#include "X86Subtarget.h"
+#include "llvm/CodeGen/LivePhysRegs.h"
+#include "llvm/CodeGen/MachineFunctionPass.h"
+#include "llvm/CodeGen/MachineInstrBuilder.h"
+#include "llvm/CodeGen/MachineRegisterInfo.h"
+#include "llvm/IR/Module.h"
+#include 
+
+using namespace llvm;
+
+#define DEBUG_TYPE "x86-fixup-bscheck"

RKSimon wrote:

Update this name?

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


[clang] [llvm] [X86][CodeGen] security check cookie execute only when needed (PR #95904)

2024-07-03 Thread Simon Pilgrim via cfe-commits


@@ -0,0 +1,247 @@
+//=== X86FixupBufferSecurityCheck.cpp Fix Buffer Security Check 
Call---===//
+//
+// 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
+//
+//===--===//
+// Buffer Security Check implementation inserts platform specific callback into
+// code. For windows __security_check_cookie call gets call everytime function
+// is return without fixup. Since this function is defined in runtime library,
+// it incures cost of call in dll which simply does comparison and returns most
+// time. With Fixup, We selective move to call in DLL only if comparison fails.
+//===--===//
+
+#include "X86.h"
+#include "X86FrameLowering.h"
+#include "X86InstrInfo.h"
+#include "X86Subtarget.h"
+#include "llvm/CodeGen/LivePhysRegs.h"
+#include "llvm/CodeGen/MachineFunctionPass.h"
+#include "llvm/CodeGen/MachineInstrBuilder.h"
+#include "llvm/CodeGen/MachineRegisterInfo.h"
+#include "llvm/IR/Module.h"
+#include 
+
+using namespace llvm;
+
+#define DEBUG_TYPE "x86-fixup-bscheck"
+
+namespace {
+
+class X86WinFixupBufferSecurityCheckPass : public MachineFunctionPass {
+public:
+  static char ID;
+
+  X86WinFixupBufferSecurityCheckPass() : MachineFunctionPass(ID) {}
+
+  StringRef getPassName() const override {
+return "X86 Fixup Buffer Security Check";

RKSimon wrote:

"X86 Windows Fixup Buffer Security Check" ?

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


[clang] [llvm] [X86][CodeGen] security check cookie execute only when needed (PR #95904)

2024-07-03 Thread Simon Pilgrim via cfe-commits

https://github.com/RKSimon commented:

SGTM with a few minors

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


[clang] [Clang] Access tls_guard via llvm.threadlocal.address (PR #96633)

2024-07-03 Thread via cfe-commits

https://github.com/nikola-tesic-ns updated 
https://github.com/llvm/llvm-project/pull/96633

>From 41427a3de345517025477257bfd4f614f06cbcfe Mon Sep 17 00:00:00 2001
From: Nikola Tesic 
Date: Tue, 25 Jun 2024 15:58:18 +0300
Subject: [PATCH 1/3] [Clang] Access tls_guard via llvm.threadlocal.address

This patch fixes compiler generated code in `tls_init` function to access
TLS variable (`tls_guard`) via llvm.threadlocal.address intrinsic.
---
 clang/lib/CodeGen/CGDeclCXX.cpp   | 29 +++---
 clang/test/CodeGenCXX/cxx11-thread-local.cpp  |  9 --
 .../static-initializer-branch-weights.cpp |  3 +-
 clang/test/OpenMP/parallel_copyin_codegen.cpp |  6 ++--
 .../OpenMP/target_has_device_addr_codegen.cpp |  6 ++--
 clang/test/OpenMP/threadprivate_codegen.cpp   | 30 ---
 6 files changed, 55 insertions(+), 28 deletions(-)

diff --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index e18b339b31d24..0663a083bf3e8 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -1059,9 +1059,10 @@ 
CodeGenFunction::GenerateCXXGlobalInitFunc(llvm::Function *Fn,
 if (Guard.isValid()) {
   // If we have a guard variable, check whether we've already performed
   // these initializations. This happens for TLS initialization functions.
-  llvm::Value *GuardVal = Builder.CreateLoad(Guard);
-  llvm::Value *Uninit = Builder.CreateIsNull(GuardVal,
- "guard.uninitialized");
+  llvm::Value *GuardVal = EmitLoadOfScalar(
+  MakeAddrLValue(Guard, getContext().IntTy), SourceLocation());
+  llvm::Value *Uninit =
+  Builder.CreateIsNull(GuardVal, "guard.uninitialized");
   llvm::BasicBlock *InitBlock = createBasicBlock("init");
   ExitBlock = createBasicBlock("exit");
   EmitCXXGuardedInitBranch(Uninit, InitBlock, ExitBlock,
@@ -1070,13 +1071,21 @@ 
CodeGenFunction::GenerateCXXGlobalInitFunc(llvm::Function *Fn,
   // Mark as initialized before initializing anything else. If the
   // initializers use previously-initialized thread_local vars, that's
   // probably supposed to be OK, but the standard doesn't say.
-  Builder.CreateStore(llvm::ConstantInt::get(GuardVal->getType(),1), 
Guard);
-
-  // The guard variable can't ever change again.
-  EmitInvariantStart(
-  Guard.getPointer(),
-  CharUnits::fromQuantity(
-  CGM.getDataLayout().getTypeAllocSize(GuardVal->getType(;
+  EmitStoreOfScalar(llvm::ConstantInt::get(GuardVal->getType(), 1),
+MakeAddrLValue(Guard, getContext().IntTy));
+
+  // Emit invariant start for TLS guard address.
+  if (CGM.getCodeGenOpts().OptimizationLevel > 0) {
+uint64_t Width =
+CGM.getDataLayout().getTypeAllocSize(GuardVal->getType());
+llvm::Value *TLSAddr = Guard.getPointer();
+// Get the thread-local address via intrinsic.
+if (auto *GV = dyn_cast(Guard.getPointer()))
+  if (GV->isThreadLocal())
+TLSAddr = Builder.CreateThreadLocalAddress(Guard.getPointer());
+Builder.CreateInvariantStart(
+TLSAddr, llvm::ConstantInt::getSigned(Int64Ty, Width));
+  }
 }
 
 RunCleanupsScope Scope(*this);
diff --git a/clang/test/CodeGenCXX/cxx11-thread-local.cpp 
b/clang/test/CodeGenCXX/cxx11-thread-local.cpp
index bcc490bc32e6e..e9a0799cf8d9a 100644
--- a/clang/test/CodeGenCXX/cxx11-thread-local.cpp
+++ b/clang/test/CodeGenCXX/cxx11-thread-local.cpp
@@ -358,12 +358,15 @@ void set_anon_i() {
 
 
 // CHECK: define {{.*}}@__tls_init()
-// CHECK: load i8, ptr @__tls_guard
+// CHECK: [[TLS_GUARD_ADDR_1:%.+]] = call align 1 ptr 
@llvm.threadlocal.address.p0(ptr align 1 @__tls_guard)
+// CHECK: load i8, ptr [[TLS_GUARD_ADDR_1]]
 // CHECK: %[[NEED_TLS_INIT:.*]] = icmp eq i8 %{{.*}}, 0
 // CHECK: br i1 %[[NEED_TLS_INIT]],
 // init:
-// CHECK: store i8 1, ptr @__tls_guard
-// CHECK-OPT: call ptr @llvm.invariant.start.p0(i64 1, ptr @__tls_guard)
+// CHECK: [[TLS_GUARD_ADDR_2:%.+]] = call align 1 ptr 
@llvm.threadlocal.address.p0(ptr align 1 @__tls_guard)
+// CHECK: store i8 1, ptr [[TLS_GUARD_ADDR_2]]
+// CHECK-OPT: [[TLS_GUARD_ADDR_3:%.+]] = call align 1 ptr 
@llvm.threadlocal.address.p0(ptr align 1 @__tls_guard)
+// CHECK-OPT: call ptr @llvm.invariant.start.p0(i64 1, ptr 
[[TLS_GUARD_ADDR_3]])
 // CHECK-NOT: call void @[[V_M_INIT]]()
 // CHECK: call void @[[A_INIT]]()
 // CHECK-NOT: call void @[[V_M_INIT]]()
diff --git a/clang/test/CodeGenCXX/static-initializer-branch-weights.cpp 
b/clang/test/CodeGenCXX/static-initializer-branch-weights.cpp
index 121b9b2029959..e855f54643eae 100644
--- a/clang/test/CodeGenCXX/static-initializer-branch-weights.cpp
+++ b/clang/test/CodeGenCXX/static-initializer-branch-weights.cpp
@@ -118,7 +118,8 @@ void use_b() {
 }
 
 // CHECK-LABEL: define {{.*}}tls_init()
-// CHECK: load i8, ptr @__tls_guard, align 1
+// CHECK: [[TLS_GUARD_

[clang] [Clang] Access tls_guard via llvm.threadlocal.address (PR #96633)

2024-07-03 Thread via cfe-commits


@@ -1059,9 +1059,15 @@ 
CodeGenFunction::GenerateCXXGlobalInitFunc(llvm::Function *Fn,
 if (Guard.isValid()) {
   // If we have a guard variable, check whether we've already performed
   // these initializations. This happens for TLS initialization functions.
-  llvm::Value *GuardVal = Builder.CreateLoad(Guard);
-  llvm::Value *Uninit = Builder.CreateIsNull(GuardVal,
- "guard.uninitialized");
+  Address GuardAddr = Guard;
+  if (auto *GV = dyn_cast(Guard.getPointer()))

nikola-tesic-ns wrote:

I've added changes to pass down `IsTLS` flag from the point where variable is 
created. That should ensure we always emit TLS intrinsic.

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


[clang] [Clang] Access tls_guard via llvm.threadlocal.address (PR #96633)

2024-07-03 Thread via cfe-commits


@@ -1059,9 +1059,15 @@ 
CodeGenFunction::GenerateCXXGlobalInitFunc(llvm::Function *Fn,
 if (Guard.isValid()) {
   // If we have a guard variable, check whether we've already performed
   // these initializations. This happens for TLS initialization functions.
-  llvm::Value *GuardVal = Builder.CreateLoad(Guard);
-  llvm::Value *Uninit = Builder.CreateIsNull(GuardVal,
- "guard.uninitialized");
+  Address GuardAddr = Guard;
+  if (auto *GV = dyn_cast(Guard.getPointer()))
+// Get the thread-local address via intrinsic.
+if (GV->isThreadLocal())
+  GuardAddr = GuardAddr.withPointer(
+  Builder.CreateThreadLocalAddress(GV), NotKnownNonNull);
+  llvm::Value *GuardVal = Builder.CreateLoad(GuardAddr);

nikola-tesic-ns wrote:

I think this is related to the conversation in the other comment
> The Guard is a ConstantAddress, so I cannot change it, that's why I 
> introduced new variable. If you have some suggestion, I would be happy to 
> adapt the code.

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


[clang] [Clang] Access tls_guard via llvm.threadlocal.address (PR #96633)

2024-07-03 Thread via cfe-commits

https://github.com/nikola-tesic-ns edited 
https://github.com/llvm/llvm-project/pull/96633
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] bcb7c38 - [C23] Add INFINITY and NAN macros to (#96659)

2024-07-03 Thread via cfe-commits

Author: Aaron Ballman
Date: 2024-07-03T07:23:44-04:00
New Revision: bcb7c38af7de59f3b2201734ee11987839cd7bbe

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

LOG:  [C23] Add INFINITY and NAN macros to  (#96659)

This is in support of WG14 N2848 which only define the macros if
an infinity or nan are supported. However, because we support builtins
that can produce an infinity or a NAN, and because we have pragmas
that control infinity or NAN behavior, we always define the macros even
if the user passed -ffinite-math-only on the command line.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Headers/float.h
clang/test/Headers/float.c
clang/www/c_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1537eaaba0c66..f40fd1cd145bb 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -338,6 +338,11 @@ C23 Feature Support
 - Properly promote bit-fields of bit-precise integer types to the field's type
   rather than to ``int``. #GH87641
 
+- Added the ``INFINITY`` and ``NAN`` macros to Clang's 
+  freestanding implementation; these macros were defined in  in C99
+  but C23 added them to  in
+  `WG14 N2848 `_.
+
 Non-comprehensive list of changes in this release
 -
 

diff  --git a/clang/lib/Headers/float.h b/clang/lib/Headers/float.h
index 642c8f06cc938..a565a33243df1 100644
--- a/clang/lib/Headers/float.h
+++ b/clang/lib/Headers/float.h
@@ -88,6 +88,12 @@
 #  endif
 #endif
 
+#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L) ||  
\
+!defined(__STRICT_ANSI__)
+#  undef INFINITY
+#  undef NAN
+#endif
+
 /* Characteristics of floating point types, C99 5.2.4.2.2 */
 
 #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) ||  
\
@@ -155,6 +161,13 @@
 #  define LDBL_HAS_SUBNORM __LDBL_HAS_DENORM__
 #endif
 
+#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L) ||  
\
+!defined(__STRICT_ANSI__)
+   /* C23 5.2.5.3.3p29-30 */
+#  define INFINITY (__builtin_inf())
+#  define NAN (__builtin_nan(""))
+#endif
+
 #ifdef __STDC_WANT_IEC_60559_TYPES_EXT__
 #  define FLT16_MANT_DIG__FLT16_MANT_DIG__
 #  define FLT16_DECIMAL_DIG __FLT16_DECIMAL_DIG__

diff  --git a/clang/test/Headers/float.c b/clang/test/Headers/float.c
index 70c11b0537537..b9e6e971545e5 100644
--- a/clang/test/Headers/float.c
+++ b/clang/test/Headers/float.c
@@ -1,9 +1,13 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c89 -ffreestanding %s
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c99 -ffreestanding %s
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c11 -ffreestanding %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c23 -ffreestanding %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c23 -ffreestanding 
-ffinite-math-only %s
 // RUN: %clang_cc1 -fsyntax-only -verify -xc++ -std=c++11 -ffreestanding %s
 // RUN: %clang_cc1 -fsyntax-only -verify -xc++ -std=c++14 -ffreestanding %s
 // RUN: %clang_cc1 -fsyntax-only -verify -xc++ -std=c++17 -ffreestanding %s
+// RUN: %clang_cc1 -fsyntax-only -verify -xc++ -std=c++23 -ffreestanding %s
+// RUN: %clang_cc1 -fsyntax-only -verify -xc++ -std=c++23 -ffreestanding 
-ffinite-math-only %s
 // expected-no-diagnostics
 
 /* Basic floating point conformance checks against:
@@ -207,6 +211,21 @@
 #error "Mandatory macros {FLT,DBL,LDBL}_MAX_10_EXP are invalid."
 #endif
 
+#if __STDC_VERSION__ >= 202311L || !defined(__STRICT_ANSI__)
+  #ifndef INFINITY
+#error "Mandatory macro INFINITY is missing."
+  #endif
+  #ifndef NAN
+#error "Mandatory macro NAN is missing."
+  #endif
+#else
+  #ifdef INFINITY
+#error "Macro INFINITY should not be defined."
+  #endif
+  #ifdef NAN
+#error "Macro NAN should not be defined."
+  #endif
+#endif
 
 /* Internal consistency checks */
 _Static_assert(FLT_RADIX == __FLT_RADIX__, "");
@@ -244,3 +263,9 @@ _Static_assert(LDBL_MAX_EXP == __LDBL_MAX_EXP__, "");
 _Static_assert(FLT_MAX_10_EXP == __FLT_MAX_10_EXP__, "");
 _Static_assert(DBL_MAX_10_EXP == __DBL_MAX_10_EXP__, "");
 _Static_assert(LDBL_MAX_10_EXP == __LDBL_MAX_10_EXP__, "");
+
+#if (__STDC_VERSION__ >= 202311L || !defined(__STRICT_ANSI__)) && 
__FINITE_MATH_ONLY__ == 0
+// Ensure INFINITY and NAN are suitable for use in a constant expression.
+float f1 = INFINITY;
+float f2 = NAN;
+#endif

diff  --git a/clang/www/c_status.html b/clang/www/c_status.html
index ccb39a15b25aa..3fb1efc1989e8 100644
--- a/clang/www/c_status.html
+++ b/clang/www/c_status.html
@@ -995,7 +995,7 @@ C23 implementation status
 
   Contradiction about INFINITY macro
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2

[clang] [C23] Add INFINITY and NAN macros to (PR #96659)

2024-07-03 Thread Aaron Ballman via cfe-commits

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


[clang] 5fd5b8a - [OpenCL] Emit opencl.cxx.version metadata for C++ (#92140)

2024-07-03 Thread via cfe-commits

Author: Sven van Haastregt
Date: 2024-07-03T13:24:22+02:00
New Revision: 5fd5b8ada70d9cbdaa8cc5bea50a6314e3140364

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

LOG: [OpenCL] Emit opencl.cxx.version metadata for C++ (#92140)

Currently there is no way to tell whether an IR module was generated
using `-cl-std=cl3.0` or `-cl-std=clc++2021`, i.e., whether the origin
was a OpenCL C or C++ for OpenCL source.

Add new `opencl.cxx.version` named metadata when compiling C++. Keep the
`opencl.ocl.version` metadata to convey the compatible OpenCL C version.

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

Added: 
clang/test/CodeGenOpenCLCXX/version.clcpp

Modified: 
clang/lib/CodeGen/CodeGenModule.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 652f519d82488..99e986d371cac 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1399,17 +1399,25 @@ void CodeGenModule::Release() {
 void CodeGenModule::EmitOpenCLMetadata() {
   // SPIR v2.0 s2.13 - The OpenCL version used by the module is stored in the
   // opencl.ocl.version named metadata node.
-  // C++ for OpenCL has a distinct mapping for versions compatibile with 
OpenCL.
-  auto Version = LangOpts.getOpenCLCompatibleVersion();
-  llvm::Metadata *OCLVerElts[] = {
-  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
-  Int32Ty, Version / 100)),
-  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
-  Int32Ty, (Version % 100) / 10))};
-  llvm::NamedMDNode *OCLVerMD =
-  TheModule.getOrInsertNamedMetadata("opencl.ocl.version");
-  llvm::LLVMContext &Ctx = TheModule.getContext();
-  OCLVerMD->addOperand(llvm::MDNode::get(Ctx, OCLVerElts));
+  // C++ for OpenCL has a distinct mapping for versions compatible with OpenCL.
+  auto CLVersion = LangOpts.getOpenCLCompatibleVersion();
+
+  auto EmitVersion = [this](StringRef MDName, int Version) {
+llvm::Metadata *OCLVerElts[] = {
+llvm::ConstantAsMetadata::get(
+llvm::ConstantInt::get(Int32Ty, Version / 100)),
+llvm::ConstantAsMetadata::get(
+llvm::ConstantInt::get(Int32Ty, (Version % 100) / 10))};
+llvm::NamedMDNode *OCLVerMD = TheModule.getOrInsertNamedMetadata(MDName);
+llvm::LLVMContext &Ctx = TheModule.getContext();
+OCLVerMD->addOperand(llvm::MDNode::get(Ctx, OCLVerElts));
+  };
+
+  EmitVersion("opencl.ocl.version", CLVersion);
+  if (LangOpts.OpenCLCPlusPlus) {
+// In addition to the OpenCL compatible version, emit the C++ version.
+EmitVersion("opencl.cxx.version", LangOpts.OpenCLCPlusPlusVersion);
+  }
 }
 
 void CodeGenModule::EmitBackendOptionsMetadata(

diff  --git a/clang/test/CodeGenOpenCLCXX/version.clcpp 
b/clang/test/CodeGenOpenCLCXX/version.clcpp
new file mode 100644
index 0..2f2aa022afab2
--- /dev/null
+++ b/clang/test/CodeGenOpenCLCXX/version.clcpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 %s -triple "spir64-unknown-unknown" -emit-llvm -o - 
-cl-std=CL2.0 | FileCheck %s --check-prefix=CHECK-NO-CXX
+
+// RUN: %clang_cc1 %s -triple "spir64-unknown-unknown" -emit-llvm -o - 
-cl-std=clc++1.0 | FileCheck %s --check-prefix=CHECK-CXX100
+// RUN: %clang_cc1 %s -triple "spir64-unknown-unknown" -emit-llvm -o - 
-cl-std=clc++2021 | FileCheck %s --check-prefix=CHECK-CXX2021
+
+// This test checks that opencl.cxx.version metadata is emitted accordingly.
+// It avoids any C++ features to enable checking that the metadata is not 
emitted in non-C++ mode.
+
+kernel void foo() {}
+
+// CHECK-NO-CXX-NOT: opencl.cxx.version
+
+// CHECK-CXX100-DAG: !opencl.ocl.version = !{[[OCL:![0-9]+]]}
+// CHECK-CXX100-DAG: !opencl.cxx.version = !{[[CXX:![0-9]+]]}
+// CHECK-CXX100-DAG: [[OCL]] = !{i32 2, i32 0}
+// CHECK-CXX100-DAG: [[CXX]] = !{i32 1, i32 0}
+
+// CHECK-CXX2021-DAG: !opencl.ocl.version = !{[[OCL:![0-9]+]]}
+// CHECK-CXX2021-DAG: !opencl.cxx.version = !{[[CXX:![0-9]+]]}
+// CHECK-CXX2021-DAG: [[OCL]] = !{i32 3, i32 0}
+// CHECK-CXX2021-DAG: [[CXX]] = !{i32 2021, i32 0}



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


[clang] [OpenCL] Emit opencl.cxx.version metadata for C++ (PR #92140)

2024-07-03 Thread Sven van Haastregt via cfe-commits

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


[clang] [llvm] [mlir] [OMPIRBuilder] - Handle dependencies in `createTarget` (PR #93977)

2024-07-03 Thread Sergio Afonso via cfe-commits

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

Thank you Pranav, LGTM. I have just one more comment but no need to wait for 
another review by me before merging this. Just make sure @Meinersbur is happy 
with it as well!

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


[clang] [llvm] [mlir] [OMPIRBuilder] - Handle dependencies in `createTarget` (PR #93977)

2024-07-03 Thread Sergio Afonso via cfe-commits

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


[clang] [llvm] [mlir] [OMPIRBuilder] - Handle dependencies in `createTarget` (PR #93977)

2024-07-03 Thread Sergio Afonso via cfe-commits


@@ -682,6 +682,41 @@ convertOmpTeams(omp::TeamsOp op, llvm::IRBuilderBase 
&builder,
   return bodyGenStatus;
 }
 
+static void
+buildDependData(Operation *op, LLVM::ModuleTranslation &moduleTranslation,

skatrak wrote:

I'd suggest taking `std::optional depends` and `OperandRange 
dependVars` as arguments instead of `Operation *op` here. This way you don't 
need to try casting `op` to each supported operation below, but rather make the 
body of this function what the `processDepends` lambda inside currently has.

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


[clang] [llvm] [mlir] [OMPIRBuilder] - Handle dependencies in `createTarget` (PR #93977)

2024-07-03 Thread Sergio Afonso via cfe-commits


@@ -705,28 +740,7 @@ convertOmpTaskOp(omp::TaskOp taskOp, llvm::IRBuilderBase 
&builder,
   };
 
   SmallVector dds;
-  if (!taskOp.getDependVars().empty() && taskOp.getDepends()) {
-for (auto dep :
- llvm::zip(taskOp.getDependVars(), taskOp.getDepends()->getValue())) {
-  llvm::omp::RTLDependenceKindTy type;
-  switch (
-  cast(std::get<1>(dep)).getValue()) {
-  case mlir::omp::ClauseTaskDepend::taskdependin:
-type = llvm::omp::RTLDependenceKindTy::DepIn;
-break;
-  // The OpenMP runtime requires that the codegen for 'depend' clause for
-  // 'out' dependency kind must be the same as codegen for 'depend' clause
-  // with 'inout' dependency.
-  case mlir::omp::ClauseTaskDepend::taskdependout:
-  case mlir::omp::ClauseTaskDepend::taskdependinout:
-type = llvm::omp::RTLDependenceKindTy::DepInOut;
-break;
-  };
-  llvm::Value *depVal = moduleTranslation.lookupValue(std::get<0>(dep));
-  llvm::OpenMPIRBuilder::DependData dd(type, depVal->getType(), depVal);
-  dds.emplace_back(dd);
-}
-  }
+  buildDependData(taskOp.getOperation(), moduleTranslation, dds);

skatrak wrote:

Suggestion to how this call could look if following my comment above:
```suggestion
  buildDependData(moduleTranslation, taskOp.getDepends(), 
taskOp.getDependVars(), dds);
```

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


[clang] clang: Relax LangOpts checks when lexing quoted numbers during preprocessing (PR #95798)

2024-07-03 Thread Aaron Ballman via cfe-commits


@@ -2068,7 +2068,8 @@ bool Lexer::LexNumericConstant(Token &Result, const char 
*CurPtr) {
   }
 
   // If we have a digit separator, continue.
-  if (C == '\'' && (LangOpts.CPlusPlus14 || LangOpts.C23)) {
+  if (C == '\'' &&
+  (LangOpts.CPlusPlus14 || LangOpts.C23 || ParsingPreprocessorDirective)) {

AaronBallman wrote:

There's not a one-to-one mapping of `LangOptions` to frontend of driver 
options, yes. But I think it's a stretch to argue that the standard mode 
tracked by `LangOptions` is not exposed via flags.

I don't think per-feature `LangOptions` is viable. There's digit separators, 
hex float support, binary literal support, different literal suffixes, various 
keywords, etc and that doesn't seem likely to scale well. Also, it makes it 
seem like we support a la carte language features when we don't -- we 
intentionally don't want to let users disable standard features (in general; 
exceptions exist) and so that approach gives the impression contributors need 
to check both language mode and feature availability which is a maintenance 
concern.

I'm still wondering about the question I asked here: 
https://github.com/llvm/llvm-project/pull/93753#issuecomment-217302

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


[clang] [NFC] Add assertion to ensure FiniteMathOnly is in sync with HonorINFs and HonorNANs. (PR #97342)

2024-07-03 Thread Aaron Ballman via cfe-commits


@@ -816,6 +816,11 @@ class FPOptions {
 setAllowFPReassociate(LO.AllowFPReassoc);
 setNoHonorNaNs(LO.NoHonorNaNs);
 setNoHonorInfs(LO.NoHonorInfs);
+// Ensure that if FiniteMathOnly is enabled, NoHonorNaNs and NoHonorInfs 
are
+// also enabled. This is because FiniteMathOnly mode assumes no NaNs or 
Infs
+// are present in computations.
+if (!LO.NoHonorInfs || !LO.NoHonorInfs)
+  assert(!LO.FiniteMathOnly && "FiniteMathOnly implies NoHonorInfs");

AaronBallman wrote:

> There is quite a bit of LIT tests that have that "logic bug" then. They are 
> using -Xclang -menable-no-infs -Xclang  -menable-no-nan without the 
> -ffinite-math-only option.

I didn't mean the logic bug was on the user end; I meant that our internal 
state has the logic bug because `!FiniteMathOnly` implies that infinities are 
supported and so it logically conflicts with `!HonorInfs`.

> Getting rid of FiniteMathOnly is fine by me.
FiniteMathOnly = !HonorINFs && !HonorNaNs which would mean -menable-no-infs 
-menable-non-nans. I would think using one or the other of these options could 
still mean that input values may be either INF or NAN or we can produce them, 
in which case we wouldn't be in finite math mode.

I can see the logic there and I think that's defensible, but because 
`FiniteMathOnly` determines the value `__FINITE_MATH_ONLY__` expands to, we 
should probably see how that flag is being used in the wild to see whether 
folks expect it to be `1` or `0` when infinity is enabled but NAN is disabled 
(for example).

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


[clang-tools-extra] [llvm] [Support] Move raw_ostream::tie to raw_fd_ostream (PR #97396)

2024-07-03 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

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

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

Here is the relevant piece of the build log for the reference:
```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
llvm-lit: 
/b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60:
 warning: Path reported by clang does not exist: 
"/b/sanitizer-aarch64-linux/build/build_debug/lib/clang/19/lib/aarch64-unknown-linux-gnu".
 This path was found by running 
['/b/sanitizer-aarch64-linux/build/build_debug/./bin/clang', 
'--target=aarch64-unknown-linux-gnu', '-Wthread-safety', 
'-Wthread-safety-reference', '-Wthread-safety-beta', '-print-runtime-dir'].
llvm-lit: 
/b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60:
 warning: Path reported by clang does not exist: 
"/b/sanitizer-aarch64-linux/build/build_debug/lib/clang/19/lib/aarch64-unknown-linux-gnu".
 This path was found by running 
['/b/sanitizer-aarch64-linux/build/build_debug/./bin/clang', 
'--target=aarch64-unknown-linux-gnu', '-Wthread-safety', 
'-Wthread-safety-reference', '-Wthread-safety-beta', '-print-runtime-dir'].
llvm-lit: 
/b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60:
 warning: Path reported by clang does not exist: 
"/b/sanitizer-aarch64-linux/build/build_debug/lib/clang/19/lib/aarch64-unknown-linux-gnu".
 This path was found by running 
['/b/sanitizer-aarch64-linux/build/build_debug/./bin/clang', 
'--target=aarch64-unknown-linux-gnu', '-Wthread-safety', 
'-Wthread-safety-reference', '-Wthread-safety-beta', '-print-runtime-dir'].
llvm-lit: 
/b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60:
 warning: Path reported by clang does not exist: 
"/b/sanitizer-aarch64-linux/build/build_debug/lib/clang/19/lib/aarch64-unknown-linux-gnu".
 This path was found by running 
['/b/sanitizer-aarch64-linux/build/build_debug/./bin/clang', 
'--target=aarch64-unknown-linux-gnu', '-Wthread-safety', 
'-Wthread-safety-reference', '-Wthread-safety-beta', '-print-runtime-dir'].
llvm-lit: 
/b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60:
 warning: Path reported by clang does not exist: 
"/b/sanitizer-aarch64-linux/build/build_debug/lib/clang/19/lib/aarch64-unknown-linux-gnu".
 This path was found by running 
['/b/sanitizer-aarch64-linux/build/build_debug/./bin/clang', 
'--target=aarch64-unknown-linux-gnu', '-Wthread-safety', 
'-Wthread-safety-reference', '-Wthread-safety-beta', '-print-runtime-dir'].
llvm-lit: 
/b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60:
 warning: Path reported by clang does not exist: 
"/b/sanitizer-aarch64-linux/build/build_debug/lib/clang/19/lib/aarch64-unknown-linux-gnu".
 This path was found by running 
['/b/sanitizer-aarch64-linux/build/build_debug/./bin/clang', 
'--target=aarch64-unknown-linux-gnu', '-Wthread-safety', 
'-Wthread-safety-reference', '-Wthread-safety-beta', '-print-runtime-dir'].
llvm-lit: 
/b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60:
 warning: Path reported by clang does not exist: 
"/b/sanitizer-aarch64-linux/build/build_debug/lib/clang/19/lib/aarch64-unknown-linux-gnu".
 This path was found by running 
['/b/sanitizer-aarch64-linux/build/build_debug/./bin/clang', 
'--target=aarch64-unknown-linux-gnu', '-Wthread-safety', 
'-Wthread-safety-reference', '-Wthread-safety-beta', '-print-runtime-dir'].
llvm-lit: 
/b/sanitizer-aarch64-linux/build/llvm-project/llvm/utils/lit/lit/main.py:72: 
note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 900 seconds was requested on the command line. Forcing 
timeout to be 900 seconds.
-- Testing: 2598 of 5474 tests, 48 workers --
Testing: 
FAIL: libFuzzer-aarch64-default-Linux :: fuzzer-leak.test (1 of 2598)
 TEST 'libFuzzer-aarch64-default-Linux :: fuzzer-leak.test' 
FAILED 
Exit Code: 1

Command Output (stderr):
--
RUN: at line 3: /b/sanitizer-aarch64-linux/build/build_debug/./bin/clang
-Wthread-safety -Wthread-safety-reference -Wthread-safety-beta   
--driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer 
-I/b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/lib/fuzzer  
-Wthread-safety -Wthread-safety-reference -Wthread-safety-beta  
/b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/test/fuzzer/LeakTest.cpp
 -o 
/b/sanitizer-aarch64-linux/build/build_debug/runtimes/runtimes-bins/compiler-rt/test/fuzzer/AARCH64DefaultLinuxConfig/Output/fuzzer-leak.test.tmp-LeakTest
+ /b/sanitizer-aarch64-linux/build/build_debug/./bin/clang -Wthread-safety 
-Wthread-safety-reference -Wt

[clang] [flang] [Flang-new][OpenMP] Add bitcode files for AMD GPU OpenMP (PR #96742)

2024-07-03 Thread Dominik Adamski via cfe-commits

https://github.com/DominikAdamski updated 
https://github.com/llvm/llvm-project/pull/96742

>From 5b487aac3c8414b6f37f6888f361ca7488094048 Mon Sep 17 00:00:00 2001
From: Dominik Adamski 
Date: Fri, 21 Jun 2024 18:03:53 +0200
Subject: [PATCH 1/4] [Flang-new][OpenMP] Add offload related flags for AMDGPU

Flang-new needs to add mlink-builtin-bitcode objects
to properly support offload code generation for AMD GPU.

fcuda-is-device flag is not used by Flang currently.
In the future it will be needed for Flang equivalent function:
AMDGPUTargetCodeGenInfo::getGlobalVarAddressSpace.
---
 clang/include/clang/Driver/Options.td |  4 +-
 clang/lib/Driver/ToolChains/Flang.cpp |  3 ++
 flang/test/Driver/omp-driver-offload.f90  | 58 +--
 flang/test/Driver/target-cpu-features.f90 |  4 +-
 flang/test/Driver/target-gpu-features.f90 |  2 +-
 5 files changed, 41 insertions(+), 30 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index dd55838dcf384..612d5793232ce 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8016,7 +8016,7 @@ def source_date_epoch : Separate<["-"], 
"source-date-epoch">,
 // CUDA Options
 
//===--===//
 
-let Visibility = [CC1Option] in {
+let Visibility = [CC1Option, FC1Option] in {
 
 def fcuda_is_device : Flag<["-"], "fcuda-is-device">,
   HelpText<"Generate code for CUDA device">,
@@ -8031,7 +8031,7 @@ def fno_cuda_host_device_constexpr : Flag<["-"], 
"fno-cuda-host-device-constexpr
   HelpText<"Don't treat unattributed constexpr functions as __host__ 
__device__.">,
   MarshallingInfoNegativeFlag>;
 
-} // let Visibility = [CC1Option]
+} // let Visibility = [CC1Option, FC1Option]
 
 
//===--===//
 // OpenMP Options
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 42b45dba2bd31..2679f284c5016 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -333,6 +333,9 @@ void Flang::AddAMDGPUTargetArgs(const ArgList &Args,
 StringRef Val = A->getValue();
 CmdArgs.push_back(Args.MakeArgString("-mcode-object-version=" + Val));
   }
+
+  const ToolChain &TC = getToolChain();
+  TC.addClangTargetOptions(Args, CmdArgs, Action::OffloadKind::OFK_OpenMP);
 }
 
 void Flang::addTargetOptions(const ArgList &Args,
diff --git a/flang/test/Driver/omp-driver-offload.f90 
b/flang/test/Driver/omp-driver-offload.f90
index 6fb4f4ca1..da81a6ee3ba8f 100644
--- a/flang/test/Driver/omp-driver-offload.f90
+++ b/flang/test/Driver/omp-driver-offload.f90
@@ -14,12 +14,12 @@
 ! Test regular -fopenmp with offload, and invocation filtering options
 ! RUN: %flang -S -### %s -o %t 2>&1 \
 ! RUN: -fopenmp --offload-arch=gfx90a --offload-arch=sm_70 \
-! RUN: --target=aarch64-unknown-linux-gnu \
+! RUN: --target=aarch64-unknown-linux-gnu -nogpulib\
 ! RUN:   | FileCheck %s --check-prefix=OFFLOAD-HOST-AND-DEVICE
 
 ! RUN: %flang -S -### %s -o %t 2>&1 \
 ! RUN: -fopenmp --offload-arch=gfx90a --offload-arch=sm_70 
--offload-host-device \
-! RUN: --target=aarch64-unknown-linux-gnu \
+! RUN: --target=aarch64-unknown-linux-gnu -nogpulib\
 ! RUN:   | FileCheck %s --check-prefix=OFFLOAD-HOST-AND-DEVICE
 
 ! OFFLOAD-HOST-AND-DEVICE: "{{[^"]*}}flang-new" "-fc1" "-triple" 
"aarch64-unknown-linux-gnu"
@@ -29,7 +29,7 @@
 
 ! RUN: %flang -S -### %s -o %t 2>&1 \
 ! RUN: -fopenmp --offload-arch=gfx90a --offload-arch=sm_70 --offload-host-only 
\
-! RUN: --target=aarch64-unknown-linux-gnu \
+! RUN: --target=aarch64-unknown-linux-gnu -nogpulib\
 ! RUN:   | FileCheck %s --check-prefix=OFFLOAD-HOST
 
 ! OFFLOAD-HOST: "{{[^"]*}}flang-new" "-fc1" "-triple" 
"aarch64-unknown-linux-gnu"
@@ -39,7 +39,7 @@
 
 ! RUN: %flang -S -### %s 2>&1 \
 ! RUN: -fopenmp --offload-arch=gfx90a --offload-arch=sm_70 
--offload-device-only \
-! RUN: --target=aarch64-unknown-linux-gnu \
+! RUN: --target=aarch64-unknown-linux-gnu -nogpulib\
 ! RUN:   | FileCheck %s --check-prefix=OFFLOAD-DEVICE
 
 ! OFFLOAD-DEVICE: "{{[^"]*}}flang-new" "-fc1" "-triple" 
"aarch64-unknown-linux-gnu"
@@ -48,13 +48,13 @@
 ! OFFLOAD-DEVICE-NOT: "{{[^"]*}}flang-new" "-fc1" "-triple" 
"aarch64-unknown-linux-gnu"
 
 ! Test regular -fopenmp with offload for basic fopenmp-is-target-device flag 
addition and correct fopenmp 
-! RUN: %flang -### -fopenmp --offload-arch=gfx90a 
-fopenmp-targets=amdgcn-amd-amdhsa %s 2>&1 | FileCheck 
--check-prefixes=CHECK-OPENMP-IS-TARGET-DEVICE %s
+! RUN: %flang -### -fopenmp --offload-arch=gfx90a 
-fopenmp-targets=amdgcn-amd-amdhsa -nogpulib %s 2>&1 | FileCheck 
--check-prefixes=CHECK-OPENMP-IS-TARGET-DEVICE %s
 ! CHECK-OPENMP-IS-TARGET-DEVICE: "{{[^"]*}}flang-new" "-fc1" {{.*}} "-fopenmp" 
{{.*}} "-fopenmp-is-target-device" {{.*}}.f90"
 
 ! Testing appropriate flags are gnerated and appropriately assigned by the 
dr

[clang] [clang][test] add TestLanguage.def to specify all tested language versions (PR #94243)

2024-07-03 Thread Aaron Ballman via cfe-commits


@@ -0,0 +1,39 @@
+
+//===-- TestLanguage.def - Language Versions for Testing *- 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 TESTLANGUAGE
+#error "TESTLANGUAGE must be defined before including this file"
+#endif
+
+#ifndef TESTLANGUAGE_C
+#define TESTLANGUAGE_C TESTLANGUAGE
+#endif
+
+#ifndef TESTLANGUAGE_CXX
+#define TESTLANGUAGE_CXX TESTLANGUAGE
+#endif
+
+TESTLANGUAGE_C(C, 89, c89, 0)
+TESTLANGUAGE_C(C, 99, c99, 1)
+TESTLANGUAGE_C(C, 11, c11, 2)
+TESTLANGUAGE_C(C, 17, c17, 3)
+TESTLANGUAGE_C(C, 23, c23, 4)

AaronBallman wrote:

Add c2y now that it was added to trunk?

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


[clang] [clang][test] add TestLanguage.def to specify all tested language versions (PR #94243)

2024-07-03 Thread Aaron Ballman via cfe-commits


@@ -0,0 +1,39 @@
+
+//===-- TestLanguage.def - Language Versions for Testing *- 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 TESTLANGUAGE
+#error "TESTLANGUAGE must be defined before including this file"
+#endif
+
+#ifndef TESTLANGUAGE_C
+#define TESTLANGUAGE_C TESTLANGUAGE
+#endif
+
+#ifndef TESTLANGUAGE_CXX
+#define TESTLANGUAGE_CXX TESTLANGUAGE
+#endif
+
+TESTLANGUAGE_C(C, 89, c89, 0)

AaronBallman wrote:

It would be helpful to have a comment at the top of the file explaining the 
macro arguments

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


[clang] c1af97d - [clang][Interp] Diagnose comparisons against one-past-end pointers

2024-07-03 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-07-03T14:07:28+02:00
New Revision: c1af97db1e3846db1188149afe86cee6585dfc9a

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

LOG: [clang][Interp] Diagnose comparisons against one-past-end pointers

Added: 


Modified: 
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/Pointer.cpp
clang/lib/AST/Interp/Pointer.h
clang/test/AST/Interp/literals.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 328db219ca628..5d8362b4fa881 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -922,6 +922,7 @@ inline bool CmpHelperEQ(InterpState &S, CodePtr 
OpPC, CompareFn Fn) {
 return true;
   }
 
+  // Reject comparisons to weak pointers.
   for (const auto &P : {LHS, RHS}) {
 if (P.isZero())
   continue;
@@ -934,6 +935,20 @@ inline bool CmpHelperEQ(InterpState &S, CodePtr 
OpPC, CompareFn Fn) {
   }
 
   if (!Pointer::hasSameBase(LHS, RHS)) {
+if (LHS.isOnePastEnd() && !RHS.isOnePastEnd() && !RHS.isZero() &&
+RHS.getOffset() == 0) {
+  const SourceInfo &Loc = S.Current->getSource(OpPC);
+  S.FFDiag(Loc, diag::note_constexpr_pointer_comparison_past_end)
+  << LHS.toDiagnosticString(S.getCtx());
+  return false;
+} else if (RHS.isOnePastEnd() && !LHS.isOnePastEnd() && !LHS.isZero() &&
+   LHS.getOffset() == 0) {
+  const SourceInfo &Loc = S.Current->getSource(OpPC);
+  S.FFDiag(Loc, diag::note_constexpr_pointer_comparison_past_end)
+  << RHS.toDiagnosticString(S.getCtx());
+  return false;
+}
+
 S.Stk.push(BoolT::from(Fn(ComparisonCategoryResult::Unordered)));
 return true;
   } else {

diff  --git a/clang/lib/AST/Interp/Pointer.cpp 
b/clang/lib/AST/Interp/Pointer.cpp
index 4070d0c54225d..d6603f91fb127 100644
--- a/clang/lib/AST/Interp/Pointer.cpp
+++ b/clang/lib/AST/Interp/Pointer.cpp
@@ -143,7 +143,7 @@ APValue Pointer::toAPValue() const {
 
   if (isDummy() || isUnknownSizeArray() || Desc->asExpr())
 return APValue(Base, CharUnits::Zero(), Path,
-   /*IsOnePastEnd=*/false, /*IsNullPtr=*/false);
+   /*IsOnePastEnd=*/isOnePastEnd(), /*IsNullPtr=*/false);
 
   // TODO: compute the offset into the object.
   CharUnits Offset = CharUnits::Zero();
@@ -181,7 +181,8 @@ APValue Pointer::toAPValue() const {
   // Just invert the order of the elements.
   std::reverse(Path.begin(), Path.end());
 
-  return APValue(Base, Offset, Path, /*IsOnePastEnd=*/false, 
/*IsNullPtr=*/false);
+  return APValue(Base, Offset, Path, /*IsOnePastEnd=*/isOnePastEnd(),
+ /*IsNullPtr=*/false);
 }
 
 void Pointer::print(llvm::raw_ostream &OS) const {
@@ -348,7 +349,7 @@ std::optional Pointer::toRValue(const Context 
&Ctx) const {
 
 // Invalid pointers.
 if (Ptr.isDummy() || !Ptr.isLive() || !Ptr.isBlockPointer() ||
-(!Ptr.isUnknownSizeArray() && Ptr.isOnePastEnd()))
+Ptr.isPastEnd())
   return false;
 
 // Primitive values.

diff  --git a/clang/lib/AST/Interp/Pointer.h b/clang/lib/AST/Interp/Pointer.h
index 5faec75cc3ec5..4f277eb7d9e58 100644
--- a/clang/lib/AST/Interp/Pointer.h
+++ b/clang/lib/AST/Interp/Pointer.h
@@ -556,10 +556,18 @@ class Pointer {
 if (isUnknownSizeArray())
   return false;
 
-return isElementPastEnd() ||
+return isElementPastEnd() || isPastEnd() ||
(getSize() == getOffset() && !isZeroSizeArray());
   }
 
+  /// Checks if the pointer points past the end of the object.
+  bool isPastEnd() const {
+if (isIntegralPointer())
+  return false;
+
+return !isZero() && Offset > PointeeStorage.BS.Pointee->getSize();
+  }
+
   /// Checks if the pointer is an out-of-bounds element pointer.
   bool isElementPastEnd() const { return Offset == PastEndMark; }
 

diff  --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index f70ca79e216da..630d9b53cca25 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -1266,3 +1266,13 @@ static_assert(ReturnInStmtExpr() == 1, ""); // 
both-error {{not an integral cons
 // both-note {{in call to}}
 
 #endif
+
+namespace ComparisonAgainstOnePastEnd {
+  int a, b;
+  static_assert(&a + 1 == &b, ""); // both-error {{not an integral constant 
expression}} \
+   // both-note {{comparison against pointer 
'&a + 1' that points past the end of a complete object has unspecified value}}
+  static_assert(&a == &b + 1, ""); // both-error {{not an integral constant 
expression}} \
+   // both-note {{comparison against pointer 
'&b + 1' that points past the end of a complete object has unspec

[clang] [flang] [Flang-new][OpenMP] Add bitcode files for AMD GPU OpenMP (PR #96742)

2024-07-03 Thread Dominik Adamski via cfe-commits

DominikAdamski wrote:

@tblah Thanks for your review.
Unfortunately, I had to restore adding fcuda-is-device option ( 
https://github.com/llvm/llvm-project/pull/97531 ) because of regression related 
to handling by clang virtual functions in OpenMP target region.

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


[clang] [flang] [Flang-new][OpenMP] Add bitcode files for AMD GPU OpenMP (PR #96742)

2024-07-03 Thread Joseph Huber via cfe-commits

jhuber6 wrote:

Would it be possible for you to investigate that? It really shouldn't be 
required if we can't help it.

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


[clang] [flang] [Flang-new][OpenMP] Add bitcode files for AMD GPU OpenMP (PR #96742)

2024-07-03 Thread Dominik Adamski via cfe-commits

DominikAdamski wrote:

@jhuber6 I'm working on that.

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


[clang] [clang] Extend lifetimebound analysis to detect within-initializer assignments between pointer-like objects. (PR #97473)

2024-07-03 Thread Haojian Wu via cfe-commits

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


[clang] [libcxx] [clang] Add builtin to clear padding bytes (prework for P0528R3) (PR #75371)

2024-07-03 Thread via cfe-commits

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


[clang] [libcxx] [clang] Add builtin to clear padding bytes (prework for P0528R3) (PR #75371)

2024-07-03 Thread via cfe-commits

huixie90 wrote:

> If you want to modify part of a bitfield unit, you need to load/store the 
> whole bitfield unit, as computed by the CGRecordLayout. This is true whether 
> you're modifying an actual field, or padding adjacent to a field. Since any 
> padding has to be adjacent to a bitfield, you can get the relevant 
> information out of the CGBitFieldInfo for that bitfield.

Hello, this is now working with the bitfield. Iterating over the field of a 
struct also gives me information about where bit fields are

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


[clang] [libcxx] [clang] Add builtin to clear padding bytes (prework for P0528R3) (PR #75371)

2024-07-03 Thread via cfe-commits

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


[clang] acaa026 - [clang][OpenMP] Use leaf constructs in `mapLoopConstruct` (#97446)

2024-07-03 Thread via cfe-commits

Author: Krzysztof Parzyszek
Date: 2024-07-03T07:57:31-05:00
New Revision: acaa0262a98fe8ecc525bdbdc2692d803e50976a

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

LOG: [clang][OpenMP] Use leaf constructs in `mapLoopConstruct` (#97446)

This removes mentions of specific combined directives.

Also, add a quote from the OpenMP spec to explain the code dealing with
the `bind` clause.

Added: 


Modified: 
clang/lib/Sema/SemaOpenMP.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 8f064f35d..5fde4f67b4fd9 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -6270,16 +6270,21 @@ bool SemaOpenMP::mapLoopConstruct(
 if (BindKind == OMPC_BIND_unknown) {
   // Setting the enclosing teams or parallel construct for the loop
   // directive without bind clause.
+  // [5.0:129:25-28] If the bind clause is not present on the construct and
+  // the loop construct is closely nested inside a teams or parallel
+  // construct, the binding region is the corresponding teams or parallel
+  // region. If none of those conditions hold, the binding region is not
+  // defined.
   BindKind = OMPC_BIND_thread; // Default bind(thread) if binding is 
unknown
+  ArrayRef ParentLeafs =
+  getLeafConstructsOrSelf(ParentDirective);
 
   if (ParentDirective == OMPD_unknown) {
 Diag(DSAStack->getDefaultDSALocation(),
  diag::err_omp_bind_required_on_loop);
-  } else if (ParentDirective == OMPD_parallel ||
- ParentDirective == OMPD_target_parallel) {
+  } else if (ParentLeafs.back() == OMPD_parallel) {
 BindKind = OMPC_BIND_parallel;
-  } else if (ParentDirective == OMPD_teams ||
- ParentDirective == OMPD_target_teams) {
+  } else if (ParentLeafs.back() == OMPD_teams) {
 BindKind = OMPC_BIND_teams;
   }
 } else {



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


[clang] [clang][OpenMP] Use leaf constructs in `mapLoopConstruct` (PR #97446)

2024-07-03 Thread Krzysztof Parzyszek via cfe-commits

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


[clang] 6461b92 - [clang][OpenMP] Change `ActOnOpenMPRegionStart` to use captured regions (#97445)

2024-07-03 Thread via cfe-commits

Author: Krzysztof Parzyszek
Date: 2024-07-03T07:58:01-05:00
New Revision: 6461b921fd06b1c812f1172685b8b7edc0608af7

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

LOG: [clang][OpenMP] Change `ActOnOpenMPRegionStart` to use captured regions 
(#97445)

Instead of checking specific directives, this function now gets the list
of captured regions, and processes them individually. This makes this
function directive-agnostic (except a few cases of leaf constructs).

Added: 


Modified: 
clang/lib/Sema/SemaOpenMP.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 5fde4f67b4fd9..12cd75e7102ba 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -4234,454 +4234,186 @@ static void 
handleDeclareVariantConstructTrait(DSAStackTy *Stack,
   Stack->handleConstructTrait(Traits, ScopeEntry);
 }
 
-void SemaOpenMP::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind,
-Scope *CurScope) {
-  ASTContext &Context = getASTContext();
-  switch (DKind) {
-  case OMPD_parallel:
-  case OMPD_parallel_for:
-  case OMPD_parallel_for_simd:
-  case OMPD_parallel_sections:
-  case OMPD_parallel_master:
-  case OMPD_parallel_masked:
-  case OMPD_parallel_loop:
-  case OMPD_teams:
-  case OMPD_teams_distribute:
-  case OMPD_teams_distribute_simd: {
-QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1).withConst();
-QualType KmpInt32PtrTy =
-Context.getPointerType(KmpInt32Ty).withConst().withRestrict();
-SemaOpenMP::CapturedParamNameType Params[] = {
-std::make_pair(".global_tid.", KmpInt32PtrTy),
-std::make_pair(".bound_tid.", KmpInt32PtrTy),
-std::make_pair(StringRef(), QualType()) // __context with shared vars
-};
-SemaRef.ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope,
- CR_OpenMP, Params);
-break;
+static SmallVector
+getParallelRegionParams(Sema &SemaRef, bool LoopBoundSharing) {
+  ASTContext &Context = SemaRef.getASTContext();
+  QualType KmpInt32Ty =
+  Context.getIntTypeForBitwidth(/*DestWidth=*/32, 
/*Signed=*/1).withConst();
+  QualType KmpInt32PtrTy =
+  Context.getPointerType(KmpInt32Ty).withConst().withRestrict();
+  SmallVector Params{
+  std::make_pair(".global_tid.", KmpInt32PtrTy),
+  std::make_pair(".bound_tid.", KmpInt32PtrTy),
+  };
+  if (LoopBoundSharing) {
+QualType KmpSizeTy = Context.getSizeType().withConst();
+Params.push_back(std::make_pair(".previous.lb.", KmpSizeTy));
+Params.push_back(std::make_pair(".previous.ub.", KmpSizeTy));
   }
-  case OMPD_target_teams:
-  case OMPD_target_parallel:
-  case OMPD_target_parallel_for:
-  case OMPD_target_parallel_for_simd:
-  case OMPD_target_parallel_loop:
-  case OMPD_target_teams_distribute:
-  case OMPD_target_teams_distribute_simd: {
-QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1).withConst();
+
+  // __context with shared vars
+  Params.push_back(std::make_pair(StringRef(), QualType()));
+  return Params;
+}
+
+static SmallVector
+getTeamsRegionParams(Sema &SemaRef) {
+  return getParallelRegionParams(SemaRef, /*LoopBoundSharing=*/false);
+}
+
+static SmallVector
+getTaskRegionParams(Sema &SemaRef) {
+  ASTContext &Context = SemaRef.getASTContext();
+  QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1).withConst();
+  QualType VoidPtrTy = Context.VoidPtrTy.withConst().withRestrict();
+  QualType KmpInt32PtrTy =
+  Context.getPointerType(KmpInt32Ty).withConst().withRestrict();
+  QualType Args[] = {VoidPtrTy};
+  FunctionProtoType::ExtProtoInfo EPI;
+  EPI.Variadic = true;
+  QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI);
+  SmallVector Params{
+  std::make_pair(".global_tid.", KmpInt32Ty),
+  std::make_pair(".part_id.", KmpInt32PtrTy),
+  std::make_pair(".privates.", VoidPtrTy),
+  std::make_pair(
+  ".copy_fn.",
+  Context.getPointerType(CopyFnType).withConst().withRestrict()),
+  std::make_pair(".task_t.", Context.VoidPtrTy.withConst()),
+  std::make_pair(StringRef(), QualType()) // __context with shared vars
+  };
+  return Params;
+}
+
+static SmallVector
+getTargetRegionParams(Sema &SemaRef) {
+  ASTContext &Context = SemaRef.getASTContext();
+  SmallVector Params;
+  if (SemaRef.getLangOpts().OpenMPIsTargetDevice) {
 QualType VoidPtrTy = Context.VoidPtrTy.withConst().withRestrict();
-QualType KmpInt32PtrTy =
-Context.getPointerType(KmpInt32Ty).withConst().withRestrict();
-QualType Args[] = {VoidPtrTy};
-FunctionProtoType::ExtProtoInfo EPI;
-EPI.Variadic = true;
-QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI);
-SemaOpenMP:

[clang] [clang][OpenMP] Change `ActOnOpenMPRegionStart` to use captured regions (PR #97445)

2024-07-03 Thread Krzysztof Parzyszek via cfe-commits

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


[clang] [Clang] [C23] Implement N2653: u8 strings are char8_t[] (PR #97208)

2024-07-03 Thread Mital Ashok via cfe-commits


@@ -104,6 +107,7 @@ typedef _Atomic(long)   atomic_long;
 typedef _Atomic(unsigned long)  atomic_ulong;
 typedef _Atomic(long long)  atomic_llong;
 typedef _Atomic(unsigned long long) atomic_ullong;
+typedef _Atomic(unsigned char)  atomic_char8_t;
 typedef _Atomic(uint_least16_t) atomic_char16_t;
 typedef _Atomic(uint_least32_t) atomic_char32_t;

MitalAshok wrote:

It seems like this header doesn't properly implement 
[P0943R6](https://wg21.link/P0943R6) in C++23 (Where `#define _Atomic(T) 
std::atomic` and all these typedefs should just be `using std::atomic_*`.

So `::atomic_char8_t` should be `std::atomic`, not 
`std::atomic` (nor `unsigned char _Atomic`), but that is outside 
the scope of this PR. I'll just make this match the surrounding typedefs for 
now.

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


[clang] [Clang] [C23] Implement N2653: u8 strings are char8_t[] (PR #97208)

2024-07-03 Thread Mital Ashok via cfe-commits

https://github.com/MitalAshok updated 
https://github.com/llvm/llvm-project/pull/97208

>From ef0072d1fc9b14f7ee657fa95f44a686b78b525a Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Sun, 30 Jun 2024 12:07:54 +0100
Subject: [PATCH 1/5] [Clang] [C23] Implement N2653: u8 strings are char8_t[]

---
 clang/docs/ReleaseNotes.rst   |  6 
 .../clang/Basic/DiagnosticSemaKinds.td|  5 +++-
 clang/lib/Frontend/InitPreprocessor.cpp   |  6 ++--
 clang/lib/Headers/stdatomic.h |  5 
 clang/lib/Sema/SemaExpr.cpp   | 23 ++-
 clang/test/C/C2x/n2653.c  | 29 +++
 clang/www/c_status.html   |  2 +-
 7 files changed, 65 insertions(+), 11 deletions(-)
 create mode 100644 clang/test/C/C2x/n2653.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c720e47dbe35b..e51be81d8b11a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -337,6 +337,12 @@ C23 Feature Support
 - Properly promote bit-fields of bit-precise integer types to the field's type
   rather than to ``int``. #GH87641
 
+- Compiler support for `N2653 char8_t: A type for UTF-8 characters and strings`
+  `_: ``u8`` string
+  literals are now of type ``char8_t[N]`` in C23 and expose
+  ``__CLANG_ATOMIC_CHAR8_T_LOCK_FREE``/``__GCC_ATOMIC_CHAR8_T_LOCK_FREE`` to
+  implement the corresponding macro in .
+
 Non-comprehensive list of changes in this release
 -
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 5dc36c594bcb7..6a00b92df1c36 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7252,7 +7252,10 @@ def err_array_init_utf8_string_into_char : Error<
 def warn_cxx20_compat_utf8_string : Warning<
   "type of UTF-8 string literal will change from array of const char to "
   "array of const char8_t in C++20">, InGroup, DefaultIgnore;
-def note_cxx20_compat_utf8_string_remove_u8 : Note<
+def warn_c23_compat_utf8_string : Warning<
+  "type of UTF-8 string literal will change from array of char to "
+  "array of char8_t in C23">, InGroup, DefaultIgnore;
+def note_cxx20_c23_compat_utf8_string_remove_u8 : Note<
   "remove 'u8' prefix to avoid a change of behavior; "
   "Clang encodes unprefixed narrow string literals as UTF-8">;
 def err_array_init_different_type : Error<
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index 55ec460064830..6270c37342bcf 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -1342,8 +1342,10 @@ static void InitializePredefinedMacros(const TargetInfo 
&TI,
   getLockFreeValue(TI.get##Type##Width(), TI));
 DEFINE_LOCK_FREE_MACRO(BOOL, Bool);
 DEFINE_LOCK_FREE_MACRO(CHAR, Char);
-if (LangOpts.Char8)
-  DEFINE_LOCK_FREE_MACRO(CHAR8_T, Char); // Treat char8_t like char.
+// char8_t has the same representation / width as unsigned
+// char in C++ and is a typedef for unsigned char in C23
+if (LangOpts.Char8 || LangOpts.C23)
+  DEFINE_LOCK_FREE_MACRO(CHAR8_T, Char);
 DEFINE_LOCK_FREE_MACRO(CHAR16_T, Char16);
 DEFINE_LOCK_FREE_MACRO(CHAR32_T, Char32);
 DEFINE_LOCK_FREE_MACRO(WCHAR_T, WChar);
diff --git a/clang/lib/Headers/stdatomic.h b/clang/lib/Headers/stdatomic.h
index 9c103d98af8c5..c33cd8083525c 100644
--- a/clang/lib/Headers/stdatomic.h
+++ b/clang/lib/Headers/stdatomic.h
@@ -35,6 +35,10 @@ extern "C" {
 
 #define ATOMIC_BOOL_LOCK_FREE   __CLANG_ATOMIC_BOOL_LOCK_FREE
 #define ATOMIC_CHAR_LOCK_FREE   __CLANG_ATOMIC_CHAR_LOCK_FREE
+#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L) ||  
\
+defined(__cplusplus)
+#define ATOMIC_CHAR8_T_LOCK_FREE__CLANG_ATOMIC_CHAR8_T_LOCK_FREE
+#endif
 #define ATOMIC_CHAR16_T_LOCK_FREE   __CLANG_ATOMIC_CHAR16_T_LOCK_FREE
 #define ATOMIC_CHAR32_T_LOCK_FREE   __CLANG_ATOMIC_CHAR32_T_LOCK_FREE
 #define ATOMIC_WCHAR_T_LOCK_FREE__CLANG_ATOMIC_WCHAR_T_LOCK_FREE
@@ -104,6 +108,7 @@ typedef _Atomic(long)   atomic_long;
 typedef _Atomic(unsigned long)  atomic_ulong;
 typedef _Atomic(long long)  atomic_llong;
 typedef _Atomic(unsigned long long) atomic_ullong;
+typedef _Atomic(unsigned char)  atomic_char8_t;
 typedef _Atomic(uint_least16_t) atomic_char16_t;
 typedef _Atomic(uint_least32_t) atomic_char32_t;
 typedef _Atomic(wchar_t)atomic_wchar_t;
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index db44cfe1288b6..a1b060f7f1510 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -2082,6 +2082,8 @@ Sema::ActOnStringLiteral(ArrayRef StringToks, 
Scope *UDLScope) {
   } else if (Literal.isUTF8()) {
 if

[clang] [Clang] [C23] Implement N2653: u8 strings are char8_t[] (PR #97208)

2024-07-03 Thread Mital Ashok via cfe-commits


@@ -1165,6 +1165,8 @@ static void InitializePredefinedMacros(const TargetInfo 
&TI,
   DefineType("__WCHAR_TYPE__", TI.getWCharType(), Builder);
   DefineType("__WINT_TYPE__", TI.getWIntType(), Builder);
   DefineTypeSizeAndWidth("__SIG_ATOMIC", TI.getSigAtomicType(), TI, Builder);
+  if (LangOpts.Char8 || LangOpts.C23)
+DefineType("__CHAR8_TYPE__", TI.UnsignedChar, Builder);

MitalAshok wrote:

This matches GCC behaviour: https://godbolt.org/z/6Eax3eqrd

But I'm not sure why it's defined in C++ at all

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


[clang] [LinkerWrapper] Pass all files to the device linker (PR #97573)

2024-07-03 Thread Joseph Huber via cfe-commits

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

Summary:
The linker wrapper's job is to extract embedded device code from fat
binaries and create linked images that can then be embedded and
executed. In order to support LTO, we originally reinvented all of the
LTO handling that `ld.lld` normally does. Primarily, this was because
`nvlink` didn't support this at all, and we have special hacks required
for offloading languages interacting with archive libraries.

Now since I wrote https://github.com/llvm/llvm-project/pull/96561 we
should be able to pass all the inputs to the device linker
transparently. This has the advantage of allowing the `clang` Driver to
do its own handling. Primarily, this will be used to implicitly pass
libraries to the device link job to make it more consistent with other
toolchains.

The JIT support is a notable departure, however there is an option
called `--lto-emit-llvm` that performs the exact function where we want
the final link job to output LLVM-IR that we can then embed instead.

This patch does not fully delete the LTO handling, primarily because I
think the SPIR-V people might want it. To see only the relevant patches,
ignore the first commit of the nvlink-wrapper.

Depends on https://github.com/llvm/llvm-project/pull/96561.


>From 2d3957ac14906d569acf5b3ceb5c7e2f4dfabe54 Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Mon, 24 Jun 2024 15:14:52 -0500
Subject: [PATCH 1/2] [Clang] Introduce 'clang-nvlink-wrappaer' to work around
 'nvlink'

Summary:
The `clang-nvlink-wrapper` is a utility that I removed awhile back
during the transition to the new driver. This patch adds back in a new,
upgraded version that does LTO + archive linking. It's not an easy
choice to reintroduce something I happily deleted, but this is the only
way to move forward with improving GPU support in LLVM.

While NVIDIA provides a linker called 'nvlink', its main interface is
very difficult to work with. It does not provide LTO, or static linking,
requires all files to be named a non-standard `.cubin`, and rejects link
jobs that other linkers would be fine with (i.e empty). I have spent a
great deal of time hacking around this in the GPU `libc` implementation,
where I deliberately avoid LTO and static linking and have about 100
lines of hacky CMake dedicated to storing these files in a format that
the clang-linker-wrapper accepts to avoid this limitation.

The main reason I want to re-intorudce this tool is because I am
planning on creating a more standard C/C++ toolchain for GPUs to use.
This will install files like the following.
```
/lib/nvptx64-nvidia-cuda/libc.a
/lib/nvptx64-nvidia-cuda/libc++.a
/lib/nvptx64-nvidia-cuda/libomp.a
/lib/clang/19/lib/nvptx64-nvidia-cuda/libclang_rt.builtins.a
```
Linking in these libraries will then simply require passing `-lc` like
is already done for non-GPU toolchains. However, this doesn't work with
the currently deficient `nvlink` linker, so I consider this a blocking
issue to massively improving the state of building GPU libraries.

In the future we may be able to convince NVIDIA to port their linker to
`ld.lld`, but for now this is the only workable solution that allows us
to hack around the weird behavior of their closed-source software.
---
 clang/docs/ClangNVLinkWrapper.rst |  64 ++
 clang/docs/index.rst  |   1 +
 clang/lib/Driver/ToolChains/Cuda.cpp  |  61 +-
 clang/lib/Driver/ToolChains/Cuda.h|   3 +
 clang/test/Driver/cuda-cross-compiling.c  |   8 +-
 clang/test/Driver/nvlink-wrapper.c|  65 ++
 clang/test/lit.cfg.py |   1 +
 clang/tools/CMakeLists.txt|   1 +
 .../tools/clang-nvlink-wrapper/CMakeLists.txt |  44 +
 .../ClangNVLinkWrapper.cpp| 776 ++
 .../tools/clang-nvlink-wrapper/NVLinkOpts.td  |  88 ++
 11 files changed, 1055 insertions(+), 57 deletions(-)
 create mode 100644 clang/docs/ClangNVLinkWrapper.rst
 create mode 100644 clang/test/Driver/nvlink-wrapper.c
 create mode 100644 clang/tools/clang-nvlink-wrapper/CMakeLists.txt
 create mode 100644 clang/tools/clang-nvlink-wrapper/ClangNVLinkWrapper.cpp
 create mode 100644 clang/tools/clang-nvlink-wrapper/NVLinkOpts.td

diff --git a/clang/docs/ClangNVLinkWrapper.rst 
b/clang/docs/ClangNVLinkWrapper.rst
new file mode 100644
index 0..0a312bdbf3066
--- /dev/null
+++ b/clang/docs/ClangNVLinkWrapper.rst
@@ -0,0 +1,64 @@
+
+Clang nvlink Wrapper
+
+
+.. contents::
+   :local:
+
+.. _clang-nvlink-wrapper:
+
+Introduction
+
+
+This tools works as a wrapper around the NVIDIA ``nvlink`` linker. The purpose 
+of this wrapper is to provide an interface similar to the ``ld.lld`` linker 
+while still relying on NVIDIA's proprietary linker to produce the final 
output. 
+Features include, static archive (.a) linking, LTO, and accepting files ending 
+in ``.o`` without e

[clang] [LinkerWrapper] Pass all files to the device linker (PR #97573)

2024-07-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Joseph Huber (jhuber6)


Changes

Summary:
The linker wrapper's job is to extract embedded device code from fat
binaries and create linked images that can then be embedded and
executed. In order to support LTO, we originally reinvented all of the
LTO handling that `ld.lld` normally does. Primarily, this was because
`nvlink` didn't support this at all, and we have special hacks required
for offloading languages interacting with archive libraries.

Now since I wrote https://github.com/llvm/llvm-project/pull/96561 we
should be able to pass all the inputs to the device linker
transparently. This has the advantage of allowing the `clang` Driver to
do its own handling. Primarily, this will be used to implicitly pass
libraries to the device link job to make it more consistent with other
toolchains.

The JIT support is a notable departure, however there is an option
called `--lto-emit-llvm` that performs the exact function where we want
the final link job to output LLVM-IR that we can then embed instead.

This patch does not fully delete the LTO handling, primarily because I
think the SPIR-V people might want it. To see only the relevant patches,
ignore the first commit of the nvlink-wrapper.

Depends on https://github.com/llvm/llvm-project/pull/96561.


---

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


14 Files Affected:

- (added) clang/docs/ClangNVLinkWrapper.rst (+64) 
- (modified) clang/docs/index.rst (+1) 
- (modified) clang/lib/Driver/ToolChains/Cuda.cpp (+8-53) 
- (modified) clang/lib/Driver/ToolChains/Cuda.h (+3) 
- (modified) clang/test/Driver/cuda-cross-compiling.c (+4-4) 
- (modified) clang/test/Driver/linker-wrapper-libs.c (+6-6) 
- (modified) clang/test/Driver/linker-wrapper.c (+2-2) 
- (added) clang/test/Driver/nvlink-wrapper.c (+65) 
- (modified) clang/test/lit.cfg.py (+1) 
- (modified) clang/tools/CMakeLists.txt (+1) 
- (modified) clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp (+60-38) 
- (added) clang/tools/clang-nvlink-wrapper/CMakeLists.txt (+44) 
- (added) clang/tools/clang-nvlink-wrapper/ClangNVLinkWrapper.cpp (+776) 
- (added) clang/tools/clang-nvlink-wrapper/NVLinkOpts.td (+88) 


``diff
diff --git a/clang/docs/ClangNVLinkWrapper.rst 
b/clang/docs/ClangNVLinkWrapper.rst
new file mode 100644
index 0..0a312bdbf3066
--- /dev/null
+++ b/clang/docs/ClangNVLinkWrapper.rst
@@ -0,0 +1,64 @@
+
+Clang nvlink Wrapper
+
+
+.. contents::
+   :local:
+
+.. _clang-nvlink-wrapper:
+
+Introduction
+
+
+This tools works as a wrapper around the NVIDIA ``nvlink`` linker. The purpose 
+of this wrapper is to provide an interface similar to the ``ld.lld`` linker 
+while still relying on NVIDIA's proprietary linker to produce the final 
output. 
+Features include, static archive (.a) linking, LTO, and accepting files ending 
+in ``.o`` without error.
+
+Usage
+=
+
+This tool can be used with the following options. Any arguments not intended
+only for the linker wrapper will be forwarded to ``nvlink``.
+
+.. code-block:: console
+
+  OVERVIEW: A utility that wraps around the NVIDIA 'nvlink' linker.
+  This enables static linking and LTO handling for NVPTX targets.
+
+  USAGE: clang-nvlink-wrapper [options] 
+
+  OPTIONS:
+--archSpecify the 'sm_' name of the target architecture.
+--cuda-path=Set the system CUDA path
+--dry-runPrint generated commands without running.
+--feature Specify the '+ptx' freature to use for LTO.
+-g   Specify that this was a debug compile.
+-help-hidden Display all available options
+-helpDisplay available options (--help-hidden for more)
+-L  Add  to the library search path
+-l  Search for library 
+-mllvm  Arguments passed to LLVM, including Clang 
invocations, for which the '-mllvm' prefix is preserved. Use '-mllvm --help' 
for a list of options.
+-o Path to file to write output
+--plugin-opt=jobs=
+ Number of LTO codegen partitions
+--plugin-opt=lto-partitions=
+ Number of LTO codegen partitions
+--plugin-opt=O
+ Optimization level for LTO
+--plugin-opt=thinlto
+ Enable the thin-lto backend
+--plugin-opt= Options passed to LLVM, not including the Clang 
invocation. Use '--plugin-opt=--help' for a list of options.
+--save-temps Save intermediate results
+--versionDisplay the version number and exit
+-v   Print verbose information
+
+Example
+===
+
+This tool is intended to be invoked when targeting the NVPTX toolchain 
directly. 
+
+.. code-block:: console
+
+  clang --target=nvptx64-nvidia-cuda -march=native -flto=full input.c
diff --git a/clang/docs/index.rst 

[clang] 50c8112 - Rename C2x to C23; NFC

2024-07-03 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2024-07-03T10:11:31-04:00
New Revision: 50c81128de8616117118564eff22cf508cba7848

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

LOG: Rename C2x to C23; NFC

This renames the test directory for C23 tests.

Added: 
clang/test/C/C23/Inputs/bits.bin
clang/test/C/C23/Inputs/boop.h
clang/test/C/C23/Inputs/i.dat
clang/test/C/C23/Inputs/jump.wav
clang/test/C/C23/Inputs/s.dat
clang/test/C/C23/n2322.c
clang/test/C/C23/n2350.c
clang/test/C/C23/n2359.c
clang/test/C/C23/n2508.c
clang/test/C/C23/n2549.c
clang/test/C/C23/n2607.c
clang/test/C/C23/n2670.c
clang/test/C/C23/n2683.c
clang/test/C/C23/n2683_2.c
clang/test/C/C23/n2819.c
clang/test/C/C23/n2826.c
clang/test/C/C23/n2836_n2939.c
clang/test/C/C23/n2838.c
clang/test/C/C23/n2886.c
clang/test/C/C23/n2900_n3011.c
clang/test/C/C23/n2900_n3011_2.c
clang/test/C/C23/n2927.c
clang/test/C/C23/n2927_2.c
clang/test/C/C23/n2930.c
clang/test/C/C23/n2934.c
clang/test/C/C23/n2940.c
clang/test/C/C23/n2975.c
clang/test/C/C23/n3007.c
clang/test/C/C23/n3017.c
clang/test/C/C23/n3018.c
clang/test/C/C23/n3033.c
clang/test/C/C23/n3033_2.c
clang/test/C/C23/n3035.c
clang/test/C/C23/n3042.c

Modified: 


Removed: 
clang/test/C/C2x/Inputs/bits.bin
clang/test/C/C2x/Inputs/boop.h
clang/test/C/C2x/Inputs/i.dat
clang/test/C/C2x/Inputs/jump.wav
clang/test/C/C2x/Inputs/s.dat
clang/test/C/C2x/n2322.c
clang/test/C/C2x/n2350.c
clang/test/C/C2x/n2359.c
clang/test/C/C2x/n2508.c
clang/test/C/C2x/n2549.c
clang/test/C/C2x/n2607.c
clang/test/C/C2x/n2670.c
clang/test/C/C2x/n2683.c
clang/test/C/C2x/n2683_2.c
clang/test/C/C2x/n2819.c
clang/test/C/C2x/n2826.c
clang/test/C/C2x/n2836_n2939.c
clang/test/C/C2x/n2838.c
clang/test/C/C2x/n2886.c
clang/test/C/C2x/n2900_n3011.c
clang/test/C/C2x/n2900_n3011_2.c
clang/test/C/C2x/n2927.c
clang/test/C/C2x/n2927_2.c
clang/test/C/C2x/n2930.c
clang/test/C/C2x/n2934.c
clang/test/C/C2x/n2940.c
clang/test/C/C2x/n2975.c
clang/test/C/C2x/n3007.c
clang/test/C/C2x/n3017.c
clang/test/C/C2x/n3018.c
clang/test/C/C2x/n3033.c
clang/test/C/C2x/n3033_2.c
clang/test/C/C2x/n3035.c
clang/test/C/C2x/n3042.c



diff  --git a/clang/test/C/C2x/Inputs/bits.bin 
b/clang/test/C/C23/Inputs/bits.bin
similarity index 100%
rename from clang/test/C/C2x/Inputs/bits.bin
rename to clang/test/C/C23/Inputs/bits.bin

diff  --git a/clang/test/C/C2x/Inputs/boop.h b/clang/test/C/C23/Inputs/boop.h
similarity index 100%
rename from clang/test/C/C2x/Inputs/boop.h
rename to clang/test/C/C23/Inputs/boop.h

diff  --git a/clang/test/C/C2x/Inputs/i.dat b/clang/test/C/C23/Inputs/i.dat
similarity index 100%
rename from clang/test/C/C2x/Inputs/i.dat
rename to clang/test/C/C23/Inputs/i.dat

diff  --git a/clang/test/C/C2x/Inputs/jump.wav 
b/clang/test/C/C23/Inputs/jump.wav
similarity index 100%
rename from clang/test/C/C2x/Inputs/jump.wav
rename to clang/test/C/C23/Inputs/jump.wav

diff  --git a/clang/test/C/C2x/Inputs/s.dat b/clang/test/C/C23/Inputs/s.dat
similarity index 100%
rename from clang/test/C/C2x/Inputs/s.dat
rename to clang/test/C/C23/Inputs/s.dat

diff  --git a/clang/test/C/C2x/n2322.c b/clang/test/C/C23/n2322.c
similarity index 100%
rename from clang/test/C/C2x/n2322.c
rename to clang/test/C/C23/n2322.c

diff  --git a/clang/test/C/C2x/n2350.c b/clang/test/C/C23/n2350.c
similarity index 100%
rename from clang/test/C/C2x/n2350.c
rename to clang/test/C/C23/n2350.c

diff  --git a/clang/test/C/C2x/n2359.c b/clang/test/C/C23/n2359.c
similarity index 100%
rename from clang/test/C/C2x/n2359.c
rename to clang/test/C/C23/n2359.c

diff  --git a/clang/test/C/C2x/n2508.c b/clang/test/C/C23/n2508.c
similarity index 100%
rename from clang/test/C/C2x/n2508.c
rename to clang/test/C/C23/n2508.c

diff  --git a/clang/test/C/C2x/n2549.c b/clang/test/C/C23/n2549.c
similarity index 100%
rename from clang/test/C/C2x/n2549.c
rename to clang/test/C/C23/n2549.c

diff  --git a/clang/test/C/C2x/n2607.c b/clang/test/C/C23/n2607.c
similarity index 100%
rename from clang/test/C/C2x/n2607.c
rename to clang/test/C/C23/n2607.c

diff  --git a/clang/test/C/C2x/n2670.c b/clang/test/C/C23/n2670.c
similarity index 100%
rename from clang/test/C/C2x/n2670.c
rename to clang/test/C/C23/n2670.c

diff  --git a/clang/test/C/C2x/n2683.c b/clang/test/C/C23/n2683.c
similarity index 100%
rename from clang/test/C/C2x/n2683.c
rename to clang/test/C/C23/n2683.c

diff  --git a/clang/test/C/C2x/n2683_2.c b/clang/test/C/C23/n2683_2.c
similarity index 100%
rename from clang/test/C/C2x/n2683_2.c
rename to clang/test/C/C23/n2683_2.c

diff  --git a/clang/tes

  1   2   3   4   >