[clang] 43baa59 - Pre-commit test for D151696.

2023-06-27 Thread Freddy Ye via cfe-commits

Author: Freddy Ye
Date: 2023-06-28T13:53:35+08:00
New Revision: 43baa5986c20aa510144c0de9b7782050ccba530

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

LOG: Pre-commit test for D151696.

Meanwhile this patch added missing tests for supported CPU names
of cpu_dispatch/specific attribute and added more CHECKs for
resolver function.

Reviewed By: pengfei, skan

Differential Revision: https://reviews.llvm.org/D152989

Added: 
clang/test/CodeGen/attr-cpuspecific-cpus.c

Modified: 
clang/test/CodeGen/attr-cpuspecific.c

Removed: 




diff  --git a/clang/test/CodeGen/attr-cpuspecific-cpus.c 
b/clang/test/CodeGen/attr-cpuspecific-cpus.c
new file mode 100644
index 0..a5b60d69c87e2
--- /dev/null
+++ b/clang/test/CodeGen/attr-cpuspecific-cpus.c
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -emit-llvm -o - %s
+// RUN: %clang_cc1 -verify -triple x86_64-windows-pc -fms-compatibility 
-emit-llvm -o - %s
+
+// expected-no-diagnostics
+
+#ifdef _WIN64
+#define ATTR(X) __declspec(X)
+#else
+#define ATTR(X) __attribute__((X))
+#endif // _WIN64
+
+ATTR(cpu_specific(generic)) void CPU(void){}
+ATTR(cpu_specific(pentium)) void CPU(void){}
+ATTR(cpu_specific(pentium_pro)) void CPU(void){}
+ATTR(cpu_specific(pentium_mmx)) void CPU(void){}
+ATTR(cpu_specific(pentium_ii)) void CPU(void){}
+ATTR(cpu_specific(pentium_iii)) void CPU(void){}
+ATTR(cpu_specific(pentium_4)) void CPU(void){}
+ATTR(cpu_specific(pentium_m)) void CPU(void){}
+ATTR(cpu_specific(pentium_4_sse3)) void CPU(void){}
+ATTR(cpu_specific(core_2_duo_ssse3)) void CPU(void){}
+ATTR(cpu_specific(core_2_duo_sse4_1)) void CPU(void){}
+ATTR(cpu_specific(atom)) void CPU(void){}
+ATTR(cpu_specific(atom_sse4_2)) void CPU(void){}
+ATTR(cpu_specific(core_i7_sse4_2)) void CPU(void){}
+ATTR(cpu_specific(core_aes_pclmulqdq)) void CPU(void){}
+ATTR(cpu_specific(atom_sse4_2_movbe)) void CPU(void){}
+ATTR(cpu_specific(goldmont)) void CPU(void){}
+ATTR(cpu_specific(sandybridge)) void CPU(void){}
+ATTR(cpu_specific(ivybridge)) void CPU(void){}
+ATTR(cpu_specific(haswell)) void CPU(void){}
+ATTR(cpu_specific(core_4th_gen_avx_tsx)) void CPU(void){}
+ATTR(cpu_specific(broadwell)) void CPU(void){}
+ATTR(cpu_specific(core_5th_gen_avx_tsx)) void CPU(void){}
+ATTR(cpu_specific(knl)) void CPU(void){}
+ATTR(cpu_specific(skylake)) void CPU(void){}
+ATTR(cpu_specific(skylake_avx512)) void CPU(void){}
+ATTR(cpu_specific(cannonlake)) void CPU(void){}
+ATTR(cpu_specific(knm)) void CPU(void){}
+
+// ALIAS CPUs
+ATTR(cpu_specific(pentium_iii_no_xmm_regs)) void CPU0(void){}
+ATTR(cpu_specific(core_2nd_gen_avx)) void CPU1(void){}
+ATTR(cpu_specific(core_3rd_gen_avx)) void CPU2(void){}
+ATTR(cpu_specific(core_4th_gen_avx)) void CPU3(void){}
+ATTR(cpu_specific(core_5th_gen_avx)) void CPU4(void){}
+ATTR(cpu_specific(mic_avx512)) void CPU5(void){}

diff  --git a/clang/test/CodeGen/attr-cpuspecific.c 
b/clang/test/CodeGen/attr-cpuspecific.c
index 5f4c9102cbecb..2cab5affd356c 100644
--- a/clang/test/CodeGen/attr-cpuspecific.c
+++ b/clang/test/CodeGen/attr-cpuspecific.c
@@ -5,7 +5,7 @@
 #define ATTR(X) __declspec(X)
 #else
 #define ATTR(X) __attribute__((X))
-#endif // _MSC_VER
+#endif // _WIN64
 
 // Each version should have an IFunc and an alias.
 // LINUX: @SingleVersion = weak_odr alias void (), ptr @SingleVersion.ifunc
@@ -43,12 +43,18 @@ ATTR(cpu_dispatch(ivybridge))
 void SingleVersion(void);
 // LINUX: define weak_odr ptr @SingleVersion.resolver()
 // LINUX: call void @__cpu_indicator_init
+// LINUX: %[[FEAT_INIT:.+]] = load i32, ptr getelementptr inbounds ({ i32, 
i32, i32, [1 x i32] }, ptr @__cpu_model, i32 0, i32 3, i32 0), align 4
+// LINUX: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 1023
+// LINUX: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 1023
 // LINUX: ret ptr @SingleVersion.S
 // LINUX: call void @llvm.trap
 // LINUX: unreachable
 
 // WINDOWS: define weak_odr dso_local void @SingleVersion() comdat
 // WINDOWS: call void @__cpu_indicator_init()
+// WINDOWS: %[[FEAT_INIT:.+]] = load i32, ptr getelementptr inbounds ({ i32, 
i32, i32, [1 x i32] }, ptr @__cpu_model, i32 0, i32 3, i32 0), align 4
+// WINDOWS: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 1023
+// WINDOWS: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 1023
 // WINDOWS: call void @SingleVersion.S()
 // WINDOWS-NEXT: ret void
 // WINDOWS: call void @llvm.trap
@@ -67,6 +73,9 @@ ATTR(cpu_dispatch(ivybridge, knl))
 void TwoVersions(void);
 // LINUX: define weak_odr ptr @TwoVersions.resolver()
 // LINUX: call void @__cpu_indicator_init
+// LINUX: %[[FEAT_INIT:.+]] = load i32, ptr getelementptr inbounds ({ i32, 
i32, i32, [1 x i32] }, ptr @__cpu_model, i32 0, i32 3, i32 0), align 4
+// LINUX: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 58836991
+// LINUX: 

[PATCH] D152989: Pre-commit test for D151696.

2023-06-27 Thread Freddy, Ye via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG43baa5986c20: Pre-commit test for D151696. (authored by 
FreddyYe).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152989/new/

https://reviews.llvm.org/D152989

Files:
  clang/test/CodeGen/attr-cpuspecific-cpus.c
  clang/test/CodeGen/attr-cpuspecific.c

Index: clang/test/CodeGen/attr-cpuspecific.c
===
--- clang/test/CodeGen/attr-cpuspecific.c
+++ clang/test/CodeGen/attr-cpuspecific.c
@@ -5,7 +5,7 @@
 #define ATTR(X) __declspec(X)
 #else
 #define ATTR(X) __attribute__((X))
-#endif // _MSC_VER
+#endif // _WIN64
 
 // Each version should have an IFunc and an alias.
 // LINUX: @SingleVersion = weak_odr alias void (), ptr @SingleVersion.ifunc
@@ -43,12 +43,18 @@
 void SingleVersion(void);
 // LINUX: define weak_odr ptr @SingleVersion.resolver()
 // LINUX: call void @__cpu_indicator_init
+// LINUX: %[[FEAT_INIT:.+]] = load i32, ptr getelementptr inbounds ({ i32, i32, i32, [1 x i32] }, ptr @__cpu_model, i32 0, i32 3, i32 0), align 4
+// LINUX: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 1023
+// LINUX: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 1023
 // LINUX: ret ptr @SingleVersion.S
 // LINUX: call void @llvm.trap
 // LINUX: unreachable
 
 // WINDOWS: define weak_odr dso_local void @SingleVersion() comdat
 // WINDOWS: call void @__cpu_indicator_init()
+// WINDOWS: %[[FEAT_INIT:.+]] = load i32, ptr getelementptr inbounds ({ i32, i32, i32, [1 x i32] }, ptr @__cpu_model, i32 0, i32 3, i32 0), align 4
+// WINDOWS: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 1023
+// WINDOWS: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 1023
 // WINDOWS: call void @SingleVersion.S()
 // WINDOWS-NEXT: ret void
 // WINDOWS: call void @llvm.trap
@@ -67,6 +73,9 @@
 void TwoVersions(void);
 // LINUX: define weak_odr ptr @TwoVersions.resolver()
 // LINUX: call void @__cpu_indicator_init
+// LINUX: %[[FEAT_INIT:.+]] = load i32, ptr getelementptr inbounds ({ i32, i32, i32, [1 x i32] }, ptr @__cpu_model, i32 0, i32 3, i32 0), align 4
+// LINUX: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 58836991
+// LINUX: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 58836991
 // LINUX: ret ptr @TwoVersions.Z
 // LINUX: ret ptr @TwoVersions.S
 // LINUX: call void @llvm.trap
@@ -74,6 +83,9 @@
 
 // WINDOWS: define weak_odr dso_local void @TwoVersions() comdat
 // WINDOWS: call void @__cpu_indicator_init()
+// WINDOWS: %[[FEAT_INIT:.+]] = load i32, ptr getelementptr inbounds ({ i32, i32, i32, [1 x i32] }, ptr @__cpu_model, i32 0, i32 3, i32 0), align 4
+// WINDOWS: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 58836991
+// WINDOWS: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 58836991
 // WINDOWS: call void @TwoVersions.Z()
 // WINDOWS-NEXT: ret void
 // WINDOWS: call void @TwoVersions.S()
Index: clang/test/CodeGen/attr-cpuspecific-cpus.c
===
--- /dev/null
+++ clang/test/CodeGen/attr-cpuspecific-cpus.c
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -emit-llvm -o - %s
+// RUN: %clang_cc1 -verify -triple x86_64-windows-pc -fms-compatibility -emit-llvm -o - %s
+
+// expected-no-diagnostics
+
+#ifdef _WIN64
+#define ATTR(X) __declspec(X)
+#else
+#define ATTR(X) __attribute__((X))
+#endif // _WIN64
+
+ATTR(cpu_specific(generic)) void CPU(void){}
+ATTR(cpu_specific(pentium)) void CPU(void){}
+ATTR(cpu_specific(pentium_pro)) void CPU(void){}
+ATTR(cpu_specific(pentium_mmx)) void CPU(void){}
+ATTR(cpu_specific(pentium_ii)) void CPU(void){}
+ATTR(cpu_specific(pentium_iii)) void CPU(void){}
+ATTR(cpu_specific(pentium_4)) void CPU(void){}
+ATTR(cpu_specific(pentium_m)) void CPU(void){}
+ATTR(cpu_specific(pentium_4_sse3)) void CPU(void){}
+ATTR(cpu_specific(core_2_duo_ssse3)) void CPU(void){}
+ATTR(cpu_specific(core_2_duo_sse4_1)) void CPU(void){}
+ATTR(cpu_specific(atom)) void CPU(void){}
+ATTR(cpu_specific(atom_sse4_2)) void CPU(void){}
+ATTR(cpu_specific(core_i7_sse4_2)) void CPU(void){}
+ATTR(cpu_specific(core_aes_pclmulqdq)) void CPU(void){}
+ATTR(cpu_specific(atom_sse4_2_movbe)) void CPU(void){}
+ATTR(cpu_specific(goldmont)) void CPU(void){}
+ATTR(cpu_specific(sandybridge)) void CPU(void){}
+ATTR(cpu_specific(ivybridge)) void CPU(void){}
+ATTR(cpu_specific(haswell)) void CPU(void){}
+ATTR(cpu_specific(core_4th_gen_avx_tsx)) void CPU(void){}
+ATTR(cpu_specific(broadwell)) void CPU(void){}
+ATTR(cpu_specific(core_5th_gen_avx_tsx)) void CPU(void){}
+ATTR(cpu_specific(knl)) void CPU(void){}
+ATTR(cpu_specific(skylake)) void CPU(void){}
+ATTR(cpu_specific(skylake_avx512)) void CPU(void){}
+ATTR(cpu_specific(cannonlake)) void CPU(void){}
+ATTR(cpu_specific(knm)) void CPU(void){}
+
+// ALIAS CPUs
+ATTR(cpu_specific(pentium_iii_no_xmm_regs)) void CPU0(void){}
+ATTR(cpu_specific(core_2nd_gen_avx)) void CPU1(void){}

[PATCH] D153674: [dataflow] Disallow implicit copy of Environment, use fork() instead

2023-06-27 Thread Zixuan Wu via Phabricator via cfe-commits
zixuan-wu added a comment.

Hi, there is a compiling error introduced recently as like following when files 
under clang/lib/Analysis/FlowSensitive/ are being compiled such as 
TypeErasedDataflowAnalysis.cpp and Transfer.cpp. Does anybody meet also?

>   from /usr/include/c++/7/functional:60,
>   from 
> /iothome/wuzx/workspace/master-csky/clang/unittests/Analysis/FlowSensitive/TestingSupport.h:16,
>   from 
> /iothome/wuzx/workspace/master-csky/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp:9:
>
> /usr/include/c++/7/optional:453:11: note: 
> ‘std::optional
>  >::optional(const 
> std::optional
>  >&)’ is implicitly deleted because the default definition would be 
> ill-formed:
>
>   class optional
> ^~~~
>
> /usr/include/c++/7/optional:453:11: error: use of deleted function ‘constexpr 
> std::_Enable_copy_move _Tag>::_Enable_copy_move(const std::_Enable_copy_move true, _Tag>&) [with _Tag = 
> std::optional
>  >]’
> In file included from /usr/include/c++/7/optional:43:0,
>
>   from /usr/include/c++/7/bits/node_handle.h:39,
>   from /usr/include/c++/7/bits/hashtable.h:37,
>   from /usr/include/c++/7/unordered_map:47,
>   from /usr/include/c++/7/functional:60,
>   from 
> /iothome/wuzx/workspace/master-csky/clang/unittests/Analysis/FlowSensitive/TestingSupport.h:16,
>   from 
> /iothome/wuzx/workspace/master-csky/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp:9:
>
> /usr/include/c++/7/bits/enable_special_members.h:157:15: note: declared here
>
>   constexpr _Enable_copy_move(_Enable_copy_move const&) noexcept  = delete;
> ^
>
> In file included from /usr/include/c++/7

The gcc version is gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153674/new/

https://reviews.llvm.org/D153674

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


[clang] e9fb7d6 - [Fuchsia] Enable libcxx filesystem on Windows for stage 1 build

2023-06-27 Thread Petr Hosek via cfe-commits

Author: Petr Hosek
Date: 2023-06-28T05:43:16Z
New Revision: e9fb7d6972b9a48918ebffb61ef1472e1b1d7636

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

LOG: [Fuchsia] Enable libcxx filesystem on Windows for stage 1 build

This is a follow up to D153931 but for the first stage.

Added: 


Modified: 
clang/cmake/caches/Fuchsia.cmake

Removed: 




diff  --git a/clang/cmake/caches/Fuchsia.cmake 
b/clang/cmake/caches/Fuchsia.cmake
index cc6bddf76d42a..bbaf8e262b925 100644
--- a/clang/cmake/caches/Fuchsia.cmake
+++ b/clang/cmake/caches/Fuchsia.cmake
@@ -95,7 +95,6 @@ endif()
 
 if(WIN32)
   set(LIBCXX_ABI_VERSION 2 CACHE STRING "")
-  set(LIBCXX_ENABLE_FILESYSTEM OFF CACHE BOOL "")
   set(LIBCXX_ENABLE_ABI_LINKER_SCRIPT OFF CACHE BOOL "")
   set(LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
   set(BUILTINS_CMAKE_ARGS -DCMAKE_SYSTEM_NAME=Windows CACHE STRING "")



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


[clang] 2241146 - [NFC] [C++20] [Modules] Add a test for merging lambda types

2023-06-27 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2023-06-28T13:41:39+08:00
New Revision: 2241146752f9260d077a6ac38f43069f945e85b4

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

LOG: [NFC] [C++20] [Modules] Add a test for merging lambda types

Close https://github.com/llvm/llvm-project/issues/57222.

This should be fixed with the series of bc73ef0. Add the test case for
C++20 Named modules.

Added: 
clang/test/Modules/merge-lambdas.cppm

Modified: 


Removed: 




diff  --git a/clang/test/Modules/merge-lambdas.cppm 
b/clang/test/Modules/merge-lambdas.cppm
new file mode 100644
index 0..a1d04ab4e234d
--- /dev/null
+++ b/clang/test/Modules/merge-lambdas.cppm
@@ -0,0 +1,40 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 %t/A.cppm -emit-module-interface -o %t/A.pcm
+// RUN: %clang_cc1 -std=c++20 %t/B.cppm -emit-module-interface -o %t/B.pcm
+// RUN: %clang_cc1 -std=c++20 %t/use.cppm -fprebuilt-module-path=%t 
-fsyntax-only -verify
+
+//--- lambda.h
+inline auto cmp = [](auto l, auto r) {
+  return l < r;
+};
+
+//--- A.cppm
+module;
+#include "lambda.h"
+
+export module A;
+export auto c1 = cmp;
+export using ::cmp;
+
+//--- B.cppm
+module;
+#include "lambda.h"
+
+export module B;
+export auto c2 = cmp;
+export using ::cmp;
+
+//--- use.cppm
+// expected-no-diagnostics
+module;
+
+export module use;
+
+import A;
+import B;
+
+static_assert(__is_same(decltype(c1), decltype(c2))); // should succeed.
+auto x = cmp; // cmp must not be ambiguous,



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


[PATCH] D153714: [NFC] Add missing cpu tests in predefined-arch-macros.c

2023-06-27 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe added a comment.

ping this thread, too. Notice that this is an independent patch :-)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153714/new/

https://reviews.llvm.org/D153714

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


[PATCH] D152989: Pre-commit test for D151696.

2023-06-27 Thread Kan Shengchen via Phabricator via cfe-commits
skan accepted this revision.
skan added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152989/new/

https://reviews.llvm.org/D152989

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


[PATCH] D152989: Pre-commit test for D151696.

2023-06-27 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe updated this revision to Diff 535223.
FreddyYe added a comment.

Seperate ALIAS CPUs.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152989/new/

https://reviews.llvm.org/D152989

Files:
  clang/test/CodeGen/attr-cpuspecific-cpus.c
  clang/test/CodeGen/attr-cpuspecific.c

Index: clang/test/CodeGen/attr-cpuspecific.c
===
--- clang/test/CodeGen/attr-cpuspecific.c
+++ clang/test/CodeGen/attr-cpuspecific.c
@@ -5,7 +5,7 @@
 #define ATTR(X) __declspec(X)
 #else
 #define ATTR(X) __attribute__((X))
-#endif // _MSC_VER
+#endif // _WIN64
 
 // Each version should have an IFunc and an alias.
 // LINUX: @SingleVersion = weak_odr alias void (), ptr @SingleVersion.ifunc
@@ -43,12 +43,18 @@
 void SingleVersion(void);
 // LINUX: define weak_odr ptr @SingleVersion.resolver()
 // LINUX: call void @__cpu_indicator_init
+// LINUX: %[[FEAT_INIT:.+]] = load i32, ptr getelementptr inbounds ({ i32, i32, i32, [1 x i32] }, ptr @__cpu_model, i32 0, i32 3, i32 0), align 4
+// LINUX: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 1023
+// LINUX: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 1023
 // LINUX: ret ptr @SingleVersion.S
 // LINUX: call void @llvm.trap
 // LINUX: unreachable
 
 // WINDOWS: define weak_odr dso_local void @SingleVersion() comdat
 // WINDOWS: call void @__cpu_indicator_init()
+// WINDOWS: %[[FEAT_INIT:.+]] = load i32, ptr getelementptr inbounds ({ i32, i32, i32, [1 x i32] }, ptr @__cpu_model, i32 0, i32 3, i32 0), align 4
+// WINDOWS: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 1023
+// WINDOWS: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 1023
 // WINDOWS: call void @SingleVersion.S()
 // WINDOWS-NEXT: ret void
 // WINDOWS: call void @llvm.trap
@@ -67,6 +73,9 @@
 void TwoVersions(void);
 // LINUX: define weak_odr ptr @TwoVersions.resolver()
 // LINUX: call void @__cpu_indicator_init
+// LINUX: %[[FEAT_INIT:.+]] = load i32, ptr getelementptr inbounds ({ i32, i32, i32, [1 x i32] }, ptr @__cpu_model, i32 0, i32 3, i32 0), align 4
+// LINUX: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 58836991
+// LINUX: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 58836991
 // LINUX: ret ptr @TwoVersions.Z
 // LINUX: ret ptr @TwoVersions.S
 // LINUX: call void @llvm.trap
@@ -74,6 +83,9 @@
 
 // WINDOWS: define weak_odr dso_local void @TwoVersions() comdat
 // WINDOWS: call void @__cpu_indicator_init()
+// WINDOWS: %[[FEAT_INIT:.+]] = load i32, ptr getelementptr inbounds ({ i32, i32, i32, [1 x i32] }, ptr @__cpu_model, i32 0, i32 3, i32 0), align 4
+// WINDOWS: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 58836991
+// WINDOWS: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 58836991
 // WINDOWS: call void @TwoVersions.Z()
 // WINDOWS-NEXT: ret void
 // WINDOWS: call void @TwoVersions.S()
Index: clang/test/CodeGen/attr-cpuspecific-cpus.c
===
--- /dev/null
+++ clang/test/CodeGen/attr-cpuspecific-cpus.c
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -emit-llvm -o - %s
+// RUN: %clang_cc1 -verify -triple x86_64-windows-pc -fms-compatibility -emit-llvm -o - %s
+
+// expected-no-diagnostics
+
+#ifdef _WIN64
+#define ATTR(X) __declspec(X)
+#else
+#define ATTR(X) __attribute__((X))
+#endif // _WIN64
+
+ATTR(cpu_specific(generic)) void CPU(void){}
+ATTR(cpu_specific(pentium)) void CPU(void){}
+ATTR(cpu_specific(pentium_pro)) void CPU(void){}
+ATTR(cpu_specific(pentium_mmx)) void CPU(void){}
+ATTR(cpu_specific(pentium_ii)) void CPU(void){}
+ATTR(cpu_specific(pentium_iii)) void CPU(void){}
+ATTR(cpu_specific(pentium_4)) void CPU(void){}
+ATTR(cpu_specific(pentium_m)) void CPU(void){}
+ATTR(cpu_specific(pentium_4_sse3)) void CPU(void){}
+ATTR(cpu_specific(core_2_duo_ssse3)) void CPU(void){}
+ATTR(cpu_specific(core_2_duo_sse4_1)) void CPU(void){}
+ATTR(cpu_specific(atom)) void CPU(void){}
+ATTR(cpu_specific(atom_sse4_2)) void CPU(void){}
+ATTR(cpu_specific(core_i7_sse4_2)) void CPU(void){}
+ATTR(cpu_specific(core_aes_pclmulqdq)) void CPU(void){}
+ATTR(cpu_specific(atom_sse4_2_movbe)) void CPU(void){}
+ATTR(cpu_specific(goldmont)) void CPU(void){}
+ATTR(cpu_specific(sandybridge)) void CPU(void){}
+ATTR(cpu_specific(ivybridge)) void CPU(void){}
+ATTR(cpu_specific(haswell)) void CPU(void){}
+ATTR(cpu_specific(core_4th_gen_avx_tsx)) void CPU(void){}
+ATTR(cpu_specific(broadwell)) void CPU(void){}
+ATTR(cpu_specific(core_5th_gen_avx_tsx)) void CPU(void){}
+ATTR(cpu_specific(knl)) void CPU(void){}
+ATTR(cpu_specific(skylake)) void CPU(void){}
+ATTR(cpu_specific(skylake_avx512)) void CPU(void){}
+ATTR(cpu_specific(cannonlake)) void CPU(void){}
+ATTR(cpu_specific(knm)) void CPU(void){}
+
+// ALIAS CPUs
+ATTR(cpu_specific(pentium_iii_no_xmm_regs)) void CPU0(void){}
+ATTR(cpu_specific(core_2nd_gen_avx)) void CPU1(void){}
+ATTR(cpu_specific(core_3rd_gen_avx)) void CPU2(void){}
+ATTR(cpu_specific(core_4th_gen_avx)) void CPU3(void){}

[PATCH] D153924: Allowing exception handling in OpenMP target regions when offloading to AMDGCN or NVPTX targets

2023-06-27 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticCommonKinds.td:432
+  "Target '%0' does not support exception handling."
+  " To allow code generation for '%0', 'catch' statement will be replaced by a 
no operation instruction.">;
 }

Check the style of other messages, they have a single sentence and start with a 
lower case letter.
Also, the explanation doesn't make sense for users. They don't know about 
traps, basic blocks, etc.
Maybe:
`target '%0' does not support exception handling; 'throw' is assumed to be 
never reached`
`target '%0' does not support exception handling; 'catch' block is ignored`
and nothing for try.
Finally, these need a group so users can also disable them.



Comment at: clang/lib/CodeGen/CGException.cpp:12
 
//===--===//
-
 #include "CGCXXABI.h"

unrelated, please add back



Comment at: clang/lib/CodeGen/CGException.cpp:450-451
+<< T.str();
+EmitTrapCall(llvm::Intrinsic::trap);
+  } else if (const Expr *SubExpr = E->getSubExpr()) {
 QualType ThrowType = SubExpr->getType();

You should be able to return after the EmitTrap to simplify the code.



Comment at: clang/lib/CodeGen/CGException.cpp:624
+  const bool is_omp_gpu_target =
+  (CGM.getLangOpts().OpenMPIsDevice && (T.isNVPTX() || T.isAMDGCN()));
+  if (is_omp_gpu_target) {

Check the LLVM style guide, or the surrounding code, for variable naming.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:3837
+Opts.Exceptions = exceptions_user_enabled;
+Opts.CXXExceptions = exceptions_user_enabled;
   }

I don't get this. Is this needed?



Comment at: clang/test/OpenMP/target_throw_message.cpp:6
+// RUN: -Xopenmp-target -fcxx-exceptions -emit-llvm -S %s -o - 2>&1 | 
FileCheck %s -v --check-prefix=TEST1
+// TEST1: {{Target 'amdgcn-amd-amdhsa' does not support exception handling. To 
allow code generation for 'amdgcn-amd-amdhsa', 'throw' expressions will be 
replaced by traps}}
+

It is very suspicious that you cannot use cc1 and verify. Also, various options 
are odd. 
I don't think we want the driver here, but we want cc1. We need to find out why 
this is not working.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153924/new/

https://reviews.llvm.org/D153924

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


[clang] d39b4ce - [test] Replace aarch64-*-eabi with aarch64

2023-06-27 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-06-27T20:02:52-07:00
New Revision: d39b4ce3ce8a3c256e01bdec2b140777a332a633

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

LOG: [test] Replace aarch64-*-eabi with aarch64

Using "eabi" for aarch64 targets is a common mistake and warned by Clang Driver.
We want to avoid it elsewhere as well. Just use the common "aarch64" without
other triple components.

Added: 


Modified: 
clang/test/CodeGen/aarch64-args-hfa.c
clang/test/CodeGen/aarch64-mops.c
llvm/test/Analysis/CostModel/AArch64/abs.ll
llvm/test/Analysis/CostModel/AArch64/arith-ssat.ll
llvm/test/Analysis/CostModel/AArch64/arith-usat.ll
llvm/test/CodeGen/AArch64/GlobalISel/inttoptr_add.ll
llvm/test/CodeGen/AArch64/GlobalISel/select-gv-cmodel-tiny.mir
llvm/test/CodeGen/AArch64/abd-combine.ll
llvm/test/CodeGen/AArch64/arm64-trn.ll
llvm/test/CodeGen/AArch64/bcax.ll
llvm/test/CodeGen/AArch64/bf16-vector-bitcast.ll
llvm/test/CodeGen/AArch64/bf16-vector-shuffle.ll
llvm/test/CodeGen/AArch64/cmp-const-max.ll
llvm/test/CodeGen/AArch64/code-model-tiny-abs.ll
llvm/test/CodeGen/AArch64/combine-andintoload.ll
llvm/test/CodeGen/AArch64/eor3.ll
llvm/test/CodeGen/AArch64/f16-imm.ll
llvm/test/CodeGen/AArch64/fcopysign.ll
llvm/test/CodeGen/AArch64/fp-intrinsics-fp16.ll
llvm/test/CodeGen/AArch64/fp-intrinsics-vector.ll
llvm/test/CodeGen/AArch64/fp-intrinsics.ll
llvm/test/CodeGen/AArch64/fp16-v16-instructions.ll
llvm/test/CodeGen/AArch64/fp16-v4-instructions.ll
llvm/test/CodeGen/AArch64/fp16-v8-instructions.ll
llvm/test/CodeGen/AArch64/fp16-vector-bitcast.ll
llvm/test/CodeGen/AArch64/fp16-vector-load-store.ll
llvm/test/CodeGen/AArch64/fp16-vector-nvcast.ll
llvm/test/CodeGen/AArch64/fp16-vector-shuffle.ll
llvm/test/CodeGen/AArch64/fpimm.ll
llvm/test/CodeGen/AArch64/hadd-combine.ll
llvm/test/CodeGen/AArch64/inline-asm-clobber-base-frame-pointer.ll
llvm/test/CodeGen/AArch64/inline-asm-clobber.ll
llvm/test/CodeGen/AArch64/inlineasm-X-allocation.ll
llvm/test/CodeGen/AArch64/ld1postmul.ll
llvm/test/CodeGen/AArch64/ldradr.ll
llvm/test/CodeGen/AArch64/ldrpre-ldr-merge.mir
llvm/test/CodeGen/AArch64/load-insert-zero.ll
llvm/test/CodeGen/AArch64/lowerMUL-newload.ll
llvm/test/CodeGen/AArch64/mulcmle.ll
llvm/test/CodeGen/AArch64/neon-extadd.ll
llvm/test/CodeGen/AArch64/neon-rshrn.ll
llvm/test/CodeGen/AArch64/rax1.ll
llvm/test/CodeGen/AArch64/reassocmls.ll
llvm/test/CodeGen/AArch64/shift-accumulate.ll
llvm/test/CodeGen/AArch64/shuffle-tbl34.ll
llvm/test/CodeGen/AArch64/sign-return-address-cfi-negate-ra-state.ll
llvm/test/CodeGen/AArch64/sign-return-address.ll
llvm/test/CodeGen/AArch64/special-reg.ll
llvm/test/CodeGen/AArch64/stack-tagging-ex-1.ll
llvm/test/CodeGen/AArch64/stack-tagging-musttail.ll
llvm/test/CodeGen/AArch64/stack-tagging-split-lifetime.ll
llvm/test/CodeGen/AArch64/stack-tagging-untag-placement.ll
llvm/test/CodeGen/AArch64/storepairsuppress_minsize.ll
llvm/test/CodeGen/AArch64/strict-fp-opt.ll
llvm/test/CodeGen/AArch64/strpre-str-merge.mir
llvm/test/CodeGen/AArch64/sve-pr62151.ll
llvm/test/CodeGen/AArch64/sve-pred-selectop.ll
llvm/test/CodeGen/AArch64/sve-pred-selectop2.ll
llvm/test/CodeGen/AArch64/sve-pred-selectop3.ll
llvm/test/CodeGen/AArch64/sve2-eor3.ll
llvm/test/CodeGen/AArch64/tbl-loops.ll
llvm/test/CodeGen/AArch64/tiny_supported.ll
llvm/test/CodeGen/AArch64/typepromotion-cost.ll
llvm/test/CodeGen/AArch64/vacg.ll
llvm/test/CodeGen/AArch64/vector-fcvt.ll
llvm/test/CodeGen/AArch64/vldn_shuffle.ll
llvm/test/CodeGen/AArch64/vscale-power-of-two.ll
llvm/test/Instrumentation/HWAddressSanitizer/musttail.ll
llvm/test/MC/AArch64/align.s
llvm/test/MC/AsmParser/AArch64/directive-parse-err.s
llvm/test/Transforms/AggressiveInstCombine/AArch64/fptosisat.ll
llvm/test/Transforms/InstCombine/AArch64/demandelts.ll
llvm/test/Transforms/LoopStrengthReduce/AArch64/lsr-pre-inc-offset-check.ll
llvm/test/Transforms/SLPVectorizer/AArch64/fpsat.ll
llvm/test/Transforms/VectorCombine/AArch64/select-shuffle.ll
llvm/test/Transforms/VectorCombine/AArch64/vecreduce-shuffle.ll
llvm/test/tools/llvm-mca/AArch64/Cortex/forwarding-A57.s

Removed: 




diff  --git a/clang/test/CodeGen/aarch64-args-hfa.c 
b/clang/test/CodeGen/aarch64-args-hfa.c
index 400375f8cb789..fbfedc7db7913 100644
--- a/clang/test/CodeGen/aarch64-args-hfa.c
+++ b/clang/test/CodeGen/aarch64-args-hfa.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple aarch64-none-eabi -emit-llvm -o - %s | FileCheck %s 
--check-prefixes=CHECK,CHECK-AAPCS
+// RUN: %clang_cc1 -triple aarch64 

[PATCH] D152989: Pre-commit test for D151696.

2023-06-27 Thread Kan Shengchen via Phabricator via cfe-commits
skan added inline comments.



Comment at: clang/test/CodeGen/attr-cpuspecific-cpus.c:12
+
+ATTR(cpu_specific(generic)) void CPU0(void){}
+ATTR(cpu_specific(pentium)) void CPU1(void){}

FreddyYe wrote:
> skan wrote:
> > Shouldn't we use the same function name?
> Emmm...  it would involve a new problem that some aliased cpu names would 
> result a diagnostic like this:
> ```
> definition with same mangled name 'CPU.H' as another definition
> ```
> This is expected but my original purpose here is only to check if cpu name 
> strings are valid. If you prefer, I can change into a style that makes the 
> non-alias CPU names use the same function and makes the aliased ones' 
> function names indexed. WDYT?
That would make sense to me.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152989/new/

https://reviews.llvm.org/D152989

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


[PATCH] D152989: Pre-commit test for D151696.

2023-06-27 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe added inline comments.



Comment at: clang/test/CodeGen/attr-cpuspecific-cpus.c:12
+
+ATTR(cpu_specific(generic)) void CPU0(void){}
+ATTR(cpu_specific(pentium)) void CPU1(void){}

skan wrote:
> Shouldn't we use the same function name?
Emmm...  it would involve a new problem that some aliased cpu names would 
result a diagnostic like this:
```
definition with same mangled name 'CPU.H' as another definition
```
This is expected but my original purpose here is only to check if cpu name 
strings are valid. If you prefer, I can change into a style that makes the 
non-alias CPU names use the same function and makes the aliased ones' function 
names indexed. WDYT?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152989/new/

https://reviews.llvm.org/D152989

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


[PATCH] D152989: Pre-commit test for D151696.

2023-06-27 Thread Kan Shengchen via Phabricator via cfe-commits
skan added inline comments.



Comment at: clang/test/CodeGen/attr-cpuspecific-cpus.c:12
+
+ATTR(cpu_specific(generic)) void CPU0(void){}
+ATTR(cpu_specific(pentium)) void CPU1(void){}

Shouldn't we use the same function name?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152989/new/

https://reviews.llvm.org/D152989

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


[clang] 02e9441 - [test] Replace -triple aarch64-arm-none-eabi with -triple aarch64

2023-06-27 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-06-27T19:21:41-07:00
New Revision: 02e9441d6ca73314afa1973a234dce1e390da1da

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

LOG: [test] Replace -triple aarch64-arm-none-eabi with -triple aarch64

Using "eabi" for aarch64 targets is a common mistake and warned by driver
(D153430). We want to avoid them for -cc1 tests as well.

Added: 


Modified: 
clang/test/CodeGen/aarch64-bf16-dotprod-intrinsics.c
clang/test/CodeGen/aarch64-bf16-getset-intrinsics.c
clang/test/CodeGen/aarch64-bf16-lane-intrinsics.c
clang/test/CodeGen/aarch64-bf16-ldst-intrinsics.c
clang/test/CodeGen/aarch64-bf16-reinterpret-intrinsics.c
clang/test/CodeGen/arm-bf16-convert-intrinsics.c
clang/test/CodeGen/arm-bf16-params-returns.c
clang/test/CodeGen/arm-mangle-bf16.cpp
clang/test/CodeGenCXX/fp16-mangle-arg-return.cpp
clang/test/Driver/arm-aarch64-bitfield-flags.c
clang/test/Sema/aarch64-bf16-ldst-intrinsics.c
clang/test/Sema/aarch64-neon-bf16-ranges.c
clang/test/Sema/arm-bfloat.cpp
clang/test/Sema/arm-sve-target.cpp
clang/test/Sema/sugar-common-types.c
clang/test/SemaOpenMP/arm-sve-acle-types.cpp

Removed: 




diff  --git a/clang/test/CodeGen/aarch64-bf16-dotprod-intrinsics.c 
b/clang/test/CodeGen/aarch64-bf16-dotprod-intrinsics.c
index e6179880c850a..0f4d955808054 100644
--- a/clang/test/CodeGen/aarch64-bf16-dotprod-intrinsics.c
+++ b/clang/test/CodeGen/aarch64-bf16-dotprod-intrinsics.c
@@ -1,5 +1,5 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
-// RUN: %clang_cc1 -triple aarch64-arm-none-eabi -target-feature +neon 
-target-feature +bf16 \
+// RUN: %clang_cc1 -triple aarch64 -target-feature +neon -target-feature +bf16 
\
 // RUN: -disable-O0-optnone -emit-llvm %s -o - | opt -S -passes=mem2reg | 
FileCheck %s
 
 // REQUIRES: aarch64-registered-target || arm-registered-target

diff  --git a/clang/test/CodeGen/aarch64-bf16-getset-intrinsics.c 
b/clang/test/CodeGen/aarch64-bf16-getset-intrinsics.c
index ed686dc03d20d..e07d93f7f0182 100644
--- a/clang/test/CodeGen/aarch64-bf16-getset-intrinsics.c
+++ b/clang/test/CodeGen/aarch64-bf16-getset-intrinsics.c
@@ -1,5 +1,5 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
-// RUN: %clang_cc1 -triple aarch64-arm-none-eabi -target-feature +neon 
-target-feature +bf16 \
+// RUN: %clang_cc1 -triple aarch64 -target-feature +neon -target-feature +bf16 
\
 // RUN:  -disable-O0-optnone -emit-llvm %s -o - | opt -S -passes=mem2reg | 
FileCheck %s
 
 // REQUIRES: aarch64-registered-target || arm-registered-target

diff  --git a/clang/test/CodeGen/aarch64-bf16-lane-intrinsics.c 
b/clang/test/CodeGen/aarch64-bf16-lane-intrinsics.c
index b807370b7c5cb..7f989588eca80 100644
--- a/clang/test/CodeGen/aarch64-bf16-lane-intrinsics.c
+++ b/clang/test/CodeGen/aarch64-bf16-lane-intrinsics.c
@@ -1,5 +1,5 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
-// RUN: %clang_cc1 -triple aarch64-arm-none-eabi -target-feature +neon 
-target-feature +bf16 \
+// RUN: %clang_cc1 -triple aarch64 -target-feature +neon -target-feature +bf16 
\
 // RUN:  -disable-O0-optnone -emit-llvm %s -o - | opt -S -passes=mem2reg | 
FileCheck --check-prefix=CHECK-LE %s
 // RUN: %clang_cc1 -triple aarch64_be-arm-none-eabi -target-feature +neon 
-target-feature +bf16 \
 // RUN:  -disable-O0-optnone -emit-llvm %s -o - | opt -S -passes=mem2reg | 
FileCheck --check-prefix=CHECK-BE %s

diff  --git a/clang/test/CodeGen/aarch64-bf16-ldst-intrinsics.c 
b/clang/test/CodeGen/aarch64-bf16-ldst-intrinsics.c
index 84d7fd05c276e..5d778e3b51d0e 100644
--- a/clang/test/CodeGen/aarch64-bf16-ldst-intrinsics.c
+++ b/clang/test/CodeGen/aarch64-bf16-ldst-intrinsics.c
@@ -1,5 +1,5 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
-// RUN: %clang_cc1 -triple aarch64-arm-none-eabi -target-feature +neon 
-target-feature +bf16 \
+// RUN: %clang_cc1 -triple aarch64 -target-feature +neon -target-feature +bf16 
\
 // RUN:  -O2 -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK64
 // RUN: %clang_cc1 -triple armv8.6a-arm-none-eabi -target-feature +neon 
-target-feature +bf16 -mfloat-abi hard \
 // RUN:  -O2 -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK32

diff  --git a/clang/test/CodeGen/aarch64-bf16-reinterpret-intrinsics.c 
b/clang/test/CodeGen/aarch64-bf16-reinterpret-intrinsics.c
index 1ad3726d910a7..850d8fa5bbab4 100644
--- a/clang/test/CodeGen/aarch64-bf16-reinterpret-intrinsics.c
+++ b/clang/test/CodeGen/aarch64-bf16-reinterpret-intrinsics.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple aarch64-arm-none-eabi -target-feature +neon 
-target-feature +bf16 \
+// RUN: %clang_cc1 -triple aarch64 

[PATCH] D152989: Pre-commit test for D151696.

2023-06-27 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei accepted this revision.
pengfei added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152989/new/

https://reviews.llvm.org/D152989

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


[PATCH] D153321: [OpenMP] Fix lvalue reference type generation in untied task loop

2023-06-27 Thread Zhiheng Xie via Phabricator via cfe-commits
eastb233 added a comment.

Ping.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153321/new/

https://reviews.llvm.org/D153321

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


[PATCH] D152989: Pre-commit test for D151696.

2023-06-27 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe updated this revision to Diff 535215.
FreddyYe added a comment.

Change into a more simplified style.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152989/new/

https://reviews.llvm.org/D152989

Files:
  clang/test/CodeGen/attr-cpuspecific-cpus.c
  clang/test/CodeGen/attr-cpuspecific.c

Index: clang/test/CodeGen/attr-cpuspecific.c
===
--- clang/test/CodeGen/attr-cpuspecific.c
+++ clang/test/CodeGen/attr-cpuspecific.c
@@ -5,7 +5,7 @@
 #define ATTR(X) __declspec(X)
 #else
 #define ATTR(X) __attribute__((X))
-#endif // _MSC_VER
+#endif // _WIN64
 
 // Each version should have an IFunc and an alias.
 // LINUX: @SingleVersion = weak_odr alias void (), ptr @SingleVersion.ifunc
@@ -43,12 +43,18 @@
 void SingleVersion(void);
 // LINUX: define weak_odr ptr @SingleVersion.resolver()
 // LINUX: call void @__cpu_indicator_init
+// LINUX: %[[FEAT_INIT:.+]] = load i32, ptr getelementptr inbounds ({ i32, i32, i32, [1 x i32] }, ptr @__cpu_model, i32 0, i32 3, i32 0), align 4
+// LINUX: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 1023
+// LINUX: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 1023
 // LINUX: ret ptr @SingleVersion.S
 // LINUX: call void @llvm.trap
 // LINUX: unreachable
 
 // WINDOWS: define weak_odr dso_local void @SingleVersion() comdat
 // WINDOWS: call void @__cpu_indicator_init()
+// WINDOWS: %[[FEAT_INIT:.+]] = load i32, ptr getelementptr inbounds ({ i32, i32, i32, [1 x i32] }, ptr @__cpu_model, i32 0, i32 3, i32 0), align 4
+// WINDOWS: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 1023
+// WINDOWS: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 1023
 // WINDOWS: call void @SingleVersion.S()
 // WINDOWS-NEXT: ret void
 // WINDOWS: call void @llvm.trap
@@ -67,6 +73,9 @@
 void TwoVersions(void);
 // LINUX: define weak_odr ptr @TwoVersions.resolver()
 // LINUX: call void @__cpu_indicator_init
+// LINUX: %[[FEAT_INIT:.+]] = load i32, ptr getelementptr inbounds ({ i32, i32, i32, [1 x i32] }, ptr @__cpu_model, i32 0, i32 3, i32 0), align 4
+// LINUX: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 58836991
+// LINUX: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 58836991
 // LINUX: ret ptr @TwoVersions.Z
 // LINUX: ret ptr @TwoVersions.S
 // LINUX: call void @llvm.trap
@@ -74,6 +83,9 @@
 
 // WINDOWS: define weak_odr dso_local void @TwoVersions() comdat
 // WINDOWS: call void @__cpu_indicator_init()
+// WINDOWS: %[[FEAT_INIT:.+]] = load i32, ptr getelementptr inbounds ({ i32, i32, i32, [1 x i32] }, ptr @__cpu_model, i32 0, i32 3, i32 0), align 4
+// WINDOWS: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 58836991
+// WINDOWS: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 58836991
 // WINDOWS: call void @TwoVersions.Z()
 // WINDOWS-NEXT: ret void
 // WINDOWS: call void @TwoVersions.S()
Index: clang/test/CodeGen/attr-cpuspecific-cpus.c
===
--- /dev/null
+++ clang/test/CodeGen/attr-cpuspecific-cpus.c
@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -emit-llvm -o - %s
+// RUN: %clang_cc1 -verify -triple x86_64-windows-pc -fms-compatibility -emit-llvm -o - %s
+
+// expected-no-diagnostics
+
+#ifdef _WIN64
+#define ATTR(X) __declspec(X)
+#else
+#define ATTR(X) __attribute__((X))
+#endif // _WIN64
+
+ATTR(cpu_specific(generic)) void CPU0(void){}
+ATTR(cpu_specific(pentium)) void CPU1(void){}
+ATTR(cpu_specific(pentium_pro)) void CPU2(void){}
+ATTR(cpu_specific(pentium_mmx)) void CPU3(void){}
+ATTR(cpu_specific(pentium_ii)) void CPU4(void){}
+ATTR(cpu_specific(pentium_iii)) void CPU5(void){}
+ATTR(cpu_specific(pentium_iii_no_xmm_regs)) void CPU6(void){}
+ATTR(cpu_specific(pentium_4)) void CPU7(void){}
+ATTR(cpu_specific(pentium_m)) void CPU8(void){}
+ATTR(cpu_specific(pentium_4_sse3)) void CPU9(void){}
+ATTR(cpu_specific(core_2_duo_ssse3)) void CPU10(void){}
+ATTR(cpu_specific(core_2_duo_sse4_1)) void CPU11(void){}
+ATTR(cpu_specific(atom)) void CPU12(void){}
+ATTR(cpu_specific(atom_sse4_2)) void CPU13(void){}
+ATTR(cpu_specific(core_i7_sse4_2)) void CPU14(void){}
+ATTR(cpu_specific(core_aes_pclmulqdq)) void CPU15(void){}
+ATTR(cpu_specific(atom_sse4_2_movbe)) void CPU16(void){}
+ATTR(cpu_specific(goldmont)) void CPU17(void){}
+ATTR(cpu_specific(sandybridge)) void CPU18(void){}
+ATTR(cpu_specific(core_2nd_gen_avx)) void CPU19(void){}
+ATTR(cpu_specific(ivybridge)) void CPU20(void){}
+ATTR(cpu_specific(core_3rd_gen_avx)) void CPU21(void){}
+ATTR(cpu_specific(haswell)) void CPU22(void){}
+ATTR(cpu_specific(core_4th_gen_avx)) void CPU23(void){}
+ATTR(cpu_specific(core_4th_gen_avx_tsx)) void CPU24(void){}
+ATTR(cpu_specific(broadwell)) void CPU25(void){}
+ATTR(cpu_specific(core_5th_gen_avx)) void CPU26(void){}
+ATTR(cpu_specific(core_5th_gen_avx_tsx)) void CPU27(void){}
+ATTR(cpu_specific(knl)) void CPU28(void){}
+ATTR(cpu_specific(mic_avx512)) void CPU29(void){}
+ATTR(cpu_specific(skylake)) void CPU30(void){}

[PATCH] D153582: [SystemZ][z/OS] Add required options/macro/etc for z/os compilation step

2023-06-27 Thread Sean via Phabricator via cfe-commits
SeanP updated this revision to Diff 535214.
SeanP added a comment.

Generalize path names in test cases so \\ on windows match.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153582/new/

https://reviews.llvm.org/D153582

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/OSTargets.h
  clang/lib/Basic/Targets/SystemZ.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/ZOS.cpp
  clang/lib/Driver/ToolChains/ZOS.h
  clang/test/Driver/zos-comp-cxx.cpp
  clang/test/Driver/zos-comp.c
  clang/test/Driver/zos-driver-defaults.c
  clang/test/Preprocessor/init-s390x.c

Index: clang/test/Preprocessor/init-s390x.c
===
--- clang/test/Preprocessor/init-s390x.c
+++ clang/test/Preprocessor/init-s390x.c
@@ -183,17 +183,12 @@
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=s390x-none-zos -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix S390X-ZOS %s
 // RUN: %clang_cc1 -x c++ -std=gnu++14 -E -dM -ffreestanding -triple=s390x-none-zos -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix S390X-ZOS -check-prefix S390X-ZOS-GNUXX %s
 
-// S390X-ZOS-GNUXX: #define _EXT 1
 // S390X-ZOS:   #define _LONG_LONG 1
-// S390X-ZOS-GNUXX: #define _MI_BUILTIN 1
-// S390X-ZOS:   #define _OPEN_DEFAULT 1
-// S390X-ZOS:   #define _UNIX03_WITHDRAWN 1
-// S390X-ZOS-GNUXX: #define _XOPEN_SOURCE 600
 // S390X-ZOS:   #define __370__ 1
 // S390X-ZOS:   #define __64BIT__ 1
 // S390X-ZOS:   #define __BFP__ 1
 // S390X-ZOS:   #define __BOOL__ 1
-// S390X-ZOS-GNUXX: #define __DLL__ 1
+// S390X-ZOS:   #define __COMPILER_VER__ 0x5000
 // S390X-ZOS:   #define __LONGNAME__ 1
 // S390X-ZOS:   #define __MVS__ 1
 // S390X-ZOS:   #define __THW_370__ 1
Index: clang/test/Driver/zos-driver-defaults.c
===
--- clang/test/Driver/zos-driver-defaults.c
+++ clang/test/Driver/zos-driver-defaults.c
@@ -1,8 +1,21 @@
-// RUN: %clang -### --target=s390x-none-zos -fsyntax-only %s 2>&1 | FileCheck --check-prefix=CHECK-SHORT-ENUMS %s
+// RUN: %clang -### --target=s390x-none-zos -fsyntax-only %s 2>&1 | FileCheck --check-prefixes=CHECK-C-MACRO,CHECK-SHORT-ENUMS %s
+// RUN: %clang -### --target=s390x-none-zos -fsyntax-only %s 2>&1 | FileCheck --check-prefix=CHECK-ZOS-INCLUDES %s
 // RUN: %clang -### --target=s390x-none-zos -fno-short-enums -fsyntax-only %s 2>&1 | FileCheck %s
+// RUN: %clangxx -### --target=s390x-none-zos -fsyntax-only %s 2>&1 | FileCheck --check-prefixes=CHECK-C-MACRO,CHECK-CXX-MACRO %s
+// RUN: %clang -### --target=s390x-none-zos -x c++ -fsyntax-only %s 2>&1 | FileCheck --check-prefixes=CHECK-C-MACRO,CHECK-CXX-MACRO %s
+
+//CHECK-C-MACRO: -D_UNIX03_WITHDRAWN
+//CHECK-C-MACRO: -D_OPEN_DEFAULT
+
+//CHECK-CXX-MACRO: -D_XOPEN_SOURCE=600
+//CHECK-USER-CXX-MACRO-NOT: -D_XOPEN_SOURCE=600
+//CHECK-USER-CXX-MACRO: "-D" "_XOPEN_SOURCE=700"
 
 //CHECK-SHORT-ENUMS: -fshort-enums
 //CHECK-SHORT-ENUMS: -fno-signed-char
 
+//CHECK-ZOS-INCLUDES: clang{{.*}} "-cc1" "-triple" "s390x-none-zos"
+//CHECK-ZOS-INCLUDES-SAME: "-internal-isystem" {{".+/lib/clang/.+/include/zos_wrappers"}} "-internal-isystem" {{".+/lib/clang/.+/include"}}
+
 //CHECK-NOT: -fshort-enums
 //CHECK: -fno-signed-char
Index: clang/test/Driver/zos-comp.c
===
--- /dev/null
+++ clang/test/Driver/zos-comp.c
@@ -0,0 +1,75 @@
+// Tests that the z/OS toolchain adds system includes to its search path.
+
+// RUN: %clang -c -### %s --target=s390x-ibm-zos 2>&1 \
+// RUN:   | FileCheck %s
+
+// CHECK: "-D_UNIX03_WITHDRAWN"
+// CHECK-SAME: "-D_OPEN_DEFAULT"
+// CHECK-SAME: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
+// CHECK-SAME: "-internal-isystem" "[[RESOURCE_DIR]]{{(/|)}}include{{(/|)}}zos_wrappers"
+// CHECK-SAME: "-internal-isystem" "[[RESOURCE_DIR]]{{(/|)}}include"
+// CHECK-SAME: "-internal-isystem" "/usr/include"
+// CHECK-SAME: "-fshort-enums"
+// CHECK-SAME: "-fno-signed-char"
+// CHECK-SAME: "-fno-signed-wchar"
+
+// RUN: %clang -c -### -mzos-sys-include=/ABC/DEF %s 2>&1 \
+// RUN:		--target=s390x-ibm-zos \
+// RUN:   | FileCheck --check-prefixes=CHECK2 %s
+
+// CHECK2: "-D_UNIX03_WITHDRAWN"
+// CHECK2-SAME: "-D_OPEN_DEFAULT"
+// CHECK2-SAME: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
+// CHECK2-SAME: "-internal-isystem" "[[RESOURCE_DIR]]{{(/|)}}include{{(/|)}}zos_wrappers"
+// CHECK2-SAME: "-internal-isystem" "[[RESOURCE_DIR]]{{(/|)}}include"
+// CHECK2-SAME: "-internal-isystem" "/ABC/DEF"
+// CHECK2-NOT: "-internal-isystem" "/usr/include"
+// CHECK2-SAME: "-fshort-enums"
+// CHECK2-SAME: "-fno-signed-char"
+// CHECK2-SAME: "-fno-signed-wchar"
+
+// RUN: %clang -c -### -mzos-sys-include=/ABC/DEF:/ghi/jkl %s 2>&1 \
+// RUN:		--target=s390x-ibm-zos \
+// RUN:   | FileCheck --check-prefixes=CHECK3 %s
+
+// CHECK3: "-D_UNIX03_WITHDRAWN"
+// CHECK3-SAME: 

[PATCH] D152989: Pre-commit test for D151696.

2023-06-27 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe added a comment.

It came to me a better style:

  ATTR(cpu_specific(generic)) void CPU1(void){}
  ATTR(cpu_specific(pentium_pro)) void CPU2(void){}
  ATTR(cpu_specific(pentium_mmx)) void CPU3(void){}
  ATTR(cpu_specific(pentium_ii)) void CPU4(void){}
  ATTR(cpu_specific(pentium_iii)) void CPU5(void){}
  ATTR(cpu_specific(pentium_iii_no_xmm_regs)) void CPU6(void){}
  ...
  
  My purpose here is only to check if the cpu name string is valid for 
cpu_specific. So this also looks good, though it doesn't do the multiversion. 
I'll change into this style if no objections.




Comment at: clang/test/CodeGen/attr-cpuspecific-cpus.c:1-2
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s
+// RUN: %clang_cc1 -triple x86_64-windows-pc -fms-compatibility -emit-llvm -o 
- %s
+

pengfei wrote:
> Is it only to check no compile warning/error? Should we add a `-verify`?
Yes, that's my purpose. Will do.



Comment at: clang/test/CodeGen/attr-cpuspecific-cpus.c:8
+#define ATTR(X) __attribute__((X))
+#endif // _MSC_VER
+

pengfei wrote:
> _MSC_VER or _WIN64?
Good catch.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152989/new/

https://reviews.llvm.org/D152989

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


[PATCH] D152989: Pre-commit test for D151696.

2023-06-27 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe updated this revision to Diff 535213.
FreddyYe marked an inline comment as done.
FreddyYe added a comment.

address comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152989/new/

https://reviews.llvm.org/D152989

Files:
  clang/test/CodeGen/attr-cpuspecific-cpus.c
  clang/test/CodeGen/attr-cpuspecific-small.c
  clang/test/CodeGen/attr-cpuspecific.c
  clang/test/Sema/attr-cpuspecific-small.c

Index: clang/test/Sema/attr-cpuspecific-small.c
===
--- /dev/null
+++ clang/test/Sema/attr-cpuspecific-small.c
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s
+// RUN: %clang_cc1 -triple x86_64-windows-pc -fms-compatibility -emit-llvm -o - %s
+
+#ifdef _WIN64
+#define ATTR(X) __declspec(X)
+#else
+#define ATTR(X) __attribute__((X))
+#endif // _MSC_VER
+
+ATTR(cpu_specific(ivybridge))
+void SingleVersion(void){}
+ATTR(cpu_dispatch(ivybridge))
+void SingleVersion(void);
+
+
Index: clang/test/CodeGen/attr-cpuspecific.c
===
--- clang/test/CodeGen/attr-cpuspecific.c
+++ clang/test/CodeGen/attr-cpuspecific.c
@@ -5,7 +5,7 @@
 #define ATTR(X) __declspec(X)
 #else
 #define ATTR(X) __attribute__((X))
-#endif // _MSC_VER
+#endif // _WIN64
 
 // Each version should have an IFunc and an alias.
 // LINUX: @SingleVersion = weak_odr alias void (), ptr @SingleVersion.ifunc
@@ -43,12 +43,18 @@
 void SingleVersion(void);
 // LINUX: define weak_odr ptr @SingleVersion.resolver()
 // LINUX: call void @__cpu_indicator_init
+// LINUX: %[[FEAT_INIT:.+]] = load i32, ptr getelementptr inbounds ({ i32, i32, i32, [1 x i32] }, ptr @__cpu_model, i32 0, i32 3, i32 0), align 4
+// LINUX: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 1023
+// LINUX: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 1023
 // LINUX: ret ptr @SingleVersion.S
 // LINUX: call void @llvm.trap
 // LINUX: unreachable
 
 // WINDOWS: define weak_odr dso_local void @SingleVersion() comdat
 // WINDOWS: call void @__cpu_indicator_init()
+// WINDOWS: %[[FEAT_INIT:.+]] = load i32, ptr getelementptr inbounds ({ i32, i32, i32, [1 x i32] }, ptr @__cpu_model, i32 0, i32 3, i32 0), align 4
+// WINDOWS: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 1023
+// WINDOWS: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 1023
 // WINDOWS: call void @SingleVersion.S()
 // WINDOWS-NEXT: ret void
 // WINDOWS: call void @llvm.trap
@@ -67,6 +73,9 @@
 void TwoVersions(void);
 // LINUX: define weak_odr ptr @TwoVersions.resolver()
 // LINUX: call void @__cpu_indicator_init
+// LINUX: %[[FEAT_INIT:.+]] = load i32, ptr getelementptr inbounds ({ i32, i32, i32, [1 x i32] }, ptr @__cpu_model, i32 0, i32 3, i32 0), align 4
+// LINUX: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 58836991
+// LINUX: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 58836991
 // LINUX: ret ptr @TwoVersions.Z
 // LINUX: ret ptr @TwoVersions.S
 // LINUX: call void @llvm.trap
@@ -74,6 +83,9 @@
 
 // WINDOWS: define weak_odr dso_local void @TwoVersions() comdat
 // WINDOWS: call void @__cpu_indicator_init()
+// WINDOWS: %[[FEAT_INIT:.+]] = load i32, ptr getelementptr inbounds ({ i32, i32, i32, [1 x i32] }, ptr @__cpu_model, i32 0, i32 3, i32 0), align 4
+// WINDOWS: %[[FEAT_JOIN:.+]] = and i32 %[[FEAT_INIT]], 58836991
+// WINDOWS: %[[FEAT_CHECK:.+]] = icmp eq i32 %[[FEAT_JOIN]], 58836991
 // WINDOWS: call void @TwoVersions.Z()
 // WINDOWS-NEXT: ret void
 // WINDOWS: call void @TwoVersions.S()
Index: clang/test/CodeGen/attr-cpuspecific-small.c
===
--- /dev/null
+++ clang/test/CodeGen/attr-cpuspecific-small.c
@@ -0,0 +1,16 @@
+#ifdef _WIN64
+#define ATTR(X) __declspec(X)
+#else
+#define ATTR(X) __attribute__((X))
+#endif // _MSC_VER
+
+void TwoVersions(void);
+
+ATTR(cpu_dispatch(ivybridge, knl))
+void TwoVersions(void);
+
+ATTR(cpu_specific(ivybridge))
+void TwoVersions(void){}
+
+ATTR(cpu_specific(knl))
+void TwoVersions(void){}
Index: clang/test/CodeGen/attr-cpuspecific-cpus.c
===
--- /dev/null
+++ clang/test/CodeGen/attr-cpuspecific-cpus.c
@@ -0,0 +1,242 @@
+// RUN: %clang_cc1 -verify -triple x86_64-linux-gnu -emit-llvm -o - %s
+// RUN: %clang_cc1 -verify -triple x86_64-windows-pc -fms-compatibility -emit-llvm -o - %s
+
+// expected-no-diagnostics
+
+#ifdef _WIN64
+#define ATTR(X) __declspec(X)
+#else
+#define ATTR(X) __attribute__((X))
+#endif // _WIN64
+
+ATTR(cpu_dispatch(generic, pentium))
+void Version1(void);
+ATTR(cpu_specific(generic))
+void Version1(void){}
+ATTR(cpu_specific(pentium))
+void Version1(void){}
+
+ATTR(cpu_dispatch(generic, pentium_pro))
+void Version2(void);
+ATTR(cpu_specific(generic))
+void Version2(void){}
+ATTR(cpu_specific(pentium_pro))
+void Version2(void){}
+
+ATTR(cpu_dispatch(generic, pentium_mmx))
+void Version3(void);
+ATTR(cpu_specific(generic))
+void 

[PATCH] D152989: Pre-commit test for D151696.

2023-06-27 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added inline comments.



Comment at: clang/test/CodeGen/attr-cpuspecific-cpus.c:1-2
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s
+// RUN: %clang_cc1 -triple x86_64-windows-pc -fms-compatibility -emit-llvm -o 
- %s
+

Is it only to check no compile warning/error? Should we add a `-verify`?



Comment at: clang/test/CodeGen/attr-cpuspecific-cpus.c:8
+#define ATTR(X) __attribute__((X))
+#endif // _MSC_VER
+

_MSC_VER or _WIN64?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152989/new/

https://reviews.llvm.org/D152989

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


[PATCH] D152989: Pre-commit test for D151696.

2023-06-27 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe added a comment.

ping for review.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152989/new/

https://reviews.llvm.org/D152989

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


[PATCH] D153906: [clang] Allow disassembly of multi-module bitcode files

2023-06-27 Thread Matthew Voss via Phabricator via cfe-commits
ormris updated this revision to Diff 535202.
ormris added a comment.

clang-format


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153906/new/

https://reviews.llvm.org/D153906

Files:
  clang/include/clang/CodeGen/CodeGenAction.h
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/test/Frontend/split-lto-ir-support.cpp

Index: clang/test/Frontend/split-lto-ir-support.cpp
===
--- /dev/null
+++ clang/test/Frontend/split-lto-ir-support.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang -O0 -Xclang -mconstructor-aliases -c -flto=thin -Xclang -fsplit-lto-unit -ffunction-sections %s -o %t0.bc
+// RUN: rm -rf %t1.d && mkdir -p %t1.d
+// RUN: %clang -S -emit-llvm %t0.bc -o %t1.d/split-lto-ir-support.ll
+// RUN: %clang -S %t1.d/split-lto-ir-support.0.ll %t1.d/split-lto-ir-support.1.ll
+// RUN: FileCheck c(0);
+}
Index: clang/lib/CodeGen/CodeGenAction.cpp
===
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -1107,26 +1107,59 @@
   return std::move(Result);
 }
 
-std::unique_ptr
+std::vector>
 CodeGenAction::loadModule(MemoryBufferRef MBRef) {
   CompilerInstance  = getCompilerInstance();
   SourceManager  = CI.getSourceManager();
 
+  std::vector> Result;
+
+  if (!llvm::isBitcode((const unsigned char *)MBRef.getBufferStart(),
+   (const unsigned char *)MBRef.getBufferEnd())) {
+llvm::SMDiagnostic Err;
+std::unique_ptr M = parseIR(MBRef, Err, *VMContext);
+if (!M) {
+  // Translate from the diagnostic info to the SourceManager location if
+  // available.
+  // TODO: Unify this with ConvertBackendLocation()
+  SourceLocation Loc;
+  if (Err.getLineNo() > 0) {
+assert(Err.getColumnNo() >= 0);
+Loc = SM.translateFileLineCol(SM.getFileEntryForID(SM.getMainFileID()),
+  Err.getLineNo(), Err.getColumnNo() + 1);
+  }
+
+  // Strip off a leading diagnostic code if there is one.
+  StringRef Msg = Err.getMessage();
+  if (Msg.startswith("error: "))
+Msg = Msg.substr(7);
+
+  unsigned DiagID =
+  CI.getDiagnostics().getCustomDiagID(DiagnosticsEngine::Error, "%0");
+
+  CI.getDiagnostics().Report(Loc, DiagID) << Msg;
+  return {};
+}
+
+Result.push_back(std::move(M));
+return Result;
+  }
+
+  auto DiagErrors = [&](Error E) -> std::vector> {
+unsigned DiagID =
+CI.getDiagnostics().getCustomDiagID(DiagnosticsEngine::Error, "%0");
+handleAllErrors(std::move(E), [&](ErrorInfoBase ) {
+  CI.getDiagnostics().Report(DiagID) << EIB.message();
+});
+return {};
+  };
+
   // For ThinLTO backend invocations, ensure that the context
   // merges types based on ODR identifiers. We also need to read
   // the correct module out of a multi-module bitcode file.
   if (!CI.getCodeGenOpts().ThinLTOIndexFile.empty()) {
 VMContext->enableDebugTypeODRUniquing();
 
-auto DiagErrors = [&](Error E) -> std::unique_ptr {
-  unsigned DiagID =
-  CI.getDiagnostics().getCustomDiagID(DiagnosticsEngine::Error, "%0");
-  handleAllErrors(std::move(E), [&](ErrorInfoBase ) {
-CI.getDiagnostics().Report(DiagID) << EIB.message();
-  });
-  return {};
-};
-
 Expected> BMsOrErr = getBitcodeModuleList(MBRef);
 if (!BMsOrErr)
   return DiagErrors(BMsOrErr.takeError());
@@ -1138,43 +1171,33 @@
 if (!Bm) {
   auto M = std::make_unique("empty", *VMContext);
   M->setTargetTriple(CI.getTargetOpts().Triple);
-  return M;
+  Result.push_back(std::move(M));
+  return Result;
 }
 Expected> MOrErr =
 Bm->parseModule(*VMContext);
 if (!MOrErr)
   return DiagErrors(MOrErr.takeError());
-return std::move(*MOrErr);
+Result.push_back(std::move(MOrErr.get()));
+return Result;
   }
 
   // Load bitcode modules to link with, if we need to.
   if (loadLinkModules(CI))
-return nullptr;
-
-  llvm::SMDiagnostic Err;
-  if (std::unique_ptr M = parseIR(MBRef, Err, *VMContext))
-return M;
-
-  // Translate from the diagnostic info to the SourceManager location if
-  // available.
-  // TODO: Unify this with ConvertBackendLocation()
-  SourceLocation Loc;
-  if (Err.getLineNo() > 0) {
-assert(Err.getColumnNo() >= 0);
-Loc = SM.translateFileLineCol(SM.getFileEntryForID(SM.getMainFileID()),
-  Err.getLineNo(), Err.getColumnNo() + 1);
-  }
+return {};
 
-  // Strip off a leading diagnostic code if there is one.
-  StringRef Msg = Err.getMessage();
-  if (Msg.startswith("error: "))
-Msg = Msg.substr(7);
+  Expected> BMsOrErr = getBitcodeModuleList(MBRef);
+  if (!BMsOrErr)
+return DiagErrors(BMsOrErr.takeError());
 
-  unsigned DiagID =
-  CI.getDiagnostics().getCustomDiagID(DiagnosticsEngine::Error, "%0");
+  for (auto BM : BMsOrErr.get()) {
+  

[PATCH] D151730: [RISCV] Support target attribute for function

2023-06-27 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/lib/Basic/Targets/RISCV.cpp:385
+  StringRef ExtName = Ext.substr(1);
+  if (llvm::RISCVISAInfo::isSupportedExtensionWithVersion(ExtName) ||
+  llvm::RISCVISAInfo::isSupportedExtension(ExtName))

I wonder if we could encapsulate this `if` and the 3 calls into RISCVISAInfo 
into a single function in RISCVISAInfo?

Basically we want to know if an extension that may or may not have a version, 
is a valid extension and if so what is the target feature name for it. We could 
have one function that does all that and returns the target feature name or an 
empty string.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151730/new/

https://reviews.llvm.org/D151730

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


[PATCH] D153931: [Fuchsia] Enable libcxx filesystem on Windows build.

2023-06-27 Thread Haowei Wu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfa872aa221e2: [Fuchsia] Enable libcxx filesystem on Windows 
build. (authored by haowei).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153931/new/

https://reviews.llvm.org/D153931

Files:
  clang/cmake/caches/Fuchsia-stage2.cmake


Index: clang/cmake/caches/Fuchsia-stage2.cmake
===
--- clang/cmake/caches/Fuchsia-stage2.cmake
+++ clang/cmake/caches/Fuchsia-stage2.cmake
@@ -119,7 +119,6 @@
   set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Windows CACHE STRING "")
   set(RUNTIMES_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
   set(RUNTIMES_${target}_LIBCXX_ABI_VERSION 2 CACHE STRING "")
-  set(RUNTIMES_${target}_LIBCXX_ENABLE_FILESYSTEM OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_ABI_LINKER_SCRIPT OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx" CACHE 
STRING "")


Index: clang/cmake/caches/Fuchsia-stage2.cmake
===
--- clang/cmake/caches/Fuchsia-stage2.cmake
+++ clang/cmake/caches/Fuchsia-stage2.cmake
@@ -119,7 +119,6 @@
   set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Windows CACHE STRING "")
   set(RUNTIMES_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
   set(RUNTIMES_${target}_LIBCXX_ABI_VERSION 2 CACHE STRING "")
-  set(RUNTIMES_${target}_LIBCXX_ENABLE_FILESYSTEM OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_ABI_LINKER_SCRIPT OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx" CACHE STRING "")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] fa872aa - [Fuchsia] Enable libcxx filesystem on Windows build.

2023-06-27 Thread Haowei Wu via cfe-commits

Author: Haowei Wu
Date: 2023-06-27T16:57:58-07:00
New Revision: fa872aa221e2c632048517e5580b059ce7fc6900

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

LOG: [Fuchsia] Enable libcxx filesystem on Windows build.

This patch enables the libcxx filesystem when building runtimes for
Windows.

Differential Revision: https://reviews.llvm.org/D153931

Added: 


Modified: 
clang/cmake/caches/Fuchsia-stage2.cmake

Removed: 




diff  --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index 763a79eee9cea..42d7f36df3f93 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -119,7 +119,6 @@ if(WIN32 OR LLVM_WINSYSROOT)
   set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Windows CACHE STRING "")
   set(RUNTIMES_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
   set(RUNTIMES_${target}_LIBCXX_ABI_VERSION 2 CACHE STRING "")
-  set(RUNTIMES_${target}_LIBCXX_ENABLE_FILESYSTEM OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_ABI_LINKER_SCRIPT OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx" CACHE 
STRING "")



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


[PATCH] D153931: [Fuchsia] Enable libcxx filesystem on Windows build.

2023-06-27 Thread Petr Hosek via Phabricator via cfe-commits
phosek accepted this revision.
phosek added a comment.
This revision is now accepted and ready to land.

LGTM


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153931/new/

https://reviews.llvm.org/D153931

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


[PATCH] D153931: [Fuchsia] Enable libcxx filesystem on Windows build.

2023-06-27 Thread Haowei Wu via Phabricator via cfe-commits
haowei updated this revision to Diff 535194.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153931/new/

https://reviews.llvm.org/D153931

Files:
  clang/cmake/caches/Fuchsia-stage2.cmake


Index: clang/cmake/caches/Fuchsia-stage2.cmake
===
--- clang/cmake/caches/Fuchsia-stage2.cmake
+++ clang/cmake/caches/Fuchsia-stage2.cmake
@@ -119,7 +119,6 @@
   set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Windows CACHE STRING "")
   set(RUNTIMES_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
   set(RUNTIMES_${target}_LIBCXX_ABI_VERSION 2 CACHE STRING "")
-  set(RUNTIMES_${target}_LIBCXX_ENABLE_FILESYSTEM OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_ABI_LINKER_SCRIPT OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx" CACHE 
STRING "")


Index: clang/cmake/caches/Fuchsia-stage2.cmake
===
--- clang/cmake/caches/Fuchsia-stage2.cmake
+++ clang/cmake/caches/Fuchsia-stage2.cmake
@@ -119,7 +119,6 @@
   set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Windows CACHE STRING "")
   set(RUNTIMES_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
   set(RUNTIMES_${target}_LIBCXX_ABI_VERSION 2 CACHE STRING "")
-  set(RUNTIMES_${target}_LIBCXX_ENABLE_FILESYSTEM OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_ABI_LINKER_SCRIPT OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx" CACHE STRING "")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153931: [Fuchsia] Enable libcxx filesystem on Windows build.

2023-06-27 Thread Haowei Wu via Phabricator via cfe-commits
haowei created this revision.
haowei added reviewers: phosek, Prabhuk.
Herald added a subscriber: abrachet.
Herald added a project: All.
haowei requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch enables the libcxx filesystem when building runtimes for Windows.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153931

Files:
  clang/cmake/caches/Fuchsia-stage2.cmake


Index: clang/cmake/caches/Fuchsia-stage2.cmake
===
--- clang/cmake/caches/Fuchsia-stage2.cmake
+++ clang/cmake/caches/Fuchsia-stage2.cmake
@@ -119,7 +119,7 @@
   set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Windows CACHE STRING "")
   set(RUNTIMES_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
   set(RUNTIMES_${target}_LIBCXX_ABI_VERSION 2 CACHE STRING "")
-  set(RUNTIMES_${target}_LIBCXX_ENABLE_FILESYSTEM OFF CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXX_ENABLE_FILESYSTEM ON CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_ABI_LINKER_SCRIPT OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx" CACHE 
STRING "")


Index: clang/cmake/caches/Fuchsia-stage2.cmake
===
--- clang/cmake/caches/Fuchsia-stage2.cmake
+++ clang/cmake/caches/Fuchsia-stage2.cmake
@@ -119,7 +119,7 @@
   set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME Windows CACHE STRING "")
   set(RUNTIMES_${target}_CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
   set(RUNTIMES_${target}_LIBCXX_ABI_VERSION 2 CACHE STRING "")
-  set(RUNTIMES_${target}_LIBCXX_ENABLE_FILESYSTEM OFF CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXX_ENABLE_FILESYSTEM ON CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_ABI_LINKER_SCRIPT OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx" CACHE STRING "")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151730: [RISCV] Support target attribute for function

2023-06-27 Thread Piyou Chen via Phabricator via cfe-commits
BeMg updated this revision to Diff 535191.
BeMg marked 8 inline comments as done.
BeMg added a comment.

Add const


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151730/new/

https://reviews.llvm.org/D151730

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Basic/Targets/RISCV.h
  clang/test/CodeGen/RISCV/riscv-func-attr-target.c
  llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
  llvm/test/CodeGen/RISCV/riscv-func-attr-target.ll

Index: llvm/test/CodeGen/RISCV/riscv-func-attr-target.ll
===
--- /dev/null
+++ llvm/test/CodeGen/RISCV/riscv-func-attr-target.ll
@@ -0,0 +1,81 @@
+; RUN: llc -mtriple=riscv64 -mattr=+a,+d,+f,+m -verify-machineinstrs < %s | FileCheck %s
+
+; CHECK: .option push
+; CHECK-NEXT: .optionarch,   +c, +v, +zifencei, +zve32f, +zve32x, +zve64d, +zve64f, +zve64x, +zvl128b, +zvl32b, +zvl64b
+define void @test1() #0 {
+; CHECK-LABEL: test1
+; CHECL: .option pop
+entry:
+  ret void
+}
+
+; CHECK: .option push
+; CHECK-NEXT: .optionarch,   +c, +zifencei
+define void @test2() #1 {
+; CHECK-LABEL: test2
+; CHECL: .option pop
+entry:
+  ret void
+}
+
+; CHECK: .option push
+; CHECK-NEXT: .optionarch,   +c, +zifencei
+define void @test3() #1 {
+; CHECK-LABEL: test3
+; CHECL: .option pop
+entry:
+  ret void
+}
+
+; CHECK: .option push
+; CHECK-NEXT: .optionarch,   +v, +zifencei, +zve32f, +zve32x, +zve64d, +zve64f, +zve64x, +zvl128b, +zvl32b, +zvl64b
+define void @test4() #2 {
+; CHECK-LABEL: test4
+; CHECL: .option pop
+entry:
+  ret void
+}
+
+; CHECK: .option push
+; CHECK-NEXT: .optionarch,   +experimental-zihintntl, +zifencei
+define void @test5() #3 {
+; CHECK-LABEL: test5
+; CHECL: .option pop
+entry:
+  ret void
+}
+
+; CHECK: .option push
+; CHECK-NEXT: .optionarch,   +zifencei
+define void @test7() #4 {
+; CHECK-LABEL: test7
+; CHECL: .option pop
+entry:
+  ret void
+}
+
+; CHECK: .option push
+; CHECK-NEXT: .optionarch,   +c, +zifencei
+define void @test9() #6 {
+; CHECK-LABEL: test9
+; CHECL: .option pop
+entry:
+  ret void
+}
+
+; CHECK: .option push
+; CHECK-NEXT: .optionarch,   +c, +v, +zifencei, +zve32f, +zve32x, +zve64d, +zve64f, +zve64x, +zvl128b, +zvl32b, +zvl64b
+define void @test10() #7 {
+; CHECK-LABEL: test10
+; CHECL: .option pop
+entry:
+  ret void
+}
+
+attributes #0 = { noinline nounwind optnone "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="generic-rv64" "target-features"="+64bit,+a,+c,+d,+f,+m,+relax,+v,+zicsr,+zifencei,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b,-e,-experimental-smaia,-experimental-ssaia,-experimental-zca,-experimental-zcb,-experimental-zcd,-experimental-zcf,-experimental-zcmp,-experimental-zcmt,-experimental-zfa,-experimental-zfbfmin,-experimental-zicond,-experimental-zihintntl,-experimental-ztso,-experimental-zvbb,-experimental-zvbc,-experimental-zvfbfmin,-experimental-zvfbfwma,-experimental-zvfh,-experimental-zvkg,-experimental-zvkn,-experimental-zvkned,-experimental-zvkng,-experimental-zvknha,-experimental-zvknhb,-experimental-zvks,-experimental-zvksed,-experimental-zvksg,-experimental-zvksh,-experimental-zvkt,-h,-save-restore,-svinval,-svnapot,-svpbmt,-xsfvcp,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xventanacondops,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zdinx,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zicbom,-zicbop,-zicboz,-zicntr,-zihintpause,-zihpm,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-zmmul,-zvl1024b,-zvl16384b,-zvl2048b,-zvl256b,-zvl32768b,-zvl4096b,-zvl512b,-zvl65536b,-zvl8192b" }
+attributes #1 = { noinline nounwind optnone "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="generic-rv64" 

[PATCH] D153883: [Clang][OpenMP] Enable use of __kmpc_alloc_shared for VLAs defined in AMD GPU offloaded regions

2023-06-27 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/CodeGen/CGDecl.cpp:1603
+// deallocation call of __kmpc_free_shared() is emitted later.
+if (getLangOpts().OpenMP && getTarget().getTriple().isAMDGCN()) {
+  // Emit call to __kmpc_alloc_shared() instead of the alloca.

doru1004 wrote:
> jhuber6 wrote:
> > ABataev wrote:
> > > OpenMPIsDevice?
> > Does NVPTX handle this already? If not, is there a compelling reason to 
> > exclude NVPTX? Otherwise we should check if we are the OpenMP device.
> Does NVPTX support dynamic allocas?
It does not matter here, it depends on the runtime library implementations. The 
compiler just shall provide proper runtime calls emission, everything else is 
part of the runtime support.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153883/new/

https://reviews.llvm.org/D153883

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


[PATCH] D153909: [AMDGPU] Always pass `-mcpu` to the `lld` linker

2023-06-27 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

In D153909#4454383 , @JonChesterfield 
wrote:

> I thought lld did the right thing if you pass it raw IR, without specifying 
> an arch, but on reflection it might just be silently miscompiling things. The 
> test doesn't seem to involve a specific type of input file, does clang foo.ll 
> -o a.out pass a mcpu flag along?
>
> It's a bit weird that the architecture doesn't seem to be embedded in the IR 
> file (e.g. you have to pass it to llc) but that's out of scope here

it markedly does not work without it. I don't think there's currently 
facilities to define a module-wide architecture, there's only function-level 
metadata.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153909/new/

https://reviews.llvm.org/D153909

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


[PATCH] D150803: [WebAssembly] Support `annotate` clang attributes for marking functions.

2023-06-27 Thread Brendan Dahl via Phabricator via cfe-commits
brendandahl marked an inline comment as not done.
brendandahl added inline comments.



Comment at: llvm/test/MC/WebAssembly/func-attr.s:21
+# CHECK-OBJ-NEXT:  Offset:  0x0
+# CHECK-OBJ-NEXT: Name:func_attr.custom0

sbc100 wrote:
> Should these be `llvm.func_attr.custom0` perhaps?
> 
> I also wonder if its makes sense to preserve all of these.  I worry that it 
> could result in production code that contains these extra sections.   Can we 
> figure out way to drop them by default on only preserve them in the cases we 
> care about?
> 
> How about maybe a linker flag?  Something like 
> `--preserve-attributes=async`.. that emcc could inject?
I'm planning to have binaryen remove all of these by default, since they're 
only needed as hints for binaryen.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150803/new/

https://reviews.llvm.org/D150803

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


[PATCH] D150803: [WebAssembly] Support `annotate` clang attributes for marking functions.

2023-06-27 Thread Brendan Dahl via Phabricator via cfe-commits
brendandahl updated this revision to Diff 535187.
brendandahl added a comment.

Remove annotate arguments. Change name from func_attr to llvm.func_attr.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150803/new/

https://reviews.llvm.org/D150803

Files:
  lld/test/wasm/func-attr-tombstone.s
  lld/test/wasm/func-attr.s
  lld/test/wasm/merge-func-attr-section.s
  lld/wasm/InputChunks.cpp
  lld/wasm/InputFiles.cpp
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm/BinaryFormat/WasmRelocs.def
  llvm/include/llvm/MC/MCExpr.h
  llvm/lib/MC/MCExpr.cpp
  llvm/lib/MC/WasmObjectWriter.cpp
  llvm/lib/Object/WasmObjectFile.cpp
  llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.h
  llvm/test/CodeGen/WebAssembly/func-attr-annotate.ll
  llvm/test/MC/WebAssembly/func-attr.s

Index: llvm/test/MC/WebAssembly/func-attr.s
===
--- /dev/null
+++ llvm/test/MC/WebAssembly/func-attr.s
@@ -0,0 +1,21 @@
+# RUN: llvm-mc -triple=wasm32-unknown-unknown < %s | FileCheck %s
+# Check that it also comiled to object for format.
+# RUN: llvm-mc -triple=wasm32-unknown-unknown -filetype=obj -o - < %s | obj2yaml | FileCheck -check-prefix=CHECK-OBJ %s
+
+foo:
+.globl foo
+.functype foo () -> ()
+end_function
+
+.section.custom_section.llvm.func_attr.custom0,"",@
+.int32  foo@FUNCINDEX
+
+# CHECK:   .section .custom_section.llvm.func_attr.custom0,"",@
+# CHECK-NEXT: .int32  foo@FUNCINDEX
+
+# CHECK-OBJ:- Type:CUSTOM
+# CHECK-OBJ-NEXT: Relocations:
+# CHECK-OBJ-NEXT:- Type:R_WASM_FUNCTION_INDEX_I32
+# CHECK-OBJ-NEXT:  Index:   0
+# CHECK-OBJ-NEXT:  Offset:  0x0
+# CHECK-OBJ-NEXT: Name:llvm.func_attr.custom0
Index: llvm/test/CodeGen/WebAssembly/func-attr-annotate.ll
===
--- /dev/null
+++ llvm/test/CodeGen/WebAssembly/func-attr-annotate.ll
@@ -0,0 +1,31 @@
+; RUN: llc < %s -asm-verbose=false -wasm-keep-registers | FileCheck %s
+
+target triple = "wasm32-unknown-unknown"
+
+@.str = private unnamed_addr constant [8 x i8] c"custom0\00", section "llvm.metadata"
+@.str.1 = private unnamed_addr constant [7 x i8] c"main.c\00", section "llvm.metadata"
+@.str.2 = private unnamed_addr constant [8 x i8] c"custom1\00", section "llvm.metadata"
+@.str.3 = private unnamed_addr constant [8 x i8] c"custom2\00", section "llvm.metadata"
+@llvm.global.annotations = appending global [3 x { ptr, ptr, ptr, i32, ptr }] [{ ptr, ptr, ptr, i32, ptr } { ptr @test0, ptr @.str, ptr @.str.1, i32 4, ptr null }, { ptr, ptr, ptr, i32, ptr } { ptr @test1, ptr @.str, ptr @.str.1, i32 5, ptr null }, { ptr, ptr, ptr, i32, ptr } { ptr @test2, ptr @.str.2, ptr @.str.1, i32 6, ptr null }], section "llvm.metadata"
+
+define void @test0() {
+  ret void
+}
+
+define void @test1() {
+  ret void
+}
+
+define void @test2() {
+  ret void
+}
+
+define void @test3() {
+  ret void
+}
+
+; CHECK:  .section.custom_section.llvm.func_attr.annotate.custom0,"",@
+; CHECK-NEXT: .int32  test0@FUNCINDEX
+; CHECK-NEXT: .int32  test1@FUNCINDEX
+; CHECK:  .section.custom_section.llvm.func_attr.annotate.custom1,"",@
+; CHECK-NEXT: .int32  test2@FUNCINDEX
Index: llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.h
===
--- llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.h
+++ llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.h
@@ -66,6 +66,7 @@
   void emitEndOfAsmFile(Module ) override;
   void EmitProducerInfo(Module );
   void EmitTargetFeatures(Module );
+  void EmitFunctionAttributes(Module );
   void emitSymbolType(const MCSymbolWasm *Sym);
   void emitGlobalVariable(const GlobalVariable *GV) override;
   void emitJumpTableInfo() override;
Index: llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
===
--- llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
@@ -27,6 +27,8 @@
 #include "WebAssemblyTargetMachine.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringMap.h"
+#include "llvm/Analysis/ValueTracking.h"
 #include "llvm/BinaryFormat/Wasm.h"
 #include "llvm/CodeGen/Analysis.h"
 #include "llvm/CodeGen/AsmPrinter.h"
@@ -438,6 +440,7 @@
 
   EmitProducerInfo(M);
   EmitTargetFeatures(M);
+  EmitFunctionAttributes(M);
 }
 
 void WebAssemblyAsmPrinter::EmitProducerInfo(Module ) {
@@ -556,6 +559,49 @@
   OutStreamer->popSection();
 }
 
+void WebAssemblyAsmPrinter::EmitFunctionAttributes(Module ) {
+  auto V = M.getNamedGlobal("llvm.global.annotations");
+  if (!V)
+return;
+
+  // Group all the custom attributes by name.
+  

[PATCH] D153909: [AMDGPU] Always pass `-mcpu` to the `lld` linker

2023-06-27 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield added a comment.

I thought lld did the right thing if you pass it raw IR, without specifying an 
arch, but on reflection it might just be silently miscompiling things. The test 
doesn't seem to involve a specific type of input file, does clang foo.ll -o 
a.out pass a mcpu flag along?

It's a bit weird that the architecture doesn't seem to be embedded in the IR 
file (e.g. you have to pass it to llc) but that's out of scope here


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153909/new/

https://reviews.llvm.org/D153909

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


[PATCH] D153883: [Clang][OpenMP] Enable use of __kmpc_alloc_shared for VLAs defined in AMD GPU offloaded regions

2023-06-27 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
doru1004 added inline comments.



Comment at: clang/lib/CodeGen/CGDecl.cpp:1603
+// deallocation call of __kmpc_free_shared() is emitted later.
+if (getLangOpts().OpenMP && getTarget().getTriple().isAMDGCN()) {
+  // Emit call to __kmpc_alloc_shared() instead of the alloca.

jhuber6 wrote:
> ABataev wrote:
> > OpenMPIsDevice?
> Does NVPTX handle this already? If not, is there a compelling reason to 
> exclude NVPTX? Otherwise we should check if we are the OpenMP device.
Does NVPTX support dynamic allocas?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153883/new/

https://reviews.llvm.org/D153883

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


[PATCH] D153883: [Clang][OpenMP] Enable use of __kmpc_alloc_shared for VLAs defined in AMD GPU offloaded regions

2023-06-27 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
doru1004 updated this revision to Diff 535186.
doru1004 marked 3 inline comments as done.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153883/new/

https://reviews.llvm.org/D153883

Files:
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.h
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/OpenMP/amdgcn_target_device_vla.cpp

Index: clang/test/OpenMP/amdgcn_target_device_vla.cpp
===
--- /dev/null
+++ clang/test/OpenMP/amdgcn_target_device_vla.cpp
@@ -0,0 +1,1258 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature --include-generated-funcs --replace-value-regex "__omp_offloading_[0-9a-z]+_[0-9a-z]+" "reduction_size[.].+[.]" "pl_cond[.].+[.|,]" --prefix-filecheck-ir-name _
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm-bc %s -o %t-ppc-host.bc
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple amdgcn-amd-amdhsa -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s
+// expected-no-diagnostics
+#ifndef HEADER
+#define HEADER
+
+int foo1() {
+  int sum = 0.0;
+  #pragma omp target map(tofrom: sum)
+  {
+int N = 10;
+int A[N];
+
+for (int i = 0; i < N; i++)
+  A[i] = i;
+
+for (int i = 0; i < N; i++)
+  sum += A[i];
+  }
+  return sum;
+}
+
+int foo2() {
+  int sum = 0.0;
+  int M = 12;
+  int result[M];
+  #pragma omp target teams distribute parallel for map(from: result[:M])
+  for (int i = 0; i < M; i++) {
+int N = 10;
+int A[N];
+result[i] = i;
+
+for (int j = 0; j < N; j++)
+  A[j] = j;
+
+for (int j = 0; j < N; j++)
+  result[i] += A[j];
+  }
+
+  for (int i = 0; i < M; i++)
+sum += result[i];
+  return sum;
+}
+
+int foo3() {
+  int sum = 0.0;
+  int M = 12;
+  int result[M];
+  #pragma omp target teams distribute map(from: result[:M])
+  for (int i = 0; i < M; i++) {
+int N = 10;
+int A[N];
+result[i] = i;
+
+#pragma omp parallel for
+for (int j = 0; j < N; j++)
+  A[j] = j;
+
+for (int j = 0; j < N; j++)
+  result[i] += A[j];
+  }
+
+  for (int i = 0; i < M; i++)
+sum += result[i];
+  return sum;
+}
+
+int foo4() {
+  int sum = 0.0;
+  int M = 12;
+  int result[M];
+  int N = 10;
+  #pragma omp target teams distribute map(from: result[:M])
+  for (int i = 0; i < M; i++) {
+int A[N];
+result[i] = i;
+
+#pragma omp parallel for
+for (int j = 0; j < N; j++)
+  A[j] = j;
+
+for (int j = 0; j < N; j++)
+  result[i] += A[j];
+  }
+
+  for (int i = 0; i < M; i++)
+sum += result[i];
+  return sum;
+}
+
+int main() {
+  return foo1() + foo2() + foo3() + foo4();
+}
+
+#endif
+// CHECK-LABEL: define {{[^@]+}}@{{__omp_offloading_[0-9a-z]+_[0-9a-z]+}}__Z4foo1v_l12
+// CHECK-SAME: (ptr noundef nonnull align 4 dereferenceable(4) [[SUM:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[SUM_ADDR:%.*]] = alloca ptr, align 8, addrspace(5)
+// CHECK-NEXT:[[N:%.*]] = alloca i32, align 4, addrspace(5)
+// CHECK-NEXT:[[__VLA_EXPR0:%.*]] = alloca i64, align 8, addrspace(5)
+// CHECK-NEXT:[[I:%.*]] = alloca i32, align 4, addrspace(5)
+// CHECK-NEXT:[[I1:%.*]] = alloca i32, align 4, addrspace(5)
+// CHECK-NEXT:[[SUM_ADDR_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[SUM_ADDR]] to ptr
+// CHECK-NEXT:[[N_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[N]] to ptr
+// CHECK-NEXT:[[__VLA_EXPR0_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[__VLA_EXPR0]] to ptr
+// CHECK-NEXT:[[I_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[I]] to ptr
+// CHECK-NEXT:[[I1_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[I1]] to ptr
+// CHECK-NEXT:store ptr [[SUM]], ptr [[SUM_ADDR_ASCAST]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[SUM_ADDR_ASCAST]], align 8
+// CHECK-NEXT:[[TMP1:%.*]] = call i32 @__kmpc_target_init(ptr addrspacecast (ptr addrspace(1) @[[GLOB1:[0-9]+]] to ptr), i8 1, i1 true)
+// CHECK-NEXT:[[EXEC_USER_CODE:%.*]] = icmp eq i32 [[TMP1]], -1
+// CHECK-NEXT:br i1 [[EXEC_USER_CODE]], label [[USER_CODE_ENTRY:%.*]], label [[WORKER_EXIT:%.*]]
+// CHECK:   user_code.entry:
+// CHECK-NEXT:store i32 10, ptr [[N_ASCAST]], align 4
+// CHECK-NEXT:[[TMP2:%.*]] = load i32, ptr [[N_ASCAST]], align 4
+// CHECK-NEXT:[[TMP3:%.*]] = zext i32 [[TMP2]] to i64
+// CHECK-NEXT:[[TMP4:%.*]] = mul nuw i64 [[TMP3]], 4
+// CHECK-NEXT:[[TMP5:%.*]] = add nuw i64 [[TMP4]], 3
+// CHECK-NEXT:[[TMP6:%.*]] = udiv i64 [[TMP5]], 4
+// CHECK-NEXT:[[TMP7:%.*]] = mul nuw i64 [[TMP6]], 4
+// CHECK-NEXT:[[A:%.*]] = call align 4 ptr @__kmpc_alloc_shared(i64 

[PATCH] D153430: [Clang][Driver] Warn on invalid Arm or AArch64 baremetal target triple

2023-06-27 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

After the patch, LLVM still has a number of `aarch64-arm-none-eabi` usages in 
tests, which is also considered invalid now: https://gcc.godbolt.org/z/z8cY5j68M


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153430/new/

https://reviews.llvm.org/D153430

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


[PATCH] D153745: [clang-format] Fix bugs in annotating r_paren as C-style cast

2023-06-27 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

In D153745#4448113 , @rymiel wrote:

> It appears other operators aren't affected, after D153641 
>  I would have not been surprised if && had 
> become unary :)

`&&` doesn't become unary because of `isUnaryOperator` on line 2432 in the 
annotator.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153745/new/

https://reviews.llvm.org/D153745

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


[PATCH] D153745: [clang-format] Fix bugs in annotating r_paren as C-style cast

2023-06-27 Thread Owen Pan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7a4cdbeafb4c: [clang-format] Fix bugs in annotating r_paren 
as C-style cast (authored by owenpan).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153745/new/

https://reviews.llvm.org/D153745

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


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -554,6 +554,17 @@
   Tokens = annotate("throw (Foo)p;");
   EXPECT_EQ(Tokens.size(), 7u) << Tokens;
   EXPECT_TOKEN(Tokens[3], tok::r_paren, TT_CastRParen);
+
+  Tokens = annotate("#define FOO(x) (((uint64_t)(x) * BAR) / 100)");
+  EXPECT_EQ(Tokens.size(), 21u) << Tokens;
+  EXPECT_TOKEN(Tokens[10], tok::r_paren, TT_CastRParen);
+  EXPECT_TOKEN(Tokens[13], tok::r_paren, TT_Unknown);
+  EXPECT_TOKEN(Tokens[14], tok::star, TT_BinaryOperator);
+
+  Tokens = annotate("return (Foo) & 10;");
+  EXPECT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::r_paren, TT_Unknown);
+  EXPECT_TOKEN(Tokens[4], tok::amp, TT_BinaryOperator);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsDynamicExceptionSpecifier) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2428,12 +2428,16 @@
 // If the next token after the parenthesis is a unary operator, assume
 // that this is cast, unless there are unexpected tokens inside the
 // parenthesis.
-bool NextIsUnary =
-Tok.Next->isUnaryOperator() || Tok.Next->isOneOf(tok::amp, tok::star);
-if (!NextIsUnary || Tok.Next->is(tok::plus) ||
+const bool NextIsAmpOrStar = Tok.Next->isOneOf(tok::amp, tok::star);
+if (!(Tok.Next->isUnaryOperator() || NextIsAmpOrStar) ||
+Tok.Next->is(tok::plus) ||
 !Tok.Next->Next->isOneOf(tok::identifier, tok::numeric_constant)) {
   return false;
 }
+if (NextIsAmpOrStar &&
+(Tok.Next->Next->is(tok::numeric_constant) || Line.InPPDirective)) {
+  return false;
+}
 // Search for unexpected tokens.
 for (FormatToken *Prev = Tok.Previous; Prev != Tok.MatchingParen;
  Prev = Prev->Previous) {


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -554,6 +554,17 @@
   Tokens = annotate("throw (Foo)p;");
   EXPECT_EQ(Tokens.size(), 7u) << Tokens;
   EXPECT_TOKEN(Tokens[3], tok::r_paren, TT_CastRParen);
+
+  Tokens = annotate("#define FOO(x) (((uint64_t)(x) * BAR) / 100)");
+  EXPECT_EQ(Tokens.size(), 21u) << Tokens;
+  EXPECT_TOKEN(Tokens[10], tok::r_paren, TT_CastRParen);
+  EXPECT_TOKEN(Tokens[13], tok::r_paren, TT_Unknown);
+  EXPECT_TOKEN(Tokens[14], tok::star, TT_BinaryOperator);
+
+  Tokens = annotate("return (Foo) & 10;");
+  EXPECT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::r_paren, TT_Unknown);
+  EXPECT_TOKEN(Tokens[4], tok::amp, TT_BinaryOperator);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsDynamicExceptionSpecifier) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2428,12 +2428,16 @@
 // If the next token after the parenthesis is a unary operator, assume
 // that this is cast, unless there are unexpected tokens inside the
 // parenthesis.
-bool NextIsUnary =
-Tok.Next->isUnaryOperator() || Tok.Next->isOneOf(tok::amp, tok::star);
-if (!NextIsUnary || Tok.Next->is(tok::plus) ||
+const bool NextIsAmpOrStar = Tok.Next->isOneOf(tok::amp, tok::star);
+if (!(Tok.Next->isUnaryOperator() || NextIsAmpOrStar) ||
+Tok.Next->is(tok::plus) ||
 !Tok.Next->Next->isOneOf(tok::identifier, tok::numeric_constant)) {
   return false;
 }
+if (NextIsAmpOrStar &&
+(Tok.Next->Next->is(tok::numeric_constant) || Line.InPPDirective)) {
+  return false;
+}
 // Search for unexpected tokens.
 for (FormatToken *Prev = Tok.Previous; Prev != Tok.MatchingParen;
  Prev = Prev->Previous) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 7a4cdbe - [clang-format] Fix bugs in annotating r_paren as C-style cast

2023-06-27 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2023-06-27T16:16:36-07:00
New Revision: 7a4cdbeafb4c2c9fae2ac69d362d22d431404bbe

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

LOG: [clang-format] Fix bugs in annotating r_paren as C-style cast

Don't annotate r_paren as TT_CastRParen if it's followed by an amp/star and
either the line is in a macro definition or a numeric_constant follows the
amp/star.

Fixes #59634.

Differential Revision: https://reviews.llvm.org/D153745

Added: 


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

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 997fe92cabac5..27814b8f46862 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2428,12 +2428,16 @@ class AnnotatingParser {
 // If the next token after the parenthesis is a unary operator, assume
 // that this is cast, unless there are unexpected tokens inside the
 // parenthesis.
-bool NextIsUnary =
-Tok.Next->isUnaryOperator() || Tok.Next->isOneOf(tok::amp, tok::star);
-if (!NextIsUnary || Tok.Next->is(tok::plus) ||
+const bool NextIsAmpOrStar = Tok.Next->isOneOf(tok::amp, tok::star);
+if (!(Tok.Next->isUnaryOperator() || NextIsAmpOrStar) ||
+Tok.Next->is(tok::plus) ||
 !Tok.Next->Next->isOneOf(tok::identifier, tok::numeric_constant)) {
   return false;
 }
+if (NextIsAmpOrStar &&
+(Tok.Next->Next->is(tok::numeric_constant) || Line.InPPDirective)) {
+  return false;
+}
 // Search for unexpected tokens.
 for (FormatToken *Prev = Tok.Previous; Prev != Tok.MatchingParen;
  Prev = Prev->Previous) {

diff  --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 59b1421f99617..b7980bb6d923d 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -554,6 +554,17 @@ TEST_F(TokenAnnotatorTest, UnderstandsCasts) {
   Tokens = annotate("throw (Foo)p;");
   EXPECT_EQ(Tokens.size(), 7u) << Tokens;
   EXPECT_TOKEN(Tokens[3], tok::r_paren, TT_CastRParen);
+
+  Tokens = annotate("#define FOO(x) (((uint64_t)(x) * BAR) / 100)");
+  EXPECT_EQ(Tokens.size(), 21u) << Tokens;
+  EXPECT_TOKEN(Tokens[10], tok::r_paren, TT_CastRParen);
+  EXPECT_TOKEN(Tokens[13], tok::r_paren, TT_Unknown);
+  EXPECT_TOKEN(Tokens[14], tok::star, TT_BinaryOperator);
+
+  Tokens = annotate("return (Foo) & 10;");
+  EXPECT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::r_paren, TT_Unknown);
+  EXPECT_TOKEN(Tokens[4], tok::amp, TT_BinaryOperator);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsDynamicExceptionSpecifier) {



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


[PATCH] D150803: [WebAssembly] Support `annotate` clang attributes for marking functions.

2023-06-27 Thread Sam Clegg via Phabricator via cfe-commits
sbc100 added inline comments.



Comment at: llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp:585-598
+// The fifth field is an optional pointer to the arguments. Append each
+// argument to the name separated by a '.'.
+auto *ArgsVar = 
dyn_cast(CS->getOperand(4)->stripPointerCasts());
+if (ArgsVar) {
+  auto *ArgsStruct = cast(ArgsVar->getInitializer());
+  for (Value *ArgOp : ArgsStruct->operands()) {
+StringRef Arg;

brendandahl wrote:
> This currently supports arguments, but it's somewhat brittle since the 
> arguments aren't escaped. I'm fine with dropping this and only supporting 
> name, but I think this could be useful.
I'd suggest going for the simplified version.. and just ignore any annotations 
that have arguments.   My rational here is that we shouldn't add stuff that we 
don't actually need yet, and also that the code annotation proposal might 
supersede this mechanism in the future.  




Comment at: llvm/test/MC/WebAssembly/func-attr.s:21
+# CHECK-OBJ-NEXT:  Offset:  0x0
+# CHECK-OBJ-NEXT: Name:func_attr.custom0

Should these be `llvm.func_attr.custom0` perhaps?

I also wonder if its makes sense to preserve all of these.  I worry that it 
could result in production code that contains these extra sections.   Can we 
figure out way to drop them by default on only preserve them in the cases we 
care about?

How about maybe a linker flag?  Something like `--preserve-attributes=async`.. 
that emcc could inject?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150803/new/

https://reviews.llvm.org/D150803

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


[PATCH] D150803: [WebAssembly] Support `annotate` clang attributes for marking functions.

2023-06-27 Thread Brendan Dahl via Phabricator via cfe-commits
brendandahl added inline comments.



Comment at: llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp:585-598
+// The fifth field is an optional pointer to the arguments. Append each
+// argument to the name separated by a '.'.
+auto *ArgsVar = 
dyn_cast(CS->getOperand(4)->stripPointerCasts());
+if (ArgsVar) {
+  auto *ArgsStruct = cast(ArgsVar->getInitializer());
+  for (Value *ArgOp : ArgsStruct->operands()) {
+StringRef Arg;

This currently supports arguments, but it's somewhat brittle since the 
arguments aren't escaped. I'm fine with dropping this and only supporting name, 
but I think this could be useful.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150803/new/

https://reviews.llvm.org/D150803

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


[PATCH] D153926: [NFC] Initialize class member pointers to nullptr.

2023-06-27 Thread Sindhu Chittireddy via Phabricator via cfe-commits
schittir created this revision.
schittir added reviewers: erichkeane, aaron.ballman, tahonermann, shafik.
Herald added subscribers: cfe-commits, steakhal, martong.
Herald added a reviewer: NoQ.
Herald added projects: All, clang, clang-format.
Herald added reviewers: rymiel, HazardyKnusperkeks, owenpan, MyDeveloperDay.
schittir requested review of this revision.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153926

Files:
  clang/include/clang/AST/RawCommentList.h
  clang/include/clang/AST/Redeclarable.h
  clang/include/clang/CodeGen/CodeGenAction.h
  clang/include/clang/Sema/HLSLExternalSemaSource.h
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Serialization/ModuleFile.h
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Format/SortJavaScriptImports.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
  clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp

Index: clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedLambdaCapturesChecker.cpp
@@ -25,7 +25,7 @@
 private:
   BugType Bug{this, "Lambda capture of uncounted variable",
   "WebKit coding guidelines"};
-  mutable BugReporter *BR;
+  mutable BugReporter *BR = nullptr;
 
 public:
   void checkASTDecl(const TranslationUnitDecl *TUD, AnalysisManager ,
Index: clang/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
+++ clang/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
@@ -754,7 +754,7 @@
 
 ObjCDeallocChecker::ObjCDeallocChecker()
 : NSObjectII(nullptr), SenTestCaseII(nullptr), XCTestCaseII(nullptr),
-  CIFilterII(nullptr) {
+  Block_releaseII(nullptr), CIFilterII(nullptr) {
 
   MissingReleaseBugType.reset(
   new BugType(this, "Missing ivar release (leak)",
Index: clang/lib/Serialization/ASTReaderDecl.cpp
===
--- clang/lib/Serialization/ASTReaderDecl.cpp
+++ clang/lib/Serialization/ASTReaderDecl.cpp
@@ -478,7 +478,7 @@
 /// been merged into the same redeclaration chain.
 template
 class MergedRedeclIterator {
-  DeclT *Start;
+  DeclT *Start = nullptr;
   DeclT *Canonical = nullptr;
   DeclT *Current = nullptr;
 
Index: clang/lib/Format/SortJavaScriptImports.cpp
===
--- clang/lib/Format/SortJavaScriptImports.cpp
+++ clang/lib/Format/SortJavaScriptImports.cpp
@@ -217,8 +217,8 @@
   }
 
 private:
-  FormatToken *Current;
-  FormatToken *LineEnd;
+  FormatToken *Current = nullptr;
+  FormatToken *LineEnd = nullptr;
 
   FormatToken invalidToken;
 
Index: clang/lib/CodeGen/CodeGenFunction.h
===
--- clang/lib/CodeGen/CodeGenFunction.h
+++ clang/lib/CodeGen/CodeGenFunction.h
@@ -318,10 +318,10 @@
 
   /// CurFuncDecl - Holds the Decl for the current outermost
   /// non-closure context.
-  const Decl *CurFuncDecl;
+  const Decl *CurFuncDecl = nullptr;
   /// CurCodeDecl - This is the inner-most code context, which includes blocks.
-  const Decl *CurCodeDecl;
-  const CGFunctionInfo *CurFnInfo;
+  const Decl *CurCodeDecl = nullptr;
+  const CGFunctionInfo *CurFnInfo = nullptr;
   QualType FnRetTy;
   llvm::Function *CurFn = nullptr;
 
@@ -748,11 +748,11 @@
 
 /// An i1 variable indicating whether or not the @finally is
 /// running for an exception.
-llvm::AllocaInst *ForEHVar;
+llvm::AllocaInst *ForEHVar = nullptr;
 
 /// An i8* variable into which the exception pointer to rethrow
 /// has been saved.
-llvm::AllocaInst *SavedExnVar;
+llvm::AllocaInst *SavedExnVar = nullptr;
 
   public:
 void enter(CodeGenFunction , const Stmt *Finally,
Index: clang/include/clang/Serialization/ModuleFile.h
===
--- clang/include/clang/Serialization/ModuleFile.h
+++ clang/include/clang/Serialization/ModuleFile.h
@@ -196,7 +196,7 @@
 
   /// The memory buffer that stores the data associated with
   /// this AST file, owned by the InMemoryModuleCache.
-  llvm::MemoryBuffer *Buffer;
+  llvm::MemoryBuffer *Buffer = nullptr;
 
   /// The size of this file, in bits.
   uint64_t SizeInBits = 0;
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -937,7 +937,7 @@
   class DelayedDiagnostics;
 
   class DelayedDiagnosticsState {
-sema::DelayedDiagnosticPool *SavedPool;
+sema::DelayedDiagnosticPool *SavedPool = nullptr;
 friend class Sema::DelayedDiagnostics;
   };
   typedef 

[PATCH] D150803: Add a new `wasm_custom` clang attribute for marking functions.

2023-06-27 Thread Sam Clegg via Phabricator via cfe-commits
sbc100 added a comment.

In D150803#4454164 , @brendandahl 
wrote:

> In D150803#4440802 , @aaron.ballman 
> wrote:
>
>> Marking as requested changes so it's clear there's more worth discussing, so 
>> we don't accidentally land this.
>
> I've switched to using `annotate` now. Let me know if there's anything else.

I guess the CL title and description now need updating?   Nice to see we no 
longer need any clang changes here!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150803/new/

https://reviews.llvm.org/D150803

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


[PATCH] D150803: Add a new `wasm_custom` clang attribute for marking functions.

2023-06-27 Thread Brendan Dahl via Phabricator via cfe-commits
brendandahl added a comment.

In D150803#4440802 , @aaron.ballman 
wrote:

> Marking as requested changes so it's clear there's more worth discussing, so 
> we don't accidentally land this.

I've switched to using `annotate` now. Let me know if there's anything else.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150803/new/

https://reviews.llvm.org/D150803

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


[PATCH] D153924: Allowing exception handling in OpenMP target regions when offloading to AMDGCN or NVPTX targets

2023-06-27 Thread Anton Rydahl via Phabricator via cfe-commits
AntonRydahl created this revision.
AntonRydahl added reviewers: jdoerfert, jhuber6.
Herald added subscribers: sunshaoce, mattd, gchakrabarti, asavonic, guansong, 
tpr, yaxunl, rampitec.
Herald added a project: All.
AntonRydahl requested review of this revision.
Herald added subscribers: cfe-commits, jplehr, sstefan1.
Herald added a project: clang.

The motivation for this patch is that many code bases use exception handling. 
As GPUs are not expected to support exception handling in the near future, we 
can experiment with compiling the code for GPU targets anyway. This will 
allow us to run the code, as long as no exception is thrown.

The overall idea is very simple:

- If a throw expression is compiled to AMDGCN or NVPTX, it is replaced with a 
trap during code generation.
- If a try/catch statement is compiled to AMDGCN or AMDHSA, we ganerate code 
for the try statement as if it were a basic block.

While I have almost not modified any code, I have made tests that verify that 
we still do not allow compilation of exceptions, unless the user explicitly 
enables `-fcxx-exceptions` or `-fexceptions`.

Please let me know what you think of this patch and if the warnings could be 
improved.

Example
---

With this patch, the compilation of the following example

  C++
  #include 
  #pragma omp declare target
  int gaussian_sum(int a,int b){
if ((a + b) % 2 == 0) {throw -1;};
return (a+b) * ((a+b)/2);
  }
  #pragma omp end declare target
  
  int main(void) {
int gauss = 0;
#pragma omp target map(from:gauss)
{
try {
gauss = gaussian_sum(1,100);
}
catch (int e){
gauss = e;
}
}
std::cout << "GaussianSum(1,100)="&1 | FileCheck %s -v --check-prefix=TEST1
+// TEST1: {{Target 'amdgcn-amd-amdhsa' does not support exception handling. To allow code generation for 'amdgcn-amd-amdhsa', 'try' statements are treated as basic blocks}}
+// TEST1: {{Target 'amdgcn-amd-amdhsa' does not support exception handling. To allow code generation for 'amdgcn-amd-amdhsa', 'throw' expressions will be replaced by traps}}
+
+// RUN: %clangxx -O0 -Wall -std=c++17 -fopenmp \
+// RUN: -fopenmp-targets=nvptx64-nvidia-cuda --offload-arch=sm_70 \
+// RUN: -fopenmp-offload-mandatory -Xopenmp-target -fexceptions \
+// RUN: -Xopenmp-target -fcxx-exceptions -emit-llvm -S %s -o - 2>&1 | FileCheck %s -v --check-prefix=TEST2
+// TEST2: {{Target 'nvptx64-nvidia-cuda' does not support exception handling. To allow code generation for 'nvptx64-nvidia-cuda', 'try' statements are treated as basic blocks}}
+// TEST2: {{Target 'nvptx64-nvidia-cuda' does not support exception handling. To allow code generation for 'nvptx64-nvidia-cuda', 'throw' expressions will be replaced by traps}}
+
+// Then, we test that exception handling is still allowed on code offloaded to a CPU in TEST3
+// RUN: %clangxx -O0 -Wall -std=c++17 -fopenmp \
+// RUN: -fopenmp-targets=x86_64-pc-linux-gnu 

[PATCH] D145302: [clangd] Add library for clangd main function

2023-06-27 Thread Ivan Murashko via Phabricator via cfe-commits
ivanmurashko updated this revision to Diff 535144.
ivanmurashko added a comment.

small fixes


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145302/new/

https://reviews.llvm.org/D145302

Files:
  clang-tools-extra/clangd/tool/CMakeLists.txt
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang-tools-extra/clangd/tool/ClangdMain.h
  clang-tools-extra/clangd/tool/ClangdToolMain.cpp

Index: clang-tools-extra/clangd/tool/ClangdToolMain.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/tool/ClangdToolMain.cpp
@@ -0,0 +1,13 @@
+//===--- ClangdToolMain.cpp - clangd main function ===//
+//
+// 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 "ClangdMain.h"
+
+int main(int argc, char **argv) {
+  return clang::clangd::clangdMain(argc, argv);
+}
Index: clang-tools-extra/clangd/tool/ClangdMain.h
===
--- /dev/null
+++ clang-tools-extra/clangd/tool/ClangdMain.h
@@ -0,0 +1,19 @@
+//===--- ClangdMain.h - clangd main function ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_TOOL_CLANGDMAIN_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_TOOL_CLANGDMAIN_H
+
+namespace clang {
+namespace clangd {
+// clangd main function (clangd server loop)
+int clangdMain(int argc, char *argv[]);
+} // namespace clangd
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_TOOL_CLANGDMAIN_H
Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -6,6 +6,7 @@
 //
 //===--===//
 
+#include "ClangdMain.h"
 #include "ClangdLSPServer.h"
 #include "CodeComplete.h"
 #include "Compiler.h"
@@ -710,8 +711,6 @@
   }
 };
 } // namespace
-} // namespace clangd
-} // namespace clang
 
 enum class ErrorResultCode : int {
   NoShutdownRequest = 1,
@@ -719,10 +718,7 @@
   CheckFailed = 3
 };
 
-int main(int argc, char *argv[]) {
-  using namespace clang;
-  using namespace clang::clangd;
-
+int clangdMain(int argc, char *argv[]) {
   llvm::InitializeAllTargetInfos();
   llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
   llvm::sys::AddSignalHandler(
@@ -1041,3 +1037,6 @@
 
   return ExitCode;
 }
+
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/clangd/tool/CMakeLists.txt
===
--- clang-tools-extra/clangd/tool/CMakeLists.txt
+++ clang-tools-extra/clangd/tool/CMakeLists.txt
@@ -1,9 +1,16 @@
-add_clang_tool(clangd
+# Needed by LLVM's CMake checks because this file defines multiple targets.
+set(LLVM_OPTIONAL_SOURCES ClangdToolMain.cpp)
+
+add_clang_library(clangdMain
   ClangdMain.cpp
   Check.cpp
   $
   )
 
+add_clang_tool(clangd
+  ClangdToolMain.cpp
+  )
+
 set(LLVM_LINK_COMPONENTS
   support
   )
@@ -13,7 +20,7 @@
   list(APPEND CLANGD_XPC_LIBS "clangdXpcJsonConversions" "clangdXpcTransport")
 endif()
 
-clang_target_link_libraries(clangd
+clang_target_link_libraries(clangdMain
   PRIVATE
   clangAST
   clangBasic
@@ -25,14 +32,14 @@
   clangToolingCore
   clangToolingRefactoring
   clangToolingSyntax
-  )
-
-target_link_libraries(clangd
-  PRIVATE
   clangTidy
-
   clangDaemon
   clangdRemoteIndex
   clangdSupport
   ${CLANGD_XPC_LIBS}
   )
+
+clang_target_link_libraries(clangd
+  PRIVATE
+  clangdMain
+  )
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153857: [clang] Fix new-expression with elaborated-type-specifier

2023-06-27 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

MSVC rejects the first but accepts the second which I think is wrong but worth 
testing:

  alignof(struct B {});
  sizeof(struct B{});

https://godbolt.org/z/153jYqaPM




Comment at: clang/include/clang/Parse/Parser.h:2359
 case DeclSpecContext::DSC_template_param:
+case DeclSpecContext::DSC_new:
   return ImplicitTypenameContext::Yes;

Should this be below since `DeclaratorContext::CXXNew` was grouped w/ 
`DSC_normal` normal before?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153857/new/

https://reviews.llvm.org/D153857

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


[PATCH] D145302: [clangd] Add library for clangd main function

2023-06-27 Thread Ivan Murashko via Phabricator via cfe-commits
ivanmurashko updated this revision to Diff 535138.
ivanmurashko added a comment.

Rebase + apply suggestions from @kadircet


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145302/new/

https://reviews.llvm.org/D145302

Files:
  clang-tools-extra/clangd/tool/CMakeLists.txt
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang-tools-extra/clangd/tool/ClangdMain.h
  clang-tools-extra/clangd/tool/ClangdToolMain.cpp

Index: clang-tools-extra/clangd/tool/ClangdToolMain.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/tool/ClangdToolMain.cpp
@@ -0,0 +1,13 @@
+//===--- ClangdToolMain.cpp - clangd main function ===//
+//
+// 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 "ClangdMain.h"
+
+int main(int argc, char **argv) {
+  return clang::clangd::clangdMain(argc, argv);
+}
Index: clang-tools-extra/clangd/tool/ClangdMain.h
===
--- /dev/null
+++ clang-tools-extra/clangd/tool/ClangdMain.h
@@ -0,0 +1,19 @@
+//===--- ClangdMain.h - clangd main function ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_TOOL_CLANGDMAIN_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_TOOL_CLANGDMAIN_H
+
+namespace clang {
+namespace clangd {
+// clangd main function (clangd server loop)
+int clangdMain(int argc, char *argv[]);
+} // namespace clangd
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_TOOL_CLANGDMAIN_H
Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -6,6 +6,7 @@
 //
 //===--===//
 
+#include "ClangdMain.h"
 #include "ClangdLSPServer.h"
 #include "CodeComplete.h"
 #include "Compiler.h"
@@ -710,8 +711,6 @@
   }
 };
 } // namespace
-} // namespace clangd
-} // namespace clang
 
 enum class ErrorResultCode : int {
   NoShutdownRequest = 1,
@@ -719,10 +718,7 @@
   CheckFailed = 3
 };
 
-int main(int argc, char *argv[]) {
-  using namespace clang;
-  using namespace clang::clangd;
-
+int clangdMain(int argc, char *argv[]) {
   llvm::InitializeAllTargetInfos();
   llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
   llvm::sys::AddSignalHandler(
@@ -1041,3 +1037,6 @@
 
   return ExitCode;
 }
+
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/clangd/tool/CMakeLists.txt
===
--- clang-tools-extra/clangd/tool/CMakeLists.txt
+++ clang-tools-extra/clangd/tool/CMakeLists.txt
@@ -1,6 +1,13 @@
-add_clang_tool(clangd
+# Needed by LLVM's CMake checks because this file defines multiple targets.
+set(LLVM_OPTIONAL_SOURCES ClangdToolMain.cpp)
+
+add_clang_library(clangdMain
   ClangdMain.cpp
   Check.cpp
+  )
+
+add_clang_tool(clangd
+  ClangdToolMain.cpp
   $
   )
 
@@ -13,7 +20,7 @@
   list(APPEND CLANGD_XPC_LIBS "clangdXpcJsonConversions" "clangdXpcTransport")
 endif()
 
-clang_target_link_libraries(clangd
+clang_target_link_libraries(clangdMain
   PRIVATE
   clangAST
   clangBasic
@@ -25,14 +32,14 @@
   clangToolingCore
   clangToolingRefactoring
   clangToolingSyntax
-  )
-
-target_link_libraries(clangd
-  PRIVATE
   clangTidy
-
   clangDaemon
   clangdRemoteIndex
   clangdSupport
   ${CLANGD_XPC_LIBS}
   )
+
+clang_target_link_libraries(clangd
+  PRIVATE
+  clangdMain
+  )
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D139837: [Clang] Implements CTAD for aggregates P1816R0 and P2082R1

2023-06-27 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen updated this revision to Diff 535132.
ychen marked 3 inline comments as done.
ychen added a comment.

- address comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139837/new/

https://reviews.llvm.org/D139837

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/DeclBase.h
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Sema/TemplateDeduction.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Decl.cpp
  clang/lib/AST/DeclCXX.cpp
  clang/lib/Frontend/FrontendActions.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/test/SemaTemplate/aggregate-deduction-candidate.cpp
  clang/unittests/AST/ASTImporterTest.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1246,7 +1246,7 @@
 
   Class template argument deduction for aggregates
   https://wg21.link/p1816r0;>P1816R0
-  No
+  Clang 17
 

 https://wg21.link/p2082r1;>P2082R1
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -7372,7 +7372,7 @@
   cxxDeductionGuideDecl(hasParameter(0, hasType(asString("A");
   auto *ToD = Import(FromD, Lang_CXX17);
   ASSERT_TRUE(ToD);
-  EXPECT_TRUE(ToD->isCopyDeductionCandidate());
+  EXPECT_EQ(ToD->getDeductionCandidateKind(), DeductionCandidate::Copy);
   // Check that the deduced class template is also imported.
   EXPECT_TRUE(findFromTU(FromD)->Importer->GetAlreadyImportedOrNull(
   FromD->getDeducedTemplate()));
Index: clang/test/SemaTemplate/aggregate-deduction-candidate.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/aggregate-deduction-candidate.cpp
@@ -0,0 +1,364 @@
+// RUN: %clang_cc1 -std=c++20 -verify -ast-dump -ast-dump-decl-types -ast-dump-filter "deduction guide" %s | FileCheck %s --strict-whitespace
+
+namespace Basic {
+  template struct A {
+T x;
+T y;
+  };
+
+  A a1 = {3.0, 4.0};
+  A a2 = {.x = 3.0, .y = 4.0};
+
+  A a3(3.0, 4.0);
+
+  // CHECK-LABEL: Dumping Basic:::
+  // CHECK: FunctionTemplateDecl {{.*}} implicit 
+  // CHECK: |-TemplateTypeParmDecl {{.*}} referenced class depth 0 index 0 T
+  // CHECK: |-CXXDeductionGuideDecl {{.*}} implicit  'auto (T, T) -> A'
+  // CHECK: | |-ParmVarDecl {{.*}} 'T'
+  // CHECK: | `-ParmVarDecl {{.*}} 'T'
+  // CHECK: `-CXXDeductionGuideDecl {{.*}} implicit used  'auto (double, double) -> Basic::A'
+  // CHECK:   |-TemplateArgument type 'double'
+  // CHECK:   | `-BuiltinType {{.*}} 'double'
+  // CHECK:   |-ParmVarDecl {{.*}} 'double':'double'
+  // CHECK:   `-ParmVarDecl {{.*}} 'double':'double'
+  // CHECK: FunctionProtoType {{.*}} 'auto (T, T) -> A' dependent trailing_return cdecl
+  // CHECK: |-InjectedClassNameType {{.*}} 'A' dependent
+  // CHECK: | `-CXXRecord {{.*}} 'A'
+  // CHECK: |-TemplateTypeParmType {{.*}} 'T' dependent depth 0 index 0
+  // CHECK: | `-TemplateTypeParm {{.*}} 'T'
+  // CHECK: `-TemplateTypeParmType {{.*}} 'T' dependent depth 0 index 0
+  // CHECK:   `-TemplateTypeParm {{.*}} 'T'
+
+  template  struct S { // expected-note 2 {{candidate}}
+T x;
+T y;
+  };
+
+  template  struct C { // expected-note 10 {{candidate}}
+S s;
+T t;
+  };
+
+  template  struct D { // expected-note 6 {{candidate}}
+S s;
+T t;
+  };
+
+  C c1 = {1, 2}; // expected-error {{no viable}}
+  C c2 = {1, 2, 3}; // expected-error {{no viable}}
+  C c3 = {{1u, 2u}, 3};
+
+  C c4(1, 2);// expected-error {{no viable}}
+  C c5(1, 2, 3); // expected-error {{no viable}}
+  C c6({1u, 2u}, 3);
+
+  D d1 = {1, 2}; // expected-error {{no viable}}
+  D d2 = {1, 2, 3};
+
+  D d3(1, 2); // expected-error {{no viable}}
+  // CTAD succeed but brace elision is not allowed for parenthesized aggregate init. 
+  D d4(1, 2, 3); // expected-error {{no viable}}
+
+  // CHECK-LABEL: Dumping Basic:::
+  // CHECK: FunctionTemplateDecl {{.*}} implicit 
+  // CHECK: |-TemplateTypeParmDecl {{.*}} referenced typename depth 0 index 0 T
+  // CHECK: |-CXXDeductionGuideDecl {{.*}} implicit  'auto (S, T) -> C'
+  // CHECK: | |-ParmVarDecl {{.*}} 'S':'S'
+  // CHECK: | `-ParmVarDecl {{.*}} 'T'
+  // CHECK: `-CXXDeductionGuideDecl {{.*}} implicit used  'auto (S, int) -> Basic::C'
+  // CHECK:   |-TemplateArgument type 'int'
+  // CHECK:   | `-BuiltinType {{.*}} 'int'
+  // CHECK:   |-ParmVarDecl {{.*}} 'S':'Basic::S'
+  // CHECK:   

[PATCH] D153857: [clang] Fix new-expression with elaborated-type-specifier

2023-06-27 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

What about

  template 
  struct A { };
  
void foo() {
  new struct A {};
}

I think this should be allowed, right?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153857/new/

https://reviews.llvm.org/D153857

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


[PATCH] D150803: Add a new `wasm_custom` clang attribute for marking functions.

2023-06-27 Thread Brendan Dahl via Phabricator via cfe-commits
brendandahl updated this revision to Diff 535126.
brendandahl added a comment.

Use the annotate attribute to generate custom sections.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150803/new/

https://reviews.llvm.org/D150803

Files:
  lld/test/wasm/func-attr-tombstone.s
  lld/test/wasm/func-attr.s
  lld/test/wasm/merge-func-attr-section.s
  lld/wasm/InputChunks.cpp
  lld/wasm/InputFiles.cpp
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm/BinaryFormat/WasmRelocs.def
  llvm/include/llvm/MC/MCExpr.h
  llvm/lib/MC/MCExpr.cpp
  llvm/lib/MC/WasmObjectWriter.cpp
  llvm/lib/Object/WasmObjectFile.cpp
  llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
  llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.h
  llvm/test/CodeGen/WebAssembly/func-attr-annotate.ll
  llvm/test/MC/WebAssembly/func-attr.s

Index: llvm/test/MC/WebAssembly/func-attr.s
===
--- /dev/null
+++ llvm/test/MC/WebAssembly/func-attr.s
@@ -0,0 +1,21 @@
+# RUN: llvm-mc -triple=wasm32-unknown-unknown < %s | FileCheck %s
+# Check that it also comiled to object for format.
+# RUN: llvm-mc -triple=wasm32-unknown-unknown -filetype=obj -o - < %s | obj2yaml | FileCheck -check-prefix=CHECK-OBJ %s
+
+foo:
+.globl foo
+.functype foo () -> ()
+end_function
+
+.section.custom_section.func_attr.custom0,"",@
+.int32  foo@FUNCINDEX
+
+# CHECK:   .section .custom_section.func_attr.custom0,"",@
+# CHECK-NEXT: .int32  foo@FUNCINDEX
+
+# CHECK-OBJ:- Type:CUSTOM
+# CHECK-OBJ-NEXT: Relocations:
+# CHECK-OBJ-NEXT:- Type:R_WASM_FUNCTION_INDEX_I32
+# CHECK-OBJ-NEXT:  Index:   0
+# CHECK-OBJ-NEXT:  Offset:  0x0
+# CHECK-OBJ-NEXT: Name:func_attr.custom0
Index: llvm/test/CodeGen/WebAssembly/func-attr-annotate.ll
===
--- /dev/null
+++ llvm/test/CodeGen/WebAssembly/func-attr-annotate.ll
@@ -0,0 +1,36 @@
+; RUN: llc < %s -asm-verbose=false -wasm-keep-registers | FileCheck %s
+
+target triple = "wasm32-unknown-unknown"
+
+@.str = private unnamed_addr constant [8 x i8] c"custom0\00", section "llvm.metadata"
+@.str.1 = private unnamed_addr constant [7 x i8] c"main.c\00", section "llvm.metadata"
+@.str.2 = private unnamed_addr constant [8 x i8] c"custom1\00", section "llvm.metadata"
+@.str.3 = private unnamed_addr constant [8 x i8] c"custom2\00", section "llvm.metadata"
+@.str.4 = private unnamed_addr constant [12 x i8] c"custom2arg0\00", align 1
+@.str.5 = private unnamed_addr constant [12 x i8] c"custom2arg1\00", align 1
+@.args = private unnamed_addr constant { ptr, ptr } { ptr @.str.4, ptr @.str.5 }, section "llvm.metadata"
+@llvm.global.annotations = appending global [4 x { ptr, ptr, ptr, i32, ptr }] [{ ptr, ptr, ptr, i32, ptr } { ptr @test0, ptr @.str, ptr @.str.1, i32 4, ptr null }, { ptr, ptr, ptr, i32, ptr } { ptr @test1, ptr @.str, ptr @.str.1, i32 5, ptr null }, { ptr, ptr, ptr, i32, ptr } { ptr @test2, ptr @.str.2, ptr @.str.1, i32 6, ptr null }, { ptr, ptr, ptr, i32, ptr } { ptr @test3, ptr @.str.3, ptr @.str.1, i32 7, ptr @.args }], section "llvm.metadata"
+
+define void @test0() {
+  ret void
+}
+
+define void @test1() {
+  ret void
+}
+
+define void @test2() {
+  ret void
+}
+
+define void @test3() {
+  ret void
+}
+
+; CHECK:  .section.custom_section.func_attr.annotate.custom2.custom2arg0.custom2arg1,"",@
+; CHECK-NEXT: .int32  test3@FUNCINDEX
+; CHECK:  .section.custom_section.func_attr.annotate.custom0,"",@
+; CHECK-NEXT: .int32  test0@FUNCINDEX
+; CHECK-NEXT: .int32  test1@FUNCINDEX
+; CHECK:  .section.custom_section.func_attr.annotate.custom1,"",@
+; CHECK-NEXT: .int32  test2@FUNCINDEX
Index: llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.h
===
--- llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.h
+++ llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.h
@@ -66,6 +66,7 @@
   void emitEndOfAsmFile(Module ) override;
   void EmitProducerInfo(Module );
   void EmitTargetFeatures(Module );
+  void EmitFunctionAttributes(Module );
   void emitSymbolType(const MCSymbolWasm *Sym);
   void emitGlobalVariable(const GlobalVariable *GV) override;
   void emitJumpTableInfo() override;
Index: llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
===
--- llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
@@ -27,6 +27,8 @@
 #include "WebAssemblyTargetMachine.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringMap.h"
+#include "llvm/Analysis/ValueTracking.h"
 #include "llvm/BinaryFormat/Wasm.h"
 #include "llvm/CodeGen/Analysis.h"
 

[PATCH] D151820: [clang][WebAssembly] Fix __BIGGEST_ALIGNMENT__ under emscripten

2023-06-27 Thread Sam Clegg via Phabricator via cfe-commits
sbc100 abandoned this revision.
sbc100 added a comment.

Yes, on further investigation is seems that there is precedent for having 
`alignof(max_align_t)` and `__BIGGEST_ALIGNMENT__` be different.  See 
https://github.com/emscripten-core/emscripten/pull/19728


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151820/new/

https://reviews.llvm.org/D151820

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


[PATCH] D151820: [clang][WebAssembly] Fix __BIGGEST_ALIGNMENT__ under emscripten

2023-06-27 Thread Derek Schuff via Phabricator via cfe-commits
dschuff added a comment.

After local discussion, I guess we decided to leave this as-is?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151820/new/

https://reviews.llvm.org/D151820

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


[PATCH] D153430: [Clang][Driver] Warn on invalid Arm or AArch64 baremetal target triple

2023-06-27 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

Thank you for implementing this warning. Side note: it would be better to (a) 
fix the tests separately from (b) implementing the warning and (c) adding tests 
to demonstrate the warning.
This way the patch is more focused.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153430/new/

https://reviews.llvm.org/D153430

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


[PATCH] D153536: [Clang] Implement P2169 A nice placeholder with no name

2023-06-27 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin marked 14 inline comments as done.
cor3ntin added inline comments.



Comment at: clang/include/clang/AST/DeclBase.h:340-342
+  /// Whether this declaration denotes a placeholder that can be
+  /// redefined in the same scope.
+  unsigned IsPlaceholder : 1;

aaron.ballman wrote:
> cor3ntin wrote:
> > aaron.ballman wrote:
> > > This seems a bit heavy to put on every `Decl`, it only matters for 
> > > declarations with names, right? Should this be on `NamedDecl` instead? 
> > > And should it be using terminology like "name independent"?
> > > 
> > > Actually, do we need this bit at all? Would it work for `NamedDecl` to 
> > > have a function that returns whether the declaration name is `_` or not? 
> > > Oh, I suppose we can't get away with that because `void _(int x);` does 
> > > not introduce a placeholder identifier but a regular one, right?
> > I think you made me realize we can probably compute that completely without 
> > using bits. Oups.
> > It would certainly simplify things. I'll investigate!
> Thank you!
Removed!



Comment at: clang/test/SemaCXX/cxx2c-placeholder-vars.cpp:31
+   // expected-note 4{{placeholder declared here}} \\
+   // expected-warning 2{{placeholder variable has no 
side effect}}
+(void)_++; // expected-error {{referring to placeholder '_' is not 
allowed}}

aaron.ballman wrote:
> cor3ntin wrote:
> > aaron.ballman wrote:
> > > I don't understand what this diagnostic is trying to tell me, can you 
> > > explain a bit more?
> > The no side effect one?
> > You are assigning something that has no side effect to something that you 
> > may never be able to name, so the whole thing is likely dead code.
> > I welcome improvements suggestions
> Yeah, the no side effect one.
> 
> Corentin and I discussed this off-list and I understand the situation a bit 
> better now. Basically, an init capture named `_` either has a side effect on 
> construction and/or destruction (like an RAII object) or it cannot be used 
> within the lambda. However, it does still have effects (for example, it 
> impacts whether the lambda has a function conversion operator).
> 
> That makes this kind of tricky to word. Given that it's a QoI warning, I'd 
> recommend we leave this bit for a follow-up so that we can land the majority 
> of the functionality and we can add the safety rails later.
Removed



Comment at: clang/test/SemaCXX/cxx2c-placeholder-vars.cpp:79
+void test_param(int _) {}
+void test_params(int _, int _); // expected-error {{redefinition of parameter 
'_'}} \
+// expected-note {{previous declaration is 
here}}

aaron.ballman wrote:
> cor3ntin wrote:
> > aaron.ballman wrote:
> > > Weird.. is this expected? You can have two variables named `_` in block 
> > > scope, but you can't have two parameters named `_` despite them 
> > > inhabiting the same block scope?
> > Yes, CWG decided against having it in parameter declarations, because 
> > otherwise we'd need them in template parameters which we didn't want to do.
> > And it would be useless, you can simply not name them.
> I guess I see the same amount of utility in allowing an init capture named 
> `_` as I do a function parameter named `_` as a local variable named `_` (if 
> it is an RAII type, it can do useful things in theory; otherwise, it's not a 
> useful declaration).
side effects are the main motivation for local variables beside structured 
bindings (and pattern matching later)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153536/new/

https://reviews.llvm.org/D153536

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


[PATCH] D105759: Implement P2361 Unevaluated string literals

2023-06-27 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:3048
   }];
+  let ParseArgumentsAsUnevaluated = 1;
 }

cor3ntin wrote:
> aaron.ballman wrote:
> > I don't think we should reuse this flag this way. This flag is for the 
> > traditional sense of "unevaluated", but unevaluated string literals are a 
> > different kind of beast. I think that should be tracked on the argument 
> > level. We can either adjust:
> > ```
> > class StringArgument : Argument;
> > ```
> > so that it takes another bit for whether the string is unevaluated or not, 
> > or we could add a new subclass for `UnevaluatedStringArgument`. Then 
> > ClangAttrEmitter.cpp would look at this information when emitting the 
> > switch cases.
> This is the previous approach i forgot to fixup everywhere.
> My current approach is to always consider StringArgument unevaluated.
> I don't think it make sense to have both StringArgument and 
> UnevaluatedStringArgument.
> Currently in all the places we accept StringArgument, we check it's a 
> possibly parenthesized StringLiteral
> 
> If you want an evaluated string literal, an expression that produce a const 
> char* or something should work
> My current approach is to always consider StringArgument unevaluated.
> I don't think it make sense to have both StringArgument and 
> UnevaluatedStringArgument.

I think that's potentially a pretty significant change in behavior until we 
actually evaluate (ahahaha, puns!) all the vendor attributes using a 
`StringArgument`. Also, I thought you mentioned you planned to leave variadic 
string arguments as evaluated strings, so there would be a pretty surprising 
inconsistency to the behavior there. I would feel more comfortable not changing 
the behavior of attributes we've not validated are still correct when using 
unevaluated strings.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105759/new/

https://reviews.llvm.org/D105759

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


[PATCH] D153536: [Clang] Implement P2169 A nice placeholder with no name

2023-06-27 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 535116.
cor3ntin added a comment.

- Address more feedback
- reword diag
- remove diag for unused init capture
- Remove the IsPlaceholder bit, as placeholder variables can be determined 
without data


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153536/new/

https://reviews.llvm.org/D153536

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/Decl.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/IdentifierTable.h
  clang/include/clang/Sema/Lookup.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Decl.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaLookup.cpp
  clang/test/Lexer/cxx-features.cpp
  clang/test/Lexer/unicode.c
  clang/test/SemaCXX/cxx2c-placeholder-vars.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -145,7 +145,7 @@
  
   Placeholder variables with no name
   https://wg21.link/P2169R4;>P2169R4
-  No
+  Clang 17
  
 
 
Index: clang/test/SemaCXX/cxx2c-placeholder-vars.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx2c-placeholder-vars.cpp
@@ -0,0 +1,103 @@
+// RUN: %clang -cc1 -fsyntax-only -verify -std=c++2c -Wunused-parameter -Wunused %s
+
+void static_var() {
+static int _; // expected-note {{previous definition is here}} \
+  // expected-note {{candidate}}
+static int _; // expected-error {{redefinition of '_'}}
+int _;// expected-warning {{placeholder variables are a C++2c extension}} \
+  // expected-note {{candidate}}
+_++; // expected-error{{reference to '_' is ambiguous}}
+}
+
+void static_var_2() {
+int _; // expected-note {{previous definition is here}}
+static int _; // expected-error {{redefinition of '_'}}
+}
+
+void bindings() {
+int arr[4] = {0, 1, 2, 3};
+auto [_, _, _, _] = arr; // expected-warning 3{{placeholder variables are a C++2c extension}} \
+ // expected-note 4{{placeholder declared here}}
+_ == 42; // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}}
+{
+auto [_, a, b, c] = arr; // expected-warning {{unused variable '[_, a, b, c]'}}
+}
+{
+auto [_, _, b, c] = arr; // expected-warning {{unused variable '[_, _, b, c]'}} \
+ // expected-warning {{placeholder variables are a C++2c extension}}
+}
+{
+auto [_, _, _, _] = arr; // expected-warning 3{{placeholder variables are a C++2c extension}}
+}
+}
+
+void lambda() {
+(void)[_ = 0, _ = 1] { // expected-warning {{placeholder variables are a C++2c extension}} \
+   // expected-note 4{{placeholder declared here}}
+(void)_++; // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}}
+};
+}
+
+namespace global_var {
+int _; // expected-note {{previous definition is here}}
+int _; // expected-error {{redefinition of '_'}}
+}
+
+namespace global_fun {
+void _();
+void _();
+
+void _() {} // expected-note {{previous definition is here}}
+void _() {} // expected-error {{redefinition of '_'}}
+void _(int){};
+}
+
+void extern_test() {
+extern int _;
+extern int _; // expected-note {{candidate}}
+int _; //expected-note {{candidate}}
+_++; // expected-error {{reference to '_' is ambiguous}}
+}
+
+
+struct Members {
+int _; // expected-note {{placeholder declared here}}
+int _; // expected-warning{{placeholder variables are a C++2c extension}} \
+   // expected-note {{placeholder declared here}}
+void f() {
+_++; // expected-error {{ambiguous reference to placeholder '_', which is defined multiple times}}
+}
+};
+
+namespace using_ {
+int _; // expected-note {{target of using declaration}}
+void f() {
+int _; // expected-note {{conflicting declaration}}
+_ = 0;
+using using_::_; // expected-error {{target of using declaration conflicts with declaration already in scope}}
+}
+}
+
+
+void call(int);
+void test_param(int _) {}
+void test_params(int _, int _); // expected-error {{redefinition of parameter '_'}} \
+// expected-note {{previous declaration is here}}
+
+template  // expected-error {{declaration of '_' shadows template parameter}} \
+  // expected-note  {{template parameter is declared here}}
+auto i = 0;
+
+template 
+concept C = requires(T _, T _) {  // expected-error {{redefinition of parameter '_'}} \
+// expected-note {{previous declaration is here}}
+T{};
+};
+
+struct S {
+int a;
+};
+
+void f(S a, S _) { // 

[PATCH] D153914: [clang-cl] Enable concatenation of predefined identifiers

2023-06-27 Thread Richard Dzenis via Phabricator via cfe-commits
RIscRIpt added a comment.

GitHub issue: https://github.com/llvm/llvm-project/issues/63563


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153914/new/

https://reviews.llvm.org/D153914

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


[PATCH] D153914: [clang-cl] Enable concatenation of predefined identifiers

2023-06-27 Thread Richard Dzenis via Phabricator via cfe-commits
RIscRIpt created this revision.
Herald added a project: All.
RIscRIpt requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153914

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/TokenKinds.h
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Sema/ms_predefined_expr.cpp

Index: clang/test/Sema/ms_predefined_expr.cpp
===
--- clang/test/Sema/ms_predefined_expr.cpp
+++ clang/test/Sema/ms_predefined_expr.cpp
@@ -6,4 +6,47 @@
  const char c[] = __FUNCSIG__; // expected-warning{{initializing an array from a '__FUNCSIG__' predefined identifier is a Microsoft extension}}
  const char d[] = __func__; // expected-warning{{initializing an array from a '__func__' predefined identifier is a Microsoft extension}}
  const char e[] = __PRETTY_FUNCTION__; // expected-warning{{initializing an array from a '__PRETTY_FUNCTION__' predefined identifier is a Microsoft extension}}
+ const wchar_t f[] = L__FUNCTION__; // expected-warning{{initializing an array from a 'L__FUNCTION__' predefined identifier is a Microsoft extension}}
+ const wchar_t g[] = L__FUNCSIG__; // expected-warning{{initializing an array from a 'L__FUNCSIG__' predefined identifier is a Microsoft extension}}
+}
+
+// Test concatenation
+
+void eat_const_char_p(const char*);
+void eat_const_wchar_p(const wchar_t*);
+
+void test_concat() {
+  eat_const_char_p("s" __FUNCTION__); // expected-warning{{concatenation of predefined identifier '__FUNCTION__' is a Microsoft extension}}
+  eat_const_char_p("s" __FUNCDNAME__); // expected-warning{{concatenation of predefined identifier '__FUNCDNAME__' is a Microsoft extension}}
+  eat_const_char_p("s" __FUNCSIG__); // expected-warning{{concatenation of predefined identifier '__FUNCSIG__' is a Microsoft extension}}
+
+  eat_const_char_p(__FUNCTION__ "s"); // expected-warning{{concatenation of predefined identifier '__FUNCTION__' is a Microsoft extension}}
+  eat_const_char_p(__FUNCDNAME__ "s"); // expected-warning{{concatenation of predefined identifier '__FUNCDNAME__' is a Microsoft extension}}
+  eat_const_char_p(__FUNCSIG__ "s"); // expected-warning{{concatenation of predefined identifier '__FUNCSIG__' is a Microsoft extension}}
+
+  eat_const_char_p("s" __FUNCTION__ "s"); // expected-warning{{concatenation of predefined identifier '__FUNCTION__' is a Microsoft extension}}
+  eat_const_char_p("s" __FUNCDNAME__ "s"); // expected-warning{{concatenation of predefined identifier '__FUNCDNAME__' is a Microsoft extension}}
+  eat_const_char_p("s" __FUNCSIG__ "s"); // expected-warning{{concatenation of predefined identifier '__FUNCSIG__' is a Microsoft extension}}
+}
+
+void test_wide_concat() {
+  eat_const_wchar_p(L"s" L__FUNCTION__); // expected-warning{{concatenation of predefined identifier 'L__FUNCTION__' is a Microsoft extension}}
+  eat_const_wchar_p(L"s" L__FUNCSIG__); // expected-warning{{concatenation of predefined identifier 'L__FUNCSIG__' is a Microsoft extension}}
+
+  eat_const_wchar_p(L__FUNCTION__ L"s"); // expected-warning{{concatenation of predefined identifier 'L__FUNCTION__' is a Microsoft extension}}
+  eat_const_wchar_p(L__FUNCSIG__ L"s"); // expected-warning{{concatenation of predefined identifier 'L__FUNCSIG__' is a Microsoft extension}}
+
+  eat_const_wchar_p(L"s" L__FUNCTION__ L"s"); // expected-warning{{concatenation of predefined identifier 'L__FUNCTION__' is a Microsoft extension}}
+  eat_const_wchar_p(L"s" L__FUNCSIG__ L"s"); // expected-warning{{concatenation of predefined identifier 'L__FUNCSIG__' is a Microsoft extension}}
+}
+
+const char* test_return() {
+  return __FUNCTION__ "s" __FUNCSIG__; // expected-warning{{concatenation of predefined identifier '__FUNCTION__' is a Microsoft extension}} \
+   // expected-warning{{concatenation of predefined identifier '__FUNCSIG__' is a Microsoft extension}}
+}
+
+void test_struct_init_fn() {
+  struct test_struct_init {
+const char* str;
+  } struct_init = { "struct: " __FUNCSIG__ }; // expected-warning{{concatenation of predefined identifier '__FUNCSIG__' is a Microsoft extension}}
 }
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -1882,6 +1882,27 @@
   ContainsUnexpandedParameterPack, ResultIndex);
 }
 
+static PredefinedExpr::IdentKind getPredefinedExprKind(tok::TokenKind Kind) {
+  switch (Kind) {
+  default:
+llvm_unreachable("unexpected TokenKind");
+  case tok::kw___func__:
+return PredefinedExpr::Func; // [C99 6.4.2.2]
+  case tok::kw___FUNCTION__:
+return PredefinedExpr::Function;
+  

[PATCH] D150978: [clang][Sema] Add CodeCompletionContext::CCC_ObjCClassForwardDecl

2023-06-27 Thread David Goldman via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa42ce094d903: [clang][Sema] Add 
CodeCompletionContext::CCC_ObjCClassForwardDecl (authored by dgoldman).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150978/new/

https://reviews.llvm.org/D150978

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang/include/clang/Sema/CodeCompleteConsumer.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Frontend/ASTUnit.cpp
  clang/lib/Parse/ParseObjc.cpp
  clang/lib/Sema/CodeCompleteConsumer.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/tools/libclang/CIndexCodeCompletion.cpp

Index: clang/tools/libclang/CIndexCodeCompletion.cpp
===
--- clang/tools/libclang/CIndexCodeCompletion.cpp
+++ clang/tools/libclang/CIndexCodeCompletion.cpp
@@ -537,6 +537,7 @@
 case CodeCompletionContext::CCC_Other:
 case CodeCompletionContext::CCC_ObjCInterface:
 case CodeCompletionContext::CCC_ObjCImplementation:
+case CodeCompletionContext::CCC_ObjCClassForwardDecl:
 case CodeCompletionContext::CCC_NewName:
 case CodeCompletionContext::CCC_MacroName:
 case CodeCompletionContext::CCC_PreprocessorExpression:
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -8460,6 +8460,24 @@
 Results.data(), Results.size());
 }
 
+void Sema::CodeCompleteObjCClassForwardDecl(Scope *S) {
+  ResultBuilder Results(*this, CodeCompleter->getAllocator(),
+CodeCompleter->getCodeCompletionTUInfo(),
+CodeCompletionContext::CCC_ObjCClassForwardDecl);
+  Results.EnterNewScope();
+
+  if (CodeCompleter->includeGlobals()) {
+// Add all classes.
+AddInterfaceResults(Context.getTranslationUnitDecl(), CurContext, false,
+false, Results);
+  }
+
+  Results.ExitScope();
+
+  HandleCodeCompleteResults(this, CodeCompleter, Results.getCompletionContext(),
+Results.data(), Results.size());
+}
+
 void Sema::CodeCompleteObjCSuperclass(Scope *S, IdentifierInfo *ClassName,
   SourceLocation ClassNameLoc) {
   ResultBuilder Results(*this, CodeCompleter->getAllocator(),
Index: clang/lib/Sema/CodeCompleteConsumer.cpp
===
--- clang/lib/Sema/CodeCompleteConsumer.cpp
+++ clang/lib/Sema/CodeCompleteConsumer.cpp
@@ -83,6 +83,7 @@
   case CCC_ObjCCategoryName:
   case CCC_IncludedFile:
   case CCC_Attribute:
+  case CCC_ObjCClassForwardDecl:
 return false;
   }
 
@@ -166,6 +167,8 @@
 return "Attribute";
   case CCKind::CCC_Recovery:
 return "Recovery";
+  case CCKind::CCC_ObjCClassForwardDecl:
+return "ObjCClassForwardDecl";
   }
   llvm_unreachable("Invalid CodeCompletionContext::Kind!");
 }
Index: clang/lib/Parse/ParseObjc.cpp
===
--- clang/lib/Parse/ParseObjc.cpp
+++ clang/lib/Parse/ParseObjc.cpp
@@ -153,6 +153,11 @@
 
   while (true) {
 MaybeSkipAttributes(tok::objc_class);
+if (Tok.is(tok::code_completion)) {
+  cutOffParsing();
+  Actions.CodeCompleteObjCClassForwardDecl(getCurScope());
+  return Actions.ConvertDeclToDeclGroup(nullptr);
+}
 if (expectIdentifier()) {
   SkipUntil(tok::semi);
   return Actions.ConvertDeclToDeclGroup(nullptr);
Index: clang/lib/Frontend/ASTUnit.cpp
===
--- clang/lib/Frontend/ASTUnit.cpp
+++ clang/lib/Frontend/ASTUnit.cpp
@@ -322,6 +322,7 @@
   if (ID->getDefinition())
 Contexts |= (1LL << CodeCompletionContext::CCC_Expression);
   Contexts |= (1LL << CodeCompletionContext::CCC_ObjCInterfaceName);
+  Contexts |= (1LL << CodeCompletionContext::CCC_ObjCClassForwardDecl);
 }
 
 // Deal with tag names.
@@ -2028,6 +2029,7 @@
   case CodeCompletionContext::CCC_IncludedFile:
   case CodeCompletionContext::CCC_Attribute:
   case CodeCompletionContext::CCC_NewName:
+  case CodeCompletionContext::CCC_ObjCClassForwardDecl:
 // We're looking for nothing, or we're looking for names that cannot
 // be hidden.
 return;
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -13429,6 +13429,7 @@
  ArrayRef Protocols);
   void CodeCompleteObjCProtocolDecl(Scope *S);
   void CodeCompleteObjCInterfaceDecl(Scope *S);
+  void CodeCompleteObjCClassForwardDecl(Scope *S);
   void CodeCompleteObjCSuperclass(Scope *S,
  

[clang-tools-extra] a42ce09 - [clang][Sema] Add CodeCompletionContext::CCC_ObjCClassForwardDecl

2023-06-27 Thread David Goldman via cfe-commits

Author: David Goldman
Date: 2023-06-27T16:25:40-04:00
New Revision: a42ce094d90341f88a845740b2e5783060f23e3e

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

LOG: [clang][Sema] Add CodeCompletionContext::CCC_ObjCClassForwardDecl

- Use this new context in Sema to limit completions to seen ObjC class
  names

- Use this new context in clangd to disable include insertions when
  completing ObjC forward decls

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D150978

Added: 


Modified: 
clang-tools-extra/clangd/CodeComplete.cpp
clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
clang/include/clang/Sema/CodeCompleteConsumer.h
clang/include/clang/Sema/Sema.h
clang/lib/Frontend/ASTUnit.cpp
clang/lib/Parse/ParseObjc.cpp
clang/lib/Sema/CodeCompleteConsumer.cpp
clang/lib/Sema/SemaCodeComplete.cpp
clang/tools/libclang/CIndexCodeCompletion.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/CodeComplete.cpp 
b/clang-tools-extra/clangd/CodeComplete.cpp
index f4f93a01ec90e..70f2634aa7763 100644
--- a/clang-tools-extra/clangd/CodeComplete.cpp
+++ b/clang-tools-extra/clangd/CodeComplete.cpp
@@ -214,7 +214,8 @@ struct CompletionCandidate {
   // Returns a token identifying the overload set this is part of.
   // 0 indicates it's not part of any overload set.
   size_t overloadSet(const CodeCompleteOptions , llvm::StringRef FileName,
- IncludeInserter *Inserter) const {
+ IncludeInserter *Inserter,
+ CodeCompletionContext::Kind CCContextKind) const {
 if (!Opts.BundleOverloads.value_or(false))
   return 0;
 
@@ -223,7 +224,7 @@ struct CompletionCandidate {
 // bundle those, so we must resolve the header to be included here.
 std::string HeaderForHash;
 if (Inserter) {
-  if (auto Header = headerToInsertIfAllowed(Opts)) {
+  if (auto Header = headerToInsertIfAllowed(Opts, CCContextKind)) {
 if (auto HeaderFile = toHeaderFile(*Header, FileName)) {
   if (auto Spelled =
   Inserter->calculateIncludePath(*HeaderFile, FileName))
@@ -271,11 +272,21 @@ struct CompletionCandidate {
 return 0;
   }
 
+  bool contextAllowsHeaderInsertion(CodeCompletionContext::Kind Kind) const {
+// Explicitly disable insertions for forward declarations since they don't
+// reference the declaration.
+if (Kind == CodeCompletionContext::CCC_ObjCClassForwardDecl)
+  return false;
+return true;
+  }
+
   // The best header to include if include insertion is allowed.
   std::optional
-  headerToInsertIfAllowed(const CodeCompleteOptions ) const {
+  headerToInsertIfAllowed(const CodeCompleteOptions ,
+  CodeCompletionContext::Kind ContextKind) const {
 if (Opts.InsertIncludes == CodeCompleteOptions::NeverInsert ||
-RankedIncludeHeaders.empty())
+RankedIncludeHeaders.empty() ||
+!contextAllowsHeaderInsertion(ContextKind))
   return std::nullopt;
 if (SemaResult && SemaResult->Declaration) {
   // Avoid inserting new #include if the declaration is found in the 
current
@@ -401,7 +412,8 @@ struct CodeCompletionBuilder {
   std::move(*Spelled),
   Includes.shouldInsertInclude(*ResolvedDeclaring, *ResolvedInserted));
 };
-bool ShouldInsert = C.headerToInsertIfAllowed(Opts).has_value();
+bool ShouldInsert =
+C.headerToInsertIfAllowed(Opts, ContextKind).has_value();
 Symbol::IncludeDirective Directive = insertionDirective(Opts);
 // Calculate include paths and edits for all possible headers.
 for (const auto  : C.RankedIncludeHeaders) {
@@ -780,6 +792,7 @@ bool contextAllowsIndex(enum CodeCompletionContext::Kind K) 
{
   case CodeCompletionContext::CCC_ObjCInterfaceName:
   case CodeCompletionContext::CCC_Symbol:
   case CodeCompletionContext::CCC_SymbolOrNewName:
+  case CodeCompletionContext::CCC_ObjCClassForwardDecl:
 return true;
   case CodeCompletionContext::CCC_OtherWithMacros:
   case CodeCompletionContext::CCC_DotMemberAccess:
@@ -1422,6 +1435,10 @@ bool includeSymbolFromIndex(CodeCompletionContext::Kind 
Kind,
   else if (Kind == CodeCompletionContext::CCC_ObjCProtocolName)
 // Don't show anything else in ObjC protocol completions.
 return false;
+
+  if (Kind == CodeCompletionContext::CCC_ObjCClassForwardDecl)
+return Sym.SymInfo.Kind == index::SymbolKind::Class &&
+   Sym.SymInfo.Lang == index::SymbolLanguage::ObjC;
   return true;
 }
 
@@ -1832,8 +1849,8 @@ class CodeCompleteFlow {
 assert(IdentifierResult);
 C.Name = IdentifierResult->Name;
   }
-  if (auto OverloadSet =
-  C.overloadSet(Opts, FileName, Inserter ? &*Inserter : nullptr)) {
+  

[PATCH] D153860: [clang-tidy] Fix modernize-use-std-print check when return value used

2023-06-27 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe updated this revision to Diff 535106.
mikecrowe added a comment.

Fix test failures on PS4 and PS5 and improve tests

- Ensure that exceptions are available so the test can use try/catch
- Remove unwanted -NOT checks
- Add more return value tests


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153860/new/

https://reviews.llvm.org/D153860

Files:
  clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp
  clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst
  clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-absl.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-custom.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print.cpp
@@ -1,11 +1,11 @@
 // RUN: %check_clang_tidy -check-suffixes=,STRICT \
 // RUN:   -std=c++23 %s modernize-use-std-print %t -- \
 // RUN:   -config="{CheckOptions: [{key: StrictMode, value: true}]}" \
-// RUN:   -- -isystem %clang_tidy_headers
+// RUN:   -- -isystem %clang_tidy_headers -fexceptions
 // RUN: %check_clang_tidy -check-suffixes=,NOTSTRICT \
 // RUN:   -std=c++23 %s modernize-use-std-print %t -- \
 // RUN:   -config="{CheckOptions: [{key: StrictMode, value: false}]}" \
-// RUN:   -- -isystem %clang_tidy_headers
+// RUN:   -- -isystem %clang_tidy_headers -fexceptions
 #include 
 #include 
 #include 
@@ -44,6 +44,239 @@
   // CHECK-FIXES: std::println("Hello");
 }
 
+// std::print returns nothing, so any callers that use the return
+// value cannot be automatically translated.
+int printf_uses_return_value(int choice) {
+  const int i = printf("Return value assigned to variable %d\n", 42);
+
+  extern void accepts_int(int);
+  accepts_int(printf("Return value passed to function %d\n", 42));
+
+  if (choice == 0)
+printf("if body %d\n", i);
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: use 'std::println' instead of 'printf' [modernize-use-std-print]
+// CHECK-FIXES: std::println("if body {}", i);
+  else if (choice == 1)
+printf("else if body %d\n", i);
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: use 'std::println' instead of 'printf' [modernize-use-std-print]
+// CHECK-FIXES: std::println("else if body {}", i);
+  else
+printf("else body %d\n", i);
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: use 'std::println' instead of 'printf' [modernize-use-std-print]
+// CHECK-FIXES: std::println("else body {}", i);
+
+  if (printf("Return value used as boolean in if statement"))
+if (printf("Return value used in expression if statement") == 44)
+  if (const int j = printf("Return value used in assignment in if statement"))
+if (const int k = printf("Return value used with initializer in if statement"); k == 44)
+  ;
+
+  int d = 0;
+  while (printf("%d", d) < 2)
+++d;
+
+  while (true)
+printf("while body %d\n", i);
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: use 'std::println' instead of 'printf' [modernize-use-std-print]
+// CHECK-FIXES: std::println("while body {}", i);
+
+  do
+printf("do body %d\n", i);
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: use 'std::println' instead of 'printf' [modernize-use-std-print]
+// CHECK-FIXES: std::println("do body {}", i);
+  while (true);
+
+  for (;;)
+printf("for body %d\n", i);
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: use 'std::println' instead of 'printf' [modernize-use-std-print]
+// CHECK-FIXES: std::println("for body {}", i);
+
+  for (printf("for init statement %d\n", i);;)
+// CHECK-MESSAGES: [[@LINE-1]]:8: warning: use 'std::println' instead of 'printf' [modernize-use-std-print]
+// CHECK-FIXES: std::println("for init statement {}", i);
+;;
+
+  for (int j = printf("for init statement %d\n", i);;)
+;;
+
+  for (; printf("for condition %d\n", i);)
+;;
+
+  for (;; printf("for expression %d\n", i))
+// CHECK-MESSAGES: [[@LINE-1]]:11: warning: use 'std::println' instead of 'printf' [modernize-use-std-print]
+// CHECK-FIXES: std::println("for expression {}", i)
+;;
+
+  for (auto C : "foo")
+printf("ranged-for body %d\n", i);
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: use 'std::println' instead of 'printf' [modernize-use-std-print]
+// CHECK-FIXES: std::println("ranged-for body {}", i);
+
+  switch (1) {
+  case 1:
+printf("switch case body %d\n", i);
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: use 'std::println' instead of 'printf' [modernize-use-std-print]
+// CHECK-FIXES: std::println("switch case body {}", i);
+break;
+  default:
+printf("switch default body %d\n", i);
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: use 'std::println' instead of 

[PATCH] D153536: [Clang] Implement P2169 A nice placeholder with no name

2023-06-27 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:135-136
 - Compiler flags ``-std=c++2c`` and ``-std=gnu++2c`` have been added for 
experimental C++2c implementation work.
+- Implemented `P2169R4: A nice placeholder with no name 
`_. This allows to use `_`
+  as a variable name multiple times in the same scope and is supported in all 
C++ language modes as an extension.
 

cor3ntin wrote:
> aaron.ballman wrote:
> > Should we consider adding this as an extension to C? It would be conforming 
> > there as well because it wouldn't change the behavior of any correct C 
> > code, right?
> Maybe we should consult WG14 first?
> It's of very questionable usefulness without structured bindings and 
> destructors.
We certainly could ask WG14 for their opinion, but the scenario I was thinking 
this would help with is for complex macros where variables are sometimes 
defined but the names are not important as they shouldn't escape. However, I 
think those scenarios generally introduce different scopes (often with GNU 
statement expressions) so there's not a naming conflict that we'd need to 
avoid. So I'm fine skipping C for now until we hit a concrete use case.



Comment at: clang/include/clang/AST/DeclBase.h:340-342
+  /// Whether this declaration denotes a placeholder that can be
+  /// redefined in the same scope.
+  unsigned IsPlaceholder : 1;

cor3ntin wrote:
> aaron.ballman wrote:
> > This seems a bit heavy to put on every `Decl`, it only matters for 
> > declarations with names, right? Should this be on `NamedDecl` instead? And 
> > should it be using terminology like "name independent"?
> > 
> > Actually, do we need this bit at all? Would it work for `NamedDecl` to have 
> > a function that returns whether the declaration name is `_` or not? Oh, I 
> > suppose we can't get away with that because `void _(int x);` does not 
> > introduce a placeholder identifier but a regular one, right?
> I think you made me realize we can probably compute that completely without 
> using bits. Oups.
> It would certainly simplify things. I'll investigate!
Thank you!



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:6589
+def err_using_placeholder_variable : Error<
+  "referring to placeholder '_' is not allowed">;
+def note_reference_placeholder : Note<

cor3ntin wrote:
> cjdb wrote:
> > aaron.ballman wrote:
> > > I don't think this helps the user understand what's wrong with their 
> > > code, especially given the somewhat odd language rules around the 
> > > feature. How about: `ambiguous reference to multiply-defined placeholder 
> > > '_'` or something along those lines? Then the note can show the previous 
> > > declarations of the placeholders that are in scope? e.g.,
> > > ```
> > > void g() {
> > > int _; // note: placeholder declared here
> > > _ = 0;
> > > int _; // note: placeholder declared here
> > > _ = 0; // error: `ambiguous reference to multiply-defined placeholder '_'`
> > > }
> > > ```
> > > CC @cjdb 
> > Agreed. I'd suggest a rewording though: I took "multiply" to mean the maths 
> > term until completing the sentence, rather than its alternative meaning of 
> > "multiple instances" (which is more or less the same meaning, but 
> > "multiply" maps to the `x * y` operation for me).
> > 
> > Perhaps `ambiguous reference to placeholder '_', which has multiple 
> > definitions`? Not sold on that being the best wording, but it does avoid 
> > the hardcoded-word-at-8yo problem :)
> @cjdb I like your suggestion. maybe "which is defined multiple times?"  - 
> pedantically a bunch of things  have been defined once each, it's not a 
> redefinition of the same entity in the c++ sense
I like either of your suggestions better than my use of "multiply-defined." :-)



Comment at: clang/lib/Sema/SemaDecl.cpp:2171-2172
 
+  if (VD->isPlaceholderVar())
+return;
+

cor3ntin wrote:
> aaron.ballman wrote:
> > What's the rationale here? I know the standard has a recommended practice, 
> > but I don't see why that should apply to the case where the user assigns a 
> > value to the placeholder but never references it otherwise.
> The intent is that this behave like `[[maybe_unused]]`
Ah, thank you! I think we should make a slightly wider change here then. Let's 
move `VD->hasAttr()` out of the first if statement and into this 
one, then add a comment about the relationship between the attribute and this 
feautre. WDYT?



Comment at: clang/test/SemaCXX/cxx2c-placeholder-vars.cpp:31
+   // expected-note 4{{placeholder declared here}} \\
+   // expected-warning 2{{placeholder variable has no 
side effect}}
+(void)_++; // expected-error {{referring to placeholder '_' is not 
allowed}}

cor3ntin wrote:
> aaron.ballman wrote:
> > I don't 

[PATCH] D153860: [clang-tidy] Fix modernize-use-std-print check when return value used

2023-06-27 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe marked an inline comment as done.
mikecrowe added a comment.

In D153860#4453572 , @dyung wrote:

> @mikecrowe Your change is causing a test failure on the PS4 linux and PS5 
> Windows build bots. Can you take a look and fix or revert if you need time to 
> investigate?
>
> https://lab.llvm.org/buildbot/#/builders/139/builds/43856
> https://lab.llvm.org/buildbot/#/builders/216/builds/23017

The failure is due to:

  use-std-print.cpp.tmp.cpp:125:3: error: cannot use 'try' with exceptions 
disabled [clang-diagnostic-error]

I wasn't expecting that!

It looks like I failed to notice that the `bugprone-unused-return-value` check 
explicitly added `-fexceptions` to the `clang-tidy` command line to avoid this 
problem. I can add that to hopefully fix the problem, and I had some other 
changes that I hadn't pushed for review before this landed the first time too.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153860/new/

https://reviews.llvm.org/D153860

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


[PATCH] D153885: [Clang][Driver] Change missing multilib error to warning

2023-06-27 Thread Michael Platings via Phabricator via cfe-commits
michaelplatings updated this revision to Diff 535102.
michaelplatings added a comment.

Rename variable


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153885/new/

https://reviews.llvm.org/D153885

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/test/Driver/baremetal-multilib.yaml


Index: clang/test/Driver/baremetal-multilib.yaml
===
--- clang/test/Driver/baremetal-multilib.yaml
+++ clang/test/Driver/baremetal-multilib.yaml
@@ -23,7 +23,7 @@
 # RUN: %T/baremetal_multilib/bin/clang -no-canonical-prefixes -x c++ %s -### 
-o %t.out 2>&1 \
 # RUN: --target=thumbv7em-none-eabi -mfpu=fpv4-sp-d16 --sysroot= \
 # RUN:   | FileCheck --check-prefix=CHECK-NO-MATCH %s
-# CHECK-NO-MATCH: error: no multilib found matching flags:
+# CHECK-NO-MATCH: warning: no multilib found matching flags:
 # CHECK-NO-MATCH-SAME: --target=thumbv7em-none-unknown-eabi
 # CHECK-NO-MATCH: note: available multilibs are:
 # CHECK-NO-MATCH: --target=thumbv6m-none-unknown-eabi -mfpu=none
Index: clang/lib/Driver/ToolChains/BareMetal.cpp
===
--- clang/lib/Driver/ToolChains/BareMetal.cpp
+++ clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -175,7 +175,7 @@
   Result.Multilibs = ErrorOrMultilibSet.get();
   if (Result.Multilibs.select(Flags, Result.SelectedMultilibs))
 return;
-  D.Diag(clang::diag::err_drv_no_matching_multilib) << llvm::join(Flags, " ");
+  D.Diag(clang::diag::warn_drv_missing_multilib) << llvm::join(Flags, " ");
   std::stringstream ss;
   for (const Multilib  : Result.Multilibs)
 ss << "\n" << llvm::join(Multilib.flags(), " ");
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -737,8 +737,9 @@
 def err_drv_expand_response_file : Error<
   "failed to expand response file: %0">;
 
-def err_drv_no_matching_multilib : Error<
-  "no multilib found matching flags: %0">;
+def warn_drv_missing_multilib : Warning<
+  "no multilib found matching flags: %0">,
+  InGroup>;
 def note_drv_available_multilibs : Note<
   "available multilibs are:%0">;
 }


Index: clang/test/Driver/baremetal-multilib.yaml
===
--- clang/test/Driver/baremetal-multilib.yaml
+++ clang/test/Driver/baremetal-multilib.yaml
@@ -23,7 +23,7 @@
 # RUN: %T/baremetal_multilib/bin/clang -no-canonical-prefixes -x c++ %s -### -o %t.out 2>&1 \
 # RUN: --target=thumbv7em-none-eabi -mfpu=fpv4-sp-d16 --sysroot= \
 # RUN:   | FileCheck --check-prefix=CHECK-NO-MATCH %s
-# CHECK-NO-MATCH: error: no multilib found matching flags:
+# CHECK-NO-MATCH: warning: no multilib found matching flags:
 # CHECK-NO-MATCH-SAME: --target=thumbv7em-none-unknown-eabi
 # CHECK-NO-MATCH: note: available multilibs are:
 # CHECK-NO-MATCH: --target=thumbv6m-none-unknown-eabi -mfpu=none
Index: clang/lib/Driver/ToolChains/BareMetal.cpp
===
--- clang/lib/Driver/ToolChains/BareMetal.cpp
+++ clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -175,7 +175,7 @@
   Result.Multilibs = ErrorOrMultilibSet.get();
   if (Result.Multilibs.select(Flags, Result.SelectedMultilibs))
 return;
-  D.Diag(clang::diag::err_drv_no_matching_multilib) << llvm::join(Flags, " ");
+  D.Diag(clang::diag::warn_drv_missing_multilib) << llvm::join(Flags, " ");
   std::stringstream ss;
   for (const Multilib  : Result.Multilibs)
 ss << "\n" << llvm::join(Multilib.flags(), " ");
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -737,8 +737,9 @@
 def err_drv_expand_response_file : Error<
   "failed to expand response file: %0">;
 
-def err_drv_no_matching_multilib : Error<
-  "no multilib found matching flags: %0">;
+def warn_drv_missing_multilib : Warning<
+  "no multilib found matching flags: %0">,
+  InGroup>;
 def note_drv_available_multilibs : Note<
   "available multilibs are:%0">;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D105759: Implement P2361 Unevaluated string literals

2023-06-27 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:3048
   }];
+  let ParseArgumentsAsUnevaluated = 1;
 }

aaron.ballman wrote:
> I don't think we should reuse this flag this way. This flag is for the 
> traditional sense of "unevaluated", but unevaluated string literals are a 
> different kind of beast. I think that should be tracked on the argument 
> level. We can either adjust:
> ```
> class StringArgument : Argument;
> ```
> so that it takes another bit for whether the string is unevaluated or not, or 
> we could add a new subclass for `UnevaluatedStringArgument`. Then 
> ClangAttrEmitter.cpp would look at this information when emitting the switch 
> cases.
This is the previous approach i forgot to fixup everywhere.
My current approach is to always consider StringArgument unevaluated.
I don't think it make sense to have both StringArgument and 
UnevaluatedStringArgument.
Currently in all the places we accept StringArgument, we check it's a possibly 
parenthesized StringLiteral

If you want an evaluated string literal, an expression that produce a const 
char* or something should work



Comment at: llvm/cmake/modules/HandleLLVMOptions.cmake:608
   # based on object lifetime.
-  add_flag_if_supported("-fno-lifetime-dse" CMAKE_CXX_FLAGS)
+  # add_flag_if_supported("-fno-lifetime-dse" CMAKE_CXX_FLAGS)
 endif ( LLVM_COMPILER_IS_GCC_COMPATIBLE )

aaron.ballman wrote:
> Spurious change. ;-)
I've been battling with that for weeks, that flag completely breaks my IDE, not 
sure why. It was inevitable that it ended up in a commit :|


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105759/new/

https://reviews.llvm.org/D105759

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


[PATCH] D153798: [clang-format] Correctly annotate operator free function call

2023-06-27 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks accepted this revision.
HazardyKnusperkeks added inline comments.



Comment at: clang/lib/Format/TokenAnnotator.cpp:316
+  // line can't be a declaration.
   bool OperatorCalledAsMemberFunction =
+  (Prev->Previous &&

Nuu wrote:
> minor. Probably better to rename it to something like `IsOperatorCallSite`.
The Name should really be changes, since it's not limited to member functions 
anymore.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153798/new/

https://reviews.llvm.org/D153798

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


[PATCH] D153130: [Clang][AArch64] Implement ACLE feature macro for FEAT_LRCPC3

2023-06-27 Thread Tomas Matheson via Phabricator via cfe-commits
tmatheson accepted this revision.
tmatheson added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: clang/lib/Basic/Targets/AArch64.cpp:420
+Builder.defineMacro("__ARM_FEATURE_RCPC", "3");
+  else if (HasRCPC)
 Builder.defineMacro("__ARM_FEATURE_RCPC", "1");

I didn't realise we hadn't implemented RPCP2 here. If we aren't aware of anyone 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153130/new/

https://reviews.llvm.org/D153130

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


[PATCH] D152504: [clang][ThreadSafety] Analyze cleanup functions

2023-06-27 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added inline comments.



Comment at: clang/lib/Analysis/ThreadSafety.cpp:2436
+CF.getVarDecl()->getLocation());
+  break;
+}

aaronpuchert wrote:
> tbaeder wrote:
> > This handles the function call, but without the instance parameter. I was 
> > wondering how to best do that.
> Should you not simply pass `SxBuilder.createVariable(CF.getVarDecl())` as 
> third parameter in analogy with the `AutomaticObjectDtor` case? It might also 
> make sense to copy the attribute check.
Can you write a test case that relies on passing the variable? Here is an idea:
```
void unlock_scope(Mutex **mu) __attribute__((release_capability(*mu))) {
  mutex_exclusive_unlock(*mu);
}

Mutex* const CLEANUP(unlock_scope) scope = 
mutex_exclusive_lock(*scope);
// Unlock should happen automatically.
```
I think this is mildly more interesting than the cleanup function with an 
unused parameter.

Unfortunately this is not quite as powerful as a scoped lock in C++, as we 
don't track the identity `scope == `. So `guarded_by` won't work with this. 
But we can at least see warnings on balanced locking/unlocking.

As for proper scoped locking, we could treat some variable initializations like 
construction of a C++ scoped lock. But let's discuss this separately.



Comment at: clang/test/Sema/warn-thread-safety-analysis.c:76-77
 
+void cleanup_int(int *unused) __attribute__((release_capability(mu1))) {
+  (void)unused;
+  mutex_exclusive_unlock();

tbaeder wrote:
> aaronpuchert wrote:
> > 
> > omitting the parameter name in a function definition is a C2x extension
Ah, I didn't know that C gained this only recently.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152504/new/

https://reviews.llvm.org/D152504

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


[clang-tools-extra] 43fa7ea - Revert "[clang-tidy] Fix modernize-use-std-print check when return value used"

2023-06-27 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-06-27T19:25:52Z
New Revision: 43fa7ea9df3a7b3bdc9d0129bcc3bed4db52dba0

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

LOG: Revert "[clang-tidy] Fix modernize-use-std-print check when return value 
used"

This reverts commit 3e12b2e207cfa802937488a2c0b90d482eaf00a9.

Added: 


Modified: 
clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp
clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-absl.cpp

clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-custom.cpp
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp
index b1e1189d4ed77..9b368f9a3e6c9 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp
@@ -70,53 +70,27 @@ void UseStdPrintCheck::registerPPCallbacks(const 
SourceManager ,
   IncludeInserter.registerPreprocessor(PP);
 }
 
-static clang::ast_matchers::StatementMatcher
-unusedReturnValue(clang::ast_matchers::StatementMatcher MatchedCallExpr) {
-  auto UnusedInCompoundStmt =
-  compoundStmt(forEach(MatchedCallExpr),
-   // The checker can't currently 
diff erentiate between the
-   // return statement and other statements inside GNU 
statement
-   // expressions, so disable the checker inside them to avoid
-   // false positives.
-   unless(hasParent(stmtExpr(;
-  auto UnusedInIfStmt =
-  ifStmt(eachOf(hasThen(MatchedCallExpr), hasElse(MatchedCallExpr)));
-  auto UnusedInWhileStmt = whileStmt(hasBody(MatchedCallExpr));
-  auto UnusedInDoStmt = doStmt(hasBody(MatchedCallExpr));
-  auto UnusedInForStmt =
-  forStmt(eachOf(hasLoopInit(MatchedCallExpr),
- hasIncrement(MatchedCallExpr), hasBody(MatchedCallExpr)));
-  auto UnusedInRangeForStmt = cxxForRangeStmt(hasBody(MatchedCallExpr));
-  auto UnusedInCaseStmt = switchCase(forEach(MatchedCallExpr));
-
-  return stmt(anyOf(UnusedInCompoundStmt, UnusedInIfStmt, UnusedInWhileStmt,
-UnusedInDoStmt, UnusedInForStmt, UnusedInRangeForStmt,
-UnusedInCaseStmt));
-}
-
 void UseStdPrintCheck::registerMatchers(MatchFinder *Finder) {
   if (!PrintfLikeFunctions.empty())
 Finder->addMatcher(
-unusedReturnValue(
-callExpr(argumentCountAtLeast(1),
- hasArgument(0, stringLiteral(isOrdinary())),
- callee(functionDecl(unless(cxxMethodDecl()),
- matchers::matchesAnyListedName(
- PrintfLikeFunctions))
-.bind("func_decl")))
-.bind("printf")),
+callExpr(argumentCountAtLeast(1),
+ hasArgument(0, stringLiteral(isOrdinary())),
+ callee(functionDecl(
+unless(cxxMethodDecl()),
+
matchers::matchesAnyListedName(PrintfLikeFunctions))
+.bind("func_decl")))
+.bind("printf"),
 this);
 
   if (!FprintfLikeFunctions.empty())
 Finder->addMatcher(
-unusedReturnValue(
-callExpr(argumentCountAtLeast(2),
- hasArgument(1, stringLiteral(isOrdinary())),
- callee(functionDecl(unless(cxxMethodDecl()),
- matchers::matchesAnyListedName(
- FprintfLikeFunctions))
-.bind("func_decl")))
-.bind("fprintf")),
+callExpr(argumentCountAtLeast(2),
+ hasArgument(1, stringLiteral(isOrdinary())),
+ callee(functionDecl(unless(cxxMethodDecl()),
+ matchers::matchesAnyListedName(
+ FprintfLikeFunctions))
+.bind("func_decl")))
+.bind("fprintf"),
 this);
 }
 

diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst
index 8034238bea90e..385ee35c4f8f8 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst
@@ -49,13 +49,6 @@ It doesn't do a bad job, but it's not perfect. In particular:
 
   - The glibc extension ``%m``.
 
-- ``printf`` and similar 

[PATCH] D105759: Implement P2361 Unevaluated string literals

2023-06-27 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman requested changes to this revision.
aaron.ballman added a comment.
This revision now requires changes to proceed.

Clearing the "accepted" status so it's not confusing as to the state of things.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105759/new/

https://reviews.llvm.org/D105759

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


[PATCH] D105759: Implement P2361 Unevaluated string literals

2023-06-27 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D105759#4453440 , @cor3ntin wrote:

> Parse attribute as unevaluated string if they 
> are declare StringLiteralArgument in the Attr.td file.
>
> WIP
>
> @aaron.ballman Do we agree on direction before I 
> fix the remaining broken tests?

Mostly agreed, though I left a comment where I think the direction should 
change slightly.

> There are a few limitations, which I'm hoping not to fix there
>
> - It doesn't support variadic string arguments

That's reasonable; let's leave them as evaluated strings for now so there's no 
behavioral change.

> - checking the type of argument ahead of time seems like a good idea overall, 
> maybe we want to expand that system?

I agree; we currently have the common handler checking argument counts 
(https://github.com/llvm/llvm-project/blob/1e010c5c4fae43c52d6f5f1c8e8920c26bcc6cc7/clang/lib/Sema/SemaAttr.cpp#L1419),
 but we don't generate any code for checking argument types. But certainly 
doesn't need to be done as part of your work.




Comment at: clang/include/clang/Basic/Attr.td:3048
   }];
+  let ParseArgumentsAsUnevaluated = 1;
 }

I don't think we should reuse this flag this way. This flag is for the 
traditional sense of "unevaluated", but unevaluated string literals are a 
different kind of beast. I think that should be tracked on the argument level. 
We can either adjust:
```
class StringArgument : Argument;
```
so that it takes another bit for whether the string is unevaluated or not, or 
we could add a new subclass for `UnevaluatedStringArgument`. Then 
ClangAttrEmitter.cpp would look at this information when emitting the switch 
cases.



Comment at: llvm/cmake/modules/HandleLLVMOptions.cmake:608
   # based on object lifetime.
-  add_flag_if_supported("-fno-lifetime-dse" CMAKE_CXX_FLAGS)
+  # add_flag_if_supported("-fno-lifetime-dse" CMAKE_CXX_FLAGS)
 endif ( LLVM_COMPILER_IS_GCC_COMPATIBLE )

Spurious change. ;-)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105759/new/

https://reviews.llvm.org/D105759

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


[PATCH] D153909: [AMDGPU] Always pass `-mcpu` to the `lld` linker

2023-06-27 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 created this revision.
jhuber6 added reviewers: JonChesterfield, yaxunl, tra.
Herald added subscribers: kerbowa, tpr, dstuttard, jvesely, kzhuravl.
Herald added a project: All.
jhuber6 requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, wdng.
Herald added a project: clang.

Currently, AMDGPU more or less only supports linking with LTO. If the
user does not either pass `-flto` or `-Wl,-plugin-opt=mcpu=` manually
linking will fail because the architecture's aren't compatible. THis
patch simply passes `-mcpu` by default if it was specified. Should be a
no-op if it's not actually used.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153909

Files:
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/test/Driver/amdgpu-toolchain.c


Index: clang/test/Driver/amdgpu-toolchain.c
===
--- clang/test/Driver/amdgpu-toolchain.c
+++ clang/test/Driver/amdgpu-toolchain.c
@@ -11,6 +11,8 @@
 // DWARF_VER: "-dwarf-version=5"
 
 // RUN: %clang -### --target=amdgcn-amd-amdhsa -mcpu=gfx906 -nogpulib \
-// RUN:   -L. -flto -fconvergent-functions %s 2>&1 | FileCheck 
-check-prefix=LTO %s
+// RUN:   -L. -flto -fconvergent-functions %s 2>&1 | FileCheck 
-check-prefixes=LTO,MCPU %s
+// RUN: %clang -### --target=amdgcn-amd-amdhsa -mcpu=gfx906 -nogpulib \
+// RUN:   -L. -fconvergent-functions %s 2>&1 | FileCheck -check-prefix=MCPU %s
 // LTO: clang{{.*}} "-flto=full"{{.*}}"-fconvergent-functions"
-// LTO: ld.lld{{.*}}"-L."{{.*}}"-plugin-opt=mcpu=gfx906"
+// MCPU: ld.lld{{.*}}"-L."{{.*}}"-plugin-opt=mcpu=gfx906"
Index: clang/lib/Driver/ToolChains/AMDGPU.cpp
===
--- clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -545,6 +545,9 @@
   if (C.getDriver().isUsingLTO())
 addLTOOptions(getToolChain(), Args, CmdArgs, Output, Inputs[0],
   C.getDriver().getLTOMode() == LTOK_Thin);
+  else if (Args.hasArg(options::OPT_mcpu_EQ))
+CmdArgs.push_back(Args.MakeArgString(
+"-plugin-opt=mcpu=" + Args.getLastArgValue(options::OPT_mcpu_EQ)));
   CmdArgs.push_back("--no-undefined");
   CmdArgs.push_back("-shared");
   CmdArgs.push_back("-o");


Index: clang/test/Driver/amdgpu-toolchain.c
===
--- clang/test/Driver/amdgpu-toolchain.c
+++ clang/test/Driver/amdgpu-toolchain.c
@@ -11,6 +11,8 @@
 // DWARF_VER: "-dwarf-version=5"
 
 // RUN: %clang -### --target=amdgcn-amd-amdhsa -mcpu=gfx906 -nogpulib \
-// RUN:   -L. -flto -fconvergent-functions %s 2>&1 | FileCheck -check-prefix=LTO %s
+// RUN:   -L. -flto -fconvergent-functions %s 2>&1 | FileCheck -check-prefixes=LTO,MCPU %s
+// RUN: %clang -### --target=amdgcn-amd-amdhsa -mcpu=gfx906 -nogpulib \
+// RUN:   -L. -fconvergent-functions %s 2>&1 | FileCheck -check-prefix=MCPU %s
 // LTO: clang{{.*}} "-flto=full"{{.*}}"-fconvergent-functions"
-// LTO: ld.lld{{.*}}"-L."{{.*}}"-plugin-opt=mcpu=gfx906"
+// MCPU: ld.lld{{.*}}"-L."{{.*}}"-plugin-opt=mcpu=gfx906"
Index: clang/lib/Driver/ToolChains/AMDGPU.cpp
===
--- clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -545,6 +545,9 @@
   if (C.getDriver().isUsingLTO())
 addLTOOptions(getToolChain(), Args, CmdArgs, Output, Inputs[0],
   C.getDriver().getLTOMode() == LTOK_Thin);
+  else if (Args.hasArg(options::OPT_mcpu_EQ))
+CmdArgs.push_back(Args.MakeArgString(
+"-plugin-opt=mcpu=" + Args.getLastArgValue(options::OPT_mcpu_EQ)));
   CmdArgs.push_back("--no-undefined");
   CmdArgs.push_back("-shared");
   CmdArgs.push_back("-o");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153857: [clang] Fix new-expression with elaborated-type-specifier

2023-06-27 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

> With code like struct A {}; , the expressions 
> were parsed as redefining struct A and failed. However, as clarified by 
> CWG2141, new-expression cannot define a type, so both these expressions 
> should be considered as valid references to the previously declared struct A.

Sure, thank you and sorry for the confusion! I should have added `struct A {};` 
to the example in the first place.

> I think the root cause of that issue is that we don't implement DR2141 
> (https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#2141); are you 
> intending to cover that DR? If so, there should be tests added to 
> clang/test/CXX/drs/dr21xx.cpp.

The original intent was to fix the bug because I wasn't confident enough that 
I'll be able to cover all possible cases by the tests. Will the simple examples 
that I'm already adding to clang/test/Parser/cxx11-type-specifier.cpp test be 
enough?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153857/new/

https://reviews.llvm.org/D153857

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


[PATCH] D151963: [clang][NFC] Remove trailing whitespaces and enforce it in lib, include and docs

2023-06-27 Thread Louis Dionne via Phabricator via cfe-commits
ldionne added inline comments.



Comment at: libcxx/utils/ci/buildkite-pipeline-clang.yml:20-31
+  - label: "Format"
+commands:
+  - "! grep -rnI '[[:blank:]]$' clang/lib clang/include clang/docs || 
false"
+
+agents:
+  queue: "libcxx-builders"
+  os: "linux"

Something in here broke the Clang CI. See for example 
https://buildkite.com/llvm-project/libcxx-ci/builds/27050#0188fe23-c359-4a1d-8d10-f0fb966f142e.

It's actually interesting, now the libc++ CI is lightning fast since we're not 
sharing our resources anymore. I'll follow-up on that, I never expected it to 
make such a huge difference.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151963/new/

https://reviews.llvm.org/D151963

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


[PATCH] D153908: [dataflow] Use consistent, symmetrical, non-mutating erased signature for join()

2023-06-27 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added reviewers: ymandel, xazax.hun.
Herald added a subscriber: martong.
Herald added a reviewer: NoQ.
Herald added a project: All.
sammccall requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Mutating join() isn't used and so appears to be an anti-optimization.
Having Lattice vs Environment inconsistent is awkward, particularly when trying
to minimize copies while joining.

This patch eliminates the difference, but doesn't actually change the signature
of join on concrete lattice types (as that's a breaking change).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153908

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp

Index: clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
===
--- clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -227,50 +227,39 @@
 // Avoids unneccesary copies of the environment.
 class JoinedStateBuilder {
   AnalysisContext 
-  std::optional OwnedState;
-  // Points either to OwnedState, an external Environment, or nothing.
-  const TypeErasedDataflowAnalysisState *CurrentState = nullptr;
+  std::vector All;
+  std::deque Owned;
+
+  TypeErasedDataflowAnalysisState
+  join(const TypeErasedDataflowAnalysisState ,
+   const TypeErasedDataflowAnalysisState ) {
+return {AC.Analysis.joinTypeErased(L.Lattice, R.Lattice),
+Environment::join(L.Env, R.Env, AC.Analysis)};
+  }
 
 public:
   JoinedStateBuilder(AnalysisContext ) : AC(AC) {}
 
   void addOwned(TypeErasedDataflowAnalysisState State) {
-if (!CurrentState) {
-  OwnedState = std::move(State);
-  CurrentState = &*OwnedState;
-} else if (!OwnedState) {
-  OwnedState.emplace(std::move(CurrentState->Lattice),
- CurrentState->Env.join(State.Env, AC.Analysis));
-  AC.Analysis.joinTypeErased(OwnedState->Lattice, State.Lattice);
-} else {
-  OwnedState->Env = CurrentState->Env.join(State.Env, AC.Analysis);
-  AC.Analysis.joinTypeErased(OwnedState->Lattice, State.Lattice);
-}
+Owned.push_back(std::move(State));
+All.push_back(());
   }
   void addUnowned(const TypeErasedDataflowAnalysisState ) {
-if (!CurrentState) {
-  CurrentState = 
-} else if (!OwnedState) {
-  OwnedState.emplace(CurrentState->Lattice,
- CurrentState->Env.join(State.Env, AC.Analysis));
-  AC.Analysis.joinTypeErased(OwnedState->Lattice, State.Lattice);
-} else {
-  OwnedState->Env = CurrentState->Env.join(State.Env, AC.Analysis);
-  AC.Analysis.joinTypeErased(OwnedState->Lattice, State.Lattice);
-}
+All.push_back();
   }
   TypeErasedDataflowAnalysisState take() && {
-if (!OwnedState) {
-  if (CurrentState)
-OwnedState.emplace(CurrentState->Lattice, CurrentState->Env.fork());
-  else
-// FIXME: Consider passing `Block` to Analysis.typeErasedInitialElement
-// to enable building analyses like computation of dominators that
-// initialize the state of each basic block differently.
-OwnedState.emplace(AC.Analysis.typeErasedInitialElement(),
-   AC.InitEnv.fork());
-}
-return std::move(*OwnedState);
+if (All.empty())
+  // FIXME: Consider passing `Block` to Analysis.typeErasedInitialElement
+  // to enable building analyses like computation of dominators that
+  // initialize the state of each basic block differently.
+  return {AC.Analysis.typeErasedInitialElement(), AC.InitEnv.fork()};
+if (All.size() == 1)
+  return Owned.empty() ? All.front()->fork() : std::move(Owned.front());
+
+auto Result = join(*All[0], *All[1]);
+for (unsigned I = 2; I < All.size(); ++I)
+  Result = join(Result, *All[I]);
+return Result;
   }
 };
 
Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -526,18 +526,18 @@
   return Effect;
 }
 
-Environment Environment::join(const Environment ,
-  Environment::ValueModel ) const {
-  assert(DACtx == Other.DACtx);
-  assert(ThisPointeeLoc == Other.ThisPointeeLoc);
-  assert(CallStack == Other.CallStack);
+Environment Environment::join(const Environment , const Environment ,
+  Environment::ValueModel ) {
+  assert(EnvA.DACtx == EnvB.DACtx);
+  

[PATCH] D153536: [Clang] Implement P2169 A nice placeholder with no name

2023-06-27 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 535089.
cor3ntin marked 2 inline comments as done.
cor3ntin added a comment.

Address some of Aarons comments before getting rid of the bit in Decl


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153536/new/

https://reviews.llvm.org/D153536

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/Decl.h
  clang/include/clang/AST/DeclBase.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/IdentifierTable.h
  clang/include/clang/Sema/Lookup.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaLookup.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/test/Lexer/cxx-features.cpp
  clang/test/Lexer/unicode.c
  clang/test/SemaCXX/cxx2c-placeholder-vars.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -145,7 +145,7 @@
  
   Placeholder variables with no name
   https://wg21.link/P2169R4;>P2169R4
-  No
+  Clang 17
  
 
 
Index: clang/test/SemaCXX/cxx2c-placeholder-vars.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx2c-placeholder-vars.cpp
@@ -0,0 +1,98 @@
+// RUN: %clang -cc1 -fsyntax-only -verify -std=c++2c -Wunused-parameter -Wunused %s
+
+void static_var() {
+static int _; // expected-note {{previous definition is here}} \
+  // expected-note {{candidate}}
+static int _; // expected-error {{redefinition of '_'}}
+int _;// expected-warning {{placeholder variables are a C++2c extension}} \
+  // expected-note {{candidate}}
+_++; // expected-error{{reference to '_' is ambiguous}}
+}
+
+void static_var_2() {
+int _; // expected-note {{previous definition is here}}
+static int _; // expected-error {{redefinition of '_'}}
+}
+
+void bindings() {
+int arr[4] = {0, 1, 2, 3};
+auto [_, _, _, _] = arr; // expected-warning 3{{placeholder variables are a C++2c extension}} \
+ // expected-note 4{{placeholder declared here}}
+_ == 42; // expected-error {{referring to placeholder '_' is not allowed}}
+{
+auto [_, a, b, c] = arr;
+auto [_, _, _, _] = arr; // expected-warning 4{{placeholder variables are a C++2c extension}}
+}
+}
+
+void lambda() {
+(void)[_ = 0, _ = 1] { // expected-warning {{placeholder variables are a C++2c extension}} \
+   // expected-note 4{{placeholder declared here}} \\
+   // expected-warning 2{{placeholder variable has no side effect}}
+(void)_++; // expected-error {{referring to placeholder '_' is not allowed}}
+};
+}
+
+namespace global_var {
+int _; // expected-note {{previous definition is here}}
+int _; // expected-error {{redefinition of '_'}}
+}
+
+namespace global_fun {
+void _();
+void _();
+
+void _() {} // expected-note {{previous definition is here}}
+void _() {} // expected-error {{redefinition of '_'}}
+void _(int){};
+}
+
+void extern_test() {
+extern int _;
+extern int _; // expected-note {{candidate}}
+int _; //expected-note {{candidate}}
+_++; // expected-error {{reference to '_' is ambiguous}}
+}
+
+
+struct Members {
+int _; // expected-note {{placeholder declared here}}
+int _; // expected-warning{{placeholder variables are a C++2c extension}} \
+   // expected-note {{placeholder declared here}}
+void f() {
+_++; // expected-error {{referring to placeholder '_' is not allowed}}
+}
+};
+
+namespace using_ {
+int _; // expected-note {{target of using declaration}}
+void f() {
+int _; // expected-note {{conflicting declaration}}
+_ = 0;
+using using_::_; // expected-error {{target of using declaration conflicts with declaration already in scope}}
+}
+}
+
+
+void call(int);
+void test_param(int _) {}
+void test_params(int _, int _); // expected-error {{redefinition of parameter '_'}} \
+// expected-note {{previous declaration is here}}
+
+template  // expected-error {{declaration of '_' shadows template parameter}} \
+  // expected-note  {{template parameter is declared here}}
+auto i = 0;
+
+template 
+concept C = requires(T _, T _) {  // expected-error {{redefinition of parameter '_'}} \
+// expected-note {{previous declaration is here}}
+T{};
+};
+
+struct S {
+int a;
+};
+
+void f(S a, S _) { // expected-warning {{unused parameter 'a'}}
+
+}
Index: clang/test/Lexer/unicode.c
===
--- 

[PATCH] D153860: [clang-tidy] Fix modernize-use-std-print check when return value used

2023-06-27 Thread Douglas Yung via Phabricator via cfe-commits
dyung added a comment.

@mikecrowe Your change is causing a test failure on the PS4 linux and PS5 
Windows build bots. Can you take a look and fix or revert if you need time to 
investigate?

https://lab.llvm.org/buildbot/#/builders/139/builds/43856
https://lab.llvm.org/buildbot/#/builders/216/builds/23017


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153860/new/

https://reviews.llvm.org/D153860

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


[PATCH] D153536: [Clang] Implement P2169 A nice placeholder with no name

2023-06-27 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin marked 14 inline comments as done.
cor3ntin added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:135-136
 - Compiler flags ``-std=c++2c`` and ``-std=gnu++2c`` have been added for 
experimental C++2c implementation work.
+- Implemented `P2169R4: A nice placeholder with no name 
`_. This allows to use `_`
+  as a variable name multiple times in the same scope and is supported in all 
C++ language modes as an extension.
 

aaron.ballman wrote:
> Should we consider adding this as an extension to C? It would be conforming 
> there as well because it wouldn't change the behavior of any correct C code, 
> right?
Maybe we should consult WG14 first?
It's of very questionable usefulness without structured bindings and 
destructors.



Comment at: clang/include/clang/AST/DeclBase.h:340-342
+  /// Whether this declaration denotes a placeholder that can be
+  /// redefined in the same scope.
+  unsigned IsPlaceholder : 1;

aaron.ballman wrote:
> This seems a bit heavy to put on every `Decl`, it only matters for 
> declarations with names, right? Should this be on `NamedDecl` instead? And 
> should it be using terminology like "name independent"?
> 
> Actually, do we need this bit at all? Would it work for `NamedDecl` to have a 
> function that returns whether the declaration name is `_` or not? Oh, I 
> suppose we can't get away with that because `void _(int x);` does not 
> introduce a placeholder identifier but a regular one, right?
I think you made me realize we can probably compute that completely without 
using bits. Oups.
It would certainly simplify things. I'll investigate!



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:6589
+def err_using_placeholder_variable : Error<
+  "referring to placeholder '_' is not allowed">;
+def note_reference_placeholder : Note<

cjdb wrote:
> aaron.ballman wrote:
> > I don't think this helps the user understand what's wrong with their code, 
> > especially given the somewhat odd language rules around the feature. How 
> > about: `ambiguous reference to multiply-defined placeholder '_'` or 
> > something along those lines? Then the note can show the previous 
> > declarations of the placeholders that are in scope? e.g.,
> > ```
> > void g() {
> > int _; // note: placeholder declared here
> > _ = 0;
> > int _; // note: placeholder declared here
> > _ = 0; // error: `ambiguous reference to multiply-defined placeholder '_'`
> > }
> > ```
> > CC @cjdb 
> Agreed. I'd suggest a rewording though: I took "multiply" to mean the maths 
> term until completing the sentence, rather than its alternative meaning of 
> "multiple instances" (which is more or less the same meaning, but "multiply" 
> maps to the `x * y` operation for me).
> 
> Perhaps `ambiguous reference to placeholder '_', which has multiple 
> definitions`? Not sold on that being the best wording, but it does avoid the 
> hardcoded-word-at-8yo problem :)
@cjdb I like your suggestion. maybe "which is defined multiple times?"  - 
pedantically a bunch of things  have been defined once each, it's not a 
redefinition of the same entity in the c++ sense



Comment at: clang/lib/Sema/SemaDecl.cpp:2171-2172
 
+  if (VD->isPlaceholderVar())
+return;
+

aaron.ballman wrote:
> What's the rationale here? I know the standard has a recommended practice, 
> but I don't see why that should apply to the case where the user assigns a 
> value to the placeholder but never references it otherwise.
The intent is that this behave like `[[maybe_unused]]`



Comment at: clang/test/SemaCXX/cxx2c-placeholder-vars.cpp:31
+   // expected-note 4{{placeholder declared here}} \\
+   // expected-warning 2{{placeholder variable has no 
side effect}}
+(void)_++; // expected-error {{referring to placeholder '_' is not 
allowed}}

aaron.ballman wrote:
> I don't understand what this diagnostic is trying to tell me, can you explain 
> a bit more?
The no side effect one?
You are assigning something that has no side effect to something that you may 
never be able to name, so the whole thing is likely dead code.
I welcome improvements suggestions



Comment at: clang/test/SemaCXX/cxx2c-placeholder-vars.cpp:79
+void test_param(int _) {}
+void test_params(int _, int _); // expected-error {{redefinition of parameter 
'_'}} \
+// expected-note {{previous declaration is 
here}}

aaron.ballman wrote:
> Weird.. is this expected? You can have two variables named `_` in block 
> scope, but you can't have two parameters named `_` despite them inhabiting 
> the same block scope?
Yes, CWG decided against having it in parameter declarations, because otherwise 
we'd need them in template parameters which we didn't want to do.
And it would 

[PATCH] D153906: [clang] Allow disassembly of multi-module bitcode files

2023-06-27 Thread Matthew Voss via Phabricator via cfe-commits
ormris created this revision.
ormris added reviewers: efriedma, rjmccall, MaskRay, aaron.ballman.
Herald added subscribers: steven_wu, hiraditya.
Herald added a project: All.
ormris requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Clang currently exits with an error message if asked to disassemble a
multi-module bitcode file. This might be confusing to some who are not
familiar with bitcode formats. In addition, multi-module bitcode files
are reasonably common, since they enable desired features. This patch
makes clang's behavior consistent for all common bitcode files.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153906

Files:
  clang/include/clang/CodeGen/CodeGenAction.h
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/test/Frontend/split-lto-ir-support.cpp

Index: clang/test/Frontend/split-lto-ir-support.cpp
===
--- /dev/null
+++ clang/test/Frontend/split-lto-ir-support.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang -O0 -Xclang -mconstructor-aliases -c -flto=thin -Xclang -fsplit-lto-unit -ffunction-sections %s -o %t0.bc
+// RUN: rm -rf %t1.d && mkdir -p %t1.d
+// RUN: %clang -S -emit-llvm %t0.bc -o %t1.d/split-lto-ir-support.ll
+// RUN: %clang -S %t1.d/split-lto-ir-support.0.ll %t1.d/split-lto-ir-support.1.ll
+// RUN: FileCheck c(0);
+}
Index: clang/lib/CodeGen/CodeGenAction.cpp
===
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -1107,26 +1107,59 @@
   return std::move(Result);
 }
 
-std::unique_ptr
+std::vector>
 CodeGenAction::loadModule(MemoryBufferRef MBRef) {
   CompilerInstance  = getCompilerInstance();
   SourceManager  = CI.getSourceManager();
 
+  std::vector> Result;
+
+  if (!llvm::isBitcode((const unsigned char *)MBRef.getBufferStart(),
+   (const unsigned char *)MBRef.getBufferEnd())) {
+llvm::SMDiagnostic Err;
+std::unique_ptr M = parseIR(MBRef, Err, *VMContext);
+if (!M) {
+  // Translate from the diagnostic info to the SourceManager location if
+  // available.
+  // TODO: Unify this with ConvertBackendLocation()
+  SourceLocation Loc;
+  if (Err.getLineNo() > 0) {
+assert(Err.getColumnNo() >= 0);
+Loc = SM.translateFileLineCol(SM.getFileEntryForID(SM.getMainFileID()),
+  Err.getLineNo(), Err.getColumnNo() + 1);
+  }
+
+  // Strip off a leading diagnostic code if there is one.
+  StringRef Msg = Err.getMessage();
+  if (Msg.startswith("error: "))
+Msg = Msg.substr(7);
+
+  unsigned DiagID =
+  CI.getDiagnostics().getCustomDiagID(DiagnosticsEngine::Error, "%0");
+
+  CI.getDiagnostics().Report(Loc, DiagID) << Msg;
+  return {};
+}
+
+Result.push_back(std::move(M));
+return Result;
+  }
+
+  auto DiagErrors = [&](Error E) -> std::vector> {
+unsigned DiagID =
+CI.getDiagnostics().getCustomDiagID(DiagnosticsEngine::Error, "%0");
+handleAllErrors(std::move(E), [&](ErrorInfoBase ) {
+  CI.getDiagnostics().Report(DiagID) << EIB.message();
+});
+return {};
+  };
+
   // For ThinLTO backend invocations, ensure that the context
   // merges types based on ODR identifiers. We also need to read
   // the correct module out of a multi-module bitcode file.
   if (!CI.getCodeGenOpts().ThinLTOIndexFile.empty()) {
 VMContext->enableDebugTypeODRUniquing();
 
-auto DiagErrors = [&](Error E) -> std::unique_ptr {
-  unsigned DiagID =
-  CI.getDiagnostics().getCustomDiagID(DiagnosticsEngine::Error, "%0");
-  handleAllErrors(std::move(E), [&](ErrorInfoBase ) {
-CI.getDiagnostics().Report(DiagID) << EIB.message();
-  });
-  return {};
-};
-
 Expected> BMsOrErr = getBitcodeModuleList(MBRef);
 if (!BMsOrErr)
   return DiagErrors(BMsOrErr.takeError());
@@ -1138,43 +1171,33 @@
 if (!Bm) {
   auto M = std::make_unique("empty", *VMContext);
   M->setTargetTriple(CI.getTargetOpts().Triple);
-  return M;
+  Result.push_back(std::move(M));
+  return Result;
 }
 Expected> MOrErr =
 Bm->parseModule(*VMContext);
 if (!MOrErr)
   return DiagErrors(MOrErr.takeError());
-return std::move(*MOrErr);
+Result.push_back(std::move(MOrErr.get()));
+return Result;
   }
 
   // Load bitcode modules to link with, if we need to.
   if (loadLinkModules(CI))
-return nullptr;
-
-  llvm::SMDiagnostic Err;
-  if (std::unique_ptr M = parseIR(MBRef, Err, *VMContext))
-return M;
-
-  // Translate from the diagnostic info to the SourceManager location if
-  // available.
-  // TODO: Unify this with ConvertBackendLocation()
-  SourceLocation Loc;
-  if (Err.getLineNo() > 0) {
-assert(Err.getColumnNo() >= 0);
-Loc = SM.translateFileLineCol(SM.getFileEntryForID(SM.getMainFileID()),
-

[clang] 1e010c5 - Reland "[dataflow] avoid more accidental copies of Environment"

2023-06-27 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2023-06-27T20:31:40+02:00
New Revision: 1e010c5c4fae43c52d6f5f1c8e8920c26bcc6cc7

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

LOG: Reland "[dataflow] avoid more accidental copies of Environment"

This reverts commit fb13d027eae405a7be96fd7da0d72422e48a0719.

Added: 


Modified: 
clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp

Removed: 




diff  --git a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
index 15e63c3d91a32..8494bc197cb25 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
@@ -226,9 +226,8 @@ class Environment {
   /// Requirements:
   ///
   ///  `Other` and `this` must use the same `DataflowAnalysisContext`.
-  LatticeJoinEffect join(const Environment ,
- Environment::ValueModel );
-
+  Environment join(const Environment ,
+   Environment::ValueModel ) const;
 
   /// Widens the environment point-wise, using `PrevEnv` as needed to inform 
the
   /// approximation.

diff  --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index b2e67651626d5..3296fee39dd13 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -526,14 +526,12 @@ LatticeJoinEffect Environment::widen(const Environment 
,
   return Effect;
 }
 
-LatticeJoinEffect Environment::join(const Environment ,
-Environment::ValueModel ) {
+Environment Environment::join(const Environment ,
+  Environment::ValueModel ) const {
   assert(DACtx == Other.DACtx);
   assert(ThisPointeeLoc == Other.ThisPointeeLoc);
   assert(CallStack == Other.CallStack);
 
-  auto Effect = LatticeJoinEffect::Unchanged;
-
   Environment JoinedEnv(*DACtx);
 
   JoinedEnv.CallStack = CallStack;
@@ -558,10 +556,8 @@ LatticeJoinEffect Environment::join(const Environment 
,
 assert(Func != nullptr);
 if (Value *MergedVal =
 mergeDistinctValues(Func->getReturnType(), *ReturnVal, *this,
-*Other.ReturnVal, Other, JoinedEnv, Model)) {
+*Other.ReturnVal, Other, JoinedEnv, Model))
   JoinedEnv.ReturnVal = MergedVal;
-  Effect = LatticeJoinEffect::Changed;
-}
   }
 
   if (ReturnLoc == Other.ReturnLoc)
@@ -574,19 +570,12 @@ LatticeJoinEffect Environment::join(const Environment 
,
   // `DeclToLoc` and `Other.DeclToLoc` that map the same declaration to
   // 
diff erent storage locations.
   JoinedEnv.DeclToLoc = intersectDenseMaps(DeclToLoc, Other.DeclToLoc);
-  if (DeclToLoc.size() != JoinedEnv.DeclToLoc.size())
-Effect = LatticeJoinEffect::Changed;
 
   JoinedEnv.ExprToLoc = intersectDenseMaps(ExprToLoc, Other.ExprToLoc);
-  if (ExprToLoc.size() != JoinedEnv.ExprToLoc.size())
-Effect = LatticeJoinEffect::Changed;
 
   JoinedEnv.MemberLocToStruct =
   intersectDenseMaps(MemberLocToStruct, Other.MemberLocToStruct);
-  if (MemberLocToStruct.size() != JoinedEnv.MemberLocToStruct.size())
-Effect = LatticeJoinEffect::Changed;
 
-  // FIXME: set `Effect` as needed.
   // FIXME: update join to detect backedges and simplify the flow condition
   // accordingly.
   JoinedEnv.FlowConditionToken = >joinFlowConditions(
@@ -613,15 +602,10 @@ LatticeJoinEffect Environment::join(const Environment 
,
 mergeDistinctValues(Loc->getType(), *Val, *this, *It->second, 
Other,
 JoinedEnv, Model)) {
   JoinedEnv.LocToVal.insert({Loc, MergedVal});
-  Effect = LatticeJoinEffect::Changed;
 }
   }
-  if (LocToVal.size() != JoinedEnv.LocToVal.size())
-Effect = LatticeJoinEffect::Changed;
 
-  *this = std::move(JoinedEnv);
-
-  return Effect;
+  return JoinedEnv;
 }
 
 StorageLocation ::createStorageLocation(QualType Type) {

diff  --git a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp 
b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
index 1f23b6cf238f7..880ad6fa8bcf6 100644
--- a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -221,6 +221,59 @@ class PrettyStackTraceCFGElement : public 
llvm::PrettyStackTraceEntry {
   const char *Message;
 };
 
+// Builds a joined TypeErasedDataflowAnalysisState from 0 or more sources,
+// each of which may be owned (built as part of the 

[PATCH] D144911: adding bf16 support to NVPTX

2023-06-27 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

@bkramer Ben, PTAL when you get a chance.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144911/new/

https://reviews.llvm.org/D144911

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


[PATCH] D153375: [Clang] Fix incorrect use of direct initialization with copy initialization

2023-06-27 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

ping


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153375/new/

https://reviews.llvm.org/D153375

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


[PATCH] D153493: [dataflow] avoid more accidental copies of Environment

2023-06-27 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Thanks! I'll land this to eliminate the variables, and follow up with trying to 
simplify join().

In D153493#4450440 , @ymandel wrote:

> In D153493#4450358 , @sammccall 
> wrote:
>
>>> I realize the complexity is frustrating, but I don't see how that's related 
>>> to the issue here. The complexity of the `JoinedStateBuilder` is caused by 
>>> the desire to minimize copies. The multiple cases come directly from the 
>>> algorithm itself, most particularly that we may or may not be in an initial 
>>> state, and the previous block may or may not have an environment we care 
>>> about. At least, that is the specific issue I'm concerned with.
>>
>> We have 9 state transitions (3 states x 3 operations). Each would be less 
>> than half as complicated if it didn't have to deal with Lattice's join being 
>> mutating and Environment's being non-mutating.
>>
>> I believe further simplifications are possible (essentially: back at the 
>> callsite track `vector All` plus `deque Owned` for 
>> owned copies, special case `All.size() == 0` and `All.size() == 1` and 
>> otherwise `joinVec(All)`.
>> However with Lattice's mutating join involved this no longer works, and 
>> after addressing that it's no longer simpler.
>
> I'm pretty sure I agree on all of this, please document it somewhere (file an 
> Issue in the github tracker?). FWIW, I think mutating join was a case of 
> premature optimization gone bad

Thanks - I will file a bug if it turns out not to be trivial, but I think it 
probably is trivial to fix so I'll give that a shot first.

> and ultimately the builtin lattice should not be built in at all -- it should 
> exist outside the core and be just another client.

Yeah, this looks like a bigger change :-)

>>> "join with InitEnv" should reduce to the identity function, so if its not, 
>>> that feels like a problem we're sweeping under the rug.
>>
>> Only in a mathematical sense - in reality humans need to read these SAT 
>> systems, and we're using a solver that can't perform that reduction.
>
> I think we're talking past each other (and actually agreeing), sorry. To be 
> clear, I don't mean that as a criticism of this change -- I think you've hit 
> an important point and fixing it might make this simpler. I totally agree 
> about SAT systems, and the solver, etc. But, I'm saying that it shouldn't 
> come to that. I think the Environment join operation is broken if  
> `join(InitEnv, E) != E`. I'm asking whether we can reduce (some) complexity 
> by fixing that.  From your earlier point, there are more problems, but I want 
> to focus on this particular one in case solving it makes other things easier.

Ah, got it, thanks!
I think if we can change Environment (e.g. dropping FC tokens) so this just 
falls out, and it makes sense for other reasons, that'd be great.
I'm not a big fan of special-casing InitEnv somehow though.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153493/new/

https://reviews.llvm.org/D153493

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


[PATCH] D105759: Implement P2361 Unevaluated string literals

2023-06-27 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 535073.
cor3ntin added a comment.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Parse attribute as unevaluated string if they 
are declare StringLiteralArgument in the Attr.td file.

WIP

@aaron.ballman Do we agree on direction before I 
fix the remaining broken tests?

There are a few limitations, which I'm hoping not to fix there

- It doesn't support variadic string arguments
- checking the type of argument ahead of time seems like a good idea overall, 
maybe we want to expand that system?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105759/new/

https://reviews.llvm.org/D105759

Files:
  clang-tools-extra/test/clang-tidy/checkers/modernize/unary-static-assert.cpp
  clang/include/clang/AST/Expr.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Lex/LiteralSupport.h
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/ParsedAttr.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Expr.cpp
  clang/lib/Lex/LiteralSupport.cpp
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/lib/Lex/Pragma.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/test/CXX/dcl.dcl/dcl.link/p2.cpp
  clang/test/CXX/dcl.dcl/p4-0x.cpp
  clang/test/FixIt/fixit-static-assert.cpp
  clang/test/Parser/cxx-attributes.cpp
  clang/test/Parser/cxx0x-attributes.cpp
  clang/test/Sema/MicrosoftExtensions.c
  clang/test/Sema/attr-btf_type_tag.c
  clang/test/Sema/attr-capabilities.c
  clang/test/SemaCXX/static-assert.cpp
  clang/utils/TableGen/ClangAttrEmitter.cpp
  llvm/cmake/modules/HandleLLVMOptions.cmake

Index: llvm/cmake/modules/HandleLLVMOptions.cmake
===
--- llvm/cmake/modules/HandleLLVMOptions.cmake
+++ llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -605,7 +605,7 @@
   # crash if LLVM is built with GCC and LTO enabled (#57740).  Until
   # these bugs are fixed, we need to disable dead store eliminations
   # based on object lifetime.
-  add_flag_if_supported("-fno-lifetime-dse" CMAKE_CXX_FLAGS)
+  # add_flag_if_supported("-fno-lifetime-dse" CMAKE_CXX_FLAGS)
 endif ( LLVM_COMPILER_IS_GCC_COMPATIBLE )
 
 # Modules enablement for GCC-compatible compilers:
Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -2280,6 +2280,14 @@
 .Default(false);
 }
 
+static bool isStringLiteralArgument(const Record *Arg) {
+  return !Arg->getSuperClasses().empty() &&
+ llvm::StringSwitch(
+ Arg->getSuperClasses().back().first->getName())
+ .Case("StringArgument", true)
+ .Default(false);
+}
+
 static bool isVariadicIdentifierArgument(const Record *Arg) {
   return !Arg->getSuperClasses().empty() &&
  llvm::StringSwitch(
@@ -2317,6 +2325,27 @@
   OS << "#endif // CLANG_ATTR_VARIADIC_IDENTIFIER_ARG_LIST\n\n";
 }
 
+// Emits the list of arguments that shoulkd be parsed as unevaluated string
+// literals for each attributes
+static void emitClangAttrUnevaluatedStringLiteralList(RecordKeeper ,
+  raw_ostream ) {
+  OS << "#if defined(CLANG_ATTR_STRING_LITERAL_ARG_LIST)\n";
+  std::vector Attrs = Records.getAllDerivedDefinitions("Attr");
+  for (const auto *Attr : Attrs) {
+std::vector Args = Attr->getValueAsListOfDefs("Args");
+uint32_t Bits = 0;
+for (uint32_t N = 0; N < Args.size(); N++)
+  Bits |= (isStringLiteralArgument(Args[N]) << N);
+if (!Bits)
+  continue;
+// All these spellings have at least one string literal has argument.
+forEachUniqueSpelling(*Attr, [&](const FlattenedSpelling ) {
+  OS << ".Case(\"" << S.name() << "\", " << Bits << ")\n";
+});
+  }
+  OS << "#endif // CLANG_ATTR_STRING_LITERAL_ARG_LIST\n\n";
+}
+
 // Emits the first-argument-is-identifier property for attributes.
 static void emitClangAttrIdentifierArgList(RecordKeeper , raw_ostream ) {
   OS << "#if defined(CLANG_ATTR_IDENTIFIER_ARG_LIST)\n";
@@ -4615,6 +4644,7 @@
   emitSourceFileHeader("Parser-related llvm::StringSwitch cases", OS);
   emitClangAttrArgContextList(Records, OS);
   emitClangAttrIdentifierArgList(Records, OS);
+  emitClangAttrUnevaluatedStringLiteralList(Records, OS);
   emitClangAttrVariadicIdentifierArgList(Records, OS);
   emitClangAttrThisIsaIdentifierArgList(Records, OS);
   emitClangAttrAcceptsExprPack(Records, OS);
Index: clang/test/SemaCXX/static-assert.cpp

[PATCH] D151820: [clang][WebAssembly] Fix __BIGGEST_ALIGNMENT__ under emscripten

2023-06-27 Thread Sam Clegg via Phabricator via cfe-commits
sbc100 added a comment.

OK to land this?  (With a provision that I will add something to the emscripten 
changelog?)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151820/new/

https://reviews.llvm.org/D151820

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


[PATCH] D153898: [DebugInfo] Enable debug info emission for extern variables in C++

2023-06-27 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added subscribers: MaskRay, dblaikie.
rnk added a comment.
This revision is now accepted and ready to land.

This seems reasonable to me, but I want to get a second opinion from @dblaikie 
and @maskray for some debug info and BPF perspective.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153898/new/

https://reviews.llvm.org/D153898

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


[PATCH] D153898: [DebugInfo] Enable debug info emission for extern variables in C++

2023-06-27 Thread Yuze Chi via Phabricator via cfe-commits
chiyuze created this revision.
chiyuze added a reviewer: rnk.
Herald added a project: All.
chiyuze requested review of this revision.
Herald added a project: clang.

Debug info emission for extern variables in C++ was previously disabled
when the functionality was added in https://reviews.llvm.org/D71818 and
originally in https://reviews.llvm.org/D70696, because there was no use
case. We are enabling it now, as we start to deploy BPF programs
compiled from C++, leveraging C++ features like templates to reduce code
complexity. This patch is required so that we can still use kconfig in
such BPF programs compiled from C++.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153898

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CodeGen/debug-info-extern-basic.cpp


Index: clang/test/CodeGen/debug-info-extern-basic.cpp
===
--- /dev/null
+++ clang/test/CodeGen/debug-info-extern-basic.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -x c++ -debug-info-kind=limited -triple bpf-linux-gnu 
-emit-llvm %s -o - | FileCheck %s
+
+namespace foo {
+
+template 
+struct S {
+  T x;
+};
+
+extern S s;
+
+int test(void) {
+  return s.x;
+}
+
+}  // namespace foo
+
+// CHECK: distinct !DIGlobalVariable(name: "s", scope: 
![[NAMESPACE:[0-9]+]],{{.*}} type: ![[STRUCT_TYPE:[0-9]+]], isLocal: false, 
isDefinition: false)
+// CHECK: ![[NAMESPACE]] = !DINamespace(name: "foo", scope: null)
+// CHECK: ![[STRUCT_TYPE]] = distinct !DICompositeType(tag: 
DW_TAG_structure_type, name: "S",{{.*}}size: 8, flags: 
DIFlagTypePassByValue, elements: ![[ELEMENT_TYPE:[0-9]+]], templateParams: 
![[TEMPLATE_TYPE:[0-9]+]], identifier: "_ZTSN3foo1SIcEE")
+// CHECK: ![[ELEMENT_TYPE]] = !{![[ELEMENT_TYPE:[0-9]+]]}
+// CHECK: ![[ELEMENT_TYPE]] = !DIDerivedType(tag: DW_TAG_member, name: 
"x",{{.*}} baseType: ![[BASE_TYPE:[0-9]+]], size: 8)
+// CHECK: ![[BASE_TYPE]] = !DIBasicType(name: "char", size: 8, encoding: 
DW_ATE_signed_char)
+// CHECK: ![[TEMPLATE_TYPE]] = !{![[TEMPLATE_TYPE:[0-9]+]]}
+// CHECK: ![[TEMPLATE_TYPE]] = !DITemplateTypeParameter(name: "T", type: 
![[BASE_TYPE]])
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -13773,7 +13773,7 @@
   }
 
   if (Context.getTargetInfo().allowDebugInfoForExternalRef() &&
-  !Var->isInvalidDecl() && !getLangOpts().CPlusPlus)
+  !Var->isInvalidDecl())
 ExternalDeclarations.push_back(Var);
 
   return;


Index: clang/test/CodeGen/debug-info-extern-basic.cpp
===
--- /dev/null
+++ clang/test/CodeGen/debug-info-extern-basic.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -x c++ -debug-info-kind=limited -triple bpf-linux-gnu -emit-llvm %s -o - | FileCheck %s
+
+namespace foo {
+
+template 
+struct S {
+  T x;
+};
+
+extern S s;
+
+int test(void) {
+  return s.x;
+}
+
+}  // namespace foo
+
+// CHECK: distinct !DIGlobalVariable(name: "s", scope: ![[NAMESPACE:[0-9]+]],{{.*}} type: ![[STRUCT_TYPE:[0-9]+]], isLocal: false, isDefinition: false)
+// CHECK: ![[NAMESPACE]] = !DINamespace(name: "foo", scope: null)
+// CHECK: ![[STRUCT_TYPE]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "S",{{.*}}size: 8, flags: DIFlagTypePassByValue, elements: ![[ELEMENT_TYPE:[0-9]+]], templateParams: ![[TEMPLATE_TYPE:[0-9]+]], identifier: "_ZTSN3foo1SIcEE")
+// CHECK: ![[ELEMENT_TYPE]] = !{![[ELEMENT_TYPE:[0-9]+]]}
+// CHECK: ![[ELEMENT_TYPE]] = !DIDerivedType(tag: DW_TAG_member, name: "x",{{.*}} baseType: ![[BASE_TYPE:[0-9]+]], size: 8)
+// CHECK: ![[BASE_TYPE]] = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
+// CHECK: ![[TEMPLATE_TYPE]] = !{![[TEMPLATE_TYPE:[0-9]+]]}
+// CHECK: ![[TEMPLATE_TYPE]] = !DITemplateTypeParameter(name: "T", type: ![[BASE_TYPE]])
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -13773,7 +13773,7 @@
   }
 
   if (Context.getTargetInfo().allowDebugInfoForExternalRef() &&
-  !Var->isInvalidDecl() && !getLangOpts().CPlusPlus)
+  !Var->isInvalidDecl())
 ExternalDeclarations.push_back(Var);
 
   return;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153857: [clang] Fix new-expression with elaborated-type-specifier

2023-06-27 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D153857#4453092 , @aaron.ballman 
wrote:

> Thank you for the fix! Just to clarify some things before diving into the 
> review too much... From the patch summary:
>
>   Expressions like
>   
>   new struct A {};
>   struct A* b = (1 == 1) ? new struct A : new struct A;
>   Were parsed as definitions of struct A and failed, however as clarified by
>   CWG2141 new-expression cannot define a type, so both these examples
>   should be considered as valid.
>
> There's a typo there -- the `new struct A{};` bit should be `struct A {};` 
> (dropping the `new`), right?
>
> I think the root cause of that issue is that we don't implement DR2141 
> (https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#2141); are you 
> intending to cover that DR? If so, there should be tests added to 
> clang/test/CXX/drs/dr21xx.cpp.

With offline help from @erichkeane and @shafik I realized where my confusion 
came from here. The patch summary presumes `struct A` is already defined in 
order for us to accept those code examples. I was thrown off by the DR and the 
original issue using `struct A {};` as the first relevant line in the code 
example and was thinking there was confusion as to how the DR was resolved.

How about the summary be changed to something along the lines of:

With code like `struct A {}; `, the expressions 
were parsed as redefining `struct A` and failed. However, as clarified by 
CWG2141, new-expression cannot define a type, so both these expressions should 
be considered as valid references to the previously declared `struct A`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153857/new/

https://reviews.llvm.org/D153857

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


[PATCH] D153589: [NFC] Initialize pointer fields and remove a needless null check.

2023-06-27 Thread Sindhu Chittireddy via Phabricator via cfe-commits
schittir updated this revision to Diff 535050.
schittir added a comment.

Remove stale comment about default constructor not initializing members in a 
useful way.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153589/new/

https://reviews.llvm.org/D153589

Files:
  clang/lib/Analysis/CFG.cpp
  clang/lib/CodeGen/CGObjCGNU.cpp
  clang/lib/Format/UnwrappedLineParser.h
  clang/lib/Lex/PPExpressions.cpp
  clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp


Index: clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -96,7 +96,7 @@
   mutable std::unique_ptr BT_Null, BT_Bounds, BT_Overlap,
   BT_NotCString, BT_AdditionOverflow, BT_UninitRead;
 
-  mutable const char *CurrentFunctionDescription;
+  mutable const char *CurrentFunctionDescription = nullptr;
 
 public:
   /// The filter is used to filter out the diagnostics which are not enabled by
Index: clang/lib/Lex/PPExpressions.cpp
===
--- clang/lib/Lex/PPExpressions.cpp
+++ clang/lib/Lex/PPExpressions.cpp
@@ -44,7 +44,7 @@
 /// conditional and the source range covered by it.
 class PPValue {
   SourceRange Range;
-  IdentifierInfo *II;
+  IdentifierInfo *II = nullptr;
 
 public:
   llvm::APSInt Val;
Index: clang/lib/Format/UnwrappedLineParser.h
===
--- clang/lib/Format/UnwrappedLineParser.h
+++ clang/lib/Format/UnwrappedLineParser.h
@@ -306,7 +306,7 @@
   // Since the next token might already be in a new unwrapped line, we need to
   // store the comments belonging to that token.
   SmallVector CommentsBeforeNextToken;
-  FormatToken *FormatTok;
+  FormatToken *FormatTok = nullptr;
   bool MustBreakBeforeNextToken;
 
   // The parsed lines. Only added to through \c CurrentLines.
Index: clang/lib/CodeGen/CGObjCGNU.cpp
===
--- clang/lib/CodeGen/CGObjCGNU.cpp
+++ clang/lib/CodeGen/CGObjCGNU.cpp
@@ -46,17 +46,13 @@
 /// types and the function declaration into a module if they're not used, and
 /// avoids constructing the type more than once if it's used more than once.
 class LazyRuntimeFunction {
-  CodeGenModule *CGM;
-  llvm::FunctionType *FTy;
-  const char *FunctionName;
-  llvm::FunctionCallee Function;
+  CodeGenModule *CGM = nullptr;
+  llvm::FunctionType *FTy = nullptr;
+  const char *FunctionName = nullptr;
+  llvm::FunctionCallee Function = nullptr;
 
 public:
-  /// Constructor leaves this class uninitialized, because it is intended to
-  /// be used as a field in another class and not all of the types that are
-  /// used as arguments will necessarily be available at construction time.
-  LazyRuntimeFunction()
-  : CGM(nullptr), FunctionName(nullptr), Function(nullptr) {}
+  LazyRuntimeFunction() = default;
 
   /// Initialises the lazy function with the name, return type, and the types
   /// of the arguments.
Index: clang/lib/Analysis/CFG.cpp
===
--- clang/lib/Analysis/CFG.cpp
+++ clang/lib/Analysis/CFG.cpp
@@ -4153,7 +4153,7 @@
   //   operand. [...]
   // We add only potentially evaluated statements to the block to avoid
   // CFG generation for unevaluated operands.
-  if (S && !S->isTypeDependent() && S->isPotentiallyEvaluated())
+  if (!S->isTypeDependent() && S->isPotentiallyEvaluated())
 return VisitChildren(S);
 
   // Return block without CFG for unevaluated operands.


Index: clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -96,7 +96,7 @@
   mutable std::unique_ptr BT_Null, BT_Bounds, BT_Overlap,
   BT_NotCString, BT_AdditionOverflow, BT_UninitRead;
 
-  mutable const char *CurrentFunctionDescription;
+  mutable const char *CurrentFunctionDescription = nullptr;
 
 public:
   /// The filter is used to filter out the diagnostics which are not enabled by
Index: clang/lib/Lex/PPExpressions.cpp
===
--- clang/lib/Lex/PPExpressions.cpp
+++ clang/lib/Lex/PPExpressions.cpp
@@ -44,7 +44,7 @@
 /// conditional and the source range covered by it.
 class PPValue {
   SourceRange Range;
-  IdentifierInfo *II;
+  IdentifierInfo *II = nullptr;
 
 public:
   llvm::APSInt Val;
Index: clang/lib/Format/UnwrappedLineParser.h
===
--- clang/lib/Format/UnwrappedLineParser.h
+++ clang/lib/Format/UnwrappedLineParser.h
@@ -306,7 +306,7 @@
   // Since the next token might already be in a new unwrapped line, we need to
   // store the comments belonging to that token.
   SmallVector 

[PATCH] D153589: [NFC] Initialize pointer fields and remove a needless null check.

2023-06-27 Thread Sindhu Chittireddy via Phabricator via cfe-commits
schittir added inline comments.



Comment at: clang/lib/Analysis/CFG.cpp:4156
   // CFG generation for unevaluated operands.
-  if (S && !S->isTypeDependent() && S->isPotentiallyEvaluated())
+  if (!S->isTypeDependent() && S->isPotentiallyEvaluated())
 return VisitChildren(S);

aaron.ballman wrote:
> schittir wrote:
> > schittir wrote:
> > > erichkeane wrote:
> > > > schittir wrote:
> > > > > erichkeane wrote:
> > > > > > schittir wrote:
> > > > > > > erichkeane wrote:
> > > > > > > > I get that we're counting on the dereference on 4145 to have 
> > > > > > > > made this check irrelevant, but are we sure that we KNOW that 
> > > > > > > > "S" is non-null here otherwise?  That is, is the bug actually 
> > > > > > > > 4145 doing 'alwaysAdd' without checking vs the unnecessary 
> > > > > > > > check here?
> > > > > > > VisitCXXTypeidExpr is used only in one place - here 
> > > > > > > https://github.com/llvm/llvm-project/blob/a89c9b35be08b665cc1a01d840bc20349ba1308f/clang/lib/Analysis/CFG.cpp#L2288
> > > > > > >  where S is not null. Null check for S already happens at the 
> > > > > > > beginning of the method where VisitCXXTypeidExpr is called. 
> > > > > > SG, an assert is perhaps not a bad idea, but LGTM.  I don't know 
> > > > > > very much about the CFG stuff, so aaron might wish to take a final 
> > > > > > look.
> > > > > What is SG? 
> > > > "Sounds Good"
> > > Haha! 
> > > Thanks for the review. 
> > > SG, an assert is perhaps not a bad idea, but LGTM.  I don't know very 
> > > much about the CFG stuff, so aaron might wish to take a final look.
> > 
> > Hi @aaron.ballman, could you please comment on this? Thank you!
> I don't think an assert is necessary; I think it's a predicate to pass 
> non-null nodes to the Visit functions in general, and I don't think we get a 
> whole lot out of asserting in each Visit method that its given node is 
> nonnull.
Thanks for the comment.



Comment at: clang/lib/CodeGen/CGObjCGNU.cpp:58
   /// used as arguments will necessarily be available at construction time.
-  LazyRuntimeFunction()
-  : CGM(nullptr), FunctionName(nullptr), Function(nullptr) {}
+  LazyRuntimeFunction() {}
 

aaron.ballman wrote:
> schittir wrote:
> > erichkeane wrote:
> > > schittir wrote:
> > > > erichkeane wrote:
> > > > > 
> > > > The comment above needs to be updated?
> > > I don't think so?  It still leaves the class uninitialized.
> > Right! Still valid. 
> I think the comment is stale or imprecise -- the class certainly is 
> initialized (it was being initialized previously as well, just not fully 
> initialized). I think it may have meant "not initialized to useful values", 
> so we could either repair it that way or remove the comment entirely.
I prefer removing the comment entirely because constructor = default() is 
self-explanatory. 


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153589/new/

https://reviews.llvm.org/D153589

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


[PATCH] D153860: [clang-tidy] Fix modernize-use-std-print check when return value used

2023-06-27 Thread Piotr Zegar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3e12b2e207cf: [clang-tidy] Fix modernize-use-std-print check 
when return value used (authored by mikecrowe, committed by PiotrZSL).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153860/new/

https://reviews.llvm.org/D153860

Files:
  clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp
  clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst
  clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-absl.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-custom.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print.cpp
@@ -44,6 +44,233 @@
   // CHECK-FIXES: std::println("Hello");
 }
 
+// std::print returns nothing, so any callers that use the return
+// value cannot be automatically translated.
+int printf_uses_return_value(int choice) {
+  const int i = printf("Return value assigned to variable %d\n", 42);
+
+  if (choice == 0)
+printf("if body %d\n", i);
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: use 'std::println' instead of 'printf' [modernize-use-std-print]
+// CHECK-FIXES: std::println("if body {}", i);
+  else if (choice == 1)
+printf("else if body %d\n", i);
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: use 'std::println' instead of 'printf' [modernize-use-std-print]
+// CHECK-FIXES: std::println("else if body {}", i);
+  else
+printf("else body %d\n", i);
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: use 'std::println' instead of 'printf' [modernize-use-std-print]
+// CHECK-FIXES: std::println("else body {}", i);
+
+  if (printf("Return value used as boolean in if statement"))
+if (printf("Return value used in expression if statement") == 44)
+  if (const int j = printf("Return value used in assignment in if statement"))
+if (const int k = printf("Return value used with initializer in if statement"); k == 44)
+  ;
+
+  int d = 0;
+  while (printf("%d", d) < 2)
+++d;
+
+  while (true)
+printf("while body %d\n", i);
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: use 'std::println' instead of 'printf' [modernize-use-std-print]
+// CHECK-FIXES: std::println("while body {}", i);
+
+  do
+printf("do body %d\n", i);
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: use 'std::println' instead of 'printf' [modernize-use-std-print]
+// CHECK-FIXES: std::println("do body {}", i);
+  while (true);
+
+  for (;;)
+printf("for body %d\n", i);
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: use 'std::println' instead of 'printf' [modernize-use-std-print]
+// CHECK-FIXES: std::println("for body {}", i);
+
+  for (printf("for init statement %d\n", i);;)
+// CHECK-MESSAGES: [[@LINE-1]]:8: warning: use 'std::println' instead of 'printf' [modernize-use-std-print]
+// CHECK-FIXES: std::println("for init statement {}", i);
+;;
+
+  for (int j = printf("for init statement %d\n", i);;)
+;;
+
+  for (; printf("for condition %d\n", i);)
+;;
+
+  for (;; printf("for expression %d\n", i))
+// CHECK-MESSAGES: [[@LINE-1]]:11: warning: use 'std::println' instead of 'printf' [modernize-use-std-print]
+// CHECK-FIXES: std::println("for expression {}", i)
+;;
+
+  for (auto C : "foo")
+printf("ranged-for body %d\n", i);
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: use 'std::println' instead of 'printf' [modernize-use-std-print]
+// CHECK-FIXES: std::println("ranged-for body {}", i);
+
+  switch (1) {
+  case 1:
+printf("switch case body %d\n", i);
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: use 'std::println' instead of 'printf' [modernize-use-std-print]
+// CHECK-FIXES: std::println("switch case body {}", i);
+break;
+  default:
+printf("switch default body %d\n", i);
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: use 'std::println' instead of 'printf' [modernize-use-std-print]
+// CHECK-FIXES: std::println("switch default body {}", i);
+break;
+  }
+
+  try {
+printf("try body %d\n", i);
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: use 'std::println' instead of 'printf' [modernize-use-std-print]
+// CHECK-FIXES: std::println("try body {}", i);
+  } catch (int) {
+printf("catch body %d\n", i);
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: use 'std::println' instead of 'printf' [modernize-use-std-print]
+// CHECK-FIXES: std::println("catch body {}", i);
+  }
+
+  (printf("Parenthesised expression %d\n", i));
+  // CHECK-MESSAGES: [[@LINE-1]]:4: warning: use 'std::println' instead of 'printf' [modernize-use-std-print]
+  // CHECK-FIXES: 

[clang-tools-extra] 3e12b2e - [clang-tidy] Fix modernize-use-std-print check when return value used

2023-06-27 Thread Piotr Zegar via cfe-commits

Author: Mike Crowe
Date: 2023-06-27T17:23:52Z
New Revision: 3e12b2e207cfa802937488a2c0b90d482eaf00a9

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

LOG: [clang-tidy] Fix modernize-use-std-print check when return value used

The initial implementation of the modernize-use-std-print check was
capable of converting calls to printf (etc.) which used the return value
to calls to std::print which has no return value, thus breaking the
code.

Use code inspired by the implementation of bugprone-unused-return-value
check to ignore cases where the return value is used. Add appropriate
lit test cases and documentation.

Reviewed By: PiotrZSL

Differential Revision: https://reviews.llvm.org/D153860

Added: 


Modified: 
clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp
clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-absl.cpp

clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-custom.cpp
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp
index 9b368f9a3e6c9..b1e1189d4ed77 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp
@@ -70,27 +70,53 @@ void UseStdPrintCheck::registerPPCallbacks(const 
SourceManager ,
   IncludeInserter.registerPreprocessor(PP);
 }
 
+static clang::ast_matchers::StatementMatcher
+unusedReturnValue(clang::ast_matchers::StatementMatcher MatchedCallExpr) {
+  auto UnusedInCompoundStmt =
+  compoundStmt(forEach(MatchedCallExpr),
+   // The checker can't currently 
diff erentiate between the
+   // return statement and other statements inside GNU 
statement
+   // expressions, so disable the checker inside them to avoid
+   // false positives.
+   unless(hasParent(stmtExpr(;
+  auto UnusedInIfStmt =
+  ifStmt(eachOf(hasThen(MatchedCallExpr), hasElse(MatchedCallExpr)));
+  auto UnusedInWhileStmt = whileStmt(hasBody(MatchedCallExpr));
+  auto UnusedInDoStmt = doStmt(hasBody(MatchedCallExpr));
+  auto UnusedInForStmt =
+  forStmt(eachOf(hasLoopInit(MatchedCallExpr),
+ hasIncrement(MatchedCallExpr), hasBody(MatchedCallExpr)));
+  auto UnusedInRangeForStmt = cxxForRangeStmt(hasBody(MatchedCallExpr));
+  auto UnusedInCaseStmt = switchCase(forEach(MatchedCallExpr));
+
+  return stmt(anyOf(UnusedInCompoundStmt, UnusedInIfStmt, UnusedInWhileStmt,
+UnusedInDoStmt, UnusedInForStmt, UnusedInRangeForStmt,
+UnusedInCaseStmt));
+}
+
 void UseStdPrintCheck::registerMatchers(MatchFinder *Finder) {
   if (!PrintfLikeFunctions.empty())
 Finder->addMatcher(
-callExpr(argumentCountAtLeast(1),
- hasArgument(0, stringLiteral(isOrdinary())),
- callee(functionDecl(
-unless(cxxMethodDecl()),
-
matchers::matchesAnyListedName(PrintfLikeFunctions))
-.bind("func_decl")))
-.bind("printf"),
+unusedReturnValue(
+callExpr(argumentCountAtLeast(1),
+ hasArgument(0, stringLiteral(isOrdinary())),
+ callee(functionDecl(unless(cxxMethodDecl()),
+ matchers::matchesAnyListedName(
+ PrintfLikeFunctions))
+.bind("func_decl")))
+.bind("printf")),
 this);
 
   if (!FprintfLikeFunctions.empty())
 Finder->addMatcher(
-callExpr(argumentCountAtLeast(2),
- hasArgument(1, stringLiteral(isOrdinary())),
- callee(functionDecl(unless(cxxMethodDecl()),
- matchers::matchesAnyListedName(
- FprintfLikeFunctions))
-.bind("func_decl")))
-.bind("fprintf"),
+unusedReturnValue(
+callExpr(argumentCountAtLeast(2),
+ hasArgument(1, stringLiteral(isOrdinary())),
+ callee(functionDecl(unless(cxxMethodDecl()),
+ matchers::matchesAnyListedName(
+ FprintfLikeFunctions))
+.bind("func_decl")))
+.bind("fprintf")),
 this);
 }
 

diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst 

[PATCH] D153589: [NFC] Initialize pointer fields and remove a needless null check.

2023-06-27 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Analysis/CFG.cpp:4156
   // CFG generation for unevaluated operands.
-  if (S && !S->isTypeDependent() && S->isPotentiallyEvaluated())
+  if (!S->isTypeDependent() && S->isPotentiallyEvaluated())
 return VisitChildren(S);

schittir wrote:
> schittir wrote:
> > erichkeane wrote:
> > > schittir wrote:
> > > > erichkeane wrote:
> > > > > schittir wrote:
> > > > > > erichkeane wrote:
> > > > > > > I get that we're counting on the dereference on 4145 to have made 
> > > > > > > this check irrelevant, but are we sure that we KNOW that "S" is 
> > > > > > > non-null here otherwise?  That is, is the bug actually 4145 doing 
> > > > > > > 'alwaysAdd' without checking vs the unnecessary check here?
> > > > > > VisitCXXTypeidExpr is used only in one place - here 
> > > > > > https://github.com/llvm/llvm-project/blob/a89c9b35be08b665cc1a01d840bc20349ba1308f/clang/lib/Analysis/CFG.cpp#L2288
> > > > > >  where S is not null. Null check for S already happens at the 
> > > > > > beginning of the method where VisitCXXTypeidExpr is called. 
> > > > > SG, an assert is perhaps not a bad idea, but LGTM.  I don't know very 
> > > > > much about the CFG stuff, so aaron might wish to take a final look.
> > > > What is SG? 
> > > "Sounds Good"
> > Haha! 
> > Thanks for the review. 
> > SG, an assert is perhaps not a bad idea, but LGTM.  I don't know very much 
> > about the CFG stuff, so aaron might wish to take a final look.
> 
> Hi @aaron.ballman, could you please comment on this? Thank you!
I don't think an assert is necessary; I think it's a predicate to pass non-null 
nodes to the Visit functions in general, and I don't think we get a whole lot 
out of asserting in each Visit method that its given node is nonnull.



Comment at: clang/lib/CodeGen/CGObjCGNU.cpp:58
   /// used as arguments will necessarily be available at construction time.
-  LazyRuntimeFunction()
-  : CGM(nullptr), FunctionName(nullptr), Function(nullptr) {}
+  LazyRuntimeFunction() {}
 

schittir wrote:
> erichkeane wrote:
> > schittir wrote:
> > > erichkeane wrote:
> > > > 
> > > The comment above needs to be updated?
> > I don't think so?  It still leaves the class uninitialized.
> Right! Still valid. 
I think the comment is stale or imprecise -- the class certainly is initialized 
(it was being initialized previously as well, just not fully initialized). I 
think it may have meant "not initialized to useful values", so we could either 
repair it that way or remove the comment entirely.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153589/new/

https://reviews.llvm.org/D153589

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


[PATCH] D153560: [Clang] Allow C++11 style initialisation of SVE types.

2023-06-27 Thread Eli Friedman via Phabricator via cfe-commits
efriedma accepted this revision.
efriedma added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153560/new/

https://reviews.llvm.org/D153560

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


[PATCH] D152263: [clang][CFG] Add support for partitioning CFG into intervals.

2023-06-27 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
ymandel marked 2 inline comments as done.
Closed by commit rGf4cf51c99c74: [clang][CFG] Add support for partitioning CFG 
into intervals. (authored by ymandel).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152263/new/

https://reviews.llvm.org/D152263

Files:
  clang/include/clang/Analysis/Analyses/IntervalPartition.h
  clang/lib/Analysis/CMakeLists.txt
  clang/lib/Analysis/IntervalPartition.cpp
  clang/unittests/Analysis/CMakeLists.txt
  clang/unittests/Analysis/IntervalPartitionTest.cpp

Index: clang/unittests/Analysis/IntervalPartitionTest.cpp
===
--- /dev/null
+++ clang/unittests/Analysis/IntervalPartitionTest.cpp
@@ -0,0 +1,164 @@
+//===- unittests/Analysis/IntervalPartitionTest.cpp ---===//
+//
+// 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 "clang/Analysis/Analyses/IntervalPartition.h"
+#include "CFGBuildResult.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace analysis {
+namespace {
+
+TEST(BuildInterval, PartitionSimpleOneInterval) {
+
+  const char *Code = R"(void f() {
+  int x = 3;
+  int y = 7;
+  x = y + x;
+})";
+  BuildResult Result = BuildCFG(Code);
+  EXPECT_EQ(BuildResult::BuiltCFG, Result.getStatus());
+
+  CFG *cfg = Result.getCFG();
+
+  // Basic correctness checks.
+  ASSERT_EQ(cfg->size(), 3u);
+
+  auto  = cfg->getEntry();
+
+  CFGInterval I = buildInterval(*cfg, EntryBlock);
+  EXPECT_EQ(I.Blocks.size(), 3u);
+}
+
+TEST(BuildInterval, PartitionIfThenOneInterval) {
+
+  const char *Code = R"(void f() {
+  int x = 3;
+  if (x > 3)
+x = 2;
+  else
+x = 7;
+  x = x + x;
+})";
+  BuildResult Result = BuildCFG(Code);
+  EXPECT_EQ(BuildResult::BuiltCFG, Result.getStatus());
+
+  CFG *cfg = Result.getCFG();
+
+  // Basic correctness checks.
+  ASSERT_EQ(cfg->size(), 6u);
+
+  auto  = cfg->getEntry();
+
+  CFGInterval I = buildInterval(*cfg, EntryBlock);
+  EXPECT_EQ(I.Blocks.size(), 6u);
+}
+
+using ::testing::UnorderedElementsAre;
+
+TEST(BuildInterval, PartitionWhileMultipleIntervals) {
+
+  const char *Code = R"(void f() {
+  int x = 3;
+  while (x >= 3)
+--x;
+  x = x + x;
+})";
+  BuildResult Result = BuildCFG(Code);
+  ASSERT_EQ(BuildResult::BuiltCFG, Result.getStatus());
+
+  CFG *cfg = Result.getCFG();
+  ASSERT_EQ(cfg->size(), 7u);
+
+  auto *EntryBlock = >getEntry();
+  CFGBlock *InitXBlock = *EntryBlock->succ_begin();
+  CFGBlock *LoopHeadBlock = *InitXBlock->succ_begin();
+
+  CFGInterval I1 = buildInterval(*cfg, *EntryBlock);
+  EXPECT_THAT(I1.Blocks, UnorderedElementsAre(EntryBlock, InitXBlock));
+
+  CFGInterval I2 = buildInterval(*cfg, *LoopHeadBlock);
+  EXPECT_EQ(I2.Blocks.size(), 5u);
+}
+
+TEST(PartitionIntoIntervals, PartitionIfThenOneInterval) {
+  const char *Code = R"(void f() {
+  int x = 3;
+  if (x > 3)
+x = 2;
+  else
+x = 7;
+  x = x + x;
+})";
+  BuildResult Result = BuildCFG(Code);
+  ASSERT_EQ(BuildResult::BuiltCFG, Result.getStatus());
+
+  CFG *cfg = Result.getCFG();
+  ASSERT_EQ(cfg->size(), 6u);
+
+  auto Intervals = partitionIntoIntervals(*cfg);
+  EXPECT_EQ(Intervals.size(), 1u);
+}
+
+TEST(PartitionIntoIntervals, PartitionWhileTwoIntervals) {
+  const char *Code = R"(void f() {
+  int x = 3;
+  while (x >= 3)
+--x;
+  x = x + x;
+})";
+  BuildResult Result = BuildCFG(Code);
+  ASSERT_EQ(BuildResult::BuiltCFG, Result.getStatus());
+
+  CFG *cfg = Result.getCFG();
+  ASSERT_EQ(cfg->size(), 7u);
+
+  auto Intervals = partitionIntoIntervals(*cfg);
+  EXPECT_EQ(Intervals.size(), 2u);
+}
+
+TEST(PartitionIntoIntervals, PartitionNestedWhileThreeIntervals) {
+  const char *Code = R"(void f() {
+  int x = 3;
+  while (x >= 3) {
+--x;
+int y = x;
+while (y > 0) --y;
+  }
+ 

[clang] f4cf51c - [clang][CFG] Add support for partitioning CFG into intervals.

2023-06-27 Thread Yitzhak Mandelbaum via cfe-commits

Author: Yitzhak Mandelbaum
Date: 2023-06-27T17:07:54Z
New Revision: f4cf51c99c74f46a490e0ae265da8fba298d800b

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

LOG: [clang][CFG] Add support for partitioning CFG into intervals.

Adds support for the classic dataflow algorithm that partitions a flow graph
into distinct intervals. C.f. Dragon book, pp. 664-666.

A version of this algorithm exists in LLVM (see llvm/Analysis/Interval.h and
related files), but it is specific to LLVM, is a recursive (vs iterative)
algorithm, and uses many layers of abstraction that seem unnecessary for CFG
purposes.

This patch is part 1 of 2. The next patch will generalize the code to work on
intervals, to support computation of the limit flow graph.

Differential Revision: https://reviews.llvm.org/D152263

Added: 
clang/include/clang/Analysis/Analyses/IntervalPartition.h
clang/lib/Analysis/IntervalPartition.cpp
clang/unittests/Analysis/IntervalPartitionTest.cpp

Modified: 
clang/lib/Analysis/CMakeLists.txt
clang/unittests/Analysis/CMakeLists.txt

Removed: 




diff  --git a/clang/include/clang/Analysis/Analyses/IntervalPartition.h 
b/clang/include/clang/Analysis/Analyses/IntervalPartition.h
new file mode 100644
index 0..cc04bab7bf6c4
--- /dev/null
+++ b/clang/include/clang/Analysis/Analyses/IntervalPartition.h
@@ -0,0 +1,50 @@
+//===- IntervalPartition.h - CFG Partitioning into Intervals -*- 
C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+//  This file defines functionality for partitioning a CFG into intervals. The
+//  concepts and implementations are based on the presentation in "Compilers" 
by
+//  Aho, Sethi and Ullman (the "dragon book"), pages 664-666.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_ANALYSIS_ANALYSES_INTERVALPARTITION_H
+#define LLVM_CLANG_ANALYSIS_ANALYSES_INTERVALPARTITION_H
+
+#include "clang/Analysis/CFG.h"
+#include "llvm/ADT/DenseSet.h"
+#include 
+
+namespace clang {
+
+// An interval is a strongly-connected component of the CFG along with a
+// trailing acyclic structure. The _header_ of the interval is either the CFG
+// entry block or has at least one predecessor outside of the interval. All
+// other blocks in the interval have only predecessors also in the interval.
+struct CFGInterval {
+  CFGInterval(const CFGBlock *Header) : Header(Header), Blocks({Header}) {}
+
+  // The block from which the interval was constructed. Is either the CFG entry
+  // block or has at least one predecessor outside the interval.
+  const CFGBlock *Header;
+
+  llvm::SmallDenseSet Blocks;
+
+  // Successor blocks of the *interval*: blocks outside the interval for
+  // reachable (in one edge) from within the interval.
+  llvm::SmallDenseSet Successors;
+};
+
+CFGInterval buildInterval(const CFG , const CFGBlock );
+
+// Partitions `Cfg` into intervals and constructs a graph of the intervals,
+// based on the edges between nodes in these intervals.
+std::vector partitionIntoIntervals(const CFG );
+
+} // namespace clang
+
+#endif // LLVM_CLANG_ANALYSIS_ANALYSES_INTERVALPARTITION_H

diff  --git a/clang/lib/Analysis/CMakeLists.txt 
b/clang/lib/Analysis/CMakeLists.txt
index ea6cb59e8e199..d029926c76e89 100644
--- a/clang/lib/Analysis/CMakeLists.txt
+++ b/clang/lib/Analysis/CMakeLists.txt
@@ -18,6 +18,7 @@ add_clang_library(clangAnalysis
   CodeInjector.cpp
   Dominators.cpp
   ExprMutationAnalyzer.cpp
+  IntervalPartition.cpp
   IssueHash.cpp
   LiveVariables.cpp
   MacroExpansionContext.cpp

diff  --git a/clang/lib/Analysis/IntervalPartition.cpp 
b/clang/lib/Analysis/IntervalPartition.cpp
new file mode 100644
index 0..9d093d8986f78
--- /dev/null
+++ b/clang/lib/Analysis/IntervalPartition.cpp
@@ -0,0 +1,116 @@
+//===- IntervalPartition.cpp - CFG Partitioning into Intervals --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+//  This file defines functionality for partitioning a CFG into intervals.
+//
+//===--===//
+
+#include "clang/Analysis/Analyses/IntervalPartition.h"
+#include "clang/Analysis/CFG.h"
+#include "llvm/ADT/BitVector.h"
+#include 
+#include 
+#include 
+
+namespace clang {
+
+static 

[PATCH] D153857: [clang] Fix new-expression with elaborated-type-specifier

2023-06-27 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Thank you for the fix! Just to clarify some things before diving into the 
review too much... From the patch summary:

  Expressions like
  
  new struct A {};
  struct A* b = (1 == 1) ? new struct A : new struct A;
  Were parsed as definitions of struct A and failed, however as clarified by
  CWG2141 new-expression cannot define a type, so both these examples
  should be considered as valid.

There's a typo there -- the `new struct A{};` bit should be `struct A {};` 
(dropping the `new`), right?

I think the root cause of that issue is that we don't implement DR2141 
(https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#2141); are you 
intending to cover that DR? If so, there should be tests added to 
clang/test/CXX/drs/dr21xx.cpp.




Comment at: clang/include/clang/Parse/Parser.h:2221
+DSC_association, // A _Generic selection expression's type association
+DSC_new  // C++ new operator
   };

Adding the comma so the next person doesn't have to, and realigning to the 
usual indentation


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153857/new/

https://reviews.llvm.org/D153857

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


  1   2   3   >