[clang] da9499e - [AArch64] Reduce +sve2-aes to an alias of +sve-aes+sve2 (#114293)

2024-11-08 Thread via cfe-commits

Author: SpencerAbson
Date: 2024-11-08T15:07:05Z
New Revision: da9499ebfb323602c42aeb674571fe89cec20ca6

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

LOG: [AArch64] Reduce +sve2-aes to an alias of +sve-aes+sve2 (#114293)

This patch introduces the amended feature flag for
[FEAT_SVE_AES](https://developer.arm.com/documentation/109697/2024_09/Feature-descriptions/The-Armv9-0-architecture-extension?lang=en#md457-the-armv90-architecture-extension__feat_FEAT_SVE_AES),
'**sve-aes**'. The existing flag associated with this feature,
'sve2-aes' must be retained as an alias of 'sve-aes' and 'sve2' for
backwards compatibility.

The
[ACLE](https://github.com/ARM-software/acle/blob/main/main/acle.md#aes-extension)
documents `__ARM_FEATURE_SVE2_AES`, which was previously defined to 1
when

> there is hardware support for the SVE2 AES (FEAT_SVE_AES) instructions
and if the associated ACLE intrinsics are available.

The front-end has been amended such that it is compatible with +sve2-aes
and +sve2+sve-aes.

Added: 


Modified: 
clang/include/clang/Basic/arm_sve.td
clang/lib/Basic/Targets/AArch64.cpp
clang/lib/Basic/Targets/AArch64.h
clang/test/CodeGen/aarch64-fmv-dependencies.c
clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_aesd.c
clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_aese.c
clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_aesimc.c
clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_aesmc.c
clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_pmullb_128.c
clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_pmullt_128.c
clang/test/Driver/aarch64-implied-sve-features.c
clang/test/Driver/print-supported-extensions-aarch64.c
clang/test/Preprocessor/aarch64-target-features.c
clang/test/Sema/aarch64-sve2-intrinsics/acle_sve2_aes_bitperm_sha3_sm4.cpp
lldb/test/Shell/Commands/command-disassemble-aarch64-extensions.s
llvm/lib/Target/AArch64/AArch64.td
llvm/lib/Target/AArch64/AArch64FMV.td
llvm/lib/Target/AArch64/AArch64Features.td
llvm/lib/Target/AArch64/AArch64InstrInfo.td
llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td
llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
llvm/test/CodeGen/AArch64/sve2-intrinsics-crypto.ll
llvm/test/MC/AArch64/SVE2/aesd.s
llvm/test/MC/AArch64/SVE2/aese.s
llvm/test/MC/AArch64/SVE2/aesimc.s
llvm/test/MC/AArch64/SVE2/aesmc.s
llvm/test/MC/AArch64/SVE2/directive-arch-negative.s
llvm/test/MC/AArch64/SVE2/directive-arch.s
llvm/test/MC/AArch64/SVE2/directive-arch_extension-negative.s
llvm/test/MC/AArch64/SVE2/directive-arch_extension.s
llvm/test/MC/AArch64/SVE2/directive-cpu-negative.s
llvm/test/MC/AArch64/SVE2/directive-cpu.s
llvm/test/MC/AArch64/SVE2/pmullb-128.s
llvm/test/MC/AArch64/SVE2/pmullt-128.s
llvm/unittests/TargetParser/TargetParserTest.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index 90b1ec242e6bae..b4bc4b7f61c347 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -1962,7 +1962,7 @@ let SVETargetGuard = "sve2,lut,bf16", SMETargetGuard = 
"sme2,lut,bf16" in {
 

 // SVE2 - Optional
 
-let SVETargetGuard = "sve2-aes", SMETargetGuard = InvalidMode in {
+let SVETargetGuard = "sve2,sve-aes", SMETargetGuard = InvalidMode in {
 def SVAESD   : SInst<"svaesd[_{d}]",   "ddd", "Uc", MergeNone, 
"aarch64_sve_aesd", [IsOverloadNone]>;
 def SVAESIMC : SInst<"svaesimc[_{d}]", "dd",  "Uc", MergeNone, 
"aarch64_sve_aesimc", [IsOverloadNone]>;
 def SVAESE   : SInst<"svaese[_{d}]",   "ddd", "Uc", MergeNone, 
"aarch64_sve_aese", [IsOverloadNone]>;

diff  --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index e35ee2b7b9c385..3fd43373cab445 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -473,7 +473,7 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
   if (HasSVE2p1)
 Builder.defineMacro("__ARM_FEATURE_SVE2p1", "1");
 
-  if (HasSVE2 && HasSVE2AES)
+  if (HasSVE2 && HasSVEAES)
 Builder.defineMacro("__ARM_FEATURE_SVE2_AES", "1");
 
   if (HasSVE2 && HasSVE2BitPerm)
@@ -769,7 +769,7 @@ bool AArch64TargetInfo::hasFeature(StringRef Feature) const 
{
   .Case("f32mm", FPU & SveMode && HasMatmulFP32)
   .Case("f64mm", FPU & SveMode && HasMatmulFP64)
   .Case("sve2", FPU & SveMode && HasSVE2)
-  .Case("sve2-pmull128", FPU & SveMode && HasSVE2AES)
+  .Case("sve2-pmull128", FPU & SveMode && HasSVEAES && HasSVE2)
   .Case("sve2-bitperm", FPU & SveMode && HasSVE2BitPerm)
   .Case("sve2-sha3", FPU & SveMode && 

[clang] [Clang][HIP] Deprecate the AMDGCN_WAVEFRONT_SIZE macros (PR #112849)

2024-11-08 Thread Nico Weber via cfe-commits


@@ -0,0 +1,111 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang -xhip --offload-arch=gfx1030 --offload-host-only -pedantic 
-nogpuinc -nogpulib -nobuiltininc -fsyntax-only -Xclang -verify %s
+// RUN: %clang -xhip --offload-arch=gfx1030 --offload-device-only -pedantic 
-nogpuinc -nogpulib -nobuiltininc -fsyntax-only -Xclang -verify %s
+
+// Test that deprecation warnings for the wavefront size macro are emitted 
properly.
+
+#include 

nico wrote:

1. Clang's tests must be hermetic and can't include system headers
2. This fails on Mac: http://45.33.8.238/macm1/95266/step_6.txt

Please take a look and revert for now if it takes a while to fix.

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


[clang] [clang] Permit lifetimebound in all language modes (PR #115482)

2024-11-08 Thread Haojian Wu via cfe-commits

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


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


[clang] [clang] Permit lifetimebound in all language modes (PR #115482)

2024-11-08 Thread Gábor Horváth via cfe-commits

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


[clang] [lldb] [llvm] [AArch64] Reduce +sve2-aes to an alias of +sve-aes+sve2 (PR #114293)

2024-11-08 Thread via cfe-commits

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


[clang] [clang][bytecode] Fix resource leak and use-after-free issues in CallBI function (PR #115496)

2024-11-08 Thread via cfe-commits

https://github.com/smanna12 created 
https://github.com/llvm/llvm-project/pull/115496

This commit addresses two static analyzer issues in the CallBI function:

Resource Leak: Ensures that the NewFrame object is properly managed by 
releasing ownership when InterpretBuiltin returns true, preventing a resource 
leak.

Use-After-Free: Ensures that S.Current is correctly reset to the previous frame 
(FrameBefore) after InterpretBuiltin returns true, preventing a use-after-free 
error.

The changes ensure that the NewFrame object is not prematurely deleted and that 
the interpreter state is correctly restored in case of failure.


>From 0157a7817570d5f6d5ac6f862f66cb8431d542a4 Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" 
Date: Fri, 8 Nov 2024 07:11:44 -0800
Subject: [PATCH] [clang][bytecode] Fix resource leak and use-after-free issues
 in CallBI function

---
 clang/lib/AST/ByteCode/Interp.cpp | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/clang/lib/AST/ByteCode/Interp.cpp 
b/clang/lib/AST/ByteCode/Interp.cpp
index 0e571624ae18d1..dd1236b6d6115d 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -1374,9 +1374,15 @@ bool CallBI(InterpState &S, CodePtr OpPC, const Function 
*Func,
   S.Current = NewFrame.get();
 
   if (InterpretBuiltin(S, OpPC, Func, CE, BuiltinID)) {
-NewFrame.release();
+// Release ownership of NewFrame to prevent it from being deleted.
+NewFrame.release(); // Frame was deleted already.
+// Ensure that S.Current is correctly reset to the previous frame.
+assert(S.Current == FrameBefore);
 return true;
   }
+
+  // Interpreting the function failed somehow. Reset to
+  // previous state.
   S.Current = FrameBefore;
   return false;
 }

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


[clang] [PS5][Driver] Supply libraries and CRT objects to the linker (PR #115497)

2024-11-08 Thread Edd Dawson via cfe-commits

https://github.com/playstation-edd created 
https://github.com/llvm/llvm-project/pull/115497

Until now, these have been hardcoded as a downstream patches in lld. Add them 
to the driver so that the private patches can be removed.

PS5 only. On PS4, the equivalent hardcoded configuration will remain in the 
proprietary linker.

SIE tracker: TOOLCHAIN-16704

>From 112e3e7ca9e3fd041fb0a1a0b7d97aa26740a908 Mon Sep 17 00:00:00 2001
From: Edd Dawson 
Date: Thu, 7 Nov 2024 13:57:45 +
Subject: [PATCH] [PS5][Driver] Supply libraries and CRT objects to the linker

Until now, these have been hardcoded as a downstream patches in lld. Add
them to the driver so that the private patches can be removed.

PS5 only. On PS4, the equivalent hardcoded configuration will remain in
the proprietary linker.

SIE tracker: TOOLCHAIN-16704
---
 clang/lib/Driver/ToolChains/PS4CPU.cpp | 66 +-
 clang/test/Driver/ps5-linker.c | 59 ++-
 2 files changed, 113 insertions(+), 12 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index df43da93d77555..79cb31d10cdf04 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -183,6 +183,7 @@ void tools::PS4cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
 CmdArgs.push_back(
 Args.MakeArgString(Twine("-lto-debug-options=") + LTOArgs));
 
+  // Sanitizer runtimes must be supplied before all other objects and libs.
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
 TC.addSanitizerArgs(Args, CmdArgs, "-l", "");
 
@@ -358,9 +359,6 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (StringRef Jobs = getLTOParallelism(Args, D); !Jobs.empty())
 AddLTOFlag(Twine("jobs=") + Jobs);
 
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
-TC.addSanitizerArgs(Args, CmdArgs, "-l", "");
-
   TC.AddFilePathLibArgs(Args, CmdArgs);
   Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group,
 options::OPT_s, options::OPT_t});
@@ -368,17 +366,63 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (Args.hasArg(options::OPT_Z_Xlinker__no_demangle))
 CmdArgs.push_back("--no-demangle");
 
-  AddLinkerInputs(TC, Inputs, Args, CmdArgs, JA);
+  // Sanitizer runtimes must be supplied before all other objects and libs.
+  if (!Args.hasArg(options::OPT_nodefaultlibs, options::OPT_nostdlib))
+TC.addSanitizerArgs(Args, CmdArgs, "-l", "");
 
-  if (Args.hasArg(options::OPT_pthread)) {
-CmdArgs.push_back("-lpthread");
+  const bool AddStartFiles =
+  !Relocatable &&
+  !Args.hasArg(options::OPT_nostartfiles, options::OPT_nostdlib);
+
+  auto AddCRTObject = [&](const char *Name) {
+CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath(Name)));
+  };
+
+  if (AddStartFiles) {
+if (!Shared)
+  AddCRTObject("crt1.o");
+AddCRTObject("crti.o");
+AddCRTObject(Shared   ? "crtbeginS.o"
+ : Static ? "crtbeginT.o"
+  : "crtbegin.o");
   }
 
-  if (UseJMC) {
-CmdArgs.push_back("--push-state");
-CmdArgs.push_back("--whole-archive");
-CmdArgs.push_back("-lSceJmc_nosubmission");
-CmdArgs.push_back("--pop-state");
+  AddLinkerInputs(TC, Inputs, Args, CmdArgs, JA);
+
+  if (!Relocatable &&
+  !Args.hasArg(options::OPT_nodefaultlibs, options::OPT_nostdlib)) {
+
+if (UseJMC) {
+  CmdArgs.push_back("--push-state");
+  CmdArgs.push_back("--whole-archive");
+  CmdArgs.push_back("-lSceJmc_nosubmission");
+  CmdArgs.push_back("--pop-state");
+}
+
+if (Args.hasArg(options::OPT_pthread))
+  CmdArgs.push_back("-lpthread");
+
+if (Static) {
+  if (!Args.hasArg(options::OPT_nostdlibxx))
+CmdArgs.push_back("-lstdc++");
+  if (!Args.hasArg(options::OPT_nolibc)) {
+CmdArgs.push_back("-lm");
+CmdArgs.push_back("-lc");
+  }
+
+  CmdArgs.push_back("-lcompiler_rt");
+  CmdArgs.push_back("-lkernel");
+} else {
+  // The C and C++ libraries are combined.
+  if (!Args.hasArg(options::OPT_nolibc, options::OPT_nostdlibxx))
+CmdArgs.push_back("-lc_stub_weak");
+
+  CmdArgs.push_back("-lkernel_stub_weak");
+}
+  }
+  if (AddStartFiles) {
+AddCRTObject(Shared ? "crtendS.o" : "crtend.o");
+AddCRTObject("crtn.o");
   }
 
   if (Args.hasArg(options::OPT_fuse_ld_EQ)) {
diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index 95267942edc172..7a4b2afdf04e9c 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -97,6 +97,60 @@
 // Check the default library name.
 // CHECK-JMC: "--push-state" "--whole-archive" "-lSceJmc_nosubmission" 
"--pop-state"
 
+// Test that CRT objects and libraries are supplied to the linker and can be
+// omitted with -noxxx options. These switches hav

[clang] [PS5][Driver] Supply libraries and CRT objects to the linker (PR #115497)

2024-11-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Edd Dawson (playstation-edd)


Changes

Until now, these have been hardcoded as a downstream patches in lld. Add them 
to the driver so that the private patches can be removed.

PS5 only. On PS4, the equivalent hardcoded configuration will remain in the 
proprietary linker.

SIE tracker: TOOLCHAIN-16704

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


2 Files Affected:

- (modified) clang/lib/Driver/ToolChains/PS4CPU.cpp (+55-11) 
- (modified) clang/test/Driver/ps5-linker.c (+58-1) 


``diff
diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index df43da93d77555..79cb31d10cdf04 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -183,6 +183,7 @@ void tools::PS4cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
 CmdArgs.push_back(
 Args.MakeArgString(Twine("-lto-debug-options=") + LTOArgs));
 
+  // Sanitizer runtimes must be supplied before all other objects and libs.
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
 TC.addSanitizerArgs(Args, CmdArgs, "-l", "");
 
@@ -358,9 +359,6 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (StringRef Jobs = getLTOParallelism(Args, D); !Jobs.empty())
 AddLTOFlag(Twine("jobs=") + Jobs);
 
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
-TC.addSanitizerArgs(Args, CmdArgs, "-l", "");
-
   TC.AddFilePathLibArgs(Args, CmdArgs);
   Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group,
 options::OPT_s, options::OPT_t});
@@ -368,17 +366,63 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (Args.hasArg(options::OPT_Z_Xlinker__no_demangle))
 CmdArgs.push_back("--no-demangle");
 
-  AddLinkerInputs(TC, Inputs, Args, CmdArgs, JA);
+  // Sanitizer runtimes must be supplied before all other objects and libs.
+  if (!Args.hasArg(options::OPT_nodefaultlibs, options::OPT_nostdlib))
+TC.addSanitizerArgs(Args, CmdArgs, "-l", "");
 
-  if (Args.hasArg(options::OPT_pthread)) {
-CmdArgs.push_back("-lpthread");
+  const bool AddStartFiles =
+  !Relocatable &&
+  !Args.hasArg(options::OPT_nostartfiles, options::OPT_nostdlib);
+
+  auto AddCRTObject = [&](const char *Name) {
+CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath(Name)));
+  };
+
+  if (AddStartFiles) {
+if (!Shared)
+  AddCRTObject("crt1.o");
+AddCRTObject("crti.o");
+AddCRTObject(Shared   ? "crtbeginS.o"
+ : Static ? "crtbeginT.o"
+  : "crtbegin.o");
   }
 
-  if (UseJMC) {
-CmdArgs.push_back("--push-state");
-CmdArgs.push_back("--whole-archive");
-CmdArgs.push_back("-lSceJmc_nosubmission");
-CmdArgs.push_back("--pop-state");
+  AddLinkerInputs(TC, Inputs, Args, CmdArgs, JA);
+
+  if (!Relocatable &&
+  !Args.hasArg(options::OPT_nodefaultlibs, options::OPT_nostdlib)) {
+
+if (UseJMC) {
+  CmdArgs.push_back("--push-state");
+  CmdArgs.push_back("--whole-archive");
+  CmdArgs.push_back("-lSceJmc_nosubmission");
+  CmdArgs.push_back("--pop-state");
+}
+
+if (Args.hasArg(options::OPT_pthread))
+  CmdArgs.push_back("-lpthread");
+
+if (Static) {
+  if (!Args.hasArg(options::OPT_nostdlibxx))
+CmdArgs.push_back("-lstdc++");
+  if (!Args.hasArg(options::OPT_nolibc)) {
+CmdArgs.push_back("-lm");
+CmdArgs.push_back("-lc");
+  }
+
+  CmdArgs.push_back("-lcompiler_rt");
+  CmdArgs.push_back("-lkernel");
+} else {
+  // The C and C++ libraries are combined.
+  if (!Args.hasArg(options::OPT_nolibc, options::OPT_nostdlibxx))
+CmdArgs.push_back("-lc_stub_weak");
+
+  CmdArgs.push_back("-lkernel_stub_weak");
+}
+  }
+  if (AddStartFiles) {
+AddCRTObject(Shared ? "crtendS.o" : "crtend.o");
+AddCRTObject("crtn.o");
   }
 
   if (Args.hasArg(options::OPT_fuse_ld_EQ)) {
diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index 95267942edc172..7a4b2afdf04e9c 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -97,6 +97,60 @@
 // Check the default library name.
 // CHECK-JMC: "--push-state" "--whole-archive" "-lSceJmc_nosubmission" 
"--pop-state"
 
+// Test that CRT objects and libraries are supplied to the linker and can be
+// omitted with -noxxx options. These switches have some interaction with
+// sanitizer RT libraries. That's checked in fsanitize.c
+
+// RUN: %clang --target=x86_64-sie-ps5 %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-LD,CHECK-MAIN-CRT,CHECK-DYNAMIC-LIBC,CHECK-DYNAMIC-CORE-LIBS
 %s
+// RUN: %clang --target=x86_64-sie-ps5 %s -shared -### 2>&1 | FileCheck 
--check-prefixes=CHECK-LD,CHECK-SHARED-CRT,CHECK-DYNAMIC-LIBC,CHECK-DYNAMIC-CORE-LIBS
 %s
+// RUN: %clang --target=x86_64-sie-ps5 %s 

[clang] [PS5][Driver] Supply libraries and CRT objects to the linker (PR #115497)

2024-11-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Edd Dawson (playstation-edd)


Changes

Until now, these have been hardcoded as a downstream patches in lld. Add them 
to the driver so that the private patches can be removed.

PS5 only. On PS4, the equivalent hardcoded configuration will remain in the 
proprietary linker.

SIE tracker: TOOLCHAIN-16704

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


2 Files Affected:

- (modified) clang/lib/Driver/ToolChains/PS4CPU.cpp (+55-11) 
- (modified) clang/test/Driver/ps5-linker.c (+58-1) 


``diff
diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index df43da93d77555..79cb31d10cdf04 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -183,6 +183,7 @@ void tools::PS4cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
 CmdArgs.push_back(
 Args.MakeArgString(Twine("-lto-debug-options=") + LTOArgs));
 
+  // Sanitizer runtimes must be supplied before all other objects and libs.
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
 TC.addSanitizerArgs(Args, CmdArgs, "-l", "");
 
@@ -358,9 +359,6 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (StringRef Jobs = getLTOParallelism(Args, D); !Jobs.empty())
 AddLTOFlag(Twine("jobs=") + Jobs);
 
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
-TC.addSanitizerArgs(Args, CmdArgs, "-l", "");
-
   TC.AddFilePathLibArgs(Args, CmdArgs);
   Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group,
 options::OPT_s, options::OPT_t});
@@ -368,17 +366,63 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   if (Args.hasArg(options::OPT_Z_Xlinker__no_demangle))
 CmdArgs.push_back("--no-demangle");
 
-  AddLinkerInputs(TC, Inputs, Args, CmdArgs, JA);
+  // Sanitizer runtimes must be supplied before all other objects and libs.
+  if (!Args.hasArg(options::OPT_nodefaultlibs, options::OPT_nostdlib))
+TC.addSanitizerArgs(Args, CmdArgs, "-l", "");
 
-  if (Args.hasArg(options::OPT_pthread)) {
-CmdArgs.push_back("-lpthread");
+  const bool AddStartFiles =
+  !Relocatable &&
+  !Args.hasArg(options::OPT_nostartfiles, options::OPT_nostdlib);
+
+  auto AddCRTObject = [&](const char *Name) {
+CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath(Name)));
+  };
+
+  if (AddStartFiles) {
+if (!Shared)
+  AddCRTObject("crt1.o");
+AddCRTObject("crti.o");
+AddCRTObject(Shared   ? "crtbeginS.o"
+ : Static ? "crtbeginT.o"
+  : "crtbegin.o");
   }
 
-  if (UseJMC) {
-CmdArgs.push_back("--push-state");
-CmdArgs.push_back("--whole-archive");
-CmdArgs.push_back("-lSceJmc_nosubmission");
-CmdArgs.push_back("--pop-state");
+  AddLinkerInputs(TC, Inputs, Args, CmdArgs, JA);
+
+  if (!Relocatable &&
+  !Args.hasArg(options::OPT_nodefaultlibs, options::OPT_nostdlib)) {
+
+if (UseJMC) {
+  CmdArgs.push_back("--push-state");
+  CmdArgs.push_back("--whole-archive");
+  CmdArgs.push_back("-lSceJmc_nosubmission");
+  CmdArgs.push_back("--pop-state");
+}
+
+if (Args.hasArg(options::OPT_pthread))
+  CmdArgs.push_back("-lpthread");
+
+if (Static) {
+  if (!Args.hasArg(options::OPT_nostdlibxx))
+CmdArgs.push_back("-lstdc++");
+  if (!Args.hasArg(options::OPT_nolibc)) {
+CmdArgs.push_back("-lm");
+CmdArgs.push_back("-lc");
+  }
+
+  CmdArgs.push_back("-lcompiler_rt");
+  CmdArgs.push_back("-lkernel");
+} else {
+  // The C and C++ libraries are combined.
+  if (!Args.hasArg(options::OPT_nolibc, options::OPT_nostdlibxx))
+CmdArgs.push_back("-lc_stub_weak");
+
+  CmdArgs.push_back("-lkernel_stub_weak");
+}
+  }
+  if (AddStartFiles) {
+AddCRTObject(Shared ? "crtendS.o" : "crtend.o");
+AddCRTObject("crtn.o");
   }
 
   if (Args.hasArg(options::OPT_fuse_ld_EQ)) {
diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index 95267942edc172..7a4b2afdf04e9c 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -97,6 +97,60 @@
 // Check the default library name.
 // CHECK-JMC: "--push-state" "--whole-archive" "-lSceJmc_nosubmission" 
"--pop-state"
 
+// Test that CRT objects and libraries are supplied to the linker and can be
+// omitted with -noxxx options. These switches have some interaction with
+// sanitizer RT libraries. That's checked in fsanitize.c
+
+// RUN: %clang --target=x86_64-sie-ps5 %s -### 2>&1 | FileCheck 
--check-prefixes=CHECK-LD,CHECK-MAIN-CRT,CHECK-DYNAMIC-LIBC,CHECK-DYNAMIC-CORE-LIBS
 %s
+// RUN: %clang --target=x86_64-sie-ps5 %s -shared -### 2>&1 | FileCheck 
--check-prefixes=CHECK-LD,CHECK-SHARED-CRT,CHECK-DYNAMIC-LIBC,CHECK-DYNAMIC-CORE-LIBS
 %s
+// RUN: %clang --target=x86_64-sie-

[clang] [clang-tools-extra] [analyzer] Remove alpha.core.IdenticalExpr Checker (PR #114715)

2024-11-08 Thread via cfe-commits


@@ -1238,6 +1235,59 @@ void RedundantExpressionCheck::check(const 
MatchFinder::MatchResult &Result) {
   if (const auto *BinOp = Result.Nodes.getNodeAs("binary")) {
 // If the expression's constants are macros, check whether they are
 // intentional.
+
+//
+// Special case for floating-point representation.
+//
+// If expressions on both sides of comparison operator are of type float,
+// then for some comparison operators no warning shall be
+// reported even if the expressions are identical from a symbolic point of
+// view. Comparison between expressions, declared variables and literals
+// are treated differently.
+//
+// != and == between float literals that have the same value should NOT
+// warn. < > between float literals that have the same value SHOULD warn.
+//
+// != and == between the same float declaration should NOT warn.
+// < > between the same float declaration SHOULD warn.
+//
+// != and == between eq. expressions that evaluates into float
+//   should NOT warn.
+// < >   between eq. expressions that evaluates into float
+//   should NOT warn.
+//
+const Expr *LHS = BinOp->getLHS()->IgnoreParenImpCasts();
+const Expr *RHS = BinOp->getRHS()->IgnoreParenImpCasts();
+BinaryOperator::Opcode Op = BinOp->getOpcode();
+
+const DeclRefExpr *DeclRef1 = dyn_cast(LHS);

EugeneZelenko wrote:

```suggestion
const auto *DeclRef1 = dyn_cast(LHS);
```

Same below.

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


[clang] [clang-tools-extra] [analyzer] Remove alpha.core.IdenticalExpr Checker (PR #114715)

2024-11-08 Thread via cfe-commits


@@ -102,6 +102,209 @@ void BranchCloneCheck::registerMatchers(MatchFinder 
*Finder) {
   this);
   Finder->addMatcher(switchStmt().bind("switch"), this);
   Finder->addMatcher(conditionalOperator().bind("condOp"), this);
+  
Finder->addMatcher(ifStmt(hasDescendant(ifStmt())).bind("ifWithDescendantIf"),
+ this);
+}
+
+/// Determines whether two statement trees are identical regarding
+/// operators and symbols.
+///
+/// Exceptions: expressions containing macros or functions with possible side
+/// effects are never considered identical.
+/// Limitations: (t + u) and (u + t) are not considered identical.
+/// t*(u + t) and t*u + t*t are not considered identical.
+///
+static bool isIdenticalStmt(const ASTContext &Ctx, const Stmt *Stmt1,
+const Stmt *Stmt2, bool IgnoreSideEffects) {
+
+  if (!Stmt1 || !Stmt2) {
+return !Stmt1 && !Stmt2;
+  }
+
+  // If Stmt1 & Stmt2 are of different class then they are not
+  // identical statements.
+  if (Stmt1->getStmtClass() != Stmt2->getStmtClass())
+return false;
+
+  const Expr *Expr1 = dyn_cast(Stmt1);
+  const Expr *Expr2 = dyn_cast(Stmt2);
+
+  if (Expr1 && Expr2) {
+// If Stmt1 has side effects then don't warn even if expressions
+// are identical.
+if (!IgnoreSideEffects && Expr1->HasSideEffects(Ctx))
+  return false;
+// If either expression comes from a macro then don't warn even if
+// the expressions are identical.
+if ((Expr1->getExprLoc().isMacroID()) || (Expr2->getExprLoc().isMacroID()))
+  return false;
+
+// If all children of two expressions are identical, return true.
+Expr::const_child_iterator I1 = Expr1->child_begin();
+Expr::const_child_iterator I2 = Expr2->child_begin();
+while (I1 != Expr1->child_end() && I2 != Expr2->child_end()) {
+  if (!*I1 || !*I2 || !isIdenticalStmt(Ctx, *I1, *I2, IgnoreSideEffects))
+return false;
+  ++I1;
+  ++I2;
+}
+// If there are different number of children in the statements, return
+// false.
+if (I1 != Expr1->child_end())
+  return false;
+if (I2 != Expr2->child_end())
+  return false;
+  }
+
+  switch (Stmt1->getStmtClass()) {
+  default:
+return false;
+  case Stmt::CallExprClass:
+  case Stmt::ArraySubscriptExprClass:
+  case Stmt::ArraySectionExprClass:
+  case Stmt::OMPArrayShapingExprClass:
+  case Stmt::OMPIteratorExprClass:
+  case Stmt::ImplicitCastExprClass:
+  case Stmt::ParenExprClass:
+  case Stmt::BreakStmtClass:
+  case Stmt::ContinueStmtClass:
+  case Stmt::NullStmtClass:
+return true;
+  case Stmt::CStyleCastExprClass: {
+const CStyleCastExpr *CastExpr1 = cast(Stmt1);
+const CStyleCastExpr *CastExpr2 = cast(Stmt2);
+
+return CastExpr1->getTypeAsWritten() == CastExpr2->getTypeAsWritten();
+  }
+  case Stmt::ReturnStmtClass: {
+const ReturnStmt *ReturnStmt1 = cast(Stmt1);

EugeneZelenko wrote:

```suggestion
const auto *ReturnStmt1 = cast(Stmt1);
```

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


[clang] [clang-tools-extra] [analyzer] Remove alpha.core.IdenticalExpr Checker (PR #114715)

2024-11-08 Thread via cfe-commits


@@ -102,6 +102,209 @@ void BranchCloneCheck::registerMatchers(MatchFinder 
*Finder) {
   this);
   Finder->addMatcher(switchStmt().bind("switch"), this);
   Finder->addMatcher(conditionalOperator().bind("condOp"), this);
+  
Finder->addMatcher(ifStmt(hasDescendant(ifStmt())).bind("ifWithDescendantIf"),
+ this);
+}
+
+/// Determines whether two statement trees are identical regarding
+/// operators and symbols.
+///
+/// Exceptions: expressions containing macros or functions with possible side
+/// effects are never considered identical.
+/// Limitations: (t + u) and (u + t) are not considered identical.
+/// t*(u + t) and t*u + t*t are not considered identical.
+///
+static bool isIdenticalStmt(const ASTContext &Ctx, const Stmt *Stmt1,
+const Stmt *Stmt2, bool IgnoreSideEffects) {
+
+  if (!Stmt1 || !Stmt2) {
+return !Stmt1 && !Stmt2;
+  }
+
+  // If Stmt1 & Stmt2 are of different class then they are not
+  // identical statements.
+  if (Stmt1->getStmtClass() != Stmt2->getStmtClass())
+return false;
+
+  const Expr *Expr1 = dyn_cast(Stmt1);
+  const Expr *Expr2 = dyn_cast(Stmt2);

EugeneZelenko wrote:

```suggestion
  const auto *Expr2 = dyn_cast(Stmt2);
```

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


[clang] [clang-tools-extra] [analyzer] Remove alpha.core.IdenticalExpr Checker (PR #114715)

2024-11-08 Thread via cfe-commits


@@ -102,6 +102,209 @@ void BranchCloneCheck::registerMatchers(MatchFinder 
*Finder) {
   this);
   Finder->addMatcher(switchStmt().bind("switch"), this);
   Finder->addMatcher(conditionalOperator().bind("condOp"), this);
+  
Finder->addMatcher(ifStmt(hasDescendant(ifStmt())).bind("ifWithDescendantIf"),
+ this);
+}
+
+/// Determines whether two statement trees are identical regarding
+/// operators and symbols.
+///
+/// Exceptions: expressions containing macros or functions with possible side
+/// effects are never considered identical.
+/// Limitations: (t + u) and (u + t) are not considered identical.
+/// t*(u + t) and t*u + t*t are not considered identical.
+///
+static bool isIdenticalStmt(const ASTContext &Ctx, const Stmt *Stmt1,
+const Stmt *Stmt2, bool IgnoreSideEffects) {
+
+  if (!Stmt1 || !Stmt2) {
+return !Stmt1 && !Stmt2;
+  }
+
+  // If Stmt1 & Stmt2 are of different class then they are not
+  // identical statements.
+  if (Stmt1->getStmtClass() != Stmt2->getStmtClass())
+return false;
+
+  const Expr *Expr1 = dyn_cast(Stmt1);
+  const Expr *Expr2 = dyn_cast(Stmt2);
+
+  if (Expr1 && Expr2) {
+// If Stmt1 has side effects then don't warn even if expressions
+// are identical.
+if (!IgnoreSideEffects && Expr1->HasSideEffects(Ctx))
+  return false;
+// If either expression comes from a macro then don't warn even if
+// the expressions are identical.
+if ((Expr1->getExprLoc().isMacroID()) || (Expr2->getExprLoc().isMacroID()))
+  return false;
+
+// If all children of two expressions are identical, return true.
+Expr::const_child_iterator I1 = Expr1->child_begin();
+Expr::const_child_iterator I2 = Expr2->child_begin();
+while (I1 != Expr1->child_end() && I2 != Expr2->child_end()) {
+  if (!*I1 || !*I2 || !isIdenticalStmt(Ctx, *I1, *I2, IgnoreSideEffects))
+return false;
+  ++I1;
+  ++I2;
+}
+// If there are different number of children in the statements, return
+// false.
+if (I1 != Expr1->child_end())
+  return false;
+if (I2 != Expr2->child_end())
+  return false;
+  }
+
+  switch (Stmt1->getStmtClass()) {
+  default:
+return false;
+  case Stmt::CallExprClass:
+  case Stmt::ArraySubscriptExprClass:
+  case Stmt::ArraySectionExprClass:
+  case Stmt::OMPArrayShapingExprClass:
+  case Stmt::OMPIteratorExprClass:
+  case Stmt::ImplicitCastExprClass:
+  case Stmt::ParenExprClass:
+  case Stmt::BreakStmtClass:
+  case Stmt::ContinueStmtClass:
+  case Stmt::NullStmtClass:
+return true;
+  case Stmt::CStyleCastExprClass: {
+const CStyleCastExpr *CastExpr1 = cast(Stmt1);
+const CStyleCastExpr *CastExpr2 = cast(Stmt2);
+
+return CastExpr1->getTypeAsWritten() == CastExpr2->getTypeAsWritten();
+  }
+  case Stmt::ReturnStmtClass: {
+const ReturnStmt *ReturnStmt1 = cast(Stmt1);
+const ReturnStmt *ReturnStmt2 = cast(Stmt2);

EugeneZelenko wrote:

```suggestion
const auto *ReturnStmt2 = cast(Stmt2);
```

Same for other similar statements.

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


[clang] [clang-tools-extra] [analyzer] Remove alpha.core.IdenticalExpr Checker (PR #114715)

2024-11-08 Thread via cfe-commits


@@ -102,6 +102,209 @@ void BranchCloneCheck::registerMatchers(MatchFinder 
*Finder) {
   this);
   Finder->addMatcher(switchStmt().bind("switch"), this);
   Finder->addMatcher(conditionalOperator().bind("condOp"), this);
+  
Finder->addMatcher(ifStmt(hasDescendant(ifStmt())).bind("ifWithDescendantIf"),
+ this);
+}
+
+/// Determines whether two statement trees are identical regarding
+/// operators and symbols.
+///
+/// Exceptions: expressions containing macros or functions with possible side
+/// effects are never considered identical.
+/// Limitations: (t + u) and (u + t) are not considered identical.
+/// t*(u + t) and t*u + t*t are not considered identical.
+///
+static bool isIdenticalStmt(const ASTContext &Ctx, const Stmt *Stmt1,
+const Stmt *Stmt2, bool IgnoreSideEffects) {
+
+  if (!Stmt1 || !Stmt2) {
+return !Stmt1 && !Stmt2;
+  }
+
+  // If Stmt1 & Stmt2 are of different class then they are not
+  // identical statements.
+  if (Stmt1->getStmtClass() != Stmt2->getStmtClass())
+return false;
+
+  const Expr *Expr1 = dyn_cast(Stmt1);

EugeneZelenko wrote:

```suggestion
  const auto *Expr1 = dyn_cast(Stmt1);
```

Type is explicitly stated in same statement.

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


[clang] 4027400 - [C2y] Add test coverage and documentation for WG14 N3342 (#115494)

2024-11-08 Thread via cfe-commits

Author: Aaron Ballman
Date: 2024-11-08T11:25:39-05:00
New Revision: 4027400d2ceefb5ce68d4508e5f30dc40c4f535b

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

LOG: [C2y] Add test coverage and documentation for WG14 N3342 (#115494)

This paper made qualified function types implementation-defined. We have
always supported this as an extension, so now we're documenting our
behavior.

Note, we still warn about this by default even in C2y mode because a
qualified function type is a sign of programmer confusion.

Added: 
clang/test/C/C2y/n3342.c

Modified: 
clang/docs/LanguageExtensions.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaType.cpp
clang/test/Misc/warning-flags.c
clang/test/Sema/declspec.c
clang/www/c_status.html

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index f7285352b9deb9..a051eb95898ecf 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -5974,3 +5974,20 @@ Clang guarantees the following behaviors:
   padding bits are initialized to zero.
 
 Currently, the above extension only applies to C source code, not C++.
+
+Qualified function types in C
+=
+Declaring a function with a qualified type in C is undefined behavior (C23 and
+earlier) or implementation-defined behavior (C2y). Clang allows a function type
+to be specified with the ``const`` and ``volatile`` qualifiers, but ignores the
+qualifications.
+
+.. code-block:: c
+
+   typedef int f(void);
+   const volatile f func; // Qualifier on function type has no effect.
+
+
+Note, Clang does not allow an ``_Atomic`` function type because
+of explicit constraints against atomically qualified (arrays and) function
+types.

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d0c43ff11f7bae..d4bf05651a63eb 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -298,6 +298,11 @@ C2y Feature Support
   paper adopts Clang's existing practice, so there were no changes to compiler
   behavior.
 
+- Updated conformance for `N3342 
`_
+  which made qualified function types implementation-defined rather than
+  undefined. Clang has always accepted ``const`` and ``volatile`` qualified
+  function types by ignoring the qualifiers.
+
 C23 Feature Support
 ^^^
 

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 2a6ccac345af0f..a5d97d7e545ffd 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6241,8 +6241,9 @@ def err_typecheck_negative_array_size : Error<"array size 
is negative">;
 def warn_typecheck_function_qualifiers_ignored : Warning<
   "'%0' qualifier on function type %1 has no effect">,
   InGroup;
-def warn_typecheck_function_qualifiers_unspecified : Warning<
-  "'%0' qualifier on function type %1 has unspecified behavior">;
+def ext_typecheck_function_qualifiers_unspecified : ExtWarn<
+  "'%0' qualifier on function type %1 has no effect and is a Clang extension">,
+  InGroup;
 def warn_typecheck_reference_qualifiers : Warning<
   "'%0' qualifier on reference type %1 has no effect">,
   InGroup;

diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index e526a11973975d..515b9f689a248a 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -1500,16 +1500,19 @@ static QualType 
ConvertDeclSpecToType(TypeProcessingState &state) {
 // C99 6.7.3p8:
 //   If the specification of a function type includes any type qualifiers,
 //   the behavior is undefined.
+// C2y changed this behavior to be implementation-defined. Clang defines
+// the behavior in all cases to ignore the qualifier, as in C++.
 // C++11 [dcl.fct]p7:
 //   The effect of a cv-qualifier-seq in a function declarator is not the
 //   same as adding cv-qualification on top of the function type. In the
 //   latter case, the cv-qualifiers are ignored.
 if (Result->isFunctionType()) {
+  unsigned DiagId = diag::warn_typecheck_function_qualifiers_ignored;
+  if (!S.getLangOpts().CPlusPlus && !S.getLangOpts().C2y)
+DiagId = diag::ext_typecheck_function_qualifiers_unspecified;
   diagnoseAndRemoveTypeQualifiers(
   S, DS, TypeQuals, Result, DeclSpec::TQ_const | DeclSpec::TQ_volatile,
-  S.getLangOpts().CPlusPlus
-  ? diag::warn_typecheck_function_qualifiers_ignored
-  : diag::warn_typecheck_function_qualifiers_unspecified);
+  DiagId);
   // No diagnostic for 'restrict

[clang] [C2y] Add test coverage and documentation for WG14 N3342 (PR #115494)

2024-11-08 Thread Aaron Ballman via cfe-commits

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


[clang] Fix for OpenMP offloading compilation error with GNU++20 option when using complex header (PR #115306)

2024-11-08 Thread Shilei Tian via cfe-commits


@@ -64,8 +64,13 @@ template  __DEVICE__ _Tp norm(const 
std::complex<_Tp> &__c) {
 }
 
 // conj
-
-template  std::complex<_Tp> conj(const std::complex<_Tp> &__c) {
+#ifdef _GLIBCXX20_CONSTEXPR
+#define CXX20_CONSTEXPR_DEVICE __DEVICE__

shiltian wrote:

I wonder why this is not `constexpr` in C++20 but `__DEVICE__` instead?

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


[clang] Fix for codegen Crash in Clang when using locator omp_all_memory with depobj construct (PR #114221)

2024-11-08 Thread Shilei Tian via cfe-commits

https://github.com/shiltian commented:

LGTM. @alexey-bataev What do you think?

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


[clang] [llvm] [Clang][Darwin] Introduce `SubFrameworks` as a SDK default location (PR #115048)

2024-11-08 Thread Juergen Ributzka via cfe-commits


@@ -255,16 +255,21 @@ static void stubifyDirectory(const StringRef InputPath, 
Context &Ctx) {
 if (EC)
   reportError(IT->path() + ": " + EC.message());
 
-// Skip header directories (include/Headers/PrivateHeaders) and module

ributzka wrote:

How is this changing readtapi's behavior?

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


[clang] [Clang] Add support for scoped atomic thread fence (PR #115545)

2024-11-08 Thread Joseph Huber via cfe-commits

https://github.com/jhuber6 updated 
https://github.com/llvm/llvm-project/pull/115545

>From d8105f5626318868ada0deba0b5755999a47abb2 Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Fri, 8 Nov 2024 15:42:04 -0600
Subject: [PATCH 1/2] [Clang] Add support for scoped atomic thread fence

Summary:
Previously we added support for all of the atomic GNU extensions with
optional memory scoped except for `__atomic_thread_fence`. This patch
adds support for that. This should ideally allow us to generically emit
these LLVM scopes.
---
 clang/include/clang/Basic/Builtins.td |   6 +
 clang/lib/CodeGen/CGBuiltin.cpp   | 129 +++
 clang/test/CodeGen/scoped-fence-ops.c | 179 ++
 3 files changed, 314 insertions(+)
 create mode 100644 clang/test/CodeGen/scoped-fence-ops.c

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 87a798183d6e19..4c2f9f621915b1 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -1995,6 +1995,12 @@ def AtomicThreadFence : Builtin {
   let Prototype = "void(int)";
 }
 
+def ScopedAtomicThreadFence : Builtin {
+  let Spellings = ["__scoped_atomic_thread_fence"];
+  let Attributes = [NoThrow];
+  let Prototype = "void(int, int)";
+}
+
 def AtomicSignalFence : Builtin {
   let Spellings = ["__atomic_signal_fence"];
   let Attributes = [NoThrow];
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 5c3df5124517d6..4d22390c2150ca 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -5133,6 +5133,135 @@ RValue CodeGenFunction::EmitBuiltinExpr(const 
GlobalDecl GD, unsigned BuiltinID,
 Builder.SetInsertPoint(ContBB);
 return RValue::get(nullptr);
   }
+  case Builtin::BI__scoped_atomic_thread_fence: {
+auto ScopeModel = AtomicScopeModel::create(AtomicScopeModelKind::Generic);
+
+Value *Order = EmitScalarExpr(E->getArg(0));
+Value *Scope = EmitScalarExpr(E->getArg(1));
+if (isa(Order) && isa(Scope)) {
+  int Ord = cast(Order)->getZExtValue();
+  int Scp = cast(Scope)->getZExtValue();
+  SyncScope SS = ScopeModel->isValid(Scp)
+ ? ScopeModel->map(Scp)
+ : ScopeModel->map(ScopeModel->getFallBackValue());
+  switch (Ord) {
+  case 0:  // memory_order_relaxed
+  default: // invalid order
+break;
+  case 1: // memory_order_consume
+  case 2: // memory_order_acquire
+Builder.CreateFence(
+llvm::AtomicOrdering::Acquire,
+getTargetHooks().getLLVMSyncScopeID(getLangOpts(), SS,
+llvm::AtomicOrdering::Acquire,
+getLLVMContext()));
+break;
+  case 3: // memory_order_release
+Builder.CreateFence(
+llvm::AtomicOrdering::Release,
+getTargetHooks().getLLVMSyncScopeID(getLangOpts(), SS,
+llvm::AtomicOrdering::Release,
+getLLVMContext()));
+break;
+  case 4: // memory_order_acq_rel
+Builder.CreateFence(llvm::AtomicOrdering::AcquireRelease,
+getTargetHooks().getLLVMSyncScopeID(
+getLangOpts(), SS,
+llvm::AtomicOrdering::AcquireRelease,
+getLLVMContext()));
+break;
+  case 5: // memory_order_seq_cst
+Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent,
+getTargetHooks().getLLVMSyncScopeID(
+getLangOpts(), SS,
+llvm::AtomicOrdering::SequentiallyConsistent,
+getLLVMContext()));
+break;
+  }
+  return RValue::get(nullptr);
+}
+
+llvm::BasicBlock *ContBB = createBasicBlock("atomic.scope.continue", 
CurFn);
+
+llvm::DenseMap OrderBBs;
+if (isa(Order)) {
+  int Ord = cast(Order)->getZExtValue();
+  switch (Ord) {
+  case 0:  // memory_order_relaxed
+  default: // invalid order
+ContBB->eraseFromParent();
+return RValue::get(nullptr);
+  case 1: // memory_order_consume
+  case 2: // memory_order_acquire
+OrderBBs[Builder.GetInsertBlock()] = llvm::AtomicOrdering::Acquire;
+break;
+  case 3: // memory_order_release
+OrderBBs[Builder.GetInsertBlock()] = llvm::AtomicOrdering::Release;
+break;
+  case 4: // memory_order_acq_rel
+OrderBBs[Builder.GetInsertBlock()] =
+llvm::AtomicOrdering::AcquireRelease;
+break;
+  case 5: // memory_order_seq_cst
+OrderBBs[Builder.GetInsertBlock()] =
+llvm::AtomicOrdering::SequentiallyConsistent;
+break;
+  }
+} else {
+  llvm::BasicBlock *AcquireBB, *Releas

[clang] [Wunsafe-buffer-usage] Fix false positives in handling string literals. (PR #115552)

2024-11-08 Thread Malavika Samak via cfe-commits

https://github.com/malavikasamak created 
https://github.com/llvm/llvm-project/pull/115552

Do not warn when a string literal is indexed and the idex value is within the 
bounds of the length of the string.

(rdar://139106996)

>From 3be112ec1f0b2e6e2948db082a7141d91b873a17 Mon Sep 17 00:00:00 2001
From: MalavikaSamak 
Date: Fri, 8 Nov 2024 13:40:20 -0800
Subject: [PATCH] [Wunsafe-buffer-usage] Fix false positives in handling string
 literals.

Do not warn when a string literal is indexed and the idex value is within
the bounds of the length of the string.

(rdar://139106996)
---
 clang/lib/Analysis/UnsafeBufferUsage.cpp  | 28 +--
 .../warn-unsafe-buffer-usage-array.cpp|  7 +
 2 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 2c68409b846bc8..650d51bebd66f7 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -436,21 +436,31 @@ AST_MATCHER(ArraySubscriptExpr, isSafeArraySubscript) {
 
   const auto *BaseDRE =
   dyn_cast(Node.getBase()->IgnoreParenImpCasts());
-  if (!BaseDRE)
-return false;
-  if (!BaseDRE->getDecl())
-return false;
-  const auto *CATy = Finder->getASTContext().getAsConstantArrayType(
-  BaseDRE->getDecl()->getType());
-  if (!CATy)
+  const auto *SLiteral = 
dyn_cast(Node.getBase()->IgnoreParenImpCasts());
+  uint64_t size;
+
+  if (!BaseDRE && !SLiteral)
 return false;
 
+  if(BaseDRE) {
+if (!BaseDRE->getDecl())
+  return false;
+const auto *CATy = Finder->getASTContext().getAsConstantArrayType(
+BaseDRE->getDecl()->getType());
+if (!CATy) {
+  return false;
+}
+size = CATy->getLimitedSize();
+  } else if(SLiteral) {
+size = SLiteral->getLength();
+  }
+
   if (const auto *IdxLit = dyn_cast(Node.getIdx())) {
 const APInt ArrIdx = IdxLit->getValue();
 // FIXME: ArrIdx.isNegative() we could immediately emit an error as that's 
a
 // bug
 if (ArrIdx.isNonNegative() &&
-ArrIdx.getLimitedValue() < CATy->getLimitedSize())
+ArrIdx.getLimitedValue() < size)
   return true;
   }
 
@@ -1142,7 +1152,7 @@ class ArraySubscriptGadget : public WarningGadget {
 // clang-format off
   return stmt(arraySubscriptExpr(
 hasBase(ignoringParenImpCasts(
-  anyOf(hasPointerType(), hasArrayType(,
+  anyOf(hasPointerType(), hasArrayType(), stringLiteral(,
 unless(anyOf(
   isSafeArraySubscript(),
   hasIndex(
diff --git a/clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp
index 8b2f103ec66708..0a443543d3f604 100644
--- a/clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp
+++ b/clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp
@@ -38,3 +38,10 @@ void constant_idx_unsafe(unsigned idx) {
 // expected-note@-1{{change type of 'buffer' to 
'std::array' to label it for hardening}}
   buffer[10] = 0;   // expected-note{{used in buffer access here}}
 }
+
+void constant_id_string() {
+  char safe_char = "abc"[1]; // no-warning
+  char abcd[5] = "abc";
+  abcd[2]; // no-warning
+  safe_char = "abc"[3]; //expected-warning{{unsafe buffer access}}
+}

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


[clang] [Wunsafe-buffer-usage] Fix false positives in handling string literals. (PR #115552)

2024-11-08 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 5b697ef5dd6b3e29e257e6099014bf8d8e77ac9a 
3be112ec1f0b2e6e2948db082a7141d91b873a17 --extensions cpp -- 
clang/lib/Analysis/UnsafeBufferUsage.cpp 
clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 650d51bebd..6a72c7212f 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -436,13 +436,14 @@ AST_MATCHER(ArraySubscriptExpr, isSafeArraySubscript) {
 
   const auto *BaseDRE =
   dyn_cast(Node.getBase()->IgnoreParenImpCasts());
-  const auto *SLiteral = 
dyn_cast(Node.getBase()->IgnoreParenImpCasts());
+  const auto *SLiteral =
+  dyn_cast(Node.getBase()->IgnoreParenImpCasts());
   uint64_t size;
 
   if (!BaseDRE && !SLiteral)
 return false;
 
-  if(BaseDRE) {
+  if (BaseDRE) {
 if (!BaseDRE->getDecl())
   return false;
 const auto *CATy = Finder->getASTContext().getAsConstantArrayType(
@@ -451,7 +452,7 @@ AST_MATCHER(ArraySubscriptExpr, isSafeArraySubscript) {
   return false;
 }
 size = CATy->getLimitedSize();
-  } else if(SLiteral) {
+  } else if (SLiteral) {
 size = SLiteral->getLength();
   }
 
@@ -459,8 +460,7 @@ AST_MATCHER(ArraySubscriptExpr, isSafeArraySubscript) {
 const APInt ArrIdx = IdxLit->getValue();
 // FIXME: ArrIdx.isNegative() we could immediately emit an error as that's 
a
 // bug
-if (ArrIdx.isNonNegative() &&
-ArrIdx.getLimitedValue() < size)
+if (ArrIdx.isNonNegative() && ArrIdx.getLimitedValue() < size)
   return true;
   }
 

``




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


[clang] [Wunsafe-buffer-usage] Fix false positives in handling string literals. (PR #115552)

2024-11-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Malavika Samak (malavikasamak)


Changes

Do not warn when a string literal is indexed and the idex value is within the 
bounds of the length of the string.

(rdar://139106996)

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


2 Files Affected:

- (modified) clang/lib/Analysis/UnsafeBufferUsage.cpp (+19-9) 
- (modified) clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp (+7) 


``diff
diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 2c68409b846bc8..650d51bebd66f7 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -436,21 +436,31 @@ AST_MATCHER(ArraySubscriptExpr, isSafeArraySubscript) {
 
   const auto *BaseDRE =
   dyn_cast(Node.getBase()->IgnoreParenImpCasts());
-  if (!BaseDRE)
-return false;
-  if (!BaseDRE->getDecl())
-return false;
-  const auto *CATy = Finder->getASTContext().getAsConstantArrayType(
-  BaseDRE->getDecl()->getType());
-  if (!CATy)
+  const auto *SLiteral = 
dyn_cast(Node.getBase()->IgnoreParenImpCasts());
+  uint64_t size;
+
+  if (!BaseDRE && !SLiteral)
 return false;
 
+  if(BaseDRE) {
+if (!BaseDRE->getDecl())
+  return false;
+const auto *CATy = Finder->getASTContext().getAsConstantArrayType(
+BaseDRE->getDecl()->getType());
+if (!CATy) {
+  return false;
+}
+size = CATy->getLimitedSize();
+  } else if(SLiteral) {
+size = SLiteral->getLength();
+  }
+
   if (const auto *IdxLit = dyn_cast(Node.getIdx())) {
 const APInt ArrIdx = IdxLit->getValue();
 // FIXME: ArrIdx.isNegative() we could immediately emit an error as that's 
a
 // bug
 if (ArrIdx.isNonNegative() &&
-ArrIdx.getLimitedValue() < CATy->getLimitedSize())
+ArrIdx.getLimitedValue() < size)
   return true;
   }
 
@@ -1142,7 +1152,7 @@ class ArraySubscriptGadget : public WarningGadget {
 // clang-format off
   return stmt(arraySubscriptExpr(
 hasBase(ignoringParenImpCasts(
-  anyOf(hasPointerType(), hasArrayType(,
+  anyOf(hasPointerType(), hasArrayType(), stringLiteral(,
 unless(anyOf(
   isSafeArraySubscript(),
   hasIndex(
diff --git a/clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp
index 8b2f103ec66708..0a443543d3f604 100644
--- a/clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp
+++ b/clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp
@@ -38,3 +38,10 @@ void constant_idx_unsafe(unsigned idx) {
 // expected-note@-1{{change type of 'buffer' to 
'std::array' to label it for hardening}}
   buffer[10] = 0;   // expected-note{{used in buffer access here}}
 }
+
+void constant_id_string() {
+  char safe_char = "abc"[1]; // no-warning
+  char abcd[5] = "abc";
+  abcd[2]; // no-warning
+  safe_char = "abc"[3]; //expected-warning{{unsafe buffer access}}
+}

``




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


[clang] [-Wunsafe-buffer-usage] Fix false positives for string literals (PR #115554)

2024-11-08 Thread via cfe-commits

https://github.com/jkorous-apple created 
https://github.com/llvm/llvm-project/pull/115554

fixes rdar://139106996

>From 8db304f11ba708abd096b4b8df998c55548e5b4d Mon Sep 17 00:00:00 2001
From: Jan Korous 
Date: Fri, 8 Nov 2024 14:07:19 -0800
Subject: [PATCH] [-Wunsafe-buffer-usage] Fix false positives for string
 literals

# Conflicts:
#   clang/lib/Analysis/UnsafeBufferUsage.cpp
---
 clang/lib/Analysis/UnsafeBufferUsage.cpp  | 26 ---
 ...arn-unsafe-buffer-usage-string-literal.cpp | 18 +
 2 files changed, 34 insertions(+), 10 deletions(-)
 create mode 100644 
clang/test/SemaCXX/warn-unsafe-buffer-usage-string-literal.cpp

diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 2c68409b846bc8..116d098075b6bf 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -434,16 +434,22 @@ AST_MATCHER(ArraySubscriptExpr, isSafeArraySubscript) {
   //already duplicated
   //  - call both from Sema and from here
 
-  const auto *BaseDRE =
-  dyn_cast(Node.getBase()->IgnoreParenImpCasts());
-  if (!BaseDRE)
-return false;
-  if (!BaseDRE->getDecl())
-return false;
-  const auto *CATy = Finder->getASTContext().getAsConstantArrayType(
-  BaseDRE->getDecl()->getType());
-  if (!CATy)
-return false;
+  APInt ArrSize{};
+  if (const auto *BaseDRE =
+dyn_cast(Node.getBase()->IgnoreParenImpCasts())) {
+if (!BaseDRE)
+  return false;
+if (!BaseDRE->getDecl())
+  return false;
+const auto *CATy = Finder->getASTContext().getAsConstantArrayType(
+BaseDRE->getDecl()->getType());
+if (!CATy)
+  return false;
+ArrSize = CATy->getSize();
+  } else if (const auto *BaseStrLit = 
dyn_cast(Node.getBase()->IgnoreParenImpCasts())) {
+// Add 1 for the terminating null character.
+ArrSize = APInt{64, BaseStrLit->getLength() + 1, false};
+  }
 
   if (const auto *IdxLit = dyn_cast(Node.getIdx())) {
 const APInt ArrIdx = IdxLit->getValue();
diff --git a/clang/test/SemaCXX/warn-unsafe-buffer-usage-string-literal.cpp 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-string-literal.cpp
new file mode 100644
index 00..e983a8f135d8a4
--- /dev/null
+++ b/clang/test/SemaCXX/warn-unsafe-buffer-usage-string-literal.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -std=c++20 -Wno-everything -Wunsafe-buffer-usage \
+// RUN:-fsafe-buffer-usage-suggestions \
+// RUN:-verify %s
+
+// CHECK-NOT: [-Wunsafe-buffer-usage]
+
+
+void foo(unsigned idx) {
+  char c = '0';
+  c = "abc"[0];
+  c = "abc"[1];
+  c = "abc"[2];
+  c = "abc"[3];
+  c = "abc"[4]; // expected-warning{{unsafe buffer access}}
+  c = "abc"[idx]; // expected-warning{{unsafe buffer access}}
+  c = ""[0];
+  c = ""[1]; // expected-warning{{unsafe buffer access}}
+}

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


[clang] [-Wunsafe-buffer-usage] Fix false positives for string literals (PR #115554)

2024-11-08 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-analysis

Author: None (jkorous-apple)


Changes

fixes rdar://139106996

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


2 Files Affected:

- (modified) clang/lib/Analysis/UnsafeBufferUsage.cpp (+16-10) 
- (added) clang/test/SemaCXX/warn-unsafe-buffer-usage-string-literal.cpp (+18) 


``diff
diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 2c68409b846bc8..116d098075b6bf 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -434,16 +434,22 @@ AST_MATCHER(ArraySubscriptExpr, isSafeArraySubscript) {
   //already duplicated
   //  - call both from Sema and from here
 
-  const auto *BaseDRE =
-  dyn_cast(Node.getBase()->IgnoreParenImpCasts());
-  if (!BaseDRE)
-return false;
-  if (!BaseDRE->getDecl())
-return false;
-  const auto *CATy = Finder->getASTContext().getAsConstantArrayType(
-  BaseDRE->getDecl()->getType());
-  if (!CATy)
-return false;
+  APInt ArrSize{};
+  if (const auto *BaseDRE =
+dyn_cast(Node.getBase()->IgnoreParenImpCasts())) {
+if (!BaseDRE)
+  return false;
+if (!BaseDRE->getDecl())
+  return false;
+const auto *CATy = Finder->getASTContext().getAsConstantArrayType(
+BaseDRE->getDecl()->getType());
+if (!CATy)
+  return false;
+ArrSize = CATy->getSize();
+  } else if (const auto *BaseStrLit = 
dyn_cast(Node.getBase()->IgnoreParenImpCasts())) {
+// Add 1 for the terminating null character.
+ArrSize = APInt{64, BaseStrLit->getLength() + 1, false};
+  }
 
   if (const auto *IdxLit = dyn_cast(Node.getIdx())) {
 const APInt ArrIdx = IdxLit->getValue();
diff --git a/clang/test/SemaCXX/warn-unsafe-buffer-usage-string-literal.cpp 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-string-literal.cpp
new file mode 100644
index 00..e983a8f135d8a4
--- /dev/null
+++ b/clang/test/SemaCXX/warn-unsafe-buffer-usage-string-literal.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -std=c++20 -Wno-everything -Wunsafe-buffer-usage \
+// RUN:-fsafe-buffer-usage-suggestions \
+// RUN:-verify %s
+
+// CHECK-NOT: [-Wunsafe-buffer-usage]
+
+
+void foo(unsigned idx) {
+  char c = '0';
+  c = "abc"[0];
+  c = "abc"[1];
+  c = "abc"[2];
+  c = "abc"[3];
+  c = "abc"[4]; // expected-warning{{unsafe buffer access}}
+  c = "abc"[idx]; // expected-warning{{unsafe buffer access}}
+  c = ""[0];
+  c = ""[1]; // expected-warning{{unsafe buffer access}}
+}

``




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


[clang] [-Wunsafe-buffer-usage] Fix false positives for string literals (PR #115554)

2024-11-08 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 8a7a7b5ffc690bd012cf090d31d47ec938248ba3 
8db304f11ba708abd096b4b8df998c55548e5b4d --extensions cpp -- 
clang/test/SemaCXX/warn-unsafe-buffer-usage-string-literal.cpp 
clang/lib/Analysis/UnsafeBufferUsage.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 116d098075..65a4fecd54 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -436,7 +436,7 @@ AST_MATCHER(ArraySubscriptExpr, isSafeArraySubscript) {
 
   APInt ArrSize{};
   if (const auto *BaseDRE =
-dyn_cast(Node.getBase()->IgnoreParenImpCasts())) {
+  dyn_cast(Node.getBase()->IgnoreParenImpCasts())) {
 if (!BaseDRE)
   return false;
 if (!BaseDRE->getDecl())
@@ -446,7 +446,8 @@ AST_MATCHER(ArraySubscriptExpr, isSafeArraySubscript) {
 if (!CATy)
   return false;
 ArrSize = CATy->getSize();
-  } else if (const auto *BaseStrLit = 
dyn_cast(Node.getBase()->IgnoreParenImpCasts())) {
+  } else if (const auto *BaseStrLit = dyn_cast(
+ Node.getBase()->IgnoreParenImpCasts())) {
 // Add 1 for the terminating null character.
 ArrSize = APInt{64, BaseStrLit->getLength() + 1, false};
   }

``




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


[clang] [Clang] add wraps and no_wraps attributes (PR #115094)

2024-11-08 Thread Vitaly Buka via cfe-commits


@@ -8710,3 +8710,103 @@ Declares that a function potentially allocates heap 
memory, and prevents any pot
 of ``nonallocating`` by the compiler.
   }];
 }
+
+def WrapsDocs : Documentation {
+  let Category = DocCatField;
+  let Content = [{
+The ``wraps`` attribute can be used with type or variable declarations to
+denote that arithmetic containing attributed types or variables have defined
+overflow behavior. Specifically, the behavior is defined as being consistent
+with two's complement wrap-around. For the purposes of sanitizers or warnings
+that concern themselves with the definedness of integer arithmetic, they will
+cease to instrument or warn about arithmetic that directly involves operands
+attributed with the ``wraps`` attribute.
+
+The ``signed-integer-overflow``, ``unsigned-integer-overflow``,
+``implicit-signed-integer-truncation`` and the

vitalybuka wrote:

I don't think it should affect instrumentation at all.
We have -fsanitize-recover= mode.
In this case we need instrumentation to print report, regardless of "wrap", and 
the "wrap" or -fwrap will control how to calculate after the report.

to suppress report we have no_sanitize attribute already

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


[clang] [Clang] add wraps and no_wraps attributes (PR #115094)

2024-11-08 Thread Vitaly Buka via cfe-commits


@@ -433,6 +433,26 @@ Attribute Changes in Clang
 - Fix a bug where clang doesn't automatically apply the ``[[gsl::Owner]]`` or
   ``[[gsl::Pointer]]`` to STL explicit template specialization decls. 
(#GH109442)
 
+- Introduced ``__attribute__((wraps))`` which can be added to type or variable
+  declarations. Using an attributed type or variable in an arithmetic
+  expression will define the overflow behavior for that expression as having
+  two's complement wrap-around. These expressions will not be instrumented by
+  overflow sanitizers nor will they cause integer overflow warnings. They also
+  cannot be optimized away by some eager UB optimizations as the behavior of
+  the arithmetic is no longer "undefined".
+
+  There is also ``__attribute__((no_wraps))`` which can be added to types or
+  variable declarations. Types or variables with this attribute may be
+  instrumented by overflow sanitizers, if enabled. Note that this matches the
+  default behavior of integer types. So, in most cases, ``no_wraps`` serves

vitalybuka wrote:

So this is essentially no opt?
I don't thing this will help, to me it will trigger readers to think what it's 
needed, unnecessary noise.
Regular comment will be as good enough?



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


[clang] [Clang] add wraps and no_wraps attributes (PR #115094)

2024-11-08 Thread Vitaly Buka via cfe-commits

https://github.com/vitalybuka commented:

I guess we already discussed that before. My preference is the wrap and 
sanitize attributes are interdependent. Open to be convinced otherwise.

But seems like we want consistency with https://godbolt.org/z/crhdaczx1

* `__attribute__((wraps,no_sanitize("signed-integer-overflow")))` wraps quietly
* `__attribute__((wraps))`  wraps, but may report if runs with 
`-fsanitize=signed-integer-overflow`
* `__attribute__((no_sanitize("signed-integer-overflow")))` reports, but in 
recovery mode, compile UB any way it likes.


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


[clang] [Clang] add wraps and no_wraps attributes (PR #115094)

2024-11-08 Thread Vitaly Buka via cfe-commits

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


[clang] [Clang] add wraps and no_wraps attributes (PR #115094)

2024-11-08 Thread Vitaly Buka via cfe-commits


@@ -8710,3 +8710,103 @@ Declares that a function potentially allocates heap 
memory, and prevents any pot
 of ``nonallocating`` by the compiler.
   }];
 }
+
+def WrapsDocs : Documentation {
+  let Category = DocCatField;
+  let Content = [{
+The ``wraps`` attribute can be used with type or variable declarations to
+denote that arithmetic containing attributed types or variables have defined

vitalybuka wrote:

should we mention that it's `-fwrap` equivalent

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


[clang] [Clang] add wraps and no_wraps attributes (PR #115094)

2024-11-08 Thread Vitaly Buka via cfe-commits


@@ -8710,3 +8710,103 @@ Declares that a function potentially allocates heap 
memory, and prevents any pot
 of ``nonallocating`` by the compiler.
   }];
 }
+
+def WrapsDocs : Documentation {
+  let Category = DocCatField;
+  let Content = [{
+The ``wraps`` attribute can be used with type or variable declarations to
+denote that arithmetic containing attributed types or variables have defined
+overflow behavior. Specifically, the behavior is defined as being consistent
+with two's complement wrap-around. For the purposes of sanitizers or warnings
+that concern themselves with the definedness of integer arithmetic, they will
+cease to instrument or warn about arithmetic that directly involves operands
+attributed with the ``wraps`` attribute.
+
+The ``signed-integer-overflow``, ``unsigned-integer-overflow``,
+``implicit-signed-integer-truncation`` and the
+``implicit-unsigned-integer-truncation`` sanitizers will not instrument
+arithmetic containing any operands attributed by ``wraps``. Similarly, the
+``-Winteger-overflow`` warning is disabled for these instances.
+
+The following example shows how one may disable ``signed-integer-overflow``
+sanitizer instrumentation using ``__attribute__((wraps))`` on a type definition
+when building with ``-fsanitize=signed-integer-overflow``:
+
+.. code-block:: c
+
+  typedef int __attribute__((wraps)) wrapping_int;
+
+  void foo(void) {
+wrapping_int A = INT_MAX;
+++A; // no sanitizer instrumentation
+  }
+
+``wraps`` may also be used with function parameters or declarations of
+variables as well as members of structures. Using ``wraps`` on non-integer
+types will result in a ``-Wuseless-wraps-attribute`` warning. One may disable
+this warning with ``-Wno-useless-wraps-attribute``.
+
+``wraps`` persists through implicit type promotions and will be applied to the
+result type of arithmetic expressions containing a wrapping operand.
+``-Wimplicitly-discarded-wraps-attribute`` warnings can be caused in situations
+where the ``wraps`` attribute cannot persist through implicit type conversions.
+Disable this with ``-Wno-implicitly-discarded-wraps-attribute``.
+}];
+}
+
+def NoWrapsDocs : Documentation {
+  let Category = DocCatField;
+  let Content = [{
+The ``no_wraps`` attribute can be used to annotate types or variables as
+non-wrapping. This may serve as a helpful annotation to readers of code that
+particular arithmetic expressions involving these types or variables are not
+meant to wrap-around.
+
+When overflow or truncation sanitizer instrumentation is modified at the
+type-level through `SSCLs
+`_, ``no_wraps`` or
+``wraps`` may be used to override sanitizer behavior.
+
+For example, one may specify an ignorelist (with ``-fsanitize-ignorelist=``) to
+disable the ``signed-integer-overflow`` sanitizer for all types:
+
+.. code-block:: text
+
+  [signed-integer-overflow]
+  type:*
+
+``no_wraps`` can override the behavior provided by the ignorelist to

vitalybuka wrote:

I think wrap and sanitize should be independent, because of "recover" mode.
In this case no_wraps is redundant, unless it's going to override -fwrap.

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


[clang] [HLSL] Add implicit resource element type concepts to AST (PR #112600)

2024-11-08 Thread Chris B via cfe-commits


@@ -323,30 +324,127 @@ struct TemplateParameterListBuilder {
 S.Context, Builder.Record->getDeclContext(), SourceLocation(),
 SourceLocation(), /* TemplateDepth */ 0, Position,
 &S.Context.Idents.get(Name, tok::TokenKind::identifier),
-/* Typename */ false,
-/* ParameterPack */ false);
+/* Typename */ true,
+/* ParameterPack */ false,
+/* HasTypeConstraint*/ false);
 if (!DefaultValue.isNull())
   Decl->setDefaultArgument(
   S.Context, S.getTrivialTemplateArgumentLoc(DefaultValue, QualType(),
  SourceLocation()));
-
 Params.emplace_back(Decl);
 return *this;
   }
 
-  BuiltinTypeDeclBuilder &finalizeTemplateArgs() {
+  /*
+  The concept specialization expression (CSE) constructed below is constructed
+  so that it matches the CSE that is constructed when parsing
+  the below C++ code:
+
+  template
+  concept is_typed_resource_element_compatible =sizeof(T) <= 16;
+
+  template requires
+  is_typed_resource_element_compatible
+
+  struct RWBuffer {
+  element_type Val;
+  };
+
+  int fn() {
+  RWBuffer Buf;
+  }
+
+  When dumping the AST and filtering for "RWBuffer", the resulting AST
+  structure is what we're trying to construct below, specifically the
+  CSE portion.
+  */
+  ConceptSpecializationExpr *
+  constructConceptSpecializationExpr(Sema &S, ConceptDecl *CD) {
+ASTContext &Context = S.getASTContext();
+SourceLocation Loc = Builder.Record->getBeginLoc();
+DeclarationNameInfo DNI(CD->getDeclName(), Loc);
+NestedNameSpecifierLoc NNSLoc;
+DeclContext *DC = Builder.Record->getDeclContext();
+TemplateArgumentListInfo TALI(Loc, Loc);
+
+// Assume that the concept decl has just one template parameter
+// This parameter should have been added when CD was constructed
+// in getTypedBufferConceptDecl
+assert(CD->getTemplateParameters()->size() == 1 &&
+   "unexpected concept decl parameter count");
+TemplateTypeParmDecl *ConceptTTPD = dyn_cast(
+CD->getTemplateParameters()->getParam(0));
+
+// this fake TemplateTypeParmDecl is used to construct a template argument
+// that will be used to construct the ImplicitConceptSpecializationDecl

llvm-beanz wrote:

This sounds wrong... Like, completely wrong. You're absolutely adding it to the 
AST, that's what happens when you create a declaration and put it into a 
declaration context.

This also seems like we're putting this declaration into the wrong declaration 
context.

I don't see any of your tests verifying the AST shape of the concept 
declaration. Can you add tests for that so that we can see what the concept's 
AST looks like?

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


[clang] [HLSL] Add empty struct test cases to `__builtin_hlsl_is_typed_resource_element_compatible` test file (PR #115045)

2024-11-08 Thread Joshua Batista via cfe-commits

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

>From ef4a7eea3eacce4f77b628aebe7f2838733971d0 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Tue, 5 Nov 2024 10:35:59 -0800
Subject: [PATCH 1/5] add empty struct test cases

---
 .../SemaHLSL/Types/Traits/IsTypedResourceElementCompatible.hlsl | 2 ++
 1 file changed, 2 insertions(+)

diff --git 
a/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatible.hlsl 
b/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatible.hlsl
index acc1f281daddfc..08d75a0c23b228 100644
--- a/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatible.hlsl
+++ b/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatible.hlsl
@@ -107,3 +107,5 @@ struct TypeDefTest {
 };
 
 
_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(TypeDefTest),
 "");
+
+

>From 0ed4809a4bb12618e885914c09ba83e44c9c83c9 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Tue, 5 Nov 2024 10:58:58 -0800
Subject: [PATCH 2/5] remove assert, return false instead

---
 clang/lib/Sema/SemaHLSL.cpp  | 6 --
 .../Types/Traits/IsTypedResourceElementCompatible.hlsl   | 9 +
 .../Traits/IsTypedResourceElementCompatibleErrors.hlsl   | 1 -
 3 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 298b7ad4f9e687..4b5b5aa96d5c20 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -2210,8 +2210,10 @@ bool 
SemaHLSL::IsTypedResourceElementCompatible(clang::QualType QT) {
   llvm::SmallVector QTTypes;
   BuildFlattenedTypeList(QT, QTTypes);
 
-  assert(QTTypes.size() > 0 &&
- "expected at least one constituent type from non-null type");
+  // empty structs are not typed resource element compatible
+  if (QTTypes.size() == 0)
+return false;
+
   QualType FirstQT = SemaRef.Context.getCanonicalType(QTTypes[0]);
 
   // element count cannot exceed 4
diff --git 
a/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatible.hlsl 
b/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatible.hlsl
index 08d75a0c23b228..0a124be3e0aa60 100644
--- a/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatible.hlsl
+++ b/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatible.hlsl
@@ -108,4 +108,13 @@ struct TypeDefTest {
 
 
_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(TypeDefTest),
 "");
 
+struct EmptyStruct {};
+_Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(EmptyStruct),
 "");
 
+struct EmptyDerived : EmptyStruct {};
+_Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(EmptyDerived),
 "");
+
+struct EmptyBase : EmptyStruct {
+  int4 V;
+};
+_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(EmptyBase), 
""); 
diff --git 
a/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatibleErrors.hlsl 
b/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatibleErrors.hlsl
index cb3e9ae7a61509..1cc9880e5b25f1 100644
--- 
a/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatibleErrors.hlsl
+++ 
b/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatibleErrors.hlsl
@@ -7,4 +7,3 @@ 
_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(__hlsl_resour
 struct notComplete;
 // expected-error@+1{{incomplete type 'notComplete' where a complete type is 
required}}
 
_Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(notComplete),
 "");
- 

>From 65c6e1a384dd529a749a2cc8e20aa5a70d17c60b Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Tue, 5 Nov 2024 16:26:23 -0800
Subject: [PATCH 3/5] address chris

---
 clang/lib/Sema/SemaHLSL.cpp   |  11 +-
 .../IsTypedResourceElementCompatible.hlsl | 116 ++
 2 files changed, 19 insertions(+), 108 deletions(-)

diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 4b5b5aa96d5c20..b0dd7369749619 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -2200,17 +2200,20 @@ static void BuildFlattenedTypeList(QualType BaseTy,
 }
 
 bool SemaHLSL::IsTypedResourceElementCompatible(clang::QualType QT) {
-  if (QT.isNull())
+  // null and array types are not allowed.
+  if (QT.isNull() || QT->isArrayType())
 return false;
 
-  // check if the outer type was an array type
-  if (QT->isArrayType())
+  // UDT types are not allowed
+  clang::QualType CanonicalType = QT.getCanonicalType();
+  if (CanonicalType->getAs()) {
 return false;
+  }
 
   llvm::SmallVector QTTypes;
   BuildFlattenedTypeList(QT, QTTypes);
 
-  // empty structs are not typed resource element compatible
+  // empty element type is not typed resource element compatible
   if (QTTypes.size() == 0)
 return false;
 
diff --git 
a/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatible.hlsl 
b/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatible.hl

[clang] [Clang] add wraps and no_wraps attributes (PR #115094)

2024-11-08 Thread Justin Stitt via cfe-commits


@@ -67,9 +67,11 @@ types specified within an ignorelist.
 int a = 2147483647; // INT_MAX
 ++a;// Normally, an overflow with 
-fsanitize=signed-integer-overflow
   }
+

JustinStitt wrote:

I don't have commit access, but I'll revert that whitespace change 👍 

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


[clang] [Clang] add wraps and no_wraps attributes (PR #115094)

2024-11-08 Thread Vitaly Buka via cfe-commits

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


[clang] e4d57d6 - [OpenACC] Remove 'loop' link to parent construct

2024-11-08 Thread via cfe-commits

Author: erichkeane
Date: 2024-11-08T10:23:04-08:00
New Revision: e4d57d6a729fd955ccbdd8834065356f26284f3d

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

LOG: [OpenACC] Remove 'loop' link to parent construct

After implementing 'loop', we determined that the link to its parent
only ever uses the type, not the construct itself. This patch removes
it, as it is both a waste and causes problems with serialization.

Added: 


Modified: 
clang/include/clang/AST/StmtOpenACC.h
clang/include/clang/Sema/SemaOpenACC.h
clang/lib/AST/StmtOpenACC.cpp
clang/lib/AST/TextNodeDumper.cpp
clang/lib/Sema/SemaOpenACC.cpp
clang/lib/Serialization/ASTReaderStmt.cpp
clang/lib/Serialization/ASTWriterStmt.cpp
clang/test/SemaOpenACC/compute-construct-default-clause.c
clang/test/SemaOpenACC/compute-construct-if-clause.c
clang/test/SemaOpenACC/loop-ast.cpp
clang/test/SemaOpenACC/loop-construct-gang-ast.cpp
clang/test/SemaOpenACC/loop-construct-vector-ast.cpp
clang/test/SemaOpenACC/loop-construct-worker-ast.cpp

Removed: 




diff  --git a/clang/include/clang/AST/StmtOpenACC.h 
b/clang/include/clang/AST/StmtOpenACC.h
index b3aea09be03ddf..3eb50f9353ed19 100644
--- a/clang/include/clang/AST/StmtOpenACC.h
+++ b/clang/include/clang/AST/StmtOpenACC.h
@@ -114,7 +114,6 @@ class OpenACCAssociatedStmtConstruct : public 
OpenACCConstructStmt {
   }
 };
 
-class OpenACCLoopConstruct;
 /// This class represents a compute construct, representing a 'Kind' of
 /// `parallel', 'serial', or 'kernel'. These constructs are associated with a
 /// 'structured block', defined as:
@@ -183,8 +182,7 @@ class OpenACCComputeConstruct final
   static OpenACCComputeConstruct *
   Create(const ASTContext &C, OpenACCDirectiveKind K, SourceLocation BeginLoc,
  SourceLocation DirectiveLoc, SourceLocation EndLoc,
- ArrayRef Clauses, Stmt *StructuredBlock,
- ArrayRef AssociatedLoopConstructs);
+ ArrayRef Clauses, Stmt *StructuredBlock);
 
   Stmt *getStructuredBlock() { return getAssociatedStmt(); }
   const Stmt *getStructuredBlock() const {
@@ -198,12 +196,10 @@ class OpenACCLoopConstruct final
 : public OpenACCAssociatedStmtConstruct,
   public llvm::TrailingObjects {
-  // The compute construct this loop is associated with, or nullptr if this is
-  // an orphaned loop construct, or if it hasn't been set yet.  Because we
-  // construct the directives at the end of their statement, the 'parent'
-  // construct is not yet available at the time of construction, so this needs
-  // to be set 'later'.
-  const OpenACCComputeConstruct *ParentComputeConstruct = nullptr;
+  // The compute/combined construct kind this loop is associated with, or
+  // invalid if this is an orphaned loop construct.
+  OpenACCDirectiveKind ParentComputeConstructKind =
+  OpenACCDirectiveKind::Invalid;
 
   friend class ASTStmtWriter;
   friend class ASTStmtReader;
@@ -212,15 +208,9 @@ class OpenACCLoopConstruct final
 
   OpenACCLoopConstruct(unsigned NumClauses);
 
-  OpenACCLoopConstruct(SourceLocation Start, SourceLocation DirLoc,
-   SourceLocation End,
+  OpenACCLoopConstruct(OpenACCDirectiveKind ParentKind, SourceLocation Start,
+   SourceLocation DirLoc, SourceLocation End,
ArrayRef Clauses, Stmt *Loop);
-  void setLoop(Stmt *Loop);
-
-  void setParentComputeConstruct(OpenACCComputeConstruct *CC) {
-assert(!ParentComputeConstruct && "Parent already set?");
-ParentComputeConstruct = CC;
-  }
 
 public:
   static bool classof(const Stmt *T) {
@@ -231,9 +221,9 @@ class OpenACCLoopConstruct final
unsigned NumClauses);
 
   static OpenACCLoopConstruct *
-  Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation DirLoc,
- SourceLocation EndLoc, ArrayRef Clauses,
- Stmt *Loop);
+  Create(const ASTContext &C, OpenACCDirectiveKind ParentKind,
+ SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc,
+ ArrayRef Clauses, Stmt *Loop);
 
   Stmt *getLoop() { return getAssociatedStmt(); }
   const Stmt *getLoop() const {
@@ -246,10 +236,11 @@ class OpenACCLoopConstruct final
   /// loop construct is the nearest compute construct that lexically contains
   /// the loop construct.
   bool isOrphanedLoopConstruct() const {
-return ParentComputeConstruct == nullptr;
+return ParentComputeConstructKind == OpenACCDirectiveKind::Invalid;
   }
-  const OpenACCComputeConstruct *getParentComputeConstruct() const {
-return ParentComputeConstruct;
+
+  OpenACCDirectiveKind getParentComputeConstructKind() const {
+return ParentComputeConstructKind;
   }
 };
 } // namespace clang

diff  --git a/clang/include

[clang] 2b885f0 - Fix test for bots that don't default to C17

2024-11-08 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2024-11-08T13:24:11-05:00
New Revision: 2b885f056585f82903f067840e54557a5b444b65

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

LOG: Fix test for bots that don't default to C17

Added: 


Modified: 
clang/test/C/C2y/n3346.c

Removed: 




diff  --git a/clang/test/C/C2y/n3346.c b/clang/test/C/C2y/n3346.c
index 1240224216df9a..a6fc3325e0c8f7 100644
--- a/clang/test/C/C2y/n3346.c
+++ b/clang/test/C/C2y/n3346.c
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -verify -std=c2y -Wall -pedantic -ffreestanding %s
-// RUN: %clang_cc1 -verify=expected,ped -Wall -pedantic -ffreestanding %s
+// RUN: %clang_cc1 -std=c99 -verify=expected,ped -Wall -pedantic 
-ffreestanding %s
 
 /* WG14 N3346: Yes
  * Slay Some Earthly Demons VIII
@@ -33,8 +33,6 @@ void test1(void) {
 
 void test2(void) {
   typedef __WCHAR_TYPE__ wchar_t;
-  typedef __CHAR16_TYPE__ char16_t;
-  typedef __CHAR32_TYPE__ char32_t;
 
   // The initializer for an array shall be either a string literal, optionally
   // enclosed in braces, or a brace-enclosed list of initializers for the
@@ -54,6 +52,9 @@ void test2(void) {
   wchar_t str8[] = { L"string literal" };
 
 #if __STDC_VERSION__ >= 201112L
+  typedef __CHAR16_TYPE__ char16_t;
+  typedef __CHAR32_TYPE__ char32_t;
+
   char str3[] = u8"string literal";
   char str4[] = { u8"string literal" };
 
@@ -61,12 +62,13 @@ void test2(void) {
   char16_t str10[] = { u"string literal" };
   char32_t str11[] = U"string literal";
   char32_t str12[] = { U"string literal" };
-#endif
 
-  wchar_t str13[] = "nope";  // expected-error {{initializing wide char 
array with non-wide string literal}}
-  wchar_t str14[] = { "nope" };  // expected-error-re {{incompatible pointer 
to integer conversion initializing 'wchar_t' (aka '{{.*}}') with an expression 
of type 'char[5]'}}
   char16_t str15[] = "nope"; // expected-error {{initializing wide char 
array with non-wide string literal}}
   char16_t str16[] = { "nope" }; // expected-error-re {{incompatible pointer 
to integer conversion initializing 'char16_t' (aka '{{.*}}') with an expression 
of type 'char[5]'}}
   char32_t str17[] = "nope"; // expected-error {{initializing wide char 
array with non-wide string literal}}
   char32_t str18[] = { "nope" }; // expected-error-re {{incompatible pointer 
to integer conversion initializing 'char32_t' (aka '{{.*}}') with an expression 
of type 'char[5]'}}
+#endif
+
+  wchar_t str13[] = "nope";  // expected-error {{initializing wide char 
array with non-wide string literal}}
+  wchar_t str14[] = { "nope" };  // expected-error-re {{incompatible pointer 
to integer conversion initializing 'wchar_t' (aka '{{.*}}') with an expression 
of type 'char[5]'}}
 }



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


[clang] [NFC][Clang] Use StringSwitch instead of array for parsing attribute scope (PR #115414)

2024-11-08 Thread Chinmay Deshpande via cfe-commits

https://github.com/chinmaydd updated 
https://github.com/llvm/llvm-project/pull/115414

>From ce67d44d55ef488bac9428b4c7b78e37ea8471f6 Mon Sep 17 00:00:00 2001
From: Chinmay Deshpande 
Date: Thu, 7 Nov 2024 22:05:03 -0500
Subject: [PATCH 1/2] [NFC][Clang] Use StringSwitch instead of array for
 parsing attribute scope

Change-Id: Iacfabcfd3a1cedeb7c864b3b59bad88b2177e7a8
---
 .../include/clang/Basic/AttributeCommonInfo.h |  2 +-
 clang/lib/Basic/Attributes.cpp| 34 +--
 2 files changed, 17 insertions(+), 19 deletions(-)

diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h 
b/clang/include/clang/Basic/AttributeCommonInfo.h
index 11c64547721739..350154859ccdec 100644
--- a/clang/include/clang/Basic/AttributeCommonInfo.h
+++ b/clang/include/clang/Basic/AttributeCommonInfo.h
@@ -67,7 +67,7 @@ class AttributeCommonInfo {
 IgnoredAttribute,
 UnknownAttribute,
   };
-  enum class Scope { NONE, CLANG, GNU, MSVC, OMP, HLSL, GSL, RISCV };
+  enum class Scope { NONE, CLANG, GNU, MSVC, OMP, HLSL, GSL, RISCV, INVALID };
 
 private:
   const IdentifierInfo *AttrName = nullptr;
diff --git a/clang/lib/Basic/Attributes.cpp b/clang/lib/Basic/Attributes.cpp
index 2d18fb3f9d5bb2..a2ffaa147f3ef7 100644
--- a/clang/lib/Basic/Attributes.cpp
+++ b/clang/lib/Basic/Attributes.cpp
@@ -18,6 +18,7 @@
 #include "clang/Basic/TargetInfo.h"
 
 #include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/StringSwitch.h"
 
 using namespace clang;
 
@@ -155,26 +156,23 @@ std::string AttributeCommonInfo::getNormalizedFullName() 
const {
   normalizeName(getAttrName(), getScopeName(), getSyntax()));
 }
 
-// Sorted list of attribute scope names
-static constexpr std::pair ScopeList[] =
-{{"", AttributeCommonInfo::Scope::NONE},
- {"clang", AttributeCommonInfo::Scope::CLANG},
- {"gnu", AttributeCommonInfo::Scope::GNU},
- {"gsl", AttributeCommonInfo::Scope::GSL},
- {"hlsl", AttributeCommonInfo::Scope::HLSL},
- {"msvc", AttributeCommonInfo::Scope::MSVC},
- {"omp", AttributeCommonInfo::Scope::OMP},
- {"riscv", AttributeCommonInfo::Scope::RISCV}};
-
 AttributeCommonInfo::Scope
 getScopeFromNormalizedScopeName(StringRef ScopeName) {
-  auto It = std::lower_bound(
-  std::begin(ScopeList), std::end(ScopeList), ScopeName,
-  [](const std::pair &Element,
- StringRef Value) { return Element.first < Value; });
-  assert(It != std::end(ScopeList) && It->first == ScopeName);
-
-  return It->second;
+  AttributeCommonInfo::Scope ParsedScope =
+  llvm::StringSwitch(ScopeName)
+  .Case("", AttributeCommonInfo::Scope::NONE)
+  .Case("clang", AttributeCommonInfo::Scope::CLANG)
+  .Case("gnu", AttributeCommonInfo::Scope::GNU)
+  .Case("gsl", AttributeCommonInfo::Scope::GSL)
+  .Case("hlsl", AttributeCommonInfo::Scope::HLSL)
+  .Case("msvc", AttributeCommonInfo::Scope::MSVC)
+  .Case("omp", AttributeCommonInfo::Scope::OMP)
+  .Case("riscv", AttributeCommonInfo::Scope::RISCV)
+  .Default(AttributeCommonInfo::Scope::INVALID);
+
+  assert(ParsedScope != AttributeCommonInfo::Scope::INVALID);
+
+  return ParsedScope;
 }
 
 unsigned AttributeCommonInfo::calculateAttributeSpellingListIndex() const {

>From c70b5653d0903f0a8d3e27f0dff3e1c95298b207 Mon Sep 17 00:00:00 2001
From: Chinmay Deshpande 
Date: Fri, 8 Nov 2024 13:24:00 -0500
Subject: [PATCH 2/2] [NFC][Clang] Address comments

Change-Id: I99a618d8127680cb91146e1a82e0e0b6c0717888
---
 .../include/clang/Basic/AttributeCommonInfo.h |  2 +-
 clang/lib/Basic/Attributes.cpp| 24 +++
 clang/test/CodeGenCXX/split-stacks.cpp|  2 +-
 3 files changed, 11 insertions(+), 17 deletions(-)

diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h 
b/clang/include/clang/Basic/AttributeCommonInfo.h
index 350154859ccdec..11c64547721739 100644
--- a/clang/include/clang/Basic/AttributeCommonInfo.h
+++ b/clang/include/clang/Basic/AttributeCommonInfo.h
@@ -67,7 +67,7 @@ class AttributeCommonInfo {
 IgnoredAttribute,
 UnknownAttribute,
   };
-  enum class Scope { NONE, CLANG, GNU, MSVC, OMP, HLSL, GSL, RISCV, INVALID };
+  enum class Scope { NONE, CLANG, GNU, MSVC, OMP, HLSL, GSL, RISCV };
 
 private:
   const IdentifierInfo *AttrName = nullptr;
diff --git a/clang/lib/Basic/Attributes.cpp b/clang/lib/Basic/Attributes.cpp
index a2ffaa147f3ef7..6904bce3ac51ec 100644
--- a/clang/lib/Basic/Attributes.cpp
+++ b/clang/lib/Basic/Attributes.cpp
@@ -158,21 +158,15 @@ std::string AttributeCommonInfo::getNormalizedFullName() 
const {
 
 AttributeCommonInfo::Scope
 getScopeFromNormalizedScopeName(StringRef ScopeName) {
-  AttributeCommonInfo::Scope ParsedScope =
-  llvm::StringSwitch(ScopeName)
-  .Case("", AttributeCommonInfo::Scope::NONE)
-  .Case("clang", AttributeCommonInfo::Scope::CLANG)
-  .Case("gnu", AttributeCommonInfo::Scope::GNU)
-  .Case("gsl", AttributeCommonInfo::Scope::GSL)
-  .

[clang] [NFC][Clang] Use StringSwitch instead of array for parsing attribute scope (PR #115414)

2024-11-08 Thread Erich Keane via cfe-commits

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


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


[clang] [NFC][Clang] Use StringSwitch instead of array for parsing attribute scope (PR #115414)

2024-11-08 Thread Chinmay Deshpande via cfe-commits

https://github.com/chinmaydd updated 
https://github.com/llvm/llvm-project/pull/115414

>From ce67d44d55ef488bac9428b4c7b78e37ea8471f6 Mon Sep 17 00:00:00 2001
From: Chinmay Deshpande 
Date: Thu, 7 Nov 2024 22:05:03 -0500
Subject: [PATCH 1/2] [NFC][Clang] Use StringSwitch instead of array for
 parsing attribute scope

Change-Id: Iacfabcfd3a1cedeb7c864b3b59bad88b2177e7a8
---
 .../include/clang/Basic/AttributeCommonInfo.h |  2 +-
 clang/lib/Basic/Attributes.cpp| 34 +--
 2 files changed, 17 insertions(+), 19 deletions(-)

diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h 
b/clang/include/clang/Basic/AttributeCommonInfo.h
index 11c64547721739..350154859ccdec 100644
--- a/clang/include/clang/Basic/AttributeCommonInfo.h
+++ b/clang/include/clang/Basic/AttributeCommonInfo.h
@@ -67,7 +67,7 @@ class AttributeCommonInfo {
 IgnoredAttribute,
 UnknownAttribute,
   };
-  enum class Scope { NONE, CLANG, GNU, MSVC, OMP, HLSL, GSL, RISCV };
+  enum class Scope { NONE, CLANG, GNU, MSVC, OMP, HLSL, GSL, RISCV, INVALID };
 
 private:
   const IdentifierInfo *AttrName = nullptr;
diff --git a/clang/lib/Basic/Attributes.cpp b/clang/lib/Basic/Attributes.cpp
index 2d18fb3f9d5bb2..a2ffaa147f3ef7 100644
--- a/clang/lib/Basic/Attributes.cpp
+++ b/clang/lib/Basic/Attributes.cpp
@@ -18,6 +18,7 @@
 #include "clang/Basic/TargetInfo.h"
 
 #include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/StringSwitch.h"
 
 using namespace clang;
 
@@ -155,26 +156,23 @@ std::string AttributeCommonInfo::getNormalizedFullName() 
const {
   normalizeName(getAttrName(), getScopeName(), getSyntax()));
 }
 
-// Sorted list of attribute scope names
-static constexpr std::pair ScopeList[] =
-{{"", AttributeCommonInfo::Scope::NONE},
- {"clang", AttributeCommonInfo::Scope::CLANG},
- {"gnu", AttributeCommonInfo::Scope::GNU},
- {"gsl", AttributeCommonInfo::Scope::GSL},
- {"hlsl", AttributeCommonInfo::Scope::HLSL},
- {"msvc", AttributeCommonInfo::Scope::MSVC},
- {"omp", AttributeCommonInfo::Scope::OMP},
- {"riscv", AttributeCommonInfo::Scope::RISCV}};
-
 AttributeCommonInfo::Scope
 getScopeFromNormalizedScopeName(StringRef ScopeName) {
-  auto It = std::lower_bound(
-  std::begin(ScopeList), std::end(ScopeList), ScopeName,
-  [](const std::pair &Element,
- StringRef Value) { return Element.first < Value; });
-  assert(It != std::end(ScopeList) && It->first == ScopeName);
-
-  return It->second;
+  AttributeCommonInfo::Scope ParsedScope =
+  llvm::StringSwitch(ScopeName)
+  .Case("", AttributeCommonInfo::Scope::NONE)
+  .Case("clang", AttributeCommonInfo::Scope::CLANG)
+  .Case("gnu", AttributeCommonInfo::Scope::GNU)
+  .Case("gsl", AttributeCommonInfo::Scope::GSL)
+  .Case("hlsl", AttributeCommonInfo::Scope::HLSL)
+  .Case("msvc", AttributeCommonInfo::Scope::MSVC)
+  .Case("omp", AttributeCommonInfo::Scope::OMP)
+  .Case("riscv", AttributeCommonInfo::Scope::RISCV)
+  .Default(AttributeCommonInfo::Scope::INVALID);
+
+  assert(ParsedScope != AttributeCommonInfo::Scope::INVALID);
+
+  return ParsedScope;
 }
 
 unsigned AttributeCommonInfo::calculateAttributeSpellingListIndex() const {

>From a64632f9b3253a181c2a00ca44c4009736617191 Mon Sep 17 00:00:00 2001
From: Chinmay Deshpande 
Date: Fri, 8 Nov 2024 13:24:00 -0500
Subject: [PATCH 2/2] [NFC][Clang] Address comments

Change-Id: I99a618d8127680cb91146e1a82e0e0b6c0717888
---
 .../include/clang/Basic/AttributeCommonInfo.h |  2 +-
 clang/lib/Basic/Attributes.cpp| 24 +++
 2 files changed, 10 insertions(+), 16 deletions(-)

diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h 
b/clang/include/clang/Basic/AttributeCommonInfo.h
index 350154859ccdec..11c64547721739 100644
--- a/clang/include/clang/Basic/AttributeCommonInfo.h
+++ b/clang/include/clang/Basic/AttributeCommonInfo.h
@@ -67,7 +67,7 @@ class AttributeCommonInfo {
 IgnoredAttribute,
 UnknownAttribute,
   };
-  enum class Scope { NONE, CLANG, GNU, MSVC, OMP, HLSL, GSL, RISCV, INVALID };
+  enum class Scope { NONE, CLANG, GNU, MSVC, OMP, HLSL, GSL, RISCV };
 
 private:
   const IdentifierInfo *AttrName = nullptr;
diff --git a/clang/lib/Basic/Attributes.cpp b/clang/lib/Basic/Attributes.cpp
index a2ffaa147f3ef7..6904bce3ac51ec 100644
--- a/clang/lib/Basic/Attributes.cpp
+++ b/clang/lib/Basic/Attributes.cpp
@@ -158,21 +158,15 @@ std::string AttributeCommonInfo::getNormalizedFullName() 
const {
 
 AttributeCommonInfo::Scope
 getScopeFromNormalizedScopeName(StringRef ScopeName) {
-  AttributeCommonInfo::Scope ParsedScope =
-  llvm::StringSwitch(ScopeName)
-  .Case("", AttributeCommonInfo::Scope::NONE)
-  .Case("clang", AttributeCommonInfo::Scope::CLANG)
-  .Case("gnu", AttributeCommonInfo::Scope::GNU)
-  .Case("gsl", AttributeCommonInfo::Scope::GSL)
-  .Case("hlsl", AttributeCommonInfo::Scope::HLSL)
-   

[clang] [NFC][Clang] Use StringSwitch instead of array for parsing attribute scope (PR #115414)

2024-11-08 Thread Chinmay Deshpande via cfe-commits


@@ -155,26 +156,23 @@ std::string AttributeCommonInfo::getNormalizedFullName() 
const {
   normalizeName(getAttrName(), getScopeName(), getSyntax()));
 }
 
-// Sorted list of attribute scope names
-static constexpr std::pair ScopeList[] =
-{{"", AttributeCommonInfo::Scope::NONE},
- {"clang", AttributeCommonInfo::Scope::CLANG},
- {"gnu", AttributeCommonInfo::Scope::GNU},
- {"gsl", AttributeCommonInfo::Scope::GSL},
- {"hlsl", AttributeCommonInfo::Scope::HLSL},
- {"msvc", AttributeCommonInfo::Scope::MSVC},
- {"omp", AttributeCommonInfo::Scope::OMP},
- {"riscv", AttributeCommonInfo::Scope::RISCV}};
-
 AttributeCommonInfo::Scope
 getScopeFromNormalizedScopeName(StringRef ScopeName) {
-  auto It = std::lower_bound(
-  std::begin(ScopeList), std::end(ScopeList), ScopeName,
-  [](const std::pair &Element,
- StringRef Value) { return Element.first < Value; });
-  assert(It != std::end(ScopeList) && It->first == ScopeName);
-
-  return It->second;
+  AttributeCommonInfo::Scope ParsedScope =
+  llvm::StringSwitch(ScopeName)
+  .Case("", AttributeCommonInfo::Scope::NONE)
+  .Case("clang", AttributeCommonInfo::Scope::CLANG)
+  .Case("gnu", AttributeCommonInfo::Scope::GNU)
+  .Case("gsl", AttributeCommonInfo::Scope::GSL)
+  .Case("hlsl", AttributeCommonInfo::Scope::HLSL)
+  .Case("msvc", AttributeCommonInfo::Scope::MSVC)
+  .Case("omp", AttributeCommonInfo::Scope::OMP)
+  .Case("riscv", AttributeCommonInfo::Scope::RISCV)
+  .Default(AttributeCommonInfo::Scope::INVALID);
+
+  assert(ParsedScope != AttributeCommonInfo::Scope::INVALID);

chinmaydd wrote:

Thanks @erichkeane and @nikic. This looks quite clean now :)

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


[clang] 2808f05 - Update test case for bots which don't default to C17

2024-11-08 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2024-11-08T13:20:38-05:00
New Revision: 2808f05e83643b3d5ef128340f6f4da994ed71e3

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

LOG: Update test case for bots which don't default to C17

Added: 


Modified: 
clang/test/C/C2y/n3341.c

Removed: 




diff  --git a/clang/test/C/C2y/n3341.c b/clang/test/C/C2y/n3341.c
index 523c3dd945ac1d..4cff7f08cc2320 100644
--- a/clang/test/C/C2y/n3341.c
+++ b/clang/test/C/C2y/n3341.c
@@ -10,7 +10,9 @@
 // expected-no-diagnostics
 
 struct R {};   // gnu-warning {{empty struct is a GNU extension}}
+#if __STDC_VERSION__ >= 201112L
 struct S { struct { }; };  // gnu-warning {{empty struct is a GNU extension}}
+#endif
 struct T { int : 0; }; // gnu-warning {{struct without named members is a 
GNU extension}}
 union U {};// gnu-warning {{empty union is a GNU extension}}
 



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


[clang] [Clang] skip default argument instantiation for non-defining friend declarations to meet [dcl.fct.default] p4 (PR #115487)

2024-11-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Oleksandr T. (a-tarasyuk)


Changes

Fixes #113324
---

https://github.com/llvm/llvm-project/pull/113777#issuecomment-2463960195
https://github.com/llvm/llvm-project/pull/113777#issuecomment-2464234180



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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/lib/Sema/SemaTemplateInstantiateDecl.cpp (+11) 
- (modified) clang/test/CXX/temp/temp.res/p4.cpp (+43) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d4bf05651a63eb..a3bce0e77581fb 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -641,6 +641,8 @@ Bug Fixes to C++ Support
   an implicitly instantiated class template specialization. (#GH51051)
 - Fixed an assertion failure caused by invalid enum forward declarations. 
(#GH112208)
 - Name independent data members were not correctly initialized from default 
member initializers. (#GH114069)
+- Fixed an assertion failure caused by invalid default argument substitutions 
in non-defining
+  friend declarations. (#GH113324).
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 5a001843e2ba46..0bbab95001ad8e 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4694,6 +4694,17 @@ bool Sema::InstantiateDefaultArgument(SourceLocation 
CallLoc, FunctionDecl *FD,
   ParmVarDecl *Param) {
   assert(Param->hasUninstantiatedDefaultArg());
 
+  // FIXME: We don't track member specialization info for non-defining
+  // friend declarations, so we will not be able to later find the function
+  // pattern. As a workaround, don't instantiate the default argument in this
+  // case. This is correct per wording and only an error recovery issue, as per
+  // [dcl.fct.default]p4:
+  //   if a friend declaration D specifies a default argument expression,
+  //   that declaration shall be a definition.
+  if (FD->getFriendObjectKind() != Decl::FOK_None &&
+  !FD->getTemplateInstantiationPattern())
+return true;
+
   // Instantiate the expression.
   //
   // FIXME: Pass in a correct Pattern argument, otherwise
diff --git a/clang/test/CXX/temp/temp.res/p4.cpp 
b/clang/test/CXX/temp/temp.res/p4.cpp
index f54d8649f5da88..cf6c45b4c351c5 100644
--- a/clang/test/CXX/temp/temp.res/p4.cpp
+++ b/clang/test/CXX/temp/temp.res/p4.cpp
@@ -185,3 +185,46 @@ template struct S {
   friend void X::f(T::type);
 };
 }
+
+namespace GH113324 {
+template  struct S1 {
+  friend void f1(S1, int = 0); // expected-error {{friend declaration 
specifying a default argument must be a definition}}
+  friend void f2(S1 a, S1 = decltype(a){}); // expected-error {{friend 
declaration specifying a default argument must be a definition}}
+};
+
+template  using alias = int;
+template  struct S2 {
+  // FIXME: We miss diagnosing the default argument instantiation failure
+  // (forming reference to void)
+  friend void f3(S2, int a = alias(1)); // expected-error {{friend 
declaration specifying a default argument must be a definition}}
+};
+
+struct S3 {
+  friend void f4(S3, int = 42) { }
+};
+
+template  using __enable_if_t = int;
+template  struct S4 {
+  static const int value = v;
+};
+struct S5 {
+  template <__enable_if_t::value, int> = 0>
+  S5(const char *);
+};
+struct S6 {
+  template 
+  friend void f5(int, S6, a, b, S5 = "") { }
+};
+
+void test() {
+  f1(S1<>{});
+  f2(S1<>{});
+  f3(S2());
+
+  S3 s3;
+  f4(s3);
+
+  S6 s6;
+  auto result = f5(0, s6, [] {}, [] {}); // expected-error {{variable has 
incomplete type 'void}}
+}
+} // namespace GH113324

``




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


[clang] [Clang] skip default argument instantiation for non-defining friend declarations to meet [dcl.fct.default] p4 (PR #115487)

2024-11-08 Thread Oleksandr T. via cfe-commits

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


[clang] [lldb] [llvm] Revert "[AArch64] Reduce +sve2-aes to an alias of +sve-aes+sve2 (#114… (PR #115539)

2024-11-08 Thread via cfe-commits

https://github.com/SpencerAbson created 
https://github.com/llvm/llvm-project/pull/115539

…293)"

This reverts commit da9499ebfb323602c42aeb674571fe89cec20ca6.

>From 8d4263cb961fe96d329ca23e090dab25e9b697cb Mon Sep 17 00:00:00 2001
From: SpencerAbson 
Date: Fri, 8 Nov 2024 19:43:36 +
Subject: [PATCH] Revert "[AArch64] Reduce +sve2-aes to an alias of
 +sve-aes+sve2 (#114293)"

This reverts commit da9499ebfb323602c42aeb674571fe89cec20ca6.
---
 clang/include/clang/Basic/arm_sve.td  |  2 +-
 clang/lib/Basic/Targets/AArch64.cpp   | 12 ---
 clang/lib/Basic/Targets/AArch64.h |  2 +-
 clang/test/CodeGen/aarch64-fmv-dependencies.c |  2 +-
 .../aarch64-sve2-intrinsics/acle_sve2_aesd.c  |  8 ++---
 .../aarch64-sve2-intrinsics/acle_sve2_aese.c  |  8 ++---
 .../acle_sve2_aesimc.c|  8 ++---
 .../aarch64-sve2-intrinsics/acle_sve2_aesmc.c |  8 ++---
 .../acle_sve2_pmullb_128.c|  8 ++---
 .../acle_sve2_pmullt_128.c|  8 ++---
 .../Driver/aarch64-implied-sve-features.c |  9 ++---
 .../print-supported-extensions-aarch64.c  |  7 ++--
 .../Preprocessor/aarch64-target-features.c| 12 ---
 .../acle_sve2_aes_bitperm_sha3_sm4.cpp| 32 +-
 .../command-disassemble-aarch64-extensions.s  |  2 +-
 llvm/lib/Target/AArch64/AArch64.td|  2 +-
 llvm/lib/Target/AArch64/AArch64FMV.td |  2 +-
 llvm/lib/Target/AArch64/AArch64Features.td| 11 +++
 llvm/lib/Target/AArch64/AArch64InstrInfo.td   |  4 +--
 .../lib/Target/AArch64/AArch64SVEInstrInfo.td |  2 +-
 .../AArch64/AsmParser/AArch64AsmParser.cpp|  3 +-
 .../CodeGen/AArch64/sve2-intrinsics-crypto.ll |  1 -
 llvm/test/MC/AArch64/SVE2/aesd.s  | 10 +++---
 llvm/test/MC/AArch64/SVE2/aese.s  | 10 +++---
 llvm/test/MC/AArch64/SVE2/aesimc.s| 12 +++
 llvm/test/MC/AArch64/SVE2/aesmc.s | 12 +++
 .../MC/AArch64/SVE2/directive-arch-negative.s |  6 ++--
 llvm/test/MC/AArch64/SVE2/directive-arch.s|  2 +-
 .../SVE2/directive-arch_extension-negative.s  |  6 ++--
 .../AArch64/SVE2/directive-arch_extension.s   |  2 +-
 .../MC/AArch64/SVE2/directive-cpu-negative.s  |  6 ++--
 llvm/test/MC/AArch64/SVE2/directive-cpu.s |  2 +-
 llvm/test/MC/AArch64/SVE2/pmullb-128.s| 10 +++---
 llvm/test/MC/AArch64/SVE2/pmullt-128.s| 10 +++---
 .../TargetParser/TargetParserTest.cpp | 33 +--
 35 files changed, 120 insertions(+), 154 deletions(-)

diff --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index b4bc4b7f61c347..90b1ec242e6bae 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -1962,7 +1962,7 @@ let SVETargetGuard = "sve2,lut,bf16", SMETargetGuard = 
"sme2,lut,bf16" in {
 

 // SVE2 - Optional
 
-let SVETargetGuard = "sve2,sve-aes", SMETargetGuard = InvalidMode in {
+let SVETargetGuard = "sve2-aes", SMETargetGuard = InvalidMode in {
 def SVAESD   : SInst<"svaesd[_{d}]",   "ddd", "Uc", MergeNone, 
"aarch64_sve_aesd", [IsOverloadNone]>;
 def SVAESIMC : SInst<"svaesimc[_{d}]", "dd",  "Uc", MergeNone, 
"aarch64_sve_aesimc", [IsOverloadNone]>;
 def SVAESE   : SInst<"svaese[_{d}]",   "ddd", "Uc", MergeNone, 
"aarch64_sve_aese", [IsOverloadNone]>;
diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index 3fd43373cab445..e35ee2b7b9c385 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -473,7 +473,7 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
   if (HasSVE2p1)
 Builder.defineMacro("__ARM_FEATURE_SVE2p1", "1");
 
-  if (HasSVE2 && HasSVEAES)
+  if (HasSVE2 && HasSVE2AES)
 Builder.defineMacro("__ARM_FEATURE_SVE2_AES", "1");
 
   if (HasSVE2 && HasSVE2BitPerm)
@@ -769,7 +769,7 @@ bool AArch64TargetInfo::hasFeature(StringRef Feature) const 
{
   .Case("f32mm", FPU & SveMode && HasMatmulFP32)
   .Case("f64mm", FPU & SveMode && HasMatmulFP64)
   .Case("sve2", FPU & SveMode && HasSVE2)
-  .Case("sve2-pmull128", FPU & SveMode && HasSVEAES && HasSVE2)
+  .Case("sve2-pmull128", FPU & SveMode && HasSVE2AES)
   .Case("sve2-bitperm", FPU & SveMode && HasSVE2BitPerm)
   .Case("sve2-sha3", FPU & SveMode && HasSVE2SHA3)
   .Case("sve2-sm4", FPU & SveMode && HasSVE2SM4)
@@ -861,10 +861,12 @@ bool 
AArch64TargetInfo::handleTargetFeatures(std::vector &Features,
   HasSVE2 = true;
   HasSVE2p1 = true;
 }
-if (Feature == "+sve-aes") {
+if (Feature == "+sve2-aes") {
   FPU |= NeonMode;
-  HasAES = true;
-  HasSVEAES = true;
+  FPU |= SveMode;
+  HasFullFP16 = true;
+  HasSVE2 = true;
+  HasSVE2AES = true;
 }
 if (Feature == "+sve2-sha3") {
   FPU |= NeonMode;
diff --git a/clang/lib/Basic/Targets/AArch64.h 
b/clang/lib/Basic

[clang] [lldb] [llvm] Revert "[AArch64] Reduce +sve2-aes to an alias of +sve-aes+sve2 (#114… (PR #115539)

2024-11-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: None (SpencerAbson)


Changes

…293)"

This reverts commit da9499ebfb323602c42aeb674571fe89cec20ca6.

---

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


35 Files Affected:

- (modified) clang/include/clang/Basic/arm_sve.td (+1-1) 
- (modified) clang/lib/Basic/Targets/AArch64.cpp (+7-5) 
- (modified) clang/lib/Basic/Targets/AArch64.h (+1-1) 
- (modified) clang/test/CodeGen/aarch64-fmv-dependencies.c (+1-1) 
- (modified) clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_aesd.c (+4-4) 
- (modified) clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_aese.c (+4-4) 
- (modified) clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_aesimc.c 
(+4-4) 
- (modified) clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_aesmc.c 
(+4-4) 
- (modified) clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_pmullb_128.c 
(+4-4) 
- (modified) clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_pmullt_128.c 
(+4-4) 
- (modified) clang/test/Driver/aarch64-implied-sve-features.c (+3-6) 
- (modified) clang/test/Driver/print-supported-extensions-aarch64.c (+3-4) 
- (modified) clang/test/Preprocessor/aarch64-target-features.c (-12) 
- (modified) 
clang/test/Sema/aarch64-sve2-intrinsics/acle_sve2_aes_bitperm_sha3_sm4.cpp 
(+16-16) 
- (modified) lldb/test/Shell/Commands/command-disassemble-aarch64-extensions.s 
(+1-1) 
- (modified) llvm/lib/Target/AArch64/AArch64.td (+1-1) 
- (modified) llvm/lib/Target/AArch64/AArch64FMV.td (+1-1) 
- (modified) llvm/lib/Target/AArch64/AArch64Features.td (+4-7) 
- (modified) llvm/lib/Target/AArch64/AArch64InstrInfo.td (+2-2) 
- (modified) llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td (+1-1) 
- (modified) llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp (+1-2) 
- (modified) llvm/test/CodeGen/AArch64/sve2-intrinsics-crypto.ll (-1) 
- (modified) llvm/test/MC/AArch64/SVE2/aesd.s (+5-5) 
- (modified) llvm/test/MC/AArch64/SVE2/aese.s (+5-5) 
- (modified) llvm/test/MC/AArch64/SVE2/aesimc.s (+6-6) 
- (modified) llvm/test/MC/AArch64/SVE2/aesmc.s (+6-6) 
- (modified) llvm/test/MC/AArch64/SVE2/directive-arch-negative.s (+3-3) 
- (modified) llvm/test/MC/AArch64/SVE2/directive-arch.s (+1-1) 
- (modified) llvm/test/MC/AArch64/SVE2/directive-arch_extension-negative.s 
(+3-3) 
- (modified) llvm/test/MC/AArch64/SVE2/directive-arch_extension.s (+1-1) 
- (modified) llvm/test/MC/AArch64/SVE2/directive-cpu-negative.s (+3-3) 
- (modified) llvm/test/MC/AArch64/SVE2/directive-cpu.s (+1-1) 
- (modified) llvm/test/MC/AArch64/SVE2/pmullb-128.s (+5-5) 
- (modified) llvm/test/MC/AArch64/SVE2/pmullt-128.s (+5-5) 
- (modified) llvm/unittests/TargetParser/TargetParserTest.cpp (+9-24) 


``diff
diff --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index b4bc4b7f61c347..90b1ec242e6bae 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -1962,7 +1962,7 @@ let SVETargetGuard = "sve2,lut,bf16", SMETargetGuard = 
"sme2,lut,bf16" in {
 

 // SVE2 - Optional
 
-let SVETargetGuard = "sve2,sve-aes", SMETargetGuard = InvalidMode in {
+let SVETargetGuard = "sve2-aes", SMETargetGuard = InvalidMode in {
 def SVAESD   : SInst<"svaesd[_{d}]",   "ddd", "Uc", MergeNone, 
"aarch64_sve_aesd", [IsOverloadNone]>;
 def SVAESIMC : SInst<"svaesimc[_{d}]", "dd",  "Uc", MergeNone, 
"aarch64_sve_aesimc", [IsOverloadNone]>;
 def SVAESE   : SInst<"svaese[_{d}]",   "ddd", "Uc", MergeNone, 
"aarch64_sve_aese", [IsOverloadNone]>;
diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index 3fd43373cab445..e35ee2b7b9c385 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -473,7 +473,7 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
   if (HasSVE2p1)
 Builder.defineMacro("__ARM_FEATURE_SVE2p1", "1");
 
-  if (HasSVE2 && HasSVEAES)
+  if (HasSVE2 && HasSVE2AES)
 Builder.defineMacro("__ARM_FEATURE_SVE2_AES", "1");
 
   if (HasSVE2 && HasSVE2BitPerm)
@@ -769,7 +769,7 @@ bool AArch64TargetInfo::hasFeature(StringRef Feature) const 
{
   .Case("f32mm", FPU & SveMode && HasMatmulFP32)
   .Case("f64mm", FPU & SveMode && HasMatmulFP64)
   .Case("sve2", FPU & SveMode && HasSVE2)
-  .Case("sve2-pmull128", FPU & SveMode && HasSVEAES && HasSVE2)
+  .Case("sve2-pmull128", FPU & SveMode && HasSVE2AES)
   .Case("sve2-bitperm", FPU & SveMode && HasSVE2BitPerm)
   .Case("sve2-sha3", FPU & SveMode && HasSVE2SHA3)
   .Case("sve2-sm4", FPU & SveMode && HasSVE2SM4)
@@ -861,10 +861,12 @@ bool 
AArch64TargetInfo::handleTargetFeatures(std::vector &Features,
   HasSVE2 = true;
   HasSVE2p1 = true;
 }
-if (Feature == "+sve-aes") {
+if (Feature == "+sve2-aes") {
   FPU |= NeonMode;
-  HasAES = true;
-  HasSVEAES = true;
+ 

[clang] [lldb] [llvm] Revert "[AArch64] Reduce +sve2-aes to an alias of +sve-aes+sve2 (#114… (PR #115539)

2024-11-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (SpencerAbson)


Changes

…293)"

This reverts commit da9499ebfb323602c42aeb674571fe89cec20ca6.

---

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


35 Files Affected:

- (modified) clang/include/clang/Basic/arm_sve.td (+1-1) 
- (modified) clang/lib/Basic/Targets/AArch64.cpp (+7-5) 
- (modified) clang/lib/Basic/Targets/AArch64.h (+1-1) 
- (modified) clang/test/CodeGen/aarch64-fmv-dependencies.c (+1-1) 
- (modified) clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_aesd.c (+4-4) 
- (modified) clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_aese.c (+4-4) 
- (modified) clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_aesimc.c 
(+4-4) 
- (modified) clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_aesmc.c 
(+4-4) 
- (modified) clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_pmullb_128.c 
(+4-4) 
- (modified) clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_pmullt_128.c 
(+4-4) 
- (modified) clang/test/Driver/aarch64-implied-sve-features.c (+3-6) 
- (modified) clang/test/Driver/print-supported-extensions-aarch64.c (+3-4) 
- (modified) clang/test/Preprocessor/aarch64-target-features.c (-12) 
- (modified) 
clang/test/Sema/aarch64-sve2-intrinsics/acle_sve2_aes_bitperm_sha3_sm4.cpp 
(+16-16) 
- (modified) lldb/test/Shell/Commands/command-disassemble-aarch64-extensions.s 
(+1-1) 
- (modified) llvm/lib/Target/AArch64/AArch64.td (+1-1) 
- (modified) llvm/lib/Target/AArch64/AArch64FMV.td (+1-1) 
- (modified) llvm/lib/Target/AArch64/AArch64Features.td (+4-7) 
- (modified) llvm/lib/Target/AArch64/AArch64InstrInfo.td (+2-2) 
- (modified) llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td (+1-1) 
- (modified) llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp (+1-2) 
- (modified) llvm/test/CodeGen/AArch64/sve2-intrinsics-crypto.ll (-1) 
- (modified) llvm/test/MC/AArch64/SVE2/aesd.s (+5-5) 
- (modified) llvm/test/MC/AArch64/SVE2/aese.s (+5-5) 
- (modified) llvm/test/MC/AArch64/SVE2/aesimc.s (+6-6) 
- (modified) llvm/test/MC/AArch64/SVE2/aesmc.s (+6-6) 
- (modified) llvm/test/MC/AArch64/SVE2/directive-arch-negative.s (+3-3) 
- (modified) llvm/test/MC/AArch64/SVE2/directive-arch.s (+1-1) 
- (modified) llvm/test/MC/AArch64/SVE2/directive-arch_extension-negative.s 
(+3-3) 
- (modified) llvm/test/MC/AArch64/SVE2/directive-arch_extension.s (+1-1) 
- (modified) llvm/test/MC/AArch64/SVE2/directive-cpu-negative.s (+3-3) 
- (modified) llvm/test/MC/AArch64/SVE2/directive-cpu.s (+1-1) 
- (modified) llvm/test/MC/AArch64/SVE2/pmullb-128.s (+5-5) 
- (modified) llvm/test/MC/AArch64/SVE2/pmullt-128.s (+5-5) 
- (modified) llvm/unittests/TargetParser/TargetParserTest.cpp (+9-24) 


``diff
diff --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index b4bc4b7f61c347..90b1ec242e6bae 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -1962,7 +1962,7 @@ let SVETargetGuard = "sve2,lut,bf16", SMETargetGuard = 
"sme2,lut,bf16" in {
 

 // SVE2 - Optional
 
-let SVETargetGuard = "sve2,sve-aes", SMETargetGuard = InvalidMode in {
+let SVETargetGuard = "sve2-aes", SMETargetGuard = InvalidMode in {
 def SVAESD   : SInst<"svaesd[_{d}]",   "ddd", "Uc", MergeNone, 
"aarch64_sve_aesd", [IsOverloadNone]>;
 def SVAESIMC : SInst<"svaesimc[_{d}]", "dd",  "Uc", MergeNone, 
"aarch64_sve_aesimc", [IsOverloadNone]>;
 def SVAESE   : SInst<"svaese[_{d}]",   "ddd", "Uc", MergeNone, 
"aarch64_sve_aese", [IsOverloadNone]>;
diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index 3fd43373cab445..e35ee2b7b9c385 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -473,7 +473,7 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
   if (HasSVE2p1)
 Builder.defineMacro("__ARM_FEATURE_SVE2p1", "1");
 
-  if (HasSVE2 && HasSVEAES)
+  if (HasSVE2 && HasSVE2AES)
 Builder.defineMacro("__ARM_FEATURE_SVE2_AES", "1");
 
   if (HasSVE2 && HasSVE2BitPerm)
@@ -769,7 +769,7 @@ bool AArch64TargetInfo::hasFeature(StringRef Feature) const 
{
   .Case("f32mm", FPU & SveMode && HasMatmulFP32)
   .Case("f64mm", FPU & SveMode && HasMatmulFP64)
   .Case("sve2", FPU & SveMode && HasSVE2)
-  .Case("sve2-pmull128", FPU & SveMode && HasSVEAES && HasSVE2)
+  .Case("sve2-pmull128", FPU & SveMode && HasSVE2AES)
   .Case("sve2-bitperm", FPU & SveMode && HasSVE2BitPerm)
   .Case("sve2-sha3", FPU & SveMode && HasSVE2SHA3)
   .Case("sve2-sm4", FPU & SveMode && HasSVE2SM4)
@@ -861,10 +861,12 @@ bool 
AArch64TargetInfo::handleTargetFeatures(std::vector &Features,
   HasSVE2 = true;
   HasSVE2p1 = true;
 }
-if (Feature == "+sve-aes") {
+if (Feature == "+sve2-aes") {
   FPU |= NeonMode;
-  HasAES = true;
-  HasSVEAES = true;
+

[clang] [lldb] [llvm] Revert "[AArch64] Reduce +sve2-aes to an alias of +sve-aes+sve2 (#114… (PR #115539)

2024-11-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: None (SpencerAbson)


Changes

…293)"

This reverts commit da9499ebfb323602c42aeb674571fe89cec20ca6.

---

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


35 Files Affected:

- (modified) clang/include/clang/Basic/arm_sve.td (+1-1) 
- (modified) clang/lib/Basic/Targets/AArch64.cpp (+7-5) 
- (modified) clang/lib/Basic/Targets/AArch64.h (+1-1) 
- (modified) clang/test/CodeGen/aarch64-fmv-dependencies.c (+1-1) 
- (modified) clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_aesd.c (+4-4) 
- (modified) clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_aese.c (+4-4) 
- (modified) clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_aesimc.c 
(+4-4) 
- (modified) clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_aesmc.c 
(+4-4) 
- (modified) clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_pmullb_128.c 
(+4-4) 
- (modified) clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_pmullt_128.c 
(+4-4) 
- (modified) clang/test/Driver/aarch64-implied-sve-features.c (+3-6) 
- (modified) clang/test/Driver/print-supported-extensions-aarch64.c (+3-4) 
- (modified) clang/test/Preprocessor/aarch64-target-features.c (-12) 
- (modified) 
clang/test/Sema/aarch64-sve2-intrinsics/acle_sve2_aes_bitperm_sha3_sm4.cpp 
(+16-16) 
- (modified) lldb/test/Shell/Commands/command-disassemble-aarch64-extensions.s 
(+1-1) 
- (modified) llvm/lib/Target/AArch64/AArch64.td (+1-1) 
- (modified) llvm/lib/Target/AArch64/AArch64FMV.td (+1-1) 
- (modified) llvm/lib/Target/AArch64/AArch64Features.td (+4-7) 
- (modified) llvm/lib/Target/AArch64/AArch64InstrInfo.td (+2-2) 
- (modified) llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td (+1-1) 
- (modified) llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp (+1-2) 
- (modified) llvm/test/CodeGen/AArch64/sve2-intrinsics-crypto.ll (-1) 
- (modified) llvm/test/MC/AArch64/SVE2/aesd.s (+5-5) 
- (modified) llvm/test/MC/AArch64/SVE2/aese.s (+5-5) 
- (modified) llvm/test/MC/AArch64/SVE2/aesimc.s (+6-6) 
- (modified) llvm/test/MC/AArch64/SVE2/aesmc.s (+6-6) 
- (modified) llvm/test/MC/AArch64/SVE2/directive-arch-negative.s (+3-3) 
- (modified) llvm/test/MC/AArch64/SVE2/directive-arch.s (+1-1) 
- (modified) llvm/test/MC/AArch64/SVE2/directive-arch_extension-negative.s 
(+3-3) 
- (modified) llvm/test/MC/AArch64/SVE2/directive-arch_extension.s (+1-1) 
- (modified) llvm/test/MC/AArch64/SVE2/directive-cpu-negative.s (+3-3) 
- (modified) llvm/test/MC/AArch64/SVE2/directive-cpu.s (+1-1) 
- (modified) llvm/test/MC/AArch64/SVE2/pmullb-128.s (+5-5) 
- (modified) llvm/test/MC/AArch64/SVE2/pmullt-128.s (+5-5) 
- (modified) llvm/unittests/TargetParser/TargetParserTest.cpp (+9-24) 


``diff
diff --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index b4bc4b7f61c347..90b1ec242e6bae 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -1962,7 +1962,7 @@ let SVETargetGuard = "sve2,lut,bf16", SMETargetGuard = 
"sme2,lut,bf16" in {
 

 // SVE2 - Optional
 
-let SVETargetGuard = "sve2,sve-aes", SMETargetGuard = InvalidMode in {
+let SVETargetGuard = "sve2-aes", SMETargetGuard = InvalidMode in {
 def SVAESD   : SInst<"svaesd[_{d}]",   "ddd", "Uc", MergeNone, 
"aarch64_sve_aesd", [IsOverloadNone]>;
 def SVAESIMC : SInst<"svaesimc[_{d}]", "dd",  "Uc", MergeNone, 
"aarch64_sve_aesimc", [IsOverloadNone]>;
 def SVAESE   : SInst<"svaese[_{d}]",   "ddd", "Uc", MergeNone, 
"aarch64_sve_aese", [IsOverloadNone]>;
diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index 3fd43373cab445..e35ee2b7b9c385 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -473,7 +473,7 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
   if (HasSVE2p1)
 Builder.defineMacro("__ARM_FEATURE_SVE2p1", "1");
 
-  if (HasSVE2 && HasSVEAES)
+  if (HasSVE2 && HasSVE2AES)
 Builder.defineMacro("__ARM_FEATURE_SVE2_AES", "1");
 
   if (HasSVE2 && HasSVE2BitPerm)
@@ -769,7 +769,7 @@ bool AArch64TargetInfo::hasFeature(StringRef Feature) const 
{
   .Case("f32mm", FPU & SveMode && HasMatmulFP32)
   .Case("f64mm", FPU & SveMode && HasMatmulFP64)
   .Case("sve2", FPU & SveMode && HasSVE2)
-  .Case("sve2-pmull128", FPU & SveMode && HasSVEAES && HasSVE2)
+  .Case("sve2-pmull128", FPU & SveMode && HasSVE2AES)
   .Case("sve2-bitperm", FPU & SveMode && HasSVE2BitPerm)
   .Case("sve2-sha3", FPU & SveMode && HasSVE2SHA3)
   .Case("sve2-sm4", FPU & SveMode && HasSVE2SM4)
@@ -861,10 +861,12 @@ bool 
AArch64TargetInfo::handleTargetFeatures(std::vector &Features,
   HasSVE2 = true;
   HasSVE2p1 = true;
 }
-if (Feature == "+sve-aes") {
+if (Feature == "+sve2-aes") {
   FPU |= NeonMode;
-  HasAES = true;
-  HasSVEAES = 

[clang] [lldb] [llvm] Revert "[AArch64] Reduce +sve2-aes to an alias of +sve-aes+sve2 (#114… (PR #115539)

2024-11-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-aarch64

Author: None (SpencerAbson)


Changes

…293)"

This reverts commit da9499ebfb323602c42aeb674571fe89cec20ca6.

---

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


35 Files Affected:

- (modified) clang/include/clang/Basic/arm_sve.td (+1-1) 
- (modified) clang/lib/Basic/Targets/AArch64.cpp (+7-5) 
- (modified) clang/lib/Basic/Targets/AArch64.h (+1-1) 
- (modified) clang/test/CodeGen/aarch64-fmv-dependencies.c (+1-1) 
- (modified) clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_aesd.c (+4-4) 
- (modified) clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_aese.c (+4-4) 
- (modified) clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_aesimc.c 
(+4-4) 
- (modified) clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_aesmc.c 
(+4-4) 
- (modified) clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_pmullb_128.c 
(+4-4) 
- (modified) clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_pmullt_128.c 
(+4-4) 
- (modified) clang/test/Driver/aarch64-implied-sve-features.c (+3-6) 
- (modified) clang/test/Driver/print-supported-extensions-aarch64.c (+3-4) 
- (modified) clang/test/Preprocessor/aarch64-target-features.c (-12) 
- (modified) 
clang/test/Sema/aarch64-sve2-intrinsics/acle_sve2_aes_bitperm_sha3_sm4.cpp 
(+16-16) 
- (modified) lldb/test/Shell/Commands/command-disassemble-aarch64-extensions.s 
(+1-1) 
- (modified) llvm/lib/Target/AArch64/AArch64.td (+1-1) 
- (modified) llvm/lib/Target/AArch64/AArch64FMV.td (+1-1) 
- (modified) llvm/lib/Target/AArch64/AArch64Features.td (+4-7) 
- (modified) llvm/lib/Target/AArch64/AArch64InstrInfo.td (+2-2) 
- (modified) llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td (+1-1) 
- (modified) llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp (+1-2) 
- (modified) llvm/test/CodeGen/AArch64/sve2-intrinsics-crypto.ll (-1) 
- (modified) llvm/test/MC/AArch64/SVE2/aesd.s (+5-5) 
- (modified) llvm/test/MC/AArch64/SVE2/aese.s (+5-5) 
- (modified) llvm/test/MC/AArch64/SVE2/aesimc.s (+6-6) 
- (modified) llvm/test/MC/AArch64/SVE2/aesmc.s (+6-6) 
- (modified) llvm/test/MC/AArch64/SVE2/directive-arch-negative.s (+3-3) 
- (modified) llvm/test/MC/AArch64/SVE2/directive-arch.s (+1-1) 
- (modified) llvm/test/MC/AArch64/SVE2/directive-arch_extension-negative.s 
(+3-3) 
- (modified) llvm/test/MC/AArch64/SVE2/directive-arch_extension.s (+1-1) 
- (modified) llvm/test/MC/AArch64/SVE2/directive-cpu-negative.s (+3-3) 
- (modified) llvm/test/MC/AArch64/SVE2/directive-cpu.s (+1-1) 
- (modified) llvm/test/MC/AArch64/SVE2/pmullb-128.s (+5-5) 
- (modified) llvm/test/MC/AArch64/SVE2/pmullt-128.s (+5-5) 
- (modified) llvm/unittests/TargetParser/TargetParserTest.cpp (+9-24) 


``diff
diff --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index b4bc4b7f61c347..90b1ec242e6bae 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -1962,7 +1962,7 @@ let SVETargetGuard = "sve2,lut,bf16", SMETargetGuard = 
"sme2,lut,bf16" in {
 

 // SVE2 - Optional
 
-let SVETargetGuard = "sve2,sve-aes", SMETargetGuard = InvalidMode in {
+let SVETargetGuard = "sve2-aes", SMETargetGuard = InvalidMode in {
 def SVAESD   : SInst<"svaesd[_{d}]",   "ddd", "Uc", MergeNone, 
"aarch64_sve_aesd", [IsOverloadNone]>;
 def SVAESIMC : SInst<"svaesimc[_{d}]", "dd",  "Uc", MergeNone, 
"aarch64_sve_aesimc", [IsOverloadNone]>;
 def SVAESE   : SInst<"svaese[_{d}]",   "ddd", "Uc", MergeNone, 
"aarch64_sve_aese", [IsOverloadNone]>;
diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index 3fd43373cab445..e35ee2b7b9c385 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -473,7 +473,7 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
   if (HasSVE2p1)
 Builder.defineMacro("__ARM_FEATURE_SVE2p1", "1");
 
-  if (HasSVE2 && HasSVEAES)
+  if (HasSVE2 && HasSVE2AES)
 Builder.defineMacro("__ARM_FEATURE_SVE2_AES", "1");
 
   if (HasSVE2 && HasSVE2BitPerm)
@@ -769,7 +769,7 @@ bool AArch64TargetInfo::hasFeature(StringRef Feature) const 
{
   .Case("f32mm", FPU & SveMode && HasMatmulFP32)
   .Case("f64mm", FPU & SveMode && HasMatmulFP64)
   .Case("sve2", FPU & SveMode && HasSVE2)
-  .Case("sve2-pmull128", FPU & SveMode && HasSVEAES && HasSVE2)
+  .Case("sve2-pmull128", FPU & SveMode && HasSVE2AES)
   .Case("sve2-bitperm", FPU & SveMode && HasSVE2BitPerm)
   .Case("sve2-sha3", FPU & SveMode && HasSVE2SHA3)
   .Case("sve2-sm4", FPU & SveMode && HasSVE2SM4)
@@ -861,10 +861,12 @@ bool 
AArch64TargetInfo::handleTargetFeatures(std::vector &Features,
   HasSVE2 = true;
   HasSVE2p1 = true;
 }
-if (Feature == "+sve-aes") {
+if (Feature == "+sve2-aes") {
   FPU |= NeonMode;
-  HasAES = true;
-  HasSVEAES

[clang] [llvm] [HLSL] Adding HLSL `clip` function. (PR #114588)

2024-11-08 Thread via cfe-commits

https://github.com/joaosaffran updated 
https://github.com/llvm/llvm-project/pull/114588

>From 087c2dfeffbadba4df12d5c429bb1e22e9034a3f Mon Sep 17 00:00:00 2001
From: Joao Saffran 
Date: Tue, 29 Oct 2024 19:39:31 +
Subject: [PATCH 1/5] adding llvm intrinsic

---
 clang/include/clang/Basic/Builtins.td |  6 ++
 clang/lib/CodeGen/CGBuiltin.cpp   | 10 ++
 clang/lib/CodeGen/CGHLSLRuntime.h |  1 +
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  | 17 +
 clang/lib/Sema/SemaHLSL.cpp   |  8 
 clang/test/CodeGenHLSL/builtins/clip.hlsl | 14 ++
 llvm/include/llvm/IR/IntrinsicsDirectX.td |  1 +
 llvm/include/llvm/IR/IntrinsicsSPIRV.td   |  1 +
 8 files changed, 58 insertions(+)
 create mode 100644 clang/test/CodeGenHLSL/builtins/clip.hlsl

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 4360e0bf9840f1..bbbace6e193e66 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4895,6 +4895,12 @@ def HLSLSplitDouble: LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
+def HLSLClip: LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_elementwise_clip"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "void(bool)";
+}
+
 // Builtins for XRay.
 def XRayCustomEvent : Builtin {
   let Spellings = ["__xray_customevent"];
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 430ac5626f89d7..2f3e094e882863 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -19180,6 +19180,16 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
"asuint operands types mismatch");
 return handleHlslSplitdouble(E, this);
   }
+  case Builtin::BI__builtin_hlsl_elementwise_clip:
+
+assert(E->getArg(0)->getType()->hasFloatingRepresentation() &&
+   "clip operands types mismatch");
+
+Value *Op0 = EmitScalarExpr(E->getArg(0));
+auto *CMP =
+Builder.CreateFCmpOLT(Op0, ConstantFP::get(Builder.getFloatTy(), 0.0));
+return Builder.CreateIntrinsic(
+VoidTy, CGM.getHLSLRuntime().getClipIntrinsic(), {CMP}, nullptr);
   }
   return nullptr;
 }
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h 
b/clang/lib/CodeGen/CGHLSLRuntime.h
index 381a5959ec098e..a1089595683a3d 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -94,6 +94,7 @@ class CGHLSLRuntime {
   GENERATE_HLSL_INTRINSIC_FUNCTION(WaveActiveCountBits, wave_active_countbits)
   GENERATE_HLSL_INTRINSIC_FUNCTION(WaveIsFirstLane, wave_is_first_lane)
   GENERATE_HLSL_INTRINSIC_FUNCTION(WaveReadLaneAt, wave_readlane)
+  GENERATE_HLSL_INTRINSIC_FUNCTION(Clip, clip)  
   GENERATE_HLSL_INTRINSIC_FUNCTION(FirstBitUHigh, firstbituhigh)
   GENERATE_HLSL_INTRINSIC_FUNCTION(FirstBitSHigh, firstbitshigh)
   GENERATE_HLSL_INTRINSIC_FUNCTION(NClamp, nclamp)
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 2ee3827d720495..f84f48fc1c122d 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -655,6 +655,23 @@ double3 clamp(double3, double3, double3);
 _HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_clamp)
 double4 clamp(double4, double4, double4);
 
+//===--===//
+// clip builtins
+//===--===//
+
+/// \fn void clip(T Val)
+/// \brief Discards the current pixel if the specified value is less than zero.
+/// \param Val The input value.
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_clip)
+void clip(float);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_clip)
+void clip(float2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_clip)
+void clip(float3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_clip)
+void clip(float4);
+
 
//===--===//
 // cos builtins
 
//===--===//
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 65b0d9cd65637f..32efb089ca1714 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -2135,6 +2135,14 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned 
BuiltinID, CallExpr *TheCall) {
   return true;
 break;
   }
+  case Builtin::BI__builtin_hlsl_elementwise_clip: {
+if (SemaRef.checkArgCount(TheCall, 1))
+  return true;
+
+if (CheckScalarOrVector(&SemaRef, TheCall, SemaRef.Context.FloatTy, 0))
+  return true;
+break;
+  }
   case Builtin::BI__builtin_elementwise_acos:
   case Builtin::BI__builtin_elementwise_asin:
   case Builtin::BI__builtin_elementwise_atan:
diff --git a/clang/test/CodeGenHLSL/builtins/clip.hlsl 
b/clang/test/CodeGenHLSL/builtins/clip.hlsl
new file mode 100644
index 00..4

[clang] [lldb] [llvm] [AArch64] Reduce +sve2-aes to an alias of +sve-aes+sve2 (PR #114293)

2024-11-08 Thread Alexandros Lamprineas via cfe-commits


@@ -6,10 +6,10 @@ tbx z0.b, z1.b, z2.b
 // CHECK: error: instruction requires: sve2 or sme
 // CHECK-NEXT: tbx z0.b, z1.b, z2.b
 
-.arch_extension sve2-aes
-.arch_extension nosve2-aes
+.arch_extension sve-aes
+.arch_extension nosve-aes

labrinea wrote:

Here you are replacing the old test instead of adding a new one. Now the 
(no)sve2-aes directives are not tested anywhere. Similarly in other files.

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


[clang] [lldb] [llvm] [AArch64] Reduce +sve2-aes to an alias of +sve-aes+sve2 (PR #114293)

2024-11-08 Thread Alexandros Lamprineas via cfe-commits

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


[clang] [llvm] [HLSL] Adding HLSL `clip` function. (PR #114588)

2024-11-08 Thread via cfe-commits

https://github.com/joaosaffran updated 
https://github.com/llvm/llvm-project/pull/114588

>From 087c2dfeffbadba4df12d5c429bb1e22e9034a3f Mon Sep 17 00:00:00 2001
From: Joao Saffran 
Date: Tue, 29 Oct 2024 19:39:31 +
Subject: [PATCH 1/5] adding llvm intrinsic

---
 clang/include/clang/Basic/Builtins.td |  6 ++
 clang/lib/CodeGen/CGBuiltin.cpp   | 10 ++
 clang/lib/CodeGen/CGHLSLRuntime.h |  1 +
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  | 17 +
 clang/lib/Sema/SemaHLSL.cpp   |  8 
 clang/test/CodeGenHLSL/builtins/clip.hlsl | 14 ++
 llvm/include/llvm/IR/IntrinsicsDirectX.td |  1 +
 llvm/include/llvm/IR/IntrinsicsSPIRV.td   |  1 +
 8 files changed, 58 insertions(+)
 create mode 100644 clang/test/CodeGenHLSL/builtins/clip.hlsl

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 4360e0bf9840f1..bbbace6e193e66 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4895,6 +4895,12 @@ def HLSLSplitDouble: LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
+def HLSLClip: LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_elementwise_clip"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "void(bool)";
+}
+
 // Builtins for XRay.
 def XRayCustomEvent : Builtin {
   let Spellings = ["__xray_customevent"];
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 430ac5626f89d7..2f3e094e882863 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -19180,6 +19180,16 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
"asuint operands types mismatch");
 return handleHlslSplitdouble(E, this);
   }
+  case Builtin::BI__builtin_hlsl_elementwise_clip:
+
+assert(E->getArg(0)->getType()->hasFloatingRepresentation() &&
+   "clip operands types mismatch");
+
+Value *Op0 = EmitScalarExpr(E->getArg(0));
+auto *CMP =
+Builder.CreateFCmpOLT(Op0, ConstantFP::get(Builder.getFloatTy(), 0.0));
+return Builder.CreateIntrinsic(
+VoidTy, CGM.getHLSLRuntime().getClipIntrinsic(), {CMP}, nullptr);
   }
   return nullptr;
 }
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h 
b/clang/lib/CodeGen/CGHLSLRuntime.h
index 381a5959ec098e..a1089595683a3d 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -94,6 +94,7 @@ class CGHLSLRuntime {
   GENERATE_HLSL_INTRINSIC_FUNCTION(WaveActiveCountBits, wave_active_countbits)
   GENERATE_HLSL_INTRINSIC_FUNCTION(WaveIsFirstLane, wave_is_first_lane)
   GENERATE_HLSL_INTRINSIC_FUNCTION(WaveReadLaneAt, wave_readlane)
+  GENERATE_HLSL_INTRINSIC_FUNCTION(Clip, clip)  
   GENERATE_HLSL_INTRINSIC_FUNCTION(FirstBitUHigh, firstbituhigh)
   GENERATE_HLSL_INTRINSIC_FUNCTION(FirstBitSHigh, firstbitshigh)
   GENERATE_HLSL_INTRINSIC_FUNCTION(NClamp, nclamp)
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 2ee3827d720495..f84f48fc1c122d 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -655,6 +655,23 @@ double3 clamp(double3, double3, double3);
 _HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_clamp)
 double4 clamp(double4, double4, double4);
 
+//===--===//
+// clip builtins
+//===--===//
+
+/// \fn void clip(T Val)
+/// \brief Discards the current pixel if the specified value is less than zero.
+/// \param Val The input value.
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_clip)
+void clip(float);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_clip)
+void clip(float2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_clip)
+void clip(float3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_clip)
+void clip(float4);
+
 
//===--===//
 // cos builtins
 
//===--===//
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 65b0d9cd65637f..32efb089ca1714 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -2135,6 +2135,14 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned 
BuiltinID, CallExpr *TheCall) {
   return true;
 break;
   }
+  case Builtin::BI__builtin_hlsl_elementwise_clip: {
+if (SemaRef.checkArgCount(TheCall, 1))
+  return true;
+
+if (CheckScalarOrVector(&SemaRef, TheCall, SemaRef.Context.FloatTy, 0))
+  return true;
+break;
+  }
   case Builtin::BI__builtin_elementwise_acos:
   case Builtin::BI__builtin_elementwise_asin:
   case Builtin::BI__builtin_elementwise_atan:
diff --git a/clang/test/CodeGenHLSL/builtins/clip.hlsl 
b/clang/test/CodeGenHLSL/builtins/clip.hlsl
new file mode 100644
index 00..4

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

2024-11-08 Thread Reid Kleckner via cfe-commits

rnk wrote:

We can adjust the rules around language linkage if we like, but the main reason 
we implement builtins this way is to support the MSVC intrinsic model, which is 
to declare extern "C" functions and mark them with `#pragma intrinsic(NAME)` 
like so:
```
extern "C" void _m_prefetchw(volatile const void *src);
#pragma intrinsic(_m_prefetchw)
// now it works like a builtin
```

winnt.h provides macros that do stuff like this without including our intrinsic 
headers, so anything they mention this way has to get implemented as a compiler 
built-in, otherwise users experience surprising linker errors like 
"_m[m]_prefetch symbol not defined".

The Clang project policy is to be MSVC-compatible enough to compile the system 
headers. Reimplementing the entire Intel intrinsic API as builtins is out of 
scope. Any non-system, user code using this mechanism to call Intel vector 
intrinsics should be updated to include immintrin.h instead.

As a side benefit, this is also good for compile time, since the immintrin.h 
header is a giant umbrella header that's very bad for compile time. See also 
[intrin0.h](https://github.com/llvm/llvm-project/blob/main/clang/lib/Headers/intrin0.h),
 which the MSVC STL uses as a compile time optimization.

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


[clang] [llvm] [HLSL] Adding HLSL `clip` function. (PR #114588)

2024-11-08 Thread via cfe-commits

https://github.com/joaosaffran updated 
https://github.com/llvm/llvm-project/pull/114588

>From 087c2dfeffbadba4df12d5c429bb1e22e9034a3f Mon Sep 17 00:00:00 2001
From: Joao Saffran 
Date: Tue, 29 Oct 2024 19:39:31 +
Subject: [PATCH 1/5] adding llvm intrinsic

---
 clang/include/clang/Basic/Builtins.td |  6 ++
 clang/lib/CodeGen/CGBuiltin.cpp   | 10 ++
 clang/lib/CodeGen/CGHLSLRuntime.h |  1 +
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  | 17 +
 clang/lib/Sema/SemaHLSL.cpp   |  8 
 clang/test/CodeGenHLSL/builtins/clip.hlsl | 14 ++
 llvm/include/llvm/IR/IntrinsicsDirectX.td |  1 +
 llvm/include/llvm/IR/IntrinsicsSPIRV.td   |  1 +
 8 files changed, 58 insertions(+)
 create mode 100644 clang/test/CodeGenHLSL/builtins/clip.hlsl

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 4360e0bf9840f1..bbbace6e193e66 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4895,6 +4895,12 @@ def HLSLSplitDouble: LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
+def HLSLClip: LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_elementwise_clip"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "void(bool)";
+}
+
 // Builtins for XRay.
 def XRayCustomEvent : Builtin {
   let Spellings = ["__xray_customevent"];
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 430ac5626f89d7..2f3e094e882863 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -19180,6 +19180,16 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
"asuint operands types mismatch");
 return handleHlslSplitdouble(E, this);
   }
+  case Builtin::BI__builtin_hlsl_elementwise_clip:
+
+assert(E->getArg(0)->getType()->hasFloatingRepresentation() &&
+   "clip operands types mismatch");
+
+Value *Op0 = EmitScalarExpr(E->getArg(0));
+auto *CMP =
+Builder.CreateFCmpOLT(Op0, ConstantFP::get(Builder.getFloatTy(), 0.0));
+return Builder.CreateIntrinsic(
+VoidTy, CGM.getHLSLRuntime().getClipIntrinsic(), {CMP}, nullptr);
   }
   return nullptr;
 }
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h 
b/clang/lib/CodeGen/CGHLSLRuntime.h
index 381a5959ec098e..a1089595683a3d 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -94,6 +94,7 @@ class CGHLSLRuntime {
   GENERATE_HLSL_INTRINSIC_FUNCTION(WaveActiveCountBits, wave_active_countbits)
   GENERATE_HLSL_INTRINSIC_FUNCTION(WaveIsFirstLane, wave_is_first_lane)
   GENERATE_HLSL_INTRINSIC_FUNCTION(WaveReadLaneAt, wave_readlane)
+  GENERATE_HLSL_INTRINSIC_FUNCTION(Clip, clip)  
   GENERATE_HLSL_INTRINSIC_FUNCTION(FirstBitUHigh, firstbituhigh)
   GENERATE_HLSL_INTRINSIC_FUNCTION(FirstBitSHigh, firstbitshigh)
   GENERATE_HLSL_INTRINSIC_FUNCTION(NClamp, nclamp)
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 2ee3827d720495..f84f48fc1c122d 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -655,6 +655,23 @@ double3 clamp(double3, double3, double3);
 _HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_clamp)
 double4 clamp(double4, double4, double4);
 
+//===--===//
+// clip builtins
+//===--===//
+
+/// \fn void clip(T Val)
+/// \brief Discards the current pixel if the specified value is less than zero.
+/// \param Val The input value.
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_clip)
+void clip(float);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_clip)
+void clip(float2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_clip)
+void clip(float3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_clip)
+void clip(float4);
+
 
//===--===//
 // cos builtins
 
//===--===//
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 65b0d9cd65637f..32efb089ca1714 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -2135,6 +2135,14 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned 
BuiltinID, CallExpr *TheCall) {
   return true;
 break;
   }
+  case Builtin::BI__builtin_hlsl_elementwise_clip: {
+if (SemaRef.checkArgCount(TheCall, 1))
+  return true;
+
+if (CheckScalarOrVector(&SemaRef, TheCall, SemaRef.Context.FloatTy, 0))
+  return true;
+break;
+  }
   case Builtin::BI__builtin_elementwise_acos:
   case Builtin::BI__builtin_elementwise_asin:
   case Builtin::BI__builtin_elementwise_atan:
diff --git a/clang/test/CodeGenHLSL/builtins/clip.hlsl 
b/clang/test/CodeGenHLSL/builtins/clip.hlsl
new file mode 100644
index 00..4

[clang] [Clang] add wraps and no_wraps attributes (PR #115094)

2024-11-08 Thread Justin Stitt via cfe-commits


@@ -433,6 +433,26 @@ Attribute Changes in Clang
 - Fix a bug where clang doesn't automatically apply the ``[[gsl::Owner]]`` or
   ``[[gsl::Pointer]]`` to STL explicit template specialization decls. 
(#GH109442)
 
+- Introduced ``__attribute__((wraps))`` which can be added to type or variable
+  declarations. Using an attributed type or variable in an arithmetic
+  expression will define the overflow behavior for that expression as having
+  two's complement wrap-around. These expressions will not be instrumented by
+  overflow sanitizers nor will they cause integer overflow warnings. They also
+  cannot be optimized away by some eager UB optimizations as the behavior of
+  the arithmetic is no longer "undefined".
+
+  There is also ``__attribute__((no_wraps))`` which can be added to types or
+  variable declarations. Types or variables with this attribute may be
+  instrumented by overflow sanitizers, if enabled. Note that this matches the
+  default behavior of integer types. So, in most cases, ``no_wraps`` serves

JustinStitt wrote:

When used alongside very strict SSCLs there is great utility to be gained from 
`no_wraps`.

In the kernel we want to use an SSCL ignorelist like this:
```
[{signed-integer-overflow,unsigned-integer-overflow}]
type:*
```

then annotate specific types like `size_t` in source:

``` cpp
typedef __kernel_size_tsize_t __attribute__((no_wraps));
```


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


[clang] [Clang] add wraps and no_wraps attributes (PR #115094)

2024-11-08 Thread Justin Stitt via cfe-commits

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


[clang] [Clang] add wraps and no_wraps attributes (PR #115094)

2024-11-08 Thread Justin Stitt via cfe-commits


@@ -8710,3 +8710,103 @@ Declares that a function potentially allocates heap 
memory, and prevents any pot
 of ``nonallocating`` by the compiler.
   }];
 }
+
+def WrapsDocs : Documentation {
+  let Category = DocCatField;
+  let Content = [{
+The ``wraps`` attribute can be used with type or variable declarations to
+denote that arithmetic containing attributed types or variables have defined
+overflow behavior. Specifically, the behavior is defined as being consistent
+with two's complement wrap-around. For the purposes of sanitizers or warnings
+that concern themselves with the definedness of integer arithmetic, they will
+cease to instrument or warn about arithmetic that directly involves operands
+attributed with the ``wraps`` attribute.
+
+The ``signed-integer-overflow``, ``unsigned-integer-overflow``,
+``implicit-signed-integer-truncation`` and the

JustinStitt wrote:

The entire intention of `wraps` is to _disable_ instrumentation entirely. We 
never want a report or trap out of such expressions. Developers who have very 
intentional wrapping arithmetic should be able to delegate types as "wrapping" 
and move on with their day.

Furthermore, most of the use of `no_wraps` is in conjunction with SSCLs to 
further control overflow behavior at the type-level. Sanitizer recovery modes 
remain separate from all of this.

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


[clang] [Clang] add wraps and no_wraps attributes (PR #115094)

2024-11-08 Thread Justin Stitt via cfe-commits

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


[clang] [Clang] add wraps and no_wraps attributes (PR #115094)

2024-11-08 Thread Justin Stitt via cfe-commits


@@ -8710,3 +8710,103 @@ Declares that a function potentially allocates heap 
memory, and prevents any pot
 of ``nonallocating`` by the compiler.
   }];
 }
+
+def WrapsDocs : Documentation {
+  let Category = DocCatField;
+  let Content = [{
+The ``wraps`` attribute can be used with type or variable declarations to
+denote that arithmetic containing attributed types or variables have defined
+overflow behavior. Specifically, the behavior is defined as being consistent
+with two's complement wrap-around. For the purposes of sanitizers or warnings
+that concern themselves with the definedness of integer arithmetic, they will
+cease to instrument or warn about arithmetic that directly involves operands
+attributed with the ``wraps`` attribute.
+
+The ``signed-integer-overflow``, ``unsigned-integer-overflow``,
+``implicit-signed-integer-truncation`` and the
+``implicit-unsigned-integer-truncation`` sanitizers will not instrument
+arithmetic containing any operands attributed by ``wraps``. Similarly, the
+``-Winteger-overflow`` warning is disabled for these instances.
+
+The following example shows how one may disable ``signed-integer-overflow``
+sanitizer instrumentation using ``__attribute__((wraps))`` on a type definition
+when building with ``-fsanitize=signed-integer-overflow``:
+
+.. code-block:: c
+
+  typedef int __attribute__((wraps)) wrapping_int;
+
+  void foo(void) {
+wrapping_int A = INT_MAX;
+++A; // no sanitizer instrumentation
+  }
+
+``wraps`` may also be used with function parameters or declarations of
+variables as well as members of structures. Using ``wraps`` on non-integer
+types will result in a ``-Wuseless-wraps-attribute`` warning. One may disable
+this warning with ``-Wno-useless-wraps-attribute``.
+
+``wraps`` persists through implicit type promotions and will be applied to the
+result type of arithmetic expressions containing a wrapping operand.
+``-Wimplicitly-discarded-wraps-attribute`` warnings can be caused in situations
+where the ``wraps`` attribute cannot persist through implicit type conversions.
+Disable this with ``-Wno-implicitly-discarded-wraps-attribute``.
+}];
+}
+
+def NoWrapsDocs : Documentation {
+  let Category = DocCatField;
+  let Content = [{
+The ``no_wraps`` attribute can be used to annotate types or variables as
+non-wrapping. This may serve as a helpful annotation to readers of code that
+particular arithmetic expressions involving these types or variables are not
+meant to wrap-around.
+
+When overflow or truncation sanitizer instrumentation is modified at the
+type-level through `SSCLs
+`_, ``no_wraps`` or
+``wraps`` may be used to override sanitizer behavior.
+
+For example, one may specify an ignorelist (with ``-fsanitize-ignorelist=``) to
+disable the ``signed-integer-overflow`` sanitizer for all types:
+
+.. code-block:: text
+
+  [signed-integer-overflow]
+  type:*
+
+``no_wraps`` can override the behavior provided by the ignorelist to

JustinStitt wrote:

Read my other comments about `no_wraps` + SSCLs and recovery modes. I don't 
think any consideration to recovery modes should be made from `wraps` or 
`no_wraps`. These attributes only care about sanitizer instrumentation and 
_not_ the handling thereof.

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


[clang] [Clang] Add support for scoped atomic thread fence (PR #115545)

2024-11-08 Thread Matt Arsenault via cfe-commits


@@ -5133,6 +5133,135 @@ RValue CodeGenFunction::EmitBuiltinExpr(const 
GlobalDecl GD, unsigned BuiltinID,
 Builder.SetInsertPoint(ContBB);
 return RValue::get(nullptr);
   }
+  case Builtin::BI__scoped_atomic_thread_fence: {
+auto ScopeModel = AtomicScopeModel::create(AtomicScopeModelKind::Generic);
+
+Value *Order = EmitScalarExpr(E->getArg(0));
+Value *Scope = EmitScalarExpr(E->getArg(1));
+if (isa(Order) && isa(Scope)) {
+  int Ord = cast(Order)->getZExtValue();
+  int Scp = cast(Scope)->getZExtValue();
+  SyncScope SS = ScopeModel->isValid(Scp)
+ ? ScopeModel->map(Scp)
+ : ScopeModel->map(ScopeModel->getFallBackValue());
+  switch (Ord) {
+  case 0:  // memory_order_relaxed
+  default: // invalid order
+break;
+  case 1: // memory_order_consume
+  case 2: // memory_order_acquire
+Builder.CreateFence(
+llvm::AtomicOrdering::Acquire,
+getTargetHooks().getLLVMSyncScopeID(getLangOpts(), SS,
+llvm::AtomicOrdering::Acquire,
+getLLVMContext()));
+break;
+  case 3: // memory_order_release
+Builder.CreateFence(
+llvm::AtomicOrdering::Release,
+getTargetHooks().getLLVMSyncScopeID(getLangOpts(), SS,
+llvm::AtomicOrdering::Release,
+getLLVMContext()));
+break;
+  case 4: // memory_order_acq_rel
+Builder.CreateFence(llvm::AtomicOrdering::AcquireRelease,
+getTargetHooks().getLLVMSyncScopeID(
+getLangOpts(), SS,
+llvm::AtomicOrdering::AcquireRelease,
+getLLVMContext()));
+break;
+  case 5: // memory_order_seq_cst
+Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent,
+getTargetHooks().getLLVMSyncScopeID(
+getLangOpts(), SS,
+llvm::AtomicOrdering::SequentiallyConsistent,
+getLLVMContext()));
+break;
+  }
+  return RValue::get(nullptr);
+}
+
+llvm::BasicBlock *ContBB = createBasicBlock("atomic.scope.continue", 
CurFn);
+
+llvm::DenseMap OrderBBs;
+if (isa(Order)) {
+  int Ord = cast(Order)->getZExtValue();

arsenm wrote:

dyn_cast 

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


[clang] [Clang] Add support for scoped atomic thread fence (PR #115545)

2024-11-08 Thread Matt Arsenault via cfe-commits


@@ -5133,6 +5133,135 @@ RValue CodeGenFunction::EmitBuiltinExpr(const 
GlobalDecl GD, unsigned BuiltinID,
 Builder.SetInsertPoint(ContBB);
 return RValue::get(nullptr);
   }
+  case Builtin::BI__scoped_atomic_thread_fence: {
+auto ScopeModel = AtomicScopeModel::create(AtomicScopeModelKind::Generic);
+
+Value *Order = EmitScalarExpr(E->getArg(0));
+Value *Scope = EmitScalarExpr(E->getArg(1));
+if (isa(Order) && isa(Scope)) {
+  int Ord = cast(Order)->getZExtValue();
+  int Scp = cast(Scope)->getZExtValue();
+  SyncScope SS = ScopeModel->isValid(Scp)
+ ? ScopeModel->map(Scp)
+ : ScopeModel->map(ScopeModel->getFallBackValue());
+  switch (Ord) {
+  case 0:  // memory_order_relaxed
+  default: // invalid order
+break;
+  case 1: // memory_order_consume
+  case 2: // memory_order_acquire
+Builder.CreateFence(
+llvm::AtomicOrdering::Acquire,
+getTargetHooks().getLLVMSyncScopeID(getLangOpts(), SS,
+llvm::AtomicOrdering::Acquire,
+getLLVMContext()));
+break;
+  case 3: // memory_order_release
+Builder.CreateFence(
+llvm::AtomicOrdering::Release,
+getTargetHooks().getLLVMSyncScopeID(getLangOpts(), SS,
+llvm::AtomicOrdering::Release,
+getLLVMContext()));
+break;
+  case 4: // memory_order_acq_rel
+Builder.CreateFence(llvm::AtomicOrdering::AcquireRelease,
+getTargetHooks().getLLVMSyncScopeID(
+getLangOpts(), SS,
+llvm::AtomicOrdering::AcquireRelease,
+getLLVMContext()));
+break;
+  case 5: // memory_order_seq_cst
+Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent,
+getTargetHooks().getLLVMSyncScopeID(
+getLangOpts(), SS,
+llvm::AtomicOrdering::SequentiallyConsistent,
+getLLVMContext()));
+break;
+  }
+  return RValue::get(nullptr);
+}
+
+llvm::BasicBlock *ContBB = createBasicBlock("atomic.scope.continue", 
CurFn);
+
+llvm::DenseMap OrderBBs;
+if (isa(Order)) {
+  int Ord = cast(Order)->getZExtValue();
+  switch (Ord) {
+  case 0:  // memory_order_relaxed
+  default: // invalid order
+ContBB->eraseFromParent();
+return RValue::get(nullptr);
+  case 1: // memory_order_consume
+  case 2: // memory_order_acquire
+OrderBBs[Builder.GetInsertBlock()] = llvm::AtomicOrdering::Acquire;
+break;
+  case 3: // memory_order_release
+OrderBBs[Builder.GetInsertBlock()] = llvm::AtomicOrdering::Release;
+break;
+  case 4: // memory_order_acq_rel
+OrderBBs[Builder.GetInsertBlock()] =
+llvm::AtomicOrdering::AcquireRelease;
+break;
+  case 5: // memory_order_seq_cst
+OrderBBs[Builder.GetInsertBlock()] =
+llvm::AtomicOrdering::SequentiallyConsistent;
+break;
+  }
+} else {
+  llvm::BasicBlock *AcquireBB, *ReleaseBB, *AcqRelBB, *SeqCstBB;
+  AcquireBB = createBasicBlock("acquire", CurFn);
+  ReleaseBB = createBasicBlock("release", CurFn);
+  AcqRelBB = createBasicBlock("acqrel", CurFn);
+  SeqCstBB = createBasicBlock("seqcst", CurFn);

arsenm wrote:

declare and initialize on each line 

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


[clang] [Clang] add wraps and no_wraps attributes (PR #115094)

2024-11-08 Thread Justin Stitt via cfe-commits

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


[clang] [-Wunsafe-buffer-usage] Fix false positives for string literals (PR #115554)

2024-11-08 Thread via cfe-commits

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


[clang] [Clang] add wraps and no_wraps attributes (PR #115094)

2024-11-08 Thread Justin Stitt via cfe-commits

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


[clang] [Clang][perf-training] Do build of libLLVMSupport for perf training (PR #111625)

2024-11-08 Thread Chris B via cfe-commits

https://github.com/llvm-beanz approved this pull request.

Love it!

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


[clang] [Clang] skip warnings for constructors marked with the [[noreturn]] attribute (PR #115558)

2024-11-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Oleksandr T. (a-tarasyuk)


Changes

Fixes #63009

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/lib/Analysis/CFG.cpp (+10-5) 
- (modified) clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp (+12) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c3424e0e6f34c9..11d0e35d12a786 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -527,6 +527,8 @@ Improvements to Clang's diagnostics
 
 - Clang now diagnoses ``[[deprecated]]`` attribute usage on local variables 
(#GH90073).
 
+- Clang now omits warnings for constructors marked with the ``[[noreturn]]`` 
attribute (#GH63009).
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp
index f678ac6f2ff36a..4d83f04c23060a 100644
--- a/clang/lib/Analysis/CFG.cpp
+++ b/clang/lib/Analysis/CFG.cpp
@@ -4889,16 +4889,21 @@ CFGBlock 
*CFGBuilder::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E,
   return Visit(E->getSubExpr(), asc);
 }
 
-CFGBlock *CFGBuilder::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *C,
+CFGBlock *CFGBuilder::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E,
   AddStmtChoice asc) {
   // If the constructor takes objects as arguments by value, we need to 
properly
   // construct these objects. Construction contexts we find here aren't for the
   // constructor C, they're for its arguments only.
-  findConstructionContextsForArguments(C);
+  findConstructionContextsForArguments(E);
 
-  autoCreateBlock();
-  appendConstructor(Block, C);
-  return VisitChildren(C);
+  CXXConstructorDecl *C = E->getConstructor();
+  if (C && C->isNoReturn())
+Block = createNoReturnBlock();
+  else
+autoCreateBlock();
+
+  appendConstructor(Block, E);
+  return VisitChildren(E);
 }
 
 CFGBlock *CFGBuilder::VisitImplicitCastExpr(ImplicitCastExpr *E,
diff --git a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp 
b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp
index 56920ea8e8cf20..a96224dd03e360 100644
--- a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp
+++ b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp
@@ -49,3 +49,15 @@ void check() {
   test_type(g);
   test_type(h); // expected-note {{instantiation}}
 }
+
+namespace GH63009 {
+struct S {
+  [[noreturn]] S() { throw int {}; }
+};
+
+int test_no_return_constructor() { S(); } // ok
+
+int main() {
+  test_no_return_constructor();
+}
+}

``




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


[clang] [Clang] skip warnings for constructors marked with the [[noreturn]] attribute (PR #115558)

2024-11-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-analysis

Author: Oleksandr T. (a-tarasyuk)


Changes

Fixes #63009

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/lib/Analysis/CFG.cpp (+10-5) 
- (modified) clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp (+12) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c3424e0e6f34c9..11d0e35d12a786 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -527,6 +527,8 @@ Improvements to Clang's diagnostics
 
 - Clang now diagnoses ``[[deprecated]]`` attribute usage on local variables 
(#GH90073).
 
+- Clang now omits warnings for constructors marked with the ``[[noreturn]]`` 
attribute (#GH63009).
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp
index f678ac6f2ff36a..4d83f04c23060a 100644
--- a/clang/lib/Analysis/CFG.cpp
+++ b/clang/lib/Analysis/CFG.cpp
@@ -4889,16 +4889,21 @@ CFGBlock 
*CFGBuilder::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E,
   return Visit(E->getSubExpr(), asc);
 }
 
-CFGBlock *CFGBuilder::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *C,
+CFGBlock *CFGBuilder::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E,
   AddStmtChoice asc) {
   // If the constructor takes objects as arguments by value, we need to 
properly
   // construct these objects. Construction contexts we find here aren't for the
   // constructor C, they're for its arguments only.
-  findConstructionContextsForArguments(C);
+  findConstructionContextsForArguments(E);
 
-  autoCreateBlock();
-  appendConstructor(Block, C);
-  return VisitChildren(C);
+  CXXConstructorDecl *C = E->getConstructor();
+  if (C && C->isNoReturn())
+Block = createNoReturnBlock();
+  else
+autoCreateBlock();
+
+  appendConstructor(Block, E);
+  return VisitChildren(E);
 }
 
 CFGBlock *CFGBuilder::VisitImplicitCastExpr(ImplicitCastExpr *E,
diff --git a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp 
b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp
index 56920ea8e8cf20..a96224dd03e360 100644
--- a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp
+++ b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp
@@ -49,3 +49,15 @@ void check() {
   test_type(g);
   test_type(h); // expected-note {{instantiation}}
 }
+
+namespace GH63009 {
+struct S {
+  [[noreturn]] S() { throw int {}; }
+};
+
+int test_no_return_constructor() { S(); } // ok
+
+int main() {
+  test_no_return_constructor();
+}
+}

``




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


[clang] [Clang] add wraps and no_wraps attributes (PR #115094)

2024-11-08 Thread Justin Stitt via cfe-commits


@@ -8710,3 +8710,103 @@ Declares that a function potentially allocates heap 
memory, and prevents any pot
 of ``nonallocating`` by the compiler.
   }];
 }
+
+def WrapsDocs : Documentation {
+  let Category = DocCatField;
+  let Content = [{
+The ``wraps`` attribute can be used with type or variable declarations to
+denote that arithmetic containing attributed types or variables have defined
+overflow behavior. Specifically, the behavior is defined as being consistent
+with two's complement wrap-around. For the purposes of sanitizers or warnings
+that concern themselves with the definedness of integer arithmetic, they will
+cease to instrument or warn about arithmetic that directly involves operands
+attributed with the ``wraps`` attribute.
+
+The ``signed-integer-overflow``, ``unsigned-integer-overflow``,
+``implicit-signed-integer-truncation`` and the
+``implicit-unsigned-integer-truncation`` sanitizers will not instrument
+arithmetic containing any operands attributed by ``wraps``. Similarly, the
+``-Winteger-overflow`` warning is disabled for these instances.
+
+The following example shows how one may disable ``signed-integer-overflow``
+sanitizer instrumentation using ``__attribute__((wraps))`` on a type definition
+when building with ``-fsanitize=signed-integer-overflow``:
+
+.. code-block:: c
+
+  typedef int __attribute__((wraps)) wrapping_int;
+
+  void foo(void) {
+wrapping_int A = INT_MAX;
+++A; // no sanitizer instrumentation
+  }
+
+``wraps`` may also be used with function parameters or declarations of
+variables as well as members of structures. Using ``wraps`` on non-integer
+types will result in a ``-Wuseless-wraps-attribute`` warning. One may disable
+this warning with ``-Wno-useless-wraps-attribute``.
+
+``wraps`` persists through implicit type promotions and will be applied to the
+result type of arithmetic expressions containing a wrapping operand.
+``-Wimplicitly-discarded-wraps-attribute`` warnings can be caused in situations
+where the ``wraps`` attribute cannot persist through implicit type conversions.
+Disable this with ``-Wno-implicitly-discarded-wraps-attribute``.
+}];
+}
+
+def NoWrapsDocs : Documentation {
+  let Category = DocCatField;
+  let Content = [{
+The ``no_wraps`` attribute can be used to annotate types or variables as
+non-wrapping. This may serve as a helpful annotation to readers of code that
+particular arithmetic expressions involving these types or variables are not
+meant to wrap-around.
+
+When overflow or truncation sanitizer instrumentation is modified at the
+type-level through `SSCLs
+`_, ``no_wraps`` or
+``wraps`` may be used to override sanitizer behavior.
+
+For example, one may specify an ignorelist (with ``-fsanitize-ignorelist=``) to
+disable the ``signed-integer-overflow`` sanitizer for all types:
+
+.. code-block:: text
+
+  [signed-integer-overflow]
+  type:*
+
+``no_wraps`` can override the behavior provided by the ignorelist to

JustinStitt wrote:

But I see what you're saying about `__attribute__((sanitize(...)))`. Do you 
think we should use `__attribute__((sanitize(...)))` instead of 
`__attribute__((no_wraps))`? I think this may become confusing to users who 
think this is turning on a sanitizer, which is not what it does; It really is 
stating that something is "sanitizeable".

And for `wraps`, maybe you prefer `__attribute__((no_sanitize(...)))` over 
`__attribute__((wraps))`?

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


[clang] [Clang] skip warnings for constructors marked with the [[noreturn]] attribute (PR #115558)

2024-11-08 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk created 
https://github.com/llvm/llvm-project/pull/115558

Fixes #63009

>From f63263a1aa4873a63918649ea92352eb5cfe66eb Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Sat, 9 Nov 2024 00:41:13 +0200
Subject: [PATCH] [Clang] skip warnings for constructors marked with the
 [[noreturn]] attribute

---
 clang/docs/ReleaseNotes.rst   |  2 ++
 clang/lib/Analysis/CFG.cpp| 15 ++-
 .../CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp | 12 
 3 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c3424e0e6f34c9..11d0e35d12a786 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -527,6 +527,8 @@ Improvements to Clang's diagnostics
 
 - Clang now diagnoses ``[[deprecated]]`` attribute usage on local variables 
(#GH90073).
 
+- Clang now omits warnings for constructors marked with the ``[[noreturn]]`` 
attribute (#GH63009).
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp
index f678ac6f2ff36a..4d83f04c23060a 100644
--- a/clang/lib/Analysis/CFG.cpp
+++ b/clang/lib/Analysis/CFG.cpp
@@ -4889,16 +4889,21 @@ CFGBlock 
*CFGBuilder::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E,
   return Visit(E->getSubExpr(), asc);
 }
 
-CFGBlock *CFGBuilder::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *C,
+CFGBlock *CFGBuilder::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E,
   AddStmtChoice asc) {
   // If the constructor takes objects as arguments by value, we need to 
properly
   // construct these objects. Construction contexts we find here aren't for the
   // constructor C, they're for its arguments only.
-  findConstructionContextsForArguments(C);
+  findConstructionContextsForArguments(E);
 
-  autoCreateBlock();
-  appendConstructor(Block, C);
-  return VisitChildren(C);
+  CXXConstructorDecl *C = E->getConstructor();
+  if (C && C->isNoReturn())
+Block = createNoReturnBlock();
+  else
+autoCreateBlock();
+
+  appendConstructor(Block, E);
+  return VisitChildren(E);
 }
 
 CFGBlock *CFGBuilder::VisitImplicitCastExpr(ImplicitCastExpr *E,
diff --git a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp 
b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp
index 56920ea8e8cf20..a96224dd03e360 100644
--- a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp
+++ b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp
@@ -49,3 +49,15 @@ void check() {
   test_type(g);
   test_type(h); // expected-note {{instantiation}}
 }
+
+namespace GH63009 {
+struct S {
+  [[noreturn]] S() { throw int {}; }
+};
+
+int test_no_return_constructor() { S(); } // ok
+
+int main() {
+  test_no_return_constructor();
+}
+}

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


[clang] [Clang] add wraps and no_wraps attributes (PR #115094)

2024-11-08 Thread Justin Stitt via cfe-commits


@@ -8710,3 +8710,103 @@ Declares that a function potentially allocates heap 
memory, and prevents any pot
 of ``nonallocating`` by the compiler.
   }];
 }
+
+def WrapsDocs : Documentation {
+  let Category = DocCatField;
+  let Content = [{
+The ``wraps`` attribute can be used with type or variable declarations to
+denote that arithmetic containing attributed types or variables have defined

JustinStitt wrote:

Yes, good idea.

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


[clang] [Clang] add wraps and no_wraps attributes (PR #115094)

2024-11-08 Thread Justin Stitt via cfe-commits

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


[clang] [Clang] add wraps and no_wraps attributes (PR #115094)

2024-11-08 Thread Justin Stitt via cfe-commits


@@ -0,0 +1,48 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only -triple x86_64-pc-linux-gnu
+typedef int __attribute__((wraps)) wrapping_int;

JustinStitt wrote:

> Can we test more types?

Yes, I'll add some more tests 😄 

> 
> Can the attributes be applied to pointers? Both the pointer itself and the 
> pointee? It's worth adding tests, just to ensure nothing regresses here.

Pointers no:
```
warning: using attribute 'wraps' with non-integer type 'char *' has no function 
and is potentially misleading [-Wuseless-wraps-attribute]
2 |   char *A __attribute__((wraps));
```

pointees yes:
```
  char B __attribute__((wraps)) = 127;
  char *A = &B;
  (++B); // no -fsanitize=implicit-signed-integer-truncation splat!
```



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


[clang] [clang][bytecode] Fix resource leak and use-after-free issues in CallBI function (PR #115496)

2024-11-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (smanna12)


Changes

This commit addresses two static analyzer issues in the CallBI function:

Resource Leak: Ensures that the NewFrame object is properly managed by 
releasing ownership when InterpretBuiltin returns true, preventing a resource 
leak.

Use-After-Free: Ensures that S.Current is correctly reset to the previous frame 
(FrameBefore) after InterpretBuiltin returns true, preventing a use-after-free 
error.

The changes ensure that the NewFrame object is not prematurely deleted and that 
the interpreter state is correctly restored in case of failure.


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


1 Files Affected:

- (modified) clang/lib/AST/ByteCode/Interp.cpp (+7-1) 


``diff
diff --git a/clang/lib/AST/ByteCode/Interp.cpp 
b/clang/lib/AST/ByteCode/Interp.cpp
index 0e571624ae18d1..dd1236b6d6115d 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -1374,9 +1374,15 @@ bool CallBI(InterpState &S, CodePtr OpPC, const Function 
*Func,
   S.Current = NewFrame.get();
 
   if (InterpretBuiltin(S, OpPC, Func, CE, BuiltinID)) {
-NewFrame.release();
+// Release ownership of NewFrame to prevent it from being deleted.
+NewFrame.release(); // Frame was deleted already.
+// Ensure that S.Current is correctly reset to the previous frame.
+assert(S.Current == FrameBefore);
 return true;
   }
+
+  // Interpreting the function failed somehow. Reset to
+  // previous state.
   S.Current = FrameBefore;
   return false;
 }

``




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


[clang] 6737ba4 - Update the lifetimebound doc.

2024-11-08 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2024-11-08T16:25:26+01:00
New Revision: 6737ba40406030cd8a7ea706cd56302f8be7a4b4

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

LOG: Update the lifetimebound doc.

The lifetimebound attr is not C++ only anymore after 
8b29c05b73310bba3d7abd007dbbd839c46b0ab4

Added: 


Modified: 
clang/include/clang/Basic/AttrDocs.td

Removed: 




diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 23c8eb2d163c86..b64dbef6332e6a 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -3858,8 +3858,7 @@ def LifetimeBoundDocs : Documentation {
 The ``lifetimebound`` attribute on a function parameter or implicit object
 parameter indicates that objects that are referred to by that parameter may
 also be referred to by the return value of the annotated function (or, for a
-parameter of a constructor, by the value of the constructed object). It is only
-supported in C++.
+parameter of a constructor, by the value of the constructed object).
 
 By default, a reference is considered to refer to its referenced object, a
 pointer is considered to refer to its pointee, a ``std::initializer_list``



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


[clang] [clang][FMV] Pass the '+fmv' target-feature when FMV is enabled. (PR #87942)

2024-11-08 Thread Alexandros Lamprineas via cfe-commits

https://github.com/labrinea updated 
https://github.com/llvm/llvm-project/pull/87942

>From 38eea2eca0a852965f6b3d2037c5c0f2905ce6db Mon Sep 17 00:00:00 2001
From: Alexandros Lamprineas 
Date: Sun, 7 Apr 2024 16:04:12 +0100
Subject: [PATCH] [clang][FMV] Pass the '+fmv' target-feature when FMV is
 enabled.

This will allow the backend to enable the corresponding subtarget
feature (FeatureFMV), which in turn can be queried for llvm codegen
decisions. See #87939 for example.
---
 clang/lib/Driver/ToolChains/Clang.cpp | 13 +++--
 clang/test/Driver/aarch64-features.c  |  1 +
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 766a9b91e3c0ad..13dbd8ab261d3d 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7815,13 +7815,14 @@ void Clang::ConstructJob(Compilation &C, const 
JobAction &JA,
 
   addOutlineAtomicsArgs(D, getToolChain(), Args, CmdArgs, Triple);
 
-  if (Triple.isAArch64() &&
-  (Args.hasArg(options::OPT_mno_fmv) ||
-   (Triple.isAndroid() && Triple.isAndroidVersionLT(23)) ||
-   getToolChain().GetRuntimeLibType(Args) != ToolChain::RLT_CompilerRT)) {
-// Disable Function Multiversioning on AArch64 target.
+  if (Triple.isAArch64()) {
 CmdArgs.push_back("-target-feature");
-CmdArgs.push_back("-fmv");
+if (Args.hasArg(options::OPT_mno_fmv) ||
+(Triple.isAndroid() && Triple.isAndroidVersionLT(23)) ||
+getToolChain().GetRuntimeLibType(Args) != ToolChain::RLT_CompilerRT)
+  CmdArgs.push_back("-fmv");
+else
+  CmdArgs.push_back("+fmv");
   }
 
   if (Args.hasFlag(options::OPT_faddrsig, options::OPT_fno_addrsig,
diff --git a/clang/test/Driver/aarch64-features.c 
b/clang/test/Driver/aarch64-features.c
index d2075c91314a8b..4f401ea65232f2 100644
--- a/clang/test/Driver/aarch64-features.c
+++ b/clang/test/Driver/aarch64-features.c
@@ -24,6 +24,7 @@
 
 // CHECK-FMV-OFF: "-target-feature" "-fmv"
 // CHECK-FMV-NOT: "-target-feature" "-fmv"
+// CHECK-FMV: "-target-feature" "+fmv"
 
 // Check for AArch64 out-of-line atomics default settings.
 // RUN: %clang --target=aarch64-linux-android -rtlib=compiler-rt \

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


[clang] [Clang] Add __ugly__ spelling for the msvc attribute scope (PR #113765)

2024-11-08 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

@AaronBallman I'm not _super_ worried about these specific cases, but I'd like 
to know how to proceed with `msvc` attributes we'd like to use in libc++ 
generally. e.g. `msvc::intrinsic` would be quite nice and doesn't actually need 
to be bound to the MSVC ABI. Also, as more and more attributes can't be 
_Uglified due to Microsoft not feeling like it there will inevitably be a clash 
somewhere. I'd also be fine with not providing anything for MSVC-only 
attributes but providing an alternate spelling for attributes that are useful 
outside the MSVC ABI. It'd suck having to work around that my not using the 
obviously correct tool `__has_attribute(msvc::no_unique_address)` though.

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


[clang] c955228 - [clang][x86] Add constexpr support for MMX _mm_set*_pi* intrinsics

2024-11-08 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2024-11-08T15:30:02Z
New Revision: c9552283c0bf277eba490cde9fd913510f4111c0

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

LOG: [clang][x86] Add constexpr support for MMX _mm_set*_pi* intrinsics

Added: 


Modified: 
clang/lib/Headers/mmintrin.h
clang/test/CodeGen/X86/builtin_test_helpers.h
clang/test/CodeGen/X86/mmx-builtins.c

Removed: 




diff  --git a/clang/lib/Headers/mmintrin.h b/clang/lib/Headers/mmintrin.h
index 0347c5ccf8254a..dc0fa5c523eeb6 100644
--- a/clang/lib/Headers/mmintrin.h
+++ b/clang/lib/Headers/mmintrin.h
@@ -49,6 +49,12 @@ typedef char __v16qi __attribute__((__vector_size__(16)));
  __min_vector_width__(128)))
 #endif
 
+#if defined(__cplusplus) && (__cplusplus >= 201103L)
+#define __DEFAULT_FN_ATTRS_SSE2_CONSTEXPR __DEFAULT_FN_ATTRS_SSE2 constexpr
+#else
+#define __DEFAULT_FN_ATTRS_SSE2_CONSTEXPR __DEFAULT_FN_ATTRS_SSE2
+#endif
+
 #define __trunc64(x)   
\
   (__m64) __builtin_shufflevector((__v2di)(x), __extension__(__v2di){}, 0)
 #define __anyext128(x) 
\
@@ -1332,10 +1338,9 @@ _mm_cmpgt_pi32(__m64 __m1, __m64 __m2)
 /// This intrinsic corresponds to the  PXOR  instruction.
 ///
 /// \returns An initialized 64-bit integer vector with all elements set to 
zero.
-static __inline__ __m64 __DEFAULT_FN_ATTRS_SSE2
-_mm_setzero_si64(void)
-{
-return __extension__ (__m64){ 0LL };
+static __inline__ __m64 __DEFAULT_FN_ATTRS_SSE2_CONSTEXPR
+_mm_setzero_si64(void) {
+  return __extension__(__m64){0LL};
 }
 
 /// Constructs a 64-bit integer vector initialized with the specified
@@ -1353,10 +1358,9 @@ _mm_setzero_si64(void)
 ///A 32-bit integer value used to initialize the lower 32 bits of the
 ///result.
 /// \returns An initialized 64-bit integer vector.
-static __inline__ __m64 __DEFAULT_FN_ATTRS_SSE2
-_mm_set_pi32(int __i1, int __i0)
-{
-return __extension__ (__m64)(__v2si){__i0, __i1};
+static __inline__ __m64 __DEFAULT_FN_ATTRS_SSE2_CONSTEXPR
+_mm_set_pi32(int __i1, int __i0) {
+  return __extension__(__m64)(__v2si){__i0, __i1};
 }
 
 /// Constructs a 64-bit integer vector initialized with the specified
@@ -1376,10 +1380,9 @@ _mm_set_pi32(int __i1, int __i0)
 /// \param __s0
 ///A 16-bit integer value used to initialize bits [15:0] of the result.
 /// \returns An initialized 64-bit integer vector.
-static __inline__ __m64 __DEFAULT_FN_ATTRS_SSE2
-_mm_set_pi16(short __s3, short __s2, short __s1, short __s0)
-{
-return __extension__ (__m64)(__v4hi){__s0, __s1, __s2, __s3};
+static __inline__ __m64 __DEFAULT_FN_ATTRS_SSE2_CONSTEXPR
+_mm_set_pi16(short __s3, short __s2, short __s1, short __s0) {
+  return __extension__(__m64)(__v4hi){__s0, __s1, __s2, __s3};
 }
 
 /// Constructs a 64-bit integer vector initialized with the specified
@@ -1407,12 +1410,11 @@ _mm_set_pi16(short __s3, short __s2, short __s1, short 
__s0)
 /// \param __b0
 ///An 8-bit integer value used to initialize bits [7:0] of the result.
 /// \returns An initialized 64-bit integer vector.
-static __inline__ __m64 __DEFAULT_FN_ATTRS_SSE2
+static __inline__ __m64 __DEFAULT_FN_ATTRS_SSE2_CONSTEXPR
 _mm_set_pi8(char __b7, char __b6, char __b5, char __b4, char __b3, char __b2,
-char __b1, char __b0)
-{
-return __extension__ (__m64)(__v8qi){__b0, __b1, __b2, __b3,
- __b4, __b5, __b6, __b7};
+char __b1, char __b0) {
+  return __extension__(__m64)(__v8qi){__b0, __b1, __b2, __b3,
+  __b4, __b5, __b6, __b7};
 }
 
 /// Constructs a 64-bit integer vector of [2 x i32], with each of the
@@ -1428,10 +1430,9 @@ _mm_set_pi8(char __b7, char __b6, char __b5, char __b4, 
char __b3, char __b2,
 ///A 32-bit integer value used to initialize each vector element of the
 ///result.
 /// \returns An initialized 64-bit integer vector of [2 x i32].
-static __inline__ __m64 __DEFAULT_FN_ATTRS_SSE2
-_mm_set1_pi32(int __i)
-{
-return _mm_set_pi32(__i, __i);
+static __inline__ __m64 __DEFAULT_FN_ATTRS_SSE2_CONSTEXPR
+_mm_set1_pi32(int __i) {
+  return _mm_set_pi32(__i, __i);
 }
 
 /// Constructs a 64-bit integer vector of [4 x i16], with each of the
@@ -1447,10 +1448,9 @@ _mm_set1_pi32(int __i)
 ///A 16-bit integer value used to initialize each vector element of the
 ///result.
 /// \returns An initialized 64-bit integer vector of [4 x i16].
-static __inline__ __m64 __DEFAULT_FN_ATTRS_SSE2
-_mm_set1_pi16(short __w)
-{
-return _mm_set_pi16(__w, __w, __w, __w);
+static __inline__ __m64 __DEFAULT_FN_ATTRS_SSE2_CONSTEXPR
+_mm_set1_pi16(short __w) {
+  return _mm_set_pi16(__w, __w, __w, __w);
 }
 
 /// Constructs a 6

[clang] [clang-format] clang-format-ignore: Add support for double asterisk patterns (PR #110560)

2024-11-08 Thread Ameer J via cfe-commits


@@ -164,6 +164,40 @@ TEST_F(MatchFilePathTest, Path) {
   EXPECT_FALSE(match("foo\\", R"(foo*\)"));
 }
 
+TEST_F(MatchFilePathTest, DoubleAsterisk) {
+  EXPECT_TRUE(match("a/b/c/d.cpp", "**b**"));
+  EXPECT_TRUE(match("a/b/c/d.cpp", "**/b/**"));
+  EXPECT_TRUE(match("a/b/c/d_e.cpp", "**d_*"));
+  EXPECT_TRUE(match("a/b/c/d_e.cpp", "**/d_*"));
+  EXPECT_TRUE(match("a/b/c/d_e.cpp", "**d_**"));
+  EXPECT_TRUE(match("a/b/c/d_e.cpp", "**/d_**"));
+
+  EXPECT_TRUE(match("a/b/c/d_e.cpp", "**/b/c/**"));
+
+  EXPECT_TRUE(match("a/b/c/d_e.cpp", "a/**/b/c/d_e.cpp"));
+  EXPECT_TRUE(match("a/b/c/d_e.cpp", "a/**/c/d_e.cpp"));
+  EXPECT_TRUE(match("a/b/c/d_e.cpp", "a/**/b/**/d_e.cpp"));
+  EXPECT_TRUE(match("a/b/c/d_e.cpp", "**/b/**/d_e.cpp"));
+  EXPECT_TRUE(match("a/b/c/d_e.cpp", "a/**/**/b/**"));
+
+  EXPECT_FALSE(match("a/b/c/d_e.cpp", "**/d"));
+  EXPECT_FALSE(match("a/b/c/d_e.cpp", "**/b/d"));
+  EXPECT_FALSE(match("a/b/c/d_e.cpp", "**/b/d/**"));
+  EXPECT_FALSE(match("a/b/c/d_e.cpp", "**/b/c/"));
+
+  // Multiple consecutive asterisks are treated as **
+  EXPECT_TRUE(match("a/b/c/d.cpp", "***b"));
+  EXPECT_TRUE(match("a/b/c/d.cpp", "/b/***"));
+  EXPECT_TRUE(match("a/b/c/d_e.cpp", "***d_**"));
+  EXPECT_TRUE(match("a/b/c/d_e.cpp", "/d_*"));
+  EXPECT_TRUE(match("a/b/c/d_e.cpp", "***/b/c/*"));
+
+  EXPECT_FALSE(match("a/b/c/d_e.cpp", "*/d"));
+  EXPECT_FALSE(match("a/b/c/d_e.cpp", "***/b/d"));
+  EXPECT_FALSE(match("a/b/c/d_e.cpp", "*/b/d/***"));
+  EXPECT_FALSE(match("a/b/c/d_e.cpp", "***/b/c"));

ameerj wrote:

> How did you manage before clang-format gained the .clang-format-ignore 
> functionality?

PAL has not used clang-format at all, my contributions have been an effort to 
support the PAL formatting style so we can start to use the tool.

> > * Simplifying Subdirectory Exclusion: `**` allows for easy exclusion of 
> > entire subdirectories. Currently you need to specify each depth level in a 
> > subdirectory individually.
> 
> We have `DisableFormat` for that.

I was not aware of `DisableFormat`, it's not as intuitive as having everything 
in the ignore file but it can be a compromise if you're completely opposed to 
adding the `**` change. 


> > * Pattern-Based File Ignoring: `**` simplifies ignoring specific file 
> > patterns that may appear at any level within a directory tree, which is 
> > especially useful when the exact depth of these files can vary
> 
> I was conscious of this use case, but you can do something like `find . -name 
> dont-format-me >> .clang-format-ignore` even though it's less than ideal.

Like you said, this is not ideal as it relies on anyone adding/moving files 
that may need to be ignored to regenerate the clang-format-ignore file.

`**` could handle these cases without a need for manual intervention.

> If we were to add `**` to match gitignore, we should also handle it at the 
> beginning and the end of a pathname.

Are you seeing a gap in the unit tests I have? I think I have these cases 
covered but can add more specific unit tests if you have an example.

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


[clang] [Clang] SemaFunctionEffects: When verifying a function, ignore any conditional noexcept expression. (PR #115342)

2024-11-08 Thread Doug Wyatt via cfe-commits


@@ -986,9 +987,22 @@ class Analyzer {
   if (auto *Dtor = dyn_cast(CurrentCaller.CDecl))
 followDestructor(dyn_cast(Dtor->getParent()), Dtor);
 
-  if (auto *FD = dyn_cast(CurrentCaller.CDecl))
+  if (auto *FD = dyn_cast(CurrentCaller.CDecl)) {
 TrailingRequiresClause = FD->getTrailingRequiresClause();
 
+// Note that FD->getType->getAs() can yield a
+// noexcept Expr which has been boiled down to a constant expression.
+// Going through the TypeSourceInfo obtains the actual expression which
+// will be traversed as part of the function -- unless we capture it
+// here and have TraverseStmt skip it.
+if (TypeSourceInfo *TSI = FD->getTypeSourceInfo()) {
+  FunctionProtoTypeLoc TL =
+  TSI->getTypeLoc().getAs();
+  if (const FunctionProtoType *FPT = TL.getTypePtr())
+NoexceptExpr = FPT->getNoexceptExpr();
+}
+  }
+
   // Do an AST traversal of the function/block body
   TraverseDecl(const_cast(CurrentCaller.CDecl));

dougsonos wrote:

That's a good thought. Looking at `TraverseFunctionHelper`:
- the template arguments should be ignorable.
- need to traverse the function's type because it contains the parameters -- 
e.g. I caught someone passing a vector by value instead of by reference and 
that showed up first as a call to the vector's destructor, located in the 
parameter list.
- but the function's type is where the noexcept expression comes from.
- can skip the trailing return clause.
- need to traverse the constructor initializers.
- need to traverse the body of course.

I'm not excited to tear this apart at the moment but maybe the next bug that 
comes up in this area can drive an improvement.

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


[clang] [Clang] Fix name lookup for dependent bases (PR #114978)

2024-11-08 Thread Matheus Izvekov via cfe-commits

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

LGTM, but give some time for @sdkrystian to take a look, since he is actively 
working on this area.

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


[clang] [C2y] Add test coverage and documentation for WG14 N3341 (PR #115478)

2024-11-08 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman updated 
https://github.com/llvm/llvm-project/pull/115478

>From 5a9ac5588527cf76b1933a3efbc2285c7670126b Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Fri, 8 Nov 2024 08:18:18 -0500
Subject: [PATCH 1/2] [C2y] Add test coverage and documentation for WG14 N3341

This paper made empty structures and unions implementation-defined. We
have always supported this as a GNU extension, so now we're documenting
our behavior and removing the extension warning in C2y mode.
---
 clang/docs/LanguageExtensions.rst |  9 +
 clang/docs/ReleaseNotes.rst   |  6 ++
 clang/lib/Sema/SemaDecl.cpp   | 11 ++-
 clang/test/C/C2y/n3341.c  | 16 
 4 files changed, 37 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/C/C2y/n3341.c

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index f7285352b9deb9..4dea35d74ced07 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -5974,3 +5974,12 @@ Clang guarantees the following behaviors:
   padding bits are initialized to zero.
 
 Currently, the above extension only applies to C source code, not C++.
+
+Empty Objects in C
+==
+The declaration of a structure or union type which has no named members is
+undefined behavior (C23 and earlier) or implementation-defined behavior (C2y).
+Clang allows the declaration of a structure or union type with no named members
+in all C language modes. `sizeof` for such a type returns `0`, which is
+different behavior than in C++ (where the size of such an object is typically
+`1`).
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d0c43ff11f7bae..e41b9f0fab1035 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -298,6 +298,12 @@ C2y Feature Support
   paper adopts Clang's existing practice, so there were no changes to compiler
   behavior.
 
+- Implemented support for `N3341 
`_
+  which makes empty structure and union objects implementation-defined in C.
+  ``-Wgnu-empty-struct`` will be emitted in C23 and earlier modes because the
+  behavior is a conforming GNU extension in those modes, but will no longer
+  have an effect in C2y mode.
+
 C23 Feature Support
 ^^^
 
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 6b0b4840a1eb2c..61c29e320d5c73 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -19365,11 +19365,12 @@ void Sema::ActOnFields(Scope *S, SourceLocation 
RecLoc, Decl *EnclosingDecl,
   }
 
   // Structs without named members are extension in C (C99 6.7.2.1p7),
-  // but are accepted by GCC.
-  if (NonBitFields == 0 && !getLangOpts().CPlusPlus) {
-Diag(RecLoc, IsEmpty ? diag::ext_empty_struct_union :
-   diag::ext_no_named_members_in_struct_union)
-  << Record->isUnion();
+  // but are accepted by GCC. In C2y, this became implementation-defined
+  // (C2y 6.7.3.2p10).
+  if (NonBitFields == 0 && !getLangOpts().CPlusPlus && !getLangOpts().C2y) 
{
+Diag(RecLoc, IsEmpty ? diag::ext_empty_struct_union
+ : diag::ext_no_named_members_in_struct_union)
+<< Record->isUnion();
   }
 }
   } else {
diff --git a/clang/test/C/C2y/n3341.c b/clang/test/C/C2y/n3341.c
new file mode 100644
index 00..523c3dd945ac1d
--- /dev/null
+++ b/clang/test/C/C2y/n3341.c
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -verify -std=c2y -Wall -pedantic %s
+// RUN: %clang_cc1 -verify=gnu -Wall -pedantic %s
+
+/* WG14 N3341: Yes
+ * Slay Some Earthly Demons III
+ *
+ * Empty structure and union objects are now implementation-defined.
+ */
+
+// expected-no-diagnostics
+
+struct R {};   // gnu-warning {{empty struct is a GNU extension}}
+struct S { struct { }; };  // gnu-warning {{empty struct is a GNU extension}}
+struct T { int : 0; }; // gnu-warning {{struct without named members is a 
GNU extension}}
+union U {};// gnu-warning {{empty union is a GNU extension}}
+

>From 3f207565e98c25ba83d4f9279d2bfa90cd649f53 Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Fri, 8 Nov 2024 08:20:18 -0500
Subject: [PATCH 2/2] Updating the website as well

---
 clang/www/c_status.html | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/www/c_status.html b/clang/www/c_status.html
index 989a572ae70fb6..809b4dd1bfee0e 100644
--- a/clang/www/c_status.html
+++ b/clang/www/c_status.html
@@ -191,7 +191,7 @@ C2y implementation status
 
   Slay Some Earthly Demons III
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3341.pdf";>N3341
-  Unknown
+  Yes
 
 
   Slay Some Earthly Demons IV

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

[clang] c3c2f46 - [C2y] Claim conformance and add test coverage for WG14 N3346 (#115516)

2024-11-08 Thread via cfe-commits

Author: Aaron Ballman
Date: 2024-11-08T12:43:19-05:00
New Revision: c3c2f46f7bd5891af13fef56a8754007f11ff6c1

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

LOG: [C2y] Claim conformance and add test coverage for WG14 N3346 (#115516)

This converts some undefined behaviors during initialization to instead
be constraint violations. Clang has always implemented these as
constraints, so no compiler changes were needed.

Added: 
clang/test/C/C2y/n3346.c

Modified: 
clang/docs/ReleaseNotes.rst
clang/www/c_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d4bf05651a63eb..77ba5f1d79bcdb 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -303,6 +303,11 @@ C2y Feature Support
   undefined. Clang has always accepted ``const`` and ``volatile`` qualified
   function types by ignoring the qualifiers.
 
+- Updated conformance for `N3346 
`_
+  which changes some undefined behavior around initialization to instead be
+  constraint violations. This paper adopts Clang's existing practice, so there
+  were no changes to compiler behavior.
+
 C23 Feature Support
 ^^^
 

diff  --git a/clang/test/C/C2y/n3346.c b/clang/test/C/C2y/n3346.c
new file mode 100644
index 00..2f0ef51d56fb76
--- /dev/null
+++ b/clang/test/C/C2y/n3346.c
@@ -0,0 +1,68 @@
+// RUN: %clang_cc1 -verify -std=c2y -Wall -pedantic -ffreestanding %s
+// RUN: %clang_cc1 -verify=expected,ped -Wall -pedantic -ffreestanding %s
+
+/* WG14 N3346: Yes
+ * Slay Some Earthly Demons VIII
+ *
+ * Updates some undefined behavior during initialization to instead be a
+ * constraint violation.
+ */
+
+// The initializer for a scalar shall be a single expression, optionally
+// enclosed in braces, or it shall be an empty initializer.
+int i = 12, j = {12}, k = {}; // ped-warning {{use of an empty initializer is 
a C23 extension}}
+
+struct S {
+  int i;
+  float f;
+  int : 0;
+  char c;
+};
+
+void test1(void) {
+  // The initializer for an object that has structure or union type shall be
+  // either a single expression that has compatible type or a brace-enclosed
+  // list of initializers for the elements or named members.
+  struct S s1 = { 1, 1.2f, 'a' };
+  struct S s2 = s1;
+
+  // Despite being structurally identical to S, T is not compatible with S.
+  struct T { int i; float f; int : 0; char c; } t;
+  struct S s3 = t; // expected-error {{initializing 'struct S' with an 
expression of incompatible type 'struct T'}}
+}
+
+void test2(void) {
+  typedef __WCHAR_TYPE__ wchar_t;
+  typedef __CHAR16_TYPE__ char16_t;
+  typedef __CHAR32_TYPE__ char32_t;
+
+  // The initializer for an array shall be either a string literal, optionally
+  // enclosed in braces, or a brace-enclosed list of initializers for the
+  // elements. An array initialized by character string literal or UTF-8 string
+  // literal shall have a character type as element type. An array initialized
+  // with a wide string literal shall have element type compatible with a
+  // qualified or unqualified wchar_t, char16_t, or char32_t, and the string
+  // literal shall have the corresponding encoding prefix (L, u, or U,
+  // respectively).
+  char str1[] = "string literal";
+  char str2[] = { "string literal" };
+  char str3[] = u8"string literal";
+  char str4[] = { u8"string literal" };
+
+  int str5[] = "this doesn't work";  // expected-error {{array 
initializer must be an initializer list}}
+  int str6[] = { "this also doesn't work" }; // expected-error {{incompatible 
pointer to integer conversion initializing 'int' with an expression of type 
'char[23]'}}
+
+  wchar_t str7[] = L"string literal";
+  wchar_t str8[] = { L"string literal" };
+  char16_t str9[] = u"string literal";
+  char16_t str10[] = { u"string literal" };
+  char32_t str11[] = U"string literal";
+  char32_t str12[] = { U"string literal" };
+
+  wchar_t str13[] = "nope";  // expected-error {{initializing wide char 
array with non-wide string literal}}
+  wchar_t str14[] = { "nope" };  // expected-error-re {{incompatible pointer 
to integer conversion initializing 'wchar_t' (aka '{{.*}}') with an expression 
of type 'char[5]'}}
+  char16_t str15[] = "nope"; // expected-error {{initializing wide char 
array with non-wide string literal}}
+  char16_t str16[] = { "nope" }; // expected-error-re {{incompatible pointer 
to integer conversion initializing 'char16_t' (aka '{{.*}}') with an expression 
of type 'char[5]'}}
+  char32_t str17[] = "nope"; // expected-error {{initializing wide char 
array with non-wide string literal}}
+  char32_t str18[] = { "nope" }; // expected-error-re {{incompatible pointer 
to integer convers

[clang] [C2y] Claim conformance and add test coverage for WG14 N3346 (PR #115516)

2024-11-08 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`llvm-clang-x86_64-sie-ubuntu-fast` running on `sie-linux-worker` while 
building `clang` at step 6 "test-build-unified-tree-check-all".

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


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

```
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
 TEST 'Clang :: C/C2y/n3346.c' FAILED 
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/clang 
-cc1 -internal-isystem 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/lib/clang/20/include
 -nostdsysteminc -verify -std=c2y -Wall -pedantic -ffreestanding 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/C/C2y/n3346.c
+ 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/clang 
-cc1 -internal-isystem 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/lib/clang/20/include
 -nostdsysteminc -verify -std=c2y -Wall -pedantic -ffreestanding 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/C/C2y/n3346.c
RUN: at line 2: 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/clang 
-cc1 -internal-isystem 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/lib/clang/20/include
 -nostdsysteminc -verify=expected,ped -Wall -pedantic -ffreestanding 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/C/C2y/n3346.c
+ 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/clang 
-cc1 -internal-isystem 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/lib/clang/20/include
 -nostdsysteminc -verify=expected,ped -Wall -pedantic -ffreestanding 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/C/C2y/n3346.c
error: 'expected-error' diagnostics expected but not seen: 
  File 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/C/C2y/n3346.c
 Line 66: initializing wide char array with non-wide string literal
error: 'expected-error' diagnostics seen but not expected: 
  File 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/C/C2y/n3346.c
 Line 49: use of undeclared identifier 'u8'
  File 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/C/C2y/n3346.c
 Line 49: expected ';' at end of declaration
  File 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/C/C2y/n3346.c
 Line 50: use of undeclared identifier 'u8'
  File 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/C/C2y/n3346.c
 Line 57: use of undeclared identifier 'u'
  File 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/C/C2y/n3346.c
 Line 57: expected ';' at end of declaration
  File 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/C/C2y/n3346.c
 Line 58: use of undeclared identifier 'u'
  File 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/C/C2y/n3346.c
 Line 59: use of undeclared identifier 'U'
  File 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/C/C2y/n3346.c
 Line 59: expected ';' at end of declaration
  File 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/C/C2y/n3346.c
 Line 60: use of undeclared identifier 'U'
  File 
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/clang/test/C/C2y/n3346.c
 Line 66: array initializer must be an initializer list
11 errors generated.

--




```



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


[clang] [C2y] Claim conformance and add test coverage for WG14 N3346 (PR #115516)

2024-11-08 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `clang-ve-ninja` running on 
`hpce-ve-main` while building `clang` at step 4 "annotate".

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


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

```
Step 4 (annotate) failure: 'python 
../llvm-zorg/zorg/buildbot/builders/annotated/ve-linux.py ...' (failure)
...
[295/301] Linking CXX executable tools/clang/unittests/Driver/ClangDriverTests
[296/301] Linking CXX executable tools/clang/unittests/CodeGen/ClangCodeGenTests
[297/301] Linking CXX executable tools/clang/unittests/Tooling/ToolingTests
[298/301] Linking CXX executable tools/clang/unittests/Frontend/FrontendTests
[299/301] Linking CXX executable 
tools/clang/unittests/Interpreter/ExceptionTests/ClangReplInterpreterExceptionTests
[300/301] Linking CXX executable 
tools/clang/unittests/Interpreter/ClangReplInterpreterTests
[300/301] Running the Clang regression tests
-- Testing: 21274 tests, 48 workers --
llvm-lit: 
/scratch/buildbot/bothome/clang-ve-ninja/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using clang: 
/scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/clang
Testing:  0.
FAIL: Clang :: C/C2y/n3346.c (1501 of 21274)
 TEST 'Clang :: C/C2y/n3346.c' FAILED 
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: 
/scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/clang -cc1 
-internal-isystem 
/scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/lib/clang/20/include 
-nostdsysteminc -verify -std=c2y -Wall -pedantic -ffreestanding 
/scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/C/C2y/n3346.c
+ /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/clang -cc1 
-internal-isystem 
/scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/lib/clang/20/include 
-nostdsysteminc -verify -std=c2y -Wall -pedantic -ffreestanding 
/scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/C/C2y/n3346.c
error: 'expected-error' diagnostics expected but not seen: 
  File 
/scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/C/C2y/n3346.c 
Line 52: array initializer must be an initializer list
error: 'expected-error' diagnostics seen but not expected: 
  File 
/scratch/buildbot/bothome/clang-ve-ninja/llvm-project/clang/test/C/C2y/n3346.c 
Line 52: initializing wide char array with non-wide string literal
2 errors generated.

--


Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.. 

Failed Tests (1):
  Clang :: C/C2y/n3346.c


Testing Time: 52.55s

Total Discovered Tests: 45589
  Skipped  :10 (0.02%)
  Unsupported  :  3798 (8.33%)
  Passed   : 41754 (91.59%)
  Expectedly Failed:26 (0.06%)
  Failed   : 1 (0.00%)
FAILED: tools/clang/test/CMakeFiles/check-clang 
/scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/tools/clang/test/CMakeFiles/check-clang
 
cd /scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/tools/clang/test 
&& /home/buildbot/sandbox/bin/python3 
/scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/./bin/llvm-lit -sv 
--param USE_Z3_SOLVER=0 
/scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/tools/clang/test
ninja: build stopped: subcommand failed.
make: *** [check-llvm] Error 1
['make', '-f', 
'/scratch/buildbot/bothome/clang-ve-ninja/llvm-zorg/zorg/buildbot/builders/annotated/ve-linux-steps.make',
 'check-llvm', 'BUILDROOT=/scratch/buildbot/bothome/clang-ve-ninja/build'] 
exited with return code 2.
The build step threw an exception...
Traceback (most recent call last):
  File "../llvm-zorg/zorg/buildbot/builders/annotated/ve-linux.py", line 47, in 
step
Step 8 (check-llvm) failure: check-llvm (failure)
...
[295/301] Linking CXX executable tools/clang/unittests/Driver/ClangDriverTests
[296/301] Linking CXX executable tools/clang/unittests/CodeGen/ClangCodeGenTests
[297/301] Linking CXX executable tools/clang/unittests/Tooling/ToolingTests
[298/301] Linking CXX executable tools/clang/unittests/Frontend/FrontendTests
[299/301] Linking CXX executable 
tools/clang/unittests/Interpreter/ExceptionTests/ClangReplInterpreterExceptionTests
[300/301] Linking CXX executable 
tools/clang/unittests/Interpreter/ClangReplInterpreterTests
[300/301] Running the Clang regression tests
-- Testing: 21274 tests, 48 workers --
llvm-lit: 
/scratch/buildbot/bothome/clang-ve-ninja/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using clang: 
/scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/clang
Testing:  0.
FAIL: Clang :: C/C2y/n3346.c (1501 of 21274)
 TEST 'Clang :: C/C2y/n3346.c' FAILED 
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: 
/scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/bin/clang -cc1 
-internal-isystem 
/scratch/buildbot/bothome/clang-ve-ninja/build/build_llvm/lib/clang/20

[clang] [C2y] Claim conformance and add test coverage for WG14 N3346 (PR #115516)

2024-11-08 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`openmp-offload-sles-build-only` running on `rocm-worker-hw-04-sles` while 
building `clang` at step 6 "Add check check-clang".

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


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

```
Step 6 (Add check check-clang) failure: test (failure)
 TEST 'Clang :: C/C2y/n3346.c' FAILED 
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/bin/clang -cc1 
-internal-isystem 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/lib/clang/20/include
 -nostdsysteminc -verify -std=c2y -Wall -pedantic -ffreestanding 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/test/C/C2y/n3346.c
+ /home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/bin/clang 
-cc1 -internal-isystem 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.build/lib/clang/20/include
 -nostdsysteminc -verify -std=c2y -Wall -pedantic -ffreestanding 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/test/C/C2y/n3346.c
error: 'expected-error' diagnostics expected but not seen: 
  File 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/test/C/C2y/n3346.c
 Line 52: array initializer must be an initializer list
error: 'expected-error' diagnostics seen but not expected: 
  File 
/home/botworker/bbot/builds/openmp-offload-sles-build/llvm.src/clang/test/C/C2y/n3346.c
 Line 52: initializing wide char array with non-wide string literal
2 errors generated.

--




```



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


[clang] [C2y] Claim conformance and add test coverage for WG14 N3346 (PR #115516)

2024-11-08 Thread Aaron Ballman via cfe-commits

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


[clang] [C2y] Claim conformance and add test coverage for WG14 N3346 (PR #115516)

2024-11-08 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `clang-m68k-linux-cross` 
running on `suse-gary-m68k-cross` while building `clang` at step 5 "ninja check 
1".

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


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

```
Step 5 (ninja check 1) failure: stage 1 checked (failure)
 TEST 'Clang :: C/C2y/n3346.c' FAILED 
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: 
/var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/stage1/bin/clang
 -cc1 -internal-isystem 
/var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/stage1/lib/clang/20/include
 -nostdsysteminc -verify -std=c2y -Wall -pedantic -ffreestanding 
/var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/llvm/clang/test/C/C2y/n3346.c
+ 
/var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/stage1/bin/clang
 -cc1 -internal-isystem 
/var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/stage1/lib/clang/20/include
 -nostdsysteminc -verify -std=c2y -Wall -pedantic -ffreestanding 
/var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/llvm/clang/test/C/C2y/n3346.c
error: 'expected-error' diagnostics expected but not seen: 
  File 
/var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/llvm/clang/test/C/C2y/n3346.c
 Line 52: array initializer must be an initializer list
error: 'expected-error' diagnostics seen but not expected: 
  File 
/var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/llvm/clang/test/C/C2y/n3346.c
 Line 52: initializing wide char array with non-wide string literal
2 errors generated.

--




```



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


[clang] b85e5b4 - Speculatively fix test bots

2024-11-08 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2024-11-08T12:54:00-05:00
New Revision: b85e5b49d3efc37e837757a5154884648dc57113

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

LOG: Speculatively fix test bots

This should address the issues found by:
https://lab.llvm.org/buildbot/#/builders/12/builds/9226
https://lab.llvm.org/buildbot/#/builders/140/builds/10487
https://lab.llvm.org/buildbot/#/builders/27/builds/1752

Added: 


Modified: 
clang/test/C/C2y/n3346.c

Removed: 




diff  --git a/clang/test/C/C2y/n3346.c b/clang/test/C/C2y/n3346.c
index 2f0ef51d56fb76..d649181f100448 100644
--- a/clang/test/C/C2y/n3346.c
+++ b/clang/test/C/C2y/n3346.c
@@ -49,8 +49,8 @@ void test2(void) {
   char str3[] = u8"string literal";
   char str4[] = { u8"string literal" };
 
-  int str5[] = "this doesn't work";  // expected-error {{array 
initializer must be an initializer list}}
-  int str6[] = { "this also doesn't work" }; // expected-error {{incompatible 
pointer to integer conversion initializing 'int' with an expression of type 
'char[23]'}}
+  float str5[] = "this doesn't work";  // expected-error {{array 
initializer must be an initializer list}}
+  float str6[] = { "this also doesn't work" }; // expected-error 
{{initializing 'float' with an expression of incompatible type 'char[23]'}}
 
   wchar_t str7[] = L"string literal";
   wchar_t str8[] = { L"string literal" };



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


[clang] [C2y] Claim conformance and add test coverage for WG14 N3346 (PR #115516)

2024-11-08 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`clang-cmake-x86_64-avx512-linux` running on `avx512-intel64` while building 
`clang` at step 7 "ninja check 1".

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


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

```
Step 7 (ninja check 1) failure: stage 1 checked (failure)
 TEST 'Clang :: C/C2y/n3346.c' FAILED 
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: 
/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/stage1/bin/clang
 -cc1 -internal-isystem 
/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/stage1/lib/clang/20/include
 -nostdsysteminc -verify -std=c2y -Wall -pedantic -ffreestanding 
/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/llvm/clang/test/C/C2y/n3346.c
+ 
/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/stage1/bin/clang
 -cc1 -internal-isystem 
/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/stage1/lib/clang/20/include
 -nostdsysteminc -verify -std=c2y -Wall -pedantic -ffreestanding 
/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/llvm/clang/test/C/C2y/n3346.c
error: 'expected-error' diagnostics expected but not seen: 
  File 
/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/llvm/clang/test/C/C2y/n3346.c
 Line 52: array initializer must be an initializer list
error: 'expected-error' diagnostics seen but not expected: 
  File 
/localdisk2/buildbot/llvm-worker/clang-cmake-x86_64-avx512-linux/llvm/clang/test/C/C2y/n3346.c
 Line 52: initializing wide char array with non-wide string literal
2 errors generated.

--




```



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


[clang] [C2y] Claim conformance and add test coverage for WG14 N3346 (PR #115516)

2024-11-08 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`llvm-clang-x86_64-gcc-ubuntu` running on `sie-linux-worker3` while building 
`clang` at step 6 "test-build-unified-tree-check-all".

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


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

```
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
 TEST 'Clang :: C/C2y/n3346.c' FAILED 
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: 
/home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/bin/clang -cc1 
-internal-isystem 
/home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/lib/clang/20/include
 -nostdsysteminc -verify -std=c2y -Wall -pedantic -ffreestanding 
/home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/llvm-project/clang/test/C/C2y/n3346.c
+ /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/bin/clang 
-cc1 -internal-isystem 
/home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/lib/clang/20/include
 -nostdsysteminc -verify -std=c2y -Wall -pedantic -ffreestanding 
/home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/llvm-project/clang/test/C/C2y/n3346.c
error: 'expected-error' diagnostics expected but not seen: 
  File 
/home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/llvm-project/clang/test/C/C2y/n3346.c
 Line 52: array initializer must be an initializer list
error: 'expected-error' diagnostics seen but not expected: 
  File 
/home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/llvm-project/clang/test/C/C2y/n3346.c
 Line 52: initializing wide char array with non-wide string literal
2 errors generated.

--




```



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


[clang] [C2y] Claim conformance and add test coverage for WG14 N3346 (PR #115516)

2024-11-08 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `llvm-clang-aarch64-darwin` 
running on `doug-worker-5` while building `clang` at step 6 
"test-build-unified-tree-check-all".

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


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

```
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
 TEST 'Clang :: C/C2y/n3346.c' FAILED 
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/clang 
-cc1 -internal-isystem 
/Users/buildbot/buildbot-root/aarch64-darwin/build/lib/clang/20/include 
-nostdsysteminc -verify -std=c2y -Wall -pedantic -ffreestanding 
/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/C/C2y/n3346.c
+ /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/clang -cc1 
-internal-isystem 
/Users/buildbot/buildbot-root/aarch64-darwin/build/lib/clang/20/include 
-nostdsysteminc -verify -std=c2y -Wall -pedantic -ffreestanding 
/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/C/C2y/n3346.c
error: 'expected-error' diagnostics expected but not seen: 
  File 
/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/C/C2y/n3346.c
 Line 52: array initializer must be an initializer list
error: 'expected-error' diagnostics seen but not expected: 
  File 
/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/C/C2y/n3346.c
 Line 52: initializing wide char array with non-wide string literal
2 errors generated.

--




```



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


[clang] [Clang] add wraps and no_wraps attributes (PR #115094)

2024-11-08 Thread Vitaly Buka via cfe-commits

vitalybuka wrote:

I am comfortable accepting sanitization related stuff, and will be happy to 
look into implementation details.
To me this approach is LGTM, but this patch goes beyond sanitizers into the 
area of tuning behavior of UB code,
so I think we need feedback from maintainers of the related code @erichkeane, 
@efriedma-quic.

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


[clang] [Clang] add wraps and no_wraps attributes (PR #115094)

2024-11-08 Thread Vitaly Buka via cfe-commits


@@ -67,9 +67,11 @@ types specified within an ignorelist.
 int a = 2147483647; // INT_MAX
 ++a;// Normally, an overflow with 
-fsanitize=signed-integer-overflow
   }
+

vitalybuka wrote:

Yes, I'ts about spaces. Even if it's useful change  just create a new PR. Even 
from web UI. If you had commit access, no review is needed.

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


[clang] [Clang] Add support for scoped atomic thread fence (PR #115545)

2024-11-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Joseph Huber (jhuber6)


Changes

Summary:
Previously we added support for all of the atomic GNU extensions with
optional memory scoped except for `__atomic_thread_fence`. This patch
adds support for that. This should ideally allow us to generically emit
these LLVM scopes.


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


3 Files Affected:

- (modified) clang/include/clang/Basic/Builtins.td (+6) 
- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+129) 
- (added) clang/test/CodeGen/scoped-fence-ops.c (+179) 


``diff
diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 87a798183d6e19..4c2f9f621915b1 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -1995,6 +1995,12 @@ def AtomicThreadFence : Builtin {
   let Prototype = "void(int)";
 }
 
+def ScopedAtomicThreadFence : Builtin {
+  let Spellings = ["__scoped_atomic_thread_fence"];
+  let Attributes = [NoThrow];
+  let Prototype = "void(int, int)";
+}
+
 def AtomicSignalFence : Builtin {
   let Spellings = ["__atomic_signal_fence"];
   let Attributes = [NoThrow];
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 5c3df5124517d6..2ec3770ecd42ca 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -5133,6 +5133,135 @@ RValue CodeGenFunction::EmitBuiltinExpr(const 
GlobalDecl GD, unsigned BuiltinID,
 Builder.SetInsertPoint(ContBB);
 return RValue::get(nullptr);
   }
+  case Builtin::BI__scoped_atomic_thread_fence: {
+auto ScopeModel = AtomicScopeModel::create(AtomicScopeModelKind::Generic);
+
+Value *Order = EmitScalarExpr(E->getArg(0));
+Value *Scope = EmitScalarExpr(E->getArg(1));
+if (isa(Order) && isa(Scope)) {
+  int Ord = cast(Order)->getZExtValue();
+  int Scp = cast(Scope)->getZExtValue();
+  SyncScope SS = ScopeModel->isValid(Scp)
+ ? ScopeModel->map(Scp)
+ : ScopeModel->map(ScopeModel->getFallBackValue());
+  switch (Ord) {
+  case 0:  // memory_order_relaxed
+  default: // invalid order
+break;
+  case 1: // memory_order_consume
+  case 2: // memory_order_acquire
+Builder.CreateFence(
+llvm::AtomicOrdering::Acquire,
+getTargetHooks().getLLVMSyncScopeID(getLangOpts(), SS,
+llvm::AtomicOrdering::Acquire,
+getLLVMContext()));
+break;
+  case 3: // memory_order_release
+Builder.CreateFence(
+llvm::AtomicOrdering::Release,
+getTargetHooks().getLLVMSyncScopeID(getLangOpts(), SS,
+llvm::AtomicOrdering::Release,
+getLLVMContext()));
+break;
+  case 4: // memory_order_acq_rel
+Builder.CreateFence(llvm::AtomicOrdering::AcquireRelease,
+getTargetHooks().getLLVMSyncScopeID(
+getLangOpts(), SS,
+llvm::AtomicOrdering::AcquireRelease,
+getLLVMContext()));
+break;
+  case 5: // memory_order_seq_cst
+Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent,
+getTargetHooks().getLLVMSyncScopeID(
+getLangOpts(), SS,
+llvm::AtomicOrdering::SequentiallyConsistent,
+getLLVMContext()));
+break;
+  }
+  return RValue::get(nullptr);
+}
+
+llvm::BasicBlock *ContBB = createBasicBlock("atomic.scope.continue", 
CurFn);
+
+llvm::DenseMap OrderBBs;
+if (isa(Order)) {
+  int Ord = cast(Order)->getZExtValue();
+  switch (Ord) {
+  case 0:  // memory_order_relaxed
+  default: // invalid order
+ContBB->eraseFromParent();
+return RValue::get(nullptr);
+  case 1:  // memory_order_consume
+  case 2:  // memory_order_acquire
+OrderBBs[Builder.GetInsertBlock()] = llvm::AtomicOrdering::Acquire;
+break;
+  case 3: // memory_order_release
+OrderBBs[Builder.GetInsertBlock()] = llvm::AtomicOrdering::Release;
+break;
+  case 4: // memory_order_acq_rel
+OrderBBs[Builder.GetInsertBlock()] =
+llvm::AtomicOrdering::AcquireRelease;
+break;
+  case 5: // memory_order_seq_cst
+OrderBBs[Builder.GetInsertBlock()] =
+llvm::AtomicOrdering::SequentiallyConsistent;
+break;
+  }
+} else {
+  llvm::BasicBlock *AcquireBB, *ReleaseBB, *AcqRelBB, *SeqCstBB;
+  AcquireBB = createBasicBlock("acquire", CurFn);
+  ReleaseBB = createBasicBlock("release", CurFn);
+  AcqRelBB = createBasicBlock("acqrel", CurFn);
+  SeqCstBB

[clang] [Clang] Add support for scoped atomic thread fence (PR #115545)

2024-11-08 Thread Joseph Huber via cfe-commits

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

Summary:
Previously we added support for all of the atomic GNU extensions with
optional memory scoped except for `__atomic_thread_fence`. This patch
adds support for that. This should ideally allow us to generically emit
these LLVM scopes.


>From 5b5806d9e9b516cb74d75237e493941d5bab8128 Mon Sep 17 00:00:00 2001
From: Joseph Huber 
Date: Fri, 8 Nov 2024 15:42:04 -0600
Subject: [PATCH] [Clang] Add support for scoped atomic thread fence

Summary:
Previously we added support for all of the atomic GNU extensions with
optional memory scoped except for `__atomic_thread_fence`. This patch
adds support for that. This should ideally allow us to generically emit
these LLVM scopes.
---
 clang/include/clang/Basic/Builtins.td |   6 +
 clang/lib/CodeGen/CGBuiltin.cpp   | 129 +++
 clang/test/CodeGen/scoped-fence-ops.c | 179 ++
 3 files changed, 314 insertions(+)
 create mode 100644 clang/test/CodeGen/scoped-fence-ops.c

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 87a798183d6e19..4c2f9f621915b1 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -1995,6 +1995,12 @@ def AtomicThreadFence : Builtin {
   let Prototype = "void(int)";
 }
 
+def ScopedAtomicThreadFence : Builtin {
+  let Spellings = ["__scoped_atomic_thread_fence"];
+  let Attributes = [NoThrow];
+  let Prototype = "void(int, int)";
+}
+
 def AtomicSignalFence : Builtin {
   let Spellings = ["__atomic_signal_fence"];
   let Attributes = [NoThrow];
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 5c3df5124517d6..2ec3770ecd42ca 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -5133,6 +5133,135 @@ RValue CodeGenFunction::EmitBuiltinExpr(const 
GlobalDecl GD, unsigned BuiltinID,
 Builder.SetInsertPoint(ContBB);
 return RValue::get(nullptr);
   }
+  case Builtin::BI__scoped_atomic_thread_fence: {
+auto ScopeModel = AtomicScopeModel::create(AtomicScopeModelKind::Generic);
+
+Value *Order = EmitScalarExpr(E->getArg(0));
+Value *Scope = EmitScalarExpr(E->getArg(1));
+if (isa(Order) && isa(Scope)) {
+  int Ord = cast(Order)->getZExtValue();
+  int Scp = cast(Scope)->getZExtValue();
+  SyncScope SS = ScopeModel->isValid(Scp)
+ ? ScopeModel->map(Scp)
+ : ScopeModel->map(ScopeModel->getFallBackValue());
+  switch (Ord) {
+  case 0:  // memory_order_relaxed
+  default: // invalid order
+break;
+  case 1: // memory_order_consume
+  case 2: // memory_order_acquire
+Builder.CreateFence(
+llvm::AtomicOrdering::Acquire,
+getTargetHooks().getLLVMSyncScopeID(getLangOpts(), SS,
+llvm::AtomicOrdering::Acquire,
+getLLVMContext()));
+break;
+  case 3: // memory_order_release
+Builder.CreateFence(
+llvm::AtomicOrdering::Release,
+getTargetHooks().getLLVMSyncScopeID(getLangOpts(), SS,
+llvm::AtomicOrdering::Release,
+getLLVMContext()));
+break;
+  case 4: // memory_order_acq_rel
+Builder.CreateFence(llvm::AtomicOrdering::AcquireRelease,
+getTargetHooks().getLLVMSyncScopeID(
+getLangOpts(), SS,
+llvm::AtomicOrdering::AcquireRelease,
+getLLVMContext()));
+break;
+  case 5: // memory_order_seq_cst
+Builder.CreateFence(llvm::AtomicOrdering::SequentiallyConsistent,
+getTargetHooks().getLLVMSyncScopeID(
+getLangOpts(), SS,
+llvm::AtomicOrdering::SequentiallyConsistent,
+getLLVMContext()));
+break;
+  }
+  return RValue::get(nullptr);
+}
+
+llvm::BasicBlock *ContBB = createBasicBlock("atomic.scope.continue", 
CurFn);
+
+llvm::DenseMap OrderBBs;
+if (isa(Order)) {
+  int Ord = cast(Order)->getZExtValue();
+  switch (Ord) {
+  case 0:  // memory_order_relaxed
+  default: // invalid order
+ContBB->eraseFromParent();
+return RValue::get(nullptr);
+  case 1:  // memory_order_consume
+  case 2:  // memory_order_acquire
+OrderBBs[Builder.GetInsertBlock()] = llvm::AtomicOrdering::Acquire;
+break;
+  case 3: // memory_order_release
+OrderBBs[Builder.GetInsertBlock()] = llvm::AtomicOrdering::Release;
+break;
+  case 4: // memory_order_acq_rel
+OrderBBs[Builder.GetInsertBlock()] =
+llvm::AtomicOrdering::AcquireRelease;
+ 

[clang] [Clang] Add support for scoped atomic thread fence (PR #115545)

2024-11-08 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 a9cd941f392dbf99ddfcde9721bd5c485823bdf0 
5b5806d9e9b516cb74d75237e493941d5bab8128 --extensions c,cpp -- 
clang/test/CodeGen/scoped-fence-ops.c clang/lib/CodeGen/CGBuiltin.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 2ec3770ecd..4d22390c21 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -5191,8 +5191,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   default: // invalid order
 ContBB->eraseFromParent();
 return RValue::get(nullptr);
-  case 1:  // memory_order_consume
-  case 2:  // memory_order_acquire
+  case 1: // memory_order_consume
+  case 2: // memory_order_acquire
 OrderBBs[Builder.GetInsertBlock()] = llvm::AtomicOrdering::Acquire;
 break;
   case 3: // memory_order_release

``




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


[clang] [Clang] Add support for scoped atomic thread fence (PR #115545)

2024-11-08 Thread Matt Arsenault via cfe-commits


@@ -5133,6 +5133,135 @@ RValue CodeGenFunction::EmitBuiltinExpr(const 
GlobalDecl GD, unsigned BuiltinID,
 Builder.SetInsertPoint(ContBB);
 return RValue::get(nullptr);
   }
+  case Builtin::BI__scoped_atomic_thread_fence: {
+auto ScopeModel = AtomicScopeModel::create(AtomicScopeModelKind::Generic);
+
+Value *Order = EmitScalarExpr(E->getArg(0));
+Value *Scope = EmitScalarExpr(E->getArg(1));
+if (isa(Order) && isa(Scope)) {
+  int Ord = cast(Order)->getZExtValue();
+  int Scp = cast(Scope)->getZExtValue();

arsenm wrote:

use dyn_cast instead of isa + cast. But you should be able to just assume this, 
it should be an error to have non-constant arguments 

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


[clang] [llvm][ARM] Restore the default to -mstrict-align on Apple firmwares (PR #115546)

2024-11-08 Thread Jon Roelofs via cfe-commits

https://github.com/jroelofs created 
https://github.com/llvm/llvm-project/pull/115546

This is a partial revert of e314622f204a01ffeda59cbe046dd403b01f8b74

rdar://139237593

>From a54e1c1b7ff03fa0f29b0a64e290763d6b085df8 Mon Sep 17 00:00:00 2001
From: Jon Roelofs 
Date: Fri, 8 Nov 2024 13:46:33 -0800
Subject: [PATCH] [llvm][ARM] Restore the default to -mstrict-align on Apple
 firmwares

This is a partial revert of e314622f204a01ffeda59cbe046dd403b01f8b74

rdar://139237593
---
 clang/lib/Driver/ToolChains/Arch/ARM.cpp | 3 +++
 clang/test/Driver/arm-alignment.c| 6 ++
 2 files changed, 9 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/Arch/ARM.cpp 
b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
index 0489911ecd9dee..f7e9cbfe885785 100644
--- a/clang/lib/Driver/ToolChains/Arch/ARM.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
@@ -908,6 +908,9 @@ llvm::ARM::FPUKind arm::getARMTargetFeatures(const Driver 
&D,
   if (VersionNum < 6 ||
   Triple.getSubArch() == llvm::Triple::SubArchType::ARMSubArch_v6m)
 Features.push_back("+strict-align");
+} else if (Triple.getVendor() == llvm::Triple::Apple && 
Triple.isOSBinFormatMachO()) {
+  // Firmwares on Apple platforms are strict-align by default.
+  Features.push_back("+strict-align");
 } else if (VersionNum < 7 ||
Triple.getSubArch() ==
llvm::Triple::SubArchType::ARMSubArch_v6m ||
diff --git a/clang/test/Driver/arm-alignment.c 
b/clang/test/Driver/arm-alignment.c
index 8c915477af9aff..b714f80a07dc12 100644
--- a/clang/test/Driver/arm-alignment.c
+++ b/clang/test/Driver/arm-alignment.c
@@ -37,6 +37,12 @@
 // RUN: %clang -target thumbv8m.base-none-gnueabi -### %s 2> %t
 // RUN: FileCheck --check-prefix CHECK-ALIGNED-ARM <%t %s
 
+// RUN: %clang -target armv7em-apple-unknown-macho -mthumb -### %s 2> %t
+// RUN: FileCheck --check-prefix CHECK-ALIGNED-ARM <%t %s
+
+// RUN: %clang -target armv7em-apple-darwin -mthumb -### %s 2> %t
+// RUN: FileCheck --check-prefix CHECK-ALIGNED-ARM <%t %s
+
 // RUN: %clang --target=aarch64 -munaligned-access -### %s 2> %t
 // RUN: FileCheck --check-prefix=CHECK-UNALIGNED-AARCH64 < %t %s
 

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


  1   2   3   4   5   >