[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)

2024-07-16 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

@kadircet  Comments addressed. Maybe due to some github's issue, my replies are 
separated and didn't form a standalone list. Hope this won't make it harder.

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


[clang] [clang] Limit alignment for emitted vectors (PR #98629)

2024-07-16 Thread Phoebe Wang via cfe-commits


@@ -133,6 +133,7 @@ struct TransferrableTargetInfo {
   unsigned short SuitableAlign;
   unsigned short NewAlign;
   unsigned MaxVectorAlign;

phoebewang wrote:

I noticed that, but the value is set for Darwin, but the failure prefix is a 
non Darwin one.

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


[clang] [llvm] [PAC][clang][Driver] Add signed GOT flag (PR #96160)

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

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

>From f891f791dfe882389d83d3c4c4fb57d67a845c04 Mon Sep 17 00:00:00 2001
From: Daniil Kovalev 
Date: Tue, 18 Jun 2024 15:38:18 +0300
Subject: [PATCH 1/3] [PAC][clang][Driver] Add signed GOT flag

Add `-fptrauth-elf-got` clang driver flag and set `ptrauth_elf_got`
preprocessor feature and `PointerAuthELFGOT` LangOption correspondingly.
For non-ELF triples, the driver flag is ignored and a warning is emitted.
---
 .../clang/Basic/DiagnosticDriverKinds.td  |  4 ++
 clang/include/clang/Basic/Features.def|  1 +
 clang/include/clang/Driver/Options.td |  1 +
 clang/lib/Driver/ToolChains/Clang.cpp |  7 +++
 clang/lib/Frontend/CompilerInvocation.cpp |  4 ++
 clang/test/CodeGen/aarch64-elf-pauthabi.c | 11 +++-
 clang/test/Driver/aarch64-ptrauth.c   |  9 +++-
 clang/test/Preprocessor/ptrauth_feature.c | 52 ++-
 8 files changed, 72 insertions(+), 17 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 1ca2cb85565a1..28667b1eb239e 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -742,6 +742,10 @@ def warn_drv_fjmc_for_elf_only : Warning<
   "-fjmc works only for ELF; option ignored">,
   InGroup;
 
+def warn_drv_ptrauth_elf_got_for_elf_only : Warning<
+  "-fptrauth-elf-got works only for ELF; option ignored">,
+  InGroup;
+
 def warn_target_override_arm64ec : Warning<
   "/arm64EC has been overridden by specified target: %0; option ignored">,
   InGroup;
diff --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index 53f410d3cb4bd..569f4e1715af5 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -110,6 +110,7 @@ FEATURE(ptrauth_vtable_pointer_address_discrimination, 
LangOpts.PointerAuthVTPtr
 FEATURE(ptrauth_vtable_pointer_type_discrimination, 
LangOpts.PointerAuthVTPtrTypeDiscrimination)
 FEATURE(ptrauth_member_function_pointer_type_discrimination, 
LangOpts.PointerAuthCalls)
 FEATURE(ptrauth_init_fini, LangOpts.PointerAuthInitFini)
+FEATURE(ptrauth_elf_got, LangOpts.PointerAuthELFGOT)
 EXTENSION(swiftcc,
   PP.getTargetInfo().checkCallingConvention(CC_Swift) ==
   clang::TargetInfo::CCCR_OK)
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 112eb286eb075..e16c1a0d06a1b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4222,6 +4222,7 @@ defm ptrauth_vtable_pointer_address_discrimination :
 defm ptrauth_vtable_pointer_type_discrimination :
   OptInCC1FFlag<"ptrauth-vtable-pointer-type-discrimination", "Enable type 
discrimination of vtable pointers">;
 defm ptrauth_init_fini : OptInCC1FFlag<"ptrauth-init-fini", "Enable signing of 
function pointers in init/fini arrays">;
+defm ptrauth_elf_got : OptInCC1FFlag<"ptrauth-elf-got", "Enable authentication 
of pointers from GOT (ELF only)">;
 }
 
 def fenable_matrix : Flag<["-"], "fenable-matrix">, Group,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 331cf6e713d89..5f55e79ec206b 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1788,6 +1788,13 @@ void Clang::AddAArch64TargetArgs(const ArgList &Args,
   options::OPT_fno_ptrauth_vtable_pointer_type_discrimination);
   Args.addOptInFlag(CmdArgs, options::OPT_fptrauth_init_fini,
 options::OPT_fno_ptrauth_init_fini);
+
+  Args.addOptInFlag(CmdArgs, options::OPT_fptrauth_elf_got,
+options::OPT_fno_ptrauth_elf_got);
+
+  if (Args.hasArg(options::OPT_fptrauth_elf_got))
+getToolChain().getDriver().Diag(
+diag::warn_drv_ptrauth_elf_got_for_elf_only);
 }
 
 void Clang::AddLoongArchTargetArgs(const ArgList &Args,
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 58694e5399d58..97a5408a4c1e0 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -3361,6 +3361,8 @@ static void GeneratePointerAuthArgs(const LangOptions 
&Opts,
 GenerateArg(Consumer, OPT_fptrauth_vtable_pointer_type_discrimination);
   if (Opts.PointerAuthInitFini)
 GenerateArg(Consumer, OPT_fptrauth_init_fini);
+  if (Opts.PointerAuthELFGOT)
+GenerateArg(Consumer, OPT_fptrauth_elf_got);
 }
 
 static void ParsePointerAuthArgs(LangOptions &Opts, ArgList &Args,
@@ -3374,6 +3376,7 @@ static void ParsePointerAuthArgs(LangOptions &Opts, 
ArgList &Args,
   Opts.PointerAuthVTPtrTypeDiscrimination =
   Args.hasArg(OPT_fptrauth_vtable_pointer_type_discrimination);
   Opts.PointerAuthInitFini = Args.hasArg(OPT_fptrauth_init_fini);
+  Opts.PointerAuthELFGOT = Args.hasArg(OPT_fptrauth_elf_got);
 }
 
 /// Check if input file kind

[clang] [Clang] C++20 Coroutines: Introduce Frontend Attribute [[clang::coro_inplace_task]] (PR #98971)

2024-07-16 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

Haven't look into the details but just a quick scanning.

I feel the name `[[coro_inplace_task]]` is not so good. Since it doesn't happen 
unconditionally. It happens conditionally. I still want to try to make it clear 
in the name. I still like names  like `[[coro_elide_after_await]]`, which I 
feel is more clear.

Another point is, I feel the summary may be hard for other people or future 
contributors to understand. I feel it may be better to split it to 3 parts: one 
for C++'s end users (or you can skip this part in the summary since this should 
be present in Attr.doc), a high level introduction to clang's developers for 
what this PR is for, then an explanation what this patch did in low level for 
reviewers of the patch. (So the reviewers don't need to dig this out by 
themselves.)

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


[clang] [Clang] C++20 Coroutines: Introduce Frontend Attribute [[clang::coro_inplace_task]] (PR #98971)

2024-07-16 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

BTW, it will be better to use stacked PR for this one and 
https://github.com/llvm/llvm-project/pull/98974. 

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


[clang] [OpenMP][AMDGPU] Do not attach -fcuda-is-device (PR #99002)

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

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

-fcuda-is-device flag is not used for OpenMP offloading for AMD GPUs and it 
does not need to be added as clang cc1 option for OpenMP code.

This PR has the same functionality as 
https://github.com/llvm/llvm-project/pull/96909 but it doesn't introduce 
regression for virtual function support.

>From 3ffb93bef74694d71faf94fd6c30a149a028696d Mon Sep 17 00:00:00 2001
From: Dominik Adamski 
Date: Wed, 3 Jul 2024 09:08:10 -0500
Subject: [PATCH] [OpenMP][AMDGPU] Do not attach -fcuda-is-device

-fcuda-is-device flag is not used for OpenMP offloading for AMD GPUs
and it does not need to be added as clang cc1 option for OpenMP code.
---
 clang/lib/CodeGen/CodeGenModule.h| 2 +-
 clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp | 2 --
 clang/test/Driver/amdgpu-openmp-toolchain.c  | 2 +-
 3 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenModule.h 
b/clang/lib/CodeGen/CodeGenModule.h
index caa3786c033b5..657e681730c3a 100644
--- a/clang/lib/CodeGen/CodeGenModule.h
+++ b/clang/lib/CodeGen/CodeGenModule.h
@@ -1010,7 +1010,7 @@ class CodeGenModule : public CodeGenTypeCache {
   bool shouldEmitRTTI(bool ForEH = false) {
 return (ForEH || getLangOpts().RTTI) && !getLangOpts().CUDAIsDevice &&
!(getLangOpts().OpenMP && getLangOpts().OpenMPIsTargetDevice &&
- getTriple().isNVPTX());
+ (getTriple().isNVPTX() || getTriple().isAMDGPU()));
   }
 
   /// Get the address of the RTTI descriptor for the given type.
diff --git a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp 
b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
index 1c0fb4babe3a5..b75d400e6ce91 100644
--- a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
@@ -47,8 +47,6 @@ void AMDGPUOpenMPToolChain::addClangTargetOptions(
   assert(DeviceOffloadingKind == Action::OFK_OpenMP &&
  "Only OpenMP offloading kinds are supported.");
 
-  CC1Args.push_back("-fcuda-is-device");
-
   if (DriverArgs.hasArg(options::OPT_nogpulib))
 return;
 
diff --git a/clang/test/Driver/amdgpu-openmp-toolchain.c 
b/clang/test/Driver/amdgpu-openmp-toolchain.c
index 49af04acc4639..a153c4afb0ce8 100644
--- a/clang/test/Driver/amdgpu-openmp-toolchain.c
+++ b/clang/test/Driver/amdgpu-openmp-toolchain.c
@@ -7,7 +7,7 @@
 
 // verify the tools invocations
 // CHECK: "-cc1" "-triple" 
"x86_64-unknown-linux-gnu"{{.*}}"-emit-llvm-bc"{{.*}}"-x" "c"
-// CHECK: "-cc1" "-triple" "amdgcn-amd-amdhsa" "-aux-triple" 
"x86_64-unknown-linux-gnu"{{.*}}"-fcuda-is-device"{{.*}}"-target-cpu" "gfx906"
+// CHECK: "-cc1" "-triple" "amdgcn-amd-amdhsa" "-aux-triple" 
"x86_64-unknown-linux-gnu"{{.*}}"-target-cpu" "gfx906"
 // CHECK: "-cc1" "-triple" "x86_64-unknown-linux-gnu"{{.*}}"-emit-obj"
 // CHECK: clang-linker-wrapper{{.*}} "-o" "a.out"
 

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


[clang] [OpenMP][AMDGPU] Do not attach -fcuda-is-device (PR #99002)

2024-07-16 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-codegen

Author: Dominik Adamski (DominikAdamski)


Changes

-fcuda-is-device flag is not used for OpenMP offloading for AMD GPUs and it 
does not need to be added as clang cc1 option for OpenMP code.

This PR has the same functionality as 
https://github.com/llvm/llvm-project/pull/96909 but it doesn't introduce 
regression for virtual function support.

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


3 Files Affected:

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


``diff
diff --git a/clang/lib/CodeGen/CodeGenModule.h 
b/clang/lib/CodeGen/CodeGenModule.h
index caa3786c033b5..657e681730c3a 100644
--- a/clang/lib/CodeGen/CodeGenModule.h
+++ b/clang/lib/CodeGen/CodeGenModule.h
@@ -1010,7 +1010,7 @@ class CodeGenModule : public CodeGenTypeCache {
   bool shouldEmitRTTI(bool ForEH = false) {
 return (ForEH || getLangOpts().RTTI) && !getLangOpts().CUDAIsDevice &&
!(getLangOpts().OpenMP && getLangOpts().OpenMPIsTargetDevice &&
- getTriple().isNVPTX());
+ (getTriple().isNVPTX() || getTriple().isAMDGPU()));
   }
 
   /// Get the address of the RTTI descriptor for the given type.
diff --git a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp 
b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
index 1c0fb4babe3a5..b75d400e6ce91 100644
--- a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
@@ -47,8 +47,6 @@ void AMDGPUOpenMPToolChain::addClangTargetOptions(
   assert(DeviceOffloadingKind == Action::OFK_OpenMP &&
  "Only OpenMP offloading kinds are supported.");
 
-  CC1Args.push_back("-fcuda-is-device");
-
   if (DriverArgs.hasArg(options::OPT_nogpulib))
 return;
 
diff --git a/clang/test/Driver/amdgpu-openmp-toolchain.c 
b/clang/test/Driver/amdgpu-openmp-toolchain.c
index 49af04acc4639..a153c4afb0ce8 100644
--- a/clang/test/Driver/amdgpu-openmp-toolchain.c
+++ b/clang/test/Driver/amdgpu-openmp-toolchain.c
@@ -7,7 +7,7 @@
 
 // verify the tools invocations
 // CHECK: "-cc1" "-triple" 
"x86_64-unknown-linux-gnu"{{.*}}"-emit-llvm-bc"{{.*}}"-x" "c"
-// CHECK: "-cc1" "-triple" "amdgcn-amd-amdhsa" "-aux-triple" 
"x86_64-unknown-linux-gnu"{{.*}}"-fcuda-is-device"{{.*}}"-target-cpu" "gfx906"
+// CHECK: "-cc1" "-triple" "amdgcn-amd-amdhsa" "-aux-triple" 
"x86_64-unknown-linux-gnu"{{.*}}"-target-cpu" "gfx906"
 // CHECK: "-cc1" "-triple" "x86_64-unknown-linux-gnu"{{.*}}"-emit-obj"
 // CHECK: clang-linker-wrapper{{.*}} "-o" "a.out"
 

``




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


[clang] [OpenMP][AMDGPU] Do not attach -fcuda-is-device (PR #99002)

2024-07-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-amdgpu

Author: Dominik Adamski (DominikAdamski)


Changes

-fcuda-is-device flag is not used for OpenMP offloading for AMD GPUs and it 
does not need to be added as clang cc1 option for OpenMP code.

This PR has the same functionality as 
https://github.com/llvm/llvm-project/pull/96909 but it doesn't introduce 
regression for virtual function support.

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


3 Files Affected:

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


``diff
diff --git a/clang/lib/CodeGen/CodeGenModule.h 
b/clang/lib/CodeGen/CodeGenModule.h
index caa3786c033b5..657e681730c3a 100644
--- a/clang/lib/CodeGen/CodeGenModule.h
+++ b/clang/lib/CodeGen/CodeGenModule.h
@@ -1010,7 +1010,7 @@ class CodeGenModule : public CodeGenTypeCache {
   bool shouldEmitRTTI(bool ForEH = false) {
 return (ForEH || getLangOpts().RTTI) && !getLangOpts().CUDAIsDevice &&
!(getLangOpts().OpenMP && getLangOpts().OpenMPIsTargetDevice &&
- getTriple().isNVPTX());
+ (getTriple().isNVPTX() || getTriple().isAMDGPU()));
   }
 
   /// Get the address of the RTTI descriptor for the given type.
diff --git a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp 
b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
index 1c0fb4babe3a5..b75d400e6ce91 100644
--- a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
@@ -47,8 +47,6 @@ void AMDGPUOpenMPToolChain::addClangTargetOptions(
   assert(DeviceOffloadingKind == Action::OFK_OpenMP &&
  "Only OpenMP offloading kinds are supported.");
 
-  CC1Args.push_back("-fcuda-is-device");
-
   if (DriverArgs.hasArg(options::OPT_nogpulib))
 return;
 
diff --git a/clang/test/Driver/amdgpu-openmp-toolchain.c 
b/clang/test/Driver/amdgpu-openmp-toolchain.c
index 49af04acc4639..a153c4afb0ce8 100644
--- a/clang/test/Driver/amdgpu-openmp-toolchain.c
+++ b/clang/test/Driver/amdgpu-openmp-toolchain.c
@@ -7,7 +7,7 @@
 
 // verify the tools invocations
 // CHECK: "-cc1" "-triple" 
"x86_64-unknown-linux-gnu"{{.*}}"-emit-llvm-bc"{{.*}}"-x" "c"
-// CHECK: "-cc1" "-triple" "amdgcn-amd-amdhsa" "-aux-triple" 
"x86_64-unknown-linux-gnu"{{.*}}"-fcuda-is-device"{{.*}}"-target-cpu" "gfx906"
+// CHECK: "-cc1" "-triple" "amdgcn-amd-amdhsa" "-aux-triple" 
"x86_64-unknown-linux-gnu"{{.*}}"-target-cpu" "gfx906"
 // CHECK: "-cc1" "-triple" "x86_64-unknown-linux-gnu"{{.*}}"-emit-obj"
 // CHECK: clang-linker-wrapper{{.*}} "-o" "a.out"
 

``




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


[clang] [compiler-rt] [llvm] [PAC][AArch64] Support init/fini array signing (PR #96478)

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

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

>From 5399237a71c0ccd872821034d83ea2c3a04bed3f Mon Sep 17 00:00:00 2001
From: Daniil Kovalev 
Date: Fri, 21 Jun 2024 12:32:51 +0300
Subject: [PATCH 1/2] [PAC][AArch64] Support init/fini array signing

If both `-fptrauth-init-fini` and `-fptrauth-calls` are passed, sign
function pointers in `llvm.global_ctors` and `llvm.global_dtors` with
constant discriminator 0xD9D4 (`ptrauth_string_discriminator("init_fini")`).
Additionally, if `-fptrauth-init-fini-address-discrimination` is passed,
address discrimination is used for signing (otherwise, just constant
discriminator is used).
---
 clang/include/clang/Basic/Features.def|  1 +
 clang/include/clang/Basic/LangOptions.def |  1 +
 .../include/clang/Basic/PointerAuthOptions.h  |  7 ++
 clang/include/clang/Driver/Options.td |  1 +
 clang/lib/CodeGen/CodeGenModule.cpp   | 63 +--
 clang/lib/Driver/ToolChains/Clang.cpp |  3 +
 clang/lib/Frontend/CompilerInvocation.cpp |  9 +++
 clang/lib/Headers/ptrauth.h   |  8 ++
 clang/test/CodeGen/aarch64-elf-pauthabi.c | 12 ++-
 clang/test/CodeGen/ptrauth-init-fini.c| 39 ++
 clang/test/Driver/aarch64-ptrauth.c   |  6 +-
 clang/test/Preprocessor/ptrauth_feature.c | 52 +
 compiler-rt/lib/builtins/crtbegin.c   | 16 
 llvm/include/llvm/BinaryFormat/ELF.h  |  3 +-
 .../AArch64/note-gnu-property-elf-pauthabi.ll |  2 +-
 .../test/CodeGen/AArch64/ptrauth-init-fini.ll | 77 +++
 .../ELF/AArch64/aarch64-feature-pauth.s   | 18 ++---
 llvm/tools/llvm-readobj/ELFDumper.cpp |  4 +-
 18 files changed, 268 insertions(+), 54 deletions(-)
 create mode 100644 clang/test/CodeGen/ptrauth-init-fini.c
 create mode 100644 llvm/test/CodeGen/AArch64/ptrauth-init-fini.ll

diff --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index 53f410d3cb4bd..5dca40b261655 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -110,6 +110,7 @@ FEATURE(ptrauth_vtable_pointer_address_discrimination, 
LangOpts.PointerAuthVTPtr
 FEATURE(ptrauth_vtable_pointer_type_discrimination, 
LangOpts.PointerAuthVTPtrTypeDiscrimination)
 FEATURE(ptrauth_member_function_pointer_type_discrimination, 
LangOpts.PointerAuthCalls)
 FEATURE(ptrauth_init_fini, LangOpts.PointerAuthInitFini)
+FEATURE(ptrauth_init_fini_address_discrimination, 
LangOpts.PointerAuthInitFiniAddressDiscrimination)
 EXTENSION(swiftcc,
   PP.getTargetInfo().checkCallingConvention(CC_Swift) ==
   clang::TargetInfo::CCCR_OK)
diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 6dd6b5614f44c..2de854731 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -168,6 +168,7 @@ LANGOPT(PointerAuthAuthTraps, 1, 0, "pointer authentication 
failure traps")
 LANGOPT(PointerAuthVTPtrAddressDiscrimination, 1, 0, "incorporate address 
discrimination in authenticated vtable pointers")
 LANGOPT(PointerAuthVTPtrTypeDiscrimination, 1, 0, "incorporate type 
discrimination in authenticated vtable pointers")
 LANGOPT(PointerAuthInitFini, 1, 0, "sign function pointers in init/fini 
arrays")
+LANGOPT(PointerAuthInitFiniAddressDiscrimination, 1, 0, "incorporate address 
discrimination in authenticated function pointers in init/fini arrays")
 
 LANGOPT(DoubleSquareBracketAttributes, 1, 0, "'[[]]' attributes extension for 
all language standard modes")
 LANGOPT(ExperimentalLateParseAttributes, 1, 0, "experimental late parsing of 
attributes")
diff --git a/clang/include/clang/Basic/PointerAuthOptions.h 
b/clang/include/clang/Basic/PointerAuthOptions.h
index aaad4a2b2b5ae..9e2b64111e461 100644
--- a/clang/include/clang/Basic/PointerAuthOptions.h
+++ b/clang/include/clang/Basic/PointerAuthOptions.h
@@ -23,6 +23,10 @@
 
 namespace clang {
 
+/// Constant discriminator to be used with function pointers in .init_array and
+/// .fini_array. The value is ptrauth_string_discriminator("init_fini")
+constexpr uint16_t InitFiniPointerConstantDiscriminator = 0xD9D4;
+
 constexpr unsigned PointerAuthKeyNone = -1;
 
 class PointerAuthSchema {
@@ -150,6 +154,9 @@ class PointerAuthSchema {
 struct PointerAuthOptions {
   /// The ABI for C function pointers.
   PointerAuthSchema FunctionPointers;
+
+  /// The ABI for function addresses in .init_array and .fini_array
+  PointerAuthSchema InitFiniPointers;
 };
 
 } // end namespace clang
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c529cc9506667..5b8d4139d975b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4228,6 +4228,7 @@ defm ptrauth_vtable_pointer_address_discrimination :
 defm ptrauth_vtable_pointer_type_discrimination :
   OptInCC1FFlag<"ptrauth-vtable-pointer-type-discrimin

[clang] [clang] Refactor: Introduce a new LifetimeKind for the assignment case, NFC (PR #99005)

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

https://github.com/hokein created 
https://github.com/llvm/llvm-project/pull/99005

The current implementation for the assignment case uses a combination of the 
`LK_Extended` lifetime kind and the validity of `AEntity`, which is somewhat 
messy and doesn't align well with the intended mental model.

This patch introduces a dedicated lifetime kind to handle the assignment case, 
simplifying the implementation and improving clarity.

>From 0ba3ca0ac7538011b78376b30aa4aeded4a7fe54 Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Tue, 16 Jul 2024 10:23:44 +0200
Subject: [PATCH] [clang] Refactor: Introduce a new LifetimeKind for assignment
 cases, NFC

The current implementation for assignment case uses a combination of the
`LK_Extended` lifetime kind and the validity of `AEntity`, which is somewhat
messy and doesn't align well with the intended mental model.

This patch introduces a dedicated lifetime kind to handle assignment cases,
simplifying the implementation and improving clarity.
---
 clang/lib/Sema/CheckExprLifetime.cpp | 39 
 1 file changed, 23 insertions(+), 16 deletions(-)

diff --git a/clang/lib/Sema/CheckExprLifetime.cpp 
b/clang/lib/Sema/CheckExprLifetime.cpp
index 2f9ef28da2c3e..995e4cbadacfe 100644
--- a/clang/lib/Sema/CheckExprLifetime.cpp
+++ b/clang/lib/Sema/CheckExprLifetime.cpp
@@ -39,6 +39,11 @@ enum LifetimeKind {
   /// This is a mem-initializer: if it would extend a temporary (other than via
   /// a default member initializer), the program is ill-formed.
   LK_MemInitializer,
+
+  /// The lifetime of a temporary bound to this entity probably ends too soon,
+  /// because the entity is a pointer and we assign the address of a temporary
+  /// object to it.
+  LK_Assignment,
 };
 using LifetimeResult =
 llvm::PointerIntPair;
@@ -971,6 +976,8 @@ static void checkExprLifetimeImpl(Sema &SemaRef,
   const InitializedEntity *ExtendingEntity,
   LifetimeKind LK,
   const AssignedEntity *AEntity, Expr *Init) {
+  assert((AEntity && LK == LK_Assignment) ||
+ (InitEntity && LK != LK_Assignment));
   // If this entity doesn't have an interesting lifetime, don't bother looking
   // for temporaries within its initializer.
   if (LK == LK_FullExpression)
@@ -1008,19 +1015,7 @@ static void checkExprLifetimeImpl(Sema &SemaRef,
   return true;
   }
 }
-if (AEntity) {
-  if (!MTE)
-return false;
-  assert(shouldLifetimeExtendThroughPath(Path) ==
- PathLifetimeKind::NoExtend &&
- "No lifetime extension for assignments");
-  if (!pathContainsInit(Path))
-SemaRef.Diag(DiagLoc, diag::warn_dangling_pointer_assignment)
-<< AEntity->LHS << DiagRange;
-  return false;
-}
 
-assert(InitEntity && "only for initialization");
 switch (LK) {
 case LK_FullExpression:
   llvm_unreachable("already handled this");
@@ -1077,6 +1072,17 @@ static void checkExprLifetimeImpl(Sema &SemaRef,
   break;
 }
 
+case LK_Assignment: {
+  if (!MTE)
+return false;
+  assert(shouldLifetimeExtendThroughPath(Path) ==
+ PathLifetimeKind::NoExtend &&
+ "No lifetime extension for assignments");
+  if (!pathContainsInit(Path))
+SemaRef.Diag(DiagLoc, diag::warn_dangling_pointer_assignment)
+<< AEntity->LHS << DiagRange;
+  return false;
+}
 case LK_MemInitializer: {
   if (MTE) {
 // Under C++ DR1696, if a mem-initializer (or a default member
@@ -1283,10 +1289,11 @@ void checkExprLifetime(Sema &SemaRef, const 
InitializedEntity &Entity,
 
 void checkExprLifetime(Sema &SemaRef, const AssignedEntity &Entity,
Expr *Init) {
-  LifetimeKind LK = LK_FullExpression;
-  if (Entity.LHS->getType()->isPointerType()) // builtin pointer type
-LK = LK_Extended;
-  checkExprLifetimeImpl(SemaRef, nullptr, nullptr, LK, &Entity, Init);
+  if (!Entity.LHS->getType()->isPointerType()) // builtin pointer type
+return;
+  checkExprLifetimeImpl(SemaRef, /*InitEntity=*/nullptr,
+/*ExtendingEntity=*/nullptr, LK_Assignment, &Entity,
+Init);
 }
 
 } // namespace clang::sema

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


[clang] [clang] Refactor: Introduce a new LifetimeKind for the assignment case, NFC (PR #99005)

2024-07-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Haojian Wu (hokein)


Changes

The current implementation for the assignment case uses a combination of the 
`LK_Extended` lifetime kind and the validity of `AEntity`, which is somewhat 
messy and doesn't align well with the intended mental model.

This patch introduces a dedicated lifetime kind to handle the assignment case, 
simplifying the implementation and improving clarity.

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


1 Files Affected:

- (modified) clang/lib/Sema/CheckExprLifetime.cpp (+23-16) 


``diff
diff --git a/clang/lib/Sema/CheckExprLifetime.cpp 
b/clang/lib/Sema/CheckExprLifetime.cpp
index 2f9ef28da2c3e..995e4cbadacfe 100644
--- a/clang/lib/Sema/CheckExprLifetime.cpp
+++ b/clang/lib/Sema/CheckExprLifetime.cpp
@@ -39,6 +39,11 @@ enum LifetimeKind {
   /// This is a mem-initializer: if it would extend a temporary (other than via
   /// a default member initializer), the program is ill-formed.
   LK_MemInitializer,
+
+  /// The lifetime of a temporary bound to this entity probably ends too soon,
+  /// because the entity is a pointer and we assign the address of a temporary
+  /// object to it.
+  LK_Assignment,
 };
 using LifetimeResult =
 llvm::PointerIntPair;
@@ -971,6 +976,8 @@ static void checkExprLifetimeImpl(Sema &SemaRef,
   const InitializedEntity *ExtendingEntity,
   LifetimeKind LK,
   const AssignedEntity *AEntity, Expr *Init) {
+  assert((AEntity && LK == LK_Assignment) ||
+ (InitEntity && LK != LK_Assignment));
   // If this entity doesn't have an interesting lifetime, don't bother looking
   // for temporaries within its initializer.
   if (LK == LK_FullExpression)
@@ -1008,19 +1015,7 @@ static void checkExprLifetimeImpl(Sema &SemaRef,
   return true;
   }
 }
-if (AEntity) {
-  if (!MTE)
-return false;
-  assert(shouldLifetimeExtendThroughPath(Path) ==
- PathLifetimeKind::NoExtend &&
- "No lifetime extension for assignments");
-  if (!pathContainsInit(Path))
-SemaRef.Diag(DiagLoc, diag::warn_dangling_pointer_assignment)
-<< AEntity->LHS << DiagRange;
-  return false;
-}
 
-assert(InitEntity && "only for initialization");
 switch (LK) {
 case LK_FullExpression:
   llvm_unreachable("already handled this");
@@ -1077,6 +1072,17 @@ static void checkExprLifetimeImpl(Sema &SemaRef,
   break;
 }
 
+case LK_Assignment: {
+  if (!MTE)
+return false;
+  assert(shouldLifetimeExtendThroughPath(Path) ==
+ PathLifetimeKind::NoExtend &&
+ "No lifetime extension for assignments");
+  if (!pathContainsInit(Path))
+SemaRef.Diag(DiagLoc, diag::warn_dangling_pointer_assignment)
+<< AEntity->LHS << DiagRange;
+  return false;
+}
 case LK_MemInitializer: {
   if (MTE) {
 // Under C++ DR1696, if a mem-initializer (or a default member
@@ -1283,10 +1289,11 @@ void checkExprLifetime(Sema &SemaRef, const 
InitializedEntity &Entity,
 
 void checkExprLifetime(Sema &SemaRef, const AssignedEntity &Entity,
Expr *Init) {
-  LifetimeKind LK = LK_FullExpression;
-  if (Entity.LHS->getType()->isPointerType()) // builtin pointer type
-LK = LK_Extended;
-  checkExprLifetimeImpl(SemaRef, nullptr, nullptr, LK, &Entity, Init);
+  if (!Entity.LHS->getType()->isPointerType()) // builtin pointer type
+return;
+  checkExprLifetimeImpl(SemaRef, /*InitEntity=*/nullptr,
+/*ExtendingEntity=*/nullptr, LK_Assignment, &Entity,
+Init);
 }
 
 } // namespace clang::sema

``




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


[clang] [compiler-rt] [llvm] [PAC][AArch64] Support init/fini array signing (PR #96478)

2024-07-16 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 58c7df90f838251c3682abfe91abadaa68ff6a01 
8d656fc6da199e4fc600ed6454614d03bcc57721 --extensions c,h,cpp -- 
clang/test/CodeGen/ptrauth-init-fini.c 
clang/include/clang/Basic/PointerAuthOptions.h 
clang/lib/CodeGen/CodeGenModule.cpp clang/lib/Driver/ToolChains/Clang.cpp 
clang/lib/Frontend/CompilerInvocation.cpp clang/lib/Headers/ptrauth.h 
clang/test/CodeGen/aarch64-elf-pauthabi.c clang/test/Driver/aarch64-ptrauth.c 
clang/test/Preprocessor/ptrauth_feature.c compiler-rt/lib/builtins/crtbegin.c 
llvm/include/llvm/BinaryFormat/ELF.h llvm/include/llvm/IR/Constants.h 
llvm/lib/IR/Constants.cpp llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp 
llvm/tools/llvm-readobj/ELFDumper.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 6c739b5520..b2d2cb69b3 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -3439,7 +3439,7 @@ static void ParsePointerAuthArgs(LangOptions &Opts, 
ArgList &Args,
   Args.hasArg(OPT_fptrauth_function_pointer_type_discrimination);
   Opts.PointerAuthInitFini = Args.hasArg(OPT_fptrauth_init_fini);
   Opts.PointerAuthInitFiniAddressDiscrimination =
-Args.hasArg(OPT_fptrauth_init_fini_address_discrimination);
+  Args.hasArg(OPT_fptrauth_init_fini_address_discrimination);
 }
 
 /// Check if input file kind and language standard are compatible.

``




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


[clang] [compiler-rt] [llvm] [PAC][AArch64] Support init/fini array signing (PR #96478)

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

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

>From 5399237a71c0ccd872821034d83ea2c3a04bed3f Mon Sep 17 00:00:00 2001
From: Daniil Kovalev 
Date: Fri, 21 Jun 2024 12:32:51 +0300
Subject: [PATCH 1/3] [PAC][AArch64] Support init/fini array signing

If both `-fptrauth-init-fini` and `-fptrauth-calls` are passed, sign
function pointers in `llvm.global_ctors` and `llvm.global_dtors` with
constant discriminator 0xD9D4 (`ptrauth_string_discriminator("init_fini")`).
Additionally, if `-fptrauth-init-fini-address-discrimination` is passed,
address discrimination is used for signing (otherwise, just constant
discriminator is used).
---
 clang/include/clang/Basic/Features.def|  1 +
 clang/include/clang/Basic/LangOptions.def |  1 +
 .../include/clang/Basic/PointerAuthOptions.h  |  7 ++
 clang/include/clang/Driver/Options.td |  1 +
 clang/lib/CodeGen/CodeGenModule.cpp   | 63 +--
 clang/lib/Driver/ToolChains/Clang.cpp |  3 +
 clang/lib/Frontend/CompilerInvocation.cpp |  9 +++
 clang/lib/Headers/ptrauth.h   |  8 ++
 clang/test/CodeGen/aarch64-elf-pauthabi.c | 12 ++-
 clang/test/CodeGen/ptrauth-init-fini.c| 39 ++
 clang/test/Driver/aarch64-ptrauth.c   |  6 +-
 clang/test/Preprocessor/ptrauth_feature.c | 52 +
 compiler-rt/lib/builtins/crtbegin.c   | 16 
 llvm/include/llvm/BinaryFormat/ELF.h  |  3 +-
 .../AArch64/note-gnu-property-elf-pauthabi.ll |  2 +-
 .../test/CodeGen/AArch64/ptrauth-init-fini.ll | 77 +++
 .../ELF/AArch64/aarch64-feature-pauth.s   | 18 ++---
 llvm/tools/llvm-readobj/ELFDumper.cpp |  4 +-
 18 files changed, 268 insertions(+), 54 deletions(-)
 create mode 100644 clang/test/CodeGen/ptrauth-init-fini.c
 create mode 100644 llvm/test/CodeGen/AArch64/ptrauth-init-fini.ll

diff --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index 53f410d3cb4bd..5dca40b261655 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -110,6 +110,7 @@ FEATURE(ptrauth_vtable_pointer_address_discrimination, 
LangOpts.PointerAuthVTPtr
 FEATURE(ptrauth_vtable_pointer_type_discrimination, 
LangOpts.PointerAuthVTPtrTypeDiscrimination)
 FEATURE(ptrauth_member_function_pointer_type_discrimination, 
LangOpts.PointerAuthCalls)
 FEATURE(ptrauth_init_fini, LangOpts.PointerAuthInitFini)
+FEATURE(ptrauth_init_fini_address_discrimination, 
LangOpts.PointerAuthInitFiniAddressDiscrimination)
 EXTENSION(swiftcc,
   PP.getTargetInfo().checkCallingConvention(CC_Swift) ==
   clang::TargetInfo::CCCR_OK)
diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 6dd6b5614f44c..2de854731 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -168,6 +168,7 @@ LANGOPT(PointerAuthAuthTraps, 1, 0, "pointer authentication 
failure traps")
 LANGOPT(PointerAuthVTPtrAddressDiscrimination, 1, 0, "incorporate address 
discrimination in authenticated vtable pointers")
 LANGOPT(PointerAuthVTPtrTypeDiscrimination, 1, 0, "incorporate type 
discrimination in authenticated vtable pointers")
 LANGOPT(PointerAuthInitFini, 1, 0, "sign function pointers in init/fini 
arrays")
+LANGOPT(PointerAuthInitFiniAddressDiscrimination, 1, 0, "incorporate address 
discrimination in authenticated function pointers in init/fini arrays")
 
 LANGOPT(DoubleSquareBracketAttributes, 1, 0, "'[[]]' attributes extension for 
all language standard modes")
 LANGOPT(ExperimentalLateParseAttributes, 1, 0, "experimental late parsing of 
attributes")
diff --git a/clang/include/clang/Basic/PointerAuthOptions.h 
b/clang/include/clang/Basic/PointerAuthOptions.h
index aaad4a2b2b5ae..9e2b64111e461 100644
--- a/clang/include/clang/Basic/PointerAuthOptions.h
+++ b/clang/include/clang/Basic/PointerAuthOptions.h
@@ -23,6 +23,10 @@
 
 namespace clang {
 
+/// Constant discriminator to be used with function pointers in .init_array and
+/// .fini_array. The value is ptrauth_string_discriminator("init_fini")
+constexpr uint16_t InitFiniPointerConstantDiscriminator = 0xD9D4;
+
 constexpr unsigned PointerAuthKeyNone = -1;
 
 class PointerAuthSchema {
@@ -150,6 +154,9 @@ class PointerAuthSchema {
 struct PointerAuthOptions {
   /// The ABI for C function pointers.
   PointerAuthSchema FunctionPointers;
+
+  /// The ABI for function addresses in .init_array and .fini_array
+  PointerAuthSchema InitFiniPointers;
 };
 
 } // end namespace clang
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c529cc9506667..5b8d4139d975b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4228,6 +4228,7 @@ defm ptrauth_vtable_pointer_address_discrimination :
 defm ptrauth_vtable_pointer_type_discrimination :
   OptInCC1FFlag<"ptrauth-vtable-pointer-type-discrimin

[clang] 2448927 - [Clang][C++26] Implement "Ordering of constraints involving fold expressions (#98160)

2024-07-16 Thread via cfe-commits

Author: cor3ntin
Date: 2024-07-16T10:39:06+02:00
New Revision: 244892735941a455506ae38ae0fb40cf80cdb351

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

LOG: [Clang][C++26] Implement "Ordering of constraints involving fold 
expressions (#98160)

Implement https://isocpp.org/files/papers/P2963R3.pdf

Added: 
clang/test/SemaCXX/cxx2c-fold-exprs.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/Sema.h
clang/include/clang/Sema/SemaConcept.h
clang/lib/Sema/SemaConcept.cpp
clang/lib/Sema/SemaTemplateVariadic.cpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 969856a8f978c..cb35825b71e3e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -278,6 +278,9 @@ C++2c Feature Support
 
 - Implemented `P3144R2 Deleting a Pointer to an Incomplete Type Should be 
Ill-formed `_.
 
+- Implemented `P2963R3 Ordering of constraints involving fold expressions 
`_.
+
+
 Resolutions to C++ Defect Reports
 ^
 - Substitute template parameter pack, when it is not explicitly specified

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 48dff1b76cc57..3cb1aa935fe46 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -14078,6 +14078,11 @@ class Sema final : public SemaBase {
   const DeclarationNameInfo &NameInfo,
   SmallVectorImpl &Unexpanded);
 
+  /// Collect the set of unexpanded parameter packs within the given
+  /// expression.
+  static void collectUnexpandedParameterPacks(
+  Expr *E, SmallVectorImpl &Unexpanded);
+
   /// Invoked when parsing a template argument followed by an
   /// ellipsis, which creates a pack expansion.
   ///

diff  --git a/clang/include/clang/Sema/SemaConcept.h 
b/clang/include/clang/Sema/SemaConcept.h
index 711443505174f..8fb7dd6838e57 100644
--- a/clang/include/clang/Sema/SemaConcept.h
+++ b/clang/include/clang/Sema/SemaConcept.h
@@ -75,6 +75,26 @@ struct AtomicConstraint {
   }
 };
 
+struct FoldExpandedConstraint;
+
+using NormalFormConstraint =
+llvm::PointerUnion;
+struct NormalizedConstraint;
+using NormalForm =
+llvm::SmallVector, 4>;
+
+// A constraint is in conjunctive normal form when it is a conjunction of
+// clauses where each clause is a disjunction of atomic constraints. For atomic
+// constraints A, B, and C, the constraint A  ∧ (B  ∨ C) is in conjunctive
+// normal form.
+NormalForm makeCNF(const NormalizedConstraint &Normalized);
+
+// A constraint is in disjunctive normal form when it is a disjunction of
+// clauses where each clause is a conjunction of atomic constraints. For atomic
+// constraints A, B, and C, the disjunctive normal form of the constraint A
+//  ∧ (B  ∨ C) is (A  ∧ B)  ∨ (A  ∧ C).
+NormalForm makeDNF(const NormalizedConstraint &Normalized);
+
 /// \brief A normalized constraint, as defined in C++ [temp.constr.normal], is
 /// either an atomic constraint, a conjunction of normalized constraints or a
 /// disjunction of normalized constraints.
@@ -87,26 +107,17 @@ struct NormalizedConstraint {
   std::pair *, 1,
   CompoundConstraintKind>;
 
-  llvm::PointerUnion Constraint;
+  llvm::PointerUnion
+  Constraint;
 
   NormalizedConstraint(AtomicConstraint *C): Constraint{C} { };
+  NormalizedConstraint(FoldExpandedConstraint *C) : Constraint{C} {};
+
   NormalizedConstraint(ASTContext &C, NormalizedConstraint LHS,
-   NormalizedConstraint RHS, CompoundConstraintKind Kind)
-  : Constraint{CompoundConstraint{
-new (C) std::pair{
-std::move(LHS), std::move(RHS)}, Kind}} { };
-
-  NormalizedConstraint(ASTContext &C, const NormalizedConstraint &Other) {
-if (Other.isAtomic()) {
-  Constraint = new (C) AtomicConstraint(*Other.getAtomicConstraint());
-} else {
-  Constraint = CompoundConstraint(
-  new (C) std::pair{
-  NormalizedConstraint(C, Other.getLHS()),
-  NormalizedConstraint(C, Other.getRHS())},
-  Other.getCompoundKind());
-}
-  }
+   NormalizedConstraint RHS, CompoundConstraintKind Kind);
+
+  NormalizedConstraint(ASTContext &C, const NormalizedConstraint &Other);
   NormalizedConstraint(NormalizedConstraint &&Other):
   Constraint(Other.Constraint) {
 Other.Constraint = nullptr;
@@ -120,20 +131,24 @@ struct NormalizedConstraint {
 return *this;
   }
 
+  bool isAtomic() const { return Constraint.is(); }
+  bool isFoldExpanded() const {
+return Constraint.is();
+  }
+  bool isCompound() const { return Constraint.is(); }
+
   CompoundConstraintKind getCompoundKind() co

[clang] [Clang][C++26] Implement "Ordering of constraints involving fold expressions (PR #98160)

2024-07-16 Thread via cfe-commits

cor3ntin wrote:

I'll merge that. If there are further feedback I'd be happy to do post commit 
reviews and additional work on this feature

@AaronBallman Thanks for the review!

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


[clang] [Clang][C++26] Implement "Ordering of constraints involving fold expressions (PR #98160)

2024-07-16 Thread via cfe-commits

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


[clang] [Clang][C++26] Implement "Ordering of constraints involving fold expressions (PR #98160)

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `clang-armv8-quick` running 
on `linaro-clang-armv8-quick` while building `clang` at step 4 "build stage 1".

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

Here is the relevant piece of the build log for the reference:
```
Step 4 (build stage 1) failure: 'ninja' (failure)
[1/281] Building CXX object 
tools/llvm-config/CMakeFiles/llvm-config.dir/llvm-config.cpp.o
[2/281] Generating VCSRevision.h
[3/281] Generating VCSVersion.inc
[4/281] Building CXX object 
tools/clang/lib/Parse/CMakeFiles/obj.clangParse.dir/ParseCXXInlineMethods.cpp.o
FAILED: 
tools/clang/lib/Parse/CMakeFiles/obj.clangParse.dir/ParseCXXInlineMethods.cpp.o 
/usr/local/bin/c++ -DGTEST_HAS_RTTI=0 -D_DEBUG -D_FILE_OFFSET_BITS=64 
-D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D_LARGEFILE_SOURCE 
-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-I/home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/lib/Parse 
-I/home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/lib/Parse 
-I/home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/include 
-I/home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/include 
-I/home/tcwg-buildbot/worker/clang-armv8-quick/stage1/include 
-I/home/tcwg-buildbot/worker/clang-armv8-quick/llvm/llvm/include -fPIC 
-fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time 
-Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter 
-Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic 
-Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough 
-Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor 
-Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion 
-Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color 
-ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual 
-Wno-nested-anon-types -O3 -DNDEBUG  -fno-exceptions -funwind-tables -fno-rtti 
-UNDEBUG -std=c++17 -MD -MT 
tools/clang/lib/Parse/CMakeFiles/obj.clangParse.dir/ParseCXXInlineMethods.cpp.o 
-MF 
tools/clang/lib/Parse/CMakeFiles/obj.clangParse.dir/ParseCXXInlineMethods.cpp.o.d
 -o 
tools/clang/lib/Parse/CMakeFiles/obj.clangParse.dir/ParseCXXInlineMethods.cpp.o 
-c 
/home/tcwg-buildbot/worker/clang-armv8-quick/llvm/clang/lib/Parse/ParseCXXInlineMethods.cpp
In file included from ../llvm/clang/lib/Parse/ParseCXXInlineMethods.cpp:13:
In file included from ../llvm/clang/include/clang/AST/DeclTemplate.h:17:
In file included from ../llvm/clang/include/clang/AST/ASTConcept.h:17:
In file included from ../llvm/clang/include/clang/AST/DeclarationName.h:16:
In file included from ../llvm/clang/include/clang/AST/Type.h:21:
In file included from ../llvm/clang/include/clang/AST/NestedNameSpecifier.h:18:
In file included from ../llvm/clang/include/clang/Basic/Diagnostic.h:19:
In file included from ../llvm/clang/include/clang/Basic/SourceLocation.h:17:
In file included from ../llvm/clang/include/clang/Basic/FileEntry.h:22:
In file included from ../llvm/llvm/include/llvm/ADT/PointerUnion.h:19:
../llvm/llvm/include/llvm/ADT/PointerIntPair.h:172:17: error: static assertion 
failed due to requirement '2U <= PointerUnionUIntTraits *, 1, 
clang::NormalizedConstraint::CompoundConstraintKind, 
llvm::PointerLikeTypeTraits *>, 
llvm::PointerIntPairInfo *, 1, 
llvm::PointerLikeTypeTraits *::NumLowBitsAvailable': PointerIntPair with 
integer size too large for pointer
  172 |   static_assert(IntBits <= PtrTraits::NumLowBitsAvailable,
  | ^
../llvm/llvm/include/llvm/ADT/PointerIntPair.h:111:13: note: in instantiation 
of template class 'llvm::PointerIntPairInfo *, 1, 
clang::NormalizedConstraint::CompoundConstraintKind>>>' requested here
  111 | Value = Info::updateInt(Info::updatePointer(0, PtrVal),
  | ^
../llvm/llvm/include/llvm/ADT/PointerIntPair.h:89:5: note: in instantiation of 
member function 'llvm::PointerIntPair *, 1, 
clang::NormalizedConstraint::CompoundConstraintKind>>>::setPointerAndInt' 
requested here
   89 | setPointerAndInt(PtrVal, IntVal);
  | ^
../llvm/llvm/include/llvm/ADT/PointerUnion.h:77:16: note: in instantiation of 
member function 'llvm::PointerIntPair *, 1, 
clang::NormalizedConstraint::CompoundConstraintKind>>>::PointerIntPair' 
requested here
   77 | : Base(ValTy(const_cast(
  |^
../llvm/clang/include/clang/Sema/SemaConcept.h:114:46: note: in instantiation 
of member function 
'llvm::pointer_union_detail::PointerUnionMembers *, 1, 
clang::NormalizedConstraint::CompoundConstraintKind>>, 
llvm::PointerIntPair *, 1, 
clang::NormalizedConstraint::CompoundConstraintKind>>>, 0, 
clang::AtomicConstraint *, clang::FoldExpandedConstraint *, 
llvm::PointerIntPair *, 1, 
clang::NormalizedConstraint::CompoundConstraintKind>>::PointerUnionMembers' 
requested here
  114 |   NormalizedConstraint(AtomicConstraint *C): Cons

[clang] [clang] Add deprecation warning for `-Ofast` driver option (PR #98736)

2024-07-16 Thread via cfe-commits

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

LGTM!

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


[clang] [clang][driver] Support `--precompile` and `-fmodule-*` options in Clang-CL (PR #98761)

2024-07-16 Thread Chuanqi Xu via cfe-commits


@@ -242,7 +242,7 @@ bool types::isCXX(ID Id) {
   case TY_CXXHUHeader:
   case TY_PP_CXXHeaderUnit:
   case TY_ObjCXXHeader: case TY_PP_ObjCXXHeader:
-  case TY_CXXModule: case TY_PP_CXXModule:
+  case TY_CXXModule: case TY_PP_CXXModule: case TY_ModuleFile:

ChuanqiXu9 wrote:

If this is needed, it should be in a separate patch. Let's do one thing in one 
PR.

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


[clang] [Clang][C++26] Implement "Ordering of constraints involving fold expressions (PR #98160)

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `lldb-arm-ubuntu` running 
on `linaro-lldb-arm-ubuntu` while building `clang` at step 4 "build".

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

Here is the relevant piece of the build log for the reference:
```
Step 4 (build) failure: build (failure)
...
33.973 [2544/30/3650] Building CXX object 
tools/clang/lib/CodeGen/CMakeFiles/obj.clangCodeGen.dir/CGObjCGNU.cpp.o
33.975 [2544/29/3651] Building CXX object 
tools/clang/lib/CodeGen/CMakeFiles/obj.clangCodeGen.dir/CGOpenMPRuntimeGPU.cpp.o
33.977 [2544/28/3652] Building CXX object 
tools/clang/lib/CodeGen/CMakeFiles/obj.clangCodeGen.dir/CGOpenCLRuntime.cpp.o
33.985 [2544/27/3653] Building CXX object 
tools/clang/lib/CodeGen/CMakeFiles/obj.clangCodeGen.dir/CGOpenMPRuntime.cpp.o
34.049 [2544/26/3654] Building CXX object 
tools/clang/lib/AST/CMakeFiles/obj.clangAST.dir/CommentSema.cpp.o
34.085 [2544/25/3655] Building CXX object 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Version.cpp.o
34.131 [2544/24/3656] Building CXX object 
tools/clang/lib/AST/CMakeFiles/obj.clangAST.dir/Expr.cpp.o
34.287 [2544/23/3657] Building CXX object 
lib/LTO/CMakeFiles/LLVMLTO.dir/LTO.cpp.o
34.343 [2544/22/3658] Building CXX object 
tools/clang/lib/CodeGen/CMakeFiles/obj.clangCodeGen.dir/BackendUtil.cpp.o
37.510 [2544/21/3659] Building CXX object 
tools/clang/lib/Parse/CMakeFiles/obj.clangParse.dir/ParseDecl.cpp.o
FAILED: tools/clang/lib/Parse/CMakeFiles/obj.clangParse.dir/ParseDecl.cpp.o 
/usr/local/bin/c++ -DGTEST_HAS_RTTI=0 -D_DEBUG -D_FILE_OFFSET_BITS=64 
-D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D_LARGEFILE_SOURCE 
-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-I/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/tools/clang/lib/Parse 
-I/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/clang/lib/Parse 
-I/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/clang/include 
-I/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/tools/clang/include 
-I/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/include 
-I/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/llvm/include -fPIC 
-fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time 
-Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter 
-Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic 
-Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough 
-Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor 
-Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion 
-Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color 
-ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual 
-Wno-nested-anon-types -O3 -DNDEBUG  -fno-exceptions -funwind-tables -fno-rtti 
-UNDEBUG -std=c++17 -MD -MT 
tools/clang/lib/Parse/CMakeFiles/obj.clangParse.dir/ParseDecl.cpp.o -MF 
tools/clang/lib/Parse/CMakeFiles/obj.clangParse.dir/ParseDecl.cpp.o.d -o 
tools/clang/lib/Parse/CMakeFiles/obj.clangParse.dir/ParseDecl.cpp.o -c 
/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/clang/lib/Parse/ParseDecl.cpp
In file included from ../llvm-project/clang/lib/Parse/ParseDecl.cpp:13:
In file included from ../llvm-project/clang/include/clang/AST/ASTContext.h:18:
In file included from 
../llvm-project/clang/include/clang/AST/CanonicalType.h:17:
In file included from ../llvm-project/clang/include/clang/AST/Type.h:21:
In file included from 
../llvm-project/clang/include/clang/AST/NestedNameSpecifier.h:18:
In file included from ../llvm-project/clang/include/clang/Basic/Diagnostic.h:19:
In file included from 
../llvm-project/clang/include/clang/Basic/SourceLocation.h:17:
In file included from ../llvm-project/clang/include/clang/Basic/FileEntry.h:22:
In file included from ../llvm-project/llvm/include/llvm/ADT/PointerUnion.h:19:
../llvm-project/llvm/include/llvm/ADT/PointerIntPair.h:172:17: error: static 
assertion failed due to requirement '2U <= 
PointerUnionUIntTraits *, 1, 
clang::NormalizedConstraint::CompoundConstraintKind, 
llvm::PointerLikeTypeTraits *>, 
llvm::PointerIntPairInfo *, 1, 
llvm::PointerLikeTypeTraits *::NumLowBitsAvailable': PointerIntPair with 
integer size too large for pointer
  172 |   static_assert(IntBits <= PtrTraits::NumLowBitsAvailable,
  | ^
../llvm-project/llvm/include/llvm/ADT/PointerIntPair.h:111:13: note: in 
instantiation of template class 'llvm::PointerIntPairInfo *, 1, 
clang::NormalizedConstraint::CompoundConstraintKind>>>' requested here
  111 | Value = Info::updateInt(Info::updatePointer(0, PtrVal),
  | ^
../llvm-project/llvm/include/llvm/ADT/PointerIntPair.h:89:5: note: in 
instantiation of member function 'llvm::PointerIntPair *, 1, 
clang::NormalizedConstraint::CompoundConstraintKind>>>::setPointerAndInt' 
requested here
   89 | setPointerAndInt(PtrVal, IntVal);
  | ^
../llvm-project/llvm/inclu

[clang] Revert "[Clang][C++26] Implement "Ordering of constraints involving fold expressions" (PR #99007)

2024-07-16 Thread via cfe-commits

https://github.com/cor3ntin created 
https://github.com/llvm/llvm-project/pull/99007

Reverts llvm/llvm-project#98160

Breaks CI on some architectures

>From 97a9ef1c1810b88102d097d334b2017cce782390 Mon Sep 17 00:00:00 2001
From: cor3ntin 
Date: Tue, 16 Jul 2024 10:59:38 +0200
Subject: [PATCH] =?UTF-8?q?Revert=20"[Clang][C++26]=20Implement=20"Orderin?=
 =?UTF-8?q?g=20of=20constraints=20involving=20fold=20expr=E2=80=A6"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This reverts commit 244892735941a455506ae38ae0fb40cf80cdb351.
---
 clang/docs/ReleaseNotes.rst |   3 -
 clang/include/clang/Sema/Sema.h |   5 -
 clang/include/clang/Sema/SemaConcept.h  | 171 +--
 clang/lib/Sema/SemaConcept.cpp  | 603 
 clang/lib/Sema/SemaTemplateVariadic.cpp |   4 -
 clang/test/SemaCXX/cxx2c-fold-exprs.cpp | 277 ---
 clang/www/cxx_status.html   |   2 +-
 7 files changed, 223 insertions(+), 842 deletions(-)
 delete mode 100644 clang/test/SemaCXX/cxx2c-fold-exprs.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index cb35825b71e3e..969856a8f978c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -278,9 +278,6 @@ C++2c Feature Support
 
 - Implemented `P3144R2 Deleting a Pointer to an Incomplete Type Should be 
Ill-formed `_.
 
-- Implemented `P2963R3 Ordering of constraints involving fold expressions 
`_.
-
-
 Resolutions to C++ Defect Reports
 ^
 - Substitute template parameter pack, when it is not explicitly specified
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 3cb1aa935fe46..48dff1b76cc57 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -14078,11 +14078,6 @@ class Sema final : public SemaBase {
   const DeclarationNameInfo &NameInfo,
   SmallVectorImpl &Unexpanded);
 
-  /// Collect the set of unexpanded parameter packs within the given
-  /// expression.
-  static void collectUnexpandedParameterPacks(
-  Expr *E, SmallVectorImpl &Unexpanded);
-
   /// Invoked when parsing a template argument followed by an
   /// ellipsis, which creates a pack expansion.
   ///
diff --git a/clang/include/clang/Sema/SemaConcept.h 
b/clang/include/clang/Sema/SemaConcept.h
index 8fb7dd6838e57..711443505174f 100644
--- a/clang/include/clang/Sema/SemaConcept.h
+++ b/clang/include/clang/Sema/SemaConcept.h
@@ -75,26 +75,6 @@ struct AtomicConstraint {
   }
 };
 
-struct FoldExpandedConstraint;
-
-using NormalFormConstraint =
-llvm::PointerUnion;
-struct NormalizedConstraint;
-using NormalForm =
-llvm::SmallVector, 4>;
-
-// A constraint is in conjunctive normal form when it is a conjunction of
-// clauses where each clause is a disjunction of atomic constraints. For atomic
-// constraints A, B, and C, the constraint A  ∧ (B  ∨ C) is in conjunctive
-// normal form.
-NormalForm makeCNF(const NormalizedConstraint &Normalized);
-
-// A constraint is in disjunctive normal form when it is a disjunction of
-// clauses where each clause is a conjunction of atomic constraints. For atomic
-// constraints A, B, and C, the disjunctive normal form of the constraint A
-//  ∧ (B  ∨ C) is (A  ∧ B)  ∨ (A  ∧ C).
-NormalForm makeDNF(const NormalizedConstraint &Normalized);
-
 /// \brief A normalized constraint, as defined in C++ [temp.constr.normal], is
 /// either an atomic constraint, a conjunction of normalized constraints or a
 /// disjunction of normalized constraints.
@@ -107,17 +87,26 @@ struct NormalizedConstraint {
   std::pair *, 1,
   CompoundConstraintKind>;
 
-  llvm::PointerUnion
-  Constraint;
+  llvm::PointerUnion Constraint;
 
   NormalizedConstraint(AtomicConstraint *C): Constraint{C} { };
-  NormalizedConstraint(FoldExpandedConstraint *C) : Constraint{C} {};
-
   NormalizedConstraint(ASTContext &C, NormalizedConstraint LHS,
-   NormalizedConstraint RHS, CompoundConstraintKind Kind);
-
-  NormalizedConstraint(ASTContext &C, const NormalizedConstraint &Other);
+   NormalizedConstraint RHS, CompoundConstraintKind Kind)
+  : Constraint{CompoundConstraint{
+new (C) std::pair{
+std::move(LHS), std::move(RHS)}, Kind}} { };
+
+  NormalizedConstraint(ASTContext &C, const NormalizedConstraint &Other) {
+if (Other.isAtomic()) {
+  Constraint = new (C) AtomicConstraint(*Other.getAtomicConstraint());
+} else {
+  Constraint = CompoundConstraint(
+  new (C) std::pair{
+  NormalizedConstraint(C, Other.getLHS()),
+  NormalizedConstraint(C, Other.getRHS())},
+  Other.getCompoundKind());
+}
+  }
   NormalizedConstraint(NormalizedConstraint &&Other):
   Constraint(Other.Constraint) {
 Other.Constraint = nullptr;
@@ -131,24 +120,20 @@ struct NormalizedConstraint {

[clang] 762a478 - Revert "[Clang][C++26] Implement "Ordering of constraints involving fold expressions" (#99007)

2024-07-16 Thread via cfe-commits

Author: cor3ntin
Date: 2024-07-16T11:00:27+02:00
New Revision: 762a47828ef6c19426e37e1ecae6768035a4ccac

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

LOG: Revert "[Clang][C++26] Implement "Ordering of constraints involving fold 
expressions" (#99007)

Reverts llvm/llvm-project#98160

Breaks CI on some architectures

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/Sema.h
clang/include/clang/Sema/SemaConcept.h
clang/lib/Sema/SemaConcept.cpp
clang/lib/Sema/SemaTemplateVariadic.cpp
clang/www/cxx_status.html

Removed: 
clang/test/SemaCXX/cxx2c-fold-exprs.cpp



diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index cb35825b71e3e..969856a8f978c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -278,9 +278,6 @@ C++2c Feature Support
 
 - Implemented `P3144R2 Deleting a Pointer to an Incomplete Type Should be 
Ill-formed `_.
 
-- Implemented `P2963R3 Ordering of constraints involving fold expressions 
`_.
-
-
 Resolutions to C++ Defect Reports
 ^
 - Substitute template parameter pack, when it is not explicitly specified

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 3cb1aa935fe46..48dff1b76cc57 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -14078,11 +14078,6 @@ class Sema final : public SemaBase {
   const DeclarationNameInfo &NameInfo,
   SmallVectorImpl &Unexpanded);
 
-  /// Collect the set of unexpanded parameter packs within the given
-  /// expression.
-  static void collectUnexpandedParameterPacks(
-  Expr *E, SmallVectorImpl &Unexpanded);
-
   /// Invoked when parsing a template argument followed by an
   /// ellipsis, which creates a pack expansion.
   ///

diff  --git a/clang/include/clang/Sema/SemaConcept.h 
b/clang/include/clang/Sema/SemaConcept.h
index 8fb7dd6838e57..711443505174f 100644
--- a/clang/include/clang/Sema/SemaConcept.h
+++ b/clang/include/clang/Sema/SemaConcept.h
@@ -75,26 +75,6 @@ struct AtomicConstraint {
   }
 };
 
-struct FoldExpandedConstraint;
-
-using NormalFormConstraint =
-llvm::PointerUnion;
-struct NormalizedConstraint;
-using NormalForm =
-llvm::SmallVector, 4>;
-
-// A constraint is in conjunctive normal form when it is a conjunction of
-// clauses where each clause is a disjunction of atomic constraints. For atomic
-// constraints A, B, and C, the constraint A  ∧ (B  ∨ C) is in conjunctive
-// normal form.
-NormalForm makeCNF(const NormalizedConstraint &Normalized);
-
-// A constraint is in disjunctive normal form when it is a disjunction of
-// clauses where each clause is a conjunction of atomic constraints. For atomic
-// constraints A, B, and C, the disjunctive normal form of the constraint A
-//  ∧ (B  ∨ C) is (A  ∧ B)  ∨ (A  ∧ C).
-NormalForm makeDNF(const NormalizedConstraint &Normalized);
-
 /// \brief A normalized constraint, as defined in C++ [temp.constr.normal], is
 /// either an atomic constraint, a conjunction of normalized constraints or a
 /// disjunction of normalized constraints.
@@ -107,17 +87,26 @@ struct NormalizedConstraint {
   std::pair *, 1,
   CompoundConstraintKind>;
 
-  llvm::PointerUnion
-  Constraint;
+  llvm::PointerUnion Constraint;
 
   NormalizedConstraint(AtomicConstraint *C): Constraint{C} { };
-  NormalizedConstraint(FoldExpandedConstraint *C) : Constraint{C} {};
-
   NormalizedConstraint(ASTContext &C, NormalizedConstraint LHS,
-   NormalizedConstraint RHS, CompoundConstraintKind Kind);
-
-  NormalizedConstraint(ASTContext &C, const NormalizedConstraint &Other);
+   NormalizedConstraint RHS, CompoundConstraintKind Kind)
+  : Constraint{CompoundConstraint{
+new (C) std::pair{
+std::move(LHS), std::move(RHS)}, Kind}} { };
+
+  NormalizedConstraint(ASTContext &C, const NormalizedConstraint &Other) {
+if (Other.isAtomic()) {
+  Constraint = new (C) AtomicConstraint(*Other.getAtomicConstraint());
+} else {
+  Constraint = CompoundConstraint(
+  new (C) std::pair{
+  NormalizedConstraint(C, Other.getLHS()),
+  NormalizedConstraint(C, Other.getRHS())},
+  Other.getCompoundKind());
+}
+  }
   NormalizedConstraint(NormalizedConstraint &&Other):
   Constraint(Other.Constraint) {
 Other.Constraint = nullptr;
@@ -131,24 +120,20 @@ struct NormalizedConstraint {
 return *this;
   }
 
-  bool isAtomic() const { return Constraint.is(); }
-  bool isFoldExpanded() const {
-return Constraint.is();
-  }
-  bool isCompound() const { return Constraint.is(); }
-
   CompoundConstraintKind 

[clang] Revert "[Clang][C++26] Implement "Ordering of constraints involving fold expressions" (PR #99007)

2024-07-16 Thread via cfe-commits

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


[clang] [clang][driver] Fix -print-libgcc-file-name on Darwin platforms (PR #98325)

2024-07-16 Thread Gábor Horváth via cfe-commits

Xazax-hun wrote:

@MaskRay Thanks for the review. Do you think this is good to go or is there 
anything else you want me to change?

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


[clang] Revert "[Clang][C++26] Implement "Ordering of constraints involving fold expressions" (PR #99007)

2024-07-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: cor3ntin (cor3ntin)


Changes

Reverts llvm/llvm-project#98160

Breaks CI on some architectures

---

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


7 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (-3) 
- (modified) clang/include/clang/Sema/Sema.h (-5) 
- (modified) clang/include/clang/Sema/SemaConcept.h (+22-149) 
- (modified) clang/lib/Sema/SemaConcept.cpp (+200-403) 
- (modified) clang/lib/Sema/SemaTemplateVariadic.cpp (-4) 
- (removed) clang/test/SemaCXX/cxx2c-fold-exprs.cpp (-277) 
- (modified) clang/www/cxx_status.html (+1-1) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index cb35825b71e3e..969856a8f978c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -278,9 +278,6 @@ C++2c Feature Support
 
 - Implemented `P3144R2 Deleting a Pointer to an Incomplete Type Should be 
Ill-formed `_.
 
-- Implemented `P2963R3 Ordering of constraints involving fold expressions 
`_.
-
-
 Resolutions to C++ Defect Reports
 ^
 - Substitute template parameter pack, when it is not explicitly specified
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 3cb1aa935fe46..48dff1b76cc57 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -14078,11 +14078,6 @@ class Sema final : public SemaBase {
   const DeclarationNameInfo &NameInfo,
   SmallVectorImpl &Unexpanded);
 
-  /// Collect the set of unexpanded parameter packs within the given
-  /// expression.
-  static void collectUnexpandedParameterPacks(
-  Expr *E, SmallVectorImpl &Unexpanded);
-
   /// Invoked when parsing a template argument followed by an
   /// ellipsis, which creates a pack expansion.
   ///
diff --git a/clang/include/clang/Sema/SemaConcept.h 
b/clang/include/clang/Sema/SemaConcept.h
index 8fb7dd6838e57..711443505174f 100644
--- a/clang/include/clang/Sema/SemaConcept.h
+++ b/clang/include/clang/Sema/SemaConcept.h
@@ -75,26 +75,6 @@ struct AtomicConstraint {
   }
 };
 
-struct FoldExpandedConstraint;
-
-using NormalFormConstraint =
-llvm::PointerUnion;
-struct NormalizedConstraint;
-using NormalForm =
-llvm::SmallVector, 4>;
-
-// A constraint is in conjunctive normal form when it is a conjunction of
-// clauses where each clause is a disjunction of atomic constraints. For atomic
-// constraints A, B, and C, the constraint A  ∧ (B  ∨ C) is in conjunctive
-// normal form.
-NormalForm makeCNF(const NormalizedConstraint &Normalized);
-
-// A constraint is in disjunctive normal form when it is a disjunction of
-// clauses where each clause is a conjunction of atomic constraints. For atomic
-// constraints A, B, and C, the disjunctive normal form of the constraint A
-//  ∧ (B  ∨ C) is (A  ∧ B)  ∨ (A  ∧ C).
-NormalForm makeDNF(const NormalizedConstraint &Normalized);
-
 /// \brief A normalized constraint, as defined in C++ [temp.constr.normal], is
 /// either an atomic constraint, a conjunction of normalized constraints or a
 /// disjunction of normalized constraints.
@@ -107,17 +87,26 @@ struct NormalizedConstraint {
   std::pair *, 1,
   CompoundConstraintKind>;
 
-  llvm::PointerUnion
-  Constraint;
+  llvm::PointerUnion Constraint;
 
   NormalizedConstraint(AtomicConstraint *C): Constraint{C} { };
-  NormalizedConstraint(FoldExpandedConstraint *C) : Constraint{C} {};
-
   NormalizedConstraint(ASTContext &C, NormalizedConstraint LHS,
-   NormalizedConstraint RHS, CompoundConstraintKind Kind);
-
-  NormalizedConstraint(ASTContext &C, const NormalizedConstraint &Other);
+   NormalizedConstraint RHS, CompoundConstraintKind Kind)
+  : Constraint{CompoundConstraint{
+new (C) std::pair{
+std::move(LHS), std::move(RHS)}, Kind}} { };
+
+  NormalizedConstraint(ASTContext &C, const NormalizedConstraint &Other) {
+if (Other.isAtomic()) {
+  Constraint = new (C) AtomicConstraint(*Other.getAtomicConstraint());
+} else {
+  Constraint = CompoundConstraint(
+  new (C) std::pair{
+  NormalizedConstraint(C, Other.getLHS()),
+  NormalizedConstraint(C, Other.getRHS())},
+  Other.getCompoundKind());
+}
+  }
   NormalizedConstraint(NormalizedConstraint &&Other):
   Constraint(Other.Constraint) {
 Other.Constraint = nullptr;
@@ -131,24 +120,20 @@ struct NormalizedConstraint {
 return *this;
   }
 
-  bool isAtomic() const { return Constraint.is(); }
-  bool isFoldExpanded() const {
-return Constraint.is();
-  }
-  bool isCompound() const { return Constraint.is(); }
-
   CompoundConstraintKind getCompoundKind() const {
-assert(isCompound() && "getCompoundKind on a non-compound constraint..");
+assert(!isAtomic() && "getCompoundKind calle

[clang] [clang] Refactor: Introduce a new LifetimeKind for the assignment case, NFC (PR #99005)

2024-07-16 Thread Gábor Horváth via cfe-commits

https://github.com/Xazax-hun approved this pull request.

LGTM!

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


[clang] [Bounds-Safety] Add sized_by, counted_by_or_null & sized_by_or_null (PR #93231)

2024-07-16 Thread Gábor Horváth via cfe-commits

Xazax-hun wrote:

I really like the test coverage of this feature, but I started to wonder if we 
should start splitting up some sema tests into subfolders. I think the 
bounds-safety related tests would be a good candidate to have their own 
subfolder :)

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


[clang] [clang] Inject tokens containing #embed back into token stream (PR #97274)

2024-07-16 Thread Jakub Jelínek via cfe-commits

jakubjelinek wrote:

@ThePhd @AaronBallman
And even more importantly (checking on godbolt again):
```c
int a = sizeof (
#embed __FILE__ limit (1)
);
```
is 1 in clang as well as clang++ trunk and 4 with clang/clang++ trunk with 
-save-temps.
I thought there was agreement that at least for C the literals have type int, 
for C++ it is fuzzy and depends on what will be voted in but in any case, there 
shouldn't be different code produced between integrated preprocessing and 
-save-temps.
If C++ requires some cast, it would need to make it clear what that exact cast 
is, i.e. whether it is supposed to be
```c
12,143,12,16
```
or
```c
static_cast(12),static_cast(143),static_cast(12),static_cast(16)
```
or
```c
(unsigned char)12,(unsigned char)143,(unsigned char)12,(unsigned char)16
```
or
```c
'\014','\0217','\014','\020'
```
or whatever else and the preprocessor would need to emit that cast on every 
literal (unless using some extension like #embed "." __gnu__::__base64__("...") 
that the GCC patchset uses for the inner parts of the longer sequences.
I think the exact type of cast can affect parsing of some of the expressions, 
e.g.
```c
extern long long p[];
auto foo () {
return
#embed __FILE__ limit (1)
[p];
}
```
will behave one way with the cast is (unsigned char)12 and differently if it is 
static_cast(12) or ((unsigned char)12).
Most of the other bugs I'm seeing are also about consistency, with -save-temps 
it works IMHO correctly while without it misbehaves.  The behavior has to be 
the same.

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


[clang] [CMake][Fuchsia] Build libc++ on top libc for baremetal (PR #99009)

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

https://github.com/petrhosek created 
https://github.com/llvm/llvm-project/pull/99009

This is mostly a proof of concept requiring a number of workarounds, but 
demonstrates that it is feasible.

>From add4a1681a9cfcfb20443c5652e3166ec739c31b Mon Sep 17 00:00:00 2001
From: Petr Hosek 
Date: Tue, 16 Jul 2024 02:13:36 -0700
Subject: [PATCH] [CMake][Fuchsia] Build libc++ on top libc for baremetal

This is mostly a proof of concept requiring a number of workarounds,
but demonstrates that it is feasible.
---
 clang/cmake/caches/Fuchsia-stage2.cmake | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index 2d35c8d0a818a..04efd0683dbc4 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -325,7 +325,9 @@ foreach(target 
armv6m-unknown-eabi;armv7m-unknown-eabi;armv8m.main-unknown-eabi)
   set(RUNTIMES_${target}_CMAKE_BUILD_TYPE MinSizeRel CACHE STRING "")
   set(RUNTIMES_${target}_CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY CACHE 
STRING "")
   foreach(lang C;CXX;ASM)
-set(RUNTIMES_${target}_CMAKE_${lang}_FLAGS "--target=${target} -mthumb 
-Wno-atomic-alignment" CACHE STRING "")
+# TODO: The preprocessor defines workaround various issues in libc and 
libc++ integration.
+# These should be addressed and removed over time.
+set(RUNTIMES_${target}_CMAKE_${lang}_FLAGS "--target=${target} -mthumb 
-Wno-atomic-alignment -D'vfprintf(stream, format, vlist)=vprintf(format, 
vlist)' -D'fprintf(stream, format, ...)=printf(format)' -D'timeval=struct 
timeval{int tv_sec; int tv_usec;}' -D'gettimeofday(tv, tz)' -D_LIBCPP_PRINT=1" 
CACHE STRING "")
   endforeach()
   foreach(type SHARED;MODULE;EXE)
 set(RUNTIMES_${target}_CMAKE_${type}_LINKER_FLAGS "-fuse-ld=lld" CACHE 
STRING "")
@@ -335,7 +337,7 @@ foreach(target 
armv6m-unknown-eabi;armv7m-unknown-eabi;armv8m.main-unknown-eabi)
   set(RUNTIMES_${target}_LIBCXX_ABI_VERSION 2 CACHE STRING "")
   set(RUNTIMES_${target}_LIBCXX_CXX_ABI none CACHE STRING "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
-  set(RUNTIMES_${target}_LIBCXX_ENABLE_STATIC OFF CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXX_ENABLE_STATIC ON CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_FILESYSTEM OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_RANDOM_DEVICE OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_LOCALIZATION OFF CACHE BOOL "")
@@ -373,7 +375,9 @@ foreach(target riscv32-unknown-elf)
   set(RUNTIMES_${target}_CMAKE_BUILD_TYPE MinSizeRel CACHE STRING "")
   set(RUNTIMES_${target}_CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY CACHE 
STRING "")
   foreach(lang C;CXX;ASM)
-set(RUNTIMES_${target}_CMAKE_${lang}_FLAGS "--target=${target} 
-march=rv32imafc -mabi=ilp32f" CACHE STRING "")
+# TODO: The preprocessor defines workaround various issues in libc and 
libc++ integration.
+# These should be addressed and removed over time.
+set(RUNTIMES_${target}_CMAKE_${lang}_FLAGS "--target=${target} 
-march=rv32imafc -mabi=ilp32f -D'vfprintf(stream, format, 
vlist)=vprintf(format, vlist)' -D'fprintf(stream, format, ...)=printf(format)' 
-D'timeval=struct timeval{int tv_sec; int tv_usec;}' -D'gettimeofday(tv, tz)' 
-D_LIBCPP_PRINT=1" CACHE STRING "")
   endforeach()
   foreach(type SHARED;MODULE;EXE)
 set(RUNTIMES_${target}_CMAKE_${type}_LINKER_FLAGS "-fuse-ld=lld" CACHE 
STRING "")
@@ -383,7 +387,7 @@ foreach(target riscv32-unknown-elf)
   set(RUNTIMES_${target}_LIBCXX_ABI_VERSION 2 CACHE STRING "")
   set(RUNTIMES_${target}_LIBCXX_CXX_ABI none CACHE STRING "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
-  set(RUNTIMES_${target}_LIBCXX_ENABLE_STATIC OFF CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXX_ENABLE_STATIC ON CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_FILESYSTEM OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_RANDOM_DEVICE OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_LOCALIZATION OFF CACHE BOOL "")

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


[clang] [CMake][Fuchsia] Build libc++ on top libc for baremetal (PR #99009)

2024-07-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Petr Hosek (petrhosek)


Changes

This is mostly a proof of concept requiring a number of workarounds, but 
demonstrates that it is feasible.

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


1 Files Affected:

- (modified) clang/cmake/caches/Fuchsia-stage2.cmake (+8-4) 


``diff
diff --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index 2d35c8d0a818a..04efd0683dbc4 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -325,7 +325,9 @@ foreach(target 
armv6m-unknown-eabi;armv7m-unknown-eabi;armv8m.main-unknown-eabi)
   set(RUNTIMES_${target}_CMAKE_BUILD_TYPE MinSizeRel CACHE STRING "")
   set(RUNTIMES_${target}_CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY CACHE 
STRING "")
   foreach(lang C;CXX;ASM)
-set(RUNTIMES_${target}_CMAKE_${lang}_FLAGS "--target=${target} -mthumb 
-Wno-atomic-alignment" CACHE STRING "")
+# TODO: The preprocessor defines workaround various issues in libc and 
libc++ integration.
+# These should be addressed and removed over time.
+set(RUNTIMES_${target}_CMAKE_${lang}_FLAGS "--target=${target} -mthumb 
-Wno-atomic-alignment -D'vfprintf(stream, format, vlist)=vprintf(format, 
vlist)' -D'fprintf(stream, format, ...)=printf(format)' -D'timeval=struct 
timeval{int tv_sec; int tv_usec;}' -D'gettimeofday(tv, tz)' -D_LIBCPP_PRINT=1" 
CACHE STRING "")
   endforeach()
   foreach(type SHARED;MODULE;EXE)
 set(RUNTIMES_${target}_CMAKE_${type}_LINKER_FLAGS "-fuse-ld=lld" CACHE 
STRING "")
@@ -335,7 +337,7 @@ foreach(target 
armv6m-unknown-eabi;armv7m-unknown-eabi;armv8m.main-unknown-eabi)
   set(RUNTIMES_${target}_LIBCXX_ABI_VERSION 2 CACHE STRING "")
   set(RUNTIMES_${target}_LIBCXX_CXX_ABI none CACHE STRING "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
-  set(RUNTIMES_${target}_LIBCXX_ENABLE_STATIC OFF CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXX_ENABLE_STATIC ON CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_FILESYSTEM OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_RANDOM_DEVICE OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_LOCALIZATION OFF CACHE BOOL "")
@@ -373,7 +375,9 @@ foreach(target riscv32-unknown-elf)
   set(RUNTIMES_${target}_CMAKE_BUILD_TYPE MinSizeRel CACHE STRING "")
   set(RUNTIMES_${target}_CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY CACHE 
STRING "")
   foreach(lang C;CXX;ASM)
-set(RUNTIMES_${target}_CMAKE_${lang}_FLAGS "--target=${target} 
-march=rv32imafc -mabi=ilp32f" CACHE STRING "")
+# TODO: The preprocessor defines workaround various issues in libc and 
libc++ integration.
+# These should be addressed and removed over time.
+set(RUNTIMES_${target}_CMAKE_${lang}_FLAGS "--target=${target} 
-march=rv32imafc -mabi=ilp32f -D'vfprintf(stream, format, 
vlist)=vprintf(format, vlist)' -D'fprintf(stream, format, ...)=printf(format)' 
-D'timeval=struct timeval{int tv_sec; int tv_usec;}' -D'gettimeofday(tv, tz)' 
-D_LIBCPP_PRINT=1" CACHE STRING "")
   endforeach()
   foreach(type SHARED;MODULE;EXE)
 set(RUNTIMES_${target}_CMAKE_${type}_LINKER_FLAGS "-fuse-ld=lld" CACHE 
STRING "")
@@ -383,7 +387,7 @@ foreach(target riscv32-unknown-elf)
   set(RUNTIMES_${target}_LIBCXX_ABI_VERSION 2 CACHE STRING "")
   set(RUNTIMES_${target}_LIBCXX_CXX_ABI none CACHE STRING "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
-  set(RUNTIMES_${target}_LIBCXX_ENABLE_STATIC OFF CACHE BOOL "")
+  set(RUNTIMES_${target}_LIBCXX_ENABLE_STATIC ON CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_FILESYSTEM OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_RANDOM_DEVICE OFF CACHE BOOL "")
   set(RUNTIMES_${target}_LIBCXX_ENABLE_LOCALIZATION OFF CACHE BOOL "")

``




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


[clang] [clang][Interp] Implement dynamic memory allocation handling (PR #70306)

2024-07-16 Thread David Spickett via cfe-commits

DavidSpickett wrote:

@luporl please help reproduce the bot failure 
https://lab.llvm.org/buildbot/#/builders/39/builds/528.

You can also try it under qemu - 
https://linaro.atlassian.net/wiki/spaces/TCWGPUB/pages/29360783374/How+to+Reproduce+32+bit+Arm+Builds+Without+Hardware.

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


[clang] c30ce8b - [clang] Refactor: Introduce a new LifetimeKind for the assignment case, NFC (#99005)

2024-07-16 Thread via cfe-commits

Author: Haojian Wu
Date: 2024-07-16T11:23:39+02:00
New Revision: c30ce8b9d33d1050ead549705702c1472b7a7d3f

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

LOG: [clang] Refactor: Introduce a new LifetimeKind for the assignment case, 
NFC (#99005)

The current implementation for the assignment case uses a combination of
the `LK_Extended` lifetime kind and the validity of `AEntity`, which is
somewhat messy and doesn't align well with the intended mental model.

This patch introduces a dedicated lifetime kind to handle the assignment
case, simplifying the implementation and improving clarity.

Added: 


Modified: 
clang/lib/Sema/CheckExprLifetime.cpp

Removed: 




diff  --git a/clang/lib/Sema/CheckExprLifetime.cpp 
b/clang/lib/Sema/CheckExprLifetime.cpp
index 2f9ef28da2c3e..995e4cbadacfe 100644
--- a/clang/lib/Sema/CheckExprLifetime.cpp
+++ b/clang/lib/Sema/CheckExprLifetime.cpp
@@ -39,6 +39,11 @@ enum LifetimeKind {
   /// This is a mem-initializer: if it would extend a temporary (other than via
   /// a default member initializer), the program is ill-formed.
   LK_MemInitializer,
+
+  /// The lifetime of a temporary bound to this entity probably ends too soon,
+  /// because the entity is a pointer and we assign the address of a temporary
+  /// object to it.
+  LK_Assignment,
 };
 using LifetimeResult =
 llvm::PointerIntPair;
@@ -971,6 +976,8 @@ static void checkExprLifetimeImpl(Sema &SemaRef,
   const InitializedEntity *ExtendingEntity,
   LifetimeKind LK,
   const AssignedEntity *AEntity, Expr *Init) {
+  assert((AEntity && LK == LK_Assignment) ||
+ (InitEntity && LK != LK_Assignment));
   // If this entity doesn't have an interesting lifetime, don't bother looking
   // for temporaries within its initializer.
   if (LK == LK_FullExpression)
@@ -1008,19 +1015,7 @@ static void checkExprLifetimeImpl(Sema &SemaRef,
   return true;
   }
 }
-if (AEntity) {
-  if (!MTE)
-return false;
-  assert(shouldLifetimeExtendThroughPath(Path) ==
- PathLifetimeKind::NoExtend &&
- "No lifetime extension for assignments");
-  if (!pathContainsInit(Path))
-SemaRef.Diag(DiagLoc, diag::warn_dangling_pointer_assignment)
-<< AEntity->LHS << DiagRange;
-  return false;
-}
 
-assert(InitEntity && "only for initialization");
 switch (LK) {
 case LK_FullExpression:
   llvm_unreachable("already handled this");
@@ -1077,6 +1072,17 @@ static void checkExprLifetimeImpl(Sema &SemaRef,
   break;
 }
 
+case LK_Assignment: {
+  if (!MTE)
+return false;
+  assert(shouldLifetimeExtendThroughPath(Path) ==
+ PathLifetimeKind::NoExtend &&
+ "No lifetime extension for assignments");
+  if (!pathContainsInit(Path))
+SemaRef.Diag(DiagLoc, diag::warn_dangling_pointer_assignment)
+<< AEntity->LHS << DiagRange;
+  return false;
+}
 case LK_MemInitializer: {
   if (MTE) {
 // Under C++ DR1696, if a mem-initializer (or a default member
@@ -1283,10 +1289,11 @@ void checkExprLifetime(Sema &SemaRef, const 
InitializedEntity &Entity,
 
 void checkExprLifetime(Sema &SemaRef, const AssignedEntity &Entity,
Expr *Init) {
-  LifetimeKind LK = LK_FullExpression;
-  if (Entity.LHS->getType()->isPointerType()) // builtin pointer type
-LK = LK_Extended;
-  checkExprLifetimeImpl(SemaRef, nullptr, nullptr, LK, &Entity, Init);
+  if (!Entity.LHS->getType()->isPointerType()) // builtin pointer type
+return;
+  checkExprLifetimeImpl(SemaRef, /*InitEntity=*/nullptr,
+/*ExtendingEntity=*/nullptr, LK_Assignment, &Entity,
+Init);
 }
 
 } // namespace clang::sema



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


[clang] [clang] Refactor: Introduce a new LifetimeKind for the assignment case, NFC (PR #99005)

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

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


[clang] [clang] Refactor: Introduce a new LifetimeKind for the assignment case, NFC (PR #99005)

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

hokein wrote:

Thanks!

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


[clang] [compiler-rt] [llvm] [PAC][AArch64] Support init/fini array signing (PR #96478)

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

kovdan01 wrote:

Ping: would be glad to see feedback on the changes from those who are 
interested.

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


[clang] [llvm] [PAC][clang][Driver] Add signed GOT flag (PR #96160)

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

kovdan01 wrote:

Ping: would be glad to see feedback on the changes from those who are 
interested.

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


[clang] 2c13194 - [clang][ExtractAPI][NFC] Remove some nullptr dereference problems (#98914)

2024-07-16 Thread via cfe-commits

Author: Daniel Grumberg
Date: 2024-07-16T11:24:28+01:00
New Revision: 2c13194eab28474089841903acd5790b8b1a559a

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

LOG: [clang][ExtractAPI][NFC] Remove some nullptr dereference problems (#98914)

A places try to get a NamedDecl's name using getName when it isn't a
simple identifier, migrate these areas to getNameAsString.

rdar://125315602

Added: 


Modified: 
clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
clang/lib/ExtractAPI/DeclarationFragments.cpp

Removed: 




diff  --git a/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h 
b/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
index 76d7fd798bed3..1b27027621666 100644
--- a/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
+++ b/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
@@ -175,22 +175,25 @@ class ExtractAPIVisitorBase : public 
RecursiveASTVisitor {
   // skip classes not inherited as public
   if (BaseSpecifier.getAccessSpecifier() != AccessSpecifier::AS_public)
 continue;
-  SymbolReference BaseClass;
-  if (BaseSpecifier.getType().getTypePtr()->isTemplateTypeParmType()) {
-BaseClass.Name = API.copyString(BaseSpecifier.getType().getAsString());
-if (auto *TTPTD = BaseSpecifier.getType()
-  ->getAs()
-  ->getDecl()) {
-  SmallString<128> USR;
-  index::generateUSRForDecl(TTPTD, USR);
-  BaseClass.USR = API.copyString(USR);
-  BaseClass.Source = API.copyString(getOwningModuleName(*TTPTD));
-}
+  if (auto *BaseDecl = BaseSpecifier.getType()->getAsTagDecl()) {
+Bases.emplace_back(createSymbolReferenceForDecl(*BaseDecl));
   } else {
-BaseClass = createSymbolReferenceForDecl(
-*BaseSpecifier.getType().getTypePtr()->getAsCXXRecordDecl());
+SymbolReference BaseClass;
+BaseClass.Name = API.copyString(BaseSpecifier.getType().getAsString(
+Decl->getASTContext().getPrintingPolicy()));
+
+if (BaseSpecifier.getType().getTypePtr()->isTemplateTypeParmType()) {
+  if (auto *TTPTD = BaseSpecifier.getType()
+->getAs()
+->getDecl()) {
+SmallString<128> USR;
+index::generateUSRForDecl(TTPTD, USR);
+BaseClass.USR = API.copyString(USR);
+BaseClass.Source = API.copyString(getOwningModuleName(*TTPTD));
+  }
+}
+Bases.emplace_back(BaseClass);
   }
-  Bases.emplace_back(BaseClass);
 }
 return Bases;
   }
@@ -352,7 +355,7 @@ bool ExtractAPIVisitorBase::VisitFunctionDecl(
 return true;
 
   // Collect symbol information.
-  StringRef Name = Decl->getName();
+  auto Name = Decl->getNameAsString();
   SmallString<128> USR;
   index::generateUSRForDecl(Decl, USR);
   PresumedLoc Loc =
@@ -666,8 +669,8 @@ bool ExtractAPIVisitorBase::VisitCXXMethodDecl(
   if (FunctionTemplateDecl *TemplateDecl =
   Decl->getDescribedFunctionTemplate()) {
 API.createRecord(
-USR, Decl->getName(), createHierarchyInformationForDecl(*Decl), Loc,
-AvailabilityInfo::createFromDecl(Decl), Comment,
+USR, Decl->getNameAsString(), createHierarchyInformationForDecl(*Decl),
+Loc, AvailabilityInfo::createFromDecl(Decl), Comment,
 DeclarationFragmentsBuilder::getFragmentsForFunctionTemplate(
 TemplateDecl),
 SubHeading, DeclarationFragmentsBuilder::getFunctionSignature(Decl),
@@ -675,8 +678,8 @@ bool ExtractAPIVisitorBase::VisitCXXMethodDecl(
 Template(TemplateDecl), isInSystemHeader(Decl));
   } else if (Decl->getTemplateSpecializationInfo())
 API.createRecord(
-USR, Decl->getName(), createHierarchyInformationForDecl(*Decl), Loc,
-AvailabilityInfo::createFromDecl(Decl), Comment,
+USR, Decl->getNameAsString(), createHierarchyInformationForDecl(*Decl),
+Loc, AvailabilityInfo::createFromDecl(Decl), Comment,
 DeclarationFragmentsBuilder::
 getFragmentsForFunctionTemplateSpecialization(Decl),
 SubHeading, Signature, Access, isInSystemHeader(Decl));
@@ -688,14 +691,14 @@ bool ExtractAPIVisitorBase::VisitCXXMethodDecl(
 SubHeading, Signature, Access, isInSystemHeader(Decl));
   else if (Decl->isStatic())
 API.createRecord(
-USR, Decl->getName(), createHierarchyInformationForDecl(*Decl), Loc,
-AvailabilityInfo::createFromDecl(Decl), Comment,
+USR, Decl->getNameAsString(), createHierarchyInformationForDecl(*Decl),
+Loc, AvailabilityInfo::createFromDecl(Decl), Comment,
 DeclarationFragmentsBuilder::getFragmentsForCXXMethod(Decl), 
SubHeading,
 Signature, Access

[clang] [clang][ExtractAPI][NFC] Remove some nullptr dereference problems (PR #98914)

2024-07-16 Thread Daniel Grumberg via cfe-commits

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


[clang] Revert "[Clang] Instantiate local constexpr functions eagerly (#95660)" (PR #98991)

2024-07-16 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 updated 
https://github.com/llvm/llvm-project/pull/98991

>From 727d92f0651cec3110d321582a884f1c939d8a6d Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Tue, 16 Jul 2024 12:43:33 +0800
Subject: [PATCH 1/2] Revert "[Clang] Instantiate local constexpr functions
 eagerly (#95660)"

Unfortunately, this has caused a regression in DeduceReturnType(), which
causes a problem in that some of the local recursive lambdas are incorrectly
rejected.

This reverts commit 5548ea34341e9d0ae645719c34b466ca3b9eaa5a. Also,
this adds an offending case to the test.
---
 clang/docs/ReleaseNotes.rst   |  1 -
 clang/lib/Sema/SemaExpr.cpp   | 13 
 .../SemaTemplate/instantiate-local-class.cpp  | 33 +++
 3 files changed, 26 insertions(+), 21 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 838cb69f647ee..077063a828cbb 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -960,7 +960,6 @@ Bug Fixes to C++ Support
 - Fixed several bugs in capturing variables within unevaluated contexts. 
(#GH63845), (#GH67260), (#GH69307),
   (#GH88081), (#GH89496), (#GH90669) and (#GH91633).
 - Fixed handling of brace ellison when building deduction guides. (#GH64625), 
(#GH83368).
-- Clang now instantiates local constexpr functions eagerly for constant 
evaluators. (#GH35052), (#GH94849)
 - Fixed a failed assertion when attempting to convert an integer representing 
the difference
   between the addresses of two labels (a GNU extension) to a pointer within a 
constant expression. (#GH95366).
 - Fix immediate escalation bugs in the presence of dependent call arguments. 
(#GH94935)
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 852344d895ffd..9723de6f46fc7 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -17938,17 +17938,16 @@ void Sema::MarkFunctionReferenced(SourceLocation Loc, 
FunctionDecl *Func,
 
 if (FirstInstantiation || TSK != TSK_ImplicitInstantiation ||
 Func->isConstexpr()) {
-  if (Func->isConstexpr())
+  if (isa(Func->getDeclContext()) &&
+  cast(Func->getDeclContext())->isLocalClass() &&
+  CodeSynthesisContexts.size())
+PendingLocalImplicitInstantiations.push_back(
+std::make_pair(Func, PointOfInstantiation));
+  else if (Func->isConstexpr())
 // Do not defer instantiations of constexpr functions, to avoid the
 // expression evaluator needing to call back into Sema if it sees a
 // call to such a function.
 InstantiateFunctionDefinition(PointOfInstantiation, Func);
-  else if (isa(Func->getDeclContext()) &&
-   cast(Func->getDeclContext())
-   ->isLocalClass() &&
-   CodeSynthesisContexts.size())
-PendingLocalImplicitInstantiations.push_back(
-std::make_pair(Func, PointOfInstantiation));
   else {
 Func->setInstantiationIsPending(true);
 PendingInstantiations.push_back(
diff --git a/clang/test/SemaTemplate/instantiate-local-class.cpp 
b/clang/test/SemaTemplate/instantiate-local-class.cpp
index 7eee131e28d60..a313bdd9d2ea5 100644
--- a/clang/test/SemaTemplate/instantiate-local-class.cpp
+++ b/clang/test/SemaTemplate/instantiate-local-class.cpp
@@ -512,24 +512,31 @@ namespace LambdaInDefaultMemberInitializer {
 }
 
 #if __cplusplus >= 201703L
-namespace GH35052 {
 
-template  constexpr int func(F f) {
-  if constexpr (f(1UL)) {
-return 1;
+namespace local_recursive_lambda {
+
+template  struct recursive_lambda {
+  template  auto operator()(Args &&...args) const {
+return fn(*this, args...);
   }
-  return 0;
-}
+  F fn;
+};
 
-int main() {
-  auto predicate = [](auto v) /*implicit constexpr*/ -> bool {
-return v == 1;
-  };
+template  recursive_lambda(F) -> recursive_lambda;
+
+struct Tree {
+  Tree *left, *right;
+};
+
+int sumSize(Tree *tree) {
+  auto accumulate =
+  recursive_lambda{[&](auto &self_fn, Tree *element_node) -> int {
+return 1 + self_fn(tree->left) + self_fn(tree->right);
+  }};
 
-  static_assert(predicate(1));
-  return func(predicate);
+  return accumulate(tree);
 }
 
-} // namespace GH35052
+} // namespace local_recursive_lambda
 
 #endif

>From 44752766678a796b294c0cd8073a2e11c18988d8 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Tue, 16 Jul 2024 18:52:10 +0800
Subject: [PATCH 2/2] Add an issue reference

---
 .../SemaTemplate/instantiate-local-class.cpp| 17 ++---
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/clang/test/SemaTemplate/instantiate-local-class.cpp 
b/clang/test/SemaTemplate/instantiate-local-class.cpp
index a313bdd9d2ea5..298233739900f 100644
--- a/clang/test/SemaTemplate/instantiate-local-class.cpp
+++ b/clang/test/SemaTemplate/instantiate-local-class.cpp
@@ -513,6 +513

[clang] Revert "[Clang] Instantiate local constexpr functions eagerly (#95660)" (PR #98991)

2024-07-16 Thread Younan Zhang via cfe-commits

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


[clang] 862715e - Revert "[Clang] Instantiate local constexpr functions eagerly (#95660)" (#98991)

2024-07-16 Thread via cfe-commits

Author: Younan Zhang
Date: 2024-07-16T18:53:48+08:00
New Revision: 862715ea813d8ffa73050ada17567b45c41a1023

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

LOG: Revert "[Clang] Instantiate local constexpr functions eagerly (#95660)" 
(#98991)

Unfortunately, #95660 has caused a regression in DeduceReturnType(),
where some of the local recursive lambdas are getting incorrectly rejected.

This reverts commit 5548ea34341e9d0ae645719c34b466ca3b9eaa5a. Also, this
adds an offending case to the test.

Closes #98526

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaTemplate/instantiate-local-class.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 969856a8f978c..615e8879ac474 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1017,7 +1017,6 @@ Bug Fixes to C++ Support
   (#GH88081), (#GH89496), (#GH90669), (#GH91633) and (#GH97453).
 - Fixed a crash in constraint instantiation under nested lambdas with 
dependent parameters.
 - Fixed handling of brace ellison when building deduction guides. (#GH64625), 
(#GH83368).
-- Clang now instantiates local constexpr functions eagerly for constant 
evaluators. (#GH35052), (#GH94849)
 - Fixed a failed assertion when attempting to convert an integer representing 
the 
diff erence
   between the addresses of two labels (a GNU extension) to a pointer within a 
constant expression. (#GH95366).
 - Fix immediate escalation bugs in the presence of dependent call arguments. 
(#GH94935)

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index d6b85cbcaf56b..b0f953ea0a13a 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -17958,17 +17958,16 @@ void Sema::MarkFunctionReferenced(SourceLocation Loc, 
FunctionDecl *Func,
 
 if (FirstInstantiation || TSK != TSK_ImplicitInstantiation ||
 Func->isConstexpr()) {
-  if (Func->isConstexpr())
+  if (isa(Func->getDeclContext()) &&
+  cast(Func->getDeclContext())->isLocalClass() &&
+  CodeSynthesisContexts.size())
+PendingLocalImplicitInstantiations.push_back(
+std::make_pair(Func, PointOfInstantiation));
+  else if (Func->isConstexpr())
 // Do not defer instantiations of constexpr functions, to avoid the
 // expression evaluator needing to call back into Sema if it sees a
 // call to such a function.
 InstantiateFunctionDefinition(PointOfInstantiation, Func);
-  else if (isa(Func->getDeclContext()) &&
-   cast(Func->getDeclContext())
-   ->isLocalClass() &&
-   CodeSynthesisContexts.size())
-PendingLocalImplicitInstantiations.push_back(
-std::make_pair(Func, PointOfInstantiation));
   else {
 Func->setInstantiationIsPending(true);
 PendingInstantiations.push_back(

diff  --git a/clang/test/SemaTemplate/instantiate-local-class.cpp 
b/clang/test/SemaTemplate/instantiate-local-class.cpp
index 7eee131e28d60..298233739900f 100644
--- a/clang/test/SemaTemplate/instantiate-local-class.cpp
+++ b/clang/test/SemaTemplate/instantiate-local-class.cpp
@@ -512,24 +512,26 @@ namespace LambdaInDefaultMemberInitializer {
 }
 
 #if __cplusplus >= 201703L
-namespace GH35052 {
 
-template  constexpr int func(F f) {
-  if constexpr (f(1UL)) {
-return 1;
+// Reduced from https://github.com/llvm/llvm-project/issues/98526
+// This relies on the deferral instantiation of the local lambda, otherwise we 
would fail in DeduceReturnType().
+namespace local_recursive_lambda {
+
+template  struct recursive_lambda {
+  template  auto operator()(Args &&...args) const {
+return fn(*this, args...);
   }
-  return 0;
-}
+  F fn;
+};
 
-int main() {
-  auto predicate = [](auto v) /*implicit constexpr*/ -> bool {
-return v == 1;
-  };
+template  recursive_lambda(F) -> recursive_lambda;
 
-  static_assert(predicate(1));
-  return func(predicate);
+void foo() {
+  recursive_lambda{[&](auto &self_fn, int) -> int {
+return self_fn(0);
+  }}(0);
 }
 
-} // namespace GH35052
+} // namespace local_recursive_lambda
 
 #endif



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


[clang] [clang] Limit alignment for emitted vectors (PR #98629)

2024-07-16 Thread Mariya Podchishchaeva via cfe-commits


@@ -133,6 +133,7 @@ struct TransferrableTargetInfo {
   unsigned short SuitableAlign;
   unsigned short NewAlign;
   unsigned MaxVectorAlign;

Fznamznon wrote:

I pasted log in a weird way, sorry, all failures in this particular test I see 
are for Darwin.
```
// MEM256ALIGN16: define{{.*}} <4 x i64> @test_v32u128(ptr noundef byval(<4 x 
i64>) align 16 %{{.*}}, ptr noundef byval(<2 x i128>) align 16 %{{.*}})
  ^
// MEM512ALIGN32: define{{.*}} <8 x i64> @test_v64u128(ptr noundef byval(<8 x 
i64>) align 32 %{{.*}}, ptr noundef byval(<4 x i128>) align 32 %{{.*}})
  ^
```



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


[clang] [clang] Add deprecation warning for `-Ofast` driver option (PR #98736)

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


@@ -442,6 +442,9 @@ def warn_drv_deprecated_arg : Warning<
 def warn_drv_deprecated_arg_no_relaxed_template_template_args : Warning<
   "argument '-fno-relaxed-template-template-args' is deprecated">,
   InGroup;
+def warn_drv_deprecated_arg_ofast : Warning<
+  "argument '-Ofast' is deprecated; use '-O3', possibly with '-ffast-math'">,

AaronBallman wrote:

How about a slight rewording?

`use '-O3 -ffast math' for the same behavior, or '-O3' to enable conforming 
optimizations only`

(I mostly want to drop "just" and to make it more clear that `-Ofast` was 
non-conforming because of `-ffast-math`.)

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


[clang] [clang] Add deprecation warning for `-Ofast` driver option (PR #98736)

2024-07-16 Thread Thorsten Schütt via cfe-commits

tschuett wrote:

We are deprecating -Ofast and I would prefer to hint users first at conforming 
behaviour -O3 and then as last resort at -O3 with -ffast-math.

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


[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)

2024-07-16 Thread kadir çetinkaya via cfe-commits


@@ -0,0 +1,355 @@
+//===--- PrerequisiteModulesTests.cpp ---*- 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
+//
+//===--===//
+
+/// FIXME: Skip testing on windows temporarily due to the different escaping
+/// code mode.
+#ifndef _WIN32
+
+#include "ModulesBuilder.h"
+#include "ScanningProjectModules.h"
+
+#include "Annotations.h"
+#include "CodeComplete.h"
+#include "Compiler.h"
+#include "TestTU.h"
+#include "support/ThreadsafeFS.h"
+
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/raw_ostream.h"
+
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace clang::clangd {
+namespace {
+
+class MockDirectoryCompilationDatabase : public MockCompilationDatabase {
+public:
+  MockDirectoryCompilationDatabase(StringRef TestDir, const ThreadsafeFS &TFS)
+  : MockCompilationDatabase(TestDir),
+MockedCDBPtr(std::make_shared(*this)),
+TFS(TFS) {
+this->ExtraClangFlags.push_back("-std=c++20");
+this->ExtraClangFlags.push_back("-c");
+  }
+
+  void addFile(llvm::StringRef Path, llvm::StringRef Contents);
+
+  std::unique_ptr getProjectModules(PathRef) const override {
+return scanningProjectModules(MockedCDBPtr, TFS);
+  }
+
+private:
+  class MockClangCompilationDatabase : public tooling::CompilationDatabase {
+  public:
+MockClangCompilationDatabase(MockDirectoryCompilationDatabase &MCDB)
+: MCDB(MCDB) {}
+
+std::vector
+getCompileCommands(StringRef FilePath) const override {
+  std::optional Cmd =
+  MCDB.getCompileCommand(FilePath);
+  EXPECT_TRUE(Cmd);
+  return {*Cmd};
+}
+
+std::vector getAllFiles() const override { return Files; }
+
+void AddFile(StringRef File) { Files.push_back(File.str()); }
+
+  private:
+MockDirectoryCompilationDatabase &MCDB;
+std::vector Files;
+  };
+
+  std::shared_ptr MockedCDBPtr;
+  const ThreadsafeFS &TFS;
+};
+
+// Add files to the working testing directory and the compilation database.
+void MockDirectoryCompilationDatabase::addFile(llvm::StringRef Path,
+   llvm::StringRef Contents) {
+  ASSERT_FALSE(llvm::sys::path::is_absolute(Path));
+
+  SmallString<256> AbsPath(Directory);
+  llvm::sys::path::append(AbsPath, Path);
+
+  ASSERT_FALSE(
+  
llvm::sys::fs::create_directories(llvm::sys::path::parent_path(AbsPath)));
+
+  std::error_code EC;
+  llvm::raw_fd_ostream OS(AbsPath, EC);
+  ASSERT_FALSE(EC);
+  OS << Contents;
+
+  MockedCDBPtr->AddFile(Path);
+}
+
+class PrerequisiteModulesTests : public ::testing::Test {
+protected:
+  void SetUp() override {
+ASSERT_FALSE(llvm::sys::fs::createUniqueDirectory("modules-test", 
TestDir));
+  }
+
+  void TearDown() override {
+ASSERT_FALSE(llvm::sys::fs::remove_directories(TestDir));
+  }
+
+public:
+  // Get the absolute path for file specified by Path under testing working
+  // directory.
+  std::string getFullPath(llvm::StringRef Path) {
+SmallString<128> Result(TestDir);
+llvm::sys::path::append(Result, Path);
+EXPECT_TRUE(llvm::sys::fs::exists(Result.str()));
+return Result.str().str();
+  }
+
+  std::unique_ptr getGlobalCompilationDatabase() {
+// The compilation flags with modules are much complex so it looks better
+// to use DirectoryBasedGlobalCompilationDatabase than a mocked compilation
+// database.
+DirectoryBasedGlobalCompilationDatabase::Options Opts(TFS);
+return std::make_unique(Opts);
+  }
+
+  ParseInputs getInputs(llvm::StringRef FileName,
+const GlobalCompilationDatabase &CDB) {
+std::string FullPathName = getFullPath(FileName);
+
+ParseInputs Inputs;
+std::optional Cmd =
+CDB.getCompileCommand(FullPathName);
+EXPECT_TRUE(Cmd);
+Inputs.CompileCommand = std::move(*Cmd);
+Inputs.TFS = &TFS;
+
+if (auto Contents = TFS.view(TestDir)->getBufferForFile(FullPathName))

kadircet wrote:

yes. if we're trying to work on a non-existing file, there's probably some 
error in the test setup. i think it's more helpful to let the developer know in 
advance, rather than silently making progress with empty file contents.

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


[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)

2024-07-16 Thread kadir çetinkaya via cfe-commits


@@ -0,0 +1,355 @@
+//===--- PrerequisiteModulesTests.cpp ---*- 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
+//
+//===--===//
+
+/// FIXME: Skip testing on windows temporarily due to the different escaping
+/// code mode.
+#ifndef _WIN32
+
+#include "ModulesBuilder.h"
+#include "ScanningProjectModules.h"
+
+#include "Annotations.h"
+#include "CodeComplete.h"
+#include "Compiler.h"
+#include "TestTU.h"
+#include "support/ThreadsafeFS.h"
+
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/raw_ostream.h"
+
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace clang::clangd {
+namespace {
+
+class MockDirectoryCompilationDatabase : public MockCompilationDatabase {
+public:
+  MockDirectoryCompilationDatabase(StringRef TestDir, const ThreadsafeFS &TFS)
+  : MockCompilationDatabase(TestDir),
+MockedCDBPtr(std::make_shared(*this)),
+TFS(TFS) {
+this->ExtraClangFlags.push_back("-std=c++20");
+this->ExtraClangFlags.push_back("-c");
+  }
+
+  void addFile(llvm::StringRef Path, llvm::StringRef Contents);
+
+  std::unique_ptr getProjectModules(PathRef) const override {
+return scanningProjectModules(MockedCDBPtr, TFS);
+  }
+
+private:
+  class MockClangCompilationDatabase : public tooling::CompilationDatabase {
+  public:
+MockClangCompilationDatabase(MockDirectoryCompilationDatabase &MCDB)
+: MCDB(MCDB) {}
+
+std::vector
+getCompileCommands(StringRef FilePath) const override {
+  std::optional Cmd =
+  MCDB.getCompileCommand(FilePath);
+  EXPECT_TRUE(Cmd);
+  return {*Cmd};
+}
+
+std::vector getAllFiles() const override { return Files; }
+
+void AddFile(StringRef File) { Files.push_back(File.str()); }
+
+  private:
+MockDirectoryCompilationDatabase &MCDB;
+std::vector Files;
+  };
+
+  std::shared_ptr MockedCDBPtr;
+  const ThreadsafeFS &TFS;
+};
+
+// Add files to the working testing directory and the compilation database.
+void MockDirectoryCompilationDatabase::addFile(llvm::StringRef Path,
+   llvm::StringRef Contents) {
+  ASSERT_FALSE(llvm::sys::path::is_absolute(Path));
+
+  SmallString<256> AbsPath(Directory);
+  llvm::sys::path::append(AbsPath, Path);
+
+  ASSERT_FALSE(
+  
llvm::sys::fs::create_directories(llvm::sys::path::parent_path(AbsPath)));
+
+  std::error_code EC;
+  llvm::raw_fd_ostream OS(AbsPath, EC);
+  ASSERT_FALSE(EC);
+  OS << Contents;
+
+  MockedCDBPtr->AddFile(Path);
+}
+
+class PrerequisiteModulesTests : public ::testing::Test {
+protected:
+  void SetUp() override {
+ASSERT_FALSE(llvm::sys::fs::createUniqueDirectory("modules-test", 
TestDir));
+  }
+
+  void TearDown() override {
+ASSERT_FALSE(llvm::sys::fs::remove_directories(TestDir));
+  }
+
+public:
+  // Get the absolute path for file specified by Path under testing working
+  // directory.
+  std::string getFullPath(llvm::StringRef Path) {
+SmallString<128> Result(TestDir);
+llvm::sys::path::append(Result, Path);
+EXPECT_TRUE(llvm::sys::fs::exists(Result.str()));
+return Result.str().str();
+  }
+
+  std::unique_ptr getGlobalCompilationDatabase() {
+// The compilation flags with modules are much complex so it looks better
+// to use DirectoryBasedGlobalCompilationDatabase than a mocked compilation
+// database.
+DirectoryBasedGlobalCompilationDatabase::Options Opts(TFS);
+return std::make_unique(Opts);
+  }
+
+  ParseInputs getInputs(llvm::StringRef FileName,
+const GlobalCompilationDatabase &CDB) {
+std::string FullPathName = getFullPath(FileName);
+
+ParseInputs Inputs;
+std::optional Cmd =
+CDB.getCompileCommand(FullPathName);
+EXPECT_TRUE(Cmd);
+Inputs.CompileCommand = std::move(*Cmd);
+Inputs.TFS = &TFS;
+
+if (auto Contents = TFS.view(TestDir)->getBufferForFile(FullPathName))
+  Inputs.Contents = Contents->get()->getBuffer().str();
+
+return Inputs;
+  }
+
+  SmallString<256> TestDir;
+  // Noticed MockFS but its member variable 'OverlayRealFileSystemForModules'
+  // implies that it will better to use RealThreadsafeFS directly.
+  RealThreadsafeFS TFS;
+
+  DiagnosticConsumer DiagConsumer;
+};
+
+TEST_F(PrerequisiteModulesTests, PrerequisiteModulesTest) {
+  MockDirectoryCompilationDatabase CDB(TestDir, TFS);
+
+  CDB.addFile("foo.h", R"cpp(
+inline void foo() {}
+  )cpp");
+
+  CDB.addFile("M.cppm", R"cpp(
+module;
+#include "foo.h"
+export module M;
+  )cpp");
+
+  CDB.addFile("N.cppm", R"cpp(
+export module N;
+import :Part;
+import M;
+  )cpp");
+
+  CDB.addFile("N-part.cppm", R"cpp(
+// Different name with filename intentionally.

kadircet wrote:

[clang-tools-extra] [clang-tidy] Fix modernize-use-std-print/format for fmt (PR #99021)

2024-07-16 Thread Mike Crowe via cfe-commits

https://github.com/mikecrowe created 
https://github.com/llvm/llvm-project/pull/99021

When fixing #92896 in 0e62d5cf55479981da5e05e406bbca4afb3cdc4f (#94104) I 
failed to spot that I'd broken converting from fmt::printf, fmt::fprintf and 
fmt::sprintf in these checks since the format parameter of those functions is 
not a simple character pointer.

The first part of the previous fix to avoid the assert and instead produce an 
error message was sufficient. It was only the second part that required the 
format parameter of the called function to be a simple character pointer that 
was problematic. Let's remove that second part and add the now-expected error 
messages to the lit tests along with fixing the prototype for the fmt functions 
to more accurately reflect the ones used by the fmt library so they are 
actually useful.

Fixes #92896

>From af0225dd9679a4e2b6fe0070c9c55c12ea406e42 Mon Sep 17 00:00:00 2001
From: Mike Crowe 
Date: Mon, 15 Jul 2024 21:32:50 +0100
Subject: [PATCH] [clang-tidy] Fix modernize-use-std-print/format for fmt

When fixing #92896 in 0e62d5cf55479981da5e05e406bbca4afb3cdc4f (#94104)
I failed to spot that I'd broken converting from fmt::printf,
fmt::fprintf and fmt::sprintf in these checks since the format parameter
of those functions is not a simple character pointer.

The first part of the previous fix to avoid the assert and instead
produce an error message was sufficient. It was only the second part
that required the format parameter of the called function to be a simple
character pointer that was problematic. Let's remove that second part
and add the now-expected error messages to the lit tests along with
fixing the prototype for the fmt functions to more accurately reflect
the ones used by the fmt library so they are actually useful.

Fixes #92896
---
 .../modernize/UseStdFormatCheck.cpp   | 14 +-
 .../clang-tidy/modernize/UseStdPrintCheck.cpp |  4 ---
 .../modernize/use-std-format-custom.cpp   |  1 +
 .../checkers/modernize/use-std-format-fmt.cpp |  6 ++---
 .../modernize/use-std-print-custom.cpp| 26 +--
 5 files changed, 34 insertions(+), 17 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp
index d082faa786b37..6cef21f1318a2 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp
@@ -47,15 +47,13 @@ void UseStdFormatCheck::registerPPCallbacks(const 
SourceManager &SM,
 }
 
 void UseStdFormatCheck::registerMatchers(MatchFinder *Finder) {
-  auto CharPointerType =
-  hasType(pointerType(pointee(matchers::isSimpleChar(;
   Finder->addMatcher(
-  callExpr(
-  argumentCountAtLeast(1), hasArgument(0, stringLiteral(isOrdinary())),
-  callee(functionDecl(
- unless(cxxMethodDecl()), hasParameter(0, CharPointerType),
- matchers::matchesAnyListedName(StrFormatLikeFunctions))
- .bind("func_decl")))
+  callExpr(argumentCountAtLeast(1),
+   hasArgument(0, stringLiteral(isOrdinary())),
+   callee(functionDecl(unless(cxxMethodDecl()),
+   matchers::matchesAnyListedName(
+   StrFormatLikeFunctions))
+  .bind("func_decl")))
   .bind("strformat"),
   this);
 }
diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp
index 1ea170c3cd310..ff990feadc0c1 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp
@@ -95,15 +95,12 @@ unusedReturnValue(clang::ast_matchers::StatementMatcher 
MatchedCallExpr) {
 }
 
 void UseStdPrintCheck::registerMatchers(MatchFinder *Finder) {
-  auto CharPointerType =
-  hasType(pointerType(pointee(matchers::isSimpleChar(;
   if (!PrintfLikeFunctions.empty())
 Finder->addMatcher(
 unusedReturnValue(
 callExpr(argumentCountAtLeast(1),
  hasArgument(0, stringLiteral(isOrdinary())),
  callee(functionDecl(unless(cxxMethodDecl()),
- hasParameter(0, CharPointerType),
  matchers::matchesAnyListedName(
  PrintfLikeFunctions))
 .bind("func_decl")))
@@ -116,7 +113,6 @@ void UseStdPrintCheck::registerMatchers(MatchFinder 
*Finder) {
 callExpr(argumentCountAtLeast(2),
  hasArgument(1, stringLiteral(isOrdinary())),
  callee(functionDecl(unless(cxxMethodDecl()),
- hasParameter(1, CharPointerType),
  matchers::matchesAnyListedN

[clang-tools-extra] [clang-tidy] Fix modernize-use-std-print/format for fmt (PR #99021)

2024-07-16 Thread via cfe-commits

llvmbot wrote:




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

Author: Mike Crowe (mikecrowe)


Changes

When fixing #92896 in 0e62d5cf55479981da5e05e406bbca4afb3cdc4f (#94104) I failed to spot that I'd broken converting from fmt::printf, 
fmt::fprintf and fmt::sprintf in these checks since the format parameter of 
those functions is not a simple character pointer.

The first part of the previous fix to avoid the assert and instead produce an 
error message was sufficient. It was only the second part that required the 
format parameter of the called function to be a simple character pointer that 
was problematic. Let's remove that second part and add the now-expected error 
messages to the lit tests along with fixing the prototype for the fmt functions 
to more accurately reflect the ones used by the fmt library so they are 
actually useful.

Fixes #92896

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


5 Files Affected:

- (modified) clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp 
(+6-8) 
- (modified) clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp (-4) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-custom.cpp 
(+1) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-fmt.cpp 
(+3-3) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-custom.cpp 
(+24-2) 


``diff
diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp
index d082faa786b37..6cef21f1318a2 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp
@@ -47,15 +47,13 @@ void UseStdFormatCheck::registerPPCallbacks(const 
SourceManager &SM,
 }
 
 void UseStdFormatCheck::registerMatchers(MatchFinder *Finder) {
-  auto CharPointerType =
-  hasType(pointerType(pointee(matchers::isSimpleChar(;
   Finder->addMatcher(
-  callExpr(
-  argumentCountAtLeast(1), hasArgument(0, stringLiteral(isOrdinary())),
-  callee(functionDecl(
- unless(cxxMethodDecl()), hasParameter(0, CharPointerType),
- matchers::matchesAnyListedName(StrFormatLikeFunctions))
- .bind("func_decl")))
+  callExpr(argumentCountAtLeast(1),
+   hasArgument(0, stringLiteral(isOrdinary())),
+   callee(functionDecl(unless(cxxMethodDecl()),
+   matchers::matchesAnyListedName(
+   StrFormatLikeFunctions))
+  .bind("func_decl")))
   .bind("strformat"),
   this);
 }
diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp
index 1ea170c3cd310..ff990feadc0c1 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp
@@ -95,15 +95,12 @@ unusedReturnValue(clang::ast_matchers::StatementMatcher 
MatchedCallExpr) {
 }
 
 void UseStdPrintCheck::registerMatchers(MatchFinder *Finder) {
-  auto CharPointerType =
-  hasType(pointerType(pointee(matchers::isSimpleChar(;
   if (!PrintfLikeFunctions.empty())
 Finder->addMatcher(
 unusedReturnValue(
 callExpr(argumentCountAtLeast(1),
  hasArgument(0, stringLiteral(isOrdinary())),
  callee(functionDecl(unless(cxxMethodDecl()),
- hasParameter(0, CharPointerType),
  matchers::matchesAnyListedName(
  PrintfLikeFunctions))
 .bind("func_decl")))
@@ -116,7 +113,6 @@ void UseStdPrintCheck::registerMatchers(MatchFinder 
*Finder) {
 callExpr(argumentCountAtLeast(2),
  hasArgument(1, stringLiteral(isOrdinary())),
  callee(functionDecl(unless(cxxMethodDecl()),
- hasParameter(1, CharPointerType),
  matchers::matchesAnyListedName(
  FprintfLikeFunctions))
 .bind("func_decl")))
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-custom.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-custom.cpp
index c025113055cce..7da0bb02ad766 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-custom.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-custom.cpp
@@ -63,4 +63,5 @@ std::string unsupported_format_parameter_type()
   // No fixes here because the format parameter of the function called is not a
   // string.
   return bad_format_type_strprintf("");
+// CHECK-MESSA

[clang-tools-extra] [clang-tidy] Fix modernize-use-std-print/format for fmt (PR #99021)

2024-07-16 Thread Mike Crowe via cfe-commits

mikecrowe wrote:

The previous fix hadn't made it into a release yet, so I don't think that this 
newly-discovered problem requires mentioning in the release notes. I'm happy to 
create a separate issue for it if you'd like me to though.

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


[clang] [OpenMP][AMDGPU] Do not attach -fcuda-is-device (PR #99002)

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

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


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


[clang] [clang] Add deprecation warning for `-Ofast` driver option (PR #98736)

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

Endilll wrote:

> We are deprecating -Ofast and I would prefer to hint users first at 
> conforming behaviour -O3 and then as last resort at -O3 with -ffast-math.

@tschuett I'm sympathetic to this arguments, but I think it's no less important 
to tell users in no uncertain terms how to preserve their current behavior. If 
there's a wording that achieves both goals, I'd be happy to incorporate it into 
this PR.

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


[clang] [test] Precommit tests for PR96025, NFC (PR #98704)

2024-07-16 Thread via cfe-commits

vfdff wrote:

the case pass on window target with extra  `extern "C"` for the function, but 
it is strange the linux target test has not finish.

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


[clang] [clang] Add deprecation warning for `-Ofast` driver option (PR #98736)

2024-07-16 Thread Thorsten Schütt via cfe-commits

tschuett wrote:

> > We are deprecating -Ofast and I would prefer to hint users first at 
> > conforming behaviour -O3 and then as last resort at -O3 with -ffast-math.
> 
> @tschuett I'm sympathetic to this arguments, but I think it's no less 
> important to tell users in no uncertain terms how to preserve their current 
> behavior. If there's a wording that achieves both goals, I'd be happy to 
> incorporate it into this PR.

No worries. I have zero voting rights in Clang.

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


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

2024-07-16 Thread via cfe-commits


@@ -0,0 +1,43 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// The test may fail as time out on windows
+// REQUIRES: system-linux
+
+// RUN:  %clang -S -O3 -emit-llvm -o - -x c++ %s | FileCheck %s 
-check-prefixes=CHECK,NoNewStructPathTBAA
+// RUN:  %clang -S -O3 -Xclang -new-struct-path-tbaa -emit-llvm -o - -x c++ %s 
| FileCheck %s -check-prefixes=CHECK,NewStructPathTBAA
+

vfdff wrote:

As there is difference **function naming rules** between Linux and Windows, I 
try to add `extern "C"` for the function, then the case pass on windows now, 
see https://github.com/llvm/llvm-project/pull/98704. I'll rebase this PR after 
PR98704 is accepted.

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


[clang] [test] Check whether timeout exists in the Windows operating system (PR #98990)

2024-07-16 Thread via cfe-commits

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


[clang] [test] Check whether timeout exists in the Windows operating system (PR #98990)

2024-07-16 Thread via cfe-commits

vfdff wrote:

this can be closed now as we already know the reason of failure on windows 
because the **function naming rules**

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


[clang] [clang][driver] Support `--precompile` and `-fmodule-*` options in Clang-CL (PR #98761)

2024-07-16 Thread Sharadh Rajaraman via cfe-commits


@@ -242,7 +242,7 @@ bool types::isCXX(ID Id) {
   case TY_CXXHUHeader:
   case TY_PP_CXXHeaderUnit:
   case TY_ObjCXXHeader: case TY_PP_ObjCXXHeader:
-  case TY_CXXModule: case TY_PP_CXXModule:
+  case TY_CXXModule: case TY_PP_CXXModule: case TY_ModuleFile:

sharadhr wrote:

This is required to get rid of the `Wunused-argument: /std:c++20` warning.

I realised that the input file was `TY_ModuleFile` which led the Clang-CL 
driver to interpret it as a C file, and not a CXX file, and then eventually 
emitting this error. 

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


[clang] [clang][driver] Support `--precompile` and `-fmodule-*` options in Clang-CL (PR #98761)

2024-07-16 Thread Sharadh Rajaraman via cfe-commits

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


[clang] [APINotes] Remove unused API (PR #98943)

2024-07-16 Thread Egor Zhdan via cfe-commits

egorzhdan wrote:

Yeah, I can't see any usages of this in the past few years. It was probably 
used a long while ago.

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


[clang] 4348f32 - [APINotes] Remove unused API

2024-07-16 Thread via cfe-commits

Author: Egor Zhdan
Date: 2024-07-16T12:39:04+01:00
New Revision: 4348f32ec609540e642be1be263d6ad2b60a90fd

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

LOG: [APINotes] Remove unused API

This method is not actually used anywhere.

Added: 


Modified: 
clang/include/clang/APINotes/Types.h

Removed: 




diff  --git a/clang/include/clang/APINotes/Types.h 
b/clang/include/clang/APINotes/Types.h
index daf2f1897f46b..b389aa8d56f16 100644
--- a/clang/include/clang/APINotes/Types.h
+++ b/clang/include/clang/APINotes/Types.h
@@ -263,13 +263,6 @@ class ContextInfo : public CommonTypeInfo {
 SwiftObjCMembers = Value.value_or(false);
   }
 
-  /// Strip off any information within the class information structure that is
-  /// module-local, such as 'audited' flags.
-  void stripModuleLocalInfo() {
-HasDefaultNullability = false;
-DefaultNullability = 0;
-  }
-
   friend bool operator==(const ContextInfo &, const ContextInfo &);
 
   ContextInfo &operator|=(const ContextInfo &RHS) {



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


[clang] [APINotes] Remove unused API (PR #98943)

2024-07-16 Thread Egor Zhdan via cfe-commits

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


[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)

2024-07-16 Thread kadir çetinkaya via cfe-commits

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


[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)

2024-07-16 Thread kadir çetinkaya via cfe-commits


@@ -318,6 +309,10 @@ bool StandalonePrerequisiteModules::canReuse(
   Clang.getHeaderSearchOpts().ForceCheckCXX20ModulesInputFiles = true;
   Clang.getHeaderSearchOpts().ValidateASTInputFilesContent = true;
 
+  // Following the practice of clang's driver to suppres the checking for ODR

kadircet wrote:

can you instead point to 
https://clang.llvm.org/docs/StandardCPlusPlusModules.html#object-definition-consistency
 ?

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


[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)

2024-07-16 Thread kadir çetinkaya via cfe-commits


@@ -0,0 +1,411 @@
+//===--- PrerequisiteModulesTests.cpp ---*- 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
+//
+//===--===//
+
+/// FIXME: Skip testing on windows temporarily due to the different escaping
+/// code mode.
+#ifndef _WIN32
+
+#include "ModulesBuilder.h"
+#include "ScanningProjectModules.h"
+

kadircet wrote:

nit: drop spaces between includes

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


[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)

2024-07-16 Thread kadir çetinkaya via cfe-commits


@@ -0,0 +1,335 @@
+//===- ModulesBuilder.cpp *- 
C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ModulesBuilder.h"
+#include "Compiler.h"
+#include "support/Logger.h"
+#include "clang/Frontend/FrontendAction.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Serialization/ASTReader.h"
+
+namespace clang {
+namespace clangd {
+
+namespace {
+
+// Create a path to store module files. Generally it should be:
+//
+//   {TEMP_DIRS}/clangd/module_files/{hashed-file-name}-%%-%%-%%-%%-%%-%%/.
+//
+// {TEMP_DIRS} is the temporary directory for the system, e.g., "/var/tmp"
+// or "C:/TEMP".
+//
+// '%%' means random value to make the generated path unique.
+//
+// \param MainFile is used to get the root of the project from global
+// compilation database.
+//
+// TODO: Move these module fils out of the temporary directory if the module
+// files are persistent.
+llvm::SmallString<256> getUniqueModuleFilesPath(PathRef MainFile) {
+  llvm::SmallString<128> HashedPrefix = llvm::sys::path::filename(MainFile);
+  // There might be multiple files with the same name in a project. So 
appending
+  // the hash value of the full path to make sure they won't conflict.
+  HashedPrefix += std::to_string(llvm::hash_value(MainFile));
+
+  llvm::SmallString<256> ResultPattern;
+
+  llvm::sys::path::system_temp_directory(/*erasedOnReboot=*/true,
+ ResultPattern);
+
+  llvm::sys::path::append(ResultPattern, "clangd");
+  llvm::sys::path::append(ResultPattern, "module_files");
+
+  llvm::sys::path::append(ResultPattern, HashedPrefix);
+
+  ResultPattern.append("-%%-%%-%%-%%-%%-%%");
+
+  llvm::SmallString<256> Result;
+  llvm::sys::fs::createUniquePath(ResultPattern, Result,
+  /*MakeAbsolute=*/false);
+
+  llvm::sys::fs::create_directories(Result);
+  return Result;
+}
+
+// Get a unique module file path under \param ModuleFilesPrefix.
+std::string getModuleFilePath(llvm::StringRef ModuleName,
+  PathRef ModuleFilesPrefix) {
+  llvm::SmallString<256> ModuleFilePath(ModuleFilesPrefix);
+  auto [PrimaryModuleName, PartitionName] = ModuleName.split(':');
+  llvm::sys::path::append(ModuleFilePath, PrimaryModuleName);
+  if (!PartitionName.empty()) {
+ModuleFilePath.append("-");
+ModuleFilePath.append(PartitionName);
+  }
+
+  ModuleFilePath.append(".pcm");
+  return std::string(ModuleFilePath);
+}
+
+// FailedPrerequisiteModules - stands for the PrerequisiteModules which has
+// errors happened during the building process.
+class FailedPrerequisiteModules : public PrerequisiteModules {
+public:
+  ~FailedPrerequisiteModules() override = default;
+
+  // We shouldn't adjust the compilation commands based on
+  // FailedPrerequisiteModules.
+  void adjustHeaderSearchOptions(HeaderSearchOptions &Options) const override {
+  }
+
+  // FailedPrerequisiteModules can never be reused.
+  bool
+  canReuse(const CompilerInvocation &CI,
+   llvm::IntrusiveRefCntPtr) const override {
+return false;
+  }
+};
+
+// StandalonePrerequisiteModules - stands for PrerequisiteModules for which all
+// the required modules are built successfully. All the module files
+// are owned by the StandalonePrerequisiteModules class.
+//
+// Any of the built module files won't be shared with other instances of the
+// class. So that we can avoid worrying thread safety.
+//
+// We don't need to worry about duplicated module names here since the standard
+// guarantees the module names should be unique to a program.
+class StandalonePrerequisiteModules : public PrerequisiteModules {
+public:
+  StandalonePrerequisiteModules() = default;
+
+  StandalonePrerequisiteModules(const StandalonePrerequisiteModules &) = 
delete;
+  StandalonePrerequisiteModules
+  operator=(const StandalonePrerequisiteModules &) = delete;
+  StandalonePrerequisiteModules(StandalonePrerequisiteModules &&) = delete;
+  StandalonePrerequisiteModules
+  operator=(StandalonePrerequisiteModules &&) = delete;
+
+  ~StandalonePrerequisiteModules() override = default;
+
+  void adjustHeaderSearchOptions(HeaderSearchOptions &Options) const override {
+// Appending all built module files.
+for (auto &RequiredModule : RequiredModules)
+  Options.PrebuiltModuleFiles.insert_or_assign(
+  RequiredModule.ModuleName, RequiredModule.ModuleFilePath);
+  }
+
+  bool canReuse(const CompilerInvocation &CI,
+llvm::IntrusiveRefCntPtr) const 
override;
+
+  bool isModuleUnitBuilt(llvm::StringRef ModuleName) const {
+return BuiltModuleNames.contains(ModuleName);
+  }
+
+  void addModuleFile(llvm::StringRef ModuleName,
+

[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)

2024-07-16 Thread kadir çetinkaya via cfe-commits


@@ -0,0 +1,335 @@
+//===- ModulesBuilder.cpp *- 
C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ModulesBuilder.h"
+#include "Compiler.h"
+#include "support/Logger.h"
+#include "clang/Frontend/FrontendAction.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Serialization/ASTReader.h"
+
+namespace clang {
+namespace clangd {
+
+namespace {
+
+// Create a path to store module files. Generally it should be:
+//
+//   {TEMP_DIRS}/clangd/module_files/{hashed-file-name}-%%-%%-%%-%%-%%-%%/.
+//
+// {TEMP_DIRS} is the temporary directory for the system, e.g., "/var/tmp"
+// or "C:/TEMP".
+//
+// '%%' means random value to make the generated path unique.
+//
+// \param MainFile is used to get the root of the project from global
+// compilation database.
+//
+// TODO: Move these module fils out of the temporary directory if the module
+// files are persistent.
+llvm::SmallString<256> getUniqueModuleFilesPath(PathRef MainFile) {
+  llvm::SmallString<128> HashedPrefix = llvm::sys::path::filename(MainFile);
+  // There might be multiple files with the same name in a project. So 
appending
+  // the hash value of the full path to make sure they won't conflict.
+  HashedPrefix += std::to_string(llvm::hash_value(MainFile));
+
+  llvm::SmallString<256> ResultPattern;
+
+  llvm::sys::path::system_temp_directory(/*erasedOnReboot=*/true,
+ ResultPattern);
+
+  llvm::sys::path::append(ResultPattern, "clangd");
+  llvm::sys::path::append(ResultPattern, "module_files");
+
+  llvm::sys::path::append(ResultPattern, HashedPrefix);
+
+  ResultPattern.append("-%%-%%-%%-%%-%%-%%");
+
+  llvm::SmallString<256> Result;
+  llvm::sys::fs::createUniquePath(ResultPattern, Result,
+  /*MakeAbsolute=*/false);
+
+  llvm::sys::fs::create_directories(Result);
+  return Result;
+}
+
+// Get a unique module file path under \param ModuleFilesPrefix.
+std::string getModuleFilePath(llvm::StringRef ModuleName,
+  PathRef ModuleFilesPrefix) {
+  llvm::SmallString<256> ModuleFilePath(ModuleFilesPrefix);
+  auto [PrimaryModuleName, PartitionName] = ModuleName.split(':');
+  llvm::sys::path::append(ModuleFilePath, PrimaryModuleName);
+  if (!PartitionName.empty()) {
+ModuleFilePath.append("-");
+ModuleFilePath.append(PartitionName);
+  }
+
+  ModuleFilePath.append(".pcm");
+  return std::string(ModuleFilePath);
+}
+
+// FailedPrerequisiteModules - stands for the PrerequisiteModules which has
+// errors happened during the building process.
+class FailedPrerequisiteModules : public PrerequisiteModules {
+public:
+  ~FailedPrerequisiteModules() override = default;
+
+  // We shouldn't adjust the compilation commands based on
+  // FailedPrerequisiteModules.
+  void adjustHeaderSearchOptions(HeaderSearchOptions &Options) const override {
+  }
+
+  // FailedPrerequisiteModules can never be reused.
+  bool
+  canReuse(const CompilerInvocation &CI,
+   llvm::IntrusiveRefCntPtr) const override {
+return false;
+  }
+};
+
+// StandalonePrerequisiteModules - stands for PrerequisiteModules for which all
+// the required modules are built successfully. All the module files
+// are owned by the StandalonePrerequisiteModules class.
+//
+// Any of the built module files won't be shared with other instances of the
+// class. So that we can avoid worrying thread safety.
+//
+// We don't need to worry about duplicated module names here since the standard
+// guarantees the module names should be unique to a program.
+class StandalonePrerequisiteModules : public PrerequisiteModules {
+public:
+  StandalonePrerequisiteModules() = default;
+
+  StandalonePrerequisiteModules(const StandalonePrerequisiteModules &) = 
delete;
+  StandalonePrerequisiteModules
+  operator=(const StandalonePrerequisiteModules &) = delete;
+  StandalonePrerequisiteModules(StandalonePrerequisiteModules &&) = delete;
+  StandalonePrerequisiteModules
+  operator=(StandalonePrerequisiteModules &&) = delete;
+
+  ~StandalonePrerequisiteModules() override = default;
+
+  void adjustHeaderSearchOptions(HeaderSearchOptions &Options) const override {
+// Appending all built module files.
+for (auto &RequiredModule : RequiredModules)
+  Options.PrebuiltModuleFiles.insert_or_assign(
+  RequiredModule.ModuleName, RequiredModule.ModuleFilePath);
+  }
+
+  bool canReuse(const CompilerInvocation &CI,
+llvm::IntrusiveRefCntPtr) const 
override;
+
+  bool isModuleUnitBuilt(llvm::StringRef ModuleName) const {
+return BuiltModuleNames.contains(ModuleName);
+  }
+
+  void addModuleFile(llvm::StringRef ModuleName,
+

[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)

2024-07-16 Thread kadir çetinkaya via cfe-commits


@@ -0,0 +1,335 @@
+//===- ModulesBuilder.cpp *- 
C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ModulesBuilder.h"
+#include "Compiler.h"
+#include "support/Logger.h"
+#include "clang/Frontend/FrontendAction.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Serialization/ASTReader.h"
+
+namespace clang {
+namespace clangd {
+
+namespace {
+
+// Create a path to store module files. Generally it should be:
+//
+//   {TEMP_DIRS}/clangd/module_files/{hashed-file-name}-%%-%%-%%-%%-%%-%%/.
+//
+// {TEMP_DIRS} is the temporary directory for the system, e.g., "/var/tmp"
+// or "C:/TEMP".
+//
+// '%%' means random value to make the generated path unique.
+//
+// \param MainFile is used to get the root of the project from global
+// compilation database.
+//
+// TODO: Move these module fils out of the temporary directory if the module
+// files are persistent.
+llvm::SmallString<256> getUniqueModuleFilesPath(PathRef MainFile) {
+  llvm::SmallString<128> HashedPrefix = llvm::sys::path::filename(MainFile);
+  // There might be multiple files with the same name in a project. So 
appending
+  // the hash value of the full path to make sure they won't conflict.
+  HashedPrefix += std::to_string(llvm::hash_value(MainFile));
+
+  llvm::SmallString<256> ResultPattern;
+
+  llvm::sys::path::system_temp_directory(/*erasedOnReboot=*/true,
+ ResultPattern);
+
+  llvm::sys::path::append(ResultPattern, "clangd");
+  llvm::sys::path::append(ResultPattern, "module_files");
+
+  llvm::sys::path::append(ResultPattern, HashedPrefix);
+
+  ResultPattern.append("-%%-%%-%%-%%-%%-%%");
+
+  llvm::SmallString<256> Result;
+  llvm::sys::fs::createUniquePath(ResultPattern, Result,
+  /*MakeAbsolute=*/false);
+
+  llvm::sys::fs::create_directories(Result);
+  return Result;
+}
+
+// Get a unique module file path under \param ModuleFilesPrefix.
+std::string getModuleFilePath(llvm::StringRef ModuleName,
+  PathRef ModuleFilesPrefix) {
+  llvm::SmallString<256> ModuleFilePath(ModuleFilesPrefix);
+  auto [PrimaryModuleName, PartitionName] = ModuleName.split(':');
+  llvm::sys::path::append(ModuleFilePath, PrimaryModuleName);
+  if (!PartitionName.empty()) {
+ModuleFilePath.append("-");
+ModuleFilePath.append(PartitionName);
+  }
+
+  ModuleFilePath.append(".pcm");
+  return std::string(ModuleFilePath);
+}
+
+// FailedPrerequisiteModules - stands for the PrerequisiteModules which has
+// errors happened during the building process.
+class FailedPrerequisiteModules : public PrerequisiteModules {
+public:
+  ~FailedPrerequisiteModules() override = default;
+
+  // We shouldn't adjust the compilation commands based on
+  // FailedPrerequisiteModules.
+  void adjustHeaderSearchOptions(HeaderSearchOptions &Options) const override {
+  }
+
+  // FailedPrerequisiteModules can never be reused.
+  bool
+  canReuse(const CompilerInvocation &CI,
+   llvm::IntrusiveRefCntPtr) const override {
+return false;
+  }
+};
+
+// StandalonePrerequisiteModules - stands for PrerequisiteModules for which all
+// the required modules are built successfully. All the module files
+// are owned by the StandalonePrerequisiteModules class.
+//
+// Any of the built module files won't be shared with other instances of the
+// class. So that we can avoid worrying thread safety.
+//
+// We don't need to worry about duplicated module names here since the standard
+// guarantees the module names should be unique to a program.
+class StandalonePrerequisiteModules : public PrerequisiteModules {
+public:
+  StandalonePrerequisiteModules() = default;
+
+  StandalonePrerequisiteModules(const StandalonePrerequisiteModules &) = 
delete;
+  StandalonePrerequisiteModules
+  operator=(const StandalonePrerequisiteModules &) = delete;
+  StandalonePrerequisiteModules(StandalonePrerequisiteModules &&) = delete;
+  StandalonePrerequisiteModules
+  operator=(StandalonePrerequisiteModules &&) = delete;
+
+  ~StandalonePrerequisiteModules() override = default;
+
+  void adjustHeaderSearchOptions(HeaderSearchOptions &Options) const override {
+// Appending all built module files.
+for (auto &RequiredModule : RequiredModules)
+  Options.PrebuiltModuleFiles.insert_or_assign(
+  RequiredModule.ModuleName, RequiredModule.ModuleFilePath);
+  }
+
+  bool canReuse(const CompilerInvocation &CI,
+llvm::IntrusiveRefCntPtr) const 
override;
+
+  bool isModuleUnitBuilt(llvm::StringRef ModuleName) const {
+return BuiltModuleNames.contains(ModuleName);
+  }
+
+  void addModuleFile(llvm::StringRef ModuleName,
+

[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)

2024-07-16 Thread kadir çetinkaya via cfe-commits


@@ -0,0 +1,335 @@
+//===- ModulesBuilder.cpp *- 
C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ModulesBuilder.h"
+#include "Compiler.h"
+#include "support/Logger.h"
+#include "clang/Frontend/FrontendAction.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Serialization/ASTReader.h"
+
+namespace clang {
+namespace clangd {
+
+namespace {
+
+// Create a path to store module files. Generally it should be:
+//
+//   {TEMP_DIRS}/clangd/module_files/{hashed-file-name}-%%-%%-%%-%%-%%-%%/.
+//
+// {TEMP_DIRS} is the temporary directory for the system, e.g., "/var/tmp"
+// or "C:/TEMP".
+//
+// '%%' means random value to make the generated path unique.
+//
+// \param MainFile is used to get the root of the project from global
+// compilation database.
+//
+// TODO: Move these module fils out of the temporary directory if the module
+// files are persistent.
+llvm::SmallString<256> getUniqueModuleFilesPath(PathRef MainFile) {
+  llvm::SmallString<128> HashedPrefix = llvm::sys::path::filename(MainFile);
+  // There might be multiple files with the same name in a project. So 
appending
+  // the hash value of the full path to make sure they won't conflict.
+  HashedPrefix += std::to_string(llvm::hash_value(MainFile));
+
+  llvm::SmallString<256> ResultPattern;
+
+  llvm::sys::path::system_temp_directory(/*erasedOnReboot=*/true,
+ ResultPattern);
+
+  llvm::sys::path::append(ResultPattern, "clangd");
+  llvm::sys::path::append(ResultPattern, "module_files");
+
+  llvm::sys::path::append(ResultPattern, HashedPrefix);
+
+  ResultPattern.append("-%%-%%-%%-%%-%%-%%");
+
+  llvm::SmallString<256> Result;
+  llvm::sys::fs::createUniquePath(ResultPattern, Result,
+  /*MakeAbsolute=*/false);
+
+  llvm::sys::fs::create_directories(Result);
+  return Result;
+}
+
+// Get a unique module file path under \param ModuleFilesPrefix.
+std::string getModuleFilePath(llvm::StringRef ModuleName,
+  PathRef ModuleFilesPrefix) {
+  llvm::SmallString<256> ModuleFilePath(ModuleFilesPrefix);
+  auto [PrimaryModuleName, PartitionName] = ModuleName.split(':');
+  llvm::sys::path::append(ModuleFilePath, PrimaryModuleName);
+  if (!PartitionName.empty()) {
+ModuleFilePath.append("-");
+ModuleFilePath.append(PartitionName);
+  }
+
+  ModuleFilePath.append(".pcm");
+  return std::string(ModuleFilePath);
+}
+
+// FailedPrerequisiteModules - stands for the PrerequisiteModules which has
+// errors happened during the building process.
+class FailedPrerequisiteModules : public PrerequisiteModules {
+public:
+  ~FailedPrerequisiteModules() override = default;
+
+  // We shouldn't adjust the compilation commands based on
+  // FailedPrerequisiteModules.
+  void adjustHeaderSearchOptions(HeaderSearchOptions &Options) const override {
+  }
+
+  // FailedPrerequisiteModules can never be reused.
+  bool
+  canReuse(const CompilerInvocation &CI,
+   llvm::IntrusiveRefCntPtr) const override {
+return false;
+  }
+};
+
+// StandalonePrerequisiteModules - stands for PrerequisiteModules for which all
+// the required modules are built successfully. All the module files
+// are owned by the StandalonePrerequisiteModules class.
+//
+// Any of the built module files won't be shared with other instances of the
+// class. So that we can avoid worrying thread safety.
+//
+// We don't need to worry about duplicated module names here since the standard
+// guarantees the module names should be unique to a program.
+class StandalonePrerequisiteModules : public PrerequisiteModules {
+public:
+  StandalonePrerequisiteModules() = default;
+
+  StandalonePrerequisiteModules(const StandalonePrerequisiteModules &) = 
delete;
+  StandalonePrerequisiteModules
+  operator=(const StandalonePrerequisiteModules &) = delete;
+  StandalonePrerequisiteModules(StandalonePrerequisiteModules &&) = delete;
+  StandalonePrerequisiteModules
+  operator=(StandalonePrerequisiteModules &&) = delete;
+
+  ~StandalonePrerequisiteModules() override = default;
+
+  void adjustHeaderSearchOptions(HeaderSearchOptions &Options) const override {
+// Appending all built module files.
+for (auto &RequiredModule : RequiredModules)
+  Options.PrebuiltModuleFiles.insert_or_assign(
+  RequiredModule.ModuleName, RequiredModule.ModuleFilePath);
+  }
+
+  bool canReuse(const CompilerInvocation &CI,
+llvm::IntrusiveRefCntPtr) const 
override;
+
+  bool isModuleUnitBuilt(llvm::StringRef ModuleName) const {
+return BuiltModuleNames.contains(ModuleName);
+  }
+
+  void addModuleFile(llvm::StringRef ModuleName,
+

[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)

2024-07-16 Thread kadir çetinkaya via cfe-commits

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

thanks a lot, LGTM!

i think the only big item remaining is injecting resource-dir correctly when 
running clang-scan-deps.

the most important follow up (for functionality, rather than optimizations and 
usability) is indexing the PCMs as we build them (similar to preamble-indexing 
we run today). For any future travelers, please do start a discussion in 
advance for that one.

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


[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)

2024-07-16 Thread kadir çetinkaya via cfe-commits


@@ -0,0 +1,199 @@
+//===-- ProjectModules.h -*- 
C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ProjectModules.h"
+
+#include "support/Logger.h"
+
+#include "clang/Tooling/DependencyScanning/DependencyScanningService.h"
+#include "clang/Tooling/DependencyScanning/DependencyScanningTool.h"
+
+namespace clang::clangd {
+namespace {
+/// A scanner to query the dependency information for C++20 Modules.
+///
+/// The scanner can scan a single file with `scan(PathRef)` member function
+/// or scan the whole project with `globalScan(vector)` member
+/// function. See the comments of `globalScan` to see the details.
+///
+/// The ModuleDependencyScanner can get the directly required module names for 
a
+/// specific source file. Also the ModuleDependencyScanner can get the source
+/// file declaring the primary module interface for a specific module name.
+///
+/// IMPORTANT NOTE: we assume that every module unit is only declared once in a
+/// source file in the project. But the assumption is not strictly true even
+/// besides the invalid projects. The language specification requires that 
every
+/// module unit should be unique in a valid program. But a project can contain
+/// multiple programs. Then it is valid that we can have multiple source files
+/// declaring the same module in a project as long as these source files don't
+/// interfere with each other.
+class ModuleDependencyScanner {
+public:
+  ModuleDependencyScanner(
+  std::shared_ptr CDB,
+  const ThreadsafeFS &TFS)
+  : CDB(CDB), TFS(TFS),
+Service(tooling::dependencies::ScanningMode::CanonicalPreprocessing,
+tooling::dependencies::ScanningOutputFormat::P1689) {}
+
+  /// The scanned modules dependency information for a specific source file.
+  struct ModuleDependencyInfo {
+/// The name of the module if the file is a module unit.
+std::optional ModuleName;
+/// A list of names for the modules that the file directly depends.
+std::vector RequiredModules;
+  };
+
+  /// Scanning the single file specified by \param FilePath.
+  std::optional scan(PathRef FilePath);
+
+  /// Scanning every source file in the current project to get the
+  ///  to  map.
+  /// TODO: We should find an efficient method to get the 
+  /// to  map. We can make it either by providing
+  /// a global module dependency scanner to monitor every file. Or we
+  /// can simply require the build systems (or even the end users)
+  /// to provide the map.
+  void globalScan();
+
+  /// Get the source file from the module name. Note that the language
+  /// guarantees all the module names are unique in a valid program.
+  /// This function should only be called after globalScan.
+  ///
+  /// TODO: We should handle the case that there are multiple source files
+  /// declaring the same module.
+  PathRef getSourceForModuleName(llvm::StringRef ModuleName) const;
+
+  /// Return the direct required modules. Indirect required modules are not
+  /// included.
+  std::vector getRequiredModules(PathRef File);
+
+private:
+  std::shared_ptr CDB;
+  const ThreadsafeFS &TFS;
+
+  // Whether the scanner has scanned the project globally.
+  bool GlobalScanned = false;
+
+  clang::tooling::dependencies::DependencyScanningService Service;
+
+  // TODO: Add a scanning cache.
+
+  // Map module name to source file path.
+  llvm::StringMap ModuleNameToSource;
+};
+
+std::optional
+ModuleDependencyScanner::scan(PathRef FilePath) {
+  auto Candidates = CDB->getCompileCommands(FilePath);
+  if (Candidates.empty())
+return std::nullopt;
+
+  // Choose the first candidates as the compile commands as the file.
+  // Following the same logic with
+  // DirectoryBasedGlobalCompilationDatabase::getCompileCommand.
+  tooling::CompileCommand Cmd = std::move(Candidates.front());

kadircet wrote:

can you rather use `CompilerInvocation::GetResourcesPath` and don't add it as 
an include path but rather append 
`"-resource-dir="+CompilerInvocation::GetResourcesPath(..)` to commandline?

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


[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)

2024-07-16 Thread kadir çetinkaya via cfe-commits


@@ -0,0 +1,335 @@
+//===- ModulesBuilder.cpp *- 
C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ModulesBuilder.h"
+#include "Compiler.h"
+#include "support/Logger.h"
+#include "clang/Frontend/FrontendAction.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Serialization/ASTReader.h"
+
+namespace clang {
+namespace clangd {
+
+namespace {
+
+// Create a path to store module files. Generally it should be:
+//
+//   {TEMP_DIRS}/clangd/module_files/{hashed-file-name}-%%-%%-%%-%%-%%-%%/.
+//
+// {TEMP_DIRS} is the temporary directory for the system, e.g., "/var/tmp"
+// or "C:/TEMP".
+//
+// '%%' means random value to make the generated path unique.
+//
+// \param MainFile is used to get the root of the project from global
+// compilation database.
+//
+// TODO: Move these module fils out of the temporary directory if the module
+// files are persistent.
+llvm::SmallString<256> getUniqueModuleFilesPath(PathRef MainFile) {
+  llvm::SmallString<128> HashedPrefix = llvm::sys::path::filename(MainFile);
+  // There might be multiple files with the same name in a project. So 
appending
+  // the hash value of the full path to make sure they won't conflict.
+  HashedPrefix += std::to_string(llvm::hash_value(MainFile));
+
+  llvm::SmallString<256> ResultPattern;
+
+  llvm::sys::path::system_temp_directory(/*erasedOnReboot=*/true,
+ ResultPattern);
+
+  llvm::sys::path::append(ResultPattern, "clangd");
+  llvm::sys::path::append(ResultPattern, "module_files");
+
+  llvm::sys::path::append(ResultPattern, HashedPrefix);
+
+  ResultPattern.append("-%%-%%-%%-%%-%%-%%");
+
+  llvm::SmallString<256> Result;
+  llvm::sys::fs::createUniquePath(ResultPattern, Result,
+  /*MakeAbsolute=*/false);
+
+  llvm::sys::fs::create_directories(Result);
+  return Result;
+}
+
+// Get a unique module file path under \param ModuleFilesPrefix.
+std::string getModuleFilePath(llvm::StringRef ModuleName,
+  PathRef ModuleFilesPrefix) {
+  llvm::SmallString<256> ModuleFilePath(ModuleFilesPrefix);
+  auto [PrimaryModuleName, PartitionName] = ModuleName.split(':');
+  llvm::sys::path::append(ModuleFilePath, PrimaryModuleName);
+  if (!PartitionName.empty()) {
+ModuleFilePath.append("-");
+ModuleFilePath.append(PartitionName);
+  }
+
+  ModuleFilePath.append(".pcm");
+  return std::string(ModuleFilePath);
+}
+
+// FailedPrerequisiteModules - stands for the PrerequisiteModules which has
+// errors happened during the building process.
+class FailedPrerequisiteModules : public PrerequisiteModules {
+public:
+  ~FailedPrerequisiteModules() override = default;
+
+  // We shouldn't adjust the compilation commands based on
+  // FailedPrerequisiteModules.
+  void adjustHeaderSearchOptions(HeaderSearchOptions &Options) const override {
+  }
+
+  // FailedPrerequisiteModules can never be reused.
+  bool
+  canReuse(const CompilerInvocation &CI,
+   llvm::IntrusiveRefCntPtr) const override {
+return false;
+  }
+};
+
+// StandalonePrerequisiteModules - stands for PrerequisiteModules for which all
+// the required modules are built successfully. All the module files
+// are owned by the StandalonePrerequisiteModules class.
+//
+// Any of the built module files won't be shared with other instances of the
+// class. So that we can avoid worrying thread safety.
+//
+// We don't need to worry about duplicated module names here since the standard
+// guarantees the module names should be unique to a program.
+class StandalonePrerequisiteModules : public PrerequisiteModules {
+public:
+  StandalonePrerequisiteModules() = default;
+
+  StandalonePrerequisiteModules(const StandalonePrerequisiteModules &) = 
delete;
+  StandalonePrerequisiteModules
+  operator=(const StandalonePrerequisiteModules &) = delete;
+  StandalonePrerequisiteModules(StandalonePrerequisiteModules &&) = delete;
+  StandalonePrerequisiteModules
+  operator=(StandalonePrerequisiteModules &&) = delete;
+
+  ~StandalonePrerequisiteModules() override = default;
+
+  void adjustHeaderSearchOptions(HeaderSearchOptions &Options) const override {
+// Appending all built module files.
+for (auto &RequiredModule : RequiredModules)
+  Options.PrebuiltModuleFiles.insert_or_assign(
+  RequiredModule.ModuleName, RequiredModule.ModuleFilePath);
+  }
+
+  bool canReuse(const CompilerInvocation &CI,
+llvm::IntrusiveRefCntPtr) const 
override;
+
+  bool isModuleUnitBuilt(llvm::StringRef ModuleName) const {
+return BuiltModuleNames.contains(ModuleName);
+  }
+
+  void addModuleFile(llvm::StringRef ModuleName,
+

[clang] Reapply [Clang][C++26] Implement "Ordering of constraints involving fold expressions (PR #99022)

2024-07-16 Thread via cfe-commits

https://github.com/cor3ntin created 
https://github.com/llvm/llvm-project/pull/99022

Implement https://isocpp.org/files/papers/P2963R3.pdf

>From 028bac287cbc6d07ad426aa91b7df9195153dd08 Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Tue, 9 Jul 2024 16:08:44 +0200
Subject: [PATCH 01/10] [Clang][C++26] Implement "Ordering of constraints
 involving fold expressions"

Implement https://isocpp.org/files/papers/P2963R3.pdf
---
 clang/docs/ReleaseNotes.rst |   3 +
 clang/include/clang/Sema/Sema.h |   5 +
 clang/include/clang/Sema/SemaConcept.h  | 142 +-
 clang/lib/Sema/SemaConcept.cpp  | 602 
 clang/lib/Sema/SemaTemplateVariadic.cpp |   4 +
 clang/test/SemaCXX/cxx2c-fold-exprs.cpp | 239 ++
 clang/www/cxx_status.html   |   2 +-
 7 files changed, 780 insertions(+), 217 deletions(-)
 create mode 100644 clang/test/SemaCXX/cxx2c-fold-exprs.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 969856a8f978c..cb35825b71e3e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -278,6 +278,9 @@ C++2c Feature Support
 
 - Implemented `P3144R2 Deleting a Pointer to an Incomplete Type Should be 
Ill-formed `_.
 
+- Implemented `P2963R3 Ordering of constraints involving fold expressions 
`_.
+
+
 Resolutions to C++ Defect Reports
 ^
 - Substitute template parameter pack, when it is not explicitly specified
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 48dff1b76cc57..3cb1aa935fe46 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -14078,6 +14078,11 @@ class Sema final : public SemaBase {
   const DeclarationNameInfo &NameInfo,
   SmallVectorImpl &Unexpanded);
 
+  /// Collect the set of unexpanded parameter packs within the given
+  /// expression.
+  static void collectUnexpandedParameterPacks(
+  Expr *E, SmallVectorImpl &Unexpanded);
+
   /// Invoked when parsing a template argument followed by an
   /// ellipsis, which creates a pack expansion.
   ///
diff --git a/clang/include/clang/Sema/SemaConcept.h 
b/clang/include/clang/Sema/SemaConcept.h
index 711443505174f..b6327e729768b 100644
--- a/clang/include/clang/Sema/SemaConcept.h
+++ b/clang/include/clang/Sema/SemaConcept.h
@@ -75,6 +75,17 @@ struct AtomicConstraint {
   }
 };
 
+struct FoldExpandedConstraint;
+
+using NormalFormConstraint =
+llvm::PointerUnion;
+struct NormalizedConstraint;
+using NormalForm =
+llvm::SmallVector, 4>;
+
+NormalForm makeCNF(const NormalizedConstraint &Normalized);
+NormalForm makeDNF(const NormalizedConstraint &Normalized);
+
 /// \brief A normalized constraint, as defined in C++ [temp.constr.normal], is
 /// either an atomic constraint, a conjunction of normalized constraints or a
 /// disjunction of normalized constraints.
@@ -87,26 +98,17 @@ struct NormalizedConstraint {
   std::pair *, 1,
   CompoundConstraintKind>;
 
-  llvm::PointerUnion Constraint;
+  llvm::PointerUnion
+  Constraint;
 
   NormalizedConstraint(AtomicConstraint *C): Constraint{C} { };
+  NormalizedConstraint(FoldExpandedConstraint *C) : Constraint{C} {};
+
   NormalizedConstraint(ASTContext &C, NormalizedConstraint LHS,
-   NormalizedConstraint RHS, CompoundConstraintKind Kind)
-  : Constraint{CompoundConstraint{
-new (C) std::pair{
-std::move(LHS), std::move(RHS)}, Kind}} { };
-
-  NormalizedConstraint(ASTContext &C, const NormalizedConstraint &Other) {
-if (Other.isAtomic()) {
-  Constraint = new (C) AtomicConstraint(*Other.getAtomicConstraint());
-} else {
-  Constraint = CompoundConstraint(
-  new (C) std::pair{
-  NormalizedConstraint(C, Other.getLHS()),
-  NormalizedConstraint(C, Other.getRHS())},
-  Other.getCompoundKind());
-}
-  }
+   NormalizedConstraint RHS, CompoundConstraintKind Kind);
+
+  NormalizedConstraint(ASTContext &C, const NormalizedConstraint &Other);
   NormalizedConstraint(NormalizedConstraint &&Other):
   Constraint(Other.Constraint) {
 Other.Constraint = nullptr;
@@ -126,6 +128,9 @@ struct NormalizedConstraint {
   }
 
   bool isAtomic() const { return Constraint.is(); }
+  bool isFoldExpanded() const {
+return Constraint.is();
+  }
 
   NormalizedConstraint &getLHS() const {
 assert(!isAtomic() && "getLHS called on atomic constraint.");
@@ -143,6 +148,12 @@ struct NormalizedConstraint {
 return Constraint.get();
   }
 
+  FoldExpandedConstraint *getFoldExpandedConstraint() const {
+assert(isFoldExpanded() &&
+   "getFoldExpandedConstraint called on non-fold-expanded 
constraint.");
+return Constraint.get();
+  }
+
 private:
   static std::optional
   fromConstraintExprs(Sema &S, NamedDecl *D, ArrayRef E);
@@ -150,6 +161,103 @@ struct NormalizedConst

[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)

2024-07-16 Thread kadir çetinkaya via cfe-commits


@@ -0,0 +1,335 @@
+//===- ModulesBuilder.cpp *- 
C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ModulesBuilder.h"
+#include "Compiler.h"
+#include "support/Logger.h"
+#include "clang/Frontend/FrontendAction.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Serialization/ASTReader.h"
+
+namespace clang {
+namespace clangd {
+
+namespace {
+
+// Create a path to store module files. Generally it should be:
+//
+//   {TEMP_DIRS}/clangd/module_files/{hashed-file-name}-%%-%%-%%-%%-%%-%%/.
+//
+// {TEMP_DIRS} is the temporary directory for the system, e.g., "/var/tmp"
+// or "C:/TEMP".
+//
+// '%%' means random value to make the generated path unique.
+//
+// \param MainFile is used to get the root of the project from global
+// compilation database.
+//
+// TODO: Move these module fils out of the temporary directory if the module
+// files are persistent.
+llvm::SmallString<256> getUniqueModuleFilesPath(PathRef MainFile) {
+  llvm::SmallString<128> HashedPrefix = llvm::sys::path::filename(MainFile);
+  // There might be multiple files with the same name in a project. So 
appending
+  // the hash value of the full path to make sure they won't conflict.
+  HashedPrefix += std::to_string(llvm::hash_value(MainFile));
+
+  llvm::SmallString<256> ResultPattern;
+
+  llvm::sys::path::system_temp_directory(/*erasedOnReboot=*/true,
+ ResultPattern);
+
+  llvm::sys::path::append(ResultPattern, "clangd");
+  llvm::sys::path::append(ResultPattern, "module_files");
+
+  llvm::sys::path::append(ResultPattern, HashedPrefix);
+
+  ResultPattern.append("-%%-%%-%%-%%-%%-%%");
+
+  llvm::SmallString<256> Result;
+  llvm::sys::fs::createUniquePath(ResultPattern, Result,
+  /*MakeAbsolute=*/false);
+
+  llvm::sys::fs::create_directories(Result);
+  return Result;
+}
+
+// Get a unique module file path under \param ModuleFilesPrefix.
+std::string getModuleFilePath(llvm::StringRef ModuleName,
+  PathRef ModuleFilesPrefix) {
+  llvm::SmallString<256> ModuleFilePath(ModuleFilesPrefix);
+  auto [PrimaryModuleName, PartitionName] = ModuleName.split(':');
+  llvm::sys::path::append(ModuleFilePath, PrimaryModuleName);
+  if (!PartitionName.empty()) {
+ModuleFilePath.append("-");
+ModuleFilePath.append(PartitionName);
+  }
+
+  ModuleFilePath.append(".pcm");
+  return std::string(ModuleFilePath);
+}
+
+// FailedPrerequisiteModules - stands for the PrerequisiteModules which has
+// errors happened during the building process.
+class FailedPrerequisiteModules : public PrerequisiteModules {
+public:
+  ~FailedPrerequisiteModules() override = default;
+
+  // We shouldn't adjust the compilation commands based on
+  // FailedPrerequisiteModules.
+  void adjustHeaderSearchOptions(HeaderSearchOptions &Options) const override {
+  }
+
+  // FailedPrerequisiteModules can never be reused.
+  bool
+  canReuse(const CompilerInvocation &CI,
+   llvm::IntrusiveRefCntPtr) const override {
+return false;
+  }
+};
+
+// StandalonePrerequisiteModules - stands for PrerequisiteModules for which all
+// the required modules are built successfully. All the module files
+// are owned by the StandalonePrerequisiteModules class.
+//
+// Any of the built module files won't be shared with other instances of the
+// class. So that we can avoid worrying thread safety.
+//
+// We don't need to worry about duplicated module names here since the standard
+// guarantees the module names should be unique to a program.
+class StandalonePrerequisiteModules : public PrerequisiteModules {
+public:
+  StandalonePrerequisiteModules() = default;
+
+  StandalonePrerequisiteModules(const StandalonePrerequisiteModules &) = 
delete;
+  StandalonePrerequisiteModules
+  operator=(const StandalonePrerequisiteModules &) = delete;
+  StandalonePrerequisiteModules(StandalonePrerequisiteModules &&) = delete;
+  StandalonePrerequisiteModules
+  operator=(StandalonePrerequisiteModules &&) = delete;
+
+  ~StandalonePrerequisiteModules() override = default;
+
+  void adjustHeaderSearchOptions(HeaderSearchOptions &Options) const override {
+// Appending all built module files.
+for (auto &RequiredModule : RequiredModules)
+  Options.PrebuiltModuleFiles.insert_or_assign(
+  RequiredModule.ModuleName, RequiredModule.ModuleFilePath);
+  }
+
+  bool canReuse(const CompilerInvocation &CI,
+llvm::IntrusiveRefCntPtr) const 
override;
+
+  bool isModuleUnitBuilt(llvm::StringRef ModuleName) const {
+return BuiltModuleNames.contains(ModuleName);
+  }
+
+  void addModuleFile(llvm::StringRef ModuleName,
+

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

2024-07-16 Thread via cfe-commits

https://github.com/vfdff updated https://github.com/llvm/llvm-project/pull/96025

>From ed6292fd0e9119322c39e5f37e2225c76e324101 Mon Sep 17 00:00:00 2001
From: zhongyunde 00443407 
Date: Tue, 18 Jun 2024 09:21:07 -0400
Subject: [PATCH 1/9] [TBAA] Emit int TBAA metadata on FP math libcalls

Base on the discussion 
https://discourse.llvm.org/t/fp-can-we-add-pure-attribute-for-math-library-functions-default/79459,
math libcalls set errno, so it should emit "int" TBAA metadata on FP libcalls
to solve the alias issue.

Fix https://github.com/llvm/llvm-project/issues/86635
---
 clang/lib/CodeGen/CGBuiltin.cpp   | 33 ++-
 clang/test/CodeGen/math-libcalls-tbaa.cpp | 22 +++
 2 files changed, 54 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGen/math-libcalls-tbaa.cpp

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 08a89bd123d03..dc4af109cdbdb 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -707,7 +707,38 @@ static RValue emitLibraryCall(CodeGenFunction &CGF, const 
FunctionDecl *FD,
   const CallExpr *E, llvm::Constant *calleeValue) {
   CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
   CGCallee callee = CGCallee::forDirect(calleeValue, GlobalDecl(FD));
-  return CGF.EmitCall(E->getCallee()->getType(), callee, E, ReturnValueSlot());
+  RValue Call =
+  CGF.EmitCall(E->getCallee()->getType(), callee, E, ReturnValueSlot());
+
+  // Check the supported intrinsic.
+  if (unsigned BuiltinID = FD->getBuiltinID()) {
+auto IntrinsicID = [&]() -> unsigned {
+  switch (BuiltinID) {
+  case Builtin::BIexpf:
+  case Builtin::BI__builtin_expf:
+  case Builtin::BI__builtin_expf128:
+return true;
+  }
+  // TODO: support more FP math libcalls
+  return false;
+}();
+
+if (IntrinsicID) {
+  llvm::MDBuilder MDHelper(CGF.getLLVMContext());
+  MDNode *RootMD;
+  if (CGF.getLangOpts().CPlusPlus)
+RootMD = MDHelper.createTBAARoot("Simple C++ TBAA");
+  else
+RootMD = MDHelper.createTBAARoot("Simple C/C++ TBAA");
+  // Emit "int" TBAA metadata on FP math libcalls.
+  MDNode *AliasType = MDHelper.createTBAANode("int", RootMD);
+  MDNode *MDInt = MDHelper.createTBAAStructTagNode(AliasType, AliasType, 
0);
+
+  Value *Val = Call.getScalarVal();
+  cast(Val)->setMetadata(LLVMContext::MD_tbaa, MDInt);
+}
+  }
+  return Call;
 }
 
 /// Emit a call to llvm.{sadd,uadd,ssub,usub,smul,umul}.with.overflow.*
diff --git a/clang/test/CodeGen/math-libcalls-tbaa.cpp 
b/clang/test/CodeGen/math-libcalls-tbaa.cpp
new file mode 100644
index 0..d5b0741a476cb
--- /dev/null
+++ b/clang/test/CodeGen/math-libcalls-tbaa.cpp
@@ -0,0 +1,22 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 2
+// RUN:  %clang -S -O3 -emit-llvm -o - -x c++ %s | FileCheck %s 
-check-prefixes=CHECK
+
+#include 
+
+
+// Emit int TBAA metadata on FP math libcalls, which is useful for alias 
analysis
+
+// CHECK-LABEL: define dso_local noundef float @_Z3fooPffi
+// CHECK-SAME: (ptr nocapture noundef readonly [[NUM:%.*]], float noundef 
[[R2INV:%.*]], i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds i8, ptr [[NUM]], 
i64 40
+// CHECK-NEXT:[[TMP0:%.*]] = load float, ptr [[ARRAYIDX]], align 4, !tbaa 
[[TBAA6:![0-9]+]]
+// CHECK-NEXT:[[CALL_I:%.*]] = tail call noundef float @expf(float noundef 
[[TMP0]]) #[[ATTR2:[0-9]+]], !tbaa [[TBAA10:![0-9]+]]
+// CHECK-NEXT:[[MUL:%.*]] = fmul float [[TMP0]], [[CALL_I]]
+// CHECK-NEXT:ret float [[MUL]]
+//
+float foo (float num[], float r2inv, int n) {
+   const float expm2 =  std::exp(num[10]);  // Emit TBAA metadata on @expf
+   float tmp = expm2 * num[10];
+   return tmp;
+}

>From 9990877a2b9736c684c8cabeb03c6d98a3d078ce Mon Sep 17 00:00:00 2001
From: zhongyunde 00443407 
Date: Thu, 20 Jun 2024 02:29:11 -0400
Subject: [PATCH 2/9] Address comment, reuse CodeGenTBAA::getRoot

---
 clang/lib/CodeGen/CGBuiltin.cpp   |  6 +-
 clang/lib/CodeGen/CodeGenModule.h |  2 ++
 clang/lib/CodeGen/CodeGenTBAA.h   |  8 
 clang/test/CodeGen/math-libcalls-tbaa.cpp | 20 +++-
 4 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index dc4af109cdbdb..3f448e11bca1a 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -725,11 +725,7 @@ static RValue emitLibraryCall(CodeGenFunction &CGF, const 
FunctionDecl *FD,
 
 if (IntrinsicID) {
   llvm::MDBuilder MDHelper(CGF.getLLVMContext());
-  MDNode *RootMD;
-  if (CGF.getLangOpts().CPlusPlus)
-RootMD = MDHelper.createTBAARoot("Simple C++ TBAA");
-  else
-RootMD = MDHelper.createTBAARoot("Si

[clang] [clang] Add deprecation warning for `-Ofast` driver option (PR #98736)

2024-07-16 Thread via cfe-commits

cor3ntin wrote:

@Endilll I think Aaron's suggestion gets you closer to what @tschuett wants

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


[clang] [clang] Be careful when choosing "fast path" for initialization with #embed (PR #99023)

2024-07-16 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon created 
https://github.com/llvm/llvm-project/pull/99023

When #embed appears in an initializer list, we may choose a "fast path"
- if the target declaration is a char array, we simply initialize it with 
string literal that contains embedded data. However we need to be careful when 
checking that we actually can use this "fast path" since char array may be 
nested in a struct.

>From 4a48f6ab0d26d5c83b29c866a79bd8cdcc9102b9 Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Tue, 16 Jul 2024 04:45:57 -0700
Subject: [PATCH] [clang] Be careful when choosing "fast path" for
 initialization with #embed

When #embed appears in an initializer list, we may choose a "fast path"
- if the target declaration is a char array, we simply initialize it
 with string literal that contains embedded data. However we need to be
 careful when checking that we actually can use this "fast path" since
 char array may be nested in a struct.
---
 clang/lib/Sema/SemaInit.cpp | 17 +
 clang/test/Preprocessor/embed_codegen.cpp   |  8 
 clang/test/Preprocessor/embed_constexpr.cpp |  8 
 3 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index a27ed02fc73b8..d97a5c8988840 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -1993,9 +1993,18 @@ static bool checkDestructorReference(QualType 
ElementType, SourceLocation Loc,
   return SemaRef.DiagnoseUseOfDecl(Destructor, Loc);
 }
 
-static bool canInitializeArrayWithEmbedDataString(ArrayRef ExprList,
-  QualType InitType,
-  ASTContext &Context) {
+static bool
+canInitializeArrayWithEmbedDataString(ArrayRef ExprList,
+  const InitializedEntity &Entity,
+  ASTContext &Context) {
+  QualType InitType = Entity.getType();
+  const InitializedEntity *Parent = &Entity;
+
+  while (Parent) {
+InitType = Parent->getType();
+Parent = Parent->getParent();
+  }
+
   // Only one initializer, it's an embed and the types match;
   EmbedExpr *EE =
   ExprList.size() == 1
@@ -2034,7 +2043,7 @@ void InitListChecker::CheckArrayType(const 
InitializedEntity &Entity,
 }
   }
 
-  if (canInitializeArrayWithEmbedDataString(IList->inits(), DeclType,
+  if (canInitializeArrayWithEmbedDataString(IList->inits(), Entity,
 SemaRef.Context)) {
 EmbedExpr *Embed = cast(IList->inits()[0]);
 IList->setInit(0, Embed->getDataStringLiteral());
diff --git a/clang/test/Preprocessor/embed_codegen.cpp 
b/clang/test/Preprocessor/embed_codegen.cpp
index 64110afc162d7..c73a265ac7494 100644
--- a/clang/test/Preprocessor/embed_codegen.cpp
+++ b/clang/test/Preprocessor/embed_codegen.cpp
@@ -3,6 +3,7 @@
 // CHECK: @__const._Z3fooi.ca = private unnamed_addr constant [3 x i32] [i32 
0, i32 106, i32 107], align 4
 // CHECK: @__const._Z3fooi.sc = private unnamed_addr constant %struct.S1 { i32 
106, i32 107, i32 0 }, align 4
 // CHECK: @__const._Z3fooi.t = private unnamed_addr constant [3 x %struct.T] 
[%struct.T { [2 x i32] [i32 48, i32 49], %struct.S1 { i32 50, i32 51, i32 52 } 
}, %struct.T { [2 x i32] [i32 53, i32 54], %struct.S1 { i32 55, i32 56, i32 57 
} }, %struct.T { [2 x i32] [i32 10, i32 0], %struct.S1 zeroinitializer }], 
align 16
+// CHECK: @__const._Z3fooi.W = private unnamed_addr constant %struct.Wrapper { 
i32 48, %struct.HasCharArray { [10 x i8] c"123456789\0A" } }, align 4
 void foo(int a) {
 // CHECK: %a.addr = alloca i32, align 4
 // CHECK: store i32 %a, ptr %a.addr, align 4
@@ -81,4 +82,11 @@ struct T tnonc[] = {
 #embed  prefix(,)
 };
 
+
+struct HasCharArray { unsigned char h[10]; };
+struct Wrapper { int a; struct HasCharArray d;  };
+constexpr struct Wrapper W = {
+#embed "numbers.txt"
+};
+
 }
diff --git a/clang/test/Preprocessor/embed_constexpr.cpp 
b/clang/test/Preprocessor/embed_constexpr.cpp
index 1cadff76b4890..9b6470fcc7182 100644
--- a/clang/test/Preprocessor/embed_constexpr.cpp
+++ b/clang/test/Preprocessor/embed_constexpr.cpp
@@ -95,3 +95,11 @@ struct ST {};
 ST<
 #embed  limit(1)
 > st;
+
+struct HasCharArray { unsigned char h[10]; };
+struct Wrapper { int a; struct HasCharArray d;  };
+constexpr struct Wrapper W = {
+#embed "numbers.txt"
+};
+
+static_assert(W.d.h[2] == '3');

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


[clang] [clang] Be careful when choosing "fast path" for initialization with #embed (PR #99023)

2024-07-16 Thread Mariya Podchishchaeva via cfe-commits

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


[clang] [clang] Be careful when choosing "fast path" for initialization with #embed (PR #99023)

2024-07-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Mariya Podchishchaeva (Fznamznon)


Changes

When #embed appears in an initializer list, we may choose a "fast path" if the 
target declaration is a char array. We simply initialize it with string literal 
that contains embedded data. However we need to be careful when checking that 
we actually can use this "fast path" since char array may be nested in a struct.

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


3 Files Affected:

- (modified) clang/lib/Sema/SemaInit.cpp (+13-4) 
- (modified) clang/test/Preprocessor/embed_codegen.cpp (+8) 
- (modified) clang/test/Preprocessor/embed_constexpr.cpp (+8) 


``diff
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index a27ed02fc73b8..d97a5c8988840 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -1993,9 +1993,18 @@ static bool checkDestructorReference(QualType 
ElementType, SourceLocation Loc,
   return SemaRef.DiagnoseUseOfDecl(Destructor, Loc);
 }
 
-static bool canInitializeArrayWithEmbedDataString(ArrayRef ExprList,
-  QualType InitType,
-  ASTContext &Context) {
+static bool
+canInitializeArrayWithEmbedDataString(ArrayRef ExprList,
+  const InitializedEntity &Entity,
+  ASTContext &Context) {
+  QualType InitType = Entity.getType();
+  const InitializedEntity *Parent = &Entity;
+
+  while (Parent) {
+InitType = Parent->getType();
+Parent = Parent->getParent();
+  }
+
   // Only one initializer, it's an embed and the types match;
   EmbedExpr *EE =
   ExprList.size() == 1
@@ -2034,7 +2043,7 @@ void InitListChecker::CheckArrayType(const 
InitializedEntity &Entity,
 }
   }
 
-  if (canInitializeArrayWithEmbedDataString(IList->inits(), DeclType,
+  if (canInitializeArrayWithEmbedDataString(IList->inits(), Entity,
 SemaRef.Context)) {
 EmbedExpr *Embed = cast(IList->inits()[0]);
 IList->setInit(0, Embed->getDataStringLiteral());
diff --git a/clang/test/Preprocessor/embed_codegen.cpp 
b/clang/test/Preprocessor/embed_codegen.cpp
index 64110afc162d7..c73a265ac7494 100644
--- a/clang/test/Preprocessor/embed_codegen.cpp
+++ b/clang/test/Preprocessor/embed_codegen.cpp
@@ -3,6 +3,7 @@
 // CHECK: @__const._Z3fooi.ca = private unnamed_addr constant [3 x i32] [i32 
0, i32 106, i32 107], align 4
 // CHECK: @__const._Z3fooi.sc = private unnamed_addr constant %struct.S1 { i32 
106, i32 107, i32 0 }, align 4
 // CHECK: @__const._Z3fooi.t = private unnamed_addr constant [3 x %struct.T] 
[%struct.T { [2 x i32] [i32 48, i32 49], %struct.S1 { i32 50, i32 51, i32 52 } 
}, %struct.T { [2 x i32] [i32 53, i32 54], %struct.S1 { i32 55, i32 56, i32 57 
} }, %struct.T { [2 x i32] [i32 10, i32 0], %struct.S1 zeroinitializer }], 
align 16
+// CHECK: @__const._Z3fooi.W = private unnamed_addr constant %struct.Wrapper { 
i32 48, %struct.HasCharArray { [10 x i8] c"123456789\0A" } }, align 4
 void foo(int a) {
 // CHECK: %a.addr = alloca i32, align 4
 // CHECK: store i32 %a, ptr %a.addr, align 4
@@ -81,4 +82,11 @@ struct T tnonc[] = {
 #embed  prefix(,)
 };
 
+
+struct HasCharArray { unsigned char h[10]; };
+struct Wrapper { int a; struct HasCharArray d;  };
+constexpr struct Wrapper W = {
+#embed "numbers.txt"
+};
+
 }
diff --git a/clang/test/Preprocessor/embed_constexpr.cpp 
b/clang/test/Preprocessor/embed_constexpr.cpp
index 1cadff76b4890..9b6470fcc7182 100644
--- a/clang/test/Preprocessor/embed_constexpr.cpp
+++ b/clang/test/Preprocessor/embed_constexpr.cpp
@@ -95,3 +95,11 @@ struct ST {};
 ST<
 #embed  limit(1)
 > st;
+
+struct HasCharArray { unsigned char h[10]; };
+struct Wrapper { int a; struct HasCharArray d;  };
+constexpr struct Wrapper W = {
+#embed "numbers.txt"
+};
+
+static_assert(W.d.h[2] == '3');

``




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


[clang] [clang] Inject tokens containing #embed back into token stream (PR #97274)

2024-07-16 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

> Just checked that one and it still fails on latest clang trunk using godbolt.

Hmm, ok. https://github.com/llvm/llvm-project/pull/99023 . Thanks for pointing 
this out.


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


[clang] Reapply [Clang][C++26] Implement "Ordering of constraints involving fold expressions (PR #99022)

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

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

The 32-bit fix LGTM!

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


[clang] 5b310a1 - [clang][Interp] Ignore lambda static invoker frames in backtraces

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

Author: Timm Bäder
Date: 2024-07-16T13:57:41+02:00
New Revision: 5b310a1c3c5aabae325934a6475e93ea8b71cdc2

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

LOG: [clang][Interp] Ignore lambda static invoker frames in backtraces

See comment. No test but this is neccessary for a later commit.

Added: 


Modified: 
clang/lib/AST/Interp/InterpFrame.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/InterpFrame.cpp 
b/clang/lib/AST/Interp/InterpFrame.cpp
index 383380f485e03..d3f3e216b7eb2 100644
--- a/clang/lib/AST/Interp/InterpFrame.cpp
+++ b/clang/lib/AST/Interp/InterpFrame.cpp
@@ -158,7 +158,9 @@ void InterpFrame::describe(llvm::raw_ostream &OS) const {
   // diagnose them. The 'in call to' diagnostics for them add no value to the
   // user _and_ it doesn't generally work since the argument types don't always
   // match the function prototype. Just ignore them.
-  if (const auto *F = getFunction(); F && F->isBuiltin())
+  // Similarly, for lambda static invokers, we would just print __invoke().
+  if (const auto *F = getFunction();
+  F && (F->isBuiltin() || F->isLambdaStaticInvoker()))
 return;
 
   const FunctionDecl *F = getCallee();



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


[clang] [PAC] Implement function pointer re-signing (PR #98847)

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


@@ -4434,16 +4433,41 @@ class CodeGenFunction : public CodeGenTypeCache {
 llvm::Value *StorageAddress,
 GlobalDecl SchemaDecl,
 QualType SchemaType);
+
   llvm::Value *EmitPointerAuthSign(QualType PointeeType, llvm::Value *Pointer);
   llvm::Value *EmitPointerAuthSign(const CGPointerAuthInfo &Info,
llvm::Value *Pointer);
+
+  llvm::Value *EmitPointerAuthAuth(QualType PointeeType, llvm::Value *Pointer);

kovdan01 wrote:

Several newly defined member functions look unused and unneeded in scope of 
this PR:
- `llvm::Value *CodeGenFunction::EmitPointerAuthAuth(QualType PointeeType, 
llvm::Value *Pointer)`
- `Address CodeGenFunction::EmitPointerAuthSign(Address Addr, QualType 
PointeeType)`
- `Address CodeGenFunction::EmitPointerAuthAuth(Address Addr, QualType 
PointeeType)`

I think it's better to remove them

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


[clang] [PAC] Implement function pointer re-signing (PR #98847)

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


@@ -2373,7 +2373,9 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
   DestLV.setTBAAInfo(TBAAAccessInfo::getMayAliasInfo());
   return EmitLoadOfLValue(DestLV, CE->getExprLoc());
 }
-return Builder.CreateBitCast(Src, DstTy);
+
+llvm::Value *Result = Builder.CreateBitCast(Src, DstTy);

kovdan01 wrote:

Is there a test for this code path? If it's missing, I'm OK with adding that 
later in a follow-up patch.

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


[clang] [PAC] Implement function pointer re-signing (PR #98847)

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

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


[clang] [PAC] Implement function pointer re-signing (PR #98847)

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


@@ -3126,3 +3137,57 @@ CodeGenFunction::EmitPointerAuthAuth(const 
CGPointerAuthInfo &PointerAuth,
   return EmitPointerAuthCommon(*this, PointerAuth, Pointer,
llvm::Intrinsic::ptrauth_auth);
 }
+
+llvm::Value *CodeGenFunction::EmitPointerAuthSign(QualType pointeeType,

kovdan01 wrote:

Just in case if I missed smth: why are some PAuth-related member functions of 
`CodeGenFunction` defined in CGPointerAuth.cpp, and some are defined here in 
CodeGenFunction.cpp? Could you please describe the logic behind this choice?

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


[clang] [PAC] Implement function pointer re-signing (PR #98847)

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


@@ -351,3 +434,125 @@ CodeGenModule::getVTablePointerAuthInfo(CodeGenFunction 
*CGF,
/* IsIsaPointer */ false,
/* AuthenticatesNullValues */ false, Discriminator);
 }
+
+llvm::Value *CodeGenFunction::AuthPointerToPointerCast(llvm::Value *ResultPtr,
+   QualType SourceType,
+   QualType DestType) {
+  CGPointerAuthInfo CurAuthInfo, NewAuthInfo;
+  if (SourceType->isSignableType())
+CurAuthInfo = getPointerAuthInfoForType(CGM, SourceType);
+
+  if (DestType->isSignableType())
+NewAuthInfo = getPointerAuthInfoForType(CGM, DestType);
+
+  if (!CurAuthInfo && !NewAuthInfo)
+return ResultPtr;
+
+  // If only one side of the cast is a function pointer, then we still need to
+  // resign to handle casts to/from opaque pointers.
+  if (!CurAuthInfo && DestType->isFunctionPointerType())
+CurAuthInfo = CGM.getFunctionPointerAuthInfo(SourceType);
+
+  if (!NewAuthInfo && SourceType->isFunctionPointerType())
+NewAuthInfo = CGM.getFunctionPointerAuthInfo(DestType);
+
+  return EmitPointerAuthResign(ResultPtr, DestType, CurAuthInfo, NewAuthInfo,
+   /*IsKnownNonNull=*/false);
+}
+
+Address CodeGenFunction::AuthPointerToPointerCast(Address Ptr,
+  QualType SourceType,
+  QualType DestType) {
+  CGPointerAuthInfo CurAuthInfo, NewAuthInfo;
+  if (SourceType->isSignableType())
+CurAuthInfo = getPointerAuthInfoForType(CGM, SourceType);
+
+  if (DestType->isSignableType())
+NewAuthInfo = getPointerAuthInfoForType(CGM, DestType);
+
+  if (!CurAuthInfo && !NewAuthInfo)
+return Ptr;
+
+  if (!CurAuthInfo && DestType->isFunctionPointerType()) {
+// When casting a non-signed pointer to a function pointer, just set the
+// auth info on Ptr to the assumed schema. The pointer will be resigned to
+// the effective type when used.
+Ptr.setPointerAuthInfo(CGM.getFunctionPointerAuthInfo(SourceType));
+return Ptr;
+  }
+
+  if (!NewAuthInfo && SourceType->isFunctionPointerType()) {
+NewAuthInfo = CGM.getFunctionPointerAuthInfo(DestType);
+Ptr = Ptr.getResignedAddress(NewAuthInfo, *this);
+Ptr.setPointerAuthInfo(CGPointerAuthInfo());
+return Ptr;
+  }
+
+  return Ptr;
+}
+
+Address CodeGenFunction::EmitPointerAuthSign(Address Addr,
+ QualType PointeeType) {
+  CGPointerAuthInfo Info = getPointerAuthInfoForPointeeType(CGM, PointeeType);
+  llvm::Value *Ptr = EmitPointerAuthSign(Info, Addr.emitRawPointer(*this));
+  return Address(Ptr, Addr.getElementType(), Addr.getAlignment());
+}
+
+Address CodeGenFunction::EmitPointerAuthAuth(Address Addr,
+ QualType PointeeType) {
+  CGPointerAuthInfo Info = getPointerAuthInfoForPointeeType(CGM, PointeeType);
+  llvm::Value *Ptr = EmitPointerAuthAuth(Info, Addr.emitRawPointer(*this));
+  return Address(Ptr, Addr.getElementType(), Addr.getAlignment());
+}
+
+Address CodeGenFunction::getAsNaturalAddressOf(Address Addr,
+   QualType PointeeTy) {
+  CGPointerAuthInfo Info =
+  PointeeTy.isNull() ? CGPointerAuthInfo()
+ : CGM.getPointerAuthInfoForPointeeType(PointeeTy);
+  return Addr.getResignedAddress(Info, *this);
+}
+
+Address Address::getResignedAddress(const CGPointerAuthInfo &NewInfo,
+CodeGenFunction &CGF) const {
+  assert(isValid() && "pointer isn't valid");
+  CGPointerAuthInfo CurInfo = getPointerAuthInfo();
+  llvm::Value *Val;
+
+  // Nothing to do if neither the current or the new ptrauth info needs 
signing.
+  if (!CurInfo.isSigned() && !NewInfo.isSigned())
+return Address(getBasePointer(), getElementType(), getAlignment(),
+   isKnownNonNull());
+
+  assert(ElementType && "Effective type has to be set");
+
+  // If the current and the new ptrauth infos are the same and the offset is
+  // null, just cast the base pointer to the effective type.
+  if (CurInfo == NewInfo && !hasOffset())
+Val = getBasePointer();
+  else {
+assert(!Offset && "unexpected non-null offset");
+Val = CGF.EmitPointerAuthResign(getBasePointer(), QualType(), CurInfo,
+NewInfo, isKnownNonNull());
+  }
+
+  Val = CGF.Builder.CreateBitCast(Val, getType());
+  return Address(Val, getElementType(), getAlignment(), NewInfo, nullptr,
+ isKnownNonNull());
+}
+
+llvm::Value *LValue::getPointer(CodeGenFunction &CGF) const {
+  assert(isSimple());
+  return emitResignedPointer(getType(), CGF);

kovdan01 wrote:

I suppose it might be worth to have a "short-path" for non-signed pointers. 
Most code is compile w/o pauth, but we'll always have overhead of calling these 
pauth-rela

[clang] [PAC] Implement function pointer re-signing (PR #98847)

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

https://github.com/kovdan01 commented:

Mostly LGTM. There are several new pretty minor comments, but they can be 
addressed in a follor-up PR.

The thing which is better to be addressed as a part of this PR is deleting 
three unneeded member functions from `CodeGenFunction`. IMHO there is no reason 
to ship this changes right now.

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


[clang] [PAC] Implement function pointer re-signing (PR #98847)

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

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


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

2024-07-16 Thread via cfe-commits


@@ -707,7 +707,34 @@ static RValue emitLibraryCall(CodeGenFunction &CGF, const 
FunctionDecl *FD,
   const CallExpr *E, llvm::Constant *calleeValue) {
   CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
   CGCallee callee = CGCallee::forDirect(calleeValue, GlobalDecl(FD));
-  return CGF.EmitCall(E->getCallee()->getType(), callee, E, ReturnValueSlot());
+  RValue Call =
+  CGF.EmitCall(E->getCallee()->getType(), callee, E, ReturnValueSlot());
+
+  // Check the supported intrinsic.
+  if (unsigned BuiltinID = FD->getBuiltinID()) {
+auto IntrinsicID = [&]() -> unsigned {
+  switch (BuiltinID) {
+  case Builtin::BIexpf:
+  case Builtin::BI__builtin_expf:
+  case Builtin::BI__builtin_expf128:
+return true;
+  }
+  // TODO: support more FP math libcalls
+  return false;
+}();
+
+// Restrict to target with errno, for example, MacOS doesn't set errno.
+if (IntrinsicID && CGF.CGM.getLangOpts().MathErrno) {
+  llvm::MDBuilder MDHelper(CGF.getLLVMContext());

vfdff wrote:

Done,

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


[clang] [clang] Inject tokens containing #embed back into token stream (PR #97274)

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

AaronBallman wrote:

> I thought there was agreement that at least for C the literals have type int,

That's correct; this patch gets started on addressing that issue by updating 
the way we expand the embedded contents but isn't intended to fix the type 
issue yet (that will be a follow-up patch). When we do the follow-up, we should 
ensure the embedded elements are of type `int` (for both C and C++; we don't 
want different types coming out of the preprocessor depending on language mode 
as that will make life harder for mixed C and C++ code bases).

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


[clang] [clang] Inject tokens containing #embed back into token stream (PR #97274)

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

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

LGTM!

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


[clang] [clang] Add deprecation warning for `-Ofast` driver option (PR #98736)

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

https://github.com/Endilll updated 
https://github.com/llvm/llvm-project/pull/98736

>From 44b4a682f2b3d7e140f7b1bd124e7aabdbf439ad Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Sat, 13 Jul 2024 13:10:25 +0300
Subject: [PATCH 1/4] [clang] Add deprecation warning for `-Ofast` driver
 option

---
 clang/docs/ReleaseNotes.rst| 3 +++
 clang/include/clang/Basic/DiagnosticDriverKinds.td | 3 +++
 clang/include/clang/Basic/DiagnosticGroups.td  | 2 ++
 clang/include/clang/Driver/Options.td  | 3 ++-
 clang/lib/Driver/ToolChains/Clang.cpp  | 2 ++
 clang/test/Driver/Ofast.c  | 4 
 6 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ceead8c362e9c..2f5f40f355901 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -470,6 +470,9 @@ New Compiler Flags
 Deprecated Compiler Flags
 -
 
+- ``-Ofast`` is deprecated in favor of ``-O3``, possibly combined with 
``-ffast-math``.
+  See `RFC `_ for 
details.
+
 Modified Compiler Flags
 ---
 - Added a new diagnostic flag ``-Wreturn-mismatch`` which is grouped under
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 359c0de7f811c..3857f2f3a33ce 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -442,6 +442,9 @@ def warn_drv_deprecated_arg : Warning<
 def warn_drv_deprecated_arg_no_relaxed_template_template_args : Warning<
   "argument '-fno-relaxed-template-template-args' is deprecated">,
   InGroup;
+def warn_drv_deprecated_arg_ofast : Warning<
+  "argument '-Ofast' is deprecated; use '-O3', possibly with '-ffast-math'">,
+  InGroup;
 def warn_drv_deprecated_custom : Warning<
   "argument '%0' is deprecated, %1">, InGroup;
 def warn_drv_assuming_mfloat_abi_is : Warning<
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 2241f8481484e..d7dba76a0fcf8 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -103,6 +103,7 @@ def EnumConversion : DiagGroup<"enum-conversion",
 EnumFloatConversion,
 EnumCompareConditional]>;
 def DeprecatedNoRelaxedTemplateTemplateArgs : 
DiagGroup<"deprecated-no-relaxed-template-template-args">;
+def DeprecatedOFast : DiagGroup<"deprecated-ofast">;
 def ObjCSignedCharBoolImplicitIntConversion :
   DiagGroup<"objc-signed-char-bool-implicit-int-conversion">;
 def Shorten64To32 : DiagGroup<"shorten-64-to-32">;
@@ -228,6 +229,7 @@ def Deprecated : DiagGroup<"deprecated", 
[DeprecatedAnonEnumEnumConversion,
   DeprecatedPragma,
   DeprecatedRegister,
   
DeprecatedNoRelaxedTemplateTemplateArgs,
+  DeprecatedOFast,
   DeprecatedThisCapture,
   DeprecatedType,
   DeprecatedVolatile,
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index f1e8cb87e5321..269790476c1c3 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -931,7 +931,8 @@ def O : Joined<["-"], "O">, Group,
 def O_flag : Flag<["-"], "O">, Visibility<[ClangOption, CC1Option, FC1Option]>,
   Alias, AliasArgs<["1"]>;
 def Ofast : Joined<["-"], "Ofast">, Group,
-  Visibility<[ClangOption, CC1Option, FlangOption]>;
+  Visibility<[ClangOption, CC1Option, FlangOption]>,
+  HelpText<"Deprecated; use -O3, possibly with -ffast-math">;
 def P : Flag<["-"], "P">,
   Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
   Group,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index bc21d03a627b9..33e7152343171 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5712,6 +5712,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
  options::OPT_fno_zero_initialized_in_bss);
 
   bool OFastEnabled = isOptimizationLevelFast(Args);
+  if (OFastEnabled)
+D.Diag(diag::warn_drv_deprecated_arg_ofast);
   // If -Ofast is the optimization level, then -fstrict-aliasing should be
   // enabled.  This alias option is being used to simplify the hasFlag logic.
   OptSpecifier StrictAliasingAliasOption =
diff --git a/clang/test/Driver/Ofast.c b/clang/test/Driver/Ofast.c
index 8b7f2217eca2f..f5a2aabe257f1 100644
--- a/clang/test/Driver/Ofast.c
+++ b/clang/test/Driver/Ofast.c
@@ -10,6 +10,7 @@
 // RUN: %clang -Ofast -fno-stric

[clang] [clang] Add deprecation warning for `-Ofast` driver option (PR #98736)

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


@@ -10,31 +10,36 @@
 // RUN: %clang -Ofast -fno-strict-aliasing -### %s 2>&1 | FileCheck 
-check-prefix=CHECK-OFAST-NO-STRICT-ALIASING %s
 // RUN: %clang -Ofast -fno-vectorize -### %s 2>&1 | FileCheck 
-check-prefix=CHECK-OFAST-NO-VECTORIZE %s
 
+// CHECK-OFAST: argument '-Ofast' is deprecated; use '-O3 -ffast-math' 
instead, or just '-O3' if you do not intend to enable non-conforming 
optimizations
 // CHECK-OFAST: -cc1
 // CHECK-OFAST-NOT: -relaxed-aliasing
 // CHECK-OFAST: -ffast-math
 // CHECK-OFAST: -Ofast
 // CHECK-OFAST: -vectorize-loops
 
+// CHECK-OFAST-O2-NOT: argument '-Ofast' is deprecated; use '-O3 -ffast-math' 
instead, or just '-O3' if you do not intend to enable non-conforming 
optimizations

Endilll wrote:

Fixed.

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


[clang] [clang] Add deprecation warning for `-Ofast` driver option (PR #98736)

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


@@ -442,6 +442,9 @@ def warn_drv_deprecated_arg : Warning<
 def warn_drv_deprecated_arg_no_relaxed_template_template_args : Warning<
   "argument '-fno-relaxed-template-template-args' is deprecated">,
   InGroup;
+def warn_drv_deprecated_arg_ofast : Warning<
+  "argument '-Ofast' is deprecated; use '-O3', possibly with '-ffast-math'">,

Endilll wrote:

Switched to Aaron's wording

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


[clang] [clang][Interp] Implement dynamic memory allocation handling (PR #70306)

2024-07-16 Thread Timm Baeder via cfe-commits

tbaederr wrote:

> You can also try it under qemu - 
> https://linaro.atlassian.net/wiki/spaces/TCWGPUB/pages/29360783374/How+to+Reproduce+32+bit+Arm+Builds+Without+Hardware.

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


[clang] [llvm] Support for assume directive : Parse & AST modules (PR #97535)

2024-07-16 Thread via cfe-commits

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

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

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

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

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

2024-07-16 Thread Zahira Ammarguellat via cfe-commits


@@ -0,0 +1,43 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// The test may fail as time out on windows
+// REQUIRES: system-linux
+
+// RUN:  %clang -S -O3 -emit-llvm -o - -x c++ %s | FileCheck %s 
-check-prefixes=CHECK,NoNewStructPathTBAA
+// RUN:  %clang -S -O3 -Xclang -new-struct-path-tbaa -emit-llvm -o - -x c++ %s 
| FileCheck %s -check-prefixes=CHECK,NewStructPathTBAA
+

zahiraam wrote:

Yes, you are right I didn't notice that. Sorry. There is no TBAA on the `expf` 
call. But there should be since I uploaded your entire patch! I don't 
understand why the `extern C` would make any difference. Furthermore, I ran the 
LIT test with it. 

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


[clang] [clang] Be careful when choosing "fast path" for initialization with #embed (PR #99023)

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

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

LGTM!

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


[clang] [clang] Add deprecation warning for `-Ofast` driver option (PR #98736)

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

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

LGTM!

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


[clang] [llvm] Finish deleting the le32/le64 targets (PR #98497)

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

AaronBallman wrote:

> It looks like the removal missed a few bits: PNaClABIBuiltinVaList and 
> clang/lib/CodeGen/Targets/PNaCl.cpp weren't removed.

I was under the impression those bits were still needed for Chromium. CC 
@dschuff 

> > Unfortunately, this utterly breaks Halide, which was in fact relying on 
> > both of these targets.
> 
> We can temporarily revert this, but we aren't going to leave the orphaned 
> remains of PNaCl in-tree forever. If you need a "halide" target long-term, 
> please write up a proposal on Discourse describing exactly what bits you 
> need, why you need them, relevant test coverage in-tree and out-of-tree, and 
> a proposed code owner for those bits.

I'm comfortable with a second temporary revert if it's necessary so long as 
there's a time limit attached to it. The first attempted removal was over three 
years ago, so if Halide needs this target beyond Clang 20 (roughly six months 
from now), I think that they need to come to the community with a new proposed 
timeline for removal or a proposal for official target support of some kind 
(which requires additional maintenance beyond what the status quo is -- this 
target has very little in the way of testing or documentation).

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


  1   2   3   4   5   >